1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (const char *,
105 void (*) (struct breakpoint
*,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint
*);
116 create_sals_from_location_default (const struct event_location
*location
,
117 struct linespec_result
*canonical
,
118 enum bptype type_wanted
);
120 static void create_breakpoints_sal_default (struct gdbarch
*,
121 struct linespec_result
*,
122 char *, char *, enum bptype
,
123 enum bpdisp
, int, int,
125 const struct breakpoint_ops
*,
126 int, int, int, unsigned);
128 static void decode_location_default (struct breakpoint
*b
,
129 const struct event_location
*location
,
130 struct program_space
*search_pspace
,
131 struct symtabs_and_lines
*sals
);
133 static void clear_command (char *, int);
135 static void catch_command (char *, int);
137 static int can_use_hardware_watchpoint (struct value
*);
139 static void break_command_1 (char *, int, int);
141 static void mention (struct breakpoint
*);
143 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
145 const struct breakpoint_ops
*);
146 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
147 const struct symtab_and_line
*);
149 /* This function is used in gdbtk sources and thus can not be made
151 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
152 struct symtab_and_line
,
154 const struct breakpoint_ops
*);
156 static struct breakpoint
*
157 momentary_breakpoint_from_master (struct breakpoint
*orig
,
159 const struct breakpoint_ops
*ops
,
162 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
164 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
168 static void describe_other_breakpoints (struct gdbarch
*,
169 struct program_space
*, CORE_ADDR
,
170 struct obj_section
*, int);
172 static int watchpoint_locations_match (struct bp_location
*loc1
,
173 struct bp_location
*loc2
);
175 static int breakpoint_location_address_match (struct bp_location
*bl
,
176 struct address_space
*aspace
,
179 static int breakpoint_location_address_range_overlap (struct bp_location
*,
180 struct address_space
*,
183 static void breakpoints_info (char *, int);
185 static void watchpoints_info (char *, int);
187 static int breakpoint_1 (char *, int,
188 int (*) (const struct breakpoint
*));
190 static int breakpoint_cond_eval (void *);
192 static void cleanup_executing_breakpoints (void *);
194 static void commands_command (char *, int);
196 static void condition_command (char *, int);
198 static int remove_breakpoint (struct bp_location
*);
199 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
201 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
203 static int watchpoint_check (void *);
205 static void maintenance_info_breakpoints (char *, int);
207 static int hw_breakpoint_used_count (void);
209 static int hw_watchpoint_use_count (struct breakpoint
*);
211 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
213 int *other_type_used
);
215 static void hbreak_command (char *, int);
217 static void thbreak_command (char *, int);
219 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
222 static void stop_command (char *arg
, int from_tty
);
224 static void stopin_command (char *arg
, int from_tty
);
226 static void stopat_command (char *arg
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void free_bp_location (struct bp_location
*loc
);
231 static void incref_bp_location (struct bp_location
*loc
);
232 static void decref_bp_location (struct bp_location
**loc
);
234 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
236 /* update_global_location_list's modes of operation wrt to whether to
237 insert locations now. */
238 enum ugll_insert_mode
240 /* Don't insert any breakpoint locations into the inferior, only
241 remove already-inserted locations that no longer should be
242 inserted. Functions that delete a breakpoint or breakpoints
243 should specify this mode, so that deleting a breakpoint doesn't
244 have the side effect of inserting the locations of other
245 breakpoints that are marked not-inserted, but should_be_inserted
246 returns true on them.
248 This behavior is useful is situations close to tear-down -- e.g.,
249 after an exec, while the target still has execution, but
250 breakpoint shadows of the previous executable image should *NOT*
251 be restored to the new image; or before detaching, where the
252 target still has execution and wants to delete breakpoints from
253 GDB's lists, and all breakpoints had already been removed from
257 /* May insert breakpoints iff breakpoints_should_be_inserted_now
258 claims breakpoints should be inserted now. */
261 /* Insert locations now, irrespective of
262 breakpoints_should_be_inserted_now. E.g., say all threads are
263 stopped right now, and the user did "continue". We need to
264 insert breakpoints _before_ resuming the target, but
265 UGLL_MAY_INSERT wouldn't insert them, because
266 breakpoints_should_be_inserted_now returns false at that point,
267 as no thread is running yet. */
271 static void update_global_location_list (enum ugll_insert_mode
);
273 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
275 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
277 static void insert_breakpoint_locations (void);
279 static void tracepoints_info (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num
);
291 static int is_masked_watchpoint (const struct breakpoint
*b
);
293 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint
*b
);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops
;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops
;
311 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
312 static struct breakpoint_ops longjmp_breakpoint_ops
;
314 /* The breakpoint_ops structure to be used in regular user created
316 struct breakpoint_ops bkpt_breakpoint_ops
;
318 /* Breakpoints set on probes. */
319 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
321 /* Dynamic printf class type. */
322 struct breakpoint_ops dprintf_breakpoint_ops
;
324 /* The style in which to perform a dynamic printf. This is a user
325 option because different output options have different tradeoffs;
326 if GDB does the printing, there is better error handling if there
327 is a problem with any of the arguments, but using an inferior
328 function lets you have special-purpose printers and sending of
329 output to the same place as compiled-in print functions. */
331 static const char dprintf_style_gdb
[] = "gdb";
332 static const char dprintf_style_call
[] = "call";
333 static const char dprintf_style_agent
[] = "agent";
334 static const char *const dprintf_style_enums
[] = {
340 static const char *dprintf_style
= dprintf_style_gdb
;
342 /* The function to use for dynamic printf if the preferred style is to
343 call into the inferior. The value is simply a string that is
344 copied into the command, so it can be anything that GDB can
345 evaluate to a callable address, not necessarily a function name. */
347 static char *dprintf_function
;
349 /* The channel to use for dynamic printf if the preferred style is to
350 call into the inferior; if a nonempty string, it will be passed to
351 the call as the first argument, with the format string as the
352 second. As with the dprintf function, this can be anything that
353 GDB knows how to evaluate, so in addition to common choices like
354 "stderr", this could be an app-specific expression like
355 "mystreams[curlogger]". */
357 static char *dprintf_channel
;
359 /* True if dprintf commands should continue to operate even if GDB
361 static int disconnected_dprintf
= 1;
363 /* A reference-counted struct command_line. This lets multiple
364 breakpoints share a single command list. */
365 struct counted_command_line
367 /* The reference count. */
370 /* The command list. */
371 struct command_line
*commands
;
374 struct command_line
*
375 breakpoint_commands (struct breakpoint
*b
)
377 return b
->commands
? b
->commands
->commands
: NULL
;
380 /* Flag indicating that a command has proceeded the inferior past the
381 current breakpoint. */
383 static int breakpoint_proceeded
;
386 bpdisp_text (enum bpdisp disp
)
388 /* NOTE: the following values are a part of MI protocol and
389 represent values of 'disp' field returned when inferior stops at
391 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
393 return bpdisps
[(int) disp
];
396 /* Prototypes for exported functions. */
397 /* If FALSE, gdb will not use hardware support for watchpoints, even
398 if such is available. */
399 static int can_use_hw_watchpoints
;
402 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
,
406 fprintf_filtered (file
,
407 _("Debugger's willingness to use "
408 "watchpoint hardware is %s.\n"),
412 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
413 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
414 for unrecognized breakpoint locations.
415 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
416 static enum auto_boolean pending_break_support
;
418 show_pending_break_support (struct ui_file
*file
, int from_tty
,
419 struct cmd_list_element
*c
,
422 fprintf_filtered (file
,
423 _("Debugger's behavior regarding "
424 "pending breakpoints is %s.\n"),
428 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
429 set with "break" but falling in read-only memory.
430 If 0, gdb will warn about such breakpoints, but won't automatically
431 use hardware breakpoints. */
432 static int automatic_hardware_breakpoints
;
434 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
435 struct cmd_list_element
*c
,
438 fprintf_filtered (file
,
439 _("Automatic usage of hardware breakpoints is %s.\n"),
443 /* If on, GDB keeps breakpoints inserted even if the inferior is
444 stopped, and immediately inserts any new breakpoints as soon as
445 they're created. If off (default), GDB keeps breakpoints off of
446 the target as long as possible. That is, it delays inserting
447 breakpoints until the next resume, and removes them again when the
448 target fully stops. This is a bit safer in case GDB crashes while
449 processing user input. */
450 static int always_inserted_mode
= 0;
453 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
, const char *value
)
456 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
460 /* See breakpoint.h. */
463 breakpoints_should_be_inserted_now (void)
465 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
467 /* If breakpoints are global, they should be inserted even if no
468 thread under gdb's control is running, or even if there are
469 no threads under GDB's control yet. */
472 else if (target_has_execution
)
474 struct thread_info
*tp
;
476 if (always_inserted_mode
)
478 /* The user wants breakpoints inserted even if all threads
483 if (threads_are_executing ())
486 /* Don't remove breakpoints yet if, even though all threads are
487 stopped, we still have events to process. */
488 ALL_NON_EXITED_THREADS (tp
)
490 && tp
->suspend
.waitstatus_pending_p
)
496 static const char condition_evaluation_both
[] = "host or target";
498 /* Modes for breakpoint condition evaluation. */
499 static const char condition_evaluation_auto
[] = "auto";
500 static const char condition_evaluation_host
[] = "host";
501 static const char condition_evaluation_target
[] = "target";
502 static const char *const condition_evaluation_enums
[] = {
503 condition_evaluation_auto
,
504 condition_evaluation_host
,
505 condition_evaluation_target
,
509 /* Global that holds the current mode for breakpoint condition evaluation. */
510 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
512 /* Global that we use to display information to the user (gets its value from
513 condition_evaluation_mode_1. */
514 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
516 /* Translate a condition evaluation mode MODE into either "host"
517 or "target". This is used mostly to translate from "auto" to the
518 real setting that is being used. It returns the translated
522 translate_condition_evaluation_mode (const char *mode
)
524 if (mode
== condition_evaluation_auto
)
526 if (target_supports_evaluation_of_breakpoint_conditions ())
527 return condition_evaluation_target
;
529 return condition_evaluation_host
;
535 /* Discovers what condition_evaluation_auto translates to. */
538 breakpoint_condition_evaluation_mode (void)
540 return translate_condition_evaluation_mode (condition_evaluation_mode
);
543 /* Return true if GDB should evaluate breakpoint conditions or false
547 gdb_evaluates_breakpoint_condition_p (void)
549 const char *mode
= breakpoint_condition_evaluation_mode ();
551 return (mode
== condition_evaluation_host
);
554 void _initialize_breakpoint (void);
556 /* Are we executing breakpoint commands? */
557 static int executing_breakpoint_commands
;
559 /* Are overlay event breakpoints enabled? */
560 static int overlay_events_enabled
;
562 /* See description in breakpoint.h. */
563 int target_exact_watchpoints
= 0;
565 /* Walk the following statement or block through all breakpoints.
566 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
567 current breakpoint. */
569 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
571 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
572 for (B = breakpoint_chain; \
573 B ? (TMP=B->next, 1): 0; \
576 /* Similar iterator for the low-level breakpoints. SAFE variant is
577 not provided so update_global_location_list must not be called
578 while executing the block of ALL_BP_LOCATIONS. */
580 #define ALL_BP_LOCATIONS(B,BP_TMP) \
581 for (BP_TMP = bp_locations; \
582 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
585 /* Iterates through locations with address ADDRESS for the currently selected
586 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
587 to where the loop should start from.
588 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
589 appropriate location to start with. */
591 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
592 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
593 BP_LOCP_TMP = BP_LOCP_START; \
595 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
596 && (*BP_LOCP_TMP)->address == ADDRESS); \
599 /* Iterator for tracepoints only. */
601 #define ALL_TRACEPOINTS(B) \
602 for (B = breakpoint_chain; B; B = B->next) \
603 if (is_tracepoint (B))
605 /* Chains of all breakpoints defined. */
607 struct breakpoint
*breakpoint_chain
;
609 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
611 static struct bp_location
**bp_locations
;
613 /* Number of elements of BP_LOCATIONS. */
615 static unsigned bp_locations_count
;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATIONS which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_locations_placed_address_before_address_max
;
625 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
626 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
627 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATIONS to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from the bp_locations array, but for which a hit may still be
635 reported by a target. */
636 VEC(bp_location_p
) *moribund_locations
= NULL
;
638 /* Number of last breakpoint made. */
640 static int breakpoint_count
;
642 /* The value of `breakpoint_count' before the last command that
643 created breakpoints. If the last (break-like) command created more
644 than one breakpoint, then the difference between BREAKPOINT_COUNT
645 and PREV_BREAKPOINT_COUNT is more than one. */
646 static int prev_breakpoint_count
;
648 /* Number of last tracepoint made. */
650 static int tracepoint_count
;
652 static struct cmd_list_element
*breakpoint_set_cmdlist
;
653 static struct cmd_list_element
*breakpoint_show_cmdlist
;
654 struct cmd_list_element
*save_cmdlist
;
656 /* See declaration at breakpoint.h. */
659 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
662 struct breakpoint
*b
= NULL
;
666 if (func (b
, user_data
) != 0)
673 /* Return whether a breakpoint is an active enabled breakpoint. */
675 breakpoint_enabled (struct breakpoint
*b
)
677 return (b
->enable_state
== bp_enabled
);
680 /* Set breakpoint count to NUM. */
683 set_breakpoint_count (int num
)
685 prev_breakpoint_count
= breakpoint_count
;
686 breakpoint_count
= num
;
687 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
690 /* Used by `start_rbreak_breakpoints' below, to record the current
691 breakpoint count before "rbreak" creates any breakpoint. */
692 static int rbreak_start_breakpoint_count
;
694 /* Called at the start an "rbreak" command to record the first
698 start_rbreak_breakpoints (void)
700 rbreak_start_breakpoint_count
= breakpoint_count
;
703 /* Called at the end of an "rbreak" command to record the last
707 end_rbreak_breakpoints (void)
709 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
712 /* Used in run_command to zero the hit count when a new run starts. */
715 clear_breakpoint_hit_counts (void)
717 struct breakpoint
*b
;
723 /* Allocate a new counted_command_line with reference count of 1.
724 The new structure owns COMMANDS. */
726 static struct counted_command_line
*
727 alloc_counted_command_line (struct command_line
*commands
)
729 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
732 result
->commands
= commands
;
737 /* Increment reference count. This does nothing if CMD is NULL. */
740 incref_counted_command_line (struct counted_command_line
*cmd
)
746 /* Decrement reference count. If the reference count reaches 0,
747 destroy the counted_command_line. Sets *CMDP to NULL. This does
748 nothing if *CMDP is NULL. */
751 decref_counted_command_line (struct counted_command_line
**cmdp
)
755 if (--(*cmdp
)->refc
== 0)
757 free_command_lines (&(*cmdp
)->commands
);
764 /* A cleanup function that calls decref_counted_command_line. */
767 do_cleanup_counted_command_line (void *arg
)
769 decref_counted_command_line ((struct counted_command_line
**) arg
);
772 /* Create a cleanup that calls decref_counted_command_line on the
775 static struct cleanup
*
776 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
778 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
782 /* Return the breakpoint with the specified number, or NULL
783 if the number does not refer to an existing breakpoint. */
786 get_breakpoint (int num
)
788 struct breakpoint
*b
;
791 if (b
->number
== num
)
799 /* Mark locations as "conditions have changed" in case the target supports
800 evaluating conditions on its side. */
803 mark_breakpoint_modified (struct breakpoint
*b
)
805 struct bp_location
*loc
;
807 /* This is only meaningful if the target is
808 evaluating conditions and if the user has
809 opted for condition evaluation on the target's
811 if (gdb_evaluates_breakpoint_condition_p ()
812 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (b
))
818 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
819 loc
->condition_changed
= condition_modified
;
822 /* Mark location as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_location_modified (struct bp_location
*loc
)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
837 if (!is_breakpoint (loc
->owner
))
840 loc
->condition_changed
= condition_modified
;
843 /* Sets the condition-evaluation mode using the static global
844 condition_evaluation_mode. */
847 set_condition_evaluation_mode (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 const char *old_mode
, *new_mode
;
852 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
853 && !target_supports_evaluation_of_breakpoint_conditions ())
855 condition_evaluation_mode_1
= condition_evaluation_mode
;
856 warning (_("Target does not support breakpoint condition evaluation.\n"
857 "Using host evaluation mode instead."));
861 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
862 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
864 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
865 settings was "auto". */
866 condition_evaluation_mode
= condition_evaluation_mode_1
;
868 /* Only update the mode if the user picked a different one. */
869 if (new_mode
!= old_mode
)
871 struct bp_location
*loc
, **loc_tmp
;
872 /* If the user switched to a different evaluation mode, we
873 need to synch the changes with the target as follows:
875 "host" -> "target": Send all (valid) conditions to the target.
876 "target" -> "host": Remove all the conditions from the target.
879 if (new_mode
== condition_evaluation_target
)
881 /* Mark everything modified and synch conditions with the
883 ALL_BP_LOCATIONS (loc
, loc_tmp
)
884 mark_breakpoint_location_modified (loc
);
888 /* Manually mark non-duplicate locations to synch conditions
889 with the target. We do this to remove all the conditions the
890 target knows about. */
891 ALL_BP_LOCATIONS (loc
, loc_tmp
)
892 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
893 loc
->needs_update
= 1;
897 update_global_location_list (UGLL_MAY_INSERT
);
903 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
904 what "auto" is translating to. */
907 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
908 struct cmd_list_element
*c
, const char *value
)
910 if (condition_evaluation_mode
== condition_evaluation_auto
)
911 fprintf_filtered (file
,
912 _("Breakpoint condition evaluation "
913 "mode is %s (currently %s).\n"),
915 breakpoint_condition_evaluation_mode ());
917 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
921 /* A comparison function for bp_location AP and BP that is used by
922 bsearch. This comparison function only cares about addresses, unlike
923 the more general bp_locations_compare function. */
926 bp_locations_compare_addrs (const void *ap
, const void *bp
)
928 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
929 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
931 if (a
->address
== b
->address
)
934 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
937 /* Helper function to skip all bp_locations with addresses
938 less than ADDRESS. It returns the first bp_location that
939 is greater than or equal to ADDRESS. If none is found, just
942 static struct bp_location
**
943 get_first_locp_gte_addr (CORE_ADDR address
)
945 struct bp_location dummy_loc
;
946 struct bp_location
*dummy_locp
= &dummy_loc
;
947 struct bp_location
**locp_found
= NULL
;
949 /* Initialize the dummy location's address field. */
950 dummy_loc
.address
= address
;
952 /* Find a close match to the first location at ADDRESS. */
953 locp_found
= ((struct bp_location
**)
954 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
955 sizeof (struct bp_location
**),
956 bp_locations_compare_addrs
));
958 /* Nothing was found, nothing left to do. */
959 if (locp_found
== NULL
)
962 /* We may have found a location that is at ADDRESS but is not the first in the
963 location's list. Go backwards (if possible) and locate the first one. */
964 while ((locp_found
- 1) >= bp_locations
965 && (*(locp_found
- 1))->address
== address
)
972 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
975 xfree (b
->cond_string
);
976 b
->cond_string
= NULL
;
978 if (is_watchpoint (b
))
980 struct watchpoint
*w
= (struct watchpoint
*) b
;
982 w
->cond_exp
.reset ();
986 struct bp_location
*loc
;
988 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
992 /* No need to free the condition agent expression
993 bytecode (if we have one). We will handle this
994 when we go through update_global_location_list. */
1001 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1005 const char *arg
= exp
;
1007 /* I don't know if it matters whether this is the string the user
1008 typed in or the decompiled expression. */
1009 b
->cond_string
= xstrdup (arg
);
1010 b
->condition_not_parsed
= 0;
1012 if (is_watchpoint (b
))
1014 struct watchpoint
*w
= (struct watchpoint
*) b
;
1016 innermost_block
= NULL
;
1018 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1020 error (_("Junk at end of expression"));
1021 w
->cond_exp_valid_block
= innermost_block
;
1025 struct bp_location
*loc
;
1027 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1031 parse_exp_1 (&arg
, loc
->address
,
1032 block_for_pc (loc
->address
), 0);
1034 error (_("Junk at end of expression"));
1038 mark_breakpoint_modified (b
);
1040 observer_notify_breakpoint_modified (b
);
1043 /* Completion for the "condition" command. */
1045 static VEC (char_ptr
) *
1046 condition_completer (struct cmd_list_element
*cmd
,
1047 const char *text
, const char *word
)
1051 text
= skip_spaces_const (text
);
1052 space
= skip_to_space_const (text
);
1056 struct breakpoint
*b
;
1057 VEC (char_ptr
) *result
= NULL
;
1061 /* We don't support completion of history indices. */
1062 if (isdigit (text
[1]))
1064 return complete_internalvar (&text
[1]);
1067 /* We're completing the breakpoint number. */
1068 len
= strlen (text
);
1074 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1076 if (strncmp (number
, text
, len
) == 0)
1077 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1083 /* We're completing the expression part. */
1084 text
= skip_spaces_const (space
);
1085 return expression_completer (cmd
, text
, word
);
1088 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1091 condition_command (char *arg
, int from_tty
)
1093 struct breakpoint
*b
;
1098 error_no_arg (_("breakpoint number"));
1101 bnum
= get_number (&p
);
1103 error (_("Bad breakpoint argument: '%s'"), arg
);
1106 if (b
->number
== bnum
)
1108 /* Check if this breakpoint has a "stop" method implemented in an
1109 extension language. This method and conditions entered into GDB
1110 from the CLI are mutually exclusive. */
1111 const struct extension_language_defn
*extlang
1112 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1114 if (extlang
!= NULL
)
1116 error (_("Only one stop condition allowed. There is currently"
1117 " a %s stop condition defined for this breakpoint."),
1118 ext_lang_capitalized_name (extlang
));
1120 set_breakpoint_condition (b
, p
, from_tty
);
1122 if (is_breakpoint (b
))
1123 update_global_location_list (UGLL_MAY_INSERT
);
1128 error (_("No breakpoint number %d."), bnum
);
1131 /* Check that COMMAND do not contain commands that are suitable
1132 only for tracepoints and not suitable for ordinary breakpoints.
1133 Throw if any such commands is found. */
1136 check_no_tracepoint_commands (struct command_line
*commands
)
1138 struct command_line
*c
;
1140 for (c
= commands
; c
; c
= c
->next
)
1144 if (c
->control_type
== while_stepping_control
)
1145 error (_("The 'while-stepping' command can "
1146 "only be used for tracepoints"));
1148 for (i
= 0; i
< c
->body_count
; ++i
)
1149 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1151 /* Not that command parsing removes leading whitespace and comment
1152 lines and also empty lines. So, we only need to check for
1153 command directly. */
1154 if (strstr (c
->line
, "collect ") == c
->line
)
1155 error (_("The 'collect' command can only be used for tracepoints"));
1157 if (strstr (c
->line
, "teval ") == c
->line
)
1158 error (_("The 'teval' command can only be used for tracepoints"));
1162 /* Encapsulate tests for different types of tracepoints. */
1165 is_tracepoint_type (enum bptype type
)
1167 return (type
== bp_tracepoint
1168 || type
== bp_fast_tracepoint
1169 || type
== bp_static_tracepoint
);
1173 is_tracepoint (const struct breakpoint
*b
)
1175 return is_tracepoint_type (b
->type
);
1178 /* A helper function that validates that COMMANDS are valid for a
1179 breakpoint. This function will throw an exception if a problem is
1183 validate_commands_for_breakpoint (struct breakpoint
*b
,
1184 struct command_line
*commands
)
1186 if (is_tracepoint (b
))
1188 struct tracepoint
*t
= (struct tracepoint
*) b
;
1189 struct command_line
*c
;
1190 struct command_line
*while_stepping
= 0;
1192 /* Reset the while-stepping step count. The previous commands
1193 might have included a while-stepping action, while the new
1197 /* We need to verify that each top-level element of commands is
1198 valid for tracepoints, that there's at most one
1199 while-stepping element, and that the while-stepping's body
1200 has valid tracing commands excluding nested while-stepping.
1201 We also need to validate the tracepoint action line in the
1202 context of the tracepoint --- validate_actionline actually
1203 has side effects, like setting the tracepoint's
1204 while-stepping STEP_COUNT, in addition to checking if the
1205 collect/teval actions parse and make sense in the
1206 tracepoint's context. */
1207 for (c
= commands
; c
; c
= c
->next
)
1209 if (c
->control_type
== while_stepping_control
)
1211 if (b
->type
== bp_fast_tracepoint
)
1212 error (_("The 'while-stepping' command "
1213 "cannot be used for fast tracepoint"));
1214 else if (b
->type
== bp_static_tracepoint
)
1215 error (_("The 'while-stepping' command "
1216 "cannot be used for static tracepoint"));
1219 error (_("The 'while-stepping' command "
1220 "can be used only once"));
1225 validate_actionline (c
->line
, b
);
1229 struct command_line
*c2
;
1231 gdb_assert (while_stepping
->body_count
== 1);
1232 c2
= while_stepping
->body_list
[0];
1233 for (; c2
; c2
= c2
->next
)
1235 if (c2
->control_type
== while_stepping_control
)
1236 error (_("The 'while-stepping' command cannot be nested"));
1242 check_no_tracepoint_commands (commands
);
1246 /* Return a vector of all the static tracepoints set at ADDR. The
1247 caller is responsible for releasing the vector. */
1250 static_tracepoints_here (CORE_ADDR addr
)
1252 struct breakpoint
*b
;
1253 VEC(breakpoint_p
) *found
= 0;
1254 struct bp_location
*loc
;
1257 if (b
->type
== bp_static_tracepoint
)
1259 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1260 if (loc
->address
== addr
)
1261 VEC_safe_push(breakpoint_p
, found
, b
);
1267 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1268 validate that only allowed commands are included. */
1271 breakpoint_set_commands (struct breakpoint
*b
,
1272 command_line_up
&&commands
)
1274 validate_commands_for_breakpoint (b
, commands
.get ());
1276 decref_counted_command_line (&b
->commands
);
1277 b
->commands
= alloc_counted_command_line (commands
.release ());
1278 observer_notify_breakpoint_modified (b
);
1281 /* Set the internal `silent' flag on the breakpoint. Note that this
1282 is not the same as the "silent" that may appear in the breakpoint's
1286 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1288 int old_silent
= b
->silent
;
1291 if (old_silent
!= silent
)
1292 observer_notify_breakpoint_modified (b
);
1295 /* Set the thread for this breakpoint. If THREAD is -1, make the
1296 breakpoint work for any thread. */
1299 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1301 int old_thread
= b
->thread
;
1304 if (old_thread
!= thread
)
1305 observer_notify_breakpoint_modified (b
);
1308 /* Set the task for this breakpoint. If TASK is 0, make the
1309 breakpoint work for any task. */
1312 breakpoint_set_task (struct breakpoint
*b
, int task
)
1314 int old_task
= b
->task
;
1317 if (old_task
!= task
)
1318 observer_notify_breakpoint_modified (b
);
1322 check_tracepoint_command (char *line
, void *closure
)
1324 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1326 validate_actionline (line
, b
);
1329 /* A structure used to pass information through
1330 map_breakpoint_numbers. */
1332 struct commands_info
1334 /* True if the command was typed at a tty. */
1337 /* The breakpoint range spec. */
1340 /* Non-NULL if the body of the commands are being read from this
1341 already-parsed command. */
1342 struct command_line
*control
;
1344 /* The command lines read from the user, or NULL if they have not
1346 struct counted_command_line
*cmd
;
1349 /* A callback for map_breakpoint_numbers that sets the commands for
1350 commands_command. */
1353 do_map_commands_command (struct breakpoint
*b
, void *data
)
1355 struct commands_info
*info
= (struct commands_info
*) data
;
1357 if (info
->cmd
== NULL
)
1361 if (info
->control
!= NULL
)
1362 l
= copy_command_lines (info
->control
->body_list
[0]);
1365 struct cleanup
*old_chain
;
1368 str
= xstrprintf (_("Type commands for breakpoint(s) "
1369 "%s, one per line."),
1372 old_chain
= make_cleanup (xfree
, str
);
1374 l
= read_command_lines (str
,
1377 ? check_tracepoint_command
: 0),
1380 do_cleanups (old_chain
);
1383 info
->cmd
= alloc_counted_command_line (l
.release ());
1386 /* If a breakpoint was on the list more than once, we don't need to
1388 if (b
->commands
!= info
->cmd
)
1390 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1391 incref_counted_command_line (info
->cmd
);
1392 decref_counted_command_line (&b
->commands
);
1393 b
->commands
= info
->cmd
;
1394 observer_notify_breakpoint_modified (b
);
1399 commands_command_1 (const char *arg
, int from_tty
,
1400 struct command_line
*control
)
1402 struct cleanup
*cleanups
;
1403 struct commands_info info
;
1405 info
.from_tty
= from_tty
;
1406 info
.control
= control
;
1408 /* If we read command lines from the user, then `info' will hold an
1409 extra reference to the commands that we must clean up. */
1410 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1412 std::string new_arg
;
1414 if (arg
== NULL
|| !*arg
)
1416 if (breakpoint_count
- prev_breakpoint_count
> 1)
1417 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1419 else if (breakpoint_count
> 0)
1420 new_arg
= string_printf ("%d", breakpoint_count
);
1425 info
.arg
= new_arg
.c_str ();
1427 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1429 if (info
.cmd
== NULL
)
1430 error (_("No breakpoints specified."));
1432 do_cleanups (cleanups
);
1436 commands_command (char *arg
, int from_tty
)
1438 commands_command_1 (arg
, from_tty
, NULL
);
1441 /* Like commands_command, but instead of reading the commands from
1442 input stream, takes them from an already parsed command structure.
1444 This is used by cli-script.c to DTRT with breakpoint commands
1445 that are part of if and while bodies. */
1446 enum command_control_type
1447 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1449 commands_command_1 (arg
, 0, cmd
);
1450 return simple_control
;
1453 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1456 bp_location_has_shadow (struct bp_location
*bl
)
1458 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1462 if (bl
->target_info
.shadow_len
== 0)
1463 /* BL isn't valid, or doesn't shadow memory. */
1468 /* Update BUF, which is LEN bytes read from the target address
1469 MEMADDR, by replacing a memory breakpoint with its shadowed
1472 If READBUF is not NULL, this buffer must not overlap with the of
1473 the breakpoint location's shadow_contents buffer. Otherwise, a
1474 failed assertion internal error will be raised. */
1477 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1478 const gdb_byte
*writebuf_org
,
1479 ULONGEST memaddr
, LONGEST len
,
1480 struct bp_target_info
*target_info
,
1481 struct gdbarch
*gdbarch
)
1483 /* Now do full processing of the found relevant range of elements. */
1484 CORE_ADDR bp_addr
= 0;
1488 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1489 current_program_space
->aspace
, 0))
1491 /* The breakpoint is inserted in a different address space. */
1495 /* Addresses and length of the part of the breakpoint that
1497 bp_addr
= target_info
->placed_address
;
1498 bp_size
= target_info
->shadow_len
;
1500 if (bp_addr
+ bp_size
<= memaddr
)
1502 /* The breakpoint is entirely before the chunk of memory we are
1507 if (bp_addr
>= memaddr
+ len
)
1509 /* The breakpoint is entirely after the chunk of memory we are
1514 /* Offset within shadow_contents. */
1515 if (bp_addr
< memaddr
)
1517 /* Only copy the second part of the breakpoint. */
1518 bp_size
-= memaddr
- bp_addr
;
1519 bptoffset
= memaddr
- bp_addr
;
1523 if (bp_addr
+ bp_size
> memaddr
+ len
)
1525 /* Only copy the first part of the breakpoint. */
1526 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1529 if (readbuf
!= NULL
)
1531 /* Verify that the readbuf buffer does not overlap with the
1532 shadow_contents buffer. */
1533 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1534 || readbuf
>= (target_info
->shadow_contents
1535 + target_info
->shadow_len
));
1537 /* Update the read buffer with this inserted breakpoint's
1539 memcpy (readbuf
+ bp_addr
- memaddr
,
1540 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1544 const unsigned char *bp
;
1545 CORE_ADDR addr
= target_info
->reqstd_address
;
1548 /* Update the shadow with what we want to write to memory. */
1549 memcpy (target_info
->shadow_contents
+ bptoffset
,
1550 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1552 /* Determine appropriate breakpoint contents and size for this
1554 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1556 /* Update the final write buffer with this inserted
1557 breakpoint's INSN. */
1558 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1562 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1563 by replacing any memory breakpoints with their shadowed contents.
1565 If READBUF is not NULL, this buffer must not overlap with any of
1566 the breakpoint location's shadow_contents buffers. Otherwise,
1567 a failed assertion internal error will be raised.
1569 The range of shadowed area by each bp_location is:
1570 bl->address - bp_locations_placed_address_before_address_max
1571 up to bl->address + bp_locations_shadow_len_after_address_max
1572 The range we were requested to resolve shadows for is:
1573 memaddr ... memaddr + len
1574 Thus the safe cutoff boundaries for performance optimization are
1575 memaddr + len <= (bl->address
1576 - bp_locations_placed_address_before_address_max)
1578 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1581 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1582 const gdb_byte
*writebuf_org
,
1583 ULONGEST memaddr
, LONGEST len
)
1585 /* Left boundary, right boundary and median element of our binary
1587 unsigned bc_l
, bc_r
, bc
;
1589 /* Find BC_L which is a leftmost element which may affect BUF
1590 content. It is safe to report lower value but a failure to
1591 report higher one. */
1594 bc_r
= bp_locations_count
;
1595 while (bc_l
+ 1 < bc_r
)
1597 struct bp_location
*bl
;
1599 bc
= (bc_l
+ bc_r
) / 2;
1600 bl
= bp_locations
[bc
];
1602 /* Check first BL->ADDRESS will not overflow due to the added
1603 constant. Then advance the left boundary only if we are sure
1604 the BC element can in no way affect the BUF content (MEMADDR
1605 to MEMADDR + LEN range).
1607 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1608 offset so that we cannot miss a breakpoint with its shadow
1609 range tail still reaching MEMADDR. */
1611 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1613 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1620 /* Due to the binary search above, we need to make sure we pick the
1621 first location that's at BC_L's address. E.g., if there are
1622 multiple locations at the same address, BC_L may end up pointing
1623 at a duplicate location, and miss the "master"/"inserted"
1624 location. Say, given locations L1, L2 and L3 at addresses A and
1627 L1@A, L2@A, L3@B, ...
1629 BC_L could end up pointing at location L2, while the "master"
1630 location could be L1. Since the `loc->inserted' flag is only set
1631 on "master" locations, we'd forget to restore the shadow of L1
1634 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1637 /* Now do full processing of the found relevant range of elements. */
1639 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1641 struct bp_location
*bl
= bp_locations
[bc
];
1643 /* bp_location array has BL->OWNER always non-NULL. */
1644 if (bl
->owner
->type
== bp_none
)
1645 warning (_("reading through apparently deleted breakpoint #%d?"),
1648 /* Performance optimization: any further element can no longer affect BUF
1651 if (bl
->address
>= bp_locations_placed_address_before_address_max
1652 && memaddr
+ len
<= (bl
->address
1653 - bp_locations_placed_address_before_address_max
))
1656 if (!bp_location_has_shadow (bl
))
1659 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1660 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1666 /* Return true if BPT is either a software breakpoint or a hardware
1670 is_breakpoint (const struct breakpoint
*bpt
)
1672 return (bpt
->type
== bp_breakpoint
1673 || bpt
->type
== bp_hardware_breakpoint
1674 || bpt
->type
== bp_dprintf
);
1677 /* Return true if BPT is of any hardware watchpoint kind. */
1680 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1682 return (bpt
->type
== bp_hardware_watchpoint
1683 || bpt
->type
== bp_read_watchpoint
1684 || bpt
->type
== bp_access_watchpoint
);
1687 /* Return true if BPT is of any watchpoint kind, hardware or
1691 is_watchpoint (const struct breakpoint
*bpt
)
1693 return (is_hardware_watchpoint (bpt
)
1694 || bpt
->type
== bp_watchpoint
);
1697 /* Returns true if the current thread and its running state are safe
1698 to evaluate or update watchpoint B. Watchpoints on local
1699 expressions need to be evaluated in the context of the thread that
1700 was current when the watchpoint was created, and, that thread needs
1701 to be stopped to be able to select the correct frame context.
1702 Watchpoints on global expressions can be evaluated on any thread,
1703 and in any state. It is presently left to the target allowing
1704 memory accesses when threads are running. */
1707 watchpoint_in_thread_scope (struct watchpoint
*b
)
1709 return (b
->base
.pspace
== current_program_space
1710 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1711 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1712 && !is_executing (inferior_ptid
))));
1715 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1716 associated bp_watchpoint_scope breakpoint. */
1719 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1721 struct breakpoint
*b
= &w
->base
;
1723 if (b
->related_breakpoint
!= b
)
1725 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1726 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1727 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1728 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1729 b
->related_breakpoint
= b
;
1731 b
->disposition
= disp_del_at_next_stop
;
1734 /* Extract a bitfield value from value VAL using the bit parameters contained in
1737 static struct value
*
1738 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1740 struct value
*bit_val
;
1745 bit_val
= allocate_value (value_type (val
));
1747 unpack_value_bitfield (bit_val
,
1750 value_contents_for_printing (val
),
1757 /* Allocate a dummy location and add it to B, which must be a software
1758 watchpoint. This is required because even if a software watchpoint
1759 is not watching any memory, bpstat_stop_status requires a location
1760 to be able to report stops. */
1763 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1764 struct program_space
*pspace
)
1766 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1768 b
->loc
= allocate_bp_location (b
);
1769 b
->loc
->pspace
= pspace
;
1770 b
->loc
->address
= -1;
1771 b
->loc
->length
= -1;
1774 /* Returns true if B is a software watchpoint that is not watching any
1775 memory (e.g., "watch $pc"). */
1778 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1780 return (b
->type
== bp_watchpoint
1782 && b
->loc
->next
== NULL
1783 && b
->loc
->address
== -1
1784 && b
->loc
->length
== -1);
1787 /* Assuming that B is a watchpoint:
1788 - Reparse watchpoint expression, if REPARSE is non-zero
1789 - Evaluate expression and store the result in B->val
1790 - Evaluate the condition if there is one, and store the result
1792 - Update the list of values that must be watched in B->loc.
1794 If the watchpoint disposition is disp_del_at_next_stop, then do
1795 nothing. If this is local watchpoint that is out of scope, delete
1798 Even with `set breakpoint always-inserted on' the watchpoints are
1799 removed + inserted on each stop here. Normal breakpoints must
1800 never be removed because they might be missed by a running thread
1801 when debugging in non-stop mode. On the other hand, hardware
1802 watchpoints (is_hardware_watchpoint; processed here) are specific
1803 to each LWP since they are stored in each LWP's hardware debug
1804 registers. Therefore, such LWP must be stopped first in order to
1805 be able to modify its hardware watchpoints.
1807 Hardware watchpoints must be reset exactly once after being
1808 presented to the user. It cannot be done sooner, because it would
1809 reset the data used to present the watchpoint hit to the user. And
1810 it must not be done later because it could display the same single
1811 watchpoint hit during multiple GDB stops. Note that the latter is
1812 relevant only to the hardware watchpoint types bp_read_watchpoint
1813 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1814 not user-visible - its hit is suppressed if the memory content has
1817 The following constraints influence the location where we can reset
1818 hardware watchpoints:
1820 * target_stopped_by_watchpoint and target_stopped_data_address are
1821 called several times when GDB stops.
1824 * Multiple hardware watchpoints can be hit at the same time,
1825 causing GDB to stop. GDB only presents one hardware watchpoint
1826 hit at a time as the reason for stopping, and all the other hits
1827 are presented later, one after the other, each time the user
1828 requests the execution to be resumed. Execution is not resumed
1829 for the threads still having pending hit event stored in
1830 LWP_INFO->STATUS. While the watchpoint is already removed from
1831 the inferior on the first stop the thread hit event is kept being
1832 reported from its cached value by linux_nat_stopped_data_address
1833 until the real thread resume happens after the watchpoint gets
1834 presented and thus its LWP_INFO->STATUS gets reset.
1836 Therefore the hardware watchpoint hit can get safely reset on the
1837 watchpoint removal from inferior. */
1840 update_watchpoint (struct watchpoint
*b
, int reparse
)
1842 int within_current_scope
;
1843 struct frame_id saved_frame_id
;
1846 /* If this is a local watchpoint, we only want to check if the
1847 watchpoint frame is in scope if the current thread is the thread
1848 that was used to create the watchpoint. */
1849 if (!watchpoint_in_thread_scope (b
))
1852 if (b
->base
.disposition
== disp_del_at_next_stop
)
1857 /* Determine if the watchpoint is within scope. */
1858 if (b
->exp_valid_block
== NULL
)
1859 within_current_scope
= 1;
1862 struct frame_info
*fi
= get_current_frame ();
1863 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1864 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1866 /* If we're at a point where the stack has been destroyed
1867 (e.g. in a function epilogue), unwinding may not work
1868 properly. Do not attempt to recreate locations at this
1869 point. See similar comments in watchpoint_check. */
1870 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1873 /* Save the current frame's ID so we can restore it after
1874 evaluating the watchpoint expression on its own frame. */
1875 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1876 took a frame parameter, so that we didn't have to change the
1879 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1881 fi
= frame_find_by_id (b
->watchpoint_frame
);
1882 within_current_scope
= (fi
!= NULL
);
1883 if (within_current_scope
)
1887 /* We don't free locations. They are stored in the bp_location array
1888 and update_global_location_list will eventually delete them and
1889 remove breakpoints if needed. */
1892 if (within_current_scope
&& reparse
)
1897 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1898 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1899 /* If the meaning of expression itself changed, the old value is
1900 no longer relevant. We don't want to report a watchpoint hit
1901 to the user when the old value and the new value may actually
1902 be completely different objects. */
1903 value_free (b
->val
);
1907 /* Note that unlike with breakpoints, the watchpoint's condition
1908 expression is stored in the breakpoint object, not in the
1909 locations (re)created below. */
1910 if (b
->base
.cond_string
!= NULL
)
1912 b
->cond_exp
.reset ();
1914 s
= b
->base
.cond_string
;
1915 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1919 /* If we failed to parse the expression, for example because
1920 it refers to a global variable in a not-yet-loaded shared library,
1921 don't try to insert watchpoint. We don't automatically delete
1922 such watchpoint, though, since failure to parse expression
1923 is different from out-of-scope watchpoint. */
1924 if (!target_has_execution
)
1926 /* Without execution, memory can't change. No use to try and
1927 set watchpoint locations. The watchpoint will be reset when
1928 the target gains execution, through breakpoint_re_set. */
1929 if (!can_use_hw_watchpoints
)
1931 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1932 b
->base
.type
= bp_watchpoint
;
1934 error (_("Can't set read/access watchpoint when "
1935 "hardware watchpoints are disabled."));
1938 else if (within_current_scope
&& b
->exp
)
1941 struct value
*val_chain
, *v
, *result
, *next
;
1942 struct program_space
*frame_pspace
;
1944 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1946 /* Avoid setting b->val if it's already set. The meaning of
1947 b->val is 'the last value' user saw, and we should update
1948 it only if we reported that last value to user. As it
1949 happens, the code that reports it updates b->val directly.
1950 We don't keep track of the memory value for masked
1952 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1954 if (b
->val_bitsize
!= 0)
1956 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1964 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1966 /* Look at each value on the value chain. */
1967 for (v
= val_chain
; v
; v
= value_next (v
))
1969 /* If it's a memory location, and GDB actually needed
1970 its contents to evaluate the expression, then we
1971 must watch it. If the first value returned is
1972 still lazy, that means an error occurred reading it;
1973 watch it anyway in case it becomes readable. */
1974 if (VALUE_LVAL (v
) == lval_memory
1975 && (v
== val_chain
|| ! value_lazy (v
)))
1977 struct type
*vtype
= check_typedef (value_type (v
));
1979 /* We only watch structs and arrays if user asked
1980 for it explicitly, never if they just happen to
1981 appear in the middle of some value chain. */
1983 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1984 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1987 enum target_hw_bp_type type
;
1988 struct bp_location
*loc
, **tmp
;
1989 int bitpos
= 0, bitsize
= 0;
1991 if (value_bitsize (v
) != 0)
1993 /* Extract the bit parameters out from the bitfield
1995 bitpos
= value_bitpos (v
);
1996 bitsize
= value_bitsize (v
);
1998 else if (v
== result
&& b
->val_bitsize
!= 0)
2000 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2001 lvalue whose bit parameters are saved in the fields
2002 VAL_BITPOS and VAL_BITSIZE. */
2003 bitpos
= b
->val_bitpos
;
2004 bitsize
= b
->val_bitsize
;
2007 addr
= value_address (v
);
2010 /* Skip the bytes that don't contain the bitfield. */
2015 if (b
->base
.type
== bp_read_watchpoint
)
2017 else if (b
->base
.type
== bp_access_watchpoint
)
2020 loc
= allocate_bp_location (&b
->base
);
2021 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2024 loc
->gdbarch
= get_type_arch (value_type (v
));
2026 loc
->pspace
= frame_pspace
;
2027 loc
->address
= addr
;
2031 /* Just cover the bytes that make up the bitfield. */
2032 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2035 loc
->length
= TYPE_LENGTH (value_type (v
));
2037 loc
->watchpoint_type
= type
;
2042 /* Change the type of breakpoint between hardware assisted or
2043 an ordinary watchpoint depending on the hardware support
2044 and free hardware slots. REPARSE is set when the inferior
2049 enum bp_loc_type loc_type
;
2050 struct bp_location
*bl
;
2052 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2056 int i
, target_resources_ok
, other_type_used
;
2059 /* Use an exact watchpoint when there's only one memory region to be
2060 watched, and only one debug register is needed to watch it. */
2061 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2063 /* We need to determine how many resources are already
2064 used for all other hardware watchpoints plus this one
2065 to see if we still have enough resources to also fit
2066 this watchpoint in as well. */
2068 /* If this is a software watchpoint, we try to turn it
2069 to a hardware one -- count resources as if B was of
2070 hardware watchpoint type. */
2071 type
= b
->base
.type
;
2072 if (type
== bp_watchpoint
)
2073 type
= bp_hardware_watchpoint
;
2075 /* This watchpoint may or may not have been placed on
2076 the list yet at this point (it won't be in the list
2077 if we're trying to create it for the first time,
2078 through watch_command), so always account for it
2081 /* Count resources used by all watchpoints except B. */
2082 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2084 /* Add in the resources needed for B. */
2085 i
+= hw_watchpoint_use_count (&b
->base
);
2088 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2089 if (target_resources_ok
<= 0)
2091 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2093 if (target_resources_ok
== 0 && !sw_mode
)
2094 error (_("Target does not support this type of "
2095 "hardware watchpoint."));
2096 else if (target_resources_ok
< 0 && !sw_mode
)
2097 error (_("There are not enough available hardware "
2098 "resources for this watchpoint."));
2100 /* Downgrade to software watchpoint. */
2101 b
->base
.type
= bp_watchpoint
;
2105 /* If this was a software watchpoint, we've just
2106 found we have enough resources to turn it to a
2107 hardware watchpoint. Otherwise, this is a
2109 b
->base
.type
= type
;
2112 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2114 if (!can_use_hw_watchpoints
)
2115 error (_("Can't set read/access watchpoint when "
2116 "hardware watchpoints are disabled."));
2118 error (_("Expression cannot be implemented with "
2119 "read/access watchpoint."));
2122 b
->base
.type
= bp_watchpoint
;
2124 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2125 : bp_loc_hardware_watchpoint
);
2126 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2127 bl
->loc_type
= loc_type
;
2130 for (v
= val_chain
; v
; v
= next
)
2132 next
= value_next (v
);
2137 /* If a software watchpoint is not watching any memory, then the
2138 above left it without any location set up. But,
2139 bpstat_stop_status requires a location to be able to report
2140 stops, so make sure there's at least a dummy one. */
2141 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2142 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2144 else if (!within_current_scope
)
2146 printf_filtered (_("\
2147 Watchpoint %d deleted because the program has left the block\n\
2148 in which its expression is valid.\n"),
2150 watchpoint_del_at_next_stop (b
);
2153 /* Restore the selected frame. */
2155 select_frame (frame_find_by_id (saved_frame_id
));
2159 /* Returns 1 iff breakpoint location should be
2160 inserted in the inferior. We don't differentiate the type of BL's owner
2161 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2162 breakpoint_ops is not defined, because in insert_bp_location,
2163 tracepoint's insert_location will not be called. */
2165 should_be_inserted (struct bp_location
*bl
)
2167 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2170 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2173 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2176 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2179 /* This is set for example, when we're attached to the parent of a
2180 vfork, and have detached from the child. The child is running
2181 free, and we expect it to do an exec or exit, at which point the
2182 OS makes the parent schedulable again (and the target reports
2183 that the vfork is done). Until the child is done with the shared
2184 memory region, do not insert breakpoints in the parent, otherwise
2185 the child could still trip on the parent's breakpoints. Since
2186 the parent is blocked anyway, it won't miss any breakpoint. */
2187 if (bl
->pspace
->breakpoints_not_allowed
)
2190 /* Don't insert a breakpoint if we're trying to step past its
2191 location, except if the breakpoint is a single-step breakpoint,
2192 and the breakpoint's thread is the thread which is stepping past
2194 if ((bl
->loc_type
== bp_loc_software_breakpoint
2195 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2196 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2198 /* The single-step breakpoint may be inserted at the location
2199 we're trying to step if the instruction branches to itself.
2200 However, the instruction won't be executed at all and it may
2201 break the semantics of the instruction, for example, the
2202 instruction is a conditional branch or updates some flags.
2203 We can't fix it unless GDB is able to emulate the instruction
2204 or switch to displaced stepping. */
2205 && !(bl
->owner
->type
== bp_single_step
2206 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2210 fprintf_unfiltered (gdb_stdlog
,
2211 "infrun: skipping breakpoint: "
2212 "stepping past insn at: %s\n",
2213 paddress (bl
->gdbarch
, bl
->address
));
2218 /* Don't insert watchpoints if we're trying to step past the
2219 instruction that triggered one. */
2220 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2221 && stepping_past_nonsteppable_watchpoint ())
2225 fprintf_unfiltered (gdb_stdlog
,
2226 "infrun: stepping past non-steppable watchpoint. "
2227 "skipping watchpoint at %s:%d\n",
2228 paddress (bl
->gdbarch
, bl
->address
),
2237 /* Same as should_be_inserted but does the check assuming
2238 that the location is not duplicated. */
2241 unduplicated_should_be_inserted (struct bp_location
*bl
)
2244 const int save_duplicate
= bl
->duplicate
;
2247 result
= should_be_inserted (bl
);
2248 bl
->duplicate
= save_duplicate
;
2252 /* Parses a conditional described by an expression COND into an
2253 agent expression bytecode suitable for evaluation
2254 by the bytecode interpreter. Return NULL if there was
2255 any error during parsing. */
2257 static agent_expr_up
2258 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2263 agent_expr_up aexpr
;
2265 /* We don't want to stop processing, so catch any errors
2266 that may show up. */
2269 aexpr
= gen_eval_for_expr (scope
, cond
);
2272 CATCH (ex
, RETURN_MASK_ERROR
)
2274 /* If we got here, it means the condition could not be parsed to a valid
2275 bytecode expression and thus can't be evaluated on the target's side.
2276 It's no use iterating through the conditions. */
2280 /* We have a valid agent expression. */
2284 /* Based on location BL, create a list of breakpoint conditions to be
2285 passed on to the target. If we have duplicated locations with different
2286 conditions, we will add such conditions to the list. The idea is that the
2287 target will evaluate the list of conditions and will only notify GDB when
2288 one of them is true. */
2291 build_target_condition_list (struct bp_location
*bl
)
2293 struct bp_location
**locp
= NULL
, **loc2p
;
2294 int null_condition_or_parse_error
= 0;
2295 int modified
= bl
->needs_update
;
2296 struct bp_location
*loc
;
2298 /* Release conditions left over from a previous insert. */
2299 bl
->target_info
.conditions
.clear ();
2301 /* This is only meaningful if the target is
2302 evaluating conditions and if the user has
2303 opted for condition evaluation on the target's
2305 if (gdb_evaluates_breakpoint_condition_p ()
2306 || !target_supports_evaluation_of_breakpoint_conditions ())
2309 /* Do a first pass to check for locations with no assigned
2310 conditions or conditions that fail to parse to a valid agent expression
2311 bytecode. If any of these happen, then it's no use to send conditions
2312 to the target since this location will always trigger and generate a
2313 response back to GDB. */
2314 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2317 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2321 /* Re-parse the conditions since something changed. In that
2322 case we already freed the condition bytecodes (see
2323 force_breakpoint_reinsertion). We just
2324 need to parse the condition to bytecodes again. */
2325 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2329 /* If we have a NULL bytecode expression, it means something
2330 went wrong or we have a null condition expression. */
2331 if (!loc
->cond_bytecode
)
2333 null_condition_or_parse_error
= 1;
2339 /* If any of these happened, it means we will have to evaluate the conditions
2340 for the location's address on gdb's side. It is no use keeping bytecodes
2341 for all the other duplicate locations, thus we free all of them here.
2343 This is so we have a finer control over which locations' conditions are
2344 being evaluated by GDB or the remote stub. */
2345 if (null_condition_or_parse_error
)
2347 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2350 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2352 /* Only go as far as the first NULL bytecode is
2354 if (!loc
->cond_bytecode
)
2357 loc
->cond_bytecode
.reset ();
2362 /* No NULL conditions or failed bytecode generation. Build a condition list
2363 for this location's address. */
2364 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2368 && is_breakpoint (loc
->owner
)
2369 && loc
->pspace
->num
== bl
->pspace
->num
2370 && loc
->owner
->enable_state
== bp_enabled
2373 /* Add the condition to the vector. This will be used later
2374 to send the conditions to the target. */
2375 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2382 /* Parses a command described by string CMD into an agent expression
2383 bytecode suitable for evaluation by the bytecode interpreter.
2384 Return NULL if there was any error during parsing. */
2386 static agent_expr_up
2387 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2389 struct cleanup
*old_cleanups
= 0;
2390 struct expression
**argvec
;
2391 const char *cmdrest
;
2392 const char *format_start
, *format_end
;
2393 struct format_piece
*fpieces
;
2395 struct gdbarch
*gdbarch
= get_current_arch ();
2402 if (*cmdrest
== ',')
2404 cmdrest
= skip_spaces_const (cmdrest
);
2406 if (*cmdrest
++ != '"')
2407 error (_("No format string following the location"));
2409 format_start
= cmdrest
;
2411 fpieces
= parse_format_string (&cmdrest
);
2413 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2415 format_end
= cmdrest
;
2417 if (*cmdrest
++ != '"')
2418 error (_("Bad format string, non-terminated '\"'."));
2420 cmdrest
= skip_spaces_const (cmdrest
);
2422 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2423 error (_("Invalid argument syntax"));
2425 if (*cmdrest
== ',')
2427 cmdrest
= skip_spaces_const (cmdrest
);
2429 /* For each argument, make an expression. */
2431 argvec
= (struct expression
**) alloca (strlen (cmd
)
2432 * sizeof (struct expression
*));
2435 while (*cmdrest
!= '\0')
2440 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2441 argvec
[nargs
++] = expr
.release ();
2443 if (*cmdrest
== ',')
2447 agent_expr_up aexpr
;
2449 /* We don't want to stop processing, so catch any errors
2450 that may show up. */
2453 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2454 format_start
, format_end
- format_start
,
2455 fpieces
, nargs
, argvec
);
2457 CATCH (ex
, RETURN_MASK_ERROR
)
2459 /* If we got here, it means the command could not be parsed to a valid
2460 bytecode expression and thus can't be evaluated on the target's side.
2461 It's no use iterating through the other commands. */
2465 do_cleanups (old_cleanups
);
2467 /* We have a valid agent expression, return it. */
2471 /* Based on location BL, create a list of breakpoint commands to be
2472 passed on to the target. If we have duplicated locations with
2473 different commands, we will add any such to the list. */
2476 build_target_command_list (struct bp_location
*bl
)
2478 struct bp_location
**locp
= NULL
, **loc2p
;
2479 int null_command_or_parse_error
= 0;
2480 int modified
= bl
->needs_update
;
2481 struct bp_location
*loc
;
2483 /* Clear commands left over from a previous insert. */
2484 bl
->target_info
.tcommands
.clear ();
2486 if (!target_can_run_breakpoint_commands ())
2489 /* For now, limit to agent-style dprintf breakpoints. */
2490 if (dprintf_style
!= dprintf_style_agent
)
2493 /* For now, if we have any duplicate location that isn't a dprintf,
2494 don't install the target-side commands, as that would make the
2495 breakpoint not be reported to the core, and we'd lose
2497 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2500 if (is_breakpoint (loc
->owner
)
2501 && loc
->pspace
->num
== bl
->pspace
->num
2502 && loc
->owner
->type
!= bp_dprintf
)
2506 /* Do a first pass to check for locations with no assigned
2507 conditions or conditions that fail to parse to a valid agent expression
2508 bytecode. If any of these happen, then it's no use to send conditions
2509 to the target since this location will always trigger and generate a
2510 response back to GDB. */
2511 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2514 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2518 /* Re-parse the commands since something changed. In that
2519 case we already freed the command bytecodes (see
2520 force_breakpoint_reinsertion). We just
2521 need to parse the command to bytecodes again. */
2523 = parse_cmd_to_aexpr (bl
->address
,
2524 loc
->owner
->extra_string
);
2527 /* If we have a NULL bytecode expression, it means something
2528 went wrong or we have a null command expression. */
2529 if (!loc
->cmd_bytecode
)
2531 null_command_or_parse_error
= 1;
2537 /* If anything failed, then we're not doing target-side commands,
2539 if (null_command_or_parse_error
)
2541 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2544 if (is_breakpoint (loc
->owner
)
2545 && loc
->pspace
->num
== bl
->pspace
->num
)
2547 /* Only go as far as the first NULL bytecode is
2549 if (loc
->cmd_bytecode
== NULL
)
2552 loc
->cmd_bytecode
.reset ();
2557 /* No NULL commands or failed bytecode generation. Build a command list
2558 for this location's address. */
2559 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2562 if (loc
->owner
->extra_string
2563 && is_breakpoint (loc
->owner
)
2564 && loc
->pspace
->num
== bl
->pspace
->num
2565 && loc
->owner
->enable_state
== bp_enabled
2568 /* Add the command to the vector. This will be used later
2569 to send the commands to the target. */
2570 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2574 bl
->target_info
.persist
= 0;
2575 /* Maybe flag this location as persistent. */
2576 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2577 bl
->target_info
.persist
= 1;
2580 /* Return the kind of breakpoint on address *ADDR. Get the kind
2581 of breakpoint according to ADDR except single-step breakpoint.
2582 Get the kind of single-step breakpoint according to the current
2586 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2588 if (bl
->owner
->type
== bp_single_step
)
2590 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2591 struct regcache
*regcache
;
2593 regcache
= get_thread_regcache (thr
->ptid
);
2595 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2599 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2602 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2603 location. Any error messages are printed to TMP_ERROR_STREAM; and
2604 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2605 Returns 0 for success, 1 if the bp_location type is not supported or
2608 NOTE drow/2003-09-09: This routine could be broken down to an
2609 object-style method for each breakpoint or catchpoint type. */
2611 insert_bp_location (struct bp_location
*bl
,
2612 struct ui_file
*tmp_error_stream
,
2613 int *disabled_breaks
,
2614 int *hw_breakpoint_error
,
2615 int *hw_bp_error_explained_already
)
2617 enum errors bp_err
= GDB_NO_ERROR
;
2618 const char *bp_err_message
= NULL
;
2620 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2623 /* Note we don't initialize bl->target_info, as that wipes out
2624 the breakpoint location's shadow_contents if the breakpoint
2625 is still inserted at that location. This in turn breaks
2626 target_read_memory which depends on these buffers when
2627 a memory read is requested at the breakpoint location:
2628 Once the target_info has been wiped, we fail to see that
2629 we have a breakpoint inserted at that address and thus
2630 read the breakpoint instead of returning the data saved in
2631 the breakpoint location's shadow contents. */
2632 bl
->target_info
.reqstd_address
= bl
->address
;
2633 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2634 bl
->target_info
.length
= bl
->length
;
2636 /* When working with target-side conditions, we must pass all the conditions
2637 for the same breakpoint address down to the target since GDB will not
2638 insert those locations. With a list of breakpoint conditions, the target
2639 can decide when to stop and notify GDB. */
2641 if (is_breakpoint (bl
->owner
))
2643 build_target_condition_list (bl
);
2644 build_target_command_list (bl
);
2645 /* Reset the modification marker. */
2646 bl
->needs_update
= 0;
2649 if (bl
->loc_type
== bp_loc_software_breakpoint
2650 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2652 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2654 /* If the explicitly specified breakpoint type
2655 is not hardware breakpoint, check the memory map to see
2656 if the breakpoint address is in read only memory or not.
2658 Two important cases are:
2659 - location type is not hardware breakpoint, memory
2660 is readonly. We change the type of the location to
2661 hardware breakpoint.
2662 - location type is hardware breakpoint, memory is
2663 read-write. This means we've previously made the
2664 location hardware one, but then the memory map changed,
2667 When breakpoints are removed, remove_breakpoints will use
2668 location types we've just set here, the only possible
2669 problem is that memory map has changed during running
2670 program, but it's not going to work anyway with current
2672 struct mem_region
*mr
2673 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2677 if (automatic_hardware_breakpoints
)
2679 enum bp_loc_type new_type
;
2681 if (mr
->attrib
.mode
!= MEM_RW
)
2682 new_type
= bp_loc_hardware_breakpoint
;
2684 new_type
= bp_loc_software_breakpoint
;
2686 if (new_type
!= bl
->loc_type
)
2688 static int said
= 0;
2690 bl
->loc_type
= new_type
;
2693 fprintf_filtered (gdb_stdout
,
2694 _("Note: automatically using "
2695 "hardware breakpoints for "
2696 "read-only addresses.\n"));
2701 else if (bl
->loc_type
== bp_loc_software_breakpoint
2702 && mr
->attrib
.mode
!= MEM_RW
)
2704 fprintf_unfiltered (tmp_error_stream
,
2705 _("Cannot insert breakpoint %d.\n"
2706 "Cannot set software breakpoint "
2707 "at read-only address %s\n"),
2709 paddress (bl
->gdbarch
, bl
->address
));
2715 /* First check to see if we have to handle an overlay. */
2716 if (overlay_debugging
== ovly_off
2717 || bl
->section
== NULL
2718 || !(section_is_overlay (bl
->section
)))
2720 /* No overlay handling: just set the breakpoint. */
2725 val
= bl
->owner
->ops
->insert_location (bl
);
2727 bp_err
= GENERIC_ERROR
;
2729 CATCH (e
, RETURN_MASK_ALL
)
2732 bp_err_message
= e
.message
;
2738 /* This breakpoint is in an overlay section.
2739 Shall we set a breakpoint at the LMA? */
2740 if (!overlay_events_enabled
)
2742 /* Yes -- overlay event support is not active,
2743 so we must try to set a breakpoint at the LMA.
2744 This will not work for a hardware breakpoint. */
2745 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2746 warning (_("hardware breakpoint %d not supported in overlay!"),
2750 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2752 /* Set a software (trap) breakpoint at the LMA. */
2753 bl
->overlay_target_info
= bl
->target_info
;
2754 bl
->overlay_target_info
.reqstd_address
= addr
;
2756 /* No overlay handling: just set the breakpoint. */
2761 bl
->overlay_target_info
.kind
2762 = breakpoint_kind (bl
, &addr
);
2763 bl
->overlay_target_info
.placed_address
= addr
;
2764 val
= target_insert_breakpoint (bl
->gdbarch
,
2765 &bl
->overlay_target_info
);
2767 bp_err
= GENERIC_ERROR
;
2769 CATCH (e
, RETURN_MASK_ALL
)
2772 bp_err_message
= e
.message
;
2776 if (bp_err
!= GDB_NO_ERROR
)
2777 fprintf_unfiltered (tmp_error_stream
,
2778 "Overlay breakpoint %d "
2779 "failed: in ROM?\n",
2783 /* Shall we set a breakpoint at the VMA? */
2784 if (section_is_mapped (bl
->section
))
2786 /* Yes. This overlay section is mapped into memory. */
2791 val
= bl
->owner
->ops
->insert_location (bl
);
2793 bp_err
= GENERIC_ERROR
;
2795 CATCH (e
, RETURN_MASK_ALL
)
2798 bp_err_message
= e
.message
;
2804 /* No. This breakpoint will not be inserted.
2805 No error, but do not mark the bp as 'inserted'. */
2810 if (bp_err
!= GDB_NO_ERROR
)
2812 /* Can't set the breakpoint. */
2814 /* In some cases, we might not be able to insert a
2815 breakpoint in a shared library that has already been
2816 removed, but we have not yet processed the shlib unload
2817 event. Unfortunately, some targets that implement
2818 breakpoint insertion themselves can't tell why the
2819 breakpoint insertion failed (e.g., the remote target
2820 doesn't define error codes), so we must treat generic
2821 errors as memory errors. */
2822 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2823 && bl
->loc_type
== bp_loc_software_breakpoint
2824 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2825 || shared_objfile_contains_address_p (bl
->pspace
,
2828 /* See also: disable_breakpoints_in_shlibs. */
2829 bl
->shlib_disabled
= 1;
2830 observer_notify_breakpoint_modified (bl
->owner
);
2831 if (!*disabled_breaks
)
2833 fprintf_unfiltered (tmp_error_stream
,
2834 "Cannot insert breakpoint %d.\n",
2836 fprintf_unfiltered (tmp_error_stream
,
2837 "Temporarily disabling shared "
2838 "library breakpoints:\n");
2840 *disabled_breaks
= 1;
2841 fprintf_unfiltered (tmp_error_stream
,
2842 "breakpoint #%d\n", bl
->owner
->number
);
2847 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2849 *hw_breakpoint_error
= 1;
2850 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2851 fprintf_unfiltered (tmp_error_stream
,
2852 "Cannot insert hardware breakpoint %d%s",
2853 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2854 if (bp_err_message
!= NULL
)
2855 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2859 if (bp_err_message
== NULL
)
2862 = memory_error_message (TARGET_XFER_E_IO
,
2863 bl
->gdbarch
, bl
->address
);
2864 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2866 fprintf_unfiltered (tmp_error_stream
,
2867 "Cannot insert breakpoint %d.\n"
2869 bl
->owner
->number
, message
);
2870 do_cleanups (old_chain
);
2874 fprintf_unfiltered (tmp_error_stream
,
2875 "Cannot insert breakpoint %d: %s\n",
2890 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2891 /* NOTE drow/2003-09-08: This state only exists for removing
2892 watchpoints. It's not clear that it's necessary... */
2893 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2897 gdb_assert (bl
->owner
->ops
!= NULL
2898 && bl
->owner
->ops
->insert_location
!= NULL
);
2900 val
= bl
->owner
->ops
->insert_location (bl
);
2902 /* If trying to set a read-watchpoint, and it turns out it's not
2903 supported, try emulating one with an access watchpoint. */
2904 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2906 struct bp_location
*loc
, **loc_temp
;
2908 /* But don't try to insert it, if there's already another
2909 hw_access location that would be considered a duplicate
2911 ALL_BP_LOCATIONS (loc
, loc_temp
)
2913 && loc
->watchpoint_type
== hw_access
2914 && watchpoint_locations_match (bl
, loc
))
2918 bl
->target_info
= loc
->target_info
;
2919 bl
->watchpoint_type
= hw_access
;
2926 bl
->watchpoint_type
= hw_access
;
2927 val
= bl
->owner
->ops
->insert_location (bl
);
2930 /* Back to the original value. */
2931 bl
->watchpoint_type
= hw_read
;
2935 bl
->inserted
= (val
== 0);
2938 else if (bl
->owner
->type
== bp_catchpoint
)
2942 gdb_assert (bl
->owner
->ops
!= NULL
2943 && bl
->owner
->ops
->insert_location
!= NULL
);
2945 val
= bl
->owner
->ops
->insert_location (bl
);
2948 bl
->owner
->enable_state
= bp_disabled
;
2952 Error inserting catchpoint %d: Your system does not support this type\n\
2953 of catchpoint."), bl
->owner
->number
);
2955 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2958 bl
->inserted
= (val
== 0);
2960 /* We've already printed an error message if there was a problem
2961 inserting this catchpoint, and we've disabled the catchpoint,
2962 so just return success. */
2969 /* This function is called when program space PSPACE is about to be
2970 deleted. It takes care of updating breakpoints to not reference
2974 breakpoint_program_space_exit (struct program_space
*pspace
)
2976 struct breakpoint
*b
, *b_temp
;
2977 struct bp_location
*loc
, **loc_temp
;
2979 /* Remove any breakpoint that was set through this program space. */
2980 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2982 if (b
->pspace
== pspace
)
2983 delete_breakpoint (b
);
2986 /* Breakpoints set through other program spaces could have locations
2987 bound to PSPACE as well. Remove those. */
2988 ALL_BP_LOCATIONS (loc
, loc_temp
)
2990 struct bp_location
*tmp
;
2992 if (loc
->pspace
== pspace
)
2994 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2995 if (loc
->owner
->loc
== loc
)
2996 loc
->owner
->loc
= loc
->next
;
2998 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2999 if (tmp
->next
== loc
)
3001 tmp
->next
= loc
->next
;
3007 /* Now update the global location list to permanently delete the
3008 removed locations above. */
3009 update_global_location_list (UGLL_DONT_INSERT
);
3012 /* Make sure all breakpoints are inserted in inferior.
3013 Throws exception on any error.
3014 A breakpoint that is already inserted won't be inserted
3015 again, so calling this function twice is safe. */
3017 insert_breakpoints (void)
3019 struct breakpoint
*bpt
;
3021 ALL_BREAKPOINTS (bpt
)
3022 if (is_hardware_watchpoint (bpt
))
3024 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3026 update_watchpoint (w
, 0 /* don't reparse. */);
3029 /* Updating watchpoints creates new locations, so update the global
3030 location list. Explicitly tell ugll to insert locations and
3031 ignore breakpoints_always_inserted_mode. */
3032 update_global_location_list (UGLL_INSERT
);
3035 /* Invoke CALLBACK for each of bp_location. */
3038 iterate_over_bp_locations (walk_bp_location_callback callback
)
3040 struct bp_location
*loc
, **loc_tmp
;
3042 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3044 callback (loc
, NULL
);
3048 /* This is used when we need to synch breakpoint conditions between GDB and the
3049 target. It is the case with deleting and disabling of breakpoints when using
3050 always-inserted mode. */
3053 update_inserted_breakpoint_locations (void)
3055 struct bp_location
*bl
, **blp_tmp
;
3058 int disabled_breaks
= 0;
3059 int hw_breakpoint_error
= 0;
3060 int hw_bp_details_reported
= 0;
3062 string_file tmp_error_stream
;
3064 /* Explicitly mark the warning -- this will only be printed if
3065 there was an error. */
3066 tmp_error_stream
.puts ("Warning:\n");
3068 struct cleanup
*cleanups
= save_current_space_and_thread ();
3070 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3072 /* We only want to update software breakpoints and hardware
3074 if (!is_breakpoint (bl
->owner
))
3077 /* We only want to update locations that are already inserted
3078 and need updating. This is to avoid unwanted insertion during
3079 deletion of breakpoints. */
3080 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3083 switch_to_program_space_and_thread (bl
->pspace
);
3085 /* For targets that support global breakpoints, there's no need
3086 to select an inferior to insert breakpoint to. In fact, even
3087 if we aren't attached to any process yet, we should still
3088 insert breakpoints. */
3089 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3090 && ptid_equal (inferior_ptid
, null_ptid
))
3093 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3094 &hw_breakpoint_error
, &hw_bp_details_reported
);
3101 target_terminal_ours_for_output ();
3102 error_stream (tmp_error_stream
);
3105 do_cleanups (cleanups
);
3108 /* Used when starting or continuing the program. */
3111 insert_breakpoint_locations (void)
3113 struct breakpoint
*bpt
;
3114 struct bp_location
*bl
, **blp_tmp
;
3117 int disabled_breaks
= 0;
3118 int hw_breakpoint_error
= 0;
3119 int hw_bp_error_explained_already
= 0;
3121 string_file tmp_error_stream
;
3123 /* Explicitly mark the warning -- this will only be printed if
3124 there was an error. */
3125 tmp_error_stream
.puts ("Warning:\n");
3127 struct cleanup
*cleanups
= save_current_space_and_thread ();
3129 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3131 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3134 /* There is no point inserting thread-specific breakpoints if
3135 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3136 has BL->OWNER always non-NULL. */
3137 if (bl
->owner
->thread
!= -1
3138 && !valid_global_thread_id (bl
->owner
->thread
))
3141 switch_to_program_space_and_thread (bl
->pspace
);
3143 /* For targets that support global breakpoints, there's no need
3144 to select an inferior to insert breakpoint to. In fact, even
3145 if we aren't attached to any process yet, we should still
3146 insert breakpoints. */
3147 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3148 && ptid_equal (inferior_ptid
, null_ptid
))
3151 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3152 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3157 /* If we failed to insert all locations of a watchpoint, remove
3158 them, as half-inserted watchpoint is of limited use. */
3159 ALL_BREAKPOINTS (bpt
)
3161 int some_failed
= 0;
3162 struct bp_location
*loc
;
3164 if (!is_hardware_watchpoint (bpt
))
3167 if (!breakpoint_enabled (bpt
))
3170 if (bpt
->disposition
== disp_del_at_next_stop
)
3173 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3174 if (!loc
->inserted
&& should_be_inserted (loc
))
3181 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3183 remove_breakpoint (loc
);
3185 hw_breakpoint_error
= 1;
3186 tmp_error_stream
.printf ("Could not insert "
3187 "hardware watchpoint %d.\n",
3195 /* If a hardware breakpoint or watchpoint was inserted, add a
3196 message about possibly exhausted resources. */
3197 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3199 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3200 You may have requested too many hardware breakpoints/watchpoints.\n");
3202 target_terminal_ours_for_output ();
3203 error_stream (tmp_error_stream
);
3206 do_cleanups (cleanups
);
3209 /* Used when the program stops.
3210 Returns zero if successful, or non-zero if there was a problem
3211 removing a breakpoint location. */
3214 remove_breakpoints (void)
3216 struct bp_location
*bl
, **blp_tmp
;
3219 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3221 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3222 val
|= remove_breakpoint (bl
);
3227 /* When a thread exits, remove breakpoints that are related to
3231 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3233 struct breakpoint
*b
, *b_tmp
;
3235 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3237 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3239 b
->disposition
= disp_del_at_next_stop
;
3241 printf_filtered (_("\
3242 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3243 b
->number
, print_thread_id (tp
));
3245 /* Hide it from the user. */
3251 /* Remove breakpoints of process PID. */
3254 remove_breakpoints_pid (int pid
)
3256 struct bp_location
*bl
, **blp_tmp
;
3258 struct inferior
*inf
= find_inferior_pid (pid
);
3260 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3262 if (bl
->pspace
!= inf
->pspace
)
3265 if (bl
->inserted
&& !bl
->target_info
.persist
)
3267 val
= remove_breakpoint (bl
);
3276 reattach_breakpoints (int pid
)
3278 struct cleanup
*old_chain
;
3279 struct bp_location
*bl
, **blp_tmp
;
3281 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3282 struct inferior
*inf
;
3283 struct thread_info
*tp
;
3285 tp
= any_live_thread_of_process (pid
);
3289 inf
= find_inferior_pid (pid
);
3290 old_chain
= save_inferior_ptid ();
3292 inferior_ptid
= tp
->ptid
;
3294 string_file tmp_error_stream
;
3296 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3298 if (bl
->pspace
!= inf
->pspace
)
3304 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3307 do_cleanups (old_chain
);
3312 do_cleanups (old_chain
);
3316 static int internal_breakpoint_number
= -1;
3318 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3319 If INTERNAL is non-zero, the breakpoint number will be populated
3320 from internal_breakpoint_number and that variable decremented.
3321 Otherwise the breakpoint number will be populated from
3322 breakpoint_count and that value incremented. Internal breakpoints
3323 do not set the internal var bpnum. */
3325 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3328 b
->number
= internal_breakpoint_number
--;
3331 set_breakpoint_count (breakpoint_count
+ 1);
3332 b
->number
= breakpoint_count
;
3336 static struct breakpoint
*
3337 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3338 CORE_ADDR address
, enum bptype type
,
3339 const struct breakpoint_ops
*ops
)
3341 struct symtab_and_line sal
;
3342 struct breakpoint
*b
;
3344 init_sal (&sal
); /* Initialize to zeroes. */
3347 sal
.section
= find_pc_overlay (sal
.pc
);
3348 sal
.pspace
= current_program_space
;
3350 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3351 b
->number
= internal_breakpoint_number
--;
3352 b
->disposition
= disp_donttouch
;
3357 static const char *const longjmp_names
[] =
3359 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3361 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3363 /* Per-objfile data private to breakpoint.c. */
3364 struct breakpoint_objfile_data
3366 /* Minimal symbol for "_ovly_debug_event" (if any). */
3367 struct bound_minimal_symbol overlay_msym
;
3369 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3370 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3372 /* True if we have looked for longjmp probes. */
3373 int longjmp_searched
;
3375 /* SystemTap probe points for longjmp (if any). */
3376 VEC (probe_p
) *longjmp_probes
;
3378 /* Minimal symbol for "std::terminate()" (if any). */
3379 struct bound_minimal_symbol terminate_msym
;
3381 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3382 struct bound_minimal_symbol exception_msym
;
3384 /* True if we have looked for exception probes. */
3385 int exception_searched
;
3387 /* SystemTap probe points for unwinding (if any). */
3388 VEC (probe_p
) *exception_probes
;
3391 static const struct objfile_data
*breakpoint_objfile_key
;
3393 /* Minimal symbol not found sentinel. */
3394 static struct minimal_symbol msym_not_found
;
3396 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3399 msym_not_found_p (const struct minimal_symbol
*msym
)
3401 return msym
== &msym_not_found
;
3404 /* Return per-objfile data needed by breakpoint.c.
3405 Allocate the data if necessary. */
3407 static struct breakpoint_objfile_data
*
3408 get_breakpoint_objfile_data (struct objfile
*objfile
)
3410 struct breakpoint_objfile_data
*bp_objfile_data
;
3412 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3413 objfile_data (objfile
, breakpoint_objfile_key
));
3414 if (bp_objfile_data
== NULL
)
3417 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3419 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3420 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3422 return bp_objfile_data
;
3426 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3428 struct breakpoint_objfile_data
*bp_objfile_data
3429 = (struct breakpoint_objfile_data
*) data
;
3431 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3432 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3436 create_overlay_event_breakpoint (void)
3438 struct objfile
*objfile
;
3439 const char *const func_name
= "_ovly_debug_event";
3441 ALL_OBJFILES (objfile
)
3443 struct breakpoint
*b
;
3444 struct breakpoint_objfile_data
*bp_objfile_data
;
3446 struct explicit_location explicit_loc
;
3448 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3450 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3453 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3455 struct bound_minimal_symbol m
;
3457 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3458 if (m
.minsym
== NULL
)
3460 /* Avoid future lookups in this objfile. */
3461 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3464 bp_objfile_data
->overlay_msym
= m
;
3467 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3468 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3470 &internal_breakpoint_ops
);
3471 initialize_explicit_location (&explicit_loc
);
3472 explicit_loc
.function_name
= ASTRDUP (func_name
);
3473 b
->location
= new_explicit_location (&explicit_loc
);
3475 if (overlay_debugging
== ovly_auto
)
3477 b
->enable_state
= bp_enabled
;
3478 overlay_events_enabled
= 1;
3482 b
->enable_state
= bp_disabled
;
3483 overlay_events_enabled
= 0;
3489 create_longjmp_master_breakpoint (void)
3491 struct program_space
*pspace
;
3492 struct cleanup
*old_chain
;
3494 old_chain
= save_current_program_space ();
3496 ALL_PSPACES (pspace
)
3498 struct objfile
*objfile
;
3500 set_current_program_space (pspace
);
3502 ALL_OBJFILES (objfile
)
3505 struct gdbarch
*gdbarch
;
3506 struct breakpoint_objfile_data
*bp_objfile_data
;
3508 gdbarch
= get_objfile_arch (objfile
);
3510 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3512 if (!bp_objfile_data
->longjmp_searched
)
3516 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3519 /* We are only interested in checking one element. */
3520 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3522 if (!can_evaluate_probe_arguments (p
))
3524 /* We cannot use the probe interface here, because it does
3525 not know how to evaluate arguments. */
3526 VEC_free (probe_p
, ret
);
3530 bp_objfile_data
->longjmp_probes
= ret
;
3531 bp_objfile_data
->longjmp_searched
= 1;
3534 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3537 struct probe
*probe
;
3538 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3541 VEC_iterate (probe_p
,
3542 bp_objfile_data
->longjmp_probes
,
3546 struct breakpoint
*b
;
3548 b
= create_internal_breakpoint (gdbarch
,
3549 get_probe_address (probe
,
3552 &internal_breakpoint_ops
);
3553 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3554 b
->enable_state
= bp_disabled
;
3560 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3563 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3565 struct breakpoint
*b
;
3566 const char *func_name
;
3568 struct explicit_location explicit_loc
;
3570 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3573 func_name
= longjmp_names
[i
];
3574 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3576 struct bound_minimal_symbol m
;
3578 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3579 if (m
.minsym
== NULL
)
3581 /* Prevent future lookups in this objfile. */
3582 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3585 bp_objfile_data
->longjmp_msym
[i
] = m
;
3588 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3589 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3590 &internal_breakpoint_ops
);
3591 initialize_explicit_location (&explicit_loc
);
3592 explicit_loc
.function_name
= ASTRDUP (func_name
);
3593 b
->location
= new_explicit_location (&explicit_loc
);
3594 b
->enable_state
= bp_disabled
;
3599 do_cleanups (old_chain
);
3602 /* Create a master std::terminate breakpoint. */
3604 create_std_terminate_master_breakpoint (void)
3606 struct program_space
*pspace
;
3607 struct cleanup
*old_chain
;
3608 const char *const func_name
= "std::terminate()";
3610 old_chain
= save_current_program_space ();
3612 ALL_PSPACES (pspace
)
3614 struct objfile
*objfile
;
3617 set_current_program_space (pspace
);
3619 ALL_OBJFILES (objfile
)
3621 struct breakpoint
*b
;
3622 struct breakpoint_objfile_data
*bp_objfile_data
;
3623 struct explicit_location explicit_loc
;
3625 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3627 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3630 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3632 struct bound_minimal_symbol m
;
3634 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3635 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3636 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3638 /* Prevent future lookups in this objfile. */
3639 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3642 bp_objfile_data
->terminate_msym
= m
;
3645 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3646 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3647 bp_std_terminate_master
,
3648 &internal_breakpoint_ops
);
3649 initialize_explicit_location (&explicit_loc
);
3650 explicit_loc
.function_name
= ASTRDUP (func_name
);
3651 b
->location
= new_explicit_location (&explicit_loc
);
3652 b
->enable_state
= bp_disabled
;
3656 do_cleanups (old_chain
);
3659 /* Install a master breakpoint on the unwinder's debug hook. */
3662 create_exception_master_breakpoint (void)
3664 struct objfile
*objfile
;
3665 const char *const func_name
= "_Unwind_DebugHook";
3667 ALL_OBJFILES (objfile
)
3669 struct breakpoint
*b
;
3670 struct gdbarch
*gdbarch
;
3671 struct breakpoint_objfile_data
*bp_objfile_data
;
3673 struct explicit_location explicit_loc
;
3675 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3677 /* We prefer the SystemTap probe point if it exists. */
3678 if (!bp_objfile_data
->exception_searched
)
3682 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3686 /* We are only interested in checking one element. */
3687 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3689 if (!can_evaluate_probe_arguments (p
))
3691 /* We cannot use the probe interface here, because it does
3692 not know how to evaluate arguments. */
3693 VEC_free (probe_p
, ret
);
3697 bp_objfile_data
->exception_probes
= ret
;
3698 bp_objfile_data
->exception_searched
= 1;
3701 if (bp_objfile_data
->exception_probes
!= NULL
)
3703 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3705 struct probe
*probe
;
3708 VEC_iterate (probe_p
,
3709 bp_objfile_data
->exception_probes
,
3713 struct breakpoint
*b
;
3715 b
= create_internal_breakpoint (gdbarch
,
3716 get_probe_address (probe
,
3718 bp_exception_master
,
3719 &internal_breakpoint_ops
);
3720 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3721 b
->enable_state
= bp_disabled
;
3727 /* Otherwise, try the hook function. */
3729 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3732 gdbarch
= get_objfile_arch (objfile
);
3734 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3736 struct bound_minimal_symbol debug_hook
;
3738 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3739 if (debug_hook
.minsym
== NULL
)
3741 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3745 bp_objfile_data
->exception_msym
= debug_hook
;
3748 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3749 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3751 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3752 &internal_breakpoint_ops
);
3753 initialize_explicit_location (&explicit_loc
);
3754 explicit_loc
.function_name
= ASTRDUP (func_name
);
3755 b
->location
= new_explicit_location (&explicit_loc
);
3756 b
->enable_state
= bp_disabled
;
3760 /* Does B have a location spec? */
3763 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3765 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3769 update_breakpoints_after_exec (void)
3771 struct breakpoint
*b
, *b_tmp
;
3772 struct bp_location
*bploc
, **bplocp_tmp
;
3774 /* We're about to delete breakpoints from GDB's lists. If the
3775 INSERTED flag is true, GDB will try to lift the breakpoints by
3776 writing the breakpoints' "shadow contents" back into memory. The
3777 "shadow contents" are NOT valid after an exec, so GDB should not
3778 do that. Instead, the target is responsible from marking
3779 breakpoints out as soon as it detects an exec. We don't do that
3780 here instead, because there may be other attempts to delete
3781 breakpoints after detecting an exec and before reaching here. */
3782 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3783 if (bploc
->pspace
== current_program_space
)
3784 gdb_assert (!bploc
->inserted
);
3786 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3788 if (b
->pspace
!= current_program_space
)
3791 /* Solib breakpoints must be explicitly reset after an exec(). */
3792 if (b
->type
== bp_shlib_event
)
3794 delete_breakpoint (b
);
3798 /* JIT breakpoints must be explicitly reset after an exec(). */
3799 if (b
->type
== bp_jit_event
)
3801 delete_breakpoint (b
);
3805 /* Thread event breakpoints must be set anew after an exec(),
3806 as must overlay event and longjmp master breakpoints. */
3807 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3808 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3809 || b
->type
== bp_exception_master
)
3811 delete_breakpoint (b
);
3815 /* Step-resume breakpoints are meaningless after an exec(). */
3816 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3818 delete_breakpoint (b
);
3822 /* Just like single-step breakpoints. */
3823 if (b
->type
== bp_single_step
)
3825 delete_breakpoint (b
);
3829 /* Longjmp and longjmp-resume breakpoints are also meaningless
3831 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3832 || b
->type
== bp_longjmp_call_dummy
3833 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3835 delete_breakpoint (b
);
3839 if (b
->type
== bp_catchpoint
)
3841 /* For now, none of the bp_catchpoint breakpoints need to
3842 do anything at this point. In the future, if some of
3843 the catchpoints need to something, we will need to add
3844 a new method, and call this method from here. */
3848 /* bp_finish is a special case. The only way we ought to be able
3849 to see one of these when an exec() has happened, is if the user
3850 caught a vfork, and then said "finish". Ordinarily a finish just
3851 carries them to the call-site of the current callee, by setting
3852 a temporary bp there and resuming. But in this case, the finish
3853 will carry them entirely through the vfork & exec.
3855 We don't want to allow a bp_finish to remain inserted now. But
3856 we can't safely delete it, 'cause finish_command has a handle to
3857 the bp on a bpstat, and will later want to delete it. There's a
3858 chance (and I've seen it happen) that if we delete the bp_finish
3859 here, that its storage will get reused by the time finish_command
3860 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3861 We really must allow finish_command to delete a bp_finish.
3863 In the absence of a general solution for the "how do we know
3864 it's safe to delete something others may have handles to?"
3865 problem, what we'll do here is just uninsert the bp_finish, and
3866 let finish_command delete it.
3868 (We know the bp_finish is "doomed" in the sense that it's
3869 momentary, and will be deleted as soon as finish_command sees
3870 the inferior stopped. So it doesn't matter that the bp's
3871 address is probably bogus in the new a.out, unlike e.g., the
3872 solib breakpoints.) */
3874 if (b
->type
== bp_finish
)
3879 /* Without a symbolic address, we have little hope of the
3880 pre-exec() address meaning the same thing in the post-exec()
3882 if (breakpoint_event_location_empty_p (b
))
3884 delete_breakpoint (b
);
3891 detach_breakpoints (ptid_t ptid
)
3893 struct bp_location
*bl
, **blp_tmp
;
3895 struct cleanup
*old_chain
= save_inferior_ptid ();
3896 struct inferior
*inf
= current_inferior ();
3898 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3899 error (_("Cannot detach breakpoints of inferior_ptid"));
3901 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3902 inferior_ptid
= ptid
;
3903 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3905 if (bl
->pspace
!= inf
->pspace
)
3908 /* This function must physically remove breakpoints locations
3909 from the specified ptid, without modifying the breakpoint
3910 package's state. Locations of type bp_loc_other are only
3911 maintained at GDB side. So, there is no need to remove
3912 these bp_loc_other locations. Moreover, removing these
3913 would modify the breakpoint package's state. */
3914 if (bl
->loc_type
== bp_loc_other
)
3918 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3921 do_cleanups (old_chain
);
3925 /* Remove the breakpoint location BL from the current address space.
3926 Note that this is used to detach breakpoints from a child fork.
3927 When we get here, the child isn't in the inferior list, and neither
3928 do we have objects to represent its address space --- we should
3929 *not* look at bl->pspace->aspace here. */
3932 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3936 /* BL is never in moribund_locations by our callers. */
3937 gdb_assert (bl
->owner
!= NULL
);
3939 /* The type of none suggests that owner is actually deleted.
3940 This should not ever happen. */
3941 gdb_assert (bl
->owner
->type
!= bp_none
);
3943 if (bl
->loc_type
== bp_loc_software_breakpoint
3944 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3946 /* "Normal" instruction breakpoint: either the standard
3947 trap-instruction bp (bp_breakpoint), or a
3948 bp_hardware_breakpoint. */
3950 /* First check to see if we have to handle an overlay. */
3951 if (overlay_debugging
== ovly_off
3952 || bl
->section
== NULL
3953 || !(section_is_overlay (bl
->section
)))
3955 /* No overlay handling: just remove the breakpoint. */
3957 /* If we're trying to uninsert a memory breakpoint that we
3958 know is set in a dynamic object that is marked
3959 shlib_disabled, then either the dynamic object was
3960 removed with "remove-symbol-file" or with
3961 "nosharedlibrary". In the former case, we don't know
3962 whether another dynamic object might have loaded over the
3963 breakpoint's address -- the user might well let us know
3964 about it next with add-symbol-file (the whole point of
3965 add-symbol-file is letting the user manually maintain a
3966 list of dynamically loaded objects). If we have the
3967 breakpoint's shadow memory, that is, this is a software
3968 breakpoint managed by GDB, check whether the breakpoint
3969 is still inserted in memory, to avoid overwriting wrong
3970 code with stale saved shadow contents. Note that HW
3971 breakpoints don't have shadow memory, as they're
3972 implemented using a mechanism that is not dependent on
3973 being able to modify the target's memory, and as such
3974 they should always be removed. */
3975 if (bl
->shlib_disabled
3976 && bl
->target_info
.shadow_len
!= 0
3977 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3980 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3984 /* This breakpoint is in an overlay section.
3985 Did we set a breakpoint at the LMA? */
3986 if (!overlay_events_enabled
)
3988 /* Yes -- overlay event support is not active, so we
3989 should have set a breakpoint at the LMA. Remove it.
3991 /* Ignore any failures: if the LMA is in ROM, we will
3992 have already warned when we failed to insert it. */
3993 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3994 target_remove_hw_breakpoint (bl
->gdbarch
,
3995 &bl
->overlay_target_info
);
3997 target_remove_breakpoint (bl
->gdbarch
,
3998 &bl
->overlay_target_info
,
4001 /* Did we set a breakpoint at the VMA?
4002 If so, we will have marked the breakpoint 'inserted'. */
4005 /* Yes -- remove it. Previously we did not bother to
4006 remove the breakpoint if the section had been
4007 unmapped, but let's not rely on that being safe. We
4008 don't know what the overlay manager might do. */
4010 /* However, we should remove *software* breakpoints only
4011 if the section is still mapped, or else we overwrite
4012 wrong code with the saved shadow contents. */
4013 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4014 || section_is_mapped (bl
->section
))
4015 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4021 /* No -- not inserted, so no need to remove. No error. */
4026 /* In some cases, we might not be able to remove a breakpoint in
4027 a shared library that has already been removed, but we have
4028 not yet processed the shlib unload event. Similarly for an
4029 unloaded add-symbol-file object - the user might not yet have
4030 had the chance to remove-symbol-file it. shlib_disabled will
4031 be set if the library/object has already been removed, but
4032 the breakpoint hasn't been uninserted yet, e.g., after
4033 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4034 always-inserted mode. */
4036 && (bl
->loc_type
== bp_loc_software_breakpoint
4037 && (bl
->shlib_disabled
4038 || solib_name_from_address (bl
->pspace
, bl
->address
)
4039 || shared_objfile_contains_address_p (bl
->pspace
,
4045 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4047 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4049 gdb_assert (bl
->owner
->ops
!= NULL
4050 && bl
->owner
->ops
->remove_location
!= NULL
);
4052 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4053 bl
->owner
->ops
->remove_location (bl
, reason
);
4055 /* Failure to remove any of the hardware watchpoints comes here. */
4056 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4057 warning (_("Could not remove hardware watchpoint %d."),
4060 else if (bl
->owner
->type
== bp_catchpoint
4061 && breakpoint_enabled (bl
->owner
)
4064 gdb_assert (bl
->owner
->ops
!= NULL
4065 && bl
->owner
->ops
->remove_location
!= NULL
);
4067 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4071 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4078 remove_breakpoint (struct bp_location
*bl
)
4081 struct cleanup
*old_chain
;
4083 /* BL is never in moribund_locations by our callers. */
4084 gdb_assert (bl
->owner
!= NULL
);
4086 /* The type of none suggests that owner is actually deleted.
4087 This should not ever happen. */
4088 gdb_assert (bl
->owner
->type
!= bp_none
);
4090 old_chain
= save_current_space_and_thread ();
4092 switch_to_program_space_and_thread (bl
->pspace
);
4094 ret
= remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4096 do_cleanups (old_chain
);
4100 /* Clear the "inserted" flag in all breakpoints. */
4103 mark_breakpoints_out (void)
4105 struct bp_location
*bl
, **blp_tmp
;
4107 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4108 if (bl
->pspace
== current_program_space
)
4112 /* Clear the "inserted" flag in all breakpoints and delete any
4113 breakpoints which should go away between runs of the program.
4115 Plus other such housekeeping that has to be done for breakpoints
4118 Note: this function gets called at the end of a run (by
4119 generic_mourn_inferior) and when a run begins (by
4120 init_wait_for_inferior). */
4125 breakpoint_init_inferior (enum inf_context context
)
4127 struct breakpoint
*b
, *b_tmp
;
4128 struct bp_location
*bl
;
4130 struct program_space
*pspace
= current_program_space
;
4132 /* If breakpoint locations are shared across processes, then there's
4134 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4137 mark_breakpoints_out ();
4139 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4141 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4147 case bp_longjmp_call_dummy
:
4149 /* If the call dummy breakpoint is at the entry point it will
4150 cause problems when the inferior is rerun, so we better get
4153 case bp_watchpoint_scope
:
4155 /* Also get rid of scope breakpoints. */
4157 case bp_shlib_event
:
4159 /* Also remove solib event breakpoints. Their addresses may
4160 have changed since the last time we ran the program.
4161 Actually we may now be debugging against different target;
4162 and so the solib backend that installed this breakpoint may
4163 not be used in by the target. E.g.,
4165 (gdb) file prog-linux
4166 (gdb) run # native linux target
4169 (gdb) file prog-win.exe
4170 (gdb) tar rem :9999 # remote Windows gdbserver.
4173 case bp_step_resume
:
4175 /* Also remove step-resume breakpoints. */
4177 case bp_single_step
:
4179 /* Also remove single-step breakpoints. */
4181 delete_breakpoint (b
);
4185 case bp_hardware_watchpoint
:
4186 case bp_read_watchpoint
:
4187 case bp_access_watchpoint
:
4189 struct watchpoint
*w
= (struct watchpoint
*) b
;
4191 /* Likewise for watchpoints on local expressions. */
4192 if (w
->exp_valid_block
!= NULL
)
4193 delete_breakpoint (b
);
4196 /* Get rid of existing locations, which are no longer
4197 valid. New ones will be created in
4198 update_watchpoint, when the inferior is restarted.
4199 The next update_global_location_list call will
4200 garbage collect them. */
4203 if (context
== inf_starting
)
4205 /* Reset val field to force reread of starting value in
4206 insert_breakpoints. */
4208 value_free (w
->val
);
4220 /* Get rid of the moribund locations. */
4221 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4222 decref_bp_location (&bl
);
4223 VEC_free (bp_location_p
, moribund_locations
);
4226 /* These functions concern about actual breakpoints inserted in the
4227 target --- to e.g. check if we need to do decr_pc adjustment or if
4228 we need to hop over the bkpt --- so we check for address space
4229 match, not program space. */
4231 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4232 exists at PC. It returns ordinary_breakpoint_here if it's an
4233 ordinary breakpoint, or permanent_breakpoint_here if it's a
4234 permanent breakpoint.
4235 - When continuing from a location with an ordinary breakpoint, we
4236 actually single step once before calling insert_breakpoints.
4237 - When continuing from a location with a permanent breakpoint, we
4238 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4239 the target, to advance the PC past the breakpoint. */
4241 enum breakpoint_here
4242 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4244 struct bp_location
*bl
, **blp_tmp
;
4245 int any_breakpoint_here
= 0;
4247 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4249 if (bl
->loc_type
!= bp_loc_software_breakpoint
4250 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4253 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4254 if ((breakpoint_enabled (bl
->owner
)
4256 && breakpoint_location_address_match (bl
, aspace
, pc
))
4258 if (overlay_debugging
4259 && section_is_overlay (bl
->section
)
4260 && !section_is_mapped (bl
->section
))
4261 continue; /* unmapped overlay -- can't be a match */
4262 else if (bl
->permanent
)
4263 return permanent_breakpoint_here
;
4265 any_breakpoint_here
= 1;
4269 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4272 /* See breakpoint.h. */
4275 breakpoint_in_range_p (struct address_space
*aspace
,
4276 CORE_ADDR addr
, ULONGEST len
)
4278 struct bp_location
*bl
, **blp_tmp
;
4280 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4282 if (bl
->loc_type
!= bp_loc_software_breakpoint
4283 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4286 if ((breakpoint_enabled (bl
->owner
)
4288 && breakpoint_location_address_range_overlap (bl
, aspace
,
4291 if (overlay_debugging
4292 && section_is_overlay (bl
->section
)
4293 && !section_is_mapped (bl
->section
))
4295 /* Unmapped overlay -- can't be a match. */
4306 /* Return true if there's a moribund breakpoint at PC. */
4309 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4311 struct bp_location
*loc
;
4314 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4315 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4321 /* Returns non-zero iff BL is inserted at PC, in address space
4325 bp_location_inserted_here_p (struct bp_location
*bl
,
4326 struct address_space
*aspace
, CORE_ADDR pc
)
4329 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4332 if (overlay_debugging
4333 && section_is_overlay (bl
->section
)
4334 && !section_is_mapped (bl
->section
))
4335 return 0; /* unmapped overlay -- can't be a match */
4342 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4345 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4347 struct bp_location
**blp
, **blp_tmp
= NULL
;
4349 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4351 struct bp_location
*bl
= *blp
;
4353 if (bl
->loc_type
!= bp_loc_software_breakpoint
4354 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4357 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4363 /* This function returns non-zero iff there is a software breakpoint
4367 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4370 struct bp_location
**blp
, **blp_tmp
= NULL
;
4372 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4374 struct bp_location
*bl
= *blp
;
4376 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4379 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4386 /* See breakpoint.h. */
4389 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4392 struct bp_location
**blp
, **blp_tmp
= NULL
;
4394 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4396 struct bp_location
*bl
= *blp
;
4398 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4401 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4409 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4410 CORE_ADDR addr
, ULONGEST len
)
4412 struct breakpoint
*bpt
;
4414 ALL_BREAKPOINTS (bpt
)
4416 struct bp_location
*loc
;
4418 if (bpt
->type
!= bp_hardware_watchpoint
4419 && bpt
->type
!= bp_access_watchpoint
)
4422 if (!breakpoint_enabled (bpt
))
4425 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4426 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4430 /* Check for intersection. */
4431 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4432 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4441 /* bpstat stuff. External routines' interfaces are documented
4445 is_catchpoint (struct breakpoint
*ep
)
4447 return (ep
->type
== bp_catchpoint
);
4450 /* Frees any storage that is part of a bpstat. Does not walk the
4454 bpstat_free (bpstat bs
)
4456 if (bs
->old_val
!= NULL
)
4457 value_free (bs
->old_val
);
4458 decref_counted_command_line (&bs
->commands
);
4459 decref_bp_location (&bs
->bp_location_at
);
4463 /* Clear a bpstat so that it says we are not at any breakpoint.
4464 Also free any storage that is part of a bpstat. */
4467 bpstat_clear (bpstat
*bsp
)
4484 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4485 is part of the bpstat is copied as well. */
4488 bpstat_copy (bpstat bs
)
4492 bpstat retval
= NULL
;
4497 for (; bs
!= NULL
; bs
= bs
->next
)
4499 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4500 memcpy (tmp
, bs
, sizeof (*tmp
));
4501 incref_counted_command_line (tmp
->commands
);
4502 incref_bp_location (tmp
->bp_location_at
);
4503 if (bs
->old_val
!= NULL
)
4505 tmp
->old_val
= value_copy (bs
->old_val
);
4506 release_value (tmp
->old_val
);
4510 /* This is the first thing in the chain. */
4520 /* Find the bpstat associated with this breakpoint. */
4523 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4528 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4530 if (bsp
->breakpoint_at
== breakpoint
)
4536 /* See breakpoint.h. */
4539 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4541 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4543 if (bsp
->breakpoint_at
== NULL
)
4545 /* A moribund location can never explain a signal other than
4547 if (sig
== GDB_SIGNAL_TRAP
)
4552 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4561 /* Put in *NUM the breakpoint number of the first breakpoint we are
4562 stopped at. *BSP upon return is a bpstat which points to the
4563 remaining breakpoints stopped at (but which is not guaranteed to be
4564 good for anything but further calls to bpstat_num).
4566 Return 0 if passed a bpstat which does not indicate any breakpoints.
4567 Return -1 if stopped at a breakpoint that has been deleted since
4569 Return 1 otherwise. */
4572 bpstat_num (bpstat
*bsp
, int *num
)
4574 struct breakpoint
*b
;
4577 return 0; /* No more breakpoint values */
4579 /* We assume we'll never have several bpstats that correspond to a
4580 single breakpoint -- otherwise, this function might return the
4581 same number more than once and this will look ugly. */
4582 b
= (*bsp
)->breakpoint_at
;
4583 *bsp
= (*bsp
)->next
;
4585 return -1; /* breakpoint that's been deleted since */
4587 *num
= b
->number
; /* We have its number */
4591 /* See breakpoint.h. */
4594 bpstat_clear_actions (void)
4596 struct thread_info
*tp
;
4599 if (ptid_equal (inferior_ptid
, null_ptid
))
4602 tp
= find_thread_ptid (inferior_ptid
);
4606 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4608 decref_counted_command_line (&bs
->commands
);
4610 if (bs
->old_val
!= NULL
)
4612 value_free (bs
->old_val
);
4618 /* Called when a command is about to proceed the inferior. */
4621 breakpoint_about_to_proceed (void)
4623 if (!ptid_equal (inferior_ptid
, null_ptid
))
4625 struct thread_info
*tp
= inferior_thread ();
4627 /* Allow inferior function calls in breakpoint commands to not
4628 interrupt the command list. When the call finishes
4629 successfully, the inferior will be standing at the same
4630 breakpoint as if nothing happened. */
4631 if (tp
->control
.in_infcall
)
4635 breakpoint_proceeded
= 1;
4638 /* Stub for cleaning up our state if we error-out of a breakpoint
4641 cleanup_executing_breakpoints (void *ignore
)
4643 executing_breakpoint_commands
= 0;
4646 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4647 or its equivalent. */
4650 command_line_is_silent (struct command_line
*cmd
)
4652 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4655 /* Execute all the commands associated with all the breakpoints at
4656 this location. Any of these commands could cause the process to
4657 proceed beyond this point, etc. We look out for such changes by
4658 checking the global "breakpoint_proceeded" after each command.
4660 Returns true if a breakpoint command resumed the inferior. In that
4661 case, it is the caller's responsibility to recall it again with the
4662 bpstat of the current thread. */
4665 bpstat_do_actions_1 (bpstat
*bsp
)
4668 struct cleanup
*old_chain
;
4671 /* Avoid endless recursion if a `source' command is contained
4673 if (executing_breakpoint_commands
)
4676 executing_breakpoint_commands
= 1;
4677 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4679 scoped_restore preventer
= prevent_dont_repeat ();
4681 /* This pointer will iterate over the list of bpstat's. */
4684 breakpoint_proceeded
= 0;
4685 for (; bs
!= NULL
; bs
= bs
->next
)
4687 struct counted_command_line
*ccmd
;
4688 struct command_line
*cmd
;
4689 struct cleanup
*this_cmd_tree_chain
;
4691 /* Take ownership of the BSP's command tree, if it has one.
4693 The command tree could legitimately contain commands like
4694 'step' and 'next', which call clear_proceed_status, which
4695 frees stop_bpstat's command tree. To make sure this doesn't
4696 free the tree we're executing out from under us, we need to
4697 take ownership of the tree ourselves. Since a given bpstat's
4698 commands are only executed once, we don't need to copy it; we
4699 can clear the pointer in the bpstat, and make sure we free
4700 the tree when we're done. */
4701 ccmd
= bs
->commands
;
4702 bs
->commands
= NULL
;
4703 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4704 cmd
= ccmd
? ccmd
->commands
: NULL
;
4705 if (command_line_is_silent (cmd
))
4707 /* The action has been already done by bpstat_stop_status. */
4713 execute_control_command (cmd
);
4715 if (breakpoint_proceeded
)
4721 /* We can free this command tree now. */
4722 do_cleanups (this_cmd_tree_chain
);
4724 if (breakpoint_proceeded
)
4726 if (current_ui
->async
)
4727 /* If we are in async mode, then the target might be still
4728 running, not stopped at any breakpoint, so nothing for
4729 us to do here -- just return to the event loop. */
4732 /* In sync mode, when execute_control_command returns
4733 we're already standing on the next breakpoint.
4734 Breakpoint commands for that stop were not run, since
4735 execute_command does not run breakpoint commands --
4736 only command_line_handler does, but that one is not
4737 involved in execution of breakpoint commands. So, we
4738 can now execute breakpoint commands. It should be
4739 noted that making execute_command do bpstat actions is
4740 not an option -- in this case we'll have recursive
4741 invocation of bpstat for each breakpoint with a
4742 command, and can easily blow up GDB stack. Instead, we
4743 return true, which will trigger the caller to recall us
4744 with the new stop_bpstat. */
4749 do_cleanups (old_chain
);
4754 bpstat_do_actions (void)
4756 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4758 /* Do any commands attached to breakpoint we are stopped at. */
4759 while (!ptid_equal (inferior_ptid
, null_ptid
)
4760 && target_has_execution
4761 && !is_exited (inferior_ptid
)
4762 && !is_executing (inferior_ptid
))
4763 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4764 and only return when it is stopped at the next breakpoint, we
4765 keep doing breakpoint actions until it returns false to
4766 indicate the inferior was not resumed. */
4767 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4770 discard_cleanups (cleanup_if_error
);
4773 /* Print out the (old or new) value associated with a watchpoint. */
4776 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4779 fprintf_unfiltered (stream
, _("<unreadable>"));
4782 struct value_print_options opts
;
4783 get_user_print_options (&opts
);
4784 value_print (val
, stream
, &opts
);
4788 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4789 debugging multiple threads. */
4792 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4794 if (uiout
->is_mi_like_p ())
4799 if (show_thread_that_caused_stop ())
4802 struct thread_info
*thr
= inferior_thread ();
4804 uiout
->text ("Thread ");
4805 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4807 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4810 uiout
->text (" \"");
4811 uiout
->field_fmt ("name", "%s", name
);
4815 uiout
->text (" hit ");
4819 /* Generic routine for printing messages indicating why we
4820 stopped. The behavior of this function depends on the value
4821 'print_it' in the bpstat structure. Under some circumstances we
4822 may decide not to print anything here and delegate the task to
4825 static enum print_stop_action
4826 print_bp_stop_message (bpstat bs
)
4828 switch (bs
->print_it
)
4831 /* Nothing should be printed for this bpstat entry. */
4832 return PRINT_UNKNOWN
;
4836 /* We still want to print the frame, but we already printed the
4837 relevant messages. */
4838 return PRINT_SRC_AND_LOC
;
4841 case print_it_normal
:
4843 struct breakpoint
*b
= bs
->breakpoint_at
;
4845 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4846 which has since been deleted. */
4848 return PRINT_UNKNOWN
;
4850 /* Normal case. Call the breakpoint's print_it method. */
4851 return b
->ops
->print_it (bs
);
4856 internal_error (__FILE__
, __LINE__
,
4857 _("print_bp_stop_message: unrecognized enum value"));
4862 /* A helper function that prints a shared library stopped event. */
4865 print_solib_event (int is_catchpoint
)
4868 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4870 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4874 if (any_added
|| any_deleted
)
4875 current_uiout
->text (_("Stopped due to shared library event:\n"));
4877 current_uiout
->text (_("Stopped due to shared library event (no "
4878 "libraries added or removed)\n"));
4881 if (current_uiout
->is_mi_like_p ())
4882 current_uiout
->field_string ("reason",
4883 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4890 current_uiout
->text (_(" Inferior unloaded "));
4891 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4893 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4898 current_uiout
->text (" ");
4899 current_uiout
->field_string ("library", name
);
4900 current_uiout
->text ("\n");
4906 struct so_list
*iter
;
4909 current_uiout
->text (_(" Inferior loaded "));
4910 ui_out_emit_list
list_emitter (current_uiout
, "added");
4912 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4917 current_uiout
->text (" ");
4918 current_uiout
->field_string ("library", iter
->so_name
);
4919 current_uiout
->text ("\n");
4924 /* Print a message indicating what happened. This is called from
4925 normal_stop(). The input to this routine is the head of the bpstat
4926 list - a list of the eventpoints that caused this stop. KIND is
4927 the target_waitkind for the stopping event. This
4928 routine calls the generic print routine for printing a message
4929 about reasons for stopping. This will print (for example) the
4930 "Breakpoint n," part of the output. The return value of this
4933 PRINT_UNKNOWN: Means we printed nothing.
4934 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4935 code to print the location. An example is
4936 "Breakpoint 1, " which should be followed by
4938 PRINT_SRC_ONLY: Means we printed something, but there is no need
4939 to also print the location part of the message.
4940 An example is the catch/throw messages, which
4941 don't require a location appended to the end.
4942 PRINT_NOTHING: We have done some printing and we don't need any
4943 further info to be printed. */
4945 enum print_stop_action
4946 bpstat_print (bpstat bs
, int kind
)
4948 enum print_stop_action val
;
4950 /* Maybe another breakpoint in the chain caused us to stop.
4951 (Currently all watchpoints go on the bpstat whether hit or not.
4952 That probably could (should) be changed, provided care is taken
4953 with respect to bpstat_explains_signal). */
4954 for (; bs
; bs
= bs
->next
)
4956 val
= print_bp_stop_message (bs
);
4957 if (val
== PRINT_SRC_ONLY
4958 || val
== PRINT_SRC_AND_LOC
4959 || val
== PRINT_NOTHING
)
4963 /* If we had hit a shared library event breakpoint,
4964 print_bp_stop_message would print out this message. If we hit an
4965 OS-level shared library event, do the same thing. */
4966 if (kind
== TARGET_WAITKIND_LOADED
)
4968 print_solib_event (0);
4969 return PRINT_NOTHING
;
4972 /* We reached the end of the chain, or we got a null BS to start
4973 with and nothing was printed. */
4974 return PRINT_UNKNOWN
;
4977 /* Evaluate the expression EXP and return 1 if value is zero.
4978 This returns the inverse of the condition because it is called
4979 from catch_errors which returns 0 if an exception happened, and if an
4980 exception happens we want execution to stop.
4981 The argument is a "struct expression *" that has been cast to a
4982 "void *" to make it pass through catch_errors. */
4985 breakpoint_cond_eval (void *exp
)
4987 struct value
*mark
= value_mark ();
4988 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4990 value_free_to_mark (mark
);
4994 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4997 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5001 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5003 **bs_link_pointer
= bs
;
5004 *bs_link_pointer
= &bs
->next
;
5005 bs
->breakpoint_at
= bl
->owner
;
5006 bs
->bp_location_at
= bl
;
5007 incref_bp_location (bl
);
5008 /* If the condition is false, etc., don't do the commands. */
5009 bs
->commands
= NULL
;
5011 bs
->print_it
= print_it_normal
;
5015 /* The target has stopped with waitstatus WS. Check if any hardware
5016 watchpoints have triggered, according to the target. */
5019 watchpoints_triggered (struct target_waitstatus
*ws
)
5021 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5023 struct breakpoint
*b
;
5025 if (!stopped_by_watchpoint
)
5027 /* We were not stopped by a watchpoint. Mark all watchpoints
5028 as not triggered. */
5030 if (is_hardware_watchpoint (b
))
5032 struct watchpoint
*w
= (struct watchpoint
*) b
;
5034 w
->watchpoint_triggered
= watch_triggered_no
;
5040 if (!target_stopped_data_address (¤t_target
, &addr
))
5042 /* We were stopped by a watchpoint, but we don't know where.
5043 Mark all watchpoints as unknown. */
5045 if (is_hardware_watchpoint (b
))
5047 struct watchpoint
*w
= (struct watchpoint
*) b
;
5049 w
->watchpoint_triggered
= watch_triggered_unknown
;
5055 /* The target could report the data address. Mark watchpoints
5056 affected by this data address as triggered, and all others as not
5060 if (is_hardware_watchpoint (b
))
5062 struct watchpoint
*w
= (struct watchpoint
*) b
;
5063 struct bp_location
*loc
;
5065 w
->watchpoint_triggered
= watch_triggered_no
;
5066 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5068 if (is_masked_watchpoint (b
))
5070 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5071 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5073 if (newaddr
== start
)
5075 w
->watchpoint_triggered
= watch_triggered_yes
;
5079 /* Exact match not required. Within range is sufficient. */
5080 else if (target_watchpoint_addr_within_range (¤t_target
,
5084 w
->watchpoint_triggered
= watch_triggered_yes
;
5093 /* Possible return values for watchpoint_check (this can't be an enum
5094 because of check_errors). */
5095 /* The watchpoint has been deleted. */
5096 #define WP_DELETED 1
5097 /* The value has changed. */
5098 #define WP_VALUE_CHANGED 2
5099 /* The value has not changed. */
5100 #define WP_VALUE_NOT_CHANGED 3
5101 /* Ignore this watchpoint, no matter if the value changed or not. */
5104 #define BP_TEMPFLAG 1
5105 #define BP_HARDWAREFLAG 2
5107 /* Evaluate watchpoint condition expression and check if its value
5110 P should be a pointer to struct bpstat, but is defined as a void *
5111 in order for this function to be usable with catch_errors. */
5114 watchpoint_check (void *p
)
5116 bpstat bs
= (bpstat
) p
;
5117 struct watchpoint
*b
;
5118 struct frame_info
*fr
;
5119 int within_current_scope
;
5121 /* BS is built from an existing struct breakpoint. */
5122 gdb_assert (bs
->breakpoint_at
!= NULL
);
5123 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5125 /* If this is a local watchpoint, we only want to check if the
5126 watchpoint frame is in scope if the current thread is the thread
5127 that was used to create the watchpoint. */
5128 if (!watchpoint_in_thread_scope (b
))
5131 if (b
->exp_valid_block
== NULL
)
5132 within_current_scope
= 1;
5135 struct frame_info
*frame
= get_current_frame ();
5136 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5137 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5139 /* stack_frame_destroyed_p() returns a non-zero value if we're
5140 still in the function but the stack frame has already been
5141 invalidated. Since we can't rely on the values of local
5142 variables after the stack has been destroyed, we are treating
5143 the watchpoint in that state as `not changed' without further
5144 checking. Don't mark watchpoints as changed if the current
5145 frame is in an epilogue - even if they are in some other
5146 frame, our view of the stack is likely to be wrong and
5147 frame_find_by_id could error out. */
5148 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5151 fr
= frame_find_by_id (b
->watchpoint_frame
);
5152 within_current_scope
= (fr
!= NULL
);
5154 /* If we've gotten confused in the unwinder, we might have
5155 returned a frame that can't describe this variable. */
5156 if (within_current_scope
)
5158 struct symbol
*function
;
5160 function
= get_frame_function (fr
);
5161 if (function
== NULL
5162 || !contained_in (b
->exp_valid_block
,
5163 SYMBOL_BLOCK_VALUE (function
)))
5164 within_current_scope
= 0;
5167 if (within_current_scope
)
5168 /* If we end up stopping, the current frame will get selected
5169 in normal_stop. So this call to select_frame won't affect
5174 if (within_current_scope
)
5176 /* We use value_{,free_to_}mark because it could be a *long*
5177 time before we return to the command level and call
5178 free_all_values. We can't call free_all_values because we
5179 might be in the middle of evaluating a function call. */
5183 struct value
*new_val
;
5185 if (is_masked_watchpoint (&b
->base
))
5186 /* Since we don't know the exact trigger address (from
5187 stopped_data_address), just tell the user we've triggered
5188 a mask watchpoint. */
5189 return WP_VALUE_CHANGED
;
5191 mark
= value_mark ();
5192 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5194 if (b
->val_bitsize
!= 0)
5195 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5197 /* We use value_equal_contents instead of value_equal because
5198 the latter coerces an array to a pointer, thus comparing just
5199 the address of the array instead of its contents. This is
5200 not what we want. */
5201 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5202 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5204 if (new_val
!= NULL
)
5206 release_value (new_val
);
5207 value_free_to_mark (mark
);
5209 bs
->old_val
= b
->val
;
5212 return WP_VALUE_CHANGED
;
5216 /* Nothing changed. */
5217 value_free_to_mark (mark
);
5218 return WP_VALUE_NOT_CHANGED
;
5223 /* This seems like the only logical thing to do because
5224 if we temporarily ignored the watchpoint, then when
5225 we reenter the block in which it is valid it contains
5226 garbage (in the case of a function, it may have two
5227 garbage values, one before and one after the prologue).
5228 So we can't even detect the first assignment to it and
5229 watch after that (since the garbage may or may not equal
5230 the first value assigned). */
5231 /* We print all the stop information in
5232 breakpoint_ops->print_it, but in this case, by the time we
5233 call breakpoint_ops->print_it this bp will be deleted
5234 already. So we have no choice but print the information
5237 SWITCH_THRU_ALL_UIS ()
5239 struct ui_out
*uiout
= current_uiout
;
5241 if (uiout
->is_mi_like_p ())
5243 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5244 uiout
->text ("\nWatchpoint ");
5245 uiout
->field_int ("wpnum", b
->base
.number
);
5246 uiout
->text (" deleted because the program has left the block in\n"
5247 "which its expression is valid.\n");
5250 /* Make sure the watchpoint's commands aren't executed. */
5251 decref_counted_command_line (&b
->base
.commands
);
5252 watchpoint_del_at_next_stop (b
);
5258 /* Return true if it looks like target has stopped due to hitting
5259 breakpoint location BL. This function does not check if we should
5260 stop, only if BL explains the stop. */
5263 bpstat_check_location (const struct bp_location
*bl
,
5264 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5265 const struct target_waitstatus
*ws
)
5267 struct breakpoint
*b
= bl
->owner
;
5269 /* BL is from an existing breakpoint. */
5270 gdb_assert (b
!= NULL
);
5272 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5275 /* Determine if the watched values have actually changed, and we
5276 should stop. If not, set BS->stop to 0. */
5279 bpstat_check_watchpoint (bpstat bs
)
5281 const struct bp_location
*bl
;
5282 struct watchpoint
*b
;
5284 /* BS is built for existing struct breakpoint. */
5285 bl
= bs
->bp_location_at
;
5286 gdb_assert (bl
!= NULL
);
5287 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5288 gdb_assert (b
!= NULL
);
5291 int must_check_value
= 0;
5293 if (b
->base
.type
== bp_watchpoint
)
5294 /* For a software watchpoint, we must always check the
5296 must_check_value
= 1;
5297 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5298 /* We have a hardware watchpoint (read, write, or access)
5299 and the target earlier reported an address watched by
5301 must_check_value
= 1;
5302 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5303 && b
->base
.type
== bp_hardware_watchpoint
)
5304 /* We were stopped by a hardware watchpoint, but the target could
5305 not report the data address. We must check the watchpoint's
5306 value. Access and read watchpoints are out of luck; without
5307 a data address, we can't figure it out. */
5308 must_check_value
= 1;
5310 if (must_check_value
)
5313 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5315 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5316 int e
= catch_errors (watchpoint_check
, bs
, message
,
5318 do_cleanups (cleanups
);
5322 /* We've already printed what needs to be printed. */
5323 bs
->print_it
= print_it_done
;
5327 bs
->print_it
= print_it_noop
;
5330 case WP_VALUE_CHANGED
:
5331 if (b
->base
.type
== bp_read_watchpoint
)
5333 /* There are two cases to consider here:
5335 1. We're watching the triggered memory for reads.
5336 In that case, trust the target, and always report
5337 the watchpoint hit to the user. Even though
5338 reads don't cause value changes, the value may
5339 have changed since the last time it was read, and
5340 since we're not trapping writes, we will not see
5341 those, and as such we should ignore our notion of
5344 2. We're watching the triggered memory for both
5345 reads and writes. There are two ways this may
5348 2.1. This is a target that can't break on data
5349 reads only, but can break on accesses (reads or
5350 writes), such as e.g., x86. We detect this case
5351 at the time we try to insert read watchpoints.
5353 2.2. Otherwise, the target supports read
5354 watchpoints, but, the user set an access or write
5355 watchpoint watching the same memory as this read
5358 If we're watching memory writes as well as reads,
5359 ignore watchpoint hits when we find that the
5360 value hasn't changed, as reads don't cause
5361 changes. This still gives false positives when
5362 the program writes the same value to memory as
5363 what there was already in memory (we will confuse
5364 it for a read), but it's much better than
5367 int other_write_watchpoint
= 0;
5369 if (bl
->watchpoint_type
== hw_read
)
5371 struct breakpoint
*other_b
;
5373 ALL_BREAKPOINTS (other_b
)
5374 if (other_b
->type
== bp_hardware_watchpoint
5375 || other_b
->type
== bp_access_watchpoint
)
5377 struct watchpoint
*other_w
=
5378 (struct watchpoint
*) other_b
;
5380 if (other_w
->watchpoint_triggered
5381 == watch_triggered_yes
)
5383 other_write_watchpoint
= 1;
5389 if (other_write_watchpoint
5390 || bl
->watchpoint_type
== hw_access
)
5392 /* We're watching the same memory for writes,
5393 and the value changed since the last time we
5394 updated it, so this trap must be for a write.
5396 bs
->print_it
= print_it_noop
;
5401 case WP_VALUE_NOT_CHANGED
:
5402 if (b
->base
.type
== bp_hardware_watchpoint
5403 || b
->base
.type
== bp_watchpoint
)
5405 /* Don't stop: write watchpoints shouldn't fire if
5406 the value hasn't changed. */
5407 bs
->print_it
= print_it_noop
;
5415 /* Error from catch_errors. */
5417 SWITCH_THRU_ALL_UIS ()
5419 printf_filtered (_("Watchpoint %d deleted.\n"),
5422 watchpoint_del_at_next_stop (b
);
5423 /* We've already printed what needs to be printed. */
5424 bs
->print_it
= print_it_done
;
5429 else /* must_check_value == 0 */
5431 /* This is a case where some watchpoint(s) triggered, but
5432 not at the address of this watchpoint, or else no
5433 watchpoint triggered after all. So don't print
5434 anything for this watchpoint. */
5435 bs
->print_it
= print_it_noop
;
5441 /* For breakpoints that are currently marked as telling gdb to stop,
5442 check conditions (condition proper, frame, thread and ignore count)
5443 of breakpoint referred to by BS. If we should not stop for this
5444 breakpoint, set BS->stop to 0. */
5447 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5449 const struct bp_location
*bl
;
5450 struct breakpoint
*b
;
5451 int value_is_zero
= 0;
5452 struct expression
*cond
;
5454 gdb_assert (bs
->stop
);
5456 /* BS is built for existing struct breakpoint. */
5457 bl
= bs
->bp_location_at
;
5458 gdb_assert (bl
!= NULL
);
5459 b
= bs
->breakpoint_at
;
5460 gdb_assert (b
!= NULL
);
5462 /* Even if the target evaluated the condition on its end and notified GDB, we
5463 need to do so again since GDB does not know if we stopped due to a
5464 breakpoint or a single step breakpoint. */
5466 if (frame_id_p (b
->frame_id
)
5467 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5473 /* If this is a thread/task-specific breakpoint, don't waste cpu
5474 evaluating the condition if this isn't the specified
5476 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5477 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5484 /* Evaluate extension language breakpoints that have a "stop" method
5486 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5488 if (is_watchpoint (b
))
5490 struct watchpoint
*w
= (struct watchpoint
*) b
;
5492 cond
= w
->cond_exp
.get ();
5495 cond
= bl
->cond
.get ();
5497 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5499 int within_current_scope
= 1;
5500 struct watchpoint
* w
;
5502 /* We use value_mark and value_free_to_mark because it could
5503 be a long time before we return to the command level and
5504 call free_all_values. We can't call free_all_values
5505 because we might be in the middle of evaluating a
5507 struct value
*mark
= value_mark ();
5509 if (is_watchpoint (b
))
5510 w
= (struct watchpoint
*) b
;
5514 /* Need to select the frame, with all that implies so that
5515 the conditions will have the right context. Because we
5516 use the frame, we will not see an inlined function's
5517 variables when we arrive at a breakpoint at the start
5518 of the inlined function; the current frame will be the
5520 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5521 select_frame (get_current_frame ());
5524 struct frame_info
*frame
;
5526 /* For local watchpoint expressions, which particular
5527 instance of a local is being watched matters, so we
5528 keep track of the frame to evaluate the expression
5529 in. To evaluate the condition however, it doesn't
5530 really matter which instantiation of the function
5531 where the condition makes sense triggers the
5532 watchpoint. This allows an expression like "watch
5533 global if q > 10" set in `func', catch writes to
5534 global on all threads that call `func', or catch
5535 writes on all recursive calls of `func' by a single
5536 thread. We simply always evaluate the condition in
5537 the innermost frame that's executing where it makes
5538 sense to evaluate the condition. It seems
5540 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5542 select_frame (frame
);
5544 within_current_scope
= 0;
5546 if (within_current_scope
)
5548 = catch_errors (breakpoint_cond_eval
, cond
,
5549 "Error in testing breakpoint condition:\n",
5553 warning (_("Watchpoint condition cannot be tested "
5554 "in the current scope"));
5555 /* If we failed to set the right context for this
5556 watchpoint, unconditionally report it. */
5559 /* FIXME-someday, should give breakpoint #. */
5560 value_free_to_mark (mark
);
5563 if (cond
&& value_is_zero
)
5567 else if (b
->ignore_count
> 0)
5571 /* Increase the hit count even though we don't stop. */
5573 observer_notify_breakpoint_modified (b
);
5577 /* Returns true if we need to track moribund locations of LOC's type
5578 on the current target. */
5581 need_moribund_for_location_type (struct bp_location
*loc
)
5583 return ((loc
->loc_type
== bp_loc_software_breakpoint
5584 && !target_supports_stopped_by_sw_breakpoint ())
5585 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5586 && !target_supports_stopped_by_hw_breakpoint ()));
5590 /* Get a bpstat associated with having just stopped at address
5591 BP_ADDR in thread PTID.
5593 Determine whether we stopped at a breakpoint, etc, or whether we
5594 don't understand this stop. Result is a chain of bpstat's such
5597 if we don't understand the stop, the result is a null pointer.
5599 if we understand why we stopped, the result is not null.
5601 Each element of the chain refers to a particular breakpoint or
5602 watchpoint at which we have stopped. (We may have stopped for
5603 several reasons concurrently.)
5605 Each element of the chain has valid next, breakpoint_at,
5606 commands, FIXME??? fields. */
5609 bpstat_stop_status (struct address_space
*aspace
,
5610 CORE_ADDR bp_addr
, ptid_t ptid
,
5611 const struct target_waitstatus
*ws
)
5613 struct breakpoint
*b
= NULL
;
5614 struct bp_location
*bl
;
5615 struct bp_location
*loc
;
5616 /* First item of allocated bpstat's. */
5617 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5618 /* Pointer to the last thing in the chain currently. */
5621 int need_remove_insert
;
5624 /* First, build the bpstat chain with locations that explain a
5625 target stop, while being careful to not set the target running,
5626 as that may invalidate locations (in particular watchpoint
5627 locations are recreated). Resuming will happen here with
5628 breakpoint conditions or watchpoint expressions that include
5629 inferior function calls. */
5633 if (!breakpoint_enabled (b
))
5636 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5638 /* For hardware watchpoints, we look only at the first
5639 location. The watchpoint_check function will work on the
5640 entire expression, not the individual locations. For
5641 read watchpoints, the watchpoints_triggered function has
5642 checked all locations already. */
5643 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5646 if (!bl
->enabled
|| bl
->shlib_disabled
)
5649 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5652 /* Come here if it's a watchpoint, or if the break address
5655 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5658 /* Assume we stop. Should we find a watchpoint that is not
5659 actually triggered, or if the condition of the breakpoint
5660 evaluates as false, we'll reset 'stop' to 0. */
5664 /* If this is a scope breakpoint, mark the associated
5665 watchpoint as triggered so that we will handle the
5666 out-of-scope event. We'll get to the watchpoint next
5668 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5670 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5672 w
->watchpoint_triggered
= watch_triggered_yes
;
5677 /* Check if a moribund breakpoint explains the stop. */
5678 if (!target_supports_stopped_by_sw_breakpoint ()
5679 || !target_supports_stopped_by_hw_breakpoint ())
5681 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5683 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5684 && need_moribund_for_location_type (loc
))
5686 bs
= bpstat_alloc (loc
, &bs_link
);
5687 /* For hits of moribund locations, we should just proceed. */
5690 bs
->print_it
= print_it_noop
;
5695 /* A bit of special processing for shlib breakpoints. We need to
5696 process solib loading here, so that the lists of loaded and
5697 unloaded libraries are correct before we handle "catch load" and
5699 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5701 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5703 handle_solib_event ();
5708 /* Now go through the locations that caused the target to stop, and
5709 check whether we're interested in reporting this stop to higher
5710 layers, or whether we should resume the target transparently. */
5714 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5719 b
= bs
->breakpoint_at
;
5720 b
->ops
->check_status (bs
);
5723 bpstat_check_breakpoint_conditions (bs
, ptid
);
5728 observer_notify_breakpoint_modified (b
);
5730 /* We will stop here. */
5731 if (b
->disposition
== disp_disable
)
5733 --(b
->enable_count
);
5734 if (b
->enable_count
<= 0)
5735 b
->enable_state
= bp_disabled
;
5740 bs
->commands
= b
->commands
;
5741 incref_counted_command_line (bs
->commands
);
5742 if (command_line_is_silent (bs
->commands
5743 ? bs
->commands
->commands
: NULL
))
5746 b
->ops
->after_condition_true (bs
);
5751 /* Print nothing for this entry if we don't stop or don't
5753 if (!bs
->stop
|| !bs
->print
)
5754 bs
->print_it
= print_it_noop
;
5757 /* If we aren't stopping, the value of some hardware watchpoint may
5758 not have changed, but the intermediate memory locations we are
5759 watching may have. Don't bother if we're stopping; this will get
5761 need_remove_insert
= 0;
5762 if (! bpstat_causes_stop (bs_head
))
5763 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5765 && bs
->breakpoint_at
5766 && is_hardware_watchpoint (bs
->breakpoint_at
))
5768 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5770 update_watchpoint (w
, 0 /* don't reparse. */);
5771 need_remove_insert
= 1;
5774 if (need_remove_insert
)
5775 update_global_location_list (UGLL_MAY_INSERT
);
5776 else if (removed_any
)
5777 update_global_location_list (UGLL_DONT_INSERT
);
5783 handle_jit_event (void)
5785 struct frame_info
*frame
;
5786 struct gdbarch
*gdbarch
;
5789 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5791 /* Switch terminal for any messages produced by
5792 breakpoint_re_set. */
5793 target_terminal_ours_for_output ();
5795 frame
= get_current_frame ();
5796 gdbarch
= get_frame_arch (frame
);
5798 jit_event_handler (gdbarch
);
5800 target_terminal_inferior ();
5803 /* Prepare WHAT final decision for infrun. */
5805 /* Decide what infrun needs to do with this bpstat. */
5808 bpstat_what (bpstat bs_head
)
5810 struct bpstat_what retval
;
5813 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5814 retval
.call_dummy
= STOP_NONE
;
5815 retval
.is_longjmp
= 0;
5817 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5819 /* Extract this BS's action. After processing each BS, we check
5820 if its action overrides all we've seem so far. */
5821 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5824 if (bs
->breakpoint_at
== NULL
)
5826 /* I suspect this can happen if it was a momentary
5827 breakpoint which has since been deleted. */
5831 bptype
= bs
->breakpoint_at
->type
;
5838 case bp_hardware_breakpoint
:
5839 case bp_single_step
:
5842 case bp_shlib_event
:
5846 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5848 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5851 this_action
= BPSTAT_WHAT_SINGLE
;
5854 case bp_hardware_watchpoint
:
5855 case bp_read_watchpoint
:
5856 case bp_access_watchpoint
:
5860 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5862 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5866 /* There was a watchpoint, but we're not stopping.
5867 This requires no further action. */
5871 case bp_longjmp_call_dummy
:
5875 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5876 retval
.is_longjmp
= bptype
!= bp_exception
;
5879 this_action
= BPSTAT_WHAT_SINGLE
;
5881 case bp_longjmp_resume
:
5882 case bp_exception_resume
:
5885 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5886 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5889 this_action
= BPSTAT_WHAT_SINGLE
;
5891 case bp_step_resume
:
5893 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5896 /* It is for the wrong frame. */
5897 this_action
= BPSTAT_WHAT_SINGLE
;
5900 case bp_hp_step_resume
:
5902 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5905 /* It is for the wrong frame. */
5906 this_action
= BPSTAT_WHAT_SINGLE
;
5909 case bp_watchpoint_scope
:
5910 case bp_thread_event
:
5911 case bp_overlay_event
:
5912 case bp_longjmp_master
:
5913 case bp_std_terminate_master
:
5914 case bp_exception_master
:
5915 this_action
= BPSTAT_WHAT_SINGLE
;
5921 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5923 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5927 /* There was a catchpoint, but we're not stopping.
5928 This requires no further action. */
5932 this_action
= BPSTAT_WHAT_SINGLE
;
5935 /* Make sure the action is stop (silent or noisy),
5936 so infrun.c pops the dummy frame. */
5937 retval
.call_dummy
= STOP_STACK_DUMMY
;
5938 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5940 case bp_std_terminate
:
5941 /* Make sure the action is stop (silent or noisy),
5942 so infrun.c pops the dummy frame. */
5943 retval
.call_dummy
= STOP_STD_TERMINATE
;
5944 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5947 case bp_fast_tracepoint
:
5948 case bp_static_tracepoint
:
5949 /* Tracepoint hits should not be reported back to GDB, and
5950 if one got through somehow, it should have been filtered
5952 internal_error (__FILE__
, __LINE__
,
5953 _("bpstat_what: tracepoint encountered"));
5955 case bp_gnu_ifunc_resolver
:
5956 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5957 this_action
= BPSTAT_WHAT_SINGLE
;
5959 case bp_gnu_ifunc_resolver_return
:
5960 /* The breakpoint will be removed, execution will restart from the
5961 PC of the former breakpoint. */
5962 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5967 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5969 this_action
= BPSTAT_WHAT_SINGLE
;
5973 internal_error (__FILE__
, __LINE__
,
5974 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5977 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5984 bpstat_run_callbacks (bpstat bs_head
)
5988 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5990 struct breakpoint
*b
= bs
->breakpoint_at
;
5997 handle_jit_event ();
5999 case bp_gnu_ifunc_resolver
:
6000 gnu_ifunc_resolver_stop (b
);
6002 case bp_gnu_ifunc_resolver_return
:
6003 gnu_ifunc_resolver_return_stop (b
);
6009 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6010 without hardware support). This isn't related to a specific bpstat,
6011 just to things like whether watchpoints are set. */
6014 bpstat_should_step (void)
6016 struct breakpoint
*b
;
6019 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6025 bpstat_causes_stop (bpstat bs
)
6027 for (; bs
!= NULL
; bs
= bs
->next
)
6036 /* Compute a string of spaces suitable to indent the next line
6037 so it starts at the position corresponding to the table column
6038 named COL_NAME in the currently active table of UIOUT. */
6041 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6043 static char wrap_indent
[80];
6044 int i
, total_width
, width
, align
;
6048 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6050 if (strcmp (text
, col_name
) == 0)
6052 gdb_assert (total_width
< sizeof wrap_indent
);
6053 memset (wrap_indent
, ' ', total_width
);
6054 wrap_indent
[total_width
] = 0;
6059 total_width
+= width
+ 1;
6065 /* Determine if the locations of this breakpoint will have their conditions
6066 evaluated by the target, host or a mix of both. Returns the following:
6068 "host": Host evals condition.
6069 "host or target": Host or Target evals condition.
6070 "target": Target evals condition.
6074 bp_condition_evaluator (struct breakpoint
*b
)
6076 struct bp_location
*bl
;
6077 char host_evals
= 0;
6078 char target_evals
= 0;
6083 if (!is_breakpoint (b
))
6086 if (gdb_evaluates_breakpoint_condition_p ()
6087 || !target_supports_evaluation_of_breakpoint_conditions ())
6088 return condition_evaluation_host
;
6090 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6092 if (bl
->cond_bytecode
)
6098 if (host_evals
&& target_evals
)
6099 return condition_evaluation_both
;
6100 else if (target_evals
)
6101 return condition_evaluation_target
;
6103 return condition_evaluation_host
;
6106 /* Determine the breakpoint location's condition evaluator. This is
6107 similar to bp_condition_evaluator, but for locations. */
6110 bp_location_condition_evaluator (struct bp_location
*bl
)
6112 if (bl
&& !is_breakpoint (bl
->owner
))
6115 if (gdb_evaluates_breakpoint_condition_p ()
6116 || !target_supports_evaluation_of_breakpoint_conditions ())
6117 return condition_evaluation_host
;
6119 if (bl
&& bl
->cond_bytecode
)
6120 return condition_evaluation_target
;
6122 return condition_evaluation_host
;
6125 /* Print the LOC location out of the list of B->LOC locations. */
6128 print_breakpoint_location (struct breakpoint
*b
,
6129 struct bp_location
*loc
)
6131 struct ui_out
*uiout
= current_uiout
;
6132 struct cleanup
*old_chain
= save_current_program_space ();
6134 if (loc
!= NULL
&& loc
->shlib_disabled
)
6138 set_current_program_space (loc
->pspace
);
6140 if (b
->display_canonical
)
6141 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6142 else if (loc
&& loc
->symtab
)
6145 = find_pc_sect_function (loc
->address
, loc
->section
);
6148 uiout
->text ("in ");
6149 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6151 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6152 uiout
->text ("at ");
6154 uiout
->field_string ("file",
6155 symtab_to_filename_for_display (loc
->symtab
));
6158 if (uiout
->is_mi_like_p ())
6159 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6161 uiout
->field_int ("line", loc
->line_number
);
6167 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6169 uiout
->field_stream ("at", stb
);
6173 uiout
->field_string ("pending",
6174 event_location_to_string (b
->location
.get ()));
6175 /* If extra_string is available, it could be holding a condition
6176 or dprintf arguments. In either case, make sure it is printed,
6177 too, but only for non-MI streams. */
6178 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6180 if (b
->type
== bp_dprintf
)
6184 uiout
->text (b
->extra_string
);
6188 if (loc
&& is_breakpoint (b
)
6189 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6190 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6193 uiout
->field_string ("evaluated-by",
6194 bp_location_condition_evaluator (loc
));
6198 do_cleanups (old_chain
);
6202 bptype_string (enum bptype type
)
6204 struct ep_type_description
6207 const char *description
;
6209 static struct ep_type_description bptypes
[] =
6211 {bp_none
, "?deleted?"},
6212 {bp_breakpoint
, "breakpoint"},
6213 {bp_hardware_breakpoint
, "hw breakpoint"},
6214 {bp_single_step
, "sw single-step"},
6215 {bp_until
, "until"},
6216 {bp_finish
, "finish"},
6217 {bp_watchpoint
, "watchpoint"},
6218 {bp_hardware_watchpoint
, "hw watchpoint"},
6219 {bp_read_watchpoint
, "read watchpoint"},
6220 {bp_access_watchpoint
, "acc watchpoint"},
6221 {bp_longjmp
, "longjmp"},
6222 {bp_longjmp_resume
, "longjmp resume"},
6223 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6224 {bp_exception
, "exception"},
6225 {bp_exception_resume
, "exception resume"},
6226 {bp_step_resume
, "step resume"},
6227 {bp_hp_step_resume
, "high-priority step resume"},
6228 {bp_watchpoint_scope
, "watchpoint scope"},
6229 {bp_call_dummy
, "call dummy"},
6230 {bp_std_terminate
, "std::terminate"},
6231 {bp_shlib_event
, "shlib events"},
6232 {bp_thread_event
, "thread events"},
6233 {bp_overlay_event
, "overlay events"},
6234 {bp_longjmp_master
, "longjmp master"},
6235 {bp_std_terminate_master
, "std::terminate master"},
6236 {bp_exception_master
, "exception master"},
6237 {bp_catchpoint
, "catchpoint"},
6238 {bp_tracepoint
, "tracepoint"},
6239 {bp_fast_tracepoint
, "fast tracepoint"},
6240 {bp_static_tracepoint
, "static tracepoint"},
6241 {bp_dprintf
, "dprintf"},
6242 {bp_jit_event
, "jit events"},
6243 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6244 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6247 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6248 || ((int) type
!= bptypes
[(int) type
].type
))
6249 internal_error (__FILE__
, __LINE__
,
6250 _("bptypes table does not describe type #%d."),
6253 return bptypes
[(int) type
].description
;
6256 /* For MI, output a field named 'thread-groups' with a list as the value.
6257 For CLI, prefix the list with the string 'inf'. */
6260 output_thread_groups (struct ui_out
*uiout
,
6261 const char *field_name
,
6265 int is_mi
= uiout
->is_mi_like_p ();
6269 /* For backward compatibility, don't display inferiors in CLI unless
6270 there are several. Always display them for MI. */
6271 if (!is_mi
&& mi_only
)
6274 ui_out_emit_list
list_emitter (uiout
, field_name
);
6276 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6282 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6283 uiout
->field_string (NULL
, mi_group
);
6288 uiout
->text (" inf ");
6292 uiout
->text (plongest (inf
));
6297 /* Print B to gdb_stdout. */
6300 print_one_breakpoint_location (struct breakpoint
*b
,
6301 struct bp_location
*loc
,
6303 struct bp_location
**last_loc
,
6306 struct command_line
*l
;
6307 static char bpenables
[] = "nynny";
6309 struct ui_out
*uiout
= current_uiout
;
6310 int header_of_multiple
= 0;
6311 int part_of_multiple
= (loc
!= NULL
);
6312 struct value_print_options opts
;
6314 get_user_print_options (&opts
);
6316 gdb_assert (!loc
|| loc_number
!= 0);
6317 /* See comment in print_one_breakpoint concerning treatment of
6318 breakpoints with single disabled location. */
6321 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6322 header_of_multiple
= 1;
6330 if (part_of_multiple
)
6333 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6334 uiout
->field_string ("number", formatted
);
6339 uiout
->field_int ("number", b
->number
);
6344 if (part_of_multiple
)
6345 uiout
->field_skip ("type");
6347 uiout
->field_string ("type", bptype_string (b
->type
));
6351 if (part_of_multiple
)
6352 uiout
->field_skip ("disp");
6354 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6359 if (part_of_multiple
)
6360 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6362 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6367 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6369 /* Although the print_one can possibly print all locations,
6370 calling it here is not likely to get any nice result. So,
6371 make sure there's just one location. */
6372 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6373 b
->ops
->print_one (b
, last_loc
);
6379 internal_error (__FILE__
, __LINE__
,
6380 _("print_one_breakpoint: bp_none encountered\n"));
6384 case bp_hardware_watchpoint
:
6385 case bp_read_watchpoint
:
6386 case bp_access_watchpoint
:
6388 struct watchpoint
*w
= (struct watchpoint
*) b
;
6390 /* Field 4, the address, is omitted (which makes the columns
6391 not line up too nicely with the headers, but the effect
6392 is relatively readable). */
6393 if (opts
.addressprint
)
6394 uiout
->field_skip ("addr");
6396 uiout
->field_string ("what", w
->exp_string
);
6401 case bp_hardware_breakpoint
:
6402 case bp_single_step
:
6406 case bp_longjmp_resume
:
6407 case bp_longjmp_call_dummy
:
6409 case bp_exception_resume
:
6410 case bp_step_resume
:
6411 case bp_hp_step_resume
:
6412 case bp_watchpoint_scope
:
6414 case bp_std_terminate
:
6415 case bp_shlib_event
:
6416 case bp_thread_event
:
6417 case bp_overlay_event
:
6418 case bp_longjmp_master
:
6419 case bp_std_terminate_master
:
6420 case bp_exception_master
:
6422 case bp_fast_tracepoint
:
6423 case bp_static_tracepoint
:
6426 case bp_gnu_ifunc_resolver
:
6427 case bp_gnu_ifunc_resolver_return
:
6428 if (opts
.addressprint
)
6431 if (header_of_multiple
)
6432 uiout
->field_string ("addr", "<MULTIPLE>");
6433 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6434 uiout
->field_string ("addr", "<PENDING>");
6436 uiout
->field_core_addr ("addr",
6437 loc
->gdbarch
, loc
->address
);
6440 if (!header_of_multiple
)
6441 print_breakpoint_location (b
, loc
);
6448 if (loc
!= NULL
&& !header_of_multiple
)
6450 struct inferior
*inf
;
6451 VEC(int) *inf_num
= NULL
;
6456 if (inf
->pspace
== loc
->pspace
)
6457 VEC_safe_push (int, inf_num
, inf
->num
);
6460 /* For backward compatibility, don't display inferiors in CLI unless
6461 there are several. Always display for MI. */
6463 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6464 && (number_of_program_spaces () > 1
6465 || number_of_inferiors () > 1)
6466 /* LOC is for existing B, it cannot be in
6467 moribund_locations and thus having NULL OWNER. */
6468 && loc
->owner
->type
!= bp_catchpoint
))
6470 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6471 VEC_free (int, inf_num
);
6474 if (!part_of_multiple
)
6476 if (b
->thread
!= -1)
6478 /* FIXME: This seems to be redundant and lost here; see the
6479 "stop only in" line a little further down. */
6480 uiout
->text (" thread ");
6481 uiout
->field_int ("thread", b
->thread
);
6483 else if (b
->task
!= 0)
6485 uiout
->text (" task ");
6486 uiout
->field_int ("task", b
->task
);
6492 if (!part_of_multiple
)
6493 b
->ops
->print_one_detail (b
, uiout
);
6495 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6498 uiout
->text ("\tstop only in stack frame at ");
6499 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6501 uiout
->field_core_addr ("frame",
6502 b
->gdbarch
, b
->frame_id
.stack_addr
);
6506 if (!part_of_multiple
&& b
->cond_string
)
6509 if (is_tracepoint (b
))
6510 uiout
->text ("\ttrace only if ");
6512 uiout
->text ("\tstop only if ");
6513 uiout
->field_string ("cond", b
->cond_string
);
6515 /* Print whether the target is doing the breakpoint's condition
6516 evaluation. If GDB is doing the evaluation, don't print anything. */
6517 if (is_breakpoint (b
)
6518 && breakpoint_condition_evaluation_mode ()
6519 == condition_evaluation_target
)
6522 uiout
->field_string ("evaluated-by",
6523 bp_condition_evaluator (b
));
6524 uiout
->text (" evals)");
6529 if (!part_of_multiple
&& b
->thread
!= -1)
6531 /* FIXME should make an annotation for this. */
6532 uiout
->text ("\tstop only in thread ");
6533 if (uiout
->is_mi_like_p ())
6534 uiout
->field_int ("thread", b
->thread
);
6537 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6539 uiout
->field_string ("thread", print_thread_id (thr
));
6544 if (!part_of_multiple
)
6548 /* FIXME should make an annotation for this. */
6549 if (is_catchpoint (b
))
6550 uiout
->text ("\tcatchpoint");
6551 else if (is_tracepoint (b
))
6552 uiout
->text ("\ttracepoint");
6554 uiout
->text ("\tbreakpoint");
6555 uiout
->text (" already hit ");
6556 uiout
->field_int ("times", b
->hit_count
);
6557 if (b
->hit_count
== 1)
6558 uiout
->text (" time\n");
6560 uiout
->text (" times\n");
6564 /* Output the count also if it is zero, but only if this is mi. */
6565 if (uiout
->is_mi_like_p ())
6566 uiout
->field_int ("times", b
->hit_count
);
6570 if (!part_of_multiple
&& b
->ignore_count
)
6573 uiout
->text ("\tignore next ");
6574 uiout
->field_int ("ignore", b
->ignore_count
);
6575 uiout
->text (" hits\n");
6578 /* Note that an enable count of 1 corresponds to "enable once"
6579 behavior, which is reported by the combination of enablement and
6580 disposition, so we don't need to mention it here. */
6581 if (!part_of_multiple
&& b
->enable_count
> 1)
6584 uiout
->text ("\tdisable after ");
6585 /* Tweak the wording to clarify that ignore and enable counts
6586 are distinct, and have additive effect. */
6587 if (b
->ignore_count
)
6588 uiout
->text ("additional ");
6590 uiout
->text ("next ");
6591 uiout
->field_int ("enable", b
->enable_count
);
6592 uiout
->text (" hits\n");
6595 if (!part_of_multiple
&& is_tracepoint (b
))
6597 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6599 if (tp
->traceframe_usage
)
6601 uiout
->text ("\ttrace buffer usage ");
6602 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6603 uiout
->text (" bytes\n");
6607 l
= b
->commands
? b
->commands
->commands
: NULL
;
6608 if (!part_of_multiple
&& l
)
6611 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6612 print_command_lines (uiout
, l
, 4);
6615 if (is_tracepoint (b
))
6617 struct tracepoint
*t
= (struct tracepoint
*) b
;
6619 if (!part_of_multiple
&& t
->pass_count
)
6621 annotate_field (10);
6622 uiout
->text ("\tpass count ");
6623 uiout
->field_int ("pass", t
->pass_count
);
6624 uiout
->text (" \n");
6627 /* Don't display it when tracepoint or tracepoint location is
6629 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6631 annotate_field (11);
6633 if (uiout
->is_mi_like_p ())
6634 uiout
->field_string ("installed",
6635 loc
->inserted
? "y" : "n");
6641 uiout
->text ("\tnot ");
6642 uiout
->text ("installed on target\n");
6647 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6649 if (is_watchpoint (b
))
6651 struct watchpoint
*w
= (struct watchpoint
*) b
;
6653 uiout
->field_string ("original-location", w
->exp_string
);
6655 else if (b
->location
!= NULL
6656 && event_location_to_string (b
->location
.get ()) != NULL
)
6657 uiout
->field_string ("original-location",
6658 event_location_to_string (b
->location
.get ()));
6663 print_one_breakpoint (struct breakpoint
*b
,
6664 struct bp_location
**last_loc
,
6667 struct ui_out
*uiout
= current_uiout
;
6670 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6672 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6675 /* If this breakpoint has custom print function,
6676 it's already printed. Otherwise, print individual
6677 locations, if any. */
6678 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6680 /* If breakpoint has a single location that is disabled, we
6681 print it as if it had several locations, since otherwise it's
6682 hard to represent "breakpoint enabled, location disabled"
6685 Note that while hardware watchpoints have several locations
6686 internally, that's not a property exposed to user. */
6688 && !is_hardware_watchpoint (b
)
6689 && (b
->loc
->next
|| !b
->loc
->enabled
))
6691 struct bp_location
*loc
;
6694 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6696 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6697 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6704 breakpoint_address_bits (struct breakpoint
*b
)
6706 int print_address_bits
= 0;
6707 struct bp_location
*loc
;
6709 /* Software watchpoints that aren't watching memory don't have an
6710 address to print. */
6711 if (is_no_memory_software_watchpoint (b
))
6714 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6718 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6719 if (addr_bit
> print_address_bits
)
6720 print_address_bits
= addr_bit
;
6723 return print_address_bits
;
6726 struct captured_breakpoint_query_args
6732 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6734 struct captured_breakpoint_query_args
*args
6735 = (struct captured_breakpoint_query_args
*) data
;
6736 struct breakpoint
*b
;
6737 struct bp_location
*dummy_loc
= NULL
;
6741 if (args
->bnum
== b
->number
)
6743 print_one_breakpoint (b
, &dummy_loc
, 0);
6751 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6752 char **error_message
)
6754 struct captured_breakpoint_query_args args
;
6757 /* For the moment we don't trust print_one_breakpoint() to not throw
6759 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6760 error_message
, RETURN_MASK_ALL
) < 0)
6766 /* Return true if this breakpoint was set by the user, false if it is
6767 internal or momentary. */
6770 user_breakpoint_p (struct breakpoint
*b
)
6772 return b
->number
> 0;
6775 /* See breakpoint.h. */
6778 pending_breakpoint_p (struct breakpoint
*b
)
6780 return b
->loc
== NULL
;
6783 /* Print information on user settable breakpoint (watchpoint, etc)
6784 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6785 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6786 FILTER is non-NULL, call it on each breakpoint and only include the
6787 ones for which it returns non-zero. Return the total number of
6788 breakpoints listed. */
6791 breakpoint_1 (char *args
, int allflag
,
6792 int (*filter
) (const struct breakpoint
*))
6794 struct breakpoint
*b
;
6795 struct bp_location
*last_loc
= NULL
;
6796 int nr_printable_breakpoints
;
6797 struct cleanup
*bkpttbl_chain
;
6798 struct value_print_options opts
;
6799 int print_address_bits
= 0;
6800 int print_type_col_width
= 14;
6801 struct ui_out
*uiout
= current_uiout
;
6803 get_user_print_options (&opts
);
6805 /* Compute the number of rows in the table, as well as the size
6806 required for address fields. */
6807 nr_printable_breakpoints
= 0;
6810 /* If we have a filter, only list the breakpoints it accepts. */
6811 if (filter
&& !filter (b
))
6814 /* If we have an "args" string, it is a list of breakpoints to
6815 accept. Skip the others. */
6816 if (args
!= NULL
&& *args
!= '\0')
6818 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6820 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6824 if (allflag
|| user_breakpoint_p (b
))
6826 int addr_bit
, type_len
;
6828 addr_bit
= breakpoint_address_bits (b
);
6829 if (addr_bit
> print_address_bits
)
6830 print_address_bits
= addr_bit
;
6832 type_len
= strlen (bptype_string (b
->type
));
6833 if (type_len
> print_type_col_width
)
6834 print_type_col_width
= type_len
;
6836 nr_printable_breakpoints
++;
6840 if (opts
.addressprint
)
6842 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6843 nr_printable_breakpoints
,
6847 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6848 nr_printable_breakpoints
,
6851 if (nr_printable_breakpoints
> 0)
6852 annotate_breakpoints_headers ();
6853 if (nr_printable_breakpoints
> 0)
6855 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6856 if (nr_printable_breakpoints
> 0)
6858 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6859 if (nr_printable_breakpoints
> 0)
6861 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6862 if (nr_printable_breakpoints
> 0)
6864 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6865 if (opts
.addressprint
)
6867 if (nr_printable_breakpoints
> 0)
6869 if (print_address_bits
<= 32)
6870 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6872 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6874 if (nr_printable_breakpoints
> 0)
6876 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6877 uiout
->table_body ();
6878 if (nr_printable_breakpoints
> 0)
6879 annotate_breakpoints_table ();
6884 /* If we have a filter, only list the breakpoints it accepts. */
6885 if (filter
&& !filter (b
))
6888 /* If we have an "args" string, it is a list of breakpoints to
6889 accept. Skip the others. */
6891 if (args
!= NULL
&& *args
!= '\0')
6893 if (allflag
) /* maintenance info breakpoint */
6895 if (parse_and_eval_long (args
) != b
->number
)
6898 else /* all others */
6900 if (!number_is_in_list (args
, b
->number
))
6904 /* We only print out user settable breakpoints unless the
6906 if (allflag
|| user_breakpoint_p (b
))
6907 print_one_breakpoint (b
, &last_loc
, allflag
);
6910 do_cleanups (bkpttbl_chain
);
6912 if (nr_printable_breakpoints
== 0)
6914 /* If there's a filter, let the caller decide how to report
6918 if (args
== NULL
|| *args
== '\0')
6919 uiout
->message ("No breakpoints or watchpoints.\n");
6921 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6927 if (last_loc
&& !server_command
)
6928 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6931 /* FIXME? Should this be moved up so that it is only called when
6932 there have been breakpoints? */
6933 annotate_breakpoints_table_end ();
6935 return nr_printable_breakpoints
;
6938 /* Display the value of default-collect in a way that is generally
6939 compatible with the breakpoint list. */
6942 default_collect_info (void)
6944 struct ui_out
*uiout
= current_uiout
;
6946 /* If it has no value (which is frequently the case), say nothing; a
6947 message like "No default-collect." gets in user's face when it's
6949 if (!*default_collect
)
6952 /* The following phrase lines up nicely with per-tracepoint collect
6954 uiout
->text ("default collect ");
6955 uiout
->field_string ("default-collect", default_collect
);
6956 uiout
->text (" \n");
6960 breakpoints_info (char *args
, int from_tty
)
6962 breakpoint_1 (args
, 0, NULL
);
6964 default_collect_info ();
6968 watchpoints_info (char *args
, int from_tty
)
6970 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6971 struct ui_out
*uiout
= current_uiout
;
6973 if (num_printed
== 0)
6975 if (args
== NULL
|| *args
== '\0')
6976 uiout
->message ("No watchpoints.\n");
6978 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6983 maintenance_info_breakpoints (char *args
, int from_tty
)
6985 breakpoint_1 (args
, 1, NULL
);
6987 default_collect_info ();
6991 breakpoint_has_pc (struct breakpoint
*b
,
6992 struct program_space
*pspace
,
6993 CORE_ADDR pc
, struct obj_section
*section
)
6995 struct bp_location
*bl
= b
->loc
;
6997 for (; bl
; bl
= bl
->next
)
6999 if (bl
->pspace
== pspace
7000 && bl
->address
== pc
7001 && (!overlay_debugging
|| bl
->section
== section
))
7007 /* Print a message describing any user-breakpoints set at PC. This
7008 concerns with logical breakpoints, so we match program spaces, not
7012 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7013 struct program_space
*pspace
, CORE_ADDR pc
,
7014 struct obj_section
*section
, int thread
)
7017 struct breakpoint
*b
;
7020 others
+= (user_breakpoint_p (b
)
7021 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7025 printf_filtered (_("Note: breakpoint "));
7026 else /* if (others == ???) */
7027 printf_filtered (_("Note: breakpoints "));
7029 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7032 printf_filtered ("%d", b
->number
);
7033 if (b
->thread
== -1 && thread
!= -1)
7034 printf_filtered (" (all threads)");
7035 else if (b
->thread
!= -1)
7036 printf_filtered (" (thread %d)", b
->thread
);
7037 printf_filtered ("%s%s ",
7038 ((b
->enable_state
== bp_disabled
7039 || b
->enable_state
== bp_call_disabled
)
7043 : ((others
== 1) ? " and" : ""));
7045 printf_filtered (_("also set at pc "));
7046 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7047 printf_filtered (".\n");
7052 /* Return true iff it is meaningful to use the address member of
7053 BPT locations. For some breakpoint types, the locations' address members
7054 are irrelevant and it makes no sense to attempt to compare them to other
7055 addresses (or use them for any other purpose either).
7057 More specifically, each of the following breakpoint types will
7058 always have a zero valued location address and we don't want to mark
7059 breakpoints of any of these types to be a duplicate of an actual
7060 breakpoint location at address zero:
7068 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7070 enum bptype type
= bpt
->type
;
7072 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7075 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7076 true if LOC1 and LOC2 represent the same watchpoint location. */
7079 watchpoint_locations_match (struct bp_location
*loc1
,
7080 struct bp_location
*loc2
)
7082 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7083 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7085 /* Both of them must exist. */
7086 gdb_assert (w1
!= NULL
);
7087 gdb_assert (w2
!= NULL
);
7089 /* If the target can evaluate the condition expression in hardware,
7090 then we we need to insert both watchpoints even if they are at
7091 the same place. Otherwise the watchpoint will only trigger when
7092 the condition of whichever watchpoint was inserted evaluates to
7093 true, not giving a chance for GDB to check the condition of the
7094 other watchpoint. */
7096 && target_can_accel_watchpoint_condition (loc1
->address
,
7098 loc1
->watchpoint_type
,
7099 w1
->cond_exp
.get ()))
7101 && target_can_accel_watchpoint_condition (loc2
->address
,
7103 loc2
->watchpoint_type
,
7104 w2
->cond_exp
.get ())))
7107 /* Note that this checks the owner's type, not the location's. In
7108 case the target does not support read watchpoints, but does
7109 support access watchpoints, we'll have bp_read_watchpoint
7110 watchpoints with hw_access locations. Those should be considered
7111 duplicates of hw_read locations. The hw_read locations will
7112 become hw_access locations later. */
7113 return (loc1
->owner
->type
== loc2
->owner
->type
7114 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7115 && loc1
->address
== loc2
->address
7116 && loc1
->length
== loc2
->length
);
7119 /* See breakpoint.h. */
7122 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7123 struct address_space
*aspace2
, CORE_ADDR addr2
)
7125 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7126 || aspace1
== aspace2
)
7130 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7131 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7132 matches ASPACE2. On targets that have global breakpoints, the address
7133 space doesn't really matter. */
7136 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7137 int len1
, struct address_space
*aspace2
,
7140 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7141 || aspace1
== aspace2
)
7142 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7145 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7146 a ranged breakpoint. In most targets, a match happens only if ASPACE
7147 matches the breakpoint's address space. On targets that have global
7148 breakpoints, the address space doesn't really matter. */
7151 breakpoint_location_address_match (struct bp_location
*bl
,
7152 struct address_space
*aspace
,
7155 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7158 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7159 bl
->address
, bl
->length
,
7163 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7164 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7165 match happens only if ASPACE matches the breakpoint's address
7166 space. On targets that have global breakpoints, the address space
7167 doesn't really matter. */
7170 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7171 struct address_space
*aspace
,
7172 CORE_ADDR addr
, int len
)
7174 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7175 || bl
->pspace
->aspace
== aspace
)
7177 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7179 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7185 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7186 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7187 true, otherwise returns false. */
7190 tracepoint_locations_match (struct bp_location
*loc1
,
7191 struct bp_location
*loc2
)
7193 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7194 /* Since tracepoint locations are never duplicated with others', tracepoint
7195 locations at the same address of different tracepoints are regarded as
7196 different locations. */
7197 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7202 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7203 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7204 represent the same location. */
7207 breakpoint_locations_match (struct bp_location
*loc1
,
7208 struct bp_location
*loc2
)
7210 int hw_point1
, hw_point2
;
7212 /* Both of them must not be in moribund_locations. */
7213 gdb_assert (loc1
->owner
!= NULL
);
7214 gdb_assert (loc2
->owner
!= NULL
);
7216 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7217 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7219 if (hw_point1
!= hw_point2
)
7222 return watchpoint_locations_match (loc1
, loc2
);
7223 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7224 return tracepoint_locations_match (loc1
, loc2
);
7226 /* We compare bp_location.length in order to cover ranged breakpoints. */
7227 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7228 loc2
->pspace
->aspace
, loc2
->address
)
7229 && loc1
->length
== loc2
->length
);
7233 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7234 int bnum
, int have_bnum
)
7236 /* The longest string possibly returned by hex_string_custom
7237 is 50 chars. These must be at least that big for safety. */
7241 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7242 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7244 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7245 bnum
, astr1
, astr2
);
7247 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7250 /* Adjust a breakpoint's address to account for architectural
7251 constraints on breakpoint placement. Return the adjusted address.
7252 Note: Very few targets require this kind of adjustment. For most
7253 targets, this function is simply the identity function. */
7256 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7257 CORE_ADDR bpaddr
, enum bptype bptype
)
7259 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7261 /* Very few targets need any kind of breakpoint adjustment. */
7264 else if (bptype
== bp_watchpoint
7265 || bptype
== bp_hardware_watchpoint
7266 || bptype
== bp_read_watchpoint
7267 || bptype
== bp_access_watchpoint
7268 || bptype
== bp_catchpoint
)
7270 /* Watchpoints and the various bp_catch_* eventpoints should not
7271 have their addresses modified. */
7274 else if (bptype
== bp_single_step
)
7276 /* Single-step breakpoints should not have their addresses
7277 modified. If there's any architectural constrain that
7278 applies to this address, then it should have already been
7279 taken into account when the breakpoint was created in the
7280 first place. If we didn't do this, stepping through e.g.,
7281 Thumb-2 IT blocks would break. */
7286 CORE_ADDR adjusted_bpaddr
;
7288 /* Some targets have architectural constraints on the placement
7289 of breakpoint instructions. Obtain the adjusted address. */
7290 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7292 /* An adjusted breakpoint address can significantly alter
7293 a user's expectations. Print a warning if an adjustment
7295 if (adjusted_bpaddr
!= bpaddr
)
7296 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7298 return adjusted_bpaddr
;
7302 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7304 bp_location
*loc
= this;
7306 gdb_assert (ops
!= NULL
);
7310 loc
->cond_bytecode
= NULL
;
7311 loc
->shlib_disabled
= 0;
7314 switch (owner
->type
)
7317 case bp_single_step
:
7321 case bp_longjmp_resume
:
7322 case bp_longjmp_call_dummy
:
7324 case bp_exception_resume
:
7325 case bp_step_resume
:
7326 case bp_hp_step_resume
:
7327 case bp_watchpoint_scope
:
7329 case bp_std_terminate
:
7330 case bp_shlib_event
:
7331 case bp_thread_event
:
7332 case bp_overlay_event
:
7334 case bp_longjmp_master
:
7335 case bp_std_terminate_master
:
7336 case bp_exception_master
:
7337 case bp_gnu_ifunc_resolver
:
7338 case bp_gnu_ifunc_resolver_return
:
7340 loc
->loc_type
= bp_loc_software_breakpoint
;
7341 mark_breakpoint_location_modified (loc
);
7343 case bp_hardware_breakpoint
:
7344 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7345 mark_breakpoint_location_modified (loc
);
7347 case bp_hardware_watchpoint
:
7348 case bp_read_watchpoint
:
7349 case bp_access_watchpoint
:
7350 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7355 case bp_fast_tracepoint
:
7356 case bp_static_tracepoint
:
7357 loc
->loc_type
= bp_loc_other
;
7360 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7366 /* Allocate a struct bp_location. */
7368 static struct bp_location
*
7369 allocate_bp_location (struct breakpoint
*bpt
)
7371 return bpt
->ops
->allocate_location (bpt
);
7375 free_bp_location (struct bp_location
*loc
)
7377 loc
->ops
->dtor (loc
);
7381 /* Increment reference count. */
7384 incref_bp_location (struct bp_location
*bl
)
7389 /* Decrement reference count. If the reference count reaches 0,
7390 destroy the bp_location. Sets *BLP to NULL. */
7393 decref_bp_location (struct bp_location
**blp
)
7395 gdb_assert ((*blp
)->refc
> 0);
7397 if (--(*blp
)->refc
== 0)
7398 free_bp_location (*blp
);
7402 /* Add breakpoint B at the end of the global breakpoint chain. */
7405 add_to_breakpoint_chain (struct breakpoint
*b
)
7407 struct breakpoint
*b1
;
7409 /* Add this breakpoint to the end of the chain so that a list of
7410 breakpoints will come out in order of increasing numbers. */
7412 b1
= breakpoint_chain
;
7414 breakpoint_chain
= b
;
7423 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7426 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7427 struct gdbarch
*gdbarch
,
7429 const struct breakpoint_ops
*ops
)
7431 memset (b
, 0, sizeof (*b
));
7433 gdb_assert (ops
!= NULL
);
7437 b
->gdbarch
= gdbarch
;
7438 b
->language
= current_language
->la_language
;
7439 b
->input_radix
= input_radix
;
7441 b
->enable_state
= bp_enabled
;
7444 b
->ignore_count
= 0;
7446 b
->frame_id
= null_frame_id
;
7447 b
->condition_not_parsed
= 0;
7448 b
->py_bp_object
= NULL
;
7449 b
->related_breakpoint
= b
;
7453 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7454 that has type BPTYPE and has no locations as yet. */
7456 static struct breakpoint
*
7457 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7459 const struct breakpoint_ops
*ops
)
7461 struct breakpoint
*b
= new breakpoint ();
7463 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7464 add_to_breakpoint_chain (b
);
7468 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7469 resolutions should be made as the user specified the location explicitly
7473 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7475 gdb_assert (loc
->owner
!= NULL
);
7477 if (loc
->owner
->type
== bp_breakpoint
7478 || loc
->owner
->type
== bp_hardware_breakpoint
7479 || is_tracepoint (loc
->owner
))
7482 const char *function_name
;
7483 CORE_ADDR func_addr
;
7485 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7486 &func_addr
, NULL
, &is_gnu_ifunc
);
7488 if (is_gnu_ifunc
&& !explicit_loc
)
7490 struct breakpoint
*b
= loc
->owner
;
7492 gdb_assert (loc
->pspace
== current_program_space
);
7493 if (gnu_ifunc_resolve_name (function_name
,
7494 &loc
->requested_address
))
7496 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7497 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7498 loc
->requested_address
,
7501 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7502 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7504 /* Create only the whole new breakpoint of this type but do not
7505 mess more complicated breakpoints with multiple locations. */
7506 b
->type
= bp_gnu_ifunc_resolver
;
7507 /* Remember the resolver's address for use by the return
7509 loc
->related_address
= func_addr
;
7514 loc
->function_name
= xstrdup (function_name
);
7518 /* Attempt to determine architecture of location identified by SAL. */
7520 get_sal_arch (struct symtab_and_line sal
)
7523 return get_objfile_arch (sal
.section
->objfile
);
7525 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7530 /* Low level routine for partially initializing a breakpoint of type
7531 BPTYPE. The newly created breakpoint's address, section, source
7532 file name, and line number are provided by SAL.
7534 It is expected that the caller will complete the initialization of
7535 the newly created breakpoint struct as well as output any status
7536 information regarding the creation of a new breakpoint. */
7539 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7540 struct symtab_and_line sal
, enum bptype bptype
,
7541 const struct breakpoint_ops
*ops
)
7543 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7545 add_location_to_breakpoint (b
, &sal
);
7547 if (bptype
!= bp_catchpoint
)
7548 gdb_assert (sal
.pspace
!= NULL
);
7550 /* Store the program space that was used to set the breakpoint,
7551 except for ordinary breakpoints, which are independent of the
7553 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7554 b
->pspace
= sal
.pspace
;
7557 /* set_raw_breakpoint is a low level routine for allocating and
7558 partially initializing a breakpoint of type BPTYPE. The newly
7559 created breakpoint's address, section, source file name, and line
7560 number are provided by SAL. The newly created and partially
7561 initialized breakpoint is added to the breakpoint chain and
7562 is also returned as the value of this function.
7564 It is expected that the caller will complete the initialization of
7565 the newly created breakpoint struct as well as output any status
7566 information regarding the creation of a new breakpoint. In
7567 particular, set_raw_breakpoint does NOT set the breakpoint
7568 number! Care should be taken to not allow an error to occur
7569 prior to completing the initialization of the breakpoint. If this
7570 should happen, a bogus breakpoint will be left on the chain. */
7573 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7574 struct symtab_and_line sal
, enum bptype bptype
,
7575 const struct breakpoint_ops
*ops
)
7577 struct breakpoint
*b
= new breakpoint ();
7579 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7580 add_to_breakpoint_chain (b
);
7584 /* Call this routine when stepping and nexting to enable a breakpoint
7585 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7586 initiated the operation. */
7589 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7591 struct breakpoint
*b
, *b_tmp
;
7592 int thread
= tp
->global_num
;
7594 /* To avoid having to rescan all objfile symbols at every step,
7595 we maintain a list of continually-inserted but always disabled
7596 longjmp "master" breakpoints. Here, we simply create momentary
7597 clones of those and enable them for the requested thread. */
7598 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7599 if (b
->pspace
== current_program_space
7600 && (b
->type
== bp_longjmp_master
7601 || b
->type
== bp_exception_master
))
7603 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7604 struct breakpoint
*clone
;
7606 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7607 after their removal. */
7608 clone
= momentary_breakpoint_from_master (b
, type
,
7609 &longjmp_breakpoint_ops
, 1);
7610 clone
->thread
= thread
;
7613 tp
->initiating_frame
= frame
;
7616 /* Delete all longjmp breakpoints from THREAD. */
7618 delete_longjmp_breakpoint (int thread
)
7620 struct breakpoint
*b
, *b_tmp
;
7622 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7623 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7625 if (b
->thread
== thread
)
7626 delete_breakpoint (b
);
7631 delete_longjmp_breakpoint_at_next_stop (int thread
)
7633 struct breakpoint
*b
, *b_tmp
;
7635 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7636 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7638 if (b
->thread
== thread
)
7639 b
->disposition
= disp_del_at_next_stop
;
7643 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7644 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7645 pointer to any of them. Return NULL if this system cannot place longjmp
7649 set_longjmp_breakpoint_for_call_dummy (void)
7651 struct breakpoint
*b
, *retval
= NULL
;
7654 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7656 struct breakpoint
*new_b
;
7658 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7659 &momentary_breakpoint_ops
,
7661 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7663 /* Link NEW_B into the chain of RETVAL breakpoints. */
7665 gdb_assert (new_b
->related_breakpoint
== new_b
);
7668 new_b
->related_breakpoint
= retval
;
7669 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7670 retval
= retval
->related_breakpoint
;
7671 retval
->related_breakpoint
= new_b
;
7677 /* Verify all existing dummy frames and their associated breakpoints for
7678 TP. Remove those which can no longer be found in the current frame
7681 You should call this function only at places where it is safe to currently
7682 unwind the whole stack. Failed stack unwind would discard live dummy
7686 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7688 struct breakpoint
*b
, *b_tmp
;
7690 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7691 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7693 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7695 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7696 dummy_b
= dummy_b
->related_breakpoint
;
7697 if (dummy_b
->type
!= bp_call_dummy
7698 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7701 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7703 while (b
->related_breakpoint
!= b
)
7705 if (b_tmp
== b
->related_breakpoint
)
7706 b_tmp
= b
->related_breakpoint
->next
;
7707 delete_breakpoint (b
->related_breakpoint
);
7709 delete_breakpoint (b
);
7714 enable_overlay_breakpoints (void)
7716 struct breakpoint
*b
;
7719 if (b
->type
== bp_overlay_event
)
7721 b
->enable_state
= bp_enabled
;
7722 update_global_location_list (UGLL_MAY_INSERT
);
7723 overlay_events_enabled
= 1;
7728 disable_overlay_breakpoints (void)
7730 struct breakpoint
*b
;
7733 if (b
->type
== bp_overlay_event
)
7735 b
->enable_state
= bp_disabled
;
7736 update_global_location_list (UGLL_DONT_INSERT
);
7737 overlay_events_enabled
= 0;
7741 /* Set an active std::terminate breakpoint for each std::terminate
7742 master breakpoint. */
7744 set_std_terminate_breakpoint (void)
7746 struct breakpoint
*b
, *b_tmp
;
7748 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7749 if (b
->pspace
== current_program_space
7750 && b
->type
== bp_std_terminate_master
)
7752 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7753 &momentary_breakpoint_ops
, 1);
7757 /* Delete all the std::terminate breakpoints. */
7759 delete_std_terminate_breakpoint (void)
7761 struct breakpoint
*b
, *b_tmp
;
7763 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7764 if (b
->type
== bp_std_terminate
)
7765 delete_breakpoint (b
);
7769 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7771 struct breakpoint
*b
;
7773 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7774 &internal_breakpoint_ops
);
7776 b
->enable_state
= bp_enabled
;
7777 /* location has to be used or breakpoint_re_set will delete me. */
7778 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7780 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7785 struct lang_and_radix
7791 /* Create a breakpoint for JIT code registration and unregistration. */
7794 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7796 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7797 &internal_breakpoint_ops
);
7800 /* Remove JIT code registration and unregistration breakpoint(s). */
7803 remove_jit_event_breakpoints (void)
7805 struct breakpoint
*b
, *b_tmp
;
7807 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7808 if (b
->type
== bp_jit_event
7809 && b
->loc
->pspace
== current_program_space
)
7810 delete_breakpoint (b
);
7814 remove_solib_event_breakpoints (void)
7816 struct breakpoint
*b
, *b_tmp
;
7818 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7819 if (b
->type
== bp_shlib_event
7820 && b
->loc
->pspace
== current_program_space
)
7821 delete_breakpoint (b
);
7824 /* See breakpoint.h. */
7827 remove_solib_event_breakpoints_at_next_stop (void)
7829 struct breakpoint
*b
, *b_tmp
;
7831 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7832 if (b
->type
== bp_shlib_event
7833 && b
->loc
->pspace
== current_program_space
)
7834 b
->disposition
= disp_del_at_next_stop
;
7837 /* Helper for create_solib_event_breakpoint /
7838 create_and_insert_solib_event_breakpoint. Allows specifying which
7839 INSERT_MODE to pass through to update_global_location_list. */
7841 static struct breakpoint
*
7842 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7843 enum ugll_insert_mode insert_mode
)
7845 struct breakpoint
*b
;
7847 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7848 &internal_breakpoint_ops
);
7849 update_global_location_list_nothrow (insert_mode
);
7854 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7856 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7859 /* See breakpoint.h. */
7862 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7864 struct breakpoint
*b
;
7866 /* Explicitly tell update_global_location_list to insert
7868 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7869 if (!b
->loc
->inserted
)
7871 delete_breakpoint (b
);
7877 /* Disable any breakpoints that are on code in shared libraries. Only
7878 apply to enabled breakpoints, disabled ones can just stay disabled. */
7881 disable_breakpoints_in_shlibs (void)
7883 struct bp_location
*loc
, **locp_tmp
;
7885 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7887 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7888 struct breakpoint
*b
= loc
->owner
;
7890 /* We apply the check to all breakpoints, including disabled for
7891 those with loc->duplicate set. This is so that when breakpoint
7892 becomes enabled, or the duplicate is removed, gdb will try to
7893 insert all breakpoints. If we don't set shlib_disabled here,
7894 we'll try to insert those breakpoints and fail. */
7895 if (((b
->type
== bp_breakpoint
)
7896 || (b
->type
== bp_jit_event
)
7897 || (b
->type
== bp_hardware_breakpoint
)
7898 || (is_tracepoint (b
)))
7899 && loc
->pspace
== current_program_space
7900 && !loc
->shlib_disabled
7901 && solib_name_from_address (loc
->pspace
, loc
->address
)
7904 loc
->shlib_disabled
= 1;
7909 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7910 notification of unloaded_shlib. Only apply to enabled breakpoints,
7911 disabled ones can just stay disabled. */
7914 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7916 struct bp_location
*loc
, **locp_tmp
;
7917 int disabled_shlib_breaks
= 0;
7919 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7921 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7922 struct breakpoint
*b
= loc
->owner
;
7924 if (solib
->pspace
== loc
->pspace
7925 && !loc
->shlib_disabled
7926 && (((b
->type
== bp_breakpoint
7927 || b
->type
== bp_jit_event
7928 || b
->type
== bp_hardware_breakpoint
)
7929 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7930 || loc
->loc_type
== bp_loc_software_breakpoint
))
7931 || is_tracepoint (b
))
7932 && solib_contains_address_p (solib
, loc
->address
))
7934 loc
->shlib_disabled
= 1;
7935 /* At this point, we cannot rely on remove_breakpoint
7936 succeeding so we must mark the breakpoint as not inserted
7937 to prevent future errors occurring in remove_breakpoints. */
7940 /* This may cause duplicate notifications for the same breakpoint. */
7941 observer_notify_breakpoint_modified (b
);
7943 if (!disabled_shlib_breaks
)
7945 target_terminal_ours_for_output ();
7946 warning (_("Temporarily disabling breakpoints "
7947 "for unloaded shared library \"%s\""),
7950 disabled_shlib_breaks
= 1;
7955 /* Disable any breakpoints and tracepoints in OBJFILE upon
7956 notification of free_objfile. Only apply to enabled breakpoints,
7957 disabled ones can just stay disabled. */
7960 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7962 struct breakpoint
*b
;
7964 if (objfile
== NULL
)
7967 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7968 managed by the user with add-symbol-file/remove-symbol-file.
7969 Similarly to how breakpoints in shared libraries are handled in
7970 response to "nosharedlibrary", mark breakpoints in such modules
7971 shlib_disabled so they end up uninserted on the next global
7972 location list update. Shared libraries not loaded by the user
7973 aren't handled here -- they're already handled in
7974 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7975 solib_unloaded observer. We skip objfiles that are not
7976 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7978 if ((objfile
->flags
& OBJF_SHARED
) == 0
7979 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7984 struct bp_location
*loc
;
7985 int bp_modified
= 0;
7987 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7990 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7992 CORE_ADDR loc_addr
= loc
->address
;
7994 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7995 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7998 if (loc
->shlib_disabled
!= 0)
8001 if (objfile
->pspace
!= loc
->pspace
)
8004 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8005 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8008 if (is_addr_in_objfile (loc_addr
, objfile
))
8010 loc
->shlib_disabled
= 1;
8011 /* At this point, we don't know whether the object was
8012 unmapped from the inferior or not, so leave the
8013 inserted flag alone. We'll handle failure to
8014 uninsert quietly, in case the object was indeed
8017 mark_breakpoint_location_modified (loc
);
8024 observer_notify_breakpoint_modified (b
);
8028 /* FORK & VFORK catchpoints. */
8030 /* An instance of this type is used to represent a fork or vfork
8031 catchpoint. It includes a "struct breakpoint" as a kind of base
8032 class; users downcast to "struct breakpoint *" when needed. A
8033 breakpoint is really of this type iff its ops pointer points to
8034 CATCH_FORK_BREAKPOINT_OPS. */
8036 struct fork_catchpoint
8038 /* The base class. */
8039 struct breakpoint base
;
8041 /* Process id of a child process whose forking triggered this
8042 catchpoint. This field is only valid immediately after this
8043 catchpoint has triggered. */
8044 ptid_t forked_inferior_pid
;
8047 /* Implement the "insert" breakpoint_ops method for fork
8051 insert_catch_fork (struct bp_location
*bl
)
8053 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8056 /* Implement the "remove" breakpoint_ops method for fork
8060 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8062 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8065 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8069 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8070 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8071 const struct target_waitstatus
*ws
)
8073 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8075 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8078 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8082 /* Implement the "print_it" breakpoint_ops method for fork
8085 static enum print_stop_action
8086 print_it_catch_fork (bpstat bs
)
8088 struct ui_out
*uiout
= current_uiout
;
8089 struct breakpoint
*b
= bs
->breakpoint_at
;
8090 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8092 annotate_catchpoint (b
->number
);
8093 maybe_print_thread_hit_breakpoint (uiout
);
8094 if (b
->disposition
== disp_del
)
8095 uiout
->text ("Temporary catchpoint ");
8097 uiout
->text ("Catchpoint ");
8098 if (uiout
->is_mi_like_p ())
8100 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8101 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8103 uiout
->field_int ("bkptno", b
->number
);
8104 uiout
->text (" (forked process ");
8105 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8106 uiout
->text ("), ");
8107 return PRINT_SRC_AND_LOC
;
8110 /* Implement the "print_one" breakpoint_ops method for fork
8114 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8116 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8117 struct value_print_options opts
;
8118 struct ui_out
*uiout
= current_uiout
;
8120 get_user_print_options (&opts
);
8122 /* Field 4, the address, is omitted (which makes the columns not
8123 line up too nicely with the headers, but the effect is relatively
8125 if (opts
.addressprint
)
8126 uiout
->field_skip ("addr");
8128 uiout
->text ("fork");
8129 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8131 uiout
->text (", process ");
8132 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8136 if (uiout
->is_mi_like_p ())
8137 uiout
->field_string ("catch-type", "fork");
8140 /* Implement the "print_mention" breakpoint_ops method for fork
8144 print_mention_catch_fork (struct breakpoint
*b
)
8146 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8149 /* Implement the "print_recreate" breakpoint_ops method for fork
8153 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8155 fprintf_unfiltered (fp
, "catch fork");
8156 print_recreate_thread (b
, fp
);
8159 /* The breakpoint_ops structure to be used in fork catchpoints. */
8161 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8163 /* Implement the "insert" breakpoint_ops method for vfork
8167 insert_catch_vfork (struct bp_location
*bl
)
8169 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8172 /* Implement the "remove" breakpoint_ops method for vfork
8176 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8178 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8181 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8185 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8186 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8187 const struct target_waitstatus
*ws
)
8189 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8191 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8194 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8198 /* Implement the "print_it" breakpoint_ops method for vfork
8201 static enum print_stop_action
8202 print_it_catch_vfork (bpstat bs
)
8204 struct ui_out
*uiout
= current_uiout
;
8205 struct breakpoint
*b
= bs
->breakpoint_at
;
8206 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8208 annotate_catchpoint (b
->number
);
8209 maybe_print_thread_hit_breakpoint (uiout
);
8210 if (b
->disposition
== disp_del
)
8211 uiout
->text ("Temporary catchpoint ");
8213 uiout
->text ("Catchpoint ");
8214 if (uiout
->is_mi_like_p ())
8216 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8217 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8219 uiout
->field_int ("bkptno", b
->number
);
8220 uiout
->text (" (vforked process ");
8221 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8222 uiout
->text ("), ");
8223 return PRINT_SRC_AND_LOC
;
8226 /* Implement the "print_one" breakpoint_ops method for vfork
8230 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8232 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8233 struct value_print_options opts
;
8234 struct ui_out
*uiout
= current_uiout
;
8236 get_user_print_options (&opts
);
8237 /* Field 4, the address, is omitted (which makes the columns not
8238 line up too nicely with the headers, but the effect is relatively
8240 if (opts
.addressprint
)
8241 uiout
->field_skip ("addr");
8243 uiout
->text ("vfork");
8244 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8246 uiout
->text (", process ");
8247 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8251 if (uiout
->is_mi_like_p ())
8252 uiout
->field_string ("catch-type", "vfork");
8255 /* Implement the "print_mention" breakpoint_ops method for vfork
8259 print_mention_catch_vfork (struct breakpoint
*b
)
8261 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8264 /* Implement the "print_recreate" breakpoint_ops method for vfork
8268 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8270 fprintf_unfiltered (fp
, "catch vfork");
8271 print_recreate_thread (b
, fp
);
8274 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8276 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8278 /* An instance of this type is used to represent an solib catchpoint.
8279 It includes a "struct breakpoint" as a kind of base class; users
8280 downcast to "struct breakpoint *" when needed. A breakpoint is
8281 really of this type iff its ops pointer points to
8282 CATCH_SOLIB_BREAKPOINT_OPS. */
8284 struct solib_catchpoint
8286 /* The base class. */
8287 struct breakpoint base
;
8289 /* True for "catch load", false for "catch unload". */
8290 unsigned char is_load
;
8292 /* Regular expression to match, if any. COMPILED is only valid when
8293 REGEX is non-NULL. */
8299 dtor_catch_solib (struct breakpoint
*b
)
8301 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8304 regfree (&self
->compiled
);
8305 xfree (self
->regex
);
8307 base_breakpoint_ops
.dtor (b
);
8311 insert_catch_solib (struct bp_location
*ignore
)
8317 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8323 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8324 struct address_space
*aspace
,
8326 const struct target_waitstatus
*ws
)
8328 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8329 struct breakpoint
*other
;
8331 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8334 ALL_BREAKPOINTS (other
)
8336 struct bp_location
*other_bl
;
8338 if (other
== bl
->owner
)
8341 if (other
->type
!= bp_shlib_event
)
8344 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8347 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8349 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8358 check_status_catch_solib (struct bpstats
*bs
)
8360 struct solib_catchpoint
*self
8361 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8366 struct so_list
*iter
;
8369 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8374 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8383 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8388 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8394 bs
->print_it
= print_it_noop
;
8397 static enum print_stop_action
8398 print_it_catch_solib (bpstat bs
)
8400 struct breakpoint
*b
= bs
->breakpoint_at
;
8401 struct ui_out
*uiout
= current_uiout
;
8403 annotate_catchpoint (b
->number
);
8404 maybe_print_thread_hit_breakpoint (uiout
);
8405 if (b
->disposition
== disp_del
)
8406 uiout
->text ("Temporary catchpoint ");
8408 uiout
->text ("Catchpoint ");
8409 uiout
->field_int ("bkptno", b
->number
);
8411 if (uiout
->is_mi_like_p ())
8412 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8413 print_solib_event (1);
8414 return PRINT_SRC_AND_LOC
;
8418 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8420 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8421 struct value_print_options opts
;
8422 struct ui_out
*uiout
= current_uiout
;
8425 get_user_print_options (&opts
);
8426 /* Field 4, the address, is omitted (which makes the columns not
8427 line up too nicely with the headers, but the effect is relatively
8429 if (opts
.addressprint
)
8432 uiout
->field_skip ("addr");
8439 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8441 msg
= xstrdup (_("load of library"));
8446 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8448 msg
= xstrdup (_("unload of library"));
8450 uiout
->field_string ("what", msg
);
8453 if (uiout
->is_mi_like_p ())
8454 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8458 print_mention_catch_solib (struct breakpoint
*b
)
8460 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8462 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8463 self
->is_load
? "load" : "unload");
8467 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8469 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8471 fprintf_unfiltered (fp
, "%s %s",
8472 b
->disposition
== disp_del
? "tcatch" : "catch",
8473 self
->is_load
? "load" : "unload");
8475 fprintf_unfiltered (fp
, " %s", self
->regex
);
8476 fprintf_unfiltered (fp
, "\n");
8479 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8481 /* Shared helper function (MI and CLI) for creating and installing
8482 a shared object event catchpoint. If IS_LOAD is non-zero then
8483 the events to be caught are load events, otherwise they are
8484 unload events. If IS_TEMP is non-zero the catchpoint is a
8485 temporary one. If ENABLED is non-zero the catchpoint is
8486 created in an enabled state. */
8489 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8491 struct solib_catchpoint
*c
;
8492 struct gdbarch
*gdbarch
= get_current_arch ();
8493 struct cleanup
*cleanup
;
8497 arg
= skip_spaces_const (arg
);
8499 c
= new solib_catchpoint ();
8500 cleanup
= make_cleanup (xfree
, c
);
8506 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8509 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8511 make_cleanup (xfree
, err
);
8512 error (_("Invalid regexp (%s): %s"), err
, arg
);
8514 c
->regex
= xstrdup (arg
);
8517 c
->is_load
= is_load
;
8518 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8519 &catch_solib_breakpoint_ops
);
8521 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8523 discard_cleanups (cleanup
);
8524 install_breakpoint (0, &c
->base
, 1);
8527 /* A helper function that does all the work for "catch load" and
8531 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8532 struct cmd_list_element
*command
)
8535 const int enabled
= 1;
8537 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8539 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8543 catch_load_command_1 (char *arg
, int from_tty
,
8544 struct cmd_list_element
*command
)
8546 catch_load_or_unload (arg
, from_tty
, 1, command
);
8550 catch_unload_command_1 (char *arg
, int from_tty
,
8551 struct cmd_list_element
*command
)
8553 catch_load_or_unload (arg
, from_tty
, 0, command
);
8556 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8557 is non-zero, then make the breakpoint temporary. If COND_STRING is
8558 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8559 the breakpoint_ops structure associated to the catchpoint. */
8562 init_catchpoint (struct breakpoint
*b
,
8563 struct gdbarch
*gdbarch
, int tempflag
,
8564 const char *cond_string
,
8565 const struct breakpoint_ops
*ops
)
8567 struct symtab_and_line sal
;
8570 sal
.pspace
= current_program_space
;
8572 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8574 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8575 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8579 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8581 add_to_breakpoint_chain (b
);
8582 set_breakpoint_number (internal
, b
);
8583 if (is_tracepoint (b
))
8584 set_tracepoint_count (breakpoint_count
);
8587 observer_notify_breakpoint_created (b
);
8590 update_global_location_list (UGLL_MAY_INSERT
);
8594 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8595 int tempflag
, const char *cond_string
,
8596 const struct breakpoint_ops
*ops
)
8598 struct fork_catchpoint
*c
= new fork_catchpoint ();
8600 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8602 c
->forked_inferior_pid
= null_ptid
;
8604 install_breakpoint (0, &c
->base
, 1);
8607 /* Exec catchpoints. */
8609 /* An instance of this type is used to represent an exec catchpoint.
8610 It includes a "struct breakpoint" as a kind of base class; users
8611 downcast to "struct breakpoint *" when needed. A breakpoint is
8612 really of this type iff its ops pointer points to
8613 CATCH_EXEC_BREAKPOINT_OPS. */
8615 struct exec_catchpoint
8617 /* The base class. */
8618 struct breakpoint base
;
8620 /* Filename of a program whose exec triggered this catchpoint.
8621 This field is only valid immediately after this catchpoint has
8623 char *exec_pathname
;
8626 /* Implement the "dtor" breakpoint_ops method for exec
8630 dtor_catch_exec (struct breakpoint
*b
)
8632 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8634 xfree (c
->exec_pathname
);
8636 base_breakpoint_ops
.dtor (b
);
8640 insert_catch_exec (struct bp_location
*bl
)
8642 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8646 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8648 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8652 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8653 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8654 const struct target_waitstatus
*ws
)
8656 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8658 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8661 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8665 static enum print_stop_action
8666 print_it_catch_exec (bpstat bs
)
8668 struct ui_out
*uiout
= current_uiout
;
8669 struct breakpoint
*b
= bs
->breakpoint_at
;
8670 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8672 annotate_catchpoint (b
->number
);
8673 maybe_print_thread_hit_breakpoint (uiout
);
8674 if (b
->disposition
== disp_del
)
8675 uiout
->text ("Temporary catchpoint ");
8677 uiout
->text ("Catchpoint ");
8678 if (uiout
->is_mi_like_p ())
8680 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8681 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8683 uiout
->field_int ("bkptno", b
->number
);
8684 uiout
->text (" (exec'd ");
8685 uiout
->field_string ("new-exec", c
->exec_pathname
);
8686 uiout
->text ("), ");
8688 return PRINT_SRC_AND_LOC
;
8692 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8694 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8695 struct value_print_options opts
;
8696 struct ui_out
*uiout
= current_uiout
;
8698 get_user_print_options (&opts
);
8700 /* Field 4, the address, is omitted (which makes the columns
8701 not line up too nicely with the headers, but the effect
8702 is relatively readable). */
8703 if (opts
.addressprint
)
8704 uiout
->field_skip ("addr");
8706 uiout
->text ("exec");
8707 if (c
->exec_pathname
!= NULL
)
8709 uiout
->text (", program \"");
8710 uiout
->field_string ("what", c
->exec_pathname
);
8711 uiout
->text ("\" ");
8714 if (uiout
->is_mi_like_p ())
8715 uiout
->field_string ("catch-type", "exec");
8719 print_mention_catch_exec (struct breakpoint
*b
)
8721 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8724 /* Implement the "print_recreate" breakpoint_ops method for exec
8728 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8730 fprintf_unfiltered (fp
, "catch exec");
8731 print_recreate_thread (b
, fp
);
8734 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8737 hw_breakpoint_used_count (void)
8740 struct breakpoint
*b
;
8741 struct bp_location
*bl
;
8745 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8746 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8748 /* Special types of hardware breakpoints may use more than
8750 i
+= b
->ops
->resources_needed (bl
);
8757 /* Returns the resources B would use if it were a hardware
8761 hw_watchpoint_use_count (struct breakpoint
*b
)
8764 struct bp_location
*bl
;
8766 if (!breakpoint_enabled (b
))
8769 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8771 /* Special types of hardware watchpoints may use more than
8773 i
+= b
->ops
->resources_needed (bl
);
8779 /* Returns the sum the used resources of all hardware watchpoints of
8780 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8781 the sum of the used resources of all hardware watchpoints of other
8782 types _not_ TYPE. */
8785 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8786 enum bptype type
, int *other_type_used
)
8789 struct breakpoint
*b
;
8791 *other_type_used
= 0;
8796 if (!breakpoint_enabled (b
))
8799 if (b
->type
== type
)
8800 i
+= hw_watchpoint_use_count (b
);
8801 else if (is_hardware_watchpoint (b
))
8802 *other_type_used
= 1;
8809 disable_watchpoints_before_interactive_call_start (void)
8811 struct breakpoint
*b
;
8815 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8817 b
->enable_state
= bp_call_disabled
;
8818 update_global_location_list (UGLL_DONT_INSERT
);
8824 enable_watchpoints_after_interactive_call_stop (void)
8826 struct breakpoint
*b
;
8830 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8832 b
->enable_state
= bp_enabled
;
8833 update_global_location_list (UGLL_MAY_INSERT
);
8839 disable_breakpoints_before_startup (void)
8841 current_program_space
->executing_startup
= 1;
8842 update_global_location_list (UGLL_DONT_INSERT
);
8846 enable_breakpoints_after_startup (void)
8848 current_program_space
->executing_startup
= 0;
8849 breakpoint_re_set ();
8852 /* Create a new single-step breakpoint for thread THREAD, with no
8855 static struct breakpoint
*
8856 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8858 struct breakpoint
*b
= new breakpoint ();
8860 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8861 &momentary_breakpoint_ops
);
8863 b
->disposition
= disp_donttouch
;
8864 b
->frame_id
= null_frame_id
;
8867 gdb_assert (b
->thread
!= 0);
8869 add_to_breakpoint_chain (b
);
8874 /* Set a momentary breakpoint of type TYPE at address specified by
8875 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8879 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8880 struct frame_id frame_id
, enum bptype type
)
8882 struct breakpoint
*b
;
8884 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8886 gdb_assert (!frame_id_artificial_p (frame_id
));
8888 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8889 b
->enable_state
= bp_enabled
;
8890 b
->disposition
= disp_donttouch
;
8891 b
->frame_id
= frame_id
;
8893 /* If we're debugging a multi-threaded program, then we want
8894 momentary breakpoints to be active in only a single thread of
8896 if (in_thread_list (inferior_ptid
))
8897 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8899 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8904 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8905 The new breakpoint will have type TYPE, use OPS as its
8906 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8908 static struct breakpoint
*
8909 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8911 const struct breakpoint_ops
*ops
,
8914 struct breakpoint
*copy
;
8916 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8917 copy
->loc
= allocate_bp_location (copy
);
8918 set_breakpoint_location_function (copy
->loc
, 1);
8920 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8921 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8922 copy
->loc
->address
= orig
->loc
->address
;
8923 copy
->loc
->section
= orig
->loc
->section
;
8924 copy
->loc
->pspace
= orig
->loc
->pspace
;
8925 copy
->loc
->probe
= orig
->loc
->probe
;
8926 copy
->loc
->line_number
= orig
->loc
->line_number
;
8927 copy
->loc
->symtab
= orig
->loc
->symtab
;
8928 copy
->loc
->enabled
= loc_enabled
;
8929 copy
->frame_id
= orig
->frame_id
;
8930 copy
->thread
= orig
->thread
;
8931 copy
->pspace
= orig
->pspace
;
8933 copy
->enable_state
= bp_enabled
;
8934 copy
->disposition
= disp_donttouch
;
8935 copy
->number
= internal_breakpoint_number
--;
8937 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8941 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8945 clone_momentary_breakpoint (struct breakpoint
*orig
)
8947 /* If there's nothing to clone, then return nothing. */
8951 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8955 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8958 struct symtab_and_line sal
;
8960 sal
= find_pc_line (pc
, 0);
8962 sal
.section
= find_pc_overlay (pc
);
8963 sal
.explicit_pc
= 1;
8965 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8969 /* Tell the user we have just set a breakpoint B. */
8972 mention (struct breakpoint
*b
)
8974 b
->ops
->print_mention (b
);
8975 if (current_uiout
->is_mi_like_p ())
8977 printf_filtered ("\n");
8981 static int bp_loc_is_permanent (struct bp_location
*loc
);
8983 static struct bp_location
*
8984 add_location_to_breakpoint (struct breakpoint
*b
,
8985 const struct symtab_and_line
*sal
)
8987 struct bp_location
*loc
, **tmp
;
8988 CORE_ADDR adjusted_address
;
8989 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8991 if (loc_gdbarch
== NULL
)
8992 loc_gdbarch
= b
->gdbarch
;
8994 /* Adjust the breakpoint's address prior to allocating a location.
8995 Once we call allocate_bp_location(), that mostly uninitialized
8996 location will be placed on the location chain. Adjustment of the
8997 breakpoint may cause target_read_memory() to be called and we do
8998 not want its scan of the location chain to find a breakpoint and
8999 location that's only been partially initialized. */
9000 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9003 /* Sort the locations by their ADDRESS. */
9004 loc
= allocate_bp_location (b
);
9005 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9006 tmp
= &((*tmp
)->next
))
9011 loc
->requested_address
= sal
->pc
;
9012 loc
->address
= adjusted_address
;
9013 loc
->pspace
= sal
->pspace
;
9014 loc
->probe
.probe
= sal
->probe
;
9015 loc
->probe
.objfile
= sal
->objfile
;
9016 gdb_assert (loc
->pspace
!= NULL
);
9017 loc
->section
= sal
->section
;
9018 loc
->gdbarch
= loc_gdbarch
;
9019 loc
->line_number
= sal
->line
;
9020 loc
->symtab
= sal
->symtab
;
9022 set_breakpoint_location_function (loc
,
9023 sal
->explicit_pc
|| sal
->explicit_line
);
9025 /* While by definition, permanent breakpoints are already present in the
9026 code, we don't mark the location as inserted. Normally one would expect
9027 that GDB could rely on that breakpoint instruction to stop the program,
9028 thus removing the need to insert its own breakpoint, except that executing
9029 the breakpoint instruction can kill the target instead of reporting a
9030 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9031 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9032 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9033 breakpoint be inserted normally results in QEMU knowing about the GDB
9034 breakpoint, and thus trap before the breakpoint instruction is executed.
9035 (If GDB later needs to continue execution past the permanent breakpoint,
9036 it manually increments the PC, thus avoiding executing the breakpoint
9038 if (bp_loc_is_permanent (loc
))
9045 /* See breakpoint.h. */
9048 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9052 const gdb_byte
*bpoint
;
9053 gdb_byte
*target_mem
;
9054 struct cleanup
*cleanup
;
9058 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9060 /* Software breakpoints unsupported? */
9064 target_mem
= (gdb_byte
*) alloca (len
);
9066 /* Enable the automatic memory restoration from breakpoints while
9067 we read the memory. Otherwise we could say about our temporary
9068 breakpoints they are permanent. */
9069 cleanup
= make_show_memory_breakpoints_cleanup (0);
9071 if (target_read_memory (address
, target_mem
, len
) == 0
9072 && memcmp (target_mem
, bpoint
, len
) == 0)
9075 do_cleanups (cleanup
);
9080 /* Return 1 if LOC is pointing to a permanent breakpoint,
9081 return 0 otherwise. */
9084 bp_loc_is_permanent (struct bp_location
*loc
)
9086 struct cleanup
*cleanup
;
9089 gdb_assert (loc
!= NULL
);
9091 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9092 attempt to read from the addresses the locations of these breakpoint types
9093 point to. program_breakpoint_here_p, below, will attempt to read
9095 if (!breakpoint_address_is_meaningful (loc
->owner
))
9098 cleanup
= save_current_space_and_thread ();
9099 switch_to_program_space_and_thread (loc
->pspace
);
9101 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9103 do_cleanups (cleanup
);
9108 /* Build a command list for the dprintf corresponding to the current
9109 settings of the dprintf style options. */
9112 update_dprintf_command_list (struct breakpoint
*b
)
9114 char *dprintf_args
= b
->extra_string
;
9115 char *printf_line
= NULL
;
9120 dprintf_args
= skip_spaces (dprintf_args
);
9122 /* Allow a comma, as it may have terminated a location, but don't
9124 if (*dprintf_args
== ',')
9126 dprintf_args
= skip_spaces (dprintf_args
);
9128 if (*dprintf_args
!= '"')
9129 error (_("Bad format string, missing '\"'."));
9131 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9132 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9133 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9135 if (!dprintf_function
)
9136 error (_("No function supplied for dprintf call"));
9138 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9139 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9144 printf_line
= xstrprintf ("call (void) %s (%s)",
9148 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9150 if (target_can_run_breakpoint_commands ())
9151 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9154 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9155 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9159 internal_error (__FILE__
, __LINE__
,
9160 _("Invalid dprintf style."));
9162 gdb_assert (printf_line
!= NULL
);
9163 /* Manufacture a printf sequence. */
9165 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9167 printf_cmd_line
->control_type
= simple_control
;
9168 printf_cmd_line
->body_count
= 0;
9169 printf_cmd_line
->body_list
= NULL
;
9170 printf_cmd_line
->next
= NULL
;
9171 printf_cmd_line
->line
= printf_line
;
9173 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9177 /* Update all dprintf commands, making their command lists reflect
9178 current style settings. */
9181 update_dprintf_commands (char *args
, int from_tty
,
9182 struct cmd_list_element
*c
)
9184 struct breakpoint
*b
;
9188 if (b
->type
== bp_dprintf
)
9189 update_dprintf_command_list (b
);
9193 /* Create a breakpoint with SAL as location. Use LOCATION
9194 as a description of the location, and COND_STRING
9195 as condition expression. If LOCATION is NULL then create an
9196 "address location" from the address in the SAL. */
9199 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9200 struct symtabs_and_lines sals
,
9201 event_location_up
&&location
,
9202 char *filter
, char *cond_string
,
9204 enum bptype type
, enum bpdisp disposition
,
9205 int thread
, int task
, int ignore_count
,
9206 const struct breakpoint_ops
*ops
, int from_tty
,
9207 int enabled
, int internal
, unsigned flags
,
9208 int display_canonical
)
9212 if (type
== bp_hardware_breakpoint
)
9214 int target_resources_ok
;
9216 i
= hw_breakpoint_used_count ();
9217 target_resources_ok
=
9218 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9220 if (target_resources_ok
== 0)
9221 error (_("No hardware breakpoint support in the target."));
9222 else if (target_resources_ok
< 0)
9223 error (_("Hardware breakpoints used exceeds limit."));
9226 gdb_assert (sals
.nelts
> 0);
9228 for (i
= 0; i
< sals
.nelts
; ++i
)
9230 struct symtab_and_line sal
= sals
.sals
[i
];
9231 struct bp_location
*loc
;
9235 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9237 loc_gdbarch
= gdbarch
;
9239 describe_other_breakpoints (loc_gdbarch
,
9240 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9245 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9249 b
->cond_string
= cond_string
;
9250 b
->extra_string
= extra_string
;
9251 b
->ignore_count
= ignore_count
;
9252 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9253 b
->disposition
= disposition
;
9255 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9256 b
->loc
->inserted
= 1;
9258 if (type
== bp_static_tracepoint
)
9260 struct tracepoint
*t
= (struct tracepoint
*) b
;
9261 struct static_tracepoint_marker marker
;
9263 if (strace_marker_p (b
))
9265 /* We already know the marker exists, otherwise, we
9266 wouldn't see a sal for it. */
9268 = &event_location_to_string (b
->location
.get ())[3];
9272 p
= skip_spaces_const (p
);
9274 endp
= skip_to_space_const (p
);
9276 marker_str
= savestring (p
, endp
- p
);
9277 t
->static_trace_marker_id
= marker_str
;
9279 printf_filtered (_("Probed static tracepoint "
9281 t
->static_trace_marker_id
);
9283 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9285 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9286 release_static_tracepoint_marker (&marker
);
9288 printf_filtered (_("Probed static tracepoint "
9290 t
->static_trace_marker_id
);
9293 warning (_("Couldn't determine the static "
9294 "tracepoint marker to probe"));
9301 loc
= add_location_to_breakpoint (b
, &sal
);
9302 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9308 const char *arg
= b
->cond_string
;
9310 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9311 block_for_pc (loc
->address
), 0);
9313 error (_("Garbage '%s' follows condition"), arg
);
9316 /* Dynamic printf requires and uses additional arguments on the
9317 command line, otherwise it's an error. */
9318 if (type
== bp_dprintf
)
9320 if (b
->extra_string
)
9321 update_dprintf_command_list (b
);
9323 error (_("Format string required"));
9325 else if (b
->extra_string
)
9326 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9329 b
->display_canonical
= display_canonical
;
9330 if (location
!= NULL
)
9331 b
->location
= std::move (location
);
9333 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9338 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9339 struct symtabs_and_lines sals
,
9340 event_location_up
&&location
,
9341 char *filter
, char *cond_string
,
9343 enum bptype type
, enum bpdisp disposition
,
9344 int thread
, int task
, int ignore_count
,
9345 const struct breakpoint_ops
*ops
, int from_tty
,
9346 int enabled
, int internal
, unsigned flags
,
9347 int display_canonical
)
9349 struct breakpoint
*b
;
9350 struct cleanup
*old_chain
;
9352 if (is_tracepoint_type (type
))
9354 struct tracepoint
*t
;
9356 t
= new tracepoint ();
9360 b
= new breakpoint ();
9362 old_chain
= make_cleanup (xfree
, b
);
9364 init_breakpoint_sal (b
, gdbarch
,
9365 sals
, std::move (location
),
9366 filter
, cond_string
, extra_string
,
9368 thread
, task
, ignore_count
,
9370 enabled
, internal
, flags
,
9372 discard_cleanups (old_chain
);
9374 install_breakpoint (internal
, b
, 0);
9377 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9378 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9379 value. COND_STRING, if not NULL, specified the condition to be
9380 used for all breakpoints. Essentially the only case where
9381 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9382 function. In that case, it's still not possible to specify
9383 separate conditions for different overloaded functions, so
9384 we take just a single condition string.
9386 NOTE: If the function succeeds, the caller is expected to cleanup
9387 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9388 array contents). If the function fails (error() is called), the
9389 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9390 COND and SALS arrays and each of those arrays contents. */
9393 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9394 struct linespec_result
*canonical
,
9395 char *cond_string
, char *extra_string
,
9396 enum bptype type
, enum bpdisp disposition
,
9397 int thread
, int task
, int ignore_count
,
9398 const struct breakpoint_ops
*ops
, int from_tty
,
9399 int enabled
, int internal
, unsigned flags
)
9402 struct linespec_sals
*lsal
;
9404 if (canonical
->pre_expanded
)
9405 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9407 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9409 /* Note that 'location' can be NULL in the case of a plain
9410 'break', without arguments. */
9411 event_location_up location
9412 = (canonical
->location
!= NULL
9413 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9414 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9416 make_cleanup (xfree
, filter_string
);
9417 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9418 std::move (location
),
9420 cond_string
, extra_string
,
9422 thread
, task
, ignore_count
, ops
,
9423 from_tty
, enabled
, internal
, flags
,
9424 canonical
->special_display
);
9428 /* Parse LOCATION which is assumed to be a SAL specification possibly
9429 followed by conditionals. On return, SALS contains an array of SAL
9430 addresses found. LOCATION points to the end of the SAL (for
9431 linespec locations).
9433 The array and the line spec strings are allocated on the heap, it is
9434 the caller's responsibility to free them. */
9437 parse_breakpoint_sals (const struct event_location
*location
,
9438 struct linespec_result
*canonical
)
9440 struct symtab_and_line cursal
;
9442 if (event_location_type (location
) == LINESPEC_LOCATION
)
9444 const char *address
= get_linespec_location (location
);
9446 if (address
== NULL
)
9448 /* The last displayed codepoint, if it's valid, is our default
9449 breakpoint address. */
9450 if (last_displayed_sal_is_valid ())
9452 struct linespec_sals lsal
;
9453 struct symtab_and_line sal
;
9456 init_sal (&sal
); /* Initialize to zeroes. */
9457 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9459 /* Set sal's pspace, pc, symtab, and line to the values
9460 corresponding to the last call to print_frame_info.
9461 Be sure to reinitialize LINE with NOTCURRENT == 0
9462 as the breakpoint line number is inappropriate otherwise.
9463 find_pc_line would adjust PC, re-set it back. */
9464 get_last_displayed_sal (&sal
);
9466 sal
= find_pc_line (pc
, 0);
9468 /* "break" without arguments is equivalent to "break *PC"
9469 where PC is the last displayed codepoint's address. So
9470 make sure to set sal.explicit_pc to prevent GDB from
9471 trying to expand the list of sals to include all other
9472 instances with the same symtab and line. */
9474 sal
.explicit_pc
= 1;
9476 lsal
.sals
.sals
[0] = sal
;
9477 lsal
.sals
.nelts
= 1;
9478 lsal
.canonical
= NULL
;
9480 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9484 error (_("No default breakpoint address now."));
9488 /* Force almost all breakpoints to be in terms of the
9489 current_source_symtab (which is decode_line_1's default).
9490 This should produce the results we want almost all of the
9491 time while leaving default_breakpoint_* alone.
9493 ObjC: However, don't match an Objective-C method name which
9494 may have a '+' or '-' succeeded by a '['. */
9495 cursal
= get_current_source_symtab_and_line ();
9496 if (last_displayed_sal_is_valid ())
9498 const char *address
= NULL
;
9500 if (event_location_type (location
) == LINESPEC_LOCATION
)
9501 address
= get_linespec_location (location
);
9505 && strchr ("+-", address
[0]) != NULL
9506 && address
[1] != '['))
9508 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9509 get_last_displayed_symtab (),
9510 get_last_displayed_line (),
9511 canonical
, NULL
, NULL
);
9516 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9517 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9521 /* Convert each SAL into a real PC. Verify that the PC can be
9522 inserted as a breakpoint. If it can't throw an error. */
9525 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9529 for (i
= 0; i
< sals
->nelts
; i
++)
9530 resolve_sal_pc (&sals
->sals
[i
]);
9533 /* Fast tracepoints may have restrictions on valid locations. For
9534 instance, a fast tracepoint using a jump instead of a trap will
9535 likely have to overwrite more bytes than a trap would, and so can
9536 only be placed where the instruction is longer than the jump, or a
9537 multi-instruction sequence does not have a jump into the middle of
9541 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9542 struct symtabs_and_lines
*sals
)
9545 struct symtab_and_line
*sal
;
9547 struct cleanup
*old_chain
;
9549 for (i
= 0; i
< sals
->nelts
; i
++)
9551 struct gdbarch
*sarch
;
9553 sal
= &sals
->sals
[i
];
9555 sarch
= get_sal_arch (*sal
);
9556 /* We fall back to GDBARCH if there is no architecture
9557 associated with SAL. */
9560 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9561 old_chain
= make_cleanup (xfree
, msg
);
9564 error (_("May not have a fast tracepoint at %s%s"),
9565 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9567 do_cleanups (old_chain
);
9571 /* Given TOK, a string specification of condition and thread, as
9572 accepted by the 'break' command, extract the condition
9573 string and thread number and set *COND_STRING and *THREAD.
9574 PC identifies the context at which the condition should be parsed.
9575 If no condition is found, *COND_STRING is set to NULL.
9576 If no thread is found, *THREAD is set to -1. */
9579 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9580 char **cond_string
, int *thread
, int *task
,
9583 *cond_string
= NULL
;
9590 const char *end_tok
;
9592 const char *cond_start
= NULL
;
9593 const char *cond_end
= NULL
;
9595 tok
= skip_spaces_const (tok
);
9597 if ((*tok
== '"' || *tok
== ',') && rest
)
9599 *rest
= savestring (tok
, strlen (tok
));
9603 end_tok
= skip_to_space_const (tok
);
9605 toklen
= end_tok
- tok
;
9607 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9609 tok
= cond_start
= end_tok
+ 1;
9610 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9612 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9614 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9617 struct thread_info
*thr
;
9620 thr
= parse_thread_id (tok
, &tmptok
);
9622 error (_("Junk after thread keyword."));
9623 *thread
= thr
->global_num
;
9626 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9631 *task
= strtol (tok
, &tmptok
, 0);
9633 error (_("Junk after task keyword."));
9634 if (!valid_task_id (*task
))
9635 error (_("Unknown task %d."), *task
);
9640 *rest
= savestring (tok
, strlen (tok
));
9644 error (_("Junk at end of arguments."));
9648 /* Decode a static tracepoint marker spec. */
9650 static struct symtabs_and_lines
9651 decode_static_tracepoint_spec (const char **arg_p
)
9653 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9654 struct symtabs_and_lines sals
;
9655 struct cleanup
*old_chain
;
9656 const char *p
= &(*arg_p
)[3];
9661 p
= skip_spaces_const (p
);
9663 endp
= skip_to_space_const (p
);
9665 marker_str
= savestring (p
, endp
- p
);
9666 old_chain
= make_cleanup (xfree
, marker_str
);
9668 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9669 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9670 error (_("No known static tracepoint marker named %s"), marker_str
);
9672 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9673 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9675 for (i
= 0; i
< sals
.nelts
; i
++)
9677 struct static_tracepoint_marker
*marker
;
9679 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9681 init_sal (&sals
.sals
[i
]);
9683 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9684 sals
.sals
[i
].pc
= marker
->address
;
9686 release_static_tracepoint_marker (marker
);
9689 do_cleanups (old_chain
);
9695 /* See breakpoint.h. */
9698 create_breakpoint (struct gdbarch
*gdbarch
,
9699 const struct event_location
*location
, char *cond_string
,
9700 int thread
, char *extra_string
,
9702 int tempflag
, enum bptype type_wanted
,
9704 enum auto_boolean pending_break_support
,
9705 const struct breakpoint_ops
*ops
,
9706 int from_tty
, int enabled
, int internal
,
9709 struct linespec_result canonical
;
9710 struct cleanup
*bkpt_chain
= NULL
;
9713 int prev_bkpt_count
= breakpoint_count
;
9715 gdb_assert (ops
!= NULL
);
9717 /* If extra_string isn't useful, set it to NULL. */
9718 if (extra_string
!= NULL
&& *extra_string
== '\0')
9719 extra_string
= NULL
;
9723 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9725 CATCH (e
, RETURN_MASK_ERROR
)
9727 /* If caller is interested in rc value from parse, set
9729 if (e
.error
== NOT_FOUND_ERROR
)
9731 /* If pending breakpoint support is turned off, throw
9734 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9735 throw_exception (e
);
9737 exception_print (gdb_stderr
, e
);
9739 /* If pending breakpoint support is auto query and the user
9740 selects no, then simply return the error code. */
9741 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9742 && !nquery (_("Make %s pending on future shared library load? "),
9743 bptype_string (type_wanted
)))
9746 /* At this point, either the user was queried about setting
9747 a pending breakpoint and selected yes, or pending
9748 breakpoint behavior is on and thus a pending breakpoint
9749 is defaulted on behalf of the user. */
9753 throw_exception (e
);
9757 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9760 /* ----------------------------- SNIP -----------------------------
9761 Anything added to the cleanup chain beyond this point is assumed
9762 to be part of a breakpoint. If the breakpoint create succeeds
9763 then the memory is not reclaimed. */
9764 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9766 /* Resolve all line numbers to PC's and verify that the addresses
9767 are ok for the target. */
9771 struct linespec_sals
*iter
;
9773 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9774 breakpoint_sals_to_pc (&iter
->sals
);
9777 /* Fast tracepoints may have additional restrictions on location. */
9778 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9781 struct linespec_sals
*iter
;
9783 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9784 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9787 /* Verify that condition can be parsed, before setting any
9788 breakpoints. Allocate a separate condition expression for each
9795 struct linespec_sals
*lsal
;
9797 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9799 /* Here we only parse 'arg' to separate condition
9800 from thread number, so parsing in context of first
9801 sal is OK. When setting the breakpoint we'll
9802 re-parse it in context of each sal. */
9804 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9805 &cond_string
, &thread
, &task
, &rest
);
9807 make_cleanup (xfree
, cond_string
);
9809 make_cleanup (xfree
, rest
);
9811 extra_string
= rest
;
9813 extra_string
= NULL
;
9817 if (type_wanted
!= bp_dprintf
9818 && extra_string
!= NULL
&& *extra_string
!= '\0')
9819 error (_("Garbage '%s' at end of location"), extra_string
);
9821 /* Create a private copy of condition string. */
9824 cond_string
= xstrdup (cond_string
);
9825 make_cleanup (xfree
, cond_string
);
9827 /* Create a private copy of any extra string. */
9830 extra_string
= xstrdup (extra_string
);
9831 make_cleanup (xfree
, extra_string
);
9835 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9836 cond_string
, extra_string
, type_wanted
,
9837 tempflag
? disp_del
: disp_donttouch
,
9838 thread
, task
, ignore_count
, ops
,
9839 from_tty
, enabled
, internal
, flags
);
9843 struct breakpoint
*b
;
9845 if (is_tracepoint_type (type_wanted
))
9847 struct tracepoint
*t
;
9849 t
= new tracepoint ();
9853 b
= new breakpoint ();
9855 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9856 b
->location
= copy_event_location (location
);
9859 b
->cond_string
= NULL
;
9862 /* Create a private copy of condition string. */
9865 cond_string
= xstrdup (cond_string
);
9866 make_cleanup (xfree
, cond_string
);
9868 b
->cond_string
= cond_string
;
9872 /* Create a private copy of any extra string. */
9873 if (extra_string
!= NULL
)
9875 extra_string
= xstrdup (extra_string
);
9876 make_cleanup (xfree
, extra_string
);
9878 b
->extra_string
= extra_string
;
9879 b
->ignore_count
= ignore_count
;
9880 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9881 b
->condition_not_parsed
= 1;
9882 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9883 if ((type_wanted
!= bp_breakpoint
9884 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9885 b
->pspace
= current_program_space
;
9887 install_breakpoint (internal
, b
, 0);
9890 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9892 warning (_("Multiple breakpoints were set.\nUse the "
9893 "\"delete\" command to delete unwanted breakpoints."));
9894 prev_breakpoint_count
= prev_bkpt_count
;
9897 /* That's it. Discard the cleanups for data inserted into the
9899 discard_cleanups (bkpt_chain
);
9901 /* error call may happen here - have BKPT_CHAIN already discarded. */
9902 update_global_location_list (UGLL_MAY_INSERT
);
9907 /* Set a breakpoint.
9908 ARG is a string describing breakpoint address,
9909 condition, and thread.
9910 FLAG specifies if a breakpoint is hardware on,
9911 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9915 break_command_1 (char *arg
, int flag
, int from_tty
)
9917 int tempflag
= flag
& BP_TEMPFLAG
;
9918 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9919 ? bp_hardware_breakpoint
9921 struct breakpoint_ops
*ops
;
9923 event_location_up location
= string_to_event_location (&arg
, current_language
);
9925 /* Matching breakpoints on probes. */
9926 if (location
!= NULL
9927 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9928 ops
= &bkpt_probe_breakpoint_ops
;
9930 ops
= &bkpt_breakpoint_ops
;
9932 create_breakpoint (get_current_arch (),
9934 NULL
, 0, arg
, 1 /* parse arg */,
9935 tempflag
, type_wanted
,
9936 0 /* Ignore count */,
9937 pending_break_support
,
9945 /* Helper function for break_command_1 and disassemble_command. */
9948 resolve_sal_pc (struct symtab_and_line
*sal
)
9952 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9954 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9955 error (_("No line %d in file \"%s\"."),
9956 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9959 /* If this SAL corresponds to a breakpoint inserted using a line
9960 number, then skip the function prologue if necessary. */
9961 if (sal
->explicit_line
)
9962 skip_prologue_sal (sal
);
9965 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9967 const struct blockvector
*bv
;
9968 const struct block
*b
;
9971 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9972 SYMTAB_COMPUNIT (sal
->symtab
));
9975 sym
= block_linkage_function (b
);
9978 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9979 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9984 /* It really is worthwhile to have the section, so we'll
9985 just have to look harder. This case can be executed
9986 if we have line numbers but no functions (as can
9987 happen in assembly source). */
9989 struct bound_minimal_symbol msym
;
9990 struct cleanup
*old_chain
= save_current_space_and_thread ();
9992 switch_to_program_space_and_thread (sal
->pspace
);
9994 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9996 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9998 do_cleanups (old_chain
);
10005 break_command (char *arg
, int from_tty
)
10007 break_command_1 (arg
, 0, from_tty
);
10011 tbreak_command (char *arg
, int from_tty
)
10013 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10017 hbreak_command (char *arg
, int from_tty
)
10019 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10023 thbreak_command (char *arg
, int from_tty
)
10025 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10029 stop_command (char *arg
, int from_tty
)
10031 printf_filtered (_("Specify the type of breakpoint to set.\n\
10032 Usage: stop in <function | address>\n\
10033 stop at <line>\n"));
10037 stopin_command (char *arg
, int from_tty
)
10041 if (arg
== (char *) NULL
)
10043 else if (*arg
!= '*')
10045 char *argptr
= arg
;
10048 /* Look for a ':'. If this is a line number specification, then
10049 say it is bad, otherwise, it should be an address or
10050 function/method name. */
10051 while (*argptr
&& !hasColon
)
10053 hasColon
= (*argptr
== ':');
10058 badInput
= (*argptr
!= ':'); /* Not a class::method */
10060 badInput
= isdigit (*arg
); /* a simple line number */
10064 printf_filtered (_("Usage: stop in <function | address>\n"));
10066 break_command_1 (arg
, 0, from_tty
);
10070 stopat_command (char *arg
, int from_tty
)
10074 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10078 char *argptr
= arg
;
10081 /* Look for a ':'. If there is a '::' then get out, otherwise
10082 it is probably a line number. */
10083 while (*argptr
&& !hasColon
)
10085 hasColon
= (*argptr
== ':');
10090 badInput
= (*argptr
== ':'); /* we have class::method */
10092 badInput
= !isdigit (*arg
); /* not a line number */
10096 printf_filtered (_("Usage: stop at <line>\n"));
10098 break_command_1 (arg
, 0, from_tty
);
10101 /* The dynamic printf command is mostly like a regular breakpoint, but
10102 with a prewired command list consisting of a single output command,
10103 built from extra arguments supplied on the dprintf command
10107 dprintf_command (char *arg
, int from_tty
)
10109 event_location_up location
= string_to_event_location (&arg
, current_language
);
10111 /* If non-NULL, ARG should have been advanced past the location;
10112 the next character must be ','. */
10115 if (arg
[0] != ',' || arg
[1] == '\0')
10116 error (_("Format string required"));
10119 /* Skip the comma. */
10124 create_breakpoint (get_current_arch (),
10126 NULL
, 0, arg
, 1 /* parse arg */,
10128 0 /* Ignore count */,
10129 pending_break_support
,
10130 &dprintf_breakpoint_ops
,
10138 agent_printf_command (char *arg
, int from_tty
)
10140 error (_("May only run agent-printf on the target"));
10143 /* Implement the "breakpoint_hit" breakpoint_ops method for
10144 ranged breakpoints. */
10147 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10148 struct address_space
*aspace
,
10150 const struct target_waitstatus
*ws
)
10152 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10153 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10156 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10157 bl
->length
, aspace
, bp_addr
);
10160 /* Implement the "resources_needed" breakpoint_ops method for
10161 ranged breakpoints. */
10164 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10166 return target_ranged_break_num_registers ();
10169 /* Implement the "print_it" breakpoint_ops method for
10170 ranged breakpoints. */
10172 static enum print_stop_action
10173 print_it_ranged_breakpoint (bpstat bs
)
10175 struct breakpoint
*b
= bs
->breakpoint_at
;
10176 struct bp_location
*bl
= b
->loc
;
10177 struct ui_out
*uiout
= current_uiout
;
10179 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10181 /* Ranged breakpoints have only one location. */
10182 gdb_assert (bl
&& bl
->next
== NULL
);
10184 annotate_breakpoint (b
->number
);
10186 maybe_print_thread_hit_breakpoint (uiout
);
10188 if (b
->disposition
== disp_del
)
10189 uiout
->text ("Temporary ranged breakpoint ");
10191 uiout
->text ("Ranged breakpoint ");
10192 if (uiout
->is_mi_like_p ())
10194 uiout
->field_string ("reason",
10195 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10196 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10198 uiout
->field_int ("bkptno", b
->number
);
10199 uiout
->text (", ");
10201 return PRINT_SRC_AND_LOC
;
10204 /* Implement the "print_one" breakpoint_ops method for
10205 ranged breakpoints. */
10208 print_one_ranged_breakpoint (struct breakpoint
*b
,
10209 struct bp_location
**last_loc
)
10211 struct bp_location
*bl
= b
->loc
;
10212 struct value_print_options opts
;
10213 struct ui_out
*uiout
= current_uiout
;
10215 /* Ranged breakpoints have only one location. */
10216 gdb_assert (bl
&& bl
->next
== NULL
);
10218 get_user_print_options (&opts
);
10220 if (opts
.addressprint
)
10221 /* We don't print the address range here, it will be printed later
10222 by print_one_detail_ranged_breakpoint. */
10223 uiout
->field_skip ("addr");
10224 annotate_field (5);
10225 print_breakpoint_location (b
, bl
);
10229 /* Implement the "print_one_detail" breakpoint_ops method for
10230 ranged breakpoints. */
10233 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10234 struct ui_out
*uiout
)
10236 CORE_ADDR address_start
, address_end
;
10237 struct bp_location
*bl
= b
->loc
;
10242 address_start
= bl
->address
;
10243 address_end
= address_start
+ bl
->length
- 1;
10245 uiout
->text ("\taddress range: ");
10246 stb
.printf ("[%s, %s]",
10247 print_core_address (bl
->gdbarch
, address_start
),
10248 print_core_address (bl
->gdbarch
, address_end
));
10249 uiout
->field_stream ("addr", stb
);
10250 uiout
->text ("\n");
10253 /* Implement the "print_mention" breakpoint_ops method for
10254 ranged breakpoints. */
10257 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10259 struct bp_location
*bl
= b
->loc
;
10260 struct ui_out
*uiout
= current_uiout
;
10263 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10265 if (uiout
->is_mi_like_p ())
10268 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10269 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10270 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10273 /* Implement the "print_recreate" breakpoint_ops method for
10274 ranged breakpoints. */
10277 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10279 fprintf_unfiltered (fp
, "break-range %s, %s",
10280 event_location_to_string (b
->location
.get ()),
10281 event_location_to_string (b
->location_range_end
.get ()));
10282 print_recreate_thread (b
, fp
);
10285 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10287 static struct breakpoint_ops ranged_breakpoint_ops
;
10289 /* Find the address where the end of the breakpoint range should be
10290 placed, given the SAL of the end of the range. This is so that if
10291 the user provides a line number, the end of the range is set to the
10292 last instruction of the given line. */
10295 find_breakpoint_range_end (struct symtab_and_line sal
)
10299 /* If the user provided a PC value, use it. Otherwise,
10300 find the address of the end of the given location. */
10301 if (sal
.explicit_pc
)
10308 ret
= find_line_pc_range (sal
, &start
, &end
);
10310 error (_("Could not find location of the end of the range."));
10312 /* find_line_pc_range returns the start of the next line. */
10319 /* Implement the "break-range" CLI command. */
10322 break_range_command (char *arg
, int from_tty
)
10324 char *arg_start
, *addr_string_start
;
10325 struct linespec_result canonical_start
, canonical_end
;
10326 int bp_count
, can_use_bp
, length
;
10328 struct breakpoint
*b
;
10329 struct symtab_and_line sal_start
, sal_end
;
10330 struct cleanup
*cleanup_bkpt
;
10331 struct linespec_sals
*lsal_start
, *lsal_end
;
10333 /* We don't support software ranged breakpoints. */
10334 if (target_ranged_break_num_registers () < 0)
10335 error (_("This target does not support hardware ranged breakpoints."));
10337 bp_count
= hw_breakpoint_used_count ();
10338 bp_count
+= target_ranged_break_num_registers ();
10339 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10341 if (can_use_bp
< 0)
10342 error (_("Hardware breakpoints used exceeds limit."));
10344 arg
= skip_spaces (arg
);
10345 if (arg
== NULL
|| arg
[0] == '\0')
10346 error(_("No address range specified."));
10349 event_location_up start_location
= string_to_event_location (&arg
,
10351 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10354 error (_("Too few arguments."));
10355 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10356 error (_("Could not find location of the beginning of the range."));
10358 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10360 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10361 || lsal_start
->sals
.nelts
!= 1)
10362 error (_("Cannot create a ranged breakpoint with multiple locations."));
10364 sal_start
= lsal_start
->sals
.sals
[0];
10365 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10366 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10368 arg
++; /* Skip the comma. */
10369 arg
= skip_spaces (arg
);
10371 /* Parse the end location. */
10375 /* We call decode_line_full directly here instead of using
10376 parse_breakpoint_sals because we need to specify the start location's
10377 symtab and line as the default symtab and line for the end of the
10378 range. This makes it possible to have ranges like "foo.c:27, +14",
10379 where +14 means 14 lines from the start location. */
10380 event_location_up end_location
= string_to_event_location (&arg
,
10382 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10383 sal_start
.symtab
, sal_start
.line
,
10384 &canonical_end
, NULL
, NULL
);
10386 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10387 error (_("Could not find location of the end of the range."));
10389 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10390 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10391 || lsal_end
->sals
.nelts
!= 1)
10392 error (_("Cannot create a ranged breakpoint with multiple locations."));
10394 sal_end
= lsal_end
->sals
.sals
[0];
10396 end
= find_breakpoint_range_end (sal_end
);
10397 if (sal_start
.pc
> end
)
10398 error (_("Invalid address range, end precedes start."));
10400 length
= end
- sal_start
.pc
+ 1;
10402 /* Length overflowed. */
10403 error (_("Address range too large."));
10404 else if (length
== 1)
10406 /* This range is simple enough to be handled by
10407 the `hbreak' command. */
10408 hbreak_command (addr_string_start
, 1);
10410 do_cleanups (cleanup_bkpt
);
10415 /* Now set up the breakpoint. */
10416 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10417 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10418 set_breakpoint_count (breakpoint_count
+ 1);
10419 b
->number
= breakpoint_count
;
10420 b
->disposition
= disp_donttouch
;
10421 b
->location
= std::move (start_location
);
10422 b
->location_range_end
= std::move (end_location
);
10423 b
->loc
->length
= length
;
10425 do_cleanups (cleanup_bkpt
);
10428 observer_notify_breakpoint_created (b
);
10429 update_global_location_list (UGLL_MAY_INSERT
);
10432 /* Return non-zero if EXP is verified as constant. Returned zero
10433 means EXP is variable. Also the constant detection may fail for
10434 some constant expressions and in such case still falsely return
10438 watchpoint_exp_is_const (const struct expression
*exp
)
10440 int i
= exp
->nelts
;
10446 /* We are only interested in the descriptor of each element. */
10447 operator_length (exp
, i
, &oplenp
, &argsp
);
10450 switch (exp
->elts
[i
].opcode
)
10460 case BINOP_LOGICAL_AND
:
10461 case BINOP_LOGICAL_OR
:
10462 case BINOP_BITWISE_AND
:
10463 case BINOP_BITWISE_IOR
:
10464 case BINOP_BITWISE_XOR
:
10466 case BINOP_NOTEQUAL
:
10493 case OP_OBJC_NSSTRING
:
10496 case UNOP_LOGICAL_NOT
:
10497 case UNOP_COMPLEMENT
:
10502 case UNOP_CAST_TYPE
:
10503 case UNOP_REINTERPRET_CAST
:
10504 case UNOP_DYNAMIC_CAST
:
10505 /* Unary, binary and ternary operators: We have to check
10506 their operands. If they are constant, then so is the
10507 result of that operation. For instance, if A and B are
10508 determined to be constants, then so is "A + B".
10510 UNOP_IND is one exception to the rule above, because the
10511 value of *ADDR is not necessarily a constant, even when
10516 /* Check whether the associated symbol is a constant.
10518 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10519 possible that a buggy compiler could mark a variable as
10520 constant even when it is not, and TYPE_CONST would return
10521 true in this case, while SYMBOL_CLASS wouldn't.
10523 We also have to check for function symbols because they
10524 are always constant. */
10526 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10528 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10529 && SYMBOL_CLASS (s
) != LOC_CONST
10530 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10535 /* The default action is to return 0 because we are using
10536 the optimistic approach here: If we don't know something,
10537 then it is not a constant. */
10546 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10549 dtor_watchpoint (struct breakpoint
*self
)
10551 struct watchpoint
*w
= (struct watchpoint
*) self
;
10553 xfree (w
->exp_string
);
10554 xfree (w
->exp_string_reparse
);
10555 value_free (w
->val
);
10557 base_breakpoint_ops
.dtor (self
);
10560 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10563 re_set_watchpoint (struct breakpoint
*b
)
10565 struct watchpoint
*w
= (struct watchpoint
*) b
;
10567 /* Watchpoint can be either on expression using entirely global
10568 variables, or it can be on local variables.
10570 Watchpoints of the first kind are never auto-deleted, and even
10571 persist across program restarts. Since they can use variables
10572 from shared libraries, we need to reparse expression as libraries
10573 are loaded and unloaded.
10575 Watchpoints on local variables can also change meaning as result
10576 of solib event. For example, if a watchpoint uses both a local
10577 and a global variables in expression, it's a local watchpoint,
10578 but unloading of a shared library will make the expression
10579 invalid. This is not a very common use case, but we still
10580 re-evaluate expression, to avoid surprises to the user.
10582 Note that for local watchpoints, we re-evaluate it only if
10583 watchpoints frame id is still valid. If it's not, it means the
10584 watchpoint is out of scope and will be deleted soon. In fact,
10585 I'm not sure we'll ever be called in this case.
10587 If a local watchpoint's frame id is still valid, then
10588 w->exp_valid_block is likewise valid, and we can safely use it.
10590 Don't do anything about disabled watchpoints, since they will be
10591 reevaluated again when enabled. */
10592 update_watchpoint (w
, 1 /* reparse */);
10595 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10598 insert_watchpoint (struct bp_location
*bl
)
10600 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10601 int length
= w
->exact
? 1 : bl
->length
;
10603 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10604 w
->cond_exp
.get ());
10607 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10610 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10612 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10613 int length
= w
->exact
? 1 : bl
->length
;
10615 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10616 w
->cond_exp
.get ());
10620 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10621 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10622 const struct target_waitstatus
*ws
)
10624 struct breakpoint
*b
= bl
->owner
;
10625 struct watchpoint
*w
= (struct watchpoint
*) b
;
10627 /* Continuable hardware watchpoints are treated as non-existent if the
10628 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10629 some data address). Otherwise gdb won't stop on a break instruction
10630 in the code (not from a breakpoint) when a hardware watchpoint has
10631 been defined. Also skip watchpoints which we know did not trigger
10632 (did not match the data address). */
10633 if (is_hardware_watchpoint (b
)
10634 && w
->watchpoint_triggered
== watch_triggered_no
)
10641 check_status_watchpoint (bpstat bs
)
10643 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10645 bpstat_check_watchpoint (bs
);
10648 /* Implement the "resources_needed" breakpoint_ops method for
10649 hardware watchpoints. */
10652 resources_needed_watchpoint (const struct bp_location
*bl
)
10654 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10655 int length
= w
->exact
? 1 : bl
->length
;
10657 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10660 /* Implement the "works_in_software_mode" breakpoint_ops method for
10661 hardware watchpoints. */
10664 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10666 /* Read and access watchpoints only work with hardware support. */
10667 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10670 static enum print_stop_action
10671 print_it_watchpoint (bpstat bs
)
10673 struct cleanup
*old_chain
;
10674 struct breakpoint
*b
;
10675 enum print_stop_action result
;
10676 struct watchpoint
*w
;
10677 struct ui_out
*uiout
= current_uiout
;
10679 gdb_assert (bs
->bp_location_at
!= NULL
);
10681 b
= bs
->breakpoint_at
;
10682 w
= (struct watchpoint
*) b
;
10684 old_chain
= make_cleanup (null_cleanup
, NULL
);
10686 annotate_watchpoint (b
->number
);
10687 maybe_print_thread_hit_breakpoint (uiout
);
10693 case bp_watchpoint
:
10694 case bp_hardware_watchpoint
:
10695 if (uiout
->is_mi_like_p ())
10696 uiout
->field_string
10697 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10699 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10700 uiout
->text ("\nOld value = ");
10701 watchpoint_value_print (bs
->old_val
, &stb
);
10702 uiout
->field_stream ("old", stb
);
10703 uiout
->text ("\nNew value = ");
10704 watchpoint_value_print (w
->val
, &stb
);
10705 uiout
->field_stream ("new", stb
);
10706 uiout
->text ("\n");
10707 /* More than one watchpoint may have been triggered. */
10708 result
= PRINT_UNKNOWN
;
10711 case bp_read_watchpoint
:
10712 if (uiout
->is_mi_like_p ())
10713 uiout
->field_string
10714 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10716 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10717 uiout
->text ("\nValue = ");
10718 watchpoint_value_print (w
->val
, &stb
);
10719 uiout
->field_stream ("value", stb
);
10720 uiout
->text ("\n");
10721 result
= PRINT_UNKNOWN
;
10724 case bp_access_watchpoint
:
10725 if (bs
->old_val
!= NULL
)
10727 if (uiout
->is_mi_like_p ())
10728 uiout
->field_string
10730 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10732 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10733 uiout
->text ("\nOld value = ");
10734 watchpoint_value_print (bs
->old_val
, &stb
);
10735 uiout
->field_stream ("old", stb
);
10736 uiout
->text ("\nNew value = ");
10741 if (uiout
->is_mi_like_p ())
10742 uiout
->field_string
10744 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10745 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10746 uiout
->text ("\nValue = ");
10748 watchpoint_value_print (w
->val
, &stb
);
10749 uiout
->field_stream ("new", stb
);
10750 uiout
->text ("\n");
10751 result
= PRINT_UNKNOWN
;
10754 result
= PRINT_UNKNOWN
;
10757 do_cleanups (old_chain
);
10761 /* Implement the "print_mention" breakpoint_ops method for hardware
10765 print_mention_watchpoint (struct breakpoint
*b
)
10767 struct watchpoint
*w
= (struct watchpoint
*) b
;
10768 struct ui_out
*uiout
= current_uiout
;
10769 const char *tuple_name
;
10773 case bp_watchpoint
:
10774 uiout
->text ("Watchpoint ");
10775 tuple_name
= "wpt";
10777 case bp_hardware_watchpoint
:
10778 uiout
->text ("Hardware watchpoint ");
10779 tuple_name
= "wpt";
10781 case bp_read_watchpoint
:
10782 uiout
->text ("Hardware read watchpoint ");
10783 tuple_name
= "hw-rwpt";
10785 case bp_access_watchpoint
:
10786 uiout
->text ("Hardware access (read/write) watchpoint ");
10787 tuple_name
= "hw-awpt";
10790 internal_error (__FILE__
, __LINE__
,
10791 _("Invalid hardware watchpoint type."));
10794 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10795 uiout
->field_int ("number", b
->number
);
10796 uiout
->text (": ");
10797 uiout
->field_string ("exp", w
->exp_string
);
10800 /* Implement the "print_recreate" breakpoint_ops method for
10804 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10806 struct watchpoint
*w
= (struct watchpoint
*) b
;
10810 case bp_watchpoint
:
10811 case bp_hardware_watchpoint
:
10812 fprintf_unfiltered (fp
, "watch");
10814 case bp_read_watchpoint
:
10815 fprintf_unfiltered (fp
, "rwatch");
10817 case bp_access_watchpoint
:
10818 fprintf_unfiltered (fp
, "awatch");
10821 internal_error (__FILE__
, __LINE__
,
10822 _("Invalid watchpoint type."));
10825 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10826 print_recreate_thread (b
, fp
);
10829 /* Implement the "explains_signal" breakpoint_ops method for
10833 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10835 /* A software watchpoint cannot cause a signal other than
10836 GDB_SIGNAL_TRAP. */
10837 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10843 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10845 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10847 /* Implement the "insert" breakpoint_ops method for
10848 masked hardware watchpoints. */
10851 insert_masked_watchpoint (struct bp_location
*bl
)
10853 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10855 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10856 bl
->watchpoint_type
);
10859 /* Implement the "remove" breakpoint_ops method for
10860 masked hardware watchpoints. */
10863 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10865 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10867 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10868 bl
->watchpoint_type
);
10871 /* Implement the "resources_needed" breakpoint_ops method for
10872 masked hardware watchpoints. */
10875 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10877 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10879 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10882 /* Implement the "works_in_software_mode" breakpoint_ops method for
10883 masked hardware watchpoints. */
10886 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10891 /* Implement the "print_it" breakpoint_ops method for
10892 masked hardware watchpoints. */
10894 static enum print_stop_action
10895 print_it_masked_watchpoint (bpstat bs
)
10897 struct breakpoint
*b
= bs
->breakpoint_at
;
10898 struct ui_out
*uiout
= current_uiout
;
10900 /* Masked watchpoints have only one location. */
10901 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10903 annotate_watchpoint (b
->number
);
10904 maybe_print_thread_hit_breakpoint (uiout
);
10908 case bp_hardware_watchpoint
:
10909 if (uiout
->is_mi_like_p ())
10910 uiout
->field_string
10911 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10914 case bp_read_watchpoint
:
10915 if (uiout
->is_mi_like_p ())
10916 uiout
->field_string
10917 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10920 case bp_access_watchpoint
:
10921 if (uiout
->is_mi_like_p ())
10922 uiout
->field_string
10924 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10927 internal_error (__FILE__
, __LINE__
,
10928 _("Invalid hardware watchpoint type."));
10932 uiout
->text (_("\n\
10933 Check the underlying instruction at PC for the memory\n\
10934 address and value which triggered this watchpoint.\n"));
10935 uiout
->text ("\n");
10937 /* More than one watchpoint may have been triggered. */
10938 return PRINT_UNKNOWN
;
10941 /* Implement the "print_one_detail" breakpoint_ops method for
10942 masked hardware watchpoints. */
10945 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10946 struct ui_out
*uiout
)
10948 struct watchpoint
*w
= (struct watchpoint
*) b
;
10950 /* Masked watchpoints have only one location. */
10951 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10953 uiout
->text ("\tmask ");
10954 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10955 uiout
->text ("\n");
10958 /* Implement the "print_mention" breakpoint_ops method for
10959 masked hardware watchpoints. */
10962 print_mention_masked_watchpoint (struct breakpoint
*b
)
10964 struct watchpoint
*w
= (struct watchpoint
*) b
;
10965 struct ui_out
*uiout
= current_uiout
;
10966 const char *tuple_name
;
10970 case bp_hardware_watchpoint
:
10971 uiout
->text ("Masked hardware watchpoint ");
10972 tuple_name
= "wpt";
10974 case bp_read_watchpoint
:
10975 uiout
->text ("Masked hardware read watchpoint ");
10976 tuple_name
= "hw-rwpt";
10978 case bp_access_watchpoint
:
10979 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10980 tuple_name
= "hw-awpt";
10983 internal_error (__FILE__
, __LINE__
,
10984 _("Invalid hardware watchpoint type."));
10987 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10988 uiout
->field_int ("number", b
->number
);
10989 uiout
->text (": ");
10990 uiout
->field_string ("exp", w
->exp_string
);
10993 /* Implement the "print_recreate" breakpoint_ops method for
10994 masked hardware watchpoints. */
10997 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10999 struct watchpoint
*w
= (struct watchpoint
*) b
;
11004 case bp_hardware_watchpoint
:
11005 fprintf_unfiltered (fp
, "watch");
11007 case bp_read_watchpoint
:
11008 fprintf_unfiltered (fp
, "rwatch");
11010 case bp_access_watchpoint
:
11011 fprintf_unfiltered (fp
, "awatch");
11014 internal_error (__FILE__
, __LINE__
,
11015 _("Invalid hardware watchpoint type."));
11018 sprintf_vma (tmp
, w
->hw_wp_mask
);
11019 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11020 print_recreate_thread (b
, fp
);
11023 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11025 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11027 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11030 is_masked_watchpoint (const struct breakpoint
*b
)
11032 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11035 /* accessflag: hw_write: watch write,
11036 hw_read: watch read,
11037 hw_access: watch access (read or write) */
11039 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11040 int just_location
, int internal
)
11042 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11043 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11044 struct value
*val
, *mark
, *result
;
11045 int saved_bitpos
= 0, saved_bitsize
= 0;
11046 const char *exp_start
= NULL
;
11047 const char *exp_end
= NULL
;
11048 const char *tok
, *end_tok
;
11050 const char *cond_start
= NULL
;
11051 const char *cond_end
= NULL
;
11052 enum bptype bp_type
;
11055 /* Flag to indicate whether we are going to use masks for
11056 the hardware watchpoint. */
11058 CORE_ADDR mask
= 0;
11059 struct watchpoint
*w
;
11061 struct cleanup
*back_to
;
11063 /* Make sure that we actually have parameters to parse. */
11064 if (arg
!= NULL
&& arg
[0] != '\0')
11066 const char *value_start
;
11068 exp_end
= arg
+ strlen (arg
);
11070 /* Look for "parameter value" pairs at the end
11071 of the arguments string. */
11072 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11074 /* Skip whitespace at the end of the argument list. */
11075 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11078 /* Find the beginning of the last token.
11079 This is the value of the parameter. */
11080 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11082 value_start
= tok
+ 1;
11084 /* Skip whitespace. */
11085 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11090 /* Find the beginning of the second to last token.
11091 This is the parameter itself. */
11092 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11095 toklen
= end_tok
- tok
+ 1;
11097 if (toklen
== 6 && startswith (tok
, "thread"))
11099 struct thread_info
*thr
;
11100 /* At this point we've found a "thread" token, which means
11101 the user is trying to set a watchpoint that triggers
11102 only in a specific thread. */
11106 error(_("You can specify only one thread."));
11108 /* Extract the thread ID from the next token. */
11109 thr
= parse_thread_id (value_start
, &endp
);
11111 /* Check if the user provided a valid thread ID. */
11112 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11113 invalid_thread_id_error (value_start
);
11115 thread
= thr
->global_num
;
11117 else if (toklen
== 4 && startswith (tok
, "mask"))
11119 /* We've found a "mask" token, which means the user wants to
11120 create a hardware watchpoint that is going to have the mask
11122 struct value
*mask_value
, *mark
;
11125 error(_("You can specify only one mask."));
11127 use_mask
= just_location
= 1;
11129 mark
= value_mark ();
11130 mask_value
= parse_to_comma_and_eval (&value_start
);
11131 mask
= value_as_address (mask_value
);
11132 value_free_to_mark (mark
);
11135 /* We didn't recognize what we found. We should stop here. */
11138 /* Truncate the string and get rid of the "parameter value" pair before
11139 the arguments string is parsed by the parse_exp_1 function. */
11146 /* Parse the rest of the arguments. From here on out, everything
11147 is in terms of a newly allocated string instead of the original
11149 innermost_block
= NULL
;
11150 expression
= savestring (arg
, exp_end
- arg
);
11151 back_to
= make_cleanup (xfree
, expression
);
11152 exp_start
= arg
= expression
;
11153 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11155 /* Remove trailing whitespace from the expression before saving it.
11156 This makes the eventual display of the expression string a bit
11158 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11161 /* Checking if the expression is not constant. */
11162 if (watchpoint_exp_is_const (exp
.get ()))
11166 len
= exp_end
- exp_start
;
11167 while (len
> 0 && isspace (exp_start
[len
- 1]))
11169 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11172 exp_valid_block
= innermost_block
;
11173 mark
= value_mark ();
11174 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11176 if (val
!= NULL
&& just_location
)
11178 saved_bitpos
= value_bitpos (val
);
11179 saved_bitsize
= value_bitsize (val
);
11186 exp_valid_block
= NULL
;
11187 val
= value_addr (result
);
11188 release_value (val
);
11189 value_free_to_mark (mark
);
11193 ret
= target_masked_watch_num_registers (value_as_address (val
),
11196 error (_("This target does not support masked watchpoints."));
11197 else if (ret
== -2)
11198 error (_("Invalid mask or memory region."));
11201 else if (val
!= NULL
)
11202 release_value (val
);
11204 tok
= skip_spaces_const (arg
);
11205 end_tok
= skip_to_space_const (tok
);
11207 toklen
= end_tok
- tok
;
11208 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11210 innermost_block
= NULL
;
11211 tok
= cond_start
= end_tok
+ 1;
11212 parse_exp_1 (&tok
, 0, 0, 0);
11214 /* The watchpoint expression may not be local, but the condition
11215 may still be. E.g.: `watch global if local > 0'. */
11216 cond_exp_valid_block
= innermost_block
;
11221 error (_("Junk at end of command."));
11223 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11225 /* Save this because create_internal_breakpoint below invalidates
11227 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11229 /* If the expression is "local", then set up a "watchpoint scope"
11230 breakpoint at the point where we've left the scope of the watchpoint
11231 expression. Create the scope breakpoint before the watchpoint, so
11232 that we will encounter it first in bpstat_stop_status. */
11233 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11235 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11237 if (frame_id_p (caller_frame_id
))
11239 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11240 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11243 = create_internal_breakpoint (caller_arch
, caller_pc
,
11244 bp_watchpoint_scope
,
11245 &momentary_breakpoint_ops
);
11247 /* create_internal_breakpoint could invalidate WP_FRAME. */
11250 scope_breakpoint
->enable_state
= bp_enabled
;
11252 /* Automatically delete the breakpoint when it hits. */
11253 scope_breakpoint
->disposition
= disp_del
;
11255 /* Only break in the proper frame (help with recursion). */
11256 scope_breakpoint
->frame_id
= caller_frame_id
;
11258 /* Set the address at which we will stop. */
11259 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11260 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11261 scope_breakpoint
->loc
->address
11262 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11263 scope_breakpoint
->loc
->requested_address
,
11264 scope_breakpoint
->type
);
11268 /* Now set up the breakpoint. We create all watchpoints as hardware
11269 watchpoints here even if hardware watchpoints are turned off, a call
11270 to update_watchpoint later in this function will cause the type to
11271 drop back to bp_watchpoint (software watchpoint) if required. */
11273 if (accessflag
== hw_read
)
11274 bp_type
= bp_read_watchpoint
;
11275 else if (accessflag
== hw_access
)
11276 bp_type
= bp_access_watchpoint
;
11278 bp_type
= bp_hardware_watchpoint
;
11280 w
= new watchpoint ();
11283 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11284 &masked_watchpoint_breakpoint_ops
);
11286 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11287 &watchpoint_breakpoint_ops
);
11288 b
->thread
= thread
;
11289 b
->disposition
= disp_donttouch
;
11290 b
->pspace
= current_program_space
;
11291 w
->exp
= std::move (exp
);
11292 w
->exp_valid_block
= exp_valid_block
;
11293 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11296 struct type
*t
= value_type (val
);
11297 CORE_ADDR addr
= value_as_address (val
);
11299 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11301 std::string name
= type_to_string (t
);
11303 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
.c_str (),
11304 core_addr_to_string (addr
));
11306 w
->exp_string
= xstrprintf ("-location %.*s",
11307 (int) (exp_end
- exp_start
), exp_start
);
11309 /* The above expression is in C. */
11310 b
->language
= language_c
;
11313 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11317 w
->hw_wp_mask
= mask
;
11322 w
->val_bitpos
= saved_bitpos
;
11323 w
->val_bitsize
= saved_bitsize
;
11328 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11330 b
->cond_string
= 0;
11332 if (frame_id_p (watchpoint_frame
))
11334 w
->watchpoint_frame
= watchpoint_frame
;
11335 w
->watchpoint_thread
= inferior_ptid
;
11339 w
->watchpoint_frame
= null_frame_id
;
11340 w
->watchpoint_thread
= null_ptid
;
11343 if (scope_breakpoint
!= NULL
)
11345 /* The scope breakpoint is related to the watchpoint. We will
11346 need to act on them together. */
11347 b
->related_breakpoint
= scope_breakpoint
;
11348 scope_breakpoint
->related_breakpoint
= b
;
11351 if (!just_location
)
11352 value_free_to_mark (mark
);
11356 /* Finally update the new watchpoint. This creates the locations
11357 that should be inserted. */
11358 update_watchpoint (w
, 1);
11360 CATCH (e
, RETURN_MASK_ALL
)
11362 delete_breakpoint (b
);
11363 throw_exception (e
);
11367 install_breakpoint (internal
, b
, 1);
11368 do_cleanups (back_to
);
11371 /* Return count of debug registers needed to watch the given expression.
11372 If the watchpoint cannot be handled in hardware return zero. */
11375 can_use_hardware_watchpoint (struct value
*v
)
11377 int found_memory_cnt
= 0;
11378 struct value
*head
= v
;
11380 /* Did the user specifically forbid us to use hardware watchpoints? */
11381 if (!can_use_hw_watchpoints
)
11384 /* Make sure that the value of the expression depends only upon
11385 memory contents, and values computed from them within GDB. If we
11386 find any register references or function calls, we can't use a
11387 hardware watchpoint.
11389 The idea here is that evaluating an expression generates a series
11390 of values, one holding the value of every subexpression. (The
11391 expression a*b+c has five subexpressions: a, b, a*b, c, and
11392 a*b+c.) GDB's values hold almost enough information to establish
11393 the criteria given above --- they identify memory lvalues,
11394 register lvalues, computed values, etcetera. So we can evaluate
11395 the expression, and then scan the chain of values that leaves
11396 behind to decide whether we can detect any possible change to the
11397 expression's final value using only hardware watchpoints.
11399 However, I don't think that the values returned by inferior
11400 function calls are special in any way. So this function may not
11401 notice that an expression involving an inferior function call
11402 can't be watched with hardware watchpoints. FIXME. */
11403 for (; v
; v
= value_next (v
))
11405 if (VALUE_LVAL (v
) == lval_memory
)
11407 if (v
!= head
&& value_lazy (v
))
11408 /* A lazy memory lvalue in the chain is one that GDB never
11409 needed to fetch; we either just used its address (e.g.,
11410 `a' in `a.b') or we never needed it at all (e.g., `a'
11411 in `a,b'). This doesn't apply to HEAD; if that is
11412 lazy then it was not readable, but watch it anyway. */
11416 /* Ahh, memory we actually used! Check if we can cover
11417 it with hardware watchpoints. */
11418 struct type
*vtype
= check_typedef (value_type (v
));
11420 /* We only watch structs and arrays if user asked for it
11421 explicitly, never if they just happen to appear in a
11422 middle of some value chain. */
11424 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11425 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11427 CORE_ADDR vaddr
= value_address (v
);
11431 len
= (target_exact_watchpoints
11432 && is_scalar_type_recursive (vtype
))?
11433 1 : TYPE_LENGTH (value_type (v
));
11435 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11439 found_memory_cnt
+= num_regs
;
11443 else if (VALUE_LVAL (v
) != not_lval
11444 && deprecated_value_modifiable (v
) == 0)
11445 return 0; /* These are values from the history (e.g., $1). */
11446 else if (VALUE_LVAL (v
) == lval_register
)
11447 return 0; /* Cannot watch a register with a HW watchpoint. */
11450 /* The expression itself looks suitable for using a hardware
11451 watchpoint, but give the target machine a chance to reject it. */
11452 return found_memory_cnt
;
11456 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11458 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11461 /* A helper function that looks for the "-location" argument and then
11462 calls watch_command_1. */
11465 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11467 int just_location
= 0;
11470 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11471 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11473 arg
= skip_spaces (arg
);
11477 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11481 watch_command (char *arg
, int from_tty
)
11483 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11487 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11489 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11493 rwatch_command (char *arg
, int from_tty
)
11495 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11499 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11501 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11505 awatch_command (char *arg
, int from_tty
)
11507 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11511 /* Data for the FSM that manages the until(location)/advance commands
11512 in infcmd.c. Here because it uses the mechanisms of
11515 struct until_break_fsm
11517 /* The base class. */
11518 struct thread_fsm thread_fsm
;
11520 /* The thread that as current when the command was executed. */
11523 /* The breakpoint set at the destination location. */
11524 struct breakpoint
*location_breakpoint
;
11526 /* Breakpoint set at the return address in the caller frame. May be
11528 struct breakpoint
*caller_breakpoint
;
11531 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11532 struct thread_info
*thread
);
11533 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11534 struct thread_info
*thread
);
11535 static enum async_reply_reason
11536 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11538 /* until_break_fsm's vtable. */
11540 static struct thread_fsm_ops until_break_fsm_ops
=
11543 until_break_fsm_clean_up
,
11544 until_break_fsm_should_stop
,
11545 NULL
, /* return_value */
11546 until_break_fsm_async_reply_reason
,
11549 /* Allocate a new until_break_command_fsm. */
11551 static struct until_break_fsm
*
11552 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11553 struct breakpoint
*location_breakpoint
,
11554 struct breakpoint
*caller_breakpoint
)
11556 struct until_break_fsm
*sm
;
11558 sm
= XCNEW (struct until_break_fsm
);
11559 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11561 sm
->thread
= thread
;
11562 sm
->location_breakpoint
= location_breakpoint
;
11563 sm
->caller_breakpoint
= caller_breakpoint
;
11568 /* Implementation of the 'should_stop' FSM method for the
11569 until(location)/advance commands. */
11572 until_break_fsm_should_stop (struct thread_fsm
*self
,
11573 struct thread_info
*tp
)
11575 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11577 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11578 sm
->location_breakpoint
) != NULL
11579 || (sm
->caller_breakpoint
!= NULL
11580 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11581 sm
->caller_breakpoint
) != NULL
))
11582 thread_fsm_set_finished (self
);
11587 /* Implementation of the 'clean_up' FSM method for the
11588 until(location)/advance commands. */
11591 until_break_fsm_clean_up (struct thread_fsm
*self
,
11592 struct thread_info
*thread
)
11594 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11596 /* Clean up our temporary breakpoints. */
11597 if (sm
->location_breakpoint
!= NULL
)
11599 delete_breakpoint (sm
->location_breakpoint
);
11600 sm
->location_breakpoint
= NULL
;
11602 if (sm
->caller_breakpoint
!= NULL
)
11604 delete_breakpoint (sm
->caller_breakpoint
);
11605 sm
->caller_breakpoint
= NULL
;
11607 delete_longjmp_breakpoint (sm
->thread
);
11610 /* Implementation of the 'async_reply_reason' FSM method for the
11611 until(location)/advance commands. */
11613 static enum async_reply_reason
11614 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11616 return EXEC_ASYNC_LOCATION_REACHED
;
11620 until_break_command (char *arg
, int from_tty
, int anywhere
)
11622 struct symtabs_and_lines sals
;
11623 struct symtab_and_line sal
;
11624 struct frame_info
*frame
;
11625 struct gdbarch
*frame_gdbarch
;
11626 struct frame_id stack_frame_id
;
11627 struct frame_id caller_frame_id
;
11628 struct breakpoint
*location_breakpoint
;
11629 struct breakpoint
*caller_breakpoint
= NULL
;
11630 struct cleanup
*old_chain
;
11632 struct thread_info
*tp
;
11633 struct until_break_fsm
*sm
;
11635 clear_proceed_status (0);
11637 /* Set a breakpoint where the user wants it and at return from
11640 event_location_up location
= string_to_event_location (&arg
, current_language
);
11642 if (last_displayed_sal_is_valid ())
11643 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11644 get_last_displayed_symtab (),
11645 get_last_displayed_line ());
11647 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11648 NULL
, (struct symtab
*) NULL
, 0);
11650 if (sals
.nelts
!= 1)
11651 error (_("Couldn't get information on specified line."));
11653 sal
= sals
.sals
[0];
11654 xfree (sals
.sals
); /* malloc'd, so freed. */
11657 error (_("Junk at end of arguments."));
11659 resolve_sal_pc (&sal
);
11661 tp
= inferior_thread ();
11662 thread
= tp
->global_num
;
11664 old_chain
= make_cleanup (null_cleanup
, NULL
);
11666 /* Note linespec handling above invalidates the frame chain.
11667 Installing a breakpoint also invalidates the frame chain (as it
11668 may need to switch threads), so do any frame handling before
11671 frame
= get_selected_frame (NULL
);
11672 frame_gdbarch
= get_frame_arch (frame
);
11673 stack_frame_id
= get_stack_frame_id (frame
);
11674 caller_frame_id
= frame_unwind_caller_id (frame
);
11676 /* Keep within the current frame, or in frames called by the current
11679 if (frame_id_p (caller_frame_id
))
11681 struct symtab_and_line sal2
;
11682 struct gdbarch
*caller_gdbarch
;
11684 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11685 sal2
.pc
= frame_unwind_caller_pc (frame
);
11686 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11687 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11691 make_cleanup_delete_breakpoint (caller_breakpoint
);
11693 set_longjmp_breakpoint (tp
, caller_frame_id
);
11694 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11697 /* set_momentary_breakpoint could invalidate FRAME. */
11701 /* If the user told us to continue until a specified location,
11702 we don't specify a frame at which we need to stop. */
11703 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11704 null_frame_id
, bp_until
);
11706 /* Otherwise, specify the selected frame, because we want to stop
11707 only at the very same frame. */
11708 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11709 stack_frame_id
, bp_until
);
11710 make_cleanup_delete_breakpoint (location_breakpoint
);
11712 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11713 location_breakpoint
, caller_breakpoint
);
11714 tp
->thread_fsm
= &sm
->thread_fsm
;
11716 discard_cleanups (old_chain
);
11718 proceed (-1, GDB_SIGNAL_DEFAULT
);
11721 /* This function attempts to parse an optional "if <cond>" clause
11722 from the arg string. If one is not found, it returns NULL.
11724 Else, it returns a pointer to the condition string. (It does not
11725 attempt to evaluate the string against a particular block.) And,
11726 it updates arg to point to the first character following the parsed
11727 if clause in the arg string. */
11730 ep_parse_optional_if_clause (const char **arg
)
11732 const char *cond_string
;
11734 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11737 /* Skip the "if" keyword. */
11740 /* Skip any extra leading whitespace, and record the start of the
11741 condition string. */
11742 *arg
= skip_spaces_const (*arg
);
11743 cond_string
= *arg
;
11745 /* Assume that the condition occupies the remainder of the arg
11747 (*arg
) += strlen (cond_string
);
11749 return cond_string
;
11752 /* Commands to deal with catching events, such as signals, exceptions,
11753 process start/exit, etc. */
11757 catch_fork_temporary
, catch_vfork_temporary
,
11758 catch_fork_permanent
, catch_vfork_permanent
11763 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11764 struct cmd_list_element
*command
)
11766 const char *arg
= arg_entry
;
11767 struct gdbarch
*gdbarch
= get_current_arch ();
11768 const char *cond_string
= NULL
;
11769 catch_fork_kind fork_kind
;
11772 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11773 tempflag
= (fork_kind
== catch_fork_temporary
11774 || fork_kind
== catch_vfork_temporary
);
11778 arg
= skip_spaces_const (arg
);
11780 /* The allowed syntax is:
11782 catch [v]fork if <cond>
11784 First, check if there's an if clause. */
11785 cond_string
= ep_parse_optional_if_clause (&arg
);
11787 if ((*arg
!= '\0') && !isspace (*arg
))
11788 error (_("Junk at end of arguments."));
11790 /* If this target supports it, create a fork or vfork catchpoint
11791 and enable reporting of such events. */
11794 case catch_fork_temporary
:
11795 case catch_fork_permanent
:
11796 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11797 &catch_fork_breakpoint_ops
);
11799 case catch_vfork_temporary
:
11800 case catch_vfork_permanent
:
11801 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11802 &catch_vfork_breakpoint_ops
);
11805 error (_("unsupported or unknown fork kind; cannot catch it"));
11811 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11812 struct cmd_list_element
*command
)
11814 const char *arg
= arg_entry
;
11815 struct exec_catchpoint
*c
;
11816 struct gdbarch
*gdbarch
= get_current_arch ();
11818 const char *cond_string
= NULL
;
11820 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11824 arg
= skip_spaces_const (arg
);
11826 /* The allowed syntax is:
11828 catch exec if <cond>
11830 First, check if there's an if clause. */
11831 cond_string
= ep_parse_optional_if_clause (&arg
);
11833 if ((*arg
!= '\0') && !isspace (*arg
))
11834 error (_("Junk at end of arguments."));
11836 c
= new exec_catchpoint ();
11837 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11838 &catch_exec_breakpoint_ops
);
11839 c
->exec_pathname
= NULL
;
11841 install_breakpoint (0, &c
->base
, 1);
11845 init_ada_exception_breakpoint (struct breakpoint
*b
,
11846 struct gdbarch
*gdbarch
,
11847 struct symtab_and_line sal
,
11849 const struct breakpoint_ops
*ops
,
11856 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11858 loc_gdbarch
= gdbarch
;
11860 describe_other_breakpoints (loc_gdbarch
,
11861 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11862 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11863 version for exception catchpoints, because two catchpoints
11864 used for different exception names will use the same address.
11865 In this case, a "breakpoint ... also set at..." warning is
11866 unproductive. Besides, the warning phrasing is also a bit
11867 inappropriate, we should use the word catchpoint, and tell
11868 the user what type of catchpoint it is. The above is good
11869 enough for now, though. */
11872 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11874 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11875 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11876 b
->location
= string_to_event_location (&addr_string
,
11877 language_def (language_ada
));
11878 b
->language
= language_ada
;
11882 catch_command (char *arg
, int from_tty
)
11884 error (_("Catch requires an event name."));
11889 tcatch_command (char *arg
, int from_tty
)
11891 error (_("Catch requires an event name."));
11894 /* A qsort comparison function that sorts breakpoints in order. */
11897 compare_breakpoints (const void *a
, const void *b
)
11899 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11900 uintptr_t ua
= (uintptr_t) *ba
;
11901 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11902 uintptr_t ub
= (uintptr_t) *bb
;
11904 if ((*ba
)->number
< (*bb
)->number
)
11906 else if ((*ba
)->number
> (*bb
)->number
)
11909 /* Now sort by address, in case we see, e..g, two breakpoints with
11913 return ua
> ub
? 1 : 0;
11916 /* Delete breakpoints by address or line. */
11919 clear_command (char *arg
, int from_tty
)
11921 struct breakpoint
*b
, *prev
;
11922 VEC(breakpoint_p
) *found
= 0;
11925 struct symtabs_and_lines sals
;
11926 struct symtab_and_line sal
;
11928 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11932 sals
= decode_line_with_current_source (arg
,
11933 (DECODE_LINE_FUNFIRSTLINE
11934 | DECODE_LINE_LIST_MODE
));
11935 make_cleanup (xfree
, sals
.sals
);
11940 sals
.sals
= XNEW (struct symtab_and_line
);
11941 make_cleanup (xfree
, sals
.sals
);
11942 init_sal (&sal
); /* Initialize to zeroes. */
11944 /* Set sal's line, symtab, pc, and pspace to the values
11945 corresponding to the last call to print_frame_info. If the
11946 codepoint is not valid, this will set all the fields to 0. */
11947 get_last_displayed_sal (&sal
);
11948 if (sal
.symtab
== 0)
11949 error (_("No source file specified."));
11951 sals
.sals
[0] = sal
;
11957 /* We don't call resolve_sal_pc here. That's not as bad as it
11958 seems, because all existing breakpoints typically have both
11959 file/line and pc set. So, if clear is given file/line, we can
11960 match this to existing breakpoint without obtaining pc at all.
11962 We only support clearing given the address explicitly
11963 present in breakpoint table. Say, we've set breakpoint
11964 at file:line. There were several PC values for that file:line,
11965 due to optimization, all in one block.
11967 We've picked one PC value. If "clear" is issued with another
11968 PC corresponding to the same file:line, the breakpoint won't
11969 be cleared. We probably can still clear the breakpoint, but
11970 since the other PC value is never presented to user, user
11971 can only find it by guessing, and it does not seem important
11972 to support that. */
11974 /* For each line spec given, delete bps which correspond to it. Do
11975 it in two passes, solely to preserve the current behavior that
11976 from_tty is forced true if we delete more than one
11980 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11981 for (i
= 0; i
< sals
.nelts
; i
++)
11983 const char *sal_fullname
;
11985 /* If exact pc given, clear bpts at that pc.
11986 If line given (pc == 0), clear all bpts on specified line.
11987 If defaulting, clear all bpts on default line
11990 defaulting sal.pc != 0 tests to do
11995 1 0 <can't happen> */
11997 sal
= sals
.sals
[i
];
11998 sal_fullname
= (sal
.symtab
== NULL
11999 ? NULL
: symtab_to_fullname (sal
.symtab
));
12001 /* Find all matching breakpoints and add them to 'found'. */
12002 ALL_BREAKPOINTS (b
)
12005 /* Are we going to delete b? */
12006 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12008 struct bp_location
*loc
= b
->loc
;
12009 for (; loc
; loc
= loc
->next
)
12011 /* If the user specified file:line, don't allow a PC
12012 match. This matches historical gdb behavior. */
12013 int pc_match
= (!sal
.explicit_line
12015 && (loc
->pspace
== sal
.pspace
)
12016 && (loc
->address
== sal
.pc
)
12017 && (!section_is_overlay (loc
->section
)
12018 || loc
->section
== sal
.section
));
12019 int line_match
= 0;
12021 if ((default_match
|| sal
.explicit_line
)
12022 && loc
->symtab
!= NULL
12023 && sal_fullname
!= NULL
12024 && sal
.pspace
== loc
->pspace
12025 && loc
->line_number
== sal
.line
12026 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12027 sal_fullname
) == 0)
12030 if (pc_match
|| line_match
)
12039 VEC_safe_push(breakpoint_p
, found
, b
);
12043 /* Now go thru the 'found' chain and delete them. */
12044 if (VEC_empty(breakpoint_p
, found
))
12047 error (_("No breakpoint at %s."), arg
);
12049 error (_("No breakpoint at this line."));
12052 /* Remove duplicates from the vec. */
12053 qsort (VEC_address (breakpoint_p
, found
),
12054 VEC_length (breakpoint_p
, found
),
12055 sizeof (breakpoint_p
),
12056 compare_breakpoints
);
12057 prev
= VEC_index (breakpoint_p
, found
, 0);
12058 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12062 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12067 if (VEC_length(breakpoint_p
, found
) > 1)
12068 from_tty
= 1; /* Always report if deleted more than one. */
12071 if (VEC_length(breakpoint_p
, found
) == 1)
12072 printf_unfiltered (_("Deleted breakpoint "));
12074 printf_unfiltered (_("Deleted breakpoints "));
12077 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12080 printf_unfiltered ("%d ", b
->number
);
12081 delete_breakpoint (b
);
12084 putchar_unfiltered ('\n');
12086 do_cleanups (cleanups
);
12089 /* Delete breakpoint in BS if they are `delete' breakpoints and
12090 all breakpoints that are marked for deletion, whether hit or not.
12091 This is called after any breakpoint is hit, or after errors. */
12094 breakpoint_auto_delete (bpstat bs
)
12096 struct breakpoint
*b
, *b_tmp
;
12098 for (; bs
; bs
= bs
->next
)
12099 if (bs
->breakpoint_at
12100 && bs
->breakpoint_at
->disposition
== disp_del
12102 delete_breakpoint (bs
->breakpoint_at
);
12104 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12106 if (b
->disposition
== disp_del_at_next_stop
)
12107 delete_breakpoint (b
);
12111 /* A comparison function for bp_location AP and BP being interfaced to
12112 qsort. Sort elements primarily by their ADDRESS (no matter what
12113 does breakpoint_address_is_meaningful say for its OWNER),
12114 secondarily by ordering first permanent elements and
12115 terciarily just ensuring the array is sorted stable way despite
12116 qsort being an unstable algorithm. */
12119 bp_locations_compare (const void *ap
, const void *bp
)
12121 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12122 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12124 if (a
->address
!= b
->address
)
12125 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12127 /* Sort locations at the same address by their pspace number, keeping
12128 locations of the same inferior (in a multi-inferior environment)
12131 if (a
->pspace
->num
!= b
->pspace
->num
)
12132 return ((a
->pspace
->num
> b
->pspace
->num
)
12133 - (a
->pspace
->num
< b
->pspace
->num
));
12135 /* Sort permanent breakpoints first. */
12136 if (a
->permanent
!= b
->permanent
)
12137 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12139 /* Make the internal GDB representation stable across GDB runs
12140 where A and B memory inside GDB can differ. Breakpoint locations of
12141 the same type at the same address can be sorted in arbitrary order. */
12143 if (a
->owner
->number
!= b
->owner
->number
)
12144 return ((a
->owner
->number
> b
->owner
->number
)
12145 - (a
->owner
->number
< b
->owner
->number
));
12147 return (a
> b
) - (a
< b
);
12150 /* Set bp_locations_placed_address_before_address_max and
12151 bp_locations_shadow_len_after_address_max according to the current
12152 content of the bp_locations array. */
12155 bp_locations_target_extensions_update (void)
12157 struct bp_location
*bl
, **blp_tmp
;
12159 bp_locations_placed_address_before_address_max
= 0;
12160 bp_locations_shadow_len_after_address_max
= 0;
12162 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12164 CORE_ADDR start
, end
, addr
;
12166 if (!bp_location_has_shadow (bl
))
12169 start
= bl
->target_info
.placed_address
;
12170 end
= start
+ bl
->target_info
.shadow_len
;
12172 gdb_assert (bl
->address
>= start
);
12173 addr
= bl
->address
- start
;
12174 if (addr
> bp_locations_placed_address_before_address_max
)
12175 bp_locations_placed_address_before_address_max
= addr
;
12177 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12179 gdb_assert (bl
->address
< end
);
12180 addr
= end
- bl
->address
;
12181 if (addr
> bp_locations_shadow_len_after_address_max
)
12182 bp_locations_shadow_len_after_address_max
= addr
;
12186 /* Download tracepoint locations if they haven't been. */
12189 download_tracepoint_locations (void)
12191 struct breakpoint
*b
;
12192 struct cleanup
*old_chain
;
12193 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12195 old_chain
= save_current_space_and_thread ();
12197 ALL_TRACEPOINTS (b
)
12199 struct bp_location
*bl
;
12200 struct tracepoint
*t
;
12201 int bp_location_downloaded
= 0;
12203 if ((b
->type
== bp_fast_tracepoint
12204 ? !may_insert_fast_tracepoints
12205 : !may_insert_tracepoints
))
12208 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12210 if (target_can_download_tracepoint ())
12211 can_download_tracepoint
= TRIBOOL_TRUE
;
12213 can_download_tracepoint
= TRIBOOL_FALSE
;
12216 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12219 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12221 /* In tracepoint, locations are _never_ duplicated, so
12222 should_be_inserted is equivalent to
12223 unduplicated_should_be_inserted. */
12224 if (!should_be_inserted (bl
) || bl
->inserted
)
12227 switch_to_program_space_and_thread (bl
->pspace
);
12229 target_download_tracepoint (bl
);
12232 bp_location_downloaded
= 1;
12234 t
= (struct tracepoint
*) b
;
12235 t
->number_on_target
= b
->number
;
12236 if (bp_location_downloaded
)
12237 observer_notify_breakpoint_modified (b
);
12240 do_cleanups (old_chain
);
12243 /* Swap the insertion/duplication state between two locations. */
12246 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12248 const int left_inserted
= left
->inserted
;
12249 const int left_duplicate
= left
->duplicate
;
12250 const int left_needs_update
= left
->needs_update
;
12251 const struct bp_target_info left_target_info
= left
->target_info
;
12253 /* Locations of tracepoints can never be duplicated. */
12254 if (is_tracepoint (left
->owner
))
12255 gdb_assert (!left
->duplicate
);
12256 if (is_tracepoint (right
->owner
))
12257 gdb_assert (!right
->duplicate
);
12259 left
->inserted
= right
->inserted
;
12260 left
->duplicate
= right
->duplicate
;
12261 left
->needs_update
= right
->needs_update
;
12262 left
->target_info
= right
->target_info
;
12263 right
->inserted
= left_inserted
;
12264 right
->duplicate
= left_duplicate
;
12265 right
->needs_update
= left_needs_update
;
12266 right
->target_info
= left_target_info
;
12269 /* Force the re-insertion of the locations at ADDRESS. This is called
12270 once a new/deleted/modified duplicate location is found and we are evaluating
12271 conditions on the target's side. Such conditions need to be updated on
12275 force_breakpoint_reinsertion (struct bp_location
*bl
)
12277 struct bp_location
**locp
= NULL
, **loc2p
;
12278 struct bp_location
*loc
;
12279 CORE_ADDR address
= 0;
12282 address
= bl
->address
;
12283 pspace_num
= bl
->pspace
->num
;
12285 /* This is only meaningful if the target is
12286 evaluating conditions and if the user has
12287 opted for condition evaluation on the target's
12289 if (gdb_evaluates_breakpoint_condition_p ()
12290 || !target_supports_evaluation_of_breakpoint_conditions ())
12293 /* Flag all breakpoint locations with this address and
12294 the same program space as the location
12295 as "its condition has changed". We need to
12296 update the conditions on the target's side. */
12297 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12301 if (!is_breakpoint (loc
->owner
)
12302 || pspace_num
!= loc
->pspace
->num
)
12305 /* Flag the location appropriately. We use a different state to
12306 let everyone know that we already updated the set of locations
12307 with addr bl->address and program space bl->pspace. This is so
12308 we don't have to keep calling these functions just to mark locations
12309 that have already been marked. */
12310 loc
->condition_changed
= condition_updated
;
12312 /* Free the agent expression bytecode as well. We will compute
12314 loc
->cond_bytecode
.reset ();
12317 /* Called whether new breakpoints are created, or existing breakpoints
12318 deleted, to update the global location list and recompute which
12319 locations are duplicate of which.
12321 The INSERT_MODE flag determines whether locations may not, may, or
12322 shall be inserted now. See 'enum ugll_insert_mode' for more
12326 update_global_location_list (enum ugll_insert_mode insert_mode
)
12328 struct breakpoint
*b
;
12329 struct bp_location
**locp
, *loc
;
12330 struct cleanup
*cleanups
;
12331 /* Last breakpoint location address that was marked for update. */
12332 CORE_ADDR last_addr
= 0;
12333 /* Last breakpoint location program space that was marked for update. */
12334 int last_pspace_num
= -1;
12336 /* Used in the duplicates detection below. When iterating over all
12337 bp_locations, points to the first bp_location of a given address.
12338 Breakpoints and watchpoints of different types are never
12339 duplicates of each other. Keep one pointer for each type of
12340 breakpoint/watchpoint, so we only need to loop over all locations
12342 struct bp_location
*bp_loc_first
; /* breakpoint */
12343 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12344 struct bp_location
*awp_loc_first
; /* access watchpoint */
12345 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12347 /* Saved former bp_locations array which we compare against the newly
12348 built bp_locations from the current state of ALL_BREAKPOINTS. */
12349 struct bp_location
**old_locations
, **old_locp
;
12350 unsigned old_locations_count
;
12352 old_locations
= bp_locations
;
12353 old_locations_count
= bp_locations_count
;
12354 bp_locations
= NULL
;
12355 bp_locations_count
= 0;
12356 cleanups
= make_cleanup (xfree
, old_locations
);
12358 ALL_BREAKPOINTS (b
)
12359 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12360 bp_locations_count
++;
12362 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12363 locp
= bp_locations
;
12364 ALL_BREAKPOINTS (b
)
12365 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12367 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12368 bp_locations_compare
);
12370 bp_locations_target_extensions_update ();
12372 /* Identify bp_location instances that are no longer present in the
12373 new list, and therefore should be freed. Note that it's not
12374 necessary that those locations should be removed from inferior --
12375 if there's another location at the same address (previously
12376 marked as duplicate), we don't need to remove/insert the
12379 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12380 and former bp_location array state respectively. */
12382 locp
= bp_locations
;
12383 for (old_locp
= old_locations
;
12384 old_locp
< old_locations
+ old_locations_count
;
12387 struct bp_location
*old_loc
= *old_locp
;
12388 struct bp_location
**loc2p
;
12390 /* Tells if 'old_loc' is found among the new locations. If
12391 not, we have to free it. */
12392 int found_object
= 0;
12393 /* Tells if the location should remain inserted in the target. */
12394 int keep_in_target
= 0;
12397 /* Skip LOCP entries which will definitely never be needed.
12398 Stop either at or being the one matching OLD_LOC. */
12399 while (locp
< bp_locations
+ bp_locations_count
12400 && (*locp
)->address
< old_loc
->address
)
12404 (loc2p
< bp_locations
+ bp_locations_count
12405 && (*loc2p
)->address
== old_loc
->address
);
12408 /* Check if this is a new/duplicated location or a duplicated
12409 location that had its condition modified. If so, we want to send
12410 its condition to the target if evaluation of conditions is taking
12412 if ((*loc2p
)->condition_changed
== condition_modified
12413 && (last_addr
!= old_loc
->address
12414 || last_pspace_num
!= old_loc
->pspace
->num
))
12416 force_breakpoint_reinsertion (*loc2p
);
12417 last_pspace_num
= old_loc
->pspace
->num
;
12420 if (*loc2p
== old_loc
)
12424 /* We have already handled this address, update it so that we don't
12425 have to go through updates again. */
12426 last_addr
= old_loc
->address
;
12428 /* Target-side condition evaluation: Handle deleted locations. */
12430 force_breakpoint_reinsertion (old_loc
);
12432 /* If this location is no longer present, and inserted, look if
12433 there's maybe a new location at the same address. If so,
12434 mark that one inserted, and don't remove this one. This is
12435 needed so that we don't have a time window where a breakpoint
12436 at certain location is not inserted. */
12438 if (old_loc
->inserted
)
12440 /* If the location is inserted now, we might have to remove
12443 if (found_object
&& should_be_inserted (old_loc
))
12445 /* The location is still present in the location list,
12446 and still should be inserted. Don't do anything. */
12447 keep_in_target
= 1;
12451 /* This location still exists, but it won't be kept in the
12452 target since it may have been disabled. We proceed to
12453 remove its target-side condition. */
12455 /* The location is either no longer present, or got
12456 disabled. See if there's another location at the
12457 same address, in which case we don't need to remove
12458 this one from the target. */
12460 /* OLD_LOC comes from existing struct breakpoint. */
12461 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12464 (loc2p
< bp_locations
+ bp_locations_count
12465 && (*loc2p
)->address
== old_loc
->address
);
12468 struct bp_location
*loc2
= *loc2p
;
12470 if (breakpoint_locations_match (loc2
, old_loc
))
12472 /* Read watchpoint locations are switched to
12473 access watchpoints, if the former are not
12474 supported, but the latter are. */
12475 if (is_hardware_watchpoint (old_loc
->owner
))
12477 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12478 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12481 /* loc2 is a duplicated location. We need to check
12482 if it should be inserted in case it will be
12484 if (loc2
!= old_loc
12485 && unduplicated_should_be_inserted (loc2
))
12487 swap_insertion (old_loc
, loc2
);
12488 keep_in_target
= 1;
12496 if (!keep_in_target
)
12498 if (remove_breakpoint (old_loc
))
12500 /* This is just about all we can do. We could keep
12501 this location on the global list, and try to
12502 remove it next time, but there's no particular
12503 reason why we will succeed next time.
12505 Note that at this point, old_loc->owner is still
12506 valid, as delete_breakpoint frees the breakpoint
12507 only after calling us. */
12508 printf_filtered (_("warning: Error removing "
12509 "breakpoint %d\n"),
12510 old_loc
->owner
->number
);
12518 if (removed
&& target_is_non_stop_p ()
12519 && need_moribund_for_location_type (old_loc
))
12521 /* This location was removed from the target. In
12522 non-stop mode, a race condition is possible where
12523 we've removed a breakpoint, but stop events for that
12524 breakpoint are already queued and will arrive later.
12525 We apply an heuristic to be able to distinguish such
12526 SIGTRAPs from other random SIGTRAPs: we keep this
12527 breakpoint location for a bit, and will retire it
12528 after we see some number of events. The theory here
12529 is that reporting of events should, "on the average",
12530 be fair, so after a while we'll see events from all
12531 threads that have anything of interest, and no longer
12532 need to keep this breakpoint location around. We
12533 don't hold locations forever so to reduce chances of
12534 mistaking a non-breakpoint SIGTRAP for a breakpoint
12537 The heuristic failing can be disastrous on
12538 decr_pc_after_break targets.
12540 On decr_pc_after_break targets, like e.g., x86-linux,
12541 if we fail to recognize a late breakpoint SIGTRAP,
12542 because events_till_retirement has reached 0 too
12543 soon, we'll fail to do the PC adjustment, and report
12544 a random SIGTRAP to the user. When the user resumes
12545 the inferior, it will most likely immediately crash
12546 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12547 corrupted, because of being resumed e.g., in the
12548 middle of a multi-byte instruction, or skipped a
12549 one-byte instruction. This was actually seen happen
12550 on native x86-linux, and should be less rare on
12551 targets that do not support new thread events, like
12552 remote, due to the heuristic depending on
12555 Mistaking a random SIGTRAP for a breakpoint trap
12556 causes similar symptoms (PC adjustment applied when
12557 it shouldn't), but then again, playing with SIGTRAPs
12558 behind the debugger's back is asking for trouble.
12560 Since hardware watchpoint traps are always
12561 distinguishable from other traps, so we don't need to
12562 apply keep hardware watchpoint moribund locations
12563 around. We simply always ignore hardware watchpoint
12564 traps we can no longer explain. */
12566 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12567 old_loc
->owner
= NULL
;
12569 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12573 old_loc
->owner
= NULL
;
12574 decref_bp_location (&old_loc
);
12579 /* Rescan breakpoints at the same address and section, marking the
12580 first one as "first" and any others as "duplicates". This is so
12581 that the bpt instruction is only inserted once. If we have a
12582 permanent breakpoint at the same place as BPT, make that one the
12583 official one, and the rest as duplicates. Permanent breakpoints
12584 are sorted first for the same address.
12586 Do the same for hardware watchpoints, but also considering the
12587 watchpoint's type (regular/access/read) and length. */
12589 bp_loc_first
= NULL
;
12590 wp_loc_first
= NULL
;
12591 awp_loc_first
= NULL
;
12592 rwp_loc_first
= NULL
;
12593 ALL_BP_LOCATIONS (loc
, locp
)
12595 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12597 struct bp_location
**loc_first_p
;
12600 if (!unduplicated_should_be_inserted (loc
)
12601 || !breakpoint_address_is_meaningful (b
)
12602 /* Don't detect duplicate for tracepoint locations because they are
12603 never duplicated. See the comments in field `duplicate' of
12604 `struct bp_location'. */
12605 || is_tracepoint (b
))
12607 /* Clear the condition modification flag. */
12608 loc
->condition_changed
= condition_unchanged
;
12612 if (b
->type
== bp_hardware_watchpoint
)
12613 loc_first_p
= &wp_loc_first
;
12614 else if (b
->type
== bp_read_watchpoint
)
12615 loc_first_p
= &rwp_loc_first
;
12616 else if (b
->type
== bp_access_watchpoint
)
12617 loc_first_p
= &awp_loc_first
;
12619 loc_first_p
= &bp_loc_first
;
12621 if (*loc_first_p
== NULL
12622 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12623 || !breakpoint_locations_match (loc
, *loc_first_p
))
12625 *loc_first_p
= loc
;
12626 loc
->duplicate
= 0;
12628 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12630 loc
->needs_update
= 1;
12631 /* Clear the condition modification flag. */
12632 loc
->condition_changed
= condition_unchanged
;
12638 /* This and the above ensure the invariant that the first location
12639 is not duplicated, and is the inserted one.
12640 All following are marked as duplicated, and are not inserted. */
12642 swap_insertion (loc
, *loc_first_p
);
12643 loc
->duplicate
= 1;
12645 /* Clear the condition modification flag. */
12646 loc
->condition_changed
= condition_unchanged
;
12649 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12651 if (insert_mode
!= UGLL_DONT_INSERT
)
12652 insert_breakpoint_locations ();
12655 /* Even though the caller told us to not insert new
12656 locations, we may still need to update conditions on the
12657 target's side of breakpoints that were already inserted
12658 if the target is evaluating breakpoint conditions. We
12659 only update conditions for locations that are marked
12661 update_inserted_breakpoint_locations ();
12665 if (insert_mode
!= UGLL_DONT_INSERT
)
12666 download_tracepoint_locations ();
12668 do_cleanups (cleanups
);
12672 breakpoint_retire_moribund (void)
12674 struct bp_location
*loc
;
12677 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12678 if (--(loc
->events_till_retirement
) == 0)
12680 decref_bp_location (&loc
);
12681 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12687 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12692 update_global_location_list (insert_mode
);
12694 CATCH (e
, RETURN_MASK_ERROR
)
12700 /* Clear BKP from a BPS. */
12703 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12707 for (bs
= bps
; bs
; bs
= bs
->next
)
12708 if (bs
->breakpoint_at
== bpt
)
12710 bs
->breakpoint_at
= NULL
;
12711 bs
->old_val
= NULL
;
12712 /* bs->commands will be freed later. */
12716 /* Callback for iterate_over_threads. */
12718 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12720 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12722 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12726 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12730 say_where (struct breakpoint
*b
)
12732 struct value_print_options opts
;
12734 get_user_print_options (&opts
);
12736 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12738 if (b
->loc
== NULL
)
12740 /* For pending locations, the output differs slightly based
12741 on b->extra_string. If this is non-NULL, it contains either
12742 a condition or dprintf arguments. */
12743 if (b
->extra_string
== NULL
)
12745 printf_filtered (_(" (%s) pending."),
12746 event_location_to_string (b
->location
.get ()));
12748 else if (b
->type
== bp_dprintf
)
12750 printf_filtered (_(" (%s,%s) pending."),
12751 event_location_to_string (b
->location
.get ()),
12756 printf_filtered (_(" (%s %s) pending."),
12757 event_location_to_string (b
->location
.get ()),
12763 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12765 printf_filtered (" at ");
12766 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12769 if (b
->loc
->symtab
!= NULL
)
12771 /* If there is a single location, we can print the location
12773 if (b
->loc
->next
== NULL
)
12774 printf_filtered (": file %s, line %d.",
12775 symtab_to_filename_for_display (b
->loc
->symtab
),
12776 b
->loc
->line_number
);
12778 /* This is not ideal, but each location may have a
12779 different file name, and this at least reflects the
12780 real situation somewhat. */
12781 printf_filtered (": %s.",
12782 event_location_to_string (b
->location
.get ()));
12787 struct bp_location
*loc
= b
->loc
;
12789 for (; loc
; loc
= loc
->next
)
12791 printf_filtered (" (%d locations)", n
);
12796 /* Default bp_location_ops methods. */
12799 bp_location_dtor (struct bp_location
*self
)
12801 xfree (self
->function_name
);
12804 static const struct bp_location_ops bp_location_ops
=
12809 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12813 base_breakpoint_dtor (struct breakpoint
*self
)
12815 decref_counted_command_line (&self
->commands
);
12816 xfree (self
->cond_string
);
12817 xfree (self
->extra_string
);
12818 xfree (self
->filter
);
12821 static struct bp_location
*
12822 base_breakpoint_allocate_location (struct breakpoint
*self
)
12824 return new bp_location (&bp_location_ops
, self
);
12828 base_breakpoint_re_set (struct breakpoint
*b
)
12830 /* Nothing to re-set. */
12833 #define internal_error_pure_virtual_called() \
12834 gdb_assert_not_reached ("pure virtual function called")
12837 base_breakpoint_insert_location (struct bp_location
*bl
)
12839 internal_error_pure_virtual_called ();
12843 base_breakpoint_remove_location (struct bp_location
*bl
,
12844 enum remove_bp_reason reason
)
12846 internal_error_pure_virtual_called ();
12850 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12851 struct address_space
*aspace
,
12853 const struct target_waitstatus
*ws
)
12855 internal_error_pure_virtual_called ();
12859 base_breakpoint_check_status (bpstat bs
)
12864 /* A "works_in_software_mode" breakpoint_ops method that just internal
12868 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12870 internal_error_pure_virtual_called ();
12873 /* A "resources_needed" breakpoint_ops method that just internal
12877 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12879 internal_error_pure_virtual_called ();
12882 static enum print_stop_action
12883 base_breakpoint_print_it (bpstat bs
)
12885 internal_error_pure_virtual_called ();
12889 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12890 struct ui_out
*uiout
)
12896 base_breakpoint_print_mention (struct breakpoint
*b
)
12898 internal_error_pure_virtual_called ();
12902 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12904 internal_error_pure_virtual_called ();
12908 base_breakpoint_create_sals_from_location
12909 (const struct event_location
*location
,
12910 struct linespec_result
*canonical
,
12911 enum bptype type_wanted
)
12913 internal_error_pure_virtual_called ();
12917 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12918 struct linespec_result
*c
,
12920 char *extra_string
,
12921 enum bptype type_wanted
,
12922 enum bpdisp disposition
,
12924 int task
, int ignore_count
,
12925 const struct breakpoint_ops
*o
,
12926 int from_tty
, int enabled
,
12927 int internal
, unsigned flags
)
12929 internal_error_pure_virtual_called ();
12933 base_breakpoint_decode_location (struct breakpoint
*b
,
12934 const struct event_location
*location
,
12935 struct program_space
*search_pspace
,
12936 struct symtabs_and_lines
*sals
)
12938 internal_error_pure_virtual_called ();
12941 /* The default 'explains_signal' method. */
12944 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12949 /* The default "after_condition_true" method. */
12952 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12954 /* Nothing to do. */
12957 struct breakpoint_ops base_breakpoint_ops
=
12959 base_breakpoint_dtor
,
12960 base_breakpoint_allocate_location
,
12961 base_breakpoint_re_set
,
12962 base_breakpoint_insert_location
,
12963 base_breakpoint_remove_location
,
12964 base_breakpoint_breakpoint_hit
,
12965 base_breakpoint_check_status
,
12966 base_breakpoint_resources_needed
,
12967 base_breakpoint_works_in_software_mode
,
12968 base_breakpoint_print_it
,
12970 base_breakpoint_print_one_detail
,
12971 base_breakpoint_print_mention
,
12972 base_breakpoint_print_recreate
,
12973 base_breakpoint_create_sals_from_location
,
12974 base_breakpoint_create_breakpoints_sal
,
12975 base_breakpoint_decode_location
,
12976 base_breakpoint_explains_signal
,
12977 base_breakpoint_after_condition_true
,
12980 /* Default breakpoint_ops methods. */
12983 bkpt_re_set (struct breakpoint
*b
)
12985 /* FIXME: is this still reachable? */
12986 if (breakpoint_event_location_empty_p (b
))
12988 /* Anything without a location can't be re-set. */
12989 delete_breakpoint (b
);
12993 breakpoint_re_set_default (b
);
12997 bkpt_insert_location (struct bp_location
*bl
)
12999 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
13001 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
13002 bl
->target_info
.placed_address
= addr
;
13004 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13005 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13007 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13011 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
13013 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13014 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13016 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
13020 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13021 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13022 const struct target_waitstatus
*ws
)
13024 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13025 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13028 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13032 if (overlay_debugging
/* unmapped overlay section */
13033 && section_is_overlay (bl
->section
)
13034 && !section_is_mapped (bl
->section
))
13041 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13042 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13043 const struct target_waitstatus
*ws
)
13045 if (dprintf_style
== dprintf_style_agent
13046 && target_can_run_breakpoint_commands ())
13048 /* An agent-style dprintf never causes a stop. If we see a trap
13049 for this address it must be for a breakpoint that happens to
13050 be set at the same address. */
13054 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13058 bkpt_resources_needed (const struct bp_location
*bl
)
13060 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13065 static enum print_stop_action
13066 bkpt_print_it (bpstat bs
)
13068 struct breakpoint
*b
;
13069 const struct bp_location
*bl
;
13071 struct ui_out
*uiout
= current_uiout
;
13073 gdb_assert (bs
->bp_location_at
!= NULL
);
13075 bl
= bs
->bp_location_at
;
13076 b
= bs
->breakpoint_at
;
13078 bp_temp
= b
->disposition
== disp_del
;
13079 if (bl
->address
!= bl
->requested_address
)
13080 breakpoint_adjustment_warning (bl
->requested_address
,
13083 annotate_breakpoint (b
->number
);
13084 maybe_print_thread_hit_breakpoint (uiout
);
13087 uiout
->text ("Temporary breakpoint ");
13089 uiout
->text ("Breakpoint ");
13090 if (uiout
->is_mi_like_p ())
13092 uiout
->field_string ("reason",
13093 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13094 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
13096 uiout
->field_int ("bkptno", b
->number
);
13097 uiout
->text (", ");
13099 return PRINT_SRC_AND_LOC
;
13103 bkpt_print_mention (struct breakpoint
*b
)
13105 if (current_uiout
->is_mi_like_p ())
13110 case bp_breakpoint
:
13111 case bp_gnu_ifunc_resolver
:
13112 if (b
->disposition
== disp_del
)
13113 printf_filtered (_("Temporary breakpoint"));
13115 printf_filtered (_("Breakpoint"));
13116 printf_filtered (_(" %d"), b
->number
);
13117 if (b
->type
== bp_gnu_ifunc_resolver
)
13118 printf_filtered (_(" at gnu-indirect-function resolver"));
13120 case bp_hardware_breakpoint
:
13121 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13124 printf_filtered (_("Dprintf %d"), b
->number
);
13132 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13134 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13135 fprintf_unfiltered (fp
, "tbreak");
13136 else if (tp
->type
== bp_breakpoint
)
13137 fprintf_unfiltered (fp
, "break");
13138 else if (tp
->type
== bp_hardware_breakpoint
13139 && tp
->disposition
== disp_del
)
13140 fprintf_unfiltered (fp
, "thbreak");
13141 else if (tp
->type
== bp_hardware_breakpoint
)
13142 fprintf_unfiltered (fp
, "hbreak");
13144 internal_error (__FILE__
, __LINE__
,
13145 _("unhandled breakpoint type %d"), (int) tp
->type
);
13147 fprintf_unfiltered (fp
, " %s",
13148 event_location_to_string (tp
->location
.get ()));
13150 /* Print out extra_string if this breakpoint is pending. It might
13151 contain, for example, conditions that were set by the user. */
13152 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13153 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13155 print_recreate_thread (tp
, fp
);
13159 bkpt_create_sals_from_location (const struct event_location
*location
,
13160 struct linespec_result
*canonical
,
13161 enum bptype type_wanted
)
13163 create_sals_from_location_default (location
, canonical
, type_wanted
);
13167 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13168 struct linespec_result
*canonical
,
13170 char *extra_string
,
13171 enum bptype type_wanted
,
13172 enum bpdisp disposition
,
13174 int task
, int ignore_count
,
13175 const struct breakpoint_ops
*ops
,
13176 int from_tty
, int enabled
,
13177 int internal
, unsigned flags
)
13179 create_breakpoints_sal_default (gdbarch
, canonical
,
13180 cond_string
, extra_string
,
13182 disposition
, thread
, task
,
13183 ignore_count
, ops
, from_tty
,
13184 enabled
, internal
, flags
);
13188 bkpt_decode_location (struct breakpoint
*b
,
13189 const struct event_location
*location
,
13190 struct program_space
*search_pspace
,
13191 struct symtabs_and_lines
*sals
)
13193 decode_location_default (b
, location
, search_pspace
, sals
);
13196 /* Virtual table for internal breakpoints. */
13199 internal_bkpt_re_set (struct breakpoint
*b
)
13203 /* Delete overlay event and longjmp master breakpoints; they
13204 will be reset later by breakpoint_re_set. */
13205 case bp_overlay_event
:
13206 case bp_longjmp_master
:
13207 case bp_std_terminate_master
:
13208 case bp_exception_master
:
13209 delete_breakpoint (b
);
13212 /* This breakpoint is special, it's set up when the inferior
13213 starts and we really don't want to touch it. */
13214 case bp_shlib_event
:
13216 /* Like bp_shlib_event, this breakpoint type is special. Once
13217 it is set up, we do not want to touch it. */
13218 case bp_thread_event
:
13224 internal_bkpt_check_status (bpstat bs
)
13226 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13228 /* If requested, stop when the dynamic linker notifies GDB of
13229 events. This allows the user to get control and place
13230 breakpoints in initializer routines for dynamically loaded
13231 objects (among other things). */
13232 bs
->stop
= stop_on_solib_events
;
13233 bs
->print
= stop_on_solib_events
;
13239 static enum print_stop_action
13240 internal_bkpt_print_it (bpstat bs
)
13242 struct breakpoint
*b
;
13244 b
= bs
->breakpoint_at
;
13248 case bp_shlib_event
:
13249 /* Did we stop because the user set the stop_on_solib_events
13250 variable? (If so, we report this as a generic, "Stopped due
13251 to shlib event" message.) */
13252 print_solib_event (0);
13255 case bp_thread_event
:
13256 /* Not sure how we will get here.
13257 GDB should not stop for these breakpoints. */
13258 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13261 case bp_overlay_event
:
13262 /* By analogy with the thread event, GDB should not stop for these. */
13263 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13266 case bp_longjmp_master
:
13267 /* These should never be enabled. */
13268 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13271 case bp_std_terminate_master
:
13272 /* These should never be enabled. */
13273 printf_filtered (_("std::terminate Master Breakpoint: "
13274 "gdb should not stop!\n"));
13277 case bp_exception_master
:
13278 /* These should never be enabled. */
13279 printf_filtered (_("Exception Master Breakpoint: "
13280 "gdb should not stop!\n"));
13284 return PRINT_NOTHING
;
13288 internal_bkpt_print_mention (struct breakpoint
*b
)
13290 /* Nothing to mention. These breakpoints are internal. */
13293 /* Virtual table for momentary breakpoints */
13296 momentary_bkpt_re_set (struct breakpoint
*b
)
13298 /* Keep temporary breakpoints, which can be encountered when we step
13299 over a dlopen call and solib_add is resetting the breakpoints.
13300 Otherwise these should have been blown away via the cleanup chain
13301 or by breakpoint_init_inferior when we rerun the executable. */
13305 momentary_bkpt_check_status (bpstat bs
)
13307 /* Nothing. The point of these breakpoints is causing a stop. */
13310 static enum print_stop_action
13311 momentary_bkpt_print_it (bpstat bs
)
13313 return PRINT_UNKNOWN
;
13317 momentary_bkpt_print_mention (struct breakpoint
*b
)
13319 /* Nothing to mention. These breakpoints are internal. */
13322 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13324 It gets cleared already on the removal of the first one of such placed
13325 breakpoints. This is OK as they get all removed altogether. */
13328 longjmp_bkpt_dtor (struct breakpoint
*self
)
13330 struct thread_info
*tp
= find_thread_global_id (self
->thread
);
13333 tp
->initiating_frame
= null_frame_id
;
13335 momentary_breakpoint_ops
.dtor (self
);
13338 /* Specific methods for probe breakpoints. */
13341 bkpt_probe_insert_location (struct bp_location
*bl
)
13343 int v
= bkpt_insert_location (bl
);
13347 /* The insertion was successful, now let's set the probe's semaphore
13349 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13350 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13359 bkpt_probe_remove_location (struct bp_location
*bl
,
13360 enum remove_bp_reason reason
)
13362 /* Let's clear the semaphore before removing the location. */
13363 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13364 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13368 return bkpt_remove_location (bl
, reason
);
13372 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13373 struct linespec_result
*canonical
,
13374 enum bptype type_wanted
)
13376 struct linespec_sals lsal
;
13378 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13380 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13381 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13385 bkpt_probe_decode_location (struct breakpoint
*b
,
13386 const struct event_location
*location
,
13387 struct program_space
*search_pspace
,
13388 struct symtabs_and_lines
*sals
)
13390 *sals
= parse_probes (location
, search_pspace
, NULL
);
13392 error (_("probe not found"));
13395 /* The breakpoint_ops structure to be used in tracepoints. */
13398 tracepoint_re_set (struct breakpoint
*b
)
13400 breakpoint_re_set_default (b
);
13404 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13405 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13406 const struct target_waitstatus
*ws
)
13408 /* By definition, the inferior does not report stops at
13414 tracepoint_print_one_detail (const struct breakpoint
*self
,
13415 struct ui_out
*uiout
)
13417 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13418 if (tp
->static_trace_marker_id
)
13420 gdb_assert (self
->type
== bp_static_tracepoint
);
13422 uiout
->text ("\tmarker id is ");
13423 uiout
->field_string ("static-tracepoint-marker-string-id",
13424 tp
->static_trace_marker_id
);
13425 uiout
->text ("\n");
13430 tracepoint_print_mention (struct breakpoint
*b
)
13432 if (current_uiout
->is_mi_like_p ())
13437 case bp_tracepoint
:
13438 printf_filtered (_("Tracepoint"));
13439 printf_filtered (_(" %d"), b
->number
);
13441 case bp_fast_tracepoint
:
13442 printf_filtered (_("Fast tracepoint"));
13443 printf_filtered (_(" %d"), b
->number
);
13445 case bp_static_tracepoint
:
13446 printf_filtered (_("Static tracepoint"));
13447 printf_filtered (_(" %d"), b
->number
);
13450 internal_error (__FILE__
, __LINE__
,
13451 _("unhandled tracepoint type %d"), (int) b
->type
);
13458 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13460 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13462 if (self
->type
== bp_fast_tracepoint
)
13463 fprintf_unfiltered (fp
, "ftrace");
13464 else if (self
->type
== bp_static_tracepoint
)
13465 fprintf_unfiltered (fp
, "strace");
13466 else if (self
->type
== bp_tracepoint
)
13467 fprintf_unfiltered (fp
, "trace");
13469 internal_error (__FILE__
, __LINE__
,
13470 _("unhandled tracepoint type %d"), (int) self
->type
);
13472 fprintf_unfiltered (fp
, " %s",
13473 event_location_to_string (self
->location
.get ()));
13474 print_recreate_thread (self
, fp
);
13476 if (tp
->pass_count
)
13477 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13481 tracepoint_create_sals_from_location (const struct event_location
*location
,
13482 struct linespec_result
*canonical
,
13483 enum bptype type_wanted
)
13485 create_sals_from_location_default (location
, canonical
, type_wanted
);
13489 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13490 struct linespec_result
*canonical
,
13492 char *extra_string
,
13493 enum bptype type_wanted
,
13494 enum bpdisp disposition
,
13496 int task
, int ignore_count
,
13497 const struct breakpoint_ops
*ops
,
13498 int from_tty
, int enabled
,
13499 int internal
, unsigned flags
)
13501 create_breakpoints_sal_default (gdbarch
, canonical
,
13502 cond_string
, extra_string
,
13504 disposition
, thread
, task
,
13505 ignore_count
, ops
, from_tty
,
13506 enabled
, internal
, flags
);
13510 tracepoint_decode_location (struct breakpoint
*b
,
13511 const struct event_location
*location
,
13512 struct program_space
*search_pspace
,
13513 struct symtabs_and_lines
*sals
)
13515 decode_location_default (b
, location
, search_pspace
, sals
);
13518 struct breakpoint_ops tracepoint_breakpoint_ops
;
13520 /* The breakpoint_ops structure to be use on tracepoints placed in a
13524 tracepoint_probe_create_sals_from_location
13525 (const struct event_location
*location
,
13526 struct linespec_result
*canonical
,
13527 enum bptype type_wanted
)
13529 /* We use the same method for breakpoint on probes. */
13530 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13534 tracepoint_probe_decode_location (struct breakpoint
*b
,
13535 const struct event_location
*location
,
13536 struct program_space
*search_pspace
,
13537 struct symtabs_and_lines
*sals
)
13539 /* We use the same method for breakpoint on probes. */
13540 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13543 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13545 /* Dprintf breakpoint_ops methods. */
13548 dprintf_re_set (struct breakpoint
*b
)
13550 breakpoint_re_set_default (b
);
13552 /* extra_string should never be non-NULL for dprintf. */
13553 gdb_assert (b
->extra_string
!= NULL
);
13555 /* 1 - connect to target 1, that can run breakpoint commands.
13556 2 - create a dprintf, which resolves fine.
13557 3 - disconnect from target 1
13558 4 - connect to target 2, that can NOT run breakpoint commands.
13560 After steps #3/#4, you'll want the dprintf command list to
13561 be updated, because target 1 and 2 may well return different
13562 answers for target_can_run_breakpoint_commands().
13563 Given absence of finer grained resetting, we get to do
13564 it all the time. */
13565 if (b
->extra_string
!= NULL
)
13566 update_dprintf_command_list (b
);
13569 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13572 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13574 fprintf_unfiltered (fp
, "dprintf %s,%s",
13575 event_location_to_string (tp
->location
.get ()),
13577 print_recreate_thread (tp
, fp
);
13580 /* Implement the "after_condition_true" breakpoint_ops method for
13583 dprintf's are implemented with regular commands in their command
13584 list, but we run the commands here instead of before presenting the
13585 stop to the user, as dprintf's don't actually cause a stop. This
13586 also makes it so that the commands of multiple dprintfs at the same
13587 address are all handled. */
13590 dprintf_after_condition_true (struct bpstats
*bs
)
13592 struct cleanup
*old_chain
;
13593 struct bpstats tmp_bs
= { NULL
};
13594 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13596 /* dprintf's never cause a stop. This wasn't set in the
13597 check_status hook instead because that would make the dprintf's
13598 condition not be evaluated. */
13601 /* Run the command list here. Take ownership of it instead of
13602 copying. We never want these commands to run later in
13603 bpstat_do_actions, if a breakpoint that causes a stop happens to
13604 be set at same address as this dprintf, or even if running the
13605 commands here throws. */
13606 tmp_bs
.commands
= bs
->commands
;
13607 bs
->commands
= NULL
;
13608 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13610 bpstat_do_actions_1 (&tmp_bs_p
);
13612 /* 'tmp_bs.commands' will usually be NULL by now, but
13613 bpstat_do_actions_1 may return early without processing the whole
13615 do_cleanups (old_chain
);
13618 /* The breakpoint_ops structure to be used on static tracepoints with
13622 strace_marker_create_sals_from_location (const struct event_location
*location
,
13623 struct linespec_result
*canonical
,
13624 enum bptype type_wanted
)
13626 struct linespec_sals lsal
;
13627 const char *arg_start
, *arg
;
13629 struct cleanup
*cleanup
;
13631 arg
= arg_start
= get_linespec_location (location
);
13632 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13634 str
= savestring (arg_start
, arg
- arg_start
);
13635 cleanup
= make_cleanup (xfree
, str
);
13636 canonical
->location
= new_linespec_location (&str
);
13637 do_cleanups (cleanup
);
13640 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13641 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13645 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13646 struct linespec_result
*canonical
,
13648 char *extra_string
,
13649 enum bptype type_wanted
,
13650 enum bpdisp disposition
,
13652 int task
, int ignore_count
,
13653 const struct breakpoint_ops
*ops
,
13654 int from_tty
, int enabled
,
13655 int internal
, unsigned flags
)
13658 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13659 canonical
->sals
, 0);
13661 /* If the user is creating a static tracepoint by marker id
13662 (strace -m MARKER_ID), then store the sals index, so that
13663 breakpoint_re_set can try to match up which of the newly
13664 found markers corresponds to this one, and, don't try to
13665 expand multiple locations for each sal, given than SALS
13666 already should contain all sals for MARKER_ID. */
13668 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13670 struct symtabs_and_lines expanded
;
13671 struct tracepoint
*tp
;
13672 event_location_up location
;
13674 expanded
.nelts
= 1;
13675 expanded
.sals
= &lsal
->sals
.sals
[i
];
13677 location
= copy_event_location (canonical
->location
.get ());
13679 tp
= new tracepoint ();
13680 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13681 std::move (location
), NULL
,
13682 cond_string
, extra_string
,
13683 type_wanted
, disposition
,
13684 thread
, task
, ignore_count
, ops
,
13685 from_tty
, enabled
, internal
, flags
,
13686 canonical
->special_display
);
13687 /* Given that its possible to have multiple markers with
13688 the same string id, if the user is creating a static
13689 tracepoint by marker id ("strace -m MARKER_ID"), then
13690 store the sals index, so that breakpoint_re_set can
13691 try to match up which of the newly found markers
13692 corresponds to this one */
13693 tp
->static_trace_marker_id_idx
= i
;
13695 install_breakpoint (internal
, &tp
->base
, 0);
13700 strace_marker_decode_location (struct breakpoint
*b
,
13701 const struct event_location
*location
,
13702 struct program_space
*search_pspace
,
13703 struct symtabs_and_lines
*sals
)
13705 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13706 const char *s
= get_linespec_location (location
);
13708 *sals
= decode_static_tracepoint_spec (&s
);
13709 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13711 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13715 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13718 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13721 strace_marker_p (struct breakpoint
*b
)
13723 return b
->ops
== &strace_marker_breakpoint_ops
;
13726 /* Delete a breakpoint and clean up all traces of it in the data
13730 delete_breakpoint (struct breakpoint
*bpt
)
13732 struct breakpoint
*b
;
13734 gdb_assert (bpt
!= NULL
);
13736 /* Has this bp already been deleted? This can happen because
13737 multiple lists can hold pointers to bp's. bpstat lists are
13740 One example of this happening is a watchpoint's scope bp. When
13741 the scope bp triggers, we notice that the watchpoint is out of
13742 scope, and delete it. We also delete its scope bp. But the
13743 scope bp is marked "auto-deleting", and is already on a bpstat.
13744 That bpstat is then checked for auto-deleting bp's, which are
13747 A real solution to this problem might involve reference counts in
13748 bp's, and/or giving them pointers back to their referencing
13749 bpstat's, and teaching delete_breakpoint to only free a bp's
13750 storage when no more references were extent. A cheaper bandaid
13752 if (bpt
->type
== bp_none
)
13755 /* At least avoid this stale reference until the reference counting
13756 of breakpoints gets resolved. */
13757 if (bpt
->related_breakpoint
!= bpt
)
13759 struct breakpoint
*related
;
13760 struct watchpoint
*w
;
13762 if (bpt
->type
== bp_watchpoint_scope
)
13763 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13764 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13765 w
= (struct watchpoint
*) bpt
;
13769 watchpoint_del_at_next_stop (w
);
13771 /* Unlink bpt from the bpt->related_breakpoint ring. */
13772 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13773 related
= related
->related_breakpoint
);
13774 related
->related_breakpoint
= bpt
->related_breakpoint
;
13775 bpt
->related_breakpoint
= bpt
;
13778 /* watch_command_1 creates a watchpoint but only sets its number if
13779 update_watchpoint succeeds in creating its bp_locations. If there's
13780 a problem in that process, we'll be asked to delete the half-created
13781 watchpoint. In that case, don't announce the deletion. */
13783 observer_notify_breakpoint_deleted (bpt
);
13785 if (breakpoint_chain
== bpt
)
13786 breakpoint_chain
= bpt
->next
;
13788 ALL_BREAKPOINTS (b
)
13789 if (b
->next
== bpt
)
13791 b
->next
= bpt
->next
;
13795 /* Be sure no bpstat's are pointing at the breakpoint after it's
13797 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13798 in all threads for now. Note that we cannot just remove bpstats
13799 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13800 commands are associated with the bpstat; if we remove it here,
13801 then the later call to bpstat_do_actions (&stop_bpstat); in
13802 event-top.c won't do anything, and temporary breakpoints with
13803 commands won't work. */
13805 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13807 /* Now that breakpoint is removed from breakpoint list, update the
13808 global location list. This will remove locations that used to
13809 belong to this breakpoint. Do this before freeing the breakpoint
13810 itself, since remove_breakpoint looks at location's owner. It
13811 might be better design to have location completely
13812 self-contained, but it's not the case now. */
13813 update_global_location_list (UGLL_DONT_INSERT
);
13815 bpt
->ops
->dtor (bpt
);
13816 /* On the chance that someone will soon try again to delete this
13817 same bp, we mark it as deleted before freeing its storage. */
13818 bpt
->type
= bp_none
;
13823 do_delete_breakpoint_cleanup (void *b
)
13825 delete_breakpoint ((struct breakpoint
*) b
);
13829 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13831 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13834 /* Iterator function to call a user-provided callback function once
13835 for each of B and its related breakpoints. */
13838 iterate_over_related_breakpoints (struct breakpoint
*b
,
13839 void (*function
) (struct breakpoint
*,
13843 struct breakpoint
*related
;
13848 struct breakpoint
*next
;
13850 /* FUNCTION may delete RELATED. */
13851 next
= related
->related_breakpoint
;
13853 if (next
== related
)
13855 /* RELATED is the last ring entry. */
13856 function (related
, data
);
13858 /* FUNCTION may have deleted it, so we'd never reach back to
13859 B. There's nothing left to do anyway, so just break
13864 function (related
, data
);
13868 while (related
!= b
);
13872 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13874 delete_breakpoint (b
);
13877 /* A callback for map_breakpoint_numbers that calls
13878 delete_breakpoint. */
13881 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13883 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13887 delete_command (char *arg
, int from_tty
)
13889 struct breakpoint
*b
, *b_tmp
;
13895 int breaks_to_delete
= 0;
13897 /* Delete all breakpoints if no argument. Do not delete
13898 internal breakpoints, these have to be deleted with an
13899 explicit breakpoint number argument. */
13900 ALL_BREAKPOINTS (b
)
13901 if (user_breakpoint_p (b
))
13903 breaks_to_delete
= 1;
13907 /* Ask user only if there are some breakpoints to delete. */
13909 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13911 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13912 if (user_breakpoint_p (b
))
13913 delete_breakpoint (b
);
13917 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13920 /* Return true if all locations of B bound to PSPACE are pending. If
13921 PSPACE is NULL, all locations of all program spaces are
13925 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13927 struct bp_location
*loc
;
13929 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13930 if ((pspace
== NULL
13931 || loc
->pspace
== pspace
)
13932 && !loc
->shlib_disabled
13933 && !loc
->pspace
->executing_startup
)
13938 /* Subroutine of update_breakpoint_locations to simplify it.
13939 Return non-zero if multiple fns in list LOC have the same name.
13940 Null names are ignored. */
13943 ambiguous_names_p (struct bp_location
*loc
)
13945 struct bp_location
*l
;
13946 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13947 (int (*) (const void *,
13948 const void *)) streq
,
13949 NULL
, xcalloc
, xfree
);
13951 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13954 const char *name
= l
->function_name
;
13956 /* Allow for some names to be NULL, ignore them. */
13960 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13962 /* NOTE: We can assume slot != NULL here because xcalloc never
13966 htab_delete (htab
);
13972 htab_delete (htab
);
13976 /* When symbols change, it probably means the sources changed as well,
13977 and it might mean the static tracepoint markers are no longer at
13978 the same address or line numbers they used to be at last we
13979 checked. Losing your static tracepoints whenever you rebuild is
13980 undesirable. This function tries to resync/rematch gdb static
13981 tracepoints with the markers on the target, for static tracepoints
13982 that have not been set by marker id. Static tracepoint that have
13983 been set by marker id are reset by marker id in breakpoint_re_set.
13986 1) For a tracepoint set at a specific address, look for a marker at
13987 the old PC. If one is found there, assume to be the same marker.
13988 If the name / string id of the marker found is different from the
13989 previous known name, assume that means the user renamed the marker
13990 in the sources, and output a warning.
13992 2) For a tracepoint set at a given line number, look for a marker
13993 at the new address of the old line number. If one is found there,
13994 assume to be the same marker. If the name / string id of the
13995 marker found is different from the previous known name, assume that
13996 means the user renamed the marker in the sources, and output a
13999 3) If a marker is no longer found at the same address or line, it
14000 may mean the marker no longer exists. But it may also just mean
14001 the code changed a bit. Maybe the user added a few lines of code
14002 that made the marker move up or down (in line number terms). Ask
14003 the target for info about the marker with the string id as we knew
14004 it. If found, update line number and address in the matching
14005 static tracepoint. This will get confused if there's more than one
14006 marker with the same ID (possible in UST, although unadvised
14007 precisely because it confuses tools). */
14009 static struct symtab_and_line
14010 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14012 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14013 struct static_tracepoint_marker marker
;
14018 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14020 if (target_static_tracepoint_marker_at (pc
, &marker
))
14022 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14023 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14025 tp
->static_trace_marker_id
, marker
.str_id
);
14027 xfree (tp
->static_trace_marker_id
);
14028 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14029 release_static_tracepoint_marker (&marker
);
14034 /* Old marker wasn't found on target at lineno. Try looking it up
14036 if (!sal
.explicit_pc
14038 && sal
.symtab
!= NULL
14039 && tp
->static_trace_marker_id
!= NULL
)
14041 VEC(static_tracepoint_marker_p
) *markers
;
14044 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14046 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14048 struct symtab_and_line sal2
;
14049 struct symbol
*sym
;
14050 struct static_tracepoint_marker
*tpmarker
;
14051 struct ui_out
*uiout
= current_uiout
;
14052 struct explicit_location explicit_loc
;
14054 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14056 xfree (tp
->static_trace_marker_id
);
14057 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14059 warning (_("marker for static tracepoint %d (%s) not "
14060 "found at previous line number"),
14061 b
->number
, tp
->static_trace_marker_id
);
14065 sal2
.pc
= tpmarker
->address
;
14067 sal2
= find_pc_line (tpmarker
->address
, 0);
14068 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14069 uiout
->text ("Now in ");
14072 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
14073 uiout
->text (" at ");
14075 uiout
->field_string ("file",
14076 symtab_to_filename_for_display (sal2
.symtab
));
14079 if (uiout
->is_mi_like_p ())
14081 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14083 uiout
->field_string ("fullname", fullname
);
14086 uiout
->field_int ("line", sal2
.line
);
14087 uiout
->text ("\n");
14089 b
->loc
->line_number
= sal2
.line
;
14090 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14092 b
->location
.reset (NULL
);
14093 initialize_explicit_location (&explicit_loc
);
14094 explicit_loc
.source_filename
14095 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14096 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14097 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14098 b
->location
= new_explicit_location (&explicit_loc
);
14100 /* Might be nice to check if function changed, and warn if
14103 release_static_tracepoint_marker (tpmarker
);
14109 /* Returns 1 iff locations A and B are sufficiently same that
14110 we don't need to report breakpoint as changed. */
14113 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14117 if (a
->address
!= b
->address
)
14120 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14123 if (a
->enabled
!= b
->enabled
)
14130 if ((a
== NULL
) != (b
== NULL
))
14136 /* Split all locations of B that are bound to PSPACE out of B's
14137 location list to a separate list and return that list's head. If
14138 PSPACE is NULL, hoist out all locations of B. */
14140 static struct bp_location
*
14141 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14143 struct bp_location head
;
14144 struct bp_location
*i
= b
->loc
;
14145 struct bp_location
**i_link
= &b
->loc
;
14146 struct bp_location
*hoisted
= &head
;
14148 if (pspace
== NULL
)
14159 if (i
->pspace
== pspace
)
14174 /* Create new breakpoint locations for B (a hardware or software
14175 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14176 zero, then B is a ranged breakpoint. Only recreates locations for
14177 FILTER_PSPACE. Locations of other program spaces are left
14181 update_breakpoint_locations (struct breakpoint
*b
,
14182 struct program_space
*filter_pspace
,
14183 struct symtabs_and_lines sals
,
14184 struct symtabs_and_lines sals_end
)
14187 struct bp_location
*existing_locations
;
14189 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14191 /* Ranged breakpoints have only one start location and one end
14193 b
->enable_state
= bp_disabled
;
14194 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14195 "multiple locations found\n"),
14200 /* If there's no new locations, and all existing locations are
14201 pending, don't do anything. This optimizes the common case where
14202 all locations are in the same shared library, that was unloaded.
14203 We'd like to retain the location, so that when the library is
14204 loaded again, we don't loose the enabled/disabled status of the
14205 individual locations. */
14206 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14209 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14211 for (i
= 0; i
< sals
.nelts
; ++i
)
14213 struct bp_location
*new_loc
;
14215 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14217 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14219 /* Reparse conditions, they might contain references to the
14221 if (b
->cond_string
!= NULL
)
14225 s
= b
->cond_string
;
14228 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14229 block_for_pc (sals
.sals
[i
].pc
),
14232 CATCH (e
, RETURN_MASK_ERROR
)
14234 warning (_("failed to reevaluate condition "
14235 "for breakpoint %d: %s"),
14236 b
->number
, e
.message
);
14237 new_loc
->enabled
= 0;
14242 if (sals_end
.nelts
)
14244 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14246 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14250 /* If possible, carry over 'disable' status from existing
14253 struct bp_location
*e
= existing_locations
;
14254 /* If there are multiple breakpoints with the same function name,
14255 e.g. for inline functions, comparing function names won't work.
14256 Instead compare pc addresses; this is just a heuristic as things
14257 may have moved, but in practice it gives the correct answer
14258 often enough until a better solution is found. */
14259 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14261 for (; e
; e
= e
->next
)
14263 if (!e
->enabled
&& e
->function_name
)
14265 struct bp_location
*l
= b
->loc
;
14266 if (have_ambiguous_names
)
14268 for (; l
; l
= l
->next
)
14269 if (breakpoint_locations_match (e
, l
))
14277 for (; l
; l
= l
->next
)
14278 if (l
->function_name
14279 && strcmp (e
->function_name
, l
->function_name
) == 0)
14289 if (!locations_are_equal (existing_locations
, b
->loc
))
14290 observer_notify_breakpoint_modified (b
);
14293 /* Find the SaL locations corresponding to the given LOCATION.
14294 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14296 static struct symtabs_and_lines
14297 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14298 struct program_space
*search_pspace
, int *found
)
14300 struct symtabs_and_lines sals
= {0};
14301 struct gdb_exception exception
= exception_none
;
14303 gdb_assert (b
->ops
!= NULL
);
14307 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14309 CATCH (e
, RETURN_MASK_ERROR
)
14311 int not_found_and_ok
= 0;
14315 /* For pending breakpoints, it's expected that parsing will
14316 fail until the right shared library is loaded. User has
14317 already told to create pending breakpoints and don't need
14318 extra messages. If breakpoint is in bp_shlib_disabled
14319 state, then user already saw the message about that
14320 breakpoint being disabled, and don't want to see more
14322 if (e
.error
== NOT_FOUND_ERROR
14323 && (b
->condition_not_parsed
14325 && search_pspace
!= NULL
14326 && b
->loc
->pspace
!= search_pspace
)
14327 || (b
->loc
&& b
->loc
->shlib_disabled
)
14328 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14329 || b
->enable_state
== bp_disabled
))
14330 not_found_and_ok
= 1;
14332 if (!not_found_and_ok
)
14334 /* We surely don't want to warn about the same breakpoint
14335 10 times. One solution, implemented here, is disable
14336 the breakpoint on error. Another solution would be to
14337 have separate 'warning emitted' flag. Since this
14338 happens only when a binary has changed, I don't know
14339 which approach is better. */
14340 b
->enable_state
= bp_disabled
;
14341 throw_exception (e
);
14346 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14350 for (i
= 0; i
< sals
.nelts
; ++i
)
14351 resolve_sal_pc (&sals
.sals
[i
]);
14352 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14354 char *cond_string
, *extra_string
;
14357 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14358 &cond_string
, &thread
, &task
,
14360 gdb_assert (b
->cond_string
== NULL
);
14362 b
->cond_string
= cond_string
;
14363 b
->thread
= thread
;
14367 xfree (b
->extra_string
);
14368 b
->extra_string
= extra_string
;
14370 b
->condition_not_parsed
= 0;
14373 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14374 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14384 /* The default re_set method, for typical hardware or software
14385 breakpoints. Reevaluate the breakpoint and recreate its
14389 breakpoint_re_set_default (struct breakpoint
*b
)
14392 struct symtabs_and_lines sals
, sals_end
;
14393 struct symtabs_and_lines expanded
= {0};
14394 struct symtabs_and_lines expanded_end
= {0};
14395 struct program_space
*filter_pspace
= current_program_space
;
14397 sals
= location_to_sals (b
, b
->location
.get (), filter_pspace
, &found
);
14400 make_cleanup (xfree
, sals
.sals
);
14404 if (b
->location_range_end
!= NULL
)
14406 sals_end
= location_to_sals (b
, b
->location_range_end
.get (),
14407 filter_pspace
, &found
);
14410 make_cleanup (xfree
, sals_end
.sals
);
14411 expanded_end
= sals_end
;
14415 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14418 /* Default method for creating SALs from an address string. It basically
14419 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14422 create_sals_from_location_default (const struct event_location
*location
,
14423 struct linespec_result
*canonical
,
14424 enum bptype type_wanted
)
14426 parse_breakpoint_sals (location
, canonical
);
14429 /* Call create_breakpoints_sal for the given arguments. This is the default
14430 function for the `create_breakpoints_sal' method of
14434 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14435 struct linespec_result
*canonical
,
14437 char *extra_string
,
14438 enum bptype type_wanted
,
14439 enum bpdisp disposition
,
14441 int task
, int ignore_count
,
14442 const struct breakpoint_ops
*ops
,
14443 int from_tty
, int enabled
,
14444 int internal
, unsigned flags
)
14446 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14448 type_wanted
, disposition
,
14449 thread
, task
, ignore_count
, ops
, from_tty
,
14450 enabled
, internal
, flags
);
14453 /* Decode the line represented by S by calling decode_line_full. This is the
14454 default function for the `decode_location' method of breakpoint_ops. */
14457 decode_location_default (struct breakpoint
*b
,
14458 const struct event_location
*location
,
14459 struct program_space
*search_pspace
,
14460 struct symtabs_and_lines
*sals
)
14462 struct linespec_result canonical
;
14464 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14465 (struct symtab
*) NULL
, 0,
14466 &canonical
, multiple_symbols_all
,
14469 /* We should get 0 or 1 resulting SALs. */
14470 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14472 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14474 struct linespec_sals
*lsal
;
14476 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14477 *sals
= lsal
->sals
;
14478 /* Arrange it so the destructor does not free the
14480 lsal
->sals
.sals
= NULL
;
14484 /* Prepare the global context for a re-set of breakpoint B. */
14486 static struct cleanup
*
14487 prepare_re_set_context (struct breakpoint
*b
)
14489 input_radix
= b
->input_radix
;
14490 set_language (b
->language
);
14492 return make_cleanup (null_cleanup
, NULL
);
14495 /* Reset a breakpoint given it's struct breakpoint * BINT.
14496 The value we return ends up being the return value from catch_errors.
14497 Unused in this case. */
14500 breakpoint_re_set_one (void *bint
)
14502 /* Get past catch_errs. */
14503 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14504 struct cleanup
*cleanups
;
14506 cleanups
= prepare_re_set_context (b
);
14507 b
->ops
->re_set (b
);
14508 do_cleanups (cleanups
);
14512 /* Re-set breakpoint locations for the current program space.
14513 Locations bound to other program spaces are left untouched. */
14516 breakpoint_re_set (void)
14518 struct breakpoint
*b
, *b_tmp
;
14519 enum language save_language
;
14520 int save_input_radix
;
14521 struct cleanup
*old_chain
;
14523 save_language
= current_language
->la_language
;
14524 save_input_radix
= input_radix
;
14525 old_chain
= save_current_space_and_thread ();
14527 /* Note: we must not try to insert locations until after all
14528 breakpoints have been re-set. Otherwise, e.g., when re-setting
14529 breakpoint 1, we'd insert the locations of breakpoint 2, which
14530 hadn't been re-set yet, and thus may have stale locations. */
14532 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14534 /* Format possible error msg. */
14535 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14537 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14538 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14539 do_cleanups (cleanups
);
14541 set_language (save_language
);
14542 input_radix
= save_input_radix
;
14544 jit_breakpoint_re_set ();
14546 do_cleanups (old_chain
);
14548 create_overlay_event_breakpoint ();
14549 create_longjmp_master_breakpoint ();
14550 create_std_terminate_master_breakpoint ();
14551 create_exception_master_breakpoint ();
14553 /* Now we can insert. */
14554 update_global_location_list (UGLL_MAY_INSERT
);
14557 /* Reset the thread number of this breakpoint:
14559 - If the breakpoint is for all threads, leave it as-is.
14560 - Else, reset it to the current thread for inferior_ptid. */
14562 breakpoint_re_set_thread (struct breakpoint
*b
)
14564 if (b
->thread
!= -1)
14566 if (in_thread_list (inferior_ptid
))
14567 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14569 /* We're being called after following a fork. The new fork is
14570 selected as current, and unless this was a vfork will have a
14571 different program space from the original thread. Reset that
14573 b
->loc
->pspace
= current_program_space
;
14577 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14578 If from_tty is nonzero, it prints a message to that effect,
14579 which ends with a period (no newline). */
14582 set_ignore_count (int bptnum
, int count
, int from_tty
)
14584 struct breakpoint
*b
;
14589 ALL_BREAKPOINTS (b
)
14590 if (b
->number
== bptnum
)
14592 if (is_tracepoint (b
))
14594 if (from_tty
&& count
!= 0)
14595 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14600 b
->ignore_count
= count
;
14604 printf_filtered (_("Will stop next time "
14605 "breakpoint %d is reached."),
14607 else if (count
== 1)
14608 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14611 printf_filtered (_("Will ignore next %d "
14612 "crossings of breakpoint %d."),
14615 observer_notify_breakpoint_modified (b
);
14619 error (_("No breakpoint number %d."), bptnum
);
14622 /* Command to set ignore-count of breakpoint N to COUNT. */
14625 ignore_command (char *args
, int from_tty
)
14631 error_no_arg (_("a breakpoint number"));
14633 num
= get_number (&p
);
14635 error (_("bad breakpoint number: '%s'"), args
);
14637 error (_("Second argument (specified ignore-count) is missing."));
14639 set_ignore_count (num
,
14640 longest_to_int (value_as_long (parse_and_eval (p
))),
14643 printf_filtered ("\n");
14646 /* Call FUNCTION on each of the breakpoints
14647 whose numbers are given in ARGS. */
14650 map_breakpoint_numbers (const char *args
,
14651 void (*function
) (struct breakpoint
*,
14656 struct breakpoint
*b
, *tmp
;
14658 if (args
== 0 || *args
== '\0')
14659 error_no_arg (_("one or more breakpoint numbers"));
14661 number_or_range_parser
parser (args
);
14663 while (!parser
.finished ())
14665 const char *p
= parser
.cur_tok ();
14666 bool match
= false;
14668 num
= parser
.get_number ();
14671 warning (_("bad breakpoint number at or near '%s'"), p
);
14675 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14676 if (b
->number
== num
)
14679 function (b
, data
);
14683 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14688 static struct bp_location
*
14689 find_location_by_number (char *number
)
14691 char *dot
= strchr (number
, '.');
14695 struct breakpoint
*b
;
14696 struct bp_location
*loc
;
14701 bp_num
= get_number (&p1
);
14703 error (_("Bad breakpoint number '%s'"), number
);
14705 ALL_BREAKPOINTS (b
)
14706 if (b
->number
== bp_num
)
14711 if (!b
|| b
->number
!= bp_num
)
14712 error (_("Bad breakpoint number '%s'"), number
);
14715 loc_num
= get_number (&p1
);
14717 error (_("Bad breakpoint location number '%s'"), number
);
14721 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14724 error (_("Bad breakpoint location number '%s'"), dot
+1);
14730 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14731 If from_tty is nonzero, it prints a message to that effect,
14732 which ends with a period (no newline). */
14735 disable_breakpoint (struct breakpoint
*bpt
)
14737 /* Never disable a watchpoint scope breakpoint; we want to
14738 hit them when we leave scope so we can delete both the
14739 watchpoint and its scope breakpoint at that time. */
14740 if (bpt
->type
== bp_watchpoint_scope
)
14743 bpt
->enable_state
= bp_disabled
;
14745 /* Mark breakpoint locations modified. */
14746 mark_breakpoint_modified (bpt
);
14748 if (target_supports_enable_disable_tracepoint ()
14749 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14751 struct bp_location
*location
;
14753 for (location
= bpt
->loc
; location
; location
= location
->next
)
14754 target_disable_tracepoint (location
);
14757 update_global_location_list (UGLL_DONT_INSERT
);
14759 observer_notify_breakpoint_modified (bpt
);
14762 /* A callback for iterate_over_related_breakpoints. */
14765 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14767 disable_breakpoint (b
);
14770 /* A callback for map_breakpoint_numbers that calls
14771 disable_breakpoint. */
14774 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14776 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14780 disable_command (char *args
, int from_tty
)
14784 struct breakpoint
*bpt
;
14786 ALL_BREAKPOINTS (bpt
)
14787 if (user_breakpoint_p (bpt
))
14788 disable_breakpoint (bpt
);
14792 char *num
= extract_arg (&args
);
14796 if (strchr (num
, '.'))
14798 struct bp_location
*loc
= find_location_by_number (num
);
14805 mark_breakpoint_location_modified (loc
);
14807 if (target_supports_enable_disable_tracepoint ()
14808 && current_trace_status ()->running
&& loc
->owner
14809 && is_tracepoint (loc
->owner
))
14810 target_disable_tracepoint (loc
);
14812 update_global_location_list (UGLL_DONT_INSERT
);
14815 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14816 num
= extract_arg (&args
);
14822 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14825 int target_resources_ok
;
14827 if (bpt
->type
== bp_hardware_breakpoint
)
14830 i
= hw_breakpoint_used_count ();
14831 target_resources_ok
=
14832 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14834 if (target_resources_ok
== 0)
14835 error (_("No hardware breakpoint support in the target."));
14836 else if (target_resources_ok
< 0)
14837 error (_("Hardware breakpoints used exceeds limit."));
14840 if (is_watchpoint (bpt
))
14842 /* Initialize it just to avoid a GCC false warning. */
14843 enum enable_state orig_enable_state
= bp_disabled
;
14847 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14849 orig_enable_state
= bpt
->enable_state
;
14850 bpt
->enable_state
= bp_enabled
;
14851 update_watchpoint (w
, 1 /* reparse */);
14853 CATCH (e
, RETURN_MASK_ALL
)
14855 bpt
->enable_state
= orig_enable_state
;
14856 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14863 bpt
->enable_state
= bp_enabled
;
14865 /* Mark breakpoint locations modified. */
14866 mark_breakpoint_modified (bpt
);
14868 if (target_supports_enable_disable_tracepoint ()
14869 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14871 struct bp_location
*location
;
14873 for (location
= bpt
->loc
; location
; location
= location
->next
)
14874 target_enable_tracepoint (location
);
14877 bpt
->disposition
= disposition
;
14878 bpt
->enable_count
= count
;
14879 update_global_location_list (UGLL_MAY_INSERT
);
14881 observer_notify_breakpoint_modified (bpt
);
14886 enable_breakpoint (struct breakpoint
*bpt
)
14888 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14892 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14894 enable_breakpoint (bpt
);
14897 /* A callback for map_breakpoint_numbers that calls
14898 enable_breakpoint. */
14901 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14903 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14906 /* The enable command enables the specified breakpoints (or all defined
14907 breakpoints) so they once again become (or continue to be) effective
14908 in stopping the inferior. */
14911 enable_command (char *args
, int from_tty
)
14915 struct breakpoint
*bpt
;
14917 ALL_BREAKPOINTS (bpt
)
14918 if (user_breakpoint_p (bpt
))
14919 enable_breakpoint (bpt
);
14923 char *num
= extract_arg (&args
);
14927 if (strchr (num
, '.'))
14929 struct bp_location
*loc
= find_location_by_number (num
);
14936 mark_breakpoint_location_modified (loc
);
14938 if (target_supports_enable_disable_tracepoint ()
14939 && current_trace_status ()->running
&& loc
->owner
14940 && is_tracepoint (loc
->owner
))
14941 target_enable_tracepoint (loc
);
14943 update_global_location_list (UGLL_MAY_INSERT
);
14946 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14947 num
= extract_arg (&args
);
14952 /* This struct packages up disposition data for application to multiple
14962 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14964 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14966 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14970 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14972 struct disp_data disp
= { disp_disable
, 1 };
14974 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14978 enable_once_command (char *args
, int from_tty
)
14980 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14984 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14986 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14988 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14992 enable_count_command (char *args
, int from_tty
)
14997 error_no_arg (_("hit count"));
14999 count
= get_number (&args
);
15001 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15005 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15007 struct disp_data disp
= { disp_del
, 1 };
15009 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15013 enable_delete_command (char *args
, int from_tty
)
15015 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15019 set_breakpoint_cmd (char *args
, int from_tty
)
15024 show_breakpoint_cmd (char *args
, int from_tty
)
15028 /* Invalidate last known value of any hardware watchpoint if
15029 the memory which that value represents has been written to by
15033 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15034 CORE_ADDR addr
, ssize_t len
,
15035 const bfd_byte
*data
)
15037 struct breakpoint
*bp
;
15039 ALL_BREAKPOINTS (bp
)
15040 if (bp
->enable_state
== bp_enabled
15041 && bp
->type
== bp_hardware_watchpoint
)
15043 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15045 if (wp
->val_valid
&& wp
->val
)
15047 struct bp_location
*loc
;
15049 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15050 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15051 && loc
->address
+ loc
->length
> addr
15052 && addr
+ len
> loc
->address
)
15054 value_free (wp
->val
);
15062 /* Create and insert a breakpoint for software single step. */
15065 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15066 struct address_space
*aspace
,
15069 struct thread_info
*tp
= inferior_thread ();
15070 struct symtab_and_line sal
;
15071 CORE_ADDR pc
= next_pc
;
15073 if (tp
->control
.single_step_breakpoints
== NULL
)
15075 tp
->control
.single_step_breakpoints
15076 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
15079 sal
= find_pc_line (pc
, 0);
15081 sal
.section
= find_pc_overlay (pc
);
15082 sal
.explicit_pc
= 1;
15083 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15085 update_global_location_list (UGLL_INSERT
);
15088 /* Insert single step breakpoints according to the current state. */
15091 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
15093 struct regcache
*regcache
= get_current_regcache ();
15094 VEC (CORE_ADDR
) * next_pcs
;
15096 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
15098 if (next_pcs
!= NULL
)
15102 struct frame_info
*frame
= get_current_frame ();
15103 struct address_space
*aspace
= get_frame_address_space (frame
);
15105 for (i
= 0; VEC_iterate (CORE_ADDR
, next_pcs
, i
, pc
); i
++)
15106 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
15108 VEC_free (CORE_ADDR
, next_pcs
);
15116 /* See breakpoint.h. */
15119 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15120 struct address_space
*aspace
,
15123 struct bp_location
*loc
;
15125 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15127 && breakpoint_location_address_match (loc
, aspace
, pc
))
15133 /* Check whether a software single-step breakpoint is inserted at
15137 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15140 struct breakpoint
*bpt
;
15142 ALL_BREAKPOINTS (bpt
)
15144 if (bpt
->type
== bp_single_step
15145 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15151 /* Tracepoint-specific operations. */
15153 /* Set tracepoint count to NUM. */
15155 set_tracepoint_count (int num
)
15157 tracepoint_count
= num
;
15158 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15162 trace_command (char *arg
, int from_tty
)
15164 struct breakpoint_ops
*ops
;
15166 event_location_up location
= string_to_event_location (&arg
,
15168 if (location
!= NULL
15169 && event_location_type (location
.get ()) == PROBE_LOCATION
)
15170 ops
= &tracepoint_probe_breakpoint_ops
;
15172 ops
= &tracepoint_breakpoint_ops
;
15174 create_breakpoint (get_current_arch (),
15176 NULL
, 0, arg
, 1 /* parse arg */,
15178 bp_tracepoint
/* type_wanted */,
15179 0 /* Ignore count */,
15180 pending_break_support
,
15184 0 /* internal */, 0);
15188 ftrace_command (char *arg
, int from_tty
)
15190 event_location_up location
= string_to_event_location (&arg
,
15192 create_breakpoint (get_current_arch (),
15194 NULL
, 0, arg
, 1 /* parse arg */,
15196 bp_fast_tracepoint
/* type_wanted */,
15197 0 /* Ignore count */,
15198 pending_break_support
,
15199 &tracepoint_breakpoint_ops
,
15202 0 /* internal */, 0);
15205 /* strace command implementation. Creates a static tracepoint. */
15208 strace_command (char *arg
, int from_tty
)
15210 struct breakpoint_ops
*ops
;
15211 event_location_up location
;
15212 struct cleanup
*back_to
;
15214 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15215 or with a normal static tracepoint. */
15216 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15218 ops
= &strace_marker_breakpoint_ops
;
15219 location
= new_linespec_location (&arg
);
15223 ops
= &tracepoint_breakpoint_ops
;
15224 location
= string_to_event_location (&arg
, current_language
);
15227 create_breakpoint (get_current_arch (),
15229 NULL
, 0, arg
, 1 /* parse arg */,
15231 bp_static_tracepoint
/* type_wanted */,
15232 0 /* Ignore count */,
15233 pending_break_support
,
15237 0 /* internal */, 0);
15240 /* Set up a fake reader function that gets command lines from a linked
15241 list that was acquired during tracepoint uploading. */
15243 static struct uploaded_tp
*this_utp
;
15244 static int next_cmd
;
15247 read_uploaded_action (void)
15251 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15258 /* Given information about a tracepoint as recorded on a target (which
15259 can be either a live system or a trace file), attempt to create an
15260 equivalent GDB tracepoint. This is not a reliable process, since
15261 the target does not necessarily have all the information used when
15262 the tracepoint was originally defined. */
15264 struct tracepoint
*
15265 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15267 char *addr_str
, small_buf
[100];
15268 struct tracepoint
*tp
;
15270 if (utp
->at_string
)
15271 addr_str
= utp
->at_string
;
15274 /* In the absence of a source location, fall back to raw
15275 address. Since there is no way to confirm that the address
15276 means the same thing as when the trace was started, warn the
15278 warning (_("Uploaded tracepoint %d has no "
15279 "source location, using raw address"),
15281 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15282 addr_str
= small_buf
;
15285 /* There's not much we can do with a sequence of bytecodes. */
15286 if (utp
->cond
&& !utp
->cond_string
)
15287 warning (_("Uploaded tracepoint %d condition "
15288 "has no source form, ignoring it"),
15291 event_location_up location
= string_to_event_location (&addr_str
,
15293 if (!create_breakpoint (get_current_arch (),
15295 utp
->cond_string
, -1, addr_str
,
15296 0 /* parse cond/thread */,
15298 utp
->type
/* type_wanted */,
15299 0 /* Ignore count */,
15300 pending_break_support
,
15301 &tracepoint_breakpoint_ops
,
15303 utp
->enabled
/* enabled */,
15305 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15308 /* Get the tracepoint we just created. */
15309 tp
= get_tracepoint (tracepoint_count
);
15310 gdb_assert (tp
!= NULL
);
15314 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15317 trace_pass_command (small_buf
, 0);
15320 /* If we have uploaded versions of the original commands, set up a
15321 special-purpose "reader" function and call the usual command line
15322 reader, then pass the result to the breakpoint command-setting
15324 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15326 command_line_up cmd_list
;
15331 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15333 breakpoint_set_commands (&tp
->base
, std::move (cmd_list
));
15335 else if (!VEC_empty (char_ptr
, utp
->actions
)
15336 || !VEC_empty (char_ptr
, utp
->step_actions
))
15337 warning (_("Uploaded tracepoint %d actions "
15338 "have no source form, ignoring them"),
15341 /* Copy any status information that might be available. */
15342 tp
->base
.hit_count
= utp
->hit_count
;
15343 tp
->traceframe_usage
= utp
->traceframe_usage
;
15348 /* Print information on tracepoint number TPNUM_EXP, or all if
15352 tracepoints_info (char *args
, int from_tty
)
15354 struct ui_out
*uiout
= current_uiout
;
15357 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15359 if (num_printed
== 0)
15361 if (args
== NULL
|| *args
== '\0')
15362 uiout
->message ("No tracepoints.\n");
15364 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15367 default_collect_info ();
15370 /* The 'enable trace' command enables tracepoints.
15371 Not supported by all targets. */
15373 enable_trace_command (char *args
, int from_tty
)
15375 enable_command (args
, from_tty
);
15378 /* The 'disable trace' command disables tracepoints.
15379 Not supported by all targets. */
15381 disable_trace_command (char *args
, int from_tty
)
15383 disable_command (args
, from_tty
);
15386 /* Remove a tracepoint (or all if no argument). */
15388 delete_trace_command (char *arg
, int from_tty
)
15390 struct breakpoint
*b
, *b_tmp
;
15396 int breaks_to_delete
= 0;
15398 /* Delete all breakpoints if no argument.
15399 Do not delete internal or call-dummy breakpoints, these
15400 have to be deleted with an explicit breakpoint number
15402 ALL_TRACEPOINTS (b
)
15403 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15405 breaks_to_delete
= 1;
15409 /* Ask user only if there are some breakpoints to delete. */
15411 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15413 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15414 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15415 delete_breakpoint (b
);
15419 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15422 /* Helper function for trace_pass_command. */
15425 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15427 tp
->pass_count
= count
;
15428 observer_notify_breakpoint_modified (&tp
->base
);
15430 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15431 tp
->base
.number
, count
);
15434 /* Set passcount for tracepoint.
15436 First command argument is passcount, second is tracepoint number.
15437 If tracepoint number omitted, apply to most recently defined.
15438 Also accepts special argument "all". */
15441 trace_pass_command (char *args
, int from_tty
)
15443 struct tracepoint
*t1
;
15444 unsigned int count
;
15446 if (args
== 0 || *args
== 0)
15447 error (_("passcount command requires an "
15448 "argument (count + optional TP num)"));
15450 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15452 args
= skip_spaces (args
);
15453 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15455 struct breakpoint
*b
;
15457 args
+= 3; /* Skip special argument "all". */
15459 error (_("Junk at end of arguments."));
15461 ALL_TRACEPOINTS (b
)
15463 t1
= (struct tracepoint
*) b
;
15464 trace_pass_set_count (t1
, count
, from_tty
);
15467 else if (*args
== '\0')
15469 t1
= get_tracepoint_by_number (&args
, NULL
);
15471 trace_pass_set_count (t1
, count
, from_tty
);
15475 number_or_range_parser
parser (args
);
15476 while (!parser
.finished ())
15478 t1
= get_tracepoint_by_number (&args
, &parser
);
15480 trace_pass_set_count (t1
, count
, from_tty
);
15485 struct tracepoint
*
15486 get_tracepoint (int num
)
15488 struct breakpoint
*t
;
15490 ALL_TRACEPOINTS (t
)
15491 if (t
->number
== num
)
15492 return (struct tracepoint
*) t
;
15497 /* Find the tracepoint with the given target-side number (which may be
15498 different from the tracepoint number after disconnecting and
15501 struct tracepoint
*
15502 get_tracepoint_by_number_on_target (int num
)
15504 struct breakpoint
*b
;
15506 ALL_TRACEPOINTS (b
)
15508 struct tracepoint
*t
= (struct tracepoint
*) b
;
15510 if (t
->number_on_target
== num
)
15517 /* Utility: parse a tracepoint number and look it up in the list.
15518 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15519 If the argument is missing, the most recent tracepoint
15520 (tracepoint_count) is returned. */
15522 struct tracepoint
*
15523 get_tracepoint_by_number (char **arg
,
15524 number_or_range_parser
*parser
)
15526 struct breakpoint
*t
;
15528 char *instring
= arg
== NULL
? NULL
: *arg
;
15530 if (parser
!= NULL
)
15532 gdb_assert (!parser
->finished ());
15533 tpnum
= parser
->get_number ();
15535 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15536 tpnum
= tracepoint_count
;
15538 tpnum
= get_number (arg
);
15542 if (instring
&& *instring
)
15543 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15546 printf_filtered (_("No previous tracepoint\n"));
15550 ALL_TRACEPOINTS (t
)
15551 if (t
->number
== tpnum
)
15553 return (struct tracepoint
*) t
;
15556 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15561 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15563 if (b
->thread
!= -1)
15564 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15567 fprintf_unfiltered (fp
, " task %d", b
->task
);
15569 fprintf_unfiltered (fp
, "\n");
15572 /* Save information on user settable breakpoints (watchpoints, etc) to
15573 a new script file named FILENAME. If FILTER is non-NULL, call it
15574 on each breakpoint and only include the ones for which it returns
15578 save_breakpoints (char *filename
, int from_tty
,
15579 int (*filter
) (const struct breakpoint
*))
15581 struct breakpoint
*tp
;
15583 struct cleanup
*cleanup
;
15584 int extra_trace_bits
= 0;
15586 if (filename
== 0 || *filename
== 0)
15587 error (_("Argument required (file name in which to save)"));
15589 /* See if we have anything to save. */
15590 ALL_BREAKPOINTS (tp
)
15592 /* Skip internal and momentary breakpoints. */
15593 if (!user_breakpoint_p (tp
))
15596 /* If we have a filter, only save the breakpoints it accepts. */
15597 if (filter
&& !filter (tp
))
15602 if (is_tracepoint (tp
))
15604 extra_trace_bits
= 1;
15606 /* We can stop searching. */
15613 warning (_("Nothing to save."));
15617 filename
= tilde_expand (filename
);
15618 cleanup
= make_cleanup (xfree
, filename
);
15622 if (!fp
.open (filename
, "w"))
15623 error (_("Unable to open file '%s' for saving (%s)"),
15624 filename
, safe_strerror (errno
));
15626 if (extra_trace_bits
)
15627 save_trace_state_variables (&fp
);
15629 ALL_BREAKPOINTS (tp
)
15631 /* Skip internal and momentary breakpoints. */
15632 if (!user_breakpoint_p (tp
))
15635 /* If we have a filter, only save the breakpoints it accepts. */
15636 if (filter
&& !filter (tp
))
15639 tp
->ops
->print_recreate (tp
, &fp
);
15641 /* Note, we can't rely on tp->number for anything, as we can't
15642 assume the recreated breakpoint numbers will match. Use $bpnum
15645 if (tp
->cond_string
)
15646 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15648 if (tp
->ignore_count
)
15649 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15651 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15653 fp
.puts (" commands\n");
15655 current_uiout
->redirect (&fp
);
15658 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15660 CATCH (ex
, RETURN_MASK_ALL
)
15662 current_uiout
->redirect (NULL
);
15663 throw_exception (ex
);
15667 current_uiout
->redirect (NULL
);
15668 fp
.puts (" end\n");
15671 if (tp
->enable_state
== bp_disabled
)
15672 fp
.puts ("disable $bpnum\n");
15674 /* If this is a multi-location breakpoint, check if the locations
15675 should be individually disabled. Watchpoint locations are
15676 special, and not user visible. */
15677 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15679 struct bp_location
*loc
;
15682 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15684 fp
.printf ("disable $bpnum.%d\n", n
);
15688 if (extra_trace_bits
&& *default_collect
)
15689 fp
.printf ("set default-collect %s\n", default_collect
);
15692 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15693 do_cleanups (cleanup
);
15696 /* The `save breakpoints' command. */
15699 save_breakpoints_command (char *args
, int from_tty
)
15701 save_breakpoints (args
, from_tty
, NULL
);
15704 /* The `save tracepoints' command. */
15707 save_tracepoints_command (char *args
, int from_tty
)
15709 save_breakpoints (args
, from_tty
, is_tracepoint
);
15712 /* Create a vector of all tracepoints. */
15714 VEC(breakpoint_p
) *
15715 all_tracepoints (void)
15717 VEC(breakpoint_p
) *tp_vec
= 0;
15718 struct breakpoint
*tp
;
15720 ALL_TRACEPOINTS (tp
)
15722 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15729 /* This help string is used to consolidate all the help string for specifying
15730 locations used by several commands. */
15732 #define LOCATION_HELP_STRING \
15733 "Linespecs are colon-separated lists of location parameters, such as\n\
15734 source filename, function name, label name, and line number.\n\
15735 Example: To specify the start of a label named \"the_top\" in the\n\
15736 function \"fact\" in the file \"factorial.c\", use\n\
15737 \"factorial.c:fact:the_top\".\n\
15739 Address locations begin with \"*\" and specify an exact address in the\n\
15740 program. Example: To specify the fourth byte past the start function\n\
15741 \"main\", use \"*main + 4\".\n\
15743 Explicit locations are similar to linespecs but use an option/argument\n\
15744 syntax to specify location parameters.\n\
15745 Example: To specify the start of the label named \"the_top\" in the\n\
15746 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15747 -function fact -label the_top\".\n"
15749 /* This help string is used for the break, hbreak, tbreak and thbreak
15750 commands. It is defined as a macro to prevent duplication.
15751 COMMAND should be a string constant containing the name of the
15754 #define BREAK_ARGS_HELP(command) \
15755 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15756 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15757 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15758 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15759 `-probe-dtrace' (for a DTrace probe).\n\
15760 LOCATION may be a linespec, address, or explicit location as described\n\
15763 With no LOCATION, uses current execution address of the selected\n\
15764 stack frame. This is useful for breaking on return to a stack frame.\n\
15766 THREADNUM is the number from \"info threads\".\n\
15767 CONDITION is a boolean expression.\n\
15768 \n" LOCATION_HELP_STRING "\n\
15769 Multiple breakpoints at one place are permitted, and useful if their\n\
15770 conditions are different.\n\
15772 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15774 /* List of subcommands for "catch". */
15775 static struct cmd_list_element
*catch_cmdlist
;
15777 /* List of subcommands for "tcatch". */
15778 static struct cmd_list_element
*tcatch_cmdlist
;
15781 add_catch_command (const char *name
, const char *docstring
,
15782 cmd_sfunc_ftype
*sfunc
,
15783 completer_ftype
*completer
,
15784 void *user_data_catch
,
15785 void *user_data_tcatch
)
15787 struct cmd_list_element
*command
;
15789 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15791 set_cmd_sfunc (command
, sfunc
);
15792 set_cmd_context (command
, user_data_catch
);
15793 set_cmd_completer (command
, completer
);
15795 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15797 set_cmd_sfunc (command
, sfunc
);
15798 set_cmd_context (command
, user_data_tcatch
);
15799 set_cmd_completer (command
, completer
);
15803 save_command (char *arg
, int from_tty
)
15805 printf_unfiltered (_("\"save\" must be followed by "
15806 "the name of a save subcommand.\n"));
15807 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15810 struct breakpoint
*
15811 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15814 struct breakpoint
*b
, *b_tmp
;
15816 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15818 if ((*callback
) (b
, data
))
15825 /* Zero if any of the breakpoint's locations could be a location where
15826 functions have been inlined, nonzero otherwise. */
15829 is_non_inline_function (struct breakpoint
*b
)
15831 /* The shared library event breakpoint is set on the address of a
15832 non-inline function. */
15833 if (b
->type
== bp_shlib_event
)
15839 /* Nonzero if the specified PC cannot be a location where functions
15840 have been inlined. */
15843 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15844 const struct target_waitstatus
*ws
)
15846 struct breakpoint
*b
;
15847 struct bp_location
*bl
;
15849 ALL_BREAKPOINTS (b
)
15851 if (!is_non_inline_function (b
))
15854 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15856 if (!bl
->shlib_disabled
15857 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15865 /* Remove any references to OBJFILE which is going to be freed. */
15868 breakpoint_free_objfile (struct objfile
*objfile
)
15870 struct bp_location
**locp
, *loc
;
15872 ALL_BP_LOCATIONS (loc
, locp
)
15873 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15874 loc
->symtab
= NULL
;
15878 initialize_breakpoint_ops (void)
15880 static int initialized
= 0;
15882 struct breakpoint_ops
*ops
;
15888 /* The breakpoint_ops structure to be inherit by all kinds of
15889 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15890 internal and momentary breakpoints, etc.). */
15891 ops
= &bkpt_base_breakpoint_ops
;
15892 *ops
= base_breakpoint_ops
;
15893 ops
->re_set
= bkpt_re_set
;
15894 ops
->insert_location
= bkpt_insert_location
;
15895 ops
->remove_location
= bkpt_remove_location
;
15896 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15897 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15898 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15899 ops
->decode_location
= bkpt_decode_location
;
15901 /* The breakpoint_ops structure to be used in regular breakpoints. */
15902 ops
= &bkpt_breakpoint_ops
;
15903 *ops
= bkpt_base_breakpoint_ops
;
15904 ops
->re_set
= bkpt_re_set
;
15905 ops
->resources_needed
= bkpt_resources_needed
;
15906 ops
->print_it
= bkpt_print_it
;
15907 ops
->print_mention
= bkpt_print_mention
;
15908 ops
->print_recreate
= bkpt_print_recreate
;
15910 /* Ranged breakpoints. */
15911 ops
= &ranged_breakpoint_ops
;
15912 *ops
= bkpt_breakpoint_ops
;
15913 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15914 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15915 ops
->print_it
= print_it_ranged_breakpoint
;
15916 ops
->print_one
= print_one_ranged_breakpoint
;
15917 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15918 ops
->print_mention
= print_mention_ranged_breakpoint
;
15919 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15921 /* Internal breakpoints. */
15922 ops
= &internal_breakpoint_ops
;
15923 *ops
= bkpt_base_breakpoint_ops
;
15924 ops
->re_set
= internal_bkpt_re_set
;
15925 ops
->check_status
= internal_bkpt_check_status
;
15926 ops
->print_it
= internal_bkpt_print_it
;
15927 ops
->print_mention
= internal_bkpt_print_mention
;
15929 /* Momentary breakpoints. */
15930 ops
= &momentary_breakpoint_ops
;
15931 *ops
= bkpt_base_breakpoint_ops
;
15932 ops
->re_set
= momentary_bkpt_re_set
;
15933 ops
->check_status
= momentary_bkpt_check_status
;
15934 ops
->print_it
= momentary_bkpt_print_it
;
15935 ops
->print_mention
= momentary_bkpt_print_mention
;
15937 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15938 ops
= &longjmp_breakpoint_ops
;
15939 *ops
= momentary_breakpoint_ops
;
15940 ops
->dtor
= longjmp_bkpt_dtor
;
15942 /* Probe breakpoints. */
15943 ops
= &bkpt_probe_breakpoint_ops
;
15944 *ops
= bkpt_breakpoint_ops
;
15945 ops
->insert_location
= bkpt_probe_insert_location
;
15946 ops
->remove_location
= bkpt_probe_remove_location
;
15947 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15948 ops
->decode_location
= bkpt_probe_decode_location
;
15951 ops
= &watchpoint_breakpoint_ops
;
15952 *ops
= base_breakpoint_ops
;
15953 ops
->dtor
= dtor_watchpoint
;
15954 ops
->re_set
= re_set_watchpoint
;
15955 ops
->insert_location
= insert_watchpoint
;
15956 ops
->remove_location
= remove_watchpoint
;
15957 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15958 ops
->check_status
= check_status_watchpoint
;
15959 ops
->resources_needed
= resources_needed_watchpoint
;
15960 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15961 ops
->print_it
= print_it_watchpoint
;
15962 ops
->print_mention
= print_mention_watchpoint
;
15963 ops
->print_recreate
= print_recreate_watchpoint
;
15964 ops
->explains_signal
= explains_signal_watchpoint
;
15966 /* Masked watchpoints. */
15967 ops
= &masked_watchpoint_breakpoint_ops
;
15968 *ops
= watchpoint_breakpoint_ops
;
15969 ops
->insert_location
= insert_masked_watchpoint
;
15970 ops
->remove_location
= remove_masked_watchpoint
;
15971 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15972 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15973 ops
->print_it
= print_it_masked_watchpoint
;
15974 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15975 ops
->print_mention
= print_mention_masked_watchpoint
;
15976 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15979 ops
= &tracepoint_breakpoint_ops
;
15980 *ops
= base_breakpoint_ops
;
15981 ops
->re_set
= tracepoint_re_set
;
15982 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15983 ops
->print_one_detail
= tracepoint_print_one_detail
;
15984 ops
->print_mention
= tracepoint_print_mention
;
15985 ops
->print_recreate
= tracepoint_print_recreate
;
15986 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15987 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15988 ops
->decode_location
= tracepoint_decode_location
;
15990 /* Probe tracepoints. */
15991 ops
= &tracepoint_probe_breakpoint_ops
;
15992 *ops
= tracepoint_breakpoint_ops
;
15993 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15994 ops
->decode_location
= tracepoint_probe_decode_location
;
15996 /* Static tracepoints with marker (`-m'). */
15997 ops
= &strace_marker_breakpoint_ops
;
15998 *ops
= tracepoint_breakpoint_ops
;
15999 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
16000 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16001 ops
->decode_location
= strace_marker_decode_location
;
16003 /* Fork catchpoints. */
16004 ops
= &catch_fork_breakpoint_ops
;
16005 *ops
= base_breakpoint_ops
;
16006 ops
->insert_location
= insert_catch_fork
;
16007 ops
->remove_location
= remove_catch_fork
;
16008 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16009 ops
->print_it
= print_it_catch_fork
;
16010 ops
->print_one
= print_one_catch_fork
;
16011 ops
->print_mention
= print_mention_catch_fork
;
16012 ops
->print_recreate
= print_recreate_catch_fork
;
16014 /* Vfork catchpoints. */
16015 ops
= &catch_vfork_breakpoint_ops
;
16016 *ops
= base_breakpoint_ops
;
16017 ops
->insert_location
= insert_catch_vfork
;
16018 ops
->remove_location
= remove_catch_vfork
;
16019 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16020 ops
->print_it
= print_it_catch_vfork
;
16021 ops
->print_one
= print_one_catch_vfork
;
16022 ops
->print_mention
= print_mention_catch_vfork
;
16023 ops
->print_recreate
= print_recreate_catch_vfork
;
16025 /* Exec catchpoints. */
16026 ops
= &catch_exec_breakpoint_ops
;
16027 *ops
= base_breakpoint_ops
;
16028 ops
->dtor
= dtor_catch_exec
;
16029 ops
->insert_location
= insert_catch_exec
;
16030 ops
->remove_location
= remove_catch_exec
;
16031 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16032 ops
->print_it
= print_it_catch_exec
;
16033 ops
->print_one
= print_one_catch_exec
;
16034 ops
->print_mention
= print_mention_catch_exec
;
16035 ops
->print_recreate
= print_recreate_catch_exec
;
16037 /* Solib-related catchpoints. */
16038 ops
= &catch_solib_breakpoint_ops
;
16039 *ops
= base_breakpoint_ops
;
16040 ops
->dtor
= dtor_catch_solib
;
16041 ops
->insert_location
= insert_catch_solib
;
16042 ops
->remove_location
= remove_catch_solib
;
16043 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16044 ops
->check_status
= check_status_catch_solib
;
16045 ops
->print_it
= print_it_catch_solib
;
16046 ops
->print_one
= print_one_catch_solib
;
16047 ops
->print_mention
= print_mention_catch_solib
;
16048 ops
->print_recreate
= print_recreate_catch_solib
;
16050 ops
= &dprintf_breakpoint_ops
;
16051 *ops
= bkpt_base_breakpoint_ops
;
16052 ops
->re_set
= dprintf_re_set
;
16053 ops
->resources_needed
= bkpt_resources_needed
;
16054 ops
->print_it
= bkpt_print_it
;
16055 ops
->print_mention
= bkpt_print_mention
;
16056 ops
->print_recreate
= dprintf_print_recreate
;
16057 ops
->after_condition_true
= dprintf_after_condition_true
;
16058 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16061 /* Chain containing all defined "enable breakpoint" subcommands. */
16063 static struct cmd_list_element
*enablebreaklist
= NULL
;
16066 _initialize_breakpoint (void)
16068 struct cmd_list_element
*c
;
16070 initialize_breakpoint_ops ();
16072 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16073 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16074 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16076 breakpoint_objfile_key
16077 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16079 breakpoint_chain
= 0;
16080 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16081 before a breakpoint is set. */
16082 breakpoint_count
= 0;
16084 tracepoint_count
= 0;
16086 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16087 Set ignore-count of breakpoint number N to COUNT.\n\
16088 Usage is `ignore N COUNT'."));
16090 add_com ("commands", class_breakpoint
, commands_command
, _("\
16091 Set commands to be executed when the given breakpoints are hit.\n\
16092 Give a space-separated breakpoint list as argument after \"commands\".\n\
16093 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
16095 With no argument, the targeted breakpoint is the last one set.\n\
16096 The commands themselves follow starting on the next line.\n\
16097 Type a line containing \"end\" to indicate the end of them.\n\
16098 Give \"silent\" as the first line to make the breakpoint silent;\n\
16099 then no output is printed when it is hit, except what the commands print."));
16101 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16102 Specify breakpoint number N to break only if COND is true.\n\
16103 Usage is `condition N COND', where N is an integer and COND is an\n\
16104 expression to be evaluated whenever breakpoint N is reached."));
16105 set_cmd_completer (c
, condition_completer
);
16107 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16108 Set a temporary breakpoint.\n\
16109 Like \"break\" except the breakpoint is only temporary,\n\
16110 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16111 by using \"enable delete\" on the breakpoint number.\n\
16113 BREAK_ARGS_HELP ("tbreak")));
16114 set_cmd_completer (c
, location_completer
);
16116 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16117 Set a hardware assisted breakpoint.\n\
16118 Like \"break\" except the breakpoint requires hardware support,\n\
16119 some target hardware may not have this support.\n\
16121 BREAK_ARGS_HELP ("hbreak")));
16122 set_cmd_completer (c
, location_completer
);
16124 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16125 Set a temporary hardware assisted breakpoint.\n\
16126 Like \"hbreak\" except the breakpoint is only temporary,\n\
16127 so it will be deleted when hit.\n\
16129 BREAK_ARGS_HELP ("thbreak")));
16130 set_cmd_completer (c
, location_completer
);
16132 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16133 Enable some breakpoints.\n\
16134 Give breakpoint numbers (separated by spaces) as arguments.\n\
16135 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16136 This is used to cancel the effect of the \"disable\" command.\n\
16137 With a subcommand you can enable temporarily."),
16138 &enablelist
, "enable ", 1, &cmdlist
);
16140 add_com_alias ("en", "enable", class_breakpoint
, 1);
16142 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16143 Enable some breakpoints.\n\
16144 Give breakpoint numbers (separated by spaces) as arguments.\n\
16145 This is used to cancel the effect of the \"disable\" command.\n\
16146 May be abbreviated to simply \"enable\".\n"),
16147 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16149 add_cmd ("once", no_class
, enable_once_command
, _("\
16150 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16151 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16154 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16155 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16156 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16159 add_cmd ("count", no_class
, enable_count_command
, _("\
16160 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16161 If a breakpoint is hit while enabled in this fashion,\n\
16162 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16165 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16166 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16167 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16170 add_cmd ("once", no_class
, enable_once_command
, _("\
16171 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16172 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16175 add_cmd ("count", no_class
, enable_count_command
, _("\
16176 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16177 If a breakpoint is hit while enabled in this fashion,\n\
16178 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16181 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16182 Disable some breakpoints.\n\
16183 Arguments are breakpoint numbers with spaces in between.\n\
16184 To disable all breakpoints, give no argument.\n\
16185 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16186 &disablelist
, "disable ", 1, &cmdlist
);
16187 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16188 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16190 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16191 Disable some breakpoints.\n\
16192 Arguments are breakpoint numbers with spaces in between.\n\
16193 To disable all breakpoints, give no argument.\n\
16194 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16195 This command may be abbreviated \"disable\"."),
16198 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16199 Delete some breakpoints or auto-display expressions.\n\
16200 Arguments are breakpoint numbers with spaces in between.\n\
16201 To delete all breakpoints, give no argument.\n\
16203 Also a prefix command for deletion of other GDB objects.\n\
16204 The \"unset\" command is also an alias for \"delete\"."),
16205 &deletelist
, "delete ", 1, &cmdlist
);
16206 add_com_alias ("d", "delete", class_breakpoint
, 1);
16207 add_com_alias ("del", "delete", class_breakpoint
, 1);
16209 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16210 Delete some breakpoints or auto-display expressions.\n\
16211 Arguments are breakpoint numbers with spaces in between.\n\
16212 To delete all breakpoints, give no argument.\n\
16213 This command may be abbreviated \"delete\"."),
16216 add_com ("clear", class_breakpoint
, clear_command
, _("\
16217 Clear breakpoint at specified location.\n\
16218 Argument may be a linespec, explicit, or address location as described below.\n\
16220 With no argument, clears all breakpoints in the line that the selected frame\n\
16221 is executing in.\n"
16222 "\n" LOCATION_HELP_STRING
"\n\
16223 See also the \"delete\" command which clears breakpoints by number."));
16224 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16226 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16227 Set breakpoint at specified location.\n"
16228 BREAK_ARGS_HELP ("break")));
16229 set_cmd_completer (c
, location_completer
);
16231 add_com_alias ("b", "break", class_run
, 1);
16232 add_com_alias ("br", "break", class_run
, 1);
16233 add_com_alias ("bre", "break", class_run
, 1);
16234 add_com_alias ("brea", "break", class_run
, 1);
16238 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16239 Break in function/address or break at a line in the current file."),
16240 &stoplist
, "stop ", 1, &cmdlist
);
16241 add_cmd ("in", class_breakpoint
, stopin_command
,
16242 _("Break in function or address."), &stoplist
);
16243 add_cmd ("at", class_breakpoint
, stopat_command
,
16244 _("Break at a line in the current file."), &stoplist
);
16245 add_com ("status", class_info
, breakpoints_info
, _("\
16246 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16247 The \"Type\" column indicates one of:\n\
16248 \tbreakpoint - normal breakpoint\n\
16249 \twatchpoint - watchpoint\n\
16250 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16251 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16252 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16253 address and file/line number respectively.\n\
16255 Convenience variable \"$_\" and default examine address for \"x\"\n\
16256 are set to the address of the last breakpoint listed unless the command\n\
16257 is prefixed with \"server \".\n\n\
16258 Convenience variable \"$bpnum\" contains the number of the last\n\
16259 breakpoint set."));
16262 add_info ("breakpoints", breakpoints_info
, _("\
16263 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16264 The \"Type\" column indicates one of:\n\
16265 \tbreakpoint - normal breakpoint\n\
16266 \twatchpoint - watchpoint\n\
16267 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16268 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16269 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16270 address and file/line number respectively.\n\
16272 Convenience variable \"$_\" and default examine address for \"x\"\n\
16273 are set to the address of the last breakpoint listed unless the command\n\
16274 is prefixed with \"server \".\n\n\
16275 Convenience variable \"$bpnum\" contains the number of the last\n\
16276 breakpoint set."));
16278 add_info_alias ("b", "breakpoints", 1);
16280 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16281 Status of all breakpoints, or breakpoint number NUMBER.\n\
16282 The \"Type\" column indicates one of:\n\
16283 \tbreakpoint - normal breakpoint\n\
16284 \twatchpoint - watchpoint\n\
16285 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16286 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16287 \tuntil - internal breakpoint used by the \"until\" command\n\
16288 \tfinish - internal breakpoint used by the \"finish\" command\n\
16289 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16290 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16291 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16292 address and file/line number respectively.\n\
16294 Convenience variable \"$_\" and default examine address for \"x\"\n\
16295 are set to the address of the last breakpoint listed unless the command\n\
16296 is prefixed with \"server \".\n\n\
16297 Convenience variable \"$bpnum\" contains the number of the last\n\
16299 &maintenanceinfolist
);
16301 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16302 Set catchpoints to catch events."),
16303 &catch_cmdlist
, "catch ",
16304 0/*allow-unknown*/, &cmdlist
);
16306 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16307 Set temporary catchpoints to catch events."),
16308 &tcatch_cmdlist
, "tcatch ",
16309 0/*allow-unknown*/, &cmdlist
);
16311 add_catch_command ("fork", _("Catch calls to fork."),
16312 catch_fork_command_1
,
16314 (void *) (uintptr_t) catch_fork_permanent
,
16315 (void *) (uintptr_t) catch_fork_temporary
);
16316 add_catch_command ("vfork", _("Catch calls to vfork."),
16317 catch_fork_command_1
,
16319 (void *) (uintptr_t) catch_vfork_permanent
,
16320 (void *) (uintptr_t) catch_vfork_temporary
);
16321 add_catch_command ("exec", _("Catch calls to exec."),
16322 catch_exec_command_1
,
16326 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16327 Usage: catch load [REGEX]\n\
16328 If REGEX is given, only stop for libraries matching the regular expression."),
16329 catch_load_command_1
,
16333 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16334 Usage: catch unload [REGEX]\n\
16335 If REGEX is given, only stop for libraries matching the regular expression."),
16336 catch_unload_command_1
,
16341 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16342 Set a watchpoint for an expression.\n\
16343 Usage: watch [-l|-location] EXPRESSION\n\
16344 A watchpoint stops execution of your program whenever the value of\n\
16345 an expression changes.\n\
16346 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16347 the memory to which it refers."));
16348 set_cmd_completer (c
, expression_completer
);
16350 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16351 Set a read watchpoint for an expression.\n\
16352 Usage: rwatch [-l|-location] EXPRESSION\n\
16353 A watchpoint stops execution of your program whenever the value of\n\
16354 an expression is read.\n\
16355 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16356 the memory to which it refers."));
16357 set_cmd_completer (c
, expression_completer
);
16359 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16360 Set a watchpoint for an expression.\n\
16361 Usage: awatch [-l|-location] EXPRESSION\n\
16362 A watchpoint stops execution of your program whenever the value of\n\
16363 an expression is either read or written.\n\
16364 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16365 the memory to which it refers."));
16366 set_cmd_completer (c
, expression_completer
);
16368 add_info ("watchpoints", watchpoints_info
, _("\
16369 Status of specified watchpoints (all watchpoints if no argument)."));
16371 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16372 respond to changes - contrary to the description. */
16373 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16374 &can_use_hw_watchpoints
, _("\
16375 Set debugger's willingness to use watchpoint hardware."), _("\
16376 Show debugger's willingness to use watchpoint hardware."), _("\
16377 If zero, gdb will not use hardware for new watchpoints, even if\n\
16378 such is available. (However, any hardware watchpoints that were\n\
16379 created before setting this to nonzero, will continue to use watchpoint\n\
16382 show_can_use_hw_watchpoints
,
16383 &setlist
, &showlist
);
16385 can_use_hw_watchpoints
= 1;
16387 /* Tracepoint manipulation commands. */
16389 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16390 Set a tracepoint at specified location.\n\
16392 BREAK_ARGS_HELP ("trace") "\n\
16393 Do \"help tracepoints\" for info on other tracepoint commands."));
16394 set_cmd_completer (c
, location_completer
);
16396 add_com_alias ("tp", "trace", class_alias
, 0);
16397 add_com_alias ("tr", "trace", class_alias
, 1);
16398 add_com_alias ("tra", "trace", class_alias
, 1);
16399 add_com_alias ("trac", "trace", class_alias
, 1);
16401 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16402 Set a fast tracepoint at specified location.\n\
16404 BREAK_ARGS_HELP ("ftrace") "\n\
16405 Do \"help tracepoints\" for info on other tracepoint commands."));
16406 set_cmd_completer (c
, location_completer
);
16408 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16409 Set a static tracepoint at location or marker.\n\
16411 strace [LOCATION] [if CONDITION]\n\
16412 LOCATION may be a linespec, explicit, or address location (described below) \n\
16413 or -m MARKER_ID.\n\n\
16414 If a marker id is specified, probe the marker with that name. With\n\
16415 no LOCATION, uses current execution address of the selected stack frame.\n\
16416 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16417 This collects arbitrary user data passed in the probe point call to the\n\
16418 tracing library. You can inspect it when analyzing the trace buffer,\n\
16419 by printing the $_sdata variable like any other convenience variable.\n\
16421 CONDITION is a boolean expression.\n\
16422 \n" LOCATION_HELP_STRING
"\n\
16423 Multiple tracepoints at one place are permitted, and useful if their\n\
16424 conditions are different.\n\
16426 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16427 Do \"help tracepoints\" for info on other tracepoint commands."));
16428 set_cmd_completer (c
, location_completer
);
16430 add_info ("tracepoints", tracepoints_info
, _("\
16431 Status of specified tracepoints (all tracepoints if no argument).\n\
16432 Convenience variable \"$tpnum\" contains the number of the\n\
16433 last tracepoint set."));
16435 add_info_alias ("tp", "tracepoints", 1);
16437 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16438 Delete specified tracepoints.\n\
16439 Arguments are tracepoint numbers, separated by spaces.\n\
16440 No argument means delete all tracepoints."),
16442 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16444 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16445 Disable specified tracepoints.\n\
16446 Arguments are tracepoint numbers, separated by spaces.\n\
16447 No argument means disable all tracepoints."),
16449 deprecate_cmd (c
, "disable");
16451 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16452 Enable specified tracepoints.\n\
16453 Arguments are tracepoint numbers, separated by spaces.\n\
16454 No argument means enable all tracepoints."),
16456 deprecate_cmd (c
, "enable");
16458 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16459 Set the passcount for a tracepoint.\n\
16460 The trace will end when the tracepoint has been passed 'count' times.\n\
16461 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16462 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16464 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16465 _("Save breakpoint definitions as a script."),
16466 &save_cmdlist
, "save ",
16467 0/*allow-unknown*/, &cmdlist
);
16469 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16470 Save current breakpoint definitions as a script.\n\
16471 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16472 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16473 session to restore them."),
16475 set_cmd_completer (c
, filename_completer
);
16477 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16478 Save current tracepoint definitions as a script.\n\
16479 Use the 'source' command in another debug session to restore them."),
16481 set_cmd_completer (c
, filename_completer
);
16483 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16484 deprecate_cmd (c
, "save tracepoints");
16486 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16487 Breakpoint specific settings\n\
16488 Configure various breakpoint-specific variables such as\n\
16489 pending breakpoint behavior"),
16490 &breakpoint_set_cmdlist
, "set breakpoint ",
16491 0/*allow-unknown*/, &setlist
);
16492 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16493 Breakpoint specific settings\n\
16494 Configure various breakpoint-specific variables such as\n\
16495 pending breakpoint behavior"),
16496 &breakpoint_show_cmdlist
, "show breakpoint ",
16497 0/*allow-unknown*/, &showlist
);
16499 add_setshow_auto_boolean_cmd ("pending", no_class
,
16500 &pending_break_support
, _("\
16501 Set debugger's behavior regarding pending breakpoints."), _("\
16502 Show debugger's behavior regarding pending breakpoints."), _("\
16503 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16504 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16505 an error. If auto, an unrecognized breakpoint location results in a\n\
16506 user-query to see if a pending breakpoint should be created."),
16508 show_pending_break_support
,
16509 &breakpoint_set_cmdlist
,
16510 &breakpoint_show_cmdlist
);
16512 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16514 add_setshow_boolean_cmd ("auto-hw", no_class
,
16515 &automatic_hardware_breakpoints
, _("\
16516 Set automatic usage of hardware breakpoints."), _("\
16517 Show automatic usage of hardware breakpoints."), _("\
16518 If set, the debugger will automatically use hardware breakpoints for\n\
16519 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16520 a warning will be emitted for such breakpoints."),
16522 show_automatic_hardware_breakpoints
,
16523 &breakpoint_set_cmdlist
,
16524 &breakpoint_show_cmdlist
);
16526 add_setshow_boolean_cmd ("always-inserted", class_support
,
16527 &always_inserted_mode
, _("\
16528 Set mode for inserting breakpoints."), _("\
16529 Show mode for inserting breakpoints."), _("\
16530 When this mode is on, breakpoints are inserted immediately as soon as\n\
16531 they're created, kept inserted even when execution stops, and removed\n\
16532 only when the user deletes them. When this mode is off (the default),\n\
16533 breakpoints are inserted only when execution continues, and removed\n\
16534 when execution stops."),
16536 &show_always_inserted_mode
,
16537 &breakpoint_set_cmdlist
,
16538 &breakpoint_show_cmdlist
);
16540 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16541 condition_evaluation_enums
,
16542 &condition_evaluation_mode_1
, _("\
16543 Set mode of breakpoint condition evaluation."), _("\
16544 Show mode of breakpoint condition evaluation."), _("\
16545 When this is set to \"host\", breakpoint conditions will be\n\
16546 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16547 breakpoint conditions will be downloaded to the target (if the target\n\
16548 supports such feature) and conditions will be evaluated on the target's side.\n\
16549 If this is set to \"auto\" (default), this will be automatically set to\n\
16550 \"target\" if it supports condition evaluation, otherwise it will\n\
16551 be set to \"gdb\""),
16552 &set_condition_evaluation_mode
,
16553 &show_condition_evaluation_mode
,
16554 &breakpoint_set_cmdlist
,
16555 &breakpoint_show_cmdlist
);
16557 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16558 Set a breakpoint for an address range.\n\
16559 break-range START-LOCATION, END-LOCATION\n\
16560 where START-LOCATION and END-LOCATION can be one of the following:\n\
16561 LINENUM, for that line in the current file,\n\
16562 FILE:LINENUM, for that line in that file,\n\
16563 +OFFSET, for that number of lines after the current line\n\
16564 or the start of the range\n\
16565 FUNCTION, for the first line in that function,\n\
16566 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16567 *ADDRESS, for the instruction at that address.\n\
16569 The breakpoint will stop execution of the inferior whenever it executes\n\
16570 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16571 range (including START-LOCATION and END-LOCATION)."));
16573 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16574 Set a dynamic printf at specified location.\n\
16575 dprintf location,format string,arg1,arg2,...\n\
16576 location may be a linespec, explicit, or address location.\n"
16577 "\n" LOCATION_HELP_STRING
));
16578 set_cmd_completer (c
, location_completer
);
16580 add_setshow_enum_cmd ("dprintf-style", class_support
,
16581 dprintf_style_enums
, &dprintf_style
, _("\
16582 Set the style of usage for dynamic printf."), _("\
16583 Show the style of usage for dynamic printf."), _("\
16584 This setting chooses how GDB will do a dynamic printf.\n\
16585 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16586 console, as with the \"printf\" command.\n\
16587 If the value is \"call\", the print is done by calling a function in your\n\
16588 program; by default printf(), but you can choose a different function or\n\
16589 output stream by setting dprintf-function and dprintf-channel."),
16590 update_dprintf_commands
, NULL
,
16591 &setlist
, &showlist
);
16593 dprintf_function
= xstrdup ("printf");
16594 add_setshow_string_cmd ("dprintf-function", class_support
,
16595 &dprintf_function
, _("\
16596 Set the function to use for dynamic printf"), _("\
16597 Show the function to use for dynamic printf"), NULL
,
16598 update_dprintf_commands
, NULL
,
16599 &setlist
, &showlist
);
16601 dprintf_channel
= xstrdup ("");
16602 add_setshow_string_cmd ("dprintf-channel", class_support
,
16603 &dprintf_channel
, _("\
16604 Set the channel to use for dynamic printf"), _("\
16605 Show the channel to use for dynamic printf"), NULL
,
16606 update_dprintf_commands
, NULL
,
16607 &setlist
, &showlist
);
16609 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16610 &disconnected_dprintf
, _("\
16611 Set whether dprintf continues after GDB disconnects."), _("\
16612 Show whether dprintf continues after GDB disconnects."), _("\
16613 Use this to let dprintf commands continue to hit and produce output\n\
16614 even if GDB disconnects or detaches from the target."),
16617 &setlist
, &showlist
);
16619 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16620 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16621 (target agent only) This is useful for formatted output in user-defined commands."));
16623 automatic_hardware_breakpoints
= 1;
16625 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16626 observer_attach_thread_exit (remove_threaded_breakpoints
);