1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 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"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (const char *,
105 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_locations; \
582 BP_TMP < bp_locations + bp_locations_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_locations + bp_locations_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_locations_compare - primarily by the ADDRESS. */
611 static struct bp_location
**bp_locations
;
613 /* Number of elements of BP_LOCATIONS. */
615 static unsigned bp_locations_count
;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATIONS which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_locations_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_LOCATIONS which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATIONS to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from the bp_locations array, but for which a hit may still be
635 reported by a target. */
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_locations_compare function. */
926 bp_locations_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 dummy_loc
.address
= address
;
952 /* Find a close match to the first location at ADDRESS. */
953 locp_found
= ((struct bp_location
**)
954 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
955 sizeof (struct bp_location
**),
956 bp_locations_compare_addrs
));
958 /* Nothing was found, nothing left to do. */
959 if (locp_found
== NULL
)
962 /* We may have found a location that is at ADDRESS but is not the first in the
963 location's list. Go backwards (if possible) and locate the first one. */
964 while ((locp_found
- 1) >= bp_locations
965 && (*(locp_found
- 1))->address
== address
)
972 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
975 xfree (b
->cond_string
);
976 b
->cond_string
= NULL
;
978 if (is_watchpoint (b
))
980 struct watchpoint
*w
= (struct watchpoint
*) b
;
982 w
->cond_exp
.reset ();
986 struct bp_location
*loc
;
988 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
992 /* No need to free the condition agent expression
993 bytecode (if we have one). We will handle this
994 when we go through update_global_location_list. */
1001 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1005 const char *arg
= exp
;
1007 /* I don't know if it matters whether this is the string the user
1008 typed in or the decompiled expression. */
1009 b
->cond_string
= xstrdup (arg
);
1010 b
->condition_not_parsed
= 0;
1012 if (is_watchpoint (b
))
1014 struct watchpoint
*w
= (struct watchpoint
*) b
;
1016 innermost_block
= NULL
;
1018 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1020 error (_("Junk at end of expression"));
1021 w
->cond_exp_valid_block
= innermost_block
;
1025 struct bp_location
*loc
;
1027 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1031 parse_exp_1 (&arg
, loc
->address
,
1032 block_for_pc (loc
->address
), 0);
1034 error (_("Junk at end of expression"));
1038 mark_breakpoint_modified (b
);
1040 observer_notify_breakpoint_modified (b
);
1043 /* Completion for the "condition" command. */
1045 static VEC (char_ptr
) *
1046 condition_completer (struct cmd_list_element
*cmd
,
1047 const char *text
, const char *word
)
1051 text
= skip_spaces_const (text
);
1052 space
= skip_to_space_const (text
);
1056 struct breakpoint
*b
;
1057 VEC (char_ptr
) *result
= NULL
;
1061 /* We don't support completion of history indices. */
1062 if (isdigit (text
[1]))
1064 return complete_internalvar (&text
[1]);
1067 /* We're completing the breakpoint number. */
1068 len
= strlen (text
);
1074 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1076 if (strncmp (number
, text
, len
) == 0)
1077 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1083 /* We're completing the expression part. */
1084 text
= skip_spaces_const (space
);
1085 return expression_completer (cmd
, text
, word
);
1088 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1091 condition_command (char *arg
, int from_tty
)
1093 struct breakpoint
*b
;
1098 error_no_arg (_("breakpoint number"));
1101 bnum
= get_number (&p
);
1103 error (_("Bad breakpoint argument: '%s'"), arg
);
1106 if (b
->number
== bnum
)
1108 /* Check if this breakpoint has a "stop" method implemented in an
1109 extension language. This method and conditions entered into GDB
1110 from the CLI are mutually exclusive. */
1111 const struct extension_language_defn
*extlang
1112 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1114 if (extlang
!= NULL
)
1116 error (_("Only one stop condition allowed. There is currently"
1117 " a %s stop condition defined for this breakpoint."),
1118 ext_lang_capitalized_name (extlang
));
1120 set_breakpoint_condition (b
, p
, from_tty
);
1122 if (is_breakpoint (b
))
1123 update_global_location_list (UGLL_MAY_INSERT
);
1128 error (_("No breakpoint number %d."), bnum
);
1131 /* Check that COMMAND do not contain commands that are suitable
1132 only for tracepoints and not suitable for ordinary breakpoints.
1133 Throw if any such commands is found. */
1136 check_no_tracepoint_commands (struct command_line
*commands
)
1138 struct command_line
*c
;
1140 for (c
= commands
; c
; c
= c
->next
)
1144 if (c
->control_type
== while_stepping_control
)
1145 error (_("The 'while-stepping' command can "
1146 "only be used for tracepoints"));
1148 for (i
= 0; i
< c
->body_count
; ++i
)
1149 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1151 /* Not that command parsing removes leading whitespace and comment
1152 lines and also empty lines. So, we only need to check for
1153 command directly. */
1154 if (strstr (c
->line
, "collect ") == c
->line
)
1155 error (_("The 'collect' command can only be used for tracepoints"));
1157 if (strstr (c
->line
, "teval ") == c
->line
)
1158 error (_("The 'teval' command can only be used for tracepoints"));
1162 /* Encapsulate tests for different types of tracepoints. */
1165 is_tracepoint_type (enum bptype type
)
1167 return (type
== bp_tracepoint
1168 || type
== bp_fast_tracepoint
1169 || type
== bp_static_tracepoint
);
1173 is_tracepoint (const struct breakpoint
*b
)
1175 return is_tracepoint_type (b
->type
);
1178 /* A helper function that validates that COMMANDS are valid for a
1179 breakpoint. This function will throw an exception if a problem is
1183 validate_commands_for_breakpoint (struct breakpoint
*b
,
1184 struct command_line
*commands
)
1186 if (is_tracepoint (b
))
1188 struct tracepoint
*t
= (struct tracepoint
*) b
;
1189 struct command_line
*c
;
1190 struct command_line
*while_stepping
= 0;
1192 /* Reset the while-stepping step count. The previous commands
1193 might have included a while-stepping action, while the new
1197 /* We need to verify that each top-level element of commands is
1198 valid for tracepoints, that there's at most one
1199 while-stepping element, and that the while-stepping's body
1200 has valid tracing commands excluding nested while-stepping.
1201 We also need to validate the tracepoint action line in the
1202 context of the tracepoint --- validate_actionline actually
1203 has side effects, like setting the tracepoint's
1204 while-stepping STEP_COUNT, in addition to checking if the
1205 collect/teval actions parse and make sense in the
1206 tracepoint's context. */
1207 for (c
= commands
; c
; c
= c
->next
)
1209 if (c
->control_type
== while_stepping_control
)
1211 if (b
->type
== bp_fast_tracepoint
)
1212 error (_("The 'while-stepping' command "
1213 "cannot be used for fast tracepoint"));
1214 else if (b
->type
== bp_static_tracepoint
)
1215 error (_("The 'while-stepping' command "
1216 "cannot be used for static tracepoint"));
1219 error (_("The 'while-stepping' command "
1220 "can be used only once"));
1225 validate_actionline (c
->line
, b
);
1229 struct command_line
*c2
;
1231 gdb_assert (while_stepping
->body_count
== 1);
1232 c2
= while_stepping
->body_list
[0];
1233 for (; c2
; c2
= c2
->next
)
1235 if (c2
->control_type
== while_stepping_control
)
1236 error (_("The 'while-stepping' command cannot be nested"));
1242 check_no_tracepoint_commands (commands
);
1246 /* Return a vector of all the static tracepoints set at ADDR. The
1247 caller is responsible for releasing the vector. */
1250 static_tracepoints_here (CORE_ADDR addr
)
1252 struct breakpoint
*b
;
1253 VEC(breakpoint_p
) *found
= 0;
1254 struct bp_location
*loc
;
1257 if (b
->type
== bp_static_tracepoint
)
1259 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1260 if (loc
->address
== addr
)
1261 VEC_safe_push(breakpoint_p
, found
, b
);
1267 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1268 validate that only allowed commands are included. */
1271 breakpoint_set_commands (struct breakpoint
*b
,
1272 command_line_up
&&commands
)
1274 validate_commands_for_breakpoint (b
, commands
.get ());
1276 decref_counted_command_line (&b
->commands
);
1277 b
->commands
= alloc_counted_command_line (commands
.release ());
1278 observer_notify_breakpoint_modified (b
);
1281 /* Set the internal `silent' flag on the breakpoint. Note that this
1282 is not the same as the "silent" that may appear in the breakpoint's
1286 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1288 int old_silent
= b
->silent
;
1291 if (old_silent
!= silent
)
1292 observer_notify_breakpoint_modified (b
);
1295 /* Set the thread for this breakpoint. If THREAD is -1, make the
1296 breakpoint work for any thread. */
1299 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1301 int old_thread
= b
->thread
;
1304 if (old_thread
!= thread
)
1305 observer_notify_breakpoint_modified (b
);
1308 /* Set the task for this breakpoint. If TASK is 0, make the
1309 breakpoint work for any task. */
1312 breakpoint_set_task (struct breakpoint
*b
, int task
)
1314 int old_task
= b
->task
;
1317 if (old_task
!= task
)
1318 observer_notify_breakpoint_modified (b
);
1322 check_tracepoint_command (char *line
, void *closure
)
1324 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1326 validate_actionline (line
, b
);
1329 /* A structure used to pass information through
1330 map_breakpoint_numbers. */
1332 struct commands_info
1334 /* True if the command was typed at a tty. */
1337 /* The breakpoint range spec. */
1340 /* Non-NULL if the body of the commands are being read from this
1341 already-parsed command. */
1342 struct command_line
*control
;
1344 /* The command lines read from the user, or NULL if they have not
1346 struct counted_command_line
*cmd
;
1349 /* A callback for map_breakpoint_numbers that sets the commands for
1350 commands_command. */
1353 do_map_commands_command (struct breakpoint
*b
, void *data
)
1355 struct commands_info
*info
= (struct commands_info
*) data
;
1357 if (info
->cmd
== NULL
)
1361 if (info
->control
!= NULL
)
1362 l
= copy_command_lines (info
->control
->body_list
[0]);
1365 struct cleanup
*old_chain
;
1368 str
= xstrprintf (_("Type commands for breakpoint(s) "
1369 "%s, one per line."),
1372 old_chain
= make_cleanup (xfree
, str
);
1374 l
= read_command_lines (str
,
1377 ? check_tracepoint_command
: 0),
1380 do_cleanups (old_chain
);
1383 info
->cmd
= alloc_counted_command_line (l
.release ());
1386 /* If a breakpoint was on the list more than once, we don't need to
1388 if (b
->commands
!= info
->cmd
)
1390 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1391 incref_counted_command_line (info
->cmd
);
1392 decref_counted_command_line (&b
->commands
);
1393 b
->commands
= info
->cmd
;
1394 observer_notify_breakpoint_modified (b
);
1399 commands_command_1 (const char *arg
, int from_tty
,
1400 struct command_line
*control
)
1402 struct cleanup
*cleanups
;
1403 struct commands_info info
;
1405 info
.from_tty
= from_tty
;
1406 info
.control
= control
;
1408 /* If we read command lines from the user, then `info' will hold an
1409 extra reference to the commands that we must clean up. */
1410 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1412 std::string new_arg
;
1414 if (arg
== NULL
|| !*arg
)
1416 if (breakpoint_count
- prev_breakpoint_count
> 1)
1417 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1419 else if (breakpoint_count
> 0)
1420 new_arg
= string_printf ("%d", breakpoint_count
);
1425 info
.arg
= new_arg
.c_str ();
1427 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1429 if (info
.cmd
== NULL
)
1430 error (_("No breakpoints specified."));
1432 do_cleanups (cleanups
);
1436 commands_command (char *arg
, int from_tty
)
1438 commands_command_1 (arg
, from_tty
, NULL
);
1441 /* Like commands_command, but instead of reading the commands from
1442 input stream, takes them from an already parsed command structure.
1444 This is used by cli-script.c to DTRT with breakpoint commands
1445 that are part of if and while bodies. */
1446 enum command_control_type
1447 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1449 commands_command_1 (arg
, 0, cmd
);
1450 return simple_control
;
1453 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1456 bp_location_has_shadow (struct bp_location
*bl
)
1458 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1462 if (bl
->target_info
.shadow_len
== 0)
1463 /* BL isn't valid, or doesn't shadow memory. */
1468 /* Update BUF, which is LEN bytes read from the target address
1469 MEMADDR, by replacing a memory breakpoint with its shadowed
1472 If READBUF is not NULL, this buffer must not overlap with the of
1473 the breakpoint location's shadow_contents buffer. Otherwise, a
1474 failed assertion internal error will be raised. */
1477 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1478 const gdb_byte
*writebuf_org
,
1479 ULONGEST memaddr
, LONGEST len
,
1480 struct bp_target_info
*target_info
,
1481 struct gdbarch
*gdbarch
)
1483 /* Now do full processing of the found relevant range of elements. */
1484 CORE_ADDR bp_addr
= 0;
1488 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1489 current_program_space
->aspace
, 0))
1491 /* The breakpoint is inserted in a different address space. */
1495 /* Addresses and length of the part of the breakpoint that
1497 bp_addr
= target_info
->placed_address
;
1498 bp_size
= target_info
->shadow_len
;
1500 if (bp_addr
+ bp_size
<= memaddr
)
1502 /* The breakpoint is entirely before the chunk of memory we are
1507 if (bp_addr
>= memaddr
+ len
)
1509 /* The breakpoint is entirely after the chunk of memory we are
1514 /* Offset within shadow_contents. */
1515 if (bp_addr
< memaddr
)
1517 /* Only copy the second part of the breakpoint. */
1518 bp_size
-= memaddr
- bp_addr
;
1519 bptoffset
= memaddr
- bp_addr
;
1523 if (bp_addr
+ bp_size
> memaddr
+ len
)
1525 /* Only copy the first part of the breakpoint. */
1526 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1529 if (readbuf
!= NULL
)
1531 /* Verify that the readbuf buffer does not overlap with the
1532 shadow_contents buffer. */
1533 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1534 || readbuf
>= (target_info
->shadow_contents
1535 + target_info
->shadow_len
));
1537 /* Update the read buffer with this inserted breakpoint's
1539 memcpy (readbuf
+ bp_addr
- memaddr
,
1540 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1544 const unsigned char *bp
;
1545 CORE_ADDR addr
= target_info
->reqstd_address
;
1548 /* Update the shadow with what we want to write to memory. */
1549 memcpy (target_info
->shadow_contents
+ bptoffset
,
1550 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1552 /* Determine appropriate breakpoint contents and size for this
1554 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1556 /* Update the final write buffer with this inserted
1557 breakpoint's INSN. */
1558 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1562 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1563 by replacing any memory breakpoints with their shadowed contents.
1565 If READBUF is not NULL, this buffer must not overlap with any of
1566 the breakpoint location's shadow_contents buffers. Otherwise,
1567 a failed assertion internal error will be raised.
1569 The range of shadowed area by each bp_location is:
1570 bl->address - bp_locations_placed_address_before_address_max
1571 up to bl->address + bp_locations_shadow_len_after_address_max
1572 The range we were requested to resolve shadows for is:
1573 memaddr ... memaddr + len
1574 Thus the safe cutoff boundaries for performance optimization are
1575 memaddr + len <= (bl->address
1576 - bp_locations_placed_address_before_address_max)
1578 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1581 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1582 const gdb_byte
*writebuf_org
,
1583 ULONGEST memaddr
, LONGEST len
)
1585 /* Left boundary, right boundary and median element of our binary
1587 unsigned bc_l
, bc_r
, bc
;
1589 /* Find BC_L which is a leftmost element which may affect BUF
1590 content. It is safe to report lower value but a failure to
1591 report higher one. */
1594 bc_r
= bp_locations_count
;
1595 while (bc_l
+ 1 < bc_r
)
1597 struct bp_location
*bl
;
1599 bc
= (bc_l
+ bc_r
) / 2;
1600 bl
= bp_locations
[bc
];
1602 /* Check first BL->ADDRESS will not overflow due to the added
1603 constant. Then advance the left boundary only if we are sure
1604 the BC element can in no way affect the BUF content (MEMADDR
1605 to MEMADDR + LEN range).
1607 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1608 offset so that we cannot miss a breakpoint with its shadow
1609 range tail still reaching MEMADDR. */
1611 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1613 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1620 /* Due to the binary search above, we need to make sure we pick the
1621 first location that's at BC_L's address. E.g., if there are
1622 multiple locations at the same address, BC_L may end up pointing
1623 at a duplicate location, and miss the "master"/"inserted"
1624 location. Say, given locations L1, L2 and L3 at addresses A and
1627 L1@A, L2@A, L3@B, ...
1629 BC_L could end up pointing at location L2, while the "master"
1630 location could be L1. Since the `loc->inserted' flag is only set
1631 on "master" locations, we'd forget to restore the shadow of L1
1634 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1637 /* Now do full processing of the found relevant range of elements. */
1639 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1641 struct bp_location
*bl
= bp_locations
[bc
];
1643 /* bp_location array has BL->OWNER always non-NULL. */
1644 if (bl
->owner
->type
== bp_none
)
1645 warning (_("reading through apparently deleted breakpoint #%d?"),
1648 /* Performance optimization: any further element can no longer affect BUF
1651 if (bl
->address
>= bp_locations_placed_address_before_address_max
1652 && memaddr
+ len
<= (bl
->address
1653 - bp_locations_placed_address_before_address_max
))
1656 if (!bp_location_has_shadow (bl
))
1659 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1660 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1666 /* Return true if BPT is either a software breakpoint or a hardware
1670 is_breakpoint (const struct breakpoint
*bpt
)
1672 return (bpt
->type
== bp_breakpoint
1673 || bpt
->type
== bp_hardware_breakpoint
1674 || bpt
->type
== bp_dprintf
);
1677 /* Return true if BPT is of any hardware watchpoint kind. */
1680 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1682 return (bpt
->type
== bp_hardware_watchpoint
1683 || bpt
->type
== bp_read_watchpoint
1684 || bpt
->type
== bp_access_watchpoint
);
1687 /* Return true if BPT is of any watchpoint kind, hardware or
1691 is_watchpoint (const struct breakpoint
*bpt
)
1693 return (is_hardware_watchpoint (bpt
)
1694 || bpt
->type
== bp_watchpoint
);
1697 /* Returns true if the current thread and its running state are safe
1698 to evaluate or update watchpoint B. Watchpoints on local
1699 expressions need to be evaluated in the context of the thread that
1700 was current when the watchpoint was created, and, that thread needs
1701 to be stopped to be able to select the correct frame context.
1702 Watchpoints on global expressions can be evaluated on any thread,
1703 and in any state. It is presently left to the target allowing
1704 memory accesses when threads are running. */
1707 watchpoint_in_thread_scope (struct watchpoint
*b
)
1709 return (b
->base
.pspace
== current_program_space
1710 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1711 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1712 && !is_executing (inferior_ptid
))));
1715 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1716 associated bp_watchpoint_scope breakpoint. */
1719 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1721 struct breakpoint
*b
= &w
->base
;
1723 if (b
->related_breakpoint
!= b
)
1725 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1726 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1727 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1728 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1729 b
->related_breakpoint
= b
;
1731 b
->disposition
= disp_del_at_next_stop
;
1734 /* Extract a bitfield value from value VAL using the bit parameters contained in
1737 static struct value
*
1738 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1740 struct value
*bit_val
;
1745 bit_val
= allocate_value (value_type (val
));
1747 unpack_value_bitfield (bit_val
,
1750 value_contents_for_printing (val
),
1757 /* Allocate a dummy location and add it to B, which must be a software
1758 watchpoint. This is required because even if a software watchpoint
1759 is not watching any memory, bpstat_stop_status requires a location
1760 to be able to report stops. */
1763 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1764 struct program_space
*pspace
)
1766 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1768 b
->loc
= allocate_bp_location (b
);
1769 b
->loc
->pspace
= pspace
;
1770 b
->loc
->address
= -1;
1771 b
->loc
->length
= -1;
1774 /* Returns true if B is a software watchpoint that is not watching any
1775 memory (e.g., "watch $pc"). */
1778 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1780 return (b
->type
== bp_watchpoint
1782 && b
->loc
->next
== NULL
1783 && b
->loc
->address
== -1
1784 && b
->loc
->length
== -1);
1787 /* Assuming that B is a watchpoint:
1788 - Reparse watchpoint expression, if REPARSE is non-zero
1789 - Evaluate expression and store the result in B->val
1790 - Evaluate the condition if there is one, and store the result
1792 - Update the list of values that must be watched in B->loc.
1794 If the watchpoint disposition is disp_del_at_next_stop, then do
1795 nothing. If this is local watchpoint that is out of scope, delete
1798 Even with `set breakpoint always-inserted on' the watchpoints are
1799 removed + inserted on each stop here. Normal breakpoints must
1800 never be removed because they might be missed by a running thread
1801 when debugging in non-stop mode. On the other hand, hardware
1802 watchpoints (is_hardware_watchpoint; processed here) are specific
1803 to each LWP since they are stored in each LWP's hardware debug
1804 registers. Therefore, such LWP must be stopped first in order to
1805 be able to modify its hardware watchpoints.
1807 Hardware watchpoints must be reset exactly once after being
1808 presented to the user. It cannot be done sooner, because it would
1809 reset the data used to present the watchpoint hit to the user. And
1810 it must not be done later because it could display the same single
1811 watchpoint hit during multiple GDB stops. Note that the latter is
1812 relevant only to the hardware watchpoint types bp_read_watchpoint
1813 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1814 not user-visible - its hit is suppressed if the memory content has
1817 The following constraints influence the location where we can reset
1818 hardware watchpoints:
1820 * target_stopped_by_watchpoint and target_stopped_data_address are
1821 called several times when GDB stops.
1824 * Multiple hardware watchpoints can be hit at the same time,
1825 causing GDB to stop. GDB only presents one hardware watchpoint
1826 hit at a time as the reason for stopping, and all the other hits
1827 are presented later, one after the other, each time the user
1828 requests the execution to be resumed. Execution is not resumed
1829 for the threads still having pending hit event stored in
1830 LWP_INFO->STATUS. While the watchpoint is already removed from
1831 the inferior on the first stop the thread hit event is kept being
1832 reported from its cached value by linux_nat_stopped_data_address
1833 until the real thread resume happens after the watchpoint gets
1834 presented and thus its LWP_INFO->STATUS gets reset.
1836 Therefore the hardware watchpoint hit can get safely reset on the
1837 watchpoint removal from inferior. */
1840 update_watchpoint (struct watchpoint
*b
, int reparse
)
1842 int within_current_scope
;
1843 struct frame_id saved_frame_id
;
1846 /* If this is a local watchpoint, we only want to check if the
1847 watchpoint frame is in scope if the current thread is the thread
1848 that was used to create the watchpoint. */
1849 if (!watchpoint_in_thread_scope (b
))
1852 if (b
->base
.disposition
== disp_del_at_next_stop
)
1857 /* Determine if the watchpoint is within scope. */
1858 if (b
->exp_valid_block
== NULL
)
1859 within_current_scope
= 1;
1862 struct frame_info
*fi
= get_current_frame ();
1863 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1864 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1866 /* If we're at a point where the stack has been destroyed
1867 (e.g. in a function epilogue), unwinding may not work
1868 properly. Do not attempt to recreate locations at this
1869 point. See similar comments in watchpoint_check. */
1870 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1873 /* Save the current frame's ID so we can restore it after
1874 evaluating the watchpoint expression on its own frame. */
1875 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1876 took a frame parameter, so that we didn't have to change the
1879 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1881 fi
= frame_find_by_id (b
->watchpoint_frame
);
1882 within_current_scope
= (fi
!= NULL
);
1883 if (within_current_scope
)
1887 /* We don't free locations. They are stored in the bp_location array
1888 and update_global_location_list will eventually delete them and
1889 remove breakpoints if needed. */
1892 if (within_current_scope
&& reparse
)
1897 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1898 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1899 /* If the meaning of expression itself changed, the old value is
1900 no longer relevant. We don't want to report a watchpoint hit
1901 to the user when the old value and the new value may actually
1902 be completely different objects. */
1903 value_free (b
->val
);
1907 /* Note that unlike with breakpoints, the watchpoint's condition
1908 expression is stored in the breakpoint object, not in the
1909 locations (re)created below. */
1910 if (b
->base
.cond_string
!= NULL
)
1912 b
->cond_exp
.reset ();
1914 s
= b
->base
.cond_string
;
1915 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1919 /* If we failed to parse the expression, for example because
1920 it refers to a global variable in a not-yet-loaded shared library,
1921 don't try to insert watchpoint. We don't automatically delete
1922 such watchpoint, though, since failure to parse expression
1923 is different from out-of-scope watchpoint. */
1924 if (!target_has_execution
)
1926 /* Without execution, memory can't change. No use to try and
1927 set watchpoint locations. The watchpoint will be reset when
1928 the target gains execution, through breakpoint_re_set. */
1929 if (!can_use_hw_watchpoints
)
1931 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1932 b
->base
.type
= bp_watchpoint
;
1934 error (_("Can't set read/access watchpoint when "
1935 "hardware watchpoints are disabled."));
1938 else if (within_current_scope
&& b
->exp
)
1941 struct value
*val_chain
, *v
, *result
, *next
;
1942 struct program_space
*frame_pspace
;
1944 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1946 /* Avoid setting b->val if it's already set. The meaning of
1947 b->val is 'the last value' user saw, and we should update
1948 it only if we reported that last value to user. As it
1949 happens, the code that reports it updates b->val directly.
1950 We don't keep track of the memory value for masked
1952 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1954 if (b
->val_bitsize
!= 0)
1956 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1964 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1966 /* Look at each value on the value chain. */
1967 for (v
= val_chain
; v
; v
= value_next (v
))
1969 /* If it's a memory location, and GDB actually needed
1970 its contents to evaluate the expression, then we
1971 must watch it. If the first value returned is
1972 still lazy, that means an error occurred reading it;
1973 watch it anyway in case it becomes readable. */
1974 if (VALUE_LVAL (v
) == lval_memory
1975 && (v
== val_chain
|| ! value_lazy (v
)))
1977 struct type
*vtype
= check_typedef (value_type (v
));
1979 /* We only watch structs and arrays if user asked
1980 for it explicitly, never if they just happen to
1981 appear in the middle of some value chain. */
1983 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1984 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1987 enum target_hw_bp_type type
;
1988 struct bp_location
*loc
, **tmp
;
1989 int bitpos
= 0, bitsize
= 0;
1991 if (value_bitsize (v
) != 0)
1993 /* Extract the bit parameters out from the bitfield
1995 bitpos
= value_bitpos (v
);
1996 bitsize
= value_bitsize (v
);
1998 else if (v
== result
&& b
->val_bitsize
!= 0)
2000 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2001 lvalue whose bit parameters are saved in the fields
2002 VAL_BITPOS and VAL_BITSIZE. */
2003 bitpos
= b
->val_bitpos
;
2004 bitsize
= b
->val_bitsize
;
2007 addr
= value_address (v
);
2010 /* Skip the bytes that don't contain the bitfield. */
2015 if (b
->base
.type
== bp_read_watchpoint
)
2017 else if (b
->base
.type
== bp_access_watchpoint
)
2020 loc
= allocate_bp_location (&b
->base
);
2021 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2024 loc
->gdbarch
= get_type_arch (value_type (v
));
2026 loc
->pspace
= frame_pspace
;
2027 loc
->address
= addr
;
2031 /* Just cover the bytes that make up the bitfield. */
2032 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2035 loc
->length
= TYPE_LENGTH (value_type (v
));
2037 loc
->watchpoint_type
= type
;
2042 /* Change the type of breakpoint between hardware assisted or
2043 an ordinary watchpoint depending on the hardware support
2044 and free hardware slots. REPARSE is set when the inferior
2049 enum bp_loc_type loc_type
;
2050 struct bp_location
*bl
;
2052 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2056 int i
, target_resources_ok
, other_type_used
;
2059 /* Use an exact watchpoint when there's only one memory region to be
2060 watched, and only one debug register is needed to watch it. */
2061 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2063 /* We need to determine how many resources are already
2064 used for all other hardware watchpoints plus this one
2065 to see if we still have enough resources to also fit
2066 this watchpoint in as well. */
2068 /* If this is a software watchpoint, we try to turn it
2069 to a hardware one -- count resources as if B was of
2070 hardware watchpoint type. */
2071 type
= b
->base
.type
;
2072 if (type
== bp_watchpoint
)
2073 type
= bp_hardware_watchpoint
;
2075 /* This watchpoint may or may not have been placed on
2076 the list yet at this point (it won't be in the list
2077 if we're trying to create it for the first time,
2078 through watch_command), so always account for it
2081 /* Count resources used by all watchpoints except B. */
2082 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2084 /* Add in the resources needed for B. */
2085 i
+= hw_watchpoint_use_count (&b
->base
);
2088 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2089 if (target_resources_ok
<= 0)
2091 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2093 if (target_resources_ok
== 0 && !sw_mode
)
2094 error (_("Target does not support this type of "
2095 "hardware watchpoint."));
2096 else if (target_resources_ok
< 0 && !sw_mode
)
2097 error (_("There are not enough available hardware "
2098 "resources for this watchpoint."));
2100 /* Downgrade to software watchpoint. */
2101 b
->base
.type
= bp_watchpoint
;
2105 /* If this was a software watchpoint, we've just
2106 found we have enough resources to turn it to a
2107 hardware watchpoint. Otherwise, this is a
2109 b
->base
.type
= type
;
2112 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2114 if (!can_use_hw_watchpoints
)
2115 error (_("Can't set read/access watchpoint when "
2116 "hardware watchpoints are disabled."));
2118 error (_("Expression cannot be implemented with "
2119 "read/access watchpoint."));
2122 b
->base
.type
= bp_watchpoint
;
2124 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2125 : bp_loc_hardware_watchpoint
);
2126 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2127 bl
->loc_type
= loc_type
;
2130 for (v
= val_chain
; v
; v
= next
)
2132 next
= value_next (v
);
2137 /* If a software watchpoint is not watching any memory, then the
2138 above left it without any location set up. But,
2139 bpstat_stop_status requires a location to be able to report
2140 stops, so make sure there's at least a dummy one. */
2141 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2142 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2144 else if (!within_current_scope
)
2146 printf_filtered (_("\
2147 Watchpoint %d deleted because the program has left the block\n\
2148 in which its expression is valid.\n"),
2150 watchpoint_del_at_next_stop (b
);
2153 /* Restore the selected frame. */
2155 select_frame (frame_find_by_id (saved_frame_id
));
2159 /* Returns 1 iff breakpoint location should be
2160 inserted in the inferior. We don't differentiate the type of BL's owner
2161 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2162 breakpoint_ops is not defined, because in insert_bp_location,
2163 tracepoint's insert_location will not be called. */
2165 should_be_inserted (struct bp_location
*bl
)
2167 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2170 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2173 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2176 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2179 /* This is set for example, when we're attached to the parent of a
2180 vfork, and have detached from the child. The child is running
2181 free, and we expect it to do an exec or exit, at which point the
2182 OS makes the parent schedulable again (and the target reports
2183 that the vfork is done). Until the child is done with the shared
2184 memory region, do not insert breakpoints in the parent, otherwise
2185 the child could still trip on the parent's breakpoints. Since
2186 the parent is blocked anyway, it won't miss any breakpoint. */
2187 if (bl
->pspace
->breakpoints_not_allowed
)
2190 /* Don't insert a breakpoint if we're trying to step past its
2191 location, except if the breakpoint is a single-step breakpoint,
2192 and the breakpoint's thread is the thread which is stepping past
2194 if ((bl
->loc_type
== bp_loc_software_breakpoint
2195 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2196 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2198 /* The single-step breakpoint may be inserted at the location
2199 we're trying to step if the instruction branches to itself.
2200 However, the instruction won't be executed at all and it may
2201 break the semantics of the instruction, for example, the
2202 instruction is a conditional branch or updates some flags.
2203 We can't fix it unless GDB is able to emulate the instruction
2204 or switch to displaced stepping. */
2205 && !(bl
->owner
->type
== bp_single_step
2206 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2210 fprintf_unfiltered (gdb_stdlog
,
2211 "infrun: skipping breakpoint: "
2212 "stepping past insn at: %s\n",
2213 paddress (bl
->gdbarch
, bl
->address
));
2218 /* Don't insert watchpoints if we're trying to step past the
2219 instruction that triggered one. */
2220 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2221 && stepping_past_nonsteppable_watchpoint ())
2225 fprintf_unfiltered (gdb_stdlog
,
2226 "infrun: stepping past non-steppable watchpoint. "
2227 "skipping watchpoint at %s:%d\n",
2228 paddress (bl
->gdbarch
, bl
->address
),
2237 /* Same as should_be_inserted but does the check assuming
2238 that the location is not duplicated. */
2241 unduplicated_should_be_inserted (struct bp_location
*bl
)
2244 const int save_duplicate
= bl
->duplicate
;
2247 result
= should_be_inserted (bl
);
2248 bl
->duplicate
= save_duplicate
;
2252 /* Parses a conditional described by an expression COND into an
2253 agent expression bytecode suitable for evaluation
2254 by the bytecode interpreter. Return NULL if there was
2255 any error during parsing. */
2257 static agent_expr_up
2258 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2263 agent_expr_up aexpr
;
2265 /* We don't want to stop processing, so catch any errors
2266 that may show up. */
2269 aexpr
= gen_eval_for_expr (scope
, cond
);
2272 CATCH (ex
, RETURN_MASK_ERROR
)
2274 /* If we got here, it means the condition could not be parsed to a valid
2275 bytecode expression and thus can't be evaluated on the target's side.
2276 It's no use iterating through the conditions. */
2280 /* We have a valid agent expression. */
2284 /* Based on location BL, create a list of breakpoint conditions to be
2285 passed on to the target. If we have duplicated locations with different
2286 conditions, we will add such conditions to the list. The idea is that the
2287 target will evaluate the list of conditions and will only notify GDB when
2288 one of them is true. */
2291 build_target_condition_list (struct bp_location
*bl
)
2293 struct bp_location
**locp
= NULL
, **loc2p
;
2294 int null_condition_or_parse_error
= 0;
2295 int modified
= bl
->needs_update
;
2296 struct bp_location
*loc
;
2298 /* Release conditions left over from a previous insert. */
2299 bl
->target_info
.conditions
.clear ();
2301 /* This is only meaningful if the target is
2302 evaluating conditions and if the user has
2303 opted for condition evaluation on the target's
2305 if (gdb_evaluates_breakpoint_condition_p ()
2306 || !target_supports_evaluation_of_breakpoint_conditions ())
2309 /* Do a first pass to check for locations with no assigned
2310 conditions or conditions that fail to parse to a valid agent expression
2311 bytecode. If any of these happen, then it's no use to send conditions
2312 to the target since this location will always trigger and generate a
2313 response back to GDB. */
2314 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2317 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2321 /* Re-parse the conditions since something changed. In that
2322 case we already freed the condition bytecodes (see
2323 force_breakpoint_reinsertion). We just
2324 need to parse the condition to bytecodes again. */
2325 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2329 /* If we have a NULL bytecode expression, it means something
2330 went wrong or we have a null condition expression. */
2331 if (!loc
->cond_bytecode
)
2333 null_condition_or_parse_error
= 1;
2339 /* If any of these happened, it means we will have to evaluate the conditions
2340 for the location's address on gdb's side. It is no use keeping bytecodes
2341 for all the other duplicate locations, thus we free all of them here.
2343 This is so we have a finer control over which locations' conditions are
2344 being evaluated by GDB or the remote stub. */
2345 if (null_condition_or_parse_error
)
2347 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2350 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2352 /* Only go as far as the first NULL bytecode is
2354 if (!loc
->cond_bytecode
)
2357 loc
->cond_bytecode
.reset ();
2362 /* No NULL conditions or failed bytecode generation. Build a condition list
2363 for this location's address. */
2364 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2368 && is_breakpoint (loc
->owner
)
2369 && loc
->pspace
->num
== bl
->pspace
->num
2370 && loc
->owner
->enable_state
== bp_enabled
2373 /* Add the condition to the vector. This will be used later
2374 to send the conditions to the target. */
2375 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2382 /* Parses a command described by string CMD into an agent expression
2383 bytecode suitable for evaluation by the bytecode interpreter.
2384 Return NULL if there was any error during parsing. */
2386 static agent_expr_up
2387 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2389 struct cleanup
*old_cleanups
= 0;
2390 struct expression
**argvec
;
2391 const char *cmdrest
;
2392 const char *format_start
, *format_end
;
2393 struct format_piece
*fpieces
;
2395 struct gdbarch
*gdbarch
= get_current_arch ();
2402 if (*cmdrest
== ',')
2404 cmdrest
= skip_spaces_const (cmdrest
);
2406 if (*cmdrest
++ != '"')
2407 error (_("No format string following the location"));
2409 format_start
= cmdrest
;
2411 fpieces
= parse_format_string (&cmdrest
);
2413 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2415 format_end
= cmdrest
;
2417 if (*cmdrest
++ != '"')
2418 error (_("Bad format string, non-terminated '\"'."));
2420 cmdrest
= skip_spaces_const (cmdrest
);
2422 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2423 error (_("Invalid argument syntax"));
2425 if (*cmdrest
== ',')
2427 cmdrest
= skip_spaces_const (cmdrest
);
2429 /* For each argument, make an expression. */
2431 argvec
= (struct expression
**) alloca (strlen (cmd
)
2432 * sizeof (struct expression
*));
2435 while (*cmdrest
!= '\0')
2440 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2441 argvec
[nargs
++] = expr
.release ();
2443 if (*cmdrest
== ',')
2447 agent_expr_up aexpr
;
2449 /* We don't want to stop processing, so catch any errors
2450 that may show up. */
2453 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2454 format_start
, format_end
- format_start
,
2455 fpieces
, nargs
, argvec
);
2457 CATCH (ex
, RETURN_MASK_ERROR
)
2459 /* If we got here, it means the command could not be parsed to a valid
2460 bytecode expression and thus can't be evaluated on the target's side.
2461 It's no use iterating through the other commands. */
2465 do_cleanups (old_cleanups
);
2467 /* We have a valid agent expression, return it. */
2471 /* Based on location BL, create a list of breakpoint commands to be
2472 passed on to the target. If we have duplicated locations with
2473 different commands, we will add any such to the list. */
2476 build_target_command_list (struct bp_location
*bl
)
2478 struct bp_location
**locp
= NULL
, **loc2p
;
2479 int null_command_or_parse_error
= 0;
2480 int modified
= bl
->needs_update
;
2481 struct bp_location
*loc
;
2483 /* Clear commands left over from a previous insert. */
2484 bl
->target_info
.tcommands
.clear ();
2486 if (!target_can_run_breakpoint_commands ())
2489 /* For now, limit to agent-style dprintf breakpoints. */
2490 if (dprintf_style
!= dprintf_style_agent
)
2493 /* For now, if we have any duplicate location that isn't a dprintf,
2494 don't install the target-side commands, as that would make the
2495 breakpoint not be reported to the core, and we'd lose
2497 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2500 if (is_breakpoint (loc
->owner
)
2501 && loc
->pspace
->num
== bl
->pspace
->num
2502 && loc
->owner
->type
!= bp_dprintf
)
2506 /* Do a first pass to check for locations with no assigned
2507 conditions or conditions that fail to parse to a valid agent expression
2508 bytecode. If any of these happen, then it's no use to send conditions
2509 to the target since this location will always trigger and generate a
2510 response back to GDB. */
2511 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2514 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2518 /* Re-parse the commands since something changed. In that
2519 case we already freed the command bytecodes (see
2520 force_breakpoint_reinsertion). We just
2521 need to parse the command to bytecodes again. */
2523 = parse_cmd_to_aexpr (bl
->address
,
2524 loc
->owner
->extra_string
);
2527 /* If we have a NULL bytecode expression, it means something
2528 went wrong or we have a null command expression. */
2529 if (!loc
->cmd_bytecode
)
2531 null_command_or_parse_error
= 1;
2537 /* If anything failed, then we're not doing target-side commands,
2539 if (null_command_or_parse_error
)
2541 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2544 if (is_breakpoint (loc
->owner
)
2545 && loc
->pspace
->num
== bl
->pspace
->num
)
2547 /* Only go as far as the first NULL bytecode is
2549 if (loc
->cmd_bytecode
== NULL
)
2552 loc
->cmd_bytecode
.reset ();
2557 /* No NULL commands or failed bytecode generation. Build a command list
2558 for this location's address. */
2559 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2562 if (loc
->owner
->extra_string
2563 && is_breakpoint (loc
->owner
)
2564 && loc
->pspace
->num
== bl
->pspace
->num
2565 && loc
->owner
->enable_state
== bp_enabled
2568 /* Add the command to the vector. This will be used later
2569 to send the commands to the target. */
2570 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2574 bl
->target_info
.persist
= 0;
2575 /* Maybe flag this location as persistent. */
2576 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2577 bl
->target_info
.persist
= 1;
2580 /* Return the kind of breakpoint on address *ADDR. Get the kind
2581 of breakpoint according to ADDR except single-step breakpoint.
2582 Get the kind of single-step breakpoint according to the current
2586 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2588 if (bl
->owner
->type
== bp_single_step
)
2590 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2591 struct regcache
*regcache
;
2593 regcache
= get_thread_regcache (thr
->ptid
);
2595 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2599 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2602 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2603 location. Any error messages are printed to TMP_ERROR_STREAM; and
2604 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2605 Returns 0 for success, 1 if the bp_location type is not supported or
2608 NOTE drow/2003-09-09: This routine could be broken down to an
2609 object-style method for each breakpoint or catchpoint type. */
2611 insert_bp_location (struct bp_location
*bl
,
2612 struct ui_file
*tmp_error_stream
,
2613 int *disabled_breaks
,
2614 int *hw_breakpoint_error
,
2615 int *hw_bp_error_explained_already
)
2617 enum errors bp_err
= GDB_NO_ERROR
;
2618 const char *bp_err_message
= NULL
;
2620 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2623 /* Note we don't initialize bl->target_info, as that wipes out
2624 the breakpoint location's shadow_contents if the breakpoint
2625 is still inserted at that location. This in turn breaks
2626 target_read_memory which depends on these buffers when
2627 a memory read is requested at the breakpoint location:
2628 Once the target_info has been wiped, we fail to see that
2629 we have a breakpoint inserted at that address and thus
2630 read the breakpoint instead of returning the data saved in
2631 the breakpoint location's shadow contents. */
2632 bl
->target_info
.reqstd_address
= bl
->address
;
2633 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2634 bl
->target_info
.length
= bl
->length
;
2636 /* When working with target-side conditions, we must pass all the conditions
2637 for the same breakpoint address down to the target since GDB will not
2638 insert those locations. With a list of breakpoint conditions, the target
2639 can decide when to stop and notify GDB. */
2641 if (is_breakpoint (bl
->owner
))
2643 build_target_condition_list (bl
);
2644 build_target_command_list (bl
);
2645 /* Reset the modification marker. */
2646 bl
->needs_update
= 0;
2649 if (bl
->loc_type
== bp_loc_software_breakpoint
2650 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2652 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2654 /* If the explicitly specified breakpoint type
2655 is not hardware breakpoint, check the memory map to see
2656 if the breakpoint address is in read only memory or not.
2658 Two important cases are:
2659 - location type is not hardware breakpoint, memory
2660 is readonly. We change the type of the location to
2661 hardware breakpoint.
2662 - location type is hardware breakpoint, memory is
2663 read-write. This means we've previously made the
2664 location hardware one, but then the memory map changed,
2667 When breakpoints are removed, remove_breakpoints will use
2668 location types we've just set here, the only possible
2669 problem is that memory map has changed during running
2670 program, but it's not going to work anyway with current
2672 struct mem_region
*mr
2673 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2677 if (automatic_hardware_breakpoints
)
2679 enum bp_loc_type new_type
;
2681 if (mr
->attrib
.mode
!= MEM_RW
)
2682 new_type
= bp_loc_hardware_breakpoint
;
2684 new_type
= bp_loc_software_breakpoint
;
2686 if (new_type
!= bl
->loc_type
)
2688 static int said
= 0;
2690 bl
->loc_type
= new_type
;
2693 fprintf_filtered (gdb_stdout
,
2694 _("Note: automatically using "
2695 "hardware breakpoints for "
2696 "read-only addresses.\n"));
2701 else if (bl
->loc_type
== bp_loc_software_breakpoint
2702 && mr
->attrib
.mode
!= MEM_RW
)
2704 fprintf_unfiltered (tmp_error_stream
,
2705 _("Cannot insert breakpoint %d.\n"
2706 "Cannot set software breakpoint "
2707 "at read-only address %s\n"),
2709 paddress (bl
->gdbarch
, bl
->address
));
2715 /* First check to see if we have to handle an overlay. */
2716 if (overlay_debugging
== ovly_off
2717 || bl
->section
== NULL
2718 || !(section_is_overlay (bl
->section
)))
2720 /* No overlay handling: just set the breakpoint. */
2725 val
= bl
->owner
->ops
->insert_location (bl
);
2727 bp_err
= GENERIC_ERROR
;
2729 CATCH (e
, RETURN_MASK_ALL
)
2732 bp_err_message
= e
.message
;
2738 /* This breakpoint is in an overlay section.
2739 Shall we set a breakpoint at the LMA? */
2740 if (!overlay_events_enabled
)
2742 /* Yes -- overlay event support is not active,
2743 so we must try to set a breakpoint at the LMA.
2744 This will not work for a hardware breakpoint. */
2745 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2746 warning (_("hardware breakpoint %d not supported in overlay!"),
2750 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2752 /* Set a software (trap) breakpoint at the LMA. */
2753 bl
->overlay_target_info
= bl
->target_info
;
2754 bl
->overlay_target_info
.reqstd_address
= addr
;
2756 /* No overlay handling: just set the breakpoint. */
2761 bl
->overlay_target_info
.kind
2762 = breakpoint_kind (bl
, &addr
);
2763 bl
->overlay_target_info
.placed_address
= addr
;
2764 val
= target_insert_breakpoint (bl
->gdbarch
,
2765 &bl
->overlay_target_info
);
2767 bp_err
= GENERIC_ERROR
;
2769 CATCH (e
, RETURN_MASK_ALL
)
2772 bp_err_message
= e
.message
;
2776 if (bp_err
!= GDB_NO_ERROR
)
2777 fprintf_unfiltered (tmp_error_stream
,
2778 "Overlay breakpoint %d "
2779 "failed: in ROM?\n",
2783 /* Shall we set a breakpoint at the VMA? */
2784 if (section_is_mapped (bl
->section
))
2786 /* Yes. This overlay section is mapped into memory. */
2791 val
= bl
->owner
->ops
->insert_location (bl
);
2793 bp_err
= GENERIC_ERROR
;
2795 CATCH (e
, RETURN_MASK_ALL
)
2798 bp_err_message
= e
.message
;
2804 /* No. This breakpoint will not be inserted.
2805 No error, but do not mark the bp as 'inserted'. */
2810 if (bp_err
!= GDB_NO_ERROR
)
2812 /* Can't set the breakpoint. */
2814 /* In some cases, we might not be able to insert a
2815 breakpoint in a shared library that has already been
2816 removed, but we have not yet processed the shlib unload
2817 event. Unfortunately, some targets that implement
2818 breakpoint insertion themselves can't tell why the
2819 breakpoint insertion failed (e.g., the remote target
2820 doesn't define error codes), so we must treat generic
2821 errors as memory errors. */
2822 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2823 && bl
->loc_type
== bp_loc_software_breakpoint
2824 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2825 || shared_objfile_contains_address_p (bl
->pspace
,
2828 /* See also: disable_breakpoints_in_shlibs. */
2829 bl
->shlib_disabled
= 1;
2830 observer_notify_breakpoint_modified (bl
->owner
);
2831 if (!*disabled_breaks
)
2833 fprintf_unfiltered (tmp_error_stream
,
2834 "Cannot insert breakpoint %d.\n",
2836 fprintf_unfiltered (tmp_error_stream
,
2837 "Temporarily disabling shared "
2838 "library breakpoints:\n");
2840 *disabled_breaks
= 1;
2841 fprintf_unfiltered (tmp_error_stream
,
2842 "breakpoint #%d\n", bl
->owner
->number
);
2847 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2849 *hw_breakpoint_error
= 1;
2850 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2851 fprintf_unfiltered (tmp_error_stream
,
2852 "Cannot insert hardware breakpoint %d%s",
2853 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2854 if (bp_err_message
!= NULL
)
2855 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2859 if (bp_err_message
== NULL
)
2862 = memory_error_message (TARGET_XFER_E_IO
,
2863 bl
->gdbarch
, bl
->address
);
2864 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2866 fprintf_unfiltered (tmp_error_stream
,
2867 "Cannot insert breakpoint %d.\n"
2869 bl
->owner
->number
, message
);
2870 do_cleanups (old_chain
);
2874 fprintf_unfiltered (tmp_error_stream
,
2875 "Cannot insert breakpoint %d: %s\n",
2890 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2891 /* NOTE drow/2003-09-08: This state only exists for removing
2892 watchpoints. It's not clear that it's necessary... */
2893 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2897 gdb_assert (bl
->owner
->ops
!= NULL
2898 && bl
->owner
->ops
->insert_location
!= NULL
);
2900 val
= bl
->owner
->ops
->insert_location (bl
);
2902 /* If trying to set a read-watchpoint, and it turns out it's not
2903 supported, try emulating one with an access watchpoint. */
2904 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2906 struct bp_location
*loc
, **loc_temp
;
2908 /* But don't try to insert it, if there's already another
2909 hw_access location that would be considered a duplicate
2911 ALL_BP_LOCATIONS (loc
, loc_temp
)
2913 && loc
->watchpoint_type
== hw_access
2914 && watchpoint_locations_match (bl
, loc
))
2918 bl
->target_info
= loc
->target_info
;
2919 bl
->watchpoint_type
= hw_access
;
2926 bl
->watchpoint_type
= hw_access
;
2927 val
= bl
->owner
->ops
->insert_location (bl
);
2930 /* Back to the original value. */
2931 bl
->watchpoint_type
= hw_read
;
2935 bl
->inserted
= (val
== 0);
2938 else if (bl
->owner
->type
== bp_catchpoint
)
2942 gdb_assert (bl
->owner
->ops
!= NULL
2943 && bl
->owner
->ops
->insert_location
!= NULL
);
2945 val
= bl
->owner
->ops
->insert_location (bl
);
2948 bl
->owner
->enable_state
= bp_disabled
;
2952 Error inserting catchpoint %d: Your system does not support this type\n\
2953 of catchpoint."), bl
->owner
->number
);
2955 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2958 bl
->inserted
= (val
== 0);
2960 /* We've already printed an error message if there was a problem
2961 inserting this catchpoint, and we've disabled the catchpoint,
2962 so just return success. */
2969 /* This function is called when program space PSPACE is about to be
2970 deleted. It takes care of updating breakpoints to not reference
2974 breakpoint_program_space_exit (struct program_space
*pspace
)
2976 struct breakpoint
*b
, *b_temp
;
2977 struct bp_location
*loc
, **loc_temp
;
2979 /* Remove any breakpoint that was set through this program space. */
2980 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2982 if (b
->pspace
== pspace
)
2983 delete_breakpoint (b
);
2986 /* Breakpoints set through other program spaces could have locations
2987 bound to PSPACE as well. Remove those. */
2988 ALL_BP_LOCATIONS (loc
, loc_temp
)
2990 struct bp_location
*tmp
;
2992 if (loc
->pspace
== pspace
)
2994 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2995 if (loc
->owner
->loc
== loc
)
2996 loc
->owner
->loc
= loc
->next
;
2998 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2999 if (tmp
->next
== loc
)
3001 tmp
->next
= loc
->next
;
3007 /* Now update the global location list to permanently delete the
3008 removed locations above. */
3009 update_global_location_list (UGLL_DONT_INSERT
);
3012 /* Make sure all breakpoints are inserted in inferior.
3013 Throws exception on any error.
3014 A breakpoint that is already inserted won't be inserted
3015 again, so calling this function twice is safe. */
3017 insert_breakpoints (void)
3019 struct breakpoint
*bpt
;
3021 ALL_BREAKPOINTS (bpt
)
3022 if (is_hardware_watchpoint (bpt
))
3024 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3026 update_watchpoint (w
, 0 /* don't reparse. */);
3029 /* Updating watchpoints creates new locations, so update the global
3030 location list. Explicitly tell ugll to insert locations and
3031 ignore breakpoints_always_inserted_mode. */
3032 update_global_location_list (UGLL_INSERT
);
3035 /* Invoke CALLBACK for each of bp_location. */
3038 iterate_over_bp_locations (walk_bp_location_callback callback
)
3040 struct bp_location
*loc
, **loc_tmp
;
3042 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3044 callback (loc
, NULL
);
3048 /* This is used when we need to synch breakpoint conditions between GDB and the
3049 target. It is the case with deleting and disabling of breakpoints when using
3050 always-inserted mode. */
3053 update_inserted_breakpoint_locations (void)
3055 struct bp_location
*bl
, **blp_tmp
;
3058 int disabled_breaks
= 0;
3059 int hw_breakpoint_error
= 0;
3060 int hw_bp_details_reported
= 0;
3062 string_file tmp_error_stream
;
3064 /* Explicitly mark the warning -- this will only be printed if
3065 there was an error. */
3066 tmp_error_stream
.puts ("Warning:\n");
3068 struct cleanup
*cleanups
= save_current_space_and_thread ();
3070 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3072 /* We only want to update software breakpoints and hardware
3074 if (!is_breakpoint (bl
->owner
))
3077 /* We only want to update locations that are already inserted
3078 and need updating. This is to avoid unwanted insertion during
3079 deletion of breakpoints. */
3080 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3083 switch_to_program_space_and_thread (bl
->pspace
);
3085 /* For targets that support global breakpoints, there's no need
3086 to select an inferior to insert breakpoint to. In fact, even
3087 if we aren't attached to any process yet, we should still
3088 insert breakpoints. */
3089 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3090 && ptid_equal (inferior_ptid
, null_ptid
))
3093 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3094 &hw_breakpoint_error
, &hw_bp_details_reported
);
3101 target_terminal_ours_for_output ();
3102 error_stream (tmp_error_stream
);
3105 do_cleanups (cleanups
);
3108 /* Used when starting or continuing the program. */
3111 insert_breakpoint_locations (void)
3113 struct breakpoint
*bpt
;
3114 struct bp_location
*bl
, **blp_tmp
;
3117 int disabled_breaks
= 0;
3118 int hw_breakpoint_error
= 0;
3119 int hw_bp_error_explained_already
= 0;
3121 string_file tmp_error_stream
;
3123 /* Explicitly mark the warning -- this will only be printed if
3124 there was an error. */
3125 tmp_error_stream
.puts ("Warning:\n");
3127 struct cleanup
*cleanups
= save_current_space_and_thread ();
3129 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3131 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3134 /* There is no point inserting thread-specific breakpoints if
3135 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3136 has BL->OWNER always non-NULL. */
3137 if (bl
->owner
->thread
!= -1
3138 && !valid_global_thread_id (bl
->owner
->thread
))
3141 switch_to_program_space_and_thread (bl
->pspace
);
3143 /* For targets that support global breakpoints, there's no need
3144 to select an inferior to insert breakpoint to. In fact, even
3145 if we aren't attached to any process yet, we should still
3146 insert breakpoints. */
3147 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3148 && ptid_equal (inferior_ptid
, null_ptid
))
3151 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3152 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3157 /* If we failed to insert all locations of a watchpoint, remove
3158 them, as half-inserted watchpoint is of limited use. */
3159 ALL_BREAKPOINTS (bpt
)
3161 int some_failed
= 0;
3162 struct bp_location
*loc
;
3164 if (!is_hardware_watchpoint (bpt
))
3167 if (!breakpoint_enabled (bpt
))
3170 if (bpt
->disposition
== disp_del_at_next_stop
)
3173 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3174 if (!loc
->inserted
&& should_be_inserted (loc
))
3181 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3183 remove_breakpoint (loc
);
3185 hw_breakpoint_error
= 1;
3186 tmp_error_stream
.printf ("Could not insert "
3187 "hardware watchpoint %d.\n",
3195 /* If a hardware breakpoint or watchpoint was inserted, add a
3196 message about possibly exhausted resources. */
3197 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3199 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3200 You may have requested too many hardware breakpoints/watchpoints.\n");
3202 target_terminal_ours_for_output ();
3203 error_stream (tmp_error_stream
);
3206 do_cleanups (cleanups
);
3209 /* Used when the program stops.
3210 Returns zero if successful, or non-zero if there was a problem
3211 removing a breakpoint location. */
3214 remove_breakpoints (void)
3216 struct bp_location
*bl
, **blp_tmp
;
3219 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3221 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3222 val
|= remove_breakpoint (bl
);
3227 /* When a thread exits, remove breakpoints that are related to
3231 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3233 struct breakpoint
*b
, *b_tmp
;
3235 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3237 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3239 b
->disposition
= disp_del_at_next_stop
;
3241 printf_filtered (_("\
3242 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3243 b
->number
, print_thread_id (tp
));
3245 /* Hide it from the user. */
3251 /* Remove breakpoints of process PID. */
3254 remove_breakpoints_pid (int pid
)
3256 struct bp_location
*bl
, **blp_tmp
;
3258 struct inferior
*inf
= find_inferior_pid (pid
);
3260 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3262 if (bl
->pspace
!= inf
->pspace
)
3265 if (bl
->inserted
&& !bl
->target_info
.persist
)
3267 val
= remove_breakpoint (bl
);
3276 reattach_breakpoints (int pid
)
3278 struct cleanup
*old_chain
;
3279 struct bp_location
*bl
, **blp_tmp
;
3281 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3282 struct inferior
*inf
;
3283 struct thread_info
*tp
;
3285 tp
= any_live_thread_of_process (pid
);
3289 inf
= find_inferior_pid (pid
);
3290 old_chain
= save_inferior_ptid ();
3292 inferior_ptid
= tp
->ptid
;
3294 string_file tmp_error_stream
;
3296 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3298 if (bl
->pspace
!= inf
->pspace
)
3304 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3307 do_cleanups (old_chain
);
3312 do_cleanups (old_chain
);
3316 static int internal_breakpoint_number
= -1;
3318 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3319 If INTERNAL is non-zero, the breakpoint number will be populated
3320 from internal_breakpoint_number and that variable decremented.
3321 Otherwise the breakpoint number will be populated from
3322 breakpoint_count and that value incremented. Internal breakpoints
3323 do not set the internal var bpnum. */
3325 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3328 b
->number
= internal_breakpoint_number
--;
3331 set_breakpoint_count (breakpoint_count
+ 1);
3332 b
->number
= breakpoint_count
;
3336 static struct breakpoint
*
3337 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3338 CORE_ADDR address
, enum bptype type
,
3339 const struct breakpoint_ops
*ops
)
3341 struct symtab_and_line sal
;
3342 struct breakpoint
*b
;
3344 init_sal (&sal
); /* Initialize to zeroes. */
3347 sal
.section
= find_pc_overlay (sal
.pc
);
3348 sal
.pspace
= current_program_space
;
3350 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3351 b
->number
= internal_breakpoint_number
--;
3352 b
->disposition
= disp_donttouch
;
3357 static const char *const longjmp_names
[] =
3359 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3361 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3363 /* Per-objfile data private to breakpoint.c. */
3364 struct breakpoint_objfile_data
3366 /* Minimal symbol for "_ovly_debug_event" (if any). */
3367 struct bound_minimal_symbol overlay_msym
;
3369 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3370 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3372 /* True if we have looked for longjmp probes. */
3373 int longjmp_searched
;
3375 /* SystemTap probe points for longjmp (if any). */
3376 VEC (probe_p
) *longjmp_probes
;
3378 /* Minimal symbol for "std::terminate()" (if any). */
3379 struct bound_minimal_symbol terminate_msym
;
3381 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3382 struct bound_minimal_symbol exception_msym
;
3384 /* True if we have looked for exception probes. */
3385 int exception_searched
;
3387 /* SystemTap probe points for unwinding (if any). */
3388 VEC (probe_p
) *exception_probes
;
3391 static const struct objfile_data
*breakpoint_objfile_key
;
3393 /* Minimal symbol not found sentinel. */
3394 static struct minimal_symbol msym_not_found
;
3396 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3399 msym_not_found_p (const struct minimal_symbol
*msym
)
3401 return msym
== &msym_not_found
;
3404 /* Return per-objfile data needed by breakpoint.c.
3405 Allocate the data if necessary. */
3407 static struct breakpoint_objfile_data
*
3408 get_breakpoint_objfile_data (struct objfile
*objfile
)
3410 struct breakpoint_objfile_data
*bp_objfile_data
;
3412 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3413 objfile_data (objfile
, breakpoint_objfile_key
));
3414 if (bp_objfile_data
== NULL
)
3417 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3419 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3420 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3422 return bp_objfile_data
;
3426 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3428 struct breakpoint_objfile_data
*bp_objfile_data
3429 = (struct breakpoint_objfile_data
*) data
;
3431 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3432 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3436 create_overlay_event_breakpoint (void)
3438 struct objfile
*objfile
;
3439 const char *const func_name
= "_ovly_debug_event";
3441 ALL_OBJFILES (objfile
)
3443 struct breakpoint
*b
;
3444 struct breakpoint_objfile_data
*bp_objfile_data
;
3446 struct explicit_location explicit_loc
;
3448 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3450 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3453 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3455 struct bound_minimal_symbol m
;
3457 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3458 if (m
.minsym
== NULL
)
3460 /* Avoid future lookups in this objfile. */
3461 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3464 bp_objfile_data
->overlay_msym
= m
;
3467 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3468 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3470 &internal_breakpoint_ops
);
3471 initialize_explicit_location (&explicit_loc
);
3472 explicit_loc
.function_name
= ASTRDUP (func_name
);
3473 b
->location
= new_explicit_location (&explicit_loc
);
3475 if (overlay_debugging
== ovly_auto
)
3477 b
->enable_state
= bp_enabled
;
3478 overlay_events_enabled
= 1;
3482 b
->enable_state
= bp_disabled
;
3483 overlay_events_enabled
= 0;
3489 create_longjmp_master_breakpoint (void)
3491 struct program_space
*pspace
;
3492 struct cleanup
*old_chain
;
3494 old_chain
= save_current_program_space ();
3496 ALL_PSPACES (pspace
)
3498 struct objfile
*objfile
;
3500 set_current_program_space (pspace
);
3502 ALL_OBJFILES (objfile
)
3505 struct gdbarch
*gdbarch
;
3506 struct breakpoint_objfile_data
*bp_objfile_data
;
3508 gdbarch
= get_objfile_arch (objfile
);
3510 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3512 if (!bp_objfile_data
->longjmp_searched
)
3516 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3519 /* We are only interested in checking one element. */
3520 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3522 if (!can_evaluate_probe_arguments (p
))
3524 /* We cannot use the probe interface here, because it does
3525 not know how to evaluate arguments. */
3526 VEC_free (probe_p
, ret
);
3530 bp_objfile_data
->longjmp_probes
= ret
;
3531 bp_objfile_data
->longjmp_searched
= 1;
3534 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3537 struct probe
*probe
;
3538 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3541 VEC_iterate (probe_p
,
3542 bp_objfile_data
->longjmp_probes
,
3546 struct breakpoint
*b
;
3548 b
= create_internal_breakpoint (gdbarch
,
3549 get_probe_address (probe
,
3552 &internal_breakpoint_ops
);
3553 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3554 b
->enable_state
= bp_disabled
;
3560 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3563 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3565 struct breakpoint
*b
;
3566 const char *func_name
;
3568 struct explicit_location explicit_loc
;
3570 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3573 func_name
= longjmp_names
[i
];
3574 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3576 struct bound_minimal_symbol m
;
3578 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3579 if (m
.minsym
== NULL
)
3581 /* Prevent future lookups in this objfile. */
3582 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3585 bp_objfile_data
->longjmp_msym
[i
] = m
;
3588 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3589 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3590 &internal_breakpoint_ops
);
3591 initialize_explicit_location (&explicit_loc
);
3592 explicit_loc
.function_name
= ASTRDUP (func_name
);
3593 b
->location
= new_explicit_location (&explicit_loc
);
3594 b
->enable_state
= bp_disabled
;
3599 do_cleanups (old_chain
);
3602 /* Create a master std::terminate breakpoint. */
3604 create_std_terminate_master_breakpoint (void)
3606 struct program_space
*pspace
;
3607 struct cleanup
*old_chain
;
3608 const char *const func_name
= "std::terminate()";
3610 old_chain
= save_current_program_space ();
3612 ALL_PSPACES (pspace
)
3614 struct objfile
*objfile
;
3617 set_current_program_space (pspace
);
3619 ALL_OBJFILES (objfile
)
3621 struct breakpoint
*b
;
3622 struct breakpoint_objfile_data
*bp_objfile_data
;
3623 struct explicit_location explicit_loc
;
3625 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3627 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3630 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3632 struct bound_minimal_symbol m
;
3634 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3635 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3636 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3638 /* Prevent future lookups in this objfile. */
3639 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3642 bp_objfile_data
->terminate_msym
= m
;
3645 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3646 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3647 bp_std_terminate_master
,
3648 &internal_breakpoint_ops
);
3649 initialize_explicit_location (&explicit_loc
);
3650 explicit_loc
.function_name
= ASTRDUP (func_name
);
3651 b
->location
= new_explicit_location (&explicit_loc
);
3652 b
->enable_state
= bp_disabled
;
3656 do_cleanups (old_chain
);
3659 /* Install a master breakpoint on the unwinder's debug hook. */
3662 create_exception_master_breakpoint (void)
3664 struct objfile
*objfile
;
3665 const char *const func_name
= "_Unwind_DebugHook";
3667 ALL_OBJFILES (objfile
)
3669 struct breakpoint
*b
;
3670 struct gdbarch
*gdbarch
;
3671 struct breakpoint_objfile_data
*bp_objfile_data
;
3673 struct explicit_location explicit_loc
;
3675 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3677 /* We prefer the SystemTap probe point if it exists. */
3678 if (!bp_objfile_data
->exception_searched
)
3682 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3686 /* We are only interested in checking one element. */
3687 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3689 if (!can_evaluate_probe_arguments (p
))
3691 /* We cannot use the probe interface here, because it does
3692 not know how to evaluate arguments. */
3693 VEC_free (probe_p
, ret
);
3697 bp_objfile_data
->exception_probes
= ret
;
3698 bp_objfile_data
->exception_searched
= 1;
3701 if (bp_objfile_data
->exception_probes
!= NULL
)
3703 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3705 struct probe
*probe
;
3708 VEC_iterate (probe_p
,
3709 bp_objfile_data
->exception_probes
,
3713 struct breakpoint
*b
;
3715 b
= create_internal_breakpoint (gdbarch
,
3716 get_probe_address (probe
,
3718 bp_exception_master
,
3719 &internal_breakpoint_ops
);
3720 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3721 b
->enable_state
= bp_disabled
;
3727 /* Otherwise, try the hook function. */
3729 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3732 gdbarch
= get_objfile_arch (objfile
);
3734 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3736 struct bound_minimal_symbol debug_hook
;
3738 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3739 if (debug_hook
.minsym
== NULL
)
3741 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3745 bp_objfile_data
->exception_msym
= debug_hook
;
3748 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3749 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3751 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3752 &internal_breakpoint_ops
);
3753 initialize_explicit_location (&explicit_loc
);
3754 explicit_loc
.function_name
= ASTRDUP (func_name
);
3755 b
->location
= new_explicit_location (&explicit_loc
);
3756 b
->enable_state
= bp_disabled
;
3760 /* Does B have a location spec? */
3763 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3765 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3769 update_breakpoints_after_exec (void)
3771 struct breakpoint
*b
, *b_tmp
;
3772 struct bp_location
*bploc
, **bplocp_tmp
;
3774 /* We're about to delete breakpoints from GDB's lists. If the
3775 INSERTED flag is true, GDB will try to lift the breakpoints by
3776 writing the breakpoints' "shadow contents" back into memory. The
3777 "shadow contents" are NOT valid after an exec, so GDB should not
3778 do that. Instead, the target is responsible from marking
3779 breakpoints out as soon as it detects an exec. We don't do that
3780 here instead, because there may be other attempts to delete
3781 breakpoints after detecting an exec and before reaching here. */
3782 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3783 if (bploc
->pspace
== current_program_space
)
3784 gdb_assert (!bploc
->inserted
);
3786 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3788 if (b
->pspace
!= current_program_space
)
3791 /* Solib breakpoints must be explicitly reset after an exec(). */
3792 if (b
->type
== bp_shlib_event
)
3794 delete_breakpoint (b
);
3798 /* JIT breakpoints must be explicitly reset after an exec(). */
3799 if (b
->type
== bp_jit_event
)
3801 delete_breakpoint (b
);
3805 /* Thread event breakpoints must be set anew after an exec(),
3806 as must overlay event and longjmp master breakpoints. */
3807 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3808 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3809 || b
->type
== bp_exception_master
)
3811 delete_breakpoint (b
);
3815 /* Step-resume breakpoints are meaningless after an exec(). */
3816 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3818 delete_breakpoint (b
);
3822 /* Just like single-step breakpoints. */
3823 if (b
->type
== bp_single_step
)
3825 delete_breakpoint (b
);
3829 /* Longjmp and longjmp-resume breakpoints are also meaningless
3831 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3832 || b
->type
== bp_longjmp_call_dummy
3833 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3835 delete_breakpoint (b
);
3839 if (b
->type
== bp_catchpoint
)
3841 /* For now, none of the bp_catchpoint breakpoints need to
3842 do anything at this point. In the future, if some of
3843 the catchpoints need to something, we will need to add
3844 a new method, and call this method from here. */
3848 /* bp_finish is a special case. The only way we ought to be able
3849 to see one of these when an exec() has happened, is if the user
3850 caught a vfork, and then said "finish". Ordinarily a finish just
3851 carries them to the call-site of the current callee, by setting
3852 a temporary bp there and resuming. But in this case, the finish
3853 will carry them entirely through the vfork & exec.
3855 We don't want to allow a bp_finish to remain inserted now. But
3856 we can't safely delete it, 'cause finish_command has a handle to
3857 the bp on a bpstat, and will later want to delete it. There's a
3858 chance (and I've seen it happen) that if we delete the bp_finish
3859 here, that its storage will get reused by the time finish_command
3860 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3861 We really must allow finish_command to delete a bp_finish.
3863 In the absence of a general solution for the "how do we know
3864 it's safe to delete something others may have handles to?"
3865 problem, what we'll do here is just uninsert the bp_finish, and
3866 let finish_command delete it.
3868 (We know the bp_finish is "doomed" in the sense that it's
3869 momentary, and will be deleted as soon as finish_command sees
3870 the inferior stopped. So it doesn't matter that the bp's
3871 address is probably bogus in the new a.out, unlike e.g., the
3872 solib breakpoints.) */
3874 if (b
->type
== bp_finish
)
3879 /* Without a symbolic address, we have little hope of the
3880 pre-exec() address meaning the same thing in the post-exec()
3882 if (breakpoint_event_location_empty_p (b
))
3884 delete_breakpoint (b
);
3891 detach_breakpoints (ptid_t ptid
)
3893 struct bp_location
*bl
, **blp_tmp
;
3895 struct cleanup
*old_chain
= save_inferior_ptid ();
3896 struct inferior
*inf
= current_inferior ();
3898 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3899 error (_("Cannot detach breakpoints of inferior_ptid"));
3901 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3902 inferior_ptid
= ptid
;
3903 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3905 if (bl
->pspace
!= inf
->pspace
)
3908 /* This function must physically remove breakpoints locations
3909 from the specified ptid, without modifying the breakpoint
3910 package's state. Locations of type bp_loc_other are only
3911 maintained at GDB side. So, there is no need to remove
3912 these bp_loc_other locations. Moreover, removing these
3913 would modify the breakpoint package's state. */
3914 if (bl
->loc_type
== bp_loc_other
)
3918 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3921 do_cleanups (old_chain
);
3925 /* Remove the breakpoint location BL from the current address space.
3926 Note that this is used to detach breakpoints from a child fork.
3927 When we get here, the child isn't in the inferior list, and neither
3928 do we have objects to represent its address space --- we should
3929 *not* look at bl->pspace->aspace here. */
3932 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3936 /* BL is never in moribund_locations by our callers. */
3937 gdb_assert (bl
->owner
!= NULL
);
3939 /* The type of none suggests that owner is actually deleted.
3940 This should not ever happen. */
3941 gdb_assert (bl
->owner
->type
!= bp_none
);
3943 if (bl
->loc_type
== bp_loc_software_breakpoint
3944 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3946 /* "Normal" instruction breakpoint: either the standard
3947 trap-instruction bp (bp_breakpoint), or a
3948 bp_hardware_breakpoint. */
3950 /* First check to see if we have to handle an overlay. */
3951 if (overlay_debugging
== ovly_off
3952 || bl
->section
== NULL
3953 || !(section_is_overlay (bl
->section
)))
3955 /* No overlay handling: just remove the breakpoint. */
3957 /* If we're trying to uninsert a memory breakpoint that we
3958 know is set in a dynamic object that is marked
3959 shlib_disabled, then either the dynamic object was
3960 removed with "remove-symbol-file" or with
3961 "nosharedlibrary". In the former case, we don't know
3962 whether another dynamic object might have loaded over the
3963 breakpoint's address -- the user might well let us know
3964 about it next with add-symbol-file (the whole point of
3965 add-symbol-file is letting the user manually maintain a
3966 list of dynamically loaded objects). If we have the
3967 breakpoint's shadow memory, that is, this is a software
3968 breakpoint managed by GDB, check whether the breakpoint
3969 is still inserted in memory, to avoid overwriting wrong
3970 code with stale saved shadow contents. Note that HW
3971 breakpoints don't have shadow memory, as they're
3972 implemented using a mechanism that is not dependent on
3973 being able to modify the target's memory, and as such
3974 they should always be removed. */
3975 if (bl
->shlib_disabled
3976 && bl
->target_info
.shadow_len
!= 0
3977 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3980 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3984 /* This breakpoint is in an overlay section.
3985 Did we set a breakpoint at the LMA? */
3986 if (!overlay_events_enabled
)
3988 /* Yes -- overlay event support is not active, so we
3989 should have set a breakpoint at the LMA. Remove it.
3991 /* Ignore any failures: if the LMA is in ROM, we will
3992 have already warned when we failed to insert it. */
3993 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3994 target_remove_hw_breakpoint (bl
->gdbarch
,
3995 &bl
->overlay_target_info
);
3997 target_remove_breakpoint (bl
->gdbarch
,
3998 &bl
->overlay_target_info
,
4001 /* Did we set a breakpoint at the VMA?
4002 If so, we will have marked the breakpoint 'inserted'. */
4005 /* Yes -- remove it. Previously we did not bother to
4006 remove the breakpoint if the section had been
4007 unmapped, but let's not rely on that being safe. We
4008 don't know what the overlay manager might do. */
4010 /* However, we should remove *software* breakpoints only
4011 if the section is still mapped, or else we overwrite
4012 wrong code with the saved shadow contents. */
4013 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4014 || section_is_mapped (bl
->section
))
4015 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4021 /* No -- not inserted, so no need to remove. No error. */
4026 /* In some cases, we might not be able to remove a breakpoint in
4027 a shared library that has already been removed, but we have
4028 not yet processed the shlib unload event. Similarly for an
4029 unloaded add-symbol-file object - the user might not yet have
4030 had the chance to remove-symbol-file it. shlib_disabled will
4031 be set if the library/object has already been removed, but
4032 the breakpoint hasn't been uninserted yet, e.g., after
4033 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4034 always-inserted mode. */
4036 && (bl
->loc_type
== bp_loc_software_breakpoint
4037 && (bl
->shlib_disabled
4038 || solib_name_from_address (bl
->pspace
, bl
->address
)
4039 || shared_objfile_contains_address_p (bl
->pspace
,
4045 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4047 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4049 gdb_assert (bl
->owner
->ops
!= NULL
4050 && bl
->owner
->ops
->remove_location
!= NULL
);
4052 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4053 bl
->owner
->ops
->remove_location (bl
, reason
);
4055 /* Failure to remove any of the hardware watchpoints comes here. */
4056 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4057 warning (_("Could not remove hardware watchpoint %d."),
4060 else if (bl
->owner
->type
== bp_catchpoint
4061 && breakpoint_enabled (bl
->owner
)
4064 gdb_assert (bl
->owner
->ops
!= NULL
4065 && bl
->owner
->ops
->remove_location
!= NULL
);
4067 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4071 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4078 remove_breakpoint (struct bp_location
*bl
)
4081 struct cleanup
*old_chain
;
4083 /* BL is never in moribund_locations by our callers. */
4084 gdb_assert (bl
->owner
!= NULL
);
4086 /* The type of none suggests that owner is actually deleted.
4087 This should not ever happen. */
4088 gdb_assert (bl
->owner
->type
!= bp_none
);
4090 old_chain
= save_current_space_and_thread ();
4092 switch_to_program_space_and_thread (bl
->pspace
);
4094 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4096 do_cleanups (old_chain
);
4100 /* Clear the "inserted" flag in all breakpoints. */
4103 mark_breakpoints_out (void)
4105 struct bp_location
*bl
, **blp_tmp
;
4107 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4108 if (bl
->pspace
== current_program_space
)
4112 /* Clear the "inserted" flag in all breakpoints and delete any
4113 breakpoints which should go away between runs of the program.
4115 Plus other such housekeeping that has to be done for breakpoints
4118 Note: this function gets called at the end of a run (by
4119 generic_mourn_inferior) and when a run begins (by
4120 init_wait_for_inferior). */
4125 breakpoint_init_inferior (enum inf_context context
)
4127 struct breakpoint
*b
, *b_tmp
;
4128 struct bp_location
*bl
;
4130 struct program_space
*pspace
= current_program_space
;
4132 /* If breakpoint locations are shared across processes, then there's
4134 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4137 mark_breakpoints_out ();
4139 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4141 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4147 case bp_longjmp_call_dummy
:
4149 /* If the call dummy breakpoint is at the entry point it will
4150 cause problems when the inferior is rerun, so we better get
4153 case bp_watchpoint_scope
:
4155 /* Also get rid of scope breakpoints. */
4157 case bp_shlib_event
:
4159 /* Also remove solib event breakpoints. Their addresses may
4160 have changed since the last time we ran the program.
4161 Actually we may now be debugging against different target;
4162 and so the solib backend that installed this breakpoint may
4163 not be used in by the target. E.g.,
4165 (gdb) file prog-linux
4166 (gdb) run # native linux target
4169 (gdb) file prog-win.exe
4170 (gdb) tar rem :9999 # remote Windows gdbserver.
4173 case bp_step_resume
:
4175 /* Also remove step-resume breakpoints. */
4177 case bp_single_step
:
4179 /* Also remove single-step breakpoints. */
4181 delete_breakpoint (b
);
4185 case bp_hardware_watchpoint
:
4186 case bp_read_watchpoint
:
4187 case bp_access_watchpoint
:
4189 struct watchpoint
*w
= (struct watchpoint
*) b
;
4191 /* Likewise for watchpoints on local expressions. */
4192 if (w
->exp_valid_block
!= NULL
)
4193 delete_breakpoint (b
);
4196 /* Get rid of existing locations, which are no longer
4197 valid. New ones will be created in
4198 update_watchpoint, when the inferior is restarted.
4199 The next update_global_location_list call will
4200 garbage collect them. */
4203 if (context
== inf_starting
)
4205 /* Reset val field to force reread of starting value in
4206 insert_breakpoints. */
4208 value_free (w
->val
);
4220 /* Get rid of the moribund locations. */
4221 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4222 decref_bp_location (&bl
);
4223 VEC_free (bp_location_p
, moribund_locations
);
4226 /* These functions concern about actual breakpoints inserted in the
4227 target --- to e.g. check if we need to do decr_pc adjustment or if
4228 we need to hop over the bkpt --- so we check for address space
4229 match, not program space. */
4231 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4232 exists at PC. It returns ordinary_breakpoint_here if it's an
4233 ordinary breakpoint, or permanent_breakpoint_here if it's a
4234 permanent breakpoint.
4235 - When continuing from a location with an ordinary breakpoint, we
4236 actually single step once before calling insert_breakpoints.
4237 - When continuing from a location with a permanent breakpoint, we
4238 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4239 the target, to advance the PC past the breakpoint. */
4241 enum breakpoint_here
4242 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4244 struct bp_location
*bl
, **blp_tmp
;
4245 int any_breakpoint_here
= 0;
4247 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4249 if (bl
->loc_type
!= bp_loc_software_breakpoint
4250 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4253 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4254 if ((breakpoint_enabled (bl
->owner
)
4256 && breakpoint_location_address_match (bl
, aspace
, pc
))
4258 if (overlay_debugging
4259 && section_is_overlay (bl
->section
)
4260 && !section_is_mapped (bl
->section
))
4261 continue; /* unmapped overlay -- can't be a match */
4262 else if (bl
->permanent
)
4263 return permanent_breakpoint_here
;
4265 any_breakpoint_here
= 1;
4269 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4272 /* See breakpoint.h. */
4275 breakpoint_in_range_p (struct address_space
*aspace
,
4276 CORE_ADDR addr
, ULONGEST len
)
4278 struct bp_location
*bl
, **blp_tmp
;
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 if ((breakpoint_enabled (bl
->owner
)
4288 && breakpoint_location_address_range_overlap (bl
, aspace
,
4291 if (overlay_debugging
4292 && section_is_overlay (bl
->section
)
4293 && !section_is_mapped (bl
->section
))
4295 /* Unmapped overlay -- can't be a match. */
4306 /* Return true if there's a moribund breakpoint at PC. */
4309 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4311 struct bp_location
*loc
;
4314 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4315 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4321 /* Returns non-zero iff BL is inserted at PC, in address space
4325 bp_location_inserted_here_p (struct bp_location
*bl
,
4326 struct address_space
*aspace
, CORE_ADDR pc
)
4329 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4332 if (overlay_debugging
4333 && section_is_overlay (bl
->section
)
4334 && !section_is_mapped (bl
->section
))
4335 return 0; /* unmapped overlay -- can't be a match */
4342 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4345 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4347 struct bp_location
**blp
, **blp_tmp
= NULL
;
4349 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4351 struct bp_location
*bl
= *blp
;
4353 if (bl
->loc_type
!= bp_loc_software_breakpoint
4354 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4357 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4363 /* This function returns non-zero iff there is a software breakpoint
4367 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4370 struct bp_location
**blp
, **blp_tmp
= NULL
;
4372 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4374 struct bp_location
*bl
= *blp
;
4376 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4379 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4386 /* See breakpoint.h. */
4389 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4392 struct bp_location
**blp
, **blp_tmp
= NULL
;
4394 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4396 struct bp_location
*bl
= *blp
;
4398 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4401 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4409 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4410 CORE_ADDR addr
, ULONGEST len
)
4412 struct breakpoint
*bpt
;
4414 ALL_BREAKPOINTS (bpt
)
4416 struct bp_location
*loc
;
4418 if (bpt
->type
!= bp_hardware_watchpoint
4419 && bpt
->type
!= bp_access_watchpoint
)
4422 if (!breakpoint_enabled (bpt
))
4425 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4426 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4430 /* Check for intersection. */
4431 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4432 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4441 /* bpstat stuff. External routines' interfaces are documented
4445 is_catchpoint (struct breakpoint
*ep
)
4447 return (ep
->type
== bp_catchpoint
);
4450 /* Frees any storage that is part of a bpstat. Does not walk the
4454 bpstat_free (bpstat bs
)
4456 if (bs
->old_val
!= NULL
)
4457 value_free (bs
->old_val
);
4458 decref_counted_command_line (&bs
->commands
);
4459 decref_bp_location (&bs
->bp_location_at
);
4463 /* Clear a bpstat so that it says we are not at any breakpoint.
4464 Also free any storage that is part of a bpstat. */
4467 bpstat_clear (bpstat
*bsp
)
4484 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4485 is part of the bpstat is copied as well. */
4488 bpstat_copy (bpstat bs
)
4492 bpstat retval
= NULL
;
4497 for (; bs
!= NULL
; bs
= bs
->next
)
4499 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4500 memcpy (tmp
, bs
, sizeof (*tmp
));
4501 incref_counted_command_line (tmp
->commands
);
4502 incref_bp_location (tmp
->bp_location_at
);
4503 if (bs
->old_val
!= NULL
)
4505 tmp
->old_val
= value_copy (bs
->old_val
);
4506 release_value (tmp
->old_val
);
4510 /* This is the first thing in the chain. */
4520 /* Find the bpstat associated with this breakpoint. */
4523 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4528 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4530 if (bsp
->breakpoint_at
== breakpoint
)
4536 /* See breakpoint.h. */
4539 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4541 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4543 if (bsp
->breakpoint_at
== NULL
)
4545 /* A moribund location can never explain a signal other than
4547 if (sig
== GDB_SIGNAL_TRAP
)
4552 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4561 /* Put in *NUM the breakpoint number of the first breakpoint we are
4562 stopped at. *BSP upon return is a bpstat which points to the
4563 remaining breakpoints stopped at (but which is not guaranteed to be
4564 good for anything but further calls to bpstat_num).
4566 Return 0 if passed a bpstat which does not indicate any breakpoints.
4567 Return -1 if stopped at a breakpoint that has been deleted since
4569 Return 1 otherwise. */
4572 bpstat_num (bpstat
*bsp
, int *num
)
4574 struct breakpoint
*b
;
4577 return 0; /* No more breakpoint values */
4579 /* We assume we'll never have several bpstats that correspond to a
4580 single breakpoint -- otherwise, this function might return the
4581 same number more than once and this will look ugly. */
4582 b
= (*bsp
)->breakpoint_at
;
4583 *bsp
= (*bsp
)->next
;
4585 return -1; /* breakpoint that's been deleted since */
4587 *num
= b
->number
; /* We have its number */
4591 /* See breakpoint.h. */
4594 bpstat_clear_actions (void)
4596 struct thread_info
*tp
;
4599 if (ptid_equal (inferior_ptid
, null_ptid
))
4602 tp
= find_thread_ptid (inferior_ptid
);
4606 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4608 decref_counted_command_line (&bs
->commands
);
4610 if (bs
->old_val
!= NULL
)
4612 value_free (bs
->old_val
);
4618 /* Called when a command is about to proceed the inferior. */
4621 breakpoint_about_to_proceed (void)
4623 if (!ptid_equal (inferior_ptid
, null_ptid
))
4625 struct thread_info
*tp
= inferior_thread ();
4627 /* Allow inferior function calls in breakpoint commands to not
4628 interrupt the command list. When the call finishes
4629 successfully, the inferior will be standing at the same
4630 breakpoint as if nothing happened. */
4631 if (tp
->control
.in_infcall
)
4635 breakpoint_proceeded
= 1;
4638 /* Stub for cleaning up our state if we error-out of a breakpoint
4641 cleanup_executing_breakpoints (void *ignore
)
4643 executing_breakpoint_commands
= 0;
4646 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4647 or its equivalent. */
4650 command_line_is_silent (struct command_line
*cmd
)
4652 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4655 /* Execute all the commands associated with all the breakpoints at
4656 this location. Any of these commands could cause the process to
4657 proceed beyond this point, etc. We look out for such changes by
4658 checking the global "breakpoint_proceeded" after each command.
4660 Returns true if a breakpoint command resumed the inferior. In that
4661 case, it is the caller's responsibility to recall it again with the
4662 bpstat of the current thread. */
4665 bpstat_do_actions_1 (bpstat
*bsp
)
4668 struct cleanup
*old_chain
;
4671 /* Avoid endless recursion if a `source' command is contained
4673 if (executing_breakpoint_commands
)
4676 executing_breakpoint_commands
= 1;
4677 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4679 scoped_restore preventer
= prevent_dont_repeat ();
4681 /* This pointer will iterate over the list of bpstat's. */
4684 breakpoint_proceeded
= 0;
4685 for (; bs
!= NULL
; bs
= bs
->next
)
4687 struct counted_command_line
*ccmd
;
4688 struct command_line
*cmd
;
4689 struct cleanup
*this_cmd_tree_chain
;
4691 /* Take ownership of the BSP's command tree, if it has one.
4693 The command tree could legitimately contain commands like
4694 'step' and 'next', which call clear_proceed_status, which
4695 frees stop_bpstat's command tree. To make sure this doesn't
4696 free the tree we're executing out from under us, we need to
4697 take ownership of the tree ourselves. Since a given bpstat's
4698 commands are only executed once, we don't need to copy it; we
4699 can clear the pointer in the bpstat, and make sure we free
4700 the tree when we're done. */
4701 ccmd
= bs
->commands
;
4702 bs
->commands
= NULL
;
4703 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4704 cmd
= ccmd
? ccmd
->commands
: NULL
;
4705 if (command_line_is_silent (cmd
))
4707 /* The action has been already done by bpstat_stop_status. */
4713 execute_control_command (cmd
);
4715 if (breakpoint_proceeded
)
4721 /* We can free this command tree now. */
4722 do_cleanups (this_cmd_tree_chain
);
4724 if (breakpoint_proceeded
)
4726 if (current_ui
->async
)
4727 /* If we are in async mode, then the target might be still
4728 running, not stopped at any breakpoint, so nothing for
4729 us to do here -- just return to the event loop. */
4732 /* In sync mode, when execute_control_command returns
4733 we're already standing on the next breakpoint.
4734 Breakpoint commands for that stop were not run, since
4735 execute_command does not run breakpoint commands --
4736 only command_line_handler does, but that one is not
4737 involved in execution of breakpoint commands. So, we
4738 can now execute breakpoint commands. It should be
4739 noted that making execute_command do bpstat actions is
4740 not an option -- in this case we'll have recursive
4741 invocation of bpstat for each breakpoint with a
4742 command, and can easily blow up GDB stack. Instead, we
4743 return true, which will trigger the caller to recall us
4744 with the new stop_bpstat. */
4749 do_cleanups (old_chain
);
4754 bpstat_do_actions (void)
4756 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4758 /* Do any commands attached to breakpoint we are stopped at. */
4759 while (!ptid_equal (inferior_ptid
, null_ptid
)
4760 && target_has_execution
4761 && !is_exited (inferior_ptid
)
4762 && !is_executing (inferior_ptid
))
4763 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4764 and only return when it is stopped at the next breakpoint, we
4765 keep doing breakpoint actions until it returns false to
4766 indicate the inferior was not resumed. */
4767 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4770 discard_cleanups (cleanup_if_error
);
4773 /* Print out the (old or new) value associated with a watchpoint. */
4776 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4779 fprintf_unfiltered (stream
, _("<unreadable>"));
4782 struct value_print_options opts
;
4783 get_user_print_options (&opts
);
4784 value_print (val
, stream
, &opts
);
4788 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4789 debugging multiple threads. */
4792 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4794 if (uiout
->is_mi_like_p ())
4799 if (show_thread_that_caused_stop ())
4802 struct thread_info
*thr
= inferior_thread ();
4804 uiout
->text ("Thread ");
4805 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4807 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4810 uiout
->text (" \"");
4811 uiout
->field_fmt ("name", "%s", name
);
4815 uiout
->text (" hit ");
4819 /* Generic routine for printing messages indicating why we
4820 stopped. The behavior of this function depends on the value
4821 'print_it' in the bpstat structure. Under some circumstances we
4822 may decide not to print anything here and delegate the task to
4825 static enum print_stop_action
4826 print_bp_stop_message (bpstat bs
)
4828 switch (bs
->print_it
)
4831 /* Nothing should be printed for this bpstat entry. */
4832 return PRINT_UNKNOWN
;
4836 /* We still want to print the frame, but we already printed the
4837 relevant messages. */
4838 return PRINT_SRC_AND_LOC
;
4841 case print_it_normal
:
4843 struct breakpoint
*b
= bs
->breakpoint_at
;
4845 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4846 which has since been deleted. */
4848 return PRINT_UNKNOWN
;
4850 /* Normal case. Call the breakpoint's print_it method. */
4851 return b
->ops
->print_it (bs
);
4856 internal_error (__FILE__
, __LINE__
,
4857 _("print_bp_stop_message: unrecognized enum value"));
4862 /* A helper function that prints a shared library stopped event. */
4865 print_solib_event (int is_catchpoint
)
4868 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4870 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4874 if (any_added
|| any_deleted
)
4875 current_uiout
->text (_("Stopped due to shared library event:\n"));
4877 current_uiout
->text (_("Stopped due to shared library event (no "
4878 "libraries added or removed)\n"));
4881 if (current_uiout
->is_mi_like_p ())
4882 current_uiout
->field_string ("reason",
4883 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4890 current_uiout
->text (_(" Inferior unloaded "));
4891 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4893 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4898 current_uiout
->text (" ");
4899 current_uiout
->field_string ("library", name
);
4900 current_uiout
->text ("\n");
4906 struct so_list
*iter
;
4909 current_uiout
->text (_(" Inferior loaded "));
4910 ui_out_emit_list
list_emitter (current_uiout
, "added");
4912 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4917 current_uiout
->text (" ");
4918 current_uiout
->field_string ("library", iter
->so_name
);
4919 current_uiout
->text ("\n");
4924 /* Print a message indicating what happened. This is called from
4925 normal_stop(). The input to this routine is the head of the bpstat
4926 list - a list of the eventpoints that caused this stop. KIND is
4927 the target_waitkind for the stopping event. This
4928 routine calls the generic print routine for printing a message
4929 about reasons for stopping. This will print (for example) the
4930 "Breakpoint n," part of the output. The return value of this
4933 PRINT_UNKNOWN: Means we printed nothing.
4934 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4935 code to print the location. An example is
4936 "Breakpoint 1, " which should be followed by
4938 PRINT_SRC_ONLY: Means we printed something, but there is no need
4939 to also print the location part of the message.
4940 An example is the catch/throw messages, which
4941 don't require a location appended to the end.
4942 PRINT_NOTHING: We have done some printing and we don't need any
4943 further info to be printed. */
4945 enum print_stop_action
4946 bpstat_print (bpstat bs
, int kind
)
4948 enum print_stop_action val
;
4950 /* Maybe another breakpoint in the chain caused us to stop.
4951 (Currently all watchpoints go on the bpstat whether hit or not.
4952 That probably could (should) be changed, provided care is taken
4953 with respect to bpstat_explains_signal). */
4954 for (; bs
; bs
= bs
->next
)
4956 val
= print_bp_stop_message (bs
);
4957 if (val
== PRINT_SRC_ONLY
4958 || val
== PRINT_SRC_AND_LOC
4959 || val
== PRINT_NOTHING
)
4963 /* If we had hit a shared library event breakpoint,
4964 print_bp_stop_message would print out this message. If we hit an
4965 OS-level shared library event, do the same thing. */
4966 if (kind
== TARGET_WAITKIND_LOADED
)
4968 print_solib_event (0);
4969 return PRINT_NOTHING
;
4972 /* We reached the end of the chain, or we got a null BS to start
4973 with and nothing was printed. */
4974 return PRINT_UNKNOWN
;
4977 /* Evaluate the expression EXP and return 1 if value is zero.
4978 This returns the inverse of the condition because it is called
4979 from catch_errors which returns 0 if an exception happened, and if an
4980 exception happens we want execution to stop.
4981 The argument is a "struct expression *" that has been cast to a
4982 "void *" to make it pass through catch_errors. */
4985 breakpoint_cond_eval (void *exp
)
4987 struct value
*mark
= value_mark ();
4988 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4990 value_free_to_mark (mark
);
4994 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4997 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5001 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5003 **bs_link_pointer
= bs
;
5004 *bs_link_pointer
= &bs
->next
;
5005 bs
->breakpoint_at
= bl
->owner
;
5006 bs
->bp_location_at
= bl
;
5007 incref_bp_location (bl
);
5008 /* If the condition is false, etc., don't do the commands. */
5009 bs
->commands
= NULL
;
5011 bs
->print_it
= print_it_normal
;
5015 /* The target has stopped with waitstatus WS. Check if any hardware
5016 watchpoints have triggered, according to the target. */
5019 watchpoints_triggered (struct target_waitstatus
*ws
)
5021 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5023 struct breakpoint
*b
;
5025 if (!stopped_by_watchpoint
)
5027 /* We were not stopped by a watchpoint. Mark all watchpoints
5028 as not triggered. */
5030 if (is_hardware_watchpoint (b
))
5032 struct watchpoint
*w
= (struct watchpoint
*) b
;
5034 w
->watchpoint_triggered
= watch_triggered_no
;
5040 if (!target_stopped_data_address (¤t_target
, &addr
))
5042 /* We were stopped by a watchpoint, but we don't know where.
5043 Mark all watchpoints as unknown. */
5045 if (is_hardware_watchpoint (b
))
5047 struct watchpoint
*w
= (struct watchpoint
*) b
;
5049 w
->watchpoint_triggered
= watch_triggered_unknown
;
5055 /* The target could report the data address. Mark watchpoints
5056 affected by this data address as triggered, and all others as not
5060 if (is_hardware_watchpoint (b
))
5062 struct watchpoint
*w
= (struct watchpoint
*) b
;
5063 struct bp_location
*loc
;
5065 w
->watchpoint_triggered
= watch_triggered_no
;
5066 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5068 if (is_masked_watchpoint (b
))
5070 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5071 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5073 if (newaddr
== start
)
5075 w
->watchpoint_triggered
= watch_triggered_yes
;
5079 /* Exact match not required. Within range is sufficient. */
5080 else if (target_watchpoint_addr_within_range (¤t_target
,
5084 w
->watchpoint_triggered
= watch_triggered_yes
;
5093 /* Possible return values for watchpoint_check (this can't be an enum
5094 because of check_errors). */
5095 /* The watchpoint has been deleted. */
5096 #define WP_DELETED 1
5097 /* The value has changed. */
5098 #define WP_VALUE_CHANGED 2
5099 /* The value has not changed. */
5100 #define WP_VALUE_NOT_CHANGED 3
5101 /* Ignore this watchpoint, no matter if the value changed or not. */
5104 #define BP_TEMPFLAG 1
5105 #define BP_HARDWAREFLAG 2
5107 /* Evaluate watchpoint condition expression and check if its value
5110 P should be a pointer to struct bpstat, but is defined as a void *
5111 in order for this function to be usable with catch_errors. */
5114 watchpoint_check (void *p
)
5116 bpstat bs
= (bpstat
) p
;
5117 struct watchpoint
*b
;
5118 struct frame_info
*fr
;
5119 int within_current_scope
;
5121 /* BS is built from an existing struct breakpoint. */
5122 gdb_assert (bs
->breakpoint_at
!= NULL
);
5123 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5125 /* If this is a local watchpoint, we only want to check if the
5126 watchpoint frame is in scope if the current thread is the thread
5127 that was used to create the watchpoint. */
5128 if (!watchpoint_in_thread_scope (b
))
5131 if (b
->exp_valid_block
== NULL
)
5132 within_current_scope
= 1;
5135 struct frame_info
*frame
= get_current_frame ();
5136 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5137 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5139 /* stack_frame_destroyed_p() returns a non-zero value if we're
5140 still in the function but the stack frame has already been
5141 invalidated. Since we can't rely on the values of local
5142 variables after the stack has been destroyed, we are treating
5143 the watchpoint in that state as `not changed' without further
5144 checking. Don't mark watchpoints as changed if the current
5145 frame is in an epilogue - even if they are in some other
5146 frame, our view of the stack is likely to be wrong and
5147 frame_find_by_id could error out. */
5148 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5151 fr
= frame_find_by_id (b
->watchpoint_frame
);
5152 within_current_scope
= (fr
!= NULL
);
5154 /* If we've gotten confused in the unwinder, we might have
5155 returned a frame that can't describe this variable. */
5156 if (within_current_scope
)
5158 struct symbol
*function
;
5160 function
= get_frame_function (fr
);
5161 if (function
== NULL
5162 || !contained_in (b
->exp_valid_block
,
5163 SYMBOL_BLOCK_VALUE (function
)))
5164 within_current_scope
= 0;
5167 if (within_current_scope
)
5168 /* If we end up stopping, the current frame will get selected
5169 in normal_stop. So this call to select_frame won't affect
5174 if (within_current_scope
)
5176 /* We use value_{,free_to_}mark because it could be a *long*
5177 time before we return to the command level and call
5178 free_all_values. We can't call free_all_values because we
5179 might be in the middle of evaluating a function call. */
5183 struct value
*new_val
;
5185 if (is_masked_watchpoint (&b
->base
))
5186 /* Since we don't know the exact trigger address (from
5187 stopped_data_address), just tell the user we've triggered
5188 a mask watchpoint. */
5189 return WP_VALUE_CHANGED
;
5191 mark
= value_mark ();
5192 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5194 if (b
->val_bitsize
!= 0)
5195 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5197 /* We use value_equal_contents instead of value_equal because
5198 the latter coerces an array to a pointer, thus comparing just
5199 the address of the array instead of its contents. This is
5200 not what we want. */
5201 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5202 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5204 if (new_val
!= NULL
)
5206 release_value (new_val
);
5207 value_free_to_mark (mark
);
5209 bs
->old_val
= b
->val
;
5212 return WP_VALUE_CHANGED
;
5216 /* Nothing changed. */
5217 value_free_to_mark (mark
);
5218 return WP_VALUE_NOT_CHANGED
;
5223 /* This seems like the only logical thing to do because
5224 if we temporarily ignored the watchpoint, then when
5225 we reenter the block in which it is valid it contains
5226 garbage (in the case of a function, it may have two
5227 garbage values, one before and one after the prologue).
5228 So we can't even detect the first assignment to it and
5229 watch after that (since the garbage may or may not equal
5230 the first value assigned). */
5231 /* We print all the stop information in
5232 breakpoint_ops->print_it, but in this case, by the time we
5233 call breakpoint_ops->print_it this bp will be deleted
5234 already. So we have no choice but print the information
5237 SWITCH_THRU_ALL_UIS ()
5239 struct ui_out
*uiout
= current_uiout
;
5241 if (uiout
->is_mi_like_p ())
5243 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5244 uiout
->text ("\nWatchpoint ");
5245 uiout
->field_int ("wpnum", b
->base
.number
);
5246 uiout
->text (" deleted because the program has left the block in\n"
5247 "which its expression is valid.\n");
5250 /* Make sure the watchpoint's commands aren't executed. */
5251 decref_counted_command_line (&b
->base
.commands
);
5252 watchpoint_del_at_next_stop (b
);
5258 /* Return true if it looks like target has stopped due to hitting
5259 breakpoint location BL. This function does not check if we should
5260 stop, only if BL explains the stop. */
5263 bpstat_check_location (const struct bp_location
*bl
,
5264 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5265 const struct target_waitstatus
*ws
)
5267 struct breakpoint
*b
= bl
->owner
;
5269 /* BL is from an existing breakpoint. */
5270 gdb_assert (b
!= NULL
);
5272 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5275 /* Determine if the watched values have actually changed, and we
5276 should stop. If not, set BS->stop to 0. */
5279 bpstat_check_watchpoint (bpstat bs
)
5281 const struct bp_location
*bl
;
5282 struct watchpoint
*b
;
5284 /* BS is built for existing struct breakpoint. */
5285 bl
= bs
->bp_location_at
;
5286 gdb_assert (bl
!= NULL
);
5287 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5288 gdb_assert (b
!= NULL
);
5291 int must_check_value
= 0;
5293 if (b
->base
.type
== bp_watchpoint
)
5294 /* For a software watchpoint, we must always check the
5296 must_check_value
= 1;
5297 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5298 /* We have a hardware watchpoint (read, write, or access)
5299 and the target earlier reported an address watched by
5301 must_check_value
= 1;
5302 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5303 && b
->base
.type
== bp_hardware_watchpoint
)
5304 /* We were stopped by a hardware watchpoint, but the target could
5305 not report the data address. We must check the watchpoint's
5306 value. Access and read watchpoints are out of luck; without
5307 a data address, we can't figure it out. */
5308 must_check_value
= 1;
5310 if (must_check_value
)
5313 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5315 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5316 int e
= catch_errors (watchpoint_check
, bs
, message
,
5318 do_cleanups (cleanups
);
5322 /* We've already printed what needs to be printed. */
5323 bs
->print_it
= print_it_done
;
5327 bs
->print_it
= print_it_noop
;
5330 case WP_VALUE_CHANGED
:
5331 if (b
->base
.type
== bp_read_watchpoint
)
5333 /* There are two cases to consider here:
5335 1. We're watching the triggered memory for reads.
5336 In that case, trust the target, and always report
5337 the watchpoint hit to the user. Even though
5338 reads don't cause value changes, the value may
5339 have changed since the last time it was read, and
5340 since we're not trapping writes, we will not see
5341 those, and as such we should ignore our notion of
5344 2. We're watching the triggered memory for both
5345 reads and writes. There are two ways this may
5348 2.1. This is a target that can't break on data
5349 reads only, but can break on accesses (reads or
5350 writes), such as e.g., x86. We detect this case
5351 at the time we try to insert read watchpoints.
5353 2.2. Otherwise, the target supports read
5354 watchpoints, but, the user set an access or write
5355 watchpoint watching the same memory as this read
5358 If we're watching memory writes as well as reads,
5359 ignore watchpoint hits when we find that the
5360 value hasn't changed, as reads don't cause
5361 changes. This still gives false positives when
5362 the program writes the same value to memory as
5363 what there was already in memory (we will confuse
5364 it for a read), but it's much better than
5367 int other_write_watchpoint
= 0;
5369 if (bl
->watchpoint_type
== hw_read
)
5371 struct breakpoint
*other_b
;
5373 ALL_BREAKPOINTS (other_b
)
5374 if (other_b
->type
== bp_hardware_watchpoint
5375 || other_b
->type
== bp_access_watchpoint
)
5377 struct watchpoint
*other_w
=
5378 (struct watchpoint
*) other_b
;
5380 if (other_w
->watchpoint_triggered
5381 == watch_triggered_yes
)
5383 other_write_watchpoint
= 1;
5389 if (other_write_watchpoint
5390 || bl
->watchpoint_type
== hw_access
)
5392 /* We're watching the same memory for writes,
5393 and the value changed since the last time we
5394 updated it, so this trap must be for a write.
5396 bs
->print_it
= print_it_noop
;
5401 case WP_VALUE_NOT_CHANGED
:
5402 if (b
->base
.type
== bp_hardware_watchpoint
5403 || b
->base
.type
== bp_watchpoint
)
5405 /* Don't stop: write watchpoints shouldn't fire if
5406 the value hasn't changed. */
5407 bs
->print_it
= print_it_noop
;
5415 /* Error from catch_errors. */
5417 SWITCH_THRU_ALL_UIS ()
5419 printf_filtered (_("Watchpoint %d deleted.\n"),
5422 watchpoint_del_at_next_stop (b
);
5423 /* We've already printed what needs to be printed. */
5424 bs
->print_it
= print_it_done
;
5429 else /* must_check_value == 0 */
5431 /* This is a case where some watchpoint(s) triggered, but
5432 not at the address of this watchpoint, or else no
5433 watchpoint triggered after all. So don't print
5434 anything for this watchpoint. */
5435 bs
->print_it
= print_it_noop
;
5441 /* For breakpoints that are currently marked as telling gdb to stop,
5442 check conditions (condition proper, frame, thread and ignore count)
5443 of breakpoint referred to by BS. If we should not stop for this
5444 breakpoint, set BS->stop to 0. */
5447 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5449 const struct bp_location
*bl
;
5450 struct breakpoint
*b
;
5451 int value_is_zero
= 0;
5452 struct expression
*cond
;
5454 gdb_assert (bs
->stop
);
5456 /* BS is built for existing struct breakpoint. */
5457 bl
= bs
->bp_location_at
;
5458 gdb_assert (bl
!= NULL
);
5459 b
= bs
->breakpoint_at
;
5460 gdb_assert (b
!= NULL
);
5462 /* Even if the target evaluated the condition on its end and notified GDB, we
5463 need to do so again since GDB does not know if we stopped due to a
5464 breakpoint or a single step breakpoint. */
5466 if (frame_id_p (b
->frame_id
)
5467 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5473 /* If this is a thread/task-specific breakpoint, don't waste cpu
5474 evaluating the condition if this isn't the specified
5476 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5477 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5484 /* Evaluate extension language breakpoints that have a "stop" method
5486 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5488 if (is_watchpoint (b
))
5490 struct watchpoint
*w
= (struct watchpoint
*) b
;
5492 cond
= w
->cond_exp
.get ();
5495 cond
= bl
->cond
.get ();
5497 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5499 int within_current_scope
= 1;
5500 struct watchpoint
* w
;
5502 /* We use value_mark and value_free_to_mark because it could
5503 be a long time before we return to the command level and
5504 call free_all_values. We can't call free_all_values
5505 because we might be in the middle of evaluating a
5507 struct value
*mark
= value_mark ();
5509 if (is_watchpoint (b
))
5510 w
= (struct watchpoint
*) b
;
5514 /* Need to select the frame, with all that implies so that
5515 the conditions will have the right context. Because we
5516 use the frame, we will not see an inlined function's
5517 variables when we arrive at a breakpoint at the start
5518 of the inlined function; the current frame will be the
5520 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5521 select_frame (get_current_frame ());
5524 struct frame_info
*frame
;
5526 /* For local watchpoint expressions, which particular
5527 instance of a local is being watched matters, so we
5528 keep track of the frame to evaluate the expression
5529 in. To evaluate the condition however, it doesn't
5530 really matter which instantiation of the function
5531 where the condition makes sense triggers the
5532 watchpoint. This allows an expression like "watch
5533 global if q > 10" set in `func', catch writes to
5534 global on all threads that call `func', or catch
5535 writes on all recursive calls of `func' by a single
5536 thread. We simply always evaluate the condition in
5537 the innermost frame that's executing where it makes
5538 sense to evaluate the condition. It seems
5540 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5542 select_frame (frame
);
5544 within_current_scope
= 0;
5546 if (within_current_scope
)
5548 = catch_errors (breakpoint_cond_eval
, cond
,
5549 "Error in testing breakpoint condition:\n",
5553 warning (_("Watchpoint condition cannot be tested "
5554 "in the current scope"));
5555 /* If we failed to set the right context for this
5556 watchpoint, unconditionally report it. */
5559 /* FIXME-someday, should give breakpoint #. */
5560 value_free_to_mark (mark
);
5563 if (cond
&& value_is_zero
)
5567 else if (b
->ignore_count
> 0)
5571 /* Increase the hit count even though we don't stop. */
5573 observer_notify_breakpoint_modified (b
);
5577 /* Returns true if we need to track moribund locations of LOC's type
5578 on the current target. */
5581 need_moribund_for_location_type (struct bp_location
*loc
)
5583 return ((loc
->loc_type
== bp_loc_software_breakpoint
5584 && !target_supports_stopped_by_sw_breakpoint ())
5585 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5586 && !target_supports_stopped_by_hw_breakpoint ()));
5590 /* Get a bpstat associated with having just stopped at address
5591 BP_ADDR in thread PTID.
5593 Determine whether we stopped at a breakpoint, etc, or whether we
5594 don't understand this stop. Result is a chain of bpstat's such
5597 if we don't understand the stop, the result is a null pointer.
5599 if we understand why we stopped, the result is not null.
5601 Each element of the chain refers to a particular breakpoint or
5602 watchpoint at which we have stopped. (We may have stopped for
5603 several reasons concurrently.)
5605 Each element of the chain has valid next, breakpoint_at,
5606 commands, FIXME??? fields. */
5609 bpstat_stop_status (struct address_space
*aspace
,
5610 CORE_ADDR bp_addr
, ptid_t ptid
,
5611 const struct target_waitstatus
*ws
)
5613 struct breakpoint
*b
= NULL
;
5614 struct bp_location
*bl
;
5615 struct bp_location
*loc
;
5616 /* First item of allocated bpstat's. */
5617 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5618 /* Pointer to the last thing in the chain currently. */
5621 int need_remove_insert
;
5624 /* First, build the bpstat chain with locations that explain a
5625 target stop, while being careful to not set the target running,
5626 as that may invalidate locations (in particular watchpoint
5627 locations are recreated). Resuming will happen here with
5628 breakpoint conditions or watchpoint expressions that include
5629 inferior function calls. */
5633 if (!breakpoint_enabled (b
))
5636 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5638 /* For hardware watchpoints, we look only at the first
5639 location. The watchpoint_check function will work on the
5640 entire expression, not the individual locations. For
5641 read watchpoints, the watchpoints_triggered function has
5642 checked all locations already. */
5643 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5646 if (!bl
->enabled
|| bl
->shlib_disabled
)
5649 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5652 /* Come here if it's a watchpoint, or if the break address
5655 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5658 /* Assume we stop. Should we find a watchpoint that is not
5659 actually triggered, or if the condition of the breakpoint
5660 evaluates as false, we'll reset 'stop' to 0. */
5664 /* If this is a scope breakpoint, mark the associated
5665 watchpoint as triggered so that we will handle the
5666 out-of-scope event. We'll get to the watchpoint next
5668 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5670 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5672 w
->watchpoint_triggered
= watch_triggered_yes
;
5677 /* Check if a moribund breakpoint explains the stop. */
5678 if (!target_supports_stopped_by_sw_breakpoint ()
5679 || !target_supports_stopped_by_hw_breakpoint ())
5681 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5683 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5684 && need_moribund_for_location_type (loc
))
5686 bs
= bpstat_alloc (loc
, &bs_link
);
5687 /* For hits of moribund locations, we should just proceed. */
5690 bs
->print_it
= print_it_noop
;
5695 /* A bit of special processing for shlib breakpoints. We need to
5696 process solib loading here, so that the lists of loaded and
5697 unloaded libraries are correct before we handle "catch load" and
5699 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5701 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5703 handle_solib_event ();
5708 /* Now go through the locations that caused the target to stop, and
5709 check whether we're interested in reporting this stop to higher
5710 layers, or whether we should resume the target transparently. */
5714 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5719 b
= bs
->breakpoint_at
;
5720 b
->ops
->check_status (bs
);
5723 bpstat_check_breakpoint_conditions (bs
, ptid
);
5728 observer_notify_breakpoint_modified (b
);
5730 /* We will stop here. */
5731 if (b
->disposition
== disp_disable
)
5733 --(b
->enable_count
);
5734 if (b
->enable_count
<= 0)
5735 b
->enable_state
= bp_disabled
;
5740 bs
->commands
= b
->commands
;
5741 incref_counted_command_line (bs
->commands
);
5742 if (command_line_is_silent (bs
->commands
5743 ? bs
->commands
->commands
: NULL
))
5746 b
->ops
->after_condition_true (bs
);
5751 /* Print nothing for this entry if we don't stop or don't
5753 if (!bs
->stop
|| !bs
->print
)
5754 bs
->print_it
= print_it_noop
;
5757 /* If we aren't stopping, the value of some hardware watchpoint may
5758 not have changed, but the intermediate memory locations we are
5759 watching may have. Don't bother if we're stopping; this will get
5761 need_remove_insert
= 0;
5762 if (! bpstat_causes_stop (bs_head
))
5763 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5765 && bs
->breakpoint_at
5766 && is_hardware_watchpoint (bs
->breakpoint_at
))
5768 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5770 update_watchpoint (w
, 0 /* don't reparse. */);
5771 need_remove_insert
= 1;
5774 if (need_remove_insert
)
5775 update_global_location_list (UGLL_MAY_INSERT
);
5776 else if (removed_any
)
5777 update_global_location_list (UGLL_DONT_INSERT
);
5783 handle_jit_event (void)
5785 struct frame_info
*frame
;
5786 struct gdbarch
*gdbarch
;
5789 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5791 /* Switch terminal for any messages produced by
5792 breakpoint_re_set. */
5793 target_terminal_ours_for_output ();
5795 frame
= get_current_frame ();
5796 gdbarch
= get_frame_arch (frame
);
5798 jit_event_handler (gdbarch
);
5800 target_terminal_inferior ();
5803 /* Prepare WHAT final decision for infrun. */
5805 /* Decide what infrun needs to do with this bpstat. */
5808 bpstat_what (bpstat bs_head
)
5810 struct bpstat_what retval
;
5813 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5814 retval
.call_dummy
= STOP_NONE
;
5815 retval
.is_longjmp
= 0;
5817 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5819 /* Extract this BS's action. After processing each BS, we check
5820 if its action overrides all we've seem so far. */
5821 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5824 if (bs
->breakpoint_at
== NULL
)
5826 /* I suspect this can happen if it was a momentary
5827 breakpoint which has since been deleted. */
5831 bptype
= bs
->breakpoint_at
->type
;
5838 case bp_hardware_breakpoint
:
5839 case bp_single_step
:
5842 case bp_shlib_event
:
5846 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5848 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5851 this_action
= BPSTAT_WHAT_SINGLE
;
5854 case bp_hardware_watchpoint
:
5855 case bp_read_watchpoint
:
5856 case bp_access_watchpoint
:
5860 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5862 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5866 /* There was a watchpoint, but we're not stopping.
5867 This requires no further action. */
5871 case bp_longjmp_call_dummy
:
5875 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5876 retval
.is_longjmp
= bptype
!= bp_exception
;
5879 this_action
= BPSTAT_WHAT_SINGLE
;
5881 case bp_longjmp_resume
:
5882 case bp_exception_resume
:
5885 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5886 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5889 this_action
= BPSTAT_WHAT_SINGLE
;
5891 case bp_step_resume
:
5893 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5896 /* It is for the wrong frame. */
5897 this_action
= BPSTAT_WHAT_SINGLE
;
5900 case bp_hp_step_resume
:
5902 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5905 /* It is for the wrong frame. */
5906 this_action
= BPSTAT_WHAT_SINGLE
;
5909 case bp_watchpoint_scope
:
5910 case bp_thread_event
:
5911 case bp_overlay_event
:
5912 case bp_longjmp_master
:
5913 case bp_std_terminate_master
:
5914 case bp_exception_master
:
5915 this_action
= BPSTAT_WHAT_SINGLE
;
5921 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5923 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5927 /* There was a catchpoint, but we're not stopping.
5928 This requires no further action. */
5932 this_action
= BPSTAT_WHAT_SINGLE
;
5935 /* Make sure the action is stop (silent or noisy),
5936 so infrun.c pops the dummy frame. */
5937 retval
.call_dummy
= STOP_STACK_DUMMY
;
5938 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5940 case bp_std_terminate
:
5941 /* Make sure the action is stop (silent or noisy),
5942 so infrun.c pops the dummy frame. */
5943 retval
.call_dummy
= STOP_STD_TERMINATE
;
5944 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5947 case bp_fast_tracepoint
:
5948 case bp_static_tracepoint
:
5949 /* Tracepoint hits should not be reported back to GDB, and
5950 if one got through somehow, it should have been filtered
5952 internal_error (__FILE__
, __LINE__
,
5953 _("bpstat_what: tracepoint encountered"));
5955 case bp_gnu_ifunc_resolver
:
5956 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5957 this_action
= BPSTAT_WHAT_SINGLE
;
5959 case bp_gnu_ifunc_resolver_return
:
5960 /* The breakpoint will be removed, execution will restart from the
5961 PC of the former breakpoint. */
5962 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5967 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5969 this_action
= BPSTAT_WHAT_SINGLE
;
5973 internal_error (__FILE__
, __LINE__
,
5974 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5977 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5984 bpstat_run_callbacks (bpstat bs_head
)
5988 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5990 struct breakpoint
*b
= bs
->breakpoint_at
;
5997 handle_jit_event ();
5999 case bp_gnu_ifunc_resolver
:
6000 gnu_ifunc_resolver_stop (b
);
6002 case bp_gnu_ifunc_resolver_return
:
6003 gnu_ifunc_resolver_return_stop (b
);
6009 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6010 without hardware support). This isn't related to a specific bpstat,
6011 just to things like whether watchpoints are set. */
6014 bpstat_should_step (void)
6016 struct breakpoint
*b
;
6019 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6025 bpstat_causes_stop (bpstat bs
)
6027 for (; bs
!= NULL
; bs
= bs
->next
)
6036 /* Compute a string of spaces suitable to indent the next line
6037 so it starts at the position corresponding to the table column
6038 named COL_NAME in the currently active table of UIOUT. */
6041 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6043 static char wrap_indent
[80];
6044 int i
, total_width
, width
, align
;
6048 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6050 if (strcmp (text
, col_name
) == 0)
6052 gdb_assert (total_width
< sizeof wrap_indent
);
6053 memset (wrap_indent
, ' ', total_width
);
6054 wrap_indent
[total_width
] = 0;
6059 total_width
+= width
+ 1;
6065 /* Determine if the locations of this breakpoint will have their conditions
6066 evaluated by the target, host or a mix of both. Returns the following:
6068 "host": Host evals condition.
6069 "host or target": Host or Target evals condition.
6070 "target": Target evals condition.
6074 bp_condition_evaluator (struct breakpoint
*b
)
6076 struct bp_location
*bl
;
6077 char host_evals
= 0;
6078 char target_evals
= 0;
6083 if (!is_breakpoint (b
))
6086 if (gdb_evaluates_breakpoint_condition_p ()
6087 || !target_supports_evaluation_of_breakpoint_conditions ())
6088 return condition_evaluation_host
;
6090 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6092 if (bl
->cond_bytecode
)
6098 if (host_evals
&& target_evals
)
6099 return condition_evaluation_both
;
6100 else if (target_evals
)
6101 return condition_evaluation_target
;
6103 return condition_evaluation_host
;
6106 /* Determine the breakpoint location's condition evaluator. This is
6107 similar to bp_condition_evaluator, but for locations. */
6110 bp_location_condition_evaluator (struct bp_location
*bl
)
6112 if (bl
&& !is_breakpoint (bl
->owner
))
6115 if (gdb_evaluates_breakpoint_condition_p ()
6116 || !target_supports_evaluation_of_breakpoint_conditions ())
6117 return condition_evaluation_host
;
6119 if (bl
&& bl
->cond_bytecode
)
6120 return condition_evaluation_target
;
6122 return condition_evaluation_host
;
6125 /* Print the LOC location out of the list of B->LOC locations. */
6128 print_breakpoint_location (struct breakpoint
*b
,
6129 struct bp_location
*loc
)
6131 struct ui_out
*uiout
= current_uiout
;
6132 struct cleanup
*old_chain
= save_current_program_space ();
6134 if (loc
!= NULL
&& loc
->shlib_disabled
)
6138 set_current_program_space (loc
->pspace
);
6140 if (b
->display_canonical
)
6141 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6142 else if (loc
&& loc
->symtab
)
6145 = find_pc_sect_function (loc
->address
, loc
->section
);
6148 uiout
->text ("in ");
6149 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6151 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6152 uiout
->text ("at ");
6154 uiout
->field_string ("file",
6155 symtab_to_filename_for_display (loc
->symtab
));
6158 if (uiout
->is_mi_like_p ())
6159 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6161 uiout
->field_int ("line", loc
->line_number
);
6167 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6169 uiout
->field_stream ("at", stb
);
6173 uiout
->field_string ("pending",
6174 event_location_to_string (b
->location
.get ()));
6175 /* If extra_string is available, it could be holding a condition
6176 or dprintf arguments. In either case, make sure it is printed,
6177 too, but only for non-MI streams. */
6178 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6180 if (b
->type
== bp_dprintf
)
6184 uiout
->text (b
->extra_string
);
6188 if (loc
&& is_breakpoint (b
)
6189 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6190 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6193 uiout
->field_string ("evaluated-by",
6194 bp_location_condition_evaluator (loc
));
6198 do_cleanups (old_chain
);
6202 bptype_string (enum bptype type
)
6204 struct ep_type_description
6207 const char *description
;
6209 static struct ep_type_description bptypes
[] =
6211 {bp_none
, "?deleted?"},
6212 {bp_breakpoint
, "breakpoint"},
6213 {bp_hardware_breakpoint
, "hw breakpoint"},
6214 {bp_single_step
, "sw single-step"},
6215 {bp_until
, "until"},
6216 {bp_finish
, "finish"},
6217 {bp_watchpoint
, "watchpoint"},
6218 {bp_hardware_watchpoint
, "hw watchpoint"},
6219 {bp_read_watchpoint
, "read watchpoint"},
6220 {bp_access_watchpoint
, "acc watchpoint"},
6221 {bp_longjmp
, "longjmp"},
6222 {bp_longjmp_resume
, "longjmp resume"},
6223 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6224 {bp_exception
, "exception"},
6225 {bp_exception_resume
, "exception resume"},
6226 {bp_step_resume
, "step resume"},
6227 {bp_hp_step_resume
, "high-priority step resume"},
6228 {bp_watchpoint_scope
, "watchpoint scope"},
6229 {bp_call_dummy
, "call dummy"},
6230 {bp_std_terminate
, "std::terminate"},
6231 {bp_shlib_event
, "shlib events"},
6232 {bp_thread_event
, "thread events"},
6233 {bp_overlay_event
, "overlay events"},
6234 {bp_longjmp_master
, "longjmp master"},
6235 {bp_std_terminate_master
, "std::terminate master"},
6236 {bp_exception_master
, "exception master"},
6237 {bp_catchpoint
, "catchpoint"},
6238 {bp_tracepoint
, "tracepoint"},
6239 {bp_fast_tracepoint
, "fast tracepoint"},
6240 {bp_static_tracepoint
, "static tracepoint"},
6241 {bp_dprintf
, "dprintf"},
6242 {bp_jit_event
, "jit events"},
6243 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6244 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6247 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6248 || ((int) type
!= bptypes
[(int) type
].type
))
6249 internal_error (__FILE__
, __LINE__
,
6250 _("bptypes table does not describe type #%d."),
6253 return bptypes
[(int) type
].description
;
6256 /* For MI, output a field named 'thread-groups' with a list as the value.
6257 For CLI, prefix the list with the string 'inf'. */
6260 output_thread_groups (struct ui_out
*uiout
,
6261 const char *field_name
,
6265 int is_mi
= uiout
->is_mi_like_p ();
6269 /* For backward compatibility, don't display inferiors in CLI unless
6270 there are several. Always display them for MI. */
6271 if (!is_mi
&& mi_only
)
6274 ui_out_emit_list
list_emitter (uiout
, field_name
);
6276 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6282 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6283 uiout
->field_string (NULL
, mi_group
);
6288 uiout
->text (" inf ");
6292 uiout
->text (plongest (inf
));
6297 /* Print B to gdb_stdout. */
6300 print_one_breakpoint_location (struct breakpoint
*b
,
6301 struct bp_location
*loc
,
6303 struct bp_location
**last_loc
,
6306 struct command_line
*l
;
6307 static char bpenables
[] = "nynny";
6309 struct ui_out
*uiout
= current_uiout
;
6310 int header_of_multiple
= 0;
6311 int part_of_multiple
= (loc
!= NULL
);
6312 struct value_print_options opts
;
6314 get_user_print_options (&opts
);
6316 gdb_assert (!loc
|| loc_number
!= 0);
6317 /* See comment in print_one_breakpoint concerning treatment of
6318 breakpoints with single disabled location. */
6321 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6322 header_of_multiple
= 1;
6330 if (part_of_multiple
)
6333 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6334 uiout
->field_string ("number", formatted
);
6339 uiout
->field_int ("number", b
->number
);
6344 if (part_of_multiple
)
6345 uiout
->field_skip ("type");
6347 uiout
->field_string ("type", bptype_string (b
->type
));
6351 if (part_of_multiple
)
6352 uiout
->field_skip ("disp");
6354 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6359 if (part_of_multiple
)
6360 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6362 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6367 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6369 /* Although the print_one can possibly print all locations,
6370 calling it here is not likely to get any nice result. So,
6371 make sure there's just one location. */
6372 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6373 b
->ops
->print_one (b
, last_loc
);
6379 internal_error (__FILE__
, __LINE__
,
6380 _("print_one_breakpoint: bp_none encountered\n"));
6384 case bp_hardware_watchpoint
:
6385 case bp_read_watchpoint
:
6386 case bp_access_watchpoint
:
6388 struct watchpoint
*w
= (struct watchpoint
*) b
;
6390 /* Field 4, the address, is omitted (which makes the columns
6391 not line up too nicely with the headers, but the effect
6392 is relatively readable). */
6393 if (opts
.addressprint
)
6394 uiout
->field_skip ("addr");
6396 uiout
->field_string ("what", w
->exp_string
);
6401 case bp_hardware_breakpoint
:
6402 case bp_single_step
:
6406 case bp_longjmp_resume
:
6407 case bp_longjmp_call_dummy
:
6409 case bp_exception_resume
:
6410 case bp_step_resume
:
6411 case bp_hp_step_resume
:
6412 case bp_watchpoint_scope
:
6414 case bp_std_terminate
:
6415 case bp_shlib_event
:
6416 case bp_thread_event
:
6417 case bp_overlay_event
:
6418 case bp_longjmp_master
:
6419 case bp_std_terminate_master
:
6420 case bp_exception_master
:
6422 case bp_fast_tracepoint
:
6423 case bp_static_tracepoint
:
6426 case bp_gnu_ifunc_resolver
:
6427 case bp_gnu_ifunc_resolver_return
:
6428 if (opts
.addressprint
)
6431 if (header_of_multiple
)
6432 uiout
->field_string ("addr", "<MULTIPLE>");
6433 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6434 uiout
->field_string ("addr", "<PENDING>");
6436 uiout
->field_core_addr ("addr",
6437 loc
->gdbarch
, loc
->address
);
6440 if (!header_of_multiple
)
6441 print_breakpoint_location (b
, loc
);
6448 if (loc
!= NULL
&& !header_of_multiple
)
6450 struct inferior
*inf
;
6451 VEC(int) *inf_num
= NULL
;
6456 if (inf
->pspace
== loc
->pspace
)
6457 VEC_safe_push (int, inf_num
, inf
->num
);
6460 /* For backward compatibility, don't display inferiors in CLI unless
6461 there are several. Always display for MI. */
6463 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6464 && (number_of_program_spaces () > 1
6465 || number_of_inferiors () > 1)
6466 /* LOC is for existing B, it cannot be in
6467 moribund_locations and thus having NULL OWNER. */
6468 && loc
->owner
->type
!= bp_catchpoint
))
6470 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6471 VEC_free (int, inf_num
);
6474 if (!part_of_multiple
)
6476 if (b
->thread
!= -1)
6478 /* FIXME: This seems to be redundant and lost here; see the
6479 "stop only in" line a little further down. */
6480 uiout
->text (" thread ");
6481 uiout
->field_int ("thread", b
->thread
);
6483 else if (b
->task
!= 0)
6485 uiout
->text (" task ");
6486 uiout
->field_int ("task", b
->task
);
6492 if (!part_of_multiple
)
6493 b
->ops
->print_one_detail (b
, uiout
);
6495 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6498 uiout
->text ("\tstop only in stack frame at ");
6499 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6501 uiout
->field_core_addr ("frame",
6502 b
->gdbarch
, b
->frame_id
.stack_addr
);
6506 if (!part_of_multiple
&& b
->cond_string
)
6509 if (is_tracepoint (b
))
6510 uiout
->text ("\ttrace only if ");
6512 uiout
->text ("\tstop only if ");
6513 uiout
->field_string ("cond", b
->cond_string
);
6515 /* Print whether the target is doing the breakpoint's condition
6516 evaluation. If GDB is doing the evaluation, don't print anything. */
6517 if (is_breakpoint (b
)
6518 && breakpoint_condition_evaluation_mode ()
6519 == condition_evaluation_target
)
6522 uiout
->field_string ("evaluated-by",
6523 bp_condition_evaluator (b
));
6524 uiout
->text (" evals)");
6529 if (!part_of_multiple
&& b
->thread
!= -1)
6531 /* FIXME should make an annotation for this. */
6532 uiout
->text ("\tstop only in thread ");
6533 if (uiout
->is_mi_like_p ())
6534 uiout
->field_int ("thread", b
->thread
);
6537 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6539 uiout
->field_string ("thread", print_thread_id (thr
));
6544 if (!part_of_multiple
)
6548 /* FIXME should make an annotation for this. */
6549 if (is_catchpoint (b
))
6550 uiout
->text ("\tcatchpoint");
6551 else if (is_tracepoint (b
))
6552 uiout
->text ("\ttracepoint");
6554 uiout
->text ("\tbreakpoint");
6555 uiout
->text (" already hit ");
6556 uiout
->field_int ("times", b
->hit_count
);
6557 if (b
->hit_count
== 1)
6558 uiout
->text (" time\n");
6560 uiout
->text (" times\n");
6564 /* Output the count also if it is zero, but only if this is mi. */
6565 if (uiout
->is_mi_like_p ())
6566 uiout
->field_int ("times", b
->hit_count
);
6570 if (!part_of_multiple
&& b
->ignore_count
)
6573 uiout
->text ("\tignore next ");
6574 uiout
->field_int ("ignore", b
->ignore_count
);
6575 uiout
->text (" hits\n");
6578 /* Note that an enable count of 1 corresponds to "enable once"
6579 behavior, which is reported by the combination of enablement and
6580 disposition, so we don't need to mention it here. */
6581 if (!part_of_multiple
&& b
->enable_count
> 1)
6584 uiout
->text ("\tdisable after ");
6585 /* Tweak the wording to clarify that ignore and enable counts
6586 are distinct, and have additive effect. */
6587 if (b
->ignore_count
)
6588 uiout
->text ("additional ");
6590 uiout
->text ("next ");
6591 uiout
->field_int ("enable", b
->enable_count
);
6592 uiout
->text (" hits\n");
6595 if (!part_of_multiple
&& is_tracepoint (b
))
6597 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6599 if (tp
->traceframe_usage
)
6601 uiout
->text ("\ttrace buffer usage ");
6602 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6603 uiout
->text (" bytes\n");
6607 l
= b
->commands
? b
->commands
->commands
: NULL
;
6608 if (!part_of_multiple
&& l
)
6611 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6612 print_command_lines (uiout
, l
, 4);
6615 if (is_tracepoint (b
))
6617 struct tracepoint
*t
= (struct tracepoint
*) b
;
6619 if (!part_of_multiple
&& t
->pass_count
)
6621 annotate_field (10);
6622 uiout
->text ("\tpass count ");
6623 uiout
->field_int ("pass", t
->pass_count
);
6624 uiout
->text (" \n");
6627 /* Don't display it when tracepoint or tracepoint location is
6629 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6631 annotate_field (11);
6633 if (uiout
->is_mi_like_p ())
6634 uiout
->field_string ("installed",
6635 loc
->inserted
? "y" : "n");
6641 uiout
->text ("\tnot ");
6642 uiout
->text ("installed on target\n");
6647 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6649 if (is_watchpoint (b
))
6651 struct watchpoint
*w
= (struct watchpoint
*) b
;
6653 uiout
->field_string ("original-location", w
->exp_string
);
6655 else if (b
->location
!= NULL
6656 && event_location_to_string (b
->location
.get ()) != NULL
)
6657 uiout
->field_string ("original-location",
6658 event_location_to_string (b
->location
.get ()));
6663 print_one_breakpoint (struct breakpoint
*b
,
6664 struct bp_location
**last_loc
,
6667 struct ui_out
*uiout
= current_uiout
;
6670 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6672 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6675 /* If this breakpoint has custom print function,
6676 it's already printed. Otherwise, print individual
6677 locations, if any. */
6678 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6680 /* If breakpoint has a single location that is disabled, we
6681 print it as if it had several locations, since otherwise it's
6682 hard to represent "breakpoint enabled, location disabled"
6685 Note that while hardware watchpoints have several locations
6686 internally, that's not a property exposed to user. */
6688 && !is_hardware_watchpoint (b
)
6689 && (b
->loc
->next
|| !b
->loc
->enabled
))
6691 struct bp_location
*loc
;
6694 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6696 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6697 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6704 breakpoint_address_bits (struct breakpoint
*b
)
6706 int print_address_bits
= 0;
6707 struct bp_location
*loc
;
6709 /* Software watchpoints that aren't watching memory don't have an
6710 address to print. */
6711 if (is_no_memory_software_watchpoint (b
))
6714 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6718 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6719 if (addr_bit
> print_address_bits
)
6720 print_address_bits
= addr_bit
;
6723 return print_address_bits
;
6726 struct captured_breakpoint_query_args
6732 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6734 struct captured_breakpoint_query_args
*args
6735 = (struct captured_breakpoint_query_args
*) data
;
6736 struct breakpoint
*b
;
6737 struct bp_location
*dummy_loc
= NULL
;
6741 if (args
->bnum
== b
->number
)
6743 print_one_breakpoint (b
, &dummy_loc
, 0);
6751 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6752 char **error_message
)
6754 struct captured_breakpoint_query_args args
;
6757 /* For the moment we don't trust print_one_breakpoint() to not throw
6759 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6760 error_message
, RETURN_MASK_ALL
) < 0)
6766 /* Return true if this breakpoint was set by the user, false if it is
6767 internal or momentary. */
6770 user_breakpoint_p (struct breakpoint
*b
)
6772 return b
->number
> 0;
6775 /* See breakpoint.h. */
6778 pending_breakpoint_p (struct breakpoint
*b
)
6780 return b
->loc
== NULL
;
6783 /* Print information on user settable breakpoint (watchpoint, etc)
6784 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6785 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6786 FILTER is non-NULL, call it on each breakpoint and only include the
6787 ones for which it returns non-zero. Return the total number of
6788 breakpoints listed. */
6791 breakpoint_1 (char *args
, int allflag
,
6792 int (*filter
) (const struct breakpoint
*))
6794 struct breakpoint
*b
;
6795 struct bp_location
*last_loc
= NULL
;
6796 int nr_printable_breakpoints
;
6797 struct cleanup
*bkpttbl_chain
;
6798 struct value_print_options opts
;
6799 int print_address_bits
= 0;
6800 int print_type_col_width
= 14;
6801 struct ui_out
*uiout
= current_uiout
;
6803 get_user_print_options (&opts
);
6805 /* Compute the number of rows in the table, as well as the size
6806 required for address fields. */
6807 nr_printable_breakpoints
= 0;
6810 /* If we have a filter, only list the breakpoints it accepts. */
6811 if (filter
&& !filter (b
))
6814 /* If we have an "args" string, it is a list of breakpoints to
6815 accept. Skip the others. */
6816 if (args
!= NULL
&& *args
!= '\0')
6818 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6820 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6824 if (allflag
|| user_breakpoint_p (b
))
6826 int addr_bit
, type_len
;
6828 addr_bit
= breakpoint_address_bits (b
);
6829 if (addr_bit
> print_address_bits
)
6830 print_address_bits
= addr_bit
;
6832 type_len
= strlen (bptype_string (b
->type
));
6833 if (type_len
> print_type_col_width
)
6834 print_type_col_width
= type_len
;
6836 nr_printable_breakpoints
++;
6840 if (opts
.addressprint
)
6842 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6843 nr_printable_breakpoints
,
6847 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6848 nr_printable_breakpoints
,
6851 if (nr_printable_breakpoints
> 0)
6852 annotate_breakpoints_headers ();
6853 if (nr_printable_breakpoints
> 0)
6855 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6856 if (nr_printable_breakpoints
> 0)
6858 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6859 if (nr_printable_breakpoints
> 0)
6861 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6862 if (nr_printable_breakpoints
> 0)
6864 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6865 if (opts
.addressprint
)
6867 if (nr_printable_breakpoints
> 0)
6869 if (print_address_bits
<= 32)
6870 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6872 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6874 if (nr_printable_breakpoints
> 0)
6876 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6877 uiout
->table_body ();
6878 if (nr_printable_breakpoints
> 0)
6879 annotate_breakpoints_table ();
6884 /* If we have a filter, only list the breakpoints it accepts. */
6885 if (filter
&& !filter (b
))
6888 /* If we have an "args" string, it is a list of breakpoints to
6889 accept. Skip the others. */
6891 if (args
!= NULL
&& *args
!= '\0')
6893 if (allflag
) /* maintenance info breakpoint */
6895 if (parse_and_eval_long (args
) != b
->number
)
6898 else /* all others */
6900 if (!number_is_in_list (args
, b
->number
))
6904 /* We only print out user settable breakpoints unless the
6906 if (allflag
|| user_breakpoint_p (b
))
6907 print_one_breakpoint (b
, &last_loc
, allflag
);
6910 do_cleanups (bkpttbl_chain
);
6912 if (nr_printable_breakpoints
== 0)
6914 /* If there's a filter, let the caller decide how to report
6918 if (args
== NULL
|| *args
== '\0')
6919 uiout
->message ("No breakpoints or watchpoints.\n");
6921 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6927 if (last_loc
&& !server_command
)
6928 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6931 /* FIXME? Should this be moved up so that it is only called when
6932 there have been breakpoints? */
6933 annotate_breakpoints_table_end ();
6935 return nr_printable_breakpoints
;
6938 /* Display the value of default-collect in a way that is generally
6939 compatible with the breakpoint list. */
6942 default_collect_info (void)
6944 struct ui_out
*uiout
= current_uiout
;
6946 /* If it has no value (which is frequently the case), say nothing; a
6947 message like "No default-collect." gets in user's face when it's
6949 if (!*default_collect
)
6952 /* The following phrase lines up nicely with per-tracepoint collect
6954 uiout
->text ("default collect ");
6955 uiout
->field_string ("default-collect", default_collect
);
6956 uiout
->text (" \n");
6960 breakpoints_info (char *args
, int from_tty
)
6962 breakpoint_1 (args
, 0, NULL
);
6964 default_collect_info ();
6968 watchpoints_info (char *args
, int from_tty
)
6970 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6971 struct ui_out
*uiout
= current_uiout
;
6973 if (num_printed
== 0)
6975 if (args
== NULL
|| *args
== '\0')
6976 uiout
->message ("No watchpoints.\n");
6978 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6983 maintenance_info_breakpoints (char *args
, int from_tty
)
6985 breakpoint_1 (args
, 1, NULL
);
6987 default_collect_info ();
6991 breakpoint_has_pc (struct breakpoint
*b
,
6992 struct program_space
*pspace
,
6993 CORE_ADDR pc
, struct obj_section
*section
)
6995 struct bp_location
*bl
= b
->loc
;
6997 for (; bl
; bl
= bl
->next
)
6999 if (bl
->pspace
== pspace
7000 && bl
->address
== pc
7001 && (!overlay_debugging
|| bl
->section
== section
))
7007 /* Print a message describing any user-breakpoints set at PC. This
7008 concerns with logical breakpoints, so we match program spaces, not
7012 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7013 struct program_space
*pspace
, CORE_ADDR pc
,
7014 struct obj_section
*section
, int thread
)
7017 struct breakpoint
*b
;
7020 others
+= (user_breakpoint_p (b
)
7021 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7025 printf_filtered (_("Note: breakpoint "));
7026 else /* if (others == ???) */
7027 printf_filtered (_("Note: breakpoints "));
7029 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7032 printf_filtered ("%d", b
->number
);
7033 if (b
->thread
== -1 && thread
!= -1)
7034 printf_filtered (" (all threads)");
7035 else if (b
->thread
!= -1)
7036 printf_filtered (" (thread %d)", b
->thread
);
7037 printf_filtered ("%s%s ",
7038 ((b
->enable_state
== bp_disabled
7039 || b
->enable_state
== bp_call_disabled
)
7043 : ((others
== 1) ? " and" : ""));
7045 printf_filtered (_("also set at pc "));
7046 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7047 printf_filtered (".\n");
7052 /* Return true iff it is meaningful to use the address member of
7053 BPT locations. For some breakpoint types, the locations' address members
7054 are irrelevant and it makes no sense to attempt to compare them to other
7055 addresses (or use them for any other purpose either).
7057 More specifically, each of the following breakpoint types will
7058 always have a zero valued location address and we don't want to mark
7059 breakpoints of any of these types to be a duplicate of an actual
7060 breakpoint location at address zero:
7068 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7070 enum bptype type
= bpt
->type
;
7072 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7075 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7076 true if LOC1 and LOC2 represent the same watchpoint location. */
7079 watchpoint_locations_match (struct bp_location
*loc1
,
7080 struct bp_location
*loc2
)
7082 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7083 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7085 /* Both of them must exist. */
7086 gdb_assert (w1
!= NULL
);
7087 gdb_assert (w2
!= NULL
);
7089 /* If the target can evaluate the condition expression in hardware,
7090 then we we need to insert both watchpoints even if they are at
7091 the same place. Otherwise the watchpoint will only trigger when
7092 the condition of whichever watchpoint was inserted evaluates to
7093 true, not giving a chance for GDB to check the condition of the
7094 other watchpoint. */
7096 && target_can_accel_watchpoint_condition (loc1
->address
,
7098 loc1
->watchpoint_type
,
7099 w1
->cond_exp
.get ()))
7101 && target_can_accel_watchpoint_condition (loc2
->address
,
7103 loc2
->watchpoint_type
,
7104 w2
->cond_exp
.get ())))
7107 /* Note that this checks the owner's type, not the location's. In
7108 case the target does not support read watchpoints, but does
7109 support access watchpoints, we'll have bp_read_watchpoint
7110 watchpoints with hw_access locations. Those should be considered
7111 duplicates of hw_read locations. The hw_read locations will
7112 become hw_access locations later. */
7113 return (loc1
->owner
->type
== loc2
->owner
->type
7114 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7115 && loc1
->address
== loc2
->address
7116 && loc1
->length
== loc2
->length
);
7119 /* See breakpoint.h. */
7122 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7123 struct address_space
*aspace2
, CORE_ADDR addr2
)
7125 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7126 || aspace1
== aspace2
)
7130 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7131 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7132 matches ASPACE2. On targets that have global breakpoints, the address
7133 space doesn't really matter. */
7136 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7137 int len1
, struct address_space
*aspace2
,
7140 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7141 || aspace1
== aspace2
)
7142 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7145 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7146 a ranged breakpoint. In most targets, a match happens only if ASPACE
7147 matches the breakpoint's address space. On targets that have global
7148 breakpoints, the address space doesn't really matter. */
7151 breakpoint_location_address_match (struct bp_location
*bl
,
7152 struct address_space
*aspace
,
7155 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7158 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7159 bl
->address
, bl
->length
,
7163 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7164 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7165 match happens only if ASPACE matches the breakpoint's address
7166 space. On targets that have global breakpoints, the address space
7167 doesn't really matter. */
7170 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7171 struct address_space
*aspace
,
7172 CORE_ADDR addr
, int len
)
7174 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7175 || bl
->pspace
->aspace
== aspace
)
7177 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7179 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7185 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7186 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7187 true, otherwise returns false. */
7190 tracepoint_locations_match (struct bp_location
*loc1
,
7191 struct bp_location
*loc2
)
7193 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7194 /* Since tracepoint locations are never duplicated with others', tracepoint
7195 locations at the same address of different tracepoints are regarded as
7196 different locations. */
7197 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7202 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7203 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7204 represent the same location. */
7207 breakpoint_locations_match (struct bp_location
*loc1
,
7208 struct bp_location
*loc2
)
7210 int hw_point1
, hw_point2
;
7212 /* Both of them must not be in moribund_locations. */
7213 gdb_assert (loc1
->owner
!= NULL
);
7214 gdb_assert (loc2
->owner
!= NULL
);
7216 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7217 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7219 if (hw_point1
!= hw_point2
)
7222 return watchpoint_locations_match (loc1
, loc2
);
7223 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7224 return tracepoint_locations_match (loc1
, loc2
);
7226 /* We compare bp_location.length in order to cover ranged breakpoints. */
7227 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7228 loc2
->pspace
->aspace
, loc2
->address
)
7229 && loc1
->length
== loc2
->length
);
7233 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7234 int bnum
, int have_bnum
)
7236 /* The longest string possibly returned by hex_string_custom
7237 is 50 chars. These must be at least that big for safety. */
7241 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7242 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7244 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7245 bnum
, astr1
, astr2
);
7247 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7250 /* Adjust a breakpoint's address to account for architectural
7251 constraints on breakpoint placement. Return the adjusted address.
7252 Note: Very few targets require this kind of adjustment. For most
7253 targets, this function is simply the identity function. */
7256 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7257 CORE_ADDR bpaddr
, enum bptype bptype
)
7259 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7261 /* Very few targets need any kind of breakpoint adjustment. */
7264 else if (bptype
== bp_watchpoint
7265 || bptype
== bp_hardware_watchpoint
7266 || bptype
== bp_read_watchpoint
7267 || bptype
== bp_access_watchpoint
7268 || bptype
== bp_catchpoint
)
7270 /* Watchpoints and the various bp_catch_* eventpoints should not
7271 have their addresses modified. */
7274 else if (bptype
== bp_single_step
)
7276 /* Single-step breakpoints should not have their addresses
7277 modified. If there's any architectural constrain that
7278 applies to this address, then it should have already been
7279 taken into account when the breakpoint was created in the
7280 first place. If we didn't do this, stepping through e.g.,
7281 Thumb-2 IT blocks would break. */
7286 CORE_ADDR adjusted_bpaddr
;
7288 /* Some targets have architectural constraints on the placement
7289 of breakpoint instructions. Obtain the adjusted address. */
7290 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7292 /* An adjusted breakpoint address can significantly alter
7293 a user's expectations. Print a warning if an adjustment
7295 if (adjusted_bpaddr
!= bpaddr
)
7296 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7298 return adjusted_bpaddr
;
7302 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7304 bp_location
*loc
= this;
7306 gdb_assert (ops
!= NULL
);
7310 loc
->cond_bytecode
= NULL
;
7311 loc
->shlib_disabled
= 0;
7314 switch (owner
->type
)
7317 case bp_single_step
:
7321 case bp_longjmp_resume
:
7322 case bp_longjmp_call_dummy
:
7324 case bp_exception_resume
:
7325 case bp_step_resume
:
7326 case bp_hp_step_resume
:
7327 case bp_watchpoint_scope
:
7329 case bp_std_terminate
:
7330 case bp_shlib_event
:
7331 case bp_thread_event
:
7332 case bp_overlay_event
:
7334 case bp_longjmp_master
:
7335 case bp_std_terminate_master
:
7336 case bp_exception_master
:
7337 case bp_gnu_ifunc_resolver
:
7338 case bp_gnu_ifunc_resolver_return
:
7340 loc
->loc_type
= bp_loc_software_breakpoint
;
7341 mark_breakpoint_location_modified (loc
);
7343 case bp_hardware_breakpoint
:
7344 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7345 mark_breakpoint_location_modified (loc
);
7347 case bp_hardware_watchpoint
:
7348 case bp_read_watchpoint
:
7349 case bp_access_watchpoint
:
7350 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7355 case bp_fast_tracepoint
:
7356 case bp_static_tracepoint
:
7357 loc
->loc_type
= bp_loc_other
;
7360 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7366 /* Allocate a struct bp_location. */
7368 static struct bp_location
*
7369 allocate_bp_location (struct breakpoint
*bpt
)
7371 return bpt
->ops
->allocate_location (bpt
);
7375 free_bp_location (struct bp_location
*loc
)
7377 loc
->ops
->dtor (loc
);
7381 /* Increment reference count. */
7384 incref_bp_location (struct bp_location
*bl
)
7389 /* Decrement reference count. If the reference count reaches 0,
7390 destroy the bp_location. Sets *BLP to NULL. */
7393 decref_bp_location (struct bp_location
**blp
)
7395 gdb_assert ((*blp
)->refc
> 0);
7397 if (--(*blp
)->refc
== 0)
7398 free_bp_location (*blp
);
7402 /* Add breakpoint B at the end of the global breakpoint chain. */
7405 add_to_breakpoint_chain (struct breakpoint
*b
)
7407 struct breakpoint
*b1
;
7409 /* Add this breakpoint to the end of the chain so that a list of
7410 breakpoints will come out in order of increasing numbers. */
7412 b1
= breakpoint_chain
;
7414 breakpoint_chain
= b
;
7423 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7426 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7427 struct gdbarch
*gdbarch
,
7429 const struct breakpoint_ops
*ops
)
7431 gdb_assert (ops
!= NULL
);
7435 b
->gdbarch
= gdbarch
;
7436 b
->language
= current_language
->la_language
;
7437 b
->input_radix
= input_radix
;
7438 b
->related_breakpoint
= b
;
7441 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7442 that has type BPTYPE and has no locations as yet. */
7444 static struct breakpoint
*
7445 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7447 const struct breakpoint_ops
*ops
)
7449 struct breakpoint
*b
= new breakpoint ();
7451 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7452 add_to_breakpoint_chain (b
);
7456 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7457 resolutions should be made as the user specified the location explicitly
7461 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7463 gdb_assert (loc
->owner
!= NULL
);
7465 if (loc
->owner
->type
== bp_breakpoint
7466 || loc
->owner
->type
== bp_hardware_breakpoint
7467 || is_tracepoint (loc
->owner
))
7470 const char *function_name
;
7471 CORE_ADDR func_addr
;
7473 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7474 &func_addr
, NULL
, &is_gnu_ifunc
);
7476 if (is_gnu_ifunc
&& !explicit_loc
)
7478 struct breakpoint
*b
= loc
->owner
;
7480 gdb_assert (loc
->pspace
== current_program_space
);
7481 if (gnu_ifunc_resolve_name (function_name
,
7482 &loc
->requested_address
))
7484 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7485 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7486 loc
->requested_address
,
7489 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7490 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7492 /* Create only the whole new breakpoint of this type but do not
7493 mess more complicated breakpoints with multiple locations. */
7494 b
->type
= bp_gnu_ifunc_resolver
;
7495 /* Remember the resolver's address for use by the return
7497 loc
->related_address
= func_addr
;
7502 loc
->function_name
= xstrdup (function_name
);
7506 /* Attempt to determine architecture of location identified by SAL. */
7508 get_sal_arch (struct symtab_and_line sal
)
7511 return get_objfile_arch (sal
.section
->objfile
);
7513 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7518 /* Low level routine for partially initializing a breakpoint of type
7519 BPTYPE. The newly created breakpoint's address, section, source
7520 file name, and line number are provided by SAL.
7522 It is expected that the caller will complete the initialization of
7523 the newly created breakpoint struct as well as output any status
7524 information regarding the creation of a new breakpoint. */
7527 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7528 struct symtab_and_line sal
, enum bptype bptype
,
7529 const struct breakpoint_ops
*ops
)
7531 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7533 add_location_to_breakpoint (b
, &sal
);
7535 if (bptype
!= bp_catchpoint
)
7536 gdb_assert (sal
.pspace
!= NULL
);
7538 /* Store the program space that was used to set the breakpoint,
7539 except for ordinary breakpoints, which are independent of the
7541 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7542 b
->pspace
= sal
.pspace
;
7545 /* set_raw_breakpoint is a low level routine for allocating and
7546 partially initializing a breakpoint of type BPTYPE. The newly
7547 created breakpoint's address, section, source file name, and line
7548 number are provided by SAL. The newly created and partially
7549 initialized breakpoint is added to the breakpoint chain and
7550 is also returned as the value of this function.
7552 It is expected that the caller will complete the initialization of
7553 the newly created breakpoint struct as well as output any status
7554 information regarding the creation of a new breakpoint. In
7555 particular, set_raw_breakpoint does NOT set the breakpoint
7556 number! Care should be taken to not allow an error to occur
7557 prior to completing the initialization of the breakpoint. If this
7558 should happen, a bogus breakpoint will be left on the chain. */
7561 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7562 struct symtab_and_line sal
, enum bptype bptype
,
7563 const struct breakpoint_ops
*ops
)
7565 struct breakpoint
*b
= new breakpoint ();
7567 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7568 add_to_breakpoint_chain (b
);
7572 /* Call this routine when stepping and nexting to enable a breakpoint
7573 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7574 initiated the operation. */
7577 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7579 struct breakpoint
*b
, *b_tmp
;
7580 int thread
= tp
->global_num
;
7582 /* To avoid having to rescan all objfile symbols at every step,
7583 we maintain a list of continually-inserted but always disabled
7584 longjmp "master" breakpoints. Here, we simply create momentary
7585 clones of those and enable them for the requested thread. */
7586 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7587 if (b
->pspace
== current_program_space
7588 && (b
->type
== bp_longjmp_master
7589 || b
->type
== bp_exception_master
))
7591 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7592 struct breakpoint
*clone
;
7594 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7595 after their removal. */
7596 clone
= momentary_breakpoint_from_master (b
, type
,
7597 &longjmp_breakpoint_ops
, 1);
7598 clone
->thread
= thread
;
7601 tp
->initiating_frame
= frame
;
7604 /* Delete all longjmp breakpoints from THREAD. */
7606 delete_longjmp_breakpoint (int thread
)
7608 struct breakpoint
*b
, *b_tmp
;
7610 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7611 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7613 if (b
->thread
== thread
)
7614 delete_breakpoint (b
);
7619 delete_longjmp_breakpoint_at_next_stop (int thread
)
7621 struct breakpoint
*b
, *b_tmp
;
7623 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7624 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7626 if (b
->thread
== thread
)
7627 b
->disposition
= disp_del_at_next_stop
;
7631 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7632 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7633 pointer to any of them. Return NULL if this system cannot place longjmp
7637 set_longjmp_breakpoint_for_call_dummy (void)
7639 struct breakpoint
*b
, *retval
= NULL
;
7642 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7644 struct breakpoint
*new_b
;
7646 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7647 &momentary_breakpoint_ops
,
7649 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7651 /* Link NEW_B into the chain of RETVAL breakpoints. */
7653 gdb_assert (new_b
->related_breakpoint
== new_b
);
7656 new_b
->related_breakpoint
= retval
;
7657 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7658 retval
= retval
->related_breakpoint
;
7659 retval
->related_breakpoint
= new_b
;
7665 /* Verify all existing dummy frames and their associated breakpoints for
7666 TP. Remove those which can no longer be found in the current frame
7669 You should call this function only at places where it is safe to currently
7670 unwind the whole stack. Failed stack unwind would discard live dummy
7674 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7676 struct breakpoint
*b
, *b_tmp
;
7678 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7679 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7681 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7683 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7684 dummy_b
= dummy_b
->related_breakpoint
;
7685 if (dummy_b
->type
!= bp_call_dummy
7686 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7689 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7691 while (b
->related_breakpoint
!= b
)
7693 if (b_tmp
== b
->related_breakpoint
)
7694 b_tmp
= b
->related_breakpoint
->next
;
7695 delete_breakpoint (b
->related_breakpoint
);
7697 delete_breakpoint (b
);
7702 enable_overlay_breakpoints (void)
7704 struct breakpoint
*b
;
7707 if (b
->type
== bp_overlay_event
)
7709 b
->enable_state
= bp_enabled
;
7710 update_global_location_list (UGLL_MAY_INSERT
);
7711 overlay_events_enabled
= 1;
7716 disable_overlay_breakpoints (void)
7718 struct breakpoint
*b
;
7721 if (b
->type
== bp_overlay_event
)
7723 b
->enable_state
= bp_disabled
;
7724 update_global_location_list (UGLL_DONT_INSERT
);
7725 overlay_events_enabled
= 0;
7729 /* Set an active std::terminate breakpoint for each std::terminate
7730 master breakpoint. */
7732 set_std_terminate_breakpoint (void)
7734 struct breakpoint
*b
, *b_tmp
;
7736 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7737 if (b
->pspace
== current_program_space
7738 && b
->type
== bp_std_terminate_master
)
7740 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7741 &momentary_breakpoint_ops
, 1);
7745 /* Delete all the std::terminate breakpoints. */
7747 delete_std_terminate_breakpoint (void)
7749 struct breakpoint
*b
, *b_tmp
;
7751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7752 if (b
->type
== bp_std_terminate
)
7753 delete_breakpoint (b
);
7757 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7759 struct breakpoint
*b
;
7761 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7762 &internal_breakpoint_ops
);
7764 b
->enable_state
= bp_enabled
;
7765 /* location has to be used or breakpoint_re_set will delete me. */
7766 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7768 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7773 struct lang_and_radix
7779 /* Create a breakpoint for JIT code registration and unregistration. */
7782 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7784 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7785 &internal_breakpoint_ops
);
7788 /* Remove JIT code registration and unregistration breakpoint(s). */
7791 remove_jit_event_breakpoints (void)
7793 struct breakpoint
*b
, *b_tmp
;
7795 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7796 if (b
->type
== bp_jit_event
7797 && b
->loc
->pspace
== current_program_space
)
7798 delete_breakpoint (b
);
7802 remove_solib_event_breakpoints (void)
7804 struct breakpoint
*b
, *b_tmp
;
7806 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7807 if (b
->type
== bp_shlib_event
7808 && b
->loc
->pspace
== current_program_space
)
7809 delete_breakpoint (b
);
7812 /* See breakpoint.h. */
7815 remove_solib_event_breakpoints_at_next_stop (void)
7817 struct breakpoint
*b
, *b_tmp
;
7819 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7820 if (b
->type
== bp_shlib_event
7821 && b
->loc
->pspace
== current_program_space
)
7822 b
->disposition
= disp_del_at_next_stop
;
7825 /* Helper for create_solib_event_breakpoint /
7826 create_and_insert_solib_event_breakpoint. Allows specifying which
7827 INSERT_MODE to pass through to update_global_location_list. */
7829 static struct breakpoint
*
7830 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7831 enum ugll_insert_mode insert_mode
)
7833 struct breakpoint
*b
;
7835 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7836 &internal_breakpoint_ops
);
7837 update_global_location_list_nothrow (insert_mode
);
7842 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7844 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7847 /* See breakpoint.h. */
7850 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7852 struct breakpoint
*b
;
7854 /* Explicitly tell update_global_location_list to insert
7856 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7857 if (!b
->loc
->inserted
)
7859 delete_breakpoint (b
);
7865 /* Disable any breakpoints that are on code in shared libraries. Only
7866 apply to enabled breakpoints, disabled ones can just stay disabled. */
7869 disable_breakpoints_in_shlibs (void)
7871 struct bp_location
*loc
, **locp_tmp
;
7873 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7875 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7876 struct breakpoint
*b
= loc
->owner
;
7878 /* We apply the check to all breakpoints, including disabled for
7879 those with loc->duplicate set. This is so that when breakpoint
7880 becomes enabled, or the duplicate is removed, gdb will try to
7881 insert all breakpoints. If we don't set shlib_disabled here,
7882 we'll try to insert those breakpoints and fail. */
7883 if (((b
->type
== bp_breakpoint
)
7884 || (b
->type
== bp_jit_event
)
7885 || (b
->type
== bp_hardware_breakpoint
)
7886 || (is_tracepoint (b
)))
7887 && loc
->pspace
== current_program_space
7888 && !loc
->shlib_disabled
7889 && solib_name_from_address (loc
->pspace
, loc
->address
)
7892 loc
->shlib_disabled
= 1;
7897 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7898 notification of unloaded_shlib. Only apply to enabled breakpoints,
7899 disabled ones can just stay disabled. */
7902 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7904 struct bp_location
*loc
, **locp_tmp
;
7905 int disabled_shlib_breaks
= 0;
7907 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7909 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7910 struct breakpoint
*b
= loc
->owner
;
7912 if (solib
->pspace
== loc
->pspace
7913 && !loc
->shlib_disabled
7914 && (((b
->type
== bp_breakpoint
7915 || b
->type
== bp_jit_event
7916 || b
->type
== bp_hardware_breakpoint
)
7917 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7918 || loc
->loc_type
== bp_loc_software_breakpoint
))
7919 || is_tracepoint (b
))
7920 && solib_contains_address_p (solib
, loc
->address
))
7922 loc
->shlib_disabled
= 1;
7923 /* At this point, we cannot rely on remove_breakpoint
7924 succeeding so we must mark the breakpoint as not inserted
7925 to prevent future errors occurring in remove_breakpoints. */
7928 /* This may cause duplicate notifications for the same breakpoint. */
7929 observer_notify_breakpoint_modified (b
);
7931 if (!disabled_shlib_breaks
)
7933 target_terminal_ours_for_output ();
7934 warning (_("Temporarily disabling breakpoints "
7935 "for unloaded shared library \"%s\""),
7938 disabled_shlib_breaks
= 1;
7943 /* Disable any breakpoints and tracepoints in OBJFILE upon
7944 notification of free_objfile. Only apply to enabled breakpoints,
7945 disabled ones can just stay disabled. */
7948 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7950 struct breakpoint
*b
;
7952 if (objfile
== NULL
)
7955 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7956 managed by the user with add-symbol-file/remove-symbol-file.
7957 Similarly to how breakpoints in shared libraries are handled in
7958 response to "nosharedlibrary", mark breakpoints in such modules
7959 shlib_disabled so they end up uninserted on the next global
7960 location list update. Shared libraries not loaded by the user
7961 aren't handled here -- they're already handled in
7962 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7963 solib_unloaded observer. We skip objfiles that are not
7964 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7966 if ((objfile
->flags
& OBJF_SHARED
) == 0
7967 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7972 struct bp_location
*loc
;
7973 int bp_modified
= 0;
7975 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7978 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7980 CORE_ADDR loc_addr
= loc
->address
;
7982 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7983 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7986 if (loc
->shlib_disabled
!= 0)
7989 if (objfile
->pspace
!= loc
->pspace
)
7992 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7993 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7996 if (is_addr_in_objfile (loc_addr
, objfile
))
7998 loc
->shlib_disabled
= 1;
7999 /* At this point, we don't know whether the object was
8000 unmapped from the inferior or not, so leave the
8001 inserted flag alone. We'll handle failure to
8002 uninsert quietly, in case the object was indeed
8005 mark_breakpoint_location_modified (loc
);
8012 observer_notify_breakpoint_modified (b
);
8016 /* FORK & VFORK catchpoints. */
8018 /* An instance of this type is used to represent a fork or vfork
8019 catchpoint. It includes a "struct breakpoint" as a kind of base
8020 class; users downcast to "struct breakpoint *" when needed. A
8021 breakpoint is really of this type iff its ops pointer points to
8022 CATCH_FORK_BREAKPOINT_OPS. */
8024 struct fork_catchpoint
8026 /* The base class. */
8027 struct breakpoint base
;
8029 /* Process id of a child process whose forking triggered this
8030 catchpoint. This field is only valid immediately after this
8031 catchpoint has triggered. */
8032 ptid_t forked_inferior_pid
;
8035 /* Implement the "insert" breakpoint_ops method for fork
8039 insert_catch_fork (struct bp_location
*bl
)
8041 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8044 /* Implement the "remove" breakpoint_ops method for fork
8048 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8050 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8053 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8057 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8058 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8059 const struct target_waitstatus
*ws
)
8061 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8063 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8066 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8070 /* Implement the "print_it" breakpoint_ops method for fork
8073 static enum print_stop_action
8074 print_it_catch_fork (bpstat bs
)
8076 struct ui_out
*uiout
= current_uiout
;
8077 struct breakpoint
*b
= bs
->breakpoint_at
;
8078 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8080 annotate_catchpoint (b
->number
);
8081 maybe_print_thread_hit_breakpoint (uiout
);
8082 if (b
->disposition
== disp_del
)
8083 uiout
->text ("Temporary catchpoint ");
8085 uiout
->text ("Catchpoint ");
8086 if (uiout
->is_mi_like_p ())
8088 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8089 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8091 uiout
->field_int ("bkptno", b
->number
);
8092 uiout
->text (" (forked process ");
8093 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8094 uiout
->text ("), ");
8095 return PRINT_SRC_AND_LOC
;
8098 /* Implement the "print_one" breakpoint_ops method for fork
8102 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8104 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8105 struct value_print_options opts
;
8106 struct ui_out
*uiout
= current_uiout
;
8108 get_user_print_options (&opts
);
8110 /* Field 4, the address, is omitted (which makes the columns not
8111 line up too nicely with the headers, but the effect is relatively
8113 if (opts
.addressprint
)
8114 uiout
->field_skip ("addr");
8116 uiout
->text ("fork");
8117 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8119 uiout
->text (", process ");
8120 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8124 if (uiout
->is_mi_like_p ())
8125 uiout
->field_string ("catch-type", "fork");
8128 /* Implement the "print_mention" breakpoint_ops method for fork
8132 print_mention_catch_fork (struct breakpoint
*b
)
8134 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8137 /* Implement the "print_recreate" breakpoint_ops method for fork
8141 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8143 fprintf_unfiltered (fp
, "catch fork");
8144 print_recreate_thread (b
, fp
);
8147 /* The breakpoint_ops structure to be used in fork catchpoints. */
8149 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8151 /* Implement the "insert" breakpoint_ops method for vfork
8155 insert_catch_vfork (struct bp_location
*bl
)
8157 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8160 /* Implement the "remove" breakpoint_ops method for vfork
8164 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8166 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8169 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8173 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8174 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8175 const struct target_waitstatus
*ws
)
8177 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8179 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8182 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8186 /* Implement the "print_it" breakpoint_ops method for vfork
8189 static enum print_stop_action
8190 print_it_catch_vfork (bpstat bs
)
8192 struct ui_out
*uiout
= current_uiout
;
8193 struct breakpoint
*b
= bs
->breakpoint_at
;
8194 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8196 annotate_catchpoint (b
->number
);
8197 maybe_print_thread_hit_breakpoint (uiout
);
8198 if (b
->disposition
== disp_del
)
8199 uiout
->text ("Temporary catchpoint ");
8201 uiout
->text ("Catchpoint ");
8202 if (uiout
->is_mi_like_p ())
8204 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8205 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8207 uiout
->field_int ("bkptno", b
->number
);
8208 uiout
->text (" (vforked process ");
8209 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8210 uiout
->text ("), ");
8211 return PRINT_SRC_AND_LOC
;
8214 /* Implement the "print_one" breakpoint_ops method for vfork
8218 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8220 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8221 struct value_print_options opts
;
8222 struct ui_out
*uiout
= current_uiout
;
8224 get_user_print_options (&opts
);
8225 /* Field 4, the address, is omitted (which makes the columns not
8226 line up too nicely with the headers, but the effect is relatively
8228 if (opts
.addressprint
)
8229 uiout
->field_skip ("addr");
8231 uiout
->text ("vfork");
8232 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8234 uiout
->text (", process ");
8235 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8239 if (uiout
->is_mi_like_p ())
8240 uiout
->field_string ("catch-type", "vfork");
8243 /* Implement the "print_mention" breakpoint_ops method for vfork
8247 print_mention_catch_vfork (struct breakpoint
*b
)
8249 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8252 /* Implement the "print_recreate" breakpoint_ops method for vfork
8256 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8258 fprintf_unfiltered (fp
, "catch vfork");
8259 print_recreate_thread (b
, fp
);
8262 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8264 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8266 /* An instance of this type is used to represent an solib catchpoint.
8267 It includes a "struct breakpoint" as a kind of base class; users
8268 downcast to "struct breakpoint *" when needed. A breakpoint is
8269 really of this type iff its ops pointer points to
8270 CATCH_SOLIB_BREAKPOINT_OPS. */
8272 struct solib_catchpoint
8274 /* The base class. */
8275 struct breakpoint base
;
8277 /* True for "catch load", false for "catch unload". */
8278 unsigned char is_load
;
8280 /* Regular expression to match, if any. COMPILED is only valid when
8281 REGEX is non-NULL. */
8287 dtor_catch_solib (struct breakpoint
*b
)
8289 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8292 regfree (&self
->compiled
);
8293 xfree (self
->regex
);
8295 base_breakpoint_ops
.dtor (b
);
8299 insert_catch_solib (struct bp_location
*ignore
)
8305 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8311 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8312 struct address_space
*aspace
,
8314 const struct target_waitstatus
*ws
)
8316 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8317 struct breakpoint
*other
;
8319 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8322 ALL_BREAKPOINTS (other
)
8324 struct bp_location
*other_bl
;
8326 if (other
== bl
->owner
)
8329 if (other
->type
!= bp_shlib_event
)
8332 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8335 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8337 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8346 check_status_catch_solib (struct bpstats
*bs
)
8348 struct solib_catchpoint
*self
8349 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8354 struct so_list
*iter
;
8357 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8362 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8371 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8376 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8382 bs
->print_it
= print_it_noop
;
8385 static enum print_stop_action
8386 print_it_catch_solib (bpstat bs
)
8388 struct breakpoint
*b
= bs
->breakpoint_at
;
8389 struct ui_out
*uiout
= current_uiout
;
8391 annotate_catchpoint (b
->number
);
8392 maybe_print_thread_hit_breakpoint (uiout
);
8393 if (b
->disposition
== disp_del
)
8394 uiout
->text ("Temporary catchpoint ");
8396 uiout
->text ("Catchpoint ");
8397 uiout
->field_int ("bkptno", b
->number
);
8399 if (uiout
->is_mi_like_p ())
8400 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8401 print_solib_event (1);
8402 return PRINT_SRC_AND_LOC
;
8406 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8408 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8409 struct value_print_options opts
;
8410 struct ui_out
*uiout
= current_uiout
;
8413 get_user_print_options (&opts
);
8414 /* Field 4, the address, is omitted (which makes the columns not
8415 line up too nicely with the headers, but the effect is relatively
8417 if (opts
.addressprint
)
8420 uiout
->field_skip ("addr");
8427 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8429 msg
= xstrdup (_("load of library"));
8434 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8436 msg
= xstrdup (_("unload of library"));
8438 uiout
->field_string ("what", msg
);
8441 if (uiout
->is_mi_like_p ())
8442 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8446 print_mention_catch_solib (struct breakpoint
*b
)
8448 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8450 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8451 self
->is_load
? "load" : "unload");
8455 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8457 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8459 fprintf_unfiltered (fp
, "%s %s",
8460 b
->disposition
== disp_del
? "tcatch" : "catch",
8461 self
->is_load
? "load" : "unload");
8463 fprintf_unfiltered (fp
, " %s", self
->regex
);
8464 fprintf_unfiltered (fp
, "\n");
8467 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8469 /* Shared helper function (MI and CLI) for creating and installing
8470 a shared object event catchpoint. If IS_LOAD is non-zero then
8471 the events to be caught are load events, otherwise they are
8472 unload events. If IS_TEMP is non-zero the catchpoint is a
8473 temporary one. If ENABLED is non-zero the catchpoint is
8474 created in an enabled state. */
8477 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8479 struct solib_catchpoint
*c
;
8480 struct gdbarch
*gdbarch
= get_current_arch ();
8481 struct cleanup
*cleanup
;
8485 arg
= skip_spaces_const (arg
);
8487 c
= new solib_catchpoint ();
8488 cleanup
= make_cleanup (xfree
, c
);
8494 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8497 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8499 make_cleanup (xfree
, err
);
8500 error (_("Invalid regexp (%s): %s"), err
, arg
);
8502 c
->regex
= xstrdup (arg
);
8505 c
->is_load
= is_load
;
8506 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8507 &catch_solib_breakpoint_ops
);
8509 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8511 discard_cleanups (cleanup
);
8512 install_breakpoint (0, &c
->base
, 1);
8515 /* A helper function that does all the work for "catch load" and
8519 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8520 struct cmd_list_element
*command
)
8523 const int enabled
= 1;
8525 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8527 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8531 catch_load_command_1 (char *arg
, int from_tty
,
8532 struct cmd_list_element
*command
)
8534 catch_load_or_unload (arg
, from_tty
, 1, command
);
8538 catch_unload_command_1 (char *arg
, int from_tty
,
8539 struct cmd_list_element
*command
)
8541 catch_load_or_unload (arg
, from_tty
, 0, command
);
8544 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8545 is non-zero, then make the breakpoint temporary. If COND_STRING is
8546 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8547 the breakpoint_ops structure associated to the catchpoint. */
8550 init_catchpoint (struct breakpoint
*b
,
8551 struct gdbarch
*gdbarch
, int tempflag
,
8552 const char *cond_string
,
8553 const struct breakpoint_ops
*ops
)
8555 struct symtab_and_line sal
;
8558 sal
.pspace
= current_program_space
;
8560 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8562 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8563 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8567 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8569 add_to_breakpoint_chain (b
);
8570 set_breakpoint_number (internal
, b
);
8571 if (is_tracepoint (b
))
8572 set_tracepoint_count (breakpoint_count
);
8575 observer_notify_breakpoint_created (b
);
8578 update_global_location_list (UGLL_MAY_INSERT
);
8582 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8583 int tempflag
, const char *cond_string
,
8584 const struct breakpoint_ops
*ops
)
8586 struct fork_catchpoint
*c
= new fork_catchpoint ();
8588 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8590 c
->forked_inferior_pid
= null_ptid
;
8592 install_breakpoint (0, &c
->base
, 1);
8595 /* Exec catchpoints. */
8597 /* An instance of this type is used to represent an exec catchpoint.
8598 It includes a "struct breakpoint" as a kind of base class; users
8599 downcast to "struct breakpoint *" when needed. A breakpoint is
8600 really of this type iff its ops pointer points to
8601 CATCH_EXEC_BREAKPOINT_OPS. */
8603 struct exec_catchpoint
8605 /* The base class. */
8606 struct breakpoint base
;
8608 /* Filename of a program whose exec triggered this catchpoint.
8609 This field is only valid immediately after this catchpoint has
8611 char *exec_pathname
;
8614 /* Implement the "dtor" breakpoint_ops method for exec
8618 dtor_catch_exec (struct breakpoint
*b
)
8620 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8622 xfree (c
->exec_pathname
);
8624 base_breakpoint_ops
.dtor (b
);
8628 insert_catch_exec (struct bp_location
*bl
)
8630 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8634 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8636 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8640 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8641 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8642 const struct target_waitstatus
*ws
)
8644 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8646 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8649 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8653 static enum print_stop_action
8654 print_it_catch_exec (bpstat bs
)
8656 struct ui_out
*uiout
= current_uiout
;
8657 struct breakpoint
*b
= bs
->breakpoint_at
;
8658 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8660 annotate_catchpoint (b
->number
);
8661 maybe_print_thread_hit_breakpoint (uiout
);
8662 if (b
->disposition
== disp_del
)
8663 uiout
->text ("Temporary catchpoint ");
8665 uiout
->text ("Catchpoint ");
8666 if (uiout
->is_mi_like_p ())
8668 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8669 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8671 uiout
->field_int ("bkptno", b
->number
);
8672 uiout
->text (" (exec'd ");
8673 uiout
->field_string ("new-exec", c
->exec_pathname
);
8674 uiout
->text ("), ");
8676 return PRINT_SRC_AND_LOC
;
8680 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8682 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8683 struct value_print_options opts
;
8684 struct ui_out
*uiout
= current_uiout
;
8686 get_user_print_options (&opts
);
8688 /* Field 4, the address, is omitted (which makes the columns
8689 not line up too nicely with the headers, but the effect
8690 is relatively readable). */
8691 if (opts
.addressprint
)
8692 uiout
->field_skip ("addr");
8694 uiout
->text ("exec");
8695 if (c
->exec_pathname
!= NULL
)
8697 uiout
->text (", program \"");
8698 uiout
->field_string ("what", c
->exec_pathname
);
8699 uiout
->text ("\" ");
8702 if (uiout
->is_mi_like_p ())
8703 uiout
->field_string ("catch-type", "exec");
8707 print_mention_catch_exec (struct breakpoint
*b
)
8709 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8712 /* Implement the "print_recreate" breakpoint_ops method for exec
8716 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8718 fprintf_unfiltered (fp
, "catch exec");
8719 print_recreate_thread (b
, fp
);
8722 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8725 hw_breakpoint_used_count (void)
8728 struct breakpoint
*b
;
8729 struct bp_location
*bl
;
8733 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8734 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8736 /* Special types of hardware breakpoints may use more than
8738 i
+= b
->ops
->resources_needed (bl
);
8745 /* Returns the resources B would use if it were a hardware
8749 hw_watchpoint_use_count (struct breakpoint
*b
)
8752 struct bp_location
*bl
;
8754 if (!breakpoint_enabled (b
))
8757 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8759 /* Special types of hardware watchpoints may use more than
8761 i
+= b
->ops
->resources_needed (bl
);
8767 /* Returns the sum the used resources of all hardware watchpoints of
8768 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8769 the sum of the used resources of all hardware watchpoints of other
8770 types _not_ TYPE. */
8773 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8774 enum bptype type
, int *other_type_used
)
8777 struct breakpoint
*b
;
8779 *other_type_used
= 0;
8784 if (!breakpoint_enabled (b
))
8787 if (b
->type
== type
)
8788 i
+= hw_watchpoint_use_count (b
);
8789 else if (is_hardware_watchpoint (b
))
8790 *other_type_used
= 1;
8797 disable_watchpoints_before_interactive_call_start (void)
8799 struct breakpoint
*b
;
8803 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8805 b
->enable_state
= bp_call_disabled
;
8806 update_global_location_list (UGLL_DONT_INSERT
);
8812 enable_watchpoints_after_interactive_call_stop (void)
8814 struct breakpoint
*b
;
8818 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8820 b
->enable_state
= bp_enabled
;
8821 update_global_location_list (UGLL_MAY_INSERT
);
8827 disable_breakpoints_before_startup (void)
8829 current_program_space
->executing_startup
= 1;
8830 update_global_location_list (UGLL_DONT_INSERT
);
8834 enable_breakpoints_after_startup (void)
8836 current_program_space
->executing_startup
= 0;
8837 breakpoint_re_set ();
8840 /* Create a new single-step breakpoint for thread THREAD, with no
8843 static struct breakpoint
*
8844 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8846 struct breakpoint
*b
= new breakpoint ();
8848 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8849 &momentary_breakpoint_ops
);
8851 b
->disposition
= disp_donttouch
;
8852 b
->frame_id
= null_frame_id
;
8855 gdb_assert (b
->thread
!= 0);
8857 add_to_breakpoint_chain (b
);
8862 /* Set a momentary breakpoint of type TYPE at address specified by
8863 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8867 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8868 struct frame_id frame_id
, enum bptype type
)
8870 struct breakpoint
*b
;
8872 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8874 gdb_assert (!frame_id_artificial_p (frame_id
));
8876 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8877 b
->enable_state
= bp_enabled
;
8878 b
->disposition
= disp_donttouch
;
8879 b
->frame_id
= frame_id
;
8881 /* If we're debugging a multi-threaded program, then we want
8882 momentary breakpoints to be active in only a single thread of
8884 if (in_thread_list (inferior_ptid
))
8885 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8887 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8892 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8893 The new breakpoint will have type TYPE, use OPS as its
8894 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8896 static struct breakpoint
*
8897 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8899 const struct breakpoint_ops
*ops
,
8902 struct breakpoint
*copy
;
8904 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8905 copy
->loc
= allocate_bp_location (copy
);
8906 set_breakpoint_location_function (copy
->loc
, 1);
8908 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8909 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8910 copy
->loc
->address
= orig
->loc
->address
;
8911 copy
->loc
->section
= orig
->loc
->section
;
8912 copy
->loc
->pspace
= orig
->loc
->pspace
;
8913 copy
->loc
->probe
= orig
->loc
->probe
;
8914 copy
->loc
->line_number
= orig
->loc
->line_number
;
8915 copy
->loc
->symtab
= orig
->loc
->symtab
;
8916 copy
->loc
->enabled
= loc_enabled
;
8917 copy
->frame_id
= orig
->frame_id
;
8918 copy
->thread
= orig
->thread
;
8919 copy
->pspace
= orig
->pspace
;
8921 copy
->enable_state
= bp_enabled
;
8922 copy
->disposition
= disp_donttouch
;
8923 copy
->number
= internal_breakpoint_number
--;
8925 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8929 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8933 clone_momentary_breakpoint (struct breakpoint
*orig
)
8935 /* If there's nothing to clone, then return nothing. */
8939 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8943 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8946 struct symtab_and_line sal
;
8948 sal
= find_pc_line (pc
, 0);
8950 sal
.section
= find_pc_overlay (pc
);
8951 sal
.explicit_pc
= 1;
8953 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8957 /* Tell the user we have just set a breakpoint B. */
8960 mention (struct breakpoint
*b
)
8962 b
->ops
->print_mention (b
);
8963 if (current_uiout
->is_mi_like_p ())
8965 printf_filtered ("\n");
8969 static int bp_loc_is_permanent (struct bp_location
*loc
);
8971 static struct bp_location
*
8972 add_location_to_breakpoint (struct breakpoint
*b
,
8973 const struct symtab_and_line
*sal
)
8975 struct bp_location
*loc
, **tmp
;
8976 CORE_ADDR adjusted_address
;
8977 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8979 if (loc_gdbarch
== NULL
)
8980 loc_gdbarch
= b
->gdbarch
;
8982 /* Adjust the breakpoint's address prior to allocating a location.
8983 Once we call allocate_bp_location(), that mostly uninitialized
8984 location will be placed on the location chain. Adjustment of the
8985 breakpoint may cause target_read_memory() to be called and we do
8986 not want its scan of the location chain to find a breakpoint and
8987 location that's only been partially initialized. */
8988 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8991 /* Sort the locations by their ADDRESS. */
8992 loc
= allocate_bp_location (b
);
8993 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8994 tmp
= &((*tmp
)->next
))
8999 loc
->requested_address
= sal
->pc
;
9000 loc
->address
= adjusted_address
;
9001 loc
->pspace
= sal
->pspace
;
9002 loc
->probe
.probe
= sal
->probe
;
9003 loc
->probe
.objfile
= sal
->objfile
;
9004 gdb_assert (loc
->pspace
!= NULL
);
9005 loc
->section
= sal
->section
;
9006 loc
->gdbarch
= loc_gdbarch
;
9007 loc
->line_number
= sal
->line
;
9008 loc
->symtab
= sal
->symtab
;
9010 set_breakpoint_location_function (loc
,
9011 sal
->explicit_pc
|| sal
->explicit_line
);
9013 /* While by definition, permanent breakpoints are already present in the
9014 code, we don't mark the location as inserted. Normally one would expect
9015 that GDB could rely on that breakpoint instruction to stop the program,
9016 thus removing the need to insert its own breakpoint, except that executing
9017 the breakpoint instruction can kill the target instead of reporting a
9018 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9019 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9020 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9021 breakpoint be inserted normally results in QEMU knowing about the GDB
9022 breakpoint, and thus trap before the breakpoint instruction is executed.
9023 (If GDB later needs to continue execution past the permanent breakpoint,
9024 it manually increments the PC, thus avoiding executing the breakpoint
9026 if (bp_loc_is_permanent (loc
))
9033 /* See breakpoint.h. */
9036 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9040 const gdb_byte
*bpoint
;
9041 gdb_byte
*target_mem
;
9042 struct cleanup
*cleanup
;
9046 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9048 /* Software breakpoints unsupported? */
9052 target_mem
= (gdb_byte
*) alloca (len
);
9054 /* Enable the automatic memory restoration from breakpoints while
9055 we read the memory. Otherwise we could say about our temporary
9056 breakpoints they are permanent. */
9057 cleanup
= make_show_memory_breakpoints_cleanup (0);
9059 if (target_read_memory (address
, target_mem
, len
) == 0
9060 && memcmp (target_mem
, bpoint
, len
) == 0)
9063 do_cleanups (cleanup
);
9068 /* Return 1 if LOC is pointing to a permanent breakpoint,
9069 return 0 otherwise. */
9072 bp_loc_is_permanent (struct bp_location
*loc
)
9074 struct cleanup
*cleanup
;
9077 gdb_assert (loc
!= NULL
);
9079 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9080 attempt to read from the addresses the locations of these breakpoint types
9081 point to. program_breakpoint_here_p, below, will attempt to read
9083 if (!breakpoint_address_is_meaningful (loc
->owner
))
9086 cleanup
= save_current_space_and_thread ();
9087 switch_to_program_space_and_thread (loc
->pspace
);
9089 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9091 do_cleanups (cleanup
);
9096 /* Build a command list for the dprintf corresponding to the current
9097 settings of the dprintf style options. */
9100 update_dprintf_command_list (struct breakpoint
*b
)
9102 char *dprintf_args
= b
->extra_string
;
9103 char *printf_line
= NULL
;
9108 dprintf_args
= skip_spaces (dprintf_args
);
9110 /* Allow a comma, as it may have terminated a location, but don't
9112 if (*dprintf_args
== ',')
9114 dprintf_args
= skip_spaces (dprintf_args
);
9116 if (*dprintf_args
!= '"')
9117 error (_("Bad format string, missing '\"'."));
9119 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9120 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9121 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9123 if (!dprintf_function
)
9124 error (_("No function supplied for dprintf call"));
9126 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9127 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9132 printf_line
= xstrprintf ("call (void) %s (%s)",
9136 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9138 if (target_can_run_breakpoint_commands ())
9139 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9142 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9143 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9147 internal_error (__FILE__
, __LINE__
,
9148 _("Invalid dprintf style."));
9150 gdb_assert (printf_line
!= NULL
);
9151 /* Manufacture a printf sequence. */
9153 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9155 printf_cmd_line
->control_type
= simple_control
;
9156 printf_cmd_line
->body_count
= 0;
9157 printf_cmd_line
->body_list
= NULL
;
9158 printf_cmd_line
->next
= NULL
;
9159 printf_cmd_line
->line
= printf_line
;
9161 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9165 /* Update all dprintf commands, making their command lists reflect
9166 current style settings. */
9169 update_dprintf_commands (char *args
, int from_tty
,
9170 struct cmd_list_element
*c
)
9172 struct breakpoint
*b
;
9176 if (b
->type
== bp_dprintf
)
9177 update_dprintf_command_list (b
);
9181 /* Create a breakpoint with SAL as location. Use LOCATION
9182 as a description of the location, and COND_STRING
9183 as condition expression. If LOCATION is NULL then create an
9184 "address location" from the address in the SAL. */
9187 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9188 struct symtabs_and_lines sals
,
9189 event_location_up
&&location
,
9190 char *filter
, char *cond_string
,
9192 enum bptype type
, enum bpdisp disposition
,
9193 int thread
, int task
, int ignore_count
,
9194 const struct breakpoint_ops
*ops
, int from_tty
,
9195 int enabled
, int internal
, unsigned flags
,
9196 int display_canonical
)
9200 if (type
== bp_hardware_breakpoint
)
9202 int target_resources_ok
;
9204 i
= hw_breakpoint_used_count ();
9205 target_resources_ok
=
9206 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9208 if (target_resources_ok
== 0)
9209 error (_("No hardware breakpoint support in the target."));
9210 else if (target_resources_ok
< 0)
9211 error (_("Hardware breakpoints used exceeds limit."));
9214 gdb_assert (sals
.nelts
> 0);
9216 for (i
= 0; i
< sals
.nelts
; ++i
)
9218 struct symtab_and_line sal
= sals
.sals
[i
];
9219 struct bp_location
*loc
;
9223 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9225 loc_gdbarch
= gdbarch
;
9227 describe_other_breakpoints (loc_gdbarch
,
9228 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9233 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9237 b
->cond_string
= cond_string
;
9238 b
->extra_string
= extra_string
;
9239 b
->ignore_count
= ignore_count
;
9240 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9241 b
->disposition
= disposition
;
9243 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9244 b
->loc
->inserted
= 1;
9246 if (type
== bp_static_tracepoint
)
9248 struct tracepoint
*t
= (struct tracepoint
*) b
;
9249 struct static_tracepoint_marker marker
;
9251 if (strace_marker_p (b
))
9253 /* We already know the marker exists, otherwise, we
9254 wouldn't see a sal for it. */
9256 = &event_location_to_string (b
->location
.get ())[3];
9260 p
= skip_spaces_const (p
);
9262 endp
= skip_to_space_const (p
);
9264 marker_str
= savestring (p
, endp
- p
);
9265 t
->static_trace_marker_id
= marker_str
;
9267 printf_filtered (_("Probed static tracepoint "
9269 t
->static_trace_marker_id
);
9271 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9273 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9274 release_static_tracepoint_marker (&marker
);
9276 printf_filtered (_("Probed static tracepoint "
9278 t
->static_trace_marker_id
);
9281 warning (_("Couldn't determine the static "
9282 "tracepoint marker to probe"));
9289 loc
= add_location_to_breakpoint (b
, &sal
);
9290 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9296 const char *arg
= b
->cond_string
;
9298 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9299 block_for_pc (loc
->address
), 0);
9301 error (_("Garbage '%s' follows condition"), arg
);
9304 /* Dynamic printf requires and uses additional arguments on the
9305 command line, otherwise it's an error. */
9306 if (type
== bp_dprintf
)
9308 if (b
->extra_string
)
9309 update_dprintf_command_list (b
);
9311 error (_("Format string required"));
9313 else if (b
->extra_string
)
9314 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9317 b
->display_canonical
= display_canonical
;
9318 if (location
!= NULL
)
9319 b
->location
= std::move (location
);
9321 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9326 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9327 struct symtabs_and_lines sals
,
9328 event_location_up
&&location
,
9329 char *filter
, char *cond_string
,
9331 enum bptype type
, enum bpdisp disposition
,
9332 int thread
, int task
, int ignore_count
,
9333 const struct breakpoint_ops
*ops
, int from_tty
,
9334 int enabled
, int internal
, unsigned flags
,
9335 int display_canonical
)
9337 struct breakpoint
*b
;
9338 struct cleanup
*old_chain
;
9340 if (is_tracepoint_type (type
))
9342 struct tracepoint
*t
;
9344 t
= new tracepoint ();
9348 b
= new breakpoint ();
9350 old_chain
= make_cleanup (xfree
, b
);
9352 init_breakpoint_sal (b
, gdbarch
,
9353 sals
, std::move (location
),
9354 filter
, cond_string
, extra_string
,
9356 thread
, task
, ignore_count
,
9358 enabled
, internal
, flags
,
9360 discard_cleanups (old_chain
);
9362 install_breakpoint (internal
, b
, 0);
9365 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9366 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9367 value. COND_STRING, if not NULL, specified the condition to be
9368 used for all breakpoints. Essentially the only case where
9369 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9370 function. In that case, it's still not possible to specify
9371 separate conditions for different overloaded functions, so
9372 we take just a single condition string.
9374 NOTE: If the function succeeds, the caller is expected to cleanup
9375 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9376 array contents). If the function fails (error() is called), the
9377 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9378 COND and SALS arrays and each of those arrays contents. */
9381 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9382 struct linespec_result
*canonical
,
9383 char *cond_string
, char *extra_string
,
9384 enum bptype type
, enum bpdisp disposition
,
9385 int thread
, int task
, int ignore_count
,
9386 const struct breakpoint_ops
*ops
, int from_tty
,
9387 int enabled
, int internal
, unsigned flags
)
9390 struct linespec_sals
*lsal
;
9392 if (canonical
->pre_expanded
)
9393 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9395 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9397 /* Note that 'location' can be NULL in the case of a plain
9398 'break', without arguments. */
9399 event_location_up location
9400 = (canonical
->location
!= NULL
9401 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9402 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9404 make_cleanup (xfree
, filter_string
);
9405 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9406 std::move (location
),
9408 cond_string
, extra_string
,
9410 thread
, task
, ignore_count
, ops
,
9411 from_tty
, enabled
, internal
, flags
,
9412 canonical
->special_display
);
9416 /* Parse LOCATION which is assumed to be a SAL specification possibly
9417 followed by conditionals. On return, SALS contains an array of SAL
9418 addresses found. LOCATION points to the end of the SAL (for
9419 linespec locations).
9421 The array and the line spec strings are allocated on the heap, it is
9422 the caller's responsibility to free them. */
9425 parse_breakpoint_sals (const struct event_location
*location
,
9426 struct linespec_result
*canonical
)
9428 struct symtab_and_line cursal
;
9430 if (event_location_type (location
) == LINESPEC_LOCATION
)
9432 const char *address
= get_linespec_location (location
);
9434 if (address
== NULL
)
9436 /* The last displayed codepoint, if it's valid, is our default
9437 breakpoint address. */
9438 if (last_displayed_sal_is_valid ())
9440 struct linespec_sals lsal
;
9441 struct symtab_and_line sal
;
9444 init_sal (&sal
); /* Initialize to zeroes. */
9445 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9447 /* Set sal's pspace, pc, symtab, and line to the values
9448 corresponding to the last call to print_frame_info.
9449 Be sure to reinitialize LINE with NOTCURRENT == 0
9450 as the breakpoint line number is inappropriate otherwise.
9451 find_pc_line would adjust PC, re-set it back. */
9452 get_last_displayed_sal (&sal
);
9454 sal
= find_pc_line (pc
, 0);
9456 /* "break" without arguments is equivalent to "break *PC"
9457 where PC is the last displayed codepoint's address. So
9458 make sure to set sal.explicit_pc to prevent GDB from
9459 trying to expand the list of sals to include all other
9460 instances with the same symtab and line. */
9462 sal
.explicit_pc
= 1;
9464 lsal
.sals
.sals
[0] = sal
;
9465 lsal
.sals
.nelts
= 1;
9466 lsal
.canonical
= NULL
;
9468 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9472 error (_("No default breakpoint address now."));
9476 /* Force almost all breakpoints to be in terms of the
9477 current_source_symtab (which is decode_line_1's default).
9478 This should produce the results we want almost all of the
9479 time while leaving default_breakpoint_* alone.
9481 ObjC: However, don't match an Objective-C method name which
9482 may have a '+' or '-' succeeded by a '['. */
9483 cursal
= get_current_source_symtab_and_line ();
9484 if (last_displayed_sal_is_valid ())
9486 const char *address
= NULL
;
9488 if (event_location_type (location
) == LINESPEC_LOCATION
)
9489 address
= get_linespec_location (location
);
9493 && strchr ("+-", address
[0]) != NULL
9494 && address
[1] != '['))
9496 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9497 get_last_displayed_symtab (),
9498 get_last_displayed_line (),
9499 canonical
, NULL
, NULL
);
9504 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9505 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9509 /* Convert each SAL into a real PC. Verify that the PC can be
9510 inserted as a breakpoint. If it can't throw an error. */
9513 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9517 for (i
= 0; i
< sals
->nelts
; i
++)
9518 resolve_sal_pc (&sals
->sals
[i
]);
9521 /* Fast tracepoints may have restrictions on valid locations. For
9522 instance, a fast tracepoint using a jump instead of a trap will
9523 likely have to overwrite more bytes than a trap would, and so can
9524 only be placed where the instruction is longer than the jump, or a
9525 multi-instruction sequence does not have a jump into the middle of
9529 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9530 struct symtabs_and_lines
*sals
)
9533 struct symtab_and_line
*sal
;
9535 struct cleanup
*old_chain
;
9537 for (i
= 0; i
< sals
->nelts
; i
++)
9539 struct gdbarch
*sarch
;
9541 sal
= &sals
->sals
[i
];
9543 sarch
= get_sal_arch (*sal
);
9544 /* We fall back to GDBARCH if there is no architecture
9545 associated with SAL. */
9548 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9549 old_chain
= make_cleanup (xfree
, msg
);
9552 error (_("May not have a fast tracepoint at %s%s"),
9553 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9555 do_cleanups (old_chain
);
9559 /* Given TOK, a string specification of condition and thread, as
9560 accepted by the 'break' command, extract the condition
9561 string and thread number and set *COND_STRING and *THREAD.
9562 PC identifies the context at which the condition should be parsed.
9563 If no condition is found, *COND_STRING is set to NULL.
9564 If no thread is found, *THREAD is set to -1. */
9567 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9568 char **cond_string
, int *thread
, int *task
,
9571 *cond_string
= NULL
;
9578 const char *end_tok
;
9580 const char *cond_start
= NULL
;
9581 const char *cond_end
= NULL
;
9583 tok
= skip_spaces_const (tok
);
9585 if ((*tok
== '"' || *tok
== ',') && rest
)
9587 *rest
= savestring (tok
, strlen (tok
));
9591 end_tok
= skip_to_space_const (tok
);
9593 toklen
= end_tok
- tok
;
9595 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9597 tok
= cond_start
= end_tok
+ 1;
9598 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9600 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9602 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9605 struct thread_info
*thr
;
9608 thr
= parse_thread_id (tok
, &tmptok
);
9610 error (_("Junk after thread keyword."));
9611 *thread
= thr
->global_num
;
9614 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9619 *task
= strtol (tok
, &tmptok
, 0);
9621 error (_("Junk after task keyword."));
9622 if (!valid_task_id (*task
))
9623 error (_("Unknown task %d."), *task
);
9628 *rest
= savestring (tok
, strlen (tok
));
9632 error (_("Junk at end of arguments."));
9636 /* Decode a static tracepoint marker spec. */
9638 static struct symtabs_and_lines
9639 decode_static_tracepoint_spec (const char **arg_p
)
9641 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9642 struct symtabs_and_lines sals
;
9643 struct cleanup
*old_chain
;
9644 const char *p
= &(*arg_p
)[3];
9649 p
= skip_spaces_const (p
);
9651 endp
= skip_to_space_const (p
);
9653 marker_str
= savestring (p
, endp
- p
);
9654 old_chain
= make_cleanup (xfree
, marker_str
);
9656 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9657 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9658 error (_("No known static tracepoint marker named %s"), marker_str
);
9660 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9661 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9663 for (i
= 0; i
< sals
.nelts
; i
++)
9665 struct static_tracepoint_marker
*marker
;
9667 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9669 init_sal (&sals
.sals
[i
]);
9671 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9672 sals
.sals
[i
].pc
= marker
->address
;
9674 release_static_tracepoint_marker (marker
);
9677 do_cleanups (old_chain
);
9683 /* See breakpoint.h. */
9686 create_breakpoint (struct gdbarch
*gdbarch
,
9687 const struct event_location
*location
, char *cond_string
,
9688 int thread
, char *extra_string
,
9690 int tempflag
, enum bptype type_wanted
,
9692 enum auto_boolean pending_break_support
,
9693 const struct breakpoint_ops
*ops
,
9694 int from_tty
, int enabled
, int internal
,
9697 struct linespec_result canonical
;
9698 struct cleanup
*bkpt_chain
= NULL
;
9701 int prev_bkpt_count
= breakpoint_count
;
9703 gdb_assert (ops
!= NULL
);
9705 /* If extra_string isn't useful, set it to NULL. */
9706 if (extra_string
!= NULL
&& *extra_string
== '\0')
9707 extra_string
= NULL
;
9711 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9713 CATCH (e
, RETURN_MASK_ERROR
)
9715 /* If caller is interested in rc value from parse, set
9717 if (e
.error
== NOT_FOUND_ERROR
)
9719 /* If pending breakpoint support is turned off, throw
9722 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9723 throw_exception (e
);
9725 exception_print (gdb_stderr
, e
);
9727 /* If pending breakpoint support is auto query and the user
9728 selects no, then simply return the error code. */
9729 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9730 && !nquery (_("Make %s pending on future shared library load? "),
9731 bptype_string (type_wanted
)))
9734 /* At this point, either the user was queried about setting
9735 a pending breakpoint and selected yes, or pending
9736 breakpoint behavior is on and thus a pending breakpoint
9737 is defaulted on behalf of the user. */
9741 throw_exception (e
);
9745 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9748 /* ----------------------------- SNIP -----------------------------
9749 Anything added to the cleanup chain beyond this point is assumed
9750 to be part of a breakpoint. If the breakpoint create succeeds
9751 then the memory is not reclaimed. */
9752 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9754 /* Resolve all line numbers to PC's and verify that the addresses
9755 are ok for the target. */
9759 struct linespec_sals
*iter
;
9761 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9762 breakpoint_sals_to_pc (&iter
->sals
);
9765 /* Fast tracepoints may have additional restrictions on location. */
9766 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9769 struct linespec_sals
*iter
;
9771 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9772 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9775 /* Verify that condition can be parsed, before setting any
9776 breakpoints. Allocate a separate condition expression for each
9783 struct linespec_sals
*lsal
;
9785 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9787 /* Here we only parse 'arg' to separate condition
9788 from thread number, so parsing in context of first
9789 sal is OK. When setting the breakpoint we'll
9790 re-parse it in context of each sal. */
9792 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9793 &cond_string
, &thread
, &task
, &rest
);
9795 make_cleanup (xfree
, cond_string
);
9797 make_cleanup (xfree
, rest
);
9799 extra_string
= rest
;
9801 extra_string
= NULL
;
9805 if (type_wanted
!= bp_dprintf
9806 && extra_string
!= NULL
&& *extra_string
!= '\0')
9807 error (_("Garbage '%s' at end of location"), extra_string
);
9809 /* Create a private copy of condition string. */
9812 cond_string
= xstrdup (cond_string
);
9813 make_cleanup (xfree
, cond_string
);
9815 /* Create a private copy of any extra string. */
9818 extra_string
= xstrdup (extra_string
);
9819 make_cleanup (xfree
, extra_string
);
9823 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9824 cond_string
, extra_string
, type_wanted
,
9825 tempflag
? disp_del
: disp_donttouch
,
9826 thread
, task
, ignore_count
, ops
,
9827 from_tty
, enabled
, internal
, flags
);
9831 struct breakpoint
*b
;
9833 if (is_tracepoint_type (type_wanted
))
9835 struct tracepoint
*t
;
9837 t
= new tracepoint ();
9841 b
= new breakpoint ();
9843 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9844 b
->location
= copy_event_location (location
);
9847 b
->cond_string
= NULL
;
9850 /* Create a private copy of condition string. */
9853 cond_string
= xstrdup (cond_string
);
9854 make_cleanup (xfree
, cond_string
);
9856 b
->cond_string
= cond_string
;
9860 /* Create a private copy of any extra string. */
9861 if (extra_string
!= NULL
)
9863 extra_string
= xstrdup (extra_string
);
9864 make_cleanup (xfree
, extra_string
);
9866 b
->extra_string
= extra_string
;
9867 b
->ignore_count
= ignore_count
;
9868 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9869 b
->condition_not_parsed
= 1;
9870 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9871 if ((type_wanted
!= bp_breakpoint
9872 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9873 b
->pspace
= current_program_space
;
9875 install_breakpoint (internal
, b
, 0);
9878 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9880 warning (_("Multiple breakpoints were set.\nUse the "
9881 "\"delete\" command to delete unwanted breakpoints."));
9882 prev_breakpoint_count
= prev_bkpt_count
;
9885 /* That's it. Discard the cleanups for data inserted into the
9887 discard_cleanups (bkpt_chain
);
9889 /* error call may happen here - have BKPT_CHAIN already discarded. */
9890 update_global_location_list (UGLL_MAY_INSERT
);
9895 /* Set a breakpoint.
9896 ARG is a string describing breakpoint address,
9897 condition, and thread.
9898 FLAG specifies if a breakpoint is hardware on,
9899 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9903 break_command_1 (char *arg
, int flag
, int from_tty
)
9905 int tempflag
= flag
& BP_TEMPFLAG
;
9906 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9907 ? bp_hardware_breakpoint
9909 struct breakpoint_ops
*ops
;
9911 event_location_up location
= string_to_event_location (&arg
, current_language
);
9913 /* Matching breakpoints on probes. */
9914 if (location
!= NULL
9915 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9916 ops
= &bkpt_probe_breakpoint_ops
;
9918 ops
= &bkpt_breakpoint_ops
;
9920 create_breakpoint (get_current_arch (),
9922 NULL
, 0, arg
, 1 /* parse arg */,
9923 tempflag
, type_wanted
,
9924 0 /* Ignore count */,
9925 pending_break_support
,
9933 /* Helper function for break_command_1 and disassemble_command. */
9936 resolve_sal_pc (struct symtab_and_line
*sal
)
9940 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9942 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9943 error (_("No line %d in file \"%s\"."),
9944 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9947 /* If this SAL corresponds to a breakpoint inserted using a line
9948 number, then skip the function prologue if necessary. */
9949 if (sal
->explicit_line
)
9950 skip_prologue_sal (sal
);
9953 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9955 const struct blockvector
*bv
;
9956 const struct block
*b
;
9959 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9960 SYMTAB_COMPUNIT (sal
->symtab
));
9963 sym
= block_linkage_function (b
);
9966 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9967 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9972 /* It really is worthwhile to have the section, so we'll
9973 just have to look harder. This case can be executed
9974 if we have line numbers but no functions (as can
9975 happen in assembly source). */
9977 struct bound_minimal_symbol msym
;
9978 struct cleanup
*old_chain
= save_current_space_and_thread ();
9980 switch_to_program_space_and_thread (sal
->pspace
);
9982 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9984 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9986 do_cleanups (old_chain
);
9993 break_command (char *arg
, int from_tty
)
9995 break_command_1 (arg
, 0, from_tty
);
9999 tbreak_command (char *arg
, int from_tty
)
10001 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10005 hbreak_command (char *arg
, int from_tty
)
10007 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10011 thbreak_command (char *arg
, int from_tty
)
10013 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10017 stop_command (char *arg
, int from_tty
)
10019 printf_filtered (_("Specify the type of breakpoint to set.\n\
10020 Usage: stop in <function | address>\n\
10021 stop at <line>\n"));
10025 stopin_command (char *arg
, int from_tty
)
10029 if (arg
== (char *) NULL
)
10031 else if (*arg
!= '*')
10033 char *argptr
= arg
;
10036 /* Look for a ':'. If this is a line number specification, then
10037 say it is bad, otherwise, it should be an address or
10038 function/method name. */
10039 while (*argptr
&& !hasColon
)
10041 hasColon
= (*argptr
== ':');
10046 badInput
= (*argptr
!= ':'); /* Not a class::method */
10048 badInput
= isdigit (*arg
); /* a simple line number */
10052 printf_filtered (_("Usage: stop in <function | address>\n"));
10054 break_command_1 (arg
, 0, from_tty
);
10058 stopat_command (char *arg
, int from_tty
)
10062 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10066 char *argptr
= arg
;
10069 /* Look for a ':'. If there is a '::' then get out, otherwise
10070 it is probably a line number. */
10071 while (*argptr
&& !hasColon
)
10073 hasColon
= (*argptr
== ':');
10078 badInput
= (*argptr
== ':'); /* we have class::method */
10080 badInput
= !isdigit (*arg
); /* not a line number */
10084 printf_filtered (_("Usage: stop at <line>\n"));
10086 break_command_1 (arg
, 0, from_tty
);
10089 /* The dynamic printf command is mostly like a regular breakpoint, but
10090 with a prewired command list consisting of a single output command,
10091 built from extra arguments supplied on the dprintf command
10095 dprintf_command (char *arg
, int from_tty
)
10097 event_location_up location
= string_to_event_location (&arg
, current_language
);
10099 /* If non-NULL, ARG should have been advanced past the location;
10100 the next character must be ','. */
10103 if (arg
[0] != ',' || arg
[1] == '\0')
10104 error (_("Format string required"));
10107 /* Skip the comma. */
10112 create_breakpoint (get_current_arch (),
10114 NULL
, 0, arg
, 1 /* parse arg */,
10116 0 /* Ignore count */,
10117 pending_break_support
,
10118 &dprintf_breakpoint_ops
,
10126 agent_printf_command (char *arg
, int from_tty
)
10128 error (_("May only run agent-printf on the target"));
10131 /* Implement the "breakpoint_hit" breakpoint_ops method for
10132 ranged breakpoints. */
10135 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10136 struct address_space
*aspace
,
10138 const struct target_waitstatus
*ws
)
10140 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10141 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10144 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10145 bl
->length
, aspace
, bp_addr
);
10148 /* Implement the "resources_needed" breakpoint_ops method for
10149 ranged breakpoints. */
10152 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10154 return target_ranged_break_num_registers ();
10157 /* Implement the "print_it" breakpoint_ops method for
10158 ranged breakpoints. */
10160 static enum print_stop_action
10161 print_it_ranged_breakpoint (bpstat bs
)
10163 struct breakpoint
*b
= bs
->breakpoint_at
;
10164 struct bp_location
*bl
= b
->loc
;
10165 struct ui_out
*uiout
= current_uiout
;
10167 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10169 /* Ranged breakpoints have only one location. */
10170 gdb_assert (bl
&& bl
->next
== NULL
);
10172 annotate_breakpoint (b
->number
);
10174 maybe_print_thread_hit_breakpoint (uiout
);
10176 if (b
->disposition
== disp_del
)
10177 uiout
->text ("Temporary ranged breakpoint ");
10179 uiout
->text ("Ranged breakpoint ");
10180 if (uiout
->is_mi_like_p ())
10182 uiout
->field_string ("reason",
10183 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10184 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10186 uiout
->field_int ("bkptno", b
->number
);
10187 uiout
->text (", ");
10189 return PRINT_SRC_AND_LOC
;
10192 /* Implement the "print_one" breakpoint_ops method for
10193 ranged breakpoints. */
10196 print_one_ranged_breakpoint (struct breakpoint
*b
,
10197 struct bp_location
**last_loc
)
10199 struct bp_location
*bl
= b
->loc
;
10200 struct value_print_options opts
;
10201 struct ui_out
*uiout
= current_uiout
;
10203 /* Ranged breakpoints have only one location. */
10204 gdb_assert (bl
&& bl
->next
== NULL
);
10206 get_user_print_options (&opts
);
10208 if (opts
.addressprint
)
10209 /* We don't print the address range here, it will be printed later
10210 by print_one_detail_ranged_breakpoint. */
10211 uiout
->field_skip ("addr");
10212 annotate_field (5);
10213 print_breakpoint_location (b
, bl
);
10217 /* Implement the "print_one_detail" breakpoint_ops method for
10218 ranged breakpoints. */
10221 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10222 struct ui_out
*uiout
)
10224 CORE_ADDR address_start
, address_end
;
10225 struct bp_location
*bl
= b
->loc
;
10230 address_start
= bl
->address
;
10231 address_end
= address_start
+ bl
->length
- 1;
10233 uiout
->text ("\taddress range: ");
10234 stb
.printf ("[%s, %s]",
10235 print_core_address (bl
->gdbarch
, address_start
),
10236 print_core_address (bl
->gdbarch
, address_end
));
10237 uiout
->field_stream ("addr", stb
);
10238 uiout
->text ("\n");
10241 /* Implement the "print_mention" breakpoint_ops method for
10242 ranged breakpoints. */
10245 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10247 struct bp_location
*bl
= b
->loc
;
10248 struct ui_out
*uiout
= current_uiout
;
10251 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10253 if (uiout
->is_mi_like_p ())
10256 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10257 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10258 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10261 /* Implement the "print_recreate" breakpoint_ops method for
10262 ranged breakpoints. */
10265 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10267 fprintf_unfiltered (fp
, "break-range %s, %s",
10268 event_location_to_string (b
->location
.get ()),
10269 event_location_to_string (b
->location_range_end
.get ()));
10270 print_recreate_thread (b
, fp
);
10273 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10275 static struct breakpoint_ops ranged_breakpoint_ops
;
10277 /* Find the address where the end of the breakpoint range should be
10278 placed, given the SAL of the end of the range. This is so that if
10279 the user provides a line number, the end of the range is set to the
10280 last instruction of the given line. */
10283 find_breakpoint_range_end (struct symtab_and_line sal
)
10287 /* If the user provided a PC value, use it. Otherwise,
10288 find the address of the end of the given location. */
10289 if (sal
.explicit_pc
)
10296 ret
= find_line_pc_range (sal
, &start
, &end
);
10298 error (_("Could not find location of the end of the range."));
10300 /* find_line_pc_range returns the start of the next line. */
10307 /* Implement the "break-range" CLI command. */
10310 break_range_command (char *arg
, int from_tty
)
10312 char *arg_start
, *addr_string_start
;
10313 struct linespec_result canonical_start
, canonical_end
;
10314 int bp_count
, can_use_bp
, length
;
10316 struct breakpoint
*b
;
10317 struct symtab_and_line sal_start
, sal_end
;
10318 struct cleanup
*cleanup_bkpt
;
10319 struct linespec_sals
*lsal_start
, *lsal_end
;
10321 /* We don't support software ranged breakpoints. */
10322 if (target_ranged_break_num_registers () < 0)
10323 error (_("This target does not support hardware ranged breakpoints."));
10325 bp_count
= hw_breakpoint_used_count ();
10326 bp_count
+= target_ranged_break_num_registers ();
10327 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10329 if (can_use_bp
< 0)
10330 error (_("Hardware breakpoints used exceeds limit."));
10332 arg
= skip_spaces (arg
);
10333 if (arg
== NULL
|| arg
[0] == '\0')
10334 error(_("No address range specified."));
10337 event_location_up start_location
= string_to_event_location (&arg
,
10339 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10342 error (_("Too few arguments."));
10343 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10344 error (_("Could not find location of the beginning of the range."));
10346 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10348 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10349 || lsal_start
->sals
.nelts
!= 1)
10350 error (_("Cannot create a ranged breakpoint with multiple locations."));
10352 sal_start
= lsal_start
->sals
.sals
[0];
10353 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10354 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10356 arg
++; /* Skip the comma. */
10357 arg
= skip_spaces (arg
);
10359 /* Parse the end location. */
10363 /* We call decode_line_full directly here instead of using
10364 parse_breakpoint_sals because we need to specify the start location's
10365 symtab and line as the default symtab and line for the end of the
10366 range. This makes it possible to have ranges like "foo.c:27, +14",
10367 where +14 means 14 lines from the start location. */
10368 event_location_up end_location
= string_to_event_location (&arg
,
10370 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10371 sal_start
.symtab
, sal_start
.line
,
10372 &canonical_end
, NULL
, NULL
);
10374 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10375 error (_("Could not find location of the end of the range."));
10377 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10378 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10379 || lsal_end
->sals
.nelts
!= 1)
10380 error (_("Cannot create a ranged breakpoint with multiple locations."));
10382 sal_end
= lsal_end
->sals
.sals
[0];
10384 end
= find_breakpoint_range_end (sal_end
);
10385 if (sal_start
.pc
> end
)
10386 error (_("Invalid address range, end precedes start."));
10388 length
= end
- sal_start
.pc
+ 1;
10390 /* Length overflowed. */
10391 error (_("Address range too large."));
10392 else if (length
== 1)
10394 /* This range is simple enough to be handled by
10395 the `hbreak' command. */
10396 hbreak_command (addr_string_start
, 1);
10398 do_cleanups (cleanup_bkpt
);
10403 /* Now set up the breakpoint. */
10404 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10405 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10406 set_breakpoint_count (breakpoint_count
+ 1);
10407 b
->number
= breakpoint_count
;
10408 b
->disposition
= disp_donttouch
;
10409 b
->location
= std::move (start_location
);
10410 b
->location_range_end
= std::move (end_location
);
10411 b
->loc
->length
= length
;
10413 do_cleanups (cleanup_bkpt
);
10416 observer_notify_breakpoint_created (b
);
10417 update_global_location_list (UGLL_MAY_INSERT
);
10420 /* Return non-zero if EXP is verified as constant. Returned zero
10421 means EXP is variable. Also the constant detection may fail for
10422 some constant expressions and in such case still falsely return
10426 watchpoint_exp_is_const (const struct expression
*exp
)
10428 int i
= exp
->nelts
;
10434 /* We are only interested in the descriptor of each element. */
10435 operator_length (exp
, i
, &oplenp
, &argsp
);
10438 switch (exp
->elts
[i
].opcode
)
10448 case BINOP_LOGICAL_AND
:
10449 case BINOP_LOGICAL_OR
:
10450 case BINOP_BITWISE_AND
:
10451 case BINOP_BITWISE_IOR
:
10452 case BINOP_BITWISE_XOR
:
10454 case BINOP_NOTEQUAL
:
10481 case OP_OBJC_NSSTRING
:
10484 case UNOP_LOGICAL_NOT
:
10485 case UNOP_COMPLEMENT
:
10490 case UNOP_CAST_TYPE
:
10491 case UNOP_REINTERPRET_CAST
:
10492 case UNOP_DYNAMIC_CAST
:
10493 /* Unary, binary and ternary operators: We have to check
10494 their operands. If they are constant, then so is the
10495 result of that operation. For instance, if A and B are
10496 determined to be constants, then so is "A + B".
10498 UNOP_IND is one exception to the rule above, because the
10499 value of *ADDR is not necessarily a constant, even when
10504 /* Check whether the associated symbol is a constant.
10506 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10507 possible that a buggy compiler could mark a variable as
10508 constant even when it is not, and TYPE_CONST would return
10509 true in this case, while SYMBOL_CLASS wouldn't.
10511 We also have to check for function symbols because they
10512 are always constant. */
10514 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10516 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10517 && SYMBOL_CLASS (s
) != LOC_CONST
10518 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10523 /* The default action is to return 0 because we are using
10524 the optimistic approach here: If we don't know something,
10525 then it is not a constant. */
10534 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10537 dtor_watchpoint (struct breakpoint
*self
)
10539 struct watchpoint
*w
= (struct watchpoint
*) self
;
10541 xfree (w
->exp_string
);
10542 xfree (w
->exp_string_reparse
);
10543 value_free (w
->val
);
10545 base_breakpoint_ops
.dtor (self
);
10548 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10551 re_set_watchpoint (struct breakpoint
*b
)
10553 struct watchpoint
*w
= (struct watchpoint
*) b
;
10555 /* Watchpoint can be either on expression using entirely global
10556 variables, or it can be on local variables.
10558 Watchpoints of the first kind are never auto-deleted, and even
10559 persist across program restarts. Since they can use variables
10560 from shared libraries, we need to reparse expression as libraries
10561 are loaded and unloaded.
10563 Watchpoints on local variables can also change meaning as result
10564 of solib event. For example, if a watchpoint uses both a local
10565 and a global variables in expression, it's a local watchpoint,
10566 but unloading of a shared library will make the expression
10567 invalid. This is not a very common use case, but we still
10568 re-evaluate expression, to avoid surprises to the user.
10570 Note that for local watchpoints, we re-evaluate it only if
10571 watchpoints frame id is still valid. If it's not, it means the
10572 watchpoint is out of scope and will be deleted soon. In fact,
10573 I'm not sure we'll ever be called in this case.
10575 If a local watchpoint's frame id is still valid, then
10576 w->exp_valid_block is likewise valid, and we can safely use it.
10578 Don't do anything about disabled watchpoints, since they will be
10579 reevaluated again when enabled. */
10580 update_watchpoint (w
, 1 /* reparse */);
10583 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10586 insert_watchpoint (struct bp_location
*bl
)
10588 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10589 int length
= w
->exact
? 1 : bl
->length
;
10591 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10592 w
->cond_exp
.get ());
10595 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10598 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10600 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10601 int length
= w
->exact
? 1 : bl
->length
;
10603 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10604 w
->cond_exp
.get ());
10608 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10609 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10610 const struct target_waitstatus
*ws
)
10612 struct breakpoint
*b
= bl
->owner
;
10613 struct watchpoint
*w
= (struct watchpoint
*) b
;
10615 /* Continuable hardware watchpoints are treated as non-existent if the
10616 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10617 some data address). Otherwise gdb won't stop on a break instruction
10618 in the code (not from a breakpoint) when a hardware watchpoint has
10619 been defined. Also skip watchpoints which we know did not trigger
10620 (did not match the data address). */
10621 if (is_hardware_watchpoint (b
)
10622 && w
->watchpoint_triggered
== watch_triggered_no
)
10629 check_status_watchpoint (bpstat bs
)
10631 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10633 bpstat_check_watchpoint (bs
);
10636 /* Implement the "resources_needed" breakpoint_ops method for
10637 hardware watchpoints. */
10640 resources_needed_watchpoint (const struct bp_location
*bl
)
10642 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10643 int length
= w
->exact
? 1 : bl
->length
;
10645 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10648 /* Implement the "works_in_software_mode" breakpoint_ops method for
10649 hardware watchpoints. */
10652 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10654 /* Read and access watchpoints only work with hardware support. */
10655 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10658 static enum print_stop_action
10659 print_it_watchpoint (bpstat bs
)
10661 struct cleanup
*old_chain
;
10662 struct breakpoint
*b
;
10663 enum print_stop_action result
;
10664 struct watchpoint
*w
;
10665 struct ui_out
*uiout
= current_uiout
;
10667 gdb_assert (bs
->bp_location_at
!= NULL
);
10669 b
= bs
->breakpoint_at
;
10670 w
= (struct watchpoint
*) b
;
10672 old_chain
= make_cleanup (null_cleanup
, NULL
);
10674 annotate_watchpoint (b
->number
);
10675 maybe_print_thread_hit_breakpoint (uiout
);
10681 case bp_watchpoint
:
10682 case bp_hardware_watchpoint
:
10683 if (uiout
->is_mi_like_p ())
10684 uiout
->field_string
10685 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10687 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10688 uiout
->text ("\nOld value = ");
10689 watchpoint_value_print (bs
->old_val
, &stb
);
10690 uiout
->field_stream ("old", stb
);
10691 uiout
->text ("\nNew value = ");
10692 watchpoint_value_print (w
->val
, &stb
);
10693 uiout
->field_stream ("new", stb
);
10694 uiout
->text ("\n");
10695 /* More than one watchpoint may have been triggered. */
10696 result
= PRINT_UNKNOWN
;
10699 case bp_read_watchpoint
:
10700 if (uiout
->is_mi_like_p ())
10701 uiout
->field_string
10702 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10704 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10705 uiout
->text ("\nValue = ");
10706 watchpoint_value_print (w
->val
, &stb
);
10707 uiout
->field_stream ("value", stb
);
10708 uiout
->text ("\n");
10709 result
= PRINT_UNKNOWN
;
10712 case bp_access_watchpoint
:
10713 if (bs
->old_val
!= NULL
)
10715 if (uiout
->is_mi_like_p ())
10716 uiout
->field_string
10718 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10720 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10721 uiout
->text ("\nOld value = ");
10722 watchpoint_value_print (bs
->old_val
, &stb
);
10723 uiout
->field_stream ("old", stb
);
10724 uiout
->text ("\nNew value = ");
10729 if (uiout
->is_mi_like_p ())
10730 uiout
->field_string
10732 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10733 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10734 uiout
->text ("\nValue = ");
10736 watchpoint_value_print (w
->val
, &stb
);
10737 uiout
->field_stream ("new", stb
);
10738 uiout
->text ("\n");
10739 result
= PRINT_UNKNOWN
;
10742 result
= PRINT_UNKNOWN
;
10745 do_cleanups (old_chain
);
10749 /* Implement the "print_mention" breakpoint_ops method for hardware
10753 print_mention_watchpoint (struct breakpoint
*b
)
10755 struct watchpoint
*w
= (struct watchpoint
*) b
;
10756 struct ui_out
*uiout
= current_uiout
;
10757 const char *tuple_name
;
10761 case bp_watchpoint
:
10762 uiout
->text ("Watchpoint ");
10763 tuple_name
= "wpt";
10765 case bp_hardware_watchpoint
:
10766 uiout
->text ("Hardware watchpoint ");
10767 tuple_name
= "wpt";
10769 case bp_read_watchpoint
:
10770 uiout
->text ("Hardware read watchpoint ");
10771 tuple_name
= "hw-rwpt";
10773 case bp_access_watchpoint
:
10774 uiout
->text ("Hardware access (read/write) watchpoint ");
10775 tuple_name
= "hw-awpt";
10778 internal_error (__FILE__
, __LINE__
,
10779 _("Invalid hardware watchpoint type."));
10782 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10783 uiout
->field_int ("number", b
->number
);
10784 uiout
->text (": ");
10785 uiout
->field_string ("exp", w
->exp_string
);
10788 /* Implement the "print_recreate" breakpoint_ops method for
10792 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10794 struct watchpoint
*w
= (struct watchpoint
*) b
;
10798 case bp_watchpoint
:
10799 case bp_hardware_watchpoint
:
10800 fprintf_unfiltered (fp
, "watch");
10802 case bp_read_watchpoint
:
10803 fprintf_unfiltered (fp
, "rwatch");
10805 case bp_access_watchpoint
:
10806 fprintf_unfiltered (fp
, "awatch");
10809 internal_error (__FILE__
, __LINE__
,
10810 _("Invalid watchpoint type."));
10813 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10814 print_recreate_thread (b
, fp
);
10817 /* Implement the "explains_signal" breakpoint_ops method for
10821 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10823 /* A software watchpoint cannot cause a signal other than
10824 GDB_SIGNAL_TRAP. */
10825 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10831 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10833 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10835 /* Implement the "insert" breakpoint_ops method for
10836 masked hardware watchpoints. */
10839 insert_masked_watchpoint (struct bp_location
*bl
)
10841 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10843 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10844 bl
->watchpoint_type
);
10847 /* Implement the "remove" breakpoint_ops method for
10848 masked hardware watchpoints. */
10851 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10853 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10855 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10856 bl
->watchpoint_type
);
10859 /* Implement the "resources_needed" breakpoint_ops method for
10860 masked hardware watchpoints. */
10863 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10865 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10867 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10870 /* Implement the "works_in_software_mode" breakpoint_ops method for
10871 masked hardware watchpoints. */
10874 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10879 /* Implement the "print_it" breakpoint_ops method for
10880 masked hardware watchpoints. */
10882 static enum print_stop_action
10883 print_it_masked_watchpoint (bpstat bs
)
10885 struct breakpoint
*b
= bs
->breakpoint_at
;
10886 struct ui_out
*uiout
= current_uiout
;
10888 /* Masked watchpoints have only one location. */
10889 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10891 annotate_watchpoint (b
->number
);
10892 maybe_print_thread_hit_breakpoint (uiout
);
10896 case bp_hardware_watchpoint
:
10897 if (uiout
->is_mi_like_p ())
10898 uiout
->field_string
10899 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10902 case bp_read_watchpoint
:
10903 if (uiout
->is_mi_like_p ())
10904 uiout
->field_string
10905 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10908 case bp_access_watchpoint
:
10909 if (uiout
->is_mi_like_p ())
10910 uiout
->field_string
10912 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10915 internal_error (__FILE__
, __LINE__
,
10916 _("Invalid hardware watchpoint type."));
10920 uiout
->text (_("\n\
10921 Check the underlying instruction at PC for the memory\n\
10922 address and value which triggered this watchpoint.\n"));
10923 uiout
->text ("\n");
10925 /* More than one watchpoint may have been triggered. */
10926 return PRINT_UNKNOWN
;
10929 /* Implement the "print_one_detail" breakpoint_ops method for
10930 masked hardware watchpoints. */
10933 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10934 struct ui_out
*uiout
)
10936 struct watchpoint
*w
= (struct watchpoint
*) b
;
10938 /* Masked watchpoints have only one location. */
10939 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10941 uiout
->text ("\tmask ");
10942 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10943 uiout
->text ("\n");
10946 /* Implement the "print_mention" breakpoint_ops method for
10947 masked hardware watchpoints. */
10950 print_mention_masked_watchpoint (struct breakpoint
*b
)
10952 struct watchpoint
*w
= (struct watchpoint
*) b
;
10953 struct ui_out
*uiout
= current_uiout
;
10954 const char *tuple_name
;
10958 case bp_hardware_watchpoint
:
10959 uiout
->text ("Masked hardware watchpoint ");
10960 tuple_name
= "wpt";
10962 case bp_read_watchpoint
:
10963 uiout
->text ("Masked hardware read watchpoint ");
10964 tuple_name
= "hw-rwpt";
10966 case bp_access_watchpoint
:
10967 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10968 tuple_name
= "hw-awpt";
10971 internal_error (__FILE__
, __LINE__
,
10972 _("Invalid hardware watchpoint type."));
10975 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10976 uiout
->field_int ("number", b
->number
);
10977 uiout
->text (": ");
10978 uiout
->field_string ("exp", w
->exp_string
);
10981 /* Implement the "print_recreate" breakpoint_ops method for
10982 masked hardware watchpoints. */
10985 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10987 struct watchpoint
*w
= (struct watchpoint
*) b
;
10992 case bp_hardware_watchpoint
:
10993 fprintf_unfiltered (fp
, "watch");
10995 case bp_read_watchpoint
:
10996 fprintf_unfiltered (fp
, "rwatch");
10998 case bp_access_watchpoint
:
10999 fprintf_unfiltered (fp
, "awatch");
11002 internal_error (__FILE__
, __LINE__
,
11003 _("Invalid hardware watchpoint type."));
11006 sprintf_vma (tmp
, w
->hw_wp_mask
);
11007 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11008 print_recreate_thread (b
, fp
);
11011 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11013 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11015 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11018 is_masked_watchpoint (const struct breakpoint
*b
)
11020 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11023 /* accessflag: hw_write: watch write,
11024 hw_read: watch read,
11025 hw_access: watch access (read or write) */
11027 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11028 int just_location
, int internal
)
11030 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11031 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11032 struct value
*val
, *mark
, *result
;
11033 int saved_bitpos
= 0, saved_bitsize
= 0;
11034 const char *exp_start
= NULL
;
11035 const char *exp_end
= NULL
;
11036 const char *tok
, *end_tok
;
11038 const char *cond_start
= NULL
;
11039 const char *cond_end
= NULL
;
11040 enum bptype bp_type
;
11043 /* Flag to indicate whether we are going to use masks for
11044 the hardware watchpoint. */
11046 CORE_ADDR mask
= 0;
11047 struct watchpoint
*w
;
11049 struct cleanup
*back_to
;
11051 /* Make sure that we actually have parameters to parse. */
11052 if (arg
!= NULL
&& arg
[0] != '\0')
11054 const char *value_start
;
11056 exp_end
= arg
+ strlen (arg
);
11058 /* Look for "parameter value" pairs at the end
11059 of the arguments string. */
11060 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11062 /* Skip whitespace at the end of the argument list. */
11063 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11066 /* Find the beginning of the last token.
11067 This is the value of the parameter. */
11068 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11070 value_start
= tok
+ 1;
11072 /* Skip whitespace. */
11073 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11078 /* Find the beginning of the second to last token.
11079 This is the parameter itself. */
11080 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11083 toklen
= end_tok
- tok
+ 1;
11085 if (toklen
== 6 && startswith (tok
, "thread"))
11087 struct thread_info
*thr
;
11088 /* At this point we've found a "thread" token, which means
11089 the user is trying to set a watchpoint that triggers
11090 only in a specific thread. */
11094 error(_("You can specify only one thread."));
11096 /* Extract the thread ID from the next token. */
11097 thr
= parse_thread_id (value_start
, &endp
);
11099 /* Check if the user provided a valid thread ID. */
11100 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11101 invalid_thread_id_error (value_start
);
11103 thread
= thr
->global_num
;
11105 else if (toklen
== 4 && startswith (tok
, "mask"))
11107 /* We've found a "mask" token, which means the user wants to
11108 create a hardware watchpoint that is going to have the mask
11110 struct value
*mask_value
, *mark
;
11113 error(_("You can specify only one mask."));
11115 use_mask
= just_location
= 1;
11117 mark
= value_mark ();
11118 mask_value
= parse_to_comma_and_eval (&value_start
);
11119 mask
= value_as_address (mask_value
);
11120 value_free_to_mark (mark
);
11123 /* We didn't recognize what we found. We should stop here. */
11126 /* Truncate the string and get rid of the "parameter value" pair before
11127 the arguments string is parsed by the parse_exp_1 function. */
11134 /* Parse the rest of the arguments. From here on out, everything
11135 is in terms of a newly allocated string instead of the original
11137 innermost_block
= NULL
;
11138 expression
= savestring (arg
, exp_end
- arg
);
11139 back_to
= make_cleanup (xfree
, expression
);
11140 exp_start
= arg
= expression
;
11141 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11143 /* Remove trailing whitespace from the expression before saving it.
11144 This makes the eventual display of the expression string a bit
11146 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11149 /* Checking if the expression is not constant. */
11150 if (watchpoint_exp_is_const (exp
.get ()))
11154 len
= exp_end
- exp_start
;
11155 while (len
> 0 && isspace (exp_start
[len
- 1]))
11157 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11160 exp_valid_block
= innermost_block
;
11161 mark
= value_mark ();
11162 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11164 if (val
!= NULL
&& just_location
)
11166 saved_bitpos
= value_bitpos (val
);
11167 saved_bitsize
= value_bitsize (val
);
11174 exp_valid_block
= NULL
;
11175 val
= value_addr (result
);
11176 release_value (val
);
11177 value_free_to_mark (mark
);
11181 ret
= target_masked_watch_num_registers (value_as_address (val
),
11184 error (_("This target does not support masked watchpoints."));
11185 else if (ret
== -2)
11186 error (_("Invalid mask or memory region."));
11189 else if (val
!= NULL
)
11190 release_value (val
);
11192 tok
= skip_spaces_const (arg
);
11193 end_tok
= skip_to_space_const (tok
);
11195 toklen
= end_tok
- tok
;
11196 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11198 innermost_block
= NULL
;
11199 tok
= cond_start
= end_tok
+ 1;
11200 parse_exp_1 (&tok
, 0, 0, 0);
11202 /* The watchpoint expression may not be local, but the condition
11203 may still be. E.g.: `watch global if local > 0'. */
11204 cond_exp_valid_block
= innermost_block
;
11209 error (_("Junk at end of command."));
11211 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11213 /* Save this because create_internal_breakpoint below invalidates
11215 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11217 /* If the expression is "local", then set up a "watchpoint scope"
11218 breakpoint at the point where we've left the scope of the watchpoint
11219 expression. Create the scope breakpoint before the watchpoint, so
11220 that we will encounter it first in bpstat_stop_status. */
11221 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11223 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11225 if (frame_id_p (caller_frame_id
))
11227 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11228 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11231 = create_internal_breakpoint (caller_arch
, caller_pc
,
11232 bp_watchpoint_scope
,
11233 &momentary_breakpoint_ops
);
11235 /* create_internal_breakpoint could invalidate WP_FRAME. */
11238 scope_breakpoint
->enable_state
= bp_enabled
;
11240 /* Automatically delete the breakpoint when it hits. */
11241 scope_breakpoint
->disposition
= disp_del
;
11243 /* Only break in the proper frame (help with recursion). */
11244 scope_breakpoint
->frame_id
= caller_frame_id
;
11246 /* Set the address at which we will stop. */
11247 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11248 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11249 scope_breakpoint
->loc
->address
11250 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11251 scope_breakpoint
->loc
->requested_address
,
11252 scope_breakpoint
->type
);
11256 /* Now set up the breakpoint. We create all watchpoints as hardware
11257 watchpoints here even if hardware watchpoints are turned off, a call
11258 to update_watchpoint later in this function will cause the type to
11259 drop back to bp_watchpoint (software watchpoint) if required. */
11261 if (accessflag
== hw_read
)
11262 bp_type
= bp_read_watchpoint
;
11263 else if (accessflag
== hw_access
)
11264 bp_type
= bp_access_watchpoint
;
11266 bp_type
= bp_hardware_watchpoint
;
11268 w
= new watchpoint ();
11271 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11272 &masked_watchpoint_breakpoint_ops
);
11274 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11275 &watchpoint_breakpoint_ops
);
11276 b
->thread
= thread
;
11277 b
->disposition
= disp_donttouch
;
11278 b
->pspace
= current_program_space
;
11279 w
->exp
= std::move (exp
);
11280 w
->exp_valid_block
= exp_valid_block
;
11281 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11284 struct type
*t
= value_type (val
);
11285 CORE_ADDR addr
= value_as_address (val
);
11287 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11289 std::string name
= type_to_string (t
);
11291 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
.c_str (),
11292 core_addr_to_string (addr
));
11294 w
->exp_string
= xstrprintf ("-location %.*s",
11295 (int) (exp_end
- exp_start
), exp_start
);
11297 /* The above expression is in C. */
11298 b
->language
= language_c
;
11301 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11305 w
->hw_wp_mask
= mask
;
11310 w
->val_bitpos
= saved_bitpos
;
11311 w
->val_bitsize
= saved_bitsize
;
11316 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11318 b
->cond_string
= 0;
11320 if (frame_id_p (watchpoint_frame
))
11322 w
->watchpoint_frame
= watchpoint_frame
;
11323 w
->watchpoint_thread
= inferior_ptid
;
11327 w
->watchpoint_frame
= null_frame_id
;
11328 w
->watchpoint_thread
= null_ptid
;
11331 if (scope_breakpoint
!= NULL
)
11333 /* The scope breakpoint is related to the watchpoint. We will
11334 need to act on them together. */
11335 b
->related_breakpoint
= scope_breakpoint
;
11336 scope_breakpoint
->related_breakpoint
= b
;
11339 if (!just_location
)
11340 value_free_to_mark (mark
);
11344 /* Finally update the new watchpoint. This creates the locations
11345 that should be inserted. */
11346 update_watchpoint (w
, 1);
11348 CATCH (e
, RETURN_MASK_ALL
)
11350 delete_breakpoint (b
);
11351 throw_exception (e
);
11355 install_breakpoint (internal
, b
, 1);
11356 do_cleanups (back_to
);
11359 /* Return count of debug registers needed to watch the given expression.
11360 If the watchpoint cannot be handled in hardware return zero. */
11363 can_use_hardware_watchpoint (struct value
*v
)
11365 int found_memory_cnt
= 0;
11366 struct value
*head
= v
;
11368 /* Did the user specifically forbid us to use hardware watchpoints? */
11369 if (!can_use_hw_watchpoints
)
11372 /* Make sure that the value of the expression depends only upon
11373 memory contents, and values computed from them within GDB. If we
11374 find any register references or function calls, we can't use a
11375 hardware watchpoint.
11377 The idea here is that evaluating an expression generates a series
11378 of values, one holding the value of every subexpression. (The
11379 expression a*b+c has five subexpressions: a, b, a*b, c, and
11380 a*b+c.) GDB's values hold almost enough information to establish
11381 the criteria given above --- they identify memory lvalues,
11382 register lvalues, computed values, etcetera. So we can evaluate
11383 the expression, and then scan the chain of values that leaves
11384 behind to decide whether we can detect any possible change to the
11385 expression's final value using only hardware watchpoints.
11387 However, I don't think that the values returned by inferior
11388 function calls are special in any way. So this function may not
11389 notice that an expression involving an inferior function call
11390 can't be watched with hardware watchpoints. FIXME. */
11391 for (; v
; v
= value_next (v
))
11393 if (VALUE_LVAL (v
) == lval_memory
)
11395 if (v
!= head
&& value_lazy (v
))
11396 /* A lazy memory lvalue in the chain is one that GDB never
11397 needed to fetch; we either just used its address (e.g.,
11398 `a' in `a.b') or we never needed it at all (e.g., `a'
11399 in `a,b'). This doesn't apply to HEAD; if that is
11400 lazy then it was not readable, but watch it anyway. */
11404 /* Ahh, memory we actually used! Check if we can cover
11405 it with hardware watchpoints. */
11406 struct type
*vtype
= check_typedef (value_type (v
));
11408 /* We only watch structs and arrays if user asked for it
11409 explicitly, never if they just happen to appear in a
11410 middle of some value chain. */
11412 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11413 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11415 CORE_ADDR vaddr
= value_address (v
);
11419 len
= (target_exact_watchpoints
11420 && is_scalar_type_recursive (vtype
))?
11421 1 : TYPE_LENGTH (value_type (v
));
11423 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11427 found_memory_cnt
+= num_regs
;
11431 else if (VALUE_LVAL (v
) != not_lval
11432 && deprecated_value_modifiable (v
) == 0)
11433 return 0; /* These are values from the history (e.g., $1). */
11434 else if (VALUE_LVAL (v
) == lval_register
)
11435 return 0; /* Cannot watch a register with a HW watchpoint. */
11438 /* The expression itself looks suitable for using a hardware
11439 watchpoint, but give the target machine a chance to reject it. */
11440 return found_memory_cnt
;
11444 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11446 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11449 /* A helper function that looks for the "-location" argument and then
11450 calls watch_command_1. */
11453 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11455 int just_location
= 0;
11458 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11459 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11461 arg
= skip_spaces (arg
);
11465 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11469 watch_command (char *arg
, int from_tty
)
11471 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11475 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11477 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11481 rwatch_command (char *arg
, int from_tty
)
11483 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11487 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11489 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11493 awatch_command (char *arg
, int from_tty
)
11495 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11499 /* Data for the FSM that manages the until(location)/advance commands
11500 in infcmd.c. Here because it uses the mechanisms of
11503 struct until_break_fsm
11505 /* The base class. */
11506 struct thread_fsm thread_fsm
;
11508 /* The thread that as current when the command was executed. */
11511 /* The breakpoint set at the destination location. */
11512 struct breakpoint
*location_breakpoint
;
11514 /* Breakpoint set at the return address in the caller frame. May be
11516 struct breakpoint
*caller_breakpoint
;
11519 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11520 struct thread_info
*thread
);
11521 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11522 struct thread_info
*thread
);
11523 static enum async_reply_reason
11524 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11526 /* until_break_fsm's vtable. */
11528 static struct thread_fsm_ops until_break_fsm_ops
=
11531 until_break_fsm_clean_up
,
11532 until_break_fsm_should_stop
,
11533 NULL
, /* return_value */
11534 until_break_fsm_async_reply_reason
,
11537 /* Allocate a new until_break_command_fsm. */
11539 static struct until_break_fsm
*
11540 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11541 struct breakpoint
*location_breakpoint
,
11542 struct breakpoint
*caller_breakpoint
)
11544 struct until_break_fsm
*sm
;
11546 sm
= XCNEW (struct until_break_fsm
);
11547 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11549 sm
->thread
= thread
;
11550 sm
->location_breakpoint
= location_breakpoint
;
11551 sm
->caller_breakpoint
= caller_breakpoint
;
11556 /* Implementation of the 'should_stop' FSM method for the
11557 until(location)/advance commands. */
11560 until_break_fsm_should_stop (struct thread_fsm
*self
,
11561 struct thread_info
*tp
)
11563 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11565 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11566 sm
->location_breakpoint
) != NULL
11567 || (sm
->caller_breakpoint
!= NULL
11568 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11569 sm
->caller_breakpoint
) != NULL
))
11570 thread_fsm_set_finished (self
);
11575 /* Implementation of the 'clean_up' FSM method for the
11576 until(location)/advance commands. */
11579 until_break_fsm_clean_up (struct thread_fsm
*self
,
11580 struct thread_info
*thread
)
11582 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11584 /* Clean up our temporary breakpoints. */
11585 if (sm
->location_breakpoint
!= NULL
)
11587 delete_breakpoint (sm
->location_breakpoint
);
11588 sm
->location_breakpoint
= NULL
;
11590 if (sm
->caller_breakpoint
!= NULL
)
11592 delete_breakpoint (sm
->caller_breakpoint
);
11593 sm
->caller_breakpoint
= NULL
;
11595 delete_longjmp_breakpoint (sm
->thread
);
11598 /* Implementation of the 'async_reply_reason' FSM method for the
11599 until(location)/advance commands. */
11601 static enum async_reply_reason
11602 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11604 return EXEC_ASYNC_LOCATION_REACHED
;
11608 until_break_command (char *arg
, int from_tty
, int anywhere
)
11610 struct symtabs_and_lines sals
;
11611 struct symtab_and_line sal
;
11612 struct frame_info
*frame
;
11613 struct gdbarch
*frame_gdbarch
;
11614 struct frame_id stack_frame_id
;
11615 struct frame_id caller_frame_id
;
11616 struct breakpoint
*location_breakpoint
;
11617 struct breakpoint
*caller_breakpoint
= NULL
;
11618 struct cleanup
*old_chain
;
11620 struct thread_info
*tp
;
11621 struct until_break_fsm
*sm
;
11623 clear_proceed_status (0);
11625 /* Set a breakpoint where the user wants it and at return from
11628 event_location_up location
= string_to_event_location (&arg
, current_language
);
11630 if (last_displayed_sal_is_valid ())
11631 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11632 get_last_displayed_symtab (),
11633 get_last_displayed_line ());
11635 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11636 NULL
, (struct symtab
*) NULL
, 0);
11638 if (sals
.nelts
!= 1)
11639 error (_("Couldn't get information on specified line."));
11641 sal
= sals
.sals
[0];
11642 xfree (sals
.sals
); /* malloc'd, so freed. */
11645 error (_("Junk at end of arguments."));
11647 resolve_sal_pc (&sal
);
11649 tp
= inferior_thread ();
11650 thread
= tp
->global_num
;
11652 old_chain
= make_cleanup (null_cleanup
, NULL
);
11654 /* Note linespec handling above invalidates the frame chain.
11655 Installing a breakpoint also invalidates the frame chain (as it
11656 may need to switch threads), so do any frame handling before
11659 frame
= get_selected_frame (NULL
);
11660 frame_gdbarch
= get_frame_arch (frame
);
11661 stack_frame_id
= get_stack_frame_id (frame
);
11662 caller_frame_id
= frame_unwind_caller_id (frame
);
11664 /* Keep within the current frame, or in frames called by the current
11667 if (frame_id_p (caller_frame_id
))
11669 struct symtab_and_line sal2
;
11670 struct gdbarch
*caller_gdbarch
;
11672 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11673 sal2
.pc
= frame_unwind_caller_pc (frame
);
11674 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11675 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11679 make_cleanup_delete_breakpoint (caller_breakpoint
);
11681 set_longjmp_breakpoint (tp
, caller_frame_id
);
11682 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11685 /* set_momentary_breakpoint could invalidate FRAME. */
11689 /* If the user told us to continue until a specified location,
11690 we don't specify a frame at which we need to stop. */
11691 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11692 null_frame_id
, bp_until
);
11694 /* Otherwise, specify the selected frame, because we want to stop
11695 only at the very same frame. */
11696 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11697 stack_frame_id
, bp_until
);
11698 make_cleanup_delete_breakpoint (location_breakpoint
);
11700 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11701 location_breakpoint
, caller_breakpoint
);
11702 tp
->thread_fsm
= &sm
->thread_fsm
;
11704 discard_cleanups (old_chain
);
11706 proceed (-1, GDB_SIGNAL_DEFAULT
);
11709 /* This function attempts to parse an optional "if <cond>" clause
11710 from the arg string. If one is not found, it returns NULL.
11712 Else, it returns a pointer to the condition string. (It does not
11713 attempt to evaluate the string against a particular block.) And,
11714 it updates arg to point to the first character following the parsed
11715 if clause in the arg string. */
11718 ep_parse_optional_if_clause (const char **arg
)
11720 const char *cond_string
;
11722 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11725 /* Skip the "if" keyword. */
11728 /* Skip any extra leading whitespace, and record the start of the
11729 condition string. */
11730 *arg
= skip_spaces_const (*arg
);
11731 cond_string
= *arg
;
11733 /* Assume that the condition occupies the remainder of the arg
11735 (*arg
) += strlen (cond_string
);
11737 return cond_string
;
11740 /* Commands to deal with catching events, such as signals, exceptions,
11741 process start/exit, etc. */
11745 catch_fork_temporary
, catch_vfork_temporary
,
11746 catch_fork_permanent
, catch_vfork_permanent
11751 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11752 struct cmd_list_element
*command
)
11754 const char *arg
= arg_entry
;
11755 struct gdbarch
*gdbarch
= get_current_arch ();
11756 const char *cond_string
= NULL
;
11757 catch_fork_kind fork_kind
;
11760 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11761 tempflag
= (fork_kind
== catch_fork_temporary
11762 || fork_kind
== catch_vfork_temporary
);
11766 arg
= skip_spaces_const (arg
);
11768 /* The allowed syntax is:
11770 catch [v]fork if <cond>
11772 First, check if there's an if clause. */
11773 cond_string
= ep_parse_optional_if_clause (&arg
);
11775 if ((*arg
!= '\0') && !isspace (*arg
))
11776 error (_("Junk at end of arguments."));
11778 /* If this target supports it, create a fork or vfork catchpoint
11779 and enable reporting of such events. */
11782 case catch_fork_temporary
:
11783 case catch_fork_permanent
:
11784 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11785 &catch_fork_breakpoint_ops
);
11787 case catch_vfork_temporary
:
11788 case catch_vfork_permanent
:
11789 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11790 &catch_vfork_breakpoint_ops
);
11793 error (_("unsupported or unknown fork kind; cannot catch it"));
11799 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11800 struct cmd_list_element
*command
)
11802 const char *arg
= arg_entry
;
11803 struct exec_catchpoint
*c
;
11804 struct gdbarch
*gdbarch
= get_current_arch ();
11806 const char *cond_string
= NULL
;
11808 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11812 arg
= skip_spaces_const (arg
);
11814 /* The allowed syntax is:
11816 catch exec if <cond>
11818 First, check if there's an if clause. */
11819 cond_string
= ep_parse_optional_if_clause (&arg
);
11821 if ((*arg
!= '\0') && !isspace (*arg
))
11822 error (_("Junk at end of arguments."));
11824 c
= new exec_catchpoint ();
11825 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11826 &catch_exec_breakpoint_ops
);
11827 c
->exec_pathname
= NULL
;
11829 install_breakpoint (0, &c
->base
, 1);
11833 init_ada_exception_breakpoint (struct breakpoint
*b
,
11834 struct gdbarch
*gdbarch
,
11835 struct symtab_and_line sal
,
11837 const struct breakpoint_ops
*ops
,
11844 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11846 loc_gdbarch
= gdbarch
;
11848 describe_other_breakpoints (loc_gdbarch
,
11849 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11850 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11851 version for exception catchpoints, because two catchpoints
11852 used for different exception names will use the same address.
11853 In this case, a "breakpoint ... also set at..." warning is
11854 unproductive. Besides, the warning phrasing is also a bit
11855 inappropriate, we should use the word catchpoint, and tell
11856 the user what type of catchpoint it is. The above is good
11857 enough for now, though. */
11860 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11862 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11863 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11864 b
->location
= string_to_event_location (&addr_string
,
11865 language_def (language_ada
));
11866 b
->language
= language_ada
;
11870 catch_command (char *arg
, int from_tty
)
11872 error (_("Catch requires an event name."));
11877 tcatch_command (char *arg
, int from_tty
)
11879 error (_("Catch requires an event name."));
11882 /* A qsort comparison function that sorts breakpoints in order. */
11885 compare_breakpoints (const void *a
, const void *b
)
11887 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11888 uintptr_t ua
= (uintptr_t) *ba
;
11889 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11890 uintptr_t ub
= (uintptr_t) *bb
;
11892 if ((*ba
)->number
< (*bb
)->number
)
11894 else if ((*ba
)->number
> (*bb
)->number
)
11897 /* Now sort by address, in case we see, e..g, two breakpoints with
11901 return ua
> ub
? 1 : 0;
11904 /* Delete breakpoints by address or line. */
11907 clear_command (char *arg
, int from_tty
)
11909 struct breakpoint
*b
, *prev
;
11910 VEC(breakpoint_p
) *found
= 0;
11913 struct symtabs_and_lines sals
;
11914 struct symtab_and_line sal
;
11916 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11920 sals
= decode_line_with_current_source (arg
,
11921 (DECODE_LINE_FUNFIRSTLINE
11922 | DECODE_LINE_LIST_MODE
));
11923 make_cleanup (xfree
, sals
.sals
);
11928 sals
.sals
= XNEW (struct symtab_and_line
);
11929 make_cleanup (xfree
, sals
.sals
);
11930 init_sal (&sal
); /* Initialize to zeroes. */
11932 /* Set sal's line, symtab, pc, and pspace to the values
11933 corresponding to the last call to print_frame_info. If the
11934 codepoint is not valid, this will set all the fields to 0. */
11935 get_last_displayed_sal (&sal
);
11936 if (sal
.symtab
== 0)
11937 error (_("No source file specified."));
11939 sals
.sals
[0] = sal
;
11945 /* We don't call resolve_sal_pc here. That's not as bad as it
11946 seems, because all existing breakpoints typically have both
11947 file/line and pc set. So, if clear is given file/line, we can
11948 match this to existing breakpoint without obtaining pc at all.
11950 We only support clearing given the address explicitly
11951 present in breakpoint table. Say, we've set breakpoint
11952 at file:line. There were several PC values for that file:line,
11953 due to optimization, all in one block.
11955 We've picked one PC value. If "clear" is issued with another
11956 PC corresponding to the same file:line, the breakpoint won't
11957 be cleared. We probably can still clear the breakpoint, but
11958 since the other PC value is never presented to user, user
11959 can only find it by guessing, and it does not seem important
11960 to support that. */
11962 /* For each line spec given, delete bps which correspond to it. Do
11963 it in two passes, solely to preserve the current behavior that
11964 from_tty is forced true if we delete more than one
11968 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11969 for (i
= 0; i
< sals
.nelts
; i
++)
11971 const char *sal_fullname
;
11973 /* If exact pc given, clear bpts at that pc.
11974 If line given (pc == 0), clear all bpts on specified line.
11975 If defaulting, clear all bpts on default line
11978 defaulting sal.pc != 0 tests to do
11983 1 0 <can't happen> */
11985 sal
= sals
.sals
[i
];
11986 sal_fullname
= (sal
.symtab
== NULL
11987 ? NULL
: symtab_to_fullname (sal
.symtab
));
11989 /* Find all matching breakpoints and add them to 'found'. */
11990 ALL_BREAKPOINTS (b
)
11993 /* Are we going to delete b? */
11994 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11996 struct bp_location
*loc
= b
->loc
;
11997 for (; loc
; loc
= loc
->next
)
11999 /* If the user specified file:line, don't allow a PC
12000 match. This matches historical gdb behavior. */
12001 int pc_match
= (!sal
.explicit_line
12003 && (loc
->pspace
== sal
.pspace
)
12004 && (loc
->address
== sal
.pc
)
12005 && (!section_is_overlay (loc
->section
)
12006 || loc
->section
== sal
.section
));
12007 int line_match
= 0;
12009 if ((default_match
|| sal
.explicit_line
)
12010 && loc
->symtab
!= NULL
12011 && sal_fullname
!= NULL
12012 && sal
.pspace
== loc
->pspace
12013 && loc
->line_number
== sal
.line
12014 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12015 sal_fullname
) == 0)
12018 if (pc_match
|| line_match
)
12027 VEC_safe_push(breakpoint_p
, found
, b
);
12031 /* Now go thru the 'found' chain and delete them. */
12032 if (VEC_empty(breakpoint_p
, found
))
12035 error (_("No breakpoint at %s."), arg
);
12037 error (_("No breakpoint at this line."));
12040 /* Remove duplicates from the vec. */
12041 qsort (VEC_address (breakpoint_p
, found
),
12042 VEC_length (breakpoint_p
, found
),
12043 sizeof (breakpoint_p
),
12044 compare_breakpoints
);
12045 prev
= VEC_index (breakpoint_p
, found
, 0);
12046 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12050 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12055 if (VEC_length(breakpoint_p
, found
) > 1)
12056 from_tty
= 1; /* Always report if deleted more than one. */
12059 if (VEC_length(breakpoint_p
, found
) == 1)
12060 printf_unfiltered (_("Deleted breakpoint "));
12062 printf_unfiltered (_("Deleted breakpoints "));
12065 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12068 printf_unfiltered ("%d ", b
->number
);
12069 delete_breakpoint (b
);
12072 putchar_unfiltered ('\n');
12074 do_cleanups (cleanups
);
12077 /* Delete breakpoint in BS if they are `delete' breakpoints and
12078 all breakpoints that are marked for deletion, whether hit or not.
12079 This is called after any breakpoint is hit, or after errors. */
12082 breakpoint_auto_delete (bpstat bs
)
12084 struct breakpoint
*b
, *b_tmp
;
12086 for (; bs
; bs
= bs
->next
)
12087 if (bs
->breakpoint_at
12088 && bs
->breakpoint_at
->disposition
== disp_del
12090 delete_breakpoint (bs
->breakpoint_at
);
12092 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12094 if (b
->disposition
== disp_del_at_next_stop
)
12095 delete_breakpoint (b
);
12099 /* A comparison function for bp_location AP and BP being interfaced to
12100 qsort. Sort elements primarily by their ADDRESS (no matter what
12101 does breakpoint_address_is_meaningful say for its OWNER),
12102 secondarily by ordering first permanent elements and
12103 terciarily just ensuring the array is sorted stable way despite
12104 qsort being an unstable algorithm. */
12107 bp_locations_compare (const void *ap
, const void *bp
)
12109 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12110 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12112 if (a
->address
!= b
->address
)
12113 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12115 /* Sort locations at the same address by their pspace number, keeping
12116 locations of the same inferior (in a multi-inferior environment)
12119 if (a
->pspace
->num
!= b
->pspace
->num
)
12120 return ((a
->pspace
->num
> b
->pspace
->num
)
12121 - (a
->pspace
->num
< b
->pspace
->num
));
12123 /* Sort permanent breakpoints first. */
12124 if (a
->permanent
!= b
->permanent
)
12125 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12127 /* Make the internal GDB representation stable across GDB runs
12128 where A and B memory inside GDB can differ. Breakpoint locations of
12129 the same type at the same address can be sorted in arbitrary order. */
12131 if (a
->owner
->number
!= b
->owner
->number
)
12132 return ((a
->owner
->number
> b
->owner
->number
)
12133 - (a
->owner
->number
< b
->owner
->number
));
12135 return (a
> b
) - (a
< b
);
12138 /* Set bp_locations_placed_address_before_address_max and
12139 bp_locations_shadow_len_after_address_max according to the current
12140 content of the bp_locations array. */
12143 bp_locations_target_extensions_update (void)
12145 struct bp_location
*bl
, **blp_tmp
;
12147 bp_locations_placed_address_before_address_max
= 0;
12148 bp_locations_shadow_len_after_address_max
= 0;
12150 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12152 CORE_ADDR start
, end
, addr
;
12154 if (!bp_location_has_shadow (bl
))
12157 start
= bl
->target_info
.placed_address
;
12158 end
= start
+ bl
->target_info
.shadow_len
;
12160 gdb_assert (bl
->address
>= start
);
12161 addr
= bl
->address
- start
;
12162 if (addr
> bp_locations_placed_address_before_address_max
)
12163 bp_locations_placed_address_before_address_max
= addr
;
12165 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12167 gdb_assert (bl
->address
< end
);
12168 addr
= end
- bl
->address
;
12169 if (addr
> bp_locations_shadow_len_after_address_max
)
12170 bp_locations_shadow_len_after_address_max
= addr
;
12174 /* Download tracepoint locations if they haven't been. */
12177 download_tracepoint_locations (void)
12179 struct breakpoint
*b
;
12180 struct cleanup
*old_chain
;
12181 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12183 old_chain
= save_current_space_and_thread ();
12185 ALL_TRACEPOINTS (b
)
12187 struct bp_location
*bl
;
12188 struct tracepoint
*t
;
12189 int bp_location_downloaded
= 0;
12191 if ((b
->type
== bp_fast_tracepoint
12192 ? !may_insert_fast_tracepoints
12193 : !may_insert_tracepoints
))
12196 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12198 if (target_can_download_tracepoint ())
12199 can_download_tracepoint
= TRIBOOL_TRUE
;
12201 can_download_tracepoint
= TRIBOOL_FALSE
;
12204 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12207 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12209 /* In tracepoint, locations are _never_ duplicated, so
12210 should_be_inserted is equivalent to
12211 unduplicated_should_be_inserted. */
12212 if (!should_be_inserted (bl
) || bl
->inserted
)
12215 switch_to_program_space_and_thread (bl
->pspace
);
12217 target_download_tracepoint (bl
);
12220 bp_location_downloaded
= 1;
12222 t
= (struct tracepoint
*) b
;
12223 t
->number_on_target
= b
->number
;
12224 if (bp_location_downloaded
)
12225 observer_notify_breakpoint_modified (b
);
12228 do_cleanups (old_chain
);
12231 /* Swap the insertion/duplication state between two locations. */
12234 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12236 const int left_inserted
= left
->inserted
;
12237 const int left_duplicate
= left
->duplicate
;
12238 const int left_needs_update
= left
->needs_update
;
12239 const struct bp_target_info left_target_info
= left
->target_info
;
12241 /* Locations of tracepoints can never be duplicated. */
12242 if (is_tracepoint (left
->owner
))
12243 gdb_assert (!left
->duplicate
);
12244 if (is_tracepoint (right
->owner
))
12245 gdb_assert (!right
->duplicate
);
12247 left
->inserted
= right
->inserted
;
12248 left
->duplicate
= right
->duplicate
;
12249 left
->needs_update
= right
->needs_update
;
12250 left
->target_info
= right
->target_info
;
12251 right
->inserted
= left_inserted
;
12252 right
->duplicate
= left_duplicate
;
12253 right
->needs_update
= left_needs_update
;
12254 right
->target_info
= left_target_info
;
12257 /* Force the re-insertion of the locations at ADDRESS. This is called
12258 once a new/deleted/modified duplicate location is found and we are evaluating
12259 conditions on the target's side. Such conditions need to be updated on
12263 force_breakpoint_reinsertion (struct bp_location
*bl
)
12265 struct bp_location
**locp
= NULL
, **loc2p
;
12266 struct bp_location
*loc
;
12267 CORE_ADDR address
= 0;
12270 address
= bl
->address
;
12271 pspace_num
= bl
->pspace
->num
;
12273 /* This is only meaningful if the target is
12274 evaluating conditions and if the user has
12275 opted for condition evaluation on the target's
12277 if (gdb_evaluates_breakpoint_condition_p ()
12278 || !target_supports_evaluation_of_breakpoint_conditions ())
12281 /* Flag all breakpoint locations with this address and
12282 the same program space as the location
12283 as "its condition has changed". We need to
12284 update the conditions on the target's side. */
12285 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12289 if (!is_breakpoint (loc
->owner
)
12290 || pspace_num
!= loc
->pspace
->num
)
12293 /* Flag the location appropriately. We use a different state to
12294 let everyone know that we already updated the set of locations
12295 with addr bl->address and program space bl->pspace. This is so
12296 we don't have to keep calling these functions just to mark locations
12297 that have already been marked. */
12298 loc
->condition_changed
= condition_updated
;
12300 /* Free the agent expression bytecode as well. We will compute
12302 loc
->cond_bytecode
.reset ();
12305 /* Called whether new breakpoints are created, or existing breakpoints
12306 deleted, to update the global location list and recompute which
12307 locations are duplicate of which.
12309 The INSERT_MODE flag determines whether locations may not, may, or
12310 shall be inserted now. See 'enum ugll_insert_mode' for more
12314 update_global_location_list (enum ugll_insert_mode insert_mode
)
12316 struct breakpoint
*b
;
12317 struct bp_location
**locp
, *loc
;
12318 struct cleanup
*cleanups
;
12319 /* Last breakpoint location address that was marked for update. */
12320 CORE_ADDR last_addr
= 0;
12321 /* Last breakpoint location program space that was marked for update. */
12322 int last_pspace_num
= -1;
12324 /* Used in the duplicates detection below. When iterating over all
12325 bp_locations, points to the first bp_location of a given address.
12326 Breakpoints and watchpoints of different types are never
12327 duplicates of each other. Keep one pointer for each type of
12328 breakpoint/watchpoint, so we only need to loop over all locations
12330 struct bp_location
*bp_loc_first
; /* breakpoint */
12331 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12332 struct bp_location
*awp_loc_first
; /* access watchpoint */
12333 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12335 /* Saved former bp_locations array which we compare against the newly
12336 built bp_locations from the current state of ALL_BREAKPOINTS. */
12337 struct bp_location
**old_locations
, **old_locp
;
12338 unsigned old_locations_count
;
12340 old_locations
= bp_locations
;
12341 old_locations_count
= bp_locations_count
;
12342 bp_locations
= NULL
;
12343 bp_locations_count
= 0;
12344 cleanups
= make_cleanup (xfree
, old_locations
);
12346 ALL_BREAKPOINTS (b
)
12347 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12348 bp_locations_count
++;
12350 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12351 locp
= bp_locations
;
12352 ALL_BREAKPOINTS (b
)
12353 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12355 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12356 bp_locations_compare
);
12358 bp_locations_target_extensions_update ();
12360 /* Identify bp_location instances that are no longer present in the
12361 new list, and therefore should be freed. Note that it's not
12362 necessary that those locations should be removed from inferior --
12363 if there's another location at the same address (previously
12364 marked as duplicate), we don't need to remove/insert the
12367 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12368 and former bp_location array state respectively. */
12370 locp
= bp_locations
;
12371 for (old_locp
= old_locations
;
12372 old_locp
< old_locations
+ old_locations_count
;
12375 struct bp_location
*old_loc
= *old_locp
;
12376 struct bp_location
**loc2p
;
12378 /* Tells if 'old_loc' is found among the new locations. If
12379 not, we have to free it. */
12380 int found_object
= 0;
12381 /* Tells if the location should remain inserted in the target. */
12382 int keep_in_target
= 0;
12385 /* Skip LOCP entries which will definitely never be needed.
12386 Stop either at or being the one matching OLD_LOC. */
12387 while (locp
< bp_locations
+ bp_locations_count
12388 && (*locp
)->address
< old_loc
->address
)
12392 (loc2p
< bp_locations
+ bp_locations_count
12393 && (*loc2p
)->address
== old_loc
->address
);
12396 /* Check if this is a new/duplicated location or a duplicated
12397 location that had its condition modified. If so, we want to send
12398 its condition to the target if evaluation of conditions is taking
12400 if ((*loc2p
)->condition_changed
== condition_modified
12401 && (last_addr
!= old_loc
->address
12402 || last_pspace_num
!= old_loc
->pspace
->num
))
12404 force_breakpoint_reinsertion (*loc2p
);
12405 last_pspace_num
= old_loc
->pspace
->num
;
12408 if (*loc2p
== old_loc
)
12412 /* We have already handled this address, update it so that we don't
12413 have to go through updates again. */
12414 last_addr
= old_loc
->address
;
12416 /* Target-side condition evaluation: Handle deleted locations. */
12418 force_breakpoint_reinsertion (old_loc
);
12420 /* If this location is no longer present, and inserted, look if
12421 there's maybe a new location at the same address. If so,
12422 mark that one inserted, and don't remove this one. This is
12423 needed so that we don't have a time window where a breakpoint
12424 at certain location is not inserted. */
12426 if (old_loc
->inserted
)
12428 /* If the location is inserted now, we might have to remove
12431 if (found_object
&& should_be_inserted (old_loc
))
12433 /* The location is still present in the location list,
12434 and still should be inserted. Don't do anything. */
12435 keep_in_target
= 1;
12439 /* This location still exists, but it won't be kept in the
12440 target since it may have been disabled. We proceed to
12441 remove its target-side condition. */
12443 /* The location is either no longer present, or got
12444 disabled. See if there's another location at the
12445 same address, in which case we don't need to remove
12446 this one from the target. */
12448 /* OLD_LOC comes from existing struct breakpoint. */
12449 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12452 (loc2p
< bp_locations
+ bp_locations_count
12453 && (*loc2p
)->address
== old_loc
->address
);
12456 struct bp_location
*loc2
= *loc2p
;
12458 if (breakpoint_locations_match (loc2
, old_loc
))
12460 /* Read watchpoint locations are switched to
12461 access watchpoints, if the former are not
12462 supported, but the latter are. */
12463 if (is_hardware_watchpoint (old_loc
->owner
))
12465 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12466 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12469 /* loc2 is a duplicated location. We need to check
12470 if it should be inserted in case it will be
12472 if (loc2
!= old_loc
12473 && unduplicated_should_be_inserted (loc2
))
12475 swap_insertion (old_loc
, loc2
);
12476 keep_in_target
= 1;
12484 if (!keep_in_target
)
12486 if (remove_breakpoint (old_loc
))
12488 /* This is just about all we can do. We could keep
12489 this location on the global list, and try to
12490 remove it next time, but there's no particular
12491 reason why we will succeed next time.
12493 Note that at this point, old_loc->owner is still
12494 valid, as delete_breakpoint frees the breakpoint
12495 only after calling us. */
12496 printf_filtered (_("warning: Error removing "
12497 "breakpoint %d\n"),
12498 old_loc
->owner
->number
);
12506 if (removed
&& target_is_non_stop_p ()
12507 && need_moribund_for_location_type (old_loc
))
12509 /* This location was removed from the target. In
12510 non-stop mode, a race condition is possible where
12511 we've removed a breakpoint, but stop events for that
12512 breakpoint are already queued and will arrive later.
12513 We apply an heuristic to be able to distinguish such
12514 SIGTRAPs from other random SIGTRAPs: we keep this
12515 breakpoint location for a bit, and will retire it
12516 after we see some number of events. The theory here
12517 is that reporting of events should, "on the average",
12518 be fair, so after a while we'll see events from all
12519 threads that have anything of interest, and no longer
12520 need to keep this breakpoint location around. We
12521 don't hold locations forever so to reduce chances of
12522 mistaking a non-breakpoint SIGTRAP for a breakpoint
12525 The heuristic failing can be disastrous on
12526 decr_pc_after_break targets.
12528 On decr_pc_after_break targets, like e.g., x86-linux,
12529 if we fail to recognize a late breakpoint SIGTRAP,
12530 because events_till_retirement has reached 0 too
12531 soon, we'll fail to do the PC adjustment, and report
12532 a random SIGTRAP to the user. When the user resumes
12533 the inferior, it will most likely immediately crash
12534 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12535 corrupted, because of being resumed e.g., in the
12536 middle of a multi-byte instruction, or skipped a
12537 one-byte instruction. This was actually seen happen
12538 on native x86-linux, and should be less rare on
12539 targets that do not support new thread events, like
12540 remote, due to the heuristic depending on
12543 Mistaking a random SIGTRAP for a breakpoint trap
12544 causes similar symptoms (PC adjustment applied when
12545 it shouldn't), but then again, playing with SIGTRAPs
12546 behind the debugger's back is asking for trouble.
12548 Since hardware watchpoint traps are always
12549 distinguishable from other traps, so we don't need to
12550 apply keep hardware watchpoint moribund locations
12551 around. We simply always ignore hardware watchpoint
12552 traps we can no longer explain. */
12554 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12555 old_loc
->owner
= NULL
;
12557 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12561 old_loc
->owner
= NULL
;
12562 decref_bp_location (&old_loc
);
12567 /* Rescan breakpoints at the same address and section, marking the
12568 first one as "first" and any others as "duplicates". This is so
12569 that the bpt instruction is only inserted once. If we have a
12570 permanent breakpoint at the same place as BPT, make that one the
12571 official one, and the rest as duplicates. Permanent breakpoints
12572 are sorted first for the same address.
12574 Do the same for hardware watchpoints, but also considering the
12575 watchpoint's type (regular/access/read) and length. */
12577 bp_loc_first
= NULL
;
12578 wp_loc_first
= NULL
;
12579 awp_loc_first
= NULL
;
12580 rwp_loc_first
= NULL
;
12581 ALL_BP_LOCATIONS (loc
, locp
)
12583 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12585 struct bp_location
**loc_first_p
;
12588 if (!unduplicated_should_be_inserted (loc
)
12589 || !breakpoint_address_is_meaningful (b
)
12590 /* Don't detect duplicate for tracepoint locations because they are
12591 never duplicated. See the comments in field `duplicate' of
12592 `struct bp_location'. */
12593 || is_tracepoint (b
))
12595 /* Clear the condition modification flag. */
12596 loc
->condition_changed
= condition_unchanged
;
12600 if (b
->type
== bp_hardware_watchpoint
)
12601 loc_first_p
= &wp_loc_first
;
12602 else if (b
->type
== bp_read_watchpoint
)
12603 loc_first_p
= &rwp_loc_first
;
12604 else if (b
->type
== bp_access_watchpoint
)
12605 loc_first_p
= &awp_loc_first
;
12607 loc_first_p
= &bp_loc_first
;
12609 if (*loc_first_p
== NULL
12610 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12611 || !breakpoint_locations_match (loc
, *loc_first_p
))
12613 *loc_first_p
= loc
;
12614 loc
->duplicate
= 0;
12616 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12618 loc
->needs_update
= 1;
12619 /* Clear the condition modification flag. */
12620 loc
->condition_changed
= condition_unchanged
;
12626 /* This and the above ensure the invariant that the first location
12627 is not duplicated, and is the inserted one.
12628 All following are marked as duplicated, and are not inserted. */
12630 swap_insertion (loc
, *loc_first_p
);
12631 loc
->duplicate
= 1;
12633 /* Clear the condition modification flag. */
12634 loc
->condition_changed
= condition_unchanged
;
12637 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12639 if (insert_mode
!= UGLL_DONT_INSERT
)
12640 insert_breakpoint_locations ();
12643 /* Even though the caller told us to not insert new
12644 locations, we may still need to update conditions on the
12645 target's side of breakpoints that were already inserted
12646 if the target is evaluating breakpoint conditions. We
12647 only update conditions for locations that are marked
12649 update_inserted_breakpoint_locations ();
12653 if (insert_mode
!= UGLL_DONT_INSERT
)
12654 download_tracepoint_locations ();
12656 do_cleanups (cleanups
);
12660 breakpoint_retire_moribund (void)
12662 struct bp_location
*loc
;
12665 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12666 if (--(loc
->events_till_retirement
) == 0)
12668 decref_bp_location (&loc
);
12669 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12675 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12680 update_global_location_list (insert_mode
);
12682 CATCH (e
, RETURN_MASK_ERROR
)
12688 /* Clear BKP from a BPS. */
12691 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12695 for (bs
= bps
; bs
; bs
= bs
->next
)
12696 if (bs
->breakpoint_at
== bpt
)
12698 bs
->breakpoint_at
= NULL
;
12699 bs
->old_val
= NULL
;
12700 /* bs->commands will be freed later. */
12704 /* Callback for iterate_over_threads. */
12706 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12708 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12710 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12714 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12718 say_where (struct breakpoint
*b
)
12720 struct value_print_options opts
;
12722 get_user_print_options (&opts
);
12724 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12726 if (b
->loc
== NULL
)
12728 /* For pending locations, the output differs slightly based
12729 on b->extra_string. If this is non-NULL, it contains either
12730 a condition or dprintf arguments. */
12731 if (b
->extra_string
== NULL
)
12733 printf_filtered (_(" (%s) pending."),
12734 event_location_to_string (b
->location
.get ()));
12736 else if (b
->type
== bp_dprintf
)
12738 printf_filtered (_(" (%s,%s) pending."),
12739 event_location_to_string (b
->location
.get ()),
12744 printf_filtered (_(" (%s %s) pending."),
12745 event_location_to_string (b
->location
.get ()),
12751 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12753 printf_filtered (" at ");
12754 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12757 if (b
->loc
->symtab
!= NULL
)
12759 /* If there is a single location, we can print the location
12761 if (b
->loc
->next
== NULL
)
12762 printf_filtered (": file %s, line %d.",
12763 symtab_to_filename_for_display (b
->loc
->symtab
),
12764 b
->loc
->line_number
);
12766 /* This is not ideal, but each location may have a
12767 different file name, and this at least reflects the
12768 real situation somewhat. */
12769 printf_filtered (": %s.",
12770 event_location_to_string (b
->location
.get ()));
12775 struct bp_location
*loc
= b
->loc
;
12777 for (; loc
; loc
= loc
->next
)
12779 printf_filtered (" (%d locations)", n
);
12784 /* Default bp_location_ops methods. */
12787 bp_location_dtor (struct bp_location
*self
)
12789 xfree (self
->function_name
);
12792 static const struct bp_location_ops bp_location_ops
=
12797 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12801 base_breakpoint_dtor (struct breakpoint
*self
)
12803 decref_counted_command_line (&self
->commands
);
12804 xfree (self
->cond_string
);
12805 xfree (self
->extra_string
);
12806 xfree (self
->filter
);
12809 static struct bp_location
*
12810 base_breakpoint_allocate_location (struct breakpoint
*self
)
12812 return new bp_location (&bp_location_ops
, self
);
12816 base_breakpoint_re_set (struct breakpoint
*b
)
12818 /* Nothing to re-set. */
12821 #define internal_error_pure_virtual_called() \
12822 gdb_assert_not_reached ("pure virtual function called")
12825 base_breakpoint_insert_location (struct bp_location
*bl
)
12827 internal_error_pure_virtual_called ();
12831 base_breakpoint_remove_location (struct bp_location
*bl
,
12832 enum remove_bp_reason reason
)
12834 internal_error_pure_virtual_called ();
12838 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12839 struct address_space
*aspace
,
12841 const struct target_waitstatus
*ws
)
12843 internal_error_pure_virtual_called ();
12847 base_breakpoint_check_status (bpstat bs
)
12852 /* A "works_in_software_mode" breakpoint_ops method that just internal
12856 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12858 internal_error_pure_virtual_called ();
12861 /* A "resources_needed" breakpoint_ops method that just internal
12865 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12867 internal_error_pure_virtual_called ();
12870 static enum print_stop_action
12871 base_breakpoint_print_it (bpstat bs
)
12873 internal_error_pure_virtual_called ();
12877 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12878 struct ui_out
*uiout
)
12884 base_breakpoint_print_mention (struct breakpoint
*b
)
12886 internal_error_pure_virtual_called ();
12890 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12892 internal_error_pure_virtual_called ();
12896 base_breakpoint_create_sals_from_location
12897 (const struct event_location
*location
,
12898 struct linespec_result
*canonical
,
12899 enum bptype type_wanted
)
12901 internal_error_pure_virtual_called ();
12905 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12906 struct linespec_result
*c
,
12908 char *extra_string
,
12909 enum bptype type_wanted
,
12910 enum bpdisp disposition
,
12912 int task
, int ignore_count
,
12913 const struct breakpoint_ops
*o
,
12914 int from_tty
, int enabled
,
12915 int internal
, unsigned flags
)
12917 internal_error_pure_virtual_called ();
12921 base_breakpoint_decode_location (struct breakpoint
*b
,
12922 const struct event_location
*location
,
12923 struct program_space
*search_pspace
,
12924 struct symtabs_and_lines
*sals
)
12926 internal_error_pure_virtual_called ();
12929 /* The default 'explains_signal' method. */
12932 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12937 /* The default "after_condition_true" method. */
12940 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12942 /* Nothing to do. */
12945 struct breakpoint_ops base_breakpoint_ops
=
12947 base_breakpoint_dtor
,
12948 base_breakpoint_allocate_location
,
12949 base_breakpoint_re_set
,
12950 base_breakpoint_insert_location
,
12951 base_breakpoint_remove_location
,
12952 base_breakpoint_breakpoint_hit
,
12953 base_breakpoint_check_status
,
12954 base_breakpoint_resources_needed
,
12955 base_breakpoint_works_in_software_mode
,
12956 base_breakpoint_print_it
,
12958 base_breakpoint_print_one_detail
,
12959 base_breakpoint_print_mention
,
12960 base_breakpoint_print_recreate
,
12961 base_breakpoint_create_sals_from_location
,
12962 base_breakpoint_create_breakpoints_sal
,
12963 base_breakpoint_decode_location
,
12964 base_breakpoint_explains_signal
,
12965 base_breakpoint_after_condition_true
,
12968 /* Default breakpoint_ops methods. */
12971 bkpt_re_set (struct breakpoint
*b
)
12973 /* FIXME: is this still reachable? */
12974 if (breakpoint_event_location_empty_p (b
))
12976 /* Anything without a location can't be re-set. */
12977 delete_breakpoint (b
);
12981 breakpoint_re_set_default (b
);
12985 bkpt_insert_location (struct bp_location
*bl
)
12987 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12989 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12990 bl
->target_info
.placed_address
= addr
;
12992 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12993 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12995 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12999 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13001 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13002 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13004 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13008 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13009 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13010 const struct target_waitstatus
*ws
)
13012 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13013 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13016 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13020 if (overlay_debugging
/* unmapped overlay section */
13021 && section_is_overlay (bl
->section
)
13022 && !section_is_mapped (bl
->section
))
13029 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13030 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13031 const struct target_waitstatus
*ws
)
13033 if (dprintf_style
== dprintf_style_agent
13034 && target_can_run_breakpoint_commands ())
13036 /* An agent-style dprintf never causes a stop. If we see a trap
13037 for this address it must be for a breakpoint that happens to
13038 be set at the same address. */
13042 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13046 bkpt_resources_needed (const struct bp_location
*bl
)
13048 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13053 static enum print_stop_action
13054 bkpt_print_it (bpstat bs
)
13056 struct breakpoint
*b
;
13057 const struct bp_location
*bl
;
13059 struct ui_out
*uiout
= current_uiout
;
13061 gdb_assert (bs
->bp_location_at
!= NULL
);
13063 bl
= bs
->bp_location_at
;
13064 b
= bs
->breakpoint_at
;
13066 bp_temp
= b
->disposition
== disp_del
;
13067 if (bl
->address
!= bl
->requested_address
)
13068 breakpoint_adjustment_warning (bl
->requested_address
,
13071 annotate_breakpoint (b
->number
);
13072 maybe_print_thread_hit_breakpoint (uiout
);
13075 uiout
->text ("Temporary breakpoint ");
13077 uiout
->text ("Breakpoint ");
13078 if (uiout
->is_mi_like_p ())
13080 uiout
->field_string ("reason",
13081 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13082 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
13084 uiout
->field_int ("bkptno", b
->number
);
13085 uiout
->text (", ");
13087 return PRINT_SRC_AND_LOC
;
13091 bkpt_print_mention (struct breakpoint
*b
)
13093 if (current_uiout
->is_mi_like_p ())
13098 case bp_breakpoint
:
13099 case bp_gnu_ifunc_resolver
:
13100 if (b
->disposition
== disp_del
)
13101 printf_filtered (_("Temporary breakpoint"));
13103 printf_filtered (_("Breakpoint"));
13104 printf_filtered (_(" %d"), b
->number
);
13105 if (b
->type
== bp_gnu_ifunc_resolver
)
13106 printf_filtered (_(" at gnu-indirect-function resolver"));
13108 case bp_hardware_breakpoint
:
13109 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13112 printf_filtered (_("Dprintf %d"), b
->number
);
13120 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13122 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13123 fprintf_unfiltered (fp
, "tbreak");
13124 else if (tp
->type
== bp_breakpoint
)
13125 fprintf_unfiltered (fp
, "break");
13126 else if (tp
->type
== bp_hardware_breakpoint
13127 && tp
->disposition
== disp_del
)
13128 fprintf_unfiltered (fp
, "thbreak");
13129 else if (tp
->type
== bp_hardware_breakpoint
)
13130 fprintf_unfiltered (fp
, "hbreak");
13132 internal_error (__FILE__
, __LINE__
,
13133 _("unhandled breakpoint type %d"), (int) tp
->type
);
13135 fprintf_unfiltered (fp
, " %s",
13136 event_location_to_string (tp
->location
.get ()));
13138 /* Print out extra_string if this breakpoint is pending. It might
13139 contain, for example, conditions that were set by the user. */
13140 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13141 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13143 print_recreate_thread (tp
, fp
);
13147 bkpt_create_sals_from_location (const struct event_location
*location
,
13148 struct linespec_result
*canonical
,
13149 enum bptype type_wanted
)
13151 create_sals_from_location_default (location
, canonical
, type_wanted
);
13155 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13156 struct linespec_result
*canonical
,
13158 char *extra_string
,
13159 enum bptype type_wanted
,
13160 enum bpdisp disposition
,
13162 int task
, int ignore_count
,
13163 const struct breakpoint_ops
*ops
,
13164 int from_tty
, int enabled
,
13165 int internal
, unsigned flags
)
13167 create_breakpoints_sal_default (gdbarch
, canonical
,
13168 cond_string
, extra_string
,
13170 disposition
, thread
, task
,
13171 ignore_count
, ops
, from_tty
,
13172 enabled
, internal
, flags
);
13176 bkpt_decode_location (struct breakpoint
*b
,
13177 const struct event_location
*location
,
13178 struct program_space
*search_pspace
,
13179 struct symtabs_and_lines
*sals
)
13181 decode_location_default (b
, location
, search_pspace
, sals
);
13184 /* Virtual table for internal breakpoints. */
13187 internal_bkpt_re_set (struct breakpoint
*b
)
13191 /* Delete overlay event and longjmp master breakpoints; they
13192 will be reset later by breakpoint_re_set. */
13193 case bp_overlay_event
:
13194 case bp_longjmp_master
:
13195 case bp_std_terminate_master
:
13196 case bp_exception_master
:
13197 delete_breakpoint (b
);
13200 /* This breakpoint is special, it's set up when the inferior
13201 starts and we really don't want to touch it. */
13202 case bp_shlib_event
:
13204 /* Like bp_shlib_event, this breakpoint type is special. Once
13205 it is set up, we do not want to touch it. */
13206 case bp_thread_event
:
13212 internal_bkpt_check_status (bpstat bs
)
13214 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13216 /* If requested, stop when the dynamic linker notifies GDB of
13217 events. This allows the user to get control and place
13218 breakpoints in initializer routines for dynamically loaded
13219 objects (among other things). */
13220 bs
->stop
= stop_on_solib_events
;
13221 bs
->print
= stop_on_solib_events
;
13227 static enum print_stop_action
13228 internal_bkpt_print_it (bpstat bs
)
13230 struct breakpoint
*b
;
13232 b
= bs
->breakpoint_at
;
13236 case bp_shlib_event
:
13237 /* Did we stop because the user set the stop_on_solib_events
13238 variable? (If so, we report this as a generic, "Stopped due
13239 to shlib event" message.) */
13240 print_solib_event (0);
13243 case bp_thread_event
:
13244 /* Not sure how we will get here.
13245 GDB should not stop for these breakpoints. */
13246 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13249 case bp_overlay_event
:
13250 /* By analogy with the thread event, GDB should not stop for these. */
13251 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13254 case bp_longjmp_master
:
13255 /* These should never be enabled. */
13256 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13259 case bp_std_terminate_master
:
13260 /* These should never be enabled. */
13261 printf_filtered (_("std::terminate Master Breakpoint: "
13262 "gdb should not stop!\n"));
13265 case bp_exception_master
:
13266 /* These should never be enabled. */
13267 printf_filtered (_("Exception Master Breakpoint: "
13268 "gdb should not stop!\n"));
13272 return PRINT_NOTHING
;
13276 internal_bkpt_print_mention (struct breakpoint
*b
)
13278 /* Nothing to mention. These breakpoints are internal. */
13281 /* Virtual table for momentary breakpoints */
13284 momentary_bkpt_re_set (struct breakpoint
*b
)
13286 /* Keep temporary breakpoints, which can be encountered when we step
13287 over a dlopen call and solib_add is resetting the breakpoints.
13288 Otherwise these should have been blown away via the cleanup chain
13289 or by breakpoint_init_inferior when we rerun the executable. */
13293 momentary_bkpt_check_status (bpstat bs
)
13295 /* Nothing. The point of these breakpoints is causing a stop. */
13298 static enum print_stop_action
13299 momentary_bkpt_print_it (bpstat bs
)
13301 return PRINT_UNKNOWN
;
13305 momentary_bkpt_print_mention (struct breakpoint
*b
)
13307 /* Nothing to mention. These breakpoints are internal. */
13310 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13312 It gets cleared already on the removal of the first one of such placed
13313 breakpoints. This is OK as they get all removed altogether. */
13316 longjmp_bkpt_dtor (struct breakpoint
*self
)
13318 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13321 tp
->initiating_frame
= null_frame_id
;
13323 momentary_breakpoint_ops
.dtor (self
);
13326 /* Specific methods for probe breakpoints. */
13329 bkpt_probe_insert_location (struct bp_location
*bl
)
13331 int v
= bkpt_insert_location (bl
);
13335 /* The insertion was successful, now let's set the probe's semaphore
13337 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13338 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13347 bkpt_probe_remove_location (struct bp_location
*bl
,
13348 enum remove_bp_reason reason
)
13350 /* Let's clear the semaphore before removing the location. */
13351 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13352 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13356 return bkpt_remove_location (bl
, reason
);
13360 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13361 struct linespec_result
*canonical
,
13362 enum bptype type_wanted
)
13364 struct linespec_sals lsal
;
13366 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13368 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13369 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13373 bkpt_probe_decode_location (struct breakpoint
*b
,
13374 const struct event_location
*location
,
13375 struct program_space
*search_pspace
,
13376 struct symtabs_and_lines
*sals
)
13378 *sals
= parse_probes (location
, search_pspace
, NULL
);
13380 error (_("probe not found"));
13383 /* The breakpoint_ops structure to be used in tracepoints. */
13386 tracepoint_re_set (struct breakpoint
*b
)
13388 breakpoint_re_set_default (b
);
13392 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13393 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13394 const struct target_waitstatus
*ws
)
13396 /* By definition, the inferior does not report stops at
13402 tracepoint_print_one_detail (const struct breakpoint
*self
,
13403 struct ui_out
*uiout
)
13405 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13406 if (tp
->static_trace_marker_id
)
13408 gdb_assert (self
->type
== bp_static_tracepoint
);
13410 uiout
->text ("\tmarker id is ");
13411 uiout
->field_string ("static-tracepoint-marker-string-id",
13412 tp
->static_trace_marker_id
);
13413 uiout
->text ("\n");
13418 tracepoint_print_mention (struct breakpoint
*b
)
13420 if (current_uiout
->is_mi_like_p ())
13425 case bp_tracepoint
:
13426 printf_filtered (_("Tracepoint"));
13427 printf_filtered (_(" %d"), b
->number
);
13429 case bp_fast_tracepoint
:
13430 printf_filtered (_("Fast tracepoint"));
13431 printf_filtered (_(" %d"), b
->number
);
13433 case bp_static_tracepoint
:
13434 printf_filtered (_("Static tracepoint"));
13435 printf_filtered (_(" %d"), b
->number
);
13438 internal_error (__FILE__
, __LINE__
,
13439 _("unhandled tracepoint type %d"), (int) b
->type
);
13446 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13448 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13450 if (self
->type
== bp_fast_tracepoint
)
13451 fprintf_unfiltered (fp
, "ftrace");
13452 else if (self
->type
== bp_static_tracepoint
)
13453 fprintf_unfiltered (fp
, "strace");
13454 else if (self
->type
== bp_tracepoint
)
13455 fprintf_unfiltered (fp
, "trace");
13457 internal_error (__FILE__
, __LINE__
,
13458 _("unhandled tracepoint type %d"), (int) self
->type
);
13460 fprintf_unfiltered (fp
, " %s",
13461 event_location_to_string (self
->location
.get ()));
13462 print_recreate_thread (self
, fp
);
13464 if (tp
->pass_count
)
13465 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13469 tracepoint_create_sals_from_location (const struct event_location
*location
,
13470 struct linespec_result
*canonical
,
13471 enum bptype type_wanted
)
13473 create_sals_from_location_default (location
, canonical
, type_wanted
);
13477 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13478 struct linespec_result
*canonical
,
13480 char *extra_string
,
13481 enum bptype type_wanted
,
13482 enum bpdisp disposition
,
13484 int task
, int ignore_count
,
13485 const struct breakpoint_ops
*ops
,
13486 int from_tty
, int enabled
,
13487 int internal
, unsigned flags
)
13489 create_breakpoints_sal_default (gdbarch
, canonical
,
13490 cond_string
, extra_string
,
13492 disposition
, thread
, task
,
13493 ignore_count
, ops
, from_tty
,
13494 enabled
, internal
, flags
);
13498 tracepoint_decode_location (struct breakpoint
*b
,
13499 const struct event_location
*location
,
13500 struct program_space
*search_pspace
,
13501 struct symtabs_and_lines
*sals
)
13503 decode_location_default (b
, location
, search_pspace
, sals
);
13506 struct breakpoint_ops tracepoint_breakpoint_ops
;
13508 /* The breakpoint_ops structure to be use on tracepoints placed in a
13512 tracepoint_probe_create_sals_from_location
13513 (const struct event_location
*location
,
13514 struct linespec_result
*canonical
,
13515 enum bptype type_wanted
)
13517 /* We use the same method for breakpoint on probes. */
13518 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13522 tracepoint_probe_decode_location (struct breakpoint
*b
,
13523 const struct event_location
*location
,
13524 struct program_space
*search_pspace
,
13525 struct symtabs_and_lines
*sals
)
13527 /* We use the same method for breakpoint on probes. */
13528 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13531 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13533 /* Dprintf breakpoint_ops methods. */
13536 dprintf_re_set (struct breakpoint
*b
)
13538 breakpoint_re_set_default (b
);
13540 /* extra_string should never be non-NULL for dprintf. */
13541 gdb_assert (b
->extra_string
!= NULL
);
13543 /* 1 - connect to target 1, that can run breakpoint commands.
13544 2 - create a dprintf, which resolves fine.
13545 3 - disconnect from target 1
13546 4 - connect to target 2, that can NOT run breakpoint commands.
13548 After steps #3/#4, you'll want the dprintf command list to
13549 be updated, because target 1 and 2 may well return different
13550 answers for target_can_run_breakpoint_commands().
13551 Given absence of finer grained resetting, we get to do
13552 it all the time. */
13553 if (b
->extra_string
!= NULL
)
13554 update_dprintf_command_list (b
);
13557 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13560 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13562 fprintf_unfiltered (fp
, "dprintf %s,%s",
13563 event_location_to_string (tp
->location
.get ()),
13565 print_recreate_thread (tp
, fp
);
13568 /* Implement the "after_condition_true" breakpoint_ops method for
13571 dprintf's are implemented with regular commands in their command
13572 list, but we run the commands here instead of before presenting the
13573 stop to the user, as dprintf's don't actually cause a stop. This
13574 also makes it so that the commands of multiple dprintfs at the same
13575 address are all handled. */
13578 dprintf_after_condition_true (struct bpstats
*bs
)
13580 struct cleanup
*old_chain
;
13581 struct bpstats tmp_bs
= { NULL
};
13582 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13584 /* dprintf's never cause a stop. This wasn't set in the
13585 check_status hook instead because that would make the dprintf's
13586 condition not be evaluated. */
13589 /* Run the command list here. Take ownership of it instead of
13590 copying. We never want these commands to run later in
13591 bpstat_do_actions, if a breakpoint that causes a stop happens to
13592 be set at same address as this dprintf, or even if running the
13593 commands here throws. */
13594 tmp_bs
.commands
= bs
->commands
;
13595 bs
->commands
= NULL
;
13596 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13598 bpstat_do_actions_1 (&tmp_bs_p
);
13600 /* 'tmp_bs.commands' will usually be NULL by now, but
13601 bpstat_do_actions_1 may return early without processing the whole
13603 do_cleanups (old_chain
);
13606 /* The breakpoint_ops structure to be used on static tracepoints with
13610 strace_marker_create_sals_from_location (const struct event_location
*location
,
13611 struct linespec_result
*canonical
,
13612 enum bptype type_wanted
)
13614 struct linespec_sals lsal
;
13615 const char *arg_start
, *arg
;
13617 struct cleanup
*cleanup
;
13619 arg
= arg_start
= get_linespec_location (location
);
13620 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13622 str
= savestring (arg_start
, arg
- arg_start
);
13623 cleanup
= make_cleanup (xfree
, str
);
13624 canonical
->location
= new_linespec_location (&str
);
13625 do_cleanups (cleanup
);
13628 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13629 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13633 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13634 struct linespec_result
*canonical
,
13636 char *extra_string
,
13637 enum bptype type_wanted
,
13638 enum bpdisp disposition
,
13640 int task
, int ignore_count
,
13641 const struct breakpoint_ops
*ops
,
13642 int from_tty
, int enabled
,
13643 int internal
, unsigned flags
)
13646 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13647 canonical
->sals
, 0);
13649 /* If the user is creating a static tracepoint by marker id
13650 (strace -m MARKER_ID), then store the sals index, so that
13651 breakpoint_re_set can try to match up which of the newly
13652 found markers corresponds to this one, and, don't try to
13653 expand multiple locations for each sal, given than SALS
13654 already should contain all sals for MARKER_ID. */
13656 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13658 struct symtabs_and_lines expanded
;
13659 struct tracepoint
*tp
;
13660 event_location_up location
;
13662 expanded
.nelts
= 1;
13663 expanded
.sals
= &lsal
->sals
.sals
[i
];
13665 location
= copy_event_location (canonical
->location
.get ());
13667 tp
= new tracepoint ();
13668 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13669 std::move (location
), NULL
,
13670 cond_string
, extra_string
,
13671 type_wanted
, disposition
,
13672 thread
, task
, ignore_count
, ops
,
13673 from_tty
, enabled
, internal
, flags
,
13674 canonical
->special_display
);
13675 /* Given that its possible to have multiple markers with
13676 the same string id, if the user is creating a static
13677 tracepoint by marker id ("strace -m MARKER_ID"), then
13678 store the sals index, so that breakpoint_re_set can
13679 try to match up which of the newly found markers
13680 corresponds to this one */
13681 tp
->static_trace_marker_id_idx
= i
;
13683 install_breakpoint (internal
, &tp
->base
, 0);
13688 strace_marker_decode_location (struct breakpoint
*b
,
13689 const struct event_location
*location
,
13690 struct program_space
*search_pspace
,
13691 struct symtabs_and_lines
*sals
)
13693 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13694 const char *s
= get_linespec_location (location
);
13696 *sals
= decode_static_tracepoint_spec (&s
);
13697 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13699 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13703 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13706 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13709 strace_marker_p (struct breakpoint
*b
)
13711 return b
->ops
== &strace_marker_breakpoint_ops
;
13714 /* Delete a breakpoint and clean up all traces of it in the data
13718 delete_breakpoint (struct breakpoint
*bpt
)
13720 struct breakpoint
*b
;
13722 gdb_assert (bpt
!= NULL
);
13724 /* Has this bp already been deleted? This can happen because
13725 multiple lists can hold pointers to bp's. bpstat lists are
13728 One example of this happening is a watchpoint's scope bp. When
13729 the scope bp triggers, we notice that the watchpoint is out of
13730 scope, and delete it. We also delete its scope bp. But the
13731 scope bp is marked "auto-deleting", and is already on a bpstat.
13732 That bpstat is then checked for auto-deleting bp's, which are
13735 A real solution to this problem might involve reference counts in
13736 bp's, and/or giving them pointers back to their referencing
13737 bpstat's, and teaching delete_breakpoint to only free a bp's
13738 storage when no more references were extent. A cheaper bandaid
13740 if (bpt
->type
== bp_none
)
13743 /* At least avoid this stale reference until the reference counting
13744 of breakpoints gets resolved. */
13745 if (bpt
->related_breakpoint
!= bpt
)
13747 struct breakpoint
*related
;
13748 struct watchpoint
*w
;
13750 if (bpt
->type
== bp_watchpoint_scope
)
13751 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13752 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13753 w
= (struct watchpoint
*) bpt
;
13757 watchpoint_del_at_next_stop (w
);
13759 /* Unlink bpt from the bpt->related_breakpoint ring. */
13760 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13761 related
= related
->related_breakpoint
);
13762 related
->related_breakpoint
= bpt
->related_breakpoint
;
13763 bpt
->related_breakpoint
= bpt
;
13766 /* watch_command_1 creates a watchpoint but only sets its number if
13767 update_watchpoint succeeds in creating its bp_locations. If there's
13768 a problem in that process, we'll be asked to delete the half-created
13769 watchpoint. In that case, don't announce the deletion. */
13771 observer_notify_breakpoint_deleted (bpt
);
13773 if (breakpoint_chain
== bpt
)
13774 breakpoint_chain
= bpt
->next
;
13776 ALL_BREAKPOINTS (b
)
13777 if (b
->next
== bpt
)
13779 b
->next
= bpt
->next
;
13783 /* Be sure no bpstat's are pointing at the breakpoint after it's
13785 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13786 in all threads for now. Note that we cannot just remove bpstats
13787 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13788 commands are associated with the bpstat; if we remove it here,
13789 then the later call to bpstat_do_actions (&stop_bpstat); in
13790 event-top.c won't do anything, and temporary breakpoints with
13791 commands won't work. */
13793 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13795 /* Now that breakpoint is removed from breakpoint list, update the
13796 global location list. This will remove locations that used to
13797 belong to this breakpoint. Do this before freeing the breakpoint
13798 itself, since remove_breakpoint looks at location's owner. It
13799 might be better design to have location completely
13800 self-contained, but it's not the case now. */
13801 update_global_location_list (UGLL_DONT_INSERT
);
13803 bpt
->ops
->dtor (bpt
);
13804 /* On the chance that someone will soon try again to delete this
13805 same bp, we mark it as deleted before freeing its storage. */
13806 bpt
->type
= bp_none
;
13811 do_delete_breakpoint_cleanup (void *b
)
13813 delete_breakpoint ((struct breakpoint
*) b
);
13817 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13819 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13822 /* Iterator function to call a user-provided callback function once
13823 for each of B and its related breakpoints. */
13826 iterate_over_related_breakpoints (struct breakpoint
*b
,
13827 void (*function
) (struct breakpoint
*,
13831 struct breakpoint
*related
;
13836 struct breakpoint
*next
;
13838 /* FUNCTION may delete RELATED. */
13839 next
= related
->related_breakpoint
;
13841 if (next
== related
)
13843 /* RELATED is the last ring entry. */
13844 function (related
, data
);
13846 /* FUNCTION may have deleted it, so we'd never reach back to
13847 B. There's nothing left to do anyway, so just break
13852 function (related
, data
);
13856 while (related
!= b
);
13860 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13862 delete_breakpoint (b
);
13865 /* A callback for map_breakpoint_numbers that calls
13866 delete_breakpoint. */
13869 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13871 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13875 delete_command (char *arg
, int from_tty
)
13877 struct breakpoint
*b
, *b_tmp
;
13883 int breaks_to_delete
= 0;
13885 /* Delete all breakpoints if no argument. Do not delete
13886 internal breakpoints, these have to be deleted with an
13887 explicit breakpoint number argument. */
13888 ALL_BREAKPOINTS (b
)
13889 if (user_breakpoint_p (b
))
13891 breaks_to_delete
= 1;
13895 /* Ask user only if there are some breakpoints to delete. */
13897 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13899 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13900 if (user_breakpoint_p (b
))
13901 delete_breakpoint (b
);
13905 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13908 /* Return true if all locations of B bound to PSPACE are pending. If
13909 PSPACE is NULL, all locations of all program spaces are
13913 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13915 struct bp_location
*loc
;
13917 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13918 if ((pspace
== NULL
13919 || loc
->pspace
== pspace
)
13920 && !loc
->shlib_disabled
13921 && !loc
->pspace
->executing_startup
)
13926 /* Subroutine of update_breakpoint_locations to simplify it.
13927 Return non-zero if multiple fns in list LOC have the same name.
13928 Null names are ignored. */
13931 ambiguous_names_p (struct bp_location
*loc
)
13933 struct bp_location
*l
;
13934 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13935 (int (*) (const void *,
13936 const void *)) streq
,
13937 NULL
, xcalloc
, xfree
);
13939 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13942 const char *name
= l
->function_name
;
13944 /* Allow for some names to be NULL, ignore them. */
13948 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13950 /* NOTE: We can assume slot != NULL here because xcalloc never
13954 htab_delete (htab
);
13960 htab_delete (htab
);
13964 /* When symbols change, it probably means the sources changed as well,
13965 and it might mean the static tracepoint markers are no longer at
13966 the same address or line numbers they used to be at last we
13967 checked. Losing your static tracepoints whenever you rebuild is
13968 undesirable. This function tries to resync/rematch gdb static
13969 tracepoints with the markers on the target, for static tracepoints
13970 that have not been set by marker id. Static tracepoint that have
13971 been set by marker id are reset by marker id in breakpoint_re_set.
13974 1) For a tracepoint set at a specific address, look for a marker at
13975 the old PC. If one is found there, assume to be the same marker.
13976 If the name / string id of the marker found is different from the
13977 previous known name, assume that means the user renamed the marker
13978 in the sources, and output a warning.
13980 2) For a tracepoint set at a given line number, look for a marker
13981 at the new address of the old line number. If one is found there,
13982 assume to be the same marker. If the name / string id of the
13983 marker found is different from the previous known name, assume that
13984 means the user renamed the marker in the sources, and output a
13987 3) If a marker is no longer found at the same address or line, it
13988 may mean the marker no longer exists. But it may also just mean
13989 the code changed a bit. Maybe the user added a few lines of code
13990 that made the marker move up or down (in line number terms). Ask
13991 the target for info about the marker with the string id as we knew
13992 it. If found, update line number and address in the matching
13993 static tracepoint. This will get confused if there's more than one
13994 marker with the same ID (possible in UST, although unadvised
13995 precisely because it confuses tools). */
13997 static struct symtab_and_line
13998 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14000 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14001 struct static_tracepoint_marker marker
;
14006 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14008 if (target_static_tracepoint_marker_at (pc
, &marker
))
14010 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14011 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14013 tp
->static_trace_marker_id
, marker
.str_id
);
14015 xfree (tp
->static_trace_marker_id
);
14016 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14017 release_static_tracepoint_marker (&marker
);
14022 /* Old marker wasn't found on target at lineno. Try looking it up
14024 if (!sal
.explicit_pc
14026 && sal
.symtab
!= NULL
14027 && tp
->static_trace_marker_id
!= NULL
)
14029 VEC(static_tracepoint_marker_p
) *markers
;
14032 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14034 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14036 struct symtab_and_line sal2
;
14037 struct symbol
*sym
;
14038 struct static_tracepoint_marker
*tpmarker
;
14039 struct ui_out
*uiout
= current_uiout
;
14040 struct explicit_location explicit_loc
;
14042 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14044 xfree (tp
->static_trace_marker_id
);
14045 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14047 warning (_("marker for static tracepoint %d (%s) not "
14048 "found at previous line number"),
14049 b
->number
, tp
->static_trace_marker_id
);
14053 sal2
.pc
= tpmarker
->address
;
14055 sal2
= find_pc_line (tpmarker
->address
, 0);
14056 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14057 uiout
->text ("Now in ");
14060 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
14061 uiout
->text (" at ");
14063 uiout
->field_string ("file",
14064 symtab_to_filename_for_display (sal2
.symtab
));
14067 if (uiout
->is_mi_like_p ())
14069 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14071 uiout
->field_string ("fullname", fullname
);
14074 uiout
->field_int ("line", sal2
.line
);
14075 uiout
->text ("\n");
14077 b
->loc
->line_number
= sal2
.line
;
14078 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14080 b
->location
.reset (NULL
);
14081 initialize_explicit_location (&explicit_loc
);
14082 explicit_loc
.source_filename
14083 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14084 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14085 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14086 b
->location
= new_explicit_location (&explicit_loc
);
14088 /* Might be nice to check if function changed, and warn if
14091 release_static_tracepoint_marker (tpmarker
);
14097 /* Returns 1 iff locations A and B are sufficiently same that
14098 we don't need to report breakpoint as changed. */
14101 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14105 if (a
->address
!= b
->address
)
14108 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14111 if (a
->enabled
!= b
->enabled
)
14118 if ((a
== NULL
) != (b
== NULL
))
14124 /* Split all locations of B that are bound to PSPACE out of B's
14125 location list to a separate list and return that list's head. If
14126 PSPACE is NULL, hoist out all locations of B. */
14128 static struct bp_location
*
14129 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14131 struct bp_location head
;
14132 struct bp_location
*i
= b
->loc
;
14133 struct bp_location
**i_link
= &b
->loc
;
14134 struct bp_location
*hoisted
= &head
;
14136 if (pspace
== NULL
)
14147 if (i
->pspace
== pspace
)
14162 /* Create new breakpoint locations for B (a hardware or software
14163 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14164 zero, then B is a ranged breakpoint. Only recreates locations for
14165 FILTER_PSPACE. Locations of other program spaces are left
14169 update_breakpoint_locations (struct breakpoint
*b
,
14170 struct program_space
*filter_pspace
,
14171 struct symtabs_and_lines sals
,
14172 struct symtabs_and_lines sals_end
)
14175 struct bp_location
*existing_locations
;
14177 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14179 /* Ranged breakpoints have only one start location and one end
14181 b
->enable_state
= bp_disabled
;
14182 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14183 "multiple locations found\n"),
14188 /* If there's no new locations, and all existing locations are
14189 pending, don't do anything. This optimizes the common case where
14190 all locations are in the same shared library, that was unloaded.
14191 We'd like to retain the location, so that when the library is
14192 loaded again, we don't loose the enabled/disabled status of the
14193 individual locations. */
14194 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14197 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14199 for (i
= 0; i
< sals
.nelts
; ++i
)
14201 struct bp_location
*new_loc
;
14203 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14205 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14207 /* Reparse conditions, they might contain references to the
14209 if (b
->cond_string
!= NULL
)
14213 s
= b
->cond_string
;
14216 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14217 block_for_pc (sals
.sals
[i
].pc
),
14220 CATCH (e
, RETURN_MASK_ERROR
)
14222 warning (_("failed to reevaluate condition "
14223 "for breakpoint %d: %s"),
14224 b
->number
, e
.message
);
14225 new_loc
->enabled
= 0;
14230 if (sals_end
.nelts
)
14232 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14234 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14238 /* If possible, carry over 'disable' status from existing
14241 struct bp_location
*e
= existing_locations
;
14242 /* If there are multiple breakpoints with the same function name,
14243 e.g. for inline functions, comparing function names won't work.
14244 Instead compare pc addresses; this is just a heuristic as things
14245 may have moved, but in practice it gives the correct answer
14246 often enough until a better solution is found. */
14247 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14249 for (; e
; e
= e
->next
)
14251 if (!e
->enabled
&& e
->function_name
)
14253 struct bp_location
*l
= b
->loc
;
14254 if (have_ambiguous_names
)
14256 for (; l
; l
= l
->next
)
14257 if (breakpoint_locations_match (e
, l
))
14265 for (; l
; l
= l
->next
)
14266 if (l
->function_name
14267 && strcmp (e
->function_name
, l
->function_name
) == 0)
14277 if (!locations_are_equal (existing_locations
, b
->loc
))
14278 observer_notify_breakpoint_modified (b
);
14281 /* Find the SaL locations corresponding to the given LOCATION.
14282 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14284 static struct symtabs_and_lines
14285 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14286 struct program_space
*search_pspace
, int *found
)
14288 struct symtabs_and_lines sals
= {0};
14289 struct gdb_exception exception
= exception_none
;
14291 gdb_assert (b
->ops
!= NULL
);
14295 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14297 CATCH (e
, RETURN_MASK_ERROR
)
14299 int not_found_and_ok
= 0;
14303 /* For pending breakpoints, it's expected that parsing will
14304 fail until the right shared library is loaded. User has
14305 already told to create pending breakpoints and don't need
14306 extra messages. If breakpoint is in bp_shlib_disabled
14307 state, then user already saw the message about that
14308 breakpoint being disabled, and don't want to see more
14310 if (e
.error
== NOT_FOUND_ERROR
14311 && (b
->condition_not_parsed
14313 && search_pspace
!= NULL
14314 && b
->loc
->pspace
!= search_pspace
)
14315 || (b
->loc
&& b
->loc
->shlib_disabled
)
14316 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14317 || b
->enable_state
== bp_disabled
))
14318 not_found_and_ok
= 1;
14320 if (!not_found_and_ok
)
14322 /* We surely don't want to warn about the same breakpoint
14323 10 times. One solution, implemented here, is disable
14324 the breakpoint on error. Another solution would be to
14325 have separate 'warning emitted' flag. Since this
14326 happens only when a binary has changed, I don't know
14327 which approach is better. */
14328 b
->enable_state
= bp_disabled
;
14329 throw_exception (e
);
14334 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14338 for (i
= 0; i
< sals
.nelts
; ++i
)
14339 resolve_sal_pc (&sals
.sals
[i
]);
14340 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14342 char *cond_string
, *extra_string
;
14345 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14346 &cond_string
, &thread
, &task
,
14348 gdb_assert (b
->cond_string
== NULL
);
14350 b
->cond_string
= cond_string
;
14351 b
->thread
= thread
;
14355 xfree (b
->extra_string
);
14356 b
->extra_string
= extra_string
;
14358 b
->condition_not_parsed
= 0;
14361 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14362 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14372 /* The default re_set method, for typical hardware or software
14373 breakpoints. Reevaluate the breakpoint and recreate its
14377 breakpoint_re_set_default (struct breakpoint
*b
)
14380 struct symtabs_and_lines sals
, sals_end
;
14381 struct symtabs_and_lines expanded
= {0};
14382 struct symtabs_and_lines expanded_end
= {0};
14383 struct program_space
*filter_pspace
= current_program_space
;
14385 sals
= location_to_sals (b
, b
->location
.get (), filter_pspace
, &found
);
14388 make_cleanup (xfree
, sals
.sals
);
14392 if (b
->location_range_end
!= NULL
)
14394 sals_end
= location_to_sals (b
, b
->location_range_end
.get (),
14395 filter_pspace
, &found
);
14398 make_cleanup (xfree
, sals_end
.sals
);
14399 expanded_end
= sals_end
;
14403 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14406 /* Default method for creating SALs from an address string. It basically
14407 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14410 create_sals_from_location_default (const struct event_location
*location
,
14411 struct linespec_result
*canonical
,
14412 enum bptype type_wanted
)
14414 parse_breakpoint_sals (location
, canonical
);
14417 /* Call create_breakpoints_sal for the given arguments. This is the default
14418 function for the `create_breakpoints_sal' method of
14422 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14423 struct linespec_result
*canonical
,
14425 char *extra_string
,
14426 enum bptype type_wanted
,
14427 enum bpdisp disposition
,
14429 int task
, int ignore_count
,
14430 const struct breakpoint_ops
*ops
,
14431 int from_tty
, int enabled
,
14432 int internal
, unsigned flags
)
14434 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14436 type_wanted
, disposition
,
14437 thread
, task
, ignore_count
, ops
, from_tty
,
14438 enabled
, internal
, flags
);
14441 /* Decode the line represented by S by calling decode_line_full. This is the
14442 default function for the `decode_location' method of breakpoint_ops. */
14445 decode_location_default (struct breakpoint
*b
,
14446 const struct event_location
*location
,
14447 struct program_space
*search_pspace
,
14448 struct symtabs_and_lines
*sals
)
14450 struct linespec_result canonical
;
14452 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14453 (struct symtab
*) NULL
, 0,
14454 &canonical
, multiple_symbols_all
,
14457 /* We should get 0 or 1 resulting SALs. */
14458 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14460 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14462 struct linespec_sals
*lsal
;
14464 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14465 *sals
= lsal
->sals
;
14466 /* Arrange it so the destructor does not free the
14468 lsal
->sals
.sals
= NULL
;
14472 /* Prepare the global context for a re-set of breakpoint B. */
14474 static struct cleanup
*
14475 prepare_re_set_context (struct breakpoint
*b
)
14477 input_radix
= b
->input_radix
;
14478 set_language (b
->language
);
14480 return make_cleanup (null_cleanup
, NULL
);
14483 /* Reset a breakpoint given it's struct breakpoint * BINT.
14484 The value we return ends up being the return value from catch_errors.
14485 Unused in this case. */
14488 breakpoint_re_set_one (void *bint
)
14490 /* Get past catch_errs. */
14491 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14492 struct cleanup
*cleanups
;
14494 cleanups
= prepare_re_set_context (b
);
14495 b
->ops
->re_set (b
);
14496 do_cleanups (cleanups
);
14500 /* Re-set breakpoint locations for the current program space.
14501 Locations bound to other program spaces are left untouched. */
14504 breakpoint_re_set (void)
14506 struct breakpoint
*b
, *b_tmp
;
14507 enum language save_language
;
14508 int save_input_radix
;
14509 struct cleanup
*old_chain
;
14511 save_language
= current_language
->la_language
;
14512 save_input_radix
= input_radix
;
14513 old_chain
= save_current_space_and_thread ();
14515 /* Note: we must not try to insert locations until after all
14516 breakpoints have been re-set. Otherwise, e.g., when re-setting
14517 breakpoint 1, we'd insert the locations of breakpoint 2, which
14518 hadn't been re-set yet, and thus may have stale locations. */
14520 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14522 /* Format possible error msg. */
14523 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14525 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14526 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14527 do_cleanups (cleanups
);
14529 set_language (save_language
);
14530 input_radix
= save_input_radix
;
14532 jit_breakpoint_re_set ();
14534 do_cleanups (old_chain
);
14536 create_overlay_event_breakpoint ();
14537 create_longjmp_master_breakpoint ();
14538 create_std_terminate_master_breakpoint ();
14539 create_exception_master_breakpoint ();
14541 /* Now we can insert. */
14542 update_global_location_list (UGLL_MAY_INSERT
);
14545 /* Reset the thread number of this breakpoint:
14547 - If the breakpoint is for all threads, leave it as-is.
14548 - Else, reset it to the current thread for inferior_ptid. */
14550 breakpoint_re_set_thread (struct breakpoint
*b
)
14552 if (b
->thread
!= -1)
14554 if (in_thread_list (inferior_ptid
))
14555 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14557 /* We're being called after following a fork. The new fork is
14558 selected as current, and unless this was a vfork will have a
14559 different program space from the original thread. Reset that
14561 b
->loc
->pspace
= current_program_space
;
14565 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14566 If from_tty is nonzero, it prints a message to that effect,
14567 which ends with a period (no newline). */
14570 set_ignore_count (int bptnum
, int count
, int from_tty
)
14572 struct breakpoint
*b
;
14577 ALL_BREAKPOINTS (b
)
14578 if (b
->number
== bptnum
)
14580 if (is_tracepoint (b
))
14582 if (from_tty
&& count
!= 0)
14583 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14588 b
->ignore_count
= count
;
14592 printf_filtered (_("Will stop next time "
14593 "breakpoint %d is reached."),
14595 else if (count
== 1)
14596 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14599 printf_filtered (_("Will ignore next %d "
14600 "crossings of breakpoint %d."),
14603 observer_notify_breakpoint_modified (b
);
14607 error (_("No breakpoint number %d."), bptnum
);
14610 /* Command to set ignore-count of breakpoint N to COUNT. */
14613 ignore_command (char *args
, int from_tty
)
14619 error_no_arg (_("a breakpoint number"));
14621 num
= get_number (&p
);
14623 error (_("bad breakpoint number: '%s'"), args
);
14625 error (_("Second argument (specified ignore-count) is missing."));
14627 set_ignore_count (num
,
14628 longest_to_int (value_as_long (parse_and_eval (p
))),
14631 printf_filtered ("\n");
14634 /* Call FUNCTION on each of the breakpoints
14635 whose numbers are given in ARGS. */
14638 map_breakpoint_numbers (const char *args
,
14639 void (*function
) (struct breakpoint
*,
14644 struct breakpoint
*b
, *tmp
;
14646 if (args
== 0 || *args
== '\0')
14647 error_no_arg (_("one or more breakpoint numbers"));
14649 number_or_range_parser
parser (args
);
14651 while (!parser
.finished ())
14653 const char *p
= parser
.cur_tok ();
14654 bool match
= false;
14656 num
= parser
.get_number ();
14659 warning (_("bad breakpoint number at or near '%s'"), p
);
14663 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14664 if (b
->number
== num
)
14667 function (b
, data
);
14671 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14676 static struct bp_location
*
14677 find_location_by_number (char *number
)
14679 char *dot
= strchr (number
, '.');
14683 struct breakpoint
*b
;
14684 struct bp_location
*loc
;
14689 bp_num
= get_number (&p1
);
14691 error (_("Bad breakpoint number '%s'"), number
);
14693 ALL_BREAKPOINTS (b
)
14694 if (b
->number
== bp_num
)
14699 if (!b
|| b
->number
!= bp_num
)
14700 error (_("Bad breakpoint number '%s'"), number
);
14703 loc_num
= get_number (&p1
);
14705 error (_("Bad breakpoint location number '%s'"), number
);
14709 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14712 error (_("Bad breakpoint location number '%s'"), dot
+1);
14718 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14719 If from_tty is nonzero, it prints a message to that effect,
14720 which ends with a period (no newline). */
14723 disable_breakpoint (struct breakpoint
*bpt
)
14725 /* Never disable a watchpoint scope breakpoint; we want to
14726 hit them when we leave scope so we can delete both the
14727 watchpoint and its scope breakpoint at that time. */
14728 if (bpt
->type
== bp_watchpoint_scope
)
14731 bpt
->enable_state
= bp_disabled
;
14733 /* Mark breakpoint locations modified. */
14734 mark_breakpoint_modified (bpt
);
14736 if (target_supports_enable_disable_tracepoint ()
14737 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14739 struct bp_location
*location
;
14741 for (location
= bpt
->loc
; location
; location
= location
->next
)
14742 target_disable_tracepoint (location
);
14745 update_global_location_list (UGLL_DONT_INSERT
);
14747 observer_notify_breakpoint_modified (bpt
);
14750 /* A callback for iterate_over_related_breakpoints. */
14753 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14755 disable_breakpoint (b
);
14758 /* A callback for map_breakpoint_numbers that calls
14759 disable_breakpoint. */
14762 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14764 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14768 disable_command (char *args
, int from_tty
)
14772 struct breakpoint
*bpt
;
14774 ALL_BREAKPOINTS (bpt
)
14775 if (user_breakpoint_p (bpt
))
14776 disable_breakpoint (bpt
);
14780 char *num
= extract_arg (&args
);
14784 if (strchr (num
, '.'))
14786 struct bp_location
*loc
= find_location_by_number (num
);
14793 mark_breakpoint_location_modified (loc
);
14795 if (target_supports_enable_disable_tracepoint ()
14796 && current_trace_status ()->running
&& loc
->owner
14797 && is_tracepoint (loc
->owner
))
14798 target_disable_tracepoint (loc
);
14800 update_global_location_list (UGLL_DONT_INSERT
);
14803 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14804 num
= extract_arg (&args
);
14810 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14813 int target_resources_ok
;
14815 if (bpt
->type
== bp_hardware_breakpoint
)
14818 i
= hw_breakpoint_used_count ();
14819 target_resources_ok
=
14820 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14822 if (target_resources_ok
== 0)
14823 error (_("No hardware breakpoint support in the target."));
14824 else if (target_resources_ok
< 0)
14825 error (_("Hardware breakpoints used exceeds limit."));
14828 if (is_watchpoint (bpt
))
14830 /* Initialize it just to avoid a GCC false warning. */
14831 enum enable_state orig_enable_state
= bp_disabled
;
14835 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14837 orig_enable_state
= bpt
->enable_state
;
14838 bpt
->enable_state
= bp_enabled
;
14839 update_watchpoint (w
, 1 /* reparse */);
14841 CATCH (e
, RETURN_MASK_ALL
)
14843 bpt
->enable_state
= orig_enable_state
;
14844 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14851 bpt
->enable_state
= bp_enabled
;
14853 /* Mark breakpoint locations modified. */
14854 mark_breakpoint_modified (bpt
);
14856 if (target_supports_enable_disable_tracepoint ()
14857 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14859 struct bp_location
*location
;
14861 for (location
= bpt
->loc
; location
; location
= location
->next
)
14862 target_enable_tracepoint (location
);
14865 bpt
->disposition
= disposition
;
14866 bpt
->enable_count
= count
;
14867 update_global_location_list (UGLL_MAY_INSERT
);
14869 observer_notify_breakpoint_modified (bpt
);
14874 enable_breakpoint (struct breakpoint
*bpt
)
14876 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14880 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14882 enable_breakpoint (bpt
);
14885 /* A callback for map_breakpoint_numbers that calls
14886 enable_breakpoint. */
14889 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14891 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14894 /* The enable command enables the specified breakpoints (or all defined
14895 breakpoints) so they once again become (or continue to be) effective
14896 in stopping the inferior. */
14899 enable_command (char *args
, int from_tty
)
14903 struct breakpoint
*bpt
;
14905 ALL_BREAKPOINTS (bpt
)
14906 if (user_breakpoint_p (bpt
))
14907 enable_breakpoint (bpt
);
14911 char *num
= extract_arg (&args
);
14915 if (strchr (num
, '.'))
14917 struct bp_location
*loc
= find_location_by_number (num
);
14924 mark_breakpoint_location_modified (loc
);
14926 if (target_supports_enable_disable_tracepoint ()
14927 && current_trace_status ()->running
&& loc
->owner
14928 && is_tracepoint (loc
->owner
))
14929 target_enable_tracepoint (loc
);
14931 update_global_location_list (UGLL_MAY_INSERT
);
14934 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14935 num
= extract_arg (&args
);
14940 /* This struct packages up disposition data for application to multiple
14950 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14952 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14954 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14958 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14960 struct disp_data disp
= { disp_disable
, 1 };
14962 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14966 enable_once_command (char *args
, int from_tty
)
14968 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14972 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14974 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14976 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14980 enable_count_command (char *args
, int from_tty
)
14985 error_no_arg (_("hit count"));
14987 count
= get_number (&args
);
14989 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14993 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14995 struct disp_data disp
= { disp_del
, 1 };
14997 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15001 enable_delete_command (char *args
, int from_tty
)
15003 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15007 set_breakpoint_cmd (char *args
, int from_tty
)
15012 show_breakpoint_cmd (char *args
, int from_tty
)
15016 /* Invalidate last known value of any hardware watchpoint if
15017 the memory which that value represents has been written to by
15021 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15022 CORE_ADDR addr
, ssize_t len
,
15023 const bfd_byte
*data
)
15025 struct breakpoint
*bp
;
15027 ALL_BREAKPOINTS (bp
)
15028 if (bp
->enable_state
== bp_enabled
15029 && bp
->type
== bp_hardware_watchpoint
)
15031 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15033 if (wp
->val_valid
&& wp
->val
)
15035 struct bp_location
*loc
;
15037 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15038 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15039 && loc
->address
+ loc
->length
> addr
15040 && addr
+ len
> loc
->address
)
15042 value_free (wp
->val
);
15050 /* Create and insert a breakpoint for software single step. */
15053 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15054 struct address_space
*aspace
,
15057 struct thread_info
*tp
= inferior_thread ();
15058 struct symtab_and_line sal
;
15059 CORE_ADDR pc
= next_pc
;
15061 if (tp
->control
.single_step_breakpoints
== NULL
)
15063 tp
->control
.single_step_breakpoints
15064 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15067 sal
= find_pc_line (pc
, 0);
15069 sal
.section
= find_pc_overlay (pc
);
15070 sal
.explicit_pc
= 1;
15071 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15073 update_global_location_list (UGLL_INSERT
);
15076 /* Insert single step breakpoints according to the current state. */
15079 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
15081 struct regcache
*regcache
= get_current_regcache ();
15082 std::vector
<CORE_ADDR
> next_pcs
;
15084 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
15086 if (!next_pcs
.empty ())
15088 struct frame_info
*frame
= get_current_frame ();
15089 struct address_space
*aspace
= get_frame_address_space (frame
);
15091 for (CORE_ADDR pc
: next_pcs
)
15092 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
15100 /* See breakpoint.h. */
15103 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15104 struct address_space
*aspace
,
15107 struct bp_location
*loc
;
15109 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15111 && breakpoint_location_address_match (loc
, aspace
, pc
))
15117 /* Check whether a software single-step breakpoint is inserted at
15121 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15124 struct breakpoint
*bpt
;
15126 ALL_BREAKPOINTS (bpt
)
15128 if (bpt
->type
== bp_single_step
15129 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15135 /* Tracepoint-specific operations. */
15137 /* Set tracepoint count to NUM. */
15139 set_tracepoint_count (int num
)
15141 tracepoint_count
= num
;
15142 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15146 trace_command (char *arg
, int from_tty
)
15148 struct breakpoint_ops
*ops
;
15150 event_location_up location
= string_to_event_location (&arg
,
15152 if (location
!= NULL
15153 && event_location_type (location
.get ()) == PROBE_LOCATION
)
15154 ops
= &tracepoint_probe_breakpoint_ops
;
15156 ops
= &tracepoint_breakpoint_ops
;
15158 create_breakpoint (get_current_arch (),
15160 NULL
, 0, arg
, 1 /* parse arg */,
15162 bp_tracepoint
/* type_wanted */,
15163 0 /* Ignore count */,
15164 pending_break_support
,
15168 0 /* internal */, 0);
15172 ftrace_command (char *arg
, int from_tty
)
15174 event_location_up location
= string_to_event_location (&arg
,
15176 create_breakpoint (get_current_arch (),
15178 NULL
, 0, arg
, 1 /* parse arg */,
15180 bp_fast_tracepoint
/* type_wanted */,
15181 0 /* Ignore count */,
15182 pending_break_support
,
15183 &tracepoint_breakpoint_ops
,
15186 0 /* internal */, 0);
15189 /* strace command implementation. Creates a static tracepoint. */
15192 strace_command (char *arg
, int from_tty
)
15194 struct breakpoint_ops
*ops
;
15195 event_location_up location
;
15196 struct cleanup
*back_to
;
15198 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15199 or with a normal static tracepoint. */
15200 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15202 ops
= &strace_marker_breakpoint_ops
;
15203 location
= new_linespec_location (&arg
);
15207 ops
= &tracepoint_breakpoint_ops
;
15208 location
= string_to_event_location (&arg
, current_language
);
15211 create_breakpoint (get_current_arch (),
15213 NULL
, 0, arg
, 1 /* parse arg */,
15215 bp_static_tracepoint
/* type_wanted */,
15216 0 /* Ignore count */,
15217 pending_break_support
,
15221 0 /* internal */, 0);
15224 /* Set up a fake reader function that gets command lines from a linked
15225 list that was acquired during tracepoint uploading. */
15227 static struct uploaded_tp
*this_utp
;
15228 static int next_cmd
;
15231 read_uploaded_action (void)
15235 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15242 /* Given information about a tracepoint as recorded on a target (which
15243 can be either a live system or a trace file), attempt to create an
15244 equivalent GDB tracepoint. This is not a reliable process, since
15245 the target does not necessarily have all the information used when
15246 the tracepoint was originally defined. */
15248 struct tracepoint
*
15249 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15251 char *addr_str
, small_buf
[100];
15252 struct tracepoint
*tp
;
15254 if (utp
->at_string
)
15255 addr_str
= utp
->at_string
;
15258 /* In the absence of a source location, fall back to raw
15259 address. Since there is no way to confirm that the address
15260 means the same thing as when the trace was started, warn the
15262 warning (_("Uploaded tracepoint %d has no "
15263 "source location, using raw address"),
15265 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15266 addr_str
= small_buf
;
15269 /* There's not much we can do with a sequence of bytecodes. */
15270 if (utp
->cond
&& !utp
->cond_string
)
15271 warning (_("Uploaded tracepoint %d condition "
15272 "has no source form, ignoring it"),
15275 event_location_up location
= string_to_event_location (&addr_str
,
15277 if (!create_breakpoint (get_current_arch (),
15279 utp
->cond_string
, -1, addr_str
,
15280 0 /* parse cond/thread */,
15282 utp
->type
/* type_wanted */,
15283 0 /* Ignore count */,
15284 pending_break_support
,
15285 &tracepoint_breakpoint_ops
,
15287 utp
->enabled
/* enabled */,
15289 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15292 /* Get the tracepoint we just created. */
15293 tp
= get_tracepoint (tracepoint_count
);
15294 gdb_assert (tp
!= NULL
);
15298 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15301 trace_pass_command (small_buf
, 0);
15304 /* If we have uploaded versions of the original commands, set up a
15305 special-purpose "reader" function and call the usual command line
15306 reader, then pass the result to the breakpoint command-setting
15308 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15310 command_line_up cmd_list
;
15315 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15317 breakpoint_set_commands (&tp
->base
, std::move (cmd_list
));
15319 else if (!VEC_empty (char_ptr
, utp
->actions
)
15320 || !VEC_empty (char_ptr
, utp
->step_actions
))
15321 warning (_("Uploaded tracepoint %d actions "
15322 "have no source form, ignoring them"),
15325 /* Copy any status information that might be available. */
15326 tp
->base
.hit_count
= utp
->hit_count
;
15327 tp
->traceframe_usage
= utp
->traceframe_usage
;
15332 /* Print information on tracepoint number TPNUM_EXP, or all if
15336 tracepoints_info (char *args
, int from_tty
)
15338 struct ui_out
*uiout
= current_uiout
;
15341 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15343 if (num_printed
== 0)
15345 if (args
== NULL
|| *args
== '\0')
15346 uiout
->message ("No tracepoints.\n");
15348 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15351 default_collect_info ();
15354 /* The 'enable trace' command enables tracepoints.
15355 Not supported by all targets. */
15357 enable_trace_command (char *args
, int from_tty
)
15359 enable_command (args
, from_tty
);
15362 /* The 'disable trace' command disables tracepoints.
15363 Not supported by all targets. */
15365 disable_trace_command (char *args
, int from_tty
)
15367 disable_command (args
, from_tty
);
15370 /* Remove a tracepoint (or all if no argument). */
15372 delete_trace_command (char *arg
, int from_tty
)
15374 struct breakpoint
*b
, *b_tmp
;
15380 int breaks_to_delete
= 0;
15382 /* Delete all breakpoints if no argument.
15383 Do not delete internal or call-dummy breakpoints, these
15384 have to be deleted with an explicit breakpoint number
15386 ALL_TRACEPOINTS (b
)
15387 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15389 breaks_to_delete
= 1;
15393 /* Ask user only if there are some breakpoints to delete. */
15395 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15397 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15398 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15399 delete_breakpoint (b
);
15403 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15406 /* Helper function for trace_pass_command. */
15409 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15411 tp
->pass_count
= count
;
15412 observer_notify_breakpoint_modified (&tp
->base
);
15414 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15415 tp
->base
.number
, count
);
15418 /* Set passcount for tracepoint.
15420 First command argument is passcount, second is tracepoint number.
15421 If tracepoint number omitted, apply to most recently defined.
15422 Also accepts special argument "all". */
15425 trace_pass_command (char *args
, int from_tty
)
15427 struct tracepoint
*t1
;
15428 unsigned int count
;
15430 if (args
== 0 || *args
== 0)
15431 error (_("passcount command requires an "
15432 "argument (count + optional TP num)"));
15434 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15436 args
= skip_spaces (args
);
15437 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15439 struct breakpoint
*b
;
15441 args
+= 3; /* Skip special argument "all". */
15443 error (_("Junk at end of arguments."));
15445 ALL_TRACEPOINTS (b
)
15447 t1
= (struct tracepoint
*) b
;
15448 trace_pass_set_count (t1
, count
, from_tty
);
15451 else if (*args
== '\0')
15453 t1
= get_tracepoint_by_number (&args
, NULL
);
15455 trace_pass_set_count (t1
, count
, from_tty
);
15459 number_or_range_parser
parser (args
);
15460 while (!parser
.finished ())
15462 t1
= get_tracepoint_by_number (&args
, &parser
);
15464 trace_pass_set_count (t1
, count
, from_tty
);
15469 struct tracepoint
*
15470 get_tracepoint (int num
)
15472 struct breakpoint
*t
;
15474 ALL_TRACEPOINTS (t
)
15475 if (t
->number
== num
)
15476 return (struct tracepoint
*) t
;
15481 /* Find the tracepoint with the given target-side number (which may be
15482 different from the tracepoint number after disconnecting and
15485 struct tracepoint
*
15486 get_tracepoint_by_number_on_target (int num
)
15488 struct breakpoint
*b
;
15490 ALL_TRACEPOINTS (b
)
15492 struct tracepoint
*t
= (struct tracepoint
*) b
;
15494 if (t
->number_on_target
== num
)
15501 /* Utility: parse a tracepoint number and look it up in the list.
15502 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15503 If the argument is missing, the most recent tracepoint
15504 (tracepoint_count) is returned. */
15506 struct tracepoint
*
15507 get_tracepoint_by_number (char **arg
,
15508 number_or_range_parser
*parser
)
15510 struct breakpoint
*t
;
15512 char *instring
= arg
== NULL
? NULL
: *arg
;
15514 if (parser
!= NULL
)
15516 gdb_assert (!parser
->finished ());
15517 tpnum
= parser
->get_number ();
15519 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15520 tpnum
= tracepoint_count
;
15522 tpnum
= get_number (arg
);
15526 if (instring
&& *instring
)
15527 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15530 printf_filtered (_("No previous tracepoint\n"));
15534 ALL_TRACEPOINTS (t
)
15535 if (t
->number
== tpnum
)
15537 return (struct tracepoint
*) t
;
15540 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15545 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15547 if (b
->thread
!= -1)
15548 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15551 fprintf_unfiltered (fp
, " task %d", b
->task
);
15553 fprintf_unfiltered (fp
, "\n");
15556 /* Save information on user settable breakpoints (watchpoints, etc) to
15557 a new script file named FILENAME. If FILTER is non-NULL, call it
15558 on each breakpoint and only include the ones for which it returns
15562 save_breakpoints (char *filename
, int from_tty
,
15563 int (*filter
) (const struct breakpoint
*))
15565 struct breakpoint
*tp
;
15567 struct cleanup
*cleanup
;
15568 int extra_trace_bits
= 0;
15570 if (filename
== 0 || *filename
== 0)
15571 error (_("Argument required (file name in which to save)"));
15573 /* See if we have anything to save. */
15574 ALL_BREAKPOINTS (tp
)
15576 /* Skip internal and momentary breakpoints. */
15577 if (!user_breakpoint_p (tp
))
15580 /* If we have a filter, only save the breakpoints it accepts. */
15581 if (filter
&& !filter (tp
))
15586 if (is_tracepoint (tp
))
15588 extra_trace_bits
= 1;
15590 /* We can stop searching. */
15597 warning (_("Nothing to save."));
15601 filename
= tilde_expand (filename
);
15602 cleanup
= make_cleanup (xfree
, filename
);
15606 if (!fp
.open (filename
, "w"))
15607 error (_("Unable to open file '%s' for saving (%s)"),
15608 filename
, safe_strerror (errno
));
15610 if (extra_trace_bits
)
15611 save_trace_state_variables (&fp
);
15613 ALL_BREAKPOINTS (tp
)
15615 /* Skip internal and momentary breakpoints. */
15616 if (!user_breakpoint_p (tp
))
15619 /* If we have a filter, only save the breakpoints it accepts. */
15620 if (filter
&& !filter (tp
))
15623 tp
->ops
->print_recreate (tp
, &fp
);
15625 /* Note, we can't rely on tp->number for anything, as we can't
15626 assume the recreated breakpoint numbers will match. Use $bpnum
15629 if (tp
->cond_string
)
15630 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15632 if (tp
->ignore_count
)
15633 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15635 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15637 fp
.puts (" commands\n");
15639 current_uiout
->redirect (&fp
);
15642 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15644 CATCH (ex
, RETURN_MASK_ALL
)
15646 current_uiout
->redirect (NULL
);
15647 throw_exception (ex
);
15651 current_uiout
->redirect (NULL
);
15652 fp
.puts (" end\n");
15655 if (tp
->enable_state
== bp_disabled
)
15656 fp
.puts ("disable $bpnum\n");
15658 /* If this is a multi-location breakpoint, check if the locations
15659 should be individually disabled. Watchpoint locations are
15660 special, and not user visible. */
15661 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15663 struct bp_location
*loc
;
15666 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15668 fp
.printf ("disable $bpnum.%d\n", n
);
15672 if (extra_trace_bits
&& *default_collect
)
15673 fp
.printf ("set default-collect %s\n", default_collect
);
15676 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15677 do_cleanups (cleanup
);
15680 /* The `save breakpoints' command. */
15683 save_breakpoints_command (char *args
, int from_tty
)
15685 save_breakpoints (args
, from_tty
, NULL
);
15688 /* The `save tracepoints' command. */
15691 save_tracepoints_command (char *args
, int from_tty
)
15693 save_breakpoints (args
, from_tty
, is_tracepoint
);
15696 /* Create a vector of all tracepoints. */
15698 VEC(breakpoint_p
) *
15699 all_tracepoints (void)
15701 VEC(breakpoint_p
) *tp_vec
= 0;
15702 struct breakpoint
*tp
;
15704 ALL_TRACEPOINTS (tp
)
15706 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15713 /* This help string is used to consolidate all the help string for specifying
15714 locations used by several commands. */
15716 #define LOCATION_HELP_STRING \
15717 "Linespecs are colon-separated lists of location parameters, such as\n\
15718 source filename, function name, label name, and line number.\n\
15719 Example: To specify the start of a label named \"the_top\" in the\n\
15720 function \"fact\" in the file \"factorial.c\", use\n\
15721 \"factorial.c:fact:the_top\".\n\
15723 Address locations begin with \"*\" and specify an exact address in the\n\
15724 program. Example: To specify the fourth byte past the start function\n\
15725 \"main\", use \"*main + 4\".\n\
15727 Explicit locations are similar to linespecs but use an option/argument\n\
15728 syntax to specify location parameters.\n\
15729 Example: To specify the start of the label named \"the_top\" in the\n\
15730 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15731 -function fact -label the_top\".\n"
15733 /* This help string is used for the break, hbreak, tbreak and thbreak
15734 commands. It is defined as a macro to prevent duplication.
15735 COMMAND should be a string constant containing the name of the
15738 #define BREAK_ARGS_HELP(command) \
15739 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15740 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15741 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15742 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15743 `-probe-dtrace' (for a DTrace probe).\n\
15744 LOCATION may be a linespec, address, or explicit location as described\n\
15747 With no LOCATION, uses current execution address of the selected\n\
15748 stack frame. This is useful for breaking on return to a stack frame.\n\
15750 THREADNUM is the number from \"info threads\".\n\
15751 CONDITION is a boolean expression.\n\
15752 \n" LOCATION_HELP_STRING "\n\
15753 Multiple breakpoints at one place are permitted, and useful if their\n\
15754 conditions are different.\n\
15756 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15758 /* List of subcommands for "catch". */
15759 static struct cmd_list_element
*catch_cmdlist
;
15761 /* List of subcommands for "tcatch". */
15762 static struct cmd_list_element
*tcatch_cmdlist
;
15765 add_catch_command (const char *name
, const char *docstring
,
15766 cmd_sfunc_ftype
*sfunc
,
15767 completer_ftype
*completer
,
15768 void *user_data_catch
,
15769 void *user_data_tcatch
)
15771 struct cmd_list_element
*command
;
15773 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15775 set_cmd_sfunc (command
, sfunc
);
15776 set_cmd_context (command
, user_data_catch
);
15777 set_cmd_completer (command
, completer
);
15779 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15781 set_cmd_sfunc (command
, sfunc
);
15782 set_cmd_context (command
, user_data_tcatch
);
15783 set_cmd_completer (command
, completer
);
15787 save_command (char *arg
, int from_tty
)
15789 printf_unfiltered (_("\"save\" must be followed by "
15790 "the name of a save subcommand.\n"));
15791 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15794 struct breakpoint
*
15795 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15798 struct breakpoint
*b
, *b_tmp
;
15800 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15802 if ((*callback
) (b
, data
))
15809 /* Zero if any of the breakpoint's locations could be a location where
15810 functions have been inlined, nonzero otherwise. */
15813 is_non_inline_function (struct breakpoint
*b
)
15815 /* The shared library event breakpoint is set on the address of a
15816 non-inline function. */
15817 if (b
->type
== bp_shlib_event
)
15823 /* Nonzero if the specified PC cannot be a location where functions
15824 have been inlined. */
15827 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15828 const struct target_waitstatus
*ws
)
15830 struct breakpoint
*b
;
15831 struct bp_location
*bl
;
15833 ALL_BREAKPOINTS (b
)
15835 if (!is_non_inline_function (b
))
15838 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15840 if (!bl
->shlib_disabled
15841 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15849 /* Remove any references to OBJFILE which is going to be freed. */
15852 breakpoint_free_objfile (struct objfile
*objfile
)
15854 struct bp_location
**locp
, *loc
;
15856 ALL_BP_LOCATIONS (loc
, locp
)
15857 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15858 loc
->symtab
= NULL
;
15862 initialize_breakpoint_ops (void)
15864 static int initialized
= 0;
15866 struct breakpoint_ops
*ops
;
15872 /* The breakpoint_ops structure to be inherit by all kinds of
15873 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15874 internal and momentary breakpoints, etc.). */
15875 ops
= &bkpt_base_breakpoint_ops
;
15876 *ops
= base_breakpoint_ops
;
15877 ops
->re_set
= bkpt_re_set
;
15878 ops
->insert_location
= bkpt_insert_location
;
15879 ops
->remove_location
= bkpt_remove_location
;
15880 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15881 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15882 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15883 ops
->decode_location
= bkpt_decode_location
;
15885 /* The breakpoint_ops structure to be used in regular breakpoints. */
15886 ops
= &bkpt_breakpoint_ops
;
15887 *ops
= bkpt_base_breakpoint_ops
;
15888 ops
->re_set
= bkpt_re_set
;
15889 ops
->resources_needed
= bkpt_resources_needed
;
15890 ops
->print_it
= bkpt_print_it
;
15891 ops
->print_mention
= bkpt_print_mention
;
15892 ops
->print_recreate
= bkpt_print_recreate
;
15894 /* Ranged breakpoints. */
15895 ops
= &ranged_breakpoint_ops
;
15896 *ops
= bkpt_breakpoint_ops
;
15897 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15898 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15899 ops
->print_it
= print_it_ranged_breakpoint
;
15900 ops
->print_one
= print_one_ranged_breakpoint
;
15901 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15902 ops
->print_mention
= print_mention_ranged_breakpoint
;
15903 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15905 /* Internal breakpoints. */
15906 ops
= &internal_breakpoint_ops
;
15907 *ops
= bkpt_base_breakpoint_ops
;
15908 ops
->re_set
= internal_bkpt_re_set
;
15909 ops
->check_status
= internal_bkpt_check_status
;
15910 ops
->print_it
= internal_bkpt_print_it
;
15911 ops
->print_mention
= internal_bkpt_print_mention
;
15913 /* Momentary breakpoints. */
15914 ops
= &momentary_breakpoint_ops
;
15915 *ops
= bkpt_base_breakpoint_ops
;
15916 ops
->re_set
= momentary_bkpt_re_set
;
15917 ops
->check_status
= momentary_bkpt_check_status
;
15918 ops
->print_it
= momentary_bkpt_print_it
;
15919 ops
->print_mention
= momentary_bkpt_print_mention
;
15921 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15922 ops
= &longjmp_breakpoint_ops
;
15923 *ops
= momentary_breakpoint_ops
;
15924 ops
->dtor
= longjmp_bkpt_dtor
;
15926 /* Probe breakpoints. */
15927 ops
= &bkpt_probe_breakpoint_ops
;
15928 *ops
= bkpt_breakpoint_ops
;
15929 ops
->insert_location
= bkpt_probe_insert_location
;
15930 ops
->remove_location
= bkpt_probe_remove_location
;
15931 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15932 ops
->decode_location
= bkpt_probe_decode_location
;
15935 ops
= &watchpoint_breakpoint_ops
;
15936 *ops
= base_breakpoint_ops
;
15937 ops
->dtor
= dtor_watchpoint
;
15938 ops
->re_set
= re_set_watchpoint
;
15939 ops
->insert_location
= insert_watchpoint
;
15940 ops
->remove_location
= remove_watchpoint
;
15941 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15942 ops
->check_status
= check_status_watchpoint
;
15943 ops
->resources_needed
= resources_needed_watchpoint
;
15944 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15945 ops
->print_it
= print_it_watchpoint
;
15946 ops
->print_mention
= print_mention_watchpoint
;
15947 ops
->print_recreate
= print_recreate_watchpoint
;
15948 ops
->explains_signal
= explains_signal_watchpoint
;
15950 /* Masked watchpoints. */
15951 ops
= &masked_watchpoint_breakpoint_ops
;
15952 *ops
= watchpoint_breakpoint_ops
;
15953 ops
->insert_location
= insert_masked_watchpoint
;
15954 ops
->remove_location
= remove_masked_watchpoint
;
15955 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15956 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15957 ops
->print_it
= print_it_masked_watchpoint
;
15958 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15959 ops
->print_mention
= print_mention_masked_watchpoint
;
15960 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15963 ops
= &tracepoint_breakpoint_ops
;
15964 *ops
= base_breakpoint_ops
;
15965 ops
->re_set
= tracepoint_re_set
;
15966 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15967 ops
->print_one_detail
= tracepoint_print_one_detail
;
15968 ops
->print_mention
= tracepoint_print_mention
;
15969 ops
->print_recreate
= tracepoint_print_recreate
;
15970 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15971 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15972 ops
->decode_location
= tracepoint_decode_location
;
15974 /* Probe tracepoints. */
15975 ops
= &tracepoint_probe_breakpoint_ops
;
15976 *ops
= tracepoint_breakpoint_ops
;
15977 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15978 ops
->decode_location
= tracepoint_probe_decode_location
;
15980 /* Static tracepoints with marker (`-m'). */
15981 ops
= &strace_marker_breakpoint_ops
;
15982 *ops
= tracepoint_breakpoint_ops
;
15983 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15984 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15985 ops
->decode_location
= strace_marker_decode_location
;
15987 /* Fork catchpoints. */
15988 ops
= &catch_fork_breakpoint_ops
;
15989 *ops
= base_breakpoint_ops
;
15990 ops
->insert_location
= insert_catch_fork
;
15991 ops
->remove_location
= remove_catch_fork
;
15992 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15993 ops
->print_it
= print_it_catch_fork
;
15994 ops
->print_one
= print_one_catch_fork
;
15995 ops
->print_mention
= print_mention_catch_fork
;
15996 ops
->print_recreate
= print_recreate_catch_fork
;
15998 /* Vfork catchpoints. */
15999 ops
= &catch_vfork_breakpoint_ops
;
16000 *ops
= base_breakpoint_ops
;
16001 ops
->insert_location
= insert_catch_vfork
;
16002 ops
->remove_location
= remove_catch_vfork
;
16003 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16004 ops
->print_it
= print_it_catch_vfork
;
16005 ops
->print_one
= print_one_catch_vfork
;
16006 ops
->print_mention
= print_mention_catch_vfork
;
16007 ops
->print_recreate
= print_recreate_catch_vfork
;
16009 /* Exec catchpoints. */
16010 ops
= &catch_exec_breakpoint_ops
;
16011 *ops
= base_breakpoint_ops
;
16012 ops
->dtor
= dtor_catch_exec
;
16013 ops
->insert_location
= insert_catch_exec
;
16014 ops
->remove_location
= remove_catch_exec
;
16015 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16016 ops
->print_it
= print_it_catch_exec
;
16017 ops
->print_one
= print_one_catch_exec
;
16018 ops
->print_mention
= print_mention_catch_exec
;
16019 ops
->print_recreate
= print_recreate_catch_exec
;
16021 /* Solib-related catchpoints. */
16022 ops
= &catch_solib_breakpoint_ops
;
16023 *ops
= base_breakpoint_ops
;
16024 ops
->dtor
= dtor_catch_solib
;
16025 ops
->insert_location
= insert_catch_solib
;
16026 ops
->remove_location
= remove_catch_solib
;
16027 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16028 ops
->check_status
= check_status_catch_solib
;
16029 ops
->print_it
= print_it_catch_solib
;
16030 ops
->print_one
= print_one_catch_solib
;
16031 ops
->print_mention
= print_mention_catch_solib
;
16032 ops
->print_recreate
= print_recreate_catch_solib
;
16034 ops
= &dprintf_breakpoint_ops
;
16035 *ops
= bkpt_base_breakpoint_ops
;
16036 ops
->re_set
= dprintf_re_set
;
16037 ops
->resources_needed
= bkpt_resources_needed
;
16038 ops
->print_it
= bkpt_print_it
;
16039 ops
->print_mention
= bkpt_print_mention
;
16040 ops
->print_recreate
= dprintf_print_recreate
;
16041 ops
->after_condition_true
= dprintf_after_condition_true
;
16042 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16045 /* Chain containing all defined "enable breakpoint" subcommands. */
16047 static struct cmd_list_element
*enablebreaklist
= NULL
;
16050 _initialize_breakpoint (void)
16052 struct cmd_list_element
*c
;
16054 initialize_breakpoint_ops ();
16056 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16057 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16058 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16060 breakpoint_objfile_key
16061 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16063 breakpoint_chain
= 0;
16064 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16065 before a breakpoint is set. */
16066 breakpoint_count
= 0;
16068 tracepoint_count
= 0;
16070 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16071 Set ignore-count of breakpoint number N to COUNT.\n\
16072 Usage is `ignore N COUNT'."));
16074 add_com ("commands", class_breakpoint
, commands_command
, _("\
16075 Set commands to be executed when the given breakpoints are hit.\n\
16076 Give a space-separated breakpoint list as argument after \"commands\".\n\
16077 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
16079 With no argument, the targeted breakpoint is the last one set.\n\
16080 The commands themselves follow starting on the next line.\n\
16081 Type a line containing \"end\" to indicate the end of them.\n\
16082 Give \"silent\" as the first line to make the breakpoint silent;\n\
16083 then no output is printed when it is hit, except what the commands print."));
16085 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16086 Specify breakpoint number N to break only if COND is true.\n\
16087 Usage is `condition N COND', where N is an integer and COND is an\n\
16088 expression to be evaluated whenever breakpoint N is reached."));
16089 set_cmd_completer (c
, condition_completer
);
16091 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16092 Set a temporary breakpoint.\n\
16093 Like \"break\" except the breakpoint is only temporary,\n\
16094 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16095 by using \"enable delete\" on the breakpoint number.\n\
16097 BREAK_ARGS_HELP ("tbreak")));
16098 set_cmd_completer (c
, location_completer
);
16100 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16101 Set a hardware assisted breakpoint.\n\
16102 Like \"break\" except the breakpoint requires hardware support,\n\
16103 some target hardware may not have this support.\n\
16105 BREAK_ARGS_HELP ("hbreak")));
16106 set_cmd_completer (c
, location_completer
);
16108 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16109 Set a temporary hardware assisted breakpoint.\n\
16110 Like \"hbreak\" except the breakpoint is only temporary,\n\
16111 so it will be deleted when hit.\n\
16113 BREAK_ARGS_HELP ("thbreak")));
16114 set_cmd_completer (c
, location_completer
);
16116 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16117 Enable some breakpoints.\n\
16118 Give breakpoint numbers (separated by spaces) as arguments.\n\
16119 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16120 This is used to cancel the effect of the \"disable\" command.\n\
16121 With a subcommand you can enable temporarily."),
16122 &enablelist
, "enable ", 1, &cmdlist
);
16124 add_com_alias ("en", "enable", class_breakpoint
, 1);
16126 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16127 Enable some breakpoints.\n\
16128 Give breakpoint numbers (separated by spaces) as arguments.\n\
16129 This is used to cancel the effect of the \"disable\" command.\n\
16130 May be abbreviated to simply \"enable\".\n"),
16131 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16133 add_cmd ("once", no_class
, enable_once_command
, _("\
16134 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16135 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16138 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16139 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16140 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16143 add_cmd ("count", no_class
, enable_count_command
, _("\
16144 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16145 If a breakpoint is hit while enabled in this fashion,\n\
16146 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16149 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16150 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16151 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16154 add_cmd ("once", no_class
, enable_once_command
, _("\
16155 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16156 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16159 add_cmd ("count", no_class
, enable_count_command
, _("\
16160 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16161 If a breakpoint is hit while enabled in this fashion,\n\
16162 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16165 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16166 Disable some breakpoints.\n\
16167 Arguments are breakpoint numbers with spaces in between.\n\
16168 To disable all breakpoints, give no argument.\n\
16169 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16170 &disablelist
, "disable ", 1, &cmdlist
);
16171 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16172 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16174 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16175 Disable some breakpoints.\n\
16176 Arguments are breakpoint numbers with spaces in between.\n\
16177 To disable all breakpoints, give no argument.\n\
16178 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16179 This command may be abbreviated \"disable\"."),
16182 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16183 Delete some breakpoints or auto-display expressions.\n\
16184 Arguments are breakpoint numbers with spaces in between.\n\
16185 To delete all breakpoints, give no argument.\n\
16187 Also a prefix command for deletion of other GDB objects.\n\
16188 The \"unset\" command is also an alias for \"delete\"."),
16189 &deletelist
, "delete ", 1, &cmdlist
);
16190 add_com_alias ("d", "delete", class_breakpoint
, 1);
16191 add_com_alias ("del", "delete", class_breakpoint
, 1);
16193 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16194 Delete some breakpoints or auto-display expressions.\n\
16195 Arguments are breakpoint numbers with spaces in between.\n\
16196 To delete all breakpoints, give no argument.\n\
16197 This command may be abbreviated \"delete\"."),
16200 add_com ("clear", class_breakpoint
, clear_command
, _("\
16201 Clear breakpoint at specified location.\n\
16202 Argument may be a linespec, explicit, or address location as described below.\n\
16204 With no argument, clears all breakpoints in the line that the selected frame\n\
16205 is executing in.\n"
16206 "\n" LOCATION_HELP_STRING
"\n\
16207 See also the \"delete\" command which clears breakpoints by number."));
16208 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16210 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16211 Set breakpoint at specified location.\n"
16212 BREAK_ARGS_HELP ("break")));
16213 set_cmd_completer (c
, location_completer
);
16215 add_com_alias ("b", "break", class_run
, 1);
16216 add_com_alias ("br", "break", class_run
, 1);
16217 add_com_alias ("bre", "break", class_run
, 1);
16218 add_com_alias ("brea", "break", class_run
, 1);
16222 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16223 Break in function/address or break at a line in the current file."),
16224 &stoplist
, "stop ", 1, &cmdlist
);
16225 add_cmd ("in", class_breakpoint
, stopin_command
,
16226 _("Break in function or address."), &stoplist
);
16227 add_cmd ("at", class_breakpoint
, stopat_command
,
16228 _("Break at a line in the current file."), &stoplist
);
16229 add_com ("status", class_info
, breakpoints_info
, _("\
16230 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16231 The \"Type\" column indicates one of:\n\
16232 \tbreakpoint - normal breakpoint\n\
16233 \twatchpoint - watchpoint\n\
16234 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16235 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16236 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16237 address and file/line number respectively.\n\
16239 Convenience variable \"$_\" and default examine address for \"x\"\n\
16240 are set to the address of the last breakpoint listed unless the command\n\
16241 is prefixed with \"server \".\n\n\
16242 Convenience variable \"$bpnum\" contains the number of the last\n\
16243 breakpoint set."));
16246 add_info ("breakpoints", breakpoints_info
, _("\
16247 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16248 The \"Type\" column indicates one of:\n\
16249 \tbreakpoint - normal breakpoint\n\
16250 \twatchpoint - watchpoint\n\
16251 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16252 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16253 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16254 address and file/line number respectively.\n\
16256 Convenience variable \"$_\" and default examine address for \"x\"\n\
16257 are set to the address of the last breakpoint listed unless the command\n\
16258 is prefixed with \"server \".\n\n\
16259 Convenience variable \"$bpnum\" contains the number of the last\n\
16260 breakpoint set."));
16262 add_info_alias ("b", "breakpoints", 1);
16264 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16265 Status of all breakpoints, or breakpoint number NUMBER.\n\
16266 The \"Type\" column indicates one of:\n\
16267 \tbreakpoint - normal breakpoint\n\
16268 \twatchpoint - watchpoint\n\
16269 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16270 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16271 \tuntil - internal breakpoint used by the \"until\" command\n\
16272 \tfinish - internal breakpoint used by the \"finish\" command\n\
16273 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16274 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16275 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16276 address and file/line number respectively.\n\
16278 Convenience variable \"$_\" and default examine address for \"x\"\n\
16279 are set to the address of the last breakpoint listed unless the command\n\
16280 is prefixed with \"server \".\n\n\
16281 Convenience variable \"$bpnum\" contains the number of the last\n\
16283 &maintenanceinfolist
);
16285 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16286 Set catchpoints to catch events."),
16287 &catch_cmdlist
, "catch ",
16288 0/*allow-unknown*/, &cmdlist
);
16290 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16291 Set temporary catchpoints to catch events."),
16292 &tcatch_cmdlist
, "tcatch ",
16293 0/*allow-unknown*/, &cmdlist
);
16295 add_catch_command ("fork", _("Catch calls to fork."),
16296 catch_fork_command_1
,
16298 (void *) (uintptr_t) catch_fork_permanent
,
16299 (void *) (uintptr_t) catch_fork_temporary
);
16300 add_catch_command ("vfork", _("Catch calls to vfork."),
16301 catch_fork_command_1
,
16303 (void *) (uintptr_t) catch_vfork_permanent
,
16304 (void *) (uintptr_t) catch_vfork_temporary
);
16305 add_catch_command ("exec", _("Catch calls to exec."),
16306 catch_exec_command_1
,
16310 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16311 Usage: catch load [REGEX]\n\
16312 If REGEX is given, only stop for libraries matching the regular expression."),
16313 catch_load_command_1
,
16317 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16318 Usage: catch unload [REGEX]\n\
16319 If REGEX is given, only stop for libraries matching the regular expression."),
16320 catch_unload_command_1
,
16325 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16326 Set a watchpoint for an expression.\n\
16327 Usage: watch [-l|-location] EXPRESSION\n\
16328 A watchpoint stops execution of your program whenever the value of\n\
16329 an expression changes.\n\
16330 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16331 the memory to which it refers."));
16332 set_cmd_completer (c
, expression_completer
);
16334 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16335 Set a read watchpoint for an expression.\n\
16336 Usage: rwatch [-l|-location] EXPRESSION\n\
16337 A watchpoint stops execution of your program whenever the value of\n\
16338 an expression is read.\n\
16339 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16340 the memory to which it refers."));
16341 set_cmd_completer (c
, expression_completer
);
16343 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16344 Set a watchpoint for an expression.\n\
16345 Usage: awatch [-l|-location] EXPRESSION\n\
16346 A watchpoint stops execution of your program whenever the value of\n\
16347 an expression is either read or written.\n\
16348 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16349 the memory to which it refers."));
16350 set_cmd_completer (c
, expression_completer
);
16352 add_info ("watchpoints", watchpoints_info
, _("\
16353 Status of specified watchpoints (all watchpoints if no argument)."));
16355 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16356 respond to changes - contrary to the description. */
16357 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16358 &can_use_hw_watchpoints
, _("\
16359 Set debugger's willingness to use watchpoint hardware."), _("\
16360 Show debugger's willingness to use watchpoint hardware."), _("\
16361 If zero, gdb will not use hardware for new watchpoints, even if\n\
16362 such is available. (However, any hardware watchpoints that were\n\
16363 created before setting this to nonzero, will continue to use watchpoint\n\
16366 show_can_use_hw_watchpoints
,
16367 &setlist
, &showlist
);
16369 can_use_hw_watchpoints
= 1;
16371 /* Tracepoint manipulation commands. */
16373 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16374 Set a tracepoint at specified location.\n\
16376 BREAK_ARGS_HELP ("trace") "\n\
16377 Do \"help tracepoints\" for info on other tracepoint commands."));
16378 set_cmd_completer (c
, location_completer
);
16380 add_com_alias ("tp", "trace", class_alias
, 0);
16381 add_com_alias ("tr", "trace", class_alias
, 1);
16382 add_com_alias ("tra", "trace", class_alias
, 1);
16383 add_com_alias ("trac", "trace", class_alias
, 1);
16385 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16386 Set a fast tracepoint at specified location.\n\
16388 BREAK_ARGS_HELP ("ftrace") "\n\
16389 Do \"help tracepoints\" for info on other tracepoint commands."));
16390 set_cmd_completer (c
, location_completer
);
16392 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16393 Set a static tracepoint at location or marker.\n\
16395 strace [LOCATION] [if CONDITION]\n\
16396 LOCATION may be a linespec, explicit, or address location (described below) \n\
16397 or -m MARKER_ID.\n\n\
16398 If a marker id is specified, probe the marker with that name. With\n\
16399 no LOCATION, uses current execution address of the selected stack frame.\n\
16400 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16401 This collects arbitrary user data passed in the probe point call to the\n\
16402 tracing library. You can inspect it when analyzing the trace buffer,\n\
16403 by printing the $_sdata variable like any other convenience variable.\n\
16405 CONDITION is a boolean expression.\n\
16406 \n" LOCATION_HELP_STRING
"\n\
16407 Multiple tracepoints at one place are permitted, and useful if their\n\
16408 conditions are different.\n\
16410 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16411 Do \"help tracepoints\" for info on other tracepoint commands."));
16412 set_cmd_completer (c
, location_completer
);
16414 add_info ("tracepoints", tracepoints_info
, _("\
16415 Status of specified tracepoints (all tracepoints if no argument).\n\
16416 Convenience variable \"$tpnum\" contains the number of the\n\
16417 last tracepoint set."));
16419 add_info_alias ("tp", "tracepoints", 1);
16421 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16422 Delete specified tracepoints.\n\
16423 Arguments are tracepoint numbers, separated by spaces.\n\
16424 No argument means delete all tracepoints."),
16426 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16428 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16429 Disable specified tracepoints.\n\
16430 Arguments are tracepoint numbers, separated by spaces.\n\
16431 No argument means disable all tracepoints."),
16433 deprecate_cmd (c
, "disable");
16435 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16436 Enable specified tracepoints.\n\
16437 Arguments are tracepoint numbers, separated by spaces.\n\
16438 No argument means enable all tracepoints."),
16440 deprecate_cmd (c
, "enable");
16442 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16443 Set the passcount for a tracepoint.\n\
16444 The trace will end when the tracepoint has been passed 'count' times.\n\
16445 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16446 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16448 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16449 _("Save breakpoint definitions as a script."),
16450 &save_cmdlist
, "save ",
16451 0/*allow-unknown*/, &cmdlist
);
16453 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16454 Save current breakpoint definitions as a script.\n\
16455 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16456 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16457 session to restore them."),
16459 set_cmd_completer (c
, filename_completer
);
16461 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16462 Save current tracepoint definitions as a script.\n\
16463 Use the 'source' command in another debug session to restore them."),
16465 set_cmd_completer (c
, filename_completer
);
16467 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16468 deprecate_cmd (c
, "save tracepoints");
16470 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16471 Breakpoint specific settings\n\
16472 Configure various breakpoint-specific variables such as\n\
16473 pending breakpoint behavior"),
16474 &breakpoint_set_cmdlist
, "set breakpoint ",
16475 0/*allow-unknown*/, &setlist
);
16476 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16477 Breakpoint specific settings\n\
16478 Configure various breakpoint-specific variables such as\n\
16479 pending breakpoint behavior"),
16480 &breakpoint_show_cmdlist
, "show breakpoint ",
16481 0/*allow-unknown*/, &showlist
);
16483 add_setshow_auto_boolean_cmd ("pending", no_class
,
16484 &pending_break_support
, _("\
16485 Set debugger's behavior regarding pending breakpoints."), _("\
16486 Show debugger's behavior regarding pending breakpoints."), _("\
16487 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16488 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16489 an error. If auto, an unrecognized breakpoint location results in a\n\
16490 user-query to see if a pending breakpoint should be created."),
16492 show_pending_break_support
,
16493 &breakpoint_set_cmdlist
,
16494 &breakpoint_show_cmdlist
);
16496 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16498 add_setshow_boolean_cmd ("auto-hw", no_class
,
16499 &automatic_hardware_breakpoints
, _("\
16500 Set automatic usage of hardware breakpoints."), _("\
16501 Show automatic usage of hardware breakpoints."), _("\
16502 If set, the debugger will automatically use hardware breakpoints for\n\
16503 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16504 a warning will be emitted for such breakpoints."),
16506 show_automatic_hardware_breakpoints
,
16507 &breakpoint_set_cmdlist
,
16508 &breakpoint_show_cmdlist
);
16510 add_setshow_boolean_cmd ("always-inserted", class_support
,
16511 &always_inserted_mode
, _("\
16512 Set mode for inserting breakpoints."), _("\
16513 Show mode for inserting breakpoints."), _("\
16514 When this mode is on, breakpoints are inserted immediately as soon as\n\
16515 they're created, kept inserted even when execution stops, and removed\n\
16516 only when the user deletes them. When this mode is off (the default),\n\
16517 breakpoints are inserted only when execution continues, and removed\n\
16518 when execution stops."),
16520 &show_always_inserted_mode
,
16521 &breakpoint_set_cmdlist
,
16522 &breakpoint_show_cmdlist
);
16524 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16525 condition_evaluation_enums
,
16526 &condition_evaluation_mode_1
, _("\
16527 Set mode of breakpoint condition evaluation."), _("\
16528 Show mode of breakpoint condition evaluation."), _("\
16529 When this is set to \"host\", breakpoint conditions will be\n\
16530 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16531 breakpoint conditions will be downloaded to the target (if the target\n\
16532 supports such feature) and conditions will be evaluated on the target's side.\n\
16533 If this is set to \"auto\" (default), this will be automatically set to\n\
16534 \"target\" if it supports condition evaluation, otherwise it will\n\
16535 be set to \"gdb\""),
16536 &set_condition_evaluation_mode
,
16537 &show_condition_evaluation_mode
,
16538 &breakpoint_set_cmdlist
,
16539 &breakpoint_show_cmdlist
);
16541 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16542 Set a breakpoint for an address range.\n\
16543 break-range START-LOCATION, END-LOCATION\n\
16544 where START-LOCATION and END-LOCATION can be one of the following:\n\
16545 LINENUM, for that line in the current file,\n\
16546 FILE:LINENUM, for that line in that file,\n\
16547 +OFFSET, for that number of lines after the current line\n\
16548 or the start of the range\n\
16549 FUNCTION, for the first line in that function,\n\
16550 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16551 *ADDRESS, for the instruction at that address.\n\
16553 The breakpoint will stop execution of the inferior whenever it executes\n\
16554 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16555 range (including START-LOCATION and END-LOCATION)."));
16557 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16558 Set a dynamic printf at specified location.\n\
16559 dprintf location,format string,arg1,arg2,...\n\
16560 location may be a linespec, explicit, or address location.\n"
16561 "\n" LOCATION_HELP_STRING
));
16562 set_cmd_completer (c
, location_completer
);
16564 add_setshow_enum_cmd ("dprintf-style", class_support
,
16565 dprintf_style_enums
, &dprintf_style
, _("\
16566 Set the style of usage for dynamic printf."), _("\
16567 Show the style of usage for dynamic printf."), _("\
16568 This setting chooses how GDB will do a dynamic printf.\n\
16569 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16570 console, as with the \"printf\" command.\n\
16571 If the value is \"call\", the print is done by calling a function in your\n\
16572 program; by default printf(), but you can choose a different function or\n\
16573 output stream by setting dprintf-function and dprintf-channel."),
16574 update_dprintf_commands
, NULL
,
16575 &setlist
, &showlist
);
16577 dprintf_function
= xstrdup ("printf");
16578 add_setshow_string_cmd ("dprintf-function", class_support
,
16579 &dprintf_function
, _("\
16580 Set the function to use for dynamic printf"), _("\
16581 Show the function to use for dynamic printf"), NULL
,
16582 update_dprintf_commands
, NULL
,
16583 &setlist
, &showlist
);
16585 dprintf_channel
= xstrdup ("");
16586 add_setshow_string_cmd ("dprintf-channel", class_support
,
16587 &dprintf_channel
, _("\
16588 Set the channel to use for dynamic printf"), _("\
16589 Show the channel to use for dynamic printf"), NULL
,
16590 update_dprintf_commands
, NULL
,
16591 &setlist
, &showlist
);
16593 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16594 &disconnected_dprintf
, _("\
16595 Set whether dprintf continues after GDB disconnects."), _("\
16596 Show whether dprintf continues after GDB disconnects."), _("\
16597 Use this to let dprintf commands continue to hit and produce output\n\
16598 even if GDB disconnects or detaches from the target."),
16601 &setlist
, &showlist
);
16603 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16604 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16605 (target agent only) This is useful for formatted output in user-defined commands."));
16607 automatic_hardware_breakpoints
= 1;
16609 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16610 observer_attach_thread_exit (remove_threaded_breakpoints
);