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"
83 #include "progspace-and-thread.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (const char *,
106 void (*) (struct breakpoint
*,
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint
*);
117 create_sals_from_location_default (const struct event_location
*location
,
118 struct linespec_result
*canonical
,
119 enum bptype type_wanted
);
121 static void create_breakpoints_sal_default (struct gdbarch
*,
122 struct linespec_result
*,
123 char *, char *, enum bptype
,
124 enum bpdisp
, int, int,
126 const struct breakpoint_ops
*,
127 int, int, int, unsigned);
129 static void decode_location_default (struct breakpoint
*b
,
130 const struct event_location
*location
,
131 struct program_space
*search_pspace
,
132 struct symtabs_and_lines
*sals
);
134 static void clear_command (char *, int);
136 static void catch_command (char *, int);
138 static int can_use_hardware_watchpoint (struct value
*);
140 static void break_command_1 (char *, int, int);
142 static void mention (struct breakpoint
*);
144 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
146 const struct breakpoint_ops
*);
147 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
148 const struct symtab_and_line
*);
150 /* This function is used in gdbtk sources and thus can not be made
152 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
153 struct symtab_and_line
,
155 const struct breakpoint_ops
*);
157 static struct breakpoint
*
158 momentary_breakpoint_from_master (struct breakpoint
*orig
,
160 const struct breakpoint_ops
*ops
,
163 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
165 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
169 static void describe_other_breakpoints (struct gdbarch
*,
170 struct program_space
*, CORE_ADDR
,
171 struct obj_section
*, int);
173 static int watchpoint_locations_match (struct bp_location
*loc1
,
174 struct bp_location
*loc2
);
176 static int breakpoint_location_address_match (struct bp_location
*bl
,
177 struct address_space
*aspace
,
180 static int breakpoint_location_address_range_overlap (struct bp_location
*,
181 struct address_space
*,
184 static void breakpoints_info (char *, int);
186 static void watchpoints_info (char *, int);
188 static int breakpoint_1 (char *, int,
189 int (*) (const struct breakpoint
*));
191 static int breakpoint_cond_eval (void *);
193 static void cleanup_executing_breakpoints (void *);
195 static void commands_command (char *, int);
197 static void condition_command (char *, int);
199 static int remove_breakpoint (struct bp_location
*);
200 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
202 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
204 static int watchpoint_check (void *);
206 static void maintenance_info_breakpoints (char *, int);
208 static int hw_breakpoint_used_count (void);
210 static int hw_watchpoint_use_count (struct breakpoint
*);
212 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
214 int *other_type_used
);
216 static void hbreak_command (char *, int);
218 static void thbreak_command (char *, int);
220 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
223 static void stop_command (char *arg
, int from_tty
);
225 static void stopin_command (char *arg
, int from_tty
);
227 static void stopat_command (char *arg
, int from_tty
);
229 static void tcatch_command (char *arg
, int from_tty
);
231 static void free_bp_location (struct bp_location
*loc
);
232 static void incref_bp_location (struct bp_location
*loc
);
233 static void decref_bp_location (struct bp_location
**loc
);
235 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
237 /* update_global_location_list's modes of operation wrt to whether to
238 insert locations now. */
239 enum ugll_insert_mode
241 /* Don't insert any breakpoint locations into the inferior, only
242 remove already-inserted locations that no longer should be
243 inserted. Functions that delete a breakpoint or breakpoints
244 should specify this mode, so that deleting a breakpoint doesn't
245 have the side effect of inserting the locations of other
246 breakpoints that are marked not-inserted, but should_be_inserted
247 returns true on them.
249 This behavior is useful is situations close to tear-down -- e.g.,
250 after an exec, while the target still has execution, but
251 breakpoint shadows of the previous executable image should *NOT*
252 be restored to the new image; or before detaching, where the
253 target still has execution and wants to delete breakpoints from
254 GDB's lists, and all breakpoints had already been removed from
258 /* May insert breakpoints iff breakpoints_should_be_inserted_now
259 claims breakpoints should be inserted now. */
262 /* Insert locations now, irrespective of
263 breakpoints_should_be_inserted_now. E.g., say all threads are
264 stopped right now, and the user did "continue". We need to
265 insert breakpoints _before_ resuming the target, but
266 UGLL_MAY_INSERT wouldn't insert them, because
267 breakpoints_should_be_inserted_now returns false at that point,
268 as no thread is running yet. */
272 static void update_global_location_list (enum ugll_insert_mode
);
274 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
276 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
278 static void insert_breakpoint_locations (void);
280 static void tracepoints_info (char *, int);
282 static void delete_trace_command (char *, int);
284 static void enable_trace_command (char *, int);
286 static void disable_trace_command (char *, int);
288 static void trace_pass_command (char *, int);
290 static void set_tracepoint_count (int num
);
292 static int is_masked_watchpoint (const struct breakpoint
*b
);
294 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
296 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
299 static int strace_marker_p (struct breakpoint
*b
);
301 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
302 that are implemented on top of software or hardware breakpoints
303 (user breakpoints, internal and momentary breakpoints, etc.). */
304 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
306 /* Internal breakpoints class type. */
307 static struct breakpoint_ops internal_breakpoint_ops
;
309 /* Momentary breakpoints class type. */
310 static struct breakpoint_ops momentary_breakpoint_ops
;
312 /* The breakpoint_ops structure to be used in regular user created
314 struct breakpoint_ops bkpt_breakpoint_ops
;
316 /* Breakpoints set on probes. */
317 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
319 /* Dynamic printf class type. */
320 struct breakpoint_ops dprintf_breakpoint_ops
;
322 /* The style in which to perform a dynamic printf. This is a user
323 option because different output options have different tradeoffs;
324 if GDB does the printing, there is better error handling if there
325 is a problem with any of the arguments, but using an inferior
326 function lets you have special-purpose printers and sending of
327 output to the same place as compiled-in print functions. */
329 static const char dprintf_style_gdb
[] = "gdb";
330 static const char dprintf_style_call
[] = "call";
331 static const char dprintf_style_agent
[] = "agent";
332 static const char *const dprintf_style_enums
[] = {
338 static const char *dprintf_style
= dprintf_style_gdb
;
340 /* The function to use for dynamic printf if the preferred style is to
341 call into the inferior. The value is simply a string that is
342 copied into the command, so it can be anything that GDB can
343 evaluate to a callable address, not necessarily a function name. */
345 static char *dprintf_function
;
347 /* The channel to use for dynamic printf if the preferred style is to
348 call into the inferior; if a nonempty string, it will be passed to
349 the call as the first argument, with the format string as the
350 second. As with the dprintf function, this can be anything that
351 GDB knows how to evaluate, so in addition to common choices like
352 "stderr", this could be an app-specific expression like
353 "mystreams[curlogger]". */
355 static char *dprintf_channel
;
357 /* True if dprintf commands should continue to operate even if GDB
359 static int disconnected_dprintf
= 1;
361 /* A reference-counted struct command_line. This lets multiple
362 breakpoints share a single command list. */
363 struct counted_command_line
365 /* The reference count. */
368 /* The command list. */
369 struct command_line
*commands
;
372 struct command_line
*
373 breakpoint_commands (struct breakpoint
*b
)
375 return b
->commands
? b
->commands
->commands
: NULL
;
378 /* Flag indicating that a command has proceeded the inferior past the
379 current breakpoint. */
381 static int breakpoint_proceeded
;
384 bpdisp_text (enum bpdisp disp
)
386 /* NOTE: the following values are a part of MI protocol and
387 represent values of 'disp' field returned when inferior stops at
389 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
391 return bpdisps
[(int) disp
];
394 /* Prototypes for exported functions. */
395 /* If FALSE, gdb will not use hardware support for watchpoints, even
396 if such is available. */
397 static int can_use_hw_watchpoints
;
400 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
401 struct cmd_list_element
*c
,
404 fprintf_filtered (file
,
405 _("Debugger's willingness to use "
406 "watchpoint hardware is %s.\n"),
410 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
411 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
412 for unrecognized breakpoint locations.
413 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
414 static enum auto_boolean pending_break_support
;
416 show_pending_break_support (struct ui_file
*file
, int from_tty
,
417 struct cmd_list_element
*c
,
420 fprintf_filtered (file
,
421 _("Debugger's behavior regarding "
422 "pending breakpoints is %s.\n"),
426 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
427 set with "break" but falling in read-only memory.
428 If 0, gdb will warn about such breakpoints, but won't automatically
429 use hardware breakpoints. */
430 static int automatic_hardware_breakpoints
;
432 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
433 struct cmd_list_element
*c
,
436 fprintf_filtered (file
,
437 _("Automatic usage of hardware breakpoints is %s.\n"),
441 /* If on, GDB keeps breakpoints inserted even if the inferior is
442 stopped, and immediately inserts any new breakpoints as soon as
443 they're created. If off (default), GDB keeps breakpoints off of
444 the target as long as possible. That is, it delays inserting
445 breakpoints until the next resume, and removes them again when the
446 target fully stops. This is a bit safer in case GDB crashes while
447 processing user input. */
448 static int always_inserted_mode
= 0;
451 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
452 struct cmd_list_element
*c
, const char *value
)
454 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
458 /* See breakpoint.h. */
461 breakpoints_should_be_inserted_now (void)
463 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
465 /* If breakpoints are global, they should be inserted even if no
466 thread under gdb's control is running, or even if there are
467 no threads under GDB's control yet. */
470 else if (target_has_execution
)
472 struct thread_info
*tp
;
474 if (always_inserted_mode
)
476 /* The user wants breakpoints inserted even if all threads
481 if (threads_are_executing ())
484 /* Don't remove breakpoints yet if, even though all threads are
485 stopped, we still have events to process. */
486 ALL_NON_EXITED_THREADS (tp
)
488 && tp
->suspend
.waitstatus_pending_p
)
494 static const char condition_evaluation_both
[] = "host or target";
496 /* Modes for breakpoint condition evaluation. */
497 static const char condition_evaluation_auto
[] = "auto";
498 static const char condition_evaluation_host
[] = "host";
499 static const char condition_evaluation_target
[] = "target";
500 static const char *const condition_evaluation_enums
[] = {
501 condition_evaluation_auto
,
502 condition_evaluation_host
,
503 condition_evaluation_target
,
507 /* Global that holds the current mode for breakpoint condition evaluation. */
508 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
510 /* Global that we use to display information to the user (gets its value from
511 condition_evaluation_mode_1. */
512 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
514 /* Translate a condition evaluation mode MODE into either "host"
515 or "target". This is used mostly to translate from "auto" to the
516 real setting that is being used. It returns the translated
520 translate_condition_evaluation_mode (const char *mode
)
522 if (mode
== condition_evaluation_auto
)
524 if (target_supports_evaluation_of_breakpoint_conditions ())
525 return condition_evaluation_target
;
527 return condition_evaluation_host
;
533 /* Discovers what condition_evaluation_auto translates to. */
536 breakpoint_condition_evaluation_mode (void)
538 return translate_condition_evaluation_mode (condition_evaluation_mode
);
541 /* Return true if GDB should evaluate breakpoint conditions or false
545 gdb_evaluates_breakpoint_condition_p (void)
547 const char *mode
= breakpoint_condition_evaluation_mode ();
549 return (mode
== condition_evaluation_host
);
552 void _initialize_breakpoint (void);
554 /* Are we executing breakpoint commands? */
555 static int executing_breakpoint_commands
;
557 /* Are overlay event breakpoints enabled? */
558 static int overlay_events_enabled
;
560 /* See description in breakpoint.h. */
561 int target_exact_watchpoints
= 0;
563 /* Walk the following statement or block through all breakpoints.
564 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
565 current breakpoint. */
567 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
569 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
570 for (B = breakpoint_chain; \
571 B ? (TMP=B->next, 1): 0; \
574 /* Similar iterator for the low-level breakpoints. SAFE variant is
575 not provided so update_global_location_list must not be called
576 while executing the block of ALL_BP_LOCATIONS. */
578 #define ALL_BP_LOCATIONS(B,BP_TMP) \
579 for (BP_TMP = bp_locations; \
580 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
583 /* Iterates through locations with address ADDRESS for the currently selected
584 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
585 to where the loop should start from.
586 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
587 appropriate location to start with. */
589 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
590 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
591 BP_LOCP_TMP = BP_LOCP_START; \
593 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
594 && (*BP_LOCP_TMP)->address == ADDRESS); \
597 /* Iterator for tracepoints only. */
599 #define ALL_TRACEPOINTS(B) \
600 for (B = breakpoint_chain; B; B = B->next) \
601 if (is_tracepoint (B))
603 /* Chains of all breakpoints defined. */
605 struct breakpoint
*breakpoint_chain
;
607 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
609 static struct bp_location
**bp_locations
;
611 /* Number of elements of BP_LOCATIONS. */
613 static unsigned bp_locations_count
;
615 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
616 ADDRESS for the current elements of BP_LOCATIONS which get a valid
617 result from bp_location_has_shadow. You can use it for roughly
618 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
619 an address you need to read. */
621 static CORE_ADDR bp_locations_placed_address_before_address_max
;
623 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
624 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
625 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
626 You can use it for roughly limiting the subrange of BP_LOCATIONS to
627 scan for shadow bytes for an address you need to read. */
629 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
631 /* The locations that no longer correspond to any breakpoint, unlinked
632 from the bp_locations array, but for which a hit may still be
633 reported by a target. */
634 VEC(bp_location_p
) *moribund_locations
= NULL
;
636 /* Number of last breakpoint made. */
638 static int breakpoint_count
;
640 /* The value of `breakpoint_count' before the last command that
641 created breakpoints. If the last (break-like) command created more
642 than one breakpoint, then the difference between BREAKPOINT_COUNT
643 and PREV_BREAKPOINT_COUNT is more than one. */
644 static int prev_breakpoint_count
;
646 /* Number of last tracepoint made. */
648 static int tracepoint_count
;
650 static struct cmd_list_element
*breakpoint_set_cmdlist
;
651 static struct cmd_list_element
*breakpoint_show_cmdlist
;
652 struct cmd_list_element
*save_cmdlist
;
654 /* See declaration at breakpoint.h. */
657 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
660 struct breakpoint
*b
= NULL
;
664 if (func (b
, user_data
) != 0)
671 /* Return whether a breakpoint is an active enabled breakpoint. */
673 breakpoint_enabled (struct breakpoint
*b
)
675 return (b
->enable_state
== bp_enabled
);
678 /* Set breakpoint count to NUM. */
681 set_breakpoint_count (int num
)
683 prev_breakpoint_count
= breakpoint_count
;
684 breakpoint_count
= num
;
685 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
688 /* Used by `start_rbreak_breakpoints' below, to record the current
689 breakpoint count before "rbreak" creates any breakpoint. */
690 static int rbreak_start_breakpoint_count
;
692 /* Called at the start an "rbreak" command to record the first
696 start_rbreak_breakpoints (void)
698 rbreak_start_breakpoint_count
= breakpoint_count
;
701 /* Called at the end of an "rbreak" command to record the last
705 end_rbreak_breakpoints (void)
707 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
710 /* Used in run_command to zero the hit count when a new run starts. */
713 clear_breakpoint_hit_counts (void)
715 struct breakpoint
*b
;
721 /* Allocate a new counted_command_line with reference count of 1.
722 The new structure owns COMMANDS. */
724 static struct counted_command_line
*
725 alloc_counted_command_line (struct command_line
*commands
)
727 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
730 result
->commands
= commands
;
735 /* Increment reference count. This does nothing if CMD is NULL. */
738 incref_counted_command_line (struct counted_command_line
*cmd
)
744 /* Decrement reference count. If the reference count reaches 0,
745 destroy the counted_command_line. Sets *CMDP to NULL. This does
746 nothing if *CMDP is NULL. */
749 decref_counted_command_line (struct counted_command_line
**cmdp
)
753 if (--(*cmdp
)->refc
== 0)
755 free_command_lines (&(*cmdp
)->commands
);
762 /* A cleanup function that calls decref_counted_command_line. */
765 do_cleanup_counted_command_line (void *arg
)
767 decref_counted_command_line ((struct counted_command_line
**) arg
);
770 /* Create a cleanup that calls decref_counted_command_line on the
773 static struct cleanup
*
774 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
776 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
780 /* Return the breakpoint with the specified number, or NULL
781 if the number does not refer to an existing breakpoint. */
784 get_breakpoint (int num
)
786 struct breakpoint
*b
;
789 if (b
->number
== num
)
797 /* Mark locations as "conditions have changed" in case the target supports
798 evaluating conditions on its side. */
801 mark_breakpoint_modified (struct breakpoint
*b
)
803 struct bp_location
*loc
;
805 /* This is only meaningful if the target is
806 evaluating conditions and if the user has
807 opted for condition evaluation on the target's
809 if (gdb_evaluates_breakpoint_condition_p ()
810 || !target_supports_evaluation_of_breakpoint_conditions ())
813 if (!is_breakpoint (b
))
816 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
817 loc
->condition_changed
= condition_modified
;
820 /* Mark location as "conditions have changed" in case the target supports
821 evaluating conditions on its side. */
824 mark_breakpoint_location_modified (struct bp_location
*loc
)
826 /* This is only meaningful if the target is
827 evaluating conditions and if the user has
828 opted for condition evaluation on the target's
830 if (gdb_evaluates_breakpoint_condition_p ()
831 || !target_supports_evaluation_of_breakpoint_conditions ())
835 if (!is_breakpoint (loc
->owner
))
838 loc
->condition_changed
= condition_modified
;
841 /* Sets the condition-evaluation mode using the static global
842 condition_evaluation_mode. */
845 set_condition_evaluation_mode (char *args
, int from_tty
,
846 struct cmd_list_element
*c
)
848 const char *old_mode
, *new_mode
;
850 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
851 && !target_supports_evaluation_of_breakpoint_conditions ())
853 condition_evaluation_mode_1
= condition_evaluation_mode
;
854 warning (_("Target does not support breakpoint condition evaluation.\n"
855 "Using host evaluation mode instead."));
859 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
860 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
862 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
863 settings was "auto". */
864 condition_evaluation_mode
= condition_evaluation_mode_1
;
866 /* Only update the mode if the user picked a different one. */
867 if (new_mode
!= old_mode
)
869 struct bp_location
*loc
, **loc_tmp
;
870 /* If the user switched to a different evaluation mode, we
871 need to synch the changes with the target as follows:
873 "host" -> "target": Send all (valid) conditions to the target.
874 "target" -> "host": Remove all the conditions from the target.
877 if (new_mode
== condition_evaluation_target
)
879 /* Mark everything modified and synch conditions with the
881 ALL_BP_LOCATIONS (loc
, loc_tmp
)
882 mark_breakpoint_location_modified (loc
);
886 /* Manually mark non-duplicate locations to synch conditions
887 with the target. We do this to remove all the conditions the
888 target knows about. */
889 ALL_BP_LOCATIONS (loc
, loc_tmp
)
890 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
891 loc
->needs_update
= 1;
895 update_global_location_list (UGLL_MAY_INSERT
);
901 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
902 what "auto" is translating to. */
905 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
906 struct cmd_list_element
*c
, const char *value
)
908 if (condition_evaluation_mode
== condition_evaluation_auto
)
909 fprintf_filtered (file
,
910 _("Breakpoint condition evaluation "
911 "mode is %s (currently %s).\n"),
913 breakpoint_condition_evaluation_mode ());
915 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
919 /* A comparison function for bp_location AP and BP that is used by
920 bsearch. This comparison function only cares about addresses, unlike
921 the more general bp_locations_compare function. */
924 bp_locations_compare_addrs (const void *ap
, const void *bp
)
926 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
927 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
929 if (a
->address
== b
->address
)
932 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
935 /* Helper function to skip all bp_locations with addresses
936 less than ADDRESS. It returns the first bp_location that
937 is greater than or equal to ADDRESS. If none is found, just
940 static struct bp_location
**
941 get_first_locp_gte_addr (CORE_ADDR address
)
943 struct bp_location dummy_loc
;
944 struct bp_location
*dummy_locp
= &dummy_loc
;
945 struct bp_location
**locp_found
= NULL
;
947 /* Initialize the dummy location's address field. */
948 dummy_loc
.address
= address
;
950 /* Find a close match to the first location at ADDRESS. */
951 locp_found
= ((struct bp_location
**)
952 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
953 sizeof (struct bp_location
**),
954 bp_locations_compare_addrs
));
956 /* Nothing was found, nothing left to do. */
957 if (locp_found
== NULL
)
960 /* We may have found a location that is at ADDRESS but is not the first in the
961 location's list. Go backwards (if possible) and locate the first one. */
962 while ((locp_found
- 1) >= bp_locations
963 && (*(locp_found
- 1))->address
== address
)
970 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
973 xfree (b
->cond_string
);
974 b
->cond_string
= NULL
;
976 if (is_watchpoint (b
))
978 struct watchpoint
*w
= (struct watchpoint
*) b
;
980 w
->cond_exp
.reset ();
984 struct bp_location
*loc
;
986 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
990 /* No need to free the condition agent expression
991 bytecode (if we have one). We will handle this
992 when we go through update_global_location_list. */
999 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1003 const char *arg
= exp
;
1005 /* I don't know if it matters whether this is the string the user
1006 typed in or the decompiled expression. */
1007 b
->cond_string
= xstrdup (arg
);
1008 b
->condition_not_parsed
= 0;
1010 if (is_watchpoint (b
))
1012 struct watchpoint
*w
= (struct watchpoint
*) b
;
1014 innermost_block
= NULL
;
1016 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1018 error (_("Junk at end of expression"));
1019 w
->cond_exp_valid_block
= innermost_block
;
1023 struct bp_location
*loc
;
1025 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1029 parse_exp_1 (&arg
, loc
->address
,
1030 block_for_pc (loc
->address
), 0);
1032 error (_("Junk at end of expression"));
1036 mark_breakpoint_modified (b
);
1038 observer_notify_breakpoint_modified (b
);
1041 /* Completion for the "condition" command. */
1043 static VEC (char_ptr
) *
1044 condition_completer (struct cmd_list_element
*cmd
,
1045 const char *text
, const char *word
)
1049 text
= skip_spaces_const (text
);
1050 space
= skip_to_space_const (text
);
1054 struct breakpoint
*b
;
1055 VEC (char_ptr
) *result
= NULL
;
1059 /* We don't support completion of history indices. */
1060 if (isdigit (text
[1]))
1062 return complete_internalvar (&text
[1]);
1065 /* We're completing the breakpoint number. */
1066 len
= strlen (text
);
1072 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1074 if (strncmp (number
, text
, len
) == 0)
1075 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1081 /* We're completing the expression part. */
1082 text
= skip_spaces_const (space
);
1083 return expression_completer (cmd
, text
, word
);
1086 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1089 condition_command (char *arg
, int from_tty
)
1091 struct breakpoint
*b
;
1096 error_no_arg (_("breakpoint number"));
1099 bnum
= get_number (&p
);
1101 error (_("Bad breakpoint argument: '%s'"), arg
);
1104 if (b
->number
== bnum
)
1106 /* Check if this breakpoint has a "stop" method implemented in an
1107 extension language. This method and conditions entered into GDB
1108 from the CLI are mutually exclusive. */
1109 const struct extension_language_defn
*extlang
1110 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1112 if (extlang
!= NULL
)
1114 error (_("Only one stop condition allowed. There is currently"
1115 " a %s stop condition defined for this breakpoint."),
1116 ext_lang_capitalized_name (extlang
));
1118 set_breakpoint_condition (b
, p
, from_tty
);
1120 if (is_breakpoint (b
))
1121 update_global_location_list (UGLL_MAY_INSERT
);
1126 error (_("No breakpoint number %d."), bnum
);
1129 /* Check that COMMAND do not contain commands that are suitable
1130 only for tracepoints and not suitable for ordinary breakpoints.
1131 Throw if any such commands is found. */
1134 check_no_tracepoint_commands (struct command_line
*commands
)
1136 struct command_line
*c
;
1138 for (c
= commands
; c
; c
= c
->next
)
1142 if (c
->control_type
== while_stepping_control
)
1143 error (_("The 'while-stepping' command can "
1144 "only be used for tracepoints"));
1146 for (i
= 0; i
< c
->body_count
; ++i
)
1147 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1149 /* Not that command parsing removes leading whitespace and comment
1150 lines and also empty lines. So, we only need to check for
1151 command directly. */
1152 if (strstr (c
->line
, "collect ") == c
->line
)
1153 error (_("The 'collect' command can only be used for tracepoints"));
1155 if (strstr (c
->line
, "teval ") == c
->line
)
1156 error (_("The 'teval' command can only be used for tracepoints"));
1160 struct longjmp_breakpoint
: public breakpoint
1162 ~longjmp_breakpoint () override
;
1165 /* Encapsulate tests for different types of tracepoints. */
1168 is_tracepoint_type (bptype type
)
1170 return (type
== bp_tracepoint
1171 || type
== bp_fast_tracepoint
1172 || type
== bp_static_tracepoint
);
1176 is_longjmp_type (bptype type
)
1178 return type
== bp_longjmp
|| type
== bp_exception
;
1182 is_tracepoint (const struct breakpoint
*b
)
1184 return is_tracepoint_type (b
->type
);
1187 /* Factory function to create an appropriate instance of breakpoint given
1190 static std::unique_ptr
<breakpoint
>
1191 new_breakpoint_from_type (bptype type
)
1195 if (is_tracepoint_type (type
))
1196 b
= new tracepoint ();
1197 else if (is_longjmp_type (type
))
1198 b
= new longjmp_breakpoint ();
1200 b
= new breakpoint ();
1202 return std::unique_ptr
<breakpoint
> (b
);
1205 /* A helper function that validates that COMMANDS are valid for a
1206 breakpoint. This function will throw an exception if a problem is
1210 validate_commands_for_breakpoint (struct breakpoint
*b
,
1211 struct command_line
*commands
)
1213 if (is_tracepoint (b
))
1215 struct tracepoint
*t
= (struct tracepoint
*) b
;
1216 struct command_line
*c
;
1217 struct command_line
*while_stepping
= 0;
1219 /* Reset the while-stepping step count. The previous commands
1220 might have included a while-stepping action, while the new
1224 /* We need to verify that each top-level element of commands is
1225 valid for tracepoints, that there's at most one
1226 while-stepping element, and that the while-stepping's body
1227 has valid tracing commands excluding nested while-stepping.
1228 We also need to validate the tracepoint action line in the
1229 context of the tracepoint --- validate_actionline actually
1230 has side effects, like setting the tracepoint's
1231 while-stepping STEP_COUNT, in addition to checking if the
1232 collect/teval actions parse and make sense in the
1233 tracepoint's context. */
1234 for (c
= commands
; c
; c
= c
->next
)
1236 if (c
->control_type
== while_stepping_control
)
1238 if (b
->type
== bp_fast_tracepoint
)
1239 error (_("The 'while-stepping' command "
1240 "cannot be used for fast tracepoint"));
1241 else if (b
->type
== bp_static_tracepoint
)
1242 error (_("The 'while-stepping' command "
1243 "cannot be used for static tracepoint"));
1246 error (_("The 'while-stepping' command "
1247 "can be used only once"));
1252 validate_actionline (c
->line
, b
);
1256 struct command_line
*c2
;
1258 gdb_assert (while_stepping
->body_count
== 1);
1259 c2
= while_stepping
->body_list
[0];
1260 for (; c2
; c2
= c2
->next
)
1262 if (c2
->control_type
== while_stepping_control
)
1263 error (_("The 'while-stepping' command cannot be nested"));
1269 check_no_tracepoint_commands (commands
);
1273 /* Return a vector of all the static tracepoints set at ADDR. The
1274 caller is responsible for releasing the vector. */
1277 static_tracepoints_here (CORE_ADDR addr
)
1279 struct breakpoint
*b
;
1280 VEC(breakpoint_p
) *found
= 0;
1281 struct bp_location
*loc
;
1284 if (b
->type
== bp_static_tracepoint
)
1286 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1287 if (loc
->address
== addr
)
1288 VEC_safe_push(breakpoint_p
, found
, b
);
1294 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1295 validate that only allowed commands are included. */
1298 breakpoint_set_commands (struct breakpoint
*b
,
1299 command_line_up
&&commands
)
1301 validate_commands_for_breakpoint (b
, commands
.get ());
1303 decref_counted_command_line (&b
->commands
);
1304 b
->commands
= alloc_counted_command_line (commands
.release ());
1305 observer_notify_breakpoint_modified (b
);
1308 /* Set the internal `silent' flag on the breakpoint. Note that this
1309 is not the same as the "silent" that may appear in the breakpoint's
1313 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1315 int old_silent
= b
->silent
;
1318 if (old_silent
!= silent
)
1319 observer_notify_breakpoint_modified (b
);
1322 /* Set the thread for this breakpoint. If THREAD is -1, make the
1323 breakpoint work for any thread. */
1326 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1328 int old_thread
= b
->thread
;
1331 if (old_thread
!= thread
)
1332 observer_notify_breakpoint_modified (b
);
1335 /* Set the task for this breakpoint. If TASK is 0, make the
1336 breakpoint work for any task. */
1339 breakpoint_set_task (struct breakpoint
*b
, int task
)
1341 int old_task
= b
->task
;
1344 if (old_task
!= task
)
1345 observer_notify_breakpoint_modified (b
);
1349 check_tracepoint_command (char *line
, void *closure
)
1351 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1353 validate_actionline (line
, b
);
1356 /* A structure used to pass information through
1357 map_breakpoint_numbers. */
1359 struct commands_info
1361 /* True if the command was typed at a tty. */
1364 /* The breakpoint range spec. */
1367 /* Non-NULL if the body of the commands are being read from this
1368 already-parsed command. */
1369 struct command_line
*control
;
1371 /* The command lines read from the user, or NULL if they have not
1373 struct counted_command_line
*cmd
;
1376 /* A callback for map_breakpoint_numbers that sets the commands for
1377 commands_command. */
1380 do_map_commands_command (struct breakpoint
*b
, void *data
)
1382 struct commands_info
*info
= (struct commands_info
*) data
;
1384 if (info
->cmd
== NULL
)
1388 if (info
->control
!= NULL
)
1389 l
= copy_command_lines (info
->control
->body_list
[0]);
1392 struct cleanup
*old_chain
;
1395 str
= xstrprintf (_("Type commands for breakpoint(s) "
1396 "%s, one per line."),
1399 old_chain
= make_cleanup (xfree
, str
);
1401 l
= read_command_lines (str
,
1404 ? check_tracepoint_command
: 0),
1407 do_cleanups (old_chain
);
1410 info
->cmd
= alloc_counted_command_line (l
.release ());
1413 /* If a breakpoint was on the list more than once, we don't need to
1415 if (b
->commands
!= info
->cmd
)
1417 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1418 incref_counted_command_line (info
->cmd
);
1419 decref_counted_command_line (&b
->commands
);
1420 b
->commands
= info
->cmd
;
1421 observer_notify_breakpoint_modified (b
);
1426 commands_command_1 (const char *arg
, int from_tty
,
1427 struct command_line
*control
)
1429 struct cleanup
*cleanups
;
1430 struct commands_info info
;
1432 info
.from_tty
= from_tty
;
1433 info
.control
= control
;
1435 /* If we read command lines from the user, then `info' will hold an
1436 extra reference to the commands that we must clean up. */
1437 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1439 std::string new_arg
;
1441 if (arg
== NULL
|| !*arg
)
1443 if (breakpoint_count
- prev_breakpoint_count
> 1)
1444 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1446 else if (breakpoint_count
> 0)
1447 new_arg
= string_printf ("%d", breakpoint_count
);
1452 info
.arg
= new_arg
.c_str ();
1454 map_breakpoint_numbers (info
.arg
, do_map_commands_command
, &info
);
1456 if (info
.cmd
== NULL
)
1457 error (_("No breakpoints specified."));
1459 do_cleanups (cleanups
);
1463 commands_command (char *arg
, int from_tty
)
1465 commands_command_1 (arg
, from_tty
, NULL
);
1468 /* Like commands_command, but instead of reading the commands from
1469 input stream, takes them from an already parsed command structure.
1471 This is used by cli-script.c to DTRT with breakpoint commands
1472 that are part of if and while bodies. */
1473 enum command_control_type
1474 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1476 commands_command_1 (arg
, 0, cmd
);
1477 return simple_control
;
1480 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1483 bp_location_has_shadow (struct bp_location
*bl
)
1485 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1489 if (bl
->target_info
.shadow_len
== 0)
1490 /* BL isn't valid, or doesn't shadow memory. */
1495 /* Update BUF, which is LEN bytes read from the target address
1496 MEMADDR, by replacing a memory breakpoint with its shadowed
1499 If READBUF is not NULL, this buffer must not overlap with the of
1500 the breakpoint location's shadow_contents buffer. Otherwise, a
1501 failed assertion internal error will be raised. */
1504 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1505 const gdb_byte
*writebuf_org
,
1506 ULONGEST memaddr
, LONGEST len
,
1507 struct bp_target_info
*target_info
,
1508 struct gdbarch
*gdbarch
)
1510 /* Now do full processing of the found relevant range of elements. */
1511 CORE_ADDR bp_addr
= 0;
1515 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1516 current_program_space
->aspace
, 0))
1518 /* The breakpoint is inserted in a different address space. */
1522 /* Addresses and length of the part of the breakpoint that
1524 bp_addr
= target_info
->placed_address
;
1525 bp_size
= target_info
->shadow_len
;
1527 if (bp_addr
+ bp_size
<= memaddr
)
1529 /* The breakpoint is entirely before the chunk of memory we are
1534 if (bp_addr
>= memaddr
+ len
)
1536 /* The breakpoint is entirely after the chunk of memory we are
1541 /* Offset within shadow_contents. */
1542 if (bp_addr
< memaddr
)
1544 /* Only copy the second part of the breakpoint. */
1545 bp_size
-= memaddr
- bp_addr
;
1546 bptoffset
= memaddr
- bp_addr
;
1550 if (bp_addr
+ bp_size
> memaddr
+ len
)
1552 /* Only copy the first part of the breakpoint. */
1553 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1556 if (readbuf
!= NULL
)
1558 /* Verify that the readbuf buffer does not overlap with the
1559 shadow_contents buffer. */
1560 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1561 || readbuf
>= (target_info
->shadow_contents
1562 + target_info
->shadow_len
));
1564 /* Update the read buffer with this inserted breakpoint's
1566 memcpy (readbuf
+ bp_addr
- memaddr
,
1567 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1571 const unsigned char *bp
;
1572 CORE_ADDR addr
= target_info
->reqstd_address
;
1575 /* Update the shadow with what we want to write to memory. */
1576 memcpy (target_info
->shadow_contents
+ bptoffset
,
1577 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1579 /* Determine appropriate breakpoint contents and size for this
1581 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1583 /* Update the final write buffer with this inserted
1584 breakpoint's INSN. */
1585 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1589 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1590 by replacing any memory breakpoints with their shadowed contents.
1592 If READBUF is not NULL, this buffer must not overlap with any of
1593 the breakpoint location's shadow_contents buffers. Otherwise,
1594 a failed assertion internal error will be raised.
1596 The range of shadowed area by each bp_location is:
1597 bl->address - bp_locations_placed_address_before_address_max
1598 up to bl->address + bp_locations_shadow_len_after_address_max
1599 The range we were requested to resolve shadows for is:
1600 memaddr ... memaddr + len
1601 Thus the safe cutoff boundaries for performance optimization are
1602 memaddr + len <= (bl->address
1603 - bp_locations_placed_address_before_address_max)
1605 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1608 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1609 const gdb_byte
*writebuf_org
,
1610 ULONGEST memaddr
, LONGEST len
)
1612 /* Left boundary, right boundary and median element of our binary
1614 unsigned bc_l
, bc_r
, bc
;
1616 /* Find BC_L which is a leftmost element which may affect BUF
1617 content. It is safe to report lower value but a failure to
1618 report higher one. */
1621 bc_r
= bp_locations_count
;
1622 while (bc_l
+ 1 < bc_r
)
1624 struct bp_location
*bl
;
1626 bc
= (bc_l
+ bc_r
) / 2;
1627 bl
= bp_locations
[bc
];
1629 /* Check first BL->ADDRESS will not overflow due to the added
1630 constant. Then advance the left boundary only if we are sure
1631 the BC element can in no way affect the BUF content (MEMADDR
1632 to MEMADDR + LEN range).
1634 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1635 offset so that we cannot miss a breakpoint with its shadow
1636 range tail still reaching MEMADDR. */
1638 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1640 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1647 /* Due to the binary search above, we need to make sure we pick the
1648 first location that's at BC_L's address. E.g., if there are
1649 multiple locations at the same address, BC_L may end up pointing
1650 at a duplicate location, and miss the "master"/"inserted"
1651 location. Say, given locations L1, L2 and L3 at addresses A and
1654 L1@A, L2@A, L3@B, ...
1656 BC_L could end up pointing at location L2, while the "master"
1657 location could be L1. Since the `loc->inserted' flag is only set
1658 on "master" locations, we'd forget to restore the shadow of L1
1661 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1664 /* Now do full processing of the found relevant range of elements. */
1666 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1668 struct bp_location
*bl
= bp_locations
[bc
];
1670 /* bp_location array has BL->OWNER always non-NULL. */
1671 if (bl
->owner
->type
== bp_none
)
1672 warning (_("reading through apparently deleted breakpoint #%d?"),
1675 /* Performance optimization: any further element can no longer affect BUF
1678 if (bl
->address
>= bp_locations_placed_address_before_address_max
1679 && memaddr
+ len
<= (bl
->address
1680 - bp_locations_placed_address_before_address_max
))
1683 if (!bp_location_has_shadow (bl
))
1686 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1687 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1693 /* Return true if BPT is either a software breakpoint or a hardware
1697 is_breakpoint (const struct breakpoint
*bpt
)
1699 return (bpt
->type
== bp_breakpoint
1700 || bpt
->type
== bp_hardware_breakpoint
1701 || bpt
->type
== bp_dprintf
);
1704 /* Return true if BPT is of any hardware watchpoint kind. */
1707 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1709 return (bpt
->type
== bp_hardware_watchpoint
1710 || bpt
->type
== bp_read_watchpoint
1711 || bpt
->type
== bp_access_watchpoint
);
1714 /* Return true if BPT is of any watchpoint kind, hardware or
1718 is_watchpoint (const struct breakpoint
*bpt
)
1720 return (is_hardware_watchpoint (bpt
)
1721 || bpt
->type
== bp_watchpoint
);
1724 /* Returns true if the current thread and its running state are safe
1725 to evaluate or update watchpoint B. Watchpoints on local
1726 expressions need to be evaluated in the context of the thread that
1727 was current when the watchpoint was created, and, that thread needs
1728 to be stopped to be able to select the correct frame context.
1729 Watchpoints on global expressions can be evaluated on any thread,
1730 and in any state. It is presently left to the target allowing
1731 memory accesses when threads are running. */
1734 watchpoint_in_thread_scope (struct watchpoint
*b
)
1736 return (b
->pspace
== current_program_space
1737 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1738 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1739 && !is_executing (inferior_ptid
))));
1742 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1743 associated bp_watchpoint_scope breakpoint. */
1746 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1748 if (w
->related_breakpoint
!= w
)
1750 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1751 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1752 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1753 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1754 w
->related_breakpoint
= w
;
1756 w
->disposition
= disp_del_at_next_stop
;
1759 /* Extract a bitfield value from value VAL using the bit parameters contained in
1762 static struct value
*
1763 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1765 struct value
*bit_val
;
1770 bit_val
= allocate_value (value_type (val
));
1772 unpack_value_bitfield (bit_val
,
1775 value_contents_for_printing (val
),
1782 /* Allocate a dummy location and add it to B, which must be a software
1783 watchpoint. This is required because even if a software watchpoint
1784 is not watching any memory, bpstat_stop_status requires a location
1785 to be able to report stops. */
1788 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1789 struct program_space
*pspace
)
1791 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1793 b
->loc
= allocate_bp_location (b
);
1794 b
->loc
->pspace
= pspace
;
1795 b
->loc
->address
= -1;
1796 b
->loc
->length
= -1;
1799 /* Returns true if B is a software watchpoint that is not watching any
1800 memory (e.g., "watch $pc"). */
1803 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1805 return (b
->type
== bp_watchpoint
1807 && b
->loc
->next
== NULL
1808 && b
->loc
->address
== -1
1809 && b
->loc
->length
== -1);
1812 /* Assuming that B is a watchpoint:
1813 - Reparse watchpoint expression, if REPARSE is non-zero
1814 - Evaluate expression and store the result in B->val
1815 - Evaluate the condition if there is one, and store the result
1817 - Update the list of values that must be watched in B->loc.
1819 If the watchpoint disposition is disp_del_at_next_stop, then do
1820 nothing. If this is local watchpoint that is out of scope, delete
1823 Even with `set breakpoint always-inserted on' the watchpoints are
1824 removed + inserted on each stop here. Normal breakpoints must
1825 never be removed because they might be missed by a running thread
1826 when debugging in non-stop mode. On the other hand, hardware
1827 watchpoints (is_hardware_watchpoint; processed here) are specific
1828 to each LWP since they are stored in each LWP's hardware debug
1829 registers. Therefore, such LWP must be stopped first in order to
1830 be able to modify its hardware watchpoints.
1832 Hardware watchpoints must be reset exactly once after being
1833 presented to the user. It cannot be done sooner, because it would
1834 reset the data used to present the watchpoint hit to the user. And
1835 it must not be done later because it could display the same single
1836 watchpoint hit during multiple GDB stops. Note that the latter is
1837 relevant only to the hardware watchpoint types bp_read_watchpoint
1838 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1839 not user-visible - its hit is suppressed if the memory content has
1842 The following constraints influence the location where we can reset
1843 hardware watchpoints:
1845 * target_stopped_by_watchpoint and target_stopped_data_address are
1846 called several times when GDB stops.
1849 * Multiple hardware watchpoints can be hit at the same time,
1850 causing GDB to stop. GDB only presents one hardware watchpoint
1851 hit at a time as the reason for stopping, and all the other hits
1852 are presented later, one after the other, each time the user
1853 requests the execution to be resumed. Execution is not resumed
1854 for the threads still having pending hit event stored in
1855 LWP_INFO->STATUS. While the watchpoint is already removed from
1856 the inferior on the first stop the thread hit event is kept being
1857 reported from its cached value by linux_nat_stopped_data_address
1858 until the real thread resume happens after the watchpoint gets
1859 presented and thus its LWP_INFO->STATUS gets reset.
1861 Therefore the hardware watchpoint hit can get safely reset on the
1862 watchpoint removal from inferior. */
1865 update_watchpoint (struct watchpoint
*b
, int reparse
)
1867 int within_current_scope
;
1868 struct frame_id saved_frame_id
;
1871 /* If this is a local watchpoint, we only want to check if the
1872 watchpoint frame is in scope if the current thread is the thread
1873 that was used to create the watchpoint. */
1874 if (!watchpoint_in_thread_scope (b
))
1877 if (b
->disposition
== disp_del_at_next_stop
)
1882 /* Determine if the watchpoint is within scope. */
1883 if (b
->exp_valid_block
== NULL
)
1884 within_current_scope
= 1;
1887 struct frame_info
*fi
= get_current_frame ();
1888 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1889 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1891 /* If we're at a point where the stack has been destroyed
1892 (e.g. in a function epilogue), unwinding may not work
1893 properly. Do not attempt to recreate locations at this
1894 point. See similar comments in watchpoint_check. */
1895 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1898 /* Save the current frame's ID so we can restore it after
1899 evaluating the watchpoint expression on its own frame. */
1900 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1901 took a frame parameter, so that we didn't have to change the
1904 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1906 fi
= frame_find_by_id (b
->watchpoint_frame
);
1907 within_current_scope
= (fi
!= NULL
);
1908 if (within_current_scope
)
1912 /* We don't free locations. They are stored in the bp_location array
1913 and update_global_location_list will eventually delete them and
1914 remove breakpoints if needed. */
1917 if (within_current_scope
&& reparse
)
1922 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1923 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1924 /* If the meaning of expression itself changed, the old value is
1925 no longer relevant. We don't want to report a watchpoint hit
1926 to the user when the old value and the new value may actually
1927 be completely different objects. */
1928 value_free (b
->val
);
1932 /* Note that unlike with breakpoints, the watchpoint's condition
1933 expression is stored in the breakpoint object, not in the
1934 locations (re)created below. */
1935 if (b
->cond_string
!= NULL
)
1937 b
->cond_exp
.reset ();
1940 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1944 /* If we failed to parse the expression, for example because
1945 it refers to a global variable in a not-yet-loaded shared library,
1946 don't try to insert watchpoint. We don't automatically delete
1947 such watchpoint, though, since failure to parse expression
1948 is different from out-of-scope watchpoint. */
1949 if (!target_has_execution
)
1951 /* Without execution, memory can't change. No use to try and
1952 set watchpoint locations. The watchpoint will be reset when
1953 the target gains execution, through breakpoint_re_set. */
1954 if (!can_use_hw_watchpoints
)
1956 if (b
->ops
->works_in_software_mode (b
))
1957 b
->type
= bp_watchpoint
;
1959 error (_("Can't set read/access watchpoint when "
1960 "hardware watchpoints are disabled."));
1963 else if (within_current_scope
&& b
->exp
)
1966 struct value
*val_chain
, *v
, *result
, *next
;
1967 struct program_space
*frame_pspace
;
1969 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1971 /* Avoid setting b->val if it's already set. The meaning of
1972 b->val is 'the last value' user saw, and we should update
1973 it only if we reported that last value to user. As it
1974 happens, the code that reports it updates b->val directly.
1975 We don't keep track of the memory value for masked
1977 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1979 if (b
->val_bitsize
!= 0)
1981 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1989 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1991 /* Look at each value on the value chain. */
1992 for (v
= val_chain
; v
; v
= value_next (v
))
1994 /* If it's a memory location, and GDB actually needed
1995 its contents to evaluate the expression, then we
1996 must watch it. If the first value returned is
1997 still lazy, that means an error occurred reading it;
1998 watch it anyway in case it becomes readable. */
1999 if (VALUE_LVAL (v
) == lval_memory
2000 && (v
== val_chain
|| ! value_lazy (v
)))
2002 struct type
*vtype
= check_typedef (value_type (v
));
2004 /* We only watch structs and arrays if user asked
2005 for it explicitly, never if they just happen to
2006 appear in the middle of some value chain. */
2008 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2009 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2012 enum target_hw_bp_type type
;
2013 struct bp_location
*loc
, **tmp
;
2014 int bitpos
= 0, bitsize
= 0;
2016 if (value_bitsize (v
) != 0)
2018 /* Extract the bit parameters out from the bitfield
2020 bitpos
= value_bitpos (v
);
2021 bitsize
= value_bitsize (v
);
2023 else if (v
== result
&& b
->val_bitsize
!= 0)
2025 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2026 lvalue whose bit parameters are saved in the fields
2027 VAL_BITPOS and VAL_BITSIZE. */
2028 bitpos
= b
->val_bitpos
;
2029 bitsize
= b
->val_bitsize
;
2032 addr
= value_address (v
);
2035 /* Skip the bytes that don't contain the bitfield. */
2040 if (b
->type
== bp_read_watchpoint
)
2042 else if (b
->type
== bp_access_watchpoint
)
2045 loc
= allocate_bp_location (b
);
2046 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2049 loc
->gdbarch
= get_type_arch (value_type (v
));
2051 loc
->pspace
= frame_pspace
;
2052 loc
->address
= addr
;
2056 /* Just cover the bytes that make up the bitfield. */
2057 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2060 loc
->length
= TYPE_LENGTH (value_type (v
));
2062 loc
->watchpoint_type
= type
;
2067 /* Change the type of breakpoint between hardware assisted or
2068 an ordinary watchpoint depending on the hardware support
2069 and free hardware slots. REPARSE is set when the inferior
2074 enum bp_loc_type loc_type
;
2075 struct bp_location
*bl
;
2077 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2081 int i
, target_resources_ok
, other_type_used
;
2084 /* Use an exact watchpoint when there's only one memory region to be
2085 watched, and only one debug register is needed to watch it. */
2086 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2088 /* We need to determine how many resources are already
2089 used for all other hardware watchpoints plus this one
2090 to see if we still have enough resources to also fit
2091 this watchpoint in as well. */
2093 /* If this is a software watchpoint, we try to turn it
2094 to a hardware one -- count resources as if B was of
2095 hardware watchpoint type. */
2097 if (type
== bp_watchpoint
)
2098 type
= bp_hardware_watchpoint
;
2100 /* This watchpoint may or may not have been placed on
2101 the list yet at this point (it won't be in the list
2102 if we're trying to create it for the first time,
2103 through watch_command), so always account for it
2106 /* Count resources used by all watchpoints except B. */
2107 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2109 /* Add in the resources needed for B. */
2110 i
+= hw_watchpoint_use_count (b
);
2113 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2114 if (target_resources_ok
<= 0)
2116 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2118 if (target_resources_ok
== 0 && !sw_mode
)
2119 error (_("Target does not support this type of "
2120 "hardware watchpoint."));
2121 else if (target_resources_ok
< 0 && !sw_mode
)
2122 error (_("There are not enough available hardware "
2123 "resources for this watchpoint."));
2125 /* Downgrade to software watchpoint. */
2126 b
->type
= bp_watchpoint
;
2130 /* If this was a software watchpoint, we've just
2131 found we have enough resources to turn it to a
2132 hardware watchpoint. Otherwise, this is a
2137 else if (!b
->ops
->works_in_software_mode (b
))
2139 if (!can_use_hw_watchpoints
)
2140 error (_("Can't set read/access watchpoint when "
2141 "hardware watchpoints are disabled."));
2143 error (_("Expression cannot be implemented with "
2144 "read/access watchpoint."));
2147 b
->type
= bp_watchpoint
;
2149 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2150 : bp_loc_hardware_watchpoint
);
2151 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2152 bl
->loc_type
= loc_type
;
2155 for (v
= val_chain
; v
; v
= next
)
2157 next
= value_next (v
);
2162 /* If a software watchpoint is not watching any memory, then the
2163 above left it without any location set up. But,
2164 bpstat_stop_status requires a location to be able to report
2165 stops, so make sure there's at least a dummy one. */
2166 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2167 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2169 else if (!within_current_scope
)
2171 printf_filtered (_("\
2172 Watchpoint %d deleted because the program has left the block\n\
2173 in which its expression is valid.\n"),
2175 watchpoint_del_at_next_stop (b
);
2178 /* Restore the selected frame. */
2180 select_frame (frame_find_by_id (saved_frame_id
));
2184 /* Returns 1 iff breakpoint location should be
2185 inserted in the inferior. We don't differentiate the type of BL's owner
2186 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2187 breakpoint_ops is not defined, because in insert_bp_location,
2188 tracepoint's insert_location will not be called. */
2190 should_be_inserted (struct bp_location
*bl
)
2192 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2195 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2198 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2201 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2204 /* This is set for example, when we're attached to the parent of a
2205 vfork, and have detached from the child. The child is running
2206 free, and we expect it to do an exec or exit, at which point the
2207 OS makes the parent schedulable again (and the target reports
2208 that the vfork is done). Until the child is done with the shared
2209 memory region, do not insert breakpoints in the parent, otherwise
2210 the child could still trip on the parent's breakpoints. Since
2211 the parent is blocked anyway, it won't miss any breakpoint. */
2212 if (bl
->pspace
->breakpoints_not_allowed
)
2215 /* Don't insert a breakpoint if we're trying to step past its
2216 location, except if the breakpoint is a single-step breakpoint,
2217 and the breakpoint's thread is the thread which is stepping past
2219 if ((bl
->loc_type
== bp_loc_software_breakpoint
2220 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2221 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2223 /* The single-step breakpoint may be inserted at the location
2224 we're trying to step if the instruction branches to itself.
2225 However, the instruction won't be executed at all and it may
2226 break the semantics of the instruction, for example, the
2227 instruction is a conditional branch or updates some flags.
2228 We can't fix it unless GDB is able to emulate the instruction
2229 or switch to displaced stepping. */
2230 && !(bl
->owner
->type
== bp_single_step
2231 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2235 fprintf_unfiltered (gdb_stdlog
,
2236 "infrun: skipping breakpoint: "
2237 "stepping past insn at: %s\n",
2238 paddress (bl
->gdbarch
, bl
->address
));
2243 /* Don't insert watchpoints if we're trying to step past the
2244 instruction that triggered one. */
2245 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2246 && stepping_past_nonsteppable_watchpoint ())
2250 fprintf_unfiltered (gdb_stdlog
,
2251 "infrun: stepping past non-steppable watchpoint. "
2252 "skipping watchpoint at %s:%d\n",
2253 paddress (bl
->gdbarch
, bl
->address
),
2262 /* Same as should_be_inserted but does the check assuming
2263 that the location is not duplicated. */
2266 unduplicated_should_be_inserted (struct bp_location
*bl
)
2269 const int save_duplicate
= bl
->duplicate
;
2272 result
= should_be_inserted (bl
);
2273 bl
->duplicate
= save_duplicate
;
2277 /* Parses a conditional described by an expression COND into an
2278 agent expression bytecode suitable for evaluation
2279 by the bytecode interpreter. Return NULL if there was
2280 any error during parsing. */
2282 static agent_expr_up
2283 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2288 agent_expr_up aexpr
;
2290 /* We don't want to stop processing, so catch any errors
2291 that may show up. */
2294 aexpr
= gen_eval_for_expr (scope
, cond
);
2297 CATCH (ex
, RETURN_MASK_ERROR
)
2299 /* If we got here, it means the condition could not be parsed to a valid
2300 bytecode expression and thus can't be evaluated on the target's side.
2301 It's no use iterating through the conditions. */
2305 /* We have a valid agent expression. */
2309 /* Based on location BL, create a list of breakpoint conditions to be
2310 passed on to the target. If we have duplicated locations with different
2311 conditions, we will add such conditions to the list. The idea is that the
2312 target will evaluate the list of conditions and will only notify GDB when
2313 one of them is true. */
2316 build_target_condition_list (struct bp_location
*bl
)
2318 struct bp_location
**locp
= NULL
, **loc2p
;
2319 int null_condition_or_parse_error
= 0;
2320 int modified
= bl
->needs_update
;
2321 struct bp_location
*loc
;
2323 /* Release conditions left over from a previous insert. */
2324 bl
->target_info
.conditions
.clear ();
2326 /* This is only meaningful if the target is
2327 evaluating conditions and if the user has
2328 opted for condition evaluation on the target's
2330 if (gdb_evaluates_breakpoint_condition_p ()
2331 || !target_supports_evaluation_of_breakpoint_conditions ())
2334 /* Do a first pass to check for locations with no assigned
2335 conditions or conditions that fail to parse to a valid agent expression
2336 bytecode. If any of these happen, then it's no use to send conditions
2337 to the target since this location will always trigger and generate a
2338 response back to GDB. */
2339 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2342 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2346 /* Re-parse the conditions since something changed. In that
2347 case we already freed the condition bytecodes (see
2348 force_breakpoint_reinsertion). We just
2349 need to parse the condition to bytecodes again. */
2350 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2354 /* If we have a NULL bytecode expression, it means something
2355 went wrong or we have a null condition expression. */
2356 if (!loc
->cond_bytecode
)
2358 null_condition_or_parse_error
= 1;
2364 /* If any of these happened, it means we will have to evaluate the conditions
2365 for the location's address on gdb's side. It is no use keeping bytecodes
2366 for all the other duplicate locations, thus we free all of them here.
2368 This is so we have a finer control over which locations' conditions are
2369 being evaluated by GDB or the remote stub. */
2370 if (null_condition_or_parse_error
)
2372 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2375 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2377 /* Only go as far as the first NULL bytecode is
2379 if (!loc
->cond_bytecode
)
2382 loc
->cond_bytecode
.reset ();
2387 /* No NULL conditions or failed bytecode generation. Build a condition list
2388 for this location's address. */
2389 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2393 && is_breakpoint (loc
->owner
)
2394 && loc
->pspace
->num
== bl
->pspace
->num
2395 && loc
->owner
->enable_state
== bp_enabled
2398 /* Add the condition to the vector. This will be used later
2399 to send the conditions to the target. */
2400 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2407 /* Parses a command described by string CMD into an agent expression
2408 bytecode suitable for evaluation by the bytecode interpreter.
2409 Return NULL if there was any error during parsing. */
2411 static agent_expr_up
2412 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2414 struct cleanup
*old_cleanups
= 0;
2415 struct expression
**argvec
;
2416 const char *cmdrest
;
2417 const char *format_start
, *format_end
;
2418 struct format_piece
*fpieces
;
2420 struct gdbarch
*gdbarch
= get_current_arch ();
2427 if (*cmdrest
== ',')
2429 cmdrest
= skip_spaces_const (cmdrest
);
2431 if (*cmdrest
++ != '"')
2432 error (_("No format string following the location"));
2434 format_start
= cmdrest
;
2436 fpieces
= parse_format_string (&cmdrest
);
2438 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2440 format_end
= cmdrest
;
2442 if (*cmdrest
++ != '"')
2443 error (_("Bad format string, non-terminated '\"'."));
2445 cmdrest
= skip_spaces_const (cmdrest
);
2447 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2448 error (_("Invalid argument syntax"));
2450 if (*cmdrest
== ',')
2452 cmdrest
= skip_spaces_const (cmdrest
);
2454 /* For each argument, make an expression. */
2456 argvec
= (struct expression
**) alloca (strlen (cmd
)
2457 * sizeof (struct expression
*));
2460 while (*cmdrest
!= '\0')
2465 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2466 argvec
[nargs
++] = expr
.release ();
2468 if (*cmdrest
== ',')
2472 agent_expr_up aexpr
;
2474 /* We don't want to stop processing, so catch any errors
2475 that may show up. */
2478 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2479 format_start
, format_end
- format_start
,
2480 fpieces
, nargs
, argvec
);
2482 CATCH (ex
, RETURN_MASK_ERROR
)
2484 /* If we got here, it means the command could not be parsed to a valid
2485 bytecode expression and thus can't be evaluated on the target's side.
2486 It's no use iterating through the other commands. */
2490 do_cleanups (old_cleanups
);
2492 /* We have a valid agent expression, return it. */
2496 /* Based on location BL, create a list of breakpoint commands to be
2497 passed on to the target. If we have duplicated locations with
2498 different commands, we will add any such to the list. */
2501 build_target_command_list (struct bp_location
*bl
)
2503 struct bp_location
**locp
= NULL
, **loc2p
;
2504 int null_command_or_parse_error
= 0;
2505 int modified
= bl
->needs_update
;
2506 struct bp_location
*loc
;
2508 /* Clear commands left over from a previous insert. */
2509 bl
->target_info
.tcommands
.clear ();
2511 if (!target_can_run_breakpoint_commands ())
2514 /* For now, limit to agent-style dprintf breakpoints. */
2515 if (dprintf_style
!= dprintf_style_agent
)
2518 /* For now, if we have any duplicate location that isn't a dprintf,
2519 don't install the target-side commands, as that would make the
2520 breakpoint not be reported to the core, and we'd lose
2522 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2525 if (is_breakpoint (loc
->owner
)
2526 && loc
->pspace
->num
== bl
->pspace
->num
2527 && loc
->owner
->type
!= bp_dprintf
)
2531 /* Do a first pass to check for locations with no assigned
2532 conditions or conditions that fail to parse to a valid agent expression
2533 bytecode. If any of these happen, then it's no use to send conditions
2534 to the target since this location will always trigger and generate a
2535 response back to GDB. */
2536 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2539 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2543 /* Re-parse the commands since something changed. In that
2544 case we already freed the command bytecodes (see
2545 force_breakpoint_reinsertion). We just
2546 need to parse the command to bytecodes again. */
2548 = parse_cmd_to_aexpr (bl
->address
,
2549 loc
->owner
->extra_string
);
2552 /* If we have a NULL bytecode expression, it means something
2553 went wrong or we have a null command expression. */
2554 if (!loc
->cmd_bytecode
)
2556 null_command_or_parse_error
= 1;
2562 /* If anything failed, then we're not doing target-side commands,
2564 if (null_command_or_parse_error
)
2566 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2569 if (is_breakpoint (loc
->owner
)
2570 && loc
->pspace
->num
== bl
->pspace
->num
)
2572 /* Only go as far as the first NULL bytecode is
2574 if (loc
->cmd_bytecode
== NULL
)
2577 loc
->cmd_bytecode
.reset ();
2582 /* No NULL commands or failed bytecode generation. Build a command list
2583 for this location's address. */
2584 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2587 if (loc
->owner
->extra_string
2588 && is_breakpoint (loc
->owner
)
2589 && loc
->pspace
->num
== bl
->pspace
->num
2590 && loc
->owner
->enable_state
== bp_enabled
2593 /* Add the command to the vector. This will be used later
2594 to send the commands to the target. */
2595 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2599 bl
->target_info
.persist
= 0;
2600 /* Maybe flag this location as persistent. */
2601 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2602 bl
->target_info
.persist
= 1;
2605 /* Return the kind of breakpoint on address *ADDR. Get the kind
2606 of breakpoint according to ADDR except single-step breakpoint.
2607 Get the kind of single-step breakpoint according to the current
2611 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2613 if (bl
->owner
->type
== bp_single_step
)
2615 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2616 struct regcache
*regcache
;
2618 regcache
= get_thread_regcache (thr
->ptid
);
2620 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2624 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2627 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2628 location. Any error messages are printed to TMP_ERROR_STREAM; and
2629 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2630 Returns 0 for success, 1 if the bp_location type is not supported or
2633 NOTE drow/2003-09-09: This routine could be broken down to an
2634 object-style method for each breakpoint or catchpoint type. */
2636 insert_bp_location (struct bp_location
*bl
,
2637 struct ui_file
*tmp_error_stream
,
2638 int *disabled_breaks
,
2639 int *hw_breakpoint_error
,
2640 int *hw_bp_error_explained_already
)
2642 enum errors bp_err
= GDB_NO_ERROR
;
2643 const char *bp_err_message
= NULL
;
2645 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2648 /* Note we don't initialize bl->target_info, as that wipes out
2649 the breakpoint location's shadow_contents if the breakpoint
2650 is still inserted at that location. This in turn breaks
2651 target_read_memory which depends on these buffers when
2652 a memory read is requested at the breakpoint location:
2653 Once the target_info has been wiped, we fail to see that
2654 we have a breakpoint inserted at that address and thus
2655 read the breakpoint instead of returning the data saved in
2656 the breakpoint location's shadow contents. */
2657 bl
->target_info
.reqstd_address
= bl
->address
;
2658 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2659 bl
->target_info
.length
= bl
->length
;
2661 /* When working with target-side conditions, we must pass all the conditions
2662 for the same breakpoint address down to the target since GDB will not
2663 insert those locations. With a list of breakpoint conditions, the target
2664 can decide when to stop and notify GDB. */
2666 if (is_breakpoint (bl
->owner
))
2668 build_target_condition_list (bl
);
2669 build_target_command_list (bl
);
2670 /* Reset the modification marker. */
2671 bl
->needs_update
= 0;
2674 if (bl
->loc_type
== bp_loc_software_breakpoint
2675 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2677 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2679 /* If the explicitly specified breakpoint type
2680 is not hardware breakpoint, check the memory map to see
2681 if the breakpoint address is in read only memory or not.
2683 Two important cases are:
2684 - location type is not hardware breakpoint, memory
2685 is readonly. We change the type of the location to
2686 hardware breakpoint.
2687 - location type is hardware breakpoint, memory is
2688 read-write. This means we've previously made the
2689 location hardware one, but then the memory map changed,
2692 When breakpoints are removed, remove_breakpoints will use
2693 location types we've just set here, the only possible
2694 problem is that memory map has changed during running
2695 program, but it's not going to work anyway with current
2697 struct mem_region
*mr
2698 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2702 if (automatic_hardware_breakpoints
)
2704 enum bp_loc_type new_type
;
2706 if (mr
->attrib
.mode
!= MEM_RW
)
2707 new_type
= bp_loc_hardware_breakpoint
;
2709 new_type
= bp_loc_software_breakpoint
;
2711 if (new_type
!= bl
->loc_type
)
2713 static int said
= 0;
2715 bl
->loc_type
= new_type
;
2718 fprintf_filtered (gdb_stdout
,
2719 _("Note: automatically using "
2720 "hardware breakpoints for "
2721 "read-only addresses.\n"));
2726 else if (bl
->loc_type
== bp_loc_software_breakpoint
2727 && mr
->attrib
.mode
!= MEM_RW
)
2729 fprintf_unfiltered (tmp_error_stream
,
2730 _("Cannot insert breakpoint %d.\n"
2731 "Cannot set software breakpoint "
2732 "at read-only address %s\n"),
2734 paddress (bl
->gdbarch
, bl
->address
));
2740 /* First check to see if we have to handle an overlay. */
2741 if (overlay_debugging
== ovly_off
2742 || bl
->section
== NULL
2743 || !(section_is_overlay (bl
->section
)))
2745 /* No overlay handling: just set the breakpoint. */
2750 val
= bl
->owner
->ops
->insert_location (bl
);
2752 bp_err
= GENERIC_ERROR
;
2754 CATCH (e
, RETURN_MASK_ALL
)
2757 bp_err_message
= e
.message
;
2763 /* This breakpoint is in an overlay section.
2764 Shall we set a breakpoint at the LMA? */
2765 if (!overlay_events_enabled
)
2767 /* Yes -- overlay event support is not active,
2768 so we must try to set a breakpoint at the LMA.
2769 This will not work for a hardware breakpoint. */
2770 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2771 warning (_("hardware breakpoint %d not supported in overlay!"),
2775 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2777 /* Set a software (trap) breakpoint at the LMA. */
2778 bl
->overlay_target_info
= bl
->target_info
;
2779 bl
->overlay_target_info
.reqstd_address
= addr
;
2781 /* No overlay handling: just set the breakpoint. */
2786 bl
->overlay_target_info
.kind
2787 = breakpoint_kind (bl
, &addr
);
2788 bl
->overlay_target_info
.placed_address
= addr
;
2789 val
= target_insert_breakpoint (bl
->gdbarch
,
2790 &bl
->overlay_target_info
);
2792 bp_err
= GENERIC_ERROR
;
2794 CATCH (e
, RETURN_MASK_ALL
)
2797 bp_err_message
= e
.message
;
2801 if (bp_err
!= GDB_NO_ERROR
)
2802 fprintf_unfiltered (tmp_error_stream
,
2803 "Overlay breakpoint %d "
2804 "failed: in ROM?\n",
2808 /* Shall we set a breakpoint at the VMA? */
2809 if (section_is_mapped (bl
->section
))
2811 /* Yes. This overlay section is mapped into memory. */
2816 val
= bl
->owner
->ops
->insert_location (bl
);
2818 bp_err
= GENERIC_ERROR
;
2820 CATCH (e
, RETURN_MASK_ALL
)
2823 bp_err_message
= e
.message
;
2829 /* No. This breakpoint will not be inserted.
2830 No error, but do not mark the bp as 'inserted'. */
2835 if (bp_err
!= GDB_NO_ERROR
)
2837 /* Can't set the breakpoint. */
2839 /* In some cases, we might not be able to insert a
2840 breakpoint in a shared library that has already been
2841 removed, but we have not yet processed the shlib unload
2842 event. Unfortunately, some targets that implement
2843 breakpoint insertion themselves can't tell why the
2844 breakpoint insertion failed (e.g., the remote target
2845 doesn't define error codes), so we must treat generic
2846 errors as memory errors. */
2847 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2848 && bl
->loc_type
== bp_loc_software_breakpoint
2849 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2850 || shared_objfile_contains_address_p (bl
->pspace
,
2853 /* See also: disable_breakpoints_in_shlibs. */
2854 bl
->shlib_disabled
= 1;
2855 observer_notify_breakpoint_modified (bl
->owner
);
2856 if (!*disabled_breaks
)
2858 fprintf_unfiltered (tmp_error_stream
,
2859 "Cannot insert breakpoint %d.\n",
2861 fprintf_unfiltered (tmp_error_stream
,
2862 "Temporarily disabling shared "
2863 "library breakpoints:\n");
2865 *disabled_breaks
= 1;
2866 fprintf_unfiltered (tmp_error_stream
,
2867 "breakpoint #%d\n", bl
->owner
->number
);
2872 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2874 *hw_breakpoint_error
= 1;
2875 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2876 fprintf_unfiltered (tmp_error_stream
,
2877 "Cannot insert hardware breakpoint %d%s",
2878 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2879 if (bp_err_message
!= NULL
)
2880 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2884 if (bp_err_message
== NULL
)
2887 = memory_error_message (TARGET_XFER_E_IO
,
2888 bl
->gdbarch
, bl
->address
);
2889 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2891 fprintf_unfiltered (tmp_error_stream
,
2892 "Cannot insert breakpoint %d.\n"
2894 bl
->owner
->number
, message
);
2895 do_cleanups (old_chain
);
2899 fprintf_unfiltered (tmp_error_stream
,
2900 "Cannot insert breakpoint %d: %s\n",
2915 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2916 /* NOTE drow/2003-09-08: This state only exists for removing
2917 watchpoints. It's not clear that it's necessary... */
2918 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2922 gdb_assert (bl
->owner
->ops
!= NULL
2923 && bl
->owner
->ops
->insert_location
!= NULL
);
2925 val
= bl
->owner
->ops
->insert_location (bl
);
2927 /* If trying to set a read-watchpoint, and it turns out it's not
2928 supported, try emulating one with an access watchpoint. */
2929 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2931 struct bp_location
*loc
, **loc_temp
;
2933 /* But don't try to insert it, if there's already another
2934 hw_access location that would be considered a duplicate
2936 ALL_BP_LOCATIONS (loc
, loc_temp
)
2938 && loc
->watchpoint_type
== hw_access
2939 && watchpoint_locations_match (bl
, loc
))
2943 bl
->target_info
= loc
->target_info
;
2944 bl
->watchpoint_type
= hw_access
;
2951 bl
->watchpoint_type
= hw_access
;
2952 val
= bl
->owner
->ops
->insert_location (bl
);
2955 /* Back to the original value. */
2956 bl
->watchpoint_type
= hw_read
;
2960 bl
->inserted
= (val
== 0);
2963 else if (bl
->owner
->type
== bp_catchpoint
)
2967 gdb_assert (bl
->owner
->ops
!= NULL
2968 && bl
->owner
->ops
->insert_location
!= NULL
);
2970 val
= bl
->owner
->ops
->insert_location (bl
);
2973 bl
->owner
->enable_state
= bp_disabled
;
2977 Error inserting catchpoint %d: Your system does not support this type\n\
2978 of catchpoint."), bl
->owner
->number
);
2980 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2983 bl
->inserted
= (val
== 0);
2985 /* We've already printed an error message if there was a problem
2986 inserting this catchpoint, and we've disabled the catchpoint,
2987 so just return success. */
2994 /* This function is called when program space PSPACE is about to be
2995 deleted. It takes care of updating breakpoints to not reference
2999 breakpoint_program_space_exit (struct program_space
*pspace
)
3001 struct breakpoint
*b
, *b_temp
;
3002 struct bp_location
*loc
, **loc_temp
;
3004 /* Remove any breakpoint that was set through this program space. */
3005 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
3007 if (b
->pspace
== pspace
)
3008 delete_breakpoint (b
);
3011 /* Breakpoints set through other program spaces could have locations
3012 bound to PSPACE as well. Remove those. */
3013 ALL_BP_LOCATIONS (loc
, loc_temp
)
3015 struct bp_location
*tmp
;
3017 if (loc
->pspace
== pspace
)
3019 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3020 if (loc
->owner
->loc
== loc
)
3021 loc
->owner
->loc
= loc
->next
;
3023 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3024 if (tmp
->next
== loc
)
3026 tmp
->next
= loc
->next
;
3032 /* Now update the global location list to permanently delete the
3033 removed locations above. */
3034 update_global_location_list (UGLL_DONT_INSERT
);
3037 /* Make sure all breakpoints are inserted in inferior.
3038 Throws exception on any error.
3039 A breakpoint that is already inserted won't be inserted
3040 again, so calling this function twice is safe. */
3042 insert_breakpoints (void)
3044 struct breakpoint
*bpt
;
3046 ALL_BREAKPOINTS (bpt
)
3047 if (is_hardware_watchpoint (bpt
))
3049 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3051 update_watchpoint (w
, 0 /* don't reparse. */);
3054 /* Updating watchpoints creates new locations, so update the global
3055 location list. Explicitly tell ugll to insert locations and
3056 ignore breakpoints_always_inserted_mode. */
3057 update_global_location_list (UGLL_INSERT
);
3060 /* Invoke CALLBACK for each of bp_location. */
3063 iterate_over_bp_locations (walk_bp_location_callback callback
)
3065 struct bp_location
*loc
, **loc_tmp
;
3067 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3069 callback (loc
, NULL
);
3073 /* This is used when we need to synch breakpoint conditions between GDB and the
3074 target. It is the case with deleting and disabling of breakpoints when using
3075 always-inserted mode. */
3078 update_inserted_breakpoint_locations (void)
3080 struct bp_location
*bl
, **blp_tmp
;
3083 int disabled_breaks
= 0;
3084 int hw_breakpoint_error
= 0;
3085 int hw_bp_details_reported
= 0;
3087 string_file tmp_error_stream
;
3089 /* Explicitly mark the warning -- this will only be printed if
3090 there was an error. */
3091 tmp_error_stream
.puts ("Warning:\n");
3093 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3095 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3097 /* We only want to update software breakpoints and hardware
3099 if (!is_breakpoint (bl
->owner
))
3102 /* We only want to update locations that are already inserted
3103 and need updating. This is to avoid unwanted insertion during
3104 deletion of breakpoints. */
3105 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3108 switch_to_program_space_and_thread (bl
->pspace
);
3110 /* For targets that support global breakpoints, there's no need
3111 to select an inferior to insert breakpoint to. In fact, even
3112 if we aren't attached to any process yet, we should still
3113 insert breakpoints. */
3114 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3115 && ptid_equal (inferior_ptid
, null_ptid
))
3118 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3119 &hw_breakpoint_error
, &hw_bp_details_reported
);
3126 target_terminal_ours_for_output ();
3127 error_stream (tmp_error_stream
);
3131 /* Used when starting or continuing the program. */
3134 insert_breakpoint_locations (void)
3136 struct breakpoint
*bpt
;
3137 struct bp_location
*bl
, **blp_tmp
;
3140 int disabled_breaks
= 0;
3141 int hw_breakpoint_error
= 0;
3142 int hw_bp_error_explained_already
= 0;
3144 string_file tmp_error_stream
;
3146 /* Explicitly mark the warning -- this will only be printed if
3147 there was an error. */
3148 tmp_error_stream
.puts ("Warning:\n");
3150 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3152 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3154 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3157 /* There is no point inserting thread-specific breakpoints if
3158 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3159 has BL->OWNER always non-NULL. */
3160 if (bl
->owner
->thread
!= -1
3161 && !valid_global_thread_id (bl
->owner
->thread
))
3164 switch_to_program_space_and_thread (bl
->pspace
);
3166 /* For targets that support global breakpoints, there's no need
3167 to select an inferior to insert breakpoint to. In fact, even
3168 if we aren't attached to any process yet, we should still
3169 insert breakpoints. */
3170 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3171 && ptid_equal (inferior_ptid
, null_ptid
))
3174 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3175 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3180 /* If we failed to insert all locations of a watchpoint, remove
3181 them, as half-inserted watchpoint is of limited use. */
3182 ALL_BREAKPOINTS (bpt
)
3184 int some_failed
= 0;
3185 struct bp_location
*loc
;
3187 if (!is_hardware_watchpoint (bpt
))
3190 if (!breakpoint_enabled (bpt
))
3193 if (bpt
->disposition
== disp_del_at_next_stop
)
3196 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3197 if (!loc
->inserted
&& should_be_inserted (loc
))
3204 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3206 remove_breakpoint (loc
);
3208 hw_breakpoint_error
= 1;
3209 tmp_error_stream
.printf ("Could not insert "
3210 "hardware watchpoint %d.\n",
3218 /* If a hardware breakpoint or watchpoint was inserted, add a
3219 message about possibly exhausted resources. */
3220 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3222 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3223 You may have requested too many hardware breakpoints/watchpoints.\n");
3225 target_terminal_ours_for_output ();
3226 error_stream (tmp_error_stream
);
3230 /* Used when the program stops.
3231 Returns zero if successful, or non-zero if there was a problem
3232 removing a breakpoint location. */
3235 remove_breakpoints (void)
3237 struct bp_location
*bl
, **blp_tmp
;
3240 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3242 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3243 val
|= remove_breakpoint (bl
);
3248 /* When a thread exits, remove breakpoints that are related to
3252 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3254 struct breakpoint
*b
, *b_tmp
;
3256 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3258 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3260 b
->disposition
= disp_del_at_next_stop
;
3262 printf_filtered (_("\
3263 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3264 b
->number
, print_thread_id (tp
));
3266 /* Hide it from the user. */
3272 /* Remove breakpoints of process PID. */
3275 remove_breakpoints_pid (int pid
)
3277 struct bp_location
*bl
, **blp_tmp
;
3279 struct inferior
*inf
= find_inferior_pid (pid
);
3281 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3283 if (bl
->pspace
!= inf
->pspace
)
3286 if (bl
->inserted
&& !bl
->target_info
.persist
)
3288 val
= remove_breakpoint (bl
);
3297 reattach_breakpoints (int pid
)
3299 struct cleanup
*old_chain
;
3300 struct bp_location
*bl
, **blp_tmp
;
3302 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3303 struct inferior
*inf
;
3304 struct thread_info
*tp
;
3306 tp
= any_live_thread_of_process (pid
);
3310 inf
= find_inferior_pid (pid
);
3311 old_chain
= save_inferior_ptid ();
3313 inferior_ptid
= tp
->ptid
;
3315 string_file tmp_error_stream
;
3317 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3319 if (bl
->pspace
!= inf
->pspace
)
3325 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3328 do_cleanups (old_chain
);
3333 do_cleanups (old_chain
);
3337 static int internal_breakpoint_number
= -1;
3339 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3340 If INTERNAL is non-zero, the breakpoint number will be populated
3341 from internal_breakpoint_number and that variable decremented.
3342 Otherwise the breakpoint number will be populated from
3343 breakpoint_count and that value incremented. Internal breakpoints
3344 do not set the internal var bpnum. */
3346 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3349 b
->number
= internal_breakpoint_number
--;
3352 set_breakpoint_count (breakpoint_count
+ 1);
3353 b
->number
= breakpoint_count
;
3357 static struct breakpoint
*
3358 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3359 CORE_ADDR address
, enum bptype type
,
3360 const struct breakpoint_ops
*ops
)
3362 struct symtab_and_line sal
;
3363 struct breakpoint
*b
;
3365 init_sal (&sal
); /* Initialize to zeroes. */
3368 sal
.section
= find_pc_overlay (sal
.pc
);
3369 sal
.pspace
= current_program_space
;
3371 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3372 b
->number
= internal_breakpoint_number
--;
3373 b
->disposition
= disp_donttouch
;
3378 static const char *const longjmp_names
[] =
3380 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3382 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3384 /* Per-objfile data private to breakpoint.c. */
3385 struct breakpoint_objfile_data
3387 /* Minimal symbol for "_ovly_debug_event" (if any). */
3388 struct bound_minimal_symbol overlay_msym
;
3390 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3391 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3393 /* True if we have looked for longjmp probes. */
3394 int longjmp_searched
;
3396 /* SystemTap probe points for longjmp (if any). */
3397 VEC (probe_p
) *longjmp_probes
;
3399 /* Minimal symbol for "std::terminate()" (if any). */
3400 struct bound_minimal_symbol terminate_msym
;
3402 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3403 struct bound_minimal_symbol exception_msym
;
3405 /* True if we have looked for exception probes. */
3406 int exception_searched
;
3408 /* SystemTap probe points for unwinding (if any). */
3409 VEC (probe_p
) *exception_probes
;
3412 static const struct objfile_data
*breakpoint_objfile_key
;
3414 /* Minimal symbol not found sentinel. */
3415 static struct minimal_symbol msym_not_found
;
3417 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3420 msym_not_found_p (const struct minimal_symbol
*msym
)
3422 return msym
== &msym_not_found
;
3425 /* Return per-objfile data needed by breakpoint.c.
3426 Allocate the data if necessary. */
3428 static struct breakpoint_objfile_data
*
3429 get_breakpoint_objfile_data (struct objfile
*objfile
)
3431 struct breakpoint_objfile_data
*bp_objfile_data
;
3433 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3434 objfile_data (objfile
, breakpoint_objfile_key
));
3435 if (bp_objfile_data
== NULL
)
3438 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3440 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3441 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3443 return bp_objfile_data
;
3447 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3449 struct breakpoint_objfile_data
*bp_objfile_data
3450 = (struct breakpoint_objfile_data
*) data
;
3452 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3453 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3457 create_overlay_event_breakpoint (void)
3459 struct objfile
*objfile
;
3460 const char *const func_name
= "_ovly_debug_event";
3462 ALL_OBJFILES (objfile
)
3464 struct breakpoint
*b
;
3465 struct breakpoint_objfile_data
*bp_objfile_data
;
3467 struct explicit_location explicit_loc
;
3469 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3471 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3474 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3476 struct bound_minimal_symbol m
;
3478 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3479 if (m
.minsym
== NULL
)
3481 /* Avoid future lookups in this objfile. */
3482 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3485 bp_objfile_data
->overlay_msym
= m
;
3488 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3489 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3491 &internal_breakpoint_ops
);
3492 initialize_explicit_location (&explicit_loc
);
3493 explicit_loc
.function_name
= ASTRDUP (func_name
);
3494 b
->location
= new_explicit_location (&explicit_loc
);
3496 if (overlay_debugging
== ovly_auto
)
3498 b
->enable_state
= bp_enabled
;
3499 overlay_events_enabled
= 1;
3503 b
->enable_state
= bp_disabled
;
3504 overlay_events_enabled
= 0;
3510 create_longjmp_master_breakpoint (void)
3512 struct program_space
*pspace
;
3514 scoped_restore_current_program_space restore_pspace
;
3516 ALL_PSPACES (pspace
)
3518 struct objfile
*objfile
;
3520 set_current_program_space (pspace
);
3522 ALL_OBJFILES (objfile
)
3525 struct gdbarch
*gdbarch
;
3526 struct breakpoint_objfile_data
*bp_objfile_data
;
3528 gdbarch
= get_objfile_arch (objfile
);
3530 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3532 if (!bp_objfile_data
->longjmp_searched
)
3536 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3539 /* We are only interested in checking one element. */
3540 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3542 if (!can_evaluate_probe_arguments (p
))
3544 /* We cannot use the probe interface here, because it does
3545 not know how to evaluate arguments. */
3546 VEC_free (probe_p
, ret
);
3550 bp_objfile_data
->longjmp_probes
= ret
;
3551 bp_objfile_data
->longjmp_searched
= 1;
3554 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3557 struct probe
*probe
;
3558 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3561 VEC_iterate (probe_p
,
3562 bp_objfile_data
->longjmp_probes
,
3566 struct breakpoint
*b
;
3568 b
= create_internal_breakpoint (gdbarch
,
3569 get_probe_address (probe
,
3572 &internal_breakpoint_ops
);
3573 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3574 b
->enable_state
= bp_disabled
;
3580 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3583 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3585 struct breakpoint
*b
;
3586 const char *func_name
;
3588 struct explicit_location explicit_loc
;
3590 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3593 func_name
= longjmp_names
[i
];
3594 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3596 struct bound_minimal_symbol m
;
3598 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3599 if (m
.minsym
== NULL
)
3601 /* Prevent future lookups in this objfile. */
3602 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3605 bp_objfile_data
->longjmp_msym
[i
] = m
;
3608 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3609 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3610 &internal_breakpoint_ops
);
3611 initialize_explicit_location (&explicit_loc
);
3612 explicit_loc
.function_name
= ASTRDUP (func_name
);
3613 b
->location
= new_explicit_location (&explicit_loc
);
3614 b
->enable_state
= bp_disabled
;
3620 /* Create a master std::terminate breakpoint. */
3622 create_std_terminate_master_breakpoint (void)
3624 struct program_space
*pspace
;
3625 const char *const func_name
= "std::terminate()";
3627 scoped_restore_current_program_space restore_pspace
;
3629 ALL_PSPACES (pspace
)
3631 struct objfile
*objfile
;
3634 set_current_program_space (pspace
);
3636 ALL_OBJFILES (objfile
)
3638 struct breakpoint
*b
;
3639 struct breakpoint_objfile_data
*bp_objfile_data
;
3640 struct explicit_location explicit_loc
;
3642 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3644 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3647 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3649 struct bound_minimal_symbol m
;
3651 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3652 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3653 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3655 /* Prevent future lookups in this objfile. */
3656 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3659 bp_objfile_data
->terminate_msym
= m
;
3662 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3663 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3664 bp_std_terminate_master
,
3665 &internal_breakpoint_ops
);
3666 initialize_explicit_location (&explicit_loc
);
3667 explicit_loc
.function_name
= ASTRDUP (func_name
);
3668 b
->location
= new_explicit_location (&explicit_loc
);
3669 b
->enable_state
= bp_disabled
;
3674 /* Install a master breakpoint on the unwinder's debug hook. */
3677 create_exception_master_breakpoint (void)
3679 struct objfile
*objfile
;
3680 const char *const func_name
= "_Unwind_DebugHook";
3682 ALL_OBJFILES (objfile
)
3684 struct breakpoint
*b
;
3685 struct gdbarch
*gdbarch
;
3686 struct breakpoint_objfile_data
*bp_objfile_data
;
3688 struct explicit_location explicit_loc
;
3690 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3692 /* We prefer the SystemTap probe point if it exists. */
3693 if (!bp_objfile_data
->exception_searched
)
3697 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3701 /* We are only interested in checking one element. */
3702 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3704 if (!can_evaluate_probe_arguments (p
))
3706 /* We cannot use the probe interface here, because it does
3707 not know how to evaluate arguments. */
3708 VEC_free (probe_p
, ret
);
3712 bp_objfile_data
->exception_probes
= ret
;
3713 bp_objfile_data
->exception_searched
= 1;
3716 if (bp_objfile_data
->exception_probes
!= NULL
)
3718 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3720 struct probe
*probe
;
3723 VEC_iterate (probe_p
,
3724 bp_objfile_data
->exception_probes
,
3728 struct breakpoint
*b
;
3730 b
= create_internal_breakpoint (gdbarch
,
3731 get_probe_address (probe
,
3733 bp_exception_master
,
3734 &internal_breakpoint_ops
);
3735 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3736 b
->enable_state
= bp_disabled
;
3742 /* Otherwise, try the hook function. */
3744 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3747 gdbarch
= get_objfile_arch (objfile
);
3749 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3751 struct bound_minimal_symbol debug_hook
;
3753 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3754 if (debug_hook
.minsym
== NULL
)
3756 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3760 bp_objfile_data
->exception_msym
= debug_hook
;
3763 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3764 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3766 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3767 &internal_breakpoint_ops
);
3768 initialize_explicit_location (&explicit_loc
);
3769 explicit_loc
.function_name
= ASTRDUP (func_name
);
3770 b
->location
= new_explicit_location (&explicit_loc
);
3771 b
->enable_state
= bp_disabled
;
3775 /* Does B have a location spec? */
3778 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3780 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3784 update_breakpoints_after_exec (void)
3786 struct breakpoint
*b
, *b_tmp
;
3787 struct bp_location
*bploc
, **bplocp_tmp
;
3789 /* We're about to delete breakpoints from GDB's lists. If the
3790 INSERTED flag is true, GDB will try to lift the breakpoints by
3791 writing the breakpoints' "shadow contents" back into memory. The
3792 "shadow contents" are NOT valid after an exec, so GDB should not
3793 do that. Instead, the target is responsible from marking
3794 breakpoints out as soon as it detects an exec. We don't do that
3795 here instead, because there may be other attempts to delete
3796 breakpoints after detecting an exec and before reaching here. */
3797 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3798 if (bploc
->pspace
== current_program_space
)
3799 gdb_assert (!bploc
->inserted
);
3801 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3803 if (b
->pspace
!= current_program_space
)
3806 /* Solib breakpoints must be explicitly reset after an exec(). */
3807 if (b
->type
== bp_shlib_event
)
3809 delete_breakpoint (b
);
3813 /* JIT breakpoints must be explicitly reset after an exec(). */
3814 if (b
->type
== bp_jit_event
)
3816 delete_breakpoint (b
);
3820 /* Thread event breakpoints must be set anew after an exec(),
3821 as must overlay event and longjmp master breakpoints. */
3822 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3823 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3824 || b
->type
== bp_exception_master
)
3826 delete_breakpoint (b
);
3830 /* Step-resume breakpoints are meaningless after an exec(). */
3831 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3833 delete_breakpoint (b
);
3837 /* Just like single-step breakpoints. */
3838 if (b
->type
== bp_single_step
)
3840 delete_breakpoint (b
);
3844 /* Longjmp and longjmp-resume breakpoints are also meaningless
3846 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3847 || b
->type
== bp_longjmp_call_dummy
3848 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3850 delete_breakpoint (b
);
3854 if (b
->type
== bp_catchpoint
)
3856 /* For now, none of the bp_catchpoint breakpoints need to
3857 do anything at this point. In the future, if some of
3858 the catchpoints need to something, we will need to add
3859 a new method, and call this method from here. */
3863 /* bp_finish is a special case. The only way we ought to be able
3864 to see one of these when an exec() has happened, is if the user
3865 caught a vfork, and then said "finish". Ordinarily a finish just
3866 carries them to the call-site of the current callee, by setting
3867 a temporary bp there and resuming. But in this case, the finish
3868 will carry them entirely through the vfork & exec.
3870 We don't want to allow a bp_finish to remain inserted now. But
3871 we can't safely delete it, 'cause finish_command has a handle to
3872 the bp on a bpstat, and will later want to delete it. There's a
3873 chance (and I've seen it happen) that if we delete the bp_finish
3874 here, that its storage will get reused by the time finish_command
3875 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3876 We really must allow finish_command to delete a bp_finish.
3878 In the absence of a general solution for the "how do we know
3879 it's safe to delete something others may have handles to?"
3880 problem, what we'll do here is just uninsert the bp_finish, and
3881 let finish_command delete it.
3883 (We know the bp_finish is "doomed" in the sense that it's
3884 momentary, and will be deleted as soon as finish_command sees
3885 the inferior stopped. So it doesn't matter that the bp's
3886 address is probably bogus in the new a.out, unlike e.g., the
3887 solib breakpoints.) */
3889 if (b
->type
== bp_finish
)
3894 /* Without a symbolic address, we have little hope of the
3895 pre-exec() address meaning the same thing in the post-exec()
3897 if (breakpoint_event_location_empty_p (b
))
3899 delete_breakpoint (b
);
3906 detach_breakpoints (ptid_t ptid
)
3908 struct bp_location
*bl
, **blp_tmp
;
3910 struct cleanup
*old_chain
= save_inferior_ptid ();
3911 struct inferior
*inf
= current_inferior ();
3913 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3914 error (_("Cannot detach breakpoints of inferior_ptid"));
3916 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3917 inferior_ptid
= ptid
;
3918 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3920 if (bl
->pspace
!= inf
->pspace
)
3923 /* This function must physically remove breakpoints locations
3924 from the specified ptid, without modifying the breakpoint
3925 package's state. Locations of type bp_loc_other are only
3926 maintained at GDB side. So, there is no need to remove
3927 these bp_loc_other locations. Moreover, removing these
3928 would modify the breakpoint package's state. */
3929 if (bl
->loc_type
== bp_loc_other
)
3933 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3936 do_cleanups (old_chain
);
3940 /* Remove the breakpoint location BL from the current address space.
3941 Note that this is used to detach breakpoints from a child fork.
3942 When we get here, the child isn't in the inferior list, and neither
3943 do we have objects to represent its address space --- we should
3944 *not* look at bl->pspace->aspace here. */
3947 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3951 /* BL is never in moribund_locations by our callers. */
3952 gdb_assert (bl
->owner
!= NULL
);
3954 /* The type of none suggests that owner is actually deleted.
3955 This should not ever happen. */
3956 gdb_assert (bl
->owner
->type
!= bp_none
);
3958 if (bl
->loc_type
== bp_loc_software_breakpoint
3959 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3961 /* "Normal" instruction breakpoint: either the standard
3962 trap-instruction bp (bp_breakpoint), or a
3963 bp_hardware_breakpoint. */
3965 /* First check to see if we have to handle an overlay. */
3966 if (overlay_debugging
== ovly_off
3967 || bl
->section
== NULL
3968 || !(section_is_overlay (bl
->section
)))
3970 /* No overlay handling: just remove the breakpoint. */
3972 /* If we're trying to uninsert a memory breakpoint that we
3973 know is set in a dynamic object that is marked
3974 shlib_disabled, then either the dynamic object was
3975 removed with "remove-symbol-file" or with
3976 "nosharedlibrary". In the former case, we don't know
3977 whether another dynamic object might have loaded over the
3978 breakpoint's address -- the user might well let us know
3979 about it next with add-symbol-file (the whole point of
3980 add-symbol-file is letting the user manually maintain a
3981 list of dynamically loaded objects). If we have the
3982 breakpoint's shadow memory, that is, this is a software
3983 breakpoint managed by GDB, check whether the breakpoint
3984 is still inserted in memory, to avoid overwriting wrong
3985 code with stale saved shadow contents. Note that HW
3986 breakpoints don't have shadow memory, as they're
3987 implemented using a mechanism that is not dependent on
3988 being able to modify the target's memory, and as such
3989 they should always be removed. */
3990 if (bl
->shlib_disabled
3991 && bl
->target_info
.shadow_len
!= 0
3992 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3995 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3999 /* This breakpoint is in an overlay section.
4000 Did we set a breakpoint at the LMA? */
4001 if (!overlay_events_enabled
)
4003 /* Yes -- overlay event support is not active, so we
4004 should have set a breakpoint at the LMA. Remove it.
4006 /* Ignore any failures: if the LMA is in ROM, we will
4007 have already warned when we failed to insert it. */
4008 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4009 target_remove_hw_breakpoint (bl
->gdbarch
,
4010 &bl
->overlay_target_info
);
4012 target_remove_breakpoint (bl
->gdbarch
,
4013 &bl
->overlay_target_info
,
4016 /* Did we set a breakpoint at the VMA?
4017 If so, we will have marked the breakpoint 'inserted'. */
4020 /* Yes -- remove it. Previously we did not bother to
4021 remove the breakpoint if the section had been
4022 unmapped, but let's not rely on that being safe. We
4023 don't know what the overlay manager might do. */
4025 /* However, we should remove *software* breakpoints only
4026 if the section is still mapped, or else we overwrite
4027 wrong code with the saved shadow contents. */
4028 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4029 || section_is_mapped (bl
->section
))
4030 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4036 /* No -- not inserted, so no need to remove. No error. */
4041 /* In some cases, we might not be able to remove a breakpoint in
4042 a shared library that has already been removed, but we have
4043 not yet processed the shlib unload event. Similarly for an
4044 unloaded add-symbol-file object - the user might not yet have
4045 had the chance to remove-symbol-file it. shlib_disabled will
4046 be set if the library/object has already been removed, but
4047 the breakpoint hasn't been uninserted yet, e.g., after
4048 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4049 always-inserted mode. */
4051 && (bl
->loc_type
== bp_loc_software_breakpoint
4052 && (bl
->shlib_disabled
4053 || solib_name_from_address (bl
->pspace
, bl
->address
)
4054 || shared_objfile_contains_address_p (bl
->pspace
,
4060 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4062 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4064 gdb_assert (bl
->owner
->ops
!= NULL
4065 && bl
->owner
->ops
->remove_location
!= NULL
);
4067 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4068 bl
->owner
->ops
->remove_location (bl
, reason
);
4070 /* Failure to remove any of the hardware watchpoints comes here. */
4071 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4072 warning (_("Could not remove hardware watchpoint %d."),
4075 else if (bl
->owner
->type
== bp_catchpoint
4076 && breakpoint_enabled (bl
->owner
)
4079 gdb_assert (bl
->owner
->ops
!= NULL
4080 && bl
->owner
->ops
->remove_location
!= NULL
);
4082 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
4086 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4093 remove_breakpoint (struct bp_location
*bl
)
4095 /* BL is never in moribund_locations by our callers. */
4096 gdb_assert (bl
->owner
!= NULL
);
4098 /* The type of none suggests that owner is actually deleted.
4099 This should not ever happen. */
4100 gdb_assert (bl
->owner
->type
!= bp_none
);
4102 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4104 switch_to_program_space_and_thread (bl
->pspace
);
4106 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4109 /* Clear the "inserted" flag in all breakpoints. */
4112 mark_breakpoints_out (void)
4114 struct bp_location
*bl
, **blp_tmp
;
4116 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4117 if (bl
->pspace
== current_program_space
)
4121 /* Clear the "inserted" flag in all breakpoints and delete any
4122 breakpoints which should go away between runs of the program.
4124 Plus other such housekeeping that has to be done for breakpoints
4127 Note: this function gets called at the end of a run (by
4128 generic_mourn_inferior) and when a run begins (by
4129 init_wait_for_inferior). */
4134 breakpoint_init_inferior (enum inf_context context
)
4136 struct breakpoint
*b
, *b_tmp
;
4137 struct bp_location
*bl
;
4139 struct program_space
*pspace
= current_program_space
;
4141 /* If breakpoint locations are shared across processes, then there's
4143 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4146 mark_breakpoints_out ();
4148 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4150 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4156 case bp_longjmp_call_dummy
:
4158 /* If the call dummy breakpoint is at the entry point it will
4159 cause problems when the inferior is rerun, so we better get
4162 case bp_watchpoint_scope
:
4164 /* Also get rid of scope breakpoints. */
4166 case bp_shlib_event
:
4168 /* Also remove solib event breakpoints. Their addresses may
4169 have changed since the last time we ran the program.
4170 Actually we may now be debugging against different target;
4171 and so the solib backend that installed this breakpoint may
4172 not be used in by the target. E.g.,
4174 (gdb) file prog-linux
4175 (gdb) run # native linux target
4178 (gdb) file prog-win.exe
4179 (gdb) tar rem :9999 # remote Windows gdbserver.
4182 case bp_step_resume
:
4184 /* Also remove step-resume breakpoints. */
4186 case bp_single_step
:
4188 /* Also remove single-step breakpoints. */
4190 delete_breakpoint (b
);
4194 case bp_hardware_watchpoint
:
4195 case bp_read_watchpoint
:
4196 case bp_access_watchpoint
:
4198 struct watchpoint
*w
= (struct watchpoint
*) b
;
4200 /* Likewise for watchpoints on local expressions. */
4201 if (w
->exp_valid_block
!= NULL
)
4202 delete_breakpoint (b
);
4205 /* Get rid of existing locations, which are no longer
4206 valid. New ones will be created in
4207 update_watchpoint, when the inferior is restarted.
4208 The next update_global_location_list call will
4209 garbage collect them. */
4212 if (context
== inf_starting
)
4214 /* Reset val field to force reread of starting value in
4215 insert_breakpoints. */
4217 value_free (w
->val
);
4229 /* Get rid of the moribund locations. */
4230 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4231 decref_bp_location (&bl
);
4232 VEC_free (bp_location_p
, moribund_locations
);
4235 /* These functions concern about actual breakpoints inserted in the
4236 target --- to e.g. check if we need to do decr_pc adjustment or if
4237 we need to hop over the bkpt --- so we check for address space
4238 match, not program space. */
4240 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4241 exists at PC. It returns ordinary_breakpoint_here if it's an
4242 ordinary breakpoint, or permanent_breakpoint_here if it's a
4243 permanent breakpoint.
4244 - When continuing from a location with an ordinary breakpoint, we
4245 actually single step once before calling insert_breakpoints.
4246 - When continuing from a location with a permanent breakpoint, we
4247 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4248 the target, to advance the PC past the breakpoint. */
4250 enum breakpoint_here
4251 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4253 struct bp_location
*bl
, **blp_tmp
;
4254 int any_breakpoint_here
= 0;
4256 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4258 if (bl
->loc_type
!= bp_loc_software_breakpoint
4259 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4262 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4263 if ((breakpoint_enabled (bl
->owner
)
4265 && breakpoint_location_address_match (bl
, aspace
, pc
))
4267 if (overlay_debugging
4268 && section_is_overlay (bl
->section
)
4269 && !section_is_mapped (bl
->section
))
4270 continue; /* unmapped overlay -- can't be a match */
4271 else if (bl
->permanent
)
4272 return permanent_breakpoint_here
;
4274 any_breakpoint_here
= 1;
4278 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4281 /* See breakpoint.h. */
4284 breakpoint_in_range_p (struct address_space
*aspace
,
4285 CORE_ADDR addr
, ULONGEST len
)
4287 struct bp_location
*bl
, **blp_tmp
;
4289 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4291 if (bl
->loc_type
!= bp_loc_software_breakpoint
4292 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4295 if ((breakpoint_enabled (bl
->owner
)
4297 && breakpoint_location_address_range_overlap (bl
, aspace
,
4300 if (overlay_debugging
4301 && section_is_overlay (bl
->section
)
4302 && !section_is_mapped (bl
->section
))
4304 /* Unmapped overlay -- can't be a match. */
4315 /* Return true if there's a moribund breakpoint at PC. */
4318 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4320 struct bp_location
*loc
;
4323 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4324 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4330 /* Returns non-zero iff BL is inserted at PC, in address space
4334 bp_location_inserted_here_p (struct bp_location
*bl
,
4335 struct address_space
*aspace
, CORE_ADDR pc
)
4338 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4341 if (overlay_debugging
4342 && section_is_overlay (bl
->section
)
4343 && !section_is_mapped (bl
->section
))
4344 return 0; /* unmapped overlay -- can't be a match */
4351 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4354 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4356 struct bp_location
**blp
, **blp_tmp
= NULL
;
4358 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4360 struct bp_location
*bl
= *blp
;
4362 if (bl
->loc_type
!= bp_loc_software_breakpoint
4363 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4366 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4372 /* This function returns non-zero iff there is a software breakpoint
4376 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4379 struct bp_location
**blp
, **blp_tmp
= NULL
;
4381 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4383 struct bp_location
*bl
= *blp
;
4385 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4388 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4395 /* See breakpoint.h. */
4398 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4401 struct bp_location
**blp
, **blp_tmp
= NULL
;
4403 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4405 struct bp_location
*bl
= *blp
;
4407 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4410 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4418 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4419 CORE_ADDR addr
, ULONGEST len
)
4421 struct breakpoint
*bpt
;
4423 ALL_BREAKPOINTS (bpt
)
4425 struct bp_location
*loc
;
4427 if (bpt
->type
!= bp_hardware_watchpoint
4428 && bpt
->type
!= bp_access_watchpoint
)
4431 if (!breakpoint_enabled (bpt
))
4434 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4435 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4439 /* Check for intersection. */
4440 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4441 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4450 /* bpstat stuff. External routines' interfaces are documented
4454 is_catchpoint (struct breakpoint
*ep
)
4456 return (ep
->type
== bp_catchpoint
);
4459 /* Frees any storage that is part of a bpstat. Does not walk the
4463 bpstat_free (bpstat bs
)
4465 if (bs
->old_val
!= NULL
)
4466 value_free (bs
->old_val
);
4467 decref_counted_command_line (&bs
->commands
);
4468 decref_bp_location (&bs
->bp_location_at
);
4472 /* Clear a bpstat so that it says we are not at any breakpoint.
4473 Also free any storage that is part of a bpstat. */
4476 bpstat_clear (bpstat
*bsp
)
4493 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4494 is part of the bpstat is copied as well. */
4497 bpstat_copy (bpstat bs
)
4501 bpstat retval
= NULL
;
4506 for (; bs
!= NULL
; bs
= bs
->next
)
4508 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4509 memcpy (tmp
, bs
, sizeof (*tmp
));
4510 incref_counted_command_line (tmp
->commands
);
4511 incref_bp_location (tmp
->bp_location_at
);
4512 if (bs
->old_val
!= NULL
)
4514 tmp
->old_val
= value_copy (bs
->old_val
);
4515 release_value (tmp
->old_val
);
4519 /* This is the first thing in the chain. */
4529 /* Find the bpstat associated with this breakpoint. */
4532 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4537 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4539 if (bsp
->breakpoint_at
== breakpoint
)
4545 /* See breakpoint.h. */
4548 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4550 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4552 if (bsp
->breakpoint_at
== NULL
)
4554 /* A moribund location can never explain a signal other than
4556 if (sig
== GDB_SIGNAL_TRAP
)
4561 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4570 /* Put in *NUM the breakpoint number of the first breakpoint we are
4571 stopped at. *BSP upon return is a bpstat which points to the
4572 remaining breakpoints stopped at (but which is not guaranteed to be
4573 good for anything but further calls to bpstat_num).
4575 Return 0 if passed a bpstat which does not indicate any breakpoints.
4576 Return -1 if stopped at a breakpoint that has been deleted since
4578 Return 1 otherwise. */
4581 bpstat_num (bpstat
*bsp
, int *num
)
4583 struct breakpoint
*b
;
4586 return 0; /* No more breakpoint values */
4588 /* We assume we'll never have several bpstats that correspond to a
4589 single breakpoint -- otherwise, this function might return the
4590 same number more than once and this will look ugly. */
4591 b
= (*bsp
)->breakpoint_at
;
4592 *bsp
= (*bsp
)->next
;
4594 return -1; /* breakpoint that's been deleted since */
4596 *num
= b
->number
; /* We have its number */
4600 /* See breakpoint.h. */
4603 bpstat_clear_actions (void)
4605 struct thread_info
*tp
;
4608 if (ptid_equal (inferior_ptid
, null_ptid
))
4611 tp
= find_thread_ptid (inferior_ptid
);
4615 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4617 decref_counted_command_line (&bs
->commands
);
4619 if (bs
->old_val
!= NULL
)
4621 value_free (bs
->old_val
);
4627 /* Called when a command is about to proceed the inferior. */
4630 breakpoint_about_to_proceed (void)
4632 if (!ptid_equal (inferior_ptid
, null_ptid
))
4634 struct thread_info
*tp
= inferior_thread ();
4636 /* Allow inferior function calls in breakpoint commands to not
4637 interrupt the command list. When the call finishes
4638 successfully, the inferior will be standing at the same
4639 breakpoint as if nothing happened. */
4640 if (tp
->control
.in_infcall
)
4644 breakpoint_proceeded
= 1;
4647 /* Stub for cleaning up our state if we error-out of a breakpoint
4650 cleanup_executing_breakpoints (void *ignore
)
4652 executing_breakpoint_commands
= 0;
4655 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4656 or its equivalent. */
4659 command_line_is_silent (struct command_line
*cmd
)
4661 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4664 /* Execute all the commands associated with all the breakpoints at
4665 this location. Any of these commands could cause the process to
4666 proceed beyond this point, etc. We look out for such changes by
4667 checking the global "breakpoint_proceeded" after each command.
4669 Returns true if a breakpoint command resumed the inferior. In that
4670 case, it is the caller's responsibility to recall it again with the
4671 bpstat of the current thread. */
4674 bpstat_do_actions_1 (bpstat
*bsp
)
4677 struct cleanup
*old_chain
;
4680 /* Avoid endless recursion if a `source' command is contained
4682 if (executing_breakpoint_commands
)
4685 executing_breakpoint_commands
= 1;
4686 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4688 scoped_restore preventer
= prevent_dont_repeat ();
4690 /* This pointer will iterate over the list of bpstat's. */
4693 breakpoint_proceeded
= 0;
4694 for (; bs
!= NULL
; bs
= bs
->next
)
4696 struct counted_command_line
*ccmd
;
4697 struct command_line
*cmd
;
4698 struct cleanup
*this_cmd_tree_chain
;
4700 /* Take ownership of the BSP's command tree, if it has one.
4702 The command tree could legitimately contain commands like
4703 'step' and 'next', which call clear_proceed_status, which
4704 frees stop_bpstat's command tree. To make sure this doesn't
4705 free the tree we're executing out from under us, we need to
4706 take ownership of the tree ourselves. Since a given bpstat's
4707 commands are only executed once, we don't need to copy it; we
4708 can clear the pointer in the bpstat, and make sure we free
4709 the tree when we're done. */
4710 ccmd
= bs
->commands
;
4711 bs
->commands
= NULL
;
4712 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4713 cmd
= ccmd
? ccmd
->commands
: NULL
;
4714 if (command_line_is_silent (cmd
))
4716 /* The action has been already done by bpstat_stop_status. */
4722 execute_control_command (cmd
);
4724 if (breakpoint_proceeded
)
4730 /* We can free this command tree now. */
4731 do_cleanups (this_cmd_tree_chain
);
4733 if (breakpoint_proceeded
)
4735 if (current_ui
->async
)
4736 /* If we are in async mode, then the target might be still
4737 running, not stopped at any breakpoint, so nothing for
4738 us to do here -- just return to the event loop. */
4741 /* In sync mode, when execute_control_command returns
4742 we're already standing on the next breakpoint.
4743 Breakpoint commands for that stop were not run, since
4744 execute_command does not run breakpoint commands --
4745 only command_line_handler does, but that one is not
4746 involved in execution of breakpoint commands. So, we
4747 can now execute breakpoint commands. It should be
4748 noted that making execute_command do bpstat actions is
4749 not an option -- in this case we'll have recursive
4750 invocation of bpstat for each breakpoint with a
4751 command, and can easily blow up GDB stack. Instead, we
4752 return true, which will trigger the caller to recall us
4753 with the new stop_bpstat. */
4758 do_cleanups (old_chain
);
4763 bpstat_do_actions (void)
4765 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4767 /* Do any commands attached to breakpoint we are stopped at. */
4768 while (!ptid_equal (inferior_ptid
, null_ptid
)
4769 && target_has_execution
4770 && !is_exited (inferior_ptid
)
4771 && !is_executing (inferior_ptid
))
4772 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4773 and only return when it is stopped at the next breakpoint, we
4774 keep doing breakpoint actions until it returns false to
4775 indicate the inferior was not resumed. */
4776 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4779 discard_cleanups (cleanup_if_error
);
4782 /* Print out the (old or new) value associated with a watchpoint. */
4785 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4788 fprintf_unfiltered (stream
, _("<unreadable>"));
4791 struct value_print_options opts
;
4792 get_user_print_options (&opts
);
4793 value_print (val
, stream
, &opts
);
4797 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4798 debugging multiple threads. */
4801 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4803 if (uiout
->is_mi_like_p ())
4808 if (show_thread_that_caused_stop ())
4811 struct thread_info
*thr
= inferior_thread ();
4813 uiout
->text ("Thread ");
4814 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4816 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4819 uiout
->text (" \"");
4820 uiout
->field_fmt ("name", "%s", name
);
4824 uiout
->text (" hit ");
4828 /* Generic routine for printing messages indicating why we
4829 stopped. The behavior of this function depends on the value
4830 'print_it' in the bpstat structure. Under some circumstances we
4831 may decide not to print anything here and delegate the task to
4834 static enum print_stop_action
4835 print_bp_stop_message (bpstat bs
)
4837 switch (bs
->print_it
)
4840 /* Nothing should be printed for this bpstat entry. */
4841 return PRINT_UNKNOWN
;
4845 /* We still want to print the frame, but we already printed the
4846 relevant messages. */
4847 return PRINT_SRC_AND_LOC
;
4850 case print_it_normal
:
4852 struct breakpoint
*b
= bs
->breakpoint_at
;
4854 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4855 which has since been deleted. */
4857 return PRINT_UNKNOWN
;
4859 /* Normal case. Call the breakpoint's print_it method. */
4860 return b
->ops
->print_it (bs
);
4865 internal_error (__FILE__
, __LINE__
,
4866 _("print_bp_stop_message: unrecognized enum value"));
4871 /* A helper function that prints a shared library stopped event. */
4874 print_solib_event (int is_catchpoint
)
4877 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4879 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4883 if (any_added
|| any_deleted
)
4884 current_uiout
->text (_("Stopped due to shared library event:\n"));
4886 current_uiout
->text (_("Stopped due to shared library event (no "
4887 "libraries added or removed)\n"));
4890 if (current_uiout
->is_mi_like_p ())
4891 current_uiout
->field_string ("reason",
4892 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4899 current_uiout
->text (_(" Inferior unloaded "));
4900 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4902 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4907 current_uiout
->text (" ");
4908 current_uiout
->field_string ("library", name
);
4909 current_uiout
->text ("\n");
4915 struct so_list
*iter
;
4918 current_uiout
->text (_(" Inferior loaded "));
4919 ui_out_emit_list
list_emitter (current_uiout
, "added");
4921 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4926 current_uiout
->text (" ");
4927 current_uiout
->field_string ("library", iter
->so_name
);
4928 current_uiout
->text ("\n");
4933 /* Print a message indicating what happened. This is called from
4934 normal_stop(). The input to this routine is the head of the bpstat
4935 list - a list of the eventpoints that caused this stop. KIND is
4936 the target_waitkind for the stopping event. This
4937 routine calls the generic print routine for printing a message
4938 about reasons for stopping. This will print (for example) the
4939 "Breakpoint n," part of the output. The return value of this
4942 PRINT_UNKNOWN: Means we printed nothing.
4943 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4944 code to print the location. An example is
4945 "Breakpoint 1, " which should be followed by
4947 PRINT_SRC_ONLY: Means we printed something, but there is no need
4948 to also print the location part of the message.
4949 An example is the catch/throw messages, which
4950 don't require a location appended to the end.
4951 PRINT_NOTHING: We have done some printing and we don't need any
4952 further info to be printed. */
4954 enum print_stop_action
4955 bpstat_print (bpstat bs
, int kind
)
4957 enum print_stop_action val
;
4959 /* Maybe another breakpoint in the chain caused us to stop.
4960 (Currently all watchpoints go on the bpstat whether hit or not.
4961 That probably could (should) be changed, provided care is taken
4962 with respect to bpstat_explains_signal). */
4963 for (; bs
; bs
= bs
->next
)
4965 val
= print_bp_stop_message (bs
);
4966 if (val
== PRINT_SRC_ONLY
4967 || val
== PRINT_SRC_AND_LOC
4968 || val
== PRINT_NOTHING
)
4972 /* If we had hit a shared library event breakpoint,
4973 print_bp_stop_message would print out this message. If we hit an
4974 OS-level shared library event, do the same thing. */
4975 if (kind
== TARGET_WAITKIND_LOADED
)
4977 print_solib_event (0);
4978 return PRINT_NOTHING
;
4981 /* We reached the end of the chain, or we got a null BS to start
4982 with and nothing was printed. */
4983 return PRINT_UNKNOWN
;
4986 /* Evaluate the expression EXP and return 1 if value is zero.
4987 This returns the inverse of the condition because it is called
4988 from catch_errors which returns 0 if an exception happened, and if an
4989 exception happens we want execution to stop.
4990 The argument is a "struct expression *" that has been cast to a
4991 "void *" to make it pass through catch_errors. */
4994 breakpoint_cond_eval (void *exp
)
4996 struct value
*mark
= value_mark ();
4997 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4999 value_free_to_mark (mark
);
5003 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5006 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
5010 bs
= (bpstat
) xmalloc (sizeof (*bs
));
5012 **bs_link_pointer
= bs
;
5013 *bs_link_pointer
= &bs
->next
;
5014 bs
->breakpoint_at
= bl
->owner
;
5015 bs
->bp_location_at
= bl
;
5016 incref_bp_location (bl
);
5017 /* If the condition is false, etc., don't do the commands. */
5018 bs
->commands
= NULL
;
5020 bs
->print_it
= print_it_normal
;
5024 /* The target has stopped with waitstatus WS. Check if any hardware
5025 watchpoints have triggered, according to the target. */
5028 watchpoints_triggered (struct target_waitstatus
*ws
)
5030 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5032 struct breakpoint
*b
;
5034 if (!stopped_by_watchpoint
)
5036 /* We were not stopped by a watchpoint. Mark all watchpoints
5037 as not triggered. */
5039 if (is_hardware_watchpoint (b
))
5041 struct watchpoint
*w
= (struct watchpoint
*) b
;
5043 w
->watchpoint_triggered
= watch_triggered_no
;
5049 if (!target_stopped_data_address (¤t_target
, &addr
))
5051 /* We were stopped by a watchpoint, but we don't know where.
5052 Mark all watchpoints as unknown. */
5054 if (is_hardware_watchpoint (b
))
5056 struct watchpoint
*w
= (struct watchpoint
*) b
;
5058 w
->watchpoint_triggered
= watch_triggered_unknown
;
5064 /* The target could report the data address. Mark watchpoints
5065 affected by this data address as triggered, and all others as not
5069 if (is_hardware_watchpoint (b
))
5071 struct watchpoint
*w
= (struct watchpoint
*) b
;
5072 struct bp_location
*loc
;
5074 w
->watchpoint_triggered
= watch_triggered_no
;
5075 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5077 if (is_masked_watchpoint (b
))
5079 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5080 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5082 if (newaddr
== start
)
5084 w
->watchpoint_triggered
= watch_triggered_yes
;
5088 /* Exact match not required. Within range is sufficient. */
5089 else if (target_watchpoint_addr_within_range (¤t_target
,
5093 w
->watchpoint_triggered
= watch_triggered_yes
;
5102 /* Possible return values for watchpoint_check (this can't be an enum
5103 because of check_errors). */
5104 /* The watchpoint has been deleted. */
5105 #define WP_DELETED 1
5106 /* The value has changed. */
5107 #define WP_VALUE_CHANGED 2
5108 /* The value has not changed. */
5109 #define WP_VALUE_NOT_CHANGED 3
5110 /* Ignore this watchpoint, no matter if the value changed or not. */
5113 #define BP_TEMPFLAG 1
5114 #define BP_HARDWAREFLAG 2
5116 /* Evaluate watchpoint condition expression and check if its value
5119 P should be a pointer to struct bpstat, but is defined as a void *
5120 in order for this function to be usable with catch_errors. */
5123 watchpoint_check (void *p
)
5125 bpstat bs
= (bpstat
) p
;
5126 struct watchpoint
*b
;
5127 struct frame_info
*fr
;
5128 int within_current_scope
;
5130 /* BS is built from an existing struct breakpoint. */
5131 gdb_assert (bs
->breakpoint_at
!= NULL
);
5132 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5134 /* If this is a local watchpoint, we only want to check if the
5135 watchpoint frame is in scope if the current thread is the thread
5136 that was used to create the watchpoint. */
5137 if (!watchpoint_in_thread_scope (b
))
5140 if (b
->exp_valid_block
== NULL
)
5141 within_current_scope
= 1;
5144 struct frame_info
*frame
= get_current_frame ();
5145 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5146 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5148 /* stack_frame_destroyed_p() returns a non-zero value if we're
5149 still in the function but the stack frame has already been
5150 invalidated. Since we can't rely on the values of local
5151 variables after the stack has been destroyed, we are treating
5152 the watchpoint in that state as `not changed' without further
5153 checking. Don't mark watchpoints as changed if the current
5154 frame is in an epilogue - even if they are in some other
5155 frame, our view of the stack is likely to be wrong and
5156 frame_find_by_id could error out. */
5157 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5160 fr
= frame_find_by_id (b
->watchpoint_frame
);
5161 within_current_scope
= (fr
!= NULL
);
5163 /* If we've gotten confused in the unwinder, we might have
5164 returned a frame that can't describe this variable. */
5165 if (within_current_scope
)
5167 struct symbol
*function
;
5169 function
= get_frame_function (fr
);
5170 if (function
== NULL
5171 || !contained_in (b
->exp_valid_block
,
5172 SYMBOL_BLOCK_VALUE (function
)))
5173 within_current_scope
= 0;
5176 if (within_current_scope
)
5177 /* If we end up stopping, the current frame will get selected
5178 in normal_stop. So this call to select_frame won't affect
5183 if (within_current_scope
)
5185 /* We use value_{,free_to_}mark because it could be a *long*
5186 time before we return to the command level and call
5187 free_all_values. We can't call free_all_values because we
5188 might be in the middle of evaluating a function call. */
5192 struct value
*new_val
;
5194 if (is_masked_watchpoint (b
))
5195 /* Since we don't know the exact trigger address (from
5196 stopped_data_address), just tell the user we've triggered
5197 a mask watchpoint. */
5198 return WP_VALUE_CHANGED
;
5200 mark
= value_mark ();
5201 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5203 if (b
->val_bitsize
!= 0)
5204 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5206 /* We use value_equal_contents instead of value_equal because
5207 the latter coerces an array to a pointer, thus comparing just
5208 the address of the array instead of its contents. This is
5209 not what we want. */
5210 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5211 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5213 if (new_val
!= NULL
)
5215 release_value (new_val
);
5216 value_free_to_mark (mark
);
5218 bs
->old_val
= b
->val
;
5221 return WP_VALUE_CHANGED
;
5225 /* Nothing changed. */
5226 value_free_to_mark (mark
);
5227 return WP_VALUE_NOT_CHANGED
;
5232 /* This seems like the only logical thing to do because
5233 if we temporarily ignored the watchpoint, then when
5234 we reenter the block in which it is valid it contains
5235 garbage (in the case of a function, it may have two
5236 garbage values, one before and one after the prologue).
5237 So we can't even detect the first assignment to it and
5238 watch after that (since the garbage may or may not equal
5239 the first value assigned). */
5240 /* We print all the stop information in
5241 breakpoint_ops->print_it, but in this case, by the time we
5242 call breakpoint_ops->print_it this bp will be deleted
5243 already. So we have no choice but print the information
5246 SWITCH_THRU_ALL_UIS ()
5248 struct ui_out
*uiout
= current_uiout
;
5250 if (uiout
->is_mi_like_p ())
5252 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5253 uiout
->text ("\nWatchpoint ");
5254 uiout
->field_int ("wpnum", b
->number
);
5255 uiout
->text (" deleted because the program has left the block in\n"
5256 "which its expression is valid.\n");
5259 /* Make sure the watchpoint's commands aren't executed. */
5260 decref_counted_command_line (&b
->commands
);
5261 watchpoint_del_at_next_stop (b
);
5267 /* Return true if it looks like target has stopped due to hitting
5268 breakpoint location BL. This function does not check if we should
5269 stop, only if BL explains the stop. */
5272 bpstat_check_location (const struct bp_location
*bl
,
5273 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5274 const struct target_waitstatus
*ws
)
5276 struct breakpoint
*b
= bl
->owner
;
5278 /* BL is from an existing breakpoint. */
5279 gdb_assert (b
!= NULL
);
5281 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5284 /* Determine if the watched values have actually changed, and we
5285 should stop. If not, set BS->stop to 0. */
5288 bpstat_check_watchpoint (bpstat bs
)
5290 const struct bp_location
*bl
;
5291 struct watchpoint
*b
;
5293 /* BS is built for existing struct breakpoint. */
5294 bl
= bs
->bp_location_at
;
5295 gdb_assert (bl
!= NULL
);
5296 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5297 gdb_assert (b
!= NULL
);
5300 int must_check_value
= 0;
5302 if (b
->type
== bp_watchpoint
)
5303 /* For a software watchpoint, we must always check the
5305 must_check_value
= 1;
5306 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5307 /* We have a hardware watchpoint (read, write, or access)
5308 and the target earlier reported an address watched by
5310 must_check_value
= 1;
5311 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5312 && b
->type
== bp_hardware_watchpoint
)
5313 /* We were stopped by a hardware watchpoint, but the target could
5314 not report the data address. We must check the watchpoint's
5315 value. Access and read watchpoints are out of luck; without
5316 a data address, we can't figure it out. */
5317 must_check_value
= 1;
5319 if (must_check_value
)
5322 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5324 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5325 int e
= catch_errors (watchpoint_check
, bs
, message
,
5327 do_cleanups (cleanups
);
5331 /* We've already printed what needs to be printed. */
5332 bs
->print_it
= print_it_done
;
5336 bs
->print_it
= print_it_noop
;
5339 case WP_VALUE_CHANGED
:
5340 if (b
->type
== bp_read_watchpoint
)
5342 /* There are two cases to consider here:
5344 1. We're watching the triggered memory for reads.
5345 In that case, trust the target, and always report
5346 the watchpoint hit to the user. Even though
5347 reads don't cause value changes, the value may
5348 have changed since the last time it was read, and
5349 since we're not trapping writes, we will not see
5350 those, and as such we should ignore our notion of
5353 2. We're watching the triggered memory for both
5354 reads and writes. There are two ways this may
5357 2.1. This is a target that can't break on data
5358 reads only, but can break on accesses (reads or
5359 writes), such as e.g., x86. We detect this case
5360 at the time we try to insert read watchpoints.
5362 2.2. Otherwise, the target supports read
5363 watchpoints, but, the user set an access or write
5364 watchpoint watching the same memory as this read
5367 If we're watching memory writes as well as reads,
5368 ignore watchpoint hits when we find that the
5369 value hasn't changed, as reads don't cause
5370 changes. This still gives false positives when
5371 the program writes the same value to memory as
5372 what there was already in memory (we will confuse
5373 it for a read), but it's much better than
5376 int other_write_watchpoint
= 0;
5378 if (bl
->watchpoint_type
== hw_read
)
5380 struct breakpoint
*other_b
;
5382 ALL_BREAKPOINTS (other_b
)
5383 if (other_b
->type
== bp_hardware_watchpoint
5384 || other_b
->type
== bp_access_watchpoint
)
5386 struct watchpoint
*other_w
=
5387 (struct watchpoint
*) other_b
;
5389 if (other_w
->watchpoint_triggered
5390 == watch_triggered_yes
)
5392 other_write_watchpoint
= 1;
5398 if (other_write_watchpoint
5399 || bl
->watchpoint_type
== hw_access
)
5401 /* We're watching the same memory for writes,
5402 and the value changed since the last time we
5403 updated it, so this trap must be for a write.
5405 bs
->print_it
= print_it_noop
;
5410 case WP_VALUE_NOT_CHANGED
:
5411 if (b
->type
== bp_hardware_watchpoint
5412 || b
->type
== bp_watchpoint
)
5414 /* Don't stop: write watchpoints shouldn't fire if
5415 the value hasn't changed. */
5416 bs
->print_it
= print_it_noop
;
5424 /* Error from catch_errors. */
5426 SWITCH_THRU_ALL_UIS ()
5428 printf_filtered (_("Watchpoint %d deleted.\n"),
5431 watchpoint_del_at_next_stop (b
);
5432 /* We've already printed what needs to be printed. */
5433 bs
->print_it
= print_it_done
;
5438 else /* must_check_value == 0 */
5440 /* This is a case where some watchpoint(s) triggered, but
5441 not at the address of this watchpoint, or else no
5442 watchpoint triggered after all. So don't print
5443 anything for this watchpoint. */
5444 bs
->print_it
= print_it_noop
;
5450 /* For breakpoints that are currently marked as telling gdb to stop,
5451 check conditions (condition proper, frame, thread and ignore count)
5452 of breakpoint referred to by BS. If we should not stop for this
5453 breakpoint, set BS->stop to 0. */
5456 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5458 const struct bp_location
*bl
;
5459 struct breakpoint
*b
;
5460 int value_is_zero
= 0;
5461 struct expression
*cond
;
5463 gdb_assert (bs
->stop
);
5465 /* BS is built for existing struct breakpoint. */
5466 bl
= bs
->bp_location_at
;
5467 gdb_assert (bl
!= NULL
);
5468 b
= bs
->breakpoint_at
;
5469 gdb_assert (b
!= NULL
);
5471 /* Even if the target evaluated the condition on its end and notified GDB, we
5472 need to do so again since GDB does not know if we stopped due to a
5473 breakpoint or a single step breakpoint. */
5475 if (frame_id_p (b
->frame_id
)
5476 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5482 /* If this is a thread/task-specific breakpoint, don't waste cpu
5483 evaluating the condition if this isn't the specified
5485 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5486 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5493 /* Evaluate extension language breakpoints that have a "stop" method
5495 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5497 if (is_watchpoint (b
))
5499 struct watchpoint
*w
= (struct watchpoint
*) b
;
5501 cond
= w
->cond_exp
.get ();
5504 cond
= bl
->cond
.get ();
5506 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5508 int within_current_scope
= 1;
5509 struct watchpoint
* w
;
5511 /* We use value_mark and value_free_to_mark because it could
5512 be a long time before we return to the command level and
5513 call free_all_values. We can't call free_all_values
5514 because we might be in the middle of evaluating a
5516 struct value
*mark
= value_mark ();
5518 if (is_watchpoint (b
))
5519 w
= (struct watchpoint
*) b
;
5523 /* Need to select the frame, with all that implies so that
5524 the conditions will have the right context. Because we
5525 use the frame, we will not see an inlined function's
5526 variables when we arrive at a breakpoint at the start
5527 of the inlined function; the current frame will be the
5529 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5530 select_frame (get_current_frame ());
5533 struct frame_info
*frame
;
5535 /* For local watchpoint expressions, which particular
5536 instance of a local is being watched matters, so we
5537 keep track of the frame to evaluate the expression
5538 in. To evaluate the condition however, it doesn't
5539 really matter which instantiation of the function
5540 where the condition makes sense triggers the
5541 watchpoint. This allows an expression like "watch
5542 global if q > 10" set in `func', catch writes to
5543 global on all threads that call `func', or catch
5544 writes on all recursive calls of `func' by a single
5545 thread. We simply always evaluate the condition in
5546 the innermost frame that's executing where it makes
5547 sense to evaluate the condition. It seems
5549 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5551 select_frame (frame
);
5553 within_current_scope
= 0;
5555 if (within_current_scope
)
5557 = catch_errors (breakpoint_cond_eval
, cond
,
5558 "Error in testing breakpoint condition:\n",
5562 warning (_("Watchpoint condition cannot be tested "
5563 "in the current scope"));
5564 /* If we failed to set the right context for this
5565 watchpoint, unconditionally report it. */
5568 /* FIXME-someday, should give breakpoint #. */
5569 value_free_to_mark (mark
);
5572 if (cond
&& value_is_zero
)
5576 else if (b
->ignore_count
> 0)
5580 /* Increase the hit count even though we don't stop. */
5582 observer_notify_breakpoint_modified (b
);
5586 /* Returns true if we need to track moribund locations of LOC's type
5587 on the current target. */
5590 need_moribund_for_location_type (struct bp_location
*loc
)
5592 return ((loc
->loc_type
== bp_loc_software_breakpoint
5593 && !target_supports_stopped_by_sw_breakpoint ())
5594 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5595 && !target_supports_stopped_by_hw_breakpoint ()));
5599 /* Get a bpstat associated with having just stopped at address
5600 BP_ADDR in thread PTID.
5602 Determine whether we stopped at a breakpoint, etc, or whether we
5603 don't understand this stop. Result is a chain of bpstat's such
5606 if we don't understand the stop, the result is a null pointer.
5608 if we understand why we stopped, the result is not null.
5610 Each element of the chain refers to a particular breakpoint or
5611 watchpoint at which we have stopped. (We may have stopped for
5612 several reasons concurrently.)
5614 Each element of the chain has valid next, breakpoint_at,
5615 commands, FIXME??? fields. */
5618 bpstat_stop_status (struct address_space
*aspace
,
5619 CORE_ADDR bp_addr
, ptid_t ptid
,
5620 const struct target_waitstatus
*ws
)
5622 struct breakpoint
*b
= NULL
;
5623 struct bp_location
*bl
;
5624 struct bp_location
*loc
;
5625 /* First item of allocated bpstat's. */
5626 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5627 /* Pointer to the last thing in the chain currently. */
5630 int need_remove_insert
;
5633 /* First, build the bpstat chain with locations that explain a
5634 target stop, while being careful to not set the target running,
5635 as that may invalidate locations (in particular watchpoint
5636 locations are recreated). Resuming will happen here with
5637 breakpoint conditions or watchpoint expressions that include
5638 inferior function calls. */
5642 if (!breakpoint_enabled (b
))
5645 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5647 /* For hardware watchpoints, we look only at the first
5648 location. The watchpoint_check function will work on the
5649 entire expression, not the individual locations. For
5650 read watchpoints, the watchpoints_triggered function has
5651 checked all locations already. */
5652 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5655 if (!bl
->enabled
|| bl
->shlib_disabled
)
5658 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5661 /* Come here if it's a watchpoint, or if the break address
5664 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5667 /* Assume we stop. Should we find a watchpoint that is not
5668 actually triggered, or if the condition of the breakpoint
5669 evaluates as false, we'll reset 'stop' to 0. */
5673 /* If this is a scope breakpoint, mark the associated
5674 watchpoint as triggered so that we will handle the
5675 out-of-scope event. We'll get to the watchpoint next
5677 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5679 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5681 w
->watchpoint_triggered
= watch_triggered_yes
;
5686 /* Check if a moribund breakpoint explains the stop. */
5687 if (!target_supports_stopped_by_sw_breakpoint ()
5688 || !target_supports_stopped_by_hw_breakpoint ())
5690 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5692 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5693 && need_moribund_for_location_type (loc
))
5695 bs
= bpstat_alloc (loc
, &bs_link
);
5696 /* For hits of moribund locations, we should just proceed. */
5699 bs
->print_it
= print_it_noop
;
5704 /* A bit of special processing for shlib breakpoints. We need to
5705 process solib loading here, so that the lists of loaded and
5706 unloaded libraries are correct before we handle "catch load" and
5708 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5710 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5712 handle_solib_event ();
5717 /* Now go through the locations that caused the target to stop, and
5718 check whether we're interested in reporting this stop to higher
5719 layers, or whether we should resume the target transparently. */
5723 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5728 b
= bs
->breakpoint_at
;
5729 b
->ops
->check_status (bs
);
5732 bpstat_check_breakpoint_conditions (bs
, ptid
);
5737 observer_notify_breakpoint_modified (b
);
5739 /* We will stop here. */
5740 if (b
->disposition
== disp_disable
)
5742 --(b
->enable_count
);
5743 if (b
->enable_count
<= 0)
5744 b
->enable_state
= bp_disabled
;
5749 bs
->commands
= b
->commands
;
5750 incref_counted_command_line (bs
->commands
);
5751 if (command_line_is_silent (bs
->commands
5752 ? bs
->commands
->commands
: NULL
))
5755 b
->ops
->after_condition_true (bs
);
5760 /* Print nothing for this entry if we don't stop or don't
5762 if (!bs
->stop
|| !bs
->print
)
5763 bs
->print_it
= print_it_noop
;
5766 /* If we aren't stopping, the value of some hardware watchpoint may
5767 not have changed, but the intermediate memory locations we are
5768 watching may have. Don't bother if we're stopping; this will get
5770 need_remove_insert
= 0;
5771 if (! bpstat_causes_stop (bs_head
))
5772 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5774 && bs
->breakpoint_at
5775 && is_hardware_watchpoint (bs
->breakpoint_at
))
5777 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5779 update_watchpoint (w
, 0 /* don't reparse. */);
5780 need_remove_insert
= 1;
5783 if (need_remove_insert
)
5784 update_global_location_list (UGLL_MAY_INSERT
);
5785 else if (removed_any
)
5786 update_global_location_list (UGLL_DONT_INSERT
);
5792 handle_jit_event (void)
5794 struct frame_info
*frame
;
5795 struct gdbarch
*gdbarch
;
5798 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5800 /* Switch terminal for any messages produced by
5801 breakpoint_re_set. */
5802 target_terminal_ours_for_output ();
5804 frame
= get_current_frame ();
5805 gdbarch
= get_frame_arch (frame
);
5807 jit_event_handler (gdbarch
);
5809 target_terminal_inferior ();
5812 /* Prepare WHAT final decision for infrun. */
5814 /* Decide what infrun needs to do with this bpstat. */
5817 bpstat_what (bpstat bs_head
)
5819 struct bpstat_what retval
;
5822 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5823 retval
.call_dummy
= STOP_NONE
;
5824 retval
.is_longjmp
= 0;
5826 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5828 /* Extract this BS's action. After processing each BS, we check
5829 if its action overrides all we've seem so far. */
5830 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5833 if (bs
->breakpoint_at
== NULL
)
5835 /* I suspect this can happen if it was a momentary
5836 breakpoint which has since been deleted. */
5840 bptype
= bs
->breakpoint_at
->type
;
5847 case bp_hardware_breakpoint
:
5848 case bp_single_step
:
5851 case bp_shlib_event
:
5855 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5857 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5860 this_action
= BPSTAT_WHAT_SINGLE
;
5863 case bp_hardware_watchpoint
:
5864 case bp_read_watchpoint
:
5865 case bp_access_watchpoint
:
5869 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5871 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5875 /* There was a watchpoint, but we're not stopping.
5876 This requires no further action. */
5880 case bp_longjmp_call_dummy
:
5884 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5885 retval
.is_longjmp
= bptype
!= bp_exception
;
5888 this_action
= BPSTAT_WHAT_SINGLE
;
5890 case bp_longjmp_resume
:
5891 case bp_exception_resume
:
5894 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5895 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5898 this_action
= BPSTAT_WHAT_SINGLE
;
5900 case bp_step_resume
:
5902 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5905 /* It is for the wrong frame. */
5906 this_action
= BPSTAT_WHAT_SINGLE
;
5909 case bp_hp_step_resume
:
5911 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5914 /* It is for the wrong frame. */
5915 this_action
= BPSTAT_WHAT_SINGLE
;
5918 case bp_watchpoint_scope
:
5919 case bp_thread_event
:
5920 case bp_overlay_event
:
5921 case bp_longjmp_master
:
5922 case bp_std_terminate_master
:
5923 case bp_exception_master
:
5924 this_action
= BPSTAT_WHAT_SINGLE
;
5930 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5932 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5936 /* There was a catchpoint, but we're not stopping.
5937 This requires no further action. */
5941 this_action
= BPSTAT_WHAT_SINGLE
;
5944 /* Make sure the action is stop (silent or noisy),
5945 so infrun.c pops the dummy frame. */
5946 retval
.call_dummy
= STOP_STACK_DUMMY
;
5947 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5949 case bp_std_terminate
:
5950 /* Make sure the action is stop (silent or noisy),
5951 so infrun.c pops the dummy frame. */
5952 retval
.call_dummy
= STOP_STD_TERMINATE
;
5953 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5956 case bp_fast_tracepoint
:
5957 case bp_static_tracepoint
:
5958 /* Tracepoint hits should not be reported back to GDB, and
5959 if one got through somehow, it should have been filtered
5961 internal_error (__FILE__
, __LINE__
,
5962 _("bpstat_what: tracepoint encountered"));
5964 case bp_gnu_ifunc_resolver
:
5965 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5966 this_action
= BPSTAT_WHAT_SINGLE
;
5968 case bp_gnu_ifunc_resolver_return
:
5969 /* The breakpoint will be removed, execution will restart from the
5970 PC of the former breakpoint. */
5971 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5976 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5978 this_action
= BPSTAT_WHAT_SINGLE
;
5982 internal_error (__FILE__
, __LINE__
,
5983 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5986 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5993 bpstat_run_callbacks (bpstat bs_head
)
5997 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5999 struct breakpoint
*b
= bs
->breakpoint_at
;
6006 handle_jit_event ();
6008 case bp_gnu_ifunc_resolver
:
6009 gnu_ifunc_resolver_stop (b
);
6011 case bp_gnu_ifunc_resolver_return
:
6012 gnu_ifunc_resolver_return_stop (b
);
6018 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6019 without hardware support). This isn't related to a specific bpstat,
6020 just to things like whether watchpoints are set. */
6023 bpstat_should_step (void)
6025 struct breakpoint
*b
;
6028 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6034 bpstat_causes_stop (bpstat bs
)
6036 for (; bs
!= NULL
; bs
= bs
->next
)
6045 /* Compute a string of spaces suitable to indent the next line
6046 so it starts at the position corresponding to the table column
6047 named COL_NAME in the currently active table of UIOUT. */
6050 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6052 static char wrap_indent
[80];
6053 int i
, total_width
, width
, align
;
6057 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6059 if (strcmp (text
, col_name
) == 0)
6061 gdb_assert (total_width
< sizeof wrap_indent
);
6062 memset (wrap_indent
, ' ', total_width
);
6063 wrap_indent
[total_width
] = 0;
6068 total_width
+= width
+ 1;
6074 /* Determine if the locations of this breakpoint will have their conditions
6075 evaluated by the target, host or a mix of both. Returns the following:
6077 "host": Host evals condition.
6078 "host or target": Host or Target evals condition.
6079 "target": Target evals condition.
6083 bp_condition_evaluator (struct breakpoint
*b
)
6085 struct bp_location
*bl
;
6086 char host_evals
= 0;
6087 char target_evals
= 0;
6092 if (!is_breakpoint (b
))
6095 if (gdb_evaluates_breakpoint_condition_p ()
6096 || !target_supports_evaluation_of_breakpoint_conditions ())
6097 return condition_evaluation_host
;
6099 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6101 if (bl
->cond_bytecode
)
6107 if (host_evals
&& target_evals
)
6108 return condition_evaluation_both
;
6109 else if (target_evals
)
6110 return condition_evaluation_target
;
6112 return condition_evaluation_host
;
6115 /* Determine the breakpoint location's condition evaluator. This is
6116 similar to bp_condition_evaluator, but for locations. */
6119 bp_location_condition_evaluator (struct bp_location
*bl
)
6121 if (bl
&& !is_breakpoint (bl
->owner
))
6124 if (gdb_evaluates_breakpoint_condition_p ()
6125 || !target_supports_evaluation_of_breakpoint_conditions ())
6126 return condition_evaluation_host
;
6128 if (bl
&& bl
->cond_bytecode
)
6129 return condition_evaluation_target
;
6131 return condition_evaluation_host
;
6134 /* Print the LOC location out of the list of B->LOC locations. */
6137 print_breakpoint_location (struct breakpoint
*b
,
6138 struct bp_location
*loc
)
6140 struct ui_out
*uiout
= current_uiout
;
6142 scoped_restore_current_program_space restore_pspace
;
6144 if (loc
!= NULL
&& loc
->shlib_disabled
)
6148 set_current_program_space (loc
->pspace
);
6150 if (b
->display_canonical
)
6151 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6152 else if (loc
&& loc
->symtab
)
6155 = find_pc_sect_function (loc
->address
, loc
->section
);
6158 uiout
->text ("in ");
6159 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6161 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6162 uiout
->text ("at ");
6164 uiout
->field_string ("file",
6165 symtab_to_filename_for_display (loc
->symtab
));
6168 if (uiout
->is_mi_like_p ())
6169 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6171 uiout
->field_int ("line", loc
->line_number
);
6177 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6179 uiout
->field_stream ("at", stb
);
6183 uiout
->field_string ("pending",
6184 event_location_to_string (b
->location
.get ()));
6185 /* If extra_string is available, it could be holding a condition
6186 or dprintf arguments. In either case, make sure it is printed,
6187 too, but only for non-MI streams. */
6188 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6190 if (b
->type
== bp_dprintf
)
6194 uiout
->text (b
->extra_string
);
6198 if (loc
&& is_breakpoint (b
)
6199 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6200 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6203 uiout
->field_string ("evaluated-by",
6204 bp_location_condition_evaluator (loc
));
6210 bptype_string (enum bptype type
)
6212 struct ep_type_description
6215 const char *description
;
6217 static struct ep_type_description bptypes
[] =
6219 {bp_none
, "?deleted?"},
6220 {bp_breakpoint
, "breakpoint"},
6221 {bp_hardware_breakpoint
, "hw breakpoint"},
6222 {bp_single_step
, "sw single-step"},
6223 {bp_until
, "until"},
6224 {bp_finish
, "finish"},
6225 {bp_watchpoint
, "watchpoint"},
6226 {bp_hardware_watchpoint
, "hw watchpoint"},
6227 {bp_read_watchpoint
, "read watchpoint"},
6228 {bp_access_watchpoint
, "acc watchpoint"},
6229 {bp_longjmp
, "longjmp"},
6230 {bp_longjmp_resume
, "longjmp resume"},
6231 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6232 {bp_exception
, "exception"},
6233 {bp_exception_resume
, "exception resume"},
6234 {bp_step_resume
, "step resume"},
6235 {bp_hp_step_resume
, "high-priority step resume"},
6236 {bp_watchpoint_scope
, "watchpoint scope"},
6237 {bp_call_dummy
, "call dummy"},
6238 {bp_std_terminate
, "std::terminate"},
6239 {bp_shlib_event
, "shlib events"},
6240 {bp_thread_event
, "thread events"},
6241 {bp_overlay_event
, "overlay events"},
6242 {bp_longjmp_master
, "longjmp master"},
6243 {bp_std_terminate_master
, "std::terminate master"},
6244 {bp_exception_master
, "exception master"},
6245 {bp_catchpoint
, "catchpoint"},
6246 {bp_tracepoint
, "tracepoint"},
6247 {bp_fast_tracepoint
, "fast tracepoint"},
6248 {bp_static_tracepoint
, "static tracepoint"},
6249 {bp_dprintf
, "dprintf"},
6250 {bp_jit_event
, "jit events"},
6251 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6252 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6255 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6256 || ((int) type
!= bptypes
[(int) type
].type
))
6257 internal_error (__FILE__
, __LINE__
,
6258 _("bptypes table does not describe type #%d."),
6261 return bptypes
[(int) type
].description
;
6264 /* For MI, output a field named 'thread-groups' with a list as the value.
6265 For CLI, prefix the list with the string 'inf'. */
6268 output_thread_groups (struct ui_out
*uiout
,
6269 const char *field_name
,
6273 int is_mi
= uiout
->is_mi_like_p ();
6277 /* For backward compatibility, don't display inferiors in CLI unless
6278 there are several. Always display them for MI. */
6279 if (!is_mi
&& mi_only
)
6282 ui_out_emit_list
list_emitter (uiout
, field_name
);
6284 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6290 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6291 uiout
->field_string (NULL
, mi_group
);
6296 uiout
->text (" inf ");
6300 uiout
->text (plongest (inf
));
6305 /* Print B to gdb_stdout. */
6308 print_one_breakpoint_location (struct breakpoint
*b
,
6309 struct bp_location
*loc
,
6311 struct bp_location
**last_loc
,
6314 struct command_line
*l
;
6315 static char bpenables
[] = "nynny";
6317 struct ui_out
*uiout
= current_uiout
;
6318 int header_of_multiple
= 0;
6319 int part_of_multiple
= (loc
!= NULL
);
6320 struct value_print_options opts
;
6322 get_user_print_options (&opts
);
6324 gdb_assert (!loc
|| loc_number
!= 0);
6325 /* See comment in print_one_breakpoint concerning treatment of
6326 breakpoints with single disabled location. */
6329 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6330 header_of_multiple
= 1;
6338 if (part_of_multiple
)
6341 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6342 uiout
->field_string ("number", formatted
);
6347 uiout
->field_int ("number", b
->number
);
6352 if (part_of_multiple
)
6353 uiout
->field_skip ("type");
6355 uiout
->field_string ("type", bptype_string (b
->type
));
6359 if (part_of_multiple
)
6360 uiout
->field_skip ("disp");
6362 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6367 if (part_of_multiple
)
6368 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6370 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6375 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6377 /* Although the print_one can possibly print all locations,
6378 calling it here is not likely to get any nice result. So,
6379 make sure there's just one location. */
6380 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6381 b
->ops
->print_one (b
, last_loc
);
6387 internal_error (__FILE__
, __LINE__
,
6388 _("print_one_breakpoint: bp_none encountered\n"));
6392 case bp_hardware_watchpoint
:
6393 case bp_read_watchpoint
:
6394 case bp_access_watchpoint
:
6396 struct watchpoint
*w
= (struct watchpoint
*) b
;
6398 /* Field 4, the address, is omitted (which makes the columns
6399 not line up too nicely with the headers, but the effect
6400 is relatively readable). */
6401 if (opts
.addressprint
)
6402 uiout
->field_skip ("addr");
6404 uiout
->field_string ("what", w
->exp_string
);
6409 case bp_hardware_breakpoint
:
6410 case bp_single_step
:
6414 case bp_longjmp_resume
:
6415 case bp_longjmp_call_dummy
:
6417 case bp_exception_resume
:
6418 case bp_step_resume
:
6419 case bp_hp_step_resume
:
6420 case bp_watchpoint_scope
:
6422 case bp_std_terminate
:
6423 case bp_shlib_event
:
6424 case bp_thread_event
:
6425 case bp_overlay_event
:
6426 case bp_longjmp_master
:
6427 case bp_std_terminate_master
:
6428 case bp_exception_master
:
6430 case bp_fast_tracepoint
:
6431 case bp_static_tracepoint
:
6434 case bp_gnu_ifunc_resolver
:
6435 case bp_gnu_ifunc_resolver_return
:
6436 if (opts
.addressprint
)
6439 if (header_of_multiple
)
6440 uiout
->field_string ("addr", "<MULTIPLE>");
6441 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6442 uiout
->field_string ("addr", "<PENDING>");
6444 uiout
->field_core_addr ("addr",
6445 loc
->gdbarch
, loc
->address
);
6448 if (!header_of_multiple
)
6449 print_breakpoint_location (b
, loc
);
6456 if (loc
!= NULL
&& !header_of_multiple
)
6458 struct inferior
*inf
;
6459 VEC(int) *inf_num
= NULL
;
6464 if (inf
->pspace
== loc
->pspace
)
6465 VEC_safe_push (int, inf_num
, inf
->num
);
6468 /* For backward compatibility, don't display inferiors in CLI unless
6469 there are several. Always display for MI. */
6471 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6472 && (number_of_program_spaces () > 1
6473 || number_of_inferiors () > 1)
6474 /* LOC is for existing B, it cannot be in
6475 moribund_locations and thus having NULL OWNER. */
6476 && loc
->owner
->type
!= bp_catchpoint
))
6478 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6479 VEC_free (int, inf_num
);
6482 if (!part_of_multiple
)
6484 if (b
->thread
!= -1)
6486 /* FIXME: This seems to be redundant and lost here; see the
6487 "stop only in" line a little further down. */
6488 uiout
->text (" thread ");
6489 uiout
->field_int ("thread", b
->thread
);
6491 else if (b
->task
!= 0)
6493 uiout
->text (" task ");
6494 uiout
->field_int ("task", b
->task
);
6500 if (!part_of_multiple
)
6501 b
->ops
->print_one_detail (b
, uiout
);
6503 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6506 uiout
->text ("\tstop only in stack frame at ");
6507 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6509 uiout
->field_core_addr ("frame",
6510 b
->gdbarch
, b
->frame_id
.stack_addr
);
6514 if (!part_of_multiple
&& b
->cond_string
)
6517 if (is_tracepoint (b
))
6518 uiout
->text ("\ttrace only if ");
6520 uiout
->text ("\tstop only if ");
6521 uiout
->field_string ("cond", b
->cond_string
);
6523 /* Print whether the target is doing the breakpoint's condition
6524 evaluation. If GDB is doing the evaluation, don't print anything. */
6525 if (is_breakpoint (b
)
6526 && breakpoint_condition_evaluation_mode ()
6527 == condition_evaluation_target
)
6530 uiout
->field_string ("evaluated-by",
6531 bp_condition_evaluator (b
));
6532 uiout
->text (" evals)");
6537 if (!part_of_multiple
&& b
->thread
!= -1)
6539 /* FIXME should make an annotation for this. */
6540 uiout
->text ("\tstop only in thread ");
6541 if (uiout
->is_mi_like_p ())
6542 uiout
->field_int ("thread", b
->thread
);
6545 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6547 uiout
->field_string ("thread", print_thread_id (thr
));
6552 if (!part_of_multiple
)
6556 /* FIXME should make an annotation for this. */
6557 if (is_catchpoint (b
))
6558 uiout
->text ("\tcatchpoint");
6559 else if (is_tracepoint (b
))
6560 uiout
->text ("\ttracepoint");
6562 uiout
->text ("\tbreakpoint");
6563 uiout
->text (" already hit ");
6564 uiout
->field_int ("times", b
->hit_count
);
6565 if (b
->hit_count
== 1)
6566 uiout
->text (" time\n");
6568 uiout
->text (" times\n");
6572 /* Output the count also if it is zero, but only if this is mi. */
6573 if (uiout
->is_mi_like_p ())
6574 uiout
->field_int ("times", b
->hit_count
);
6578 if (!part_of_multiple
&& b
->ignore_count
)
6581 uiout
->text ("\tignore next ");
6582 uiout
->field_int ("ignore", b
->ignore_count
);
6583 uiout
->text (" hits\n");
6586 /* Note that an enable count of 1 corresponds to "enable once"
6587 behavior, which is reported by the combination of enablement and
6588 disposition, so we don't need to mention it here. */
6589 if (!part_of_multiple
&& b
->enable_count
> 1)
6592 uiout
->text ("\tdisable after ");
6593 /* Tweak the wording to clarify that ignore and enable counts
6594 are distinct, and have additive effect. */
6595 if (b
->ignore_count
)
6596 uiout
->text ("additional ");
6598 uiout
->text ("next ");
6599 uiout
->field_int ("enable", b
->enable_count
);
6600 uiout
->text (" hits\n");
6603 if (!part_of_multiple
&& is_tracepoint (b
))
6605 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6607 if (tp
->traceframe_usage
)
6609 uiout
->text ("\ttrace buffer usage ");
6610 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6611 uiout
->text (" bytes\n");
6615 l
= b
->commands
? b
->commands
->commands
: NULL
;
6616 if (!part_of_multiple
&& l
)
6619 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6620 print_command_lines (uiout
, l
, 4);
6623 if (is_tracepoint (b
))
6625 struct tracepoint
*t
= (struct tracepoint
*) b
;
6627 if (!part_of_multiple
&& t
->pass_count
)
6629 annotate_field (10);
6630 uiout
->text ("\tpass count ");
6631 uiout
->field_int ("pass", t
->pass_count
);
6632 uiout
->text (" \n");
6635 /* Don't display it when tracepoint or tracepoint location is
6637 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6639 annotate_field (11);
6641 if (uiout
->is_mi_like_p ())
6642 uiout
->field_string ("installed",
6643 loc
->inserted
? "y" : "n");
6649 uiout
->text ("\tnot ");
6650 uiout
->text ("installed on target\n");
6655 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6657 if (is_watchpoint (b
))
6659 struct watchpoint
*w
= (struct watchpoint
*) b
;
6661 uiout
->field_string ("original-location", w
->exp_string
);
6663 else if (b
->location
!= NULL
6664 && event_location_to_string (b
->location
.get ()) != NULL
)
6665 uiout
->field_string ("original-location",
6666 event_location_to_string (b
->location
.get ()));
6671 print_one_breakpoint (struct breakpoint
*b
,
6672 struct bp_location
**last_loc
,
6675 struct ui_out
*uiout
= current_uiout
;
6678 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6680 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6683 /* If this breakpoint has custom print function,
6684 it's already printed. Otherwise, print individual
6685 locations, if any. */
6686 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6688 /* If breakpoint has a single location that is disabled, we
6689 print it as if it had several locations, since otherwise it's
6690 hard to represent "breakpoint enabled, location disabled"
6693 Note that while hardware watchpoints have several locations
6694 internally, that's not a property exposed to user. */
6696 && !is_hardware_watchpoint (b
)
6697 && (b
->loc
->next
|| !b
->loc
->enabled
))
6699 struct bp_location
*loc
;
6702 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6704 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6705 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6712 breakpoint_address_bits (struct breakpoint
*b
)
6714 int print_address_bits
= 0;
6715 struct bp_location
*loc
;
6717 /* Software watchpoints that aren't watching memory don't have an
6718 address to print. */
6719 if (is_no_memory_software_watchpoint (b
))
6722 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6726 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6727 if (addr_bit
> print_address_bits
)
6728 print_address_bits
= addr_bit
;
6731 return print_address_bits
;
6734 struct captured_breakpoint_query_args
6740 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6742 struct captured_breakpoint_query_args
*args
6743 = (struct captured_breakpoint_query_args
*) data
;
6744 struct breakpoint
*b
;
6745 struct bp_location
*dummy_loc
= NULL
;
6749 if (args
->bnum
== b
->number
)
6751 print_one_breakpoint (b
, &dummy_loc
, 0);
6759 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6760 char **error_message
)
6762 struct captured_breakpoint_query_args args
;
6765 /* For the moment we don't trust print_one_breakpoint() to not throw
6767 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6768 error_message
, RETURN_MASK_ALL
) < 0)
6774 /* Return true if this breakpoint was set by the user, false if it is
6775 internal or momentary. */
6778 user_breakpoint_p (struct breakpoint
*b
)
6780 return b
->number
> 0;
6783 /* See breakpoint.h. */
6786 pending_breakpoint_p (struct breakpoint
*b
)
6788 return b
->loc
== NULL
;
6791 /* Print information on user settable breakpoint (watchpoint, etc)
6792 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6793 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6794 FILTER is non-NULL, call it on each breakpoint and only include the
6795 ones for which it returns non-zero. Return the total number of
6796 breakpoints listed. */
6799 breakpoint_1 (char *args
, int allflag
,
6800 int (*filter
) (const struct breakpoint
*))
6802 struct breakpoint
*b
;
6803 struct bp_location
*last_loc
= NULL
;
6804 int nr_printable_breakpoints
;
6805 struct cleanup
*bkpttbl_chain
;
6806 struct value_print_options opts
;
6807 int print_address_bits
= 0;
6808 int print_type_col_width
= 14;
6809 struct ui_out
*uiout
= current_uiout
;
6811 get_user_print_options (&opts
);
6813 /* Compute the number of rows in the table, as well as the size
6814 required for address fields. */
6815 nr_printable_breakpoints
= 0;
6818 /* If we have a filter, only list the breakpoints it accepts. */
6819 if (filter
&& !filter (b
))
6822 /* If we have an "args" string, it is a list of breakpoints to
6823 accept. Skip the others. */
6824 if (args
!= NULL
&& *args
!= '\0')
6826 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6828 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6832 if (allflag
|| user_breakpoint_p (b
))
6834 int addr_bit
, type_len
;
6836 addr_bit
= breakpoint_address_bits (b
);
6837 if (addr_bit
> print_address_bits
)
6838 print_address_bits
= addr_bit
;
6840 type_len
= strlen (bptype_string (b
->type
));
6841 if (type_len
> print_type_col_width
)
6842 print_type_col_width
= type_len
;
6844 nr_printable_breakpoints
++;
6848 if (opts
.addressprint
)
6850 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6851 nr_printable_breakpoints
,
6855 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6856 nr_printable_breakpoints
,
6859 if (nr_printable_breakpoints
> 0)
6860 annotate_breakpoints_headers ();
6861 if (nr_printable_breakpoints
> 0)
6863 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6864 if (nr_printable_breakpoints
> 0)
6866 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6867 if (nr_printable_breakpoints
> 0)
6869 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6870 if (nr_printable_breakpoints
> 0)
6872 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6873 if (opts
.addressprint
)
6875 if (nr_printable_breakpoints
> 0)
6877 if (print_address_bits
<= 32)
6878 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6880 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6882 if (nr_printable_breakpoints
> 0)
6884 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6885 uiout
->table_body ();
6886 if (nr_printable_breakpoints
> 0)
6887 annotate_breakpoints_table ();
6892 /* If we have a filter, only list the breakpoints it accepts. */
6893 if (filter
&& !filter (b
))
6896 /* If we have an "args" string, it is a list of breakpoints to
6897 accept. Skip the others. */
6899 if (args
!= NULL
&& *args
!= '\0')
6901 if (allflag
) /* maintenance info breakpoint */
6903 if (parse_and_eval_long (args
) != b
->number
)
6906 else /* all others */
6908 if (!number_is_in_list (args
, b
->number
))
6912 /* We only print out user settable breakpoints unless the
6914 if (allflag
|| user_breakpoint_p (b
))
6915 print_one_breakpoint (b
, &last_loc
, allflag
);
6918 do_cleanups (bkpttbl_chain
);
6920 if (nr_printable_breakpoints
== 0)
6922 /* If there's a filter, let the caller decide how to report
6926 if (args
== NULL
|| *args
== '\0')
6927 uiout
->message ("No breakpoints or watchpoints.\n");
6929 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6935 if (last_loc
&& !server_command
)
6936 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6939 /* FIXME? Should this be moved up so that it is only called when
6940 there have been breakpoints? */
6941 annotate_breakpoints_table_end ();
6943 return nr_printable_breakpoints
;
6946 /* Display the value of default-collect in a way that is generally
6947 compatible with the breakpoint list. */
6950 default_collect_info (void)
6952 struct ui_out
*uiout
= current_uiout
;
6954 /* If it has no value (which is frequently the case), say nothing; a
6955 message like "No default-collect." gets in user's face when it's
6957 if (!*default_collect
)
6960 /* The following phrase lines up nicely with per-tracepoint collect
6962 uiout
->text ("default collect ");
6963 uiout
->field_string ("default-collect", default_collect
);
6964 uiout
->text (" \n");
6968 breakpoints_info (char *args
, int from_tty
)
6970 breakpoint_1 (args
, 0, NULL
);
6972 default_collect_info ();
6976 watchpoints_info (char *args
, int from_tty
)
6978 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6979 struct ui_out
*uiout
= current_uiout
;
6981 if (num_printed
== 0)
6983 if (args
== NULL
|| *args
== '\0')
6984 uiout
->message ("No watchpoints.\n");
6986 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6991 maintenance_info_breakpoints (char *args
, int from_tty
)
6993 breakpoint_1 (args
, 1, NULL
);
6995 default_collect_info ();
6999 breakpoint_has_pc (struct breakpoint
*b
,
7000 struct program_space
*pspace
,
7001 CORE_ADDR pc
, struct obj_section
*section
)
7003 struct bp_location
*bl
= b
->loc
;
7005 for (; bl
; bl
= bl
->next
)
7007 if (bl
->pspace
== pspace
7008 && bl
->address
== pc
7009 && (!overlay_debugging
|| bl
->section
== section
))
7015 /* Print a message describing any user-breakpoints set at PC. This
7016 concerns with logical breakpoints, so we match program spaces, not
7020 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7021 struct program_space
*pspace
, CORE_ADDR pc
,
7022 struct obj_section
*section
, int thread
)
7025 struct breakpoint
*b
;
7028 others
+= (user_breakpoint_p (b
)
7029 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7033 printf_filtered (_("Note: breakpoint "));
7034 else /* if (others == ???) */
7035 printf_filtered (_("Note: breakpoints "));
7037 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7040 printf_filtered ("%d", b
->number
);
7041 if (b
->thread
== -1 && thread
!= -1)
7042 printf_filtered (" (all threads)");
7043 else if (b
->thread
!= -1)
7044 printf_filtered (" (thread %d)", b
->thread
);
7045 printf_filtered ("%s%s ",
7046 ((b
->enable_state
== bp_disabled
7047 || b
->enable_state
== bp_call_disabled
)
7051 : ((others
== 1) ? " and" : ""));
7053 printf_filtered (_("also set at pc "));
7054 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7055 printf_filtered (".\n");
7060 /* Return true iff it is meaningful to use the address member of
7061 BPT locations. For some breakpoint types, the locations' address members
7062 are irrelevant and it makes no sense to attempt to compare them to other
7063 addresses (or use them for any other purpose either).
7065 More specifically, each of the following breakpoint types will
7066 always have a zero valued location address and we don't want to mark
7067 breakpoints of any of these types to be a duplicate of an actual
7068 breakpoint location at address zero:
7076 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7078 enum bptype type
= bpt
->type
;
7080 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7083 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7084 true if LOC1 and LOC2 represent the same watchpoint location. */
7087 watchpoint_locations_match (struct bp_location
*loc1
,
7088 struct bp_location
*loc2
)
7090 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7091 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7093 /* Both of them must exist. */
7094 gdb_assert (w1
!= NULL
);
7095 gdb_assert (w2
!= NULL
);
7097 /* If the target can evaluate the condition expression in hardware,
7098 then we we need to insert both watchpoints even if they are at
7099 the same place. Otherwise the watchpoint will only trigger when
7100 the condition of whichever watchpoint was inserted evaluates to
7101 true, not giving a chance for GDB to check the condition of the
7102 other watchpoint. */
7104 && target_can_accel_watchpoint_condition (loc1
->address
,
7106 loc1
->watchpoint_type
,
7107 w1
->cond_exp
.get ()))
7109 && target_can_accel_watchpoint_condition (loc2
->address
,
7111 loc2
->watchpoint_type
,
7112 w2
->cond_exp
.get ())))
7115 /* Note that this checks the owner's type, not the location's. In
7116 case the target does not support read watchpoints, but does
7117 support access watchpoints, we'll have bp_read_watchpoint
7118 watchpoints with hw_access locations. Those should be considered
7119 duplicates of hw_read locations. The hw_read locations will
7120 become hw_access locations later. */
7121 return (loc1
->owner
->type
== loc2
->owner
->type
7122 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7123 && loc1
->address
== loc2
->address
7124 && loc1
->length
== loc2
->length
);
7127 /* See breakpoint.h. */
7130 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7131 struct address_space
*aspace2
, CORE_ADDR addr2
)
7133 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7134 || aspace1
== aspace2
)
7138 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7139 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7140 matches ASPACE2. On targets that have global breakpoints, the address
7141 space doesn't really matter. */
7144 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7145 int len1
, struct address_space
*aspace2
,
7148 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7149 || aspace1
== aspace2
)
7150 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7153 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7154 a ranged breakpoint. In most targets, a match happens only if ASPACE
7155 matches the breakpoint's address space. On targets that have global
7156 breakpoints, the address space doesn't really matter. */
7159 breakpoint_location_address_match (struct bp_location
*bl
,
7160 struct address_space
*aspace
,
7163 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7166 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7167 bl
->address
, bl
->length
,
7171 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7172 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7173 match happens only if ASPACE matches the breakpoint's address
7174 space. On targets that have global breakpoints, the address space
7175 doesn't really matter. */
7178 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7179 struct address_space
*aspace
,
7180 CORE_ADDR addr
, int len
)
7182 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7183 || bl
->pspace
->aspace
== aspace
)
7185 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7187 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7193 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7194 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7195 true, otherwise returns false. */
7198 tracepoint_locations_match (struct bp_location
*loc1
,
7199 struct bp_location
*loc2
)
7201 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7202 /* Since tracepoint locations are never duplicated with others', tracepoint
7203 locations at the same address of different tracepoints are regarded as
7204 different locations. */
7205 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7210 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7211 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7212 represent the same location. */
7215 breakpoint_locations_match (struct bp_location
*loc1
,
7216 struct bp_location
*loc2
)
7218 int hw_point1
, hw_point2
;
7220 /* Both of them must not be in moribund_locations. */
7221 gdb_assert (loc1
->owner
!= NULL
);
7222 gdb_assert (loc2
->owner
!= NULL
);
7224 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7225 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7227 if (hw_point1
!= hw_point2
)
7230 return watchpoint_locations_match (loc1
, loc2
);
7231 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7232 return tracepoint_locations_match (loc1
, loc2
);
7234 /* We compare bp_location.length in order to cover ranged breakpoints. */
7235 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7236 loc2
->pspace
->aspace
, loc2
->address
)
7237 && loc1
->length
== loc2
->length
);
7241 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7242 int bnum
, int have_bnum
)
7244 /* The longest string possibly returned by hex_string_custom
7245 is 50 chars. These must be at least that big for safety. */
7249 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7250 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7252 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7253 bnum
, astr1
, astr2
);
7255 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7258 /* Adjust a breakpoint's address to account for architectural
7259 constraints on breakpoint placement. Return the adjusted address.
7260 Note: Very few targets require this kind of adjustment. For most
7261 targets, this function is simply the identity function. */
7264 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7265 CORE_ADDR bpaddr
, enum bptype bptype
)
7267 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7269 /* Very few targets need any kind of breakpoint adjustment. */
7272 else if (bptype
== bp_watchpoint
7273 || bptype
== bp_hardware_watchpoint
7274 || bptype
== bp_read_watchpoint
7275 || bptype
== bp_access_watchpoint
7276 || bptype
== bp_catchpoint
)
7278 /* Watchpoints and the various bp_catch_* eventpoints should not
7279 have their addresses modified. */
7282 else if (bptype
== bp_single_step
)
7284 /* Single-step breakpoints should not have their addresses
7285 modified. If there's any architectural constrain that
7286 applies to this address, then it should have already been
7287 taken into account when the breakpoint was created in the
7288 first place. If we didn't do this, stepping through e.g.,
7289 Thumb-2 IT blocks would break. */
7294 CORE_ADDR adjusted_bpaddr
;
7296 /* Some targets have architectural constraints on the placement
7297 of breakpoint instructions. Obtain the adjusted address. */
7298 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7300 /* An adjusted breakpoint address can significantly alter
7301 a user's expectations. Print a warning if an adjustment
7303 if (adjusted_bpaddr
!= bpaddr
)
7304 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7306 return adjusted_bpaddr
;
7310 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7312 bp_location
*loc
= this;
7314 gdb_assert (ops
!= NULL
);
7318 loc
->cond_bytecode
= NULL
;
7319 loc
->shlib_disabled
= 0;
7322 switch (owner
->type
)
7325 case bp_single_step
:
7329 case bp_longjmp_resume
:
7330 case bp_longjmp_call_dummy
:
7332 case bp_exception_resume
:
7333 case bp_step_resume
:
7334 case bp_hp_step_resume
:
7335 case bp_watchpoint_scope
:
7337 case bp_std_terminate
:
7338 case bp_shlib_event
:
7339 case bp_thread_event
:
7340 case bp_overlay_event
:
7342 case bp_longjmp_master
:
7343 case bp_std_terminate_master
:
7344 case bp_exception_master
:
7345 case bp_gnu_ifunc_resolver
:
7346 case bp_gnu_ifunc_resolver_return
:
7348 loc
->loc_type
= bp_loc_software_breakpoint
;
7349 mark_breakpoint_location_modified (loc
);
7351 case bp_hardware_breakpoint
:
7352 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7353 mark_breakpoint_location_modified (loc
);
7355 case bp_hardware_watchpoint
:
7356 case bp_read_watchpoint
:
7357 case bp_access_watchpoint
:
7358 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7363 case bp_fast_tracepoint
:
7364 case bp_static_tracepoint
:
7365 loc
->loc_type
= bp_loc_other
;
7368 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7374 /* Allocate a struct bp_location. */
7376 static struct bp_location
*
7377 allocate_bp_location (struct breakpoint
*bpt
)
7379 return bpt
->ops
->allocate_location (bpt
);
7383 free_bp_location (struct bp_location
*loc
)
7385 loc
->ops
->dtor (loc
);
7389 /* Increment reference count. */
7392 incref_bp_location (struct bp_location
*bl
)
7397 /* Decrement reference count. If the reference count reaches 0,
7398 destroy the bp_location. Sets *BLP to NULL. */
7401 decref_bp_location (struct bp_location
**blp
)
7403 gdb_assert ((*blp
)->refc
> 0);
7405 if (--(*blp
)->refc
== 0)
7406 free_bp_location (*blp
);
7410 /* Add breakpoint B at the end of the global breakpoint chain. */
7413 add_to_breakpoint_chain (struct breakpoint
*b
)
7415 struct breakpoint
*b1
;
7417 /* Add this breakpoint to the end of the chain so that a list of
7418 breakpoints will come out in order of increasing numbers. */
7420 b1
= breakpoint_chain
;
7422 breakpoint_chain
= b
;
7431 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7434 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7435 struct gdbarch
*gdbarch
,
7437 const struct breakpoint_ops
*ops
)
7439 gdb_assert (ops
!= NULL
);
7443 b
->gdbarch
= gdbarch
;
7444 b
->language
= current_language
->la_language
;
7445 b
->input_radix
= input_radix
;
7446 b
->related_breakpoint
= b
;
7449 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7450 that has type BPTYPE and has no locations as yet. */
7452 static struct breakpoint
*
7453 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7455 const struct breakpoint_ops
*ops
)
7457 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7459 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7460 add_to_breakpoint_chain (b
.get ());
7462 return b
.release ();
7465 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7466 resolutions should be made as the user specified the location explicitly
7470 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7472 gdb_assert (loc
->owner
!= NULL
);
7474 if (loc
->owner
->type
== bp_breakpoint
7475 || loc
->owner
->type
== bp_hardware_breakpoint
7476 || is_tracepoint (loc
->owner
))
7479 const char *function_name
;
7480 CORE_ADDR func_addr
;
7482 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7483 &func_addr
, NULL
, &is_gnu_ifunc
);
7485 if (is_gnu_ifunc
&& !explicit_loc
)
7487 struct breakpoint
*b
= loc
->owner
;
7489 gdb_assert (loc
->pspace
== current_program_space
);
7490 if (gnu_ifunc_resolve_name (function_name
,
7491 &loc
->requested_address
))
7493 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7494 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7495 loc
->requested_address
,
7498 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7499 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7501 /* Create only the whole new breakpoint of this type but do not
7502 mess more complicated breakpoints with multiple locations. */
7503 b
->type
= bp_gnu_ifunc_resolver
;
7504 /* Remember the resolver's address for use by the return
7506 loc
->related_address
= func_addr
;
7511 loc
->function_name
= xstrdup (function_name
);
7515 /* Attempt to determine architecture of location identified by SAL. */
7517 get_sal_arch (struct symtab_and_line sal
)
7520 return get_objfile_arch (sal
.section
->objfile
);
7522 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7527 /* Low level routine for partially initializing a breakpoint of type
7528 BPTYPE. The newly created breakpoint's address, section, source
7529 file name, and line number are provided by SAL.
7531 It is expected that the caller will complete the initialization of
7532 the newly created breakpoint struct as well as output any status
7533 information regarding the creation of a new breakpoint. */
7536 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7537 struct symtab_and_line sal
, enum bptype bptype
,
7538 const struct breakpoint_ops
*ops
)
7540 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7542 add_location_to_breakpoint (b
, &sal
);
7544 if (bptype
!= bp_catchpoint
)
7545 gdb_assert (sal
.pspace
!= NULL
);
7547 /* Store the program space that was used to set the breakpoint,
7548 except for ordinary breakpoints, which are independent of the
7550 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7551 b
->pspace
= sal
.pspace
;
7554 /* set_raw_breakpoint is a low level routine for allocating and
7555 partially initializing a breakpoint of type BPTYPE. The newly
7556 created breakpoint's address, section, source file name, and line
7557 number are provided by SAL. The newly created and partially
7558 initialized breakpoint is added to the breakpoint chain and
7559 is also returned as the value of this function.
7561 It is expected that the caller will complete the initialization of
7562 the newly created breakpoint struct as well as output any status
7563 information regarding the creation of a new breakpoint. In
7564 particular, set_raw_breakpoint does NOT set the breakpoint
7565 number! Care should be taken to not allow an error to occur
7566 prior to completing the initialization of the breakpoint. If this
7567 should happen, a bogus breakpoint will be left on the chain. */
7570 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7571 struct symtab_and_line sal
, enum bptype bptype
,
7572 const struct breakpoint_ops
*ops
)
7574 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7576 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7577 add_to_breakpoint_chain (b
.get ());
7579 return b
.release ();
7582 /* Call this routine when stepping and nexting to enable a breakpoint
7583 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7584 initiated the operation. */
7587 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7589 struct breakpoint
*b
, *b_tmp
;
7590 int thread
= tp
->global_num
;
7592 /* To avoid having to rescan all objfile symbols at every step,
7593 we maintain a list of continually-inserted but always disabled
7594 longjmp "master" breakpoints. Here, we simply create momentary
7595 clones of those and enable them for the requested thread. */
7596 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7597 if (b
->pspace
== current_program_space
7598 && (b
->type
== bp_longjmp_master
7599 || b
->type
== bp_exception_master
))
7601 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7602 struct breakpoint
*clone
;
7604 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7605 after their removal. */
7606 clone
= momentary_breakpoint_from_master (b
, type
,
7607 &momentary_breakpoint_ops
, 1);
7608 clone
->thread
= thread
;
7611 tp
->initiating_frame
= frame
;
7614 /* Delete all longjmp breakpoints from THREAD. */
7616 delete_longjmp_breakpoint (int thread
)
7618 struct breakpoint
*b
, *b_tmp
;
7620 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7621 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7623 if (b
->thread
== thread
)
7624 delete_breakpoint (b
);
7629 delete_longjmp_breakpoint_at_next_stop (int thread
)
7631 struct breakpoint
*b
, *b_tmp
;
7633 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7634 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7636 if (b
->thread
== thread
)
7637 b
->disposition
= disp_del_at_next_stop
;
7641 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7642 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7643 pointer to any of them. Return NULL if this system cannot place longjmp
7647 set_longjmp_breakpoint_for_call_dummy (void)
7649 struct breakpoint
*b
, *retval
= NULL
;
7652 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7654 struct breakpoint
*new_b
;
7656 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7657 &momentary_breakpoint_ops
,
7659 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7661 /* Link NEW_B into the chain of RETVAL breakpoints. */
7663 gdb_assert (new_b
->related_breakpoint
== new_b
);
7666 new_b
->related_breakpoint
= retval
;
7667 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7668 retval
= retval
->related_breakpoint
;
7669 retval
->related_breakpoint
= new_b
;
7675 /* Verify all existing dummy frames and their associated breakpoints for
7676 TP. Remove those which can no longer be found in the current frame
7679 You should call this function only at places where it is safe to currently
7680 unwind the whole stack. Failed stack unwind would discard live dummy
7684 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7686 struct breakpoint
*b
, *b_tmp
;
7688 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7689 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7691 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7693 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7694 dummy_b
= dummy_b
->related_breakpoint
;
7695 if (dummy_b
->type
!= bp_call_dummy
7696 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7699 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7701 while (b
->related_breakpoint
!= b
)
7703 if (b_tmp
== b
->related_breakpoint
)
7704 b_tmp
= b
->related_breakpoint
->next
;
7705 delete_breakpoint (b
->related_breakpoint
);
7707 delete_breakpoint (b
);
7712 enable_overlay_breakpoints (void)
7714 struct breakpoint
*b
;
7717 if (b
->type
== bp_overlay_event
)
7719 b
->enable_state
= bp_enabled
;
7720 update_global_location_list (UGLL_MAY_INSERT
);
7721 overlay_events_enabled
= 1;
7726 disable_overlay_breakpoints (void)
7728 struct breakpoint
*b
;
7731 if (b
->type
== bp_overlay_event
)
7733 b
->enable_state
= bp_disabled
;
7734 update_global_location_list (UGLL_DONT_INSERT
);
7735 overlay_events_enabled
= 0;
7739 /* Set an active std::terminate breakpoint for each std::terminate
7740 master breakpoint. */
7742 set_std_terminate_breakpoint (void)
7744 struct breakpoint
*b
, *b_tmp
;
7746 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7747 if (b
->pspace
== current_program_space
7748 && b
->type
== bp_std_terminate_master
)
7750 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7751 &momentary_breakpoint_ops
, 1);
7755 /* Delete all the std::terminate breakpoints. */
7757 delete_std_terminate_breakpoint (void)
7759 struct breakpoint
*b
, *b_tmp
;
7761 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7762 if (b
->type
== bp_std_terminate
)
7763 delete_breakpoint (b
);
7767 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7769 struct breakpoint
*b
;
7771 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7772 &internal_breakpoint_ops
);
7774 b
->enable_state
= bp_enabled
;
7775 /* location has to be used or breakpoint_re_set will delete me. */
7776 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7778 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7783 struct lang_and_radix
7789 /* Create a breakpoint for JIT code registration and unregistration. */
7792 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7794 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7795 &internal_breakpoint_ops
);
7798 /* Remove JIT code registration and unregistration breakpoint(s). */
7801 remove_jit_event_breakpoints (void)
7803 struct breakpoint
*b
, *b_tmp
;
7805 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7806 if (b
->type
== bp_jit_event
7807 && b
->loc
->pspace
== current_program_space
)
7808 delete_breakpoint (b
);
7812 remove_solib_event_breakpoints (void)
7814 struct breakpoint
*b
, *b_tmp
;
7816 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7817 if (b
->type
== bp_shlib_event
7818 && b
->loc
->pspace
== current_program_space
)
7819 delete_breakpoint (b
);
7822 /* See breakpoint.h. */
7825 remove_solib_event_breakpoints_at_next_stop (void)
7827 struct breakpoint
*b
, *b_tmp
;
7829 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7830 if (b
->type
== bp_shlib_event
7831 && b
->loc
->pspace
== current_program_space
)
7832 b
->disposition
= disp_del_at_next_stop
;
7835 /* Helper for create_solib_event_breakpoint /
7836 create_and_insert_solib_event_breakpoint. Allows specifying which
7837 INSERT_MODE to pass through to update_global_location_list. */
7839 static struct breakpoint
*
7840 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7841 enum ugll_insert_mode insert_mode
)
7843 struct breakpoint
*b
;
7845 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7846 &internal_breakpoint_ops
);
7847 update_global_location_list_nothrow (insert_mode
);
7852 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7854 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7857 /* See breakpoint.h. */
7860 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7862 struct breakpoint
*b
;
7864 /* Explicitly tell update_global_location_list to insert
7866 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7867 if (!b
->loc
->inserted
)
7869 delete_breakpoint (b
);
7875 /* Disable any breakpoints that are on code in shared libraries. Only
7876 apply to enabled breakpoints, disabled ones can just stay disabled. */
7879 disable_breakpoints_in_shlibs (void)
7881 struct bp_location
*loc
, **locp_tmp
;
7883 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7885 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7886 struct breakpoint
*b
= loc
->owner
;
7888 /* We apply the check to all breakpoints, including disabled for
7889 those with loc->duplicate set. This is so that when breakpoint
7890 becomes enabled, or the duplicate is removed, gdb will try to
7891 insert all breakpoints. If we don't set shlib_disabled here,
7892 we'll try to insert those breakpoints and fail. */
7893 if (((b
->type
== bp_breakpoint
)
7894 || (b
->type
== bp_jit_event
)
7895 || (b
->type
== bp_hardware_breakpoint
)
7896 || (is_tracepoint (b
)))
7897 && loc
->pspace
== current_program_space
7898 && !loc
->shlib_disabled
7899 && solib_name_from_address (loc
->pspace
, loc
->address
)
7902 loc
->shlib_disabled
= 1;
7907 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7908 notification of unloaded_shlib. Only apply to enabled breakpoints,
7909 disabled ones can just stay disabled. */
7912 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7914 struct bp_location
*loc
, **locp_tmp
;
7915 int disabled_shlib_breaks
= 0;
7917 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7919 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7920 struct breakpoint
*b
= loc
->owner
;
7922 if (solib
->pspace
== loc
->pspace
7923 && !loc
->shlib_disabled
7924 && (((b
->type
== bp_breakpoint
7925 || b
->type
== bp_jit_event
7926 || b
->type
== bp_hardware_breakpoint
)
7927 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7928 || loc
->loc_type
== bp_loc_software_breakpoint
))
7929 || is_tracepoint (b
))
7930 && solib_contains_address_p (solib
, loc
->address
))
7932 loc
->shlib_disabled
= 1;
7933 /* At this point, we cannot rely on remove_breakpoint
7934 succeeding so we must mark the breakpoint as not inserted
7935 to prevent future errors occurring in remove_breakpoints. */
7938 /* This may cause duplicate notifications for the same breakpoint. */
7939 observer_notify_breakpoint_modified (b
);
7941 if (!disabled_shlib_breaks
)
7943 target_terminal_ours_for_output ();
7944 warning (_("Temporarily disabling breakpoints "
7945 "for unloaded shared library \"%s\""),
7948 disabled_shlib_breaks
= 1;
7953 /* Disable any breakpoints and tracepoints in OBJFILE upon
7954 notification of free_objfile. Only apply to enabled breakpoints,
7955 disabled ones can just stay disabled. */
7958 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7960 struct breakpoint
*b
;
7962 if (objfile
== NULL
)
7965 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7966 managed by the user with add-symbol-file/remove-symbol-file.
7967 Similarly to how breakpoints in shared libraries are handled in
7968 response to "nosharedlibrary", mark breakpoints in such modules
7969 shlib_disabled so they end up uninserted on the next global
7970 location list update. Shared libraries not loaded by the user
7971 aren't handled here -- they're already handled in
7972 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7973 solib_unloaded observer. We skip objfiles that are not
7974 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7976 if ((objfile
->flags
& OBJF_SHARED
) == 0
7977 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7982 struct bp_location
*loc
;
7983 int bp_modified
= 0;
7985 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7988 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7990 CORE_ADDR loc_addr
= loc
->address
;
7992 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7993 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7996 if (loc
->shlib_disabled
!= 0)
7999 if (objfile
->pspace
!= loc
->pspace
)
8002 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8003 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8006 if (is_addr_in_objfile (loc_addr
, objfile
))
8008 loc
->shlib_disabled
= 1;
8009 /* At this point, we don't know whether the object was
8010 unmapped from the inferior or not, so leave the
8011 inserted flag alone. We'll handle failure to
8012 uninsert quietly, in case the object was indeed
8015 mark_breakpoint_location_modified (loc
);
8022 observer_notify_breakpoint_modified (b
);
8026 /* FORK & VFORK catchpoints. */
8028 /* An instance of this type is used to represent a fork or vfork
8029 catchpoint. A breakpoint is really of this type iff its ops pointer points
8030 to CATCH_FORK_BREAKPOINT_OPS. */
8032 struct fork_catchpoint
: public breakpoint
8034 /* Process id of a child process whose forking triggered this
8035 catchpoint. This field is only valid immediately after this
8036 catchpoint has triggered. */
8037 ptid_t forked_inferior_pid
;
8040 /* Implement the "insert" breakpoint_ops method for fork
8044 insert_catch_fork (struct bp_location
*bl
)
8046 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8049 /* Implement the "remove" breakpoint_ops method for fork
8053 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8055 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8058 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8062 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8063 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8064 const struct target_waitstatus
*ws
)
8066 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8068 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8071 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8075 /* Implement the "print_it" breakpoint_ops method for fork
8078 static enum print_stop_action
8079 print_it_catch_fork (bpstat bs
)
8081 struct ui_out
*uiout
= current_uiout
;
8082 struct breakpoint
*b
= bs
->breakpoint_at
;
8083 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8085 annotate_catchpoint (b
->number
);
8086 maybe_print_thread_hit_breakpoint (uiout
);
8087 if (b
->disposition
== disp_del
)
8088 uiout
->text ("Temporary catchpoint ");
8090 uiout
->text ("Catchpoint ");
8091 if (uiout
->is_mi_like_p ())
8093 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
8094 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8096 uiout
->field_int ("bkptno", b
->number
);
8097 uiout
->text (" (forked process ");
8098 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8099 uiout
->text ("), ");
8100 return PRINT_SRC_AND_LOC
;
8103 /* Implement the "print_one" breakpoint_ops method for fork
8107 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8109 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8110 struct value_print_options opts
;
8111 struct ui_out
*uiout
= current_uiout
;
8113 get_user_print_options (&opts
);
8115 /* Field 4, the address, is omitted (which makes the columns not
8116 line up too nicely with the headers, but the effect is relatively
8118 if (opts
.addressprint
)
8119 uiout
->field_skip ("addr");
8121 uiout
->text ("fork");
8122 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8124 uiout
->text (", process ");
8125 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8129 if (uiout
->is_mi_like_p ())
8130 uiout
->field_string ("catch-type", "fork");
8133 /* Implement the "print_mention" breakpoint_ops method for fork
8137 print_mention_catch_fork (struct breakpoint
*b
)
8139 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8142 /* Implement the "print_recreate" breakpoint_ops method for fork
8146 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8148 fprintf_unfiltered (fp
, "catch fork");
8149 print_recreate_thread (b
, fp
);
8152 /* The breakpoint_ops structure to be used in fork catchpoints. */
8154 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8156 /* Implement the "insert" breakpoint_ops method for vfork
8160 insert_catch_vfork (struct bp_location
*bl
)
8162 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8165 /* Implement the "remove" breakpoint_ops method for vfork
8169 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8171 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8174 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8178 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8179 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8180 const struct target_waitstatus
*ws
)
8182 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8184 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8187 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8191 /* Implement the "print_it" breakpoint_ops method for vfork
8194 static enum print_stop_action
8195 print_it_catch_vfork (bpstat bs
)
8197 struct ui_out
*uiout
= current_uiout
;
8198 struct breakpoint
*b
= bs
->breakpoint_at
;
8199 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8201 annotate_catchpoint (b
->number
);
8202 maybe_print_thread_hit_breakpoint (uiout
);
8203 if (b
->disposition
== disp_del
)
8204 uiout
->text ("Temporary catchpoint ");
8206 uiout
->text ("Catchpoint ");
8207 if (uiout
->is_mi_like_p ())
8209 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8210 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8212 uiout
->field_int ("bkptno", b
->number
);
8213 uiout
->text (" (vforked process ");
8214 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8215 uiout
->text ("), ");
8216 return PRINT_SRC_AND_LOC
;
8219 /* Implement the "print_one" breakpoint_ops method for vfork
8223 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8225 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8226 struct value_print_options opts
;
8227 struct ui_out
*uiout
= current_uiout
;
8229 get_user_print_options (&opts
);
8230 /* Field 4, the address, is omitted (which makes the columns not
8231 line up too nicely with the headers, but the effect is relatively
8233 if (opts
.addressprint
)
8234 uiout
->field_skip ("addr");
8236 uiout
->text ("vfork");
8237 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8239 uiout
->text (", process ");
8240 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8244 if (uiout
->is_mi_like_p ())
8245 uiout
->field_string ("catch-type", "vfork");
8248 /* Implement the "print_mention" breakpoint_ops method for vfork
8252 print_mention_catch_vfork (struct breakpoint
*b
)
8254 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8257 /* Implement the "print_recreate" breakpoint_ops method for vfork
8261 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8263 fprintf_unfiltered (fp
, "catch vfork");
8264 print_recreate_thread (b
, fp
);
8267 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8269 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8271 /* An instance of this type is used to represent an solib catchpoint.
8272 A breakpoint is really of this type iff its ops pointer points to
8273 CATCH_SOLIB_BREAKPOINT_OPS. */
8275 struct solib_catchpoint
: public breakpoint
8277 ~solib_catchpoint () override
;
8279 /* True for "catch load", false for "catch unload". */
8280 unsigned char is_load
;
8282 /* Regular expression to match, if any. COMPILED is only valid when
8283 REGEX is non-NULL. */
8288 solib_catchpoint::~solib_catchpoint ()
8291 regfree (&this->compiled
);
8292 xfree (this->regex
);
8296 insert_catch_solib (struct bp_location
*ignore
)
8302 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8308 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8309 struct address_space
*aspace
,
8311 const struct target_waitstatus
*ws
)
8313 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8314 struct breakpoint
*other
;
8316 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8319 ALL_BREAKPOINTS (other
)
8321 struct bp_location
*other_bl
;
8323 if (other
== bl
->owner
)
8326 if (other
->type
!= bp_shlib_event
)
8329 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8332 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8334 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8343 check_status_catch_solib (struct bpstats
*bs
)
8345 struct solib_catchpoint
*self
8346 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8351 struct so_list
*iter
;
8354 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8359 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8368 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8373 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8379 bs
->print_it
= print_it_noop
;
8382 static enum print_stop_action
8383 print_it_catch_solib (bpstat bs
)
8385 struct breakpoint
*b
= bs
->breakpoint_at
;
8386 struct ui_out
*uiout
= current_uiout
;
8388 annotate_catchpoint (b
->number
);
8389 maybe_print_thread_hit_breakpoint (uiout
);
8390 if (b
->disposition
== disp_del
)
8391 uiout
->text ("Temporary catchpoint ");
8393 uiout
->text ("Catchpoint ");
8394 uiout
->field_int ("bkptno", b
->number
);
8396 if (uiout
->is_mi_like_p ())
8397 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8398 print_solib_event (1);
8399 return PRINT_SRC_AND_LOC
;
8403 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8405 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8406 struct value_print_options opts
;
8407 struct ui_out
*uiout
= current_uiout
;
8410 get_user_print_options (&opts
);
8411 /* Field 4, the address, is omitted (which makes the columns not
8412 line up too nicely with the headers, but the effect is relatively
8414 if (opts
.addressprint
)
8417 uiout
->field_skip ("addr");
8424 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8426 msg
= xstrdup (_("load of library"));
8431 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8433 msg
= xstrdup (_("unload of library"));
8435 uiout
->field_string ("what", msg
);
8438 if (uiout
->is_mi_like_p ())
8439 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8443 print_mention_catch_solib (struct breakpoint
*b
)
8445 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8447 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8448 self
->is_load
? "load" : "unload");
8452 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8454 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8456 fprintf_unfiltered (fp
, "%s %s",
8457 b
->disposition
== disp_del
? "tcatch" : "catch",
8458 self
->is_load
? "load" : "unload");
8460 fprintf_unfiltered (fp
, " %s", self
->regex
);
8461 fprintf_unfiltered (fp
, "\n");
8464 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8466 /* Shared helper function (MI and CLI) for creating and installing
8467 a shared object event catchpoint. If IS_LOAD is non-zero then
8468 the events to be caught are load events, otherwise they are
8469 unload events. If IS_TEMP is non-zero the catchpoint is a
8470 temporary one. If ENABLED is non-zero the catchpoint is
8471 created in an enabled state. */
8474 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8476 struct solib_catchpoint
*c
;
8477 struct gdbarch
*gdbarch
= get_current_arch ();
8478 struct cleanup
*cleanup
;
8482 arg
= skip_spaces_const (arg
);
8484 c
= new solib_catchpoint ();
8485 cleanup
= make_cleanup (xfree
, c
);
8491 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8494 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8496 make_cleanup (xfree
, err
);
8497 error (_("Invalid regexp (%s): %s"), err
, arg
);
8499 c
->regex
= xstrdup (arg
);
8502 c
->is_load
= is_load
;
8503 init_catchpoint (c
, gdbarch
, is_temp
, NULL
,
8504 &catch_solib_breakpoint_ops
);
8506 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8508 discard_cleanups (cleanup
);
8509 install_breakpoint (0, c
, 1);
8512 /* A helper function that does all the work for "catch load" and
8516 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8517 struct cmd_list_element
*command
)
8520 const int enabled
= 1;
8522 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8524 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8528 catch_load_command_1 (char *arg
, int from_tty
,
8529 struct cmd_list_element
*command
)
8531 catch_load_or_unload (arg
, from_tty
, 1, command
);
8535 catch_unload_command_1 (char *arg
, int from_tty
,
8536 struct cmd_list_element
*command
)
8538 catch_load_or_unload (arg
, from_tty
, 0, command
);
8541 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8542 is non-zero, then make the breakpoint temporary. If COND_STRING is
8543 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8544 the breakpoint_ops structure associated to the catchpoint. */
8547 init_catchpoint (struct breakpoint
*b
,
8548 struct gdbarch
*gdbarch
, int tempflag
,
8549 const char *cond_string
,
8550 const struct breakpoint_ops
*ops
)
8552 struct symtab_and_line sal
;
8555 sal
.pspace
= current_program_space
;
8557 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8559 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8560 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8564 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8566 add_to_breakpoint_chain (b
);
8567 set_breakpoint_number (internal
, b
);
8568 if (is_tracepoint (b
))
8569 set_tracepoint_count (breakpoint_count
);
8572 observer_notify_breakpoint_created (b
);
8575 update_global_location_list (UGLL_MAY_INSERT
);
8579 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8580 int tempflag
, const char *cond_string
,
8581 const struct breakpoint_ops
*ops
)
8583 struct fork_catchpoint
*c
= new fork_catchpoint ();
8585 init_catchpoint (c
, gdbarch
, tempflag
, cond_string
, ops
);
8587 c
->forked_inferior_pid
= null_ptid
;
8589 install_breakpoint (0, c
, 1);
8592 /* Exec catchpoints. */
8594 /* An instance of this type is used to represent an exec catchpoint.
8595 A breakpoint is really of this type iff its ops pointer points to
8596 CATCH_EXEC_BREAKPOINT_OPS. */
8598 struct exec_catchpoint
: public breakpoint
8600 ~exec_catchpoint () override
;
8602 /* Filename of a program whose exec triggered this catchpoint.
8603 This field is only valid immediately after this catchpoint has
8605 char *exec_pathname
;
8608 /* Exec catchpoint destructor. */
8610 exec_catchpoint::~exec_catchpoint ()
8612 xfree (this->exec_pathname
);
8616 insert_catch_exec (struct bp_location
*bl
)
8618 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8622 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8624 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8628 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8629 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8630 const struct target_waitstatus
*ws
)
8632 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8634 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8637 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8641 static enum print_stop_action
8642 print_it_catch_exec (bpstat bs
)
8644 struct ui_out
*uiout
= current_uiout
;
8645 struct breakpoint
*b
= bs
->breakpoint_at
;
8646 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8648 annotate_catchpoint (b
->number
);
8649 maybe_print_thread_hit_breakpoint (uiout
);
8650 if (b
->disposition
== disp_del
)
8651 uiout
->text ("Temporary catchpoint ");
8653 uiout
->text ("Catchpoint ");
8654 if (uiout
->is_mi_like_p ())
8656 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8657 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8659 uiout
->field_int ("bkptno", b
->number
);
8660 uiout
->text (" (exec'd ");
8661 uiout
->field_string ("new-exec", c
->exec_pathname
);
8662 uiout
->text ("), ");
8664 return PRINT_SRC_AND_LOC
;
8668 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8670 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8671 struct value_print_options opts
;
8672 struct ui_out
*uiout
= current_uiout
;
8674 get_user_print_options (&opts
);
8676 /* Field 4, the address, is omitted (which makes the columns
8677 not line up too nicely with the headers, but the effect
8678 is relatively readable). */
8679 if (opts
.addressprint
)
8680 uiout
->field_skip ("addr");
8682 uiout
->text ("exec");
8683 if (c
->exec_pathname
!= NULL
)
8685 uiout
->text (", program \"");
8686 uiout
->field_string ("what", c
->exec_pathname
);
8687 uiout
->text ("\" ");
8690 if (uiout
->is_mi_like_p ())
8691 uiout
->field_string ("catch-type", "exec");
8695 print_mention_catch_exec (struct breakpoint
*b
)
8697 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8700 /* Implement the "print_recreate" breakpoint_ops method for exec
8704 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8706 fprintf_unfiltered (fp
, "catch exec");
8707 print_recreate_thread (b
, fp
);
8710 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8713 hw_breakpoint_used_count (void)
8716 struct breakpoint
*b
;
8717 struct bp_location
*bl
;
8721 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8722 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8724 /* Special types of hardware breakpoints may use more than
8726 i
+= b
->ops
->resources_needed (bl
);
8733 /* Returns the resources B would use if it were a hardware
8737 hw_watchpoint_use_count (struct breakpoint
*b
)
8740 struct bp_location
*bl
;
8742 if (!breakpoint_enabled (b
))
8745 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8747 /* Special types of hardware watchpoints may use more than
8749 i
+= b
->ops
->resources_needed (bl
);
8755 /* Returns the sum the used resources of all hardware watchpoints of
8756 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8757 the sum of the used resources of all hardware watchpoints of other
8758 types _not_ TYPE. */
8761 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8762 enum bptype type
, int *other_type_used
)
8765 struct breakpoint
*b
;
8767 *other_type_used
= 0;
8772 if (!breakpoint_enabled (b
))
8775 if (b
->type
== type
)
8776 i
+= hw_watchpoint_use_count (b
);
8777 else if (is_hardware_watchpoint (b
))
8778 *other_type_used
= 1;
8785 disable_watchpoints_before_interactive_call_start (void)
8787 struct breakpoint
*b
;
8791 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8793 b
->enable_state
= bp_call_disabled
;
8794 update_global_location_list (UGLL_DONT_INSERT
);
8800 enable_watchpoints_after_interactive_call_stop (void)
8802 struct breakpoint
*b
;
8806 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8808 b
->enable_state
= bp_enabled
;
8809 update_global_location_list (UGLL_MAY_INSERT
);
8815 disable_breakpoints_before_startup (void)
8817 current_program_space
->executing_startup
= 1;
8818 update_global_location_list (UGLL_DONT_INSERT
);
8822 enable_breakpoints_after_startup (void)
8824 current_program_space
->executing_startup
= 0;
8825 breakpoint_re_set ();
8828 /* Create a new single-step breakpoint for thread THREAD, with no
8831 static struct breakpoint
*
8832 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8834 struct breakpoint
*b
= new breakpoint ();
8836 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8837 &momentary_breakpoint_ops
);
8839 b
->disposition
= disp_donttouch
;
8840 b
->frame_id
= null_frame_id
;
8843 gdb_assert (b
->thread
!= 0);
8845 add_to_breakpoint_chain (b
);
8850 /* Set a momentary breakpoint of type TYPE at address specified by
8851 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8855 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8856 struct frame_id frame_id
, enum bptype type
)
8858 struct breakpoint
*b
;
8860 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8862 gdb_assert (!frame_id_artificial_p (frame_id
));
8864 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8865 b
->enable_state
= bp_enabled
;
8866 b
->disposition
= disp_donttouch
;
8867 b
->frame_id
= frame_id
;
8869 /* If we're debugging a multi-threaded program, then we want
8870 momentary breakpoints to be active in only a single thread of
8872 if (in_thread_list (inferior_ptid
))
8873 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8875 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8880 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8881 The new breakpoint will have type TYPE, use OPS as its
8882 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8884 static struct breakpoint
*
8885 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8887 const struct breakpoint_ops
*ops
,
8890 struct breakpoint
*copy
;
8892 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8893 copy
->loc
= allocate_bp_location (copy
);
8894 set_breakpoint_location_function (copy
->loc
, 1);
8896 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8897 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8898 copy
->loc
->address
= orig
->loc
->address
;
8899 copy
->loc
->section
= orig
->loc
->section
;
8900 copy
->loc
->pspace
= orig
->loc
->pspace
;
8901 copy
->loc
->probe
= orig
->loc
->probe
;
8902 copy
->loc
->line_number
= orig
->loc
->line_number
;
8903 copy
->loc
->symtab
= orig
->loc
->symtab
;
8904 copy
->loc
->enabled
= loc_enabled
;
8905 copy
->frame_id
= orig
->frame_id
;
8906 copy
->thread
= orig
->thread
;
8907 copy
->pspace
= orig
->pspace
;
8909 copy
->enable_state
= bp_enabled
;
8910 copy
->disposition
= disp_donttouch
;
8911 copy
->number
= internal_breakpoint_number
--;
8913 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8917 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8921 clone_momentary_breakpoint (struct breakpoint
*orig
)
8923 /* If there's nothing to clone, then return nothing. */
8927 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8931 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8934 struct symtab_and_line sal
;
8936 sal
= find_pc_line (pc
, 0);
8938 sal
.section
= find_pc_overlay (pc
);
8939 sal
.explicit_pc
= 1;
8941 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8945 /* Tell the user we have just set a breakpoint B. */
8948 mention (struct breakpoint
*b
)
8950 b
->ops
->print_mention (b
);
8951 if (current_uiout
->is_mi_like_p ())
8953 printf_filtered ("\n");
8957 static int bp_loc_is_permanent (struct bp_location
*loc
);
8959 static struct bp_location
*
8960 add_location_to_breakpoint (struct breakpoint
*b
,
8961 const struct symtab_and_line
*sal
)
8963 struct bp_location
*loc
, **tmp
;
8964 CORE_ADDR adjusted_address
;
8965 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8967 if (loc_gdbarch
== NULL
)
8968 loc_gdbarch
= b
->gdbarch
;
8970 /* Adjust the breakpoint's address prior to allocating a location.
8971 Once we call allocate_bp_location(), that mostly uninitialized
8972 location will be placed on the location chain. Adjustment of the
8973 breakpoint may cause target_read_memory() to be called and we do
8974 not want its scan of the location chain to find a breakpoint and
8975 location that's only been partially initialized. */
8976 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8979 /* Sort the locations by their ADDRESS. */
8980 loc
= allocate_bp_location (b
);
8981 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8982 tmp
= &((*tmp
)->next
))
8987 loc
->requested_address
= sal
->pc
;
8988 loc
->address
= adjusted_address
;
8989 loc
->pspace
= sal
->pspace
;
8990 loc
->probe
.probe
= sal
->probe
;
8991 loc
->probe
.objfile
= sal
->objfile
;
8992 gdb_assert (loc
->pspace
!= NULL
);
8993 loc
->section
= sal
->section
;
8994 loc
->gdbarch
= loc_gdbarch
;
8995 loc
->line_number
= sal
->line
;
8996 loc
->symtab
= sal
->symtab
;
8998 set_breakpoint_location_function (loc
,
8999 sal
->explicit_pc
|| sal
->explicit_line
);
9001 /* While by definition, permanent breakpoints are already present in the
9002 code, we don't mark the location as inserted. Normally one would expect
9003 that GDB could rely on that breakpoint instruction to stop the program,
9004 thus removing the need to insert its own breakpoint, except that executing
9005 the breakpoint instruction can kill the target instead of reporting a
9006 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9007 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9008 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9009 breakpoint be inserted normally results in QEMU knowing about the GDB
9010 breakpoint, and thus trap before the breakpoint instruction is executed.
9011 (If GDB later needs to continue execution past the permanent breakpoint,
9012 it manually increments the PC, thus avoiding executing the breakpoint
9014 if (bp_loc_is_permanent (loc
))
9021 /* See breakpoint.h. */
9024 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9028 const gdb_byte
*bpoint
;
9029 gdb_byte
*target_mem
;
9030 struct cleanup
*cleanup
;
9034 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9036 /* Software breakpoints unsupported? */
9040 target_mem
= (gdb_byte
*) alloca (len
);
9042 /* Enable the automatic memory restoration from breakpoints while
9043 we read the memory. Otherwise we could say about our temporary
9044 breakpoints they are permanent. */
9045 cleanup
= make_show_memory_breakpoints_cleanup (0);
9047 if (target_read_memory (address
, target_mem
, len
) == 0
9048 && memcmp (target_mem
, bpoint
, len
) == 0)
9051 do_cleanups (cleanup
);
9056 /* Return 1 if LOC is pointing to a permanent breakpoint,
9057 return 0 otherwise. */
9060 bp_loc_is_permanent (struct bp_location
*loc
)
9062 gdb_assert (loc
!= NULL
);
9064 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9065 attempt to read from the addresses the locations of these breakpoint types
9066 point to. program_breakpoint_here_p, below, will attempt to read
9068 if (!breakpoint_address_is_meaningful (loc
->owner
))
9071 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9072 switch_to_program_space_and_thread (loc
->pspace
);
9073 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9076 /* Build a command list for the dprintf corresponding to the current
9077 settings of the dprintf style options. */
9080 update_dprintf_command_list (struct breakpoint
*b
)
9082 char *dprintf_args
= b
->extra_string
;
9083 char *printf_line
= NULL
;
9088 dprintf_args
= skip_spaces (dprintf_args
);
9090 /* Allow a comma, as it may have terminated a location, but don't
9092 if (*dprintf_args
== ',')
9094 dprintf_args
= skip_spaces (dprintf_args
);
9096 if (*dprintf_args
!= '"')
9097 error (_("Bad format string, missing '\"'."));
9099 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9100 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9101 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9103 if (!dprintf_function
)
9104 error (_("No function supplied for dprintf call"));
9106 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9107 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9112 printf_line
= xstrprintf ("call (void) %s (%s)",
9116 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9118 if (target_can_run_breakpoint_commands ())
9119 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9122 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9123 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9127 internal_error (__FILE__
, __LINE__
,
9128 _("Invalid dprintf style."));
9130 gdb_assert (printf_line
!= NULL
);
9131 /* Manufacture a printf sequence. */
9133 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9135 printf_cmd_line
->control_type
= simple_control
;
9136 printf_cmd_line
->body_count
= 0;
9137 printf_cmd_line
->body_list
= NULL
;
9138 printf_cmd_line
->next
= NULL
;
9139 printf_cmd_line
->line
= printf_line
;
9141 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9145 /* Update all dprintf commands, making their command lists reflect
9146 current style settings. */
9149 update_dprintf_commands (char *args
, int from_tty
,
9150 struct cmd_list_element
*c
)
9152 struct breakpoint
*b
;
9156 if (b
->type
== bp_dprintf
)
9157 update_dprintf_command_list (b
);
9161 /* Create a breakpoint with SAL as location. Use LOCATION
9162 as a description of the location, and COND_STRING
9163 as condition expression. If LOCATION is NULL then create an
9164 "address location" from the address in the SAL. */
9167 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9168 struct symtabs_and_lines sals
,
9169 event_location_up
&&location
,
9170 char *filter
, char *cond_string
,
9172 enum bptype type
, enum bpdisp disposition
,
9173 int thread
, int task
, int ignore_count
,
9174 const struct breakpoint_ops
*ops
, int from_tty
,
9175 int enabled
, int internal
, unsigned flags
,
9176 int display_canonical
)
9180 if (type
== bp_hardware_breakpoint
)
9182 int target_resources_ok
;
9184 i
= hw_breakpoint_used_count ();
9185 target_resources_ok
=
9186 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9188 if (target_resources_ok
== 0)
9189 error (_("No hardware breakpoint support in the target."));
9190 else if (target_resources_ok
< 0)
9191 error (_("Hardware breakpoints used exceeds limit."));
9194 gdb_assert (sals
.nelts
> 0);
9196 for (i
= 0; i
< sals
.nelts
; ++i
)
9198 struct symtab_and_line sal
= sals
.sals
[i
];
9199 struct bp_location
*loc
;
9203 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9205 loc_gdbarch
= gdbarch
;
9207 describe_other_breakpoints (loc_gdbarch
,
9208 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9213 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9217 b
->cond_string
= cond_string
;
9218 b
->extra_string
= extra_string
;
9219 b
->ignore_count
= ignore_count
;
9220 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9221 b
->disposition
= disposition
;
9223 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9224 b
->loc
->inserted
= 1;
9226 if (type
== bp_static_tracepoint
)
9228 struct tracepoint
*t
= (struct tracepoint
*) b
;
9229 struct static_tracepoint_marker marker
;
9231 if (strace_marker_p (b
))
9233 /* We already know the marker exists, otherwise, we
9234 wouldn't see a sal for it. */
9236 = &event_location_to_string (b
->location
.get ())[3];
9240 p
= skip_spaces_const (p
);
9242 endp
= skip_to_space_const (p
);
9244 marker_str
= savestring (p
, endp
- p
);
9245 t
->static_trace_marker_id
= marker_str
;
9247 printf_filtered (_("Probed static tracepoint "
9249 t
->static_trace_marker_id
);
9251 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9253 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9254 release_static_tracepoint_marker (&marker
);
9256 printf_filtered (_("Probed static tracepoint "
9258 t
->static_trace_marker_id
);
9261 warning (_("Couldn't determine the static "
9262 "tracepoint marker to probe"));
9269 loc
= add_location_to_breakpoint (b
, &sal
);
9270 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9276 const char *arg
= b
->cond_string
;
9278 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9279 block_for_pc (loc
->address
), 0);
9281 error (_("Garbage '%s' follows condition"), arg
);
9284 /* Dynamic printf requires and uses additional arguments on the
9285 command line, otherwise it's an error. */
9286 if (type
== bp_dprintf
)
9288 if (b
->extra_string
)
9289 update_dprintf_command_list (b
);
9291 error (_("Format string required"));
9293 else if (b
->extra_string
)
9294 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9297 b
->display_canonical
= display_canonical
;
9298 if (location
!= NULL
)
9299 b
->location
= std::move (location
);
9301 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9306 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9307 struct symtabs_and_lines sals
,
9308 event_location_up
&&location
,
9309 char *filter
, char *cond_string
,
9311 enum bptype type
, enum bpdisp disposition
,
9312 int thread
, int task
, int ignore_count
,
9313 const struct breakpoint_ops
*ops
, int from_tty
,
9314 int enabled
, int internal
, unsigned flags
,
9315 int display_canonical
)
9317 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9319 init_breakpoint_sal (b
.get (), gdbarch
,
9320 sals
, std::move (location
),
9321 filter
, cond_string
, extra_string
,
9323 thread
, task
, ignore_count
,
9325 enabled
, internal
, flags
,
9328 install_breakpoint (internal
, b
.release (), 0);
9331 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9332 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9333 value. COND_STRING, if not NULL, specified the condition to be
9334 used for all breakpoints. Essentially the only case where
9335 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9336 function. In that case, it's still not possible to specify
9337 separate conditions for different overloaded functions, so
9338 we take just a single condition string.
9340 NOTE: If the function succeeds, the caller is expected to cleanup
9341 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9342 array contents). If the function fails (error() is called), the
9343 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9344 COND and SALS arrays and each of those arrays contents. */
9347 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9348 struct linespec_result
*canonical
,
9349 char *cond_string
, char *extra_string
,
9350 enum bptype type
, enum bpdisp disposition
,
9351 int thread
, int task
, int ignore_count
,
9352 const struct breakpoint_ops
*ops
, int from_tty
,
9353 int enabled
, int internal
, unsigned flags
)
9356 struct linespec_sals
*lsal
;
9358 if (canonical
->pre_expanded
)
9359 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9361 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9363 /* Note that 'location' can be NULL in the case of a plain
9364 'break', without arguments. */
9365 event_location_up location
9366 = (canonical
->location
!= NULL
9367 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9368 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9370 make_cleanup (xfree
, filter_string
);
9371 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9372 std::move (location
),
9374 cond_string
, extra_string
,
9376 thread
, task
, ignore_count
, ops
,
9377 from_tty
, enabled
, internal
, flags
,
9378 canonical
->special_display
);
9382 /* Parse LOCATION which is assumed to be a SAL specification possibly
9383 followed by conditionals. On return, SALS contains an array of SAL
9384 addresses found. LOCATION points to the end of the SAL (for
9385 linespec locations).
9387 The array and the line spec strings are allocated on the heap, it is
9388 the caller's responsibility to free them. */
9391 parse_breakpoint_sals (const struct event_location
*location
,
9392 struct linespec_result
*canonical
)
9394 struct symtab_and_line cursal
;
9396 if (event_location_type (location
) == LINESPEC_LOCATION
)
9398 const char *address
= get_linespec_location (location
);
9400 if (address
== NULL
)
9402 /* The last displayed codepoint, if it's valid, is our default
9403 breakpoint address. */
9404 if (last_displayed_sal_is_valid ())
9406 struct linespec_sals lsal
;
9407 struct symtab_and_line sal
;
9410 init_sal (&sal
); /* Initialize to zeroes. */
9411 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9413 /* Set sal's pspace, pc, symtab, and line to the values
9414 corresponding to the last call to print_frame_info.
9415 Be sure to reinitialize LINE with NOTCURRENT == 0
9416 as the breakpoint line number is inappropriate otherwise.
9417 find_pc_line would adjust PC, re-set it back. */
9418 get_last_displayed_sal (&sal
);
9420 sal
= find_pc_line (pc
, 0);
9422 /* "break" without arguments is equivalent to "break *PC"
9423 where PC is the last displayed codepoint's address. So
9424 make sure to set sal.explicit_pc to prevent GDB from
9425 trying to expand the list of sals to include all other
9426 instances with the same symtab and line. */
9428 sal
.explicit_pc
= 1;
9430 lsal
.sals
.sals
[0] = sal
;
9431 lsal
.sals
.nelts
= 1;
9432 lsal
.canonical
= NULL
;
9434 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9438 error (_("No default breakpoint address now."));
9442 /* Force almost all breakpoints to be in terms of the
9443 current_source_symtab (which is decode_line_1's default).
9444 This should produce the results we want almost all of the
9445 time while leaving default_breakpoint_* alone.
9447 ObjC: However, don't match an Objective-C method name which
9448 may have a '+' or '-' succeeded by a '['. */
9449 cursal
= get_current_source_symtab_and_line ();
9450 if (last_displayed_sal_is_valid ())
9452 const char *address
= NULL
;
9454 if (event_location_type (location
) == LINESPEC_LOCATION
)
9455 address
= get_linespec_location (location
);
9459 && strchr ("+-", address
[0]) != NULL
9460 && address
[1] != '['))
9462 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9463 get_last_displayed_symtab (),
9464 get_last_displayed_line (),
9465 canonical
, NULL
, NULL
);
9470 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9471 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9475 /* Convert each SAL into a real PC. Verify that the PC can be
9476 inserted as a breakpoint. If it can't throw an error. */
9479 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9483 for (i
= 0; i
< sals
->nelts
; i
++)
9484 resolve_sal_pc (&sals
->sals
[i
]);
9487 /* Fast tracepoints may have restrictions on valid locations. For
9488 instance, a fast tracepoint using a jump instead of a trap will
9489 likely have to overwrite more bytes than a trap would, and so can
9490 only be placed where the instruction is longer than the jump, or a
9491 multi-instruction sequence does not have a jump into the middle of
9495 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9496 struct symtabs_and_lines
*sals
)
9499 struct symtab_and_line
*sal
;
9501 struct cleanup
*old_chain
;
9503 for (i
= 0; i
< sals
->nelts
; i
++)
9505 struct gdbarch
*sarch
;
9507 sal
= &sals
->sals
[i
];
9509 sarch
= get_sal_arch (*sal
);
9510 /* We fall back to GDBARCH if there is no architecture
9511 associated with SAL. */
9514 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9515 old_chain
= make_cleanup (xfree
, msg
);
9518 error (_("May not have a fast tracepoint at %s%s"),
9519 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9521 do_cleanups (old_chain
);
9525 /* Given TOK, a string specification of condition and thread, as
9526 accepted by the 'break' command, extract the condition
9527 string and thread number and set *COND_STRING and *THREAD.
9528 PC identifies the context at which the condition should be parsed.
9529 If no condition is found, *COND_STRING is set to NULL.
9530 If no thread is found, *THREAD is set to -1. */
9533 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9534 char **cond_string
, int *thread
, int *task
,
9537 *cond_string
= NULL
;
9544 const char *end_tok
;
9546 const char *cond_start
= NULL
;
9547 const char *cond_end
= NULL
;
9549 tok
= skip_spaces_const (tok
);
9551 if ((*tok
== '"' || *tok
== ',') && rest
)
9553 *rest
= savestring (tok
, strlen (tok
));
9557 end_tok
= skip_to_space_const (tok
);
9559 toklen
= end_tok
- tok
;
9561 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9563 tok
= cond_start
= end_tok
+ 1;
9564 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9566 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9568 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9571 struct thread_info
*thr
;
9574 thr
= parse_thread_id (tok
, &tmptok
);
9576 error (_("Junk after thread keyword."));
9577 *thread
= thr
->global_num
;
9580 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9585 *task
= strtol (tok
, &tmptok
, 0);
9587 error (_("Junk after task keyword."));
9588 if (!valid_task_id (*task
))
9589 error (_("Unknown task %d."), *task
);
9594 *rest
= savestring (tok
, strlen (tok
));
9598 error (_("Junk at end of arguments."));
9602 /* Decode a static tracepoint marker spec. */
9604 static struct symtabs_and_lines
9605 decode_static_tracepoint_spec (const char **arg_p
)
9607 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9608 struct symtabs_and_lines sals
;
9609 struct cleanup
*old_chain
;
9610 const char *p
= &(*arg_p
)[3];
9615 p
= skip_spaces_const (p
);
9617 endp
= skip_to_space_const (p
);
9619 marker_str
= savestring (p
, endp
- p
);
9620 old_chain
= make_cleanup (xfree
, marker_str
);
9622 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9623 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9624 error (_("No known static tracepoint marker named %s"), marker_str
);
9626 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9627 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9629 for (i
= 0; i
< sals
.nelts
; i
++)
9631 struct static_tracepoint_marker
*marker
;
9633 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9635 init_sal (&sals
.sals
[i
]);
9637 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9638 sals
.sals
[i
].pc
= marker
->address
;
9640 release_static_tracepoint_marker (marker
);
9643 do_cleanups (old_chain
);
9649 /* See breakpoint.h. */
9652 create_breakpoint (struct gdbarch
*gdbarch
,
9653 const struct event_location
*location
, char *cond_string
,
9654 int thread
, char *extra_string
,
9656 int tempflag
, enum bptype type_wanted
,
9658 enum auto_boolean pending_break_support
,
9659 const struct breakpoint_ops
*ops
,
9660 int from_tty
, int enabled
, int internal
,
9663 struct linespec_result canonical
;
9664 struct cleanup
*bkpt_chain
= NULL
;
9667 int prev_bkpt_count
= breakpoint_count
;
9669 gdb_assert (ops
!= NULL
);
9671 /* If extra_string isn't useful, set it to NULL. */
9672 if (extra_string
!= NULL
&& *extra_string
== '\0')
9673 extra_string
= NULL
;
9677 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9679 CATCH (e
, RETURN_MASK_ERROR
)
9681 /* If caller is interested in rc value from parse, set
9683 if (e
.error
== NOT_FOUND_ERROR
)
9685 /* If pending breakpoint support is turned off, throw
9688 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9689 throw_exception (e
);
9691 exception_print (gdb_stderr
, e
);
9693 /* If pending breakpoint support is auto query and the user
9694 selects no, then simply return the error code. */
9695 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9696 && !nquery (_("Make %s pending on future shared library load? "),
9697 bptype_string (type_wanted
)))
9700 /* At this point, either the user was queried about setting
9701 a pending breakpoint and selected yes, or pending
9702 breakpoint behavior is on and thus a pending breakpoint
9703 is defaulted on behalf of the user. */
9707 throw_exception (e
);
9711 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9714 /* ----------------------------- SNIP -----------------------------
9715 Anything added to the cleanup chain beyond this point is assumed
9716 to be part of a breakpoint. If the breakpoint create succeeds
9717 then the memory is not reclaimed. */
9718 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9720 /* Resolve all line numbers to PC's and verify that the addresses
9721 are ok for the target. */
9725 struct linespec_sals
*iter
;
9727 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9728 breakpoint_sals_to_pc (&iter
->sals
);
9731 /* Fast tracepoints may have additional restrictions on location. */
9732 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9735 struct linespec_sals
*iter
;
9737 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9738 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9741 /* Verify that condition can be parsed, before setting any
9742 breakpoints. Allocate a separate condition expression for each
9749 struct linespec_sals
*lsal
;
9751 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9753 /* Here we only parse 'arg' to separate condition
9754 from thread number, so parsing in context of first
9755 sal is OK. When setting the breakpoint we'll
9756 re-parse it in context of each sal. */
9758 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9759 &cond_string
, &thread
, &task
, &rest
);
9761 make_cleanup (xfree
, cond_string
);
9763 make_cleanup (xfree
, rest
);
9765 extra_string
= rest
;
9767 extra_string
= NULL
;
9771 if (type_wanted
!= bp_dprintf
9772 && extra_string
!= NULL
&& *extra_string
!= '\0')
9773 error (_("Garbage '%s' at end of location"), extra_string
);
9775 /* Create a private copy of condition string. */
9778 cond_string
= xstrdup (cond_string
);
9779 make_cleanup (xfree
, cond_string
);
9781 /* Create a private copy of any extra string. */
9784 extra_string
= xstrdup (extra_string
);
9785 make_cleanup (xfree
, extra_string
);
9789 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9790 cond_string
, extra_string
, type_wanted
,
9791 tempflag
? disp_del
: disp_donttouch
,
9792 thread
, task
, ignore_count
, ops
,
9793 from_tty
, enabled
, internal
, flags
);
9797 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9799 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9800 b
->location
= copy_event_location (location
);
9803 b
->cond_string
= NULL
;
9806 /* Create a private copy of condition string. */
9809 cond_string
= xstrdup (cond_string
);
9810 make_cleanup (xfree
, cond_string
);
9812 b
->cond_string
= cond_string
;
9816 /* Create a private copy of any extra string. */
9817 if (extra_string
!= NULL
)
9819 extra_string
= xstrdup (extra_string
);
9820 make_cleanup (xfree
, extra_string
);
9822 b
->extra_string
= extra_string
;
9823 b
->ignore_count
= ignore_count
;
9824 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9825 b
->condition_not_parsed
= 1;
9826 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9827 if ((type_wanted
!= bp_breakpoint
9828 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9829 b
->pspace
= current_program_space
;
9831 install_breakpoint (internal
, b
.release (), 0);
9834 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9836 warning (_("Multiple breakpoints were set.\nUse the "
9837 "\"delete\" command to delete unwanted breakpoints."));
9838 prev_breakpoint_count
= prev_bkpt_count
;
9841 /* That's it. Discard the cleanups for data inserted into the
9843 discard_cleanups (bkpt_chain
);
9845 /* error call may happen here - have BKPT_CHAIN already discarded. */
9846 update_global_location_list (UGLL_MAY_INSERT
);
9851 /* Set a breakpoint.
9852 ARG is a string describing breakpoint address,
9853 condition, and thread.
9854 FLAG specifies if a breakpoint is hardware on,
9855 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9859 break_command_1 (char *arg
, int flag
, int from_tty
)
9861 int tempflag
= flag
& BP_TEMPFLAG
;
9862 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9863 ? bp_hardware_breakpoint
9865 struct breakpoint_ops
*ops
;
9867 event_location_up location
= string_to_event_location (&arg
, current_language
);
9869 /* Matching breakpoints on probes. */
9870 if (location
!= NULL
9871 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9872 ops
= &bkpt_probe_breakpoint_ops
;
9874 ops
= &bkpt_breakpoint_ops
;
9876 create_breakpoint (get_current_arch (),
9878 NULL
, 0, arg
, 1 /* parse arg */,
9879 tempflag
, type_wanted
,
9880 0 /* Ignore count */,
9881 pending_break_support
,
9889 /* Helper function for break_command_1 and disassemble_command. */
9892 resolve_sal_pc (struct symtab_and_line
*sal
)
9896 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9898 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9899 error (_("No line %d in file \"%s\"."),
9900 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9903 /* If this SAL corresponds to a breakpoint inserted using a line
9904 number, then skip the function prologue if necessary. */
9905 if (sal
->explicit_line
)
9906 skip_prologue_sal (sal
);
9909 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9911 const struct blockvector
*bv
;
9912 const struct block
*b
;
9915 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9916 SYMTAB_COMPUNIT (sal
->symtab
));
9919 sym
= block_linkage_function (b
);
9922 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9923 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9928 /* It really is worthwhile to have the section, so we'll
9929 just have to look harder. This case can be executed
9930 if we have line numbers but no functions (as can
9931 happen in assembly source). */
9933 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9934 switch_to_program_space_and_thread (sal
->pspace
);
9936 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9938 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9945 break_command (char *arg
, int from_tty
)
9947 break_command_1 (arg
, 0, from_tty
);
9951 tbreak_command (char *arg
, int from_tty
)
9953 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9957 hbreak_command (char *arg
, int from_tty
)
9959 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9963 thbreak_command (char *arg
, int from_tty
)
9965 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9969 stop_command (char *arg
, int from_tty
)
9971 printf_filtered (_("Specify the type of breakpoint to set.\n\
9972 Usage: stop in <function | address>\n\
9973 stop at <line>\n"));
9977 stopin_command (char *arg
, int from_tty
)
9981 if (arg
== (char *) NULL
)
9983 else if (*arg
!= '*')
9988 /* Look for a ':'. If this is a line number specification, then
9989 say it is bad, otherwise, it should be an address or
9990 function/method name. */
9991 while (*argptr
&& !hasColon
)
9993 hasColon
= (*argptr
== ':');
9998 badInput
= (*argptr
!= ':'); /* Not a class::method */
10000 badInput
= isdigit (*arg
); /* a simple line number */
10004 printf_filtered (_("Usage: stop in <function | address>\n"));
10006 break_command_1 (arg
, 0, from_tty
);
10010 stopat_command (char *arg
, int from_tty
)
10014 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10018 char *argptr
= arg
;
10021 /* Look for a ':'. If there is a '::' then get out, otherwise
10022 it is probably a line number. */
10023 while (*argptr
&& !hasColon
)
10025 hasColon
= (*argptr
== ':');
10030 badInput
= (*argptr
== ':'); /* we have class::method */
10032 badInput
= !isdigit (*arg
); /* not a line number */
10036 printf_filtered (_("Usage: stop at <line>\n"));
10038 break_command_1 (arg
, 0, from_tty
);
10041 /* The dynamic printf command is mostly like a regular breakpoint, but
10042 with a prewired command list consisting of a single output command,
10043 built from extra arguments supplied on the dprintf command
10047 dprintf_command (char *arg
, int from_tty
)
10049 event_location_up location
= string_to_event_location (&arg
, current_language
);
10051 /* If non-NULL, ARG should have been advanced past the location;
10052 the next character must be ','. */
10055 if (arg
[0] != ',' || arg
[1] == '\0')
10056 error (_("Format string required"));
10059 /* Skip the comma. */
10064 create_breakpoint (get_current_arch (),
10066 NULL
, 0, arg
, 1 /* parse arg */,
10068 0 /* Ignore count */,
10069 pending_break_support
,
10070 &dprintf_breakpoint_ops
,
10078 agent_printf_command (char *arg
, int from_tty
)
10080 error (_("May only run agent-printf on the target"));
10083 /* Implement the "breakpoint_hit" breakpoint_ops method for
10084 ranged breakpoints. */
10087 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10088 struct address_space
*aspace
,
10090 const struct target_waitstatus
*ws
)
10092 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10093 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10096 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10097 bl
->length
, aspace
, bp_addr
);
10100 /* Implement the "resources_needed" breakpoint_ops method for
10101 ranged breakpoints. */
10104 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10106 return target_ranged_break_num_registers ();
10109 /* Implement the "print_it" breakpoint_ops method for
10110 ranged breakpoints. */
10112 static enum print_stop_action
10113 print_it_ranged_breakpoint (bpstat bs
)
10115 struct breakpoint
*b
= bs
->breakpoint_at
;
10116 struct bp_location
*bl
= b
->loc
;
10117 struct ui_out
*uiout
= current_uiout
;
10119 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10121 /* Ranged breakpoints have only one location. */
10122 gdb_assert (bl
&& bl
->next
== NULL
);
10124 annotate_breakpoint (b
->number
);
10126 maybe_print_thread_hit_breakpoint (uiout
);
10128 if (b
->disposition
== disp_del
)
10129 uiout
->text ("Temporary ranged breakpoint ");
10131 uiout
->text ("Ranged breakpoint ");
10132 if (uiout
->is_mi_like_p ())
10134 uiout
->field_string ("reason",
10135 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10136 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
10138 uiout
->field_int ("bkptno", b
->number
);
10139 uiout
->text (", ");
10141 return PRINT_SRC_AND_LOC
;
10144 /* Implement the "print_one" breakpoint_ops method for
10145 ranged breakpoints. */
10148 print_one_ranged_breakpoint (struct breakpoint
*b
,
10149 struct bp_location
**last_loc
)
10151 struct bp_location
*bl
= b
->loc
;
10152 struct value_print_options opts
;
10153 struct ui_out
*uiout
= current_uiout
;
10155 /* Ranged breakpoints have only one location. */
10156 gdb_assert (bl
&& bl
->next
== NULL
);
10158 get_user_print_options (&opts
);
10160 if (opts
.addressprint
)
10161 /* We don't print the address range here, it will be printed later
10162 by print_one_detail_ranged_breakpoint. */
10163 uiout
->field_skip ("addr");
10164 annotate_field (5);
10165 print_breakpoint_location (b
, bl
);
10169 /* Implement the "print_one_detail" breakpoint_ops method for
10170 ranged breakpoints. */
10173 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10174 struct ui_out
*uiout
)
10176 CORE_ADDR address_start
, address_end
;
10177 struct bp_location
*bl
= b
->loc
;
10182 address_start
= bl
->address
;
10183 address_end
= address_start
+ bl
->length
- 1;
10185 uiout
->text ("\taddress range: ");
10186 stb
.printf ("[%s, %s]",
10187 print_core_address (bl
->gdbarch
, address_start
),
10188 print_core_address (bl
->gdbarch
, address_end
));
10189 uiout
->field_stream ("addr", stb
);
10190 uiout
->text ("\n");
10193 /* Implement the "print_mention" breakpoint_ops method for
10194 ranged breakpoints. */
10197 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10199 struct bp_location
*bl
= b
->loc
;
10200 struct ui_out
*uiout
= current_uiout
;
10203 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10205 if (uiout
->is_mi_like_p ())
10208 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10209 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10210 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10213 /* Implement the "print_recreate" breakpoint_ops method for
10214 ranged breakpoints. */
10217 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10219 fprintf_unfiltered (fp
, "break-range %s, %s",
10220 event_location_to_string (b
->location
.get ()),
10221 event_location_to_string (b
->location_range_end
.get ()));
10222 print_recreate_thread (b
, fp
);
10225 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10227 static struct breakpoint_ops ranged_breakpoint_ops
;
10229 /* Find the address where the end of the breakpoint range should be
10230 placed, given the SAL of the end of the range. This is so that if
10231 the user provides a line number, the end of the range is set to the
10232 last instruction of the given line. */
10235 find_breakpoint_range_end (struct symtab_and_line sal
)
10239 /* If the user provided a PC value, use it. Otherwise,
10240 find the address of the end of the given location. */
10241 if (sal
.explicit_pc
)
10248 ret
= find_line_pc_range (sal
, &start
, &end
);
10250 error (_("Could not find location of the end of the range."));
10252 /* find_line_pc_range returns the start of the next line. */
10259 /* Implement the "break-range" CLI command. */
10262 break_range_command (char *arg
, int from_tty
)
10264 char *arg_start
, *addr_string_start
;
10265 struct linespec_result canonical_start
, canonical_end
;
10266 int bp_count
, can_use_bp
, length
;
10268 struct breakpoint
*b
;
10269 struct symtab_and_line sal_start
, sal_end
;
10270 struct cleanup
*cleanup_bkpt
;
10271 struct linespec_sals
*lsal_start
, *lsal_end
;
10273 /* We don't support software ranged breakpoints. */
10274 if (target_ranged_break_num_registers () < 0)
10275 error (_("This target does not support hardware ranged breakpoints."));
10277 bp_count
= hw_breakpoint_used_count ();
10278 bp_count
+= target_ranged_break_num_registers ();
10279 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10281 if (can_use_bp
< 0)
10282 error (_("Hardware breakpoints used exceeds limit."));
10284 arg
= skip_spaces (arg
);
10285 if (arg
== NULL
|| arg
[0] == '\0')
10286 error(_("No address range specified."));
10289 event_location_up start_location
= string_to_event_location (&arg
,
10291 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10294 error (_("Too few arguments."));
10295 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10296 error (_("Could not find location of the beginning of the range."));
10298 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10300 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10301 || lsal_start
->sals
.nelts
!= 1)
10302 error (_("Cannot create a ranged breakpoint with multiple locations."));
10304 sal_start
= lsal_start
->sals
.sals
[0];
10305 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10306 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10308 arg
++; /* Skip the comma. */
10309 arg
= skip_spaces (arg
);
10311 /* Parse the end location. */
10315 /* We call decode_line_full directly here instead of using
10316 parse_breakpoint_sals because we need to specify the start location's
10317 symtab and line as the default symtab and line for the end of the
10318 range. This makes it possible to have ranges like "foo.c:27, +14",
10319 where +14 means 14 lines from the start location. */
10320 event_location_up end_location
= string_to_event_location (&arg
,
10322 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10323 sal_start
.symtab
, sal_start
.line
,
10324 &canonical_end
, NULL
, NULL
);
10326 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10327 error (_("Could not find location of the end of the range."));
10329 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10330 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10331 || lsal_end
->sals
.nelts
!= 1)
10332 error (_("Cannot create a ranged breakpoint with multiple locations."));
10334 sal_end
= lsal_end
->sals
.sals
[0];
10336 end
= find_breakpoint_range_end (sal_end
);
10337 if (sal_start
.pc
> end
)
10338 error (_("Invalid address range, end precedes start."));
10340 length
= end
- sal_start
.pc
+ 1;
10342 /* Length overflowed. */
10343 error (_("Address range too large."));
10344 else if (length
== 1)
10346 /* This range is simple enough to be handled by
10347 the `hbreak' command. */
10348 hbreak_command (addr_string_start
, 1);
10350 do_cleanups (cleanup_bkpt
);
10355 /* Now set up the breakpoint. */
10356 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10357 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10358 set_breakpoint_count (breakpoint_count
+ 1);
10359 b
->number
= breakpoint_count
;
10360 b
->disposition
= disp_donttouch
;
10361 b
->location
= std::move (start_location
);
10362 b
->location_range_end
= std::move (end_location
);
10363 b
->loc
->length
= length
;
10365 do_cleanups (cleanup_bkpt
);
10368 observer_notify_breakpoint_created (b
);
10369 update_global_location_list (UGLL_MAY_INSERT
);
10372 /* Return non-zero if EXP is verified as constant. Returned zero
10373 means EXP is variable. Also the constant detection may fail for
10374 some constant expressions and in such case still falsely return
10378 watchpoint_exp_is_const (const struct expression
*exp
)
10380 int i
= exp
->nelts
;
10386 /* We are only interested in the descriptor of each element. */
10387 operator_length (exp
, i
, &oplenp
, &argsp
);
10390 switch (exp
->elts
[i
].opcode
)
10400 case BINOP_LOGICAL_AND
:
10401 case BINOP_LOGICAL_OR
:
10402 case BINOP_BITWISE_AND
:
10403 case BINOP_BITWISE_IOR
:
10404 case BINOP_BITWISE_XOR
:
10406 case BINOP_NOTEQUAL
:
10433 case OP_OBJC_NSSTRING
:
10436 case UNOP_LOGICAL_NOT
:
10437 case UNOP_COMPLEMENT
:
10442 case UNOP_CAST_TYPE
:
10443 case UNOP_REINTERPRET_CAST
:
10444 case UNOP_DYNAMIC_CAST
:
10445 /* Unary, binary and ternary operators: We have to check
10446 their operands. If they are constant, then so is the
10447 result of that operation. For instance, if A and B are
10448 determined to be constants, then so is "A + B".
10450 UNOP_IND is one exception to the rule above, because the
10451 value of *ADDR is not necessarily a constant, even when
10456 /* Check whether the associated symbol is a constant.
10458 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10459 possible that a buggy compiler could mark a variable as
10460 constant even when it is not, and TYPE_CONST would return
10461 true in this case, while SYMBOL_CLASS wouldn't.
10463 We also have to check for function symbols because they
10464 are always constant. */
10466 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10468 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10469 && SYMBOL_CLASS (s
) != LOC_CONST
10470 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10475 /* The default action is to return 0 because we are using
10476 the optimistic approach here: If we don't know something,
10477 then it is not a constant. */
10486 /* Watchpoint destructor. */
10488 watchpoint::~watchpoint ()
10490 xfree (this->exp_string
);
10491 xfree (this->exp_string_reparse
);
10492 value_free (this->val
);
10495 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10498 re_set_watchpoint (struct breakpoint
*b
)
10500 struct watchpoint
*w
= (struct watchpoint
*) b
;
10502 /* Watchpoint can be either on expression using entirely global
10503 variables, or it can be on local variables.
10505 Watchpoints of the first kind are never auto-deleted, and even
10506 persist across program restarts. Since they can use variables
10507 from shared libraries, we need to reparse expression as libraries
10508 are loaded and unloaded.
10510 Watchpoints on local variables can also change meaning as result
10511 of solib event. For example, if a watchpoint uses both a local
10512 and a global variables in expression, it's a local watchpoint,
10513 but unloading of a shared library will make the expression
10514 invalid. This is not a very common use case, but we still
10515 re-evaluate expression, to avoid surprises to the user.
10517 Note that for local watchpoints, we re-evaluate it only if
10518 watchpoints frame id is still valid. If it's not, it means the
10519 watchpoint is out of scope and will be deleted soon. In fact,
10520 I'm not sure we'll ever be called in this case.
10522 If a local watchpoint's frame id is still valid, then
10523 w->exp_valid_block is likewise valid, and we can safely use it.
10525 Don't do anything about disabled watchpoints, since they will be
10526 reevaluated again when enabled. */
10527 update_watchpoint (w
, 1 /* reparse */);
10530 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10533 insert_watchpoint (struct bp_location
*bl
)
10535 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10536 int length
= w
->exact
? 1 : bl
->length
;
10538 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10539 w
->cond_exp
.get ());
10542 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10545 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10547 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10548 int length
= w
->exact
? 1 : bl
->length
;
10550 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10551 w
->cond_exp
.get ());
10555 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10556 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10557 const struct target_waitstatus
*ws
)
10559 struct breakpoint
*b
= bl
->owner
;
10560 struct watchpoint
*w
= (struct watchpoint
*) b
;
10562 /* Continuable hardware watchpoints are treated as non-existent if the
10563 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10564 some data address). Otherwise gdb won't stop on a break instruction
10565 in the code (not from a breakpoint) when a hardware watchpoint has
10566 been defined. Also skip watchpoints which we know did not trigger
10567 (did not match the data address). */
10568 if (is_hardware_watchpoint (b
)
10569 && w
->watchpoint_triggered
== watch_triggered_no
)
10576 check_status_watchpoint (bpstat bs
)
10578 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10580 bpstat_check_watchpoint (bs
);
10583 /* Implement the "resources_needed" breakpoint_ops method for
10584 hardware watchpoints. */
10587 resources_needed_watchpoint (const struct bp_location
*bl
)
10589 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10590 int length
= w
->exact
? 1 : bl
->length
;
10592 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10595 /* Implement the "works_in_software_mode" breakpoint_ops method for
10596 hardware watchpoints. */
10599 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10601 /* Read and access watchpoints only work with hardware support. */
10602 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10605 static enum print_stop_action
10606 print_it_watchpoint (bpstat bs
)
10608 struct cleanup
*old_chain
;
10609 struct breakpoint
*b
;
10610 enum print_stop_action result
;
10611 struct watchpoint
*w
;
10612 struct ui_out
*uiout
= current_uiout
;
10614 gdb_assert (bs
->bp_location_at
!= NULL
);
10616 b
= bs
->breakpoint_at
;
10617 w
= (struct watchpoint
*) b
;
10619 old_chain
= make_cleanup (null_cleanup
, NULL
);
10621 annotate_watchpoint (b
->number
);
10622 maybe_print_thread_hit_breakpoint (uiout
);
10628 case bp_watchpoint
:
10629 case bp_hardware_watchpoint
:
10630 if (uiout
->is_mi_like_p ())
10631 uiout
->field_string
10632 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10634 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10635 uiout
->text ("\nOld value = ");
10636 watchpoint_value_print (bs
->old_val
, &stb
);
10637 uiout
->field_stream ("old", stb
);
10638 uiout
->text ("\nNew value = ");
10639 watchpoint_value_print (w
->val
, &stb
);
10640 uiout
->field_stream ("new", stb
);
10641 uiout
->text ("\n");
10642 /* More than one watchpoint may have been triggered. */
10643 result
= PRINT_UNKNOWN
;
10646 case bp_read_watchpoint
:
10647 if (uiout
->is_mi_like_p ())
10648 uiout
->field_string
10649 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10651 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10652 uiout
->text ("\nValue = ");
10653 watchpoint_value_print (w
->val
, &stb
);
10654 uiout
->field_stream ("value", stb
);
10655 uiout
->text ("\n");
10656 result
= PRINT_UNKNOWN
;
10659 case bp_access_watchpoint
:
10660 if (bs
->old_val
!= NULL
)
10662 if (uiout
->is_mi_like_p ())
10663 uiout
->field_string
10665 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10667 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10668 uiout
->text ("\nOld value = ");
10669 watchpoint_value_print (bs
->old_val
, &stb
);
10670 uiout
->field_stream ("old", stb
);
10671 uiout
->text ("\nNew value = ");
10676 if (uiout
->is_mi_like_p ())
10677 uiout
->field_string
10679 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10680 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10681 uiout
->text ("\nValue = ");
10683 watchpoint_value_print (w
->val
, &stb
);
10684 uiout
->field_stream ("new", stb
);
10685 uiout
->text ("\n");
10686 result
= PRINT_UNKNOWN
;
10689 result
= PRINT_UNKNOWN
;
10692 do_cleanups (old_chain
);
10696 /* Implement the "print_mention" breakpoint_ops method for hardware
10700 print_mention_watchpoint (struct breakpoint
*b
)
10702 struct watchpoint
*w
= (struct watchpoint
*) b
;
10703 struct ui_out
*uiout
= current_uiout
;
10704 const char *tuple_name
;
10708 case bp_watchpoint
:
10709 uiout
->text ("Watchpoint ");
10710 tuple_name
= "wpt";
10712 case bp_hardware_watchpoint
:
10713 uiout
->text ("Hardware watchpoint ");
10714 tuple_name
= "wpt";
10716 case bp_read_watchpoint
:
10717 uiout
->text ("Hardware read watchpoint ");
10718 tuple_name
= "hw-rwpt";
10720 case bp_access_watchpoint
:
10721 uiout
->text ("Hardware access (read/write) watchpoint ");
10722 tuple_name
= "hw-awpt";
10725 internal_error (__FILE__
, __LINE__
,
10726 _("Invalid hardware watchpoint type."));
10729 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10730 uiout
->field_int ("number", b
->number
);
10731 uiout
->text (": ");
10732 uiout
->field_string ("exp", w
->exp_string
);
10735 /* Implement the "print_recreate" breakpoint_ops method for
10739 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10741 struct watchpoint
*w
= (struct watchpoint
*) b
;
10745 case bp_watchpoint
:
10746 case bp_hardware_watchpoint
:
10747 fprintf_unfiltered (fp
, "watch");
10749 case bp_read_watchpoint
:
10750 fprintf_unfiltered (fp
, "rwatch");
10752 case bp_access_watchpoint
:
10753 fprintf_unfiltered (fp
, "awatch");
10756 internal_error (__FILE__
, __LINE__
,
10757 _("Invalid watchpoint type."));
10760 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10761 print_recreate_thread (b
, fp
);
10764 /* Implement the "explains_signal" breakpoint_ops method for
10768 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10770 /* A software watchpoint cannot cause a signal other than
10771 GDB_SIGNAL_TRAP. */
10772 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10778 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10780 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10782 /* Implement the "insert" breakpoint_ops method for
10783 masked hardware watchpoints. */
10786 insert_masked_watchpoint (struct bp_location
*bl
)
10788 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10790 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10791 bl
->watchpoint_type
);
10794 /* Implement the "remove" breakpoint_ops method for
10795 masked hardware watchpoints. */
10798 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10800 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10802 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10803 bl
->watchpoint_type
);
10806 /* Implement the "resources_needed" breakpoint_ops method for
10807 masked hardware watchpoints. */
10810 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10812 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10814 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10817 /* Implement the "works_in_software_mode" breakpoint_ops method for
10818 masked hardware watchpoints. */
10821 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10826 /* Implement the "print_it" breakpoint_ops method for
10827 masked hardware watchpoints. */
10829 static enum print_stop_action
10830 print_it_masked_watchpoint (bpstat bs
)
10832 struct breakpoint
*b
= bs
->breakpoint_at
;
10833 struct ui_out
*uiout
= current_uiout
;
10835 /* Masked watchpoints have only one location. */
10836 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10838 annotate_watchpoint (b
->number
);
10839 maybe_print_thread_hit_breakpoint (uiout
);
10843 case bp_hardware_watchpoint
:
10844 if (uiout
->is_mi_like_p ())
10845 uiout
->field_string
10846 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10849 case bp_read_watchpoint
:
10850 if (uiout
->is_mi_like_p ())
10851 uiout
->field_string
10852 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10855 case bp_access_watchpoint
:
10856 if (uiout
->is_mi_like_p ())
10857 uiout
->field_string
10859 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10862 internal_error (__FILE__
, __LINE__
,
10863 _("Invalid hardware watchpoint type."));
10867 uiout
->text (_("\n\
10868 Check the underlying instruction at PC for the memory\n\
10869 address and value which triggered this watchpoint.\n"));
10870 uiout
->text ("\n");
10872 /* More than one watchpoint may have been triggered. */
10873 return PRINT_UNKNOWN
;
10876 /* Implement the "print_one_detail" breakpoint_ops method for
10877 masked hardware watchpoints. */
10880 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10881 struct ui_out
*uiout
)
10883 struct watchpoint
*w
= (struct watchpoint
*) b
;
10885 /* Masked watchpoints have only one location. */
10886 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10888 uiout
->text ("\tmask ");
10889 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10890 uiout
->text ("\n");
10893 /* Implement the "print_mention" breakpoint_ops method for
10894 masked hardware watchpoints. */
10897 print_mention_masked_watchpoint (struct breakpoint
*b
)
10899 struct watchpoint
*w
= (struct watchpoint
*) b
;
10900 struct ui_out
*uiout
= current_uiout
;
10901 const char *tuple_name
;
10905 case bp_hardware_watchpoint
:
10906 uiout
->text ("Masked hardware watchpoint ");
10907 tuple_name
= "wpt";
10909 case bp_read_watchpoint
:
10910 uiout
->text ("Masked hardware read watchpoint ");
10911 tuple_name
= "hw-rwpt";
10913 case bp_access_watchpoint
:
10914 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10915 tuple_name
= "hw-awpt";
10918 internal_error (__FILE__
, __LINE__
,
10919 _("Invalid hardware watchpoint type."));
10922 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10923 uiout
->field_int ("number", b
->number
);
10924 uiout
->text (": ");
10925 uiout
->field_string ("exp", w
->exp_string
);
10928 /* Implement the "print_recreate" breakpoint_ops method for
10929 masked hardware watchpoints. */
10932 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10934 struct watchpoint
*w
= (struct watchpoint
*) b
;
10939 case bp_hardware_watchpoint
:
10940 fprintf_unfiltered (fp
, "watch");
10942 case bp_read_watchpoint
:
10943 fprintf_unfiltered (fp
, "rwatch");
10945 case bp_access_watchpoint
:
10946 fprintf_unfiltered (fp
, "awatch");
10949 internal_error (__FILE__
, __LINE__
,
10950 _("Invalid hardware watchpoint type."));
10953 sprintf_vma (tmp
, w
->hw_wp_mask
);
10954 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10955 print_recreate_thread (b
, fp
);
10958 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10960 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10962 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10965 is_masked_watchpoint (const struct breakpoint
*b
)
10967 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10970 /* accessflag: hw_write: watch write,
10971 hw_read: watch read,
10972 hw_access: watch access (read or write) */
10974 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10975 int just_location
, int internal
)
10977 struct breakpoint
*scope_breakpoint
= NULL
;
10978 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10979 struct value
*val
, *mark
, *result
;
10980 int saved_bitpos
= 0, saved_bitsize
= 0;
10981 const char *exp_start
= NULL
;
10982 const char *exp_end
= NULL
;
10983 const char *tok
, *end_tok
;
10985 const char *cond_start
= NULL
;
10986 const char *cond_end
= NULL
;
10987 enum bptype bp_type
;
10990 /* Flag to indicate whether we are going to use masks for
10991 the hardware watchpoint. */
10993 CORE_ADDR mask
= 0;
10994 struct watchpoint
*w
;
10996 struct cleanup
*back_to
;
10998 /* Make sure that we actually have parameters to parse. */
10999 if (arg
!= NULL
&& arg
[0] != '\0')
11001 const char *value_start
;
11003 exp_end
= arg
+ strlen (arg
);
11005 /* Look for "parameter value" pairs at the end
11006 of the arguments string. */
11007 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11009 /* Skip whitespace at the end of the argument list. */
11010 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11013 /* Find the beginning of the last token.
11014 This is the value of the parameter. */
11015 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11017 value_start
= tok
+ 1;
11019 /* Skip whitespace. */
11020 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11025 /* Find the beginning of the second to last token.
11026 This is the parameter itself. */
11027 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11030 toklen
= end_tok
- tok
+ 1;
11032 if (toklen
== 6 && startswith (tok
, "thread"))
11034 struct thread_info
*thr
;
11035 /* At this point we've found a "thread" token, which means
11036 the user is trying to set a watchpoint that triggers
11037 only in a specific thread. */
11041 error(_("You can specify only one thread."));
11043 /* Extract the thread ID from the next token. */
11044 thr
= parse_thread_id (value_start
, &endp
);
11046 /* Check if the user provided a valid thread ID. */
11047 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11048 invalid_thread_id_error (value_start
);
11050 thread
= thr
->global_num
;
11052 else if (toklen
== 4 && startswith (tok
, "mask"))
11054 /* We've found a "mask" token, which means the user wants to
11055 create a hardware watchpoint that is going to have the mask
11057 struct value
*mask_value
, *mark
;
11060 error(_("You can specify only one mask."));
11062 use_mask
= just_location
= 1;
11064 mark
= value_mark ();
11065 mask_value
= parse_to_comma_and_eval (&value_start
);
11066 mask
= value_as_address (mask_value
);
11067 value_free_to_mark (mark
);
11070 /* We didn't recognize what we found. We should stop here. */
11073 /* Truncate the string and get rid of the "parameter value" pair before
11074 the arguments string is parsed by the parse_exp_1 function. */
11081 /* Parse the rest of the arguments. From here on out, everything
11082 is in terms of a newly allocated string instead of the original
11084 innermost_block
= NULL
;
11085 expression
= savestring (arg
, exp_end
- arg
);
11086 back_to
= make_cleanup (xfree
, expression
);
11087 exp_start
= arg
= expression
;
11088 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
11090 /* Remove trailing whitespace from the expression before saving it.
11091 This makes the eventual display of the expression string a bit
11093 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11096 /* Checking if the expression is not constant. */
11097 if (watchpoint_exp_is_const (exp
.get ()))
11101 len
= exp_end
- exp_start
;
11102 while (len
> 0 && isspace (exp_start
[len
- 1]))
11104 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11107 exp_valid_block
= innermost_block
;
11108 mark
= value_mark ();
11109 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
11111 if (val
!= NULL
&& just_location
)
11113 saved_bitpos
= value_bitpos (val
);
11114 saved_bitsize
= value_bitsize (val
);
11121 exp_valid_block
= NULL
;
11122 val
= value_addr (result
);
11123 release_value (val
);
11124 value_free_to_mark (mark
);
11128 ret
= target_masked_watch_num_registers (value_as_address (val
),
11131 error (_("This target does not support masked watchpoints."));
11132 else if (ret
== -2)
11133 error (_("Invalid mask or memory region."));
11136 else if (val
!= NULL
)
11137 release_value (val
);
11139 tok
= skip_spaces_const (arg
);
11140 end_tok
= skip_to_space_const (tok
);
11142 toklen
= end_tok
- tok
;
11143 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11145 innermost_block
= NULL
;
11146 tok
= cond_start
= end_tok
+ 1;
11147 parse_exp_1 (&tok
, 0, 0, 0);
11149 /* The watchpoint expression may not be local, but the condition
11150 may still be. E.g.: `watch global if local > 0'. */
11151 cond_exp_valid_block
= innermost_block
;
11156 error (_("Junk at end of command."));
11158 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
11160 /* Save this because create_internal_breakpoint below invalidates
11162 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
11164 /* If the expression is "local", then set up a "watchpoint scope"
11165 breakpoint at the point where we've left the scope of the watchpoint
11166 expression. Create the scope breakpoint before the watchpoint, so
11167 that we will encounter it first in bpstat_stop_status. */
11168 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
11170 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
11172 if (frame_id_p (caller_frame_id
))
11174 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
11175 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
11178 = create_internal_breakpoint (caller_arch
, caller_pc
,
11179 bp_watchpoint_scope
,
11180 &momentary_breakpoint_ops
);
11182 /* create_internal_breakpoint could invalidate WP_FRAME. */
11185 scope_breakpoint
->enable_state
= bp_enabled
;
11187 /* Automatically delete the breakpoint when it hits. */
11188 scope_breakpoint
->disposition
= disp_del
;
11190 /* Only break in the proper frame (help with recursion). */
11191 scope_breakpoint
->frame_id
= caller_frame_id
;
11193 /* Set the address at which we will stop. */
11194 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11195 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11196 scope_breakpoint
->loc
->address
11197 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11198 scope_breakpoint
->loc
->requested_address
,
11199 scope_breakpoint
->type
);
11203 /* Now set up the breakpoint. We create all watchpoints as hardware
11204 watchpoints here even if hardware watchpoints are turned off, a call
11205 to update_watchpoint later in this function will cause the type to
11206 drop back to bp_watchpoint (software watchpoint) if required. */
11208 if (accessflag
== hw_read
)
11209 bp_type
= bp_read_watchpoint
;
11210 else if (accessflag
== hw_access
)
11211 bp_type
= bp_access_watchpoint
;
11213 bp_type
= bp_hardware_watchpoint
;
11215 w
= new watchpoint ();
11218 init_raw_breakpoint_without_location (w
, NULL
, bp_type
,
11219 &masked_watchpoint_breakpoint_ops
);
11221 init_raw_breakpoint_without_location (w
, NULL
, bp_type
,
11222 &watchpoint_breakpoint_ops
);
11223 w
->thread
= thread
;
11224 w
->disposition
= disp_donttouch
;
11225 w
->pspace
= current_program_space
;
11226 w
->exp
= std::move (exp
);
11227 w
->exp_valid_block
= exp_valid_block
;
11228 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11231 struct type
*t
= value_type (val
);
11232 CORE_ADDR addr
= value_as_address (val
);
11234 w
->exp_string_reparse
11235 = current_language
->la_watch_location_expression (t
, addr
).release ();
11237 w
->exp_string
= xstrprintf ("-location %.*s",
11238 (int) (exp_end
- exp_start
), exp_start
);
11241 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11245 w
->hw_wp_mask
= mask
;
11250 w
->val_bitpos
= saved_bitpos
;
11251 w
->val_bitsize
= saved_bitsize
;
11256 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11258 w
->cond_string
= 0;
11260 if (frame_id_p (watchpoint_frame
))
11262 w
->watchpoint_frame
= watchpoint_frame
;
11263 w
->watchpoint_thread
= inferior_ptid
;
11267 w
->watchpoint_frame
= null_frame_id
;
11268 w
->watchpoint_thread
= null_ptid
;
11271 if (scope_breakpoint
!= NULL
)
11273 /* The scope breakpoint is related to the watchpoint. We will
11274 need to act on them together. */
11275 w
->related_breakpoint
= scope_breakpoint
;
11276 scope_breakpoint
->related_breakpoint
= w
;
11279 if (!just_location
)
11280 value_free_to_mark (mark
);
11284 /* Finally update the new watchpoint. This creates the locations
11285 that should be inserted. */
11286 update_watchpoint (w
, 1);
11288 CATCH (e
, RETURN_MASK_ALL
)
11290 delete_breakpoint (w
);
11291 throw_exception (e
);
11295 install_breakpoint (internal
, w
, 1);
11296 do_cleanups (back_to
);
11299 /* Return count of debug registers needed to watch the given expression.
11300 If the watchpoint cannot be handled in hardware return zero. */
11303 can_use_hardware_watchpoint (struct value
*v
)
11305 int found_memory_cnt
= 0;
11306 struct value
*head
= v
;
11308 /* Did the user specifically forbid us to use hardware watchpoints? */
11309 if (!can_use_hw_watchpoints
)
11312 /* Make sure that the value of the expression depends only upon
11313 memory contents, and values computed from them within GDB. If we
11314 find any register references or function calls, we can't use a
11315 hardware watchpoint.
11317 The idea here is that evaluating an expression generates a series
11318 of values, one holding the value of every subexpression. (The
11319 expression a*b+c has five subexpressions: a, b, a*b, c, and
11320 a*b+c.) GDB's values hold almost enough information to establish
11321 the criteria given above --- they identify memory lvalues,
11322 register lvalues, computed values, etcetera. So we can evaluate
11323 the expression, and then scan the chain of values that leaves
11324 behind to decide whether we can detect any possible change to the
11325 expression's final value using only hardware watchpoints.
11327 However, I don't think that the values returned by inferior
11328 function calls are special in any way. So this function may not
11329 notice that an expression involving an inferior function call
11330 can't be watched with hardware watchpoints. FIXME. */
11331 for (; v
; v
= value_next (v
))
11333 if (VALUE_LVAL (v
) == lval_memory
)
11335 if (v
!= head
&& value_lazy (v
))
11336 /* A lazy memory lvalue in the chain is one that GDB never
11337 needed to fetch; we either just used its address (e.g.,
11338 `a' in `a.b') or we never needed it at all (e.g., `a'
11339 in `a,b'). This doesn't apply to HEAD; if that is
11340 lazy then it was not readable, but watch it anyway. */
11344 /* Ahh, memory we actually used! Check if we can cover
11345 it with hardware watchpoints. */
11346 struct type
*vtype
= check_typedef (value_type (v
));
11348 /* We only watch structs and arrays if user asked for it
11349 explicitly, never if they just happen to appear in a
11350 middle of some value chain. */
11352 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11353 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11355 CORE_ADDR vaddr
= value_address (v
);
11359 len
= (target_exact_watchpoints
11360 && is_scalar_type_recursive (vtype
))?
11361 1 : TYPE_LENGTH (value_type (v
));
11363 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11367 found_memory_cnt
+= num_regs
;
11371 else if (VALUE_LVAL (v
) != not_lval
11372 && deprecated_value_modifiable (v
) == 0)
11373 return 0; /* These are values from the history (e.g., $1). */
11374 else if (VALUE_LVAL (v
) == lval_register
)
11375 return 0; /* Cannot watch a register with a HW watchpoint. */
11378 /* The expression itself looks suitable for using a hardware
11379 watchpoint, but give the target machine a chance to reject it. */
11380 return found_memory_cnt
;
11384 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11386 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11389 /* A helper function that looks for the "-location" argument and then
11390 calls watch_command_1. */
11393 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11395 int just_location
= 0;
11398 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11399 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11401 arg
= skip_spaces (arg
);
11405 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11409 watch_command (char *arg
, int from_tty
)
11411 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11415 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11417 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11421 rwatch_command (char *arg
, int from_tty
)
11423 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11427 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11429 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11433 awatch_command (char *arg
, int from_tty
)
11435 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11439 /* Data for the FSM that manages the until(location)/advance commands
11440 in infcmd.c. Here because it uses the mechanisms of
11443 struct until_break_fsm
11445 /* The base class. */
11446 struct thread_fsm thread_fsm
;
11448 /* The thread that as current when the command was executed. */
11451 /* The breakpoint set at the destination location. */
11452 struct breakpoint
*location_breakpoint
;
11454 /* Breakpoint set at the return address in the caller frame. May be
11456 struct breakpoint
*caller_breakpoint
;
11459 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11460 struct thread_info
*thread
);
11461 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11462 struct thread_info
*thread
);
11463 static enum async_reply_reason
11464 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11466 /* until_break_fsm's vtable. */
11468 static struct thread_fsm_ops until_break_fsm_ops
=
11471 until_break_fsm_clean_up
,
11472 until_break_fsm_should_stop
,
11473 NULL
, /* return_value */
11474 until_break_fsm_async_reply_reason
,
11477 /* Allocate a new until_break_command_fsm. */
11479 static struct until_break_fsm
*
11480 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11481 struct breakpoint
*location_breakpoint
,
11482 struct breakpoint
*caller_breakpoint
)
11484 struct until_break_fsm
*sm
;
11486 sm
= XCNEW (struct until_break_fsm
);
11487 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11489 sm
->thread
= thread
;
11490 sm
->location_breakpoint
= location_breakpoint
;
11491 sm
->caller_breakpoint
= caller_breakpoint
;
11496 /* Implementation of the 'should_stop' FSM method for the
11497 until(location)/advance commands. */
11500 until_break_fsm_should_stop (struct thread_fsm
*self
,
11501 struct thread_info
*tp
)
11503 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11505 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11506 sm
->location_breakpoint
) != NULL
11507 || (sm
->caller_breakpoint
!= NULL
11508 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11509 sm
->caller_breakpoint
) != NULL
))
11510 thread_fsm_set_finished (self
);
11515 /* Implementation of the 'clean_up' FSM method for the
11516 until(location)/advance commands. */
11519 until_break_fsm_clean_up (struct thread_fsm
*self
,
11520 struct thread_info
*thread
)
11522 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11524 /* Clean up our temporary breakpoints. */
11525 if (sm
->location_breakpoint
!= NULL
)
11527 delete_breakpoint (sm
->location_breakpoint
);
11528 sm
->location_breakpoint
= NULL
;
11530 if (sm
->caller_breakpoint
!= NULL
)
11532 delete_breakpoint (sm
->caller_breakpoint
);
11533 sm
->caller_breakpoint
= NULL
;
11535 delete_longjmp_breakpoint (sm
->thread
);
11538 /* Implementation of the 'async_reply_reason' FSM method for the
11539 until(location)/advance commands. */
11541 static enum async_reply_reason
11542 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11544 return EXEC_ASYNC_LOCATION_REACHED
;
11548 until_break_command (char *arg
, int from_tty
, int anywhere
)
11550 struct symtabs_and_lines sals
;
11551 struct symtab_and_line sal
;
11552 struct frame_info
*frame
;
11553 struct gdbarch
*frame_gdbarch
;
11554 struct frame_id stack_frame_id
;
11555 struct frame_id caller_frame_id
;
11556 struct breakpoint
*location_breakpoint
;
11557 struct breakpoint
*caller_breakpoint
= NULL
;
11558 struct cleanup
*old_chain
;
11560 struct thread_info
*tp
;
11561 struct until_break_fsm
*sm
;
11563 clear_proceed_status (0);
11565 /* Set a breakpoint where the user wants it and at return from
11568 event_location_up location
= string_to_event_location (&arg
, current_language
);
11570 if (last_displayed_sal_is_valid ())
11571 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11572 get_last_displayed_symtab (),
11573 get_last_displayed_line ());
11575 sals
= decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11576 NULL
, (struct symtab
*) NULL
, 0);
11578 if (sals
.nelts
!= 1)
11579 error (_("Couldn't get information on specified line."));
11581 sal
= sals
.sals
[0];
11582 xfree (sals
.sals
); /* malloc'd, so freed. */
11585 error (_("Junk at end of arguments."));
11587 resolve_sal_pc (&sal
);
11589 tp
= inferior_thread ();
11590 thread
= tp
->global_num
;
11592 old_chain
= make_cleanup (null_cleanup
, NULL
);
11594 /* Note linespec handling above invalidates the frame chain.
11595 Installing a breakpoint also invalidates the frame chain (as it
11596 may need to switch threads), so do any frame handling before
11599 frame
= get_selected_frame (NULL
);
11600 frame_gdbarch
= get_frame_arch (frame
);
11601 stack_frame_id
= get_stack_frame_id (frame
);
11602 caller_frame_id
= frame_unwind_caller_id (frame
);
11604 /* Keep within the current frame, or in frames called by the current
11607 if (frame_id_p (caller_frame_id
))
11609 struct symtab_and_line sal2
;
11610 struct gdbarch
*caller_gdbarch
;
11612 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11613 sal2
.pc
= frame_unwind_caller_pc (frame
);
11614 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11615 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11619 make_cleanup_delete_breakpoint (caller_breakpoint
);
11621 set_longjmp_breakpoint (tp
, caller_frame_id
);
11622 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11625 /* set_momentary_breakpoint could invalidate FRAME. */
11629 /* If the user told us to continue until a specified location,
11630 we don't specify a frame at which we need to stop. */
11631 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11632 null_frame_id
, bp_until
);
11634 /* Otherwise, specify the selected frame, because we want to stop
11635 only at the very same frame. */
11636 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11637 stack_frame_id
, bp_until
);
11638 make_cleanup_delete_breakpoint (location_breakpoint
);
11640 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11641 location_breakpoint
, caller_breakpoint
);
11642 tp
->thread_fsm
= &sm
->thread_fsm
;
11644 discard_cleanups (old_chain
);
11646 proceed (-1, GDB_SIGNAL_DEFAULT
);
11649 /* This function attempts to parse an optional "if <cond>" clause
11650 from the arg string. If one is not found, it returns NULL.
11652 Else, it returns a pointer to the condition string. (It does not
11653 attempt to evaluate the string against a particular block.) And,
11654 it updates arg to point to the first character following the parsed
11655 if clause in the arg string. */
11658 ep_parse_optional_if_clause (const char **arg
)
11660 const char *cond_string
;
11662 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11665 /* Skip the "if" keyword. */
11668 /* Skip any extra leading whitespace, and record the start of the
11669 condition string. */
11670 *arg
= skip_spaces_const (*arg
);
11671 cond_string
= *arg
;
11673 /* Assume that the condition occupies the remainder of the arg
11675 (*arg
) += strlen (cond_string
);
11677 return cond_string
;
11680 /* Commands to deal with catching events, such as signals, exceptions,
11681 process start/exit, etc. */
11685 catch_fork_temporary
, catch_vfork_temporary
,
11686 catch_fork_permanent
, catch_vfork_permanent
11691 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11692 struct cmd_list_element
*command
)
11694 const char *arg
= arg_entry
;
11695 struct gdbarch
*gdbarch
= get_current_arch ();
11696 const char *cond_string
= NULL
;
11697 catch_fork_kind fork_kind
;
11700 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11701 tempflag
= (fork_kind
== catch_fork_temporary
11702 || fork_kind
== catch_vfork_temporary
);
11706 arg
= skip_spaces_const (arg
);
11708 /* The allowed syntax is:
11710 catch [v]fork if <cond>
11712 First, check if there's an if clause. */
11713 cond_string
= ep_parse_optional_if_clause (&arg
);
11715 if ((*arg
!= '\0') && !isspace (*arg
))
11716 error (_("Junk at end of arguments."));
11718 /* If this target supports it, create a fork or vfork catchpoint
11719 and enable reporting of such events. */
11722 case catch_fork_temporary
:
11723 case catch_fork_permanent
:
11724 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11725 &catch_fork_breakpoint_ops
);
11727 case catch_vfork_temporary
:
11728 case catch_vfork_permanent
:
11729 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11730 &catch_vfork_breakpoint_ops
);
11733 error (_("unsupported or unknown fork kind; cannot catch it"));
11739 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11740 struct cmd_list_element
*command
)
11742 const char *arg
= arg_entry
;
11743 struct exec_catchpoint
*c
;
11744 struct gdbarch
*gdbarch
= get_current_arch ();
11746 const char *cond_string
= NULL
;
11748 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11752 arg
= skip_spaces_const (arg
);
11754 /* The allowed syntax is:
11756 catch exec if <cond>
11758 First, check if there's an if clause. */
11759 cond_string
= ep_parse_optional_if_clause (&arg
);
11761 if ((*arg
!= '\0') && !isspace (*arg
))
11762 error (_("Junk at end of arguments."));
11764 c
= new exec_catchpoint ();
11765 init_catchpoint (c
, gdbarch
, tempflag
, cond_string
,
11766 &catch_exec_breakpoint_ops
);
11767 c
->exec_pathname
= NULL
;
11769 install_breakpoint (0, c
, 1);
11773 init_ada_exception_breakpoint (struct breakpoint
*b
,
11774 struct gdbarch
*gdbarch
,
11775 struct symtab_and_line sal
,
11777 const struct breakpoint_ops
*ops
,
11784 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11786 loc_gdbarch
= gdbarch
;
11788 describe_other_breakpoints (loc_gdbarch
,
11789 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11790 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11791 version for exception catchpoints, because two catchpoints
11792 used for different exception names will use the same address.
11793 In this case, a "breakpoint ... also set at..." warning is
11794 unproductive. Besides, the warning phrasing is also a bit
11795 inappropriate, we should use the word catchpoint, and tell
11796 the user what type of catchpoint it is. The above is good
11797 enough for now, though. */
11800 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11802 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11803 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11804 b
->location
= string_to_event_location (&addr_string
,
11805 language_def (language_ada
));
11806 b
->language
= language_ada
;
11810 catch_command (char *arg
, int from_tty
)
11812 error (_("Catch requires an event name."));
11817 tcatch_command (char *arg
, int from_tty
)
11819 error (_("Catch requires an event name."));
11822 /* A qsort comparison function that sorts breakpoints in order. */
11825 compare_breakpoints (const void *a
, const void *b
)
11827 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11828 uintptr_t ua
= (uintptr_t) *ba
;
11829 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11830 uintptr_t ub
= (uintptr_t) *bb
;
11832 if ((*ba
)->number
< (*bb
)->number
)
11834 else if ((*ba
)->number
> (*bb
)->number
)
11837 /* Now sort by address, in case we see, e..g, two breakpoints with
11841 return ua
> ub
? 1 : 0;
11844 /* Delete breakpoints by address or line. */
11847 clear_command (char *arg
, int from_tty
)
11849 struct breakpoint
*b
, *prev
;
11850 VEC(breakpoint_p
) *found
= 0;
11853 struct symtabs_and_lines sals
;
11854 struct symtab_and_line sal
;
11856 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11860 sals
= decode_line_with_current_source (arg
,
11861 (DECODE_LINE_FUNFIRSTLINE
11862 | DECODE_LINE_LIST_MODE
));
11863 make_cleanup (xfree
, sals
.sals
);
11868 sals
.sals
= XNEW (struct symtab_and_line
);
11869 make_cleanup (xfree
, sals
.sals
);
11870 init_sal (&sal
); /* Initialize to zeroes. */
11872 /* Set sal's line, symtab, pc, and pspace to the values
11873 corresponding to the last call to print_frame_info. If the
11874 codepoint is not valid, this will set all the fields to 0. */
11875 get_last_displayed_sal (&sal
);
11876 if (sal
.symtab
== 0)
11877 error (_("No source file specified."));
11879 sals
.sals
[0] = sal
;
11885 /* We don't call resolve_sal_pc here. That's not as bad as it
11886 seems, because all existing breakpoints typically have both
11887 file/line and pc set. So, if clear is given file/line, we can
11888 match this to existing breakpoint without obtaining pc at all.
11890 We only support clearing given the address explicitly
11891 present in breakpoint table. Say, we've set breakpoint
11892 at file:line. There were several PC values for that file:line,
11893 due to optimization, all in one block.
11895 We've picked one PC value. If "clear" is issued with another
11896 PC corresponding to the same file:line, the breakpoint won't
11897 be cleared. We probably can still clear the breakpoint, but
11898 since the other PC value is never presented to user, user
11899 can only find it by guessing, and it does not seem important
11900 to support that. */
11902 /* For each line spec given, delete bps which correspond to it. Do
11903 it in two passes, solely to preserve the current behavior that
11904 from_tty is forced true if we delete more than one
11908 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11909 for (i
= 0; i
< sals
.nelts
; i
++)
11911 const char *sal_fullname
;
11913 /* If exact pc given, clear bpts at that pc.
11914 If line given (pc == 0), clear all bpts on specified line.
11915 If defaulting, clear all bpts on default line
11918 defaulting sal.pc != 0 tests to do
11923 1 0 <can't happen> */
11925 sal
= sals
.sals
[i
];
11926 sal_fullname
= (sal
.symtab
== NULL
11927 ? NULL
: symtab_to_fullname (sal
.symtab
));
11929 /* Find all matching breakpoints and add them to 'found'. */
11930 ALL_BREAKPOINTS (b
)
11933 /* Are we going to delete b? */
11934 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11936 struct bp_location
*loc
= b
->loc
;
11937 for (; loc
; loc
= loc
->next
)
11939 /* If the user specified file:line, don't allow a PC
11940 match. This matches historical gdb behavior. */
11941 int pc_match
= (!sal
.explicit_line
11943 && (loc
->pspace
== sal
.pspace
)
11944 && (loc
->address
== sal
.pc
)
11945 && (!section_is_overlay (loc
->section
)
11946 || loc
->section
== sal
.section
));
11947 int line_match
= 0;
11949 if ((default_match
|| sal
.explicit_line
)
11950 && loc
->symtab
!= NULL
11951 && sal_fullname
!= NULL
11952 && sal
.pspace
== loc
->pspace
11953 && loc
->line_number
== sal
.line
11954 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11955 sal_fullname
) == 0)
11958 if (pc_match
|| line_match
)
11967 VEC_safe_push(breakpoint_p
, found
, b
);
11971 /* Now go thru the 'found' chain and delete them. */
11972 if (VEC_empty(breakpoint_p
, found
))
11975 error (_("No breakpoint at %s."), arg
);
11977 error (_("No breakpoint at this line."));
11980 /* Remove duplicates from the vec. */
11981 qsort (VEC_address (breakpoint_p
, found
),
11982 VEC_length (breakpoint_p
, found
),
11983 sizeof (breakpoint_p
),
11984 compare_breakpoints
);
11985 prev
= VEC_index (breakpoint_p
, found
, 0);
11986 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11990 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11995 if (VEC_length(breakpoint_p
, found
) > 1)
11996 from_tty
= 1; /* Always report if deleted more than one. */
11999 if (VEC_length(breakpoint_p
, found
) == 1)
12000 printf_unfiltered (_("Deleted breakpoint "));
12002 printf_unfiltered (_("Deleted breakpoints "));
12005 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12008 printf_unfiltered ("%d ", b
->number
);
12009 delete_breakpoint (b
);
12012 putchar_unfiltered ('\n');
12014 do_cleanups (cleanups
);
12017 /* Delete breakpoint in BS if they are `delete' breakpoints and
12018 all breakpoints that are marked for deletion, whether hit or not.
12019 This is called after any breakpoint is hit, or after errors. */
12022 breakpoint_auto_delete (bpstat bs
)
12024 struct breakpoint
*b
, *b_tmp
;
12026 for (; bs
; bs
= bs
->next
)
12027 if (bs
->breakpoint_at
12028 && bs
->breakpoint_at
->disposition
== disp_del
12030 delete_breakpoint (bs
->breakpoint_at
);
12032 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12034 if (b
->disposition
== disp_del_at_next_stop
)
12035 delete_breakpoint (b
);
12039 /* A comparison function for bp_location AP and BP being interfaced to
12040 qsort. Sort elements primarily by their ADDRESS (no matter what
12041 does breakpoint_address_is_meaningful say for its OWNER),
12042 secondarily by ordering first permanent elements and
12043 terciarily just ensuring the array is sorted stable way despite
12044 qsort being an unstable algorithm. */
12047 bp_locations_compare (const void *ap
, const void *bp
)
12049 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12050 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12052 if (a
->address
!= b
->address
)
12053 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12055 /* Sort locations at the same address by their pspace number, keeping
12056 locations of the same inferior (in a multi-inferior environment)
12059 if (a
->pspace
->num
!= b
->pspace
->num
)
12060 return ((a
->pspace
->num
> b
->pspace
->num
)
12061 - (a
->pspace
->num
< b
->pspace
->num
));
12063 /* Sort permanent breakpoints first. */
12064 if (a
->permanent
!= b
->permanent
)
12065 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12067 /* Make the internal GDB representation stable across GDB runs
12068 where A and B memory inside GDB can differ. Breakpoint locations of
12069 the same type at the same address can be sorted in arbitrary order. */
12071 if (a
->owner
->number
!= b
->owner
->number
)
12072 return ((a
->owner
->number
> b
->owner
->number
)
12073 - (a
->owner
->number
< b
->owner
->number
));
12075 return (a
> b
) - (a
< b
);
12078 /* Set bp_locations_placed_address_before_address_max and
12079 bp_locations_shadow_len_after_address_max according to the current
12080 content of the bp_locations array. */
12083 bp_locations_target_extensions_update (void)
12085 struct bp_location
*bl
, **blp_tmp
;
12087 bp_locations_placed_address_before_address_max
= 0;
12088 bp_locations_shadow_len_after_address_max
= 0;
12090 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12092 CORE_ADDR start
, end
, addr
;
12094 if (!bp_location_has_shadow (bl
))
12097 start
= bl
->target_info
.placed_address
;
12098 end
= start
+ bl
->target_info
.shadow_len
;
12100 gdb_assert (bl
->address
>= start
);
12101 addr
= bl
->address
- start
;
12102 if (addr
> bp_locations_placed_address_before_address_max
)
12103 bp_locations_placed_address_before_address_max
= addr
;
12105 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12107 gdb_assert (bl
->address
< end
);
12108 addr
= end
- bl
->address
;
12109 if (addr
> bp_locations_shadow_len_after_address_max
)
12110 bp_locations_shadow_len_after_address_max
= addr
;
12114 /* Download tracepoint locations if they haven't been. */
12117 download_tracepoint_locations (void)
12119 struct breakpoint
*b
;
12120 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12122 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12124 ALL_TRACEPOINTS (b
)
12126 struct bp_location
*bl
;
12127 struct tracepoint
*t
;
12128 int bp_location_downloaded
= 0;
12130 if ((b
->type
== bp_fast_tracepoint
12131 ? !may_insert_fast_tracepoints
12132 : !may_insert_tracepoints
))
12135 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12137 if (target_can_download_tracepoint ())
12138 can_download_tracepoint
= TRIBOOL_TRUE
;
12140 can_download_tracepoint
= TRIBOOL_FALSE
;
12143 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12146 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12148 /* In tracepoint, locations are _never_ duplicated, so
12149 should_be_inserted is equivalent to
12150 unduplicated_should_be_inserted. */
12151 if (!should_be_inserted (bl
) || bl
->inserted
)
12154 switch_to_program_space_and_thread (bl
->pspace
);
12156 target_download_tracepoint (bl
);
12159 bp_location_downloaded
= 1;
12161 t
= (struct tracepoint
*) b
;
12162 t
->number_on_target
= b
->number
;
12163 if (bp_location_downloaded
)
12164 observer_notify_breakpoint_modified (b
);
12168 /* Swap the insertion/duplication state between two locations. */
12171 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12173 const int left_inserted
= left
->inserted
;
12174 const int left_duplicate
= left
->duplicate
;
12175 const int left_needs_update
= left
->needs_update
;
12176 const struct bp_target_info left_target_info
= left
->target_info
;
12178 /* Locations of tracepoints can never be duplicated. */
12179 if (is_tracepoint (left
->owner
))
12180 gdb_assert (!left
->duplicate
);
12181 if (is_tracepoint (right
->owner
))
12182 gdb_assert (!right
->duplicate
);
12184 left
->inserted
= right
->inserted
;
12185 left
->duplicate
= right
->duplicate
;
12186 left
->needs_update
= right
->needs_update
;
12187 left
->target_info
= right
->target_info
;
12188 right
->inserted
= left_inserted
;
12189 right
->duplicate
= left_duplicate
;
12190 right
->needs_update
= left_needs_update
;
12191 right
->target_info
= left_target_info
;
12194 /* Force the re-insertion of the locations at ADDRESS. This is called
12195 once a new/deleted/modified duplicate location is found and we are evaluating
12196 conditions on the target's side. Such conditions need to be updated on
12200 force_breakpoint_reinsertion (struct bp_location
*bl
)
12202 struct bp_location
**locp
= NULL
, **loc2p
;
12203 struct bp_location
*loc
;
12204 CORE_ADDR address
= 0;
12207 address
= bl
->address
;
12208 pspace_num
= bl
->pspace
->num
;
12210 /* This is only meaningful if the target is
12211 evaluating conditions and if the user has
12212 opted for condition evaluation on the target's
12214 if (gdb_evaluates_breakpoint_condition_p ()
12215 || !target_supports_evaluation_of_breakpoint_conditions ())
12218 /* Flag all breakpoint locations with this address and
12219 the same program space as the location
12220 as "its condition has changed". We need to
12221 update the conditions on the target's side. */
12222 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12226 if (!is_breakpoint (loc
->owner
)
12227 || pspace_num
!= loc
->pspace
->num
)
12230 /* Flag the location appropriately. We use a different state to
12231 let everyone know that we already updated the set of locations
12232 with addr bl->address and program space bl->pspace. This is so
12233 we don't have to keep calling these functions just to mark locations
12234 that have already been marked. */
12235 loc
->condition_changed
= condition_updated
;
12237 /* Free the agent expression bytecode as well. We will compute
12239 loc
->cond_bytecode
.reset ();
12242 /* Called whether new breakpoints are created, or existing breakpoints
12243 deleted, to update the global location list and recompute which
12244 locations are duplicate of which.
12246 The INSERT_MODE flag determines whether locations may not, may, or
12247 shall be inserted now. See 'enum ugll_insert_mode' for more
12251 update_global_location_list (enum ugll_insert_mode insert_mode
)
12253 struct breakpoint
*b
;
12254 struct bp_location
**locp
, *loc
;
12255 struct cleanup
*cleanups
;
12256 /* Last breakpoint location address that was marked for update. */
12257 CORE_ADDR last_addr
= 0;
12258 /* Last breakpoint location program space that was marked for update. */
12259 int last_pspace_num
= -1;
12261 /* Used in the duplicates detection below. When iterating over all
12262 bp_locations, points to the first bp_location of a given address.
12263 Breakpoints and watchpoints of different types are never
12264 duplicates of each other. Keep one pointer for each type of
12265 breakpoint/watchpoint, so we only need to loop over all locations
12267 struct bp_location
*bp_loc_first
; /* breakpoint */
12268 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12269 struct bp_location
*awp_loc_first
; /* access watchpoint */
12270 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12272 /* Saved former bp_locations array which we compare against the newly
12273 built bp_locations from the current state of ALL_BREAKPOINTS. */
12274 struct bp_location
**old_locations
, **old_locp
;
12275 unsigned old_locations_count
;
12277 old_locations
= bp_locations
;
12278 old_locations_count
= bp_locations_count
;
12279 bp_locations
= NULL
;
12280 bp_locations_count
= 0;
12281 cleanups
= make_cleanup (xfree
, old_locations
);
12283 ALL_BREAKPOINTS (b
)
12284 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12285 bp_locations_count
++;
12287 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12288 locp
= bp_locations
;
12289 ALL_BREAKPOINTS (b
)
12290 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12292 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12293 bp_locations_compare
);
12295 bp_locations_target_extensions_update ();
12297 /* Identify bp_location instances that are no longer present in the
12298 new list, and therefore should be freed. Note that it's not
12299 necessary that those locations should be removed from inferior --
12300 if there's another location at the same address (previously
12301 marked as duplicate), we don't need to remove/insert the
12304 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12305 and former bp_location array state respectively. */
12307 locp
= bp_locations
;
12308 for (old_locp
= old_locations
;
12309 old_locp
< old_locations
+ old_locations_count
;
12312 struct bp_location
*old_loc
= *old_locp
;
12313 struct bp_location
**loc2p
;
12315 /* Tells if 'old_loc' is found among the new locations. If
12316 not, we have to free it. */
12317 int found_object
= 0;
12318 /* Tells if the location should remain inserted in the target. */
12319 int keep_in_target
= 0;
12322 /* Skip LOCP entries which will definitely never be needed.
12323 Stop either at or being the one matching OLD_LOC. */
12324 while (locp
< bp_locations
+ bp_locations_count
12325 && (*locp
)->address
< old_loc
->address
)
12329 (loc2p
< bp_locations
+ bp_locations_count
12330 && (*loc2p
)->address
== old_loc
->address
);
12333 /* Check if this is a new/duplicated location or a duplicated
12334 location that had its condition modified. If so, we want to send
12335 its condition to the target if evaluation of conditions is taking
12337 if ((*loc2p
)->condition_changed
== condition_modified
12338 && (last_addr
!= old_loc
->address
12339 || last_pspace_num
!= old_loc
->pspace
->num
))
12341 force_breakpoint_reinsertion (*loc2p
);
12342 last_pspace_num
= old_loc
->pspace
->num
;
12345 if (*loc2p
== old_loc
)
12349 /* We have already handled this address, update it so that we don't
12350 have to go through updates again. */
12351 last_addr
= old_loc
->address
;
12353 /* Target-side condition evaluation: Handle deleted locations. */
12355 force_breakpoint_reinsertion (old_loc
);
12357 /* If this location is no longer present, and inserted, look if
12358 there's maybe a new location at the same address. If so,
12359 mark that one inserted, and don't remove this one. This is
12360 needed so that we don't have a time window where a breakpoint
12361 at certain location is not inserted. */
12363 if (old_loc
->inserted
)
12365 /* If the location is inserted now, we might have to remove
12368 if (found_object
&& should_be_inserted (old_loc
))
12370 /* The location is still present in the location list,
12371 and still should be inserted. Don't do anything. */
12372 keep_in_target
= 1;
12376 /* This location still exists, but it won't be kept in the
12377 target since it may have been disabled. We proceed to
12378 remove its target-side condition. */
12380 /* The location is either no longer present, or got
12381 disabled. See if there's another location at the
12382 same address, in which case we don't need to remove
12383 this one from the target. */
12385 /* OLD_LOC comes from existing struct breakpoint. */
12386 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12389 (loc2p
< bp_locations
+ bp_locations_count
12390 && (*loc2p
)->address
== old_loc
->address
);
12393 struct bp_location
*loc2
= *loc2p
;
12395 if (breakpoint_locations_match (loc2
, old_loc
))
12397 /* Read watchpoint locations are switched to
12398 access watchpoints, if the former are not
12399 supported, but the latter are. */
12400 if (is_hardware_watchpoint (old_loc
->owner
))
12402 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12403 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12406 /* loc2 is a duplicated location. We need to check
12407 if it should be inserted in case it will be
12409 if (loc2
!= old_loc
12410 && unduplicated_should_be_inserted (loc2
))
12412 swap_insertion (old_loc
, loc2
);
12413 keep_in_target
= 1;
12421 if (!keep_in_target
)
12423 if (remove_breakpoint (old_loc
))
12425 /* This is just about all we can do. We could keep
12426 this location on the global list, and try to
12427 remove it next time, but there's no particular
12428 reason why we will succeed next time.
12430 Note that at this point, old_loc->owner is still
12431 valid, as delete_breakpoint frees the breakpoint
12432 only after calling us. */
12433 printf_filtered (_("warning: Error removing "
12434 "breakpoint %d\n"),
12435 old_loc
->owner
->number
);
12443 if (removed
&& target_is_non_stop_p ()
12444 && need_moribund_for_location_type (old_loc
))
12446 /* This location was removed from the target. In
12447 non-stop mode, a race condition is possible where
12448 we've removed a breakpoint, but stop events for that
12449 breakpoint are already queued and will arrive later.
12450 We apply an heuristic to be able to distinguish such
12451 SIGTRAPs from other random SIGTRAPs: we keep this
12452 breakpoint location for a bit, and will retire it
12453 after we see some number of events. The theory here
12454 is that reporting of events should, "on the average",
12455 be fair, so after a while we'll see events from all
12456 threads that have anything of interest, and no longer
12457 need to keep this breakpoint location around. We
12458 don't hold locations forever so to reduce chances of
12459 mistaking a non-breakpoint SIGTRAP for a breakpoint
12462 The heuristic failing can be disastrous on
12463 decr_pc_after_break targets.
12465 On decr_pc_after_break targets, like e.g., x86-linux,
12466 if we fail to recognize a late breakpoint SIGTRAP,
12467 because events_till_retirement has reached 0 too
12468 soon, we'll fail to do the PC adjustment, and report
12469 a random SIGTRAP to the user. When the user resumes
12470 the inferior, it will most likely immediately crash
12471 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12472 corrupted, because of being resumed e.g., in the
12473 middle of a multi-byte instruction, or skipped a
12474 one-byte instruction. This was actually seen happen
12475 on native x86-linux, and should be less rare on
12476 targets that do not support new thread events, like
12477 remote, due to the heuristic depending on
12480 Mistaking a random SIGTRAP for a breakpoint trap
12481 causes similar symptoms (PC adjustment applied when
12482 it shouldn't), but then again, playing with SIGTRAPs
12483 behind the debugger's back is asking for trouble.
12485 Since hardware watchpoint traps are always
12486 distinguishable from other traps, so we don't need to
12487 apply keep hardware watchpoint moribund locations
12488 around. We simply always ignore hardware watchpoint
12489 traps we can no longer explain. */
12491 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12492 old_loc
->owner
= NULL
;
12494 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12498 old_loc
->owner
= NULL
;
12499 decref_bp_location (&old_loc
);
12504 /* Rescan breakpoints at the same address and section, marking the
12505 first one as "first" and any others as "duplicates". This is so
12506 that the bpt instruction is only inserted once. If we have a
12507 permanent breakpoint at the same place as BPT, make that one the
12508 official one, and the rest as duplicates. Permanent breakpoints
12509 are sorted first for the same address.
12511 Do the same for hardware watchpoints, but also considering the
12512 watchpoint's type (regular/access/read) and length. */
12514 bp_loc_first
= NULL
;
12515 wp_loc_first
= NULL
;
12516 awp_loc_first
= NULL
;
12517 rwp_loc_first
= NULL
;
12518 ALL_BP_LOCATIONS (loc
, locp
)
12520 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12522 struct bp_location
**loc_first_p
;
12525 if (!unduplicated_should_be_inserted (loc
)
12526 || !breakpoint_address_is_meaningful (b
)
12527 /* Don't detect duplicate for tracepoint locations because they are
12528 never duplicated. See the comments in field `duplicate' of
12529 `struct bp_location'. */
12530 || is_tracepoint (b
))
12532 /* Clear the condition modification flag. */
12533 loc
->condition_changed
= condition_unchanged
;
12537 if (b
->type
== bp_hardware_watchpoint
)
12538 loc_first_p
= &wp_loc_first
;
12539 else if (b
->type
== bp_read_watchpoint
)
12540 loc_first_p
= &rwp_loc_first
;
12541 else if (b
->type
== bp_access_watchpoint
)
12542 loc_first_p
= &awp_loc_first
;
12544 loc_first_p
= &bp_loc_first
;
12546 if (*loc_first_p
== NULL
12547 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12548 || !breakpoint_locations_match (loc
, *loc_first_p
))
12550 *loc_first_p
= loc
;
12551 loc
->duplicate
= 0;
12553 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12555 loc
->needs_update
= 1;
12556 /* Clear the condition modification flag. */
12557 loc
->condition_changed
= condition_unchanged
;
12563 /* This and the above ensure the invariant that the first location
12564 is not duplicated, and is the inserted one.
12565 All following are marked as duplicated, and are not inserted. */
12567 swap_insertion (loc
, *loc_first_p
);
12568 loc
->duplicate
= 1;
12570 /* Clear the condition modification flag. */
12571 loc
->condition_changed
= condition_unchanged
;
12574 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12576 if (insert_mode
!= UGLL_DONT_INSERT
)
12577 insert_breakpoint_locations ();
12580 /* Even though the caller told us to not insert new
12581 locations, we may still need to update conditions on the
12582 target's side of breakpoints that were already inserted
12583 if the target is evaluating breakpoint conditions. We
12584 only update conditions for locations that are marked
12586 update_inserted_breakpoint_locations ();
12590 if (insert_mode
!= UGLL_DONT_INSERT
)
12591 download_tracepoint_locations ();
12593 do_cleanups (cleanups
);
12597 breakpoint_retire_moribund (void)
12599 struct bp_location
*loc
;
12602 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12603 if (--(loc
->events_till_retirement
) == 0)
12605 decref_bp_location (&loc
);
12606 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12612 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12617 update_global_location_list (insert_mode
);
12619 CATCH (e
, RETURN_MASK_ERROR
)
12625 /* Clear BKP from a BPS. */
12628 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12632 for (bs
= bps
; bs
; bs
= bs
->next
)
12633 if (bs
->breakpoint_at
== bpt
)
12635 bs
->breakpoint_at
= NULL
;
12636 bs
->old_val
= NULL
;
12637 /* bs->commands will be freed later. */
12641 /* Callback for iterate_over_threads. */
12643 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12645 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12647 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12651 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12655 say_where (struct breakpoint
*b
)
12657 struct value_print_options opts
;
12659 get_user_print_options (&opts
);
12661 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12663 if (b
->loc
== NULL
)
12665 /* For pending locations, the output differs slightly based
12666 on b->extra_string. If this is non-NULL, it contains either
12667 a condition or dprintf arguments. */
12668 if (b
->extra_string
== NULL
)
12670 printf_filtered (_(" (%s) pending."),
12671 event_location_to_string (b
->location
.get ()));
12673 else if (b
->type
== bp_dprintf
)
12675 printf_filtered (_(" (%s,%s) pending."),
12676 event_location_to_string (b
->location
.get ()),
12681 printf_filtered (_(" (%s %s) pending."),
12682 event_location_to_string (b
->location
.get ()),
12688 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12690 printf_filtered (" at ");
12691 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12694 if (b
->loc
->symtab
!= NULL
)
12696 /* If there is a single location, we can print the location
12698 if (b
->loc
->next
== NULL
)
12699 printf_filtered (": file %s, line %d.",
12700 symtab_to_filename_for_display (b
->loc
->symtab
),
12701 b
->loc
->line_number
);
12703 /* This is not ideal, but each location may have a
12704 different file name, and this at least reflects the
12705 real situation somewhat. */
12706 printf_filtered (": %s.",
12707 event_location_to_string (b
->location
.get ()));
12712 struct bp_location
*loc
= b
->loc
;
12714 for (; loc
; loc
= loc
->next
)
12716 printf_filtered (" (%d locations)", n
);
12721 /* Default bp_location_ops methods. */
12724 bp_location_dtor (struct bp_location
*self
)
12726 xfree (self
->function_name
);
12729 static const struct bp_location_ops bp_location_ops
=
12734 /* Destructor for the breakpoint base class. */
12736 breakpoint::~breakpoint ()
12738 decref_counted_command_line (&this->commands
);
12739 xfree (this->cond_string
);
12740 xfree (this->extra_string
);
12741 xfree (this->filter
);
12744 static struct bp_location
*
12745 base_breakpoint_allocate_location (struct breakpoint
*self
)
12747 return new bp_location (&bp_location_ops
, self
);
12751 base_breakpoint_re_set (struct breakpoint
*b
)
12753 /* Nothing to re-set. */
12756 #define internal_error_pure_virtual_called() \
12757 gdb_assert_not_reached ("pure virtual function called")
12760 base_breakpoint_insert_location (struct bp_location
*bl
)
12762 internal_error_pure_virtual_called ();
12766 base_breakpoint_remove_location (struct bp_location
*bl
,
12767 enum remove_bp_reason reason
)
12769 internal_error_pure_virtual_called ();
12773 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12774 struct address_space
*aspace
,
12776 const struct target_waitstatus
*ws
)
12778 internal_error_pure_virtual_called ();
12782 base_breakpoint_check_status (bpstat bs
)
12787 /* A "works_in_software_mode" breakpoint_ops method that just internal
12791 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12793 internal_error_pure_virtual_called ();
12796 /* A "resources_needed" breakpoint_ops method that just internal
12800 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12802 internal_error_pure_virtual_called ();
12805 static enum print_stop_action
12806 base_breakpoint_print_it (bpstat bs
)
12808 internal_error_pure_virtual_called ();
12812 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12813 struct ui_out
*uiout
)
12819 base_breakpoint_print_mention (struct breakpoint
*b
)
12821 internal_error_pure_virtual_called ();
12825 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12827 internal_error_pure_virtual_called ();
12831 base_breakpoint_create_sals_from_location
12832 (const struct event_location
*location
,
12833 struct linespec_result
*canonical
,
12834 enum bptype type_wanted
)
12836 internal_error_pure_virtual_called ();
12840 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12841 struct linespec_result
*c
,
12843 char *extra_string
,
12844 enum bptype type_wanted
,
12845 enum bpdisp disposition
,
12847 int task
, int ignore_count
,
12848 const struct breakpoint_ops
*o
,
12849 int from_tty
, int enabled
,
12850 int internal
, unsigned flags
)
12852 internal_error_pure_virtual_called ();
12856 base_breakpoint_decode_location (struct breakpoint
*b
,
12857 const struct event_location
*location
,
12858 struct program_space
*search_pspace
,
12859 struct symtabs_and_lines
*sals
)
12861 internal_error_pure_virtual_called ();
12864 /* The default 'explains_signal' method. */
12867 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12872 /* The default "after_condition_true" method. */
12875 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12877 /* Nothing to do. */
12880 struct breakpoint_ops base_breakpoint_ops
=
12882 base_breakpoint_allocate_location
,
12883 base_breakpoint_re_set
,
12884 base_breakpoint_insert_location
,
12885 base_breakpoint_remove_location
,
12886 base_breakpoint_breakpoint_hit
,
12887 base_breakpoint_check_status
,
12888 base_breakpoint_resources_needed
,
12889 base_breakpoint_works_in_software_mode
,
12890 base_breakpoint_print_it
,
12892 base_breakpoint_print_one_detail
,
12893 base_breakpoint_print_mention
,
12894 base_breakpoint_print_recreate
,
12895 base_breakpoint_create_sals_from_location
,
12896 base_breakpoint_create_breakpoints_sal
,
12897 base_breakpoint_decode_location
,
12898 base_breakpoint_explains_signal
,
12899 base_breakpoint_after_condition_true
,
12902 /* Default breakpoint_ops methods. */
12905 bkpt_re_set (struct breakpoint
*b
)
12907 /* FIXME: is this still reachable? */
12908 if (breakpoint_event_location_empty_p (b
))
12910 /* Anything without a location can't be re-set. */
12911 delete_breakpoint (b
);
12915 breakpoint_re_set_default (b
);
12919 bkpt_insert_location (struct bp_location
*bl
)
12921 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12923 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12924 bl
->target_info
.placed_address
= addr
;
12926 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12927 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12929 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12933 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12935 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12936 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12938 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12942 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12943 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12944 const struct target_waitstatus
*ws
)
12946 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12947 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12950 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12954 if (overlay_debugging
/* unmapped overlay section */
12955 && section_is_overlay (bl
->section
)
12956 && !section_is_mapped (bl
->section
))
12963 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12964 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12965 const struct target_waitstatus
*ws
)
12967 if (dprintf_style
== dprintf_style_agent
12968 && target_can_run_breakpoint_commands ())
12970 /* An agent-style dprintf never causes a stop. If we see a trap
12971 for this address it must be for a breakpoint that happens to
12972 be set at the same address. */
12976 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12980 bkpt_resources_needed (const struct bp_location
*bl
)
12982 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12987 static enum print_stop_action
12988 bkpt_print_it (bpstat bs
)
12990 struct breakpoint
*b
;
12991 const struct bp_location
*bl
;
12993 struct ui_out
*uiout
= current_uiout
;
12995 gdb_assert (bs
->bp_location_at
!= NULL
);
12997 bl
= bs
->bp_location_at
;
12998 b
= bs
->breakpoint_at
;
13000 bp_temp
= b
->disposition
== disp_del
;
13001 if (bl
->address
!= bl
->requested_address
)
13002 breakpoint_adjustment_warning (bl
->requested_address
,
13005 annotate_breakpoint (b
->number
);
13006 maybe_print_thread_hit_breakpoint (uiout
);
13009 uiout
->text ("Temporary breakpoint ");
13011 uiout
->text ("Breakpoint ");
13012 if (uiout
->is_mi_like_p ())
13014 uiout
->field_string ("reason",
13015 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13016 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
13018 uiout
->field_int ("bkptno", b
->number
);
13019 uiout
->text (", ");
13021 return PRINT_SRC_AND_LOC
;
13025 bkpt_print_mention (struct breakpoint
*b
)
13027 if (current_uiout
->is_mi_like_p ())
13032 case bp_breakpoint
:
13033 case bp_gnu_ifunc_resolver
:
13034 if (b
->disposition
== disp_del
)
13035 printf_filtered (_("Temporary breakpoint"));
13037 printf_filtered (_("Breakpoint"));
13038 printf_filtered (_(" %d"), b
->number
);
13039 if (b
->type
== bp_gnu_ifunc_resolver
)
13040 printf_filtered (_(" at gnu-indirect-function resolver"));
13042 case bp_hardware_breakpoint
:
13043 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13046 printf_filtered (_("Dprintf %d"), b
->number
);
13054 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13056 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13057 fprintf_unfiltered (fp
, "tbreak");
13058 else if (tp
->type
== bp_breakpoint
)
13059 fprintf_unfiltered (fp
, "break");
13060 else if (tp
->type
== bp_hardware_breakpoint
13061 && tp
->disposition
== disp_del
)
13062 fprintf_unfiltered (fp
, "thbreak");
13063 else if (tp
->type
== bp_hardware_breakpoint
)
13064 fprintf_unfiltered (fp
, "hbreak");
13066 internal_error (__FILE__
, __LINE__
,
13067 _("unhandled breakpoint type %d"), (int) tp
->type
);
13069 fprintf_unfiltered (fp
, " %s",
13070 event_location_to_string (tp
->location
.get ()));
13072 /* Print out extra_string if this breakpoint is pending. It might
13073 contain, for example, conditions that were set by the user. */
13074 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13075 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13077 print_recreate_thread (tp
, fp
);
13081 bkpt_create_sals_from_location (const struct event_location
*location
,
13082 struct linespec_result
*canonical
,
13083 enum bptype type_wanted
)
13085 create_sals_from_location_default (location
, canonical
, type_wanted
);
13089 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13090 struct linespec_result
*canonical
,
13092 char *extra_string
,
13093 enum bptype type_wanted
,
13094 enum bpdisp disposition
,
13096 int task
, int ignore_count
,
13097 const struct breakpoint_ops
*ops
,
13098 int from_tty
, int enabled
,
13099 int internal
, unsigned flags
)
13101 create_breakpoints_sal_default (gdbarch
, canonical
,
13102 cond_string
, extra_string
,
13104 disposition
, thread
, task
,
13105 ignore_count
, ops
, from_tty
,
13106 enabled
, internal
, flags
);
13110 bkpt_decode_location (struct breakpoint
*b
,
13111 const struct event_location
*location
,
13112 struct program_space
*search_pspace
,
13113 struct symtabs_and_lines
*sals
)
13115 decode_location_default (b
, location
, search_pspace
, sals
);
13118 /* Virtual table for internal breakpoints. */
13121 internal_bkpt_re_set (struct breakpoint
*b
)
13125 /* Delete overlay event and longjmp master breakpoints; they
13126 will be reset later by breakpoint_re_set. */
13127 case bp_overlay_event
:
13128 case bp_longjmp_master
:
13129 case bp_std_terminate_master
:
13130 case bp_exception_master
:
13131 delete_breakpoint (b
);
13134 /* This breakpoint is special, it's set up when the inferior
13135 starts and we really don't want to touch it. */
13136 case bp_shlib_event
:
13138 /* Like bp_shlib_event, this breakpoint type is special. Once
13139 it is set up, we do not want to touch it. */
13140 case bp_thread_event
:
13146 internal_bkpt_check_status (bpstat bs
)
13148 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13150 /* If requested, stop when the dynamic linker notifies GDB of
13151 events. This allows the user to get control and place
13152 breakpoints in initializer routines for dynamically loaded
13153 objects (among other things). */
13154 bs
->stop
= stop_on_solib_events
;
13155 bs
->print
= stop_on_solib_events
;
13161 static enum print_stop_action
13162 internal_bkpt_print_it (bpstat bs
)
13164 struct breakpoint
*b
;
13166 b
= bs
->breakpoint_at
;
13170 case bp_shlib_event
:
13171 /* Did we stop because the user set the stop_on_solib_events
13172 variable? (If so, we report this as a generic, "Stopped due
13173 to shlib event" message.) */
13174 print_solib_event (0);
13177 case bp_thread_event
:
13178 /* Not sure how we will get here.
13179 GDB should not stop for these breakpoints. */
13180 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13183 case bp_overlay_event
:
13184 /* By analogy with the thread event, GDB should not stop for these. */
13185 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13188 case bp_longjmp_master
:
13189 /* These should never be enabled. */
13190 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13193 case bp_std_terminate_master
:
13194 /* These should never be enabled. */
13195 printf_filtered (_("std::terminate Master Breakpoint: "
13196 "gdb should not stop!\n"));
13199 case bp_exception_master
:
13200 /* These should never be enabled. */
13201 printf_filtered (_("Exception Master Breakpoint: "
13202 "gdb should not stop!\n"));
13206 return PRINT_NOTHING
;
13210 internal_bkpt_print_mention (struct breakpoint
*b
)
13212 /* Nothing to mention. These breakpoints are internal. */
13215 /* Virtual table for momentary breakpoints */
13218 momentary_bkpt_re_set (struct breakpoint
*b
)
13220 /* Keep temporary breakpoints, which can be encountered when we step
13221 over a dlopen call and solib_add is resetting the breakpoints.
13222 Otherwise these should have been blown away via the cleanup chain
13223 or by breakpoint_init_inferior when we rerun the executable. */
13227 momentary_bkpt_check_status (bpstat bs
)
13229 /* Nothing. The point of these breakpoints is causing a stop. */
13232 static enum print_stop_action
13233 momentary_bkpt_print_it (bpstat bs
)
13235 return PRINT_UNKNOWN
;
13239 momentary_bkpt_print_mention (struct breakpoint
*b
)
13241 /* Nothing to mention. These breakpoints are internal. */
13244 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13246 It gets cleared already on the removal of the first one of such placed
13247 breakpoints. This is OK as they get all removed altogether. */
13249 longjmp_breakpoint::~longjmp_breakpoint ()
13251 thread_info
*tp
= find_thread_global_id (this->thread
);
13254 tp
->initiating_frame
= null_frame_id
;
13257 /* Specific methods for probe breakpoints. */
13260 bkpt_probe_insert_location (struct bp_location
*bl
)
13262 int v
= bkpt_insert_location (bl
);
13266 /* The insertion was successful, now let's set the probe's semaphore
13268 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13269 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13278 bkpt_probe_remove_location (struct bp_location
*bl
,
13279 enum remove_bp_reason reason
)
13281 /* Let's clear the semaphore before removing the location. */
13282 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13283 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13287 return bkpt_remove_location (bl
, reason
);
13291 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13292 struct linespec_result
*canonical
,
13293 enum bptype type_wanted
)
13295 struct linespec_sals lsal
;
13297 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13299 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13300 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13304 bkpt_probe_decode_location (struct breakpoint
*b
,
13305 const struct event_location
*location
,
13306 struct program_space
*search_pspace
,
13307 struct symtabs_and_lines
*sals
)
13309 *sals
= parse_probes (location
, search_pspace
, NULL
);
13311 error (_("probe not found"));
13314 /* The breakpoint_ops structure to be used in tracepoints. */
13317 tracepoint_re_set (struct breakpoint
*b
)
13319 breakpoint_re_set_default (b
);
13323 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13324 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13325 const struct target_waitstatus
*ws
)
13327 /* By definition, the inferior does not report stops at
13333 tracepoint_print_one_detail (const struct breakpoint
*self
,
13334 struct ui_out
*uiout
)
13336 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13337 if (tp
->static_trace_marker_id
)
13339 gdb_assert (self
->type
== bp_static_tracepoint
);
13341 uiout
->text ("\tmarker id is ");
13342 uiout
->field_string ("static-tracepoint-marker-string-id",
13343 tp
->static_trace_marker_id
);
13344 uiout
->text ("\n");
13349 tracepoint_print_mention (struct breakpoint
*b
)
13351 if (current_uiout
->is_mi_like_p ())
13356 case bp_tracepoint
:
13357 printf_filtered (_("Tracepoint"));
13358 printf_filtered (_(" %d"), b
->number
);
13360 case bp_fast_tracepoint
:
13361 printf_filtered (_("Fast tracepoint"));
13362 printf_filtered (_(" %d"), b
->number
);
13364 case bp_static_tracepoint
:
13365 printf_filtered (_("Static tracepoint"));
13366 printf_filtered (_(" %d"), b
->number
);
13369 internal_error (__FILE__
, __LINE__
,
13370 _("unhandled tracepoint type %d"), (int) b
->type
);
13377 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13379 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13381 if (self
->type
== bp_fast_tracepoint
)
13382 fprintf_unfiltered (fp
, "ftrace");
13383 else if (self
->type
== bp_static_tracepoint
)
13384 fprintf_unfiltered (fp
, "strace");
13385 else if (self
->type
== bp_tracepoint
)
13386 fprintf_unfiltered (fp
, "trace");
13388 internal_error (__FILE__
, __LINE__
,
13389 _("unhandled tracepoint type %d"), (int) self
->type
);
13391 fprintf_unfiltered (fp
, " %s",
13392 event_location_to_string (self
->location
.get ()));
13393 print_recreate_thread (self
, fp
);
13395 if (tp
->pass_count
)
13396 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13400 tracepoint_create_sals_from_location (const struct event_location
*location
,
13401 struct linespec_result
*canonical
,
13402 enum bptype type_wanted
)
13404 create_sals_from_location_default (location
, canonical
, type_wanted
);
13408 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13409 struct linespec_result
*canonical
,
13411 char *extra_string
,
13412 enum bptype type_wanted
,
13413 enum bpdisp disposition
,
13415 int task
, int ignore_count
,
13416 const struct breakpoint_ops
*ops
,
13417 int from_tty
, int enabled
,
13418 int internal
, unsigned flags
)
13420 create_breakpoints_sal_default (gdbarch
, canonical
,
13421 cond_string
, extra_string
,
13423 disposition
, thread
, task
,
13424 ignore_count
, ops
, from_tty
,
13425 enabled
, internal
, flags
);
13429 tracepoint_decode_location (struct breakpoint
*b
,
13430 const struct event_location
*location
,
13431 struct program_space
*search_pspace
,
13432 struct symtabs_and_lines
*sals
)
13434 decode_location_default (b
, location
, search_pspace
, sals
);
13437 struct breakpoint_ops tracepoint_breakpoint_ops
;
13439 /* The breakpoint_ops structure to be use on tracepoints placed in a
13443 tracepoint_probe_create_sals_from_location
13444 (const struct event_location
*location
,
13445 struct linespec_result
*canonical
,
13446 enum bptype type_wanted
)
13448 /* We use the same method for breakpoint on probes. */
13449 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13453 tracepoint_probe_decode_location (struct breakpoint
*b
,
13454 const struct event_location
*location
,
13455 struct program_space
*search_pspace
,
13456 struct symtabs_and_lines
*sals
)
13458 /* We use the same method for breakpoint on probes. */
13459 bkpt_probe_decode_location (b
, location
, search_pspace
, sals
);
13462 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13464 /* Dprintf breakpoint_ops methods. */
13467 dprintf_re_set (struct breakpoint
*b
)
13469 breakpoint_re_set_default (b
);
13471 /* extra_string should never be non-NULL for dprintf. */
13472 gdb_assert (b
->extra_string
!= NULL
);
13474 /* 1 - connect to target 1, that can run breakpoint commands.
13475 2 - create a dprintf, which resolves fine.
13476 3 - disconnect from target 1
13477 4 - connect to target 2, that can NOT run breakpoint commands.
13479 After steps #3/#4, you'll want the dprintf command list to
13480 be updated, because target 1 and 2 may well return different
13481 answers for target_can_run_breakpoint_commands().
13482 Given absence of finer grained resetting, we get to do
13483 it all the time. */
13484 if (b
->extra_string
!= NULL
)
13485 update_dprintf_command_list (b
);
13488 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13491 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13493 fprintf_unfiltered (fp
, "dprintf %s,%s",
13494 event_location_to_string (tp
->location
.get ()),
13496 print_recreate_thread (tp
, fp
);
13499 /* Implement the "after_condition_true" breakpoint_ops method for
13502 dprintf's are implemented with regular commands in their command
13503 list, but we run the commands here instead of before presenting the
13504 stop to the user, as dprintf's don't actually cause a stop. This
13505 also makes it so that the commands of multiple dprintfs at the same
13506 address are all handled. */
13509 dprintf_after_condition_true (struct bpstats
*bs
)
13511 struct cleanup
*old_chain
;
13512 struct bpstats tmp_bs
= { NULL
};
13513 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13515 /* dprintf's never cause a stop. This wasn't set in the
13516 check_status hook instead because that would make the dprintf's
13517 condition not be evaluated. */
13520 /* Run the command list here. Take ownership of it instead of
13521 copying. We never want these commands to run later in
13522 bpstat_do_actions, if a breakpoint that causes a stop happens to
13523 be set at same address as this dprintf, or even if running the
13524 commands here throws. */
13525 tmp_bs
.commands
= bs
->commands
;
13526 bs
->commands
= NULL
;
13527 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13529 bpstat_do_actions_1 (&tmp_bs_p
);
13531 /* 'tmp_bs.commands' will usually be NULL by now, but
13532 bpstat_do_actions_1 may return early without processing the whole
13534 do_cleanups (old_chain
);
13537 /* The breakpoint_ops structure to be used on static tracepoints with
13541 strace_marker_create_sals_from_location (const struct event_location
*location
,
13542 struct linespec_result
*canonical
,
13543 enum bptype type_wanted
)
13545 struct linespec_sals lsal
;
13546 const char *arg_start
, *arg
;
13548 struct cleanup
*cleanup
;
13550 arg
= arg_start
= get_linespec_location (location
);
13551 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13553 str
= savestring (arg_start
, arg
- arg_start
);
13554 cleanup
= make_cleanup (xfree
, str
);
13555 canonical
->location
= new_linespec_location (&str
);
13556 do_cleanups (cleanup
);
13559 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13560 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13564 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13565 struct linespec_result
*canonical
,
13567 char *extra_string
,
13568 enum bptype type_wanted
,
13569 enum bpdisp disposition
,
13571 int task
, int ignore_count
,
13572 const struct breakpoint_ops
*ops
,
13573 int from_tty
, int enabled
,
13574 int internal
, unsigned flags
)
13577 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13578 canonical
->sals
, 0);
13580 /* If the user is creating a static tracepoint by marker id
13581 (strace -m MARKER_ID), then store the sals index, so that
13582 breakpoint_re_set can try to match up which of the newly
13583 found markers corresponds to this one, and, don't try to
13584 expand multiple locations for each sal, given than SALS
13585 already should contain all sals for MARKER_ID. */
13587 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13589 struct symtabs_and_lines expanded
;
13590 struct tracepoint
*tp
;
13591 event_location_up location
;
13593 expanded
.nelts
= 1;
13594 expanded
.sals
= &lsal
->sals
.sals
[i
];
13596 location
= copy_event_location (canonical
->location
.get ());
13598 tp
= new tracepoint ();
13599 init_breakpoint_sal (tp
, gdbarch
, expanded
,
13600 std::move (location
), NULL
,
13601 cond_string
, extra_string
,
13602 type_wanted
, disposition
,
13603 thread
, task
, ignore_count
, ops
,
13604 from_tty
, enabled
, internal
, flags
,
13605 canonical
->special_display
);
13606 /* Given that its possible to have multiple markers with
13607 the same string id, if the user is creating a static
13608 tracepoint by marker id ("strace -m MARKER_ID"), then
13609 store the sals index, so that breakpoint_re_set can
13610 try to match up which of the newly found markers
13611 corresponds to this one */
13612 tp
->static_trace_marker_id_idx
= i
;
13614 install_breakpoint (internal
, tp
, 0);
13619 strace_marker_decode_location (struct breakpoint
*b
,
13620 const struct event_location
*location
,
13621 struct program_space
*search_pspace
,
13622 struct symtabs_and_lines
*sals
)
13624 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13625 const char *s
= get_linespec_location (location
);
13627 *sals
= decode_static_tracepoint_spec (&s
);
13628 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13630 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13634 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13637 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13640 strace_marker_p (struct breakpoint
*b
)
13642 return b
->ops
== &strace_marker_breakpoint_ops
;
13645 /* Delete a breakpoint and clean up all traces of it in the data
13649 delete_breakpoint (struct breakpoint
*bpt
)
13651 struct breakpoint
*b
;
13653 gdb_assert (bpt
!= NULL
);
13655 /* Has this bp already been deleted? This can happen because
13656 multiple lists can hold pointers to bp's. bpstat lists are
13659 One example of this happening is a watchpoint's scope bp. When
13660 the scope bp triggers, we notice that the watchpoint is out of
13661 scope, and delete it. We also delete its scope bp. But the
13662 scope bp is marked "auto-deleting", and is already on a bpstat.
13663 That bpstat is then checked for auto-deleting bp's, which are
13666 A real solution to this problem might involve reference counts in
13667 bp's, and/or giving them pointers back to their referencing
13668 bpstat's, and teaching delete_breakpoint to only free a bp's
13669 storage when no more references were extent. A cheaper bandaid
13671 if (bpt
->type
== bp_none
)
13674 /* At least avoid this stale reference until the reference counting
13675 of breakpoints gets resolved. */
13676 if (bpt
->related_breakpoint
!= bpt
)
13678 struct breakpoint
*related
;
13679 struct watchpoint
*w
;
13681 if (bpt
->type
== bp_watchpoint_scope
)
13682 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13683 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13684 w
= (struct watchpoint
*) bpt
;
13688 watchpoint_del_at_next_stop (w
);
13690 /* Unlink bpt from the bpt->related_breakpoint ring. */
13691 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13692 related
= related
->related_breakpoint
);
13693 related
->related_breakpoint
= bpt
->related_breakpoint
;
13694 bpt
->related_breakpoint
= bpt
;
13697 /* watch_command_1 creates a watchpoint but only sets its number if
13698 update_watchpoint succeeds in creating its bp_locations. If there's
13699 a problem in that process, we'll be asked to delete the half-created
13700 watchpoint. In that case, don't announce the deletion. */
13702 observer_notify_breakpoint_deleted (bpt
);
13704 if (breakpoint_chain
== bpt
)
13705 breakpoint_chain
= bpt
->next
;
13707 ALL_BREAKPOINTS (b
)
13708 if (b
->next
== bpt
)
13710 b
->next
= bpt
->next
;
13714 /* Be sure no bpstat's are pointing at the breakpoint after it's
13716 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13717 in all threads for now. Note that we cannot just remove bpstats
13718 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13719 commands are associated with the bpstat; if we remove it here,
13720 then the later call to bpstat_do_actions (&stop_bpstat); in
13721 event-top.c won't do anything, and temporary breakpoints with
13722 commands won't work. */
13724 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13726 /* Now that breakpoint is removed from breakpoint list, update the
13727 global location list. This will remove locations that used to
13728 belong to this breakpoint. Do this before freeing the breakpoint
13729 itself, since remove_breakpoint looks at location's owner. It
13730 might be better design to have location completely
13731 self-contained, but it's not the case now. */
13732 update_global_location_list (UGLL_DONT_INSERT
);
13734 /* On the chance that someone will soon try again to delete this
13735 same bp, we mark it as deleted before freeing its storage. */
13736 bpt
->type
= bp_none
;
13741 do_delete_breakpoint_cleanup (void *b
)
13743 delete_breakpoint ((struct breakpoint
*) b
);
13747 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13749 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13752 /* Iterator function to call a user-provided callback function once
13753 for each of B and its related breakpoints. */
13756 iterate_over_related_breakpoints (struct breakpoint
*b
,
13757 void (*function
) (struct breakpoint
*,
13761 struct breakpoint
*related
;
13766 struct breakpoint
*next
;
13768 /* FUNCTION may delete RELATED. */
13769 next
= related
->related_breakpoint
;
13771 if (next
== related
)
13773 /* RELATED is the last ring entry. */
13774 function (related
, data
);
13776 /* FUNCTION may have deleted it, so we'd never reach back to
13777 B. There's nothing left to do anyway, so just break
13782 function (related
, data
);
13786 while (related
!= b
);
13790 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13792 delete_breakpoint (b
);
13795 /* A callback for map_breakpoint_numbers that calls
13796 delete_breakpoint. */
13799 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13801 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13805 delete_command (char *arg
, int from_tty
)
13807 struct breakpoint
*b
, *b_tmp
;
13813 int breaks_to_delete
= 0;
13815 /* Delete all breakpoints if no argument. Do not delete
13816 internal breakpoints, these have to be deleted with an
13817 explicit breakpoint number argument. */
13818 ALL_BREAKPOINTS (b
)
13819 if (user_breakpoint_p (b
))
13821 breaks_to_delete
= 1;
13825 /* Ask user only if there are some breakpoints to delete. */
13827 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13829 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13830 if (user_breakpoint_p (b
))
13831 delete_breakpoint (b
);
13835 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13838 /* Return true if all locations of B bound to PSPACE are pending. If
13839 PSPACE is NULL, all locations of all program spaces are
13843 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13845 struct bp_location
*loc
;
13847 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13848 if ((pspace
== NULL
13849 || loc
->pspace
== pspace
)
13850 && !loc
->shlib_disabled
13851 && !loc
->pspace
->executing_startup
)
13856 /* Subroutine of update_breakpoint_locations to simplify it.
13857 Return non-zero if multiple fns in list LOC have the same name.
13858 Null names are ignored. */
13861 ambiguous_names_p (struct bp_location
*loc
)
13863 struct bp_location
*l
;
13864 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13865 (int (*) (const void *,
13866 const void *)) streq
,
13867 NULL
, xcalloc
, xfree
);
13869 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13872 const char *name
= l
->function_name
;
13874 /* Allow for some names to be NULL, ignore them. */
13878 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13880 /* NOTE: We can assume slot != NULL here because xcalloc never
13884 htab_delete (htab
);
13890 htab_delete (htab
);
13894 /* When symbols change, it probably means the sources changed as well,
13895 and it might mean the static tracepoint markers are no longer at
13896 the same address or line numbers they used to be at last we
13897 checked. Losing your static tracepoints whenever you rebuild is
13898 undesirable. This function tries to resync/rematch gdb static
13899 tracepoints with the markers on the target, for static tracepoints
13900 that have not been set by marker id. Static tracepoint that have
13901 been set by marker id are reset by marker id in breakpoint_re_set.
13904 1) For a tracepoint set at a specific address, look for a marker at
13905 the old PC. If one is found there, assume to be the same marker.
13906 If the name / string id of the marker found is different from the
13907 previous known name, assume that means the user renamed the marker
13908 in the sources, and output a warning.
13910 2) For a tracepoint set at a given line number, look for a marker
13911 at the new address of the old line number. If one is found there,
13912 assume to be the same marker. If the name / string id of the
13913 marker found is different from the previous known name, assume that
13914 means the user renamed the marker in the sources, and output a
13917 3) If a marker is no longer found at the same address or line, it
13918 may mean the marker no longer exists. But it may also just mean
13919 the code changed a bit. Maybe the user added a few lines of code
13920 that made the marker move up or down (in line number terms). Ask
13921 the target for info about the marker with the string id as we knew
13922 it. If found, update line number and address in the matching
13923 static tracepoint. This will get confused if there's more than one
13924 marker with the same ID (possible in UST, although unadvised
13925 precisely because it confuses tools). */
13927 static struct symtab_and_line
13928 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13930 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13931 struct static_tracepoint_marker marker
;
13936 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13938 if (target_static_tracepoint_marker_at (pc
, &marker
))
13940 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13941 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13943 tp
->static_trace_marker_id
, marker
.str_id
);
13945 xfree (tp
->static_trace_marker_id
);
13946 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13947 release_static_tracepoint_marker (&marker
);
13952 /* Old marker wasn't found on target at lineno. Try looking it up
13954 if (!sal
.explicit_pc
13956 && sal
.symtab
!= NULL
13957 && tp
->static_trace_marker_id
!= NULL
)
13959 VEC(static_tracepoint_marker_p
) *markers
;
13962 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13964 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13966 struct symtab_and_line sal2
;
13967 struct symbol
*sym
;
13968 struct static_tracepoint_marker
*tpmarker
;
13969 struct ui_out
*uiout
= current_uiout
;
13970 struct explicit_location explicit_loc
;
13972 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13974 xfree (tp
->static_trace_marker_id
);
13975 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13977 warning (_("marker for static tracepoint %d (%s) not "
13978 "found at previous line number"),
13979 b
->number
, tp
->static_trace_marker_id
);
13983 sal2
.pc
= tpmarker
->address
;
13985 sal2
= find_pc_line (tpmarker
->address
, 0);
13986 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13987 uiout
->text ("Now in ");
13990 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13991 uiout
->text (" at ");
13993 uiout
->field_string ("file",
13994 symtab_to_filename_for_display (sal2
.symtab
));
13997 if (uiout
->is_mi_like_p ())
13999 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14001 uiout
->field_string ("fullname", fullname
);
14004 uiout
->field_int ("line", sal2
.line
);
14005 uiout
->text ("\n");
14007 b
->loc
->line_number
= sal2
.line
;
14008 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14010 b
->location
.reset (NULL
);
14011 initialize_explicit_location (&explicit_loc
);
14012 explicit_loc
.source_filename
14013 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14014 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14015 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14016 b
->location
= new_explicit_location (&explicit_loc
);
14018 /* Might be nice to check if function changed, and warn if
14021 release_static_tracepoint_marker (tpmarker
);
14027 /* Returns 1 iff locations A and B are sufficiently same that
14028 we don't need to report breakpoint as changed. */
14031 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14035 if (a
->address
!= b
->address
)
14038 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14041 if (a
->enabled
!= b
->enabled
)
14048 if ((a
== NULL
) != (b
== NULL
))
14054 /* Split all locations of B that are bound to PSPACE out of B's
14055 location list to a separate list and return that list's head. If
14056 PSPACE is NULL, hoist out all locations of B. */
14058 static struct bp_location
*
14059 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
14061 struct bp_location head
;
14062 struct bp_location
*i
= b
->loc
;
14063 struct bp_location
**i_link
= &b
->loc
;
14064 struct bp_location
*hoisted
= &head
;
14066 if (pspace
== NULL
)
14077 if (i
->pspace
== pspace
)
14092 /* Create new breakpoint locations for B (a hardware or software
14093 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14094 zero, then B is a ranged breakpoint. Only recreates locations for
14095 FILTER_PSPACE. Locations of other program spaces are left
14099 update_breakpoint_locations (struct breakpoint
*b
,
14100 struct program_space
*filter_pspace
,
14101 struct symtabs_and_lines sals
,
14102 struct symtabs_and_lines sals_end
)
14105 struct bp_location
*existing_locations
;
14107 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14109 /* Ranged breakpoints have only one start location and one end
14111 b
->enable_state
= bp_disabled
;
14112 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14113 "multiple locations found\n"),
14118 /* If there's no new locations, and all existing locations are
14119 pending, don't do anything. This optimizes the common case where
14120 all locations are in the same shared library, that was unloaded.
14121 We'd like to retain the location, so that when the library is
14122 loaded again, we don't loose the enabled/disabled status of the
14123 individual locations. */
14124 if (all_locations_are_pending (b
, filter_pspace
) && sals
.nelts
== 0)
14127 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
14129 for (i
= 0; i
< sals
.nelts
; ++i
)
14131 struct bp_location
*new_loc
;
14133 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14135 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14137 /* Reparse conditions, they might contain references to the
14139 if (b
->cond_string
!= NULL
)
14143 s
= b
->cond_string
;
14146 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14147 block_for_pc (sals
.sals
[i
].pc
),
14150 CATCH (e
, RETURN_MASK_ERROR
)
14152 warning (_("failed to reevaluate condition "
14153 "for breakpoint %d: %s"),
14154 b
->number
, e
.message
);
14155 new_loc
->enabled
= 0;
14160 if (sals_end
.nelts
)
14162 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14164 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14168 /* If possible, carry over 'disable' status from existing
14171 struct bp_location
*e
= existing_locations
;
14172 /* If there are multiple breakpoints with the same function name,
14173 e.g. for inline functions, comparing function names won't work.
14174 Instead compare pc addresses; this is just a heuristic as things
14175 may have moved, but in practice it gives the correct answer
14176 often enough until a better solution is found. */
14177 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14179 for (; e
; e
= e
->next
)
14181 if (!e
->enabled
&& e
->function_name
)
14183 struct bp_location
*l
= b
->loc
;
14184 if (have_ambiguous_names
)
14186 for (; l
; l
= l
->next
)
14187 if (breakpoint_locations_match (e
, l
))
14195 for (; l
; l
= l
->next
)
14196 if (l
->function_name
14197 && strcmp (e
->function_name
, l
->function_name
) == 0)
14207 if (!locations_are_equal (existing_locations
, b
->loc
))
14208 observer_notify_breakpoint_modified (b
);
14211 /* Find the SaL locations corresponding to the given LOCATION.
14212 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14214 static struct symtabs_and_lines
14215 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14216 struct program_space
*search_pspace
, int *found
)
14218 struct symtabs_and_lines sals
= {0};
14219 struct gdb_exception exception
= exception_none
;
14221 gdb_assert (b
->ops
!= NULL
);
14225 b
->ops
->decode_location (b
, location
, search_pspace
, &sals
);
14227 CATCH (e
, RETURN_MASK_ERROR
)
14229 int not_found_and_ok
= 0;
14233 /* For pending breakpoints, it's expected that parsing will
14234 fail until the right shared library is loaded. User has
14235 already told to create pending breakpoints and don't need
14236 extra messages. If breakpoint is in bp_shlib_disabled
14237 state, then user already saw the message about that
14238 breakpoint being disabled, and don't want to see more
14240 if (e
.error
== NOT_FOUND_ERROR
14241 && (b
->condition_not_parsed
14243 && search_pspace
!= NULL
14244 && b
->loc
->pspace
!= search_pspace
)
14245 || (b
->loc
&& b
->loc
->shlib_disabled
)
14246 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14247 || b
->enable_state
== bp_disabled
))
14248 not_found_and_ok
= 1;
14250 if (!not_found_and_ok
)
14252 /* We surely don't want to warn about the same breakpoint
14253 10 times. One solution, implemented here, is disable
14254 the breakpoint on error. Another solution would be to
14255 have separate 'warning emitted' flag. Since this
14256 happens only when a binary has changed, I don't know
14257 which approach is better. */
14258 b
->enable_state
= bp_disabled
;
14259 throw_exception (e
);
14264 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14268 for (i
= 0; i
< sals
.nelts
; ++i
)
14269 resolve_sal_pc (&sals
.sals
[i
]);
14270 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14272 char *cond_string
, *extra_string
;
14275 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14276 &cond_string
, &thread
, &task
,
14278 gdb_assert (b
->cond_string
== NULL
);
14280 b
->cond_string
= cond_string
;
14281 b
->thread
= thread
;
14285 xfree (b
->extra_string
);
14286 b
->extra_string
= extra_string
;
14288 b
->condition_not_parsed
= 0;
14291 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14292 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14302 /* The default re_set method, for typical hardware or software
14303 breakpoints. Reevaluate the breakpoint and recreate its
14307 breakpoint_re_set_default (struct breakpoint
*b
)
14310 struct symtabs_and_lines sals
, sals_end
;
14311 struct symtabs_and_lines expanded
= {0};
14312 struct symtabs_and_lines expanded_end
= {0};
14313 struct program_space
*filter_pspace
= current_program_space
;
14315 sals
= location_to_sals (b
, b
->location
.get (), filter_pspace
, &found
);
14318 make_cleanup (xfree
, sals
.sals
);
14322 if (b
->location_range_end
!= NULL
)
14324 sals_end
= location_to_sals (b
, b
->location_range_end
.get (),
14325 filter_pspace
, &found
);
14328 make_cleanup (xfree
, sals_end
.sals
);
14329 expanded_end
= sals_end
;
14333 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14336 /* Default method for creating SALs from an address string. It basically
14337 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14340 create_sals_from_location_default (const struct event_location
*location
,
14341 struct linespec_result
*canonical
,
14342 enum bptype type_wanted
)
14344 parse_breakpoint_sals (location
, canonical
);
14347 /* Call create_breakpoints_sal for the given arguments. This is the default
14348 function for the `create_breakpoints_sal' method of
14352 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14353 struct linespec_result
*canonical
,
14355 char *extra_string
,
14356 enum bptype type_wanted
,
14357 enum bpdisp disposition
,
14359 int task
, int ignore_count
,
14360 const struct breakpoint_ops
*ops
,
14361 int from_tty
, int enabled
,
14362 int internal
, unsigned flags
)
14364 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14366 type_wanted
, disposition
,
14367 thread
, task
, ignore_count
, ops
, from_tty
,
14368 enabled
, internal
, flags
);
14371 /* Decode the line represented by S by calling decode_line_full. This is the
14372 default function for the `decode_location' method of breakpoint_ops. */
14375 decode_location_default (struct breakpoint
*b
,
14376 const struct event_location
*location
,
14377 struct program_space
*search_pspace
,
14378 struct symtabs_and_lines
*sals
)
14380 struct linespec_result canonical
;
14382 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14383 (struct symtab
*) NULL
, 0,
14384 &canonical
, multiple_symbols_all
,
14387 /* We should get 0 or 1 resulting SALs. */
14388 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14390 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14392 struct linespec_sals
*lsal
;
14394 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14395 *sals
= lsal
->sals
;
14396 /* Arrange it so the destructor does not free the
14398 lsal
->sals
.sals
= NULL
;
14402 /* Prepare the global context for a re-set of breakpoint B. */
14404 static struct cleanup
*
14405 prepare_re_set_context (struct breakpoint
*b
)
14407 input_radix
= b
->input_radix
;
14408 set_language (b
->language
);
14410 return make_cleanup (null_cleanup
, NULL
);
14413 /* Reset a breakpoint given it's struct breakpoint * BINT.
14414 The value we return ends up being the return value from catch_errors.
14415 Unused in this case. */
14418 breakpoint_re_set_one (void *bint
)
14420 /* Get past catch_errs. */
14421 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14422 struct cleanup
*cleanups
;
14424 cleanups
= prepare_re_set_context (b
);
14425 b
->ops
->re_set (b
);
14426 do_cleanups (cleanups
);
14430 /* Re-set breakpoint locations for the current program space.
14431 Locations bound to other program spaces are left untouched. */
14434 breakpoint_re_set (void)
14436 struct breakpoint
*b
, *b_tmp
;
14437 enum language save_language
;
14438 int save_input_radix
;
14440 save_language
= current_language
->la_language
;
14441 save_input_radix
= input_radix
;
14444 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14446 /* Note: we must not try to insert locations until after all
14447 breakpoints have been re-set. Otherwise, e.g., when re-setting
14448 breakpoint 1, we'd insert the locations of breakpoint 2, which
14449 hadn't been re-set yet, and thus may have stale locations. */
14451 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14453 /* Format possible error msg. */
14454 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14456 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14457 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14458 do_cleanups (cleanups
);
14460 set_language (save_language
);
14461 input_radix
= save_input_radix
;
14463 jit_breakpoint_re_set ();
14466 create_overlay_event_breakpoint ();
14467 create_longjmp_master_breakpoint ();
14468 create_std_terminate_master_breakpoint ();
14469 create_exception_master_breakpoint ();
14471 /* Now we can insert. */
14472 update_global_location_list (UGLL_MAY_INSERT
);
14475 /* Reset the thread number of this breakpoint:
14477 - If the breakpoint is for all threads, leave it as-is.
14478 - Else, reset it to the current thread for inferior_ptid. */
14480 breakpoint_re_set_thread (struct breakpoint
*b
)
14482 if (b
->thread
!= -1)
14484 if (in_thread_list (inferior_ptid
))
14485 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14487 /* We're being called after following a fork. The new fork is
14488 selected as current, and unless this was a vfork will have a
14489 different program space from the original thread. Reset that
14491 b
->loc
->pspace
= current_program_space
;
14495 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14496 If from_tty is nonzero, it prints a message to that effect,
14497 which ends with a period (no newline). */
14500 set_ignore_count (int bptnum
, int count
, int from_tty
)
14502 struct breakpoint
*b
;
14507 ALL_BREAKPOINTS (b
)
14508 if (b
->number
== bptnum
)
14510 if (is_tracepoint (b
))
14512 if (from_tty
&& count
!= 0)
14513 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14518 b
->ignore_count
= count
;
14522 printf_filtered (_("Will stop next time "
14523 "breakpoint %d is reached."),
14525 else if (count
== 1)
14526 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14529 printf_filtered (_("Will ignore next %d "
14530 "crossings of breakpoint %d."),
14533 observer_notify_breakpoint_modified (b
);
14537 error (_("No breakpoint number %d."), bptnum
);
14540 /* Command to set ignore-count of breakpoint N to COUNT. */
14543 ignore_command (char *args
, int from_tty
)
14549 error_no_arg (_("a breakpoint number"));
14551 num
= get_number (&p
);
14553 error (_("bad breakpoint number: '%s'"), args
);
14555 error (_("Second argument (specified ignore-count) is missing."));
14557 set_ignore_count (num
,
14558 longest_to_int (value_as_long (parse_and_eval (p
))),
14561 printf_filtered ("\n");
14564 /* Call FUNCTION on each of the breakpoints
14565 whose numbers are given in ARGS. */
14568 map_breakpoint_numbers (const char *args
,
14569 void (*function
) (struct breakpoint
*,
14574 struct breakpoint
*b
, *tmp
;
14576 if (args
== 0 || *args
== '\0')
14577 error_no_arg (_("one or more breakpoint numbers"));
14579 number_or_range_parser
parser (args
);
14581 while (!parser
.finished ())
14583 const char *p
= parser
.cur_tok ();
14584 bool match
= false;
14586 num
= parser
.get_number ();
14589 warning (_("bad breakpoint number at or near '%s'"), p
);
14593 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14594 if (b
->number
== num
)
14597 function (b
, data
);
14601 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14606 static struct bp_location
*
14607 find_location_by_number (char *number
)
14609 char *dot
= strchr (number
, '.');
14613 struct breakpoint
*b
;
14614 struct bp_location
*loc
;
14619 bp_num
= get_number (&p1
);
14621 error (_("Bad breakpoint number '%s'"), number
);
14623 ALL_BREAKPOINTS (b
)
14624 if (b
->number
== bp_num
)
14629 if (!b
|| b
->number
!= bp_num
)
14630 error (_("Bad breakpoint number '%s'"), number
);
14633 loc_num
= get_number (&p1
);
14635 error (_("Bad breakpoint location number '%s'"), number
);
14639 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14642 error (_("Bad breakpoint location number '%s'"), dot
+1);
14648 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14649 If from_tty is nonzero, it prints a message to that effect,
14650 which ends with a period (no newline). */
14653 disable_breakpoint (struct breakpoint
*bpt
)
14655 /* Never disable a watchpoint scope breakpoint; we want to
14656 hit them when we leave scope so we can delete both the
14657 watchpoint and its scope breakpoint at that time. */
14658 if (bpt
->type
== bp_watchpoint_scope
)
14661 bpt
->enable_state
= bp_disabled
;
14663 /* Mark breakpoint locations modified. */
14664 mark_breakpoint_modified (bpt
);
14666 if (target_supports_enable_disable_tracepoint ()
14667 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14669 struct bp_location
*location
;
14671 for (location
= bpt
->loc
; location
; location
= location
->next
)
14672 target_disable_tracepoint (location
);
14675 update_global_location_list (UGLL_DONT_INSERT
);
14677 observer_notify_breakpoint_modified (bpt
);
14680 /* A callback for iterate_over_related_breakpoints. */
14683 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14685 disable_breakpoint (b
);
14688 /* A callback for map_breakpoint_numbers that calls
14689 disable_breakpoint. */
14692 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14694 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14698 disable_command (char *args
, int from_tty
)
14702 struct breakpoint
*bpt
;
14704 ALL_BREAKPOINTS (bpt
)
14705 if (user_breakpoint_p (bpt
))
14706 disable_breakpoint (bpt
);
14710 char *num
= extract_arg (&args
);
14714 if (strchr (num
, '.'))
14716 struct bp_location
*loc
= find_location_by_number (num
);
14723 mark_breakpoint_location_modified (loc
);
14725 if (target_supports_enable_disable_tracepoint ()
14726 && current_trace_status ()->running
&& loc
->owner
14727 && is_tracepoint (loc
->owner
))
14728 target_disable_tracepoint (loc
);
14730 update_global_location_list (UGLL_DONT_INSERT
);
14733 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14734 num
= extract_arg (&args
);
14740 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14743 int target_resources_ok
;
14745 if (bpt
->type
== bp_hardware_breakpoint
)
14748 i
= hw_breakpoint_used_count ();
14749 target_resources_ok
=
14750 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14752 if (target_resources_ok
== 0)
14753 error (_("No hardware breakpoint support in the target."));
14754 else if (target_resources_ok
< 0)
14755 error (_("Hardware breakpoints used exceeds limit."));
14758 if (is_watchpoint (bpt
))
14760 /* Initialize it just to avoid a GCC false warning. */
14761 enum enable_state orig_enable_state
= bp_disabled
;
14765 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14767 orig_enable_state
= bpt
->enable_state
;
14768 bpt
->enable_state
= bp_enabled
;
14769 update_watchpoint (w
, 1 /* reparse */);
14771 CATCH (e
, RETURN_MASK_ALL
)
14773 bpt
->enable_state
= orig_enable_state
;
14774 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14781 bpt
->enable_state
= bp_enabled
;
14783 /* Mark breakpoint locations modified. */
14784 mark_breakpoint_modified (bpt
);
14786 if (target_supports_enable_disable_tracepoint ()
14787 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14789 struct bp_location
*location
;
14791 for (location
= bpt
->loc
; location
; location
= location
->next
)
14792 target_enable_tracepoint (location
);
14795 bpt
->disposition
= disposition
;
14796 bpt
->enable_count
= count
;
14797 update_global_location_list (UGLL_MAY_INSERT
);
14799 observer_notify_breakpoint_modified (bpt
);
14804 enable_breakpoint (struct breakpoint
*bpt
)
14806 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14810 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14812 enable_breakpoint (bpt
);
14815 /* A callback for map_breakpoint_numbers that calls
14816 enable_breakpoint. */
14819 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14821 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14824 /* The enable command enables the specified breakpoints (or all defined
14825 breakpoints) so they once again become (or continue to be) effective
14826 in stopping the inferior. */
14829 enable_command (char *args
, int from_tty
)
14833 struct breakpoint
*bpt
;
14835 ALL_BREAKPOINTS (bpt
)
14836 if (user_breakpoint_p (bpt
))
14837 enable_breakpoint (bpt
);
14841 char *num
= extract_arg (&args
);
14845 if (strchr (num
, '.'))
14847 struct bp_location
*loc
= find_location_by_number (num
);
14854 mark_breakpoint_location_modified (loc
);
14856 if (target_supports_enable_disable_tracepoint ()
14857 && current_trace_status ()->running
&& loc
->owner
14858 && is_tracepoint (loc
->owner
))
14859 target_enable_tracepoint (loc
);
14861 update_global_location_list (UGLL_MAY_INSERT
);
14864 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14865 num
= extract_arg (&args
);
14870 /* This struct packages up disposition data for application to multiple
14880 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14882 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14884 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14888 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14890 struct disp_data disp
= { disp_disable
, 1 };
14892 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14896 enable_once_command (char *args
, int from_tty
)
14898 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14902 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14904 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14906 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14910 enable_count_command (char *args
, int from_tty
)
14915 error_no_arg (_("hit count"));
14917 count
= get_number (&args
);
14919 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14923 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14925 struct disp_data disp
= { disp_del
, 1 };
14927 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14931 enable_delete_command (char *args
, int from_tty
)
14933 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14937 set_breakpoint_cmd (char *args
, int from_tty
)
14942 show_breakpoint_cmd (char *args
, int from_tty
)
14946 /* Invalidate last known value of any hardware watchpoint if
14947 the memory which that value represents has been written to by
14951 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14952 CORE_ADDR addr
, ssize_t len
,
14953 const bfd_byte
*data
)
14955 struct breakpoint
*bp
;
14957 ALL_BREAKPOINTS (bp
)
14958 if (bp
->enable_state
== bp_enabled
14959 && bp
->type
== bp_hardware_watchpoint
)
14961 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14963 if (wp
->val_valid
&& wp
->val
)
14965 struct bp_location
*loc
;
14967 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14968 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14969 && loc
->address
+ loc
->length
> addr
14970 && addr
+ len
> loc
->address
)
14972 value_free (wp
->val
);
14980 /* Create and insert a breakpoint for software single step. */
14983 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14984 struct address_space
*aspace
,
14987 struct thread_info
*tp
= inferior_thread ();
14988 struct symtab_and_line sal
;
14989 CORE_ADDR pc
= next_pc
;
14991 if (tp
->control
.single_step_breakpoints
== NULL
)
14993 tp
->control
.single_step_breakpoints
14994 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14997 sal
= find_pc_line (pc
, 0);
14999 sal
.section
= find_pc_overlay (pc
);
15000 sal
.explicit_pc
= 1;
15001 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15003 update_global_location_list (UGLL_INSERT
);
15006 /* Insert single step breakpoints according to the current state. */
15009 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
15011 struct regcache
*regcache
= get_current_regcache ();
15012 std::vector
<CORE_ADDR
> next_pcs
;
15014 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
15016 if (!next_pcs
.empty ())
15018 struct frame_info
*frame
= get_current_frame ();
15019 struct address_space
*aspace
= get_frame_address_space (frame
);
15021 for (CORE_ADDR pc
: next_pcs
)
15022 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
15030 /* See breakpoint.h. */
15033 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15034 struct address_space
*aspace
,
15037 struct bp_location
*loc
;
15039 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15041 && breakpoint_location_address_match (loc
, aspace
, pc
))
15047 /* Check whether a software single-step breakpoint is inserted at
15051 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15054 struct breakpoint
*bpt
;
15056 ALL_BREAKPOINTS (bpt
)
15058 if (bpt
->type
== bp_single_step
15059 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15065 /* Tracepoint-specific operations. */
15067 /* Set tracepoint count to NUM. */
15069 set_tracepoint_count (int num
)
15071 tracepoint_count
= num
;
15072 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15076 trace_command (char *arg
, int from_tty
)
15078 struct breakpoint_ops
*ops
;
15080 event_location_up location
= string_to_event_location (&arg
,
15082 if (location
!= NULL
15083 && event_location_type (location
.get ()) == PROBE_LOCATION
)
15084 ops
= &tracepoint_probe_breakpoint_ops
;
15086 ops
= &tracepoint_breakpoint_ops
;
15088 create_breakpoint (get_current_arch (),
15090 NULL
, 0, arg
, 1 /* parse arg */,
15092 bp_tracepoint
/* type_wanted */,
15093 0 /* Ignore count */,
15094 pending_break_support
,
15098 0 /* internal */, 0);
15102 ftrace_command (char *arg
, int from_tty
)
15104 event_location_up location
= string_to_event_location (&arg
,
15106 create_breakpoint (get_current_arch (),
15108 NULL
, 0, arg
, 1 /* parse arg */,
15110 bp_fast_tracepoint
/* type_wanted */,
15111 0 /* Ignore count */,
15112 pending_break_support
,
15113 &tracepoint_breakpoint_ops
,
15116 0 /* internal */, 0);
15119 /* strace command implementation. Creates a static tracepoint. */
15122 strace_command (char *arg
, int from_tty
)
15124 struct breakpoint_ops
*ops
;
15125 event_location_up location
;
15126 struct cleanup
*back_to
;
15128 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15129 or with a normal static tracepoint. */
15130 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15132 ops
= &strace_marker_breakpoint_ops
;
15133 location
= new_linespec_location (&arg
);
15137 ops
= &tracepoint_breakpoint_ops
;
15138 location
= string_to_event_location (&arg
, current_language
);
15141 create_breakpoint (get_current_arch (),
15143 NULL
, 0, arg
, 1 /* parse arg */,
15145 bp_static_tracepoint
/* type_wanted */,
15146 0 /* Ignore count */,
15147 pending_break_support
,
15151 0 /* internal */, 0);
15154 /* Set up a fake reader function that gets command lines from a linked
15155 list that was acquired during tracepoint uploading. */
15157 static struct uploaded_tp
*this_utp
;
15158 static int next_cmd
;
15161 read_uploaded_action (void)
15165 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15172 /* Given information about a tracepoint as recorded on a target (which
15173 can be either a live system or a trace file), attempt to create an
15174 equivalent GDB tracepoint. This is not a reliable process, since
15175 the target does not necessarily have all the information used when
15176 the tracepoint was originally defined. */
15178 struct tracepoint
*
15179 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15181 char *addr_str
, small_buf
[100];
15182 struct tracepoint
*tp
;
15184 if (utp
->at_string
)
15185 addr_str
= utp
->at_string
;
15188 /* In the absence of a source location, fall back to raw
15189 address. Since there is no way to confirm that the address
15190 means the same thing as when the trace was started, warn the
15192 warning (_("Uploaded tracepoint %d has no "
15193 "source location, using raw address"),
15195 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15196 addr_str
= small_buf
;
15199 /* There's not much we can do with a sequence of bytecodes. */
15200 if (utp
->cond
&& !utp
->cond_string
)
15201 warning (_("Uploaded tracepoint %d condition "
15202 "has no source form, ignoring it"),
15205 event_location_up location
= string_to_event_location (&addr_str
,
15207 if (!create_breakpoint (get_current_arch (),
15209 utp
->cond_string
, -1, addr_str
,
15210 0 /* parse cond/thread */,
15212 utp
->type
/* type_wanted */,
15213 0 /* Ignore count */,
15214 pending_break_support
,
15215 &tracepoint_breakpoint_ops
,
15217 utp
->enabled
/* enabled */,
15219 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15222 /* Get the tracepoint we just created. */
15223 tp
= get_tracepoint (tracepoint_count
);
15224 gdb_assert (tp
!= NULL
);
15228 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15231 trace_pass_command (small_buf
, 0);
15234 /* If we have uploaded versions of the original commands, set up a
15235 special-purpose "reader" function and call the usual command line
15236 reader, then pass the result to the breakpoint command-setting
15238 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15240 command_line_up cmd_list
;
15245 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15247 breakpoint_set_commands (tp
, std::move (cmd_list
));
15249 else if (!VEC_empty (char_ptr
, utp
->actions
)
15250 || !VEC_empty (char_ptr
, utp
->step_actions
))
15251 warning (_("Uploaded tracepoint %d actions "
15252 "have no source form, ignoring them"),
15255 /* Copy any status information that might be available. */
15256 tp
->hit_count
= utp
->hit_count
;
15257 tp
->traceframe_usage
= utp
->traceframe_usage
;
15262 /* Print information on tracepoint number TPNUM_EXP, or all if
15266 tracepoints_info (char *args
, int from_tty
)
15268 struct ui_out
*uiout
= current_uiout
;
15271 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15273 if (num_printed
== 0)
15275 if (args
== NULL
|| *args
== '\0')
15276 uiout
->message ("No tracepoints.\n");
15278 uiout
->message ("No tracepoint matching '%s'.\n", args
);
15281 default_collect_info ();
15284 /* The 'enable trace' command enables tracepoints.
15285 Not supported by all targets. */
15287 enable_trace_command (char *args
, int from_tty
)
15289 enable_command (args
, from_tty
);
15292 /* The 'disable trace' command disables tracepoints.
15293 Not supported by all targets. */
15295 disable_trace_command (char *args
, int from_tty
)
15297 disable_command (args
, from_tty
);
15300 /* Remove a tracepoint (or all if no argument). */
15302 delete_trace_command (char *arg
, int from_tty
)
15304 struct breakpoint
*b
, *b_tmp
;
15310 int breaks_to_delete
= 0;
15312 /* Delete all breakpoints if no argument.
15313 Do not delete internal or call-dummy breakpoints, these
15314 have to be deleted with an explicit breakpoint number
15316 ALL_TRACEPOINTS (b
)
15317 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15319 breaks_to_delete
= 1;
15323 /* Ask user only if there are some breakpoints to delete. */
15325 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15327 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15328 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15329 delete_breakpoint (b
);
15333 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15336 /* Helper function for trace_pass_command. */
15339 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15341 tp
->pass_count
= count
;
15342 observer_notify_breakpoint_modified (tp
);
15344 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15345 tp
->number
, count
);
15348 /* Set passcount for tracepoint.
15350 First command argument is passcount, second is tracepoint number.
15351 If tracepoint number omitted, apply to most recently defined.
15352 Also accepts special argument "all". */
15355 trace_pass_command (char *args
, int from_tty
)
15357 struct tracepoint
*t1
;
15358 unsigned int count
;
15360 if (args
== 0 || *args
== 0)
15361 error (_("passcount command requires an "
15362 "argument (count + optional TP num)"));
15364 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15366 args
= skip_spaces (args
);
15367 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15369 struct breakpoint
*b
;
15371 args
+= 3; /* Skip special argument "all". */
15373 error (_("Junk at end of arguments."));
15375 ALL_TRACEPOINTS (b
)
15377 t1
= (struct tracepoint
*) b
;
15378 trace_pass_set_count (t1
, count
, from_tty
);
15381 else if (*args
== '\0')
15383 t1
= get_tracepoint_by_number (&args
, NULL
);
15385 trace_pass_set_count (t1
, count
, from_tty
);
15389 number_or_range_parser
parser (args
);
15390 while (!parser
.finished ())
15392 t1
= get_tracepoint_by_number (&args
, &parser
);
15394 trace_pass_set_count (t1
, count
, from_tty
);
15399 struct tracepoint
*
15400 get_tracepoint (int num
)
15402 struct breakpoint
*t
;
15404 ALL_TRACEPOINTS (t
)
15405 if (t
->number
== num
)
15406 return (struct tracepoint
*) t
;
15411 /* Find the tracepoint with the given target-side number (which may be
15412 different from the tracepoint number after disconnecting and
15415 struct tracepoint
*
15416 get_tracepoint_by_number_on_target (int num
)
15418 struct breakpoint
*b
;
15420 ALL_TRACEPOINTS (b
)
15422 struct tracepoint
*t
= (struct tracepoint
*) b
;
15424 if (t
->number_on_target
== num
)
15431 /* Utility: parse a tracepoint number and look it up in the list.
15432 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15433 If the argument is missing, the most recent tracepoint
15434 (tracepoint_count) is returned. */
15436 struct tracepoint
*
15437 get_tracepoint_by_number (char **arg
,
15438 number_or_range_parser
*parser
)
15440 struct breakpoint
*t
;
15442 char *instring
= arg
== NULL
? NULL
: *arg
;
15444 if (parser
!= NULL
)
15446 gdb_assert (!parser
->finished ());
15447 tpnum
= parser
->get_number ();
15449 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15450 tpnum
= tracepoint_count
;
15452 tpnum
= get_number (arg
);
15456 if (instring
&& *instring
)
15457 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15460 printf_filtered (_("No previous tracepoint\n"));
15464 ALL_TRACEPOINTS (t
)
15465 if (t
->number
== tpnum
)
15467 return (struct tracepoint
*) t
;
15470 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15475 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15477 if (b
->thread
!= -1)
15478 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15481 fprintf_unfiltered (fp
, " task %d", b
->task
);
15483 fprintf_unfiltered (fp
, "\n");
15486 /* Save information on user settable breakpoints (watchpoints, etc) to
15487 a new script file named FILENAME. If FILTER is non-NULL, call it
15488 on each breakpoint and only include the ones for which it returns
15492 save_breakpoints (char *filename
, int from_tty
,
15493 int (*filter
) (const struct breakpoint
*))
15495 struct breakpoint
*tp
;
15497 struct cleanup
*cleanup
;
15498 int extra_trace_bits
= 0;
15500 if (filename
== 0 || *filename
== 0)
15501 error (_("Argument required (file name in which to save)"));
15503 /* See if we have anything to save. */
15504 ALL_BREAKPOINTS (tp
)
15506 /* Skip internal and momentary breakpoints. */
15507 if (!user_breakpoint_p (tp
))
15510 /* If we have a filter, only save the breakpoints it accepts. */
15511 if (filter
&& !filter (tp
))
15516 if (is_tracepoint (tp
))
15518 extra_trace_bits
= 1;
15520 /* We can stop searching. */
15527 warning (_("Nothing to save."));
15531 filename
= tilde_expand (filename
);
15532 cleanup
= make_cleanup (xfree
, filename
);
15536 if (!fp
.open (filename
, "w"))
15537 error (_("Unable to open file '%s' for saving (%s)"),
15538 filename
, safe_strerror (errno
));
15540 if (extra_trace_bits
)
15541 save_trace_state_variables (&fp
);
15543 ALL_BREAKPOINTS (tp
)
15545 /* Skip internal and momentary breakpoints. */
15546 if (!user_breakpoint_p (tp
))
15549 /* If we have a filter, only save the breakpoints it accepts. */
15550 if (filter
&& !filter (tp
))
15553 tp
->ops
->print_recreate (tp
, &fp
);
15555 /* Note, we can't rely on tp->number for anything, as we can't
15556 assume the recreated breakpoint numbers will match. Use $bpnum
15559 if (tp
->cond_string
)
15560 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15562 if (tp
->ignore_count
)
15563 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15565 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15567 fp
.puts (" commands\n");
15569 current_uiout
->redirect (&fp
);
15572 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15574 CATCH (ex
, RETURN_MASK_ALL
)
15576 current_uiout
->redirect (NULL
);
15577 throw_exception (ex
);
15581 current_uiout
->redirect (NULL
);
15582 fp
.puts (" end\n");
15585 if (tp
->enable_state
== bp_disabled
)
15586 fp
.puts ("disable $bpnum\n");
15588 /* If this is a multi-location breakpoint, check if the locations
15589 should be individually disabled. Watchpoint locations are
15590 special, and not user visible. */
15591 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15593 struct bp_location
*loc
;
15596 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15598 fp
.printf ("disable $bpnum.%d\n", n
);
15602 if (extra_trace_bits
&& *default_collect
)
15603 fp
.printf ("set default-collect %s\n", default_collect
);
15606 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15607 do_cleanups (cleanup
);
15610 /* The `save breakpoints' command. */
15613 save_breakpoints_command (char *args
, int from_tty
)
15615 save_breakpoints (args
, from_tty
, NULL
);
15618 /* The `save tracepoints' command. */
15621 save_tracepoints_command (char *args
, int from_tty
)
15623 save_breakpoints (args
, from_tty
, is_tracepoint
);
15626 /* Create a vector of all tracepoints. */
15628 VEC(breakpoint_p
) *
15629 all_tracepoints (void)
15631 VEC(breakpoint_p
) *tp_vec
= 0;
15632 struct breakpoint
*tp
;
15634 ALL_TRACEPOINTS (tp
)
15636 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15643 /* This help string is used to consolidate all the help string for specifying
15644 locations used by several commands. */
15646 #define LOCATION_HELP_STRING \
15647 "Linespecs are colon-separated lists of location parameters, such as\n\
15648 source filename, function name, label name, and line number.\n\
15649 Example: To specify the start of a label named \"the_top\" in the\n\
15650 function \"fact\" in the file \"factorial.c\", use\n\
15651 \"factorial.c:fact:the_top\".\n\
15653 Address locations begin with \"*\" and specify an exact address in the\n\
15654 program. Example: To specify the fourth byte past the start function\n\
15655 \"main\", use \"*main + 4\".\n\
15657 Explicit locations are similar to linespecs but use an option/argument\n\
15658 syntax to specify location parameters.\n\
15659 Example: To specify the start of the label named \"the_top\" in the\n\
15660 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15661 -function fact -label the_top\".\n"
15663 /* This help string is used for the break, hbreak, tbreak and thbreak
15664 commands. It is defined as a macro to prevent duplication.
15665 COMMAND should be a string constant containing the name of the
15668 #define BREAK_ARGS_HELP(command) \
15669 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15670 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15671 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15672 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15673 `-probe-dtrace' (for a DTrace probe).\n\
15674 LOCATION may be a linespec, address, or explicit location as described\n\
15677 With no LOCATION, uses current execution address of the selected\n\
15678 stack frame. This is useful for breaking on return to a stack frame.\n\
15680 THREADNUM is the number from \"info threads\".\n\
15681 CONDITION is a boolean expression.\n\
15682 \n" LOCATION_HELP_STRING "\n\
15683 Multiple breakpoints at one place are permitted, and useful if their\n\
15684 conditions are different.\n\
15686 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15688 /* List of subcommands for "catch". */
15689 static struct cmd_list_element
*catch_cmdlist
;
15691 /* List of subcommands for "tcatch". */
15692 static struct cmd_list_element
*tcatch_cmdlist
;
15695 add_catch_command (const char *name
, const char *docstring
,
15696 cmd_sfunc_ftype
*sfunc
,
15697 completer_ftype
*completer
,
15698 void *user_data_catch
,
15699 void *user_data_tcatch
)
15701 struct cmd_list_element
*command
;
15703 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15705 set_cmd_sfunc (command
, sfunc
);
15706 set_cmd_context (command
, user_data_catch
);
15707 set_cmd_completer (command
, completer
);
15709 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15711 set_cmd_sfunc (command
, sfunc
);
15712 set_cmd_context (command
, user_data_tcatch
);
15713 set_cmd_completer (command
, completer
);
15717 save_command (char *arg
, int from_tty
)
15719 printf_unfiltered (_("\"save\" must be followed by "
15720 "the name of a save subcommand.\n"));
15721 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15724 struct breakpoint
*
15725 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15728 struct breakpoint
*b
, *b_tmp
;
15730 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15732 if ((*callback
) (b
, data
))
15739 /* Zero if any of the breakpoint's locations could be a location where
15740 functions have been inlined, nonzero otherwise. */
15743 is_non_inline_function (struct breakpoint
*b
)
15745 /* The shared library event breakpoint is set on the address of a
15746 non-inline function. */
15747 if (b
->type
== bp_shlib_event
)
15753 /* Nonzero if the specified PC cannot be a location where functions
15754 have been inlined. */
15757 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15758 const struct target_waitstatus
*ws
)
15760 struct breakpoint
*b
;
15761 struct bp_location
*bl
;
15763 ALL_BREAKPOINTS (b
)
15765 if (!is_non_inline_function (b
))
15768 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15770 if (!bl
->shlib_disabled
15771 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15779 /* Remove any references to OBJFILE which is going to be freed. */
15782 breakpoint_free_objfile (struct objfile
*objfile
)
15784 struct bp_location
**locp
, *loc
;
15786 ALL_BP_LOCATIONS (loc
, locp
)
15787 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15788 loc
->symtab
= NULL
;
15792 initialize_breakpoint_ops (void)
15794 static int initialized
= 0;
15796 struct breakpoint_ops
*ops
;
15802 /* The breakpoint_ops structure to be inherit by all kinds of
15803 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15804 internal and momentary breakpoints, etc.). */
15805 ops
= &bkpt_base_breakpoint_ops
;
15806 *ops
= base_breakpoint_ops
;
15807 ops
->re_set
= bkpt_re_set
;
15808 ops
->insert_location
= bkpt_insert_location
;
15809 ops
->remove_location
= bkpt_remove_location
;
15810 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15811 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15812 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15813 ops
->decode_location
= bkpt_decode_location
;
15815 /* The breakpoint_ops structure to be used in regular breakpoints. */
15816 ops
= &bkpt_breakpoint_ops
;
15817 *ops
= bkpt_base_breakpoint_ops
;
15818 ops
->re_set
= bkpt_re_set
;
15819 ops
->resources_needed
= bkpt_resources_needed
;
15820 ops
->print_it
= bkpt_print_it
;
15821 ops
->print_mention
= bkpt_print_mention
;
15822 ops
->print_recreate
= bkpt_print_recreate
;
15824 /* Ranged breakpoints. */
15825 ops
= &ranged_breakpoint_ops
;
15826 *ops
= bkpt_breakpoint_ops
;
15827 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15828 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15829 ops
->print_it
= print_it_ranged_breakpoint
;
15830 ops
->print_one
= print_one_ranged_breakpoint
;
15831 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15832 ops
->print_mention
= print_mention_ranged_breakpoint
;
15833 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15835 /* Internal breakpoints. */
15836 ops
= &internal_breakpoint_ops
;
15837 *ops
= bkpt_base_breakpoint_ops
;
15838 ops
->re_set
= internal_bkpt_re_set
;
15839 ops
->check_status
= internal_bkpt_check_status
;
15840 ops
->print_it
= internal_bkpt_print_it
;
15841 ops
->print_mention
= internal_bkpt_print_mention
;
15843 /* Momentary breakpoints. */
15844 ops
= &momentary_breakpoint_ops
;
15845 *ops
= bkpt_base_breakpoint_ops
;
15846 ops
->re_set
= momentary_bkpt_re_set
;
15847 ops
->check_status
= momentary_bkpt_check_status
;
15848 ops
->print_it
= momentary_bkpt_print_it
;
15849 ops
->print_mention
= momentary_bkpt_print_mention
;
15851 /* Probe breakpoints. */
15852 ops
= &bkpt_probe_breakpoint_ops
;
15853 *ops
= bkpt_breakpoint_ops
;
15854 ops
->insert_location
= bkpt_probe_insert_location
;
15855 ops
->remove_location
= bkpt_probe_remove_location
;
15856 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15857 ops
->decode_location
= bkpt_probe_decode_location
;
15860 ops
= &watchpoint_breakpoint_ops
;
15861 *ops
= base_breakpoint_ops
;
15862 ops
->re_set
= re_set_watchpoint
;
15863 ops
->insert_location
= insert_watchpoint
;
15864 ops
->remove_location
= remove_watchpoint
;
15865 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15866 ops
->check_status
= check_status_watchpoint
;
15867 ops
->resources_needed
= resources_needed_watchpoint
;
15868 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15869 ops
->print_it
= print_it_watchpoint
;
15870 ops
->print_mention
= print_mention_watchpoint
;
15871 ops
->print_recreate
= print_recreate_watchpoint
;
15872 ops
->explains_signal
= explains_signal_watchpoint
;
15874 /* Masked watchpoints. */
15875 ops
= &masked_watchpoint_breakpoint_ops
;
15876 *ops
= watchpoint_breakpoint_ops
;
15877 ops
->insert_location
= insert_masked_watchpoint
;
15878 ops
->remove_location
= remove_masked_watchpoint
;
15879 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15880 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15881 ops
->print_it
= print_it_masked_watchpoint
;
15882 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15883 ops
->print_mention
= print_mention_masked_watchpoint
;
15884 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15887 ops
= &tracepoint_breakpoint_ops
;
15888 *ops
= base_breakpoint_ops
;
15889 ops
->re_set
= tracepoint_re_set
;
15890 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15891 ops
->print_one_detail
= tracepoint_print_one_detail
;
15892 ops
->print_mention
= tracepoint_print_mention
;
15893 ops
->print_recreate
= tracepoint_print_recreate
;
15894 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15895 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15896 ops
->decode_location
= tracepoint_decode_location
;
15898 /* Probe tracepoints. */
15899 ops
= &tracepoint_probe_breakpoint_ops
;
15900 *ops
= tracepoint_breakpoint_ops
;
15901 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15902 ops
->decode_location
= tracepoint_probe_decode_location
;
15904 /* Static tracepoints with marker (`-m'). */
15905 ops
= &strace_marker_breakpoint_ops
;
15906 *ops
= tracepoint_breakpoint_ops
;
15907 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15908 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15909 ops
->decode_location
= strace_marker_decode_location
;
15911 /* Fork catchpoints. */
15912 ops
= &catch_fork_breakpoint_ops
;
15913 *ops
= base_breakpoint_ops
;
15914 ops
->insert_location
= insert_catch_fork
;
15915 ops
->remove_location
= remove_catch_fork
;
15916 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15917 ops
->print_it
= print_it_catch_fork
;
15918 ops
->print_one
= print_one_catch_fork
;
15919 ops
->print_mention
= print_mention_catch_fork
;
15920 ops
->print_recreate
= print_recreate_catch_fork
;
15922 /* Vfork catchpoints. */
15923 ops
= &catch_vfork_breakpoint_ops
;
15924 *ops
= base_breakpoint_ops
;
15925 ops
->insert_location
= insert_catch_vfork
;
15926 ops
->remove_location
= remove_catch_vfork
;
15927 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15928 ops
->print_it
= print_it_catch_vfork
;
15929 ops
->print_one
= print_one_catch_vfork
;
15930 ops
->print_mention
= print_mention_catch_vfork
;
15931 ops
->print_recreate
= print_recreate_catch_vfork
;
15933 /* Exec catchpoints. */
15934 ops
= &catch_exec_breakpoint_ops
;
15935 *ops
= base_breakpoint_ops
;
15936 ops
->insert_location
= insert_catch_exec
;
15937 ops
->remove_location
= remove_catch_exec
;
15938 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15939 ops
->print_it
= print_it_catch_exec
;
15940 ops
->print_one
= print_one_catch_exec
;
15941 ops
->print_mention
= print_mention_catch_exec
;
15942 ops
->print_recreate
= print_recreate_catch_exec
;
15944 /* Solib-related catchpoints. */
15945 ops
= &catch_solib_breakpoint_ops
;
15946 *ops
= base_breakpoint_ops
;
15947 ops
->insert_location
= insert_catch_solib
;
15948 ops
->remove_location
= remove_catch_solib
;
15949 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15950 ops
->check_status
= check_status_catch_solib
;
15951 ops
->print_it
= print_it_catch_solib
;
15952 ops
->print_one
= print_one_catch_solib
;
15953 ops
->print_mention
= print_mention_catch_solib
;
15954 ops
->print_recreate
= print_recreate_catch_solib
;
15956 ops
= &dprintf_breakpoint_ops
;
15957 *ops
= bkpt_base_breakpoint_ops
;
15958 ops
->re_set
= dprintf_re_set
;
15959 ops
->resources_needed
= bkpt_resources_needed
;
15960 ops
->print_it
= bkpt_print_it
;
15961 ops
->print_mention
= bkpt_print_mention
;
15962 ops
->print_recreate
= dprintf_print_recreate
;
15963 ops
->after_condition_true
= dprintf_after_condition_true
;
15964 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15967 /* Chain containing all defined "enable breakpoint" subcommands. */
15969 static struct cmd_list_element
*enablebreaklist
= NULL
;
15972 _initialize_breakpoint (void)
15974 struct cmd_list_element
*c
;
15976 initialize_breakpoint_ops ();
15978 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15979 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15980 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15982 breakpoint_objfile_key
15983 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15985 breakpoint_chain
= 0;
15986 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15987 before a breakpoint is set. */
15988 breakpoint_count
= 0;
15990 tracepoint_count
= 0;
15992 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15993 Set ignore-count of breakpoint number N to COUNT.\n\
15994 Usage is `ignore N COUNT'."));
15996 add_com ("commands", class_breakpoint
, commands_command
, _("\
15997 Set commands to be executed when the given breakpoints are hit.\n\
15998 Give a space-separated breakpoint list as argument after \"commands\".\n\
15999 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
16001 With no argument, the targeted breakpoint is the last one set.\n\
16002 The commands themselves follow starting on the next line.\n\
16003 Type a line containing \"end\" to indicate the end of them.\n\
16004 Give \"silent\" as the first line to make the breakpoint silent;\n\
16005 then no output is printed when it is hit, except what the commands print."));
16007 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16008 Specify breakpoint number N to break only if COND is true.\n\
16009 Usage is `condition N COND', where N is an integer and COND is an\n\
16010 expression to be evaluated whenever breakpoint N is reached."));
16011 set_cmd_completer (c
, condition_completer
);
16013 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16014 Set a temporary breakpoint.\n\
16015 Like \"break\" except the breakpoint is only temporary,\n\
16016 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16017 by using \"enable delete\" on the breakpoint number.\n\
16019 BREAK_ARGS_HELP ("tbreak")));
16020 set_cmd_completer (c
, location_completer
);
16022 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16023 Set a hardware assisted breakpoint.\n\
16024 Like \"break\" except the breakpoint requires hardware support,\n\
16025 some target hardware may not have this support.\n\
16027 BREAK_ARGS_HELP ("hbreak")));
16028 set_cmd_completer (c
, location_completer
);
16030 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16031 Set a temporary hardware assisted breakpoint.\n\
16032 Like \"hbreak\" except the breakpoint is only temporary,\n\
16033 so it will be deleted when hit.\n\
16035 BREAK_ARGS_HELP ("thbreak")));
16036 set_cmd_completer (c
, location_completer
);
16038 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16039 Enable some breakpoints.\n\
16040 Give breakpoint numbers (separated by spaces) as arguments.\n\
16041 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16042 This is used to cancel the effect of the \"disable\" command.\n\
16043 With a subcommand you can enable temporarily."),
16044 &enablelist
, "enable ", 1, &cmdlist
);
16046 add_com_alias ("en", "enable", class_breakpoint
, 1);
16048 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16049 Enable some breakpoints.\n\
16050 Give breakpoint numbers (separated by spaces) as arguments.\n\
16051 This is used to cancel the effect of the \"disable\" command.\n\
16052 May be abbreviated to simply \"enable\".\n"),
16053 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16055 add_cmd ("once", no_class
, enable_once_command
, _("\
16056 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16057 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16060 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16061 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16062 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16065 add_cmd ("count", no_class
, enable_count_command
, _("\
16066 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16067 If a breakpoint is hit while enabled in this fashion,\n\
16068 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16071 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16072 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16073 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16076 add_cmd ("once", no_class
, enable_once_command
, _("\
16077 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16078 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16081 add_cmd ("count", no_class
, enable_count_command
, _("\
16082 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16083 If a breakpoint is hit while enabled in this fashion,\n\
16084 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16087 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16088 Disable some breakpoints.\n\
16089 Arguments are breakpoint numbers with spaces in between.\n\
16090 To disable all breakpoints, give no argument.\n\
16091 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16092 &disablelist
, "disable ", 1, &cmdlist
);
16093 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16094 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16096 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16097 Disable some breakpoints.\n\
16098 Arguments are breakpoint numbers with spaces in between.\n\
16099 To disable all breakpoints, give no argument.\n\
16100 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16101 This command may be abbreviated \"disable\"."),
16104 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16105 Delete some breakpoints or auto-display expressions.\n\
16106 Arguments are breakpoint numbers with spaces in between.\n\
16107 To delete all breakpoints, give no argument.\n\
16109 Also a prefix command for deletion of other GDB objects.\n\
16110 The \"unset\" command is also an alias for \"delete\"."),
16111 &deletelist
, "delete ", 1, &cmdlist
);
16112 add_com_alias ("d", "delete", class_breakpoint
, 1);
16113 add_com_alias ("del", "delete", class_breakpoint
, 1);
16115 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16116 Delete some breakpoints or auto-display expressions.\n\
16117 Arguments are breakpoint numbers with spaces in between.\n\
16118 To delete all breakpoints, give no argument.\n\
16119 This command may be abbreviated \"delete\"."),
16122 add_com ("clear", class_breakpoint
, clear_command
, _("\
16123 Clear breakpoint at specified location.\n\
16124 Argument may be a linespec, explicit, or address location as described below.\n\
16126 With no argument, clears all breakpoints in the line that the selected frame\n\
16127 is executing in.\n"
16128 "\n" LOCATION_HELP_STRING
"\n\
16129 See also the \"delete\" command which clears breakpoints by number."));
16130 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16132 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16133 Set breakpoint at specified location.\n"
16134 BREAK_ARGS_HELP ("break")));
16135 set_cmd_completer (c
, location_completer
);
16137 add_com_alias ("b", "break", class_run
, 1);
16138 add_com_alias ("br", "break", class_run
, 1);
16139 add_com_alias ("bre", "break", class_run
, 1);
16140 add_com_alias ("brea", "break", class_run
, 1);
16144 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16145 Break in function/address or break at a line in the current file."),
16146 &stoplist
, "stop ", 1, &cmdlist
);
16147 add_cmd ("in", class_breakpoint
, stopin_command
,
16148 _("Break in function or address."), &stoplist
);
16149 add_cmd ("at", class_breakpoint
, stopat_command
,
16150 _("Break at a line in the current file."), &stoplist
);
16151 add_com ("status", class_info
, breakpoints_info
, _("\
16152 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16153 The \"Type\" column indicates one of:\n\
16154 \tbreakpoint - normal breakpoint\n\
16155 \twatchpoint - watchpoint\n\
16156 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16157 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16158 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16159 address and file/line number respectively.\n\
16161 Convenience variable \"$_\" and default examine address for \"x\"\n\
16162 are set to the address of the last breakpoint listed unless the command\n\
16163 is prefixed with \"server \".\n\n\
16164 Convenience variable \"$bpnum\" contains the number of the last\n\
16165 breakpoint set."));
16168 add_info ("breakpoints", breakpoints_info
, _("\
16169 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16170 The \"Type\" column indicates one of:\n\
16171 \tbreakpoint - normal breakpoint\n\
16172 \twatchpoint - watchpoint\n\
16173 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16174 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16175 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16176 address and file/line number respectively.\n\
16178 Convenience variable \"$_\" and default examine address for \"x\"\n\
16179 are set to the address of the last breakpoint listed unless the command\n\
16180 is prefixed with \"server \".\n\n\
16181 Convenience variable \"$bpnum\" contains the number of the last\n\
16182 breakpoint set."));
16184 add_info_alias ("b", "breakpoints", 1);
16186 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16187 Status of all breakpoints, or breakpoint number NUMBER.\n\
16188 The \"Type\" column indicates one of:\n\
16189 \tbreakpoint - normal breakpoint\n\
16190 \twatchpoint - watchpoint\n\
16191 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16192 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16193 \tuntil - internal breakpoint used by the \"until\" command\n\
16194 \tfinish - internal breakpoint used by the \"finish\" command\n\
16195 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16196 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16197 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16198 address and file/line number respectively.\n\
16200 Convenience variable \"$_\" and default examine address for \"x\"\n\
16201 are set to the address of the last breakpoint listed unless the command\n\
16202 is prefixed with \"server \".\n\n\
16203 Convenience variable \"$bpnum\" contains the number of the last\n\
16205 &maintenanceinfolist
);
16207 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16208 Set catchpoints to catch events."),
16209 &catch_cmdlist
, "catch ",
16210 0/*allow-unknown*/, &cmdlist
);
16212 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16213 Set temporary catchpoints to catch events."),
16214 &tcatch_cmdlist
, "tcatch ",
16215 0/*allow-unknown*/, &cmdlist
);
16217 add_catch_command ("fork", _("Catch calls to fork."),
16218 catch_fork_command_1
,
16220 (void *) (uintptr_t) catch_fork_permanent
,
16221 (void *) (uintptr_t) catch_fork_temporary
);
16222 add_catch_command ("vfork", _("Catch calls to vfork."),
16223 catch_fork_command_1
,
16225 (void *) (uintptr_t) catch_vfork_permanent
,
16226 (void *) (uintptr_t) catch_vfork_temporary
);
16227 add_catch_command ("exec", _("Catch calls to exec."),
16228 catch_exec_command_1
,
16232 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16233 Usage: catch load [REGEX]\n\
16234 If REGEX is given, only stop for libraries matching the regular expression."),
16235 catch_load_command_1
,
16239 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16240 Usage: catch unload [REGEX]\n\
16241 If REGEX is given, only stop for libraries matching the regular expression."),
16242 catch_unload_command_1
,
16247 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16248 Set a watchpoint for an expression.\n\
16249 Usage: watch [-l|-location] EXPRESSION\n\
16250 A watchpoint stops execution of your program whenever the value of\n\
16251 an expression changes.\n\
16252 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16253 the memory to which it refers."));
16254 set_cmd_completer (c
, expression_completer
);
16256 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16257 Set a read watchpoint for an expression.\n\
16258 Usage: rwatch [-l|-location] EXPRESSION\n\
16259 A watchpoint stops execution of your program whenever the value of\n\
16260 an expression is read.\n\
16261 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16262 the memory to which it refers."));
16263 set_cmd_completer (c
, expression_completer
);
16265 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16266 Set a watchpoint for an expression.\n\
16267 Usage: awatch [-l|-location] EXPRESSION\n\
16268 A watchpoint stops execution of your program whenever the value of\n\
16269 an expression is either read or written.\n\
16270 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16271 the memory to which it refers."));
16272 set_cmd_completer (c
, expression_completer
);
16274 add_info ("watchpoints", watchpoints_info
, _("\
16275 Status of specified watchpoints (all watchpoints if no argument)."));
16277 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16278 respond to changes - contrary to the description. */
16279 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16280 &can_use_hw_watchpoints
, _("\
16281 Set debugger's willingness to use watchpoint hardware."), _("\
16282 Show debugger's willingness to use watchpoint hardware."), _("\
16283 If zero, gdb will not use hardware for new watchpoints, even if\n\
16284 such is available. (However, any hardware watchpoints that were\n\
16285 created before setting this to nonzero, will continue to use watchpoint\n\
16288 show_can_use_hw_watchpoints
,
16289 &setlist
, &showlist
);
16291 can_use_hw_watchpoints
= 1;
16293 /* Tracepoint manipulation commands. */
16295 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16296 Set a tracepoint at specified location.\n\
16298 BREAK_ARGS_HELP ("trace") "\n\
16299 Do \"help tracepoints\" for info on other tracepoint commands."));
16300 set_cmd_completer (c
, location_completer
);
16302 add_com_alias ("tp", "trace", class_alias
, 0);
16303 add_com_alias ("tr", "trace", class_alias
, 1);
16304 add_com_alias ("tra", "trace", class_alias
, 1);
16305 add_com_alias ("trac", "trace", class_alias
, 1);
16307 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16308 Set a fast tracepoint at specified location.\n\
16310 BREAK_ARGS_HELP ("ftrace") "\n\
16311 Do \"help tracepoints\" for info on other tracepoint commands."));
16312 set_cmd_completer (c
, location_completer
);
16314 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16315 Set a static tracepoint at location or marker.\n\
16317 strace [LOCATION] [if CONDITION]\n\
16318 LOCATION may be a linespec, explicit, or address location (described below) \n\
16319 or -m MARKER_ID.\n\n\
16320 If a marker id is specified, probe the marker with that name. With\n\
16321 no LOCATION, uses current execution address of the selected stack frame.\n\
16322 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16323 This collects arbitrary user data passed in the probe point call to the\n\
16324 tracing library. You can inspect it when analyzing the trace buffer,\n\
16325 by printing the $_sdata variable like any other convenience variable.\n\
16327 CONDITION is a boolean expression.\n\
16328 \n" LOCATION_HELP_STRING
"\n\
16329 Multiple tracepoints at one place are permitted, and useful if their\n\
16330 conditions are different.\n\
16332 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16333 Do \"help tracepoints\" for info on other tracepoint commands."));
16334 set_cmd_completer (c
, location_completer
);
16336 add_info ("tracepoints", tracepoints_info
, _("\
16337 Status of specified tracepoints (all tracepoints if no argument).\n\
16338 Convenience variable \"$tpnum\" contains the number of the\n\
16339 last tracepoint set."));
16341 add_info_alias ("tp", "tracepoints", 1);
16343 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16344 Delete specified tracepoints.\n\
16345 Arguments are tracepoint numbers, separated by spaces.\n\
16346 No argument means delete all tracepoints."),
16348 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16350 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16351 Disable specified tracepoints.\n\
16352 Arguments are tracepoint numbers, separated by spaces.\n\
16353 No argument means disable all tracepoints."),
16355 deprecate_cmd (c
, "disable");
16357 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16358 Enable specified tracepoints.\n\
16359 Arguments are tracepoint numbers, separated by spaces.\n\
16360 No argument means enable all tracepoints."),
16362 deprecate_cmd (c
, "enable");
16364 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16365 Set the passcount for a tracepoint.\n\
16366 The trace will end when the tracepoint has been passed 'count' times.\n\
16367 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16368 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16370 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16371 _("Save breakpoint definitions as a script."),
16372 &save_cmdlist
, "save ",
16373 0/*allow-unknown*/, &cmdlist
);
16375 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16376 Save current breakpoint definitions as a script.\n\
16377 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16378 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16379 session to restore them."),
16381 set_cmd_completer (c
, filename_completer
);
16383 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16384 Save current tracepoint definitions as a script.\n\
16385 Use the 'source' command in another debug session to restore them."),
16387 set_cmd_completer (c
, filename_completer
);
16389 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16390 deprecate_cmd (c
, "save tracepoints");
16392 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16393 Breakpoint specific settings\n\
16394 Configure various breakpoint-specific variables such as\n\
16395 pending breakpoint behavior"),
16396 &breakpoint_set_cmdlist
, "set breakpoint ",
16397 0/*allow-unknown*/, &setlist
);
16398 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16399 Breakpoint specific settings\n\
16400 Configure various breakpoint-specific variables such as\n\
16401 pending breakpoint behavior"),
16402 &breakpoint_show_cmdlist
, "show breakpoint ",
16403 0/*allow-unknown*/, &showlist
);
16405 add_setshow_auto_boolean_cmd ("pending", no_class
,
16406 &pending_break_support
, _("\
16407 Set debugger's behavior regarding pending breakpoints."), _("\
16408 Show debugger's behavior regarding pending breakpoints."), _("\
16409 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16410 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16411 an error. If auto, an unrecognized breakpoint location results in a\n\
16412 user-query to see if a pending breakpoint should be created."),
16414 show_pending_break_support
,
16415 &breakpoint_set_cmdlist
,
16416 &breakpoint_show_cmdlist
);
16418 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16420 add_setshow_boolean_cmd ("auto-hw", no_class
,
16421 &automatic_hardware_breakpoints
, _("\
16422 Set automatic usage of hardware breakpoints."), _("\
16423 Show automatic usage of hardware breakpoints."), _("\
16424 If set, the debugger will automatically use hardware breakpoints for\n\
16425 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16426 a warning will be emitted for such breakpoints."),
16428 show_automatic_hardware_breakpoints
,
16429 &breakpoint_set_cmdlist
,
16430 &breakpoint_show_cmdlist
);
16432 add_setshow_boolean_cmd ("always-inserted", class_support
,
16433 &always_inserted_mode
, _("\
16434 Set mode for inserting breakpoints."), _("\
16435 Show mode for inserting breakpoints."), _("\
16436 When this mode is on, breakpoints are inserted immediately as soon as\n\
16437 they're created, kept inserted even when execution stops, and removed\n\
16438 only when the user deletes them. When this mode is off (the default),\n\
16439 breakpoints are inserted only when execution continues, and removed\n\
16440 when execution stops."),
16442 &show_always_inserted_mode
,
16443 &breakpoint_set_cmdlist
,
16444 &breakpoint_show_cmdlist
);
16446 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16447 condition_evaluation_enums
,
16448 &condition_evaluation_mode_1
, _("\
16449 Set mode of breakpoint condition evaluation."), _("\
16450 Show mode of breakpoint condition evaluation."), _("\
16451 When this is set to \"host\", breakpoint conditions will be\n\
16452 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16453 breakpoint conditions will be downloaded to the target (if the target\n\
16454 supports such feature) and conditions will be evaluated on the target's side.\n\
16455 If this is set to \"auto\" (default), this will be automatically set to\n\
16456 \"target\" if it supports condition evaluation, otherwise it will\n\
16457 be set to \"gdb\""),
16458 &set_condition_evaluation_mode
,
16459 &show_condition_evaluation_mode
,
16460 &breakpoint_set_cmdlist
,
16461 &breakpoint_show_cmdlist
);
16463 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16464 Set a breakpoint for an address range.\n\
16465 break-range START-LOCATION, END-LOCATION\n\
16466 where START-LOCATION and END-LOCATION can be one of the following:\n\
16467 LINENUM, for that line in the current file,\n\
16468 FILE:LINENUM, for that line in that file,\n\
16469 +OFFSET, for that number of lines after the current line\n\
16470 or the start of the range\n\
16471 FUNCTION, for the first line in that function,\n\
16472 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16473 *ADDRESS, for the instruction at that address.\n\
16475 The breakpoint will stop execution of the inferior whenever it executes\n\
16476 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16477 range (including START-LOCATION and END-LOCATION)."));
16479 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16480 Set a dynamic printf at specified location.\n\
16481 dprintf location,format string,arg1,arg2,...\n\
16482 location may be a linespec, explicit, or address location.\n"
16483 "\n" LOCATION_HELP_STRING
));
16484 set_cmd_completer (c
, location_completer
);
16486 add_setshow_enum_cmd ("dprintf-style", class_support
,
16487 dprintf_style_enums
, &dprintf_style
, _("\
16488 Set the style of usage for dynamic printf."), _("\
16489 Show the style of usage for dynamic printf."), _("\
16490 This setting chooses how GDB will do a dynamic printf.\n\
16491 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16492 console, as with the \"printf\" command.\n\
16493 If the value is \"call\", the print is done by calling a function in your\n\
16494 program; by default printf(), but you can choose a different function or\n\
16495 output stream by setting dprintf-function and dprintf-channel."),
16496 update_dprintf_commands
, NULL
,
16497 &setlist
, &showlist
);
16499 dprintf_function
= xstrdup ("printf");
16500 add_setshow_string_cmd ("dprintf-function", class_support
,
16501 &dprintf_function
, _("\
16502 Set the function to use for dynamic printf"), _("\
16503 Show the function to use for dynamic printf"), NULL
,
16504 update_dprintf_commands
, NULL
,
16505 &setlist
, &showlist
);
16507 dprintf_channel
= xstrdup ("");
16508 add_setshow_string_cmd ("dprintf-channel", class_support
,
16509 &dprintf_channel
, _("\
16510 Set the channel to use for dynamic printf"), _("\
16511 Show the channel to use for dynamic printf"), NULL
,
16512 update_dprintf_commands
, NULL
,
16513 &setlist
, &showlist
);
16515 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16516 &disconnected_dprintf
, _("\
16517 Set whether dprintf continues after GDB disconnects."), _("\
16518 Show whether dprintf continues after GDB disconnects."), _("\
16519 Use this to let dprintf commands continue to hit and produce output\n\
16520 even if GDB disconnects or detaches from the target."),
16523 &setlist
, &showlist
);
16525 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16526 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16527 (target agent only) This is useful for formatted output in user-defined commands."));
16529 automatic_hardware_breakpoints
= 1;
16531 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16532 observer_attach_thread_exit (remove_threaded_breakpoints
);