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 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
951 dummy_loc
.address
= address
;
953 /* Find a close match to the first location at ADDRESS. */
954 locp_found
= ((struct bp_location
**)
955 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
956 sizeof (struct bp_location
**),
957 bp_locations_compare_addrs
));
959 /* Nothing was found, nothing left to do. */
960 if (locp_found
== NULL
)
963 /* We may have found a location that is at ADDRESS but is not the first in the
964 location's list. Go backwards (if possible) and locate the first one. */
965 while ((locp_found
- 1) >= bp_locations
966 && (*(locp_found
- 1))->address
== address
)
973 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
976 xfree (b
->cond_string
);
977 b
->cond_string
= NULL
;
979 if (is_watchpoint (b
))
981 struct watchpoint
*w
= (struct watchpoint
*) b
;
983 w
->cond_exp
.reset ();
987 struct bp_location
*loc
;
989 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
993 /* No need to free the condition agent expression
994 bytecode (if we have one). We will handle this
995 when we go through update_global_location_list. */
1002 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1006 const char *arg
= exp
;
1008 /* I don't know if it matters whether this is the string the user
1009 typed in or the decompiled expression. */
1010 b
->cond_string
= xstrdup (arg
);
1011 b
->condition_not_parsed
= 0;
1013 if (is_watchpoint (b
))
1015 struct watchpoint
*w
= (struct watchpoint
*) b
;
1017 innermost_block
= NULL
;
1019 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1021 error (_("Junk at end of expression"));
1022 w
->cond_exp_valid_block
= innermost_block
;
1026 struct bp_location
*loc
;
1028 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1032 parse_exp_1 (&arg
, loc
->address
,
1033 block_for_pc (loc
->address
), 0);
1035 error (_("Junk at end of expression"));
1039 mark_breakpoint_modified (b
);
1041 observer_notify_breakpoint_modified (b
);
1044 /* Completion for the "condition" command. */
1046 static VEC (char_ptr
) *
1047 condition_completer (struct cmd_list_element
*cmd
,
1048 const char *text
, const char *word
)
1052 text
= skip_spaces_const (text
);
1053 space
= skip_to_space_const (text
);
1057 struct breakpoint
*b
;
1058 VEC (char_ptr
) *result
= NULL
;
1062 /* We don't support completion of history indices. */
1063 if (isdigit (text
[1]))
1065 return complete_internalvar (&text
[1]);
1068 /* We're completing the breakpoint number. */
1069 len
= strlen (text
);
1075 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1077 if (strncmp (number
, text
, len
) == 0)
1078 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1084 /* We're completing the expression part. */
1085 text
= skip_spaces_const (space
);
1086 return expression_completer (cmd
, text
, word
);
1089 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1092 condition_command (char *arg
, int from_tty
)
1094 struct breakpoint
*b
;
1099 error_no_arg (_("breakpoint number"));
1102 bnum
= get_number (&p
);
1104 error (_("Bad breakpoint argument: '%s'"), arg
);
1107 if (b
->number
== bnum
)
1109 /* Check if this breakpoint has a "stop" method implemented in an
1110 extension language. This method and conditions entered into GDB
1111 from the CLI are mutually exclusive. */
1112 const struct extension_language_defn
*extlang
1113 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1115 if (extlang
!= NULL
)
1117 error (_("Only one stop condition allowed. There is currently"
1118 " a %s stop condition defined for this breakpoint."),
1119 ext_lang_capitalized_name (extlang
));
1121 set_breakpoint_condition (b
, p
, from_tty
);
1123 if (is_breakpoint (b
))
1124 update_global_location_list (UGLL_MAY_INSERT
);
1129 error (_("No breakpoint number %d."), bnum
);
1132 /* Check that COMMAND do not contain commands that are suitable
1133 only for tracepoints and not suitable for ordinary breakpoints.
1134 Throw if any such commands is found. */
1137 check_no_tracepoint_commands (struct command_line
*commands
)
1139 struct command_line
*c
;
1141 for (c
= commands
; c
; c
= c
->next
)
1145 if (c
->control_type
== while_stepping_control
)
1146 error (_("The 'while-stepping' command can "
1147 "only be used for tracepoints"));
1149 for (i
= 0; i
< c
->body_count
; ++i
)
1150 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1152 /* Not that command parsing removes leading whitespace and comment
1153 lines and also empty lines. So, we only need to check for
1154 command directly. */
1155 if (strstr (c
->line
, "collect ") == c
->line
)
1156 error (_("The 'collect' command can only be used for tracepoints"));
1158 if (strstr (c
->line
, "teval ") == c
->line
)
1159 error (_("The 'teval' command can only be used for tracepoints"));
1163 /* Encapsulate tests for different types of tracepoints. */
1166 is_tracepoint_type (enum bptype type
)
1168 return (type
== bp_tracepoint
1169 || type
== bp_fast_tracepoint
1170 || type
== bp_static_tracepoint
);
1174 is_tracepoint (const struct breakpoint
*b
)
1176 return is_tracepoint_type (b
->type
);
1179 /* A helper function that validates that COMMANDS are valid for a
1180 breakpoint. This function will throw an exception if a problem is
1184 validate_commands_for_breakpoint (struct breakpoint
*b
,
1185 struct command_line
*commands
)
1187 if (is_tracepoint (b
))
1189 struct tracepoint
*t
= (struct tracepoint
*) b
;
1190 struct command_line
*c
;
1191 struct command_line
*while_stepping
= 0;
1193 /* Reset the while-stepping step count. The previous commands
1194 might have included a while-stepping action, while the new
1198 /* We need to verify that each top-level element of commands is
1199 valid for tracepoints, that there's at most one
1200 while-stepping element, and that the while-stepping's body
1201 has valid tracing commands excluding nested while-stepping.
1202 We also need to validate the tracepoint action line in the
1203 context of the tracepoint --- validate_actionline actually
1204 has side effects, like setting the tracepoint's
1205 while-stepping STEP_COUNT, in addition to checking if the
1206 collect/teval actions parse and make sense in the
1207 tracepoint's context. */
1208 for (c
= commands
; c
; c
= c
->next
)
1210 if (c
->control_type
== while_stepping_control
)
1212 if (b
->type
== bp_fast_tracepoint
)
1213 error (_("The 'while-stepping' command "
1214 "cannot be used for fast tracepoint"));
1215 else if (b
->type
== bp_static_tracepoint
)
1216 error (_("The 'while-stepping' command "
1217 "cannot be used for static tracepoint"));
1220 error (_("The 'while-stepping' command "
1221 "can be used only once"));
1226 validate_actionline (c
->line
, b
);
1230 struct command_line
*c2
;
1232 gdb_assert (while_stepping
->body_count
== 1);
1233 c2
= while_stepping
->body_list
[0];
1234 for (; c2
; c2
= c2
->next
)
1236 if (c2
->control_type
== while_stepping_control
)
1237 error (_("The 'while-stepping' command cannot be nested"));
1243 check_no_tracepoint_commands (commands
);
1247 /* Return a vector of all the static tracepoints set at ADDR. The
1248 caller is responsible for releasing the vector. */
1251 static_tracepoints_here (CORE_ADDR addr
)
1253 struct breakpoint
*b
;
1254 VEC(breakpoint_p
) *found
= 0;
1255 struct bp_location
*loc
;
1258 if (b
->type
== bp_static_tracepoint
)
1260 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1261 if (loc
->address
== addr
)
1262 VEC_safe_push(breakpoint_p
, found
, b
);
1268 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1269 validate that only allowed commands are included. */
1272 breakpoint_set_commands (struct breakpoint
*b
,
1273 command_line_up
&&commands
)
1275 validate_commands_for_breakpoint (b
, commands
.get ());
1277 decref_counted_command_line (&b
->commands
);
1278 b
->commands
= alloc_counted_command_line (commands
.release ());
1279 observer_notify_breakpoint_modified (b
);
1282 /* Set the internal `silent' flag on the breakpoint. Note that this
1283 is not the same as the "silent" that may appear in the breakpoint's
1287 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1289 int old_silent
= b
->silent
;
1292 if (old_silent
!= silent
)
1293 observer_notify_breakpoint_modified (b
);
1296 /* Set the thread for this breakpoint. If THREAD is -1, make the
1297 breakpoint work for any thread. */
1300 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1302 int old_thread
= b
->thread
;
1305 if (old_thread
!= thread
)
1306 observer_notify_breakpoint_modified (b
);
1309 /* Set the task for this breakpoint. If TASK is 0, make the
1310 breakpoint work for any task. */
1313 breakpoint_set_task (struct breakpoint
*b
, int task
)
1315 int old_task
= b
->task
;
1318 if (old_task
!= task
)
1319 observer_notify_breakpoint_modified (b
);
1323 check_tracepoint_command (char *line
, void *closure
)
1325 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1327 validate_actionline (line
, b
);
1330 /* A structure used to pass information through
1331 map_breakpoint_numbers. */
1333 struct commands_info
1335 /* True if the command was typed at a tty. */
1338 /* The breakpoint range spec. */
1341 /* Non-NULL if the body of the commands are being read from this
1342 already-parsed command. */
1343 struct command_line
*control
;
1345 /* The command lines read from the user, or NULL if they have not
1347 struct counted_command_line
*cmd
;
1350 /* A callback for map_breakpoint_numbers that sets the commands for
1351 commands_command. */
1354 do_map_commands_command (struct breakpoint
*b
, void *data
)
1356 struct commands_info
*info
= (struct commands_info
*) data
;
1358 if (info
->cmd
== NULL
)
1362 if (info
->control
!= NULL
)
1363 l
= copy_command_lines (info
->control
->body_list
[0]);
1366 struct cleanup
*old_chain
;
1369 str
= xstrprintf (_("Type commands for breakpoint(s) "
1370 "%s, one per line."),
1373 old_chain
= make_cleanup (xfree
, str
);
1375 l
= read_command_lines (str
,
1378 ? check_tracepoint_command
: 0),
1381 do_cleanups (old_chain
);
1384 info
->cmd
= alloc_counted_command_line (l
.release ());
1387 /* If a breakpoint was on the list more than once, we don't need to
1389 if (b
->commands
!= info
->cmd
)
1391 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1392 incref_counted_command_line (info
->cmd
);
1393 decref_counted_command_line (&b
->commands
);
1394 b
->commands
= info
->cmd
;
1395 observer_notify_breakpoint_modified (b
);
1400 commands_command_1 (const char *arg
, int from_tty
,
1401 struct command_line
*control
)
1403 struct cleanup
*cleanups
;
1404 struct commands_info info
;
1406 info
.from_tty
= from_tty
;
1407 info
.control
= control
;
1409 /* If we read command lines from the user, then `info' will hold an
1410 extra reference to the commands that we must clean up. */
1411 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1413 std::string new_arg
;
1415 if (arg
== NULL
|| !*arg
)
1417 if (breakpoint_count
- prev_breakpoint_count
> 1)
1418 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1420 else if (breakpoint_count
> 0)
1421 new_arg
= string_printf ("%d", breakpoint_count
);
1426 info
.arg
= new_arg
.c_str ();
1428 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1430 if (info
.cmd
== NULL
)
1431 error (_("No breakpoints specified."));
1433 do_cleanups (cleanups
);
1437 commands_command (char *arg
, int from_tty
)
1439 commands_command_1 (arg
, from_tty
, NULL
);
1442 /* Like commands_command, but instead of reading the commands from
1443 input stream, takes them from an already parsed command structure.
1445 This is used by cli-script.c to DTRT with breakpoint commands
1446 that are part of if and while bodies. */
1447 enum command_control_type
1448 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1450 commands_command_1 (arg
, 0, cmd
);
1451 return simple_control
;
1454 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1457 bp_location_has_shadow (struct bp_location
*bl
)
1459 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1463 if (bl
->target_info
.shadow_len
== 0)
1464 /* BL isn't valid, or doesn't shadow memory. */
1469 /* Update BUF, which is LEN bytes read from the target address
1470 MEMADDR, by replacing a memory breakpoint with its shadowed
1473 If READBUF is not NULL, this buffer must not overlap with the of
1474 the breakpoint location's shadow_contents buffer. Otherwise, a
1475 failed assertion internal error will be raised. */
1478 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1479 const gdb_byte
*writebuf_org
,
1480 ULONGEST memaddr
, LONGEST len
,
1481 struct bp_target_info
*target_info
,
1482 struct gdbarch
*gdbarch
)
1484 /* Now do full processing of the found relevant range of elements. */
1485 CORE_ADDR bp_addr
= 0;
1489 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1490 current_program_space
->aspace
, 0))
1492 /* The breakpoint is inserted in a different address space. */
1496 /* Addresses and length of the part of the breakpoint that
1498 bp_addr
= target_info
->placed_address
;
1499 bp_size
= target_info
->shadow_len
;
1501 if (bp_addr
+ bp_size
<= memaddr
)
1503 /* The breakpoint is entirely before the chunk of memory we are
1508 if (bp_addr
>= memaddr
+ len
)
1510 /* The breakpoint is entirely after the chunk of memory we are
1515 /* Offset within shadow_contents. */
1516 if (bp_addr
< memaddr
)
1518 /* Only copy the second part of the breakpoint. */
1519 bp_size
-= memaddr
- bp_addr
;
1520 bptoffset
= memaddr
- bp_addr
;
1524 if (bp_addr
+ bp_size
> memaddr
+ len
)
1526 /* Only copy the first part of the breakpoint. */
1527 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1530 if (readbuf
!= NULL
)
1532 /* Verify that the readbuf buffer does not overlap with the
1533 shadow_contents buffer. */
1534 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1535 || readbuf
>= (target_info
->shadow_contents
1536 + target_info
->shadow_len
));
1538 /* Update the read buffer with this inserted breakpoint's
1540 memcpy (readbuf
+ bp_addr
- memaddr
,
1541 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1545 const unsigned char *bp
;
1546 CORE_ADDR addr
= target_info
->reqstd_address
;
1549 /* Update the shadow with what we want to write to memory. */
1550 memcpy (target_info
->shadow_contents
+ bptoffset
,
1551 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1553 /* Determine appropriate breakpoint contents and size for this
1555 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1557 /* Update the final write buffer with this inserted
1558 breakpoint's INSN. */
1559 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1563 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1564 by replacing any memory breakpoints with their shadowed contents.
1566 If READBUF is not NULL, this buffer must not overlap with any of
1567 the breakpoint location's shadow_contents buffers. Otherwise,
1568 a failed assertion internal error will be raised.
1570 The range of shadowed area by each bp_location is:
1571 bl->address - bp_locations_placed_address_before_address_max
1572 up to bl->address + bp_locations_shadow_len_after_address_max
1573 The range we were requested to resolve shadows for is:
1574 memaddr ... memaddr + len
1575 Thus the safe cutoff boundaries for performance optimization are
1576 memaddr + len <= (bl->address
1577 - bp_locations_placed_address_before_address_max)
1579 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1582 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1583 const gdb_byte
*writebuf_org
,
1584 ULONGEST memaddr
, LONGEST len
)
1586 /* Left boundary, right boundary and median element of our binary
1588 unsigned bc_l
, bc_r
, bc
;
1590 /* Find BC_L which is a leftmost element which may affect BUF
1591 content. It is safe to report lower value but a failure to
1592 report higher one. */
1595 bc_r
= bp_locations_count
;
1596 while (bc_l
+ 1 < bc_r
)
1598 struct bp_location
*bl
;
1600 bc
= (bc_l
+ bc_r
) / 2;
1601 bl
= bp_locations
[bc
];
1603 /* Check first BL->ADDRESS will not overflow due to the added
1604 constant. Then advance the left boundary only if we are sure
1605 the BC element can in no way affect the BUF content (MEMADDR
1606 to MEMADDR + LEN range).
1608 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1609 offset so that we cannot miss a breakpoint with its shadow
1610 range tail still reaching MEMADDR. */
1612 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1614 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1621 /* Due to the binary search above, we need to make sure we pick the
1622 first location that's at BC_L's address. E.g., if there are
1623 multiple locations at the same address, BC_L may end up pointing
1624 at a duplicate location, and miss the "master"/"inserted"
1625 location. Say, given locations L1, L2 and L3 at addresses A and
1628 L1@A, L2@A, L3@B, ...
1630 BC_L could end up pointing at location L2, while the "master"
1631 location could be L1. Since the `loc->inserted' flag is only set
1632 on "master" locations, we'd forget to restore the shadow of L1
1635 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1638 /* Now do full processing of the found relevant range of elements. */
1640 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1642 struct bp_location
*bl
= bp_locations
[bc
];
1644 /* bp_location array has BL->OWNER always non-NULL. */
1645 if (bl
->owner
->type
== bp_none
)
1646 warning (_("reading through apparently deleted breakpoint #%d?"),
1649 /* Performance optimization: any further element can no longer affect BUF
1652 if (bl
->address
>= bp_locations_placed_address_before_address_max
1653 && memaddr
+ len
<= (bl
->address
1654 - bp_locations_placed_address_before_address_max
))
1657 if (!bp_location_has_shadow (bl
))
1660 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1661 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1667 /* Return true if BPT is either a software breakpoint or a hardware
1671 is_breakpoint (const struct breakpoint
*bpt
)
1673 return (bpt
->type
== bp_breakpoint
1674 || bpt
->type
== bp_hardware_breakpoint
1675 || bpt
->type
== bp_dprintf
);
1678 /* Return true if BPT is of any hardware watchpoint kind. */
1681 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1683 return (bpt
->type
== bp_hardware_watchpoint
1684 || bpt
->type
== bp_read_watchpoint
1685 || bpt
->type
== bp_access_watchpoint
);
1688 /* Return true if BPT is of any watchpoint kind, hardware or
1692 is_watchpoint (const struct breakpoint
*bpt
)
1694 return (is_hardware_watchpoint (bpt
)
1695 || bpt
->type
== bp_watchpoint
);
1698 /* Returns true if the current thread and its running state are safe
1699 to evaluate or update watchpoint B. Watchpoints on local
1700 expressions need to be evaluated in the context of the thread that
1701 was current when the watchpoint was created, and, that thread needs
1702 to be stopped to be able to select the correct frame context.
1703 Watchpoints on global expressions can be evaluated on any thread,
1704 and in any state. It is presently left to the target allowing
1705 memory accesses when threads are running. */
1708 watchpoint_in_thread_scope (struct watchpoint
*b
)
1710 return (b
->base
.pspace
== current_program_space
1711 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1712 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1713 && !is_executing (inferior_ptid
))));
1716 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1717 associated bp_watchpoint_scope breakpoint. */
1720 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1722 struct breakpoint
*b
= &w
->base
;
1724 if (b
->related_breakpoint
!= b
)
1726 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1727 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1728 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1729 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1730 b
->related_breakpoint
= b
;
1732 b
->disposition
= disp_del_at_next_stop
;
1735 /* Extract a bitfield value from value VAL using the bit parameters contained in
1738 static struct value
*
1739 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1741 struct value
*bit_val
;
1746 bit_val
= allocate_value (value_type (val
));
1748 unpack_value_bitfield (bit_val
,
1751 value_contents_for_printing (val
),
1758 /* Allocate a dummy location and add it to B, which must be a software
1759 watchpoint. This is required because even if a software watchpoint
1760 is not watching any memory, bpstat_stop_status requires a location
1761 to be able to report stops. */
1764 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1765 struct program_space
*pspace
)
1767 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1769 b
->loc
= allocate_bp_location (b
);
1770 b
->loc
->pspace
= pspace
;
1771 b
->loc
->address
= -1;
1772 b
->loc
->length
= -1;
1775 /* Returns true if B is a software watchpoint that is not watching any
1776 memory (e.g., "watch $pc"). */
1779 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1781 return (b
->type
== bp_watchpoint
1783 && b
->loc
->next
== NULL
1784 && b
->loc
->address
== -1
1785 && b
->loc
->length
== -1);
1788 /* Assuming that B is a watchpoint:
1789 - Reparse watchpoint expression, if REPARSE is non-zero
1790 - Evaluate expression and store the result in B->val
1791 - Evaluate the condition if there is one, and store the result
1793 - Update the list of values that must be watched in B->loc.
1795 If the watchpoint disposition is disp_del_at_next_stop, then do
1796 nothing. If this is local watchpoint that is out of scope, delete
1799 Even with `set breakpoint always-inserted on' the watchpoints are
1800 removed + inserted on each stop here. Normal breakpoints must
1801 never be removed because they might be missed by a running thread
1802 when debugging in non-stop mode. On the other hand, hardware
1803 watchpoints (is_hardware_watchpoint; processed here) are specific
1804 to each LWP since they are stored in each LWP's hardware debug
1805 registers. Therefore, such LWP must be stopped first in order to
1806 be able to modify its hardware watchpoints.
1808 Hardware watchpoints must be reset exactly once after being
1809 presented to the user. It cannot be done sooner, because it would
1810 reset the data used to present the watchpoint hit to the user. And
1811 it must not be done later because it could display the same single
1812 watchpoint hit during multiple GDB stops. Note that the latter is
1813 relevant only to the hardware watchpoint types bp_read_watchpoint
1814 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1815 not user-visible - its hit is suppressed if the memory content has
1818 The following constraints influence the location where we can reset
1819 hardware watchpoints:
1821 * target_stopped_by_watchpoint and target_stopped_data_address are
1822 called several times when GDB stops.
1825 * Multiple hardware watchpoints can be hit at the same time,
1826 causing GDB to stop. GDB only presents one hardware watchpoint
1827 hit at a time as the reason for stopping, and all the other hits
1828 are presented later, one after the other, each time the user
1829 requests the execution to be resumed. Execution is not resumed
1830 for the threads still having pending hit event stored in
1831 LWP_INFO->STATUS. While the watchpoint is already removed from
1832 the inferior on the first stop the thread hit event is kept being
1833 reported from its cached value by linux_nat_stopped_data_address
1834 until the real thread resume happens after the watchpoint gets
1835 presented and thus its LWP_INFO->STATUS gets reset.
1837 Therefore the hardware watchpoint hit can get safely reset on the
1838 watchpoint removal from inferior. */
1841 update_watchpoint (struct watchpoint
*b
, int reparse
)
1843 int within_current_scope
;
1844 struct frame_id saved_frame_id
;
1847 /* If this is a local watchpoint, we only want to check if the
1848 watchpoint frame is in scope if the current thread is the thread
1849 that was used to create the watchpoint. */
1850 if (!watchpoint_in_thread_scope (b
))
1853 if (b
->base
.disposition
== disp_del_at_next_stop
)
1858 /* Determine if the watchpoint is within scope. */
1859 if (b
->exp_valid_block
== NULL
)
1860 within_current_scope
= 1;
1863 struct frame_info
*fi
= get_current_frame ();
1864 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1865 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1867 /* If we're at a point where the stack has been destroyed
1868 (e.g. in a function epilogue), unwinding may not work
1869 properly. Do not attempt to recreate locations at this
1870 point. See similar comments in watchpoint_check. */
1871 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1874 /* Save the current frame's ID so we can restore it after
1875 evaluating the watchpoint expression on its own frame. */
1876 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1877 took a frame parameter, so that we didn't have to change the
1880 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1882 fi
= frame_find_by_id (b
->watchpoint_frame
);
1883 within_current_scope
= (fi
!= NULL
);
1884 if (within_current_scope
)
1888 /* We don't free locations. They are stored in the bp_location array
1889 and update_global_location_list will eventually delete them and
1890 remove breakpoints if needed. */
1893 if (within_current_scope
&& reparse
)
1898 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1899 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1900 /* If the meaning of expression itself changed, the old value is
1901 no longer relevant. We don't want to report a watchpoint hit
1902 to the user when the old value and the new value may actually
1903 be completely different objects. */
1904 value_free (b
->val
);
1908 /* Note that unlike with breakpoints, the watchpoint's condition
1909 expression is stored in the breakpoint object, not in the
1910 locations (re)created below. */
1911 if (b
->base
.cond_string
!= NULL
)
1913 b
->cond_exp
.reset ();
1915 s
= b
->base
.cond_string
;
1916 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1920 /* If we failed to parse the expression, for example because
1921 it refers to a global variable in a not-yet-loaded shared library,
1922 don't try to insert watchpoint. We don't automatically delete
1923 such watchpoint, though, since failure to parse expression
1924 is different from out-of-scope watchpoint. */
1925 if (!target_has_execution
)
1927 /* Without execution, memory can't change. No use to try and
1928 set watchpoint locations. The watchpoint will be reset when
1929 the target gains execution, through breakpoint_re_set. */
1930 if (!can_use_hw_watchpoints
)
1932 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1933 b
->base
.type
= bp_watchpoint
;
1935 error (_("Can't set read/access watchpoint when "
1936 "hardware watchpoints are disabled."));
1939 else if (within_current_scope
&& b
->exp
)
1942 struct value
*val_chain
, *v
, *result
, *next
;
1943 struct program_space
*frame_pspace
;
1945 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1947 /* Avoid setting b->val if it's already set. The meaning of
1948 b->val is 'the last value' user saw, and we should update
1949 it only if we reported that last value to user. As it
1950 happens, the code that reports it updates b->val directly.
1951 We don't keep track of the memory value for masked
1953 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1955 if (b
->val_bitsize
!= 0)
1957 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1965 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1967 /* Look at each value on the value chain. */
1968 for (v
= val_chain
; v
; v
= value_next (v
))
1970 /* If it's a memory location, and GDB actually needed
1971 its contents to evaluate the expression, then we
1972 must watch it. If the first value returned is
1973 still lazy, that means an error occurred reading it;
1974 watch it anyway in case it becomes readable. */
1975 if (VALUE_LVAL (v
) == lval_memory
1976 && (v
== val_chain
|| ! value_lazy (v
)))
1978 struct type
*vtype
= check_typedef (value_type (v
));
1980 /* We only watch structs and arrays if user asked
1981 for it explicitly, never if they just happen to
1982 appear in the middle of some value chain. */
1984 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1985 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1988 enum target_hw_bp_type type
;
1989 struct bp_location
*loc
, **tmp
;
1990 int bitpos
= 0, bitsize
= 0;
1992 if (value_bitsize (v
) != 0)
1994 /* Extract the bit parameters out from the bitfield
1996 bitpos
= value_bitpos (v
);
1997 bitsize
= value_bitsize (v
);
1999 else if (v
== result
&& b
->val_bitsize
!= 0)
2001 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2002 lvalue whose bit parameters are saved in the fields
2003 VAL_BITPOS and VAL_BITSIZE. */
2004 bitpos
= b
->val_bitpos
;
2005 bitsize
= b
->val_bitsize
;
2008 addr
= value_address (v
);
2011 /* Skip the bytes that don't contain the bitfield. */
2016 if (b
->base
.type
== bp_read_watchpoint
)
2018 else if (b
->base
.type
== bp_access_watchpoint
)
2021 loc
= allocate_bp_location (&b
->base
);
2022 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2025 loc
->gdbarch
= get_type_arch (value_type (v
));
2027 loc
->pspace
= frame_pspace
;
2028 loc
->address
= addr
;
2032 /* Just cover the bytes that make up the bitfield. */
2033 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2036 loc
->length
= TYPE_LENGTH (value_type (v
));
2038 loc
->watchpoint_type
= type
;
2043 /* Change the type of breakpoint between hardware assisted or
2044 an ordinary watchpoint depending on the hardware support
2045 and free hardware slots. REPARSE is set when the inferior
2050 enum bp_loc_type loc_type
;
2051 struct bp_location
*bl
;
2053 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2057 int i
, target_resources_ok
, other_type_used
;
2060 /* Use an exact watchpoint when there's only one memory region to be
2061 watched, and only one debug register is needed to watch it. */
2062 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2064 /* We need to determine how many resources are already
2065 used for all other hardware watchpoints plus this one
2066 to see if we still have enough resources to also fit
2067 this watchpoint in as well. */
2069 /* If this is a software watchpoint, we try to turn it
2070 to a hardware one -- count resources as if B was of
2071 hardware watchpoint type. */
2072 type
= b
->base
.type
;
2073 if (type
== bp_watchpoint
)
2074 type
= bp_hardware_watchpoint
;
2076 /* This watchpoint may or may not have been placed on
2077 the list yet at this point (it won't be in the list
2078 if we're trying to create it for the first time,
2079 through watch_command), so always account for it
2082 /* Count resources used by all watchpoints except B. */
2083 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2085 /* Add in the resources needed for B. */
2086 i
+= hw_watchpoint_use_count (&b
->base
);
2089 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2090 if (target_resources_ok
<= 0)
2092 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2094 if (target_resources_ok
== 0 && !sw_mode
)
2095 error (_("Target does not support this type of "
2096 "hardware watchpoint."));
2097 else if (target_resources_ok
< 0 && !sw_mode
)
2098 error (_("There are not enough available hardware "
2099 "resources for this watchpoint."));
2101 /* Downgrade to software watchpoint. */
2102 b
->base
.type
= bp_watchpoint
;
2106 /* If this was a software watchpoint, we've just
2107 found we have enough resources to turn it to a
2108 hardware watchpoint. Otherwise, this is a
2110 b
->base
.type
= type
;
2113 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2115 if (!can_use_hw_watchpoints
)
2116 error (_("Can't set read/access watchpoint when "
2117 "hardware watchpoints are disabled."));
2119 error (_("Expression cannot be implemented with "
2120 "read/access watchpoint."));
2123 b
->base
.type
= bp_watchpoint
;
2125 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2126 : bp_loc_hardware_watchpoint
);
2127 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2128 bl
->loc_type
= loc_type
;
2131 for (v
= val_chain
; v
; v
= next
)
2133 next
= value_next (v
);
2138 /* If a software watchpoint is not watching any memory, then the
2139 above left it without any location set up. But,
2140 bpstat_stop_status requires a location to be able to report
2141 stops, so make sure there's at least a dummy one. */
2142 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2143 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2145 else if (!within_current_scope
)
2147 printf_filtered (_("\
2148 Watchpoint %d deleted because the program has left the block\n\
2149 in which its expression is valid.\n"),
2151 watchpoint_del_at_next_stop (b
);
2154 /* Restore the selected frame. */
2156 select_frame (frame_find_by_id (saved_frame_id
));
2160 /* Returns 1 iff breakpoint location should be
2161 inserted in the inferior. We don't differentiate the type of BL's owner
2162 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2163 breakpoint_ops is not defined, because in insert_bp_location,
2164 tracepoint's insert_location will not be called. */
2166 should_be_inserted (struct bp_location
*bl
)
2168 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2171 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2174 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2177 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2180 /* This is set for example, when we're attached to the parent of a
2181 vfork, and have detached from the child. The child is running
2182 free, and we expect it to do an exec or exit, at which point the
2183 OS makes the parent schedulable again (and the target reports
2184 that the vfork is done). Until the child is done with the shared
2185 memory region, do not insert breakpoints in the parent, otherwise
2186 the child could still trip on the parent's breakpoints. Since
2187 the parent is blocked anyway, it won't miss any breakpoint. */
2188 if (bl
->pspace
->breakpoints_not_allowed
)
2191 /* Don't insert a breakpoint if we're trying to step past its
2192 location, except if the breakpoint is a single-step breakpoint,
2193 and the breakpoint's thread is the thread which is stepping past
2195 if ((bl
->loc_type
== bp_loc_software_breakpoint
2196 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2197 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2199 /* The single-step breakpoint may be inserted at the location
2200 we're trying to step if the instruction branches to itself.
2201 However, the instruction won't be executed at all and it may
2202 break the semantics of the instruction, for example, the
2203 instruction is a conditional branch or updates some flags.
2204 We can't fix it unless GDB is able to emulate the instruction
2205 or switch to displaced stepping. */
2206 && !(bl
->owner
->type
== bp_single_step
2207 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2211 fprintf_unfiltered (gdb_stdlog
,
2212 "infrun: skipping breakpoint: "
2213 "stepping past insn at: %s\n",
2214 paddress (bl
->gdbarch
, bl
->address
));
2219 /* Don't insert watchpoints if we're trying to step past the
2220 instruction that triggered one. */
2221 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2222 && stepping_past_nonsteppable_watchpoint ())
2226 fprintf_unfiltered (gdb_stdlog
,
2227 "infrun: stepping past non-steppable watchpoint. "
2228 "skipping watchpoint at %s:%d\n",
2229 paddress (bl
->gdbarch
, bl
->address
),
2238 /* Same as should_be_inserted but does the check assuming
2239 that the location is not duplicated. */
2242 unduplicated_should_be_inserted (struct bp_location
*bl
)
2245 const int save_duplicate
= bl
->duplicate
;
2248 result
= should_be_inserted (bl
);
2249 bl
->duplicate
= save_duplicate
;
2253 /* Parses a conditional described by an expression COND into an
2254 agent expression bytecode suitable for evaluation
2255 by the bytecode interpreter. Return NULL if there was
2256 any error during parsing. */
2258 static agent_expr_up
2259 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2264 agent_expr_up aexpr
;
2266 /* We don't want to stop processing, so catch any errors
2267 that may show up. */
2270 aexpr
= gen_eval_for_expr (scope
, cond
);
2273 CATCH (ex
, RETURN_MASK_ERROR
)
2275 /* If we got here, it means the condition could not be parsed to a valid
2276 bytecode expression and thus can't be evaluated on the target's side.
2277 It's no use iterating through the conditions. */
2281 /* We have a valid agent expression. */
2285 /* Based on location BL, create a list of breakpoint conditions to be
2286 passed on to the target. If we have duplicated locations with different
2287 conditions, we will add such conditions to the list. The idea is that the
2288 target will evaluate the list of conditions and will only notify GDB when
2289 one of them is true. */
2292 build_target_condition_list (struct bp_location
*bl
)
2294 struct bp_location
**locp
= NULL
, **loc2p
;
2295 int null_condition_or_parse_error
= 0;
2296 int modified
= bl
->needs_update
;
2297 struct bp_location
*loc
;
2299 /* Release conditions left over from a previous insert. */
2300 bl
->target_info
.conditions
.clear ();
2302 /* This is only meaningful if the target is
2303 evaluating conditions and if the user has
2304 opted for condition evaluation on the target's
2306 if (gdb_evaluates_breakpoint_condition_p ()
2307 || !target_supports_evaluation_of_breakpoint_conditions ())
2310 /* Do a first pass to check for locations with no assigned
2311 conditions or conditions that fail to parse to a valid agent expression
2312 bytecode. If any of these happen, then it's no use to send conditions
2313 to the target since this location will always trigger and generate a
2314 response back to GDB. */
2315 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2318 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2322 /* Re-parse the conditions since something changed. In that
2323 case we already freed the condition bytecodes (see
2324 force_breakpoint_reinsertion). We just
2325 need to parse the condition to bytecodes again. */
2326 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2330 /* If we have a NULL bytecode expression, it means something
2331 went wrong or we have a null condition expression. */
2332 if (!loc
->cond_bytecode
)
2334 null_condition_or_parse_error
= 1;
2340 /* If any of these happened, it means we will have to evaluate the conditions
2341 for the location's address on gdb's side. It is no use keeping bytecodes
2342 for all the other duplicate locations, thus we free all of them here.
2344 This is so we have a finer control over which locations' conditions are
2345 being evaluated by GDB or the remote stub. */
2346 if (null_condition_or_parse_error
)
2348 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2351 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2353 /* Only go as far as the first NULL bytecode is
2355 if (!loc
->cond_bytecode
)
2358 loc
->cond_bytecode
.reset ();
2363 /* No NULL conditions or failed bytecode generation. Build a condition list
2364 for this location's address. */
2365 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2369 && is_breakpoint (loc
->owner
)
2370 && loc
->pspace
->num
== bl
->pspace
->num
2371 && loc
->owner
->enable_state
== bp_enabled
2374 /* Add the condition to the vector. This will be used later
2375 to send the conditions to the target. */
2376 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2383 /* Parses a command described by string CMD into an agent expression
2384 bytecode suitable for evaluation by the bytecode interpreter.
2385 Return NULL if there was any error during parsing. */
2387 static agent_expr_up
2388 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2390 struct cleanup
*old_cleanups
= 0;
2391 struct expression
**argvec
;
2392 const char *cmdrest
;
2393 const char *format_start
, *format_end
;
2394 struct format_piece
*fpieces
;
2396 struct gdbarch
*gdbarch
= get_current_arch ();
2403 if (*cmdrest
== ',')
2405 cmdrest
= skip_spaces_const (cmdrest
);
2407 if (*cmdrest
++ != '"')
2408 error (_("No format string following the location"));
2410 format_start
= cmdrest
;
2412 fpieces
= parse_format_string (&cmdrest
);
2414 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2416 format_end
= cmdrest
;
2418 if (*cmdrest
++ != '"')
2419 error (_("Bad format string, non-terminated '\"'."));
2421 cmdrest
= skip_spaces_const (cmdrest
);
2423 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2424 error (_("Invalid argument syntax"));
2426 if (*cmdrest
== ',')
2428 cmdrest
= skip_spaces_const (cmdrest
);
2430 /* For each argument, make an expression. */
2432 argvec
= (struct expression
**) alloca (strlen (cmd
)
2433 * sizeof (struct expression
*));
2436 while (*cmdrest
!= '\0')
2441 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2442 argvec
[nargs
++] = expr
.release ();
2444 if (*cmdrest
== ',')
2448 agent_expr_up aexpr
;
2450 /* We don't want to stop processing, so catch any errors
2451 that may show up. */
2454 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2455 format_start
, format_end
- format_start
,
2456 fpieces
, nargs
, argvec
);
2458 CATCH (ex
, RETURN_MASK_ERROR
)
2460 /* If we got here, it means the command could not be parsed to a valid
2461 bytecode expression and thus can't be evaluated on the target's side.
2462 It's no use iterating through the other commands. */
2466 do_cleanups (old_cleanups
);
2468 /* We have a valid agent expression, return it. */
2472 /* Based on location BL, create a list of breakpoint commands to be
2473 passed on to the target. If we have duplicated locations with
2474 different commands, we will add any such to the list. */
2477 build_target_command_list (struct bp_location
*bl
)
2479 struct bp_location
**locp
= NULL
, **loc2p
;
2480 int null_command_or_parse_error
= 0;
2481 int modified
= bl
->needs_update
;
2482 struct bp_location
*loc
;
2484 /* Clear commands left over from a previous insert. */
2485 bl
->target_info
.tcommands
.clear ();
2487 if (!target_can_run_breakpoint_commands ())
2490 /* For now, limit to agent-style dprintf breakpoints. */
2491 if (dprintf_style
!= dprintf_style_agent
)
2494 /* For now, if we have any duplicate location that isn't a dprintf,
2495 don't install the target-side commands, as that would make the
2496 breakpoint not be reported to the core, and we'd lose
2498 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2501 if (is_breakpoint (loc
->owner
)
2502 && loc
->pspace
->num
== bl
->pspace
->num
2503 && loc
->owner
->type
!= bp_dprintf
)
2507 /* Do a first pass to check for locations with no assigned
2508 conditions or conditions that fail to parse to a valid agent expression
2509 bytecode. If any of these happen, then it's no use to send conditions
2510 to the target since this location will always trigger and generate a
2511 response back to GDB. */
2512 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2515 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2519 /* Re-parse the commands since something changed. In that
2520 case we already freed the command bytecodes (see
2521 force_breakpoint_reinsertion). We just
2522 need to parse the command to bytecodes again. */
2524 = parse_cmd_to_aexpr (bl
->address
,
2525 loc
->owner
->extra_string
);
2528 /* If we have a NULL bytecode expression, it means something
2529 went wrong or we have a null command expression. */
2530 if (!loc
->cmd_bytecode
)
2532 null_command_or_parse_error
= 1;
2538 /* If anything failed, then we're not doing target-side commands,
2540 if (null_command_or_parse_error
)
2542 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2545 if (is_breakpoint (loc
->owner
)
2546 && loc
->pspace
->num
== bl
->pspace
->num
)
2548 /* Only go as far as the first NULL bytecode is
2550 if (loc
->cmd_bytecode
== NULL
)
2553 loc
->cmd_bytecode
.reset ();
2558 /* No NULL commands or failed bytecode generation. Build a command list
2559 for this location's address. */
2560 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2563 if (loc
->owner
->extra_string
2564 && is_breakpoint (loc
->owner
)
2565 && loc
->pspace
->num
== bl
->pspace
->num
2566 && loc
->owner
->enable_state
== bp_enabled
2569 /* Add the command to the vector. This will be used later
2570 to send the commands to the target. */
2571 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2575 bl
->target_info
.persist
= 0;
2576 /* Maybe flag this location as persistent. */
2577 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2578 bl
->target_info
.persist
= 1;
2581 /* Return the kind of breakpoint on address *ADDR. Get the kind
2582 of breakpoint according to ADDR except single-step breakpoint.
2583 Get the kind of single-step breakpoint according to the current
2587 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2589 if (bl
->owner
->type
== bp_single_step
)
2591 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2592 struct regcache
*regcache
;
2594 regcache
= get_thread_regcache (thr
->ptid
);
2596 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2600 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2603 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2604 location. Any error messages are printed to TMP_ERROR_STREAM; and
2605 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2606 Returns 0 for success, 1 if the bp_location type is not supported or
2609 NOTE drow/2003-09-09: This routine could be broken down to an
2610 object-style method for each breakpoint or catchpoint type. */
2612 insert_bp_location (struct bp_location
*bl
,
2613 struct ui_file
*tmp_error_stream
,
2614 int *disabled_breaks
,
2615 int *hw_breakpoint_error
,
2616 int *hw_bp_error_explained_already
)
2618 enum errors bp_err
= GDB_NO_ERROR
;
2619 const char *bp_err_message
= NULL
;
2621 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2624 /* Note we don't initialize bl->target_info, as that wipes out
2625 the breakpoint location's shadow_contents if the breakpoint
2626 is still inserted at that location. This in turn breaks
2627 target_read_memory which depends on these buffers when
2628 a memory read is requested at the breakpoint location:
2629 Once the target_info has been wiped, we fail to see that
2630 we have a breakpoint inserted at that address and thus
2631 read the breakpoint instead of returning the data saved in
2632 the breakpoint location's shadow contents. */
2633 bl
->target_info
.reqstd_address
= bl
->address
;
2634 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2635 bl
->target_info
.length
= bl
->length
;
2637 /* When working with target-side conditions, we must pass all the conditions
2638 for the same breakpoint address down to the target since GDB will not
2639 insert those locations. With a list of breakpoint conditions, the target
2640 can decide when to stop and notify GDB. */
2642 if (is_breakpoint (bl
->owner
))
2644 build_target_condition_list (bl
);
2645 build_target_command_list (bl
);
2646 /* Reset the modification marker. */
2647 bl
->needs_update
= 0;
2650 if (bl
->loc_type
== bp_loc_software_breakpoint
2651 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2653 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2655 /* If the explicitly specified breakpoint type
2656 is not hardware breakpoint, check the memory map to see
2657 if the breakpoint address is in read only memory or not.
2659 Two important cases are:
2660 - location type is not hardware breakpoint, memory
2661 is readonly. We change the type of the location to
2662 hardware breakpoint.
2663 - location type is hardware breakpoint, memory is
2664 read-write. This means we've previously made the
2665 location hardware one, but then the memory map changed,
2668 When breakpoints are removed, remove_breakpoints will use
2669 location types we've just set here, the only possible
2670 problem is that memory map has changed during running
2671 program, but it's not going to work anyway with current
2673 struct mem_region
*mr
2674 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2678 if (automatic_hardware_breakpoints
)
2680 enum bp_loc_type new_type
;
2682 if (mr
->attrib
.mode
!= MEM_RW
)
2683 new_type
= bp_loc_hardware_breakpoint
;
2685 new_type
= bp_loc_software_breakpoint
;
2687 if (new_type
!= bl
->loc_type
)
2689 static int said
= 0;
2691 bl
->loc_type
= new_type
;
2694 fprintf_filtered (gdb_stdout
,
2695 _("Note: automatically using "
2696 "hardware breakpoints for "
2697 "read-only addresses.\n"));
2702 else if (bl
->loc_type
== bp_loc_software_breakpoint
2703 && mr
->attrib
.mode
!= MEM_RW
)
2705 fprintf_unfiltered (tmp_error_stream
,
2706 _("Cannot insert breakpoint %d.\n"
2707 "Cannot set software breakpoint "
2708 "at read-only address %s\n"),
2710 paddress (bl
->gdbarch
, bl
->address
));
2716 /* First check to see if we have to handle an overlay. */
2717 if (overlay_debugging
== ovly_off
2718 || bl
->section
== NULL
2719 || !(section_is_overlay (bl
->section
)))
2721 /* No overlay handling: just set the breakpoint. */
2726 val
= bl
->owner
->ops
->insert_location (bl
);
2728 bp_err
= GENERIC_ERROR
;
2730 CATCH (e
, RETURN_MASK_ALL
)
2733 bp_err_message
= e
.message
;
2739 /* This breakpoint is in an overlay section.
2740 Shall we set a breakpoint at the LMA? */
2741 if (!overlay_events_enabled
)
2743 /* Yes -- overlay event support is not active,
2744 so we must try to set a breakpoint at the LMA.
2745 This will not work for a hardware breakpoint. */
2746 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2747 warning (_("hardware breakpoint %d not supported in overlay!"),
2751 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2753 /* Set a software (trap) breakpoint at the LMA. */
2754 bl
->overlay_target_info
= bl
->target_info
;
2755 bl
->overlay_target_info
.reqstd_address
= addr
;
2757 /* No overlay handling: just set the breakpoint. */
2762 bl
->overlay_target_info
.kind
2763 = breakpoint_kind (bl
, &addr
);
2764 bl
->overlay_target_info
.placed_address
= addr
;
2765 val
= target_insert_breakpoint (bl
->gdbarch
,
2766 &bl
->overlay_target_info
);
2768 bp_err
= GENERIC_ERROR
;
2770 CATCH (e
, RETURN_MASK_ALL
)
2773 bp_err_message
= e
.message
;
2777 if (bp_err
!= GDB_NO_ERROR
)
2778 fprintf_unfiltered (tmp_error_stream
,
2779 "Overlay breakpoint %d "
2780 "failed: in ROM?\n",
2784 /* Shall we set a breakpoint at the VMA? */
2785 if (section_is_mapped (bl
->section
))
2787 /* Yes. This overlay section is mapped into memory. */
2792 val
= bl
->owner
->ops
->insert_location (bl
);
2794 bp_err
= GENERIC_ERROR
;
2796 CATCH (e
, RETURN_MASK_ALL
)
2799 bp_err_message
= e
.message
;
2805 /* No. This breakpoint will not be inserted.
2806 No error, but do not mark the bp as 'inserted'. */
2811 if (bp_err
!= GDB_NO_ERROR
)
2813 /* Can't set the breakpoint. */
2815 /* In some cases, we might not be able to insert a
2816 breakpoint in a shared library that has already been
2817 removed, but we have not yet processed the shlib unload
2818 event. Unfortunately, some targets that implement
2819 breakpoint insertion themselves can't tell why the
2820 breakpoint insertion failed (e.g., the remote target
2821 doesn't define error codes), so we must treat generic
2822 errors as memory errors. */
2823 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2824 && bl
->loc_type
== bp_loc_software_breakpoint
2825 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2826 || shared_objfile_contains_address_p (bl
->pspace
,
2829 /* See also: disable_breakpoints_in_shlibs. */
2830 bl
->shlib_disabled
= 1;
2831 observer_notify_breakpoint_modified (bl
->owner
);
2832 if (!*disabled_breaks
)
2834 fprintf_unfiltered (tmp_error_stream
,
2835 "Cannot insert breakpoint %d.\n",
2837 fprintf_unfiltered (tmp_error_stream
,
2838 "Temporarily disabling shared "
2839 "library breakpoints:\n");
2841 *disabled_breaks
= 1;
2842 fprintf_unfiltered (tmp_error_stream
,
2843 "breakpoint #%d\n", bl
->owner
->number
);
2848 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2850 *hw_breakpoint_error
= 1;
2851 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2852 fprintf_unfiltered (tmp_error_stream
,
2853 "Cannot insert hardware breakpoint %d%s",
2854 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2855 if (bp_err_message
!= NULL
)
2856 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2860 if (bp_err_message
== NULL
)
2863 = memory_error_message (TARGET_XFER_E_IO
,
2864 bl
->gdbarch
, bl
->address
);
2865 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2867 fprintf_unfiltered (tmp_error_stream
,
2868 "Cannot insert breakpoint %d.\n"
2870 bl
->owner
->number
, message
);
2871 do_cleanups (old_chain
);
2875 fprintf_unfiltered (tmp_error_stream
,
2876 "Cannot insert breakpoint %d: %s\n",
2891 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2892 /* NOTE drow/2003-09-08: This state only exists for removing
2893 watchpoints. It's not clear that it's necessary... */
2894 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2898 gdb_assert (bl
->owner
->ops
!= NULL
2899 && bl
->owner
->ops
->insert_location
!= NULL
);
2901 val
= bl
->owner
->ops
->insert_location (bl
);
2903 /* If trying to set a read-watchpoint, and it turns out it's not
2904 supported, try emulating one with an access watchpoint. */
2905 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2907 struct bp_location
*loc
, **loc_temp
;
2909 /* But don't try to insert it, if there's already another
2910 hw_access location that would be considered a duplicate
2912 ALL_BP_LOCATIONS (loc
, loc_temp
)
2914 && loc
->watchpoint_type
== hw_access
2915 && watchpoint_locations_match (bl
, loc
))
2919 bl
->target_info
= loc
->target_info
;
2920 bl
->watchpoint_type
= hw_access
;
2927 bl
->watchpoint_type
= hw_access
;
2928 val
= bl
->owner
->ops
->insert_location (bl
);
2931 /* Back to the original value. */
2932 bl
->watchpoint_type
= hw_read
;
2936 bl
->inserted
= (val
== 0);
2939 else if (bl
->owner
->type
== bp_catchpoint
)
2943 gdb_assert (bl
->owner
->ops
!= NULL
2944 && bl
->owner
->ops
->insert_location
!= NULL
);
2946 val
= bl
->owner
->ops
->insert_location (bl
);
2949 bl
->owner
->enable_state
= bp_disabled
;
2953 Error inserting catchpoint %d: Your system does not support this type\n\
2954 of catchpoint."), bl
->owner
->number
);
2956 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2959 bl
->inserted
= (val
== 0);
2961 /* We've already printed an error message if there was a problem
2962 inserting this catchpoint, and we've disabled the catchpoint,
2963 so just return success. */
2970 /* This function is called when program space PSPACE is about to be
2971 deleted. It takes care of updating breakpoints to not reference
2975 breakpoint_program_space_exit (struct program_space
*pspace
)
2977 struct breakpoint
*b
, *b_temp
;
2978 struct bp_location
*loc
, **loc_temp
;
2980 /* Remove any breakpoint that was set through this program space. */
2981 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2983 if (b
->pspace
== pspace
)
2984 delete_breakpoint (b
);
2987 /* Breakpoints set through other program spaces could have locations
2988 bound to PSPACE as well. Remove those. */
2989 ALL_BP_LOCATIONS (loc
, loc_temp
)
2991 struct bp_location
*tmp
;
2993 if (loc
->pspace
== pspace
)
2995 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2996 if (loc
->owner
->loc
== loc
)
2997 loc
->owner
->loc
= loc
->next
;
2999 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3000 if (tmp
->next
== loc
)
3002 tmp
->next
= loc
->next
;
3008 /* Now update the global location list to permanently delete the
3009 removed locations above. */
3010 update_global_location_list (UGLL_DONT_INSERT
);
3013 /* Make sure all breakpoints are inserted in inferior.
3014 Throws exception on any error.
3015 A breakpoint that is already inserted won't be inserted
3016 again, so calling this function twice is safe. */
3018 insert_breakpoints (void)
3020 struct breakpoint
*bpt
;
3022 ALL_BREAKPOINTS (bpt
)
3023 if (is_hardware_watchpoint (bpt
))
3025 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3027 update_watchpoint (w
, 0 /* don't reparse. */);
3030 /* Updating watchpoints creates new locations, so update the global
3031 location list. Explicitly tell ugll to insert locations and
3032 ignore breakpoints_always_inserted_mode. */
3033 update_global_location_list (UGLL_INSERT
);
3036 /* Invoke CALLBACK for each of bp_location. */
3039 iterate_over_bp_locations (walk_bp_location_callback callback
)
3041 struct bp_location
*loc
, **loc_tmp
;
3043 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3045 callback (loc
, NULL
);
3049 /* This is used when we need to synch breakpoint conditions between GDB and the
3050 target. It is the case with deleting and disabling of breakpoints when using
3051 always-inserted mode. */
3054 update_inserted_breakpoint_locations (void)
3056 struct bp_location
*bl
, **blp_tmp
;
3059 int disabled_breaks
= 0;
3060 int hw_breakpoint_error
= 0;
3061 int hw_bp_details_reported
= 0;
3063 string_file tmp_error_stream
;
3065 /* Explicitly mark the warning -- this will only be printed if
3066 there was an error. */
3067 tmp_error_stream
.puts ("Warning:\n");
3069 struct cleanup
*cleanups
= save_current_space_and_thread ();
3071 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3073 /* We only want to update software breakpoints and hardware
3075 if (!is_breakpoint (bl
->owner
))
3078 /* We only want to update locations that are already inserted
3079 and need updating. This is to avoid unwanted insertion during
3080 deletion of breakpoints. */
3081 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3084 switch_to_program_space_and_thread (bl
->pspace
);
3086 /* For targets that support global breakpoints, there's no need
3087 to select an inferior to insert breakpoint to. In fact, even
3088 if we aren't attached to any process yet, we should still
3089 insert breakpoints. */
3090 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3091 && ptid_equal (inferior_ptid
, null_ptid
))
3094 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3095 &hw_breakpoint_error
, &hw_bp_details_reported
);
3102 target_terminal_ours_for_output ();
3103 error_stream (tmp_error_stream
);
3106 do_cleanups (cleanups
);
3109 /* Used when starting or continuing the program. */
3112 insert_breakpoint_locations (void)
3114 struct breakpoint
*bpt
;
3115 struct bp_location
*bl
, **blp_tmp
;
3118 int disabled_breaks
= 0;
3119 int hw_breakpoint_error
= 0;
3120 int hw_bp_error_explained_already
= 0;
3122 string_file tmp_error_stream
;
3124 /* Explicitly mark the warning -- this will only be printed if
3125 there was an error. */
3126 tmp_error_stream
.puts ("Warning:\n");
3128 struct cleanup
*cleanups
= save_current_space_and_thread ();
3130 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3132 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3135 /* There is no point inserting thread-specific breakpoints if
3136 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3137 has BL->OWNER always non-NULL. */
3138 if (bl
->owner
->thread
!= -1
3139 && !valid_global_thread_id (bl
->owner
->thread
))
3142 switch_to_program_space_and_thread (bl
->pspace
);
3144 /* For targets that support global breakpoints, there's no need
3145 to select an inferior to insert breakpoint to. In fact, even
3146 if we aren't attached to any process yet, we should still
3147 insert breakpoints. */
3148 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3149 && ptid_equal (inferior_ptid
, null_ptid
))
3152 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3153 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3158 /* If we failed to insert all locations of a watchpoint, remove
3159 them, as half-inserted watchpoint is of limited use. */
3160 ALL_BREAKPOINTS (bpt
)
3162 int some_failed
= 0;
3163 struct bp_location
*loc
;
3165 if (!is_hardware_watchpoint (bpt
))
3168 if (!breakpoint_enabled (bpt
))
3171 if (bpt
->disposition
== disp_del_at_next_stop
)
3174 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3175 if (!loc
->inserted
&& should_be_inserted (loc
))
3182 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3184 remove_breakpoint (loc
);
3186 hw_breakpoint_error
= 1;
3187 tmp_error_stream
.printf ("Could not insert "
3188 "hardware watchpoint %d.\n",
3196 /* If a hardware breakpoint or watchpoint was inserted, add a
3197 message about possibly exhausted resources. */
3198 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3200 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3201 You may have requested too many hardware breakpoints/watchpoints.\n");
3203 target_terminal_ours_for_output ();
3204 error_stream (tmp_error_stream
);
3207 do_cleanups (cleanups
);
3210 /* Used when the program stops.
3211 Returns zero if successful, or non-zero if there was a problem
3212 removing a breakpoint location. */
3215 remove_breakpoints (void)
3217 struct bp_location
*bl
, **blp_tmp
;
3220 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3222 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3223 val
|= remove_breakpoint (bl
);
3228 /* When a thread exits, remove breakpoints that are related to
3232 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3234 struct breakpoint
*b
, *b_tmp
;
3236 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3238 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3240 b
->disposition
= disp_del_at_next_stop
;
3242 printf_filtered (_("\
3243 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3244 b
->number
, print_thread_id (tp
));
3246 /* Hide it from the user. */
3252 /* Remove breakpoints of process PID. */
3255 remove_breakpoints_pid (int pid
)
3257 struct bp_location
*bl
, **blp_tmp
;
3259 struct inferior
*inf
= find_inferior_pid (pid
);
3261 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3263 if (bl
->pspace
!= inf
->pspace
)
3266 if (bl
->inserted
&& !bl
->target_info
.persist
)
3268 val
= remove_breakpoint (bl
);
3277 reattach_breakpoints (int pid
)
3279 struct cleanup
*old_chain
;
3280 struct bp_location
*bl
, **blp_tmp
;
3282 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3283 struct inferior
*inf
;
3284 struct thread_info
*tp
;
3286 tp
= any_live_thread_of_process (pid
);
3290 inf
= find_inferior_pid (pid
);
3291 old_chain
= save_inferior_ptid ();
3293 inferior_ptid
= tp
->ptid
;
3295 string_file tmp_error_stream
;
3297 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3299 if (bl
->pspace
!= inf
->pspace
)
3305 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3308 do_cleanups (old_chain
);
3313 do_cleanups (old_chain
);
3317 static int internal_breakpoint_number
= -1;
3319 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3320 If INTERNAL is non-zero, the breakpoint number will be populated
3321 from internal_breakpoint_number and that variable decremented.
3322 Otherwise the breakpoint number will be populated from
3323 breakpoint_count and that value incremented. Internal breakpoints
3324 do not set the internal var bpnum. */
3326 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3329 b
->number
= internal_breakpoint_number
--;
3332 set_breakpoint_count (breakpoint_count
+ 1);
3333 b
->number
= breakpoint_count
;
3337 static struct breakpoint
*
3338 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3339 CORE_ADDR address
, enum bptype type
,
3340 const struct breakpoint_ops
*ops
)
3342 struct symtab_and_line sal
;
3343 struct breakpoint
*b
;
3345 init_sal (&sal
); /* Initialize to zeroes. */
3348 sal
.section
= find_pc_overlay (sal
.pc
);
3349 sal
.pspace
= current_program_space
;
3351 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3352 b
->number
= internal_breakpoint_number
--;
3353 b
->disposition
= disp_donttouch
;
3358 static const char *const longjmp_names
[] =
3360 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3362 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3364 /* Per-objfile data private to breakpoint.c. */
3365 struct breakpoint_objfile_data
3367 /* Minimal symbol for "_ovly_debug_event" (if any). */
3368 struct bound_minimal_symbol overlay_msym
;
3370 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3371 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3373 /* True if we have looked for longjmp probes. */
3374 int longjmp_searched
;
3376 /* SystemTap probe points for longjmp (if any). */
3377 VEC (probe_p
) *longjmp_probes
;
3379 /* Minimal symbol for "std::terminate()" (if any). */
3380 struct bound_minimal_symbol terminate_msym
;
3382 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3383 struct bound_minimal_symbol exception_msym
;
3385 /* True if we have looked for exception probes. */
3386 int exception_searched
;
3388 /* SystemTap probe points for unwinding (if any). */
3389 VEC (probe_p
) *exception_probes
;
3392 static const struct objfile_data
*breakpoint_objfile_key
;
3394 /* Minimal symbol not found sentinel. */
3395 static struct minimal_symbol msym_not_found
;
3397 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3400 msym_not_found_p (const struct minimal_symbol
*msym
)
3402 return msym
== &msym_not_found
;
3405 /* Return per-objfile data needed by breakpoint.c.
3406 Allocate the data if necessary. */
3408 static struct breakpoint_objfile_data
*
3409 get_breakpoint_objfile_data (struct objfile
*objfile
)
3411 struct breakpoint_objfile_data
*bp_objfile_data
;
3413 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3414 objfile_data (objfile
, breakpoint_objfile_key
));
3415 if (bp_objfile_data
== NULL
)
3418 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3420 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3421 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3423 return bp_objfile_data
;
3427 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3429 struct breakpoint_objfile_data
*bp_objfile_data
3430 = (struct breakpoint_objfile_data
*) data
;
3432 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3433 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3437 create_overlay_event_breakpoint (void)
3439 struct objfile
*objfile
;
3440 const char *const func_name
= "_ovly_debug_event";
3442 ALL_OBJFILES (objfile
)
3444 struct breakpoint
*b
;
3445 struct breakpoint_objfile_data
*bp_objfile_data
;
3447 struct explicit_location explicit_loc
;
3449 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3451 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3454 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3456 struct bound_minimal_symbol m
;
3458 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3459 if (m
.minsym
== NULL
)
3461 /* Avoid future lookups in this objfile. */
3462 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3465 bp_objfile_data
->overlay_msym
= m
;
3468 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3469 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3471 &internal_breakpoint_ops
);
3472 initialize_explicit_location (&explicit_loc
);
3473 explicit_loc
.function_name
= ASTRDUP (func_name
);
3474 b
->location
= new_explicit_location (&explicit_loc
);
3476 if (overlay_debugging
== ovly_auto
)
3478 b
->enable_state
= bp_enabled
;
3479 overlay_events_enabled
= 1;
3483 b
->enable_state
= bp_disabled
;
3484 overlay_events_enabled
= 0;
3490 create_longjmp_master_breakpoint (void)
3492 struct program_space
*pspace
;
3493 struct cleanup
*old_chain
;
3495 old_chain
= save_current_program_space ();
3497 ALL_PSPACES (pspace
)
3499 struct objfile
*objfile
;
3501 set_current_program_space (pspace
);
3503 ALL_OBJFILES (objfile
)
3506 struct gdbarch
*gdbarch
;
3507 struct breakpoint_objfile_data
*bp_objfile_data
;
3509 gdbarch
= get_objfile_arch (objfile
);
3511 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3513 if (!bp_objfile_data
->longjmp_searched
)
3517 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3520 /* We are only interested in checking one element. */
3521 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3523 if (!can_evaluate_probe_arguments (p
))
3525 /* We cannot use the probe interface here, because it does
3526 not know how to evaluate arguments. */
3527 VEC_free (probe_p
, ret
);
3531 bp_objfile_data
->longjmp_probes
= ret
;
3532 bp_objfile_data
->longjmp_searched
= 1;
3535 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3538 struct probe
*probe
;
3539 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3542 VEC_iterate (probe_p
,
3543 bp_objfile_data
->longjmp_probes
,
3547 struct breakpoint
*b
;
3549 b
= create_internal_breakpoint (gdbarch
,
3550 get_probe_address (probe
,
3553 &internal_breakpoint_ops
);
3554 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3555 b
->enable_state
= bp_disabled
;
3561 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3564 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3566 struct breakpoint
*b
;
3567 const char *func_name
;
3569 struct explicit_location explicit_loc
;
3571 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3574 func_name
= longjmp_names
[i
];
3575 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3577 struct bound_minimal_symbol m
;
3579 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3580 if (m
.minsym
== NULL
)
3582 /* Prevent future lookups in this objfile. */
3583 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3586 bp_objfile_data
->longjmp_msym
[i
] = m
;
3589 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3590 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3591 &internal_breakpoint_ops
);
3592 initialize_explicit_location (&explicit_loc
);
3593 explicit_loc
.function_name
= ASTRDUP (func_name
);
3594 b
->location
= new_explicit_location (&explicit_loc
);
3595 b
->enable_state
= bp_disabled
;
3600 do_cleanups (old_chain
);
3603 /* Create a master std::terminate breakpoint. */
3605 create_std_terminate_master_breakpoint (void)
3607 struct program_space
*pspace
;
3608 struct cleanup
*old_chain
;
3609 const char *const func_name
= "std::terminate()";
3611 old_chain
= save_current_program_space ();
3613 ALL_PSPACES (pspace
)
3615 struct objfile
*objfile
;
3618 set_current_program_space (pspace
);
3620 ALL_OBJFILES (objfile
)
3622 struct breakpoint
*b
;
3623 struct breakpoint_objfile_data
*bp_objfile_data
;
3624 struct explicit_location explicit_loc
;
3626 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3628 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3631 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3633 struct bound_minimal_symbol m
;
3635 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3636 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3637 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3639 /* Prevent future lookups in this objfile. */
3640 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3643 bp_objfile_data
->terminate_msym
= m
;
3646 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3647 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3648 bp_std_terminate_master
,
3649 &internal_breakpoint_ops
);
3650 initialize_explicit_location (&explicit_loc
);
3651 explicit_loc
.function_name
= ASTRDUP (func_name
);
3652 b
->location
= new_explicit_location (&explicit_loc
);
3653 b
->enable_state
= bp_disabled
;
3657 do_cleanups (old_chain
);
3660 /* Install a master breakpoint on the unwinder's debug hook. */
3663 create_exception_master_breakpoint (void)
3665 struct objfile
*objfile
;
3666 const char *const func_name
= "_Unwind_DebugHook";
3668 ALL_OBJFILES (objfile
)
3670 struct breakpoint
*b
;
3671 struct gdbarch
*gdbarch
;
3672 struct breakpoint_objfile_data
*bp_objfile_data
;
3674 struct explicit_location explicit_loc
;
3676 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3678 /* We prefer the SystemTap probe point if it exists. */
3679 if (!bp_objfile_data
->exception_searched
)
3683 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3687 /* We are only interested in checking one element. */
3688 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3690 if (!can_evaluate_probe_arguments (p
))
3692 /* We cannot use the probe interface here, because it does
3693 not know how to evaluate arguments. */
3694 VEC_free (probe_p
, ret
);
3698 bp_objfile_data
->exception_probes
= ret
;
3699 bp_objfile_data
->exception_searched
= 1;
3702 if (bp_objfile_data
->exception_probes
!= NULL
)
3704 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3706 struct probe
*probe
;
3709 VEC_iterate (probe_p
,
3710 bp_objfile_data
->exception_probes
,
3714 struct breakpoint
*b
;
3716 b
= create_internal_breakpoint (gdbarch
,
3717 get_probe_address (probe
,
3719 bp_exception_master
,
3720 &internal_breakpoint_ops
);
3721 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3722 b
->enable_state
= bp_disabled
;
3728 /* Otherwise, try the hook function. */
3730 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3733 gdbarch
= get_objfile_arch (objfile
);
3735 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3737 struct bound_minimal_symbol debug_hook
;
3739 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3740 if (debug_hook
.minsym
== NULL
)
3742 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3746 bp_objfile_data
->exception_msym
= debug_hook
;
3749 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3750 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3752 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3753 &internal_breakpoint_ops
);
3754 initialize_explicit_location (&explicit_loc
);
3755 explicit_loc
.function_name
= ASTRDUP (func_name
);
3756 b
->location
= new_explicit_location (&explicit_loc
);
3757 b
->enable_state
= bp_disabled
;
3761 /* Does B have a location spec? */
3764 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3766 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3770 update_breakpoints_after_exec (void)
3772 struct breakpoint
*b
, *b_tmp
;
3773 struct bp_location
*bploc
, **bplocp_tmp
;
3775 /* We're about to delete breakpoints from GDB's lists. If the
3776 INSERTED flag is true, GDB will try to lift the breakpoints by
3777 writing the breakpoints' "shadow contents" back into memory. The
3778 "shadow contents" are NOT valid after an exec, so GDB should not
3779 do that. Instead, the target is responsible from marking
3780 breakpoints out as soon as it detects an exec. We don't do that
3781 here instead, because there may be other attempts to delete
3782 breakpoints after detecting an exec and before reaching here. */
3783 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3784 if (bploc
->pspace
== current_program_space
)
3785 gdb_assert (!bploc
->inserted
);
3787 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3789 if (b
->pspace
!= current_program_space
)
3792 /* Solib breakpoints must be explicitly reset after an exec(). */
3793 if (b
->type
== bp_shlib_event
)
3795 delete_breakpoint (b
);
3799 /* JIT breakpoints must be explicitly reset after an exec(). */
3800 if (b
->type
== bp_jit_event
)
3802 delete_breakpoint (b
);
3806 /* Thread event breakpoints must be set anew after an exec(),
3807 as must overlay event and longjmp master breakpoints. */
3808 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3809 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3810 || b
->type
== bp_exception_master
)
3812 delete_breakpoint (b
);
3816 /* Step-resume breakpoints are meaningless after an exec(). */
3817 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3819 delete_breakpoint (b
);
3823 /* Just like single-step breakpoints. */
3824 if (b
->type
== bp_single_step
)
3826 delete_breakpoint (b
);
3830 /* Longjmp and longjmp-resume breakpoints are also meaningless
3832 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3833 || b
->type
== bp_longjmp_call_dummy
3834 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3836 delete_breakpoint (b
);
3840 if (b
->type
== bp_catchpoint
)
3842 /* For now, none of the bp_catchpoint breakpoints need to
3843 do anything at this point. In the future, if some of
3844 the catchpoints need to something, we will need to add
3845 a new method, and call this method from here. */
3849 /* bp_finish is a special case. The only way we ought to be able
3850 to see one of these when an exec() has happened, is if the user
3851 caught a vfork, and then said "finish". Ordinarily a finish just
3852 carries them to the call-site of the current callee, by setting
3853 a temporary bp there and resuming. But in this case, the finish
3854 will carry them entirely through the vfork & exec.
3856 We don't want to allow a bp_finish to remain inserted now. But
3857 we can't safely delete it, 'cause finish_command has a handle to
3858 the bp on a bpstat, and will later want to delete it. There's a
3859 chance (and I've seen it happen) that if we delete the bp_finish
3860 here, that its storage will get reused by the time finish_command
3861 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3862 We really must allow finish_command to delete a bp_finish.
3864 In the absence of a general solution for the "how do we know
3865 it's safe to delete something others may have handles to?"
3866 problem, what we'll do here is just uninsert the bp_finish, and
3867 let finish_command delete it.
3869 (We know the bp_finish is "doomed" in the sense that it's
3870 momentary, and will be deleted as soon as finish_command sees
3871 the inferior stopped. So it doesn't matter that the bp's
3872 address is probably bogus in the new a.out, unlike e.g., the
3873 solib breakpoints.) */
3875 if (b
->type
== bp_finish
)
3880 /* Without a symbolic address, we have little hope of the
3881 pre-exec() address meaning the same thing in the post-exec()
3883 if (breakpoint_event_location_empty_p (b
))
3885 delete_breakpoint (b
);
3892 detach_breakpoints (ptid_t ptid
)
3894 struct bp_location
*bl
, **blp_tmp
;
3896 struct cleanup
*old_chain
= save_inferior_ptid ();
3897 struct inferior
*inf
= current_inferior ();
3899 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3900 error (_("Cannot detach breakpoints of inferior_ptid"));
3902 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3903 inferior_ptid
= ptid
;
3904 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3906 if (bl
->pspace
!= inf
->pspace
)
3909 /* This function must physically remove breakpoints locations
3910 from the specified ptid, without modifying the breakpoint
3911 package's state. Locations of type bp_loc_other are only
3912 maintained at GDB side. So, there is no need to remove
3913 these bp_loc_other locations. Moreover, removing these
3914 would modify the breakpoint package's state. */
3915 if (bl
->loc_type
== bp_loc_other
)
3919 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3922 do_cleanups (old_chain
);
3926 /* Remove the breakpoint location BL from the current address space.
3927 Note that this is used to detach breakpoints from a child fork.
3928 When we get here, the child isn't in the inferior list, and neither
3929 do we have objects to represent its address space --- we should
3930 *not* look at bl->pspace->aspace here. */
3933 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3937 /* BL is never in moribund_locations by our callers. */
3938 gdb_assert (bl
->owner
!= NULL
);
3940 /* The type of none suggests that owner is actually deleted.
3941 This should not ever happen. */
3942 gdb_assert (bl
->owner
->type
!= bp_none
);
3944 if (bl
->loc_type
== bp_loc_software_breakpoint
3945 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3947 /* "Normal" instruction breakpoint: either the standard
3948 trap-instruction bp (bp_breakpoint), or a
3949 bp_hardware_breakpoint. */
3951 /* First check to see if we have to handle an overlay. */
3952 if (overlay_debugging
== ovly_off
3953 || bl
->section
== NULL
3954 || !(section_is_overlay (bl
->section
)))
3956 /* No overlay handling: just remove the breakpoint. */
3958 /* If we're trying to uninsert a memory breakpoint that we
3959 know is set in a dynamic object that is marked
3960 shlib_disabled, then either the dynamic object was
3961 removed with "remove-symbol-file" or with
3962 "nosharedlibrary". In the former case, we don't know
3963 whether another dynamic object might have loaded over the
3964 breakpoint's address -- the user might well let us know
3965 about it next with add-symbol-file (the whole point of
3966 add-symbol-file is letting the user manually maintain a
3967 list of dynamically loaded objects). If we have the
3968 breakpoint's shadow memory, that is, this is a software
3969 breakpoint managed by GDB, check whether the breakpoint
3970 is still inserted in memory, to avoid overwriting wrong
3971 code with stale saved shadow contents. Note that HW
3972 breakpoints don't have shadow memory, as they're
3973 implemented using a mechanism that is not dependent on
3974 being able to modify the target's memory, and as such
3975 they should always be removed. */
3976 if (bl
->shlib_disabled
3977 && bl
->target_info
.shadow_len
!= 0
3978 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3981 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3985 /* This breakpoint is in an overlay section.
3986 Did we set a breakpoint at the LMA? */
3987 if (!overlay_events_enabled
)
3989 /* Yes -- overlay event support is not active, so we
3990 should have set a breakpoint at the LMA. Remove it.
3992 /* Ignore any failures: if the LMA is in ROM, we will
3993 have already warned when we failed to insert it. */
3994 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3995 target_remove_hw_breakpoint (bl
->gdbarch
,
3996 &bl
->overlay_target_info
);
3998 target_remove_breakpoint (bl
->gdbarch
,
3999 &bl
->overlay_target_info
,
4002 /* Did we set a breakpoint at the VMA?
4003 If so, we will have marked the breakpoint 'inserted'. */
4006 /* Yes -- remove it. Previously we did not bother to
4007 remove the breakpoint if the section had been
4008 unmapped, but let's not rely on that being safe. We
4009 don't know what the overlay manager might do. */
4011 /* However, we should remove *software* breakpoints only
4012 if the section is still mapped, or else we overwrite
4013 wrong code with the saved shadow contents. */
4014 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4015 || section_is_mapped (bl
->section
))
4016 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4022 /* No -- not inserted, so no need to remove. No error. */
4027 /* In some cases, we might not be able to remove a breakpoint in
4028 a shared library that has already been removed, but we have
4029 not yet processed the shlib unload event. Similarly for an
4030 unloaded add-symbol-file object - the user might not yet have
4031 had the chance to remove-symbol-file it. shlib_disabled will
4032 be set if the library/object has already been removed, but
4033 the breakpoint hasn't been uninserted yet, e.g., after
4034 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4035 always-inserted mode. */
4037 && (bl
->loc_type
== bp_loc_software_breakpoint
4038 && (bl
->shlib_disabled
4039 || solib_name_from_address (bl
->pspace
, bl
->address
)
4040 || shared_objfile_contains_address_p (bl
->pspace
,
4046 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4048 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4050 gdb_assert (bl
->owner
->ops
!= NULL
4051 && bl
->owner
->ops
->remove_location
!= NULL
);
4053 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4054 bl
->owner
->ops
->remove_location (bl
, reason
);
4056 /* Failure to remove any of the hardware watchpoints comes here. */
4057 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4058 warning (_("Could not remove hardware watchpoint %d."),
4061 else if (bl
->owner
->type
== bp_catchpoint
4062 && breakpoint_enabled (bl
->owner
)
4065 gdb_assert (bl
->owner
->ops
!= NULL
4066 && bl
->owner
->ops
->remove_location
!= NULL
);
4068 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4072 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4079 remove_breakpoint (struct bp_location
*bl
)
4082 struct cleanup
*old_chain
;
4084 /* BL is never in moribund_locations by our callers. */
4085 gdb_assert (bl
->owner
!= NULL
);
4087 /* The type of none suggests that owner is actually deleted.
4088 This should not ever happen. */
4089 gdb_assert (bl
->owner
->type
!= bp_none
);
4091 old_chain
= save_current_space_and_thread ();
4093 switch_to_program_space_and_thread (bl
->pspace
);
4095 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4097 do_cleanups (old_chain
);
4101 /* Clear the "inserted" flag in all breakpoints. */
4104 mark_breakpoints_out (void)
4106 struct bp_location
*bl
, **blp_tmp
;
4108 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4109 if (bl
->pspace
== current_program_space
)
4113 /* Clear the "inserted" flag in all breakpoints and delete any
4114 breakpoints which should go away between runs of the program.
4116 Plus other such housekeeping that has to be done for breakpoints
4119 Note: this function gets called at the end of a run (by
4120 generic_mourn_inferior) and when a run begins (by
4121 init_wait_for_inferior). */
4126 breakpoint_init_inferior (enum inf_context context
)
4128 struct breakpoint
*b
, *b_tmp
;
4129 struct bp_location
*bl
;
4131 struct program_space
*pspace
= current_program_space
;
4133 /* If breakpoint locations are shared across processes, then there's
4135 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4138 mark_breakpoints_out ();
4140 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4142 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4148 case bp_longjmp_call_dummy
:
4150 /* If the call dummy breakpoint is at the entry point it will
4151 cause problems when the inferior is rerun, so we better get
4154 case bp_watchpoint_scope
:
4156 /* Also get rid of scope breakpoints. */
4158 case bp_shlib_event
:
4160 /* Also remove solib event breakpoints. Their addresses may
4161 have changed since the last time we ran the program.
4162 Actually we may now be debugging against different target;
4163 and so the solib backend that installed this breakpoint may
4164 not be used in by the target. E.g.,
4166 (gdb) file prog-linux
4167 (gdb) run # native linux target
4170 (gdb) file prog-win.exe
4171 (gdb) tar rem :9999 # remote Windows gdbserver.
4174 case bp_step_resume
:
4176 /* Also remove step-resume breakpoints. */
4178 case bp_single_step
:
4180 /* Also remove single-step breakpoints. */
4182 delete_breakpoint (b
);
4186 case bp_hardware_watchpoint
:
4187 case bp_read_watchpoint
:
4188 case bp_access_watchpoint
:
4190 struct watchpoint
*w
= (struct watchpoint
*) b
;
4192 /* Likewise for watchpoints on local expressions. */
4193 if (w
->exp_valid_block
!= NULL
)
4194 delete_breakpoint (b
);
4197 /* Get rid of existing locations, which are no longer
4198 valid. New ones will be created in
4199 update_watchpoint, when the inferior is restarted.
4200 The next update_global_location_list call will
4201 garbage collect them. */
4204 if (context
== inf_starting
)
4206 /* Reset val field to force reread of starting value in
4207 insert_breakpoints. */
4209 value_free (w
->val
);
4221 /* Get rid of the moribund locations. */
4222 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4223 decref_bp_location (&bl
);
4224 VEC_free (bp_location_p
, moribund_locations
);
4227 /* These functions concern about actual breakpoints inserted in the
4228 target --- to e.g. check if we need to do decr_pc adjustment or if
4229 we need to hop over the bkpt --- so we check for address space
4230 match, not program space. */
4232 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4233 exists at PC. It returns ordinary_breakpoint_here if it's an
4234 ordinary breakpoint, or permanent_breakpoint_here if it's a
4235 permanent breakpoint.
4236 - When continuing from a location with an ordinary breakpoint, we
4237 actually single step once before calling insert_breakpoints.
4238 - When continuing from a location with a permanent breakpoint, we
4239 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4240 the target, to advance the PC past the breakpoint. */
4242 enum breakpoint_here
4243 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4245 struct bp_location
*bl
, **blp_tmp
;
4246 int any_breakpoint_here
= 0;
4248 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4250 if (bl
->loc_type
!= bp_loc_software_breakpoint
4251 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4254 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4255 if ((breakpoint_enabled (bl
->owner
)
4257 && breakpoint_location_address_match (bl
, aspace
, pc
))
4259 if (overlay_debugging
4260 && section_is_overlay (bl
->section
)
4261 && !section_is_mapped (bl
->section
))
4262 continue; /* unmapped overlay -- can't be a match */
4263 else if (bl
->permanent
)
4264 return permanent_breakpoint_here
;
4266 any_breakpoint_here
= 1;
4270 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4273 /* See breakpoint.h. */
4276 breakpoint_in_range_p (struct address_space
*aspace
,
4277 CORE_ADDR addr
, ULONGEST len
)
4279 struct bp_location
*bl
, **blp_tmp
;
4281 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4283 if (bl
->loc_type
!= bp_loc_software_breakpoint
4284 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4287 if ((breakpoint_enabled (bl
->owner
)
4289 && breakpoint_location_address_range_overlap (bl
, aspace
,
4292 if (overlay_debugging
4293 && section_is_overlay (bl
->section
)
4294 && !section_is_mapped (bl
->section
))
4296 /* Unmapped overlay -- can't be a match. */
4307 /* Return true if there's a moribund breakpoint at PC. */
4310 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4312 struct bp_location
*loc
;
4315 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4316 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4322 /* Returns non-zero iff BL is inserted at PC, in address space
4326 bp_location_inserted_here_p (struct bp_location
*bl
,
4327 struct address_space
*aspace
, CORE_ADDR pc
)
4330 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4333 if (overlay_debugging
4334 && section_is_overlay (bl
->section
)
4335 && !section_is_mapped (bl
->section
))
4336 return 0; /* unmapped overlay -- can't be a match */
4343 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4346 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4348 struct bp_location
**blp
, **blp_tmp
= NULL
;
4350 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4352 struct bp_location
*bl
= *blp
;
4354 if (bl
->loc_type
!= bp_loc_software_breakpoint
4355 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4358 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4364 /* This function returns non-zero iff there is a software breakpoint
4368 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4371 struct bp_location
**blp
, **blp_tmp
= NULL
;
4373 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4375 struct bp_location
*bl
= *blp
;
4377 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4380 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4387 /* See breakpoint.h. */
4390 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4393 struct bp_location
**blp
, **blp_tmp
= NULL
;
4395 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4397 struct bp_location
*bl
= *blp
;
4399 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4402 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4410 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4411 CORE_ADDR addr
, ULONGEST len
)
4413 struct breakpoint
*bpt
;
4415 ALL_BREAKPOINTS (bpt
)
4417 struct bp_location
*loc
;
4419 if (bpt
->type
!= bp_hardware_watchpoint
4420 && bpt
->type
!= bp_access_watchpoint
)
4423 if (!breakpoint_enabled (bpt
))
4426 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4427 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4431 /* Check for intersection. */
4432 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4433 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4442 /* bpstat stuff. External routines' interfaces are documented
4446 is_catchpoint (struct breakpoint
*ep
)
4448 return (ep
->type
== bp_catchpoint
);
4451 /* Frees any storage that is part of a bpstat. Does not walk the
4455 bpstat_free (bpstat bs
)
4457 if (bs
->old_val
!= NULL
)
4458 value_free (bs
->old_val
);
4459 decref_counted_command_line (&bs
->commands
);
4460 decref_bp_location (&bs
->bp_location_at
);
4464 /* Clear a bpstat so that it says we are not at any breakpoint.
4465 Also free any storage that is part of a bpstat. */
4468 bpstat_clear (bpstat
*bsp
)
4485 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4486 is part of the bpstat is copied as well. */
4489 bpstat_copy (bpstat bs
)
4493 bpstat retval
= NULL
;
4498 for (; bs
!= NULL
; bs
= bs
->next
)
4500 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4501 memcpy (tmp
, bs
, sizeof (*tmp
));
4502 incref_counted_command_line (tmp
->commands
);
4503 incref_bp_location (tmp
->bp_location_at
);
4504 if (bs
->old_val
!= NULL
)
4506 tmp
->old_val
= value_copy (bs
->old_val
);
4507 release_value (tmp
->old_val
);
4511 /* This is the first thing in the chain. */
4521 /* Find the bpstat associated with this breakpoint. */
4524 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4529 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4531 if (bsp
->breakpoint_at
== breakpoint
)
4537 /* See breakpoint.h. */
4540 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4542 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4544 if (bsp
->breakpoint_at
== NULL
)
4546 /* A moribund location can never explain a signal other than
4548 if (sig
== GDB_SIGNAL_TRAP
)
4553 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4562 /* Put in *NUM the breakpoint number of the first breakpoint we are
4563 stopped at. *BSP upon return is a bpstat which points to the
4564 remaining breakpoints stopped at (but which is not guaranteed to be
4565 good for anything but further calls to bpstat_num).
4567 Return 0 if passed a bpstat which does not indicate any breakpoints.
4568 Return -1 if stopped at a breakpoint that has been deleted since
4570 Return 1 otherwise. */
4573 bpstat_num (bpstat
*bsp
, int *num
)
4575 struct breakpoint
*b
;
4578 return 0; /* No more breakpoint values */
4580 /* We assume we'll never have several bpstats that correspond to a
4581 single breakpoint -- otherwise, this function might return the
4582 same number more than once and this will look ugly. */
4583 b
= (*bsp
)->breakpoint_at
;
4584 *bsp
= (*bsp
)->next
;
4586 return -1; /* breakpoint that's been deleted since */
4588 *num
= b
->number
; /* We have its number */
4592 /* See breakpoint.h. */
4595 bpstat_clear_actions (void)
4597 struct thread_info
*tp
;
4600 if (ptid_equal (inferior_ptid
, null_ptid
))
4603 tp
= find_thread_ptid (inferior_ptid
);
4607 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4609 decref_counted_command_line (&bs
->commands
);
4611 if (bs
->old_val
!= NULL
)
4613 value_free (bs
->old_val
);
4619 /* Called when a command is about to proceed the inferior. */
4622 breakpoint_about_to_proceed (void)
4624 if (!ptid_equal (inferior_ptid
, null_ptid
))
4626 struct thread_info
*tp
= inferior_thread ();
4628 /* Allow inferior function calls in breakpoint commands to not
4629 interrupt the command list. When the call finishes
4630 successfully, the inferior will be standing at the same
4631 breakpoint as if nothing happened. */
4632 if (tp
->control
.in_infcall
)
4636 breakpoint_proceeded
= 1;
4639 /* Stub for cleaning up our state if we error-out of a breakpoint
4642 cleanup_executing_breakpoints (void *ignore
)
4644 executing_breakpoint_commands
= 0;
4647 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4648 or its equivalent. */
4651 command_line_is_silent (struct command_line
*cmd
)
4653 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4656 /* Execute all the commands associated with all the breakpoints at
4657 this location. Any of these commands could cause the process to
4658 proceed beyond this point, etc. We look out for such changes by
4659 checking the global "breakpoint_proceeded" after each command.
4661 Returns true if a breakpoint command resumed the inferior. In that
4662 case, it is the caller's responsibility to recall it again with the
4663 bpstat of the current thread. */
4666 bpstat_do_actions_1 (bpstat
*bsp
)
4669 struct cleanup
*old_chain
;
4672 /* Avoid endless recursion if a `source' command is contained
4674 if (executing_breakpoint_commands
)
4677 executing_breakpoint_commands
= 1;
4678 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4680 scoped_restore preventer
= prevent_dont_repeat ();
4682 /* This pointer will iterate over the list of bpstat's. */
4685 breakpoint_proceeded
= 0;
4686 for (; bs
!= NULL
; bs
= bs
->next
)
4688 struct counted_command_line
*ccmd
;
4689 struct command_line
*cmd
;
4690 struct cleanup
*this_cmd_tree_chain
;
4692 /* Take ownership of the BSP's command tree, if it has one.
4694 The command tree could legitimately contain commands like
4695 'step' and 'next', which call clear_proceed_status, which
4696 frees stop_bpstat's command tree. To make sure this doesn't
4697 free the tree we're executing out from under us, we need to
4698 take ownership of the tree ourselves. Since a given bpstat's
4699 commands are only executed once, we don't need to copy it; we
4700 can clear the pointer in the bpstat, and make sure we free
4701 the tree when we're done. */
4702 ccmd
= bs
->commands
;
4703 bs
->commands
= NULL
;
4704 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4705 cmd
= ccmd
? ccmd
->commands
: NULL
;
4706 if (command_line_is_silent (cmd
))
4708 /* The action has been already done by bpstat_stop_status. */
4714 execute_control_command (cmd
);
4716 if (breakpoint_proceeded
)
4722 /* We can free this command tree now. */
4723 do_cleanups (this_cmd_tree_chain
);
4725 if (breakpoint_proceeded
)
4727 if (current_ui
->async
)
4728 /* If we are in async mode, then the target might be still
4729 running, not stopped at any breakpoint, so nothing for
4730 us to do here -- just return to the event loop. */
4733 /* In sync mode, when execute_control_command returns
4734 we're already standing on the next breakpoint.
4735 Breakpoint commands for that stop were not run, since
4736 execute_command does not run breakpoint commands --
4737 only command_line_handler does, but that one is not
4738 involved in execution of breakpoint commands. So, we
4739 can now execute breakpoint commands. It should be
4740 noted that making execute_command do bpstat actions is
4741 not an option -- in this case we'll have recursive
4742 invocation of bpstat for each breakpoint with a
4743 command, and can easily blow up GDB stack. Instead, we
4744 return true, which will trigger the caller to recall us
4745 with the new stop_bpstat. */
4750 do_cleanups (old_chain
);
4755 bpstat_do_actions (void)
4757 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4759 /* Do any commands attached to breakpoint we are stopped at. */
4760 while (!ptid_equal (inferior_ptid
, null_ptid
)
4761 && target_has_execution
4762 && !is_exited (inferior_ptid
)
4763 && !is_executing (inferior_ptid
))
4764 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4765 and only return when it is stopped at the next breakpoint, we
4766 keep doing breakpoint actions until it returns false to
4767 indicate the inferior was not resumed. */
4768 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4771 discard_cleanups (cleanup_if_error
);
4774 /* Print out the (old or new) value associated with a watchpoint. */
4777 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4780 fprintf_unfiltered (stream
, _("<unreadable>"));
4783 struct value_print_options opts
;
4784 get_user_print_options (&opts
);
4785 value_print (val
, stream
, &opts
);
4789 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4790 debugging multiple threads. */
4793 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4795 if (uiout
->is_mi_like_p ())
4800 if (show_thread_that_caused_stop ())
4803 struct thread_info
*thr
= inferior_thread ();
4805 uiout
->text ("Thread ");
4806 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4808 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4811 uiout
->text (" \"");
4812 uiout
->field_fmt ("name", "%s", name
);
4816 uiout
->text (" hit ");
4820 /* Generic routine for printing messages indicating why we
4821 stopped. The behavior of this function depends on the value
4822 'print_it' in the bpstat structure. Under some circumstances we
4823 may decide not to print anything here and delegate the task to
4826 static enum print_stop_action
4827 print_bp_stop_message (bpstat bs
)
4829 switch (bs
->print_it
)
4832 /* Nothing should be printed for this bpstat entry. */
4833 return PRINT_UNKNOWN
;
4837 /* We still want to print the frame, but we already printed the
4838 relevant messages. */
4839 return PRINT_SRC_AND_LOC
;
4842 case print_it_normal
:
4844 struct breakpoint
*b
= bs
->breakpoint_at
;
4846 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4847 which has since been deleted. */
4849 return PRINT_UNKNOWN
;
4851 /* Normal case. Call the breakpoint's print_it method. */
4852 return b
->ops
->print_it (bs
);
4857 internal_error (__FILE__
, __LINE__
,
4858 _("print_bp_stop_message: unrecognized enum value"));
4863 /* A helper function that prints a shared library stopped event. */
4866 print_solib_event (int is_catchpoint
)
4869 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4871 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4875 if (any_added
|| any_deleted
)
4876 current_uiout
->text (_("Stopped due to shared library event:\n"));
4878 current_uiout
->text (_("Stopped due to shared library event (no "
4879 "libraries added or removed)\n"));
4882 if (current_uiout
->is_mi_like_p ())
4883 current_uiout
->field_string ("reason",
4884 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4888 struct cleanup
*cleanup
;
4892 current_uiout
->text (_(" Inferior unloaded "));
4893 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4896 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4901 current_uiout
->text (" ");
4902 current_uiout
->field_string ("library", name
);
4903 current_uiout
->text ("\n");
4906 do_cleanups (cleanup
);
4911 struct so_list
*iter
;
4913 struct cleanup
*cleanup
;
4915 current_uiout
->text (_(" Inferior loaded "));
4916 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4919 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4924 current_uiout
->text (" ");
4925 current_uiout
->field_string ("library", iter
->so_name
);
4926 current_uiout
->text ("\n");
4929 do_cleanups (cleanup
);
4933 /* Print a message indicating what happened. This is called from
4934 normal_stop(). The input to this routine is the head of the bpstat
4935 list - a list of the eventpoints that caused this stop. KIND is
4936 the target_waitkind for the stopping event. This
4937 routine calls the generic print routine for printing a message
4938 about reasons for stopping. This will print (for example) the
4939 "Breakpoint n," part of the output. The return value of this
4942 PRINT_UNKNOWN: Means we printed nothing.
4943 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4944 code to print the location. An example is
4945 "Breakpoint 1, " which should be followed by
4947 PRINT_SRC_ONLY: Means we printed something, but there is no need
4948 to also print the location part of the message.
4949 An example is the catch/throw messages, which
4950 don't require a location appended to the end.
4951 PRINT_NOTHING: We have done some printing and we don't need any
4952 further info to be printed. */
4954 enum print_stop_action
4955 bpstat_print (bpstat bs
, int kind
)
4957 enum print_stop_action val
;
4959 /* Maybe another breakpoint in the chain caused us to stop.
4960 (Currently all watchpoints go on the bpstat whether hit or not.
4961 That probably could (should) be changed, provided care is taken
4962 with respect to bpstat_explains_signal). */
4963 for (; bs
; bs
= bs
->next
)
4965 val
= print_bp_stop_message (bs
);
4966 if (val
== PRINT_SRC_ONLY
4967 || val
== PRINT_SRC_AND_LOC
4968 || val
== PRINT_NOTHING
)
4972 /* If we had hit a shared library event breakpoint,
4973 print_bp_stop_message would print out this message. If we hit an
4974 OS-level shared library event, do the same thing. */
4975 if (kind
== TARGET_WAITKIND_LOADED
)
4977 print_solib_event (0);
4978 return PRINT_NOTHING
;
4981 /* We reached the end of the chain, or we got a null BS to start
4982 with and nothing was printed. */
4983 return PRINT_UNKNOWN
;
4986 /* Evaluate the expression EXP and return 1 if value is zero.
4987 This returns the inverse of the condition because it is called
4988 from catch_errors which returns 0 if an exception happened, and if an
4989 exception happens we want execution to stop.
4990 The argument is a "struct expression *" that has been cast to a
4991 "void *" to make it pass through catch_errors. */
4994 breakpoint_cond_eval (void *exp
)
4996 struct value
*mark
= value_mark ();
4997 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4999 value_free_to_mark (mark
);
5003 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5006 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5010 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5012 **bs_link_pointer
= bs
;
5013 *bs_link_pointer
= &bs
->next
;
5014 bs
->breakpoint_at
= bl
->owner
;
5015 bs
->bp_location_at
= bl
;
5016 incref_bp_location (bl
);
5017 /* If the condition is false, etc., don't do the commands. */
5018 bs
->commands
= NULL
;
5020 bs
->print_it
= print_it_normal
;
5024 /* The target has stopped with waitstatus WS. Check if any hardware
5025 watchpoints have triggered, according to the target. */
5028 watchpoints_triggered (struct target_waitstatus
*ws
)
5030 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5032 struct breakpoint
*b
;
5034 if (!stopped_by_watchpoint
)
5036 /* We were not stopped by a watchpoint. Mark all watchpoints
5037 as not triggered. */
5039 if (is_hardware_watchpoint (b
))
5041 struct watchpoint
*w
= (struct watchpoint
*) b
;
5043 w
->watchpoint_triggered
= watch_triggered_no
;
5049 if (!target_stopped_data_address (¤t_target
, &addr
))
5051 /* We were stopped by a watchpoint, but we don't know where.
5052 Mark all watchpoints as unknown. */
5054 if (is_hardware_watchpoint (b
))
5056 struct watchpoint
*w
= (struct watchpoint
*) b
;
5058 w
->watchpoint_triggered
= watch_triggered_unknown
;
5064 /* The target could report the data address. Mark watchpoints
5065 affected by this data address as triggered, and all others as not
5069 if (is_hardware_watchpoint (b
))
5071 struct watchpoint
*w
= (struct watchpoint
*) b
;
5072 struct bp_location
*loc
;
5074 w
->watchpoint_triggered
= watch_triggered_no
;
5075 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5077 if (is_masked_watchpoint (b
))
5079 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5080 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5082 if (newaddr
== start
)
5084 w
->watchpoint_triggered
= watch_triggered_yes
;
5088 /* Exact match not required. Within range is sufficient. */
5089 else if (target_watchpoint_addr_within_range (¤t_target
,
5093 w
->watchpoint_triggered
= watch_triggered_yes
;
5102 /* Possible return values for watchpoint_check (this can't be an enum
5103 because of check_errors). */
5104 /* The watchpoint has been deleted. */
5105 #define WP_DELETED 1
5106 /* The value has changed. */
5107 #define WP_VALUE_CHANGED 2
5108 /* The value has not changed. */
5109 #define WP_VALUE_NOT_CHANGED 3
5110 /* Ignore this watchpoint, no matter if the value changed or not. */
5113 #define BP_TEMPFLAG 1
5114 #define BP_HARDWAREFLAG 2
5116 /* Evaluate watchpoint condition expression and check if its value
5119 P should be a pointer to struct bpstat, but is defined as a void *
5120 in order for this function to be usable with catch_errors. */
5123 watchpoint_check (void *p
)
5125 bpstat bs
= (bpstat
) p
;
5126 struct watchpoint
*b
;
5127 struct frame_info
*fr
;
5128 int within_current_scope
;
5130 /* BS is built from an existing struct breakpoint. */
5131 gdb_assert (bs
->breakpoint_at
!= NULL
);
5132 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5134 /* If this is a local watchpoint, we only want to check if the
5135 watchpoint frame is in scope if the current thread is the thread
5136 that was used to create the watchpoint. */
5137 if (!watchpoint_in_thread_scope (b
))
5140 if (b
->exp_valid_block
== NULL
)
5141 within_current_scope
= 1;
5144 struct frame_info
*frame
= get_current_frame ();
5145 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5146 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5148 /* stack_frame_destroyed_p() returns a non-zero value if we're
5149 still in the function but the stack frame has already been
5150 invalidated. Since we can't rely on the values of local
5151 variables after the stack has been destroyed, we are treating
5152 the watchpoint in that state as `not changed' without further
5153 checking. Don't mark watchpoints as changed if the current
5154 frame is in an epilogue - even if they are in some other
5155 frame, our view of the stack is likely to be wrong and
5156 frame_find_by_id could error out. */
5157 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5160 fr
= frame_find_by_id (b
->watchpoint_frame
);
5161 within_current_scope
= (fr
!= NULL
);
5163 /* If we've gotten confused in the unwinder, we might have
5164 returned a frame that can't describe this variable. */
5165 if (within_current_scope
)
5167 struct symbol
*function
;
5169 function
= get_frame_function (fr
);
5170 if (function
== NULL
5171 || !contained_in (b
->exp_valid_block
,
5172 SYMBOL_BLOCK_VALUE (function
)))
5173 within_current_scope
= 0;
5176 if (within_current_scope
)
5177 /* If we end up stopping, the current frame will get selected
5178 in normal_stop. So this call to select_frame won't affect
5183 if (within_current_scope
)
5185 /* We use value_{,free_to_}mark because it could be a *long*
5186 time before we return to the command level and call
5187 free_all_values. We can't call free_all_values because we
5188 might be in the middle of evaluating a function call. */
5192 struct value
*new_val
;
5194 if (is_masked_watchpoint (&b
->base
))
5195 /* Since we don't know the exact trigger address (from
5196 stopped_data_address), just tell the user we've triggered
5197 a mask watchpoint. */
5198 return WP_VALUE_CHANGED
;
5200 mark
= value_mark ();
5201 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5203 if (b
->val_bitsize
!= 0)
5204 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5206 /* We use value_equal_contents instead of value_equal because
5207 the latter coerces an array to a pointer, thus comparing just
5208 the address of the array instead of its contents. This is
5209 not what we want. */
5210 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5211 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5213 if (new_val
!= NULL
)
5215 release_value (new_val
);
5216 value_free_to_mark (mark
);
5218 bs
->old_val
= b
->val
;
5221 return WP_VALUE_CHANGED
;
5225 /* Nothing changed. */
5226 value_free_to_mark (mark
);
5227 return WP_VALUE_NOT_CHANGED
;
5232 /* This seems like the only logical thing to do because
5233 if we temporarily ignored the watchpoint, then when
5234 we reenter the block in which it is valid it contains
5235 garbage (in the case of a function, it may have two
5236 garbage values, one before and one after the prologue).
5237 So we can't even detect the first assignment to it and
5238 watch after that (since the garbage may or may not equal
5239 the first value assigned). */
5240 /* We print all the stop information in
5241 breakpoint_ops->print_it, but in this case, by the time we
5242 call breakpoint_ops->print_it this bp will be deleted
5243 already. So we have no choice but print the information
5246 SWITCH_THRU_ALL_UIS ()
5248 struct ui_out
*uiout
= current_uiout
;
5250 if (uiout
->is_mi_like_p ())
5252 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5253 uiout
->text ("\nWatchpoint ");
5254 uiout
->field_int ("wpnum", b
->base
.number
);
5255 uiout
->text (" deleted because the program has left the block in\n"
5256 "which its expression is valid.\n");
5259 /* Make sure the watchpoint's commands aren't executed. */
5260 decref_counted_command_line (&b
->base
.commands
);
5261 watchpoint_del_at_next_stop (b
);
5267 /* Return true if it looks like target has stopped due to hitting
5268 breakpoint location BL. This function does not check if we should
5269 stop, only if BL explains the stop. */
5272 bpstat_check_location (const struct bp_location
*bl
,
5273 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5274 const struct target_waitstatus
*ws
)
5276 struct breakpoint
*b
= bl
->owner
;
5278 /* BL is from an existing breakpoint. */
5279 gdb_assert (b
!= NULL
);
5281 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5284 /* Determine if the watched values have actually changed, and we
5285 should stop. If not, set BS->stop to 0. */
5288 bpstat_check_watchpoint (bpstat bs
)
5290 const struct bp_location
*bl
;
5291 struct watchpoint
*b
;
5293 /* BS is built for existing struct breakpoint. */
5294 bl
= bs
->bp_location_at
;
5295 gdb_assert (bl
!= NULL
);
5296 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5297 gdb_assert (b
!= NULL
);
5300 int must_check_value
= 0;
5302 if (b
->base
.type
== bp_watchpoint
)
5303 /* For a software watchpoint, we must always check the
5305 must_check_value
= 1;
5306 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5307 /* We have a hardware watchpoint (read, write, or access)
5308 and the target earlier reported an address watched by
5310 must_check_value
= 1;
5311 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5312 && b
->base
.type
== bp_hardware_watchpoint
)
5313 /* We were stopped by a hardware watchpoint, but the target could
5314 not report the data address. We must check the watchpoint's
5315 value. Access and read watchpoints are out of luck; without
5316 a data address, we can't figure it out. */
5317 must_check_value
= 1;
5319 if (must_check_value
)
5322 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5324 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5325 int e
= catch_errors (watchpoint_check
, bs
, message
,
5327 do_cleanups (cleanups
);
5331 /* We've already printed what needs to be printed. */
5332 bs
->print_it
= print_it_done
;
5336 bs
->print_it
= print_it_noop
;
5339 case WP_VALUE_CHANGED
:
5340 if (b
->base
.type
== bp_read_watchpoint
)
5342 /* There are two cases to consider here:
5344 1. We're watching the triggered memory for reads.
5345 In that case, trust the target, and always report
5346 the watchpoint hit to the user. Even though
5347 reads don't cause value changes, the value may
5348 have changed since the last time it was read, and
5349 since we're not trapping writes, we will not see
5350 those, and as such we should ignore our notion of
5353 2. We're watching the triggered memory for both
5354 reads and writes. There are two ways this may
5357 2.1. This is a target that can't break on data
5358 reads only, but can break on accesses (reads or
5359 writes), such as e.g., x86. We detect this case
5360 at the time we try to insert read watchpoints.
5362 2.2. Otherwise, the target supports read
5363 watchpoints, but, the user set an access or write
5364 watchpoint watching the same memory as this read
5367 If we're watching memory writes as well as reads,
5368 ignore watchpoint hits when we find that the
5369 value hasn't changed, as reads don't cause
5370 changes. This still gives false positives when
5371 the program writes the same value to memory as
5372 what there was already in memory (we will confuse
5373 it for a read), but it's much better than
5376 int other_write_watchpoint
= 0;
5378 if (bl
->watchpoint_type
== hw_read
)
5380 struct breakpoint
*other_b
;
5382 ALL_BREAKPOINTS (other_b
)
5383 if (other_b
->type
== bp_hardware_watchpoint
5384 || other_b
->type
== bp_access_watchpoint
)
5386 struct watchpoint
*other_w
=
5387 (struct watchpoint
*) other_b
;
5389 if (other_w
->watchpoint_triggered
5390 == watch_triggered_yes
)
5392 other_write_watchpoint
= 1;
5398 if (other_write_watchpoint
5399 || bl
->watchpoint_type
== hw_access
)
5401 /* We're watching the same memory for writes,
5402 and the value changed since the last time we
5403 updated it, so this trap must be for a write.
5405 bs
->print_it
= print_it_noop
;
5410 case WP_VALUE_NOT_CHANGED
:
5411 if (b
->base
.type
== bp_hardware_watchpoint
5412 || b
->base
.type
== bp_watchpoint
)
5414 /* Don't stop: write watchpoints shouldn't fire if
5415 the value hasn't changed. */
5416 bs
->print_it
= print_it_noop
;
5424 /* Error from catch_errors. */
5426 SWITCH_THRU_ALL_UIS ()
5428 printf_filtered (_("Watchpoint %d deleted.\n"),
5431 watchpoint_del_at_next_stop (b
);
5432 /* We've already printed what needs to be printed. */
5433 bs
->print_it
= print_it_done
;
5438 else /* must_check_value == 0 */
5440 /* This is a case where some watchpoint(s) triggered, but
5441 not at the address of this watchpoint, or else no
5442 watchpoint triggered after all. So don't print
5443 anything for this watchpoint. */
5444 bs
->print_it
= print_it_noop
;
5450 /* For breakpoints that are currently marked as telling gdb to stop,
5451 check conditions (condition proper, frame, thread and ignore count)
5452 of breakpoint referred to by BS. If we should not stop for this
5453 breakpoint, set BS->stop to 0. */
5456 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5458 const struct bp_location
*bl
;
5459 struct breakpoint
*b
;
5460 int value_is_zero
= 0;
5461 struct expression
*cond
;
5463 gdb_assert (bs
->stop
);
5465 /* BS is built for existing struct breakpoint. */
5466 bl
= bs
->bp_location_at
;
5467 gdb_assert (bl
!= NULL
);
5468 b
= bs
->breakpoint_at
;
5469 gdb_assert (b
!= NULL
);
5471 /* Even if the target evaluated the condition on its end and notified GDB, we
5472 need to do so again since GDB does not know if we stopped due to a
5473 breakpoint or a single step breakpoint. */
5475 if (frame_id_p (b
->frame_id
)
5476 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5482 /* If this is a thread/task-specific breakpoint, don't waste cpu
5483 evaluating the condition if this isn't the specified
5485 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5486 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5493 /* Evaluate extension language breakpoints that have a "stop" method
5495 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5497 if (is_watchpoint (b
))
5499 struct watchpoint
*w
= (struct watchpoint
*) b
;
5501 cond
= w
->cond_exp
.get ();
5504 cond
= bl
->cond
.get ();
5506 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5508 int within_current_scope
= 1;
5509 struct watchpoint
* w
;
5511 /* We use value_mark and value_free_to_mark because it could
5512 be a long time before we return to the command level and
5513 call free_all_values. We can't call free_all_values
5514 because we might be in the middle of evaluating a
5516 struct value
*mark
= value_mark ();
5518 if (is_watchpoint (b
))
5519 w
= (struct watchpoint
*) b
;
5523 /* Need to select the frame, with all that implies so that
5524 the conditions will have the right context. Because we
5525 use the frame, we will not see an inlined function's
5526 variables when we arrive at a breakpoint at the start
5527 of the inlined function; the current frame will be the
5529 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5530 select_frame (get_current_frame ());
5533 struct frame_info
*frame
;
5535 /* For local watchpoint expressions, which particular
5536 instance of a local is being watched matters, so we
5537 keep track of the frame to evaluate the expression
5538 in. To evaluate the condition however, it doesn't
5539 really matter which instantiation of the function
5540 where the condition makes sense triggers the
5541 watchpoint. This allows an expression like "watch
5542 global if q > 10" set in `func', catch writes to
5543 global on all threads that call `func', or catch
5544 writes on all recursive calls of `func' by a single
5545 thread. We simply always evaluate the condition in
5546 the innermost frame that's executing where it makes
5547 sense to evaluate the condition. It seems
5549 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5551 select_frame (frame
);
5553 within_current_scope
= 0;
5555 if (within_current_scope
)
5557 = catch_errors (breakpoint_cond_eval
, cond
,
5558 "Error in testing breakpoint condition:\n",
5562 warning (_("Watchpoint condition cannot be tested "
5563 "in the current scope"));
5564 /* If we failed to set the right context for this
5565 watchpoint, unconditionally report it. */
5568 /* FIXME-someday, should give breakpoint #. */
5569 value_free_to_mark (mark
);
5572 if (cond
&& value_is_zero
)
5576 else if (b
->ignore_count
> 0)
5580 /* Increase the hit count even though we don't stop. */
5582 observer_notify_breakpoint_modified (b
);
5586 /* Returns true if we need to track moribund locations of LOC's type
5587 on the current target. */
5590 need_moribund_for_location_type (struct bp_location
*loc
)
5592 return ((loc
->loc_type
== bp_loc_software_breakpoint
5593 && !target_supports_stopped_by_sw_breakpoint ())
5594 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5595 && !target_supports_stopped_by_hw_breakpoint ()));
5599 /* Get a bpstat associated with having just stopped at address
5600 BP_ADDR in thread PTID.
5602 Determine whether we stopped at a breakpoint, etc, or whether we
5603 don't understand this stop. Result is a chain of bpstat's such
5606 if we don't understand the stop, the result is a null pointer.
5608 if we understand why we stopped, the result is not null.
5610 Each element of the chain refers to a particular breakpoint or
5611 watchpoint at which we have stopped. (We may have stopped for
5612 several reasons concurrently.)
5614 Each element of the chain has valid next, breakpoint_at,
5615 commands, FIXME??? fields. */
5618 bpstat_stop_status (struct address_space
*aspace
,
5619 CORE_ADDR bp_addr
, ptid_t ptid
,
5620 const struct target_waitstatus
*ws
)
5622 struct breakpoint
*b
= NULL
;
5623 struct bp_location
*bl
;
5624 struct bp_location
*loc
;
5625 /* First item of allocated bpstat's. */
5626 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5627 /* Pointer to the last thing in the chain currently. */
5630 int need_remove_insert
;
5633 /* First, build the bpstat chain with locations that explain a
5634 target stop, while being careful to not set the target running,
5635 as that may invalidate locations (in particular watchpoint
5636 locations are recreated). Resuming will happen here with
5637 breakpoint conditions or watchpoint expressions that include
5638 inferior function calls. */
5642 if (!breakpoint_enabled (b
))
5645 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5647 /* For hardware watchpoints, we look only at the first
5648 location. The watchpoint_check function will work on the
5649 entire expression, not the individual locations. For
5650 read watchpoints, the watchpoints_triggered function has
5651 checked all locations already. */
5652 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5655 if (!bl
->enabled
|| bl
->shlib_disabled
)
5658 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5661 /* Come here if it's a watchpoint, or if the break address
5664 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5667 /* Assume we stop. Should we find a watchpoint that is not
5668 actually triggered, or if the condition of the breakpoint
5669 evaluates as false, we'll reset 'stop' to 0. */
5673 /* If this is a scope breakpoint, mark the associated
5674 watchpoint as triggered so that we will handle the
5675 out-of-scope event. We'll get to the watchpoint next
5677 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5679 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5681 w
->watchpoint_triggered
= watch_triggered_yes
;
5686 /* Check if a moribund breakpoint explains the stop. */
5687 if (!target_supports_stopped_by_sw_breakpoint ()
5688 || !target_supports_stopped_by_hw_breakpoint ())
5690 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5692 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5693 && need_moribund_for_location_type (loc
))
5695 bs
= bpstat_alloc (loc
, &bs_link
);
5696 /* For hits of moribund locations, we should just proceed. */
5699 bs
->print_it
= print_it_noop
;
5704 /* A bit of special processing for shlib breakpoints. We need to
5705 process solib loading here, so that the lists of loaded and
5706 unloaded libraries are correct before we handle "catch load" and
5708 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5710 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5712 handle_solib_event ();
5717 /* Now go through the locations that caused the target to stop, and
5718 check whether we're interested in reporting this stop to higher
5719 layers, or whether we should resume the target transparently. */
5723 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5728 b
= bs
->breakpoint_at
;
5729 b
->ops
->check_status (bs
);
5732 bpstat_check_breakpoint_conditions (bs
, ptid
);
5737 observer_notify_breakpoint_modified (b
);
5739 /* We will stop here. */
5740 if (b
->disposition
== disp_disable
)
5742 --(b
->enable_count
);
5743 if (b
->enable_count
<= 0)
5744 b
->enable_state
= bp_disabled
;
5749 bs
->commands
= b
->commands
;
5750 incref_counted_command_line (bs
->commands
);
5751 if (command_line_is_silent (bs
->commands
5752 ? bs
->commands
->commands
: NULL
))
5755 b
->ops
->after_condition_true (bs
);
5760 /* Print nothing for this entry if we don't stop or don't
5762 if (!bs
->stop
|| !bs
->print
)
5763 bs
->print_it
= print_it_noop
;
5766 /* If we aren't stopping, the value of some hardware watchpoint may
5767 not have changed, but the intermediate memory locations we are
5768 watching may have. Don't bother if we're stopping; this will get
5770 need_remove_insert
= 0;
5771 if (! bpstat_causes_stop (bs_head
))
5772 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5774 && bs
->breakpoint_at
5775 && is_hardware_watchpoint (bs
->breakpoint_at
))
5777 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5779 update_watchpoint (w
, 0 /* don't reparse. */);
5780 need_remove_insert
= 1;
5783 if (need_remove_insert
)
5784 update_global_location_list (UGLL_MAY_INSERT
);
5785 else if (removed_any
)
5786 update_global_location_list (UGLL_DONT_INSERT
);
5792 handle_jit_event (void)
5794 struct frame_info
*frame
;
5795 struct gdbarch
*gdbarch
;
5798 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5800 /* Switch terminal for any messages produced by
5801 breakpoint_re_set. */
5802 target_terminal_ours_for_output ();
5804 frame
= get_current_frame ();
5805 gdbarch
= get_frame_arch (frame
);
5807 jit_event_handler (gdbarch
);
5809 target_terminal_inferior ();
5812 /* Prepare WHAT final decision for infrun. */
5814 /* Decide what infrun needs to do with this bpstat. */
5817 bpstat_what (bpstat bs_head
)
5819 struct bpstat_what retval
;
5822 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5823 retval
.call_dummy
= STOP_NONE
;
5824 retval
.is_longjmp
= 0;
5826 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5828 /* Extract this BS's action. After processing each BS, we check
5829 if its action overrides all we've seem so far. */
5830 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5833 if (bs
->breakpoint_at
== NULL
)
5835 /* I suspect this can happen if it was a momentary
5836 breakpoint which has since been deleted. */
5840 bptype
= bs
->breakpoint_at
->type
;
5847 case bp_hardware_breakpoint
:
5848 case bp_single_step
:
5851 case bp_shlib_event
:
5855 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5857 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5860 this_action
= BPSTAT_WHAT_SINGLE
;
5863 case bp_hardware_watchpoint
:
5864 case bp_read_watchpoint
:
5865 case bp_access_watchpoint
:
5869 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5871 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5875 /* There was a watchpoint, but we're not stopping.
5876 This requires no further action. */
5880 case bp_longjmp_call_dummy
:
5884 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5885 retval
.is_longjmp
= bptype
!= bp_exception
;
5888 this_action
= BPSTAT_WHAT_SINGLE
;
5890 case bp_longjmp_resume
:
5891 case bp_exception_resume
:
5894 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5895 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5898 this_action
= BPSTAT_WHAT_SINGLE
;
5900 case bp_step_resume
:
5902 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5905 /* It is for the wrong frame. */
5906 this_action
= BPSTAT_WHAT_SINGLE
;
5909 case bp_hp_step_resume
:
5911 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5914 /* It is for the wrong frame. */
5915 this_action
= BPSTAT_WHAT_SINGLE
;
5918 case bp_watchpoint_scope
:
5919 case bp_thread_event
:
5920 case bp_overlay_event
:
5921 case bp_longjmp_master
:
5922 case bp_std_terminate_master
:
5923 case bp_exception_master
:
5924 this_action
= BPSTAT_WHAT_SINGLE
;
5930 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5932 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5936 /* There was a catchpoint, but we're not stopping.
5937 This requires no further action. */
5941 this_action
= BPSTAT_WHAT_SINGLE
;
5944 /* Make sure the action is stop (silent or noisy),
5945 so infrun.c pops the dummy frame. */
5946 retval
.call_dummy
= STOP_STACK_DUMMY
;
5947 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5949 case bp_std_terminate
:
5950 /* Make sure the action is stop (silent or noisy),
5951 so infrun.c pops the dummy frame. */
5952 retval
.call_dummy
= STOP_STD_TERMINATE
;
5953 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5956 case bp_fast_tracepoint
:
5957 case bp_static_tracepoint
:
5958 /* Tracepoint hits should not be reported back to GDB, and
5959 if one got through somehow, it should have been filtered
5961 internal_error (__FILE__
, __LINE__
,
5962 _("bpstat_what: tracepoint encountered"));
5964 case bp_gnu_ifunc_resolver
:
5965 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5966 this_action
= BPSTAT_WHAT_SINGLE
;
5968 case bp_gnu_ifunc_resolver_return
:
5969 /* The breakpoint will be removed, execution will restart from the
5970 PC of the former breakpoint. */
5971 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5976 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5978 this_action
= BPSTAT_WHAT_SINGLE
;
5982 internal_error (__FILE__
, __LINE__
,
5983 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5986 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5993 bpstat_run_callbacks (bpstat bs_head
)
5997 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5999 struct breakpoint
*b
= bs
->breakpoint_at
;
6006 handle_jit_event ();
6008 case bp_gnu_ifunc_resolver
:
6009 gnu_ifunc_resolver_stop (b
);
6011 case bp_gnu_ifunc_resolver_return
:
6012 gnu_ifunc_resolver_return_stop (b
);
6018 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6019 without hardware support). This isn't related to a specific bpstat,
6020 just to things like whether watchpoints are set. */
6023 bpstat_should_step (void)
6025 struct breakpoint
*b
;
6028 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6034 bpstat_causes_stop (bpstat bs
)
6036 for (; bs
!= NULL
; bs
= bs
->next
)
6045 /* Compute a string of spaces suitable to indent the next line
6046 so it starts at the position corresponding to the table column
6047 named COL_NAME in the currently active table of UIOUT. */
6050 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6052 static char wrap_indent
[80];
6053 int i
, total_width
, width
, align
;
6057 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6059 if (strcmp (text
, col_name
) == 0)
6061 gdb_assert (total_width
< sizeof wrap_indent
);
6062 memset (wrap_indent
, ' ', total_width
);
6063 wrap_indent
[total_width
] = 0;
6068 total_width
+= width
+ 1;
6074 /* Determine if the locations of this breakpoint will have their conditions
6075 evaluated by the target, host or a mix of both. Returns the following:
6077 "host": Host evals condition.
6078 "host or target": Host or Target evals condition.
6079 "target": Target evals condition.
6083 bp_condition_evaluator (struct breakpoint
*b
)
6085 struct bp_location
*bl
;
6086 char host_evals
= 0;
6087 char target_evals
= 0;
6092 if (!is_breakpoint (b
))
6095 if (gdb_evaluates_breakpoint_condition_p ()
6096 || !target_supports_evaluation_of_breakpoint_conditions ())
6097 return condition_evaluation_host
;
6099 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6101 if (bl
->cond_bytecode
)
6107 if (host_evals
&& target_evals
)
6108 return condition_evaluation_both
;
6109 else if (target_evals
)
6110 return condition_evaluation_target
;
6112 return condition_evaluation_host
;
6115 /* Determine the breakpoint location's condition evaluator. This is
6116 similar to bp_condition_evaluator, but for locations. */
6119 bp_location_condition_evaluator (struct bp_location
*bl
)
6121 if (bl
&& !is_breakpoint (bl
->owner
))
6124 if (gdb_evaluates_breakpoint_condition_p ()
6125 || !target_supports_evaluation_of_breakpoint_conditions ())
6126 return condition_evaluation_host
;
6128 if (bl
&& bl
->cond_bytecode
)
6129 return condition_evaluation_target
;
6131 return condition_evaluation_host
;
6134 /* Print the LOC location out of the list of B->LOC locations. */
6137 print_breakpoint_location (struct breakpoint
*b
,
6138 struct bp_location
*loc
)
6140 struct ui_out
*uiout
= current_uiout
;
6141 struct cleanup
*old_chain
= save_current_program_space ();
6143 if (loc
!= NULL
&& loc
->shlib_disabled
)
6147 set_current_program_space (loc
->pspace
);
6149 if (b
->display_canonical
)
6150 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6151 else if (loc
&& loc
->symtab
)
6154 = find_pc_sect_function (loc
->address
, loc
->section
);
6157 uiout
->text ("in ");
6158 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6160 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6161 uiout
->text ("at ");
6163 uiout
->field_string ("file",
6164 symtab_to_filename_for_display (loc
->symtab
));
6167 if (uiout
->is_mi_like_p ())
6168 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6170 uiout
->field_int ("line", loc
->line_number
);
6176 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6178 uiout
->field_stream ("at", stb
);
6182 uiout
->field_string ("pending",
6183 event_location_to_string (b
->location
.get ()));
6184 /* If extra_string is available, it could be holding a condition
6185 or dprintf arguments. In either case, make sure it is printed,
6186 too, but only for non-MI streams. */
6187 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6189 if (b
->type
== bp_dprintf
)
6193 uiout
->text (b
->extra_string
);
6197 if (loc
&& is_breakpoint (b
)
6198 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6199 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6202 uiout
->field_string ("evaluated-by",
6203 bp_location_condition_evaluator (loc
));
6207 do_cleanups (old_chain
);
6211 bptype_string (enum bptype type
)
6213 struct ep_type_description
6216 const char *description
;
6218 static struct ep_type_description bptypes
[] =
6220 {bp_none
, "?deleted?"},
6221 {bp_breakpoint
, "breakpoint"},
6222 {bp_hardware_breakpoint
, "hw breakpoint"},
6223 {bp_single_step
, "sw single-step"},
6224 {bp_until
, "until"},
6225 {bp_finish
, "finish"},
6226 {bp_watchpoint
, "watchpoint"},
6227 {bp_hardware_watchpoint
, "hw watchpoint"},
6228 {bp_read_watchpoint
, "read watchpoint"},
6229 {bp_access_watchpoint
, "acc watchpoint"},
6230 {bp_longjmp
, "longjmp"},
6231 {bp_longjmp_resume
, "longjmp resume"},
6232 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6233 {bp_exception
, "exception"},
6234 {bp_exception_resume
, "exception resume"},
6235 {bp_step_resume
, "step resume"},
6236 {bp_hp_step_resume
, "high-priority step resume"},
6237 {bp_watchpoint_scope
, "watchpoint scope"},
6238 {bp_call_dummy
, "call dummy"},
6239 {bp_std_terminate
, "std::terminate"},
6240 {bp_shlib_event
, "shlib events"},
6241 {bp_thread_event
, "thread events"},
6242 {bp_overlay_event
, "overlay events"},
6243 {bp_longjmp_master
, "longjmp master"},
6244 {bp_std_terminate_master
, "std::terminate master"},
6245 {bp_exception_master
, "exception master"},
6246 {bp_catchpoint
, "catchpoint"},
6247 {bp_tracepoint
, "tracepoint"},
6248 {bp_fast_tracepoint
, "fast tracepoint"},
6249 {bp_static_tracepoint
, "static tracepoint"},
6250 {bp_dprintf
, "dprintf"},
6251 {bp_jit_event
, "jit events"},
6252 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6253 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6256 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6257 || ((int) type
!= bptypes
[(int) type
].type
))
6258 internal_error (__FILE__
, __LINE__
,
6259 _("bptypes table does not describe type #%d."),
6262 return bptypes
[(int) type
].description
;
6265 /* For MI, output a field named 'thread-groups' with a list as the value.
6266 For CLI, prefix the list with the string 'inf'. */
6269 output_thread_groups (struct ui_out
*uiout
,
6270 const char *field_name
,
6274 struct cleanup
*back_to
;
6275 int is_mi
= uiout
->is_mi_like_p ();
6279 /* For backward compatibility, don't display inferiors in CLI unless
6280 there are several. Always display them for MI. */
6281 if (!is_mi
&& mi_only
)
6284 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6286 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6292 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6293 uiout
->field_string (NULL
, mi_group
);
6298 uiout
->text (" inf ");
6302 uiout
->text (plongest (inf
));
6306 do_cleanups (back_to
);
6309 /* Print B to gdb_stdout. */
6312 print_one_breakpoint_location (struct breakpoint
*b
,
6313 struct bp_location
*loc
,
6315 struct bp_location
**last_loc
,
6318 struct command_line
*l
;
6319 static char bpenables
[] = "nynny";
6321 struct ui_out
*uiout
= current_uiout
;
6322 int header_of_multiple
= 0;
6323 int part_of_multiple
= (loc
!= NULL
);
6324 struct value_print_options opts
;
6326 get_user_print_options (&opts
);
6328 gdb_assert (!loc
|| loc_number
!= 0);
6329 /* See comment in print_one_breakpoint concerning treatment of
6330 breakpoints with single disabled location. */
6333 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6334 header_of_multiple
= 1;
6342 if (part_of_multiple
)
6345 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6346 uiout
->field_string ("number", formatted
);
6351 uiout
->field_int ("number", b
->number
);
6356 if (part_of_multiple
)
6357 uiout
->field_skip ("type");
6359 uiout
->field_string ("type", bptype_string (b
->type
));
6363 if (part_of_multiple
)
6364 uiout
->field_skip ("disp");
6366 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6371 if (part_of_multiple
)
6372 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6374 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6379 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6381 /* Although the print_one can possibly print all locations,
6382 calling it here is not likely to get any nice result. So,
6383 make sure there's just one location. */
6384 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6385 b
->ops
->print_one (b
, last_loc
);
6391 internal_error (__FILE__
, __LINE__
,
6392 _("print_one_breakpoint: bp_none encountered\n"));
6396 case bp_hardware_watchpoint
:
6397 case bp_read_watchpoint
:
6398 case bp_access_watchpoint
:
6400 struct watchpoint
*w
= (struct watchpoint
*) b
;
6402 /* Field 4, the address, is omitted (which makes the columns
6403 not line up too nicely with the headers, but the effect
6404 is relatively readable). */
6405 if (opts
.addressprint
)
6406 uiout
->field_skip ("addr");
6408 uiout
->field_string ("what", w
->exp_string
);
6413 case bp_hardware_breakpoint
:
6414 case bp_single_step
:
6418 case bp_longjmp_resume
:
6419 case bp_longjmp_call_dummy
:
6421 case bp_exception_resume
:
6422 case bp_step_resume
:
6423 case bp_hp_step_resume
:
6424 case bp_watchpoint_scope
:
6426 case bp_std_terminate
:
6427 case bp_shlib_event
:
6428 case bp_thread_event
:
6429 case bp_overlay_event
:
6430 case bp_longjmp_master
:
6431 case bp_std_terminate_master
:
6432 case bp_exception_master
:
6434 case bp_fast_tracepoint
:
6435 case bp_static_tracepoint
:
6438 case bp_gnu_ifunc_resolver
:
6439 case bp_gnu_ifunc_resolver_return
:
6440 if (opts
.addressprint
)
6443 if (header_of_multiple
)
6444 uiout
->field_string ("addr", "<MULTIPLE>");
6445 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6446 uiout
->field_string ("addr", "<PENDING>");
6448 uiout
->field_core_addr ("addr",
6449 loc
->gdbarch
, loc
->address
);
6452 if (!header_of_multiple
)
6453 print_breakpoint_location (b
, loc
);
6460 if (loc
!= NULL
&& !header_of_multiple
)
6462 struct inferior
*inf
;
6463 VEC(int) *inf_num
= NULL
;
6468 if (inf
->pspace
== loc
->pspace
)
6469 VEC_safe_push (int, inf_num
, inf
->num
);
6472 /* For backward compatibility, don't display inferiors in CLI unless
6473 there are several. Always display for MI. */
6475 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6476 && (number_of_program_spaces () > 1
6477 || number_of_inferiors () > 1)
6478 /* LOC is for existing B, it cannot be in
6479 moribund_locations and thus having NULL OWNER. */
6480 && loc
->owner
->type
!= bp_catchpoint
))
6482 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6483 VEC_free (int, inf_num
);
6486 if (!part_of_multiple
)
6488 if (b
->thread
!= -1)
6490 /* FIXME: This seems to be redundant and lost here; see the
6491 "stop only in" line a little further down. */
6492 uiout
->text (" thread ");
6493 uiout
->field_int ("thread", b
->thread
);
6495 else if (b
->task
!= 0)
6497 uiout
->text (" task ");
6498 uiout
->field_int ("task", b
->task
);
6504 if (!part_of_multiple
)
6505 b
->ops
->print_one_detail (b
, uiout
);
6507 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6510 uiout
->text ("\tstop only in stack frame at ");
6511 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6513 uiout
->field_core_addr ("frame",
6514 b
->gdbarch
, b
->frame_id
.stack_addr
);
6518 if (!part_of_multiple
&& b
->cond_string
)
6521 if (is_tracepoint (b
))
6522 uiout
->text ("\ttrace only if ");
6524 uiout
->text ("\tstop only if ");
6525 uiout
->field_string ("cond", b
->cond_string
);
6527 /* Print whether the target is doing the breakpoint's condition
6528 evaluation. If GDB is doing the evaluation, don't print anything. */
6529 if (is_breakpoint (b
)
6530 && breakpoint_condition_evaluation_mode ()
6531 == condition_evaluation_target
)
6534 uiout
->field_string ("evaluated-by",
6535 bp_condition_evaluator (b
));
6536 uiout
->text (" evals)");
6541 if (!part_of_multiple
&& b
->thread
!= -1)
6543 /* FIXME should make an annotation for this. */
6544 uiout
->text ("\tstop only in thread ");
6545 if (uiout
->is_mi_like_p ())
6546 uiout
->field_int ("thread", b
->thread
);
6549 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6551 uiout
->field_string ("thread", print_thread_id (thr
));
6556 if (!part_of_multiple
)
6560 /* FIXME should make an annotation for this. */
6561 if (is_catchpoint (b
))
6562 uiout
->text ("\tcatchpoint");
6563 else if (is_tracepoint (b
))
6564 uiout
->text ("\ttracepoint");
6566 uiout
->text ("\tbreakpoint");
6567 uiout
->text (" already hit ");
6568 uiout
->field_int ("times", b
->hit_count
);
6569 if (b
->hit_count
== 1)
6570 uiout
->text (" time\n");
6572 uiout
->text (" times\n");
6576 /* Output the count also if it is zero, but only if this is mi. */
6577 if (uiout
->is_mi_like_p ())
6578 uiout
->field_int ("times", b
->hit_count
);
6582 if (!part_of_multiple
&& b
->ignore_count
)
6585 uiout
->text ("\tignore next ");
6586 uiout
->field_int ("ignore", b
->ignore_count
);
6587 uiout
->text (" hits\n");
6590 /* Note that an enable count of 1 corresponds to "enable once"
6591 behavior, which is reported by the combination of enablement and
6592 disposition, so we don't need to mention it here. */
6593 if (!part_of_multiple
&& b
->enable_count
> 1)
6596 uiout
->text ("\tdisable after ");
6597 /* Tweak the wording to clarify that ignore and enable counts
6598 are distinct, and have additive effect. */
6599 if (b
->ignore_count
)
6600 uiout
->text ("additional ");
6602 uiout
->text ("next ");
6603 uiout
->field_int ("enable", b
->enable_count
);
6604 uiout
->text (" hits\n");
6607 if (!part_of_multiple
&& is_tracepoint (b
))
6609 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6611 if (tp
->traceframe_usage
)
6613 uiout
->text ("\ttrace buffer usage ");
6614 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6615 uiout
->text (" bytes\n");
6619 l
= b
->commands
? b
->commands
->commands
: NULL
;
6620 if (!part_of_multiple
&& l
)
6622 struct cleanup
*script_chain
;
6625 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6626 print_command_lines (uiout
, l
, 4);
6627 do_cleanups (script_chain
);
6630 if (is_tracepoint (b
))
6632 struct tracepoint
*t
= (struct tracepoint
*) b
;
6634 if (!part_of_multiple
&& t
->pass_count
)
6636 annotate_field (10);
6637 uiout
->text ("\tpass count ");
6638 uiout
->field_int ("pass", t
->pass_count
);
6639 uiout
->text (" \n");
6642 /* Don't display it when tracepoint or tracepoint location is
6644 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6646 annotate_field (11);
6648 if (uiout
->is_mi_like_p ())
6649 uiout
->field_string ("installed",
6650 loc
->inserted
? "y" : "n");
6656 uiout
->text ("\tnot ");
6657 uiout
->text ("installed on target\n");
6662 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6664 if (is_watchpoint (b
))
6666 struct watchpoint
*w
= (struct watchpoint
*) b
;
6668 uiout
->field_string ("original-location", w
->exp_string
);
6670 else if (b
->location
!= NULL
6671 && event_location_to_string (b
->location
.get ()) != NULL
)
6672 uiout
->field_string ("original-location",
6673 event_location_to_string (b
->location
.get ()));
6678 print_one_breakpoint (struct breakpoint
*b
,
6679 struct bp_location
**last_loc
,
6682 struct cleanup
*bkpt_chain
;
6683 struct ui_out
*uiout
= current_uiout
;
6685 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6687 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6688 do_cleanups (bkpt_chain
);
6690 /* If this breakpoint has custom print function,
6691 it's already printed. Otherwise, print individual
6692 locations, if any. */
6693 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6695 /* If breakpoint has a single location that is disabled, we
6696 print it as if it had several locations, since otherwise it's
6697 hard to represent "breakpoint enabled, location disabled"
6700 Note that while hardware watchpoints have several locations
6701 internally, that's not a property exposed to user. */
6703 && !is_hardware_watchpoint (b
)
6704 && (b
->loc
->next
|| !b
->loc
->enabled
))
6706 struct bp_location
*loc
;
6709 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6711 struct cleanup
*inner2
=
6712 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6713 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6714 do_cleanups (inner2
);
6721 breakpoint_address_bits (struct breakpoint
*b
)
6723 int print_address_bits
= 0;
6724 struct bp_location
*loc
;
6726 /* Software watchpoints that aren't watching memory don't have an
6727 address to print. */
6728 if (is_no_memory_software_watchpoint (b
))
6731 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6735 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6736 if (addr_bit
> print_address_bits
)
6737 print_address_bits
= addr_bit
;
6740 return print_address_bits
;
6743 struct captured_breakpoint_query_args
6749 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6751 struct captured_breakpoint_query_args
*args
6752 = (struct captured_breakpoint_query_args
*) data
;
6753 struct breakpoint
*b
;
6754 struct bp_location
*dummy_loc
= NULL
;
6758 if (args
->bnum
== b
->number
)
6760 print_one_breakpoint (b
, &dummy_loc
, 0);
6768 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6769 char **error_message
)
6771 struct captured_breakpoint_query_args args
;
6774 /* For the moment we don't trust print_one_breakpoint() to not throw
6776 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6777 error_message
, RETURN_MASK_ALL
) < 0)
6783 /* Return true if this breakpoint was set by the user, false if it is
6784 internal or momentary. */
6787 user_breakpoint_p (struct breakpoint
*b
)
6789 return b
->number
> 0;
6792 /* See breakpoint.h. */
6795 pending_breakpoint_p (struct breakpoint
*b
)
6797 return b
->loc
== NULL
;
6800 /* Print information on user settable breakpoint (watchpoint, etc)
6801 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6802 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6803 FILTER is non-NULL, call it on each breakpoint and only include the
6804 ones for which it returns non-zero. Return the total number of
6805 breakpoints listed. */
6808 breakpoint_1 (char *args
, int allflag
,
6809 int (*filter
) (const struct breakpoint
*))
6811 struct breakpoint
*b
;
6812 struct bp_location
*last_loc
= NULL
;
6813 int nr_printable_breakpoints
;
6814 struct cleanup
*bkpttbl_chain
;
6815 struct value_print_options opts
;
6816 int print_address_bits
= 0;
6817 int print_type_col_width
= 14;
6818 struct ui_out
*uiout
= current_uiout
;
6820 get_user_print_options (&opts
);
6822 /* Compute the number of rows in the table, as well as the size
6823 required for address fields. */
6824 nr_printable_breakpoints
= 0;
6827 /* If we have a filter, only list the breakpoints it accepts. */
6828 if (filter
&& !filter (b
))
6831 /* If we have an "args" string, it is a list of breakpoints to
6832 accept. Skip the others. */
6833 if (args
!= NULL
&& *args
!= '\0')
6835 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6837 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6841 if (allflag
|| user_breakpoint_p (b
))
6843 int addr_bit
, type_len
;
6845 addr_bit
= breakpoint_address_bits (b
);
6846 if (addr_bit
> print_address_bits
)
6847 print_address_bits
= addr_bit
;
6849 type_len
= strlen (bptype_string (b
->type
));
6850 if (type_len
> print_type_col_width
)
6851 print_type_col_width
= type_len
;
6853 nr_printable_breakpoints
++;
6857 if (opts
.addressprint
)
6859 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6860 nr_printable_breakpoints
,
6864 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6865 nr_printable_breakpoints
,
6868 if (nr_printable_breakpoints
> 0)
6869 annotate_breakpoints_headers ();
6870 if (nr_printable_breakpoints
> 0)
6872 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6873 if (nr_printable_breakpoints
> 0)
6875 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6876 if (nr_printable_breakpoints
> 0)
6878 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6879 if (nr_printable_breakpoints
> 0)
6881 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6882 if (opts
.addressprint
)
6884 if (nr_printable_breakpoints
> 0)
6886 if (print_address_bits
<= 32)
6887 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6889 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6891 if (nr_printable_breakpoints
> 0)
6893 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6894 uiout
->table_body ();
6895 if (nr_printable_breakpoints
> 0)
6896 annotate_breakpoints_table ();
6901 /* If we have a filter, only list the breakpoints it accepts. */
6902 if (filter
&& !filter (b
))
6905 /* If we have an "args" string, it is a list of breakpoints to
6906 accept. Skip the others. */
6908 if (args
!= NULL
&& *args
!= '\0')
6910 if (allflag
) /* maintenance info breakpoint */
6912 if (parse_and_eval_long (args
) != b
->number
)
6915 else /* all others */
6917 if (!number_is_in_list (args
, b
->number
))
6921 /* We only print out user settable breakpoints unless the
6923 if (allflag
|| user_breakpoint_p (b
))
6924 print_one_breakpoint (b
, &last_loc
, allflag
);
6927 do_cleanups (bkpttbl_chain
);
6929 if (nr_printable_breakpoints
== 0)
6931 /* If there's a filter, let the caller decide how to report
6935 if (args
== NULL
|| *args
== '\0')
6936 uiout
->message ("No breakpoints or watchpoints.\n");
6938 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6944 if (last_loc
&& !server_command
)
6945 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6948 /* FIXME? Should this be moved up so that it is only called when
6949 there have been breakpoints? */
6950 annotate_breakpoints_table_end ();
6952 return nr_printable_breakpoints
;
6955 /* Display the value of default-collect in a way that is generally
6956 compatible with the breakpoint list. */
6959 default_collect_info (void)
6961 struct ui_out
*uiout
= current_uiout
;
6963 /* If it has no value (which is frequently the case), say nothing; a
6964 message like "No default-collect." gets in user's face when it's
6966 if (!*default_collect
)
6969 /* The following phrase lines up nicely with per-tracepoint collect
6971 uiout
->text ("default collect ");
6972 uiout
->field_string ("default-collect", default_collect
);
6973 uiout
->text (" \n");
6977 breakpoints_info (char *args
, int from_tty
)
6979 breakpoint_1 (args
, 0, NULL
);
6981 default_collect_info ();
6985 watchpoints_info (char *args
, int from_tty
)
6987 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6988 struct ui_out
*uiout
= current_uiout
;
6990 if (num_printed
== 0)
6992 if (args
== NULL
|| *args
== '\0')
6993 uiout
->message ("No watchpoints.\n");
6995 uiout
->message ("No watchpoint matching '%s'.\n", args
);
7000 maintenance_info_breakpoints (char *args
, int from_tty
)
7002 breakpoint_1 (args
, 1, NULL
);
7004 default_collect_info ();
7008 breakpoint_has_pc (struct breakpoint
*b
,
7009 struct program_space
*pspace
,
7010 CORE_ADDR pc
, struct obj_section
*section
)
7012 struct bp_location
*bl
= b
->loc
;
7014 for (; bl
; bl
= bl
->next
)
7016 if (bl
->pspace
== pspace
7017 && bl
->address
== pc
7018 && (!overlay_debugging
|| bl
->section
== section
))
7024 /* Print a message describing any user-breakpoints set at PC. This
7025 concerns with logical breakpoints, so we match program spaces, not
7029 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7030 struct program_space
*pspace
, CORE_ADDR pc
,
7031 struct obj_section
*section
, int thread
)
7034 struct breakpoint
*b
;
7037 others
+= (user_breakpoint_p (b
)
7038 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7042 printf_filtered (_("Note: breakpoint "));
7043 else /* if (others == ???) */
7044 printf_filtered (_("Note: breakpoints "));
7046 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7049 printf_filtered ("%d", b
->number
);
7050 if (b
->thread
== -1 && thread
!= -1)
7051 printf_filtered (" (all threads)");
7052 else if (b
->thread
!= -1)
7053 printf_filtered (" (thread %d)", b
->thread
);
7054 printf_filtered ("%s%s ",
7055 ((b
->enable_state
== bp_disabled
7056 || b
->enable_state
== bp_call_disabled
)
7060 : ((others
== 1) ? " and" : ""));
7062 printf_filtered (_("also set at pc "));
7063 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7064 printf_filtered (".\n");
7069 /* Return true iff it is meaningful to use the address member of
7070 BPT locations. For some breakpoint types, the locations' address members
7071 are irrelevant and it makes no sense to attempt to compare them to other
7072 addresses (or use them for any other purpose either).
7074 More specifically, each of the following breakpoint types will
7075 always have a zero valued location address and we don't want to mark
7076 breakpoints of any of these types to be a duplicate of an actual
7077 breakpoint location at address zero:
7085 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7087 enum bptype type
= bpt
->type
;
7089 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7092 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7093 true if LOC1 and LOC2 represent the same watchpoint location. */
7096 watchpoint_locations_match (struct bp_location
*loc1
,
7097 struct bp_location
*loc2
)
7099 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7100 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7102 /* Both of them must exist. */
7103 gdb_assert (w1
!= NULL
);
7104 gdb_assert (w2
!= NULL
);
7106 /* If the target can evaluate the condition expression in hardware,
7107 then we we need to insert both watchpoints even if they are at
7108 the same place. Otherwise the watchpoint will only trigger when
7109 the condition of whichever watchpoint was inserted evaluates to
7110 true, not giving a chance for GDB to check the condition of the
7111 other watchpoint. */
7113 && target_can_accel_watchpoint_condition (loc1
->address
,
7115 loc1
->watchpoint_type
,
7116 w1
->cond_exp
.get ()))
7118 && target_can_accel_watchpoint_condition (loc2
->address
,
7120 loc2
->watchpoint_type
,
7121 w2
->cond_exp
.get ())))
7124 /* Note that this checks the owner's type, not the location's. In
7125 case the target does not support read watchpoints, but does
7126 support access watchpoints, we'll have bp_read_watchpoint
7127 watchpoints with hw_access locations. Those should be considered
7128 duplicates of hw_read locations. The hw_read locations will
7129 become hw_access locations later. */
7130 return (loc1
->owner
->type
== loc2
->owner
->type
7131 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7132 && loc1
->address
== loc2
->address
7133 && loc1
->length
== loc2
->length
);
7136 /* See breakpoint.h. */
7139 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7140 struct address_space
*aspace2
, CORE_ADDR addr2
)
7142 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7143 || aspace1
== aspace2
)
7147 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7148 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7149 matches ASPACE2. On targets that have global breakpoints, the address
7150 space doesn't really matter. */
7153 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7154 int len1
, struct address_space
*aspace2
,
7157 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7158 || aspace1
== aspace2
)
7159 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7162 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7163 a ranged breakpoint. In most targets, a match happens only if ASPACE
7164 matches the breakpoint's address space. On targets that have global
7165 breakpoints, the address space doesn't really matter. */
7168 breakpoint_location_address_match (struct bp_location
*bl
,
7169 struct address_space
*aspace
,
7172 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7175 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7176 bl
->address
, bl
->length
,
7180 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7181 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7182 match happens only if ASPACE matches the breakpoint's address
7183 space. On targets that have global breakpoints, the address space
7184 doesn't really matter. */
7187 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7188 struct address_space
*aspace
,
7189 CORE_ADDR addr
, int len
)
7191 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7192 || bl
->pspace
->aspace
== aspace
)
7194 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7196 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7202 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7203 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7204 true, otherwise returns false. */
7207 tracepoint_locations_match (struct bp_location
*loc1
,
7208 struct bp_location
*loc2
)
7210 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7211 /* Since tracepoint locations are never duplicated with others', tracepoint
7212 locations at the same address of different tracepoints are regarded as
7213 different locations. */
7214 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7219 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7220 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7221 represent the same location. */
7224 breakpoint_locations_match (struct bp_location
*loc1
,
7225 struct bp_location
*loc2
)
7227 int hw_point1
, hw_point2
;
7229 /* Both of them must not be in moribund_locations. */
7230 gdb_assert (loc1
->owner
!= NULL
);
7231 gdb_assert (loc2
->owner
!= NULL
);
7233 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7234 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7236 if (hw_point1
!= hw_point2
)
7239 return watchpoint_locations_match (loc1
, loc2
);
7240 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7241 return tracepoint_locations_match (loc1
, loc2
);
7243 /* We compare bp_location.length in order to cover ranged breakpoints. */
7244 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7245 loc2
->pspace
->aspace
, loc2
->address
)
7246 && loc1
->length
== loc2
->length
);
7250 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7251 int bnum
, int have_bnum
)
7253 /* The longest string possibly returned by hex_string_custom
7254 is 50 chars. These must be at least that big for safety. */
7258 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7259 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7261 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7262 bnum
, astr1
, astr2
);
7264 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7267 /* Adjust a breakpoint's address to account for architectural
7268 constraints on breakpoint placement. Return the adjusted address.
7269 Note: Very few targets require this kind of adjustment. For most
7270 targets, this function is simply the identity function. */
7273 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7274 CORE_ADDR bpaddr
, enum bptype bptype
)
7276 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7278 /* Very few targets need any kind of breakpoint adjustment. */
7281 else if (bptype
== bp_watchpoint
7282 || bptype
== bp_hardware_watchpoint
7283 || bptype
== bp_read_watchpoint
7284 || bptype
== bp_access_watchpoint
7285 || bptype
== bp_catchpoint
)
7287 /* Watchpoints and the various bp_catch_* eventpoints should not
7288 have their addresses modified. */
7291 else if (bptype
== bp_single_step
)
7293 /* Single-step breakpoints should not have their addresses
7294 modified. If there's any architectural constrain that
7295 applies to this address, then it should have already been
7296 taken into account when the breakpoint was created in the
7297 first place. If we didn't do this, stepping through e.g.,
7298 Thumb-2 IT blocks would break. */
7303 CORE_ADDR adjusted_bpaddr
;
7305 /* Some targets have architectural constraints on the placement
7306 of breakpoint instructions. Obtain the adjusted address. */
7307 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7309 /* An adjusted breakpoint address can significantly alter
7310 a user's expectations. Print a warning if an adjustment
7312 if (adjusted_bpaddr
!= bpaddr
)
7313 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7315 return adjusted_bpaddr
;
7320 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7321 struct breakpoint
*owner
)
7323 memset (loc
, 0, sizeof (*loc
));
7325 gdb_assert (ops
!= NULL
);
7329 loc
->cond_bytecode
= NULL
;
7330 loc
->shlib_disabled
= 0;
7333 switch (owner
->type
)
7336 case bp_single_step
:
7340 case bp_longjmp_resume
:
7341 case bp_longjmp_call_dummy
:
7343 case bp_exception_resume
:
7344 case bp_step_resume
:
7345 case bp_hp_step_resume
:
7346 case bp_watchpoint_scope
:
7348 case bp_std_terminate
:
7349 case bp_shlib_event
:
7350 case bp_thread_event
:
7351 case bp_overlay_event
:
7353 case bp_longjmp_master
:
7354 case bp_std_terminate_master
:
7355 case bp_exception_master
:
7356 case bp_gnu_ifunc_resolver
:
7357 case bp_gnu_ifunc_resolver_return
:
7359 loc
->loc_type
= bp_loc_software_breakpoint
;
7360 mark_breakpoint_location_modified (loc
);
7362 case bp_hardware_breakpoint
:
7363 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7364 mark_breakpoint_location_modified (loc
);
7366 case bp_hardware_watchpoint
:
7367 case bp_read_watchpoint
:
7368 case bp_access_watchpoint
:
7369 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7374 case bp_fast_tracepoint
:
7375 case bp_static_tracepoint
:
7376 loc
->loc_type
= bp_loc_other
;
7379 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7385 /* Allocate a struct bp_location. */
7387 static struct bp_location
*
7388 allocate_bp_location (struct breakpoint
*bpt
)
7390 return bpt
->ops
->allocate_location (bpt
);
7394 free_bp_location (struct bp_location
*loc
)
7396 loc
->ops
->dtor (loc
);
7400 /* Increment reference count. */
7403 incref_bp_location (struct bp_location
*bl
)
7408 /* Decrement reference count. If the reference count reaches 0,
7409 destroy the bp_location. Sets *BLP to NULL. */
7412 decref_bp_location (struct bp_location
**blp
)
7414 gdb_assert ((*blp
)->refc
> 0);
7416 if (--(*blp
)->refc
== 0)
7417 free_bp_location (*blp
);
7421 /* Add breakpoint B at the end of the global breakpoint chain. */
7424 add_to_breakpoint_chain (struct breakpoint
*b
)
7426 struct breakpoint
*b1
;
7428 /* Add this breakpoint to the end of the chain so that a list of
7429 breakpoints will come out in order of increasing numbers. */
7431 b1
= breakpoint_chain
;
7433 breakpoint_chain
= b
;
7442 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7445 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7446 struct gdbarch
*gdbarch
,
7448 const struct breakpoint_ops
*ops
)
7450 memset (b
, 0, sizeof (*b
));
7452 gdb_assert (ops
!= NULL
);
7456 b
->gdbarch
= gdbarch
;
7457 b
->language
= current_language
->la_language
;
7458 b
->input_radix
= input_radix
;
7460 b
->enable_state
= bp_enabled
;
7463 b
->ignore_count
= 0;
7465 b
->frame_id
= null_frame_id
;
7466 b
->condition_not_parsed
= 0;
7467 b
->py_bp_object
= NULL
;
7468 b
->related_breakpoint
= b
;
7472 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7473 that has type BPTYPE and has no locations as yet. */
7475 static struct breakpoint
*
7476 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7478 const struct breakpoint_ops
*ops
)
7480 struct breakpoint
*b
= new breakpoint ();
7482 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7483 add_to_breakpoint_chain (b
);
7487 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7488 resolutions should be made as the user specified the location explicitly
7492 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7494 gdb_assert (loc
->owner
!= NULL
);
7496 if (loc
->owner
->type
== bp_breakpoint
7497 || loc
->owner
->type
== bp_hardware_breakpoint
7498 || is_tracepoint (loc
->owner
))
7501 const char *function_name
;
7502 CORE_ADDR func_addr
;
7504 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7505 &func_addr
, NULL
, &is_gnu_ifunc
);
7507 if (is_gnu_ifunc
&& !explicit_loc
)
7509 struct breakpoint
*b
= loc
->owner
;
7511 gdb_assert (loc
->pspace
== current_program_space
);
7512 if (gnu_ifunc_resolve_name (function_name
,
7513 &loc
->requested_address
))
7515 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7516 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7517 loc
->requested_address
,
7520 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7521 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7523 /* Create only the whole new breakpoint of this type but do not
7524 mess more complicated breakpoints with multiple locations. */
7525 b
->type
= bp_gnu_ifunc_resolver
;
7526 /* Remember the resolver's address for use by the return
7528 loc
->related_address
= func_addr
;
7533 loc
->function_name
= xstrdup (function_name
);
7537 /* Attempt to determine architecture of location identified by SAL. */
7539 get_sal_arch (struct symtab_and_line sal
)
7542 return get_objfile_arch (sal
.section
->objfile
);
7544 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7549 /* Low level routine for partially initializing a breakpoint of type
7550 BPTYPE. The newly created breakpoint's address, section, source
7551 file name, and line number are provided by SAL.
7553 It is expected that the caller will complete the initialization of
7554 the newly created breakpoint struct as well as output any status
7555 information regarding the creation of a new breakpoint. */
7558 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7559 struct symtab_and_line sal
, enum bptype bptype
,
7560 const struct breakpoint_ops
*ops
)
7562 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7564 add_location_to_breakpoint (b
, &sal
);
7566 if (bptype
!= bp_catchpoint
)
7567 gdb_assert (sal
.pspace
!= NULL
);
7569 /* Store the program space that was used to set the breakpoint,
7570 except for ordinary breakpoints, which are independent of the
7572 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7573 b
->pspace
= sal
.pspace
;
7576 /* set_raw_breakpoint is a low level routine for allocating and
7577 partially initializing a breakpoint of type BPTYPE. The newly
7578 created breakpoint's address, section, source file name, and line
7579 number are provided by SAL. The newly created and partially
7580 initialized breakpoint is added to the breakpoint chain and
7581 is also returned as the value of this function.
7583 It is expected that the caller will complete the initialization of
7584 the newly created breakpoint struct as well as output any status
7585 information regarding the creation of a new breakpoint. In
7586 particular, set_raw_breakpoint does NOT set the breakpoint
7587 number! Care should be taken to not allow an error to occur
7588 prior to completing the initialization of the breakpoint. If this
7589 should happen, a bogus breakpoint will be left on the chain. */
7592 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7593 struct symtab_and_line sal
, enum bptype bptype
,
7594 const struct breakpoint_ops
*ops
)
7596 struct breakpoint
*b
= new breakpoint ();
7598 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7599 add_to_breakpoint_chain (b
);
7603 /* Call this routine when stepping and nexting to enable a breakpoint
7604 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7605 initiated the operation. */
7608 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7610 struct breakpoint
*b
, *b_tmp
;
7611 int thread
= tp
->global_num
;
7613 /* To avoid having to rescan all objfile symbols at every step,
7614 we maintain a list of continually-inserted but always disabled
7615 longjmp "master" breakpoints. Here, we simply create momentary
7616 clones of those and enable them for the requested thread. */
7617 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7618 if (b
->pspace
== current_program_space
7619 && (b
->type
== bp_longjmp_master
7620 || b
->type
== bp_exception_master
))
7622 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7623 struct breakpoint
*clone
;
7625 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7626 after their removal. */
7627 clone
= momentary_breakpoint_from_master (b
, type
,
7628 &longjmp_breakpoint_ops
, 1);
7629 clone
->thread
= thread
;
7632 tp
->initiating_frame
= frame
;
7635 /* Delete all longjmp breakpoints from THREAD. */
7637 delete_longjmp_breakpoint (int thread
)
7639 struct breakpoint
*b
, *b_tmp
;
7641 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7642 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7644 if (b
->thread
== thread
)
7645 delete_breakpoint (b
);
7650 delete_longjmp_breakpoint_at_next_stop (int thread
)
7652 struct breakpoint
*b
, *b_tmp
;
7654 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7655 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7657 if (b
->thread
== thread
)
7658 b
->disposition
= disp_del_at_next_stop
;
7662 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7663 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7664 pointer to any of them. Return NULL if this system cannot place longjmp
7668 set_longjmp_breakpoint_for_call_dummy (void)
7670 struct breakpoint
*b
, *retval
= NULL
;
7673 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7675 struct breakpoint
*new_b
;
7677 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7678 &momentary_breakpoint_ops
,
7680 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7682 /* Link NEW_B into the chain of RETVAL breakpoints. */
7684 gdb_assert (new_b
->related_breakpoint
== new_b
);
7687 new_b
->related_breakpoint
= retval
;
7688 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7689 retval
= retval
->related_breakpoint
;
7690 retval
->related_breakpoint
= new_b
;
7696 /* Verify all existing dummy frames and their associated breakpoints for
7697 TP. Remove those which can no longer be found in the current frame
7700 You should call this function only at places where it is safe to currently
7701 unwind the whole stack. Failed stack unwind would discard live dummy
7705 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7707 struct breakpoint
*b
, *b_tmp
;
7709 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7710 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7712 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7714 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7715 dummy_b
= dummy_b
->related_breakpoint
;
7716 if (dummy_b
->type
!= bp_call_dummy
7717 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7720 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7722 while (b
->related_breakpoint
!= b
)
7724 if (b_tmp
== b
->related_breakpoint
)
7725 b_tmp
= b
->related_breakpoint
->next
;
7726 delete_breakpoint (b
->related_breakpoint
);
7728 delete_breakpoint (b
);
7733 enable_overlay_breakpoints (void)
7735 struct breakpoint
*b
;
7738 if (b
->type
== bp_overlay_event
)
7740 b
->enable_state
= bp_enabled
;
7741 update_global_location_list (UGLL_MAY_INSERT
);
7742 overlay_events_enabled
= 1;
7747 disable_overlay_breakpoints (void)
7749 struct breakpoint
*b
;
7752 if (b
->type
== bp_overlay_event
)
7754 b
->enable_state
= bp_disabled
;
7755 update_global_location_list (UGLL_DONT_INSERT
);
7756 overlay_events_enabled
= 0;
7760 /* Set an active std::terminate breakpoint for each std::terminate
7761 master breakpoint. */
7763 set_std_terminate_breakpoint (void)
7765 struct breakpoint
*b
, *b_tmp
;
7767 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7768 if (b
->pspace
== current_program_space
7769 && b
->type
== bp_std_terminate_master
)
7771 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7772 &momentary_breakpoint_ops
, 1);
7776 /* Delete all the std::terminate breakpoints. */
7778 delete_std_terminate_breakpoint (void)
7780 struct breakpoint
*b
, *b_tmp
;
7782 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7783 if (b
->type
== bp_std_terminate
)
7784 delete_breakpoint (b
);
7788 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7790 struct breakpoint
*b
;
7792 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7793 &internal_breakpoint_ops
);
7795 b
->enable_state
= bp_enabled
;
7796 /* location has to be used or breakpoint_re_set will delete me. */
7797 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7799 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7804 struct lang_and_radix
7810 /* Create a breakpoint for JIT code registration and unregistration. */
7813 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7815 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7816 &internal_breakpoint_ops
);
7819 /* Remove JIT code registration and unregistration breakpoint(s). */
7822 remove_jit_event_breakpoints (void)
7824 struct breakpoint
*b
, *b_tmp
;
7826 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7827 if (b
->type
== bp_jit_event
7828 && b
->loc
->pspace
== current_program_space
)
7829 delete_breakpoint (b
);
7833 remove_solib_event_breakpoints (void)
7835 struct breakpoint
*b
, *b_tmp
;
7837 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7838 if (b
->type
== bp_shlib_event
7839 && b
->loc
->pspace
== current_program_space
)
7840 delete_breakpoint (b
);
7843 /* See breakpoint.h. */
7846 remove_solib_event_breakpoints_at_next_stop (void)
7848 struct breakpoint
*b
, *b_tmp
;
7850 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7851 if (b
->type
== bp_shlib_event
7852 && b
->loc
->pspace
== current_program_space
)
7853 b
->disposition
= disp_del_at_next_stop
;
7856 /* Helper for create_solib_event_breakpoint /
7857 create_and_insert_solib_event_breakpoint. Allows specifying which
7858 INSERT_MODE to pass through to update_global_location_list. */
7860 static struct breakpoint
*
7861 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7862 enum ugll_insert_mode insert_mode
)
7864 struct breakpoint
*b
;
7866 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7867 &internal_breakpoint_ops
);
7868 update_global_location_list_nothrow (insert_mode
);
7873 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7875 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7878 /* See breakpoint.h. */
7881 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7883 struct breakpoint
*b
;
7885 /* Explicitly tell update_global_location_list to insert
7887 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7888 if (!b
->loc
->inserted
)
7890 delete_breakpoint (b
);
7896 /* Disable any breakpoints that are on code in shared libraries. Only
7897 apply to enabled breakpoints, disabled ones can just stay disabled. */
7900 disable_breakpoints_in_shlibs (void)
7902 struct bp_location
*loc
, **locp_tmp
;
7904 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7906 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7907 struct breakpoint
*b
= loc
->owner
;
7909 /* We apply the check to all breakpoints, including disabled for
7910 those with loc->duplicate set. This is so that when breakpoint
7911 becomes enabled, or the duplicate is removed, gdb will try to
7912 insert all breakpoints. If we don't set shlib_disabled here,
7913 we'll try to insert those breakpoints and fail. */
7914 if (((b
->type
== bp_breakpoint
)
7915 || (b
->type
== bp_jit_event
)
7916 || (b
->type
== bp_hardware_breakpoint
)
7917 || (is_tracepoint (b
)))
7918 && loc
->pspace
== current_program_space
7919 && !loc
->shlib_disabled
7920 && solib_name_from_address (loc
->pspace
, loc
->address
)
7923 loc
->shlib_disabled
= 1;
7928 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7929 notification of unloaded_shlib. Only apply to enabled breakpoints,
7930 disabled ones can just stay disabled. */
7933 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7935 struct bp_location
*loc
, **locp_tmp
;
7936 int disabled_shlib_breaks
= 0;
7938 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7940 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7941 struct breakpoint
*b
= loc
->owner
;
7943 if (solib
->pspace
== loc
->pspace
7944 && !loc
->shlib_disabled
7945 && (((b
->type
== bp_breakpoint
7946 || b
->type
== bp_jit_event
7947 || b
->type
== bp_hardware_breakpoint
)
7948 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7949 || loc
->loc_type
== bp_loc_software_breakpoint
))
7950 || is_tracepoint (b
))
7951 && solib_contains_address_p (solib
, loc
->address
))
7953 loc
->shlib_disabled
= 1;
7954 /* At this point, we cannot rely on remove_breakpoint
7955 succeeding so we must mark the breakpoint as not inserted
7956 to prevent future errors occurring in remove_breakpoints. */
7959 /* This may cause duplicate notifications for the same breakpoint. */
7960 observer_notify_breakpoint_modified (b
);
7962 if (!disabled_shlib_breaks
)
7964 target_terminal_ours_for_output ();
7965 warning (_("Temporarily disabling breakpoints "
7966 "for unloaded shared library \"%s\""),
7969 disabled_shlib_breaks
= 1;
7974 /* Disable any breakpoints and tracepoints in OBJFILE upon
7975 notification of free_objfile. Only apply to enabled breakpoints,
7976 disabled ones can just stay disabled. */
7979 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7981 struct breakpoint
*b
;
7983 if (objfile
== NULL
)
7986 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7987 managed by the user with add-symbol-file/remove-symbol-file.
7988 Similarly to how breakpoints in shared libraries are handled in
7989 response to "nosharedlibrary", mark breakpoints in such modules
7990 shlib_disabled so they end up uninserted on the next global
7991 location list update. Shared libraries not loaded by the user
7992 aren't handled here -- they're already handled in
7993 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7994 solib_unloaded observer. We skip objfiles that are not
7995 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7997 if ((objfile
->flags
& OBJF_SHARED
) == 0
7998 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8003 struct bp_location
*loc
;
8004 int bp_modified
= 0;
8006 if (!is_breakpoint (b
) && !is_tracepoint (b
))
8009 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
8011 CORE_ADDR loc_addr
= loc
->address
;
8013 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8014 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8017 if (loc
->shlib_disabled
!= 0)
8020 if (objfile
->pspace
!= loc
->pspace
)
8023 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8024 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8027 if (is_addr_in_objfile (loc_addr
, objfile
))
8029 loc
->shlib_disabled
= 1;
8030 /* At this point, we don't know whether the object was
8031 unmapped from the inferior or not, so leave the
8032 inserted flag alone. We'll handle failure to
8033 uninsert quietly, in case the object was indeed
8036 mark_breakpoint_location_modified (loc
);
8043 observer_notify_breakpoint_modified (b
);
8047 /* FORK & VFORK catchpoints. */
8049 /* An instance of this type is used to represent a fork or vfork
8050 catchpoint. It includes a "struct breakpoint" as a kind of base
8051 class; users downcast to "struct breakpoint *" when needed. A
8052 breakpoint is really of this type iff its ops pointer points to
8053 CATCH_FORK_BREAKPOINT_OPS. */
8055 struct fork_catchpoint
8057 /* The base class. */
8058 struct breakpoint base
;
8060 /* Process id of a child process whose forking triggered this
8061 catchpoint. This field is only valid immediately after this
8062 catchpoint has triggered. */
8063 ptid_t forked_inferior_pid
;
8066 /* Implement the "insert" breakpoint_ops method for fork
8070 insert_catch_fork (struct bp_location
*bl
)
8072 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8075 /* Implement the "remove" breakpoint_ops method for fork
8079 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8081 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8084 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8088 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8089 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8090 const struct target_waitstatus
*ws
)
8092 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8094 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8097 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8101 /* Implement the "print_it" breakpoint_ops method for fork
8104 static enum print_stop_action
8105 print_it_catch_fork (bpstat bs
)
8107 struct ui_out
*uiout
= current_uiout
;
8108 struct breakpoint
*b
= bs
->breakpoint_at
;
8109 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8111 annotate_catchpoint (b
->number
);
8112 maybe_print_thread_hit_breakpoint (uiout
);
8113 if (b
->disposition
== disp_del
)
8114 uiout
->text ("Temporary catchpoint ");
8116 uiout
->text ("Catchpoint ");
8117 if (uiout
->is_mi_like_p ())
8119 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8120 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8122 uiout
->field_int ("bkptno", b
->number
);
8123 uiout
->text (" (forked process ");
8124 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8125 uiout
->text ("), ");
8126 return PRINT_SRC_AND_LOC
;
8129 /* Implement the "print_one" breakpoint_ops method for fork
8133 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8135 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8136 struct value_print_options opts
;
8137 struct ui_out
*uiout
= current_uiout
;
8139 get_user_print_options (&opts
);
8141 /* Field 4, the address, is omitted (which makes the columns not
8142 line up too nicely with the headers, but the effect is relatively
8144 if (opts
.addressprint
)
8145 uiout
->field_skip ("addr");
8147 uiout
->text ("fork");
8148 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8150 uiout
->text (", process ");
8151 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8155 if (uiout
->is_mi_like_p ())
8156 uiout
->field_string ("catch-type", "fork");
8159 /* Implement the "print_mention" breakpoint_ops method for fork
8163 print_mention_catch_fork (struct breakpoint
*b
)
8165 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8168 /* Implement the "print_recreate" breakpoint_ops method for fork
8172 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8174 fprintf_unfiltered (fp
, "catch fork");
8175 print_recreate_thread (b
, fp
);
8178 /* The breakpoint_ops structure to be used in fork catchpoints. */
8180 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8182 /* Implement the "insert" breakpoint_ops method for vfork
8186 insert_catch_vfork (struct bp_location
*bl
)
8188 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8191 /* Implement the "remove" breakpoint_ops method for vfork
8195 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8197 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8200 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8204 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8205 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8206 const struct target_waitstatus
*ws
)
8208 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8210 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8213 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8217 /* Implement the "print_it" breakpoint_ops method for vfork
8220 static enum print_stop_action
8221 print_it_catch_vfork (bpstat bs
)
8223 struct ui_out
*uiout
= current_uiout
;
8224 struct breakpoint
*b
= bs
->breakpoint_at
;
8225 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8227 annotate_catchpoint (b
->number
);
8228 maybe_print_thread_hit_breakpoint (uiout
);
8229 if (b
->disposition
== disp_del
)
8230 uiout
->text ("Temporary catchpoint ");
8232 uiout
->text ("Catchpoint ");
8233 if (uiout
->is_mi_like_p ())
8235 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8236 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8238 uiout
->field_int ("bkptno", b
->number
);
8239 uiout
->text (" (vforked process ");
8240 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8241 uiout
->text ("), ");
8242 return PRINT_SRC_AND_LOC
;
8245 /* Implement the "print_one" breakpoint_ops method for vfork
8249 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8251 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8252 struct value_print_options opts
;
8253 struct ui_out
*uiout
= current_uiout
;
8255 get_user_print_options (&opts
);
8256 /* Field 4, the address, is omitted (which makes the columns not
8257 line up too nicely with the headers, but the effect is relatively
8259 if (opts
.addressprint
)
8260 uiout
->field_skip ("addr");
8262 uiout
->text ("vfork");
8263 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8265 uiout
->text (", process ");
8266 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8270 if (uiout
->is_mi_like_p ())
8271 uiout
->field_string ("catch-type", "vfork");
8274 /* Implement the "print_mention" breakpoint_ops method for vfork
8278 print_mention_catch_vfork (struct breakpoint
*b
)
8280 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8283 /* Implement the "print_recreate" breakpoint_ops method for vfork
8287 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8289 fprintf_unfiltered (fp
, "catch vfork");
8290 print_recreate_thread (b
, fp
);
8293 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8295 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8297 /* An instance of this type is used to represent an solib catchpoint.
8298 It includes a "struct breakpoint" as a kind of base class; users
8299 downcast to "struct breakpoint *" when needed. A breakpoint is
8300 really of this type iff its ops pointer points to
8301 CATCH_SOLIB_BREAKPOINT_OPS. */
8303 struct solib_catchpoint
8305 /* The base class. */
8306 struct breakpoint base
;
8308 /* True for "catch load", false for "catch unload". */
8309 unsigned char is_load
;
8311 /* Regular expression to match, if any. COMPILED is only valid when
8312 REGEX is non-NULL. */
8318 dtor_catch_solib (struct breakpoint
*b
)
8320 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8323 regfree (&self
->compiled
);
8324 xfree (self
->regex
);
8326 base_breakpoint_ops
.dtor (b
);
8330 insert_catch_solib (struct bp_location
*ignore
)
8336 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8342 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8343 struct address_space
*aspace
,
8345 const struct target_waitstatus
*ws
)
8347 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8348 struct breakpoint
*other
;
8350 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8353 ALL_BREAKPOINTS (other
)
8355 struct bp_location
*other_bl
;
8357 if (other
== bl
->owner
)
8360 if (other
->type
!= bp_shlib_event
)
8363 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8366 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8368 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8377 check_status_catch_solib (struct bpstats
*bs
)
8379 struct solib_catchpoint
*self
8380 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8385 struct so_list
*iter
;
8388 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8393 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8402 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8407 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8413 bs
->print_it
= print_it_noop
;
8416 static enum print_stop_action
8417 print_it_catch_solib (bpstat bs
)
8419 struct breakpoint
*b
= bs
->breakpoint_at
;
8420 struct ui_out
*uiout
= current_uiout
;
8422 annotate_catchpoint (b
->number
);
8423 maybe_print_thread_hit_breakpoint (uiout
);
8424 if (b
->disposition
== disp_del
)
8425 uiout
->text ("Temporary catchpoint ");
8427 uiout
->text ("Catchpoint ");
8428 uiout
->field_int ("bkptno", b
->number
);
8430 if (uiout
->is_mi_like_p ())
8431 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8432 print_solib_event (1);
8433 return PRINT_SRC_AND_LOC
;
8437 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8439 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8440 struct value_print_options opts
;
8441 struct ui_out
*uiout
= current_uiout
;
8444 get_user_print_options (&opts
);
8445 /* Field 4, the address, is omitted (which makes the columns not
8446 line up too nicely with the headers, but the effect is relatively
8448 if (opts
.addressprint
)
8451 uiout
->field_skip ("addr");
8458 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8460 msg
= xstrdup (_("load of library"));
8465 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8467 msg
= xstrdup (_("unload of library"));
8469 uiout
->field_string ("what", msg
);
8472 if (uiout
->is_mi_like_p ())
8473 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8477 print_mention_catch_solib (struct breakpoint
*b
)
8479 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8481 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8482 self
->is_load
? "load" : "unload");
8486 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8488 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8490 fprintf_unfiltered (fp
, "%s %s",
8491 b
->disposition
== disp_del
? "tcatch" : "catch",
8492 self
->is_load
? "load" : "unload");
8494 fprintf_unfiltered (fp
, " %s", self
->regex
);
8495 fprintf_unfiltered (fp
, "\n");
8498 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8500 /* Shared helper function (MI and CLI) for creating and installing
8501 a shared object event catchpoint. If IS_LOAD is non-zero then
8502 the events to be caught are load events, otherwise they are
8503 unload events. If IS_TEMP is non-zero the catchpoint is a
8504 temporary one. If ENABLED is non-zero the catchpoint is
8505 created in an enabled state. */
8508 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8510 struct solib_catchpoint
*c
;
8511 struct gdbarch
*gdbarch
= get_current_arch ();
8512 struct cleanup
*cleanup
;
8516 arg
= skip_spaces_const (arg
);
8518 c
= new solib_catchpoint ();
8519 cleanup
= make_cleanup (xfree
, c
);
8525 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8528 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8530 make_cleanup (xfree
, err
);
8531 error (_("Invalid regexp (%s): %s"), err
, arg
);
8533 c
->regex
= xstrdup (arg
);
8536 c
->is_load
= is_load
;
8537 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8538 &catch_solib_breakpoint_ops
);
8540 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8542 discard_cleanups (cleanup
);
8543 install_breakpoint (0, &c
->base
, 1);
8546 /* A helper function that does all the work for "catch load" and
8550 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8551 struct cmd_list_element
*command
)
8554 const int enabled
= 1;
8556 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8558 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8562 catch_load_command_1 (char *arg
, int from_tty
,
8563 struct cmd_list_element
*command
)
8565 catch_load_or_unload (arg
, from_tty
, 1, command
);
8569 catch_unload_command_1 (char *arg
, int from_tty
,
8570 struct cmd_list_element
*command
)
8572 catch_load_or_unload (arg
, from_tty
, 0, command
);
8575 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8576 is non-zero, then make the breakpoint temporary. If COND_STRING is
8577 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8578 the breakpoint_ops structure associated to the catchpoint. */
8581 init_catchpoint (struct breakpoint
*b
,
8582 struct gdbarch
*gdbarch
, int tempflag
,
8583 const char *cond_string
,
8584 const struct breakpoint_ops
*ops
)
8586 struct symtab_and_line sal
;
8589 sal
.pspace
= current_program_space
;
8591 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8593 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8594 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8598 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8600 add_to_breakpoint_chain (b
);
8601 set_breakpoint_number (internal
, b
);
8602 if (is_tracepoint (b
))
8603 set_tracepoint_count (breakpoint_count
);
8606 observer_notify_breakpoint_created (b
);
8609 update_global_location_list (UGLL_MAY_INSERT
);
8613 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8614 int tempflag
, const char *cond_string
,
8615 const struct breakpoint_ops
*ops
)
8617 struct fork_catchpoint
*c
= new fork_catchpoint ();
8619 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8621 c
->forked_inferior_pid
= null_ptid
;
8623 install_breakpoint (0, &c
->base
, 1);
8626 /* Exec catchpoints. */
8628 /* An instance of this type is used to represent an exec catchpoint.
8629 It includes a "struct breakpoint" as a kind of base class; users
8630 downcast to "struct breakpoint *" when needed. A breakpoint is
8631 really of this type iff its ops pointer points to
8632 CATCH_EXEC_BREAKPOINT_OPS. */
8634 struct exec_catchpoint
8636 /* The base class. */
8637 struct breakpoint base
;
8639 /* Filename of a program whose exec triggered this catchpoint.
8640 This field is only valid immediately after this catchpoint has
8642 char *exec_pathname
;
8645 /* Implement the "dtor" breakpoint_ops method for exec
8649 dtor_catch_exec (struct breakpoint
*b
)
8651 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8653 xfree (c
->exec_pathname
);
8655 base_breakpoint_ops
.dtor (b
);
8659 insert_catch_exec (struct bp_location
*bl
)
8661 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8665 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8667 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8671 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8672 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8673 const struct target_waitstatus
*ws
)
8675 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8677 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8680 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8684 static enum print_stop_action
8685 print_it_catch_exec (bpstat bs
)
8687 struct ui_out
*uiout
= current_uiout
;
8688 struct breakpoint
*b
= bs
->breakpoint_at
;
8689 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8691 annotate_catchpoint (b
->number
);
8692 maybe_print_thread_hit_breakpoint (uiout
);
8693 if (b
->disposition
== disp_del
)
8694 uiout
->text ("Temporary catchpoint ");
8696 uiout
->text ("Catchpoint ");
8697 if (uiout
->is_mi_like_p ())
8699 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8700 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8702 uiout
->field_int ("bkptno", b
->number
);
8703 uiout
->text (" (exec'd ");
8704 uiout
->field_string ("new-exec", c
->exec_pathname
);
8705 uiout
->text ("), ");
8707 return PRINT_SRC_AND_LOC
;
8711 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8713 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8714 struct value_print_options opts
;
8715 struct ui_out
*uiout
= current_uiout
;
8717 get_user_print_options (&opts
);
8719 /* Field 4, the address, is omitted (which makes the columns
8720 not line up too nicely with the headers, but the effect
8721 is relatively readable). */
8722 if (opts
.addressprint
)
8723 uiout
->field_skip ("addr");
8725 uiout
->text ("exec");
8726 if (c
->exec_pathname
!= NULL
)
8728 uiout
->text (", program \"");
8729 uiout
->field_string ("what", c
->exec_pathname
);
8730 uiout
->text ("\" ");
8733 if (uiout
->is_mi_like_p ())
8734 uiout
->field_string ("catch-type", "exec");
8738 print_mention_catch_exec (struct breakpoint
*b
)
8740 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8743 /* Implement the "print_recreate" breakpoint_ops method for exec
8747 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8749 fprintf_unfiltered (fp
, "catch exec");
8750 print_recreate_thread (b
, fp
);
8753 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8756 hw_breakpoint_used_count (void)
8759 struct breakpoint
*b
;
8760 struct bp_location
*bl
;
8764 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8765 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8767 /* Special types of hardware breakpoints may use more than
8769 i
+= b
->ops
->resources_needed (bl
);
8776 /* Returns the resources B would use if it were a hardware
8780 hw_watchpoint_use_count (struct breakpoint
*b
)
8783 struct bp_location
*bl
;
8785 if (!breakpoint_enabled (b
))
8788 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8790 /* Special types of hardware watchpoints may use more than
8792 i
+= b
->ops
->resources_needed (bl
);
8798 /* Returns the sum the used resources of all hardware watchpoints of
8799 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8800 the sum of the used resources of all hardware watchpoints of other
8801 types _not_ TYPE. */
8804 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8805 enum bptype type
, int *other_type_used
)
8808 struct breakpoint
*b
;
8810 *other_type_used
= 0;
8815 if (!breakpoint_enabled (b
))
8818 if (b
->type
== type
)
8819 i
+= hw_watchpoint_use_count (b
);
8820 else if (is_hardware_watchpoint (b
))
8821 *other_type_used
= 1;
8828 disable_watchpoints_before_interactive_call_start (void)
8830 struct breakpoint
*b
;
8834 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8836 b
->enable_state
= bp_call_disabled
;
8837 update_global_location_list (UGLL_DONT_INSERT
);
8843 enable_watchpoints_after_interactive_call_stop (void)
8845 struct breakpoint
*b
;
8849 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8851 b
->enable_state
= bp_enabled
;
8852 update_global_location_list (UGLL_MAY_INSERT
);
8858 disable_breakpoints_before_startup (void)
8860 current_program_space
->executing_startup
= 1;
8861 update_global_location_list (UGLL_DONT_INSERT
);
8865 enable_breakpoints_after_startup (void)
8867 current_program_space
->executing_startup
= 0;
8868 breakpoint_re_set ();
8871 /* Create a new single-step breakpoint for thread THREAD, with no
8874 static struct breakpoint
*
8875 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8877 struct breakpoint
*b
= new breakpoint ();
8879 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8880 &momentary_breakpoint_ops
);
8882 b
->disposition
= disp_donttouch
;
8883 b
->frame_id
= null_frame_id
;
8886 gdb_assert (b
->thread
!= 0);
8888 add_to_breakpoint_chain (b
);
8893 /* Set a momentary breakpoint of type TYPE at address specified by
8894 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8898 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8899 struct frame_id frame_id
, enum bptype type
)
8901 struct breakpoint
*b
;
8903 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8905 gdb_assert (!frame_id_artificial_p (frame_id
));
8907 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8908 b
->enable_state
= bp_enabled
;
8909 b
->disposition
= disp_donttouch
;
8910 b
->frame_id
= frame_id
;
8912 /* If we're debugging a multi-threaded program, then we want
8913 momentary breakpoints to be active in only a single thread of
8915 if (in_thread_list (inferior_ptid
))
8916 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8918 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8923 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8924 The new breakpoint will have type TYPE, use OPS as its
8925 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8927 static struct breakpoint
*
8928 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8930 const struct breakpoint_ops
*ops
,
8933 struct breakpoint
*copy
;
8935 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8936 copy
->loc
= allocate_bp_location (copy
);
8937 set_breakpoint_location_function (copy
->loc
, 1);
8939 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8940 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8941 copy
->loc
->address
= orig
->loc
->address
;
8942 copy
->loc
->section
= orig
->loc
->section
;
8943 copy
->loc
->pspace
= orig
->loc
->pspace
;
8944 copy
->loc
->probe
= orig
->loc
->probe
;
8945 copy
->loc
->line_number
= orig
->loc
->line_number
;
8946 copy
->loc
->symtab
= orig
->loc
->symtab
;
8947 copy
->loc
->enabled
= loc_enabled
;
8948 copy
->frame_id
= orig
->frame_id
;
8949 copy
->thread
= orig
->thread
;
8950 copy
->pspace
= orig
->pspace
;
8952 copy
->enable_state
= bp_enabled
;
8953 copy
->disposition
= disp_donttouch
;
8954 copy
->number
= internal_breakpoint_number
--;
8956 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8960 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8964 clone_momentary_breakpoint (struct breakpoint
*orig
)
8966 /* If there's nothing to clone, then return nothing. */
8970 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8974 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8977 struct symtab_and_line sal
;
8979 sal
= find_pc_line (pc
, 0);
8981 sal
.section
= find_pc_overlay (pc
);
8982 sal
.explicit_pc
= 1;
8984 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8988 /* Tell the user we have just set a breakpoint B. */
8991 mention (struct breakpoint
*b
)
8993 b
->ops
->print_mention (b
);
8994 if (current_uiout
->is_mi_like_p ())
8996 printf_filtered ("\n");
9000 static int bp_loc_is_permanent (struct bp_location
*loc
);
9002 static struct bp_location
*
9003 add_location_to_breakpoint (struct breakpoint
*b
,
9004 const struct symtab_and_line
*sal
)
9006 struct bp_location
*loc
, **tmp
;
9007 CORE_ADDR adjusted_address
;
9008 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9010 if (loc_gdbarch
== NULL
)
9011 loc_gdbarch
= b
->gdbarch
;
9013 /* Adjust the breakpoint's address prior to allocating a location.
9014 Once we call allocate_bp_location(), that mostly uninitialized
9015 location will be placed on the location chain. Adjustment of the
9016 breakpoint may cause target_read_memory() to be called and we do
9017 not want its scan of the location chain to find a breakpoint and
9018 location that's only been partially initialized. */
9019 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9022 /* Sort the locations by their ADDRESS. */
9023 loc
= allocate_bp_location (b
);
9024 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9025 tmp
= &((*tmp
)->next
))
9030 loc
->requested_address
= sal
->pc
;
9031 loc
->address
= adjusted_address
;
9032 loc
->pspace
= sal
->pspace
;
9033 loc
->probe
.probe
= sal
->probe
;
9034 loc
->probe
.objfile
= sal
->objfile
;
9035 gdb_assert (loc
->pspace
!= NULL
);
9036 loc
->section
= sal
->section
;
9037 loc
->gdbarch
= loc_gdbarch
;
9038 loc
->line_number
= sal
->line
;
9039 loc
->symtab
= sal
->symtab
;
9041 set_breakpoint_location_function (loc
,
9042 sal
->explicit_pc
|| sal
->explicit_line
);
9044 /* While by definition, permanent breakpoints are already present in the
9045 code, we don't mark the location as inserted. Normally one would expect
9046 that GDB could rely on that breakpoint instruction to stop the program,
9047 thus removing the need to insert its own breakpoint, except that executing
9048 the breakpoint instruction can kill the target instead of reporting a
9049 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9050 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9051 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9052 breakpoint be inserted normally results in QEMU knowing about the GDB
9053 breakpoint, and thus trap before the breakpoint instruction is executed.
9054 (If GDB later needs to continue execution past the permanent breakpoint,
9055 it manually increments the PC, thus avoiding executing the breakpoint
9057 if (bp_loc_is_permanent (loc
))
9064 /* See breakpoint.h. */
9067 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9071 const gdb_byte
*bpoint
;
9072 gdb_byte
*target_mem
;
9073 struct cleanup
*cleanup
;
9077 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9079 /* Software breakpoints unsupported? */
9083 target_mem
= (gdb_byte
*) alloca (len
);
9085 /* Enable the automatic memory restoration from breakpoints while
9086 we read the memory. Otherwise we could say about our temporary
9087 breakpoints they are permanent. */
9088 cleanup
= make_show_memory_breakpoints_cleanup (0);
9090 if (target_read_memory (address
, target_mem
, len
) == 0
9091 && memcmp (target_mem
, bpoint
, len
) == 0)
9094 do_cleanups (cleanup
);
9099 /* Return 1 if LOC is pointing to a permanent breakpoint,
9100 return 0 otherwise. */
9103 bp_loc_is_permanent (struct bp_location
*loc
)
9105 struct cleanup
*cleanup
;
9108 gdb_assert (loc
!= NULL
);
9110 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9111 attempt to read from the addresses the locations of these breakpoint types
9112 point to. program_breakpoint_here_p, below, will attempt to read
9114 if (!breakpoint_address_is_meaningful (loc
->owner
))
9117 cleanup
= save_current_space_and_thread ();
9118 switch_to_program_space_and_thread (loc
->pspace
);
9120 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9122 do_cleanups (cleanup
);
9127 /* Build a command list for the dprintf corresponding to the current
9128 settings of the dprintf style options. */
9131 update_dprintf_command_list (struct breakpoint
*b
)
9133 char *dprintf_args
= b
->extra_string
;
9134 char *printf_line
= NULL
;
9139 dprintf_args
= skip_spaces (dprintf_args
);
9141 /* Allow a comma, as it may have terminated a location, but don't
9143 if (*dprintf_args
== ',')
9145 dprintf_args
= skip_spaces (dprintf_args
);
9147 if (*dprintf_args
!= '"')
9148 error (_("Bad format string, missing '\"'."));
9150 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9151 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9152 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9154 if (!dprintf_function
)
9155 error (_("No function supplied for dprintf call"));
9157 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9158 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9163 printf_line
= xstrprintf ("call (void) %s (%s)",
9167 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9169 if (target_can_run_breakpoint_commands ())
9170 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9173 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9174 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9178 internal_error (__FILE__
, __LINE__
,
9179 _("Invalid dprintf style."));
9181 gdb_assert (printf_line
!= NULL
);
9182 /* Manufacture a printf sequence. */
9184 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9186 printf_cmd_line
->control_type
= simple_control
;
9187 printf_cmd_line
->body_count
= 0;
9188 printf_cmd_line
->body_list
= NULL
;
9189 printf_cmd_line
->next
= NULL
;
9190 printf_cmd_line
->line
= printf_line
;
9192 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9196 /* Update all dprintf commands, making their command lists reflect
9197 current style settings. */
9200 update_dprintf_commands (char *args
, int from_tty
,
9201 struct cmd_list_element
*c
)
9203 struct breakpoint
*b
;
9207 if (b
->type
== bp_dprintf
)
9208 update_dprintf_command_list (b
);
9212 /* Create a breakpoint with SAL as location. Use LOCATION
9213 as a description of the location, and COND_STRING
9214 as condition expression. If LOCATION is NULL then create an
9215 "address location" from the address in the SAL. */
9218 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9219 struct symtabs_and_lines sals
,
9220 event_location_up
&&location
,
9221 char *filter
, char *cond_string
,
9223 enum bptype type
, enum bpdisp disposition
,
9224 int thread
, int task
, int ignore_count
,
9225 const struct breakpoint_ops
*ops
, int from_tty
,
9226 int enabled
, int internal
, unsigned flags
,
9227 int display_canonical
)
9231 if (type
== bp_hardware_breakpoint
)
9233 int target_resources_ok
;
9235 i
= hw_breakpoint_used_count ();
9236 target_resources_ok
=
9237 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9239 if (target_resources_ok
== 0)
9240 error (_("No hardware breakpoint support in the target."));
9241 else if (target_resources_ok
< 0)
9242 error (_("Hardware breakpoints used exceeds limit."));
9245 gdb_assert (sals
.nelts
> 0);
9247 for (i
= 0; i
< sals
.nelts
; ++i
)
9249 struct symtab_and_line sal
= sals
.sals
[i
];
9250 struct bp_location
*loc
;
9254 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9256 loc_gdbarch
= gdbarch
;
9258 describe_other_breakpoints (loc_gdbarch
,
9259 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9264 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9268 b
->cond_string
= cond_string
;
9269 b
->extra_string
= extra_string
;
9270 b
->ignore_count
= ignore_count
;
9271 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9272 b
->disposition
= disposition
;
9274 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9275 b
->loc
->inserted
= 1;
9277 if (type
== bp_static_tracepoint
)
9279 struct tracepoint
*t
= (struct tracepoint
*) b
;
9280 struct static_tracepoint_marker marker
;
9282 if (strace_marker_p (b
))
9284 /* We already know the marker exists, otherwise, we
9285 wouldn't see a sal for it. */
9287 = &event_location_to_string (b
->location
.get ())[3];
9291 p
= skip_spaces_const (p
);
9293 endp
= skip_to_space_const (p
);
9295 marker_str
= savestring (p
, endp
- p
);
9296 t
->static_trace_marker_id
= marker_str
;
9298 printf_filtered (_("Probed static tracepoint "
9300 t
->static_trace_marker_id
);
9302 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9304 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9305 release_static_tracepoint_marker (&marker
);
9307 printf_filtered (_("Probed static tracepoint "
9309 t
->static_trace_marker_id
);
9312 warning (_("Couldn't determine the static "
9313 "tracepoint marker to probe"));
9320 loc
= add_location_to_breakpoint (b
, &sal
);
9321 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9327 const char *arg
= b
->cond_string
;
9329 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9330 block_for_pc (loc
->address
), 0);
9332 error (_("Garbage '%s' follows condition"), arg
);
9335 /* Dynamic printf requires and uses additional arguments on the
9336 command line, otherwise it's an error. */
9337 if (type
== bp_dprintf
)
9339 if (b
->extra_string
)
9340 update_dprintf_command_list (b
);
9342 error (_("Format string required"));
9344 else if (b
->extra_string
)
9345 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9348 b
->display_canonical
= display_canonical
;
9349 if (location
!= NULL
)
9350 b
->location
= std::move (location
);
9352 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9357 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9358 struct symtabs_and_lines sals
,
9359 event_location_up
&&location
,
9360 char *filter
, char *cond_string
,
9362 enum bptype type
, enum bpdisp disposition
,
9363 int thread
, int task
, int ignore_count
,
9364 const struct breakpoint_ops
*ops
, int from_tty
,
9365 int enabled
, int internal
, unsigned flags
,
9366 int display_canonical
)
9368 struct breakpoint
*b
;
9369 struct cleanup
*old_chain
;
9371 if (is_tracepoint_type (type
))
9373 struct tracepoint
*t
;
9375 t
= new tracepoint ();
9379 b
= new breakpoint ();
9381 old_chain
= make_cleanup (xfree
, b
);
9383 init_breakpoint_sal (b
, gdbarch
,
9384 sals
, std::move (location
),
9385 filter
, cond_string
, extra_string
,
9387 thread
, task
, ignore_count
,
9389 enabled
, internal
, flags
,
9391 discard_cleanups (old_chain
);
9393 install_breakpoint (internal
, b
, 0);
9396 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9397 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9398 value. COND_STRING, if not NULL, specified the condition to be
9399 used for all breakpoints. Essentially the only case where
9400 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9401 function. In that case, it's still not possible to specify
9402 separate conditions for different overloaded functions, so
9403 we take just a single condition string.
9405 NOTE: If the function succeeds, the caller is expected to cleanup
9406 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9407 array contents). If the function fails (error() is called), the
9408 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9409 COND and SALS arrays and each of those arrays contents. */
9412 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9413 struct linespec_result
*canonical
,
9414 char *cond_string
, char *extra_string
,
9415 enum bptype type
, enum bpdisp disposition
,
9416 int thread
, int task
, int ignore_count
,
9417 const struct breakpoint_ops
*ops
, int from_tty
,
9418 int enabled
, int internal
, unsigned flags
)
9421 struct linespec_sals
*lsal
;
9423 if (canonical
->pre_expanded
)
9424 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9426 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9428 /* Note that 'location' can be NULL in the case of a plain
9429 'break', without arguments. */
9430 event_location_up location
9431 = (canonical
->location
!= NULL
9432 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9433 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9435 make_cleanup (xfree
, filter_string
);
9436 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9437 std::move (location
),
9439 cond_string
, extra_string
,
9441 thread
, task
, ignore_count
, ops
,
9442 from_tty
, enabled
, internal
, flags
,
9443 canonical
->special_display
);
9447 /* Parse LOCATION which is assumed to be a SAL specification possibly
9448 followed by conditionals. On return, SALS contains an array of SAL
9449 addresses found. LOCATION points to the end of the SAL (for
9450 linespec locations).
9452 The array and the line spec strings are allocated on the heap, it is
9453 the caller's responsibility to free them. */
9456 parse_breakpoint_sals (const struct event_location
*location
,
9457 struct linespec_result
*canonical
)
9459 struct symtab_and_line cursal
;
9461 if (event_location_type (location
) == LINESPEC_LOCATION
)
9463 const char *address
= get_linespec_location (location
);
9465 if (address
== NULL
)
9467 /* The last displayed codepoint, if it's valid, is our default
9468 breakpoint address. */
9469 if (last_displayed_sal_is_valid ())
9471 struct linespec_sals lsal
;
9472 struct symtab_and_line sal
;
9475 init_sal (&sal
); /* Initialize to zeroes. */
9476 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9478 /* Set sal's pspace, pc, symtab, and line to the values
9479 corresponding to the last call to print_frame_info.
9480 Be sure to reinitialize LINE with NOTCURRENT == 0
9481 as the breakpoint line number is inappropriate otherwise.
9482 find_pc_line would adjust PC, re-set it back. */
9483 get_last_displayed_sal (&sal
);
9485 sal
= find_pc_line (pc
, 0);
9487 /* "break" without arguments is equivalent to "break *PC"
9488 where PC is the last displayed codepoint's address. So
9489 make sure to set sal.explicit_pc to prevent GDB from
9490 trying to expand the list of sals to include all other
9491 instances with the same symtab and line. */
9493 sal
.explicit_pc
= 1;
9495 lsal
.sals
.sals
[0] = sal
;
9496 lsal
.sals
.nelts
= 1;
9497 lsal
.canonical
= NULL
;
9499 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9503 error (_("No default breakpoint address now."));
9507 /* Force almost all breakpoints to be in terms of the
9508 current_source_symtab (which is decode_line_1's default).
9509 This should produce the results we want almost all of the
9510 time while leaving default_breakpoint_* alone.
9512 ObjC: However, don't match an Objective-C method name which
9513 may have a '+' or '-' succeeded by a '['. */
9514 cursal
= get_current_source_symtab_and_line ();
9515 if (last_displayed_sal_is_valid ())
9517 const char *address
= NULL
;
9519 if (event_location_type (location
) == LINESPEC_LOCATION
)
9520 address
= get_linespec_location (location
);
9524 && strchr ("+-", address
[0]) != NULL
9525 && address
[1] != '['))
9527 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9528 get_last_displayed_symtab (),
9529 get_last_displayed_line (),
9530 canonical
, NULL
, NULL
);
9535 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9536 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9540 /* Convert each SAL into a real PC. Verify that the PC can be
9541 inserted as a breakpoint. If it can't throw an error. */
9544 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9548 for (i
= 0; i
< sals
->nelts
; i
++)
9549 resolve_sal_pc (&sals
->sals
[i
]);
9552 /* Fast tracepoints may have restrictions on valid locations. For
9553 instance, a fast tracepoint using a jump instead of a trap will
9554 likely have to overwrite more bytes than a trap would, and so can
9555 only be placed where the instruction is longer than the jump, or a
9556 multi-instruction sequence does not have a jump into the middle of
9560 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9561 struct symtabs_and_lines
*sals
)
9564 struct symtab_and_line
*sal
;
9566 struct cleanup
*old_chain
;
9568 for (i
= 0; i
< sals
->nelts
; i
++)
9570 struct gdbarch
*sarch
;
9572 sal
= &sals
->sals
[i
];
9574 sarch
= get_sal_arch (*sal
);
9575 /* We fall back to GDBARCH if there is no architecture
9576 associated with SAL. */
9579 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9580 old_chain
= make_cleanup (xfree
, msg
);
9583 error (_("May not have a fast tracepoint at %s%s"),
9584 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9586 do_cleanups (old_chain
);
9590 /* Given TOK, a string specification of condition and thread, as
9591 accepted by the 'break' command, extract the condition
9592 string and thread number and set *COND_STRING and *THREAD.
9593 PC identifies the context at which the condition should be parsed.
9594 If no condition is found, *COND_STRING is set to NULL.
9595 If no thread is found, *THREAD is set to -1. */
9598 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9599 char **cond_string
, int *thread
, int *task
,
9602 *cond_string
= NULL
;
9609 const char *end_tok
;
9611 const char *cond_start
= NULL
;
9612 const char *cond_end
= NULL
;
9614 tok
= skip_spaces_const (tok
);
9616 if ((*tok
== '"' || *tok
== ',') && rest
)
9618 *rest
= savestring (tok
, strlen (tok
));
9622 end_tok
= skip_to_space_const (tok
);
9624 toklen
= end_tok
- tok
;
9626 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9628 tok
= cond_start
= end_tok
+ 1;
9629 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9631 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9633 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9636 struct thread_info
*thr
;
9639 thr
= parse_thread_id (tok
, &tmptok
);
9641 error (_("Junk after thread keyword."));
9642 *thread
= thr
->global_num
;
9645 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9650 *task
= strtol (tok
, &tmptok
, 0);
9652 error (_("Junk after task keyword."));
9653 if (!valid_task_id (*task
))
9654 error (_("Unknown task %d."), *task
);
9659 *rest
= savestring (tok
, strlen (tok
));
9663 error (_("Junk at end of arguments."));
9667 /* Decode a static tracepoint marker spec. */
9669 static struct symtabs_and_lines
9670 decode_static_tracepoint_spec (const char **arg_p
)
9672 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9673 struct symtabs_and_lines sals
;
9674 struct cleanup
*old_chain
;
9675 const char *p
= &(*arg_p
)[3];
9680 p
= skip_spaces_const (p
);
9682 endp
= skip_to_space_const (p
);
9684 marker_str
= savestring (p
, endp
- p
);
9685 old_chain
= make_cleanup (xfree
, marker_str
);
9687 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9688 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9689 error (_("No known static tracepoint marker named %s"), marker_str
);
9691 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9692 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9694 for (i
= 0; i
< sals
.nelts
; i
++)
9696 struct static_tracepoint_marker
*marker
;
9698 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9700 init_sal (&sals
.sals
[i
]);
9702 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9703 sals
.sals
[i
].pc
= marker
->address
;
9705 release_static_tracepoint_marker (marker
);
9708 do_cleanups (old_chain
);
9714 /* See breakpoint.h. */
9717 create_breakpoint (struct gdbarch
*gdbarch
,
9718 const struct event_location
*location
, char *cond_string
,
9719 int thread
, char *extra_string
,
9721 int tempflag
, enum bptype type_wanted
,
9723 enum auto_boolean pending_break_support
,
9724 const struct breakpoint_ops
*ops
,
9725 int from_tty
, int enabled
, int internal
,
9728 struct linespec_result canonical
;
9729 struct cleanup
*bkpt_chain
= NULL
;
9732 int prev_bkpt_count
= breakpoint_count
;
9734 gdb_assert (ops
!= NULL
);
9736 /* If extra_string isn't useful, set it to NULL. */
9737 if (extra_string
!= NULL
&& *extra_string
== '\0')
9738 extra_string
= NULL
;
9742 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9744 CATCH (e
, RETURN_MASK_ERROR
)
9746 /* If caller is interested in rc value from parse, set
9748 if (e
.error
== NOT_FOUND_ERROR
)
9750 /* If pending breakpoint support is turned off, throw
9753 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9754 throw_exception (e
);
9756 exception_print (gdb_stderr
, e
);
9758 /* If pending breakpoint support is auto query and the user
9759 selects no, then simply return the error code. */
9760 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9761 && !nquery (_("Make %s pending on future shared library load? "),
9762 bptype_string (type_wanted
)))
9765 /* At this point, either the user was queried about setting
9766 a pending breakpoint and selected yes, or pending
9767 breakpoint behavior is on and thus a pending breakpoint
9768 is defaulted on behalf of the user. */
9772 throw_exception (e
);
9776 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9779 /* ----------------------------- SNIP -----------------------------
9780 Anything added to the cleanup chain beyond this point is assumed
9781 to be part of a breakpoint. If the breakpoint create succeeds
9782 then the memory is not reclaimed. */
9783 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9785 /* Resolve all line numbers to PC's and verify that the addresses
9786 are ok for the target. */
9790 struct linespec_sals
*iter
;
9792 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9793 breakpoint_sals_to_pc (&iter
->sals
);
9796 /* Fast tracepoints may have additional restrictions on location. */
9797 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9800 struct linespec_sals
*iter
;
9802 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9803 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9806 /* Verify that condition can be parsed, before setting any
9807 breakpoints. Allocate a separate condition expression for each
9814 struct linespec_sals
*lsal
;
9816 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9818 /* Here we only parse 'arg' to separate condition
9819 from thread number, so parsing in context of first
9820 sal is OK. When setting the breakpoint we'll
9821 re-parse it in context of each sal. */
9823 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9824 &cond_string
, &thread
, &task
, &rest
);
9826 make_cleanup (xfree
, cond_string
);
9828 make_cleanup (xfree
, rest
);
9830 extra_string
= rest
;
9832 extra_string
= NULL
;
9836 if (type_wanted
!= bp_dprintf
9837 && extra_string
!= NULL
&& *extra_string
!= '\0')
9838 error (_("Garbage '%s' at end of location"), extra_string
);
9840 /* Create a private copy of condition string. */
9843 cond_string
= xstrdup (cond_string
);
9844 make_cleanup (xfree
, cond_string
);
9846 /* Create a private copy of any extra string. */
9849 extra_string
= xstrdup (extra_string
);
9850 make_cleanup (xfree
, extra_string
);
9854 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9855 cond_string
, extra_string
, type_wanted
,
9856 tempflag
? disp_del
: disp_donttouch
,
9857 thread
, task
, ignore_count
, ops
,
9858 from_tty
, enabled
, internal
, flags
);
9862 struct breakpoint
*b
;
9864 if (is_tracepoint_type (type_wanted
))
9866 struct tracepoint
*t
;
9868 t
= new tracepoint ();
9872 b
= new breakpoint ();
9874 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9875 b
->location
= copy_event_location (location
);
9878 b
->cond_string
= NULL
;
9881 /* Create a private copy of condition string. */
9884 cond_string
= xstrdup (cond_string
);
9885 make_cleanup (xfree
, cond_string
);
9887 b
->cond_string
= cond_string
;
9891 /* Create a private copy of any extra string. */
9892 if (extra_string
!= NULL
)
9894 extra_string
= xstrdup (extra_string
);
9895 make_cleanup (xfree
, extra_string
);
9897 b
->extra_string
= extra_string
;
9898 b
->ignore_count
= ignore_count
;
9899 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9900 b
->condition_not_parsed
= 1;
9901 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9902 if ((type_wanted
!= bp_breakpoint
9903 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9904 b
->pspace
= current_program_space
;
9906 install_breakpoint (internal
, b
, 0);
9909 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9911 warning (_("Multiple breakpoints were set.\nUse the "
9912 "\"delete\" command to delete unwanted breakpoints."));
9913 prev_breakpoint_count
= prev_bkpt_count
;
9916 /* That's it. Discard the cleanups for data inserted into the
9918 discard_cleanups (bkpt_chain
);
9920 /* error call may happen here - have BKPT_CHAIN already discarded. */
9921 update_global_location_list (UGLL_MAY_INSERT
);
9926 /* Set a breakpoint.
9927 ARG is a string describing breakpoint address,
9928 condition, and thread.
9929 FLAG specifies if a breakpoint is hardware on,
9930 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9934 break_command_1 (char *arg
, int flag
, int from_tty
)
9936 int tempflag
= flag
& BP_TEMPFLAG
;
9937 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9938 ? bp_hardware_breakpoint
9940 struct breakpoint_ops
*ops
;
9942 event_location_up location
= string_to_event_location (&arg
, current_language
);
9944 /* Matching breakpoints on probes. */
9945 if (location
!= NULL
9946 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9947 ops
= &bkpt_probe_breakpoint_ops
;
9949 ops
= &bkpt_breakpoint_ops
;
9951 create_breakpoint (get_current_arch (),
9953 NULL
, 0, arg
, 1 /* parse arg */,
9954 tempflag
, type_wanted
,
9955 0 /* Ignore count */,
9956 pending_break_support
,
9964 /* Helper function for break_command_1 and disassemble_command. */
9967 resolve_sal_pc (struct symtab_and_line
*sal
)
9971 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9973 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9974 error (_("No line %d in file \"%s\"."),
9975 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9978 /* If this SAL corresponds to a breakpoint inserted using a line
9979 number, then skip the function prologue if necessary. */
9980 if (sal
->explicit_line
)
9981 skip_prologue_sal (sal
);
9984 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9986 const struct blockvector
*bv
;
9987 const struct block
*b
;
9990 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9991 SYMTAB_COMPUNIT (sal
->symtab
));
9994 sym
= block_linkage_function (b
);
9997 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9998 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10003 /* It really is worthwhile to have the section, so we'll
10004 just have to look harder. This case can be executed
10005 if we have line numbers but no functions (as can
10006 happen in assembly source). */
10008 struct bound_minimal_symbol msym
;
10009 struct cleanup
*old_chain
= save_current_space_and_thread ();
10011 switch_to_program_space_and_thread (sal
->pspace
);
10013 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10015 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10017 do_cleanups (old_chain
);
10024 break_command (char *arg
, int from_tty
)
10026 break_command_1 (arg
, 0, from_tty
);
10030 tbreak_command (char *arg
, int from_tty
)
10032 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10036 hbreak_command (char *arg
, int from_tty
)
10038 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10042 thbreak_command (char *arg
, int from_tty
)
10044 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10048 stop_command (char *arg
, int from_tty
)
10050 printf_filtered (_("Specify the type of breakpoint to set.\n\
10051 Usage: stop in <function | address>\n\
10052 stop at <line>\n"));
10056 stopin_command (char *arg
, int from_tty
)
10060 if (arg
== (char *) NULL
)
10062 else if (*arg
!= '*')
10064 char *argptr
= arg
;
10067 /* Look for a ':'. If this is a line number specification, then
10068 say it is bad, otherwise, it should be an address or
10069 function/method name. */
10070 while (*argptr
&& !hasColon
)
10072 hasColon
= (*argptr
== ':');
10077 badInput
= (*argptr
!= ':'); /* Not a class::method */
10079 badInput
= isdigit (*arg
); /* a simple line number */
10083 printf_filtered (_("Usage: stop in <function | address>\n"));
10085 break_command_1 (arg
, 0, from_tty
);
10089 stopat_command (char *arg
, int from_tty
)
10093 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10097 char *argptr
= arg
;
10100 /* Look for a ':'. If there is a '::' then get out, otherwise
10101 it is probably a line number. */
10102 while (*argptr
&& !hasColon
)
10104 hasColon
= (*argptr
== ':');
10109 badInput
= (*argptr
== ':'); /* we have class::method */
10111 badInput
= !isdigit (*arg
); /* not a line number */
10115 printf_filtered (_("Usage: stop at <line>\n"));
10117 break_command_1 (arg
, 0, from_tty
);
10120 /* The dynamic printf command is mostly like a regular breakpoint, but
10121 with a prewired command list consisting of a single output command,
10122 built from extra arguments supplied on the dprintf command
10126 dprintf_command (char *arg
, int from_tty
)
10128 event_location_up location
= string_to_event_location (&arg
, current_language
);
10130 /* If non-NULL, ARG should have been advanced past the location;
10131 the next character must be ','. */
10134 if (arg
[0] != ',' || arg
[1] == '\0')
10135 error (_("Format string required"));
10138 /* Skip the comma. */
10143 create_breakpoint (get_current_arch (),
10145 NULL
, 0, arg
, 1 /* parse arg */,
10147 0 /* Ignore count */,
10148 pending_break_support
,
10149 &dprintf_breakpoint_ops
,
10157 agent_printf_command (char *arg
, int from_tty
)
10159 error (_("May only run agent-printf on the target"));
10162 /* Implement the "breakpoint_hit" breakpoint_ops method for
10163 ranged breakpoints. */
10166 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10167 struct address_space
*aspace
,
10169 const struct target_waitstatus
*ws
)
10171 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10172 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10175 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10176 bl
->length
, aspace
, bp_addr
);
10179 /* Implement the "resources_needed" breakpoint_ops method for
10180 ranged breakpoints. */
10183 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10185 return target_ranged_break_num_registers ();
10188 /* Implement the "print_it" breakpoint_ops method for
10189 ranged breakpoints. */
10191 static enum print_stop_action
10192 print_it_ranged_breakpoint (bpstat bs
)
10194 struct breakpoint
*b
= bs
->breakpoint_at
;
10195 struct bp_location
*bl
= b
->loc
;
10196 struct ui_out
*uiout
= current_uiout
;
10198 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10200 /* Ranged breakpoints have only one location. */
10201 gdb_assert (bl
&& bl
->next
== NULL
);
10203 annotate_breakpoint (b
->number
);
10205 maybe_print_thread_hit_breakpoint (uiout
);
10207 if (b
->disposition
== disp_del
)
10208 uiout
->text ("Temporary ranged breakpoint ");
10210 uiout
->text ("Ranged breakpoint ");
10211 if (uiout
->is_mi_like_p ())
10213 uiout
->field_string ("reason",
10214 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10215 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10217 uiout
->field_int ("bkptno", b
->number
);
10218 uiout
->text (", ");
10220 return PRINT_SRC_AND_LOC
;
10223 /* Implement the "print_one" breakpoint_ops method for
10224 ranged breakpoints. */
10227 print_one_ranged_breakpoint (struct breakpoint
*b
,
10228 struct bp_location
**last_loc
)
10230 struct bp_location
*bl
= b
->loc
;
10231 struct value_print_options opts
;
10232 struct ui_out
*uiout
= current_uiout
;
10234 /* Ranged breakpoints have only one location. */
10235 gdb_assert (bl
&& bl
->next
== NULL
);
10237 get_user_print_options (&opts
);
10239 if (opts
.addressprint
)
10240 /* We don't print the address range here, it will be printed later
10241 by print_one_detail_ranged_breakpoint. */
10242 uiout
->field_skip ("addr");
10243 annotate_field (5);
10244 print_breakpoint_location (b
, bl
);
10248 /* Implement the "print_one_detail" breakpoint_ops method for
10249 ranged breakpoints. */
10252 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10253 struct ui_out
*uiout
)
10255 CORE_ADDR address_start
, address_end
;
10256 struct bp_location
*bl
= b
->loc
;
10261 address_start
= bl
->address
;
10262 address_end
= address_start
+ bl
->length
- 1;
10264 uiout
->text ("\taddress range: ");
10265 stb
.printf ("[%s, %s]",
10266 print_core_address (bl
->gdbarch
, address_start
),
10267 print_core_address (bl
->gdbarch
, address_end
));
10268 uiout
->field_stream ("addr", stb
);
10269 uiout
->text ("\n");
10272 /* Implement the "print_mention" breakpoint_ops method for
10273 ranged breakpoints. */
10276 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10278 struct bp_location
*bl
= b
->loc
;
10279 struct ui_out
*uiout
= current_uiout
;
10282 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10284 if (uiout
->is_mi_like_p ())
10287 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10288 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10289 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10292 /* Implement the "print_recreate" breakpoint_ops method for
10293 ranged breakpoints. */
10296 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10298 fprintf_unfiltered (fp
, "break-range %s, %s",
10299 event_location_to_string (b
->location
.get ()),
10300 event_location_to_string (b
->location_range_end
.get ()));
10301 print_recreate_thread (b
, fp
);
10304 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10306 static struct breakpoint_ops ranged_breakpoint_ops
;
10308 /* Find the address where the end of the breakpoint range should be
10309 placed, given the SAL of the end of the range. This is so that if
10310 the user provides a line number, the end of the range is set to the
10311 last instruction of the given line. */
10314 find_breakpoint_range_end (struct symtab_and_line sal
)
10318 /* If the user provided a PC value, use it. Otherwise,
10319 find the address of the end of the given location. */
10320 if (sal
.explicit_pc
)
10327 ret
= find_line_pc_range (sal
, &start
, &end
);
10329 error (_("Could not find location of the end of the range."));
10331 /* find_line_pc_range returns the start of the next line. */
10338 /* Implement the "break-range" CLI command. */
10341 break_range_command (char *arg
, int from_tty
)
10343 char *arg_start
, *addr_string_start
;
10344 struct linespec_result canonical_start
, canonical_end
;
10345 int bp_count
, can_use_bp
, length
;
10347 struct breakpoint
*b
;
10348 struct symtab_and_line sal_start
, sal_end
;
10349 struct cleanup
*cleanup_bkpt
;
10350 struct linespec_sals
*lsal_start
, *lsal_end
;
10352 /* We don't support software ranged breakpoints. */
10353 if (target_ranged_break_num_registers () < 0)
10354 error (_("This target does not support hardware ranged breakpoints."));
10356 bp_count
= hw_breakpoint_used_count ();
10357 bp_count
+= target_ranged_break_num_registers ();
10358 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10360 if (can_use_bp
< 0)
10361 error (_("Hardware breakpoints used exceeds limit."));
10363 arg
= skip_spaces (arg
);
10364 if (arg
== NULL
|| arg
[0] == '\0')
10365 error(_("No address range specified."));
10368 event_location_up start_location
= string_to_event_location (&arg
,
10370 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10373 error (_("Too few arguments."));
10374 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10375 error (_("Could not find location of the beginning of the range."));
10377 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10379 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10380 || lsal_start
->sals
.nelts
!= 1)
10381 error (_("Cannot create a ranged breakpoint with multiple locations."));
10383 sal_start
= lsal_start
->sals
.sals
[0];
10384 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10385 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10387 arg
++; /* Skip the comma. */
10388 arg
= skip_spaces (arg
);
10390 /* Parse the end location. */
10394 /* We call decode_line_full directly here instead of using
10395 parse_breakpoint_sals because we need to specify the start location's
10396 symtab and line as the default symtab and line for the end of the
10397 range. This makes it possible to have ranges like "foo.c:27, +14",
10398 where +14 means 14 lines from the start location. */
10399 event_location_up end_location
= string_to_event_location (&arg
,
10401 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10402 sal_start
.symtab
, sal_start
.line
,
10403 &canonical_end
, NULL
, NULL
);
10405 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10406 error (_("Could not find location of the end of the range."));
10408 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10409 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10410 || lsal_end
->sals
.nelts
!= 1)
10411 error (_("Cannot create a ranged breakpoint with multiple locations."));
10413 sal_end
= lsal_end
->sals
.sals
[0];
10415 end
= find_breakpoint_range_end (sal_end
);
10416 if (sal_start
.pc
> end
)
10417 error (_("Invalid address range, end precedes start."));
10419 length
= end
- sal_start
.pc
+ 1;
10421 /* Length overflowed. */
10422 error (_("Address range too large."));
10423 else if (length
== 1)
10425 /* This range is simple enough to be handled by
10426 the `hbreak' command. */
10427 hbreak_command (addr_string_start
, 1);
10429 do_cleanups (cleanup_bkpt
);
10434 /* Now set up the breakpoint. */
10435 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10436 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10437 set_breakpoint_count (breakpoint_count
+ 1);
10438 b
->number
= breakpoint_count
;
10439 b
->disposition
= disp_donttouch
;
10440 b
->location
= std::move (start_location
);
10441 b
->location_range_end
= std::move (end_location
);
10442 b
->loc
->length
= length
;
10444 do_cleanups (cleanup_bkpt
);
10447 observer_notify_breakpoint_created (b
);
10448 update_global_location_list (UGLL_MAY_INSERT
);
10451 /* Return non-zero if EXP is verified as constant. Returned zero
10452 means EXP is variable. Also the constant detection may fail for
10453 some constant expressions and in such case still falsely return
10457 watchpoint_exp_is_const (const struct expression
*exp
)
10459 int i
= exp
->nelts
;
10465 /* We are only interested in the descriptor of each element. */
10466 operator_length (exp
, i
, &oplenp
, &argsp
);
10469 switch (exp
->elts
[i
].opcode
)
10479 case BINOP_LOGICAL_AND
:
10480 case BINOP_LOGICAL_OR
:
10481 case BINOP_BITWISE_AND
:
10482 case BINOP_BITWISE_IOR
:
10483 case BINOP_BITWISE_XOR
:
10485 case BINOP_NOTEQUAL
:
10512 case OP_OBJC_NSSTRING
:
10515 case UNOP_LOGICAL_NOT
:
10516 case UNOP_COMPLEMENT
:
10521 case UNOP_CAST_TYPE
:
10522 case UNOP_REINTERPRET_CAST
:
10523 case UNOP_DYNAMIC_CAST
:
10524 /* Unary, binary and ternary operators: We have to check
10525 their operands. If they are constant, then so is the
10526 result of that operation. For instance, if A and B are
10527 determined to be constants, then so is "A + B".
10529 UNOP_IND is one exception to the rule above, because the
10530 value of *ADDR is not necessarily a constant, even when
10535 /* Check whether the associated symbol is a constant.
10537 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10538 possible that a buggy compiler could mark a variable as
10539 constant even when it is not, and TYPE_CONST would return
10540 true in this case, while SYMBOL_CLASS wouldn't.
10542 We also have to check for function symbols because they
10543 are always constant. */
10545 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10547 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10548 && SYMBOL_CLASS (s
) != LOC_CONST
10549 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10554 /* The default action is to return 0 because we are using
10555 the optimistic approach here: If we don't know something,
10556 then it is not a constant. */
10565 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10568 dtor_watchpoint (struct breakpoint
*self
)
10570 struct watchpoint
*w
= (struct watchpoint
*) self
;
10572 xfree (w
->exp_string
);
10573 xfree (w
->exp_string_reparse
);
10574 value_free (w
->val
);
10576 base_breakpoint_ops
.dtor (self
);
10579 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10582 re_set_watchpoint (struct breakpoint
*b
)
10584 struct watchpoint
*w
= (struct watchpoint
*) b
;
10586 /* Watchpoint can be either on expression using entirely global
10587 variables, or it can be on local variables.
10589 Watchpoints of the first kind are never auto-deleted, and even
10590 persist across program restarts. Since they can use variables
10591 from shared libraries, we need to reparse expression as libraries
10592 are loaded and unloaded.
10594 Watchpoints on local variables can also change meaning as result
10595 of solib event. For example, if a watchpoint uses both a local
10596 and a global variables in expression, it's a local watchpoint,
10597 but unloading of a shared library will make the expression
10598 invalid. This is not a very common use case, but we still
10599 re-evaluate expression, to avoid surprises to the user.
10601 Note that for local watchpoints, we re-evaluate it only if
10602 watchpoints frame id is still valid. If it's not, it means the
10603 watchpoint is out of scope and will be deleted soon. In fact,
10604 I'm not sure we'll ever be called in this case.
10606 If a local watchpoint's frame id is still valid, then
10607 w->exp_valid_block is likewise valid, and we can safely use it.
10609 Don't do anything about disabled watchpoints, since they will be
10610 reevaluated again when enabled. */
10611 update_watchpoint (w
, 1 /* reparse */);
10614 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10617 insert_watchpoint (struct bp_location
*bl
)
10619 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10620 int length
= w
->exact
? 1 : bl
->length
;
10622 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10623 w
->cond_exp
.get ());
10626 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10629 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10631 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10632 int length
= w
->exact
? 1 : bl
->length
;
10634 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10635 w
->cond_exp
.get ());
10639 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10640 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10641 const struct target_waitstatus
*ws
)
10643 struct breakpoint
*b
= bl
->owner
;
10644 struct watchpoint
*w
= (struct watchpoint
*) b
;
10646 /* Continuable hardware watchpoints are treated as non-existent if the
10647 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10648 some data address). Otherwise gdb won't stop on a break instruction
10649 in the code (not from a breakpoint) when a hardware watchpoint has
10650 been defined. Also skip watchpoints which we know did not trigger
10651 (did not match the data address). */
10652 if (is_hardware_watchpoint (b
)
10653 && w
->watchpoint_triggered
== watch_triggered_no
)
10660 check_status_watchpoint (bpstat bs
)
10662 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10664 bpstat_check_watchpoint (bs
);
10667 /* Implement the "resources_needed" breakpoint_ops method for
10668 hardware watchpoints. */
10671 resources_needed_watchpoint (const struct bp_location
*bl
)
10673 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10674 int length
= w
->exact
? 1 : bl
->length
;
10676 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10679 /* Implement the "works_in_software_mode" breakpoint_ops method for
10680 hardware watchpoints. */
10683 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10685 /* Read and access watchpoints only work with hardware support. */
10686 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10689 static enum print_stop_action
10690 print_it_watchpoint (bpstat bs
)
10692 struct cleanup
*old_chain
;
10693 struct breakpoint
*b
;
10694 enum print_stop_action result
;
10695 struct watchpoint
*w
;
10696 struct ui_out
*uiout
= current_uiout
;
10698 gdb_assert (bs
->bp_location_at
!= NULL
);
10700 b
= bs
->breakpoint_at
;
10701 w
= (struct watchpoint
*) b
;
10703 old_chain
= make_cleanup (null_cleanup
, NULL
);
10705 annotate_watchpoint (b
->number
);
10706 maybe_print_thread_hit_breakpoint (uiout
);
10712 case bp_watchpoint
:
10713 case bp_hardware_watchpoint
:
10714 if (uiout
->is_mi_like_p ())
10715 uiout
->field_string
10716 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10718 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10719 uiout
->text ("\nOld value = ");
10720 watchpoint_value_print (bs
->old_val
, &stb
);
10721 uiout
->field_stream ("old", stb
);
10722 uiout
->text ("\nNew value = ");
10723 watchpoint_value_print (w
->val
, &stb
);
10724 uiout
->field_stream ("new", stb
);
10725 uiout
->text ("\n");
10726 /* More than one watchpoint may have been triggered. */
10727 result
= PRINT_UNKNOWN
;
10730 case bp_read_watchpoint
:
10731 if (uiout
->is_mi_like_p ())
10732 uiout
->field_string
10733 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10735 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10736 uiout
->text ("\nValue = ");
10737 watchpoint_value_print (w
->val
, &stb
);
10738 uiout
->field_stream ("value", stb
);
10739 uiout
->text ("\n");
10740 result
= PRINT_UNKNOWN
;
10743 case bp_access_watchpoint
:
10744 if (bs
->old_val
!= NULL
)
10746 if (uiout
->is_mi_like_p ())
10747 uiout
->field_string
10749 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10751 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10752 uiout
->text ("\nOld value = ");
10753 watchpoint_value_print (bs
->old_val
, &stb
);
10754 uiout
->field_stream ("old", stb
);
10755 uiout
->text ("\nNew value = ");
10760 if (uiout
->is_mi_like_p ())
10761 uiout
->field_string
10763 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10764 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10765 uiout
->text ("\nValue = ");
10767 watchpoint_value_print (w
->val
, &stb
);
10768 uiout
->field_stream ("new", stb
);
10769 uiout
->text ("\n");
10770 result
= PRINT_UNKNOWN
;
10773 result
= PRINT_UNKNOWN
;
10776 do_cleanups (old_chain
);
10780 /* Implement the "print_mention" breakpoint_ops method for hardware
10784 print_mention_watchpoint (struct breakpoint
*b
)
10786 struct cleanup
*ui_out_chain
;
10787 struct watchpoint
*w
= (struct watchpoint
*) b
;
10788 struct ui_out
*uiout
= current_uiout
;
10792 case bp_watchpoint
:
10793 uiout
->text ("Watchpoint ");
10794 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10796 case bp_hardware_watchpoint
:
10797 uiout
->text ("Hardware watchpoint ");
10798 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10800 case bp_read_watchpoint
:
10801 uiout
->text ("Hardware read watchpoint ");
10802 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10804 case bp_access_watchpoint
:
10805 uiout
->text ("Hardware access (read/write) watchpoint ");
10806 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10809 internal_error (__FILE__
, __LINE__
,
10810 _("Invalid hardware watchpoint type."));
10813 uiout
->field_int ("number", b
->number
);
10814 uiout
->text (": ");
10815 uiout
->field_string ("exp", w
->exp_string
);
10816 do_cleanups (ui_out_chain
);
10819 /* Implement the "print_recreate" breakpoint_ops method for
10823 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10825 struct watchpoint
*w
= (struct watchpoint
*) b
;
10829 case bp_watchpoint
:
10830 case bp_hardware_watchpoint
:
10831 fprintf_unfiltered (fp
, "watch");
10833 case bp_read_watchpoint
:
10834 fprintf_unfiltered (fp
, "rwatch");
10836 case bp_access_watchpoint
:
10837 fprintf_unfiltered (fp
, "awatch");
10840 internal_error (__FILE__
, __LINE__
,
10841 _("Invalid watchpoint type."));
10844 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10845 print_recreate_thread (b
, fp
);
10848 /* Implement the "explains_signal" breakpoint_ops method for
10852 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10854 /* A software watchpoint cannot cause a signal other than
10855 GDB_SIGNAL_TRAP. */
10856 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10862 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10864 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10866 /* Implement the "insert" breakpoint_ops method for
10867 masked hardware watchpoints. */
10870 insert_masked_watchpoint (struct bp_location
*bl
)
10872 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10874 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10875 bl
->watchpoint_type
);
10878 /* Implement the "remove" breakpoint_ops method for
10879 masked hardware watchpoints. */
10882 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10884 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10886 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10887 bl
->watchpoint_type
);
10890 /* Implement the "resources_needed" breakpoint_ops method for
10891 masked hardware watchpoints. */
10894 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10896 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10898 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10901 /* Implement the "works_in_software_mode" breakpoint_ops method for
10902 masked hardware watchpoints. */
10905 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10910 /* Implement the "print_it" breakpoint_ops method for
10911 masked hardware watchpoints. */
10913 static enum print_stop_action
10914 print_it_masked_watchpoint (bpstat bs
)
10916 struct breakpoint
*b
= bs
->breakpoint_at
;
10917 struct ui_out
*uiout
= current_uiout
;
10919 /* Masked watchpoints have only one location. */
10920 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10922 annotate_watchpoint (b
->number
);
10923 maybe_print_thread_hit_breakpoint (uiout
);
10927 case bp_hardware_watchpoint
:
10928 if (uiout
->is_mi_like_p ())
10929 uiout
->field_string
10930 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10933 case bp_read_watchpoint
:
10934 if (uiout
->is_mi_like_p ())
10935 uiout
->field_string
10936 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10939 case bp_access_watchpoint
:
10940 if (uiout
->is_mi_like_p ())
10941 uiout
->field_string
10943 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10946 internal_error (__FILE__
, __LINE__
,
10947 _("Invalid hardware watchpoint type."));
10951 uiout
->text (_("\n\
10952 Check the underlying instruction at PC for the memory\n\
10953 address and value which triggered this watchpoint.\n"));
10954 uiout
->text ("\n");
10956 /* More than one watchpoint may have been triggered. */
10957 return PRINT_UNKNOWN
;
10960 /* Implement the "print_one_detail" breakpoint_ops method for
10961 masked hardware watchpoints. */
10964 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10965 struct ui_out
*uiout
)
10967 struct watchpoint
*w
= (struct watchpoint
*) b
;
10969 /* Masked watchpoints have only one location. */
10970 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10972 uiout
->text ("\tmask ");
10973 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10974 uiout
->text ("\n");
10977 /* Implement the "print_mention" breakpoint_ops method for
10978 masked hardware watchpoints. */
10981 print_mention_masked_watchpoint (struct breakpoint
*b
)
10983 struct watchpoint
*w
= (struct watchpoint
*) b
;
10984 struct ui_out
*uiout
= current_uiout
;
10985 struct cleanup
*ui_out_chain
;
10989 case bp_hardware_watchpoint
:
10990 uiout
->text ("Masked hardware watchpoint ");
10991 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10993 case bp_read_watchpoint
:
10994 uiout
->text ("Masked hardware read watchpoint ");
10995 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10997 case bp_access_watchpoint
:
10998 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10999 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11002 internal_error (__FILE__
, __LINE__
,
11003 _("Invalid hardware watchpoint type."));
11006 uiout
->field_int ("number", b
->number
);
11007 uiout
->text (": ");
11008 uiout
->field_string ("exp", w
->exp_string
);
11009 do_cleanups (ui_out_chain
);
11012 /* Implement the "print_recreate" breakpoint_ops method for
11013 masked hardware watchpoints. */
11016 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11018 struct watchpoint
*w
= (struct watchpoint
*) b
;
11023 case bp_hardware_watchpoint
:
11024 fprintf_unfiltered (fp
, "watch");
11026 case bp_read_watchpoint
:
11027 fprintf_unfiltered (fp
, "rwatch");
11029 case bp_access_watchpoint
:
11030 fprintf_unfiltered (fp
, "awatch");
11033 internal_error (__FILE__
, __LINE__
,
11034 _("Invalid hardware watchpoint type."));
11037 sprintf_vma (tmp
, w
->hw_wp_mask
);
11038 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11039 print_recreate_thread (b
, fp
);
11042 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11044 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11046 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11049 is_masked_watchpoint (const struct breakpoint
*b
)
11051 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11054 /* accessflag: hw_write: watch write,
11055 hw_read: watch read,
11056 hw_access: watch access (read or write) */
11058 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11059 int just_location
, int internal
)
11061 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11062 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11063 struct value
*val
, *mark
, *result
;
11064 int saved_bitpos
= 0, saved_bitsize
= 0;
11065 const char *exp_start
= NULL
;
11066 const char *exp_end
= NULL
;
11067 const char *tok
, *end_tok
;
11069 const char *cond_start
= NULL
;
11070 const char *cond_end
= NULL
;
11071 enum bptype bp_type
;
11074 /* Flag to indicate whether we are going to use masks for
11075 the hardware watchpoint. */
11077 CORE_ADDR mask
= 0;
11078 struct watchpoint
*w
;
11080 struct cleanup
*back_to
;
11082 /* Make sure that we actually have parameters to parse. */
11083 if (arg
!= NULL
&& arg
[0] != '\0')
11085 const char *value_start
;
11087 exp_end
= arg
+ strlen (arg
);
11089 /* Look for "parameter value" pairs at the end
11090 of the arguments string. */
11091 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11093 /* Skip whitespace at the end of the argument list. */
11094 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11097 /* Find the beginning of the last token.
11098 This is the value of the parameter. */
11099 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11101 value_start
= tok
+ 1;
11103 /* Skip whitespace. */
11104 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11109 /* Find the beginning of the second to last token.
11110 This is the parameter itself. */
11111 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11114 toklen
= end_tok
- tok
+ 1;
11116 if (toklen
== 6 && startswith (tok
, "thread"))
11118 struct thread_info
*thr
;
11119 /* At this point we've found a "thread" token, which means
11120 the user is trying to set a watchpoint that triggers
11121 only in a specific thread. */
11125 error(_("You can specify only one thread."));
11127 /* Extract the thread ID from the next token. */
11128 thr
= parse_thread_id (value_start
, &endp
);
11130 /* Check if the user provided a valid thread ID. */
11131 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11132 invalid_thread_id_error (value_start
);
11134 thread
= thr
->global_num
;
11136 else if (toklen
== 4 && startswith (tok
, "mask"))
11138 /* We've found a "mask" token, which means the user wants to
11139 create a hardware watchpoint that is going to have the mask
11141 struct value
*mask_value
, *mark
;
11144 error(_("You can specify only one mask."));
11146 use_mask
= just_location
= 1;
11148 mark
= value_mark ();
11149 mask_value
= parse_to_comma_and_eval (&value_start
);
11150 mask
= value_as_address (mask_value
);
11151 value_free_to_mark (mark
);
11154 /* We didn't recognize what we found. We should stop here. */
11157 /* Truncate the string and get rid of the "parameter value" pair before
11158 the arguments string is parsed by the parse_exp_1 function. */
11165 /* Parse the rest of the arguments. From here on out, everything
11166 is in terms of a newly allocated string instead of the original
11168 innermost_block
= NULL
;
11169 expression
= savestring (arg
, exp_end
- arg
);
11170 back_to
= make_cleanup (xfree
, expression
);
11171 exp_start
= arg
= expression
;
11172 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11174 /* Remove trailing whitespace from the expression before saving it.
11175 This makes the eventual display of the expression string a bit
11177 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11180 /* Checking if the expression is not constant. */
11181 if (watchpoint_exp_is_const (exp
.get ()))
11185 len
= exp_end
- exp_start
;
11186 while (len
> 0 && isspace (exp_start
[len
- 1]))
11188 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11191 exp_valid_block
= innermost_block
;
11192 mark
= value_mark ();
11193 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11195 if (val
!= NULL
&& just_location
)
11197 saved_bitpos
= value_bitpos (val
);
11198 saved_bitsize
= value_bitsize (val
);
11205 exp_valid_block
= NULL
;
11206 val
= value_addr (result
);
11207 release_value (val
);
11208 value_free_to_mark (mark
);
11212 ret
= target_masked_watch_num_registers (value_as_address (val
),
11215 error (_("This target does not support masked watchpoints."));
11216 else if (ret
== -2)
11217 error (_("Invalid mask or memory region."));
11220 else if (val
!= NULL
)
11221 release_value (val
);
11223 tok
= skip_spaces_const (arg
);
11224 end_tok
= skip_to_space_const (tok
);
11226 toklen
= end_tok
- tok
;
11227 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11229 innermost_block
= NULL
;
11230 tok
= cond_start
= end_tok
+ 1;
11231 parse_exp_1 (&tok
, 0, 0, 0);
11233 /* The watchpoint expression may not be local, but the condition
11234 may still be. E.g.: `watch global if local > 0'. */
11235 cond_exp_valid_block
= innermost_block
;
11240 error (_("Junk at end of command."));
11242 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11244 /* Save this because create_internal_breakpoint below invalidates
11246 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11248 /* If the expression is "local", then set up a "watchpoint scope"
11249 breakpoint at the point where we've left the scope of the watchpoint
11250 expression. Create the scope breakpoint before the watchpoint, so
11251 that we will encounter it first in bpstat_stop_status. */
11252 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11254 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11256 if (frame_id_p (caller_frame_id
))
11258 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11259 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11262 = create_internal_breakpoint (caller_arch
, caller_pc
,
11263 bp_watchpoint_scope
,
11264 &momentary_breakpoint_ops
);
11266 /* create_internal_breakpoint could invalidate WP_FRAME. */
11269 scope_breakpoint
->enable_state
= bp_enabled
;
11271 /* Automatically delete the breakpoint when it hits. */
11272 scope_breakpoint
->disposition
= disp_del
;
11274 /* Only break in the proper frame (help with recursion). */
11275 scope_breakpoint
->frame_id
= caller_frame_id
;
11277 /* Set the address at which we will stop. */
11278 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11279 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11280 scope_breakpoint
->loc
->address
11281 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11282 scope_breakpoint
->loc
->requested_address
,
11283 scope_breakpoint
->type
);
11287 /* Now set up the breakpoint. We create all watchpoints as hardware
11288 watchpoints here even if hardware watchpoints are turned off, a call
11289 to update_watchpoint later in this function will cause the type to
11290 drop back to bp_watchpoint (software watchpoint) if required. */
11292 if (accessflag
== hw_read
)
11293 bp_type
= bp_read_watchpoint
;
11294 else if (accessflag
== hw_access
)
11295 bp_type
= bp_access_watchpoint
;
11297 bp_type
= bp_hardware_watchpoint
;
11299 w
= new watchpoint ();
11302 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11303 &masked_watchpoint_breakpoint_ops
);
11305 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11306 &watchpoint_breakpoint_ops
);
11307 b
->thread
= thread
;
11308 b
->disposition
= disp_donttouch
;
11309 b
->pspace
= current_program_space
;
11310 w
->exp
= std::move (exp
);
11311 w
->exp_valid_block
= exp_valid_block
;
11312 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11315 struct type
*t
= value_type (val
);
11316 CORE_ADDR addr
= value_as_address (val
);
11318 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11320 std::string name
= type_to_string (t
);
11322 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
.c_str (),
11323 core_addr_to_string (addr
));
11325 w
->exp_string
= xstrprintf ("-location %.*s",
11326 (int) (exp_end
- exp_start
), exp_start
);
11328 /* The above expression is in C. */
11329 b
->language
= language_c
;
11332 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11336 w
->hw_wp_mask
= mask
;
11341 w
->val_bitpos
= saved_bitpos
;
11342 w
->val_bitsize
= saved_bitsize
;
11347 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11349 b
->cond_string
= 0;
11351 if (frame_id_p (watchpoint_frame
))
11353 w
->watchpoint_frame
= watchpoint_frame
;
11354 w
->watchpoint_thread
= inferior_ptid
;
11358 w
->watchpoint_frame
= null_frame_id
;
11359 w
->watchpoint_thread
= null_ptid
;
11362 if (scope_breakpoint
!= NULL
)
11364 /* The scope breakpoint is related to the watchpoint. We will
11365 need to act on them together. */
11366 b
->related_breakpoint
= scope_breakpoint
;
11367 scope_breakpoint
->related_breakpoint
= b
;
11370 if (!just_location
)
11371 value_free_to_mark (mark
);
11375 /* Finally update the new watchpoint. This creates the locations
11376 that should be inserted. */
11377 update_watchpoint (w
, 1);
11379 CATCH (e
, RETURN_MASK_ALL
)
11381 delete_breakpoint (b
);
11382 throw_exception (e
);
11386 install_breakpoint (internal
, b
, 1);
11387 do_cleanups (back_to
);
11390 /* Return count of debug registers needed to watch the given expression.
11391 If the watchpoint cannot be handled in hardware return zero. */
11394 can_use_hardware_watchpoint (struct value
*v
)
11396 int found_memory_cnt
= 0;
11397 struct value
*head
= v
;
11399 /* Did the user specifically forbid us to use hardware watchpoints? */
11400 if (!can_use_hw_watchpoints
)
11403 /* Make sure that the value of the expression depends only upon
11404 memory contents, and values computed from them within GDB. If we
11405 find any register references or function calls, we can't use a
11406 hardware watchpoint.
11408 The idea here is that evaluating an expression generates a series
11409 of values, one holding the value of every subexpression. (The
11410 expression a*b+c has five subexpressions: a, b, a*b, c, and
11411 a*b+c.) GDB's values hold almost enough information to establish
11412 the criteria given above --- they identify memory lvalues,
11413 register lvalues, computed values, etcetera. So we can evaluate
11414 the expression, and then scan the chain of values that leaves
11415 behind to decide whether we can detect any possible change to the
11416 expression's final value using only hardware watchpoints.
11418 However, I don't think that the values returned by inferior
11419 function calls are special in any way. So this function may not
11420 notice that an expression involving an inferior function call
11421 can't be watched with hardware watchpoints. FIXME. */
11422 for (; v
; v
= value_next (v
))
11424 if (VALUE_LVAL (v
) == lval_memory
)
11426 if (v
!= head
&& value_lazy (v
))
11427 /* A lazy memory lvalue in the chain is one that GDB never
11428 needed to fetch; we either just used its address (e.g.,
11429 `a' in `a.b') or we never needed it at all (e.g., `a'
11430 in `a,b'). This doesn't apply to HEAD; if that is
11431 lazy then it was not readable, but watch it anyway. */
11435 /* Ahh, memory we actually used! Check if we can cover
11436 it with hardware watchpoints. */
11437 struct type
*vtype
= check_typedef (value_type (v
));
11439 /* We only watch structs and arrays if user asked for it
11440 explicitly, never if they just happen to appear in a
11441 middle of some value chain. */
11443 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11444 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11446 CORE_ADDR vaddr
= value_address (v
);
11450 len
= (target_exact_watchpoints
11451 && is_scalar_type_recursive (vtype
))?
11452 1 : TYPE_LENGTH (value_type (v
));
11454 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11458 found_memory_cnt
+= num_regs
;
11462 else if (VALUE_LVAL (v
) != not_lval
11463 && deprecated_value_modifiable (v
) == 0)
11464 return 0; /* These are values from the history (e.g., $1). */
11465 else if (VALUE_LVAL (v
) == lval_register
)
11466 return 0; /* Cannot watch a register with a HW watchpoint. */
11469 /* The expression itself looks suitable for using a hardware
11470 watchpoint, but give the target machine a chance to reject it. */
11471 return found_memory_cnt
;
11475 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11477 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11480 /* A helper function that looks for the "-location" argument and then
11481 calls watch_command_1. */
11484 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11486 int just_location
= 0;
11489 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11490 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11492 arg
= skip_spaces (arg
);
11496 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11500 watch_command (char *arg
, int from_tty
)
11502 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11506 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11508 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11512 rwatch_command (char *arg
, int from_tty
)
11514 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11518 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11520 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11524 awatch_command (char *arg
, int from_tty
)
11526 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11530 /* Data for the FSM that manages the until(location)/advance commands
11531 in infcmd.c. Here because it uses the mechanisms of
11534 struct until_break_fsm
11536 /* The base class. */
11537 struct thread_fsm thread_fsm
;
11539 /* The thread that as current when the command was executed. */
11542 /* The breakpoint set at the destination location. */
11543 struct breakpoint
*location_breakpoint
;
11545 /* Breakpoint set at the return address in the caller frame. May be
11547 struct breakpoint
*caller_breakpoint
;
11550 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11551 struct thread_info
*thread
);
11552 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11553 struct thread_info
*thread
);
11554 static enum async_reply_reason
11555 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11557 /* until_break_fsm's vtable. */
11559 static struct thread_fsm_ops until_break_fsm_ops
=
11562 until_break_fsm_clean_up
,
11563 until_break_fsm_should_stop
,
11564 NULL
, /* return_value */
11565 until_break_fsm_async_reply_reason
,
11568 /* Allocate a new until_break_command_fsm. */
11570 static struct until_break_fsm
*
11571 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11572 struct breakpoint
*location_breakpoint
,
11573 struct breakpoint
*caller_breakpoint
)
11575 struct until_break_fsm
*sm
;
11577 sm
= XCNEW (struct until_break_fsm
);
11578 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11580 sm
->thread
= thread
;
11581 sm
->location_breakpoint
= location_breakpoint
;
11582 sm
->caller_breakpoint
= caller_breakpoint
;
11587 /* Implementation of the 'should_stop' FSM method for the
11588 until(location)/advance commands. */
11591 until_break_fsm_should_stop (struct thread_fsm
*self
,
11592 struct thread_info
*tp
)
11594 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11596 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11597 sm
->location_breakpoint
) != NULL
11598 || (sm
->caller_breakpoint
!= NULL
11599 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11600 sm
->caller_breakpoint
) != NULL
))
11601 thread_fsm_set_finished (self
);
11606 /* Implementation of the 'clean_up' FSM method for the
11607 until(location)/advance commands. */
11610 until_break_fsm_clean_up (struct thread_fsm
*self
,
11611 struct thread_info
*thread
)
11613 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11615 /* Clean up our temporary breakpoints. */
11616 if (sm
->location_breakpoint
!= NULL
)
11618 delete_breakpoint (sm
->location_breakpoint
);
11619 sm
->location_breakpoint
= NULL
;
11621 if (sm
->caller_breakpoint
!= NULL
)
11623 delete_breakpoint (sm
->caller_breakpoint
);
11624 sm
->caller_breakpoint
= NULL
;
11626 delete_longjmp_breakpoint (sm
->thread
);
11629 /* Implementation of the 'async_reply_reason' FSM method for the
11630 until(location)/advance commands. */
11632 static enum async_reply_reason
11633 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11635 return EXEC_ASYNC_LOCATION_REACHED
;
11639 until_break_command (char *arg
, int from_tty
, int anywhere
)
11641 struct symtabs_and_lines sals
;
11642 struct symtab_and_line sal
;
11643 struct frame_info
*frame
;
11644 struct gdbarch
*frame_gdbarch
;
11645 struct frame_id stack_frame_id
;
11646 struct frame_id caller_frame_id
;
11647 struct breakpoint
*location_breakpoint
;
11648 struct breakpoint
*caller_breakpoint
= NULL
;
11649 struct cleanup
*old_chain
;
11651 struct thread_info
*tp
;
11652 struct until_break_fsm
*sm
;
11654 clear_proceed_status (0);
11656 /* Set a breakpoint where the user wants it and at return from
11659 event_location_up location
= string_to_event_location (&arg
, current_language
);
11661 if (last_displayed_sal_is_valid ())
11662 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11663 get_last_displayed_symtab (),
11664 get_last_displayed_line ());
11666 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11667 NULL
, (struct symtab
*) NULL
, 0);
11669 if (sals
.nelts
!= 1)
11670 error (_("Couldn't get information on specified line."));
11672 sal
= sals
.sals
[0];
11673 xfree (sals
.sals
); /* malloc'd, so freed. */
11676 error (_("Junk at end of arguments."));
11678 resolve_sal_pc (&sal
);
11680 tp
= inferior_thread ();
11681 thread
= tp
->global_num
;
11683 old_chain
= make_cleanup (null_cleanup
, NULL
);
11685 /* Note linespec handling above invalidates the frame chain.
11686 Installing a breakpoint also invalidates the frame chain (as it
11687 may need to switch threads), so do any frame handling before
11690 frame
= get_selected_frame (NULL
);
11691 frame_gdbarch
= get_frame_arch (frame
);
11692 stack_frame_id
= get_stack_frame_id (frame
);
11693 caller_frame_id
= frame_unwind_caller_id (frame
);
11695 /* Keep within the current frame, or in frames called by the current
11698 if (frame_id_p (caller_frame_id
))
11700 struct symtab_and_line sal2
;
11701 struct gdbarch
*caller_gdbarch
;
11703 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11704 sal2
.pc
= frame_unwind_caller_pc (frame
);
11705 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11706 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11710 make_cleanup_delete_breakpoint (caller_breakpoint
);
11712 set_longjmp_breakpoint (tp
, caller_frame_id
);
11713 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11716 /* set_momentary_breakpoint could invalidate FRAME. */
11720 /* If the user told us to continue until a specified location,
11721 we don't specify a frame at which we need to stop. */
11722 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11723 null_frame_id
, bp_until
);
11725 /* Otherwise, specify the selected frame, because we want to stop
11726 only at the very same frame. */
11727 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11728 stack_frame_id
, bp_until
);
11729 make_cleanup_delete_breakpoint (location_breakpoint
);
11731 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11732 location_breakpoint
, caller_breakpoint
);
11733 tp
->thread_fsm
= &sm
->thread_fsm
;
11735 discard_cleanups (old_chain
);
11737 proceed (-1, GDB_SIGNAL_DEFAULT
);
11740 /* This function attempts to parse an optional "if <cond>" clause
11741 from the arg string. If one is not found, it returns NULL.
11743 Else, it returns a pointer to the condition string. (It does not
11744 attempt to evaluate the string against a particular block.) And,
11745 it updates arg to point to the first character following the parsed
11746 if clause in the arg string. */
11749 ep_parse_optional_if_clause (const char **arg
)
11751 const char *cond_string
;
11753 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11756 /* Skip the "if" keyword. */
11759 /* Skip any extra leading whitespace, and record the start of the
11760 condition string. */
11761 *arg
= skip_spaces_const (*arg
);
11762 cond_string
= *arg
;
11764 /* Assume that the condition occupies the remainder of the arg
11766 (*arg
) += strlen (cond_string
);
11768 return cond_string
;
11771 /* Commands to deal with catching events, such as signals, exceptions,
11772 process start/exit, etc. */
11776 catch_fork_temporary
, catch_vfork_temporary
,
11777 catch_fork_permanent
, catch_vfork_permanent
11782 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11783 struct cmd_list_element
*command
)
11785 const char *arg
= arg_entry
;
11786 struct gdbarch
*gdbarch
= get_current_arch ();
11787 const char *cond_string
= NULL
;
11788 catch_fork_kind fork_kind
;
11791 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11792 tempflag
= (fork_kind
== catch_fork_temporary
11793 || fork_kind
== catch_vfork_temporary
);
11797 arg
= skip_spaces_const (arg
);
11799 /* The allowed syntax is:
11801 catch [v]fork if <cond>
11803 First, check if there's an if clause. */
11804 cond_string
= ep_parse_optional_if_clause (&arg
);
11806 if ((*arg
!= '\0') && !isspace (*arg
))
11807 error (_("Junk at end of arguments."));
11809 /* If this target supports it, create a fork or vfork catchpoint
11810 and enable reporting of such events. */
11813 case catch_fork_temporary
:
11814 case catch_fork_permanent
:
11815 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11816 &catch_fork_breakpoint_ops
);
11818 case catch_vfork_temporary
:
11819 case catch_vfork_permanent
:
11820 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11821 &catch_vfork_breakpoint_ops
);
11824 error (_("unsupported or unknown fork kind; cannot catch it"));
11830 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11831 struct cmd_list_element
*command
)
11833 const char *arg
= arg_entry
;
11834 struct exec_catchpoint
*c
;
11835 struct gdbarch
*gdbarch
= get_current_arch ();
11837 const char *cond_string
= NULL
;
11839 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11843 arg
= skip_spaces_const (arg
);
11845 /* The allowed syntax is:
11847 catch exec if <cond>
11849 First, check if there's an if clause. */
11850 cond_string
= ep_parse_optional_if_clause (&arg
);
11852 if ((*arg
!= '\0') && !isspace (*arg
))
11853 error (_("Junk at end of arguments."));
11855 c
= new exec_catchpoint ();
11856 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11857 &catch_exec_breakpoint_ops
);
11858 c
->exec_pathname
= NULL
;
11860 install_breakpoint (0, &c
->base
, 1);
11864 init_ada_exception_breakpoint (struct breakpoint
*b
,
11865 struct gdbarch
*gdbarch
,
11866 struct symtab_and_line sal
,
11868 const struct breakpoint_ops
*ops
,
11875 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11877 loc_gdbarch
= gdbarch
;
11879 describe_other_breakpoints (loc_gdbarch
,
11880 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11881 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11882 version for exception catchpoints, because two catchpoints
11883 used for different exception names will use the same address.
11884 In this case, a "breakpoint ... also set at..." warning is
11885 unproductive. Besides, the warning phrasing is also a bit
11886 inappropriate, we should use the word catchpoint, and tell
11887 the user what type of catchpoint it is. The above is good
11888 enough for now, though. */
11891 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11893 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11894 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11895 b
->location
= string_to_event_location (&addr_string
,
11896 language_def (language_ada
));
11897 b
->language
= language_ada
;
11901 catch_command (char *arg
, int from_tty
)
11903 error (_("Catch requires an event name."));
11908 tcatch_command (char *arg
, int from_tty
)
11910 error (_("Catch requires an event name."));
11913 /* A qsort comparison function that sorts breakpoints in order. */
11916 compare_breakpoints (const void *a
, const void *b
)
11918 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11919 uintptr_t ua
= (uintptr_t) *ba
;
11920 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11921 uintptr_t ub
= (uintptr_t) *bb
;
11923 if ((*ba
)->number
< (*bb
)->number
)
11925 else if ((*ba
)->number
> (*bb
)->number
)
11928 /* Now sort by address, in case we see, e..g, two breakpoints with
11932 return ua
> ub
? 1 : 0;
11935 /* Delete breakpoints by address or line. */
11938 clear_command (char *arg
, int from_tty
)
11940 struct breakpoint
*b
, *prev
;
11941 VEC(breakpoint_p
) *found
= 0;
11944 struct symtabs_and_lines sals
;
11945 struct symtab_and_line sal
;
11947 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11951 sals
= decode_line_with_current_source (arg
,
11952 (DECODE_LINE_FUNFIRSTLINE
11953 | DECODE_LINE_LIST_MODE
));
11954 make_cleanup (xfree
, sals
.sals
);
11959 sals
.sals
= XNEW (struct symtab_and_line
);
11960 make_cleanup (xfree
, sals
.sals
);
11961 init_sal (&sal
); /* Initialize to zeroes. */
11963 /* Set sal's line, symtab, pc, and pspace to the values
11964 corresponding to the last call to print_frame_info. If the
11965 codepoint is not valid, this will set all the fields to 0. */
11966 get_last_displayed_sal (&sal
);
11967 if (sal
.symtab
== 0)
11968 error (_("No source file specified."));
11970 sals
.sals
[0] = sal
;
11976 /* We don't call resolve_sal_pc here. That's not as bad as it
11977 seems, because all existing breakpoints typically have both
11978 file/line and pc set. So, if clear is given file/line, we can
11979 match this to existing breakpoint without obtaining pc at all.
11981 We only support clearing given the address explicitly
11982 present in breakpoint table. Say, we've set breakpoint
11983 at file:line. There were several PC values for that file:line,
11984 due to optimization, all in one block.
11986 We've picked one PC value. If "clear" is issued with another
11987 PC corresponding to the same file:line, the breakpoint won't
11988 be cleared. We probably can still clear the breakpoint, but
11989 since the other PC value is never presented to user, user
11990 can only find it by guessing, and it does not seem important
11991 to support that. */
11993 /* For each line spec given, delete bps which correspond to it. Do
11994 it in two passes, solely to preserve the current behavior that
11995 from_tty is forced true if we delete more than one
11999 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12000 for (i
= 0; i
< sals
.nelts
; i
++)
12002 const char *sal_fullname
;
12004 /* If exact pc given, clear bpts at that pc.
12005 If line given (pc == 0), clear all bpts on specified line.
12006 If defaulting, clear all bpts on default line
12009 defaulting sal.pc != 0 tests to do
12014 1 0 <can't happen> */
12016 sal
= sals
.sals
[i
];
12017 sal_fullname
= (sal
.symtab
== NULL
12018 ? NULL
: symtab_to_fullname (sal
.symtab
));
12020 /* Find all matching breakpoints and add them to 'found'. */
12021 ALL_BREAKPOINTS (b
)
12024 /* Are we going to delete b? */
12025 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12027 struct bp_location
*loc
= b
->loc
;
12028 for (; loc
; loc
= loc
->next
)
12030 /* If the user specified file:line, don't allow a PC
12031 match. This matches historical gdb behavior. */
12032 int pc_match
= (!sal
.explicit_line
12034 && (loc
->pspace
== sal
.pspace
)
12035 && (loc
->address
== sal
.pc
)
12036 && (!section_is_overlay (loc
->section
)
12037 || loc
->section
== sal
.section
));
12038 int line_match
= 0;
12040 if ((default_match
|| sal
.explicit_line
)
12041 && loc
->symtab
!= NULL
12042 && sal_fullname
!= NULL
12043 && sal
.pspace
== loc
->pspace
12044 && loc
->line_number
== sal
.line
12045 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12046 sal_fullname
) == 0)
12049 if (pc_match
|| line_match
)
12058 VEC_safe_push(breakpoint_p
, found
, b
);
12062 /* Now go thru the 'found' chain and delete them. */
12063 if (VEC_empty(breakpoint_p
, found
))
12066 error (_("No breakpoint at %s."), arg
);
12068 error (_("No breakpoint at this line."));
12071 /* Remove duplicates from the vec. */
12072 qsort (VEC_address (breakpoint_p
, found
),
12073 VEC_length (breakpoint_p
, found
),
12074 sizeof (breakpoint_p
),
12075 compare_breakpoints
);
12076 prev
= VEC_index (breakpoint_p
, found
, 0);
12077 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12081 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12086 if (VEC_length(breakpoint_p
, found
) > 1)
12087 from_tty
= 1; /* Always report if deleted more than one. */
12090 if (VEC_length(breakpoint_p
, found
) == 1)
12091 printf_unfiltered (_("Deleted breakpoint "));
12093 printf_unfiltered (_("Deleted breakpoints "));
12096 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12099 printf_unfiltered ("%d ", b
->number
);
12100 delete_breakpoint (b
);
12103 putchar_unfiltered ('\n');
12105 do_cleanups (cleanups
);
12108 /* Delete breakpoint in BS if they are `delete' breakpoints and
12109 all breakpoints that are marked for deletion, whether hit or not.
12110 This is called after any breakpoint is hit, or after errors. */
12113 breakpoint_auto_delete (bpstat bs
)
12115 struct breakpoint
*b
, *b_tmp
;
12117 for (; bs
; bs
= bs
->next
)
12118 if (bs
->breakpoint_at
12119 && bs
->breakpoint_at
->disposition
== disp_del
12121 delete_breakpoint (bs
->breakpoint_at
);
12123 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12125 if (b
->disposition
== disp_del_at_next_stop
)
12126 delete_breakpoint (b
);
12130 /* A comparison function for bp_location AP and BP being interfaced to
12131 qsort. Sort elements primarily by their ADDRESS (no matter what
12132 does breakpoint_address_is_meaningful say for its OWNER),
12133 secondarily by ordering first permanent elements and
12134 terciarily just ensuring the array is sorted stable way despite
12135 qsort being an unstable algorithm. */
12138 bp_locations_compare (const void *ap
, const void *bp
)
12140 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12141 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12143 if (a
->address
!= b
->address
)
12144 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12146 /* Sort locations at the same address by their pspace number, keeping
12147 locations of the same inferior (in a multi-inferior environment)
12150 if (a
->pspace
->num
!= b
->pspace
->num
)
12151 return ((a
->pspace
->num
> b
->pspace
->num
)
12152 - (a
->pspace
->num
< b
->pspace
->num
));
12154 /* Sort permanent breakpoints first. */
12155 if (a
->permanent
!= b
->permanent
)
12156 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12158 /* Make the internal GDB representation stable across GDB runs
12159 where A and B memory inside GDB can differ. Breakpoint locations of
12160 the same type at the same address can be sorted in arbitrary order. */
12162 if (a
->owner
->number
!= b
->owner
->number
)
12163 return ((a
->owner
->number
> b
->owner
->number
)
12164 - (a
->owner
->number
< b
->owner
->number
));
12166 return (a
> b
) - (a
< b
);
12169 /* Set bp_locations_placed_address_before_address_max and
12170 bp_locations_shadow_len_after_address_max according to the current
12171 content of the bp_locations array. */
12174 bp_locations_target_extensions_update (void)
12176 struct bp_location
*bl
, **blp_tmp
;
12178 bp_locations_placed_address_before_address_max
= 0;
12179 bp_locations_shadow_len_after_address_max
= 0;
12181 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12183 CORE_ADDR start
, end
, addr
;
12185 if (!bp_location_has_shadow (bl
))
12188 start
= bl
->target_info
.placed_address
;
12189 end
= start
+ bl
->target_info
.shadow_len
;
12191 gdb_assert (bl
->address
>= start
);
12192 addr
= bl
->address
- start
;
12193 if (addr
> bp_locations_placed_address_before_address_max
)
12194 bp_locations_placed_address_before_address_max
= addr
;
12196 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12198 gdb_assert (bl
->address
< end
);
12199 addr
= end
- bl
->address
;
12200 if (addr
> bp_locations_shadow_len_after_address_max
)
12201 bp_locations_shadow_len_after_address_max
= addr
;
12205 /* Download tracepoint locations if they haven't been. */
12208 download_tracepoint_locations (void)
12210 struct breakpoint
*b
;
12211 struct cleanup
*old_chain
;
12212 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12214 old_chain
= save_current_space_and_thread ();
12216 ALL_TRACEPOINTS (b
)
12218 struct bp_location
*bl
;
12219 struct tracepoint
*t
;
12220 int bp_location_downloaded
= 0;
12222 if ((b
->type
== bp_fast_tracepoint
12223 ? !may_insert_fast_tracepoints
12224 : !may_insert_tracepoints
))
12227 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12229 if (target_can_download_tracepoint ())
12230 can_download_tracepoint
= TRIBOOL_TRUE
;
12232 can_download_tracepoint
= TRIBOOL_FALSE
;
12235 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12238 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12240 /* In tracepoint, locations are _never_ duplicated, so
12241 should_be_inserted is equivalent to
12242 unduplicated_should_be_inserted. */
12243 if (!should_be_inserted (bl
) || bl
->inserted
)
12246 switch_to_program_space_and_thread (bl
->pspace
);
12248 target_download_tracepoint (bl
);
12251 bp_location_downloaded
= 1;
12253 t
= (struct tracepoint
*) b
;
12254 t
->number_on_target
= b
->number
;
12255 if (bp_location_downloaded
)
12256 observer_notify_breakpoint_modified (b
);
12259 do_cleanups (old_chain
);
12262 /* Swap the insertion/duplication state between two locations. */
12265 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12267 const int left_inserted
= left
->inserted
;
12268 const int left_duplicate
= left
->duplicate
;
12269 const int left_needs_update
= left
->needs_update
;
12270 const struct bp_target_info left_target_info
= left
->target_info
;
12272 /* Locations of tracepoints can never be duplicated. */
12273 if (is_tracepoint (left
->owner
))
12274 gdb_assert (!left
->duplicate
);
12275 if (is_tracepoint (right
->owner
))
12276 gdb_assert (!right
->duplicate
);
12278 left
->inserted
= right
->inserted
;
12279 left
->duplicate
= right
->duplicate
;
12280 left
->needs_update
= right
->needs_update
;
12281 left
->target_info
= right
->target_info
;
12282 right
->inserted
= left_inserted
;
12283 right
->duplicate
= left_duplicate
;
12284 right
->needs_update
= left_needs_update
;
12285 right
->target_info
= left_target_info
;
12288 /* Force the re-insertion of the locations at ADDRESS. This is called
12289 once a new/deleted/modified duplicate location is found and we are evaluating
12290 conditions on the target's side. Such conditions need to be updated on
12294 force_breakpoint_reinsertion (struct bp_location
*bl
)
12296 struct bp_location
**locp
= NULL
, **loc2p
;
12297 struct bp_location
*loc
;
12298 CORE_ADDR address
= 0;
12301 address
= bl
->address
;
12302 pspace_num
= bl
->pspace
->num
;
12304 /* This is only meaningful if the target is
12305 evaluating conditions and if the user has
12306 opted for condition evaluation on the target's
12308 if (gdb_evaluates_breakpoint_condition_p ()
12309 || !target_supports_evaluation_of_breakpoint_conditions ())
12312 /* Flag all breakpoint locations with this address and
12313 the same program space as the location
12314 as "its condition has changed". We need to
12315 update the conditions on the target's side. */
12316 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12320 if (!is_breakpoint (loc
->owner
)
12321 || pspace_num
!= loc
->pspace
->num
)
12324 /* Flag the location appropriately. We use a different state to
12325 let everyone know that we already updated the set of locations
12326 with addr bl->address and program space bl->pspace. This is so
12327 we don't have to keep calling these functions just to mark locations
12328 that have already been marked. */
12329 loc
->condition_changed
= condition_updated
;
12331 /* Free the agent expression bytecode as well. We will compute
12333 loc
->cond_bytecode
.reset ();
12336 /* Called whether new breakpoints are created, or existing breakpoints
12337 deleted, to update the global location list and recompute which
12338 locations are duplicate of which.
12340 The INSERT_MODE flag determines whether locations may not, may, or
12341 shall be inserted now. See 'enum ugll_insert_mode' for more
12345 update_global_location_list (enum ugll_insert_mode insert_mode
)
12347 struct breakpoint
*b
;
12348 struct bp_location
**locp
, *loc
;
12349 struct cleanup
*cleanups
;
12350 /* Last breakpoint location address that was marked for update. */
12351 CORE_ADDR last_addr
= 0;
12352 /* Last breakpoint location program space that was marked for update. */
12353 int last_pspace_num
= -1;
12355 /* Used in the duplicates detection below. When iterating over all
12356 bp_locations, points to the first bp_location of a given address.
12357 Breakpoints and watchpoints of different types are never
12358 duplicates of each other. Keep one pointer for each type of
12359 breakpoint/watchpoint, so we only need to loop over all locations
12361 struct bp_location
*bp_loc_first
; /* breakpoint */
12362 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12363 struct bp_location
*awp_loc_first
; /* access watchpoint */
12364 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12366 /* Saved former bp_locations array which we compare against the newly
12367 built bp_locations from the current state of ALL_BREAKPOINTS. */
12368 struct bp_location
**old_locations
, **old_locp
;
12369 unsigned old_locations_count
;
12371 old_locations
= bp_locations
;
12372 old_locations_count
= bp_locations_count
;
12373 bp_locations
= NULL
;
12374 bp_locations_count
= 0;
12375 cleanups
= make_cleanup (xfree
, old_locations
);
12377 ALL_BREAKPOINTS (b
)
12378 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12379 bp_locations_count
++;
12381 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12382 locp
= bp_locations
;
12383 ALL_BREAKPOINTS (b
)
12384 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12386 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12387 bp_locations_compare
);
12389 bp_locations_target_extensions_update ();
12391 /* Identify bp_location instances that are no longer present in the
12392 new list, and therefore should be freed. Note that it's not
12393 necessary that those locations should be removed from inferior --
12394 if there's another location at the same address (previously
12395 marked as duplicate), we don't need to remove/insert the
12398 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12399 and former bp_location array state respectively. */
12401 locp
= bp_locations
;
12402 for (old_locp
= old_locations
;
12403 old_locp
< old_locations
+ old_locations_count
;
12406 struct bp_location
*old_loc
= *old_locp
;
12407 struct bp_location
**loc2p
;
12409 /* Tells if 'old_loc' is found among the new locations. If
12410 not, we have to free it. */
12411 int found_object
= 0;
12412 /* Tells if the location should remain inserted in the target. */
12413 int keep_in_target
= 0;
12416 /* Skip LOCP entries which will definitely never be needed.
12417 Stop either at or being the one matching OLD_LOC. */
12418 while (locp
< bp_locations
+ bp_locations_count
12419 && (*locp
)->address
< old_loc
->address
)
12423 (loc2p
< bp_locations
+ bp_locations_count
12424 && (*loc2p
)->address
== old_loc
->address
);
12427 /* Check if this is a new/duplicated location or a duplicated
12428 location that had its condition modified. If so, we want to send
12429 its condition to the target if evaluation of conditions is taking
12431 if ((*loc2p
)->condition_changed
== condition_modified
12432 && (last_addr
!= old_loc
->address
12433 || last_pspace_num
!= old_loc
->pspace
->num
))
12435 force_breakpoint_reinsertion (*loc2p
);
12436 last_pspace_num
= old_loc
->pspace
->num
;
12439 if (*loc2p
== old_loc
)
12443 /* We have already handled this address, update it so that we don't
12444 have to go through updates again. */
12445 last_addr
= old_loc
->address
;
12447 /* Target-side condition evaluation: Handle deleted locations. */
12449 force_breakpoint_reinsertion (old_loc
);
12451 /* If this location is no longer present, and inserted, look if
12452 there's maybe a new location at the same address. If so,
12453 mark that one inserted, and don't remove this one. This is
12454 needed so that we don't have a time window where a breakpoint
12455 at certain location is not inserted. */
12457 if (old_loc
->inserted
)
12459 /* If the location is inserted now, we might have to remove
12462 if (found_object
&& should_be_inserted (old_loc
))
12464 /* The location is still present in the location list,
12465 and still should be inserted. Don't do anything. */
12466 keep_in_target
= 1;
12470 /* This location still exists, but it won't be kept in the
12471 target since it may have been disabled. We proceed to
12472 remove its target-side condition. */
12474 /* The location is either no longer present, or got
12475 disabled. See if there's another location at the
12476 same address, in which case we don't need to remove
12477 this one from the target. */
12479 /* OLD_LOC comes from existing struct breakpoint. */
12480 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12483 (loc2p
< bp_locations
+ bp_locations_count
12484 && (*loc2p
)->address
== old_loc
->address
);
12487 struct bp_location
*loc2
= *loc2p
;
12489 if (breakpoint_locations_match (loc2
, old_loc
))
12491 /* Read watchpoint locations are switched to
12492 access watchpoints, if the former are not
12493 supported, but the latter are. */
12494 if (is_hardware_watchpoint (old_loc
->owner
))
12496 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12497 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12500 /* loc2 is a duplicated location. We need to check
12501 if it should be inserted in case it will be
12503 if (loc2
!= old_loc
12504 && unduplicated_should_be_inserted (loc2
))
12506 swap_insertion (old_loc
, loc2
);
12507 keep_in_target
= 1;
12515 if (!keep_in_target
)
12517 if (remove_breakpoint (old_loc
))
12519 /* This is just about all we can do. We could keep
12520 this location on the global list, and try to
12521 remove it next time, but there's no particular
12522 reason why we will succeed next time.
12524 Note that at this point, old_loc->owner is still
12525 valid, as delete_breakpoint frees the breakpoint
12526 only after calling us. */
12527 printf_filtered (_("warning: Error removing "
12528 "breakpoint %d\n"),
12529 old_loc
->owner
->number
);
12537 if (removed
&& target_is_non_stop_p ()
12538 && need_moribund_for_location_type (old_loc
))
12540 /* This location was removed from the target. In
12541 non-stop mode, a race condition is possible where
12542 we've removed a breakpoint, but stop events for that
12543 breakpoint are already queued and will arrive later.
12544 We apply an heuristic to be able to distinguish such
12545 SIGTRAPs from other random SIGTRAPs: we keep this
12546 breakpoint location for a bit, and will retire it
12547 after we see some number of events. The theory here
12548 is that reporting of events should, "on the average",
12549 be fair, so after a while we'll see events from all
12550 threads that have anything of interest, and no longer
12551 need to keep this breakpoint location around. We
12552 don't hold locations forever so to reduce chances of
12553 mistaking a non-breakpoint SIGTRAP for a breakpoint
12556 The heuristic failing can be disastrous on
12557 decr_pc_after_break targets.
12559 On decr_pc_after_break targets, like e.g., x86-linux,
12560 if we fail to recognize a late breakpoint SIGTRAP,
12561 because events_till_retirement has reached 0 too
12562 soon, we'll fail to do the PC adjustment, and report
12563 a random SIGTRAP to the user. When the user resumes
12564 the inferior, it will most likely immediately crash
12565 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12566 corrupted, because of being resumed e.g., in the
12567 middle of a multi-byte instruction, or skipped a
12568 one-byte instruction. This was actually seen happen
12569 on native x86-linux, and should be less rare on
12570 targets that do not support new thread events, like
12571 remote, due to the heuristic depending on
12574 Mistaking a random SIGTRAP for a breakpoint trap
12575 causes similar symptoms (PC adjustment applied when
12576 it shouldn't), but then again, playing with SIGTRAPs
12577 behind the debugger's back is asking for trouble.
12579 Since hardware watchpoint traps are always
12580 distinguishable from other traps, so we don't need to
12581 apply keep hardware watchpoint moribund locations
12582 around. We simply always ignore hardware watchpoint
12583 traps we can no longer explain. */
12585 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12586 old_loc
->owner
= NULL
;
12588 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12592 old_loc
->owner
= NULL
;
12593 decref_bp_location (&old_loc
);
12598 /* Rescan breakpoints at the same address and section, marking the
12599 first one as "first" and any others as "duplicates". This is so
12600 that the bpt instruction is only inserted once. If we have a
12601 permanent breakpoint at the same place as BPT, make that one the
12602 official one, and the rest as duplicates. Permanent breakpoints
12603 are sorted first for the same address.
12605 Do the same for hardware watchpoints, but also considering the
12606 watchpoint's type (regular/access/read) and length. */
12608 bp_loc_first
= NULL
;
12609 wp_loc_first
= NULL
;
12610 awp_loc_first
= NULL
;
12611 rwp_loc_first
= NULL
;
12612 ALL_BP_LOCATIONS (loc
, locp
)
12614 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12616 struct bp_location
**loc_first_p
;
12619 if (!unduplicated_should_be_inserted (loc
)
12620 || !breakpoint_address_is_meaningful (b
)
12621 /* Don't detect duplicate for tracepoint locations because they are
12622 never duplicated. See the comments in field `duplicate' of
12623 `struct bp_location'. */
12624 || is_tracepoint (b
))
12626 /* Clear the condition modification flag. */
12627 loc
->condition_changed
= condition_unchanged
;
12631 if (b
->type
== bp_hardware_watchpoint
)
12632 loc_first_p
= &wp_loc_first
;
12633 else if (b
->type
== bp_read_watchpoint
)
12634 loc_first_p
= &rwp_loc_first
;
12635 else if (b
->type
== bp_access_watchpoint
)
12636 loc_first_p
= &awp_loc_first
;
12638 loc_first_p
= &bp_loc_first
;
12640 if (*loc_first_p
== NULL
12641 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12642 || !breakpoint_locations_match (loc
, *loc_first_p
))
12644 *loc_first_p
= loc
;
12645 loc
->duplicate
= 0;
12647 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12649 loc
->needs_update
= 1;
12650 /* Clear the condition modification flag. */
12651 loc
->condition_changed
= condition_unchanged
;
12657 /* This and the above ensure the invariant that the first location
12658 is not duplicated, and is the inserted one.
12659 All following are marked as duplicated, and are not inserted. */
12661 swap_insertion (loc
, *loc_first_p
);
12662 loc
->duplicate
= 1;
12664 /* Clear the condition modification flag. */
12665 loc
->condition_changed
= condition_unchanged
;
12668 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12670 if (insert_mode
!= UGLL_DONT_INSERT
)
12671 insert_breakpoint_locations ();
12674 /* Even though the caller told us to not insert new
12675 locations, we may still need to update conditions on the
12676 target's side of breakpoints that were already inserted
12677 if the target is evaluating breakpoint conditions. We
12678 only update conditions for locations that are marked
12680 update_inserted_breakpoint_locations ();
12684 if (insert_mode
!= UGLL_DONT_INSERT
)
12685 download_tracepoint_locations ();
12687 do_cleanups (cleanups
);
12691 breakpoint_retire_moribund (void)
12693 struct bp_location
*loc
;
12696 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12697 if (--(loc
->events_till_retirement
) == 0)
12699 decref_bp_location (&loc
);
12700 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12706 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12711 update_global_location_list (insert_mode
);
12713 CATCH (e
, RETURN_MASK_ERROR
)
12719 /* Clear BKP from a BPS. */
12722 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12726 for (bs
= bps
; bs
; bs
= bs
->next
)
12727 if (bs
->breakpoint_at
== bpt
)
12729 bs
->breakpoint_at
= NULL
;
12730 bs
->old_val
= NULL
;
12731 /* bs->commands will be freed later. */
12735 /* Callback for iterate_over_threads. */
12737 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12739 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12741 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12745 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12749 say_where (struct breakpoint
*b
)
12751 struct value_print_options opts
;
12753 get_user_print_options (&opts
);
12755 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12757 if (b
->loc
== NULL
)
12759 /* For pending locations, the output differs slightly based
12760 on b->extra_string. If this is non-NULL, it contains either
12761 a condition or dprintf arguments. */
12762 if (b
->extra_string
== NULL
)
12764 printf_filtered (_(" (%s) pending."),
12765 event_location_to_string (b
->location
.get ()));
12767 else if (b
->type
== bp_dprintf
)
12769 printf_filtered (_(" (%s,%s) pending."),
12770 event_location_to_string (b
->location
.get ()),
12775 printf_filtered (_(" (%s %s) pending."),
12776 event_location_to_string (b
->location
.get ()),
12782 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12784 printf_filtered (" at ");
12785 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12788 if (b
->loc
->symtab
!= NULL
)
12790 /* If there is a single location, we can print the location
12792 if (b
->loc
->next
== NULL
)
12793 printf_filtered (": file %s, line %d.",
12794 symtab_to_filename_for_display (b
->loc
->symtab
),
12795 b
->loc
->line_number
);
12797 /* This is not ideal, but each location may have a
12798 different file name, and this at least reflects the
12799 real situation somewhat. */
12800 printf_filtered (": %s.",
12801 event_location_to_string (b
->location
.get ()));
12806 struct bp_location
*loc
= b
->loc
;
12808 for (; loc
; loc
= loc
->next
)
12810 printf_filtered (" (%d locations)", n
);
12815 /* Default bp_location_ops methods. */
12818 bp_location_dtor (struct bp_location
*self
)
12820 xfree (self
->function_name
);
12823 static const struct bp_location_ops bp_location_ops
=
12828 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12832 base_breakpoint_dtor (struct breakpoint
*self
)
12834 decref_counted_command_line (&self
->commands
);
12835 xfree (self
->cond_string
);
12836 xfree (self
->extra_string
);
12837 xfree (self
->filter
);
12840 static struct bp_location
*
12841 base_breakpoint_allocate_location (struct breakpoint
*self
)
12843 struct bp_location
*loc
;
12845 loc
= new struct bp_location ();
12846 init_bp_location (loc
, &bp_location_ops
, self
);
12851 base_breakpoint_re_set (struct breakpoint
*b
)
12853 /* Nothing to re-set. */
12856 #define internal_error_pure_virtual_called() \
12857 gdb_assert_not_reached ("pure virtual function called")
12860 base_breakpoint_insert_location (struct bp_location
*bl
)
12862 internal_error_pure_virtual_called ();
12866 base_breakpoint_remove_location (struct bp_location
*bl
,
12867 enum remove_bp_reason reason
)
12869 internal_error_pure_virtual_called ();
12873 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12874 struct address_space
*aspace
,
12876 const struct target_waitstatus
*ws
)
12878 internal_error_pure_virtual_called ();
12882 base_breakpoint_check_status (bpstat bs
)
12887 /* A "works_in_software_mode" breakpoint_ops method that just internal
12891 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12893 internal_error_pure_virtual_called ();
12896 /* A "resources_needed" breakpoint_ops method that just internal
12900 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12902 internal_error_pure_virtual_called ();
12905 static enum print_stop_action
12906 base_breakpoint_print_it (bpstat bs
)
12908 internal_error_pure_virtual_called ();
12912 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12913 struct ui_out
*uiout
)
12919 base_breakpoint_print_mention (struct breakpoint
*b
)
12921 internal_error_pure_virtual_called ();
12925 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12927 internal_error_pure_virtual_called ();
12931 base_breakpoint_create_sals_from_location
12932 (const struct event_location
*location
,
12933 struct linespec_result
*canonical
,
12934 enum bptype type_wanted
)
12936 internal_error_pure_virtual_called ();
12940 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12941 struct linespec_result
*c
,
12943 char *extra_string
,
12944 enum bptype type_wanted
,
12945 enum bpdisp disposition
,
12947 int task
, int ignore_count
,
12948 const struct breakpoint_ops
*o
,
12949 int from_tty
, int enabled
,
12950 int internal
, unsigned flags
)
12952 internal_error_pure_virtual_called ();
12956 base_breakpoint_decode_location (struct breakpoint
*b
,
12957 const struct event_location
*location
,
12958 struct program_space
*search_pspace
,
12959 struct symtabs_and_lines
*sals
)
12961 internal_error_pure_virtual_called ();
12964 /* The default 'explains_signal' method. */
12967 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12972 /* The default "after_condition_true" method. */
12975 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12977 /* Nothing to do. */
12980 struct breakpoint_ops base_breakpoint_ops
=
12982 base_breakpoint_dtor
,
12983 base_breakpoint_allocate_location
,
12984 base_breakpoint_re_set
,
12985 base_breakpoint_insert_location
,
12986 base_breakpoint_remove_location
,
12987 base_breakpoint_breakpoint_hit
,
12988 base_breakpoint_check_status
,
12989 base_breakpoint_resources_needed
,
12990 base_breakpoint_works_in_software_mode
,
12991 base_breakpoint_print_it
,
12993 base_breakpoint_print_one_detail
,
12994 base_breakpoint_print_mention
,
12995 base_breakpoint_print_recreate
,
12996 base_breakpoint_create_sals_from_location
,
12997 base_breakpoint_create_breakpoints_sal
,
12998 base_breakpoint_decode_location
,
12999 base_breakpoint_explains_signal
,
13000 base_breakpoint_after_condition_true
,
13003 /* Default breakpoint_ops methods. */
13006 bkpt_re_set (struct breakpoint
*b
)
13008 /* FIXME: is this still reachable? */
13009 if (breakpoint_event_location_empty_p (b
))
13011 /* Anything without a location can't be re-set. */
13012 delete_breakpoint (b
);
13016 breakpoint_re_set_default (b
);
13020 bkpt_insert_location (struct bp_location
*bl
)
13022 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
13024 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
13025 bl
->target_info
.placed_address
= addr
;
13027 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13028 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13030 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13034 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13036 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13037 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13039 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13043 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13044 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13045 const struct target_waitstatus
*ws
)
13047 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13048 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13051 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13055 if (overlay_debugging
/* unmapped overlay section */
13056 && section_is_overlay (bl
->section
)
13057 && !section_is_mapped (bl
->section
))
13064 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13065 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13066 const struct target_waitstatus
*ws
)
13068 if (dprintf_style
== dprintf_style_agent
13069 && target_can_run_breakpoint_commands ())
13071 /* An agent-style dprintf never causes a stop. If we see a trap
13072 for this address it must be for a breakpoint that happens to
13073 be set at the same address. */
13077 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13081 bkpt_resources_needed (const struct bp_location
*bl
)
13083 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13088 static enum print_stop_action
13089 bkpt_print_it (bpstat bs
)
13091 struct breakpoint
*b
;
13092 const struct bp_location
*bl
;
13094 struct ui_out
*uiout
= current_uiout
;
13096 gdb_assert (bs
->bp_location_at
!= NULL
);
13098 bl
= bs
->bp_location_at
;
13099 b
= bs
->breakpoint_at
;
13101 bp_temp
= b
->disposition
== disp_del
;
13102 if (bl
->address
!= bl
->requested_address
)
13103 breakpoint_adjustment_warning (bl
->requested_address
,
13106 annotate_breakpoint (b
->number
);
13107 maybe_print_thread_hit_breakpoint (uiout
);
13110 uiout
->text ("Temporary breakpoint ");
13112 uiout
->text ("Breakpoint ");
13113 if (uiout
->is_mi_like_p ())
13115 uiout
->field_string ("reason",
13116 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13117 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
13119 uiout
->field_int ("bkptno", b
->number
);
13120 uiout
->text (", ");
13122 return PRINT_SRC_AND_LOC
;
13126 bkpt_print_mention (struct breakpoint
*b
)
13128 if (current_uiout
->is_mi_like_p ())
13133 case bp_breakpoint
:
13134 case bp_gnu_ifunc_resolver
:
13135 if (b
->disposition
== disp_del
)
13136 printf_filtered (_("Temporary breakpoint"));
13138 printf_filtered (_("Breakpoint"));
13139 printf_filtered (_(" %d"), b
->number
);
13140 if (b
->type
== bp_gnu_ifunc_resolver
)
13141 printf_filtered (_(" at gnu-indirect-function resolver"));
13143 case bp_hardware_breakpoint
:
13144 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13147 printf_filtered (_("Dprintf %d"), b
->number
);
13155 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13157 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13158 fprintf_unfiltered (fp
, "tbreak");
13159 else if (tp
->type
== bp_breakpoint
)
13160 fprintf_unfiltered (fp
, "break");
13161 else if (tp
->type
== bp_hardware_breakpoint
13162 && tp
->disposition
== disp_del
)
13163 fprintf_unfiltered (fp
, "thbreak");
13164 else if (tp
->type
== bp_hardware_breakpoint
)
13165 fprintf_unfiltered (fp
, "hbreak");
13167 internal_error (__FILE__
, __LINE__
,
13168 _("unhandled breakpoint type %d"), (int) tp
->type
);
13170 fprintf_unfiltered (fp
, " %s",
13171 event_location_to_string (tp
->location
.get ()));
13173 /* Print out extra_string if this breakpoint is pending. It might
13174 contain, for example, conditions that were set by the user. */
13175 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13176 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13178 print_recreate_thread (tp
, fp
);
13182 bkpt_create_sals_from_location (const struct event_location
*location
,
13183 struct linespec_result
*canonical
,
13184 enum bptype type_wanted
)
13186 create_sals_from_location_default (location
, canonical
, type_wanted
);
13190 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13191 struct linespec_result
*canonical
,
13193 char *extra_string
,
13194 enum bptype type_wanted
,
13195 enum bpdisp disposition
,
13197 int task
, int ignore_count
,
13198 const struct breakpoint_ops
*ops
,
13199 int from_tty
, int enabled
,
13200 int internal
, unsigned flags
)
13202 create_breakpoints_sal_default (gdbarch
, canonical
,
13203 cond_string
, extra_string
,
13205 disposition
, thread
, task
,
13206 ignore_count
, ops
, from_tty
,
13207 enabled
, internal
, flags
);
13211 bkpt_decode_location (struct breakpoint
*b
,
13212 const struct event_location
*location
,
13213 struct program_space
*search_pspace
,
13214 struct symtabs_and_lines
*sals
)
13216 decode_location_default (b
, location
, search_pspace
, sals
);
13219 /* Virtual table for internal breakpoints. */
13222 internal_bkpt_re_set (struct breakpoint
*b
)
13226 /* Delete overlay event and longjmp master breakpoints; they
13227 will be reset later by breakpoint_re_set. */
13228 case bp_overlay_event
:
13229 case bp_longjmp_master
:
13230 case bp_std_terminate_master
:
13231 case bp_exception_master
:
13232 delete_breakpoint (b
);
13235 /* This breakpoint is special, it's set up when the inferior
13236 starts and we really don't want to touch it. */
13237 case bp_shlib_event
:
13239 /* Like bp_shlib_event, this breakpoint type is special. Once
13240 it is set up, we do not want to touch it. */
13241 case bp_thread_event
:
13247 internal_bkpt_check_status (bpstat bs
)
13249 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13251 /* If requested, stop when the dynamic linker notifies GDB of
13252 events. This allows the user to get control and place
13253 breakpoints in initializer routines for dynamically loaded
13254 objects (among other things). */
13255 bs
->stop
= stop_on_solib_events
;
13256 bs
->print
= stop_on_solib_events
;
13262 static enum print_stop_action
13263 internal_bkpt_print_it (bpstat bs
)
13265 struct breakpoint
*b
;
13267 b
= bs
->breakpoint_at
;
13271 case bp_shlib_event
:
13272 /* Did we stop because the user set the stop_on_solib_events
13273 variable? (If so, we report this as a generic, "Stopped due
13274 to shlib event" message.) */
13275 print_solib_event (0);
13278 case bp_thread_event
:
13279 /* Not sure how we will get here.
13280 GDB should not stop for these breakpoints. */
13281 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13284 case bp_overlay_event
:
13285 /* By analogy with the thread event, GDB should not stop for these. */
13286 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13289 case bp_longjmp_master
:
13290 /* These should never be enabled. */
13291 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13294 case bp_std_terminate_master
:
13295 /* These should never be enabled. */
13296 printf_filtered (_("std::terminate Master Breakpoint: "
13297 "gdb should not stop!\n"));
13300 case bp_exception_master
:
13301 /* These should never be enabled. */
13302 printf_filtered (_("Exception Master Breakpoint: "
13303 "gdb should not stop!\n"));
13307 return PRINT_NOTHING
;
13311 internal_bkpt_print_mention (struct breakpoint
*b
)
13313 /* Nothing to mention. These breakpoints are internal. */
13316 /* Virtual table for momentary breakpoints */
13319 momentary_bkpt_re_set (struct breakpoint
*b
)
13321 /* Keep temporary breakpoints, which can be encountered when we step
13322 over a dlopen call and solib_add is resetting the breakpoints.
13323 Otherwise these should have been blown away via the cleanup chain
13324 or by breakpoint_init_inferior when we rerun the executable. */
13328 momentary_bkpt_check_status (bpstat bs
)
13330 /* Nothing. The point of these breakpoints is causing a stop. */
13333 static enum print_stop_action
13334 momentary_bkpt_print_it (bpstat bs
)
13336 return PRINT_UNKNOWN
;
13340 momentary_bkpt_print_mention (struct breakpoint
*b
)
13342 /* Nothing to mention. These breakpoints are internal. */
13345 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13347 It gets cleared already on the removal of the first one of such placed
13348 breakpoints. This is OK as they get all removed altogether. */
13351 longjmp_bkpt_dtor (struct breakpoint
*self
)
13353 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13356 tp
->initiating_frame
= null_frame_id
;
13358 momentary_breakpoint_ops
.dtor (self
);
13361 /* Specific methods for probe breakpoints. */
13364 bkpt_probe_insert_location (struct bp_location
*bl
)
13366 int v
= bkpt_insert_location (bl
);
13370 /* The insertion was successful, now let's set the probe's semaphore
13372 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13373 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13382 bkpt_probe_remove_location (struct bp_location
*bl
,
13383 enum remove_bp_reason reason
)
13385 /* Let's clear the semaphore before removing the location. */
13386 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13387 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13391 return bkpt_remove_location (bl
, reason
);
13395 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13396 struct linespec_result
*canonical
,
13397 enum bptype type_wanted
)
13399 struct linespec_sals lsal
;
13401 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13403 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13404 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13408 bkpt_probe_decode_location (struct breakpoint
*b
,
13409 const struct event_location
*location
,
13410 struct program_space
*search_pspace
,
13411 struct symtabs_and_lines
*sals
)
13413 *sals
= parse_probes (location
, search_pspace
, NULL
);
13415 error (_("probe not found"));
13418 /* The breakpoint_ops structure to be used in tracepoints. */
13421 tracepoint_re_set (struct breakpoint
*b
)
13423 breakpoint_re_set_default (b
);
13427 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13428 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13429 const struct target_waitstatus
*ws
)
13431 /* By definition, the inferior does not report stops at
13437 tracepoint_print_one_detail (const struct breakpoint
*self
,
13438 struct ui_out
*uiout
)
13440 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13441 if (tp
->static_trace_marker_id
)
13443 gdb_assert (self
->type
== bp_static_tracepoint
);
13445 uiout
->text ("\tmarker id is ");
13446 uiout
->field_string ("static-tracepoint-marker-string-id",
13447 tp
->static_trace_marker_id
);
13448 uiout
->text ("\n");
13453 tracepoint_print_mention (struct breakpoint
*b
)
13455 if (current_uiout
->is_mi_like_p ())
13460 case bp_tracepoint
:
13461 printf_filtered (_("Tracepoint"));
13462 printf_filtered (_(" %d"), b
->number
);
13464 case bp_fast_tracepoint
:
13465 printf_filtered (_("Fast tracepoint"));
13466 printf_filtered (_(" %d"), b
->number
);
13468 case bp_static_tracepoint
:
13469 printf_filtered (_("Static tracepoint"));
13470 printf_filtered (_(" %d"), b
->number
);
13473 internal_error (__FILE__
, __LINE__
,
13474 _("unhandled tracepoint type %d"), (int) b
->type
);
13481 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13483 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13485 if (self
->type
== bp_fast_tracepoint
)
13486 fprintf_unfiltered (fp
, "ftrace");
13487 else if (self
->type
== bp_static_tracepoint
)
13488 fprintf_unfiltered (fp
, "strace");
13489 else if (self
->type
== bp_tracepoint
)
13490 fprintf_unfiltered (fp
, "trace");
13492 internal_error (__FILE__
, __LINE__
,
13493 _("unhandled tracepoint type %d"), (int) self
->type
);
13495 fprintf_unfiltered (fp
, " %s",
13496 event_location_to_string (self
->location
.get ()));
13497 print_recreate_thread (self
, fp
);
13499 if (tp
->pass_count
)
13500 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13504 tracepoint_create_sals_from_location (const struct event_location
*location
,
13505 struct linespec_result
*canonical
,
13506 enum bptype type_wanted
)
13508 create_sals_from_location_default (location
, canonical
, type_wanted
);
13512 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13513 struct linespec_result
*canonical
,
13515 char *extra_string
,
13516 enum bptype type_wanted
,
13517 enum bpdisp disposition
,
13519 int task
, int ignore_count
,
13520 const struct breakpoint_ops
*ops
,
13521 int from_tty
, int enabled
,
13522 int internal
, unsigned flags
)
13524 create_breakpoints_sal_default (gdbarch
, canonical
,
13525 cond_string
, extra_string
,
13527 disposition
, thread
, task
,
13528 ignore_count
, ops
, from_tty
,
13529 enabled
, internal
, flags
);
13533 tracepoint_decode_location (struct breakpoint
*b
,
13534 const struct event_location
*location
,
13535 struct program_space
*search_pspace
,
13536 struct symtabs_and_lines
*sals
)
13538 decode_location_default (b
, location
, search_pspace
, sals
);
13541 struct breakpoint_ops tracepoint_breakpoint_ops
;
13543 /* The breakpoint_ops structure to be use on tracepoints placed in a
13547 tracepoint_probe_create_sals_from_location
13548 (const struct event_location
*location
,
13549 struct linespec_result
*canonical
,
13550 enum bptype type_wanted
)
13552 /* We use the same method for breakpoint on probes. */
13553 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13557 tracepoint_probe_decode_location (struct breakpoint
*b
,
13558 const struct event_location
*location
,
13559 struct program_space
*search_pspace
,
13560 struct symtabs_and_lines
*sals
)
13562 /* We use the same method for breakpoint on probes. */
13563 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13566 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13568 /* Dprintf breakpoint_ops methods. */
13571 dprintf_re_set (struct breakpoint
*b
)
13573 breakpoint_re_set_default (b
);
13575 /* extra_string should never be non-NULL for dprintf. */
13576 gdb_assert (b
->extra_string
!= NULL
);
13578 /* 1 - connect to target 1, that can run breakpoint commands.
13579 2 - create a dprintf, which resolves fine.
13580 3 - disconnect from target 1
13581 4 - connect to target 2, that can NOT run breakpoint commands.
13583 After steps #3/#4, you'll want the dprintf command list to
13584 be updated, because target 1 and 2 may well return different
13585 answers for target_can_run_breakpoint_commands().
13586 Given absence of finer grained resetting, we get to do
13587 it all the time. */
13588 if (b
->extra_string
!= NULL
)
13589 update_dprintf_command_list (b
);
13592 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13595 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13597 fprintf_unfiltered (fp
, "dprintf %s,%s",
13598 event_location_to_string (tp
->location
.get ()),
13600 print_recreate_thread (tp
, fp
);
13603 /* Implement the "after_condition_true" breakpoint_ops method for
13606 dprintf's are implemented with regular commands in their command
13607 list, but we run the commands here instead of before presenting the
13608 stop to the user, as dprintf's don't actually cause a stop. This
13609 also makes it so that the commands of multiple dprintfs at the same
13610 address are all handled. */
13613 dprintf_after_condition_true (struct bpstats
*bs
)
13615 struct cleanup
*old_chain
;
13616 struct bpstats tmp_bs
= { NULL
};
13617 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13619 /* dprintf's never cause a stop. This wasn't set in the
13620 check_status hook instead because that would make the dprintf's
13621 condition not be evaluated. */
13624 /* Run the command list here. Take ownership of it instead of
13625 copying. We never want these commands to run later in
13626 bpstat_do_actions, if a breakpoint that causes a stop happens to
13627 be set at same address as this dprintf, or even if running the
13628 commands here throws. */
13629 tmp_bs
.commands
= bs
->commands
;
13630 bs
->commands
= NULL
;
13631 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13633 bpstat_do_actions_1 (&tmp_bs_p
);
13635 /* 'tmp_bs.commands' will usually be NULL by now, but
13636 bpstat_do_actions_1 may return early without processing the whole
13638 do_cleanups (old_chain
);
13641 /* The breakpoint_ops structure to be used on static tracepoints with
13645 strace_marker_create_sals_from_location (const struct event_location
*location
,
13646 struct linespec_result
*canonical
,
13647 enum bptype type_wanted
)
13649 struct linespec_sals lsal
;
13650 const char *arg_start
, *arg
;
13652 struct cleanup
*cleanup
;
13654 arg
= arg_start
= get_linespec_location (location
);
13655 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13657 str
= savestring (arg_start
, arg
- arg_start
);
13658 cleanup
= make_cleanup (xfree
, str
);
13659 canonical
->location
= new_linespec_location (&str
);
13660 do_cleanups (cleanup
);
13663 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13664 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13668 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13669 struct linespec_result
*canonical
,
13671 char *extra_string
,
13672 enum bptype type_wanted
,
13673 enum bpdisp disposition
,
13675 int task
, int ignore_count
,
13676 const struct breakpoint_ops
*ops
,
13677 int from_tty
, int enabled
,
13678 int internal
, unsigned flags
)
13681 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13682 canonical
->sals
, 0);
13684 /* If the user is creating a static tracepoint by marker id
13685 (strace -m MARKER_ID), then store the sals index, so that
13686 breakpoint_re_set can try to match up which of the newly
13687 found markers corresponds to this one, and, don't try to
13688 expand multiple locations for each sal, given than SALS
13689 already should contain all sals for MARKER_ID. */
13691 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13693 struct symtabs_and_lines expanded
;
13694 struct tracepoint
*tp
;
13695 event_location_up location
;
13697 expanded
.nelts
= 1;
13698 expanded
.sals
= &lsal
->sals
.sals
[i
];
13700 location
= copy_event_location (canonical
->location
.get ());
13702 tp
= new tracepoint ();
13703 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13704 std::move (location
), NULL
,
13705 cond_string
, extra_string
,
13706 type_wanted
, disposition
,
13707 thread
, task
, ignore_count
, ops
,
13708 from_tty
, enabled
, internal
, flags
,
13709 canonical
->special_display
);
13710 /* Given that its possible to have multiple markers with
13711 the same string id, if the user is creating a static
13712 tracepoint by marker id ("strace -m MARKER_ID"), then
13713 store the sals index, so that breakpoint_re_set can
13714 try to match up which of the newly found markers
13715 corresponds to this one */
13716 tp
->static_trace_marker_id_idx
= i
;
13718 install_breakpoint (internal
, &tp
->base
, 0);
13723 strace_marker_decode_location (struct breakpoint
*b
,
13724 const struct event_location
*location
,
13725 struct program_space
*search_pspace
,
13726 struct symtabs_and_lines
*sals
)
13728 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13729 const char *s
= get_linespec_location (location
);
13731 *sals
= decode_static_tracepoint_spec (&s
);
13732 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13734 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13738 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13741 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13744 strace_marker_p (struct breakpoint
*b
)
13746 return b
->ops
== &strace_marker_breakpoint_ops
;
13749 /* Delete a breakpoint and clean up all traces of it in the data
13753 delete_breakpoint (struct breakpoint
*bpt
)
13755 struct breakpoint
*b
;
13757 gdb_assert (bpt
!= NULL
);
13759 /* Has this bp already been deleted? This can happen because
13760 multiple lists can hold pointers to bp's. bpstat lists are
13763 One example of this happening is a watchpoint's scope bp. When
13764 the scope bp triggers, we notice that the watchpoint is out of
13765 scope, and delete it. We also delete its scope bp. But the
13766 scope bp is marked "auto-deleting", and is already on a bpstat.
13767 That bpstat is then checked for auto-deleting bp's, which are
13770 A real solution to this problem might involve reference counts in
13771 bp's, and/or giving them pointers back to their referencing
13772 bpstat's, and teaching delete_breakpoint to only free a bp's
13773 storage when no more references were extent. A cheaper bandaid
13775 if (bpt
->type
== bp_none
)
13778 /* At least avoid this stale reference until the reference counting
13779 of breakpoints gets resolved. */
13780 if (bpt
->related_breakpoint
!= bpt
)
13782 struct breakpoint
*related
;
13783 struct watchpoint
*w
;
13785 if (bpt
->type
== bp_watchpoint_scope
)
13786 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13787 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13788 w
= (struct watchpoint
*) bpt
;
13792 watchpoint_del_at_next_stop (w
);
13794 /* Unlink bpt from the bpt->related_breakpoint ring. */
13795 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13796 related
= related
->related_breakpoint
);
13797 related
->related_breakpoint
= bpt
->related_breakpoint
;
13798 bpt
->related_breakpoint
= bpt
;
13801 /* watch_command_1 creates a watchpoint but only sets its number if
13802 update_watchpoint succeeds in creating its bp_locations. If there's
13803 a problem in that process, we'll be asked to delete the half-created
13804 watchpoint. In that case, don't announce the deletion. */
13806 observer_notify_breakpoint_deleted (bpt
);
13808 if (breakpoint_chain
== bpt
)
13809 breakpoint_chain
= bpt
->next
;
13811 ALL_BREAKPOINTS (b
)
13812 if (b
->next
== bpt
)
13814 b
->next
= bpt
->next
;
13818 /* Be sure no bpstat's are pointing at the breakpoint after it's
13820 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13821 in all threads for now. Note that we cannot just remove bpstats
13822 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13823 commands are associated with the bpstat; if we remove it here,
13824 then the later call to bpstat_do_actions (&stop_bpstat); in
13825 event-top.c won't do anything, and temporary breakpoints with
13826 commands won't work. */
13828 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13830 /* Now that breakpoint is removed from breakpoint list, update the
13831 global location list. This will remove locations that used to
13832 belong to this breakpoint. Do this before freeing the breakpoint
13833 itself, since remove_breakpoint looks at location's owner. It
13834 might be better design to have location completely
13835 self-contained, but it's not the case now. */
13836 update_global_location_list (UGLL_DONT_INSERT
);
13838 bpt
->ops
->dtor (bpt
);
13839 /* On the chance that someone will soon try again to delete this
13840 same bp, we mark it as deleted before freeing its storage. */
13841 bpt
->type
= bp_none
;
13846 do_delete_breakpoint_cleanup (void *b
)
13848 delete_breakpoint ((struct breakpoint
*) b
);
13852 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13854 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13857 /* Iterator function to call a user-provided callback function once
13858 for each of B and its related breakpoints. */
13861 iterate_over_related_breakpoints (struct breakpoint
*b
,
13862 void (*function
) (struct breakpoint
*,
13866 struct breakpoint
*related
;
13871 struct breakpoint
*next
;
13873 /* FUNCTION may delete RELATED. */
13874 next
= related
->related_breakpoint
;
13876 if (next
== related
)
13878 /* RELATED is the last ring entry. */
13879 function (related
, data
);
13881 /* FUNCTION may have deleted it, so we'd never reach back to
13882 B. There's nothing left to do anyway, so just break
13887 function (related
, data
);
13891 while (related
!= b
);
13895 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13897 delete_breakpoint (b
);
13900 /* A callback for map_breakpoint_numbers that calls
13901 delete_breakpoint. */
13904 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13906 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13910 delete_command (char *arg
, int from_tty
)
13912 struct breakpoint
*b
, *b_tmp
;
13918 int breaks_to_delete
= 0;
13920 /* Delete all breakpoints if no argument. Do not delete
13921 internal breakpoints, these have to be deleted with an
13922 explicit breakpoint number argument. */
13923 ALL_BREAKPOINTS (b
)
13924 if (user_breakpoint_p (b
))
13926 breaks_to_delete
= 1;
13930 /* Ask user only if there are some breakpoints to delete. */
13932 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13934 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13935 if (user_breakpoint_p (b
))
13936 delete_breakpoint (b
);
13940 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13943 /* Return true if all locations of B bound to PSPACE are pending. If
13944 PSPACE is NULL, all locations of all program spaces are
13948 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13950 struct bp_location
*loc
;
13952 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13953 if ((pspace
== NULL
13954 || loc
->pspace
== pspace
)
13955 && !loc
->shlib_disabled
13956 && !loc
->pspace
->executing_startup
)
13961 /* Subroutine of update_breakpoint_locations to simplify it.
13962 Return non-zero if multiple fns in list LOC have the same name.
13963 Null names are ignored. */
13966 ambiguous_names_p (struct bp_location
*loc
)
13968 struct bp_location
*l
;
13969 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13970 (int (*) (const void *,
13971 const void *)) streq
,
13972 NULL
, xcalloc
, xfree
);
13974 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13977 const char *name
= l
->function_name
;
13979 /* Allow for some names to be NULL, ignore them. */
13983 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13985 /* NOTE: We can assume slot != NULL here because xcalloc never
13989 htab_delete (htab
);
13995 htab_delete (htab
);
13999 /* When symbols change, it probably means the sources changed as well,
14000 and it might mean the static tracepoint markers are no longer at
14001 the same address or line numbers they used to be at last we
14002 checked. Losing your static tracepoints whenever you rebuild is
14003 undesirable. This function tries to resync/rematch gdb static
14004 tracepoints with the markers on the target, for static tracepoints
14005 that have not been set by marker id. Static tracepoint that have
14006 been set by marker id are reset by marker id in breakpoint_re_set.
14009 1) For a tracepoint set at a specific address, look for a marker at
14010 the old PC. If one is found there, assume to be the same marker.
14011 If the name / string id of the marker found is different from the
14012 previous known name, assume that means the user renamed the marker
14013 in the sources, and output a warning.
14015 2) For a tracepoint set at a given line number, look for a marker
14016 at the new address of the old line number. If one is found there,
14017 assume to be the same marker. If the name / string id of the
14018 marker found is different from the previous known name, assume that
14019 means the user renamed the marker in the sources, and output a
14022 3) If a marker is no longer found at the same address or line, it
14023 may mean the marker no longer exists. But it may also just mean
14024 the code changed a bit. Maybe the user added a few lines of code
14025 that made the marker move up or down (in line number terms). Ask
14026 the target for info about the marker with the string id as we knew
14027 it. If found, update line number and address in the matching
14028 static tracepoint. This will get confused if there's more than one
14029 marker with the same ID (possible in UST, although unadvised
14030 precisely because it confuses tools). */
14032 static struct symtab_and_line
14033 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14035 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14036 struct static_tracepoint_marker marker
;
14041 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14043 if (target_static_tracepoint_marker_at (pc
, &marker
))
14045 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14046 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14048 tp
->static_trace_marker_id
, marker
.str_id
);
14050 xfree (tp
->static_trace_marker_id
);
14051 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14052 release_static_tracepoint_marker (&marker
);
14057 /* Old marker wasn't found on target at lineno. Try looking it up
14059 if (!sal
.explicit_pc
14061 && sal
.symtab
!= NULL
14062 && tp
->static_trace_marker_id
!= NULL
)
14064 VEC(static_tracepoint_marker_p
) *markers
;
14067 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14069 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14071 struct symtab_and_line sal2
;
14072 struct symbol
*sym
;
14073 struct static_tracepoint_marker
*tpmarker
;
14074 struct ui_out
*uiout
= current_uiout
;
14075 struct explicit_location explicit_loc
;
14077 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14079 xfree (tp
->static_trace_marker_id
);
14080 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14082 warning (_("marker for static tracepoint %d (%s) not "
14083 "found at previous line number"),
14084 b
->number
, tp
->static_trace_marker_id
);
14088 sal2
.pc
= tpmarker
->address
;
14090 sal2
= find_pc_line (tpmarker
->address
, 0);
14091 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14092 uiout
->text ("Now in ");
14095 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
14096 uiout
->text (" at ");
14098 uiout
->field_string ("file",
14099 symtab_to_filename_for_display (sal2
.symtab
));
14102 if (uiout
->is_mi_like_p ())
14104 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14106 uiout
->field_string ("fullname", fullname
);
14109 uiout
->field_int ("line", sal2
.line
);
14110 uiout
->text ("\n");
14112 b
->loc
->line_number
= sal2
.line
;
14113 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14115 b
->location
.reset (NULL
);
14116 initialize_explicit_location (&explicit_loc
);
14117 explicit_loc
.source_filename
14118 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14119 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14120 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14121 b
->location
= new_explicit_location (&explicit_loc
);
14123 /* Might be nice to check if function changed, and warn if
14126 release_static_tracepoint_marker (tpmarker
);
14132 /* Returns 1 iff locations A and B are sufficiently same that
14133 we don't need to report breakpoint as changed. */
14136 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14140 if (a
->address
!= b
->address
)
14143 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14146 if (a
->enabled
!= b
->enabled
)
14153 if ((a
== NULL
) != (b
== NULL
))
14159 /* Split all locations of B that are bound to PSPACE out of B's
14160 location list to a separate list and return that list's head. If
14161 PSPACE is NULL, hoist out all locations of B. */
14163 static struct bp_location
*
14164 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14166 struct bp_location head
;
14167 struct bp_location
*i
= b
->loc
;
14168 struct bp_location
**i_link
= &b
->loc
;
14169 struct bp_location
*hoisted
= &head
;
14171 if (pspace
== NULL
)
14182 if (i
->pspace
== pspace
)
14197 /* Create new breakpoint locations for B (a hardware or software
14198 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14199 zero, then B is a ranged breakpoint. Only recreates locations for
14200 FILTER_PSPACE. Locations of other program spaces are left
14204 update_breakpoint_locations (struct breakpoint
*b
,
14205 struct program_space
*filter_pspace
,
14206 struct symtabs_and_lines sals
,
14207 struct symtabs_and_lines sals_end
)
14210 struct bp_location
*existing_locations
;
14212 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14214 /* Ranged breakpoints have only one start location and one end
14216 b
->enable_state
= bp_disabled
;
14217 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14218 "multiple locations found\n"),
14223 /* If there's no new locations, and all existing locations are
14224 pending, don't do anything. This optimizes the common case where
14225 all locations are in the same shared library, that was unloaded.
14226 We'd like to retain the location, so that when the library is
14227 loaded again, we don't loose the enabled/disabled status of the
14228 individual locations. */
14229 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14232 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14234 for (i
= 0; i
< sals
.nelts
; ++i
)
14236 struct bp_location
*new_loc
;
14238 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14240 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14242 /* Reparse conditions, they might contain references to the
14244 if (b
->cond_string
!= NULL
)
14248 s
= b
->cond_string
;
14251 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14252 block_for_pc (sals
.sals
[i
].pc
),
14255 CATCH (e
, RETURN_MASK_ERROR
)
14257 warning (_("failed to reevaluate condition "
14258 "for breakpoint %d: %s"),
14259 b
->number
, e
.message
);
14260 new_loc
->enabled
= 0;
14265 if (sals_end
.nelts
)
14267 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14269 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14273 /* If possible, carry over 'disable' status from existing
14276 struct bp_location
*e
= existing_locations
;
14277 /* If there are multiple breakpoints with the same function name,
14278 e.g. for inline functions, comparing function names won't work.
14279 Instead compare pc addresses; this is just a heuristic as things
14280 may have moved, but in practice it gives the correct answer
14281 often enough until a better solution is found. */
14282 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14284 for (; e
; e
= e
->next
)
14286 if (!e
->enabled
&& e
->function_name
)
14288 struct bp_location
*l
= b
->loc
;
14289 if (have_ambiguous_names
)
14291 for (; l
; l
= l
->next
)
14292 if (breakpoint_locations_match (e
, l
))
14300 for (; l
; l
= l
->next
)
14301 if (l
->function_name
14302 && strcmp (e
->function_name
, l
->function_name
) == 0)
14312 if (!locations_are_equal (existing_locations
, b
->loc
))
14313 observer_notify_breakpoint_modified (b
);
14316 /* Find the SaL locations corresponding to the given LOCATION.
14317 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14319 static struct symtabs_and_lines
14320 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14321 struct program_space
*search_pspace
, int *found
)
14323 struct symtabs_and_lines sals
= {0};
14324 struct gdb_exception exception
= exception_none
;
14326 gdb_assert (b
->ops
!= NULL
);
14330 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14332 CATCH (e
, RETURN_MASK_ERROR
)
14334 int not_found_and_ok
= 0;
14338 /* For pending breakpoints, it's expected that parsing will
14339 fail until the right shared library is loaded. User has
14340 already told to create pending breakpoints and don't need
14341 extra messages. If breakpoint is in bp_shlib_disabled
14342 state, then user already saw the message about that
14343 breakpoint being disabled, and don't want to see more
14345 if (e
.error
== NOT_FOUND_ERROR
14346 && (b
->condition_not_parsed
14348 && search_pspace
!= NULL
14349 && b
->loc
->pspace
!= search_pspace
)
14350 || (b
->loc
&& b
->loc
->shlib_disabled
)
14351 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14352 || b
->enable_state
== bp_disabled
))
14353 not_found_and_ok
= 1;
14355 if (!not_found_and_ok
)
14357 /* We surely don't want to warn about the same breakpoint
14358 10 times. One solution, implemented here, is disable
14359 the breakpoint on error. Another solution would be to
14360 have separate 'warning emitted' flag. Since this
14361 happens only when a binary has changed, I don't know
14362 which approach is better. */
14363 b
->enable_state
= bp_disabled
;
14364 throw_exception (e
);
14369 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14373 for (i
= 0; i
< sals
.nelts
; ++i
)
14374 resolve_sal_pc (&sals
.sals
[i
]);
14375 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14377 char *cond_string
, *extra_string
;
14380 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14381 &cond_string
, &thread
, &task
,
14383 gdb_assert (b
->cond_string
== NULL
);
14385 b
->cond_string
= cond_string
;
14386 b
->thread
= thread
;
14390 xfree (b
->extra_string
);
14391 b
->extra_string
= extra_string
;
14393 b
->condition_not_parsed
= 0;
14396 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14397 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14407 /* The default re_set method, for typical hardware or software
14408 breakpoints. Reevaluate the breakpoint and recreate its
14412 breakpoint_re_set_default (struct breakpoint
*b
)
14415 struct symtabs_and_lines sals
, sals_end
;
14416 struct symtabs_and_lines expanded
= {0};
14417 struct symtabs_and_lines expanded_end
= {0};
14418 struct program_space
*filter_pspace
= current_program_space
;
14420 sals
= location_to_sals (b
, b
->location
.get (), filter_pspace
, &found
);
14423 make_cleanup (xfree
, sals
.sals
);
14427 if (b
->location_range_end
!= NULL
)
14429 sals_end
= location_to_sals (b
, b
->location_range_end
.get (),
14430 filter_pspace
, &found
);
14433 make_cleanup (xfree
, sals_end
.sals
);
14434 expanded_end
= sals_end
;
14438 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14441 /* Default method for creating SALs from an address string. It basically
14442 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14445 create_sals_from_location_default (const struct event_location
*location
,
14446 struct linespec_result
*canonical
,
14447 enum bptype type_wanted
)
14449 parse_breakpoint_sals (location
, canonical
);
14452 /* Call create_breakpoints_sal for the given arguments. This is the default
14453 function for the `create_breakpoints_sal' method of
14457 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14458 struct linespec_result
*canonical
,
14460 char *extra_string
,
14461 enum bptype type_wanted
,
14462 enum bpdisp disposition
,
14464 int task
, int ignore_count
,
14465 const struct breakpoint_ops
*ops
,
14466 int from_tty
, int enabled
,
14467 int internal
, unsigned flags
)
14469 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14471 type_wanted
, disposition
,
14472 thread
, task
, ignore_count
, ops
, from_tty
,
14473 enabled
, internal
, flags
);
14476 /* Decode the line represented by S by calling decode_line_full. This is the
14477 default function for the `decode_location' method of breakpoint_ops. */
14480 decode_location_default (struct breakpoint
*b
,
14481 const struct event_location
*location
,
14482 struct program_space
*search_pspace
,
14483 struct symtabs_and_lines
*sals
)
14485 struct linespec_result canonical
;
14487 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14488 (struct symtab
*) NULL
, 0,
14489 &canonical
, multiple_symbols_all
,
14492 /* We should get 0 or 1 resulting SALs. */
14493 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14495 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14497 struct linespec_sals
*lsal
;
14499 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14500 *sals
= lsal
->sals
;
14501 /* Arrange it so the destructor does not free the
14503 lsal
->sals
.sals
= NULL
;
14507 /* Prepare the global context for a re-set of breakpoint B. */
14509 static struct cleanup
*
14510 prepare_re_set_context (struct breakpoint
*b
)
14512 input_radix
= b
->input_radix
;
14513 set_language (b
->language
);
14515 return make_cleanup (null_cleanup
, NULL
);
14518 /* Reset a breakpoint given it's struct breakpoint * BINT.
14519 The value we return ends up being the return value from catch_errors.
14520 Unused in this case. */
14523 breakpoint_re_set_one (void *bint
)
14525 /* Get past catch_errs. */
14526 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14527 struct cleanup
*cleanups
;
14529 cleanups
= prepare_re_set_context (b
);
14530 b
->ops
->re_set (b
);
14531 do_cleanups (cleanups
);
14535 /* Re-set breakpoint locations for the current program space.
14536 Locations bound to other program spaces are left untouched. */
14539 breakpoint_re_set (void)
14541 struct breakpoint
*b
, *b_tmp
;
14542 enum language save_language
;
14543 int save_input_radix
;
14544 struct cleanup
*old_chain
;
14546 save_language
= current_language
->la_language
;
14547 save_input_radix
= input_radix
;
14548 old_chain
= save_current_space_and_thread ();
14550 /* Note: we must not try to insert locations until after all
14551 breakpoints have been re-set. Otherwise, e.g., when re-setting
14552 breakpoint 1, we'd insert the locations of breakpoint 2, which
14553 hadn't been re-set yet, and thus may have stale locations. */
14555 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14557 /* Format possible error msg. */
14558 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14560 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14561 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14562 do_cleanups (cleanups
);
14564 set_language (save_language
);
14565 input_radix
= save_input_radix
;
14567 jit_breakpoint_re_set ();
14569 do_cleanups (old_chain
);
14571 create_overlay_event_breakpoint ();
14572 create_longjmp_master_breakpoint ();
14573 create_std_terminate_master_breakpoint ();
14574 create_exception_master_breakpoint ();
14576 /* Now we can insert. */
14577 update_global_location_list (UGLL_MAY_INSERT
);
14580 /* Reset the thread number of this breakpoint:
14582 - If the breakpoint is for all threads, leave it as-is.
14583 - Else, reset it to the current thread for inferior_ptid. */
14585 breakpoint_re_set_thread (struct breakpoint
*b
)
14587 if (b
->thread
!= -1)
14589 if (in_thread_list (inferior_ptid
))
14590 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14592 /* We're being called after following a fork. The new fork is
14593 selected as current, and unless this was a vfork will have a
14594 different program space from the original thread. Reset that
14596 b
->loc
->pspace
= current_program_space
;
14600 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14601 If from_tty is nonzero, it prints a message to that effect,
14602 which ends with a period (no newline). */
14605 set_ignore_count (int bptnum
, int count
, int from_tty
)
14607 struct breakpoint
*b
;
14612 ALL_BREAKPOINTS (b
)
14613 if (b
->number
== bptnum
)
14615 if (is_tracepoint (b
))
14617 if (from_tty
&& count
!= 0)
14618 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14623 b
->ignore_count
= count
;
14627 printf_filtered (_("Will stop next time "
14628 "breakpoint %d is reached."),
14630 else if (count
== 1)
14631 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14634 printf_filtered (_("Will ignore next %d "
14635 "crossings of breakpoint %d."),
14638 observer_notify_breakpoint_modified (b
);
14642 error (_("No breakpoint number %d."), bptnum
);
14645 /* Command to set ignore-count of breakpoint N to COUNT. */
14648 ignore_command (char *args
, int from_tty
)
14654 error_no_arg (_("a breakpoint number"));
14656 num
= get_number (&p
);
14658 error (_("bad breakpoint number: '%s'"), args
);
14660 error (_("Second argument (specified ignore-count) is missing."));
14662 set_ignore_count (num
,
14663 longest_to_int (value_as_long (parse_and_eval (p
))),
14666 printf_filtered ("\n");
14669 /* Call FUNCTION on each of the breakpoints
14670 whose numbers are given in ARGS. */
14673 map_breakpoint_numbers (const char *args
,
14674 void (*function
) (struct breakpoint
*,
14679 struct breakpoint
*b
, *tmp
;
14681 if (args
== 0 || *args
== '\0')
14682 error_no_arg (_("one or more breakpoint numbers"));
14684 number_or_range_parser
parser (args
);
14686 while (!parser
.finished ())
14688 const char *p
= parser
.cur_tok ();
14689 bool match
= false;
14691 num
= parser
.get_number ();
14694 warning (_("bad breakpoint number at or near '%s'"), p
);
14698 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14699 if (b
->number
== num
)
14702 function (b
, data
);
14706 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14711 static struct bp_location
*
14712 find_location_by_number (char *number
)
14714 char *dot
= strchr (number
, '.');
14718 struct breakpoint
*b
;
14719 struct bp_location
*loc
;
14724 bp_num
= get_number (&p1
);
14726 error (_("Bad breakpoint number '%s'"), number
);
14728 ALL_BREAKPOINTS (b
)
14729 if (b
->number
== bp_num
)
14734 if (!b
|| b
->number
!= bp_num
)
14735 error (_("Bad breakpoint number '%s'"), number
);
14738 loc_num
= get_number (&p1
);
14740 error (_("Bad breakpoint location number '%s'"), number
);
14744 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14747 error (_("Bad breakpoint location number '%s'"), dot
+1);
14753 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14754 If from_tty is nonzero, it prints a message to that effect,
14755 which ends with a period (no newline). */
14758 disable_breakpoint (struct breakpoint
*bpt
)
14760 /* Never disable a watchpoint scope breakpoint; we want to
14761 hit them when we leave scope so we can delete both the
14762 watchpoint and its scope breakpoint at that time. */
14763 if (bpt
->type
== bp_watchpoint_scope
)
14766 bpt
->enable_state
= bp_disabled
;
14768 /* Mark breakpoint locations modified. */
14769 mark_breakpoint_modified (bpt
);
14771 if (target_supports_enable_disable_tracepoint ()
14772 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14774 struct bp_location
*location
;
14776 for (location
= bpt
->loc
; location
; location
= location
->next
)
14777 target_disable_tracepoint (location
);
14780 update_global_location_list (UGLL_DONT_INSERT
);
14782 observer_notify_breakpoint_modified (bpt
);
14785 /* A callback for iterate_over_related_breakpoints. */
14788 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14790 disable_breakpoint (b
);
14793 /* A callback for map_breakpoint_numbers that calls
14794 disable_breakpoint. */
14797 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14799 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14803 disable_command (char *args
, int from_tty
)
14807 struct breakpoint
*bpt
;
14809 ALL_BREAKPOINTS (bpt
)
14810 if (user_breakpoint_p (bpt
))
14811 disable_breakpoint (bpt
);
14815 char *num
= extract_arg (&args
);
14819 if (strchr (num
, '.'))
14821 struct bp_location
*loc
= find_location_by_number (num
);
14828 mark_breakpoint_location_modified (loc
);
14830 if (target_supports_enable_disable_tracepoint ()
14831 && current_trace_status ()->running
&& loc
->owner
14832 && is_tracepoint (loc
->owner
))
14833 target_disable_tracepoint (loc
);
14835 update_global_location_list (UGLL_DONT_INSERT
);
14838 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14839 num
= extract_arg (&args
);
14845 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14848 int target_resources_ok
;
14850 if (bpt
->type
== bp_hardware_breakpoint
)
14853 i
= hw_breakpoint_used_count ();
14854 target_resources_ok
=
14855 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14857 if (target_resources_ok
== 0)
14858 error (_("No hardware breakpoint support in the target."));
14859 else if (target_resources_ok
< 0)
14860 error (_("Hardware breakpoints used exceeds limit."));
14863 if (is_watchpoint (bpt
))
14865 /* Initialize it just to avoid a GCC false warning. */
14866 enum enable_state orig_enable_state
= bp_disabled
;
14870 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14872 orig_enable_state
= bpt
->enable_state
;
14873 bpt
->enable_state
= bp_enabled
;
14874 update_watchpoint (w
, 1 /* reparse */);
14876 CATCH (e
, RETURN_MASK_ALL
)
14878 bpt
->enable_state
= orig_enable_state
;
14879 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14886 bpt
->enable_state
= bp_enabled
;
14888 /* Mark breakpoint locations modified. */
14889 mark_breakpoint_modified (bpt
);
14891 if (target_supports_enable_disable_tracepoint ()
14892 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14894 struct bp_location
*location
;
14896 for (location
= bpt
->loc
; location
; location
= location
->next
)
14897 target_enable_tracepoint (location
);
14900 bpt
->disposition
= disposition
;
14901 bpt
->enable_count
= count
;
14902 update_global_location_list (UGLL_MAY_INSERT
);
14904 observer_notify_breakpoint_modified (bpt
);
14909 enable_breakpoint (struct breakpoint
*bpt
)
14911 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14915 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14917 enable_breakpoint (bpt
);
14920 /* A callback for map_breakpoint_numbers that calls
14921 enable_breakpoint. */
14924 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14926 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14929 /* The enable command enables the specified breakpoints (or all defined
14930 breakpoints) so they once again become (or continue to be) effective
14931 in stopping the inferior. */
14934 enable_command (char *args
, int from_tty
)
14938 struct breakpoint
*bpt
;
14940 ALL_BREAKPOINTS (bpt
)
14941 if (user_breakpoint_p (bpt
))
14942 enable_breakpoint (bpt
);
14946 char *num
= extract_arg (&args
);
14950 if (strchr (num
, '.'))
14952 struct bp_location
*loc
= find_location_by_number (num
);
14959 mark_breakpoint_location_modified (loc
);
14961 if (target_supports_enable_disable_tracepoint ()
14962 && current_trace_status ()->running
&& loc
->owner
14963 && is_tracepoint (loc
->owner
))
14964 target_enable_tracepoint (loc
);
14966 update_global_location_list (UGLL_MAY_INSERT
);
14969 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14970 num
= extract_arg (&args
);
14975 /* This struct packages up disposition data for application to multiple
14985 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14987 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14989 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14993 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14995 struct disp_data disp
= { disp_disable
, 1 };
14997 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15001 enable_once_command (char *args
, int from_tty
)
15003 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15007 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15009 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15011 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15015 enable_count_command (char *args
, int from_tty
)
15020 error_no_arg (_("hit count"));
15022 count
= get_number (&args
);
15024 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15028 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15030 struct disp_data disp
= { disp_del
, 1 };
15032 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15036 enable_delete_command (char *args
, int from_tty
)
15038 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15042 set_breakpoint_cmd (char *args
, int from_tty
)
15047 show_breakpoint_cmd (char *args
, int from_tty
)
15051 /* Invalidate last known value of any hardware watchpoint if
15052 the memory which that value represents has been written to by
15056 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15057 CORE_ADDR addr
, ssize_t len
,
15058 const bfd_byte
*data
)
15060 struct breakpoint
*bp
;
15062 ALL_BREAKPOINTS (bp
)
15063 if (bp
->enable_state
== bp_enabled
15064 && bp
->type
== bp_hardware_watchpoint
)
15066 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15068 if (wp
->val_valid
&& wp
->val
)
15070 struct bp_location
*loc
;
15072 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15073 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15074 && loc
->address
+ loc
->length
> addr
15075 && addr
+ len
> loc
->address
)
15077 value_free (wp
->val
);
15085 /* Create and insert a breakpoint for software single step. */
15088 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15089 struct address_space
*aspace
,
15092 struct thread_info
*tp
= inferior_thread ();
15093 struct symtab_and_line sal
;
15094 CORE_ADDR pc
= next_pc
;
15096 if (tp
->control
.single_step_breakpoints
== NULL
)
15098 tp
->control
.single_step_breakpoints
15099 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15102 sal
= find_pc_line (pc
, 0);
15104 sal
.section
= find_pc_overlay (pc
);
15105 sal
.explicit_pc
= 1;
15106 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15108 update_global_location_list (UGLL_INSERT
);
15111 /* Insert single step breakpoints according to the current state. */
15114 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
15116 struct regcache
*regcache
= get_current_regcache ();
15117 VEC (CORE_ADDR
) * next_pcs
;
15119 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
15121 if (next_pcs
!= NULL
)
15125 struct frame_info
*frame
= get_current_frame ();
15126 struct address_space
*aspace
= get_frame_address_space (frame
);
15128 for (i
= 0; VEC_iterate (CORE_ADDR
, next_pcs
, i
, pc
); i
++)
15129 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
15131 VEC_free (CORE_ADDR
, next_pcs
);
15139 /* See breakpoint.h. */
15142 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15143 struct address_space
*aspace
,
15146 struct bp_location
*loc
;
15148 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15150 && breakpoint_location_address_match (loc
, aspace
, pc
))
15156 /* Check whether a software single-step breakpoint is inserted at
15160 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15163 struct breakpoint
*bpt
;
15165 ALL_BREAKPOINTS (bpt
)
15167 if (bpt
->type
== bp_single_step
15168 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15174 /* Tracepoint-specific operations. */
15176 /* Set tracepoint count to NUM. */
15178 set_tracepoint_count (int num
)
15180 tracepoint_count
= num
;
15181 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15185 trace_command (char *arg
, int from_tty
)
15187 struct breakpoint_ops
*ops
;
15189 event_location_up location
= string_to_event_location (&arg
,
15191 if (location
!= NULL
15192 && event_location_type (location
.get ()) == PROBE_LOCATION
)
15193 ops
= &tracepoint_probe_breakpoint_ops
;
15195 ops
= &tracepoint_breakpoint_ops
;
15197 create_breakpoint (get_current_arch (),
15199 NULL
, 0, arg
, 1 /* parse arg */,
15201 bp_tracepoint
/* type_wanted */,
15202 0 /* Ignore count */,
15203 pending_break_support
,
15207 0 /* internal */, 0);
15211 ftrace_command (char *arg
, int from_tty
)
15213 event_location_up location
= string_to_event_location (&arg
,
15215 create_breakpoint (get_current_arch (),
15217 NULL
, 0, arg
, 1 /* parse arg */,
15219 bp_fast_tracepoint
/* type_wanted */,
15220 0 /* Ignore count */,
15221 pending_break_support
,
15222 &tracepoint_breakpoint_ops
,
15225 0 /* internal */, 0);
15228 /* strace command implementation. Creates a static tracepoint. */
15231 strace_command (char *arg
, int from_tty
)
15233 struct breakpoint_ops
*ops
;
15234 event_location_up location
;
15235 struct cleanup
*back_to
;
15237 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15238 or with a normal static tracepoint. */
15239 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15241 ops
= &strace_marker_breakpoint_ops
;
15242 location
= new_linespec_location (&arg
);
15246 ops
= &tracepoint_breakpoint_ops
;
15247 location
= string_to_event_location (&arg
, current_language
);
15250 create_breakpoint (get_current_arch (),
15252 NULL
, 0, arg
, 1 /* parse arg */,
15254 bp_static_tracepoint
/* type_wanted */,
15255 0 /* Ignore count */,
15256 pending_break_support
,
15260 0 /* internal */, 0);
15263 /* Set up a fake reader function that gets command lines from a linked
15264 list that was acquired during tracepoint uploading. */
15266 static struct uploaded_tp
*this_utp
;
15267 static int next_cmd
;
15270 read_uploaded_action (void)
15274 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15281 /* Given information about a tracepoint as recorded on a target (which
15282 can be either a live system or a trace file), attempt to create an
15283 equivalent GDB tracepoint. This is not a reliable process, since
15284 the target does not necessarily have all the information used when
15285 the tracepoint was originally defined. */
15287 struct tracepoint
*
15288 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15290 char *addr_str
, small_buf
[100];
15291 struct tracepoint
*tp
;
15293 if (utp
->at_string
)
15294 addr_str
= utp
->at_string
;
15297 /* In the absence of a source location, fall back to raw
15298 address. Since there is no way to confirm that the address
15299 means the same thing as when the trace was started, warn the
15301 warning (_("Uploaded tracepoint %d has no "
15302 "source location, using raw address"),
15304 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15305 addr_str
= small_buf
;
15308 /* There's not much we can do with a sequence of bytecodes. */
15309 if (utp
->cond
&& !utp
->cond_string
)
15310 warning (_("Uploaded tracepoint %d condition "
15311 "has no source form, ignoring it"),
15314 event_location_up location
= string_to_event_location (&addr_str
,
15316 if (!create_breakpoint (get_current_arch (),
15318 utp
->cond_string
, -1, addr_str
,
15319 0 /* parse cond/thread */,
15321 utp
->type
/* type_wanted */,
15322 0 /* Ignore count */,
15323 pending_break_support
,
15324 &tracepoint_breakpoint_ops
,
15326 utp
->enabled
/* enabled */,
15328 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15331 /* Get the tracepoint we just created. */
15332 tp
= get_tracepoint (tracepoint_count
);
15333 gdb_assert (tp
!= NULL
);
15337 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15340 trace_pass_command (small_buf
, 0);
15343 /* If we have uploaded versions of the original commands, set up a
15344 special-purpose "reader" function and call the usual command line
15345 reader, then pass the result to the breakpoint command-setting
15347 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15349 command_line_up cmd_list
;
15354 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15356 breakpoint_set_commands (&tp
->base
, std::move (cmd_list
));
15358 else if (!VEC_empty (char_ptr
, utp
->actions
)
15359 || !VEC_empty (char_ptr
, utp
->step_actions
))
15360 warning (_("Uploaded tracepoint %d actions "
15361 "have no source form, ignoring them"),
15364 /* Copy any status information that might be available. */
15365 tp
->base
.hit_count
= utp
->hit_count
;
15366 tp
->traceframe_usage
= utp
->traceframe_usage
;
15371 /* Print information on tracepoint number TPNUM_EXP, or all if
15375 tracepoints_info (char *args
, int from_tty
)
15377 struct ui_out
*uiout
= current_uiout
;
15380 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15382 if (num_printed
== 0)
15384 if (args
== NULL
|| *args
== '\0')
15385 uiout
->message ("No tracepoints.\n");
15387 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15390 default_collect_info ();
15393 /* The 'enable trace' command enables tracepoints.
15394 Not supported by all targets. */
15396 enable_trace_command (char *args
, int from_tty
)
15398 enable_command (args
, from_tty
);
15401 /* The 'disable trace' command disables tracepoints.
15402 Not supported by all targets. */
15404 disable_trace_command (char *args
, int from_tty
)
15406 disable_command (args
, from_tty
);
15409 /* Remove a tracepoint (or all if no argument). */
15411 delete_trace_command (char *arg
, int from_tty
)
15413 struct breakpoint
*b
, *b_tmp
;
15419 int breaks_to_delete
= 0;
15421 /* Delete all breakpoints if no argument.
15422 Do not delete internal or call-dummy breakpoints, these
15423 have to be deleted with an explicit breakpoint number
15425 ALL_TRACEPOINTS (b
)
15426 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15428 breaks_to_delete
= 1;
15432 /* Ask user only if there are some breakpoints to delete. */
15434 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15436 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15437 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15438 delete_breakpoint (b
);
15442 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15445 /* Helper function for trace_pass_command. */
15448 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15450 tp
->pass_count
= count
;
15451 observer_notify_breakpoint_modified (&tp
->base
);
15453 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15454 tp
->base
.number
, count
);
15457 /* Set passcount for tracepoint.
15459 First command argument is passcount, second is tracepoint number.
15460 If tracepoint number omitted, apply to most recently defined.
15461 Also accepts special argument "all". */
15464 trace_pass_command (char *args
, int from_tty
)
15466 struct tracepoint
*t1
;
15467 unsigned int count
;
15469 if (args
== 0 || *args
== 0)
15470 error (_("passcount command requires an "
15471 "argument (count + optional TP num)"));
15473 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15475 args
= skip_spaces (args
);
15476 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15478 struct breakpoint
*b
;
15480 args
+= 3; /* Skip special argument "all". */
15482 error (_("Junk at end of arguments."));
15484 ALL_TRACEPOINTS (b
)
15486 t1
= (struct tracepoint
*) b
;
15487 trace_pass_set_count (t1
, count
, from_tty
);
15490 else if (*args
== '\0')
15492 t1
= get_tracepoint_by_number (&args
, NULL
);
15494 trace_pass_set_count (t1
, count
, from_tty
);
15498 number_or_range_parser
parser (args
);
15499 while (!parser
.finished ())
15501 t1
= get_tracepoint_by_number (&args
, &parser
);
15503 trace_pass_set_count (t1
, count
, from_tty
);
15508 struct tracepoint
*
15509 get_tracepoint (int num
)
15511 struct breakpoint
*t
;
15513 ALL_TRACEPOINTS (t
)
15514 if (t
->number
== num
)
15515 return (struct tracepoint
*) t
;
15520 /* Find the tracepoint with the given target-side number (which may be
15521 different from the tracepoint number after disconnecting and
15524 struct tracepoint
*
15525 get_tracepoint_by_number_on_target (int num
)
15527 struct breakpoint
*b
;
15529 ALL_TRACEPOINTS (b
)
15531 struct tracepoint
*t
= (struct tracepoint
*) b
;
15533 if (t
->number_on_target
== num
)
15540 /* Utility: parse a tracepoint number and look it up in the list.
15541 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15542 If the argument is missing, the most recent tracepoint
15543 (tracepoint_count) is returned. */
15545 struct tracepoint
*
15546 get_tracepoint_by_number (char **arg
,
15547 number_or_range_parser
*parser
)
15549 struct breakpoint
*t
;
15551 char *instring
= arg
== NULL
? NULL
: *arg
;
15553 if (parser
!= NULL
)
15555 gdb_assert (!parser
->finished ());
15556 tpnum
= parser
->get_number ();
15558 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15559 tpnum
= tracepoint_count
;
15561 tpnum
= get_number (arg
);
15565 if (instring
&& *instring
)
15566 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15569 printf_filtered (_("No previous tracepoint\n"));
15573 ALL_TRACEPOINTS (t
)
15574 if (t
->number
== tpnum
)
15576 return (struct tracepoint
*) t
;
15579 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15584 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15586 if (b
->thread
!= -1)
15587 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15590 fprintf_unfiltered (fp
, " task %d", b
->task
);
15592 fprintf_unfiltered (fp
, "\n");
15595 /* Save information on user settable breakpoints (watchpoints, etc) to
15596 a new script file named FILENAME. If FILTER is non-NULL, call it
15597 on each breakpoint and only include the ones for which it returns
15601 save_breakpoints (char *filename
, int from_tty
,
15602 int (*filter
) (const struct breakpoint
*))
15604 struct breakpoint
*tp
;
15606 struct cleanup
*cleanup
;
15607 int extra_trace_bits
= 0;
15609 if (filename
== 0 || *filename
== 0)
15610 error (_("Argument required (file name in which to save)"));
15612 /* See if we have anything to save. */
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
))
15625 if (is_tracepoint (tp
))
15627 extra_trace_bits
= 1;
15629 /* We can stop searching. */
15636 warning (_("Nothing to save."));
15640 filename
= tilde_expand (filename
);
15641 cleanup
= make_cleanup (xfree
, filename
);
15645 if (!fp
.open (filename
, "w"))
15646 error (_("Unable to open file '%s' for saving (%s)"),
15647 filename
, safe_strerror (errno
));
15649 if (extra_trace_bits
)
15650 save_trace_state_variables (&fp
);
15652 ALL_BREAKPOINTS (tp
)
15654 /* Skip internal and momentary breakpoints. */
15655 if (!user_breakpoint_p (tp
))
15658 /* If we have a filter, only save the breakpoints it accepts. */
15659 if (filter
&& !filter (tp
))
15662 tp
->ops
->print_recreate (tp
, &fp
);
15664 /* Note, we can't rely on tp->number for anything, as we can't
15665 assume the recreated breakpoint numbers will match. Use $bpnum
15668 if (tp
->cond_string
)
15669 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15671 if (tp
->ignore_count
)
15672 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15674 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15676 fp
.puts (" commands\n");
15678 current_uiout
->redirect (&fp
);
15681 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15683 CATCH (ex
, RETURN_MASK_ALL
)
15685 current_uiout
->redirect (NULL
);
15686 throw_exception (ex
);
15690 current_uiout
->redirect (NULL
);
15691 fp
.puts (" end\n");
15694 if (tp
->enable_state
== bp_disabled
)
15695 fp
.puts ("disable $bpnum\n");
15697 /* If this is a multi-location breakpoint, check if the locations
15698 should be individually disabled. Watchpoint locations are
15699 special, and not user visible. */
15700 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15702 struct bp_location
*loc
;
15705 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15707 fp
.printf ("disable $bpnum.%d\n", n
);
15711 if (extra_trace_bits
&& *default_collect
)
15712 fp
.printf ("set default-collect %s\n", default_collect
);
15715 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15716 do_cleanups (cleanup
);
15719 /* The `save breakpoints' command. */
15722 save_breakpoints_command (char *args
, int from_tty
)
15724 save_breakpoints (args
, from_tty
, NULL
);
15727 /* The `save tracepoints' command. */
15730 save_tracepoints_command (char *args
, int from_tty
)
15732 save_breakpoints (args
, from_tty
, is_tracepoint
);
15735 /* Create a vector of all tracepoints. */
15737 VEC(breakpoint_p
) *
15738 all_tracepoints (void)
15740 VEC(breakpoint_p
) *tp_vec
= 0;
15741 struct breakpoint
*tp
;
15743 ALL_TRACEPOINTS (tp
)
15745 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15752 /* This help string is used to consolidate all the help string for specifying
15753 locations used by several commands. */
15755 #define LOCATION_HELP_STRING \
15756 "Linespecs are colon-separated lists of location parameters, such as\n\
15757 source filename, function name, label name, and line number.\n\
15758 Example: To specify the start of a label named \"the_top\" in the\n\
15759 function \"fact\" in the file \"factorial.c\", use\n\
15760 \"factorial.c:fact:the_top\".\n\
15762 Address locations begin with \"*\" and specify an exact address in the\n\
15763 program. Example: To specify the fourth byte past the start function\n\
15764 \"main\", use \"*main + 4\".\n\
15766 Explicit locations are similar to linespecs but use an option/argument\n\
15767 syntax to specify location parameters.\n\
15768 Example: To specify the start of the label named \"the_top\" in the\n\
15769 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15770 -function fact -label the_top\".\n"
15772 /* This help string is used for the break, hbreak, tbreak and thbreak
15773 commands. It is defined as a macro to prevent duplication.
15774 COMMAND should be a string constant containing the name of the
15777 #define BREAK_ARGS_HELP(command) \
15778 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15779 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15780 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15781 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15782 `-probe-dtrace' (for a DTrace probe).\n\
15783 LOCATION may be a linespec, address, or explicit location as described\n\
15786 With no LOCATION, uses current execution address of the selected\n\
15787 stack frame. This is useful for breaking on return to a stack frame.\n\
15789 THREADNUM is the number from \"info threads\".\n\
15790 CONDITION is a boolean expression.\n\
15791 \n" LOCATION_HELP_STRING "\n\
15792 Multiple breakpoints at one place are permitted, and useful if their\n\
15793 conditions are different.\n\
15795 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15797 /* List of subcommands for "catch". */
15798 static struct cmd_list_element
*catch_cmdlist
;
15800 /* List of subcommands for "tcatch". */
15801 static struct cmd_list_element
*tcatch_cmdlist
;
15804 add_catch_command (const char *name
, const char *docstring
,
15805 cmd_sfunc_ftype
*sfunc
,
15806 completer_ftype
*completer
,
15807 void *user_data_catch
,
15808 void *user_data_tcatch
)
15810 struct cmd_list_element
*command
;
15812 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15814 set_cmd_sfunc (command
, sfunc
);
15815 set_cmd_context (command
, user_data_catch
);
15816 set_cmd_completer (command
, completer
);
15818 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15820 set_cmd_sfunc (command
, sfunc
);
15821 set_cmd_context (command
, user_data_tcatch
);
15822 set_cmd_completer (command
, completer
);
15826 save_command (char *arg
, int from_tty
)
15828 printf_unfiltered (_("\"save\" must be followed by "
15829 "the name of a save subcommand.\n"));
15830 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15833 struct breakpoint
*
15834 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15837 struct breakpoint
*b
, *b_tmp
;
15839 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15841 if ((*callback
) (b
, data
))
15848 /* Zero if any of the breakpoint's locations could be a location where
15849 functions have been inlined, nonzero otherwise. */
15852 is_non_inline_function (struct breakpoint
*b
)
15854 /* The shared library event breakpoint is set on the address of a
15855 non-inline function. */
15856 if (b
->type
== bp_shlib_event
)
15862 /* Nonzero if the specified PC cannot be a location where functions
15863 have been inlined. */
15866 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15867 const struct target_waitstatus
*ws
)
15869 struct breakpoint
*b
;
15870 struct bp_location
*bl
;
15872 ALL_BREAKPOINTS (b
)
15874 if (!is_non_inline_function (b
))
15877 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15879 if (!bl
->shlib_disabled
15880 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15888 /* Remove any references to OBJFILE which is going to be freed. */
15891 breakpoint_free_objfile (struct objfile
*objfile
)
15893 struct bp_location
**locp
, *loc
;
15895 ALL_BP_LOCATIONS (loc
, locp
)
15896 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15897 loc
->symtab
= NULL
;
15901 initialize_breakpoint_ops (void)
15903 static int initialized
= 0;
15905 struct breakpoint_ops
*ops
;
15911 /* The breakpoint_ops structure to be inherit by all kinds of
15912 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15913 internal and momentary breakpoints, etc.). */
15914 ops
= &bkpt_base_breakpoint_ops
;
15915 *ops
= base_breakpoint_ops
;
15916 ops
->re_set
= bkpt_re_set
;
15917 ops
->insert_location
= bkpt_insert_location
;
15918 ops
->remove_location
= bkpt_remove_location
;
15919 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15920 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15921 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15922 ops
->decode_location
= bkpt_decode_location
;
15924 /* The breakpoint_ops structure to be used in regular breakpoints. */
15925 ops
= &bkpt_breakpoint_ops
;
15926 *ops
= bkpt_base_breakpoint_ops
;
15927 ops
->re_set
= bkpt_re_set
;
15928 ops
->resources_needed
= bkpt_resources_needed
;
15929 ops
->print_it
= bkpt_print_it
;
15930 ops
->print_mention
= bkpt_print_mention
;
15931 ops
->print_recreate
= bkpt_print_recreate
;
15933 /* Ranged breakpoints. */
15934 ops
= &ranged_breakpoint_ops
;
15935 *ops
= bkpt_breakpoint_ops
;
15936 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15937 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15938 ops
->print_it
= print_it_ranged_breakpoint
;
15939 ops
->print_one
= print_one_ranged_breakpoint
;
15940 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15941 ops
->print_mention
= print_mention_ranged_breakpoint
;
15942 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15944 /* Internal breakpoints. */
15945 ops
= &internal_breakpoint_ops
;
15946 *ops
= bkpt_base_breakpoint_ops
;
15947 ops
->re_set
= internal_bkpt_re_set
;
15948 ops
->check_status
= internal_bkpt_check_status
;
15949 ops
->print_it
= internal_bkpt_print_it
;
15950 ops
->print_mention
= internal_bkpt_print_mention
;
15952 /* Momentary breakpoints. */
15953 ops
= &momentary_breakpoint_ops
;
15954 *ops
= bkpt_base_breakpoint_ops
;
15955 ops
->re_set
= momentary_bkpt_re_set
;
15956 ops
->check_status
= momentary_bkpt_check_status
;
15957 ops
->print_it
= momentary_bkpt_print_it
;
15958 ops
->print_mention
= momentary_bkpt_print_mention
;
15960 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15961 ops
= &longjmp_breakpoint_ops
;
15962 *ops
= momentary_breakpoint_ops
;
15963 ops
->dtor
= longjmp_bkpt_dtor
;
15965 /* Probe breakpoints. */
15966 ops
= &bkpt_probe_breakpoint_ops
;
15967 *ops
= bkpt_breakpoint_ops
;
15968 ops
->insert_location
= bkpt_probe_insert_location
;
15969 ops
->remove_location
= bkpt_probe_remove_location
;
15970 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15971 ops
->decode_location
= bkpt_probe_decode_location
;
15974 ops
= &watchpoint_breakpoint_ops
;
15975 *ops
= base_breakpoint_ops
;
15976 ops
->dtor
= dtor_watchpoint
;
15977 ops
->re_set
= re_set_watchpoint
;
15978 ops
->insert_location
= insert_watchpoint
;
15979 ops
->remove_location
= remove_watchpoint
;
15980 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15981 ops
->check_status
= check_status_watchpoint
;
15982 ops
->resources_needed
= resources_needed_watchpoint
;
15983 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15984 ops
->print_it
= print_it_watchpoint
;
15985 ops
->print_mention
= print_mention_watchpoint
;
15986 ops
->print_recreate
= print_recreate_watchpoint
;
15987 ops
->explains_signal
= explains_signal_watchpoint
;
15989 /* Masked watchpoints. */
15990 ops
= &masked_watchpoint_breakpoint_ops
;
15991 *ops
= watchpoint_breakpoint_ops
;
15992 ops
->insert_location
= insert_masked_watchpoint
;
15993 ops
->remove_location
= remove_masked_watchpoint
;
15994 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15995 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15996 ops
->print_it
= print_it_masked_watchpoint
;
15997 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15998 ops
->print_mention
= print_mention_masked_watchpoint
;
15999 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16002 ops
= &tracepoint_breakpoint_ops
;
16003 *ops
= base_breakpoint_ops
;
16004 ops
->re_set
= tracepoint_re_set
;
16005 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16006 ops
->print_one_detail
= tracepoint_print_one_detail
;
16007 ops
->print_mention
= tracepoint_print_mention
;
16008 ops
->print_recreate
= tracepoint_print_recreate
;
16009 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
16010 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16011 ops
->decode_location
= tracepoint_decode_location
;
16013 /* Probe tracepoints. */
16014 ops
= &tracepoint_probe_breakpoint_ops
;
16015 *ops
= tracepoint_breakpoint_ops
;
16016 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
16017 ops
->decode_location
= tracepoint_probe_decode_location
;
16019 /* Static tracepoints with marker (`-m'). */
16020 ops
= &strace_marker_breakpoint_ops
;
16021 *ops
= tracepoint_breakpoint_ops
;
16022 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16023 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16024 ops
->decode_location
= strace_marker_decode_location
;
16026 /* Fork catchpoints. */
16027 ops
= &catch_fork_breakpoint_ops
;
16028 *ops
= base_breakpoint_ops
;
16029 ops
->insert_location
= insert_catch_fork
;
16030 ops
->remove_location
= remove_catch_fork
;
16031 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16032 ops
->print_it
= print_it_catch_fork
;
16033 ops
->print_one
= print_one_catch_fork
;
16034 ops
->print_mention
= print_mention_catch_fork
;
16035 ops
->print_recreate
= print_recreate_catch_fork
;
16037 /* Vfork catchpoints. */
16038 ops
= &catch_vfork_breakpoint_ops
;
16039 *ops
= base_breakpoint_ops
;
16040 ops
->insert_location
= insert_catch_vfork
;
16041 ops
->remove_location
= remove_catch_vfork
;
16042 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16043 ops
->print_it
= print_it_catch_vfork
;
16044 ops
->print_one
= print_one_catch_vfork
;
16045 ops
->print_mention
= print_mention_catch_vfork
;
16046 ops
->print_recreate
= print_recreate_catch_vfork
;
16048 /* Exec catchpoints. */
16049 ops
= &catch_exec_breakpoint_ops
;
16050 *ops
= base_breakpoint_ops
;
16051 ops
->dtor
= dtor_catch_exec
;
16052 ops
->insert_location
= insert_catch_exec
;
16053 ops
->remove_location
= remove_catch_exec
;
16054 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16055 ops
->print_it
= print_it_catch_exec
;
16056 ops
->print_one
= print_one_catch_exec
;
16057 ops
->print_mention
= print_mention_catch_exec
;
16058 ops
->print_recreate
= print_recreate_catch_exec
;
16060 /* Solib-related catchpoints. */
16061 ops
= &catch_solib_breakpoint_ops
;
16062 *ops
= base_breakpoint_ops
;
16063 ops
->dtor
= dtor_catch_solib
;
16064 ops
->insert_location
= insert_catch_solib
;
16065 ops
->remove_location
= remove_catch_solib
;
16066 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16067 ops
->check_status
= check_status_catch_solib
;
16068 ops
->print_it
= print_it_catch_solib
;
16069 ops
->print_one
= print_one_catch_solib
;
16070 ops
->print_mention
= print_mention_catch_solib
;
16071 ops
->print_recreate
= print_recreate_catch_solib
;
16073 ops
= &dprintf_breakpoint_ops
;
16074 *ops
= bkpt_base_breakpoint_ops
;
16075 ops
->re_set
= dprintf_re_set
;
16076 ops
->resources_needed
= bkpt_resources_needed
;
16077 ops
->print_it
= bkpt_print_it
;
16078 ops
->print_mention
= bkpt_print_mention
;
16079 ops
->print_recreate
= dprintf_print_recreate
;
16080 ops
->after_condition_true
= dprintf_after_condition_true
;
16081 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16084 /* Chain containing all defined "enable breakpoint" subcommands. */
16086 static struct cmd_list_element
*enablebreaklist
= NULL
;
16089 _initialize_breakpoint (void)
16091 struct cmd_list_element
*c
;
16093 initialize_breakpoint_ops ();
16095 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16096 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16097 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16099 breakpoint_objfile_key
16100 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16102 breakpoint_chain
= 0;
16103 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16104 before a breakpoint is set. */
16105 breakpoint_count
= 0;
16107 tracepoint_count
= 0;
16109 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16110 Set ignore-count of breakpoint number N to COUNT.\n\
16111 Usage is `ignore N COUNT'."));
16113 add_com ("commands", class_breakpoint
, commands_command
, _("\
16114 Set commands to be executed when the given breakpoints are hit.\n\
16115 Give a space-separated breakpoint list as argument after \"commands\".\n\
16116 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
16118 With no argument, the targeted breakpoint is the last one set.\n\
16119 The commands themselves follow starting on the next line.\n\
16120 Type a line containing \"end\" to indicate the end of them.\n\
16121 Give \"silent\" as the first line to make the breakpoint silent;\n\
16122 then no output is printed when it is hit, except what the commands print."));
16124 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16125 Specify breakpoint number N to break only if COND is true.\n\
16126 Usage is `condition N COND', where N is an integer and COND is an\n\
16127 expression to be evaluated whenever breakpoint N is reached."));
16128 set_cmd_completer (c
, condition_completer
);
16130 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16131 Set a temporary breakpoint.\n\
16132 Like \"break\" except the breakpoint is only temporary,\n\
16133 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16134 by using \"enable delete\" on the breakpoint number.\n\
16136 BREAK_ARGS_HELP ("tbreak")));
16137 set_cmd_completer (c
, location_completer
);
16139 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16140 Set a hardware assisted breakpoint.\n\
16141 Like \"break\" except the breakpoint requires hardware support,\n\
16142 some target hardware may not have this support.\n\
16144 BREAK_ARGS_HELP ("hbreak")));
16145 set_cmd_completer (c
, location_completer
);
16147 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16148 Set a temporary hardware assisted breakpoint.\n\
16149 Like \"hbreak\" except the breakpoint is only temporary,\n\
16150 so it will be deleted when hit.\n\
16152 BREAK_ARGS_HELP ("thbreak")));
16153 set_cmd_completer (c
, location_completer
);
16155 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16156 Enable some breakpoints.\n\
16157 Give breakpoint numbers (separated by spaces) as arguments.\n\
16158 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16159 This is used to cancel the effect of the \"disable\" command.\n\
16160 With a subcommand you can enable temporarily."),
16161 &enablelist
, "enable ", 1, &cmdlist
);
16163 add_com_alias ("en", "enable", class_breakpoint
, 1);
16165 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16166 Enable some breakpoints.\n\
16167 Give breakpoint numbers (separated by spaces) as arguments.\n\
16168 This is used to cancel the effect of the \"disable\" command.\n\
16169 May be abbreviated to simply \"enable\".\n"),
16170 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16172 add_cmd ("once", no_class
, enable_once_command
, _("\
16173 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16174 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16177 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16178 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16179 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16182 add_cmd ("count", no_class
, enable_count_command
, _("\
16183 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16184 If a breakpoint is hit while enabled in this fashion,\n\
16185 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16188 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16189 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16190 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16193 add_cmd ("once", no_class
, enable_once_command
, _("\
16194 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16195 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16198 add_cmd ("count", no_class
, enable_count_command
, _("\
16199 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16200 If a breakpoint is hit while enabled in this fashion,\n\
16201 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16204 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16205 Disable some breakpoints.\n\
16206 Arguments are breakpoint numbers with spaces in between.\n\
16207 To disable all breakpoints, give no argument.\n\
16208 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16209 &disablelist
, "disable ", 1, &cmdlist
);
16210 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16211 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16213 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16214 Disable some breakpoints.\n\
16215 Arguments are breakpoint numbers with spaces in between.\n\
16216 To disable all breakpoints, give no argument.\n\
16217 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16218 This command may be abbreviated \"disable\"."),
16221 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16222 Delete some breakpoints or auto-display expressions.\n\
16223 Arguments are breakpoint numbers with spaces in between.\n\
16224 To delete all breakpoints, give no argument.\n\
16226 Also a prefix command for deletion of other GDB objects.\n\
16227 The \"unset\" command is also an alias for \"delete\"."),
16228 &deletelist
, "delete ", 1, &cmdlist
);
16229 add_com_alias ("d", "delete", class_breakpoint
, 1);
16230 add_com_alias ("del", "delete", class_breakpoint
, 1);
16232 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16233 Delete some breakpoints or auto-display expressions.\n\
16234 Arguments are breakpoint numbers with spaces in between.\n\
16235 To delete all breakpoints, give no argument.\n\
16236 This command may be abbreviated \"delete\"."),
16239 add_com ("clear", class_breakpoint
, clear_command
, _("\
16240 Clear breakpoint at specified location.\n\
16241 Argument may be a linespec, explicit, or address location as described below.\n\
16243 With no argument, clears all breakpoints in the line that the selected frame\n\
16244 is executing in.\n"
16245 "\n" LOCATION_HELP_STRING
"\n\
16246 See also the \"delete\" command which clears breakpoints by number."));
16247 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16249 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16250 Set breakpoint at specified location.\n"
16251 BREAK_ARGS_HELP ("break")));
16252 set_cmd_completer (c
, location_completer
);
16254 add_com_alias ("b", "break", class_run
, 1);
16255 add_com_alias ("br", "break", class_run
, 1);
16256 add_com_alias ("bre", "break", class_run
, 1);
16257 add_com_alias ("brea", "break", class_run
, 1);
16261 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16262 Break in function/address or break at a line in the current file."),
16263 &stoplist
, "stop ", 1, &cmdlist
);
16264 add_cmd ("in", class_breakpoint
, stopin_command
,
16265 _("Break in function or address."), &stoplist
);
16266 add_cmd ("at", class_breakpoint
, stopat_command
,
16267 _("Break at a line in the current file."), &stoplist
);
16268 add_com ("status", class_info
, breakpoints_info
, _("\
16269 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16270 The \"Type\" column indicates one of:\n\
16271 \tbreakpoint - normal breakpoint\n\
16272 \twatchpoint - watchpoint\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\
16282 breakpoint set."));
16285 add_info ("breakpoints", breakpoints_info
, _("\
16286 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16287 The \"Type\" column indicates one of:\n\
16288 \tbreakpoint - normal breakpoint\n\
16289 \twatchpoint - watchpoint\n\
16290 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16291 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16292 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16293 address and file/line number respectively.\n\
16295 Convenience variable \"$_\" and default examine address for \"x\"\n\
16296 are set to the address of the last breakpoint listed unless the command\n\
16297 is prefixed with \"server \".\n\n\
16298 Convenience variable \"$bpnum\" contains the number of the last\n\
16299 breakpoint set."));
16301 add_info_alias ("b", "breakpoints", 1);
16303 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16304 Status of all breakpoints, or breakpoint number NUMBER.\n\
16305 The \"Type\" column indicates one of:\n\
16306 \tbreakpoint - normal breakpoint\n\
16307 \twatchpoint - watchpoint\n\
16308 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16309 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16310 \tuntil - internal breakpoint used by the \"until\" command\n\
16311 \tfinish - internal breakpoint used by the \"finish\" command\n\
16312 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16313 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16314 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16315 address and file/line number respectively.\n\
16317 Convenience variable \"$_\" and default examine address for \"x\"\n\
16318 are set to the address of the last breakpoint listed unless the command\n\
16319 is prefixed with \"server \".\n\n\
16320 Convenience variable \"$bpnum\" contains the number of the last\n\
16322 &maintenanceinfolist
);
16324 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16325 Set catchpoints to catch events."),
16326 &catch_cmdlist
, "catch ",
16327 0/*allow-unknown*/, &cmdlist
);
16329 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16330 Set temporary catchpoints to catch events."),
16331 &tcatch_cmdlist
, "tcatch ",
16332 0/*allow-unknown*/, &cmdlist
);
16334 add_catch_command ("fork", _("Catch calls to fork."),
16335 catch_fork_command_1
,
16337 (void *) (uintptr_t) catch_fork_permanent
,
16338 (void *) (uintptr_t) catch_fork_temporary
);
16339 add_catch_command ("vfork", _("Catch calls to vfork."),
16340 catch_fork_command_1
,
16342 (void *) (uintptr_t) catch_vfork_permanent
,
16343 (void *) (uintptr_t) catch_vfork_temporary
);
16344 add_catch_command ("exec", _("Catch calls to exec."),
16345 catch_exec_command_1
,
16349 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16350 Usage: catch load [REGEX]\n\
16351 If REGEX is given, only stop for libraries matching the regular expression."),
16352 catch_load_command_1
,
16356 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16357 Usage: catch unload [REGEX]\n\
16358 If REGEX is given, only stop for libraries matching the regular expression."),
16359 catch_unload_command_1
,
16364 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16365 Set a watchpoint for an expression.\n\
16366 Usage: watch [-l|-location] EXPRESSION\n\
16367 A watchpoint stops execution of your program whenever the value of\n\
16368 an expression changes.\n\
16369 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16370 the memory to which it refers."));
16371 set_cmd_completer (c
, expression_completer
);
16373 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16374 Set a read watchpoint for an expression.\n\
16375 Usage: rwatch [-l|-location] EXPRESSION\n\
16376 A watchpoint stops execution of your program whenever the value of\n\
16377 an expression is read.\n\
16378 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16379 the memory to which it refers."));
16380 set_cmd_completer (c
, expression_completer
);
16382 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16383 Set a watchpoint for an expression.\n\
16384 Usage: awatch [-l|-location] EXPRESSION\n\
16385 A watchpoint stops execution of your program whenever the value of\n\
16386 an expression is either read or written.\n\
16387 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16388 the memory to which it refers."));
16389 set_cmd_completer (c
, expression_completer
);
16391 add_info ("watchpoints", watchpoints_info
, _("\
16392 Status of specified watchpoints (all watchpoints if no argument)."));
16394 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16395 respond to changes - contrary to the description. */
16396 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16397 &can_use_hw_watchpoints
, _("\
16398 Set debugger's willingness to use watchpoint hardware."), _("\
16399 Show debugger's willingness to use watchpoint hardware."), _("\
16400 If zero, gdb will not use hardware for new watchpoints, even if\n\
16401 such is available. (However, any hardware watchpoints that were\n\
16402 created before setting this to nonzero, will continue to use watchpoint\n\
16405 show_can_use_hw_watchpoints
,
16406 &setlist
, &showlist
);
16408 can_use_hw_watchpoints
= 1;
16410 /* Tracepoint manipulation commands. */
16412 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16413 Set a tracepoint at specified location.\n\
16415 BREAK_ARGS_HELP ("trace") "\n\
16416 Do \"help tracepoints\" for info on other tracepoint commands."));
16417 set_cmd_completer (c
, location_completer
);
16419 add_com_alias ("tp", "trace", class_alias
, 0);
16420 add_com_alias ("tr", "trace", class_alias
, 1);
16421 add_com_alias ("tra", "trace", class_alias
, 1);
16422 add_com_alias ("trac", "trace", class_alias
, 1);
16424 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16425 Set a fast tracepoint at specified location.\n\
16427 BREAK_ARGS_HELP ("ftrace") "\n\
16428 Do \"help tracepoints\" for info on other tracepoint commands."));
16429 set_cmd_completer (c
, location_completer
);
16431 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16432 Set a static tracepoint at location or marker.\n\
16434 strace [LOCATION] [if CONDITION]\n\
16435 LOCATION may be a linespec, explicit, or address location (described below) \n\
16436 or -m MARKER_ID.\n\n\
16437 If a marker id is specified, probe the marker with that name. With\n\
16438 no LOCATION, uses current execution address of the selected stack frame.\n\
16439 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16440 This collects arbitrary user data passed in the probe point call to the\n\
16441 tracing library. You can inspect it when analyzing the trace buffer,\n\
16442 by printing the $_sdata variable like any other convenience variable.\n\
16444 CONDITION is a boolean expression.\n\
16445 \n" LOCATION_HELP_STRING
"\n\
16446 Multiple tracepoints at one place are permitted, and useful if their\n\
16447 conditions are different.\n\
16449 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16450 Do \"help tracepoints\" for info on other tracepoint commands."));
16451 set_cmd_completer (c
, location_completer
);
16453 add_info ("tracepoints", tracepoints_info
, _("\
16454 Status of specified tracepoints (all tracepoints if no argument).\n\
16455 Convenience variable \"$tpnum\" contains the number of the\n\
16456 last tracepoint set."));
16458 add_info_alias ("tp", "tracepoints", 1);
16460 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16461 Delete specified tracepoints.\n\
16462 Arguments are tracepoint numbers, separated by spaces.\n\
16463 No argument means delete all tracepoints."),
16465 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16467 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16468 Disable specified tracepoints.\n\
16469 Arguments are tracepoint numbers, separated by spaces.\n\
16470 No argument means disable all tracepoints."),
16472 deprecate_cmd (c
, "disable");
16474 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16475 Enable specified tracepoints.\n\
16476 Arguments are tracepoint numbers, separated by spaces.\n\
16477 No argument means enable all tracepoints."),
16479 deprecate_cmd (c
, "enable");
16481 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16482 Set the passcount for a tracepoint.\n\
16483 The trace will end when the tracepoint has been passed 'count' times.\n\
16484 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16485 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16487 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16488 _("Save breakpoint definitions as a script."),
16489 &save_cmdlist
, "save ",
16490 0/*allow-unknown*/, &cmdlist
);
16492 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16493 Save current breakpoint definitions as a script.\n\
16494 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16495 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16496 session to restore them."),
16498 set_cmd_completer (c
, filename_completer
);
16500 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16501 Save current tracepoint definitions as a script.\n\
16502 Use the 'source' command in another debug session to restore them."),
16504 set_cmd_completer (c
, filename_completer
);
16506 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16507 deprecate_cmd (c
, "save tracepoints");
16509 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16510 Breakpoint specific settings\n\
16511 Configure various breakpoint-specific variables such as\n\
16512 pending breakpoint behavior"),
16513 &breakpoint_set_cmdlist
, "set breakpoint ",
16514 0/*allow-unknown*/, &setlist
);
16515 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16516 Breakpoint specific settings\n\
16517 Configure various breakpoint-specific variables such as\n\
16518 pending breakpoint behavior"),
16519 &breakpoint_show_cmdlist
, "show breakpoint ",
16520 0/*allow-unknown*/, &showlist
);
16522 add_setshow_auto_boolean_cmd ("pending", no_class
,
16523 &pending_break_support
, _("\
16524 Set debugger's behavior regarding pending breakpoints."), _("\
16525 Show debugger's behavior regarding pending breakpoints."), _("\
16526 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16527 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16528 an error. If auto, an unrecognized breakpoint location results in a\n\
16529 user-query to see if a pending breakpoint should be created."),
16531 show_pending_break_support
,
16532 &breakpoint_set_cmdlist
,
16533 &breakpoint_show_cmdlist
);
16535 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16537 add_setshow_boolean_cmd ("auto-hw", no_class
,
16538 &automatic_hardware_breakpoints
, _("\
16539 Set automatic usage of hardware breakpoints."), _("\
16540 Show automatic usage of hardware breakpoints."), _("\
16541 If set, the debugger will automatically use hardware breakpoints for\n\
16542 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16543 a warning will be emitted for such breakpoints."),
16545 show_automatic_hardware_breakpoints
,
16546 &breakpoint_set_cmdlist
,
16547 &breakpoint_show_cmdlist
);
16549 add_setshow_boolean_cmd ("always-inserted", class_support
,
16550 &always_inserted_mode
, _("\
16551 Set mode for inserting breakpoints."), _("\
16552 Show mode for inserting breakpoints."), _("\
16553 When this mode is on, breakpoints are inserted immediately as soon as\n\
16554 they're created, kept inserted even when execution stops, and removed\n\
16555 only when the user deletes them. When this mode is off (the default),\n\
16556 breakpoints are inserted only when execution continues, and removed\n\
16557 when execution stops."),
16559 &show_always_inserted_mode
,
16560 &breakpoint_set_cmdlist
,
16561 &breakpoint_show_cmdlist
);
16563 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16564 condition_evaluation_enums
,
16565 &condition_evaluation_mode_1
, _("\
16566 Set mode of breakpoint condition evaluation."), _("\
16567 Show mode of breakpoint condition evaluation."), _("\
16568 When this is set to \"host\", breakpoint conditions will be\n\
16569 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16570 breakpoint conditions will be downloaded to the target (if the target\n\
16571 supports such feature) and conditions will be evaluated on the target's side.\n\
16572 If this is set to \"auto\" (default), this will be automatically set to\n\
16573 \"target\" if it supports condition evaluation, otherwise it will\n\
16574 be set to \"gdb\""),
16575 &set_condition_evaluation_mode
,
16576 &show_condition_evaluation_mode
,
16577 &breakpoint_set_cmdlist
,
16578 &breakpoint_show_cmdlist
);
16580 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16581 Set a breakpoint for an address range.\n\
16582 break-range START-LOCATION, END-LOCATION\n\
16583 where START-LOCATION and END-LOCATION can be one of the following:\n\
16584 LINENUM, for that line in the current file,\n\
16585 FILE:LINENUM, for that line in that file,\n\
16586 +OFFSET, for that number of lines after the current line\n\
16587 or the start of the range\n\
16588 FUNCTION, for the first line in that function,\n\
16589 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16590 *ADDRESS, for the instruction at that address.\n\
16592 The breakpoint will stop execution of the inferior whenever it executes\n\
16593 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16594 range (including START-LOCATION and END-LOCATION)."));
16596 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16597 Set a dynamic printf at specified location.\n\
16598 dprintf location,format string,arg1,arg2,...\n\
16599 location may be a linespec, explicit, or address location.\n"
16600 "\n" LOCATION_HELP_STRING
));
16601 set_cmd_completer (c
, location_completer
);
16603 add_setshow_enum_cmd ("dprintf-style", class_support
,
16604 dprintf_style_enums
, &dprintf_style
, _("\
16605 Set the style of usage for dynamic printf."), _("\
16606 Show the style of usage for dynamic printf."), _("\
16607 This setting chooses how GDB will do a dynamic printf.\n\
16608 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16609 console, as with the \"printf\" command.\n\
16610 If the value is \"call\", the print is done by calling a function in your\n\
16611 program; by default printf(), but you can choose a different function or\n\
16612 output stream by setting dprintf-function and dprintf-channel."),
16613 update_dprintf_commands
, NULL
,
16614 &setlist
, &showlist
);
16616 dprintf_function
= xstrdup ("printf");
16617 add_setshow_string_cmd ("dprintf-function", class_support
,
16618 &dprintf_function
, _("\
16619 Set the function to use for dynamic printf"), _("\
16620 Show the function to use for dynamic printf"), NULL
,
16621 update_dprintf_commands
, NULL
,
16622 &setlist
, &showlist
);
16624 dprintf_channel
= xstrdup ("");
16625 add_setshow_string_cmd ("dprintf-channel", class_support
,
16626 &dprintf_channel
, _("\
16627 Set the channel to use for dynamic printf"), _("\
16628 Show the channel to use for dynamic printf"), NULL
,
16629 update_dprintf_commands
, NULL
,
16630 &setlist
, &showlist
);
16632 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16633 &disconnected_dprintf
, _("\
16634 Set whether dprintf continues after GDB disconnects."), _("\
16635 Show whether dprintf continues after GDB disconnects."), _("\
16636 Use this to let dprintf commands continue to hit and produce output\n\
16637 even if GDB disconnects or detaches from the target."),
16640 &setlist
, &showlist
);
16642 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16643 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16644 (target agent only) This is useful for formatted output in user-defined commands."));
16646 automatic_hardware_breakpoints
= 1;
16648 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16649 observer_attach_thread_exit (remove_threaded_breakpoints
);