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"
84 #include "common/array-view.h"
85 #include "common/gdb_optional.h"
87 /* Enums for exception-handling support. */
88 enum exception_event_kind
95 /* Prototypes for local functions. */
97 static void disable_command (char *, int);
99 static void enable_command (char *, int);
101 static void map_breakpoint_numbers (const char *,
102 gdb::function_view
<void (breakpoint
*)>);
104 static void ignore_command (char *, int);
106 static int breakpoint_re_set_one (void *);
108 static void breakpoint_re_set_default (struct breakpoint
*);
111 create_sals_from_location_default (const struct event_location
*location
,
112 struct linespec_result
*canonical
,
113 enum bptype type_wanted
);
115 static void create_breakpoints_sal_default (struct gdbarch
*,
116 struct linespec_result
*,
117 gdb::unique_xmalloc_ptr
<char>,
118 gdb::unique_xmalloc_ptr
<char>,
120 enum bpdisp
, int, int,
122 const struct breakpoint_ops
*,
123 int, int, int, unsigned);
125 static std::vector
<symtab_and_line
> decode_location_default
126 (struct breakpoint
*b
, const struct event_location
*location
,
127 struct program_space
*search_pspace
);
129 static void clear_command (char *, int);
131 static void catch_command (char *, int);
133 static int can_use_hardware_watchpoint (struct value
*);
135 static void mention (struct breakpoint
*);
137 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
139 const struct breakpoint_ops
*);
140 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
141 const struct symtab_and_line
*);
143 /* This function is used in gdbtk sources and thus can not be made
145 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
146 struct symtab_and_line
,
148 const struct breakpoint_ops
*);
150 static struct breakpoint
*
151 momentary_breakpoint_from_master (struct breakpoint
*orig
,
153 const struct breakpoint_ops
*ops
,
156 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
158 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
162 static void describe_other_breakpoints (struct gdbarch
*,
163 struct program_space
*, CORE_ADDR
,
164 struct obj_section
*, int);
166 static int watchpoint_locations_match (struct bp_location
*loc1
,
167 struct bp_location
*loc2
);
169 static int breakpoint_location_address_match (struct bp_location
*bl
,
170 struct address_space
*aspace
,
173 static int breakpoint_location_address_range_overlap (struct bp_location
*,
174 struct address_space
*,
177 static void info_breakpoints_command (char *, int);
179 static void info_watchpoints_command (char *, int);
181 static int breakpoint_cond_eval (void *);
183 static void cleanup_executing_breakpoints (void *);
185 static void commands_command (char *, int);
187 static void condition_command (char *, int);
189 static int remove_breakpoint (struct bp_location
*);
190 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
192 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
194 static int watchpoint_check (void *);
196 static int hw_breakpoint_used_count (void);
198 static int hw_watchpoint_use_count (struct breakpoint
*);
200 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
202 int *other_type_used
);
204 static void hbreak_command (char *, int);
206 static void thbreak_command (char *, int);
208 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
211 static void stop_command (char *arg
, int from_tty
);
213 static void tcatch_command (char *arg
, int from_tty
);
215 static void free_bp_location (struct bp_location
*loc
);
216 static void incref_bp_location (struct bp_location
*loc
);
217 static void decref_bp_location (struct bp_location
**loc
);
219 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
221 /* update_global_location_list's modes of operation wrt to whether to
222 insert locations now. */
223 enum ugll_insert_mode
225 /* Don't insert any breakpoint locations into the inferior, only
226 remove already-inserted locations that no longer should be
227 inserted. Functions that delete a breakpoint or breakpoints
228 should specify this mode, so that deleting a breakpoint doesn't
229 have the side effect of inserting the locations of other
230 breakpoints that are marked not-inserted, but should_be_inserted
231 returns true on them.
233 This behavior is useful is situations close to tear-down -- e.g.,
234 after an exec, while the target still has execution, but
235 breakpoint shadows of the previous executable image should *NOT*
236 be restored to the new image; or before detaching, where the
237 target still has execution and wants to delete breakpoints from
238 GDB's lists, and all breakpoints had already been removed from
242 /* May insert breakpoints iff breakpoints_should_be_inserted_now
243 claims breakpoints should be inserted now. */
246 /* Insert locations now, irrespective of
247 breakpoints_should_be_inserted_now. E.g., say all threads are
248 stopped right now, and the user did "continue". We need to
249 insert breakpoints _before_ resuming the target, but
250 UGLL_MAY_INSERT wouldn't insert them, because
251 breakpoints_should_be_inserted_now returns false at that point,
252 as no thread is running yet. */
256 static void update_global_location_list (enum ugll_insert_mode
);
258 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
260 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
262 static void insert_breakpoint_locations (void);
264 static void info_tracepoints_command (char *, int);
266 static void enable_trace_command (char *, int);
268 static void disable_trace_command (char *, int);
270 static void trace_pass_command (char *, int);
272 static void set_tracepoint_count (int num
);
274 static int is_masked_watchpoint (const struct breakpoint
*b
);
276 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
278 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
281 static int strace_marker_p (struct breakpoint
*b
);
283 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
284 that are implemented on top of software or hardware breakpoints
285 (user breakpoints, internal and momentary breakpoints, etc.). */
286 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
288 /* Internal breakpoints class type. */
289 static struct breakpoint_ops internal_breakpoint_ops
;
291 /* Momentary breakpoints class type. */
292 static struct breakpoint_ops momentary_breakpoint_ops
;
294 /* The breakpoint_ops structure to be used in regular user created
296 struct breakpoint_ops bkpt_breakpoint_ops
;
298 /* Breakpoints set on probes. */
299 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
301 /* Dynamic printf class type. */
302 struct breakpoint_ops dprintf_breakpoint_ops
;
304 /* The style in which to perform a dynamic printf. This is a user
305 option because different output options have different tradeoffs;
306 if GDB does the printing, there is better error handling if there
307 is a problem with any of the arguments, but using an inferior
308 function lets you have special-purpose printers and sending of
309 output to the same place as compiled-in print functions. */
311 static const char dprintf_style_gdb
[] = "gdb";
312 static const char dprintf_style_call
[] = "call";
313 static const char dprintf_style_agent
[] = "agent";
314 static const char *const dprintf_style_enums
[] = {
320 static const char *dprintf_style
= dprintf_style_gdb
;
322 /* The function to use for dynamic printf if the preferred style is to
323 call into the inferior. The value is simply a string that is
324 copied into the command, so it can be anything that GDB can
325 evaluate to a callable address, not necessarily a function name. */
327 static char *dprintf_function
;
329 /* The channel to use for dynamic printf if the preferred style is to
330 call into the inferior; if a nonempty string, it will be passed to
331 the call as the first argument, with the format string as the
332 second. As with the dprintf function, this can be anything that
333 GDB knows how to evaluate, so in addition to common choices like
334 "stderr", this could be an app-specific expression like
335 "mystreams[curlogger]". */
337 static char *dprintf_channel
;
339 /* True if dprintf commands should continue to operate even if GDB
341 static int disconnected_dprintf
= 1;
343 struct command_line
*
344 breakpoint_commands (struct breakpoint
*b
)
346 return b
->commands
? b
->commands
.get () : NULL
;
349 /* Flag indicating that a command has proceeded the inferior past the
350 current breakpoint. */
352 static int breakpoint_proceeded
;
355 bpdisp_text (enum bpdisp disp
)
357 /* NOTE: the following values are a part of MI protocol and
358 represent values of 'disp' field returned when inferior stops at
360 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
362 return bpdisps
[(int) disp
];
365 /* Prototypes for exported functions. */
366 /* If FALSE, gdb will not use hardware support for watchpoints, even
367 if such is available. */
368 static int can_use_hw_watchpoints
;
371 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
372 struct cmd_list_element
*c
,
375 fprintf_filtered (file
,
376 _("Debugger's willingness to use "
377 "watchpoint hardware is %s.\n"),
381 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
382 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
383 for unrecognized breakpoint locations.
384 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
385 static enum auto_boolean pending_break_support
;
387 show_pending_break_support (struct ui_file
*file
, int from_tty
,
388 struct cmd_list_element
*c
,
391 fprintf_filtered (file
,
392 _("Debugger's behavior regarding "
393 "pending breakpoints is %s.\n"),
397 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
398 set with "break" but falling in read-only memory.
399 If 0, gdb will warn about such breakpoints, but won't automatically
400 use hardware breakpoints. */
401 static int automatic_hardware_breakpoints
;
403 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
404 struct cmd_list_element
*c
,
407 fprintf_filtered (file
,
408 _("Automatic usage of hardware breakpoints is %s.\n"),
412 /* If on, GDB keeps breakpoints inserted even if the inferior is
413 stopped, and immediately inserts any new breakpoints as soon as
414 they're created. If off (default), GDB keeps breakpoints off of
415 the target as long as possible. That is, it delays inserting
416 breakpoints until the next resume, and removes them again when the
417 target fully stops. This is a bit safer in case GDB crashes while
418 processing user input. */
419 static int always_inserted_mode
= 0;
422 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
423 struct cmd_list_element
*c
, const char *value
)
425 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
429 /* See breakpoint.h. */
432 breakpoints_should_be_inserted_now (void)
434 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
436 /* If breakpoints are global, they should be inserted even if no
437 thread under gdb's control is running, or even if there are
438 no threads under GDB's control yet. */
441 else if (target_has_execution
)
443 struct thread_info
*tp
;
445 if (always_inserted_mode
)
447 /* The user wants breakpoints inserted even if all threads
452 if (threads_are_executing ())
455 /* Don't remove breakpoints yet if, even though all threads are
456 stopped, we still have events to process. */
457 ALL_NON_EXITED_THREADS (tp
)
459 && tp
->suspend
.waitstatus_pending_p
)
465 static const char condition_evaluation_both
[] = "host or target";
467 /* Modes for breakpoint condition evaluation. */
468 static const char condition_evaluation_auto
[] = "auto";
469 static const char condition_evaluation_host
[] = "host";
470 static const char condition_evaluation_target
[] = "target";
471 static const char *const condition_evaluation_enums
[] = {
472 condition_evaluation_auto
,
473 condition_evaluation_host
,
474 condition_evaluation_target
,
478 /* Global that holds the current mode for breakpoint condition evaluation. */
479 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
481 /* Global that we use to display information to the user (gets its value from
482 condition_evaluation_mode_1. */
483 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
485 /* Translate a condition evaluation mode MODE into either "host"
486 or "target". This is used mostly to translate from "auto" to the
487 real setting that is being used. It returns the translated
491 translate_condition_evaluation_mode (const char *mode
)
493 if (mode
== condition_evaluation_auto
)
495 if (target_supports_evaluation_of_breakpoint_conditions ())
496 return condition_evaluation_target
;
498 return condition_evaluation_host
;
504 /* Discovers what condition_evaluation_auto translates to. */
507 breakpoint_condition_evaluation_mode (void)
509 return translate_condition_evaluation_mode (condition_evaluation_mode
);
512 /* Return true if GDB should evaluate breakpoint conditions or false
516 gdb_evaluates_breakpoint_condition_p (void)
518 const char *mode
= breakpoint_condition_evaluation_mode ();
520 return (mode
== condition_evaluation_host
);
523 /* Are we executing breakpoint commands? */
524 static int executing_breakpoint_commands
;
526 /* Are overlay event breakpoints enabled? */
527 static int overlay_events_enabled
;
529 /* See description in breakpoint.h. */
530 int target_exact_watchpoints
= 0;
532 /* Walk the following statement or block through all breakpoints.
533 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
534 current breakpoint. */
536 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
538 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
539 for (B = breakpoint_chain; \
540 B ? (TMP=B->next, 1): 0; \
543 /* Similar iterator for the low-level breakpoints. SAFE variant is
544 not provided so update_global_location_list must not be called
545 while executing the block of ALL_BP_LOCATIONS. */
547 #define ALL_BP_LOCATIONS(B,BP_TMP) \
548 for (BP_TMP = bp_locations; \
549 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
552 /* Iterates through locations with address ADDRESS for the currently selected
553 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
554 to where the loop should start from.
555 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
556 appropriate location to start with. */
558 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
559 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
560 BP_LOCP_TMP = BP_LOCP_START; \
562 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
563 && (*BP_LOCP_TMP)->address == ADDRESS); \
566 /* Iterator for tracepoints only. */
568 #define ALL_TRACEPOINTS(B) \
569 for (B = breakpoint_chain; B; B = B->next) \
570 if (is_tracepoint (B))
572 /* Chains of all breakpoints defined. */
574 struct breakpoint
*breakpoint_chain
;
576 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
578 static struct bp_location
**bp_locations
;
580 /* Number of elements of BP_LOCATIONS. */
582 static unsigned bp_locations_count
;
584 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
585 ADDRESS for the current elements of BP_LOCATIONS which get a valid
586 result from bp_location_has_shadow. You can use it for roughly
587 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
588 an address you need to read. */
590 static CORE_ADDR bp_locations_placed_address_before_address_max
;
592 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
593 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
594 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
595 You can use it for roughly limiting the subrange of BP_LOCATIONS to
596 scan for shadow bytes for an address you need to read. */
598 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
600 /* The locations that no longer correspond to any breakpoint, unlinked
601 from the bp_locations array, but for which a hit may still be
602 reported by a target. */
603 VEC(bp_location_p
) *moribund_locations
= NULL
;
605 /* Number of last breakpoint made. */
607 static int breakpoint_count
;
609 /* The value of `breakpoint_count' before the last command that
610 created breakpoints. If the last (break-like) command created more
611 than one breakpoint, then the difference between BREAKPOINT_COUNT
612 and PREV_BREAKPOINT_COUNT is more than one. */
613 static int prev_breakpoint_count
;
615 /* Number of last tracepoint made. */
617 static int tracepoint_count
;
619 static struct cmd_list_element
*breakpoint_set_cmdlist
;
620 static struct cmd_list_element
*breakpoint_show_cmdlist
;
621 struct cmd_list_element
*save_cmdlist
;
623 /* See declaration at breakpoint.h. */
626 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
629 struct breakpoint
*b
= NULL
;
633 if (func (b
, user_data
) != 0)
640 /* Return whether a breakpoint is an active enabled breakpoint. */
642 breakpoint_enabled (struct breakpoint
*b
)
644 return (b
->enable_state
== bp_enabled
);
647 /* Set breakpoint count to NUM. */
650 set_breakpoint_count (int num
)
652 prev_breakpoint_count
= breakpoint_count
;
653 breakpoint_count
= num
;
654 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
657 /* Used by `start_rbreak_breakpoints' below, to record the current
658 breakpoint count before "rbreak" creates any breakpoint. */
659 static int rbreak_start_breakpoint_count
;
661 /* Called at the start an "rbreak" command to record the first
665 start_rbreak_breakpoints (void)
667 rbreak_start_breakpoint_count
= breakpoint_count
;
670 /* Called at the end of an "rbreak" command to record the last
674 end_rbreak_breakpoints (void)
676 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
679 /* Used in run_command to zero the hit count when a new run starts. */
682 clear_breakpoint_hit_counts (void)
684 struct breakpoint
*b
;
691 /* Return the breakpoint with the specified number, or NULL
692 if the number does not refer to an existing breakpoint. */
695 get_breakpoint (int num
)
697 struct breakpoint
*b
;
700 if (b
->number
== num
)
708 /* Mark locations as "conditions have changed" in case the target supports
709 evaluating conditions on its side. */
712 mark_breakpoint_modified (struct breakpoint
*b
)
714 struct bp_location
*loc
;
716 /* This is only meaningful if the target is
717 evaluating conditions and if the user has
718 opted for condition evaluation on the target's
720 if (gdb_evaluates_breakpoint_condition_p ()
721 || !target_supports_evaluation_of_breakpoint_conditions ())
724 if (!is_breakpoint (b
))
727 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
728 loc
->condition_changed
= condition_modified
;
731 /* Mark location as "conditions have changed" in case the target supports
732 evaluating conditions on its side. */
735 mark_breakpoint_location_modified (struct bp_location
*loc
)
737 /* This is only meaningful if the target is
738 evaluating conditions and if the user has
739 opted for condition evaluation on the target's
741 if (gdb_evaluates_breakpoint_condition_p ()
742 || !target_supports_evaluation_of_breakpoint_conditions ())
746 if (!is_breakpoint (loc
->owner
))
749 loc
->condition_changed
= condition_modified
;
752 /* Sets the condition-evaluation mode using the static global
753 condition_evaluation_mode. */
756 set_condition_evaluation_mode (char *args
, int from_tty
,
757 struct cmd_list_element
*c
)
759 const char *old_mode
, *new_mode
;
761 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
762 && !target_supports_evaluation_of_breakpoint_conditions ())
764 condition_evaluation_mode_1
= condition_evaluation_mode
;
765 warning (_("Target does not support breakpoint condition evaluation.\n"
766 "Using host evaluation mode instead."));
770 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
771 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
773 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
774 settings was "auto". */
775 condition_evaluation_mode
= condition_evaluation_mode_1
;
777 /* Only update the mode if the user picked a different one. */
778 if (new_mode
!= old_mode
)
780 struct bp_location
*loc
, **loc_tmp
;
781 /* If the user switched to a different evaluation mode, we
782 need to synch the changes with the target as follows:
784 "host" -> "target": Send all (valid) conditions to the target.
785 "target" -> "host": Remove all the conditions from the target.
788 if (new_mode
== condition_evaluation_target
)
790 /* Mark everything modified and synch conditions with the
792 ALL_BP_LOCATIONS (loc
, loc_tmp
)
793 mark_breakpoint_location_modified (loc
);
797 /* Manually mark non-duplicate locations to synch conditions
798 with the target. We do this to remove all the conditions the
799 target knows about. */
800 ALL_BP_LOCATIONS (loc
, loc_tmp
)
801 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
802 loc
->needs_update
= 1;
806 update_global_location_list (UGLL_MAY_INSERT
);
812 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
813 what "auto" is translating to. */
816 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
817 struct cmd_list_element
*c
, const char *value
)
819 if (condition_evaluation_mode
== condition_evaluation_auto
)
820 fprintf_filtered (file
,
821 _("Breakpoint condition evaluation "
822 "mode is %s (currently %s).\n"),
824 breakpoint_condition_evaluation_mode ());
826 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
830 /* A comparison function for bp_location AP and BP that is used by
831 bsearch. This comparison function only cares about addresses, unlike
832 the more general bp_locations_compare function. */
835 bp_locations_compare_addrs (const void *ap
, const void *bp
)
837 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
838 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
840 if (a
->address
== b
->address
)
843 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
846 /* Helper function to skip all bp_locations with addresses
847 less than ADDRESS. It returns the first bp_location that
848 is greater than or equal to ADDRESS. If none is found, just
851 static struct bp_location
**
852 get_first_locp_gte_addr (CORE_ADDR address
)
854 struct bp_location dummy_loc
;
855 struct bp_location
*dummy_locp
= &dummy_loc
;
856 struct bp_location
**locp_found
= NULL
;
858 /* Initialize the dummy location's address field. */
859 dummy_loc
.address
= address
;
861 /* Find a close match to the first location at ADDRESS. */
862 locp_found
= ((struct bp_location
**)
863 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
864 sizeof (struct bp_location
**),
865 bp_locations_compare_addrs
));
867 /* Nothing was found, nothing left to do. */
868 if (locp_found
== NULL
)
871 /* We may have found a location that is at ADDRESS but is not the first in the
872 location's list. Go backwards (if possible) and locate the first one. */
873 while ((locp_found
- 1) >= bp_locations
874 && (*(locp_found
- 1))->address
== address
)
881 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
884 xfree (b
->cond_string
);
885 b
->cond_string
= NULL
;
887 if (is_watchpoint (b
))
889 struct watchpoint
*w
= (struct watchpoint
*) b
;
891 w
->cond_exp
.reset ();
895 struct bp_location
*loc
;
897 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
901 /* No need to free the condition agent expression
902 bytecode (if we have one). We will handle this
903 when we go through update_global_location_list. */
910 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
914 const char *arg
= exp
;
916 /* I don't know if it matters whether this is the string the user
917 typed in or the decompiled expression. */
918 b
->cond_string
= xstrdup (arg
);
919 b
->condition_not_parsed
= 0;
921 if (is_watchpoint (b
))
923 struct watchpoint
*w
= (struct watchpoint
*) b
;
925 innermost_block
= NULL
;
927 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
929 error (_("Junk at end of expression"));
930 w
->cond_exp_valid_block
= innermost_block
;
934 struct bp_location
*loc
;
936 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
940 parse_exp_1 (&arg
, loc
->address
,
941 block_for_pc (loc
->address
), 0);
943 error (_("Junk at end of expression"));
947 mark_breakpoint_modified (b
);
949 observer_notify_breakpoint_modified (b
);
952 /* Completion for the "condition" command. */
955 condition_completer (struct cmd_list_element
*cmd
,
956 completion_tracker
&tracker
,
957 const char *text
, const char *word
)
961 text
= skip_spaces (text
);
962 space
= skip_to_space (text
);
966 struct breakpoint
*b
;
967 VEC (char_ptr
) *result
= NULL
;
971 /* We don't support completion of history indices. */
972 if (!isdigit (text
[1]))
973 complete_internalvar (tracker
, &text
[1]);
977 /* We're completing the breakpoint number. */
984 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
986 if (strncmp (number
, text
, len
) == 0)
988 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
989 tracker
.add_completion (std::move (copy
));
996 /* We're completing the expression part. */
997 text
= skip_spaces (space
);
998 expression_completer (cmd
, tracker
, text
, word
);
1001 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1004 condition_command (char *arg
, int from_tty
)
1006 struct breakpoint
*b
;
1011 error_no_arg (_("breakpoint number"));
1014 bnum
= get_number (&p
);
1016 error (_("Bad breakpoint argument: '%s'"), arg
);
1019 if (b
->number
== bnum
)
1021 /* Check if this breakpoint has a "stop" method implemented in an
1022 extension language. This method and conditions entered into GDB
1023 from the CLI are mutually exclusive. */
1024 const struct extension_language_defn
*extlang
1025 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1027 if (extlang
!= NULL
)
1029 error (_("Only one stop condition allowed. There is currently"
1030 " a %s stop condition defined for this breakpoint."),
1031 ext_lang_capitalized_name (extlang
));
1033 set_breakpoint_condition (b
, p
, from_tty
);
1035 if (is_breakpoint (b
))
1036 update_global_location_list (UGLL_MAY_INSERT
);
1041 error (_("No breakpoint number %d."), bnum
);
1044 /* Check that COMMAND do not contain commands that are suitable
1045 only for tracepoints and not suitable for ordinary breakpoints.
1046 Throw if any such commands is found. */
1049 check_no_tracepoint_commands (struct command_line
*commands
)
1051 struct command_line
*c
;
1053 for (c
= commands
; c
; c
= c
->next
)
1057 if (c
->control_type
== while_stepping_control
)
1058 error (_("The 'while-stepping' command can "
1059 "only be used for tracepoints"));
1061 for (i
= 0; i
< c
->body_count
; ++i
)
1062 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1064 /* Not that command parsing removes leading whitespace and comment
1065 lines and also empty lines. So, we only need to check for
1066 command directly. */
1067 if (strstr (c
->line
, "collect ") == c
->line
)
1068 error (_("The 'collect' command can only be used for tracepoints"));
1070 if (strstr (c
->line
, "teval ") == c
->line
)
1071 error (_("The 'teval' command can only be used for tracepoints"));
1075 struct longjmp_breakpoint
: public breakpoint
1077 ~longjmp_breakpoint () override
;
1080 /* Encapsulate tests for different types of tracepoints. */
1083 is_tracepoint_type (bptype type
)
1085 return (type
== bp_tracepoint
1086 || type
== bp_fast_tracepoint
1087 || type
== bp_static_tracepoint
);
1091 is_longjmp_type (bptype type
)
1093 return type
== bp_longjmp
|| type
== bp_exception
;
1097 is_tracepoint (const struct breakpoint
*b
)
1099 return is_tracepoint_type (b
->type
);
1102 /* Factory function to create an appropriate instance of breakpoint given
1105 static std::unique_ptr
<breakpoint
>
1106 new_breakpoint_from_type (bptype type
)
1110 if (is_tracepoint_type (type
))
1111 b
= new tracepoint ();
1112 else if (is_longjmp_type (type
))
1113 b
= new longjmp_breakpoint ();
1115 b
= new breakpoint ();
1117 return std::unique_ptr
<breakpoint
> (b
);
1120 /* A helper function that validates that COMMANDS are valid for a
1121 breakpoint. This function will throw an exception if a problem is
1125 validate_commands_for_breakpoint (struct breakpoint
*b
,
1126 struct command_line
*commands
)
1128 if (is_tracepoint (b
))
1130 struct tracepoint
*t
= (struct tracepoint
*) b
;
1131 struct command_line
*c
;
1132 struct command_line
*while_stepping
= 0;
1134 /* Reset the while-stepping step count. The previous commands
1135 might have included a while-stepping action, while the new
1139 /* We need to verify that each top-level element of commands is
1140 valid for tracepoints, that there's at most one
1141 while-stepping element, and that the while-stepping's body
1142 has valid tracing commands excluding nested while-stepping.
1143 We also need to validate the tracepoint action line in the
1144 context of the tracepoint --- validate_actionline actually
1145 has side effects, like setting the tracepoint's
1146 while-stepping STEP_COUNT, in addition to checking if the
1147 collect/teval actions parse and make sense in the
1148 tracepoint's context. */
1149 for (c
= commands
; c
; c
= c
->next
)
1151 if (c
->control_type
== while_stepping_control
)
1153 if (b
->type
== bp_fast_tracepoint
)
1154 error (_("The 'while-stepping' command "
1155 "cannot be used for fast tracepoint"));
1156 else if (b
->type
== bp_static_tracepoint
)
1157 error (_("The 'while-stepping' command "
1158 "cannot be used for static tracepoint"));
1161 error (_("The 'while-stepping' command "
1162 "can be used only once"));
1167 validate_actionline (c
->line
, b
);
1171 struct command_line
*c2
;
1173 gdb_assert (while_stepping
->body_count
== 1);
1174 c2
= while_stepping
->body_list
[0];
1175 for (; c2
; c2
= c2
->next
)
1177 if (c2
->control_type
== while_stepping_control
)
1178 error (_("The 'while-stepping' command cannot be nested"));
1184 check_no_tracepoint_commands (commands
);
1188 /* Return a vector of all the static tracepoints set at ADDR. The
1189 caller is responsible for releasing the vector. */
1192 static_tracepoints_here (CORE_ADDR addr
)
1194 struct breakpoint
*b
;
1195 VEC(breakpoint_p
) *found
= 0;
1196 struct bp_location
*loc
;
1199 if (b
->type
== bp_static_tracepoint
)
1201 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1202 if (loc
->address
== addr
)
1203 VEC_safe_push(breakpoint_p
, found
, b
);
1209 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1210 validate that only allowed commands are included. */
1213 breakpoint_set_commands (struct breakpoint
*b
,
1214 command_line_up
&&commands
)
1216 validate_commands_for_breakpoint (b
, commands
.get ());
1218 b
->commands
= std::move (commands
);
1219 observer_notify_breakpoint_modified (b
);
1222 /* Set the internal `silent' flag on the breakpoint. Note that this
1223 is not the same as the "silent" that may appear in the breakpoint's
1227 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1229 int old_silent
= b
->silent
;
1232 if (old_silent
!= silent
)
1233 observer_notify_breakpoint_modified (b
);
1236 /* Set the thread for this breakpoint. If THREAD is -1, make the
1237 breakpoint work for any thread. */
1240 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1242 int old_thread
= b
->thread
;
1245 if (old_thread
!= thread
)
1246 observer_notify_breakpoint_modified (b
);
1249 /* Set the task for this breakpoint. If TASK is 0, make the
1250 breakpoint work for any task. */
1253 breakpoint_set_task (struct breakpoint
*b
, int task
)
1255 int old_task
= b
->task
;
1258 if (old_task
!= task
)
1259 observer_notify_breakpoint_modified (b
);
1263 check_tracepoint_command (char *line
, void *closure
)
1265 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1267 validate_actionline (line
, b
);
1271 commands_command_1 (const char *arg
, int from_tty
,
1272 struct command_line
*control
)
1274 counted_command_line cmd
;
1276 std::string new_arg
;
1278 if (arg
== NULL
|| !*arg
)
1280 if (breakpoint_count
- prev_breakpoint_count
> 1)
1281 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1283 else if (breakpoint_count
> 0)
1284 new_arg
= string_printf ("%d", breakpoint_count
);
1285 arg
= new_arg
.c_str ();
1288 map_breakpoint_numbers
1289 (arg
, [&] (breakpoint
*b
)
1293 if (control
!= NULL
)
1294 cmd
= copy_command_lines (control
->body_list
[0]);
1297 struct cleanup
*old_chain
;
1300 str
= xstrprintf (_("Type commands for breakpoint(s) "
1301 "%s, one per line."),
1304 old_chain
= make_cleanup (xfree
, str
);
1306 cmd
= read_command_lines (str
,
1309 ? check_tracepoint_command
: 0),
1312 do_cleanups (old_chain
);
1316 /* If a breakpoint was on the list more than once, we don't need to
1318 if (b
->commands
!= cmd
)
1320 validate_commands_for_breakpoint (b
, cmd
.get ());
1322 observer_notify_breakpoint_modified (b
);
1327 error (_("No breakpoints specified."));
1331 commands_command (char *arg
, int from_tty
)
1333 commands_command_1 (arg
, from_tty
, NULL
);
1336 /* Like commands_command, but instead of reading the commands from
1337 input stream, takes them from an already parsed command structure.
1339 This is used by cli-script.c to DTRT with breakpoint commands
1340 that are part of if and while bodies. */
1341 enum command_control_type
1342 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1344 commands_command_1 (arg
, 0, cmd
);
1345 return simple_control
;
1348 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1351 bp_location_has_shadow (struct bp_location
*bl
)
1353 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1357 if (bl
->target_info
.shadow_len
== 0)
1358 /* BL isn't valid, or doesn't shadow memory. */
1363 /* Update BUF, which is LEN bytes read from the target address
1364 MEMADDR, by replacing a memory breakpoint with its shadowed
1367 If READBUF is not NULL, this buffer must not overlap with the of
1368 the breakpoint location's shadow_contents buffer. Otherwise, a
1369 failed assertion internal error will be raised. */
1372 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1373 const gdb_byte
*writebuf_org
,
1374 ULONGEST memaddr
, LONGEST len
,
1375 struct bp_target_info
*target_info
,
1376 struct gdbarch
*gdbarch
)
1378 /* Now do full processing of the found relevant range of elements. */
1379 CORE_ADDR bp_addr
= 0;
1383 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1384 current_program_space
->aspace
, 0))
1386 /* The breakpoint is inserted in a different address space. */
1390 /* Addresses and length of the part of the breakpoint that
1392 bp_addr
= target_info
->placed_address
;
1393 bp_size
= target_info
->shadow_len
;
1395 if (bp_addr
+ bp_size
<= memaddr
)
1397 /* The breakpoint is entirely before the chunk of memory we are
1402 if (bp_addr
>= memaddr
+ len
)
1404 /* The breakpoint is entirely after the chunk of memory we are
1409 /* Offset within shadow_contents. */
1410 if (bp_addr
< memaddr
)
1412 /* Only copy the second part of the breakpoint. */
1413 bp_size
-= memaddr
- bp_addr
;
1414 bptoffset
= memaddr
- bp_addr
;
1418 if (bp_addr
+ bp_size
> memaddr
+ len
)
1420 /* Only copy the first part of the breakpoint. */
1421 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1424 if (readbuf
!= NULL
)
1426 /* Verify that the readbuf buffer does not overlap with the
1427 shadow_contents buffer. */
1428 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1429 || readbuf
>= (target_info
->shadow_contents
1430 + target_info
->shadow_len
));
1432 /* Update the read buffer with this inserted breakpoint's
1434 memcpy (readbuf
+ bp_addr
- memaddr
,
1435 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1439 const unsigned char *bp
;
1440 CORE_ADDR addr
= target_info
->reqstd_address
;
1443 /* Update the shadow with what we want to write to memory. */
1444 memcpy (target_info
->shadow_contents
+ bptoffset
,
1445 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1447 /* Determine appropriate breakpoint contents and size for this
1449 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1451 /* Update the final write buffer with this inserted
1452 breakpoint's INSN. */
1453 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1457 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1458 by replacing any memory breakpoints with their shadowed contents.
1460 If READBUF is not NULL, this buffer must not overlap with any of
1461 the breakpoint location's shadow_contents buffers. Otherwise,
1462 a failed assertion internal error will be raised.
1464 The range of shadowed area by each bp_location is:
1465 bl->address - bp_locations_placed_address_before_address_max
1466 up to bl->address + bp_locations_shadow_len_after_address_max
1467 The range we were requested to resolve shadows for is:
1468 memaddr ... memaddr + len
1469 Thus the safe cutoff boundaries for performance optimization are
1470 memaddr + len <= (bl->address
1471 - bp_locations_placed_address_before_address_max)
1473 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1476 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1477 const gdb_byte
*writebuf_org
,
1478 ULONGEST memaddr
, LONGEST len
)
1480 /* Left boundary, right boundary and median element of our binary
1482 unsigned bc_l
, bc_r
, bc
;
1484 /* Find BC_L which is a leftmost element which may affect BUF
1485 content. It is safe to report lower value but a failure to
1486 report higher one. */
1489 bc_r
= bp_locations_count
;
1490 while (bc_l
+ 1 < bc_r
)
1492 struct bp_location
*bl
;
1494 bc
= (bc_l
+ bc_r
) / 2;
1495 bl
= bp_locations
[bc
];
1497 /* Check first BL->ADDRESS will not overflow due to the added
1498 constant. Then advance the left boundary only if we are sure
1499 the BC element can in no way affect the BUF content (MEMADDR
1500 to MEMADDR + LEN range).
1502 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1503 offset so that we cannot miss a breakpoint with its shadow
1504 range tail still reaching MEMADDR. */
1506 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1508 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1515 /* Due to the binary search above, we need to make sure we pick the
1516 first location that's at BC_L's address. E.g., if there are
1517 multiple locations at the same address, BC_L may end up pointing
1518 at a duplicate location, and miss the "master"/"inserted"
1519 location. Say, given locations L1, L2 and L3 at addresses A and
1522 L1@A, L2@A, L3@B, ...
1524 BC_L could end up pointing at location L2, while the "master"
1525 location could be L1. Since the `loc->inserted' flag is only set
1526 on "master" locations, we'd forget to restore the shadow of L1
1529 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1532 /* Now do full processing of the found relevant range of elements. */
1534 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1536 struct bp_location
*bl
= bp_locations
[bc
];
1538 /* bp_location array has BL->OWNER always non-NULL. */
1539 if (bl
->owner
->type
== bp_none
)
1540 warning (_("reading through apparently deleted breakpoint #%d?"),
1543 /* Performance optimization: any further element can no longer affect BUF
1546 if (bl
->address
>= bp_locations_placed_address_before_address_max
1547 && memaddr
+ len
<= (bl
->address
1548 - bp_locations_placed_address_before_address_max
))
1551 if (!bp_location_has_shadow (bl
))
1554 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1555 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1561 /* Return true if BPT is either a software breakpoint or a hardware
1565 is_breakpoint (const struct breakpoint
*bpt
)
1567 return (bpt
->type
== bp_breakpoint
1568 || bpt
->type
== bp_hardware_breakpoint
1569 || bpt
->type
== bp_dprintf
);
1572 /* Return true if BPT is of any hardware watchpoint kind. */
1575 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1577 return (bpt
->type
== bp_hardware_watchpoint
1578 || bpt
->type
== bp_read_watchpoint
1579 || bpt
->type
== bp_access_watchpoint
);
1582 /* Return true if BPT is of any watchpoint kind, hardware or
1586 is_watchpoint (const struct breakpoint
*bpt
)
1588 return (is_hardware_watchpoint (bpt
)
1589 || bpt
->type
== bp_watchpoint
);
1592 /* Returns true if the current thread and its running state are safe
1593 to evaluate or update watchpoint B. Watchpoints on local
1594 expressions need to be evaluated in the context of the thread that
1595 was current when the watchpoint was created, and, that thread needs
1596 to be stopped to be able to select the correct frame context.
1597 Watchpoints on global expressions can be evaluated on any thread,
1598 and in any state. It is presently left to the target allowing
1599 memory accesses when threads are running. */
1602 watchpoint_in_thread_scope (struct watchpoint
*b
)
1604 return (b
->pspace
== current_program_space
1605 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1606 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1607 && !is_executing (inferior_ptid
))));
1610 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1611 associated bp_watchpoint_scope breakpoint. */
1614 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1616 if (w
->related_breakpoint
!= w
)
1618 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1619 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1620 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1621 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1622 w
->related_breakpoint
= w
;
1624 w
->disposition
= disp_del_at_next_stop
;
1627 /* Extract a bitfield value from value VAL using the bit parameters contained in
1630 static struct value
*
1631 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1633 struct value
*bit_val
;
1638 bit_val
= allocate_value (value_type (val
));
1640 unpack_value_bitfield (bit_val
,
1643 value_contents_for_printing (val
),
1650 /* Allocate a dummy location and add it to B, which must be a software
1651 watchpoint. This is required because even if a software watchpoint
1652 is not watching any memory, bpstat_stop_status requires a location
1653 to be able to report stops. */
1656 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1657 struct program_space
*pspace
)
1659 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1661 b
->loc
= allocate_bp_location (b
);
1662 b
->loc
->pspace
= pspace
;
1663 b
->loc
->address
= -1;
1664 b
->loc
->length
= -1;
1667 /* Returns true if B is a software watchpoint that is not watching any
1668 memory (e.g., "watch $pc"). */
1671 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1673 return (b
->type
== bp_watchpoint
1675 && b
->loc
->next
== NULL
1676 && b
->loc
->address
== -1
1677 && b
->loc
->length
== -1);
1680 /* Assuming that B is a watchpoint:
1681 - Reparse watchpoint expression, if REPARSE is non-zero
1682 - Evaluate expression and store the result in B->val
1683 - Evaluate the condition if there is one, and store the result
1685 - Update the list of values that must be watched in B->loc.
1687 If the watchpoint disposition is disp_del_at_next_stop, then do
1688 nothing. If this is local watchpoint that is out of scope, delete
1691 Even with `set breakpoint always-inserted on' the watchpoints are
1692 removed + inserted on each stop here. Normal breakpoints must
1693 never be removed because they might be missed by a running thread
1694 when debugging in non-stop mode. On the other hand, hardware
1695 watchpoints (is_hardware_watchpoint; processed here) are specific
1696 to each LWP since they are stored in each LWP's hardware debug
1697 registers. Therefore, such LWP must be stopped first in order to
1698 be able to modify its hardware watchpoints.
1700 Hardware watchpoints must be reset exactly once after being
1701 presented to the user. It cannot be done sooner, because it would
1702 reset the data used to present the watchpoint hit to the user. And
1703 it must not be done later because it could display the same single
1704 watchpoint hit during multiple GDB stops. Note that the latter is
1705 relevant only to the hardware watchpoint types bp_read_watchpoint
1706 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1707 not user-visible - its hit is suppressed if the memory content has
1710 The following constraints influence the location where we can reset
1711 hardware watchpoints:
1713 * target_stopped_by_watchpoint and target_stopped_data_address are
1714 called several times when GDB stops.
1717 * Multiple hardware watchpoints can be hit at the same time,
1718 causing GDB to stop. GDB only presents one hardware watchpoint
1719 hit at a time as the reason for stopping, and all the other hits
1720 are presented later, one after the other, each time the user
1721 requests the execution to be resumed. Execution is not resumed
1722 for the threads still having pending hit event stored in
1723 LWP_INFO->STATUS. While the watchpoint is already removed from
1724 the inferior on the first stop the thread hit event is kept being
1725 reported from its cached value by linux_nat_stopped_data_address
1726 until the real thread resume happens after the watchpoint gets
1727 presented and thus its LWP_INFO->STATUS gets reset.
1729 Therefore the hardware watchpoint hit can get safely reset on the
1730 watchpoint removal from inferior. */
1733 update_watchpoint (struct watchpoint
*b
, int reparse
)
1735 int within_current_scope
;
1736 struct frame_id saved_frame_id
;
1739 /* If this is a local watchpoint, we only want to check if the
1740 watchpoint frame is in scope if the current thread is the thread
1741 that was used to create the watchpoint. */
1742 if (!watchpoint_in_thread_scope (b
))
1745 if (b
->disposition
== disp_del_at_next_stop
)
1750 /* Determine if the watchpoint is within scope. */
1751 if (b
->exp_valid_block
== NULL
)
1752 within_current_scope
= 1;
1755 struct frame_info
*fi
= get_current_frame ();
1756 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1757 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1759 /* If we're at a point where the stack has been destroyed
1760 (e.g. in a function epilogue), unwinding may not work
1761 properly. Do not attempt to recreate locations at this
1762 point. See similar comments in watchpoint_check. */
1763 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1766 /* Save the current frame's ID so we can restore it after
1767 evaluating the watchpoint expression on its own frame. */
1768 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1769 took a frame parameter, so that we didn't have to change the
1772 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1774 fi
= frame_find_by_id (b
->watchpoint_frame
);
1775 within_current_scope
= (fi
!= NULL
);
1776 if (within_current_scope
)
1780 /* We don't free locations. They are stored in the bp_location array
1781 and update_global_location_list will eventually delete them and
1782 remove breakpoints if needed. */
1785 if (within_current_scope
&& reparse
)
1790 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1791 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1792 /* If the meaning of expression itself changed, the old value is
1793 no longer relevant. We don't want to report a watchpoint hit
1794 to the user when the old value and the new value may actually
1795 be completely different objects. */
1796 value_free (b
->val
);
1800 /* Note that unlike with breakpoints, the watchpoint's condition
1801 expression is stored in the breakpoint object, not in the
1802 locations (re)created below. */
1803 if (b
->cond_string
!= NULL
)
1805 b
->cond_exp
.reset ();
1808 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1812 /* If we failed to parse the expression, for example because
1813 it refers to a global variable in a not-yet-loaded shared library,
1814 don't try to insert watchpoint. We don't automatically delete
1815 such watchpoint, though, since failure to parse expression
1816 is different from out-of-scope watchpoint. */
1817 if (!target_has_execution
)
1819 /* Without execution, memory can't change. No use to try and
1820 set watchpoint locations. The watchpoint will be reset when
1821 the target gains execution, through breakpoint_re_set. */
1822 if (!can_use_hw_watchpoints
)
1824 if (b
->ops
->works_in_software_mode (b
))
1825 b
->type
= bp_watchpoint
;
1827 error (_("Can't set read/access watchpoint when "
1828 "hardware watchpoints are disabled."));
1831 else if (within_current_scope
&& b
->exp
)
1834 struct value
*val_chain
, *v
, *result
, *next
;
1835 struct program_space
*frame_pspace
;
1837 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1839 /* Avoid setting b->val if it's already set. The meaning of
1840 b->val is 'the last value' user saw, and we should update
1841 it only if we reported that last value to user. As it
1842 happens, the code that reports it updates b->val directly.
1843 We don't keep track of the memory value for masked
1845 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1847 if (b
->val_bitsize
!= 0)
1849 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1857 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1859 /* Look at each value on the value chain. */
1860 for (v
= val_chain
; v
; v
= value_next (v
))
1862 /* If it's a memory location, and GDB actually needed
1863 its contents to evaluate the expression, then we
1864 must watch it. If the first value returned is
1865 still lazy, that means an error occurred reading it;
1866 watch it anyway in case it becomes readable. */
1867 if (VALUE_LVAL (v
) == lval_memory
1868 && (v
== val_chain
|| ! value_lazy (v
)))
1870 struct type
*vtype
= check_typedef (value_type (v
));
1872 /* We only watch structs and arrays if user asked
1873 for it explicitly, never if they just happen to
1874 appear in the middle of some value chain. */
1876 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1877 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1880 enum target_hw_bp_type type
;
1881 struct bp_location
*loc
, **tmp
;
1882 int bitpos
= 0, bitsize
= 0;
1884 if (value_bitsize (v
) != 0)
1886 /* Extract the bit parameters out from the bitfield
1888 bitpos
= value_bitpos (v
);
1889 bitsize
= value_bitsize (v
);
1891 else if (v
== result
&& b
->val_bitsize
!= 0)
1893 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1894 lvalue whose bit parameters are saved in the fields
1895 VAL_BITPOS and VAL_BITSIZE. */
1896 bitpos
= b
->val_bitpos
;
1897 bitsize
= b
->val_bitsize
;
1900 addr
= value_address (v
);
1903 /* Skip the bytes that don't contain the bitfield. */
1908 if (b
->type
== bp_read_watchpoint
)
1910 else if (b
->type
== bp_access_watchpoint
)
1913 loc
= allocate_bp_location (b
);
1914 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1917 loc
->gdbarch
= get_type_arch (value_type (v
));
1919 loc
->pspace
= frame_pspace
;
1920 loc
->address
= addr
;
1924 /* Just cover the bytes that make up the bitfield. */
1925 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1928 loc
->length
= TYPE_LENGTH (value_type (v
));
1930 loc
->watchpoint_type
= type
;
1935 /* Change the type of breakpoint between hardware assisted or
1936 an ordinary watchpoint depending on the hardware support
1937 and free hardware slots. REPARSE is set when the inferior
1942 enum bp_loc_type loc_type
;
1943 struct bp_location
*bl
;
1945 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1949 int i
, target_resources_ok
, other_type_used
;
1952 /* Use an exact watchpoint when there's only one memory region to be
1953 watched, and only one debug register is needed to watch it. */
1954 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1956 /* We need to determine how many resources are already
1957 used for all other hardware watchpoints plus this one
1958 to see if we still have enough resources to also fit
1959 this watchpoint in as well. */
1961 /* If this is a software watchpoint, we try to turn it
1962 to a hardware one -- count resources as if B was of
1963 hardware watchpoint type. */
1965 if (type
== bp_watchpoint
)
1966 type
= bp_hardware_watchpoint
;
1968 /* This watchpoint may or may not have been placed on
1969 the list yet at this point (it won't be in the list
1970 if we're trying to create it for the first time,
1971 through watch_command), so always account for it
1974 /* Count resources used by all watchpoints except B. */
1975 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1977 /* Add in the resources needed for B. */
1978 i
+= hw_watchpoint_use_count (b
);
1981 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1982 if (target_resources_ok
<= 0)
1984 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1986 if (target_resources_ok
== 0 && !sw_mode
)
1987 error (_("Target does not support this type of "
1988 "hardware watchpoint."));
1989 else if (target_resources_ok
< 0 && !sw_mode
)
1990 error (_("There are not enough available hardware "
1991 "resources for this watchpoint."));
1993 /* Downgrade to software watchpoint. */
1994 b
->type
= bp_watchpoint
;
1998 /* If this was a software watchpoint, we've just
1999 found we have enough resources to turn it to a
2000 hardware watchpoint. Otherwise, this is a
2005 else if (!b
->ops
->works_in_software_mode (b
))
2007 if (!can_use_hw_watchpoints
)
2008 error (_("Can't set read/access watchpoint when "
2009 "hardware watchpoints are disabled."));
2011 error (_("Expression cannot be implemented with "
2012 "read/access watchpoint."));
2015 b
->type
= bp_watchpoint
;
2017 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2018 : bp_loc_hardware_watchpoint
);
2019 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2020 bl
->loc_type
= loc_type
;
2023 for (v
= val_chain
; v
; v
= next
)
2025 next
= value_next (v
);
2030 /* If a software watchpoint is not watching any memory, then the
2031 above left it without any location set up. But,
2032 bpstat_stop_status requires a location to be able to report
2033 stops, so make sure there's at least a dummy one. */
2034 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2035 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2037 else if (!within_current_scope
)
2039 printf_filtered (_("\
2040 Watchpoint %d deleted because the program has left the block\n\
2041 in which its expression is valid.\n"),
2043 watchpoint_del_at_next_stop (b
);
2046 /* Restore the selected frame. */
2048 select_frame (frame_find_by_id (saved_frame_id
));
2052 /* Returns 1 iff breakpoint location should be
2053 inserted in the inferior. We don't differentiate the type of BL's owner
2054 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2055 breakpoint_ops is not defined, because in insert_bp_location,
2056 tracepoint's insert_location will not be called. */
2058 should_be_inserted (struct bp_location
*bl
)
2060 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2063 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2066 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2069 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2072 /* This is set for example, when we're attached to the parent of a
2073 vfork, and have detached from the child. The child is running
2074 free, and we expect it to do an exec or exit, at which point the
2075 OS makes the parent schedulable again (and the target reports
2076 that the vfork is done). Until the child is done with the shared
2077 memory region, do not insert breakpoints in the parent, otherwise
2078 the child could still trip on the parent's breakpoints. Since
2079 the parent is blocked anyway, it won't miss any breakpoint. */
2080 if (bl
->pspace
->breakpoints_not_allowed
)
2083 /* Don't insert a breakpoint if we're trying to step past its
2084 location, except if the breakpoint is a single-step breakpoint,
2085 and the breakpoint's thread is the thread which is stepping past
2087 if ((bl
->loc_type
== bp_loc_software_breakpoint
2088 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2089 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2091 /* The single-step breakpoint may be inserted at the location
2092 we're trying to step if the instruction branches to itself.
2093 However, the instruction won't be executed at all and it may
2094 break the semantics of the instruction, for example, the
2095 instruction is a conditional branch or updates some flags.
2096 We can't fix it unless GDB is able to emulate the instruction
2097 or switch to displaced stepping. */
2098 && !(bl
->owner
->type
== bp_single_step
2099 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2103 fprintf_unfiltered (gdb_stdlog
,
2104 "infrun: skipping breakpoint: "
2105 "stepping past insn at: %s\n",
2106 paddress (bl
->gdbarch
, bl
->address
));
2111 /* Don't insert watchpoints if we're trying to step past the
2112 instruction that triggered one. */
2113 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2114 && stepping_past_nonsteppable_watchpoint ())
2118 fprintf_unfiltered (gdb_stdlog
,
2119 "infrun: stepping past non-steppable watchpoint. "
2120 "skipping watchpoint at %s:%d\n",
2121 paddress (bl
->gdbarch
, bl
->address
),
2130 /* Same as should_be_inserted but does the check assuming
2131 that the location is not duplicated. */
2134 unduplicated_should_be_inserted (struct bp_location
*bl
)
2137 const int save_duplicate
= bl
->duplicate
;
2140 result
= should_be_inserted (bl
);
2141 bl
->duplicate
= save_duplicate
;
2145 /* Parses a conditional described by an expression COND into an
2146 agent expression bytecode suitable for evaluation
2147 by the bytecode interpreter. Return NULL if there was
2148 any error during parsing. */
2150 static agent_expr_up
2151 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2156 agent_expr_up aexpr
;
2158 /* We don't want to stop processing, so catch any errors
2159 that may show up. */
2162 aexpr
= gen_eval_for_expr (scope
, cond
);
2165 CATCH (ex
, RETURN_MASK_ERROR
)
2167 /* If we got here, it means the condition could not be parsed to a valid
2168 bytecode expression and thus can't be evaluated on the target's side.
2169 It's no use iterating through the conditions. */
2173 /* We have a valid agent expression. */
2177 /* Based on location BL, create a list of breakpoint conditions to be
2178 passed on to the target. If we have duplicated locations with different
2179 conditions, we will add such conditions to the list. The idea is that the
2180 target will evaluate the list of conditions and will only notify GDB when
2181 one of them is true. */
2184 build_target_condition_list (struct bp_location
*bl
)
2186 struct bp_location
**locp
= NULL
, **loc2p
;
2187 int null_condition_or_parse_error
= 0;
2188 int modified
= bl
->needs_update
;
2189 struct bp_location
*loc
;
2191 /* Release conditions left over from a previous insert. */
2192 bl
->target_info
.conditions
.clear ();
2194 /* This is only meaningful if the target is
2195 evaluating conditions and if the user has
2196 opted for condition evaluation on the target's
2198 if (gdb_evaluates_breakpoint_condition_p ()
2199 || !target_supports_evaluation_of_breakpoint_conditions ())
2202 /* Do a first pass to check for locations with no assigned
2203 conditions or conditions that fail to parse to a valid agent expression
2204 bytecode. If any of these happen, then it's no use to send conditions
2205 to the target since this location will always trigger and generate a
2206 response back to GDB. */
2207 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2210 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2214 /* Re-parse the conditions since something changed. In that
2215 case we already freed the condition bytecodes (see
2216 force_breakpoint_reinsertion). We just
2217 need to parse the condition to bytecodes again. */
2218 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2222 /* If we have a NULL bytecode expression, it means something
2223 went wrong or we have a null condition expression. */
2224 if (!loc
->cond_bytecode
)
2226 null_condition_or_parse_error
= 1;
2232 /* If any of these happened, it means we will have to evaluate the conditions
2233 for the location's address on gdb's side. It is no use keeping bytecodes
2234 for all the other duplicate locations, thus we free all of them here.
2236 This is so we have a finer control over which locations' conditions are
2237 being evaluated by GDB or the remote stub. */
2238 if (null_condition_or_parse_error
)
2240 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2243 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2245 /* Only go as far as the first NULL bytecode is
2247 if (!loc
->cond_bytecode
)
2250 loc
->cond_bytecode
.reset ();
2255 /* No NULL conditions or failed bytecode generation. Build a condition list
2256 for this location's address. */
2257 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2261 && is_breakpoint (loc
->owner
)
2262 && loc
->pspace
->num
== bl
->pspace
->num
2263 && loc
->owner
->enable_state
== bp_enabled
2266 /* Add the condition to the vector. This will be used later
2267 to send the conditions to the target. */
2268 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2275 /* Parses a command described by string CMD into an agent expression
2276 bytecode suitable for evaluation by the bytecode interpreter.
2277 Return NULL if there was any error during parsing. */
2279 static agent_expr_up
2280 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2282 struct cleanup
*old_cleanups
= 0;
2283 struct expression
**argvec
;
2284 const char *cmdrest
;
2285 const char *format_start
, *format_end
;
2286 struct format_piece
*fpieces
;
2288 struct gdbarch
*gdbarch
= get_current_arch ();
2295 if (*cmdrest
== ',')
2297 cmdrest
= skip_spaces (cmdrest
);
2299 if (*cmdrest
++ != '"')
2300 error (_("No format string following the location"));
2302 format_start
= cmdrest
;
2304 fpieces
= parse_format_string (&cmdrest
);
2306 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2308 format_end
= cmdrest
;
2310 if (*cmdrest
++ != '"')
2311 error (_("Bad format string, non-terminated '\"'."));
2313 cmdrest
= skip_spaces (cmdrest
);
2315 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2316 error (_("Invalid argument syntax"));
2318 if (*cmdrest
== ',')
2320 cmdrest
= skip_spaces (cmdrest
);
2322 /* For each argument, make an expression. */
2324 argvec
= (struct expression
**) alloca (strlen (cmd
)
2325 * sizeof (struct expression
*));
2328 while (*cmdrest
!= '\0')
2333 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2334 argvec
[nargs
++] = expr
.release ();
2336 if (*cmdrest
== ',')
2340 agent_expr_up aexpr
;
2342 /* We don't want to stop processing, so catch any errors
2343 that may show up. */
2346 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2347 format_start
, format_end
- format_start
,
2348 fpieces
, nargs
, argvec
);
2350 CATCH (ex
, RETURN_MASK_ERROR
)
2352 /* If we got here, it means the command could not be parsed to a valid
2353 bytecode expression and thus can't be evaluated on the target's side.
2354 It's no use iterating through the other commands. */
2358 do_cleanups (old_cleanups
);
2360 /* We have a valid agent expression, return it. */
2364 /* Based on location BL, create a list of breakpoint commands to be
2365 passed on to the target. If we have duplicated locations with
2366 different commands, we will add any such to the list. */
2369 build_target_command_list (struct bp_location
*bl
)
2371 struct bp_location
**locp
= NULL
, **loc2p
;
2372 int null_command_or_parse_error
= 0;
2373 int modified
= bl
->needs_update
;
2374 struct bp_location
*loc
;
2376 /* Clear commands left over from a previous insert. */
2377 bl
->target_info
.tcommands
.clear ();
2379 if (!target_can_run_breakpoint_commands ())
2382 /* For now, limit to agent-style dprintf breakpoints. */
2383 if (dprintf_style
!= dprintf_style_agent
)
2386 /* For now, if we have any duplicate location that isn't a dprintf,
2387 don't install the target-side commands, as that would make the
2388 breakpoint not be reported to the core, and we'd lose
2390 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2393 if (is_breakpoint (loc
->owner
)
2394 && loc
->pspace
->num
== bl
->pspace
->num
2395 && loc
->owner
->type
!= bp_dprintf
)
2399 /* Do a first pass to check for locations with no assigned
2400 conditions or conditions that fail to parse to a valid agent expression
2401 bytecode. If any of these happen, then it's no use to send conditions
2402 to the target since this location will always trigger and generate a
2403 response back to GDB. */
2404 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2407 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2411 /* Re-parse the commands since something changed. In that
2412 case we already freed the command bytecodes (see
2413 force_breakpoint_reinsertion). We just
2414 need to parse the command to bytecodes again. */
2416 = parse_cmd_to_aexpr (bl
->address
,
2417 loc
->owner
->extra_string
);
2420 /* If we have a NULL bytecode expression, it means something
2421 went wrong or we have a null command expression. */
2422 if (!loc
->cmd_bytecode
)
2424 null_command_or_parse_error
= 1;
2430 /* If anything failed, then we're not doing target-side commands,
2432 if (null_command_or_parse_error
)
2434 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2437 if (is_breakpoint (loc
->owner
)
2438 && loc
->pspace
->num
== bl
->pspace
->num
)
2440 /* Only go as far as the first NULL bytecode is
2442 if (loc
->cmd_bytecode
== NULL
)
2445 loc
->cmd_bytecode
.reset ();
2450 /* No NULL commands or failed bytecode generation. Build a command list
2451 for this location's address. */
2452 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2455 if (loc
->owner
->extra_string
2456 && is_breakpoint (loc
->owner
)
2457 && loc
->pspace
->num
== bl
->pspace
->num
2458 && loc
->owner
->enable_state
== bp_enabled
2461 /* Add the command to the vector. This will be used later
2462 to send the commands to the target. */
2463 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2467 bl
->target_info
.persist
= 0;
2468 /* Maybe flag this location as persistent. */
2469 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2470 bl
->target_info
.persist
= 1;
2473 /* Return the kind of breakpoint on address *ADDR. Get the kind
2474 of breakpoint according to ADDR except single-step breakpoint.
2475 Get the kind of single-step breakpoint according to the current
2479 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2481 if (bl
->owner
->type
== bp_single_step
)
2483 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2484 struct regcache
*regcache
;
2486 regcache
= get_thread_regcache (thr
->ptid
);
2488 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2492 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2495 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2496 location. Any error messages are printed to TMP_ERROR_STREAM; and
2497 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2498 Returns 0 for success, 1 if the bp_location type is not supported or
2501 NOTE drow/2003-09-09: This routine could be broken down to an
2502 object-style method for each breakpoint or catchpoint type. */
2504 insert_bp_location (struct bp_location
*bl
,
2505 struct ui_file
*tmp_error_stream
,
2506 int *disabled_breaks
,
2507 int *hw_breakpoint_error
,
2508 int *hw_bp_error_explained_already
)
2510 enum errors bp_err
= GDB_NO_ERROR
;
2511 const char *bp_err_message
= NULL
;
2513 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2516 /* Note we don't initialize bl->target_info, as that wipes out
2517 the breakpoint location's shadow_contents if the breakpoint
2518 is still inserted at that location. This in turn breaks
2519 target_read_memory which depends on these buffers when
2520 a memory read is requested at the breakpoint location:
2521 Once the target_info has been wiped, we fail to see that
2522 we have a breakpoint inserted at that address and thus
2523 read the breakpoint instead of returning the data saved in
2524 the breakpoint location's shadow contents. */
2525 bl
->target_info
.reqstd_address
= bl
->address
;
2526 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2527 bl
->target_info
.length
= bl
->length
;
2529 /* When working with target-side conditions, we must pass all the conditions
2530 for the same breakpoint address down to the target since GDB will not
2531 insert those locations. With a list of breakpoint conditions, the target
2532 can decide when to stop and notify GDB. */
2534 if (is_breakpoint (bl
->owner
))
2536 build_target_condition_list (bl
);
2537 build_target_command_list (bl
);
2538 /* Reset the modification marker. */
2539 bl
->needs_update
= 0;
2542 if (bl
->loc_type
== bp_loc_software_breakpoint
2543 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2545 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2547 /* If the explicitly specified breakpoint type
2548 is not hardware breakpoint, check the memory map to see
2549 if the breakpoint address is in read only memory or not.
2551 Two important cases are:
2552 - location type is not hardware breakpoint, memory
2553 is readonly. We change the type of the location to
2554 hardware breakpoint.
2555 - location type is hardware breakpoint, memory is
2556 read-write. This means we've previously made the
2557 location hardware one, but then the memory map changed,
2560 When breakpoints are removed, remove_breakpoints will use
2561 location types we've just set here, the only possible
2562 problem is that memory map has changed during running
2563 program, but it's not going to work anyway with current
2565 struct mem_region
*mr
2566 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2570 if (automatic_hardware_breakpoints
)
2572 enum bp_loc_type new_type
;
2574 if (mr
->attrib
.mode
!= MEM_RW
)
2575 new_type
= bp_loc_hardware_breakpoint
;
2577 new_type
= bp_loc_software_breakpoint
;
2579 if (new_type
!= bl
->loc_type
)
2581 static int said
= 0;
2583 bl
->loc_type
= new_type
;
2586 fprintf_filtered (gdb_stdout
,
2587 _("Note: automatically using "
2588 "hardware breakpoints for "
2589 "read-only addresses.\n"));
2594 else if (bl
->loc_type
== bp_loc_software_breakpoint
2595 && mr
->attrib
.mode
!= MEM_RW
)
2597 fprintf_unfiltered (tmp_error_stream
,
2598 _("Cannot insert breakpoint %d.\n"
2599 "Cannot set software breakpoint "
2600 "at read-only address %s\n"),
2602 paddress (bl
->gdbarch
, bl
->address
));
2608 /* First check to see if we have to handle an overlay. */
2609 if (overlay_debugging
== ovly_off
2610 || bl
->section
== NULL
2611 || !(section_is_overlay (bl
->section
)))
2613 /* No overlay handling: just set the breakpoint. */
2618 val
= bl
->owner
->ops
->insert_location (bl
);
2620 bp_err
= GENERIC_ERROR
;
2622 CATCH (e
, RETURN_MASK_ALL
)
2625 bp_err_message
= e
.message
;
2631 /* This breakpoint is in an overlay section.
2632 Shall we set a breakpoint at the LMA? */
2633 if (!overlay_events_enabled
)
2635 /* Yes -- overlay event support is not active,
2636 so we must try to set a breakpoint at the LMA.
2637 This will not work for a hardware breakpoint. */
2638 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2639 warning (_("hardware breakpoint %d not supported in overlay!"),
2643 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2645 /* Set a software (trap) breakpoint at the LMA. */
2646 bl
->overlay_target_info
= bl
->target_info
;
2647 bl
->overlay_target_info
.reqstd_address
= addr
;
2649 /* No overlay handling: just set the breakpoint. */
2654 bl
->overlay_target_info
.kind
2655 = breakpoint_kind (bl
, &addr
);
2656 bl
->overlay_target_info
.placed_address
= addr
;
2657 val
= target_insert_breakpoint (bl
->gdbarch
,
2658 &bl
->overlay_target_info
);
2660 bp_err
= GENERIC_ERROR
;
2662 CATCH (e
, RETURN_MASK_ALL
)
2665 bp_err_message
= e
.message
;
2669 if (bp_err
!= GDB_NO_ERROR
)
2670 fprintf_unfiltered (tmp_error_stream
,
2671 "Overlay breakpoint %d "
2672 "failed: in ROM?\n",
2676 /* Shall we set a breakpoint at the VMA? */
2677 if (section_is_mapped (bl
->section
))
2679 /* Yes. This overlay section is mapped into memory. */
2684 val
= bl
->owner
->ops
->insert_location (bl
);
2686 bp_err
= GENERIC_ERROR
;
2688 CATCH (e
, RETURN_MASK_ALL
)
2691 bp_err_message
= e
.message
;
2697 /* No. This breakpoint will not be inserted.
2698 No error, but do not mark the bp as 'inserted'. */
2703 if (bp_err
!= GDB_NO_ERROR
)
2705 /* Can't set the breakpoint. */
2707 /* In some cases, we might not be able to insert a
2708 breakpoint in a shared library that has already been
2709 removed, but we have not yet processed the shlib unload
2710 event. Unfortunately, some targets that implement
2711 breakpoint insertion themselves can't tell why the
2712 breakpoint insertion failed (e.g., the remote target
2713 doesn't define error codes), so we must treat generic
2714 errors as memory errors. */
2715 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2716 && bl
->loc_type
== bp_loc_software_breakpoint
2717 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2718 || shared_objfile_contains_address_p (bl
->pspace
,
2721 /* See also: disable_breakpoints_in_shlibs. */
2722 bl
->shlib_disabled
= 1;
2723 observer_notify_breakpoint_modified (bl
->owner
);
2724 if (!*disabled_breaks
)
2726 fprintf_unfiltered (tmp_error_stream
,
2727 "Cannot insert breakpoint %d.\n",
2729 fprintf_unfiltered (tmp_error_stream
,
2730 "Temporarily disabling shared "
2731 "library breakpoints:\n");
2733 *disabled_breaks
= 1;
2734 fprintf_unfiltered (tmp_error_stream
,
2735 "breakpoint #%d\n", bl
->owner
->number
);
2740 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2742 *hw_breakpoint_error
= 1;
2743 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2744 fprintf_unfiltered (tmp_error_stream
,
2745 "Cannot insert hardware breakpoint %d%s",
2746 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2747 if (bp_err_message
!= NULL
)
2748 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2752 if (bp_err_message
== NULL
)
2755 = memory_error_message (TARGET_XFER_E_IO
,
2756 bl
->gdbarch
, bl
->address
);
2758 fprintf_unfiltered (tmp_error_stream
,
2759 "Cannot insert breakpoint %d.\n"
2761 bl
->owner
->number
, message
.c_str ());
2765 fprintf_unfiltered (tmp_error_stream
,
2766 "Cannot insert breakpoint %d: %s\n",
2781 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2782 /* NOTE drow/2003-09-08: This state only exists for removing
2783 watchpoints. It's not clear that it's necessary... */
2784 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2788 gdb_assert (bl
->owner
->ops
!= NULL
2789 && bl
->owner
->ops
->insert_location
!= NULL
);
2791 val
= bl
->owner
->ops
->insert_location (bl
);
2793 /* If trying to set a read-watchpoint, and it turns out it's not
2794 supported, try emulating one with an access watchpoint. */
2795 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2797 struct bp_location
*loc
, **loc_temp
;
2799 /* But don't try to insert it, if there's already another
2800 hw_access location that would be considered a duplicate
2802 ALL_BP_LOCATIONS (loc
, loc_temp
)
2804 && loc
->watchpoint_type
== hw_access
2805 && watchpoint_locations_match (bl
, loc
))
2809 bl
->target_info
= loc
->target_info
;
2810 bl
->watchpoint_type
= hw_access
;
2817 bl
->watchpoint_type
= hw_access
;
2818 val
= bl
->owner
->ops
->insert_location (bl
);
2821 /* Back to the original value. */
2822 bl
->watchpoint_type
= hw_read
;
2826 bl
->inserted
= (val
== 0);
2829 else if (bl
->owner
->type
== bp_catchpoint
)
2833 gdb_assert (bl
->owner
->ops
!= NULL
2834 && bl
->owner
->ops
->insert_location
!= NULL
);
2836 val
= bl
->owner
->ops
->insert_location (bl
);
2839 bl
->owner
->enable_state
= bp_disabled
;
2843 Error inserting catchpoint %d: Your system does not support this type\n\
2844 of catchpoint."), bl
->owner
->number
);
2846 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2849 bl
->inserted
= (val
== 0);
2851 /* We've already printed an error message if there was a problem
2852 inserting this catchpoint, and we've disabled the catchpoint,
2853 so just return success. */
2860 /* This function is called when program space PSPACE is about to be
2861 deleted. It takes care of updating breakpoints to not reference
2865 breakpoint_program_space_exit (struct program_space
*pspace
)
2867 struct breakpoint
*b
, *b_temp
;
2868 struct bp_location
*loc
, **loc_temp
;
2870 /* Remove any breakpoint that was set through this program space. */
2871 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2873 if (b
->pspace
== pspace
)
2874 delete_breakpoint (b
);
2877 /* Breakpoints set through other program spaces could have locations
2878 bound to PSPACE as well. Remove those. */
2879 ALL_BP_LOCATIONS (loc
, loc_temp
)
2881 struct bp_location
*tmp
;
2883 if (loc
->pspace
== pspace
)
2885 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2886 if (loc
->owner
->loc
== loc
)
2887 loc
->owner
->loc
= loc
->next
;
2889 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2890 if (tmp
->next
== loc
)
2892 tmp
->next
= loc
->next
;
2898 /* Now update the global location list to permanently delete the
2899 removed locations above. */
2900 update_global_location_list (UGLL_DONT_INSERT
);
2903 /* Make sure all breakpoints are inserted in inferior.
2904 Throws exception on any error.
2905 A breakpoint that is already inserted won't be inserted
2906 again, so calling this function twice is safe. */
2908 insert_breakpoints (void)
2910 struct breakpoint
*bpt
;
2912 ALL_BREAKPOINTS (bpt
)
2913 if (is_hardware_watchpoint (bpt
))
2915 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2917 update_watchpoint (w
, 0 /* don't reparse. */);
2920 /* Updating watchpoints creates new locations, so update the global
2921 location list. Explicitly tell ugll to insert locations and
2922 ignore breakpoints_always_inserted_mode. */
2923 update_global_location_list (UGLL_INSERT
);
2926 /* Invoke CALLBACK for each of bp_location. */
2929 iterate_over_bp_locations (walk_bp_location_callback callback
)
2931 struct bp_location
*loc
, **loc_tmp
;
2933 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2935 callback (loc
, NULL
);
2939 /* This is used when we need to synch breakpoint conditions between GDB and the
2940 target. It is the case with deleting and disabling of breakpoints when using
2941 always-inserted mode. */
2944 update_inserted_breakpoint_locations (void)
2946 struct bp_location
*bl
, **blp_tmp
;
2949 int disabled_breaks
= 0;
2950 int hw_breakpoint_error
= 0;
2951 int hw_bp_details_reported
= 0;
2953 string_file tmp_error_stream
;
2955 /* Explicitly mark the warning -- this will only be printed if
2956 there was an error. */
2957 tmp_error_stream
.puts ("Warning:\n");
2959 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2961 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2963 /* We only want to update software breakpoints and hardware
2965 if (!is_breakpoint (bl
->owner
))
2968 /* We only want to update locations that are already inserted
2969 and need updating. This is to avoid unwanted insertion during
2970 deletion of breakpoints. */
2971 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2974 switch_to_program_space_and_thread (bl
->pspace
);
2976 /* For targets that support global breakpoints, there's no need
2977 to select an inferior to insert breakpoint to. In fact, even
2978 if we aren't attached to any process yet, we should still
2979 insert breakpoints. */
2980 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2981 && ptid_equal (inferior_ptid
, null_ptid
))
2984 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2985 &hw_breakpoint_error
, &hw_bp_details_reported
);
2992 target_terminal::ours_for_output ();
2993 error_stream (tmp_error_stream
);
2997 /* Used when starting or continuing the program. */
3000 insert_breakpoint_locations (void)
3002 struct breakpoint
*bpt
;
3003 struct bp_location
*bl
, **blp_tmp
;
3006 int disabled_breaks
= 0;
3007 int hw_breakpoint_error
= 0;
3008 int hw_bp_error_explained_already
= 0;
3010 string_file tmp_error_stream
;
3012 /* Explicitly mark the warning -- this will only be printed if
3013 there was an error. */
3014 tmp_error_stream
.puts ("Warning:\n");
3016 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3018 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3020 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3023 /* There is no point inserting thread-specific breakpoints if
3024 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3025 has BL->OWNER always non-NULL. */
3026 if (bl
->owner
->thread
!= -1
3027 && !valid_global_thread_id (bl
->owner
->thread
))
3030 switch_to_program_space_and_thread (bl
->pspace
);
3032 /* For targets that support global breakpoints, there's no need
3033 to select an inferior to insert breakpoint to. In fact, even
3034 if we aren't attached to any process yet, we should still
3035 insert breakpoints. */
3036 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3037 && ptid_equal (inferior_ptid
, null_ptid
))
3040 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3041 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3046 /* If we failed to insert all locations of a watchpoint, remove
3047 them, as half-inserted watchpoint is of limited use. */
3048 ALL_BREAKPOINTS (bpt
)
3050 int some_failed
= 0;
3051 struct bp_location
*loc
;
3053 if (!is_hardware_watchpoint (bpt
))
3056 if (!breakpoint_enabled (bpt
))
3059 if (bpt
->disposition
== disp_del_at_next_stop
)
3062 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3063 if (!loc
->inserted
&& should_be_inserted (loc
))
3070 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3072 remove_breakpoint (loc
);
3074 hw_breakpoint_error
= 1;
3075 tmp_error_stream
.printf ("Could not insert "
3076 "hardware watchpoint %d.\n",
3084 /* If a hardware breakpoint or watchpoint was inserted, add a
3085 message about possibly exhausted resources. */
3086 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3088 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3089 You may have requested too many hardware breakpoints/watchpoints.\n");
3091 target_terminal::ours_for_output ();
3092 error_stream (tmp_error_stream
);
3096 /* Used when the program stops.
3097 Returns zero if successful, or non-zero if there was a problem
3098 removing a breakpoint location. */
3101 remove_breakpoints (void)
3103 struct bp_location
*bl
, **blp_tmp
;
3106 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3108 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3109 val
|= remove_breakpoint (bl
);
3114 /* When a thread exits, remove breakpoints that are related to
3118 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3120 struct breakpoint
*b
, *b_tmp
;
3122 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3124 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3126 b
->disposition
= disp_del_at_next_stop
;
3128 printf_filtered (_("\
3129 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3130 b
->number
, print_thread_id (tp
));
3132 /* Hide it from the user. */
3138 /* Remove breakpoints of process PID. */
3141 remove_breakpoints_pid (int pid
)
3143 struct bp_location
*bl
, **blp_tmp
;
3145 struct inferior
*inf
= find_inferior_pid (pid
);
3147 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3149 if (bl
->pspace
!= inf
->pspace
)
3152 if (bl
->inserted
&& !bl
->target_info
.persist
)
3154 val
= remove_breakpoint (bl
);
3163 reattach_breakpoints (int pid
)
3165 struct bp_location
*bl
, **blp_tmp
;
3167 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3168 struct inferior
*inf
;
3169 struct thread_info
*tp
;
3171 tp
= any_live_thread_of_process (pid
);
3175 inf
= find_inferior_pid (pid
);
3177 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3178 inferior_ptid
= tp
->ptid
;
3180 string_file tmp_error_stream
;
3182 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3184 if (bl
->pspace
!= inf
->pspace
)
3190 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3198 static int internal_breakpoint_number
= -1;
3200 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3201 If INTERNAL is non-zero, the breakpoint number will be populated
3202 from internal_breakpoint_number and that variable decremented.
3203 Otherwise the breakpoint number will be populated from
3204 breakpoint_count and that value incremented. Internal breakpoints
3205 do not set the internal var bpnum. */
3207 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3210 b
->number
= internal_breakpoint_number
--;
3213 set_breakpoint_count (breakpoint_count
+ 1);
3214 b
->number
= breakpoint_count
;
3218 static struct breakpoint
*
3219 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3220 CORE_ADDR address
, enum bptype type
,
3221 const struct breakpoint_ops
*ops
)
3223 symtab_and_line sal
;
3225 sal
.section
= find_pc_overlay (sal
.pc
);
3226 sal
.pspace
= current_program_space
;
3228 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3229 b
->number
= internal_breakpoint_number
--;
3230 b
->disposition
= disp_donttouch
;
3235 static const char *const longjmp_names
[] =
3237 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3239 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3241 /* Per-objfile data private to breakpoint.c. */
3242 struct breakpoint_objfile_data
3244 /* Minimal symbol for "_ovly_debug_event" (if any). */
3245 struct bound_minimal_symbol overlay_msym
;
3247 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3248 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3250 /* True if we have looked for longjmp probes. */
3251 int longjmp_searched
;
3253 /* SystemTap probe points for longjmp (if any). */
3254 VEC (probe_p
) *longjmp_probes
;
3256 /* Minimal symbol for "std::terminate()" (if any). */
3257 struct bound_minimal_symbol terminate_msym
;
3259 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3260 struct bound_minimal_symbol exception_msym
;
3262 /* True if we have looked for exception probes. */
3263 int exception_searched
;
3265 /* SystemTap probe points for unwinding (if any). */
3266 VEC (probe_p
) *exception_probes
;
3269 static const struct objfile_data
*breakpoint_objfile_key
;
3271 /* Minimal symbol not found sentinel. */
3272 static struct minimal_symbol msym_not_found
;
3274 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3277 msym_not_found_p (const struct minimal_symbol
*msym
)
3279 return msym
== &msym_not_found
;
3282 /* Return per-objfile data needed by breakpoint.c.
3283 Allocate the data if necessary. */
3285 static struct breakpoint_objfile_data
*
3286 get_breakpoint_objfile_data (struct objfile
*objfile
)
3288 struct breakpoint_objfile_data
*bp_objfile_data
;
3290 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3291 objfile_data (objfile
, breakpoint_objfile_key
));
3292 if (bp_objfile_data
== NULL
)
3295 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3297 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3298 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3300 return bp_objfile_data
;
3304 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3306 struct breakpoint_objfile_data
*bp_objfile_data
3307 = (struct breakpoint_objfile_data
*) data
;
3309 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3310 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3314 create_overlay_event_breakpoint (void)
3316 struct objfile
*objfile
;
3317 const char *const func_name
= "_ovly_debug_event";
3319 ALL_OBJFILES (objfile
)
3321 struct breakpoint
*b
;
3322 struct breakpoint_objfile_data
*bp_objfile_data
;
3324 struct explicit_location explicit_loc
;
3326 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3328 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3331 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3333 struct bound_minimal_symbol m
;
3335 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3336 if (m
.minsym
== NULL
)
3338 /* Avoid future lookups in this objfile. */
3339 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3342 bp_objfile_data
->overlay_msym
= m
;
3345 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3346 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3348 &internal_breakpoint_ops
);
3349 initialize_explicit_location (&explicit_loc
);
3350 explicit_loc
.function_name
= ASTRDUP (func_name
);
3351 b
->location
= new_explicit_location (&explicit_loc
);
3353 if (overlay_debugging
== ovly_auto
)
3355 b
->enable_state
= bp_enabled
;
3356 overlay_events_enabled
= 1;
3360 b
->enable_state
= bp_disabled
;
3361 overlay_events_enabled
= 0;
3367 create_longjmp_master_breakpoint (void)
3369 struct program_space
*pspace
;
3371 scoped_restore_current_program_space restore_pspace
;
3373 ALL_PSPACES (pspace
)
3375 struct objfile
*objfile
;
3377 set_current_program_space (pspace
);
3379 ALL_OBJFILES (objfile
)
3382 struct gdbarch
*gdbarch
;
3383 struct breakpoint_objfile_data
*bp_objfile_data
;
3385 gdbarch
= get_objfile_arch (objfile
);
3387 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3389 if (!bp_objfile_data
->longjmp_searched
)
3393 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3396 /* We are only interested in checking one element. */
3397 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3399 if (!can_evaluate_probe_arguments (p
))
3401 /* We cannot use the probe interface here, because it does
3402 not know how to evaluate arguments. */
3403 VEC_free (probe_p
, ret
);
3407 bp_objfile_data
->longjmp_probes
= ret
;
3408 bp_objfile_data
->longjmp_searched
= 1;
3411 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3414 struct probe
*probe
;
3415 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3418 VEC_iterate (probe_p
,
3419 bp_objfile_data
->longjmp_probes
,
3423 struct breakpoint
*b
;
3425 b
= create_internal_breakpoint (gdbarch
,
3426 get_probe_address (probe
,
3429 &internal_breakpoint_ops
);
3430 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3431 b
->enable_state
= bp_disabled
;
3437 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3440 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3442 struct breakpoint
*b
;
3443 const char *func_name
;
3445 struct explicit_location explicit_loc
;
3447 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3450 func_name
= longjmp_names
[i
];
3451 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3453 struct bound_minimal_symbol m
;
3455 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3456 if (m
.minsym
== NULL
)
3458 /* Prevent future lookups in this objfile. */
3459 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3462 bp_objfile_data
->longjmp_msym
[i
] = m
;
3465 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3466 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3467 &internal_breakpoint_ops
);
3468 initialize_explicit_location (&explicit_loc
);
3469 explicit_loc
.function_name
= ASTRDUP (func_name
);
3470 b
->location
= new_explicit_location (&explicit_loc
);
3471 b
->enable_state
= bp_disabled
;
3477 /* Create a master std::terminate breakpoint. */
3479 create_std_terminate_master_breakpoint (void)
3481 struct program_space
*pspace
;
3482 const char *const func_name
= "std::terminate()";
3484 scoped_restore_current_program_space restore_pspace
;
3486 ALL_PSPACES (pspace
)
3488 struct objfile
*objfile
;
3491 set_current_program_space (pspace
);
3493 ALL_OBJFILES (objfile
)
3495 struct breakpoint
*b
;
3496 struct breakpoint_objfile_data
*bp_objfile_data
;
3497 struct explicit_location explicit_loc
;
3499 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3501 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3504 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3506 struct bound_minimal_symbol m
;
3508 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3509 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3510 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3512 /* Prevent future lookups in this objfile. */
3513 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3516 bp_objfile_data
->terminate_msym
= m
;
3519 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3520 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3521 bp_std_terminate_master
,
3522 &internal_breakpoint_ops
);
3523 initialize_explicit_location (&explicit_loc
);
3524 explicit_loc
.function_name
= ASTRDUP (func_name
);
3525 b
->location
= new_explicit_location (&explicit_loc
);
3526 b
->enable_state
= bp_disabled
;
3531 /* Install a master breakpoint on the unwinder's debug hook. */
3534 create_exception_master_breakpoint (void)
3536 struct objfile
*objfile
;
3537 const char *const func_name
= "_Unwind_DebugHook";
3539 ALL_OBJFILES (objfile
)
3541 struct breakpoint
*b
;
3542 struct gdbarch
*gdbarch
;
3543 struct breakpoint_objfile_data
*bp_objfile_data
;
3545 struct explicit_location explicit_loc
;
3547 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3549 /* We prefer the SystemTap probe point if it exists. */
3550 if (!bp_objfile_data
->exception_searched
)
3554 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3558 /* We are only interested in checking one element. */
3559 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3561 if (!can_evaluate_probe_arguments (p
))
3563 /* We cannot use the probe interface here, because it does
3564 not know how to evaluate arguments. */
3565 VEC_free (probe_p
, ret
);
3569 bp_objfile_data
->exception_probes
= ret
;
3570 bp_objfile_data
->exception_searched
= 1;
3573 if (bp_objfile_data
->exception_probes
!= NULL
)
3575 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3577 struct probe
*probe
;
3580 VEC_iterate (probe_p
,
3581 bp_objfile_data
->exception_probes
,
3585 struct breakpoint
*b
;
3587 b
= create_internal_breakpoint (gdbarch
,
3588 get_probe_address (probe
,
3590 bp_exception_master
,
3591 &internal_breakpoint_ops
);
3592 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3593 b
->enable_state
= bp_disabled
;
3599 /* Otherwise, try the hook function. */
3601 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3604 gdbarch
= get_objfile_arch (objfile
);
3606 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3608 struct bound_minimal_symbol debug_hook
;
3610 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3611 if (debug_hook
.minsym
== NULL
)
3613 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3617 bp_objfile_data
->exception_msym
= debug_hook
;
3620 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3621 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3623 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3624 &internal_breakpoint_ops
);
3625 initialize_explicit_location (&explicit_loc
);
3626 explicit_loc
.function_name
= ASTRDUP (func_name
);
3627 b
->location
= new_explicit_location (&explicit_loc
);
3628 b
->enable_state
= bp_disabled
;
3632 /* Does B have a location spec? */
3635 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3637 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3641 update_breakpoints_after_exec (void)
3643 struct breakpoint
*b
, *b_tmp
;
3644 struct bp_location
*bploc
, **bplocp_tmp
;
3646 /* We're about to delete breakpoints from GDB's lists. If the
3647 INSERTED flag is true, GDB will try to lift the breakpoints by
3648 writing the breakpoints' "shadow contents" back into memory. The
3649 "shadow contents" are NOT valid after an exec, so GDB should not
3650 do that. Instead, the target is responsible from marking
3651 breakpoints out as soon as it detects an exec. We don't do that
3652 here instead, because there may be other attempts to delete
3653 breakpoints after detecting an exec and before reaching here. */
3654 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3655 if (bploc
->pspace
== current_program_space
)
3656 gdb_assert (!bploc
->inserted
);
3658 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3660 if (b
->pspace
!= current_program_space
)
3663 /* Solib breakpoints must be explicitly reset after an exec(). */
3664 if (b
->type
== bp_shlib_event
)
3666 delete_breakpoint (b
);
3670 /* JIT breakpoints must be explicitly reset after an exec(). */
3671 if (b
->type
== bp_jit_event
)
3673 delete_breakpoint (b
);
3677 /* Thread event breakpoints must be set anew after an exec(),
3678 as must overlay event and longjmp master breakpoints. */
3679 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3680 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3681 || b
->type
== bp_exception_master
)
3683 delete_breakpoint (b
);
3687 /* Step-resume breakpoints are meaningless after an exec(). */
3688 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3690 delete_breakpoint (b
);
3694 /* Just like single-step breakpoints. */
3695 if (b
->type
== bp_single_step
)
3697 delete_breakpoint (b
);
3701 /* Longjmp and longjmp-resume breakpoints are also meaningless
3703 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3704 || b
->type
== bp_longjmp_call_dummy
3705 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3707 delete_breakpoint (b
);
3711 if (b
->type
== bp_catchpoint
)
3713 /* For now, none of the bp_catchpoint breakpoints need to
3714 do anything at this point. In the future, if some of
3715 the catchpoints need to something, we will need to add
3716 a new method, and call this method from here. */
3720 /* bp_finish is a special case. The only way we ought to be able
3721 to see one of these when an exec() has happened, is if the user
3722 caught a vfork, and then said "finish". Ordinarily a finish just
3723 carries them to the call-site of the current callee, by setting
3724 a temporary bp there and resuming. But in this case, the finish
3725 will carry them entirely through the vfork & exec.
3727 We don't want to allow a bp_finish to remain inserted now. But
3728 we can't safely delete it, 'cause finish_command has a handle to
3729 the bp on a bpstat, and will later want to delete it. There's a
3730 chance (and I've seen it happen) that if we delete the bp_finish
3731 here, that its storage will get reused by the time finish_command
3732 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3733 We really must allow finish_command to delete a bp_finish.
3735 In the absence of a general solution for the "how do we know
3736 it's safe to delete something others may have handles to?"
3737 problem, what we'll do here is just uninsert the bp_finish, and
3738 let finish_command delete it.
3740 (We know the bp_finish is "doomed" in the sense that it's
3741 momentary, and will be deleted as soon as finish_command sees
3742 the inferior stopped. So it doesn't matter that the bp's
3743 address is probably bogus in the new a.out, unlike e.g., the
3744 solib breakpoints.) */
3746 if (b
->type
== bp_finish
)
3751 /* Without a symbolic address, we have little hope of the
3752 pre-exec() address meaning the same thing in the post-exec()
3754 if (breakpoint_event_location_empty_p (b
))
3756 delete_breakpoint (b
);
3763 detach_breakpoints (ptid_t ptid
)
3765 struct bp_location
*bl
, **blp_tmp
;
3767 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3768 struct inferior
*inf
= current_inferior ();
3770 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3771 error (_("Cannot detach breakpoints of inferior_ptid"));
3773 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3774 inferior_ptid
= ptid
;
3775 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3777 if (bl
->pspace
!= inf
->pspace
)
3780 /* This function must physically remove breakpoints locations
3781 from the specified ptid, without modifying the breakpoint
3782 package's state. Locations of type bp_loc_other are only
3783 maintained at GDB side. So, there is no need to remove
3784 these bp_loc_other locations. Moreover, removing these
3785 would modify the breakpoint package's state. */
3786 if (bl
->loc_type
== bp_loc_other
)
3790 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3796 /* Remove the breakpoint location BL from the current address space.
3797 Note that this is used to detach breakpoints from a child fork.
3798 When we get here, the child isn't in the inferior list, and neither
3799 do we have objects to represent its address space --- we should
3800 *not* look at bl->pspace->aspace here. */
3803 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3807 /* BL is never in moribund_locations by our callers. */
3808 gdb_assert (bl
->owner
!= NULL
);
3810 /* The type of none suggests that owner is actually deleted.
3811 This should not ever happen. */
3812 gdb_assert (bl
->owner
->type
!= bp_none
);
3814 if (bl
->loc_type
== bp_loc_software_breakpoint
3815 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3817 /* "Normal" instruction breakpoint: either the standard
3818 trap-instruction bp (bp_breakpoint), or a
3819 bp_hardware_breakpoint. */
3821 /* First check to see if we have to handle an overlay. */
3822 if (overlay_debugging
== ovly_off
3823 || bl
->section
== NULL
3824 || !(section_is_overlay (bl
->section
)))
3826 /* No overlay handling: just remove the breakpoint. */
3828 /* If we're trying to uninsert a memory breakpoint that we
3829 know is set in a dynamic object that is marked
3830 shlib_disabled, then either the dynamic object was
3831 removed with "remove-symbol-file" or with
3832 "nosharedlibrary". In the former case, we don't know
3833 whether another dynamic object might have loaded over the
3834 breakpoint's address -- the user might well let us know
3835 about it next with add-symbol-file (the whole point of
3836 add-symbol-file is letting the user manually maintain a
3837 list of dynamically loaded objects). If we have the
3838 breakpoint's shadow memory, that is, this is a software
3839 breakpoint managed by GDB, check whether the breakpoint
3840 is still inserted in memory, to avoid overwriting wrong
3841 code with stale saved shadow contents. Note that HW
3842 breakpoints don't have shadow memory, as they're
3843 implemented using a mechanism that is not dependent on
3844 being able to modify the target's memory, and as such
3845 they should always be removed. */
3846 if (bl
->shlib_disabled
3847 && bl
->target_info
.shadow_len
!= 0
3848 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3851 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3855 /* This breakpoint is in an overlay section.
3856 Did we set a breakpoint at the LMA? */
3857 if (!overlay_events_enabled
)
3859 /* Yes -- overlay event support is not active, so we
3860 should have set a breakpoint at the LMA. Remove it.
3862 /* Ignore any failures: if the LMA is in ROM, we will
3863 have already warned when we failed to insert it. */
3864 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3865 target_remove_hw_breakpoint (bl
->gdbarch
,
3866 &bl
->overlay_target_info
);
3868 target_remove_breakpoint (bl
->gdbarch
,
3869 &bl
->overlay_target_info
,
3872 /* Did we set a breakpoint at the VMA?
3873 If so, we will have marked the breakpoint 'inserted'. */
3876 /* Yes -- remove it. Previously we did not bother to
3877 remove the breakpoint if the section had been
3878 unmapped, but let's not rely on that being safe. We
3879 don't know what the overlay manager might do. */
3881 /* However, we should remove *software* breakpoints only
3882 if the section is still mapped, or else we overwrite
3883 wrong code with the saved shadow contents. */
3884 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3885 || section_is_mapped (bl
->section
))
3886 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3892 /* No -- not inserted, so no need to remove. No error. */
3897 /* In some cases, we might not be able to remove a breakpoint in
3898 a shared library that has already been removed, but we have
3899 not yet processed the shlib unload event. Similarly for an
3900 unloaded add-symbol-file object - the user might not yet have
3901 had the chance to remove-symbol-file it. shlib_disabled will
3902 be set if the library/object has already been removed, but
3903 the breakpoint hasn't been uninserted yet, e.g., after
3904 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3905 always-inserted mode. */
3907 && (bl
->loc_type
== bp_loc_software_breakpoint
3908 && (bl
->shlib_disabled
3909 || solib_name_from_address (bl
->pspace
, bl
->address
)
3910 || shared_objfile_contains_address_p (bl
->pspace
,
3916 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3918 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3920 gdb_assert (bl
->owner
->ops
!= NULL
3921 && bl
->owner
->ops
->remove_location
!= NULL
);
3923 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3924 bl
->owner
->ops
->remove_location (bl
, reason
);
3926 /* Failure to remove any of the hardware watchpoints comes here. */
3927 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3928 warning (_("Could not remove hardware watchpoint %d."),
3931 else if (bl
->owner
->type
== bp_catchpoint
3932 && breakpoint_enabled (bl
->owner
)
3935 gdb_assert (bl
->owner
->ops
!= NULL
3936 && bl
->owner
->ops
->remove_location
!= NULL
);
3938 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3942 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3949 remove_breakpoint (struct bp_location
*bl
)
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 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3960 switch_to_program_space_and_thread (bl
->pspace
);
3962 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3965 /* Clear the "inserted" flag in all breakpoints. */
3968 mark_breakpoints_out (void)
3970 struct bp_location
*bl
, **blp_tmp
;
3972 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3973 if (bl
->pspace
== current_program_space
)
3977 /* Clear the "inserted" flag in all breakpoints and delete any
3978 breakpoints which should go away between runs of the program.
3980 Plus other such housekeeping that has to be done for breakpoints
3983 Note: this function gets called at the end of a run (by
3984 generic_mourn_inferior) and when a run begins (by
3985 init_wait_for_inferior). */
3990 breakpoint_init_inferior (enum inf_context context
)
3992 struct breakpoint
*b
, *b_tmp
;
3993 struct bp_location
*bl
;
3995 struct program_space
*pspace
= current_program_space
;
3997 /* If breakpoint locations are shared across processes, then there's
3999 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4002 mark_breakpoints_out ();
4004 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4006 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4012 case bp_longjmp_call_dummy
:
4014 /* If the call dummy breakpoint is at the entry point it will
4015 cause problems when the inferior is rerun, so we better get
4018 case bp_watchpoint_scope
:
4020 /* Also get rid of scope breakpoints. */
4022 case bp_shlib_event
:
4024 /* Also remove solib event breakpoints. Their addresses may
4025 have changed since the last time we ran the program.
4026 Actually we may now be debugging against different target;
4027 and so the solib backend that installed this breakpoint may
4028 not be used in by the target. E.g.,
4030 (gdb) file prog-linux
4031 (gdb) run # native linux target
4034 (gdb) file prog-win.exe
4035 (gdb) tar rem :9999 # remote Windows gdbserver.
4038 case bp_step_resume
:
4040 /* Also remove step-resume breakpoints. */
4042 case bp_single_step
:
4044 /* Also remove single-step breakpoints. */
4046 delete_breakpoint (b
);
4050 case bp_hardware_watchpoint
:
4051 case bp_read_watchpoint
:
4052 case bp_access_watchpoint
:
4054 struct watchpoint
*w
= (struct watchpoint
*) b
;
4056 /* Likewise for watchpoints on local expressions. */
4057 if (w
->exp_valid_block
!= NULL
)
4058 delete_breakpoint (b
);
4061 /* Get rid of existing locations, which are no longer
4062 valid. New ones will be created in
4063 update_watchpoint, when the inferior is restarted.
4064 The next update_global_location_list call will
4065 garbage collect them. */
4068 if (context
== inf_starting
)
4070 /* Reset val field to force reread of starting value in
4071 insert_breakpoints. */
4073 value_free (w
->val
);
4085 /* Get rid of the moribund locations. */
4086 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4087 decref_bp_location (&bl
);
4088 VEC_free (bp_location_p
, moribund_locations
);
4091 /* These functions concern about actual breakpoints inserted in the
4092 target --- to e.g. check if we need to do decr_pc adjustment or if
4093 we need to hop over the bkpt --- so we check for address space
4094 match, not program space. */
4096 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4097 exists at PC. It returns ordinary_breakpoint_here if it's an
4098 ordinary breakpoint, or permanent_breakpoint_here if it's a
4099 permanent breakpoint.
4100 - When continuing from a location with an ordinary breakpoint, we
4101 actually single step once before calling insert_breakpoints.
4102 - When continuing from a location with a permanent breakpoint, we
4103 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4104 the target, to advance the PC past the breakpoint. */
4106 enum breakpoint_here
4107 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4109 struct bp_location
*bl
, **blp_tmp
;
4110 int any_breakpoint_here
= 0;
4112 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4114 if (bl
->loc_type
!= bp_loc_software_breakpoint
4115 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4118 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4119 if ((breakpoint_enabled (bl
->owner
)
4121 && breakpoint_location_address_match (bl
, aspace
, pc
))
4123 if (overlay_debugging
4124 && section_is_overlay (bl
->section
)
4125 && !section_is_mapped (bl
->section
))
4126 continue; /* unmapped overlay -- can't be a match */
4127 else if (bl
->permanent
)
4128 return permanent_breakpoint_here
;
4130 any_breakpoint_here
= 1;
4134 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4137 /* See breakpoint.h. */
4140 breakpoint_in_range_p (struct address_space
*aspace
,
4141 CORE_ADDR addr
, ULONGEST len
)
4143 struct bp_location
*bl
, **blp_tmp
;
4145 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4147 if (bl
->loc_type
!= bp_loc_software_breakpoint
4148 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4151 if ((breakpoint_enabled (bl
->owner
)
4153 && breakpoint_location_address_range_overlap (bl
, aspace
,
4156 if (overlay_debugging
4157 && section_is_overlay (bl
->section
)
4158 && !section_is_mapped (bl
->section
))
4160 /* Unmapped overlay -- can't be a match. */
4171 /* Return true if there's a moribund breakpoint at PC. */
4174 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4176 struct bp_location
*loc
;
4179 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4180 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4186 /* Returns non-zero iff BL is inserted at PC, in address space
4190 bp_location_inserted_here_p (struct bp_location
*bl
,
4191 struct address_space
*aspace
, CORE_ADDR pc
)
4194 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4197 if (overlay_debugging
4198 && section_is_overlay (bl
->section
)
4199 && !section_is_mapped (bl
->section
))
4200 return 0; /* unmapped overlay -- can't be a match */
4207 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4210 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4212 struct bp_location
**blp
, **blp_tmp
= NULL
;
4214 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4216 struct bp_location
*bl
= *blp
;
4218 if (bl
->loc_type
!= bp_loc_software_breakpoint
4219 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4222 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4228 /* This function returns non-zero iff there is a software breakpoint
4232 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4235 struct bp_location
**blp
, **blp_tmp
= NULL
;
4237 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4239 struct bp_location
*bl
= *blp
;
4241 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4244 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4251 /* See breakpoint.h. */
4254 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4257 struct bp_location
**blp
, **blp_tmp
= NULL
;
4259 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4261 struct bp_location
*bl
= *blp
;
4263 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4266 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4274 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4275 CORE_ADDR addr
, ULONGEST len
)
4277 struct breakpoint
*bpt
;
4279 ALL_BREAKPOINTS (bpt
)
4281 struct bp_location
*loc
;
4283 if (bpt
->type
!= bp_hardware_watchpoint
4284 && bpt
->type
!= bp_access_watchpoint
)
4287 if (!breakpoint_enabled (bpt
))
4290 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4291 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4295 /* Check for intersection. */
4296 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4297 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4306 /* bpstat stuff. External routines' interfaces are documented
4310 is_catchpoint (struct breakpoint
*ep
)
4312 return (ep
->type
== bp_catchpoint
);
4315 /* Frees any storage that is part of a bpstat. Does not walk the
4318 bpstats::~bpstats ()
4320 if (old_val
!= NULL
)
4321 value_free (old_val
);
4322 if (bp_location_at
!= NULL
)
4323 decref_bp_location (&bp_location_at
);
4326 /* Clear a bpstat so that it says we are not at any breakpoint.
4327 Also free any storage that is part of a bpstat. */
4330 bpstat_clear (bpstat
*bsp
)
4347 bpstats::bpstats (const bpstats
&other
)
4349 bp_location_at (other
.bp_location_at
),
4350 breakpoint_at (other
.breakpoint_at
),
4351 commands (other
.commands
),
4352 old_val (other
.old_val
),
4353 print (other
.print
),
4355 print_it (other
.print_it
)
4357 if (old_val
!= NULL
)
4359 old_val
= value_copy (old_val
);
4360 release_value (old_val
);
4362 incref_bp_location (bp_location_at
);
4365 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4366 is part of the bpstat is copied as well. */
4369 bpstat_copy (bpstat bs
)
4373 bpstat retval
= NULL
;
4378 for (; bs
!= NULL
; bs
= bs
->next
)
4380 tmp
= new bpstats (*bs
);
4383 /* This is the first thing in the chain. */
4393 /* Find the bpstat associated with this breakpoint. */
4396 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4401 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4403 if (bsp
->breakpoint_at
== breakpoint
)
4409 /* See breakpoint.h. */
4412 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4414 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4416 if (bsp
->breakpoint_at
== NULL
)
4418 /* A moribund location can never explain a signal other than
4420 if (sig
== GDB_SIGNAL_TRAP
)
4425 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4434 /* Put in *NUM the breakpoint number of the first breakpoint we are
4435 stopped at. *BSP upon return is a bpstat which points to the
4436 remaining breakpoints stopped at (but which is not guaranteed to be
4437 good for anything but further calls to bpstat_num).
4439 Return 0 if passed a bpstat which does not indicate any breakpoints.
4440 Return -1 if stopped at a breakpoint that has been deleted since
4442 Return 1 otherwise. */
4445 bpstat_num (bpstat
*bsp
, int *num
)
4447 struct breakpoint
*b
;
4450 return 0; /* No more breakpoint values */
4452 /* We assume we'll never have several bpstats that correspond to a
4453 single breakpoint -- otherwise, this function might return the
4454 same number more than once and this will look ugly. */
4455 b
= (*bsp
)->breakpoint_at
;
4456 *bsp
= (*bsp
)->next
;
4458 return -1; /* breakpoint that's been deleted since */
4460 *num
= b
->number
; /* We have its number */
4464 /* See breakpoint.h. */
4467 bpstat_clear_actions (void)
4469 struct thread_info
*tp
;
4472 if (ptid_equal (inferior_ptid
, null_ptid
))
4475 tp
= find_thread_ptid (inferior_ptid
);
4479 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4481 bs
->commands
= NULL
;
4483 if (bs
->old_val
!= NULL
)
4485 value_free (bs
->old_val
);
4491 /* Called when a command is about to proceed the inferior. */
4494 breakpoint_about_to_proceed (void)
4496 if (!ptid_equal (inferior_ptid
, null_ptid
))
4498 struct thread_info
*tp
= inferior_thread ();
4500 /* Allow inferior function calls in breakpoint commands to not
4501 interrupt the command list. When the call finishes
4502 successfully, the inferior will be standing at the same
4503 breakpoint as if nothing happened. */
4504 if (tp
->control
.in_infcall
)
4508 breakpoint_proceeded
= 1;
4511 /* Stub for cleaning up our state if we error-out of a breakpoint
4514 cleanup_executing_breakpoints (void *ignore
)
4516 executing_breakpoint_commands
= 0;
4519 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4520 or its equivalent. */
4523 command_line_is_silent (struct command_line
*cmd
)
4525 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4528 /* Execute all the commands associated with all the breakpoints at
4529 this location. Any of these commands could cause the process to
4530 proceed beyond this point, etc. We look out for such changes by
4531 checking the global "breakpoint_proceeded" after each command.
4533 Returns true if a breakpoint command resumed the inferior. In that
4534 case, it is the caller's responsibility to recall it again with the
4535 bpstat of the current thread. */
4538 bpstat_do_actions_1 (bpstat
*bsp
)
4541 struct cleanup
*old_chain
;
4544 /* Avoid endless recursion if a `source' command is contained
4546 if (executing_breakpoint_commands
)
4549 executing_breakpoint_commands
= 1;
4550 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4552 scoped_restore preventer
= prevent_dont_repeat ();
4554 /* This pointer will iterate over the list of bpstat's. */
4557 breakpoint_proceeded
= 0;
4558 for (; bs
!= NULL
; bs
= bs
->next
)
4560 struct command_line
*cmd
= NULL
;
4562 /* Take ownership of the BSP's command tree, if it has one.
4564 The command tree could legitimately contain commands like
4565 'step' and 'next', which call clear_proceed_status, which
4566 frees stop_bpstat's command tree. To make sure this doesn't
4567 free the tree we're executing out from under us, we need to
4568 take ownership of the tree ourselves. Since a given bpstat's
4569 commands are only executed once, we don't need to copy it; we
4570 can clear the pointer in the bpstat, and make sure we free
4571 the tree when we're done. */
4572 counted_command_line ccmd
= bs
->commands
;
4573 bs
->commands
= NULL
;
4576 if (command_line_is_silent (cmd
))
4578 /* The action has been already done by bpstat_stop_status. */
4584 execute_control_command (cmd
);
4586 if (breakpoint_proceeded
)
4592 if (breakpoint_proceeded
)
4594 if (current_ui
->async
)
4595 /* If we are in async mode, then the target might be still
4596 running, not stopped at any breakpoint, so nothing for
4597 us to do here -- just return to the event loop. */
4600 /* In sync mode, when execute_control_command returns
4601 we're already standing on the next breakpoint.
4602 Breakpoint commands for that stop were not run, since
4603 execute_command does not run breakpoint commands --
4604 only command_line_handler does, but that one is not
4605 involved in execution of breakpoint commands. So, we
4606 can now execute breakpoint commands. It should be
4607 noted that making execute_command do bpstat actions is
4608 not an option -- in this case we'll have recursive
4609 invocation of bpstat for each breakpoint with a
4610 command, and can easily blow up GDB stack. Instead, we
4611 return true, which will trigger the caller to recall us
4612 with the new stop_bpstat. */
4617 do_cleanups (old_chain
);
4622 bpstat_do_actions (void)
4624 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4626 /* Do any commands attached to breakpoint we are stopped at. */
4627 while (!ptid_equal (inferior_ptid
, null_ptid
)
4628 && target_has_execution
4629 && !is_exited (inferior_ptid
)
4630 && !is_executing (inferior_ptid
))
4631 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4632 and only return when it is stopped at the next breakpoint, we
4633 keep doing breakpoint actions until it returns false to
4634 indicate the inferior was not resumed. */
4635 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4638 discard_cleanups (cleanup_if_error
);
4641 /* Print out the (old or new) value associated with a watchpoint. */
4644 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4647 fprintf_unfiltered (stream
, _("<unreadable>"));
4650 struct value_print_options opts
;
4651 get_user_print_options (&opts
);
4652 value_print (val
, stream
, &opts
);
4656 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4657 debugging multiple threads. */
4660 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4662 if (uiout
->is_mi_like_p ())
4667 if (show_thread_that_caused_stop ())
4670 struct thread_info
*thr
= inferior_thread ();
4672 uiout
->text ("Thread ");
4673 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4675 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4678 uiout
->text (" \"");
4679 uiout
->field_fmt ("name", "%s", name
);
4683 uiout
->text (" hit ");
4687 /* Generic routine for printing messages indicating why we
4688 stopped. The behavior of this function depends on the value
4689 'print_it' in the bpstat structure. Under some circumstances we
4690 may decide not to print anything here and delegate the task to
4693 static enum print_stop_action
4694 print_bp_stop_message (bpstat bs
)
4696 switch (bs
->print_it
)
4699 /* Nothing should be printed for this bpstat entry. */
4700 return PRINT_UNKNOWN
;
4704 /* We still want to print the frame, but we already printed the
4705 relevant messages. */
4706 return PRINT_SRC_AND_LOC
;
4709 case print_it_normal
:
4711 struct breakpoint
*b
= bs
->breakpoint_at
;
4713 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4714 which has since been deleted. */
4716 return PRINT_UNKNOWN
;
4718 /* Normal case. Call the breakpoint's print_it method. */
4719 return b
->ops
->print_it (bs
);
4724 internal_error (__FILE__
, __LINE__
,
4725 _("print_bp_stop_message: unrecognized enum value"));
4730 /* A helper function that prints a shared library stopped event. */
4733 print_solib_event (int is_catchpoint
)
4736 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4738 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4742 if (any_added
|| any_deleted
)
4743 current_uiout
->text (_("Stopped due to shared library event:\n"));
4745 current_uiout
->text (_("Stopped due to shared library event (no "
4746 "libraries added or removed)\n"));
4749 if (current_uiout
->is_mi_like_p ())
4750 current_uiout
->field_string ("reason",
4751 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4758 current_uiout
->text (_(" Inferior unloaded "));
4759 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4761 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4766 current_uiout
->text (" ");
4767 current_uiout
->field_string ("library", name
);
4768 current_uiout
->text ("\n");
4774 struct so_list
*iter
;
4777 current_uiout
->text (_(" Inferior loaded "));
4778 ui_out_emit_list
list_emitter (current_uiout
, "added");
4780 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4785 current_uiout
->text (" ");
4786 current_uiout
->field_string ("library", iter
->so_name
);
4787 current_uiout
->text ("\n");
4792 /* Print a message indicating what happened. This is called from
4793 normal_stop(). The input to this routine is the head of the bpstat
4794 list - a list of the eventpoints that caused this stop. KIND is
4795 the target_waitkind for the stopping event. This
4796 routine calls the generic print routine for printing a message
4797 about reasons for stopping. This will print (for example) the
4798 "Breakpoint n," part of the output. The return value of this
4801 PRINT_UNKNOWN: Means we printed nothing.
4802 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4803 code to print the location. An example is
4804 "Breakpoint 1, " which should be followed by
4806 PRINT_SRC_ONLY: Means we printed something, but there is no need
4807 to also print the location part of the message.
4808 An example is the catch/throw messages, which
4809 don't require a location appended to the end.
4810 PRINT_NOTHING: We have done some printing and we don't need any
4811 further info to be printed. */
4813 enum print_stop_action
4814 bpstat_print (bpstat bs
, int kind
)
4816 enum print_stop_action val
;
4818 /* Maybe another breakpoint in the chain caused us to stop.
4819 (Currently all watchpoints go on the bpstat whether hit or not.
4820 That probably could (should) be changed, provided care is taken
4821 with respect to bpstat_explains_signal). */
4822 for (; bs
; bs
= bs
->next
)
4824 val
= print_bp_stop_message (bs
);
4825 if (val
== PRINT_SRC_ONLY
4826 || val
== PRINT_SRC_AND_LOC
4827 || val
== PRINT_NOTHING
)
4831 /* If we had hit a shared library event breakpoint,
4832 print_bp_stop_message would print out this message. If we hit an
4833 OS-level shared library event, do the same thing. */
4834 if (kind
== TARGET_WAITKIND_LOADED
)
4836 print_solib_event (0);
4837 return PRINT_NOTHING
;
4840 /* We reached the end of the chain, or we got a null BS to start
4841 with and nothing was printed. */
4842 return PRINT_UNKNOWN
;
4845 /* Evaluate the expression EXP and return 1 if value is zero.
4846 This returns the inverse of the condition because it is called
4847 from catch_errors which returns 0 if an exception happened, and if an
4848 exception happens we want execution to stop.
4849 The argument is a "struct expression *" that has been cast to a
4850 "void *" to make it pass through catch_errors. */
4853 breakpoint_cond_eval (void *exp
)
4855 struct value
*mark
= value_mark ();
4856 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4858 value_free_to_mark (mark
);
4862 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4864 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4866 bp_location_at (bl
),
4867 breakpoint_at (bl
->owner
),
4872 print_it (print_it_normal
)
4874 incref_bp_location (bl
);
4875 **bs_link_pointer
= this;
4876 *bs_link_pointer
= &next
;
4881 bp_location_at (NULL
),
4882 breakpoint_at (NULL
),
4887 print_it (print_it_normal
)
4891 /* The target has stopped with waitstatus WS. Check if any hardware
4892 watchpoints have triggered, according to the target. */
4895 watchpoints_triggered (struct target_waitstatus
*ws
)
4897 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4899 struct breakpoint
*b
;
4901 if (!stopped_by_watchpoint
)
4903 /* We were not stopped by a watchpoint. Mark all watchpoints
4904 as not triggered. */
4906 if (is_hardware_watchpoint (b
))
4908 struct watchpoint
*w
= (struct watchpoint
*) b
;
4910 w
->watchpoint_triggered
= watch_triggered_no
;
4916 if (!target_stopped_data_address (¤t_target
, &addr
))
4918 /* We were stopped by a watchpoint, but we don't know where.
4919 Mark all watchpoints as unknown. */
4921 if (is_hardware_watchpoint (b
))
4923 struct watchpoint
*w
= (struct watchpoint
*) b
;
4925 w
->watchpoint_triggered
= watch_triggered_unknown
;
4931 /* The target could report the data address. Mark watchpoints
4932 affected by this data address as triggered, and all others as not
4936 if (is_hardware_watchpoint (b
))
4938 struct watchpoint
*w
= (struct watchpoint
*) b
;
4939 struct bp_location
*loc
;
4941 w
->watchpoint_triggered
= watch_triggered_no
;
4942 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4944 if (is_masked_watchpoint (b
))
4946 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4947 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4949 if (newaddr
== start
)
4951 w
->watchpoint_triggered
= watch_triggered_yes
;
4955 /* Exact match not required. Within range is sufficient. */
4956 else if (target_watchpoint_addr_within_range (¤t_target
,
4960 w
->watchpoint_triggered
= watch_triggered_yes
;
4969 /* Possible return values for watchpoint_check (this can't be an enum
4970 because of check_errors). */
4971 /* The watchpoint has been deleted. */
4972 #define WP_DELETED 1
4973 /* The value has changed. */
4974 #define WP_VALUE_CHANGED 2
4975 /* The value has not changed. */
4976 #define WP_VALUE_NOT_CHANGED 3
4977 /* Ignore this watchpoint, no matter if the value changed or not. */
4980 #define BP_TEMPFLAG 1
4981 #define BP_HARDWAREFLAG 2
4983 /* Evaluate watchpoint condition expression and check if its value
4986 P should be a pointer to struct bpstat, but is defined as a void *
4987 in order for this function to be usable with catch_errors. */
4990 watchpoint_check (void *p
)
4992 bpstat bs
= (bpstat
) p
;
4993 struct watchpoint
*b
;
4994 struct frame_info
*fr
;
4995 int within_current_scope
;
4997 /* BS is built from an existing struct breakpoint. */
4998 gdb_assert (bs
->breakpoint_at
!= NULL
);
4999 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5001 /* If this is a local watchpoint, we only want to check if the
5002 watchpoint frame is in scope if the current thread is the thread
5003 that was used to create the watchpoint. */
5004 if (!watchpoint_in_thread_scope (b
))
5007 if (b
->exp_valid_block
== NULL
)
5008 within_current_scope
= 1;
5011 struct frame_info
*frame
= get_current_frame ();
5012 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5013 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5015 /* stack_frame_destroyed_p() returns a non-zero value if we're
5016 still in the function but the stack frame has already been
5017 invalidated. Since we can't rely on the values of local
5018 variables after the stack has been destroyed, we are treating
5019 the watchpoint in that state as `not changed' without further
5020 checking. Don't mark watchpoints as changed if the current
5021 frame is in an epilogue - even if they are in some other
5022 frame, our view of the stack is likely to be wrong and
5023 frame_find_by_id could error out. */
5024 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5027 fr
= frame_find_by_id (b
->watchpoint_frame
);
5028 within_current_scope
= (fr
!= NULL
);
5030 /* If we've gotten confused in the unwinder, we might have
5031 returned a frame that can't describe this variable. */
5032 if (within_current_scope
)
5034 struct symbol
*function
;
5036 function
= get_frame_function (fr
);
5037 if (function
== NULL
5038 || !contained_in (b
->exp_valid_block
,
5039 SYMBOL_BLOCK_VALUE (function
)))
5040 within_current_scope
= 0;
5043 if (within_current_scope
)
5044 /* If we end up stopping, the current frame will get selected
5045 in normal_stop. So this call to select_frame won't affect
5050 if (within_current_scope
)
5052 /* We use value_{,free_to_}mark because it could be a *long*
5053 time before we return to the command level and call
5054 free_all_values. We can't call free_all_values because we
5055 might be in the middle of evaluating a function call. */
5059 struct value
*new_val
;
5061 if (is_masked_watchpoint (b
))
5062 /* Since we don't know the exact trigger address (from
5063 stopped_data_address), just tell the user we've triggered
5064 a mask watchpoint. */
5065 return WP_VALUE_CHANGED
;
5067 mark
= value_mark ();
5068 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5070 if (b
->val_bitsize
!= 0)
5071 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5073 /* We use value_equal_contents instead of value_equal because
5074 the latter coerces an array to a pointer, thus comparing just
5075 the address of the array instead of its contents. This is
5076 not what we want. */
5077 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5078 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5080 if (new_val
!= NULL
)
5082 release_value (new_val
);
5083 value_free_to_mark (mark
);
5085 bs
->old_val
= b
->val
;
5088 return WP_VALUE_CHANGED
;
5092 /* Nothing changed. */
5093 value_free_to_mark (mark
);
5094 return WP_VALUE_NOT_CHANGED
;
5099 /* This seems like the only logical thing to do because
5100 if we temporarily ignored the watchpoint, then when
5101 we reenter the block in which it is valid it contains
5102 garbage (in the case of a function, it may have two
5103 garbage values, one before and one after the prologue).
5104 So we can't even detect the first assignment to it and
5105 watch after that (since the garbage may or may not equal
5106 the first value assigned). */
5107 /* We print all the stop information in
5108 breakpoint_ops->print_it, but in this case, by the time we
5109 call breakpoint_ops->print_it this bp will be deleted
5110 already. So we have no choice but print the information
5113 SWITCH_THRU_ALL_UIS ()
5115 struct ui_out
*uiout
= current_uiout
;
5117 if (uiout
->is_mi_like_p ())
5119 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5120 uiout
->text ("\nWatchpoint ");
5121 uiout
->field_int ("wpnum", b
->number
);
5122 uiout
->text (" deleted because the program has left the block in\n"
5123 "which its expression is valid.\n");
5126 /* Make sure the watchpoint's commands aren't executed. */
5128 watchpoint_del_at_next_stop (b
);
5134 /* Return true if it looks like target has stopped due to hitting
5135 breakpoint location BL. This function does not check if we should
5136 stop, only if BL explains the stop. */
5139 bpstat_check_location (const struct bp_location
*bl
,
5140 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5141 const struct target_waitstatus
*ws
)
5143 struct breakpoint
*b
= bl
->owner
;
5145 /* BL is from an existing breakpoint. */
5146 gdb_assert (b
!= NULL
);
5148 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5151 /* Determine if the watched values have actually changed, and we
5152 should stop. If not, set BS->stop to 0. */
5155 bpstat_check_watchpoint (bpstat bs
)
5157 const struct bp_location
*bl
;
5158 struct watchpoint
*b
;
5160 /* BS is built for existing struct breakpoint. */
5161 bl
= bs
->bp_location_at
;
5162 gdb_assert (bl
!= NULL
);
5163 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5164 gdb_assert (b
!= NULL
);
5167 int must_check_value
= 0;
5169 if (b
->type
== bp_watchpoint
)
5170 /* For a software watchpoint, we must always check the
5172 must_check_value
= 1;
5173 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5174 /* We have a hardware watchpoint (read, write, or access)
5175 and the target earlier reported an address watched by
5177 must_check_value
= 1;
5178 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5179 && b
->type
== bp_hardware_watchpoint
)
5180 /* We were stopped by a hardware watchpoint, but the target could
5181 not report the data address. We must check the watchpoint's
5182 value. Access and read watchpoints are out of luck; without
5183 a data address, we can't figure it out. */
5184 must_check_value
= 1;
5186 if (must_check_value
)
5189 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5191 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5192 int e
= catch_errors (watchpoint_check
, bs
, message
,
5194 do_cleanups (cleanups
);
5198 /* We've already printed what needs to be printed. */
5199 bs
->print_it
= print_it_done
;
5203 bs
->print_it
= print_it_noop
;
5206 case WP_VALUE_CHANGED
:
5207 if (b
->type
== bp_read_watchpoint
)
5209 /* There are two cases to consider here:
5211 1. We're watching the triggered memory for reads.
5212 In that case, trust the target, and always report
5213 the watchpoint hit to the user. Even though
5214 reads don't cause value changes, the value may
5215 have changed since the last time it was read, and
5216 since we're not trapping writes, we will not see
5217 those, and as such we should ignore our notion of
5220 2. We're watching the triggered memory for both
5221 reads and writes. There are two ways this may
5224 2.1. This is a target that can't break on data
5225 reads only, but can break on accesses (reads or
5226 writes), such as e.g., x86. We detect this case
5227 at the time we try to insert read watchpoints.
5229 2.2. Otherwise, the target supports read
5230 watchpoints, but, the user set an access or write
5231 watchpoint watching the same memory as this read
5234 If we're watching memory writes as well as reads,
5235 ignore watchpoint hits when we find that the
5236 value hasn't changed, as reads don't cause
5237 changes. This still gives false positives when
5238 the program writes the same value to memory as
5239 what there was already in memory (we will confuse
5240 it for a read), but it's much better than
5243 int other_write_watchpoint
= 0;
5245 if (bl
->watchpoint_type
== hw_read
)
5247 struct breakpoint
*other_b
;
5249 ALL_BREAKPOINTS (other_b
)
5250 if (other_b
->type
== bp_hardware_watchpoint
5251 || other_b
->type
== bp_access_watchpoint
)
5253 struct watchpoint
*other_w
=
5254 (struct watchpoint
*) other_b
;
5256 if (other_w
->watchpoint_triggered
5257 == watch_triggered_yes
)
5259 other_write_watchpoint
= 1;
5265 if (other_write_watchpoint
5266 || bl
->watchpoint_type
== hw_access
)
5268 /* We're watching the same memory for writes,
5269 and the value changed since the last time we
5270 updated it, so this trap must be for a write.
5272 bs
->print_it
= print_it_noop
;
5277 case WP_VALUE_NOT_CHANGED
:
5278 if (b
->type
== bp_hardware_watchpoint
5279 || b
->type
== bp_watchpoint
)
5281 /* Don't stop: write watchpoints shouldn't fire if
5282 the value hasn't changed. */
5283 bs
->print_it
= print_it_noop
;
5291 /* Error from catch_errors. */
5293 SWITCH_THRU_ALL_UIS ()
5295 printf_filtered (_("Watchpoint %d deleted.\n"),
5298 watchpoint_del_at_next_stop (b
);
5299 /* We've already printed what needs to be printed. */
5300 bs
->print_it
= print_it_done
;
5305 else /* must_check_value == 0 */
5307 /* This is a case where some watchpoint(s) triggered, but
5308 not at the address of this watchpoint, or else no
5309 watchpoint triggered after all. So don't print
5310 anything for this watchpoint. */
5311 bs
->print_it
= print_it_noop
;
5317 /* For breakpoints that are currently marked as telling gdb to stop,
5318 check conditions (condition proper, frame, thread and ignore count)
5319 of breakpoint referred to by BS. If we should not stop for this
5320 breakpoint, set BS->stop to 0. */
5323 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5325 const struct bp_location
*bl
;
5326 struct breakpoint
*b
;
5327 int value_is_zero
= 0;
5328 struct expression
*cond
;
5330 gdb_assert (bs
->stop
);
5332 /* BS is built for existing struct breakpoint. */
5333 bl
= bs
->bp_location_at
;
5334 gdb_assert (bl
!= NULL
);
5335 b
= bs
->breakpoint_at
;
5336 gdb_assert (b
!= NULL
);
5338 /* Even if the target evaluated the condition on its end and notified GDB, we
5339 need to do so again since GDB does not know if we stopped due to a
5340 breakpoint or a single step breakpoint. */
5342 if (frame_id_p (b
->frame_id
)
5343 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5349 /* If this is a thread/task-specific breakpoint, don't waste cpu
5350 evaluating the condition if this isn't the specified
5352 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5353 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5360 /* Evaluate extension language breakpoints that have a "stop" method
5362 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5364 if (is_watchpoint (b
))
5366 struct watchpoint
*w
= (struct watchpoint
*) b
;
5368 cond
= w
->cond_exp
.get ();
5371 cond
= bl
->cond
.get ();
5373 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5375 int within_current_scope
= 1;
5376 struct watchpoint
* w
;
5378 /* We use value_mark and value_free_to_mark because it could
5379 be a long time before we return to the command level and
5380 call free_all_values. We can't call free_all_values
5381 because we might be in the middle of evaluating a
5383 struct value
*mark
= value_mark ();
5385 if (is_watchpoint (b
))
5386 w
= (struct watchpoint
*) b
;
5390 /* Need to select the frame, with all that implies so that
5391 the conditions will have the right context. Because we
5392 use the frame, we will not see an inlined function's
5393 variables when we arrive at a breakpoint at the start
5394 of the inlined function; the current frame will be the
5396 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5397 select_frame (get_current_frame ());
5400 struct frame_info
*frame
;
5402 /* For local watchpoint expressions, which particular
5403 instance of a local is being watched matters, so we
5404 keep track of the frame to evaluate the expression
5405 in. To evaluate the condition however, it doesn't
5406 really matter which instantiation of the function
5407 where the condition makes sense triggers the
5408 watchpoint. This allows an expression like "watch
5409 global if q > 10" set in `func', catch writes to
5410 global on all threads that call `func', or catch
5411 writes on all recursive calls of `func' by a single
5412 thread. We simply always evaluate the condition in
5413 the innermost frame that's executing where it makes
5414 sense to evaluate the condition. It seems
5416 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5418 select_frame (frame
);
5420 within_current_scope
= 0;
5422 if (within_current_scope
)
5424 = catch_errors (breakpoint_cond_eval
, cond
,
5425 "Error in testing breakpoint condition:\n",
5429 warning (_("Watchpoint condition cannot be tested "
5430 "in the current scope"));
5431 /* If we failed to set the right context for this
5432 watchpoint, unconditionally report it. */
5435 /* FIXME-someday, should give breakpoint #. */
5436 value_free_to_mark (mark
);
5439 if (cond
&& value_is_zero
)
5443 else if (b
->ignore_count
> 0)
5447 /* Increase the hit count even though we don't stop. */
5449 observer_notify_breakpoint_modified (b
);
5453 /* Returns true if we need to track moribund locations of LOC's type
5454 on the current target. */
5457 need_moribund_for_location_type (struct bp_location
*loc
)
5459 return ((loc
->loc_type
== bp_loc_software_breakpoint
5460 && !target_supports_stopped_by_sw_breakpoint ())
5461 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5462 && !target_supports_stopped_by_hw_breakpoint ()));
5466 /* Get a bpstat associated with having just stopped at address
5467 BP_ADDR in thread PTID.
5469 Determine whether we stopped at a breakpoint, etc, or whether we
5470 don't understand this stop. Result is a chain of bpstat's such
5473 if we don't understand the stop, the result is a null pointer.
5475 if we understand why we stopped, the result is not null.
5477 Each element of the chain refers to a particular breakpoint or
5478 watchpoint at which we have stopped. (We may have stopped for
5479 several reasons concurrently.)
5481 Each element of the chain has valid next, breakpoint_at,
5482 commands, FIXME??? fields. */
5485 bpstat_stop_status (struct address_space
*aspace
,
5486 CORE_ADDR bp_addr
, ptid_t ptid
,
5487 const struct target_waitstatus
*ws
)
5489 struct breakpoint
*b
= NULL
;
5490 struct bp_location
*bl
;
5491 struct bp_location
*loc
;
5492 /* First item of allocated bpstat's. */
5493 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5494 /* Pointer to the last thing in the chain currently. */
5497 int need_remove_insert
;
5500 /* First, build the bpstat chain with locations that explain a
5501 target stop, while being careful to not set the target running,
5502 as that may invalidate locations (in particular watchpoint
5503 locations are recreated). Resuming will happen here with
5504 breakpoint conditions or watchpoint expressions that include
5505 inferior function calls. */
5509 if (!breakpoint_enabled (b
))
5512 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5514 /* For hardware watchpoints, we look only at the first
5515 location. The watchpoint_check function will work on the
5516 entire expression, not the individual locations. For
5517 read watchpoints, the watchpoints_triggered function has
5518 checked all locations already. */
5519 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5522 if (!bl
->enabled
|| bl
->shlib_disabled
)
5525 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5528 /* Come here if it's a watchpoint, or if the break address
5531 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5534 /* Assume we stop. Should we find a watchpoint that is not
5535 actually triggered, or if the condition of the breakpoint
5536 evaluates as false, we'll reset 'stop' to 0. */
5540 /* If this is a scope breakpoint, mark the associated
5541 watchpoint as triggered so that we will handle the
5542 out-of-scope event. We'll get to the watchpoint next
5544 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5546 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5548 w
->watchpoint_triggered
= watch_triggered_yes
;
5553 /* Check if a moribund breakpoint explains the stop. */
5554 if (!target_supports_stopped_by_sw_breakpoint ()
5555 || !target_supports_stopped_by_hw_breakpoint ())
5557 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5559 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5560 && need_moribund_for_location_type (loc
))
5562 bs
= new bpstats (loc
, &bs_link
);
5563 /* For hits of moribund locations, we should just proceed. */
5566 bs
->print_it
= print_it_noop
;
5571 /* A bit of special processing for shlib breakpoints. We need to
5572 process solib loading here, so that the lists of loaded and
5573 unloaded libraries are correct before we handle "catch load" and
5575 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5577 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5579 handle_solib_event ();
5584 /* Now go through the locations that caused the target to stop, and
5585 check whether we're interested in reporting this stop to higher
5586 layers, or whether we should resume the target transparently. */
5590 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5595 b
= bs
->breakpoint_at
;
5596 b
->ops
->check_status (bs
);
5599 bpstat_check_breakpoint_conditions (bs
, ptid
);
5604 observer_notify_breakpoint_modified (b
);
5606 /* We will stop here. */
5607 if (b
->disposition
== disp_disable
)
5609 --(b
->enable_count
);
5610 if (b
->enable_count
<= 0)
5611 b
->enable_state
= bp_disabled
;
5616 bs
->commands
= b
->commands
;
5617 if (command_line_is_silent (bs
->commands
5618 ? bs
->commands
.get () : NULL
))
5621 b
->ops
->after_condition_true (bs
);
5626 /* Print nothing for this entry if we don't stop or don't
5628 if (!bs
->stop
|| !bs
->print
)
5629 bs
->print_it
= print_it_noop
;
5632 /* If we aren't stopping, the value of some hardware watchpoint may
5633 not have changed, but the intermediate memory locations we are
5634 watching may have. Don't bother if we're stopping; this will get
5636 need_remove_insert
= 0;
5637 if (! bpstat_causes_stop (bs_head
))
5638 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5640 && bs
->breakpoint_at
5641 && is_hardware_watchpoint (bs
->breakpoint_at
))
5643 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5645 update_watchpoint (w
, 0 /* don't reparse. */);
5646 need_remove_insert
= 1;
5649 if (need_remove_insert
)
5650 update_global_location_list (UGLL_MAY_INSERT
);
5651 else if (removed_any
)
5652 update_global_location_list (UGLL_DONT_INSERT
);
5658 handle_jit_event (void)
5660 struct frame_info
*frame
;
5661 struct gdbarch
*gdbarch
;
5664 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5666 /* Switch terminal for any messages produced by
5667 breakpoint_re_set. */
5668 target_terminal::ours_for_output ();
5670 frame
= get_current_frame ();
5671 gdbarch
= get_frame_arch (frame
);
5673 jit_event_handler (gdbarch
);
5675 target_terminal::inferior ();
5678 /* Prepare WHAT final decision for infrun. */
5680 /* Decide what infrun needs to do with this bpstat. */
5683 bpstat_what (bpstat bs_head
)
5685 struct bpstat_what retval
;
5688 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5689 retval
.call_dummy
= STOP_NONE
;
5690 retval
.is_longjmp
= 0;
5692 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5694 /* Extract this BS's action. After processing each BS, we check
5695 if its action overrides all we've seem so far. */
5696 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5699 if (bs
->breakpoint_at
== NULL
)
5701 /* I suspect this can happen if it was a momentary
5702 breakpoint which has since been deleted. */
5706 bptype
= bs
->breakpoint_at
->type
;
5713 case bp_hardware_breakpoint
:
5714 case bp_single_step
:
5717 case bp_shlib_event
:
5721 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5723 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5726 this_action
= BPSTAT_WHAT_SINGLE
;
5729 case bp_hardware_watchpoint
:
5730 case bp_read_watchpoint
:
5731 case bp_access_watchpoint
:
5735 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5737 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5741 /* There was a watchpoint, but we're not stopping.
5742 This requires no further action. */
5746 case bp_longjmp_call_dummy
:
5750 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5751 retval
.is_longjmp
= bptype
!= bp_exception
;
5754 this_action
= BPSTAT_WHAT_SINGLE
;
5756 case bp_longjmp_resume
:
5757 case bp_exception_resume
:
5760 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5761 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5764 this_action
= BPSTAT_WHAT_SINGLE
;
5766 case bp_step_resume
:
5768 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5771 /* It is for the wrong frame. */
5772 this_action
= BPSTAT_WHAT_SINGLE
;
5775 case bp_hp_step_resume
:
5777 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5780 /* It is for the wrong frame. */
5781 this_action
= BPSTAT_WHAT_SINGLE
;
5784 case bp_watchpoint_scope
:
5785 case bp_thread_event
:
5786 case bp_overlay_event
:
5787 case bp_longjmp_master
:
5788 case bp_std_terminate_master
:
5789 case bp_exception_master
:
5790 this_action
= BPSTAT_WHAT_SINGLE
;
5796 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5798 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5802 /* There was a catchpoint, but we're not stopping.
5803 This requires no further action. */
5807 this_action
= BPSTAT_WHAT_SINGLE
;
5810 /* Make sure the action is stop (silent or noisy),
5811 so infrun.c pops the dummy frame. */
5812 retval
.call_dummy
= STOP_STACK_DUMMY
;
5813 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5815 case bp_std_terminate
:
5816 /* Make sure the action is stop (silent or noisy),
5817 so infrun.c pops the dummy frame. */
5818 retval
.call_dummy
= STOP_STD_TERMINATE
;
5819 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5822 case bp_fast_tracepoint
:
5823 case bp_static_tracepoint
:
5824 /* Tracepoint hits should not be reported back to GDB, and
5825 if one got through somehow, it should have been filtered
5827 internal_error (__FILE__
, __LINE__
,
5828 _("bpstat_what: tracepoint encountered"));
5830 case bp_gnu_ifunc_resolver
:
5831 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5832 this_action
= BPSTAT_WHAT_SINGLE
;
5834 case bp_gnu_ifunc_resolver_return
:
5835 /* The breakpoint will be removed, execution will restart from the
5836 PC of the former breakpoint. */
5837 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5842 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5844 this_action
= BPSTAT_WHAT_SINGLE
;
5848 internal_error (__FILE__
, __LINE__
,
5849 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5852 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5859 bpstat_run_callbacks (bpstat bs_head
)
5863 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5865 struct breakpoint
*b
= bs
->breakpoint_at
;
5872 handle_jit_event ();
5874 case bp_gnu_ifunc_resolver
:
5875 gnu_ifunc_resolver_stop (b
);
5877 case bp_gnu_ifunc_resolver_return
:
5878 gnu_ifunc_resolver_return_stop (b
);
5884 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5885 without hardware support). This isn't related to a specific bpstat,
5886 just to things like whether watchpoints are set. */
5889 bpstat_should_step (void)
5891 struct breakpoint
*b
;
5894 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5900 bpstat_causes_stop (bpstat bs
)
5902 for (; bs
!= NULL
; bs
= bs
->next
)
5911 /* Compute a string of spaces suitable to indent the next line
5912 so it starts at the position corresponding to the table column
5913 named COL_NAME in the currently active table of UIOUT. */
5916 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5918 static char wrap_indent
[80];
5919 int i
, total_width
, width
, align
;
5923 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5925 if (strcmp (text
, col_name
) == 0)
5927 gdb_assert (total_width
< sizeof wrap_indent
);
5928 memset (wrap_indent
, ' ', total_width
);
5929 wrap_indent
[total_width
] = 0;
5934 total_width
+= width
+ 1;
5940 /* Determine if the locations of this breakpoint will have their conditions
5941 evaluated by the target, host or a mix of both. Returns the following:
5943 "host": Host evals condition.
5944 "host or target": Host or Target evals condition.
5945 "target": Target evals condition.
5949 bp_condition_evaluator (struct breakpoint
*b
)
5951 struct bp_location
*bl
;
5952 char host_evals
= 0;
5953 char target_evals
= 0;
5958 if (!is_breakpoint (b
))
5961 if (gdb_evaluates_breakpoint_condition_p ()
5962 || !target_supports_evaluation_of_breakpoint_conditions ())
5963 return condition_evaluation_host
;
5965 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5967 if (bl
->cond_bytecode
)
5973 if (host_evals
&& target_evals
)
5974 return condition_evaluation_both
;
5975 else if (target_evals
)
5976 return condition_evaluation_target
;
5978 return condition_evaluation_host
;
5981 /* Determine the breakpoint location's condition evaluator. This is
5982 similar to bp_condition_evaluator, but for locations. */
5985 bp_location_condition_evaluator (struct bp_location
*bl
)
5987 if (bl
&& !is_breakpoint (bl
->owner
))
5990 if (gdb_evaluates_breakpoint_condition_p ()
5991 || !target_supports_evaluation_of_breakpoint_conditions ())
5992 return condition_evaluation_host
;
5994 if (bl
&& bl
->cond_bytecode
)
5995 return condition_evaluation_target
;
5997 return condition_evaluation_host
;
6000 /* Print the LOC location out of the list of B->LOC locations. */
6003 print_breakpoint_location (struct breakpoint
*b
,
6004 struct bp_location
*loc
)
6006 struct ui_out
*uiout
= current_uiout
;
6008 scoped_restore_current_program_space restore_pspace
;
6010 if (loc
!= NULL
&& loc
->shlib_disabled
)
6014 set_current_program_space (loc
->pspace
);
6016 if (b
->display_canonical
)
6017 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6018 else if (loc
&& loc
->symtab
)
6021 = find_pc_sect_function (loc
->address
, loc
->section
);
6024 uiout
->text ("in ");
6025 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6027 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6028 uiout
->text ("at ");
6030 uiout
->field_string ("file",
6031 symtab_to_filename_for_display (loc
->symtab
));
6034 if (uiout
->is_mi_like_p ())
6035 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6037 uiout
->field_int ("line", loc
->line_number
);
6043 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6045 uiout
->field_stream ("at", stb
);
6049 uiout
->field_string ("pending",
6050 event_location_to_string (b
->location
.get ()));
6051 /* If extra_string is available, it could be holding a condition
6052 or dprintf arguments. In either case, make sure it is printed,
6053 too, but only for non-MI streams. */
6054 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6056 if (b
->type
== bp_dprintf
)
6060 uiout
->text (b
->extra_string
);
6064 if (loc
&& is_breakpoint (b
)
6065 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6066 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6069 uiout
->field_string ("evaluated-by",
6070 bp_location_condition_evaluator (loc
));
6076 bptype_string (enum bptype type
)
6078 struct ep_type_description
6081 const char *description
;
6083 static struct ep_type_description bptypes
[] =
6085 {bp_none
, "?deleted?"},
6086 {bp_breakpoint
, "breakpoint"},
6087 {bp_hardware_breakpoint
, "hw breakpoint"},
6088 {bp_single_step
, "sw single-step"},
6089 {bp_until
, "until"},
6090 {bp_finish
, "finish"},
6091 {bp_watchpoint
, "watchpoint"},
6092 {bp_hardware_watchpoint
, "hw watchpoint"},
6093 {bp_read_watchpoint
, "read watchpoint"},
6094 {bp_access_watchpoint
, "acc watchpoint"},
6095 {bp_longjmp
, "longjmp"},
6096 {bp_longjmp_resume
, "longjmp resume"},
6097 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6098 {bp_exception
, "exception"},
6099 {bp_exception_resume
, "exception resume"},
6100 {bp_step_resume
, "step resume"},
6101 {bp_hp_step_resume
, "high-priority step resume"},
6102 {bp_watchpoint_scope
, "watchpoint scope"},
6103 {bp_call_dummy
, "call dummy"},
6104 {bp_std_terminate
, "std::terminate"},
6105 {bp_shlib_event
, "shlib events"},
6106 {bp_thread_event
, "thread events"},
6107 {bp_overlay_event
, "overlay events"},
6108 {bp_longjmp_master
, "longjmp master"},
6109 {bp_std_terminate_master
, "std::terminate master"},
6110 {bp_exception_master
, "exception master"},
6111 {bp_catchpoint
, "catchpoint"},
6112 {bp_tracepoint
, "tracepoint"},
6113 {bp_fast_tracepoint
, "fast tracepoint"},
6114 {bp_static_tracepoint
, "static tracepoint"},
6115 {bp_dprintf
, "dprintf"},
6116 {bp_jit_event
, "jit events"},
6117 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6118 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6121 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6122 || ((int) type
!= bptypes
[(int) type
].type
))
6123 internal_error (__FILE__
, __LINE__
,
6124 _("bptypes table does not describe type #%d."),
6127 return bptypes
[(int) type
].description
;
6130 /* For MI, output a field named 'thread-groups' with a list as the value.
6131 For CLI, prefix the list with the string 'inf'. */
6134 output_thread_groups (struct ui_out
*uiout
,
6135 const char *field_name
,
6139 int is_mi
= uiout
->is_mi_like_p ();
6143 /* For backward compatibility, don't display inferiors in CLI unless
6144 there are several. Always display them for MI. */
6145 if (!is_mi
&& mi_only
)
6148 ui_out_emit_list
list_emitter (uiout
, field_name
);
6150 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6156 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6157 uiout
->field_string (NULL
, mi_group
);
6162 uiout
->text (" inf ");
6166 uiout
->text (plongest (inf
));
6171 /* Print B to gdb_stdout. */
6174 print_one_breakpoint_location (struct breakpoint
*b
,
6175 struct bp_location
*loc
,
6177 struct bp_location
**last_loc
,
6180 struct command_line
*l
;
6181 static char bpenables
[] = "nynny";
6183 struct ui_out
*uiout
= current_uiout
;
6184 int header_of_multiple
= 0;
6185 int part_of_multiple
= (loc
!= NULL
);
6186 struct value_print_options opts
;
6188 get_user_print_options (&opts
);
6190 gdb_assert (!loc
|| loc_number
!= 0);
6191 /* See comment in print_one_breakpoint concerning treatment of
6192 breakpoints with single disabled location. */
6195 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6196 header_of_multiple
= 1;
6204 if (part_of_multiple
)
6207 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6208 uiout
->field_string ("number", formatted
);
6213 uiout
->field_int ("number", b
->number
);
6218 if (part_of_multiple
)
6219 uiout
->field_skip ("type");
6221 uiout
->field_string ("type", bptype_string (b
->type
));
6225 if (part_of_multiple
)
6226 uiout
->field_skip ("disp");
6228 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6233 if (part_of_multiple
)
6234 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6236 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6241 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6243 /* Although the print_one can possibly print all locations,
6244 calling it here is not likely to get any nice result. So,
6245 make sure there's just one location. */
6246 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6247 b
->ops
->print_one (b
, last_loc
);
6253 internal_error (__FILE__
, __LINE__
,
6254 _("print_one_breakpoint: bp_none encountered\n"));
6258 case bp_hardware_watchpoint
:
6259 case bp_read_watchpoint
:
6260 case bp_access_watchpoint
:
6262 struct watchpoint
*w
= (struct watchpoint
*) b
;
6264 /* Field 4, the address, is omitted (which makes the columns
6265 not line up too nicely with the headers, but the effect
6266 is relatively readable). */
6267 if (opts
.addressprint
)
6268 uiout
->field_skip ("addr");
6270 uiout
->field_string ("what", w
->exp_string
);
6275 case bp_hardware_breakpoint
:
6276 case bp_single_step
:
6280 case bp_longjmp_resume
:
6281 case bp_longjmp_call_dummy
:
6283 case bp_exception_resume
:
6284 case bp_step_resume
:
6285 case bp_hp_step_resume
:
6286 case bp_watchpoint_scope
:
6288 case bp_std_terminate
:
6289 case bp_shlib_event
:
6290 case bp_thread_event
:
6291 case bp_overlay_event
:
6292 case bp_longjmp_master
:
6293 case bp_std_terminate_master
:
6294 case bp_exception_master
:
6296 case bp_fast_tracepoint
:
6297 case bp_static_tracepoint
:
6300 case bp_gnu_ifunc_resolver
:
6301 case bp_gnu_ifunc_resolver_return
:
6302 if (opts
.addressprint
)
6305 if (header_of_multiple
)
6306 uiout
->field_string ("addr", "<MULTIPLE>");
6307 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6308 uiout
->field_string ("addr", "<PENDING>");
6310 uiout
->field_core_addr ("addr",
6311 loc
->gdbarch
, loc
->address
);
6314 if (!header_of_multiple
)
6315 print_breakpoint_location (b
, loc
);
6322 if (loc
!= NULL
&& !header_of_multiple
)
6324 struct inferior
*inf
;
6325 VEC(int) *inf_num
= NULL
;
6330 if (inf
->pspace
== loc
->pspace
)
6331 VEC_safe_push (int, inf_num
, inf
->num
);
6334 /* For backward compatibility, don't display inferiors in CLI unless
6335 there are several. Always display for MI. */
6337 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6338 && (number_of_program_spaces () > 1
6339 || number_of_inferiors () > 1)
6340 /* LOC is for existing B, it cannot be in
6341 moribund_locations and thus having NULL OWNER. */
6342 && loc
->owner
->type
!= bp_catchpoint
))
6344 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6345 VEC_free (int, inf_num
);
6348 if (!part_of_multiple
)
6350 if (b
->thread
!= -1)
6352 /* FIXME: This seems to be redundant and lost here; see the
6353 "stop only in" line a little further down. */
6354 uiout
->text (" thread ");
6355 uiout
->field_int ("thread", b
->thread
);
6357 else if (b
->task
!= 0)
6359 uiout
->text (" task ");
6360 uiout
->field_int ("task", b
->task
);
6366 if (!part_of_multiple
)
6367 b
->ops
->print_one_detail (b
, uiout
);
6369 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6372 uiout
->text ("\tstop only in stack frame at ");
6373 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6375 uiout
->field_core_addr ("frame",
6376 b
->gdbarch
, b
->frame_id
.stack_addr
);
6380 if (!part_of_multiple
&& b
->cond_string
)
6383 if (is_tracepoint (b
))
6384 uiout
->text ("\ttrace only if ");
6386 uiout
->text ("\tstop only if ");
6387 uiout
->field_string ("cond", b
->cond_string
);
6389 /* Print whether the target is doing the breakpoint's condition
6390 evaluation. If GDB is doing the evaluation, don't print anything. */
6391 if (is_breakpoint (b
)
6392 && breakpoint_condition_evaluation_mode ()
6393 == condition_evaluation_target
)
6396 uiout
->field_string ("evaluated-by",
6397 bp_condition_evaluator (b
));
6398 uiout
->text (" evals)");
6403 if (!part_of_multiple
&& b
->thread
!= -1)
6405 /* FIXME should make an annotation for this. */
6406 uiout
->text ("\tstop only in thread ");
6407 if (uiout
->is_mi_like_p ())
6408 uiout
->field_int ("thread", b
->thread
);
6411 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6413 uiout
->field_string ("thread", print_thread_id (thr
));
6418 if (!part_of_multiple
)
6422 /* FIXME should make an annotation for this. */
6423 if (is_catchpoint (b
))
6424 uiout
->text ("\tcatchpoint");
6425 else if (is_tracepoint (b
))
6426 uiout
->text ("\ttracepoint");
6428 uiout
->text ("\tbreakpoint");
6429 uiout
->text (" already hit ");
6430 uiout
->field_int ("times", b
->hit_count
);
6431 if (b
->hit_count
== 1)
6432 uiout
->text (" time\n");
6434 uiout
->text (" times\n");
6438 /* Output the count also if it is zero, but only if this is mi. */
6439 if (uiout
->is_mi_like_p ())
6440 uiout
->field_int ("times", b
->hit_count
);
6444 if (!part_of_multiple
&& b
->ignore_count
)
6447 uiout
->text ("\tignore next ");
6448 uiout
->field_int ("ignore", b
->ignore_count
);
6449 uiout
->text (" hits\n");
6452 /* Note that an enable count of 1 corresponds to "enable once"
6453 behavior, which is reported by the combination of enablement and
6454 disposition, so we don't need to mention it here. */
6455 if (!part_of_multiple
&& b
->enable_count
> 1)
6458 uiout
->text ("\tdisable after ");
6459 /* Tweak the wording to clarify that ignore and enable counts
6460 are distinct, and have additive effect. */
6461 if (b
->ignore_count
)
6462 uiout
->text ("additional ");
6464 uiout
->text ("next ");
6465 uiout
->field_int ("enable", b
->enable_count
);
6466 uiout
->text (" hits\n");
6469 if (!part_of_multiple
&& is_tracepoint (b
))
6471 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6473 if (tp
->traceframe_usage
)
6475 uiout
->text ("\ttrace buffer usage ");
6476 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6477 uiout
->text (" bytes\n");
6481 l
= b
->commands
? b
->commands
.get () : NULL
;
6482 if (!part_of_multiple
&& l
)
6485 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6486 print_command_lines (uiout
, l
, 4);
6489 if (is_tracepoint (b
))
6491 struct tracepoint
*t
= (struct tracepoint
*) b
;
6493 if (!part_of_multiple
&& t
->pass_count
)
6495 annotate_field (10);
6496 uiout
->text ("\tpass count ");
6497 uiout
->field_int ("pass", t
->pass_count
);
6498 uiout
->text (" \n");
6501 /* Don't display it when tracepoint or tracepoint location is
6503 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6505 annotate_field (11);
6507 if (uiout
->is_mi_like_p ())
6508 uiout
->field_string ("installed",
6509 loc
->inserted
? "y" : "n");
6515 uiout
->text ("\tnot ");
6516 uiout
->text ("installed on target\n");
6521 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6523 if (is_watchpoint (b
))
6525 struct watchpoint
*w
= (struct watchpoint
*) b
;
6527 uiout
->field_string ("original-location", w
->exp_string
);
6529 else if (b
->location
!= NULL
6530 && event_location_to_string (b
->location
.get ()) != NULL
)
6531 uiout
->field_string ("original-location",
6532 event_location_to_string (b
->location
.get ()));
6537 print_one_breakpoint (struct breakpoint
*b
,
6538 struct bp_location
**last_loc
,
6541 struct ui_out
*uiout
= current_uiout
;
6544 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6546 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6549 /* If this breakpoint has custom print function,
6550 it's already printed. Otherwise, print individual
6551 locations, if any. */
6552 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6554 /* If breakpoint has a single location that is disabled, we
6555 print it as if it had several locations, since otherwise it's
6556 hard to represent "breakpoint enabled, location disabled"
6559 Note that while hardware watchpoints have several locations
6560 internally, that's not a property exposed to user. */
6562 && !is_hardware_watchpoint (b
)
6563 && (b
->loc
->next
|| !b
->loc
->enabled
))
6565 struct bp_location
*loc
;
6568 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6570 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6571 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6578 breakpoint_address_bits (struct breakpoint
*b
)
6580 int print_address_bits
= 0;
6581 struct bp_location
*loc
;
6583 /* Software watchpoints that aren't watching memory don't have an
6584 address to print. */
6585 if (is_no_memory_software_watchpoint (b
))
6588 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6592 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6593 if (addr_bit
> print_address_bits
)
6594 print_address_bits
= addr_bit
;
6597 return print_address_bits
;
6600 struct captured_breakpoint_query_args
6606 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6608 struct captured_breakpoint_query_args
*args
6609 = (struct captured_breakpoint_query_args
*) data
;
6610 struct breakpoint
*b
;
6611 struct bp_location
*dummy_loc
= NULL
;
6615 if (args
->bnum
== b
->number
)
6617 print_one_breakpoint (b
, &dummy_loc
, 0);
6625 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6626 char **error_message
)
6628 struct captured_breakpoint_query_args args
;
6631 /* For the moment we don't trust print_one_breakpoint() to not throw
6633 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6634 error_message
, RETURN_MASK_ALL
) < 0)
6640 /* Return true if this breakpoint was set by the user, false if it is
6641 internal or momentary. */
6644 user_breakpoint_p (struct breakpoint
*b
)
6646 return b
->number
> 0;
6649 /* See breakpoint.h. */
6652 pending_breakpoint_p (struct breakpoint
*b
)
6654 return b
->loc
== NULL
;
6657 /* Print information on user settable breakpoint (watchpoint, etc)
6658 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6659 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6660 FILTER is non-NULL, call it on each breakpoint and only include the
6661 ones for which it returns non-zero. Return the total number of
6662 breakpoints listed. */
6665 breakpoint_1 (const char *args
, int allflag
,
6666 int (*filter
) (const struct breakpoint
*))
6668 struct breakpoint
*b
;
6669 struct bp_location
*last_loc
= NULL
;
6670 int nr_printable_breakpoints
;
6671 struct value_print_options opts
;
6672 int print_address_bits
= 0;
6673 int print_type_col_width
= 14;
6674 struct ui_out
*uiout
= current_uiout
;
6676 get_user_print_options (&opts
);
6678 /* Compute the number of rows in the table, as well as the size
6679 required for address fields. */
6680 nr_printable_breakpoints
= 0;
6683 /* If we have a filter, only list the breakpoints it accepts. */
6684 if (filter
&& !filter (b
))
6687 /* If we have an "args" string, it is a list of breakpoints to
6688 accept. Skip the others. */
6689 if (args
!= NULL
&& *args
!= '\0')
6691 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6693 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6697 if (allflag
|| user_breakpoint_p (b
))
6699 int addr_bit
, type_len
;
6701 addr_bit
= breakpoint_address_bits (b
);
6702 if (addr_bit
> print_address_bits
)
6703 print_address_bits
= addr_bit
;
6705 type_len
= strlen (bptype_string (b
->type
));
6706 if (type_len
> print_type_col_width
)
6707 print_type_col_width
= type_len
;
6709 nr_printable_breakpoints
++;
6714 ui_out_emit_table
table_emitter (uiout
,
6715 opts
.addressprint
? 6 : 5,
6716 nr_printable_breakpoints
,
6719 if (nr_printable_breakpoints
> 0)
6720 annotate_breakpoints_headers ();
6721 if (nr_printable_breakpoints
> 0)
6723 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6724 if (nr_printable_breakpoints
> 0)
6726 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6727 if (nr_printable_breakpoints
> 0)
6729 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6730 if (nr_printable_breakpoints
> 0)
6732 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6733 if (opts
.addressprint
)
6735 if (nr_printable_breakpoints
> 0)
6737 if (print_address_bits
<= 32)
6738 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6740 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6742 if (nr_printable_breakpoints
> 0)
6744 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6745 uiout
->table_body ();
6746 if (nr_printable_breakpoints
> 0)
6747 annotate_breakpoints_table ();
6752 /* If we have a filter, only list the breakpoints it accepts. */
6753 if (filter
&& !filter (b
))
6756 /* If we have an "args" string, it is a list of breakpoints to
6757 accept. Skip the others. */
6759 if (args
!= NULL
&& *args
!= '\0')
6761 if (allflag
) /* maintenance info breakpoint */
6763 if (parse_and_eval_long (args
) != b
->number
)
6766 else /* all others */
6768 if (!number_is_in_list (args
, b
->number
))
6772 /* We only print out user settable breakpoints unless the
6774 if (allflag
|| user_breakpoint_p (b
))
6775 print_one_breakpoint (b
, &last_loc
, allflag
);
6779 if (nr_printable_breakpoints
== 0)
6781 /* If there's a filter, let the caller decide how to report
6785 if (args
== NULL
|| *args
== '\0')
6786 uiout
->message ("No breakpoints or watchpoints.\n");
6788 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6794 if (last_loc
&& !server_command
)
6795 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6798 /* FIXME? Should this be moved up so that it is only called when
6799 there have been breakpoints? */
6800 annotate_breakpoints_table_end ();
6802 return nr_printable_breakpoints
;
6805 /* Display the value of default-collect in a way that is generally
6806 compatible with the breakpoint list. */
6809 default_collect_info (void)
6811 struct ui_out
*uiout
= current_uiout
;
6813 /* If it has no value (which is frequently the case), say nothing; a
6814 message like "No default-collect." gets in user's face when it's
6816 if (!*default_collect
)
6819 /* The following phrase lines up nicely with per-tracepoint collect
6821 uiout
->text ("default collect ");
6822 uiout
->field_string ("default-collect", default_collect
);
6823 uiout
->text (" \n");
6827 info_breakpoints_command (char *args
, int from_tty
)
6829 breakpoint_1 (args
, 0, NULL
);
6831 default_collect_info ();
6835 info_watchpoints_command (char *args
, int from_tty
)
6837 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6838 struct ui_out
*uiout
= current_uiout
;
6840 if (num_printed
== 0)
6842 if (args
== NULL
|| *args
== '\0')
6843 uiout
->message ("No watchpoints.\n");
6845 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6850 maintenance_info_breakpoints (const char *args
, int from_tty
)
6852 breakpoint_1 (args
, 1, NULL
);
6854 default_collect_info ();
6858 breakpoint_has_pc (struct breakpoint
*b
,
6859 struct program_space
*pspace
,
6860 CORE_ADDR pc
, struct obj_section
*section
)
6862 struct bp_location
*bl
= b
->loc
;
6864 for (; bl
; bl
= bl
->next
)
6866 if (bl
->pspace
== pspace
6867 && bl
->address
== pc
6868 && (!overlay_debugging
|| bl
->section
== section
))
6874 /* Print a message describing any user-breakpoints set at PC. This
6875 concerns with logical breakpoints, so we match program spaces, not
6879 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6880 struct program_space
*pspace
, CORE_ADDR pc
,
6881 struct obj_section
*section
, int thread
)
6884 struct breakpoint
*b
;
6887 others
+= (user_breakpoint_p (b
)
6888 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6892 printf_filtered (_("Note: breakpoint "));
6893 else /* if (others == ???) */
6894 printf_filtered (_("Note: breakpoints "));
6896 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6899 printf_filtered ("%d", b
->number
);
6900 if (b
->thread
== -1 && thread
!= -1)
6901 printf_filtered (" (all threads)");
6902 else if (b
->thread
!= -1)
6903 printf_filtered (" (thread %d)", b
->thread
);
6904 printf_filtered ("%s%s ",
6905 ((b
->enable_state
== bp_disabled
6906 || b
->enable_state
== bp_call_disabled
)
6910 : ((others
== 1) ? " and" : ""));
6912 printf_filtered (_("also set at pc "));
6913 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6914 printf_filtered (".\n");
6919 /* Return true iff it is meaningful to use the address member of
6920 BPT locations. For some breakpoint types, the locations' address members
6921 are irrelevant and it makes no sense to attempt to compare them to other
6922 addresses (or use them for any other purpose either).
6924 More specifically, each of the following breakpoint types will
6925 always have a zero valued location address and we don't want to mark
6926 breakpoints of any of these types to be a duplicate of an actual
6927 breakpoint location at address zero:
6935 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6937 enum bptype type
= bpt
->type
;
6939 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6942 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6943 true if LOC1 and LOC2 represent the same watchpoint location. */
6946 watchpoint_locations_match (struct bp_location
*loc1
,
6947 struct bp_location
*loc2
)
6949 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6950 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6952 /* Both of them must exist. */
6953 gdb_assert (w1
!= NULL
);
6954 gdb_assert (w2
!= NULL
);
6956 /* If the target can evaluate the condition expression in hardware,
6957 then we we need to insert both watchpoints even if they are at
6958 the same place. Otherwise the watchpoint will only trigger when
6959 the condition of whichever watchpoint was inserted evaluates to
6960 true, not giving a chance for GDB to check the condition of the
6961 other watchpoint. */
6963 && target_can_accel_watchpoint_condition (loc1
->address
,
6965 loc1
->watchpoint_type
,
6966 w1
->cond_exp
.get ()))
6968 && target_can_accel_watchpoint_condition (loc2
->address
,
6970 loc2
->watchpoint_type
,
6971 w2
->cond_exp
.get ())))
6974 /* Note that this checks the owner's type, not the location's. In
6975 case the target does not support read watchpoints, but does
6976 support access watchpoints, we'll have bp_read_watchpoint
6977 watchpoints with hw_access locations. Those should be considered
6978 duplicates of hw_read locations. The hw_read locations will
6979 become hw_access locations later. */
6980 return (loc1
->owner
->type
== loc2
->owner
->type
6981 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6982 && loc1
->address
== loc2
->address
6983 && loc1
->length
== loc2
->length
);
6986 /* See breakpoint.h. */
6989 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6990 struct address_space
*aspace2
, CORE_ADDR addr2
)
6992 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6993 || aspace1
== aspace2
)
6997 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6998 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6999 matches ASPACE2. On targets that have global breakpoints, the address
7000 space doesn't really matter. */
7003 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7004 int len1
, struct address_space
*aspace2
,
7007 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7008 || aspace1
== aspace2
)
7009 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7012 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7013 a ranged breakpoint. In most targets, a match happens only if ASPACE
7014 matches the breakpoint's address space. On targets that have global
7015 breakpoints, the address space doesn't really matter. */
7018 breakpoint_location_address_match (struct bp_location
*bl
,
7019 struct address_space
*aspace
,
7022 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7025 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7026 bl
->address
, bl
->length
,
7030 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7031 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7032 match happens only if ASPACE matches the breakpoint's address
7033 space. On targets that have global breakpoints, the address space
7034 doesn't really matter. */
7037 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7038 struct address_space
*aspace
,
7039 CORE_ADDR addr
, int len
)
7041 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7042 || bl
->pspace
->aspace
== aspace
)
7044 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7046 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7052 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7053 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7054 true, otherwise returns false. */
7057 tracepoint_locations_match (struct bp_location
*loc1
,
7058 struct bp_location
*loc2
)
7060 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7061 /* Since tracepoint locations are never duplicated with others', tracepoint
7062 locations at the same address of different tracepoints are regarded as
7063 different locations. */
7064 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7069 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7070 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7071 represent the same location. */
7074 breakpoint_locations_match (struct bp_location
*loc1
,
7075 struct bp_location
*loc2
)
7077 int hw_point1
, hw_point2
;
7079 /* Both of them must not be in moribund_locations. */
7080 gdb_assert (loc1
->owner
!= NULL
);
7081 gdb_assert (loc2
->owner
!= NULL
);
7083 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7084 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7086 if (hw_point1
!= hw_point2
)
7089 return watchpoint_locations_match (loc1
, loc2
);
7090 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7091 return tracepoint_locations_match (loc1
, loc2
);
7093 /* We compare bp_location.length in order to cover ranged breakpoints. */
7094 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7095 loc2
->pspace
->aspace
, loc2
->address
)
7096 && loc1
->length
== loc2
->length
);
7100 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7101 int bnum
, int have_bnum
)
7103 /* The longest string possibly returned by hex_string_custom
7104 is 50 chars. These must be at least that big for safety. */
7108 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7109 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7111 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7112 bnum
, astr1
, astr2
);
7114 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7117 /* Adjust a breakpoint's address to account for architectural
7118 constraints on breakpoint placement. Return the adjusted address.
7119 Note: Very few targets require this kind of adjustment. For most
7120 targets, this function is simply the identity function. */
7123 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7124 CORE_ADDR bpaddr
, enum bptype bptype
)
7126 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7128 /* Very few targets need any kind of breakpoint adjustment. */
7131 else if (bptype
== bp_watchpoint
7132 || bptype
== bp_hardware_watchpoint
7133 || bptype
== bp_read_watchpoint
7134 || bptype
== bp_access_watchpoint
7135 || bptype
== bp_catchpoint
)
7137 /* Watchpoints and the various bp_catch_* eventpoints should not
7138 have their addresses modified. */
7141 else if (bptype
== bp_single_step
)
7143 /* Single-step breakpoints should not have their addresses
7144 modified. If there's any architectural constrain that
7145 applies to this address, then it should have already been
7146 taken into account when the breakpoint was created in the
7147 first place. If we didn't do this, stepping through e.g.,
7148 Thumb-2 IT blocks would break. */
7153 CORE_ADDR adjusted_bpaddr
;
7155 /* Some targets have architectural constraints on the placement
7156 of breakpoint instructions. Obtain the adjusted address. */
7157 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7159 /* An adjusted breakpoint address can significantly alter
7160 a user's expectations. Print a warning if an adjustment
7162 if (adjusted_bpaddr
!= bpaddr
)
7163 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7165 return adjusted_bpaddr
;
7169 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7171 bp_location
*loc
= this;
7173 gdb_assert (ops
!= NULL
);
7177 loc
->cond_bytecode
= NULL
;
7178 loc
->shlib_disabled
= 0;
7181 switch (owner
->type
)
7184 case bp_single_step
:
7188 case bp_longjmp_resume
:
7189 case bp_longjmp_call_dummy
:
7191 case bp_exception_resume
:
7192 case bp_step_resume
:
7193 case bp_hp_step_resume
:
7194 case bp_watchpoint_scope
:
7196 case bp_std_terminate
:
7197 case bp_shlib_event
:
7198 case bp_thread_event
:
7199 case bp_overlay_event
:
7201 case bp_longjmp_master
:
7202 case bp_std_terminate_master
:
7203 case bp_exception_master
:
7204 case bp_gnu_ifunc_resolver
:
7205 case bp_gnu_ifunc_resolver_return
:
7207 loc
->loc_type
= bp_loc_software_breakpoint
;
7208 mark_breakpoint_location_modified (loc
);
7210 case bp_hardware_breakpoint
:
7211 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7212 mark_breakpoint_location_modified (loc
);
7214 case bp_hardware_watchpoint
:
7215 case bp_read_watchpoint
:
7216 case bp_access_watchpoint
:
7217 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7222 case bp_fast_tracepoint
:
7223 case bp_static_tracepoint
:
7224 loc
->loc_type
= bp_loc_other
;
7227 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7233 /* Allocate a struct bp_location. */
7235 static struct bp_location
*
7236 allocate_bp_location (struct breakpoint
*bpt
)
7238 return bpt
->ops
->allocate_location (bpt
);
7242 free_bp_location (struct bp_location
*loc
)
7244 loc
->ops
->dtor (loc
);
7248 /* Increment reference count. */
7251 incref_bp_location (struct bp_location
*bl
)
7256 /* Decrement reference count. If the reference count reaches 0,
7257 destroy the bp_location. Sets *BLP to NULL. */
7260 decref_bp_location (struct bp_location
**blp
)
7262 gdb_assert ((*blp
)->refc
> 0);
7264 if (--(*blp
)->refc
== 0)
7265 free_bp_location (*blp
);
7269 /* Add breakpoint B at the end of the global breakpoint chain. */
7272 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7274 struct breakpoint
*b1
;
7275 struct breakpoint
*result
= b
.get ();
7277 /* Add this breakpoint to the end of the chain so that a list of
7278 breakpoints will come out in order of increasing numbers. */
7280 b1
= breakpoint_chain
;
7282 breakpoint_chain
= b
.release ();
7287 b1
->next
= b
.release ();
7293 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7296 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7297 struct gdbarch
*gdbarch
,
7299 const struct breakpoint_ops
*ops
)
7301 gdb_assert (ops
!= NULL
);
7305 b
->gdbarch
= gdbarch
;
7306 b
->language
= current_language
->la_language
;
7307 b
->input_radix
= input_radix
;
7308 b
->related_breakpoint
= b
;
7311 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7312 that has type BPTYPE and has no locations as yet. */
7314 static struct breakpoint
*
7315 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7317 const struct breakpoint_ops
*ops
)
7319 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7321 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7322 return add_to_breakpoint_chain (std::move (b
));
7325 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7326 resolutions should be made as the user specified the location explicitly
7330 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7332 gdb_assert (loc
->owner
!= NULL
);
7334 if (loc
->owner
->type
== bp_breakpoint
7335 || loc
->owner
->type
== bp_hardware_breakpoint
7336 || is_tracepoint (loc
->owner
))
7339 const char *function_name
;
7340 CORE_ADDR func_addr
;
7342 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7343 &func_addr
, NULL
, &is_gnu_ifunc
);
7345 if (is_gnu_ifunc
&& !explicit_loc
)
7347 struct breakpoint
*b
= loc
->owner
;
7349 gdb_assert (loc
->pspace
== current_program_space
);
7350 if (gnu_ifunc_resolve_name (function_name
,
7351 &loc
->requested_address
))
7353 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7354 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7355 loc
->requested_address
,
7358 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7359 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7361 /* Create only the whole new breakpoint of this type but do not
7362 mess more complicated breakpoints with multiple locations. */
7363 b
->type
= bp_gnu_ifunc_resolver
;
7364 /* Remember the resolver's address for use by the return
7366 loc
->related_address
= func_addr
;
7371 loc
->function_name
= xstrdup (function_name
);
7375 /* Attempt to determine architecture of location identified by SAL. */
7377 get_sal_arch (struct symtab_and_line sal
)
7380 return get_objfile_arch (sal
.section
->objfile
);
7382 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7387 /* Low level routine for partially initializing a breakpoint of type
7388 BPTYPE. The newly created breakpoint's address, section, source
7389 file name, and line number are provided by SAL.
7391 It is expected that the caller will complete the initialization of
7392 the newly created breakpoint struct as well as output any status
7393 information regarding the creation of a new breakpoint. */
7396 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7397 struct symtab_and_line sal
, enum bptype bptype
,
7398 const struct breakpoint_ops
*ops
)
7400 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7402 add_location_to_breakpoint (b
, &sal
);
7404 if (bptype
!= bp_catchpoint
)
7405 gdb_assert (sal
.pspace
!= NULL
);
7407 /* Store the program space that was used to set the breakpoint,
7408 except for ordinary breakpoints, which are independent of the
7410 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7411 b
->pspace
= sal
.pspace
;
7414 /* set_raw_breakpoint is a low level routine for allocating and
7415 partially initializing a breakpoint of type BPTYPE. The newly
7416 created breakpoint's address, section, source file name, and line
7417 number are provided by SAL. The newly created and partially
7418 initialized breakpoint is added to the breakpoint chain and
7419 is also returned as the value of this function.
7421 It is expected that the caller will complete the initialization of
7422 the newly created breakpoint struct as well as output any status
7423 information regarding the creation of a new breakpoint. In
7424 particular, set_raw_breakpoint does NOT set the breakpoint
7425 number! Care should be taken to not allow an error to occur
7426 prior to completing the initialization of the breakpoint. If this
7427 should happen, a bogus breakpoint will be left on the chain. */
7430 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7431 struct symtab_and_line sal
, enum bptype bptype
,
7432 const struct breakpoint_ops
*ops
)
7434 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7436 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7437 return add_to_breakpoint_chain (std::move (b
));
7440 /* Call this routine when stepping and nexting to enable a breakpoint
7441 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7442 initiated the operation. */
7445 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7447 struct breakpoint
*b
, *b_tmp
;
7448 int thread
= tp
->global_num
;
7450 /* To avoid having to rescan all objfile symbols at every step,
7451 we maintain a list of continually-inserted but always disabled
7452 longjmp "master" breakpoints. Here, we simply create momentary
7453 clones of those and enable them for the requested thread. */
7454 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7455 if (b
->pspace
== current_program_space
7456 && (b
->type
== bp_longjmp_master
7457 || b
->type
== bp_exception_master
))
7459 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7460 struct breakpoint
*clone
;
7462 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7463 after their removal. */
7464 clone
= momentary_breakpoint_from_master (b
, type
,
7465 &momentary_breakpoint_ops
, 1);
7466 clone
->thread
= thread
;
7469 tp
->initiating_frame
= frame
;
7472 /* Delete all longjmp breakpoints from THREAD. */
7474 delete_longjmp_breakpoint (int thread
)
7476 struct breakpoint
*b
, *b_tmp
;
7478 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7479 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7481 if (b
->thread
== thread
)
7482 delete_breakpoint (b
);
7487 delete_longjmp_breakpoint_at_next_stop (int thread
)
7489 struct breakpoint
*b
, *b_tmp
;
7491 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7492 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7494 if (b
->thread
== thread
)
7495 b
->disposition
= disp_del_at_next_stop
;
7499 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7500 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7501 pointer to any of them. Return NULL if this system cannot place longjmp
7505 set_longjmp_breakpoint_for_call_dummy (void)
7507 struct breakpoint
*b
, *retval
= NULL
;
7510 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7512 struct breakpoint
*new_b
;
7514 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7515 &momentary_breakpoint_ops
,
7517 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7519 /* Link NEW_B into the chain of RETVAL breakpoints. */
7521 gdb_assert (new_b
->related_breakpoint
== new_b
);
7524 new_b
->related_breakpoint
= retval
;
7525 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7526 retval
= retval
->related_breakpoint
;
7527 retval
->related_breakpoint
= new_b
;
7533 /* Verify all existing dummy frames and their associated breakpoints for
7534 TP. Remove those which can no longer be found in the current frame
7537 You should call this function only at places where it is safe to currently
7538 unwind the whole stack. Failed stack unwind would discard live dummy
7542 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7544 struct breakpoint
*b
, *b_tmp
;
7546 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7547 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7549 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7551 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7552 dummy_b
= dummy_b
->related_breakpoint
;
7553 if (dummy_b
->type
!= bp_call_dummy
7554 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7557 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7559 while (b
->related_breakpoint
!= b
)
7561 if (b_tmp
== b
->related_breakpoint
)
7562 b_tmp
= b
->related_breakpoint
->next
;
7563 delete_breakpoint (b
->related_breakpoint
);
7565 delete_breakpoint (b
);
7570 enable_overlay_breakpoints (void)
7572 struct breakpoint
*b
;
7575 if (b
->type
== bp_overlay_event
)
7577 b
->enable_state
= bp_enabled
;
7578 update_global_location_list (UGLL_MAY_INSERT
);
7579 overlay_events_enabled
= 1;
7584 disable_overlay_breakpoints (void)
7586 struct breakpoint
*b
;
7589 if (b
->type
== bp_overlay_event
)
7591 b
->enable_state
= bp_disabled
;
7592 update_global_location_list (UGLL_DONT_INSERT
);
7593 overlay_events_enabled
= 0;
7597 /* Set an active std::terminate breakpoint for each std::terminate
7598 master breakpoint. */
7600 set_std_terminate_breakpoint (void)
7602 struct breakpoint
*b
, *b_tmp
;
7604 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7605 if (b
->pspace
== current_program_space
7606 && b
->type
== bp_std_terminate_master
)
7608 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7609 &momentary_breakpoint_ops
, 1);
7613 /* Delete all the std::terminate breakpoints. */
7615 delete_std_terminate_breakpoint (void)
7617 struct breakpoint
*b
, *b_tmp
;
7619 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7620 if (b
->type
== bp_std_terminate
)
7621 delete_breakpoint (b
);
7625 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7627 struct breakpoint
*b
;
7629 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7630 &internal_breakpoint_ops
);
7632 b
->enable_state
= bp_enabled
;
7633 /* location has to be used or breakpoint_re_set will delete me. */
7634 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7636 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7641 struct lang_and_radix
7647 /* Create a breakpoint for JIT code registration and unregistration. */
7650 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7652 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7653 &internal_breakpoint_ops
);
7656 /* Remove JIT code registration and unregistration breakpoint(s). */
7659 remove_jit_event_breakpoints (void)
7661 struct breakpoint
*b
, *b_tmp
;
7663 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7664 if (b
->type
== bp_jit_event
7665 && b
->loc
->pspace
== current_program_space
)
7666 delete_breakpoint (b
);
7670 remove_solib_event_breakpoints (void)
7672 struct breakpoint
*b
, *b_tmp
;
7674 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7675 if (b
->type
== bp_shlib_event
7676 && b
->loc
->pspace
== current_program_space
)
7677 delete_breakpoint (b
);
7680 /* See breakpoint.h. */
7683 remove_solib_event_breakpoints_at_next_stop (void)
7685 struct breakpoint
*b
, *b_tmp
;
7687 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7688 if (b
->type
== bp_shlib_event
7689 && b
->loc
->pspace
== current_program_space
)
7690 b
->disposition
= disp_del_at_next_stop
;
7693 /* Helper for create_solib_event_breakpoint /
7694 create_and_insert_solib_event_breakpoint. Allows specifying which
7695 INSERT_MODE to pass through to update_global_location_list. */
7697 static struct breakpoint
*
7698 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7699 enum ugll_insert_mode insert_mode
)
7701 struct breakpoint
*b
;
7703 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7704 &internal_breakpoint_ops
);
7705 update_global_location_list_nothrow (insert_mode
);
7710 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7712 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7715 /* See breakpoint.h. */
7718 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7720 struct breakpoint
*b
;
7722 /* Explicitly tell update_global_location_list to insert
7724 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7725 if (!b
->loc
->inserted
)
7727 delete_breakpoint (b
);
7733 /* Disable any breakpoints that are on code in shared libraries. Only
7734 apply to enabled breakpoints, disabled ones can just stay disabled. */
7737 disable_breakpoints_in_shlibs (void)
7739 struct bp_location
*loc
, **locp_tmp
;
7741 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7743 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7744 struct breakpoint
*b
= loc
->owner
;
7746 /* We apply the check to all breakpoints, including disabled for
7747 those with loc->duplicate set. This is so that when breakpoint
7748 becomes enabled, or the duplicate is removed, gdb will try to
7749 insert all breakpoints. If we don't set shlib_disabled here,
7750 we'll try to insert those breakpoints and fail. */
7751 if (((b
->type
== bp_breakpoint
)
7752 || (b
->type
== bp_jit_event
)
7753 || (b
->type
== bp_hardware_breakpoint
)
7754 || (is_tracepoint (b
)))
7755 && loc
->pspace
== current_program_space
7756 && !loc
->shlib_disabled
7757 && solib_name_from_address (loc
->pspace
, loc
->address
)
7760 loc
->shlib_disabled
= 1;
7765 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7766 notification of unloaded_shlib. Only apply to enabled breakpoints,
7767 disabled ones can just stay disabled. */
7770 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7772 struct bp_location
*loc
, **locp_tmp
;
7773 int disabled_shlib_breaks
= 0;
7775 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7777 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7778 struct breakpoint
*b
= loc
->owner
;
7780 if (solib
->pspace
== loc
->pspace
7781 && !loc
->shlib_disabled
7782 && (((b
->type
== bp_breakpoint
7783 || b
->type
== bp_jit_event
7784 || b
->type
== bp_hardware_breakpoint
)
7785 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7786 || loc
->loc_type
== bp_loc_software_breakpoint
))
7787 || is_tracepoint (b
))
7788 && solib_contains_address_p (solib
, loc
->address
))
7790 loc
->shlib_disabled
= 1;
7791 /* At this point, we cannot rely on remove_breakpoint
7792 succeeding so we must mark the breakpoint as not inserted
7793 to prevent future errors occurring in remove_breakpoints. */
7796 /* This may cause duplicate notifications for the same breakpoint. */
7797 observer_notify_breakpoint_modified (b
);
7799 if (!disabled_shlib_breaks
)
7801 target_terminal::ours_for_output ();
7802 warning (_("Temporarily disabling breakpoints "
7803 "for unloaded shared library \"%s\""),
7806 disabled_shlib_breaks
= 1;
7811 /* Disable any breakpoints and tracepoints in OBJFILE upon
7812 notification of free_objfile. Only apply to enabled breakpoints,
7813 disabled ones can just stay disabled. */
7816 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7818 struct breakpoint
*b
;
7820 if (objfile
== NULL
)
7823 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7824 managed by the user with add-symbol-file/remove-symbol-file.
7825 Similarly to how breakpoints in shared libraries are handled in
7826 response to "nosharedlibrary", mark breakpoints in such modules
7827 shlib_disabled so they end up uninserted on the next global
7828 location list update. Shared libraries not loaded by the user
7829 aren't handled here -- they're already handled in
7830 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7831 solib_unloaded observer. We skip objfiles that are not
7832 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7834 if ((objfile
->flags
& OBJF_SHARED
) == 0
7835 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7840 struct bp_location
*loc
;
7841 int bp_modified
= 0;
7843 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7846 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7848 CORE_ADDR loc_addr
= loc
->address
;
7850 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7851 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7854 if (loc
->shlib_disabled
!= 0)
7857 if (objfile
->pspace
!= loc
->pspace
)
7860 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7861 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7864 if (is_addr_in_objfile (loc_addr
, objfile
))
7866 loc
->shlib_disabled
= 1;
7867 /* At this point, we don't know whether the object was
7868 unmapped from the inferior or not, so leave the
7869 inserted flag alone. We'll handle failure to
7870 uninsert quietly, in case the object was indeed
7873 mark_breakpoint_location_modified (loc
);
7880 observer_notify_breakpoint_modified (b
);
7884 /* FORK & VFORK catchpoints. */
7886 /* An instance of this type is used to represent a fork or vfork
7887 catchpoint. A breakpoint is really of this type iff its ops pointer points
7888 to CATCH_FORK_BREAKPOINT_OPS. */
7890 struct fork_catchpoint
: public breakpoint
7892 /* Process id of a child process whose forking triggered this
7893 catchpoint. This field is only valid immediately after this
7894 catchpoint has triggered. */
7895 ptid_t forked_inferior_pid
;
7898 /* Implement the "insert" breakpoint_ops method for fork
7902 insert_catch_fork (struct bp_location
*bl
)
7904 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7907 /* Implement the "remove" breakpoint_ops method for fork
7911 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7913 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7916 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7920 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7921 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7922 const struct target_waitstatus
*ws
)
7924 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7926 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7929 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7933 /* Implement the "print_it" breakpoint_ops method for fork
7936 static enum print_stop_action
7937 print_it_catch_fork (bpstat bs
)
7939 struct ui_out
*uiout
= current_uiout
;
7940 struct breakpoint
*b
= bs
->breakpoint_at
;
7941 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7943 annotate_catchpoint (b
->number
);
7944 maybe_print_thread_hit_breakpoint (uiout
);
7945 if (b
->disposition
== disp_del
)
7946 uiout
->text ("Temporary catchpoint ");
7948 uiout
->text ("Catchpoint ");
7949 if (uiout
->is_mi_like_p ())
7951 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7952 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7954 uiout
->field_int ("bkptno", b
->number
);
7955 uiout
->text (" (forked process ");
7956 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7957 uiout
->text ("), ");
7958 return PRINT_SRC_AND_LOC
;
7961 /* Implement the "print_one" breakpoint_ops method for fork
7965 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7967 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7968 struct value_print_options opts
;
7969 struct ui_out
*uiout
= current_uiout
;
7971 get_user_print_options (&opts
);
7973 /* Field 4, the address, is omitted (which makes the columns not
7974 line up too nicely with the headers, but the effect is relatively
7976 if (opts
.addressprint
)
7977 uiout
->field_skip ("addr");
7979 uiout
->text ("fork");
7980 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7982 uiout
->text (", process ");
7983 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7987 if (uiout
->is_mi_like_p ())
7988 uiout
->field_string ("catch-type", "fork");
7991 /* Implement the "print_mention" breakpoint_ops method for fork
7995 print_mention_catch_fork (struct breakpoint
*b
)
7997 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8000 /* Implement the "print_recreate" breakpoint_ops method for fork
8004 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8006 fprintf_unfiltered (fp
, "catch fork");
8007 print_recreate_thread (b
, fp
);
8010 /* The breakpoint_ops structure to be used in fork catchpoints. */
8012 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8014 /* Implement the "insert" breakpoint_ops method for vfork
8018 insert_catch_vfork (struct bp_location
*bl
)
8020 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8023 /* Implement the "remove" breakpoint_ops method for vfork
8027 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8029 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8032 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8036 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8037 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8038 const struct target_waitstatus
*ws
)
8040 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8042 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8045 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8049 /* Implement the "print_it" breakpoint_ops method for vfork
8052 static enum print_stop_action
8053 print_it_catch_vfork (bpstat bs
)
8055 struct ui_out
*uiout
= current_uiout
;
8056 struct breakpoint
*b
= bs
->breakpoint_at
;
8057 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8059 annotate_catchpoint (b
->number
);
8060 maybe_print_thread_hit_breakpoint (uiout
);
8061 if (b
->disposition
== disp_del
)
8062 uiout
->text ("Temporary catchpoint ");
8064 uiout
->text ("Catchpoint ");
8065 if (uiout
->is_mi_like_p ())
8067 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8068 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8070 uiout
->field_int ("bkptno", b
->number
);
8071 uiout
->text (" (vforked process ");
8072 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8073 uiout
->text ("), ");
8074 return PRINT_SRC_AND_LOC
;
8077 /* Implement the "print_one" breakpoint_ops method for vfork
8081 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8083 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8084 struct value_print_options opts
;
8085 struct ui_out
*uiout
= current_uiout
;
8087 get_user_print_options (&opts
);
8088 /* Field 4, the address, is omitted (which makes the columns not
8089 line up too nicely with the headers, but the effect is relatively
8091 if (opts
.addressprint
)
8092 uiout
->field_skip ("addr");
8094 uiout
->text ("vfork");
8095 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8097 uiout
->text (", process ");
8098 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8102 if (uiout
->is_mi_like_p ())
8103 uiout
->field_string ("catch-type", "vfork");
8106 /* Implement the "print_mention" breakpoint_ops method for vfork
8110 print_mention_catch_vfork (struct breakpoint
*b
)
8112 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8115 /* Implement the "print_recreate" breakpoint_ops method for vfork
8119 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8121 fprintf_unfiltered (fp
, "catch vfork");
8122 print_recreate_thread (b
, fp
);
8125 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8127 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8129 /* An instance of this type is used to represent an solib catchpoint.
8130 A breakpoint is really of this type iff its ops pointer points to
8131 CATCH_SOLIB_BREAKPOINT_OPS. */
8133 struct solib_catchpoint
: public breakpoint
8135 ~solib_catchpoint () override
;
8137 /* True for "catch load", false for "catch unload". */
8138 unsigned char is_load
;
8140 /* Regular expression to match, if any. COMPILED is only valid when
8141 REGEX is non-NULL. */
8143 std::unique_ptr
<compiled_regex
> compiled
;
8146 solib_catchpoint::~solib_catchpoint ()
8148 xfree (this->regex
);
8152 insert_catch_solib (struct bp_location
*ignore
)
8158 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8164 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8165 struct address_space
*aspace
,
8167 const struct target_waitstatus
*ws
)
8169 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8170 struct breakpoint
*other
;
8172 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8175 ALL_BREAKPOINTS (other
)
8177 struct bp_location
*other_bl
;
8179 if (other
== bl
->owner
)
8182 if (other
->type
!= bp_shlib_event
)
8185 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8188 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8190 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8199 check_status_catch_solib (struct bpstats
*bs
)
8201 struct solib_catchpoint
*self
8202 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8207 struct so_list
*iter
;
8210 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8215 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8224 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8229 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8235 bs
->print_it
= print_it_noop
;
8238 static enum print_stop_action
8239 print_it_catch_solib (bpstat bs
)
8241 struct breakpoint
*b
= bs
->breakpoint_at
;
8242 struct ui_out
*uiout
= current_uiout
;
8244 annotate_catchpoint (b
->number
);
8245 maybe_print_thread_hit_breakpoint (uiout
);
8246 if (b
->disposition
== disp_del
)
8247 uiout
->text ("Temporary catchpoint ");
8249 uiout
->text ("Catchpoint ");
8250 uiout
->field_int ("bkptno", b
->number
);
8252 if (uiout
->is_mi_like_p ())
8253 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8254 print_solib_event (1);
8255 return PRINT_SRC_AND_LOC
;
8259 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8261 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8262 struct value_print_options opts
;
8263 struct ui_out
*uiout
= current_uiout
;
8266 get_user_print_options (&opts
);
8267 /* Field 4, the address, is omitted (which makes the columns not
8268 line up too nicely with the headers, but the effect is relatively
8270 if (opts
.addressprint
)
8273 uiout
->field_skip ("addr");
8280 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8282 msg
= xstrdup (_("load of library"));
8287 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8289 msg
= xstrdup (_("unload of library"));
8291 uiout
->field_string ("what", msg
);
8294 if (uiout
->is_mi_like_p ())
8295 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8299 print_mention_catch_solib (struct breakpoint
*b
)
8301 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8303 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8304 self
->is_load
? "load" : "unload");
8308 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8310 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8312 fprintf_unfiltered (fp
, "%s %s",
8313 b
->disposition
== disp_del
? "tcatch" : "catch",
8314 self
->is_load
? "load" : "unload");
8316 fprintf_unfiltered (fp
, " %s", self
->regex
);
8317 fprintf_unfiltered (fp
, "\n");
8320 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8322 /* Shared helper function (MI and CLI) for creating and installing
8323 a shared object event catchpoint. If IS_LOAD is non-zero then
8324 the events to be caught are load events, otherwise they are
8325 unload events. If IS_TEMP is non-zero the catchpoint is a
8326 temporary one. If ENABLED is non-zero the catchpoint is
8327 created in an enabled state. */
8330 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8332 struct gdbarch
*gdbarch
= get_current_arch ();
8336 arg
= skip_spaces (arg
);
8338 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8342 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8343 _("Invalid regexp")));
8344 c
->regex
= xstrdup (arg
);
8347 c
->is_load
= is_load
;
8348 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8349 &catch_solib_breakpoint_ops
);
8351 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8353 install_breakpoint (0, std::move (c
), 1);
8356 /* A helper function that does all the work for "catch load" and
8360 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8361 struct cmd_list_element
*command
)
8364 const int enabled
= 1;
8366 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8368 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8372 catch_load_command_1 (char *arg
, int from_tty
,
8373 struct cmd_list_element
*command
)
8375 catch_load_or_unload (arg
, from_tty
, 1, command
);
8379 catch_unload_command_1 (char *arg
, int from_tty
,
8380 struct cmd_list_element
*command
)
8382 catch_load_or_unload (arg
, from_tty
, 0, command
);
8385 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8386 is non-zero, then make the breakpoint temporary. If COND_STRING is
8387 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8388 the breakpoint_ops structure associated to the catchpoint. */
8391 init_catchpoint (struct breakpoint
*b
,
8392 struct gdbarch
*gdbarch
, int tempflag
,
8393 const char *cond_string
,
8394 const struct breakpoint_ops
*ops
)
8396 symtab_and_line sal
;
8397 sal
.pspace
= current_program_space
;
8399 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8401 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8402 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8406 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8408 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8409 set_breakpoint_number (internal
, b
);
8410 if (is_tracepoint (b
))
8411 set_tracepoint_count (breakpoint_count
);
8414 observer_notify_breakpoint_created (b
);
8417 update_global_location_list (UGLL_MAY_INSERT
);
8421 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8422 int tempflag
, const char *cond_string
,
8423 const struct breakpoint_ops
*ops
)
8425 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8427 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8429 c
->forked_inferior_pid
= null_ptid
;
8431 install_breakpoint (0, std::move (c
), 1);
8434 /* Exec catchpoints. */
8436 /* An instance of this type is used to represent an exec catchpoint.
8437 A breakpoint is really of this type iff its ops pointer points to
8438 CATCH_EXEC_BREAKPOINT_OPS. */
8440 struct exec_catchpoint
: public breakpoint
8442 ~exec_catchpoint () override
;
8444 /* Filename of a program whose exec triggered this catchpoint.
8445 This field is only valid immediately after this catchpoint has
8447 char *exec_pathname
;
8450 /* Exec catchpoint destructor. */
8452 exec_catchpoint::~exec_catchpoint ()
8454 xfree (this->exec_pathname
);
8458 insert_catch_exec (struct bp_location
*bl
)
8460 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8464 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8466 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8470 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8471 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8472 const struct target_waitstatus
*ws
)
8474 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8476 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8479 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8483 static enum print_stop_action
8484 print_it_catch_exec (bpstat bs
)
8486 struct ui_out
*uiout
= current_uiout
;
8487 struct breakpoint
*b
= bs
->breakpoint_at
;
8488 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8490 annotate_catchpoint (b
->number
);
8491 maybe_print_thread_hit_breakpoint (uiout
);
8492 if (b
->disposition
== disp_del
)
8493 uiout
->text ("Temporary catchpoint ");
8495 uiout
->text ("Catchpoint ");
8496 if (uiout
->is_mi_like_p ())
8498 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8499 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8501 uiout
->field_int ("bkptno", b
->number
);
8502 uiout
->text (" (exec'd ");
8503 uiout
->field_string ("new-exec", c
->exec_pathname
);
8504 uiout
->text ("), ");
8506 return PRINT_SRC_AND_LOC
;
8510 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8512 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8513 struct value_print_options opts
;
8514 struct ui_out
*uiout
= current_uiout
;
8516 get_user_print_options (&opts
);
8518 /* Field 4, the address, is omitted (which makes the columns
8519 not line up too nicely with the headers, but the effect
8520 is relatively readable). */
8521 if (opts
.addressprint
)
8522 uiout
->field_skip ("addr");
8524 uiout
->text ("exec");
8525 if (c
->exec_pathname
!= NULL
)
8527 uiout
->text (", program \"");
8528 uiout
->field_string ("what", c
->exec_pathname
);
8529 uiout
->text ("\" ");
8532 if (uiout
->is_mi_like_p ())
8533 uiout
->field_string ("catch-type", "exec");
8537 print_mention_catch_exec (struct breakpoint
*b
)
8539 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8542 /* Implement the "print_recreate" breakpoint_ops method for exec
8546 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8548 fprintf_unfiltered (fp
, "catch exec");
8549 print_recreate_thread (b
, fp
);
8552 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8555 hw_breakpoint_used_count (void)
8558 struct breakpoint
*b
;
8559 struct bp_location
*bl
;
8563 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8564 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8566 /* Special types of hardware breakpoints may use more than
8568 i
+= b
->ops
->resources_needed (bl
);
8575 /* Returns the resources B would use if it were a hardware
8579 hw_watchpoint_use_count (struct breakpoint
*b
)
8582 struct bp_location
*bl
;
8584 if (!breakpoint_enabled (b
))
8587 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8589 /* Special types of hardware watchpoints may use more than
8591 i
+= b
->ops
->resources_needed (bl
);
8597 /* Returns the sum the used resources of all hardware watchpoints of
8598 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8599 the sum of the used resources of all hardware watchpoints of other
8600 types _not_ TYPE. */
8603 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8604 enum bptype type
, int *other_type_used
)
8607 struct breakpoint
*b
;
8609 *other_type_used
= 0;
8614 if (!breakpoint_enabled (b
))
8617 if (b
->type
== type
)
8618 i
+= hw_watchpoint_use_count (b
);
8619 else if (is_hardware_watchpoint (b
))
8620 *other_type_used
= 1;
8627 disable_watchpoints_before_interactive_call_start (void)
8629 struct breakpoint
*b
;
8633 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8635 b
->enable_state
= bp_call_disabled
;
8636 update_global_location_list (UGLL_DONT_INSERT
);
8642 enable_watchpoints_after_interactive_call_stop (void)
8644 struct breakpoint
*b
;
8648 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8650 b
->enable_state
= bp_enabled
;
8651 update_global_location_list (UGLL_MAY_INSERT
);
8657 disable_breakpoints_before_startup (void)
8659 current_program_space
->executing_startup
= 1;
8660 update_global_location_list (UGLL_DONT_INSERT
);
8664 enable_breakpoints_after_startup (void)
8666 current_program_space
->executing_startup
= 0;
8667 breakpoint_re_set ();
8670 /* Create a new single-step breakpoint for thread THREAD, with no
8673 static struct breakpoint
*
8674 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8676 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8678 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8679 &momentary_breakpoint_ops
);
8681 b
->disposition
= disp_donttouch
;
8682 b
->frame_id
= null_frame_id
;
8685 gdb_assert (b
->thread
!= 0);
8687 return add_to_breakpoint_chain (std::move (b
));
8690 /* Set a momentary breakpoint of type TYPE at address specified by
8691 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8695 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8696 struct frame_id frame_id
, enum bptype type
)
8698 struct breakpoint
*b
;
8700 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8702 gdb_assert (!frame_id_artificial_p (frame_id
));
8704 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8705 b
->enable_state
= bp_enabled
;
8706 b
->disposition
= disp_donttouch
;
8707 b
->frame_id
= frame_id
;
8709 /* If we're debugging a multi-threaded program, then we want
8710 momentary breakpoints to be active in only a single thread of
8712 if (in_thread_list (inferior_ptid
))
8713 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8715 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8720 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8721 The new breakpoint will have type TYPE, use OPS as its
8722 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8724 static struct breakpoint
*
8725 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8727 const struct breakpoint_ops
*ops
,
8730 struct breakpoint
*copy
;
8732 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8733 copy
->loc
= allocate_bp_location (copy
);
8734 set_breakpoint_location_function (copy
->loc
, 1);
8736 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8737 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8738 copy
->loc
->address
= orig
->loc
->address
;
8739 copy
->loc
->section
= orig
->loc
->section
;
8740 copy
->loc
->pspace
= orig
->loc
->pspace
;
8741 copy
->loc
->probe
= orig
->loc
->probe
;
8742 copy
->loc
->line_number
= orig
->loc
->line_number
;
8743 copy
->loc
->symtab
= orig
->loc
->symtab
;
8744 copy
->loc
->enabled
= loc_enabled
;
8745 copy
->frame_id
= orig
->frame_id
;
8746 copy
->thread
= orig
->thread
;
8747 copy
->pspace
= orig
->pspace
;
8749 copy
->enable_state
= bp_enabled
;
8750 copy
->disposition
= disp_donttouch
;
8751 copy
->number
= internal_breakpoint_number
--;
8753 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8757 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8761 clone_momentary_breakpoint (struct breakpoint
*orig
)
8763 /* If there's nothing to clone, then return nothing. */
8767 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8771 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8774 struct symtab_and_line sal
;
8776 sal
= find_pc_line (pc
, 0);
8778 sal
.section
= find_pc_overlay (pc
);
8779 sal
.explicit_pc
= 1;
8781 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8785 /* Tell the user we have just set a breakpoint B. */
8788 mention (struct breakpoint
*b
)
8790 b
->ops
->print_mention (b
);
8791 if (current_uiout
->is_mi_like_p ())
8793 printf_filtered ("\n");
8797 static int bp_loc_is_permanent (struct bp_location
*loc
);
8799 static struct bp_location
*
8800 add_location_to_breakpoint (struct breakpoint
*b
,
8801 const struct symtab_and_line
*sal
)
8803 struct bp_location
*loc
, **tmp
;
8804 CORE_ADDR adjusted_address
;
8805 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8807 if (loc_gdbarch
== NULL
)
8808 loc_gdbarch
= b
->gdbarch
;
8810 /* Adjust the breakpoint's address prior to allocating a location.
8811 Once we call allocate_bp_location(), that mostly uninitialized
8812 location will be placed on the location chain. Adjustment of the
8813 breakpoint may cause target_read_memory() to be called and we do
8814 not want its scan of the location chain to find a breakpoint and
8815 location that's only been partially initialized. */
8816 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8819 /* Sort the locations by their ADDRESS. */
8820 loc
= allocate_bp_location (b
);
8821 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8822 tmp
= &((*tmp
)->next
))
8827 loc
->requested_address
= sal
->pc
;
8828 loc
->address
= adjusted_address
;
8829 loc
->pspace
= sal
->pspace
;
8830 loc
->probe
.probe
= sal
->probe
;
8831 loc
->probe
.objfile
= sal
->objfile
;
8832 gdb_assert (loc
->pspace
!= NULL
);
8833 loc
->section
= sal
->section
;
8834 loc
->gdbarch
= loc_gdbarch
;
8835 loc
->line_number
= sal
->line
;
8836 loc
->symtab
= sal
->symtab
;
8838 set_breakpoint_location_function (loc
,
8839 sal
->explicit_pc
|| sal
->explicit_line
);
8841 /* While by definition, permanent breakpoints are already present in the
8842 code, we don't mark the location as inserted. Normally one would expect
8843 that GDB could rely on that breakpoint instruction to stop the program,
8844 thus removing the need to insert its own breakpoint, except that executing
8845 the breakpoint instruction can kill the target instead of reporting a
8846 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8847 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8848 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8849 breakpoint be inserted normally results in QEMU knowing about the GDB
8850 breakpoint, and thus trap before the breakpoint instruction is executed.
8851 (If GDB later needs to continue execution past the permanent breakpoint,
8852 it manually increments the PC, thus avoiding executing the breakpoint
8854 if (bp_loc_is_permanent (loc
))
8861 /* See breakpoint.h. */
8864 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8868 const gdb_byte
*bpoint
;
8869 gdb_byte
*target_mem
;
8872 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8874 /* Software breakpoints unsupported? */
8878 target_mem
= (gdb_byte
*) alloca (len
);
8880 /* Enable the automatic memory restoration from breakpoints while
8881 we read the memory. Otherwise we could say about our temporary
8882 breakpoints they are permanent. */
8883 scoped_restore restore_memory
8884 = make_scoped_restore_show_memory_breakpoints (0);
8886 if (target_read_memory (address
, target_mem
, len
) == 0
8887 && memcmp (target_mem
, bpoint
, len
) == 0)
8893 /* Return 1 if LOC is pointing to a permanent breakpoint,
8894 return 0 otherwise. */
8897 bp_loc_is_permanent (struct bp_location
*loc
)
8899 gdb_assert (loc
!= NULL
);
8901 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8902 attempt to read from the addresses the locations of these breakpoint types
8903 point to. program_breakpoint_here_p, below, will attempt to read
8905 if (!breakpoint_address_is_meaningful (loc
->owner
))
8908 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8909 switch_to_program_space_and_thread (loc
->pspace
);
8910 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8913 /* Build a command list for the dprintf corresponding to the current
8914 settings of the dprintf style options. */
8917 update_dprintf_command_list (struct breakpoint
*b
)
8919 char *dprintf_args
= b
->extra_string
;
8920 char *printf_line
= NULL
;
8925 dprintf_args
= skip_spaces (dprintf_args
);
8927 /* Allow a comma, as it may have terminated a location, but don't
8929 if (*dprintf_args
== ',')
8931 dprintf_args
= skip_spaces (dprintf_args
);
8933 if (*dprintf_args
!= '"')
8934 error (_("Bad format string, missing '\"'."));
8936 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8937 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8938 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8940 if (!dprintf_function
)
8941 error (_("No function supplied for dprintf call"));
8943 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8944 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8949 printf_line
= xstrprintf ("call (void) %s (%s)",
8953 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8955 if (target_can_run_breakpoint_commands ())
8956 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8959 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8960 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8964 internal_error (__FILE__
, __LINE__
,
8965 _("Invalid dprintf style."));
8967 gdb_assert (printf_line
!= NULL
);
8968 /* Manufacture a printf sequence. */
8970 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8972 printf_cmd_line
->control_type
= simple_control
;
8973 printf_cmd_line
->body_count
= 0;
8974 printf_cmd_line
->body_list
= NULL
;
8975 printf_cmd_line
->next
= NULL
;
8976 printf_cmd_line
->line
= printf_line
;
8978 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8982 /* Update all dprintf commands, making their command lists reflect
8983 current style settings. */
8986 update_dprintf_commands (char *args
, int from_tty
,
8987 struct cmd_list_element
*c
)
8989 struct breakpoint
*b
;
8993 if (b
->type
== bp_dprintf
)
8994 update_dprintf_command_list (b
);
8998 /* Create a breakpoint with SAL as location. Use LOCATION
8999 as a description of the location, and COND_STRING
9000 as condition expression. If LOCATION is NULL then create an
9001 "address location" from the address in the SAL. */
9004 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9005 gdb::array_view
<const symtab_and_line
> sals
,
9006 event_location_up
&&location
,
9007 gdb::unique_xmalloc_ptr
<char> filter
,
9008 gdb::unique_xmalloc_ptr
<char> cond_string
,
9009 gdb::unique_xmalloc_ptr
<char> extra_string
,
9010 enum bptype type
, enum bpdisp disposition
,
9011 int thread
, int task
, int ignore_count
,
9012 const struct breakpoint_ops
*ops
, int from_tty
,
9013 int enabled
, int internal
, unsigned flags
,
9014 int display_canonical
)
9018 if (type
== bp_hardware_breakpoint
)
9020 int target_resources_ok
;
9022 i
= hw_breakpoint_used_count ();
9023 target_resources_ok
=
9024 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9026 if (target_resources_ok
== 0)
9027 error (_("No hardware breakpoint support in the target."));
9028 else if (target_resources_ok
< 0)
9029 error (_("Hardware breakpoints used exceeds limit."));
9032 gdb_assert (!sals
.empty ());
9034 for (const auto &sal
: sals
)
9036 struct bp_location
*loc
;
9040 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9042 loc_gdbarch
= gdbarch
;
9044 describe_other_breakpoints (loc_gdbarch
,
9045 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9048 if (&sal
== &sals
[0])
9050 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9054 b
->cond_string
= cond_string
.release ();
9055 b
->extra_string
= extra_string
.release ();
9056 b
->ignore_count
= ignore_count
;
9057 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9058 b
->disposition
= disposition
;
9060 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9061 b
->loc
->inserted
= 1;
9063 if (type
== bp_static_tracepoint
)
9065 struct tracepoint
*t
= (struct tracepoint
*) b
;
9066 struct static_tracepoint_marker marker
;
9068 if (strace_marker_p (b
))
9070 /* We already know the marker exists, otherwise, we
9071 wouldn't see a sal for it. */
9073 = &event_location_to_string (b
->location
.get ())[3];
9077 p
= skip_spaces (p
);
9079 endp
= skip_to_space (p
);
9081 marker_str
= savestring (p
, endp
- p
);
9082 t
->static_trace_marker_id
= marker_str
;
9084 printf_filtered (_("Probed static tracepoint "
9086 t
->static_trace_marker_id
);
9088 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9090 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9091 release_static_tracepoint_marker (&marker
);
9093 printf_filtered (_("Probed static tracepoint "
9095 t
->static_trace_marker_id
);
9098 warning (_("Couldn't determine the static "
9099 "tracepoint marker to probe"));
9106 loc
= add_location_to_breakpoint (b
, &sal
);
9107 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9113 const char *arg
= b
->cond_string
;
9115 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9116 block_for_pc (loc
->address
), 0);
9118 error (_("Garbage '%s' follows condition"), arg
);
9121 /* Dynamic printf requires and uses additional arguments on the
9122 command line, otherwise it's an error. */
9123 if (type
== bp_dprintf
)
9125 if (b
->extra_string
)
9126 update_dprintf_command_list (b
);
9128 error (_("Format string required"));
9130 else if (b
->extra_string
)
9131 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9134 b
->display_canonical
= display_canonical
;
9135 if (location
!= NULL
)
9136 b
->location
= std::move (location
);
9138 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9139 b
->filter
= filter
.release ();
9143 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9144 gdb::array_view
<const symtab_and_line
> sals
,
9145 event_location_up
&&location
,
9146 gdb::unique_xmalloc_ptr
<char> filter
,
9147 gdb::unique_xmalloc_ptr
<char> cond_string
,
9148 gdb::unique_xmalloc_ptr
<char> extra_string
,
9149 enum bptype type
, enum bpdisp disposition
,
9150 int thread
, int task
, int ignore_count
,
9151 const struct breakpoint_ops
*ops
, int from_tty
,
9152 int enabled
, int internal
, unsigned flags
,
9153 int display_canonical
)
9155 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9157 init_breakpoint_sal (b
.get (), gdbarch
,
9158 sals
, std::move (location
),
9160 std::move (cond_string
),
9161 std::move (extra_string
),
9163 thread
, task
, ignore_count
,
9165 enabled
, internal
, flags
,
9168 install_breakpoint (internal
, std::move (b
), 0);
9171 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9172 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9173 value. COND_STRING, if not NULL, specified the condition to be
9174 used for all breakpoints. Essentially the only case where
9175 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9176 function. In that case, it's still not possible to specify
9177 separate conditions for different overloaded functions, so
9178 we take just a single condition string.
9180 NOTE: If the function succeeds, the caller is expected to cleanup
9181 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9182 array contents). If the function fails (error() is called), the
9183 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9184 COND and SALS arrays and each of those arrays contents. */
9187 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9188 struct linespec_result
*canonical
,
9189 gdb::unique_xmalloc_ptr
<char> cond_string
,
9190 gdb::unique_xmalloc_ptr
<char> extra_string
,
9191 enum bptype type
, enum bpdisp disposition
,
9192 int thread
, int task
, int ignore_count
,
9193 const struct breakpoint_ops
*ops
, int from_tty
,
9194 int enabled
, int internal
, unsigned flags
)
9196 if (canonical
->pre_expanded
)
9197 gdb_assert (canonical
->lsals
.size () == 1);
9199 for (const auto &lsal
: canonical
->lsals
)
9201 /* Note that 'location' can be NULL in the case of a plain
9202 'break', without arguments. */
9203 event_location_up location
9204 = (canonical
->location
!= NULL
9205 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9206 gdb::unique_xmalloc_ptr
<char> filter_string
9207 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9209 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9210 std::move (location
),
9211 std::move (filter_string
),
9212 std::move (cond_string
),
9213 std::move (extra_string
),
9215 thread
, task
, ignore_count
, ops
,
9216 from_tty
, enabled
, internal
, flags
,
9217 canonical
->special_display
);
9221 /* Parse LOCATION which is assumed to be a SAL specification possibly
9222 followed by conditionals. On return, SALS contains an array of SAL
9223 addresses found. LOCATION points to the end of the SAL (for
9224 linespec locations).
9226 The array and the line spec strings are allocated on the heap, it is
9227 the caller's responsibility to free them. */
9230 parse_breakpoint_sals (const struct event_location
*location
,
9231 struct linespec_result
*canonical
)
9233 struct symtab_and_line cursal
;
9235 if (event_location_type (location
) == LINESPEC_LOCATION
)
9237 const char *address
= get_linespec_location (location
);
9239 if (address
== NULL
)
9241 /* The last displayed codepoint, if it's valid, is our default
9242 breakpoint address. */
9243 if (last_displayed_sal_is_valid ())
9245 /* Set sal's pspace, pc, symtab, and line to the values
9246 corresponding to the last call to print_frame_info.
9247 Be sure to reinitialize LINE with NOTCURRENT == 0
9248 as the breakpoint line number is inappropriate otherwise.
9249 find_pc_line would adjust PC, re-set it back. */
9250 symtab_and_line sal
= get_last_displayed_sal ();
9251 CORE_ADDR pc
= sal
.pc
;
9253 sal
= find_pc_line (pc
, 0);
9255 /* "break" without arguments is equivalent to "break *PC"
9256 where PC is the last displayed codepoint's address. So
9257 make sure to set sal.explicit_pc to prevent GDB from
9258 trying to expand the list of sals to include all other
9259 instances with the same symtab and line. */
9261 sal
.explicit_pc
= 1;
9263 struct linespec_sals lsal
;
9265 lsal
.canonical
= NULL
;
9267 canonical
->lsals
.push_back (std::move (lsal
));
9271 error (_("No default breakpoint address now."));
9275 /* Force almost all breakpoints to be in terms of the
9276 current_source_symtab (which is decode_line_1's default).
9277 This should produce the results we want almost all of the
9278 time while leaving default_breakpoint_* alone.
9280 ObjC: However, don't match an Objective-C method name which
9281 may have a '+' or '-' succeeded by a '['. */
9282 cursal
= get_current_source_symtab_and_line ();
9283 if (last_displayed_sal_is_valid ())
9285 const char *address
= NULL
;
9287 if (event_location_type (location
) == LINESPEC_LOCATION
)
9288 address
= get_linespec_location (location
);
9292 && strchr ("+-", address
[0]) != NULL
9293 && address
[1] != '['))
9295 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9296 get_last_displayed_symtab (),
9297 get_last_displayed_line (),
9298 canonical
, NULL
, NULL
);
9303 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9304 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9308 /* Convert each SAL into a real PC. Verify that the PC can be
9309 inserted as a breakpoint. If it can't throw an error. */
9312 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9314 for (auto &sal
: sals
)
9315 resolve_sal_pc (&sal
);
9318 /* Fast tracepoints may have restrictions on valid locations. For
9319 instance, a fast tracepoint using a jump instead of a trap will
9320 likely have to overwrite more bytes than a trap would, and so can
9321 only be placed where the instruction is longer than the jump, or a
9322 multi-instruction sequence does not have a jump into the middle of
9326 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9327 gdb::array_view
<const symtab_and_line
> sals
)
9331 struct cleanup
*old_chain
;
9333 for (const auto &sal
: sals
)
9335 struct gdbarch
*sarch
;
9337 sarch
= get_sal_arch (sal
);
9338 /* We fall back to GDBARCH if there is no architecture
9339 associated with SAL. */
9342 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9343 old_chain
= make_cleanup (xfree
, msg
);
9346 error (_("May not have a fast tracepoint at %s%s"),
9347 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9349 do_cleanups (old_chain
);
9353 /* Given TOK, a string specification of condition and thread, as
9354 accepted by the 'break' command, extract the condition
9355 string and thread number and set *COND_STRING and *THREAD.
9356 PC identifies the context at which the condition should be parsed.
9357 If no condition is found, *COND_STRING is set to NULL.
9358 If no thread is found, *THREAD is set to -1. */
9361 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9362 char **cond_string
, int *thread
, int *task
,
9365 *cond_string
= NULL
;
9372 const char *end_tok
;
9374 const char *cond_start
= NULL
;
9375 const char *cond_end
= NULL
;
9377 tok
= skip_spaces (tok
);
9379 if ((*tok
== '"' || *tok
== ',') && rest
)
9381 *rest
= savestring (tok
, strlen (tok
));
9385 end_tok
= skip_to_space (tok
);
9387 toklen
= end_tok
- tok
;
9389 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9391 tok
= cond_start
= end_tok
+ 1;
9392 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9394 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9396 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9399 struct thread_info
*thr
;
9402 thr
= parse_thread_id (tok
, &tmptok
);
9404 error (_("Junk after thread keyword."));
9405 *thread
= thr
->global_num
;
9408 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9413 *task
= strtol (tok
, &tmptok
, 0);
9415 error (_("Junk after task keyword."));
9416 if (!valid_task_id (*task
))
9417 error (_("Unknown task %d."), *task
);
9422 *rest
= savestring (tok
, strlen (tok
));
9426 error (_("Junk at end of arguments."));
9430 /* Decode a static tracepoint marker spec. */
9432 static std::vector
<symtab_and_line
>
9433 decode_static_tracepoint_spec (const char **arg_p
)
9435 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9436 struct cleanup
*old_chain
;
9437 const char *p
= &(*arg_p
)[3];
9442 p
= skip_spaces (p
);
9444 endp
= skip_to_space (p
);
9446 marker_str
= savestring (p
, endp
- p
);
9447 old_chain
= make_cleanup (xfree
, marker_str
);
9449 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9450 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9451 error (_("No known static tracepoint marker named %s"), marker_str
);
9453 std::vector
<symtab_and_line
> sals
;
9454 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9456 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9458 struct static_tracepoint_marker
*marker
;
9460 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9462 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9463 sal
.pc
= marker
->address
;
9464 sals
.push_back (sal
);
9466 release_static_tracepoint_marker (marker
);
9469 do_cleanups (old_chain
);
9475 /* See breakpoint.h. */
9478 create_breakpoint (struct gdbarch
*gdbarch
,
9479 const struct event_location
*location
,
9480 const char *cond_string
,
9481 int thread
, const char *extra_string
,
9483 int tempflag
, enum bptype type_wanted
,
9485 enum auto_boolean pending_break_support
,
9486 const struct breakpoint_ops
*ops
,
9487 int from_tty
, int enabled
, int internal
,
9490 struct linespec_result canonical
;
9491 struct cleanup
*bkpt_chain
= NULL
;
9494 int prev_bkpt_count
= breakpoint_count
;
9496 gdb_assert (ops
!= NULL
);
9498 /* If extra_string isn't useful, set it to NULL. */
9499 if (extra_string
!= NULL
&& *extra_string
== '\0')
9500 extra_string
= NULL
;
9504 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9506 CATCH (e
, RETURN_MASK_ERROR
)
9508 /* If caller is interested in rc value from parse, set
9510 if (e
.error
== NOT_FOUND_ERROR
)
9512 /* If pending breakpoint support is turned off, throw
9515 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9516 throw_exception (e
);
9518 exception_print (gdb_stderr
, e
);
9520 /* If pending breakpoint support is auto query and the user
9521 selects no, then simply return the error code. */
9522 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9523 && !nquery (_("Make %s pending on future shared library load? "),
9524 bptype_string (type_wanted
)))
9527 /* At this point, either the user was queried about setting
9528 a pending breakpoint and selected yes, or pending
9529 breakpoint behavior is on and thus a pending breakpoint
9530 is defaulted on behalf of the user. */
9534 throw_exception (e
);
9538 if (!pending
&& canonical
.lsals
.empty ())
9541 /* ----------------------------- SNIP -----------------------------
9542 Anything added to the cleanup chain beyond this point is assumed
9543 to be part of a breakpoint. If the breakpoint create succeeds
9544 then the memory is not reclaimed. */
9545 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9547 /* Resolve all line numbers to PC's and verify that the addresses
9548 are ok for the target. */
9551 for (auto &lsal
: canonical
.lsals
)
9552 breakpoint_sals_to_pc (lsal
.sals
);
9555 /* Fast tracepoints may have additional restrictions on location. */
9556 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9558 for (const auto &lsal
: canonical
.lsals
)
9559 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9562 /* Verify that condition can be parsed, before setting any
9563 breakpoints. Allocate a separate condition expression for each
9567 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9568 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9575 const linespec_sals
&lsal
= canonical
.lsals
[0];
9577 /* Here we only parse 'arg' to separate condition
9578 from thread number, so parsing in context of first
9579 sal is OK. When setting the breakpoint we'll
9580 re-parse it in context of each sal. */
9582 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9583 &cond
, &thread
, &task
, &rest
);
9584 cond_string_copy
.reset (cond
);
9585 extra_string_copy
.reset (rest
);
9589 if (type_wanted
!= bp_dprintf
9590 && extra_string
!= NULL
&& *extra_string
!= '\0')
9591 error (_("Garbage '%s' at end of location"), extra_string
);
9593 /* Create a private copy of condition string. */
9595 cond_string_copy
.reset (xstrdup (cond_string
));
9596 /* Create a private copy of any extra string. */
9598 extra_string_copy
.reset (xstrdup (extra_string
));
9601 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9602 std::move (cond_string_copy
),
9603 std::move (extra_string_copy
),
9605 tempflag
? disp_del
: disp_donttouch
,
9606 thread
, task
, ignore_count
, ops
,
9607 from_tty
, enabled
, internal
, flags
);
9611 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9613 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9614 b
->location
= copy_event_location (location
);
9617 b
->cond_string
= NULL
;
9620 /* Create a private copy of condition string. */
9621 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9625 /* Create a private copy of any extra string. */
9626 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9627 b
->ignore_count
= ignore_count
;
9628 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9629 b
->condition_not_parsed
= 1;
9630 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9631 if ((type_wanted
!= bp_breakpoint
9632 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9633 b
->pspace
= current_program_space
;
9635 install_breakpoint (internal
, std::move (b
), 0);
9638 if (canonical
.lsals
.size () > 1)
9640 warning (_("Multiple breakpoints were set.\nUse the "
9641 "\"delete\" command to delete unwanted breakpoints."));
9642 prev_breakpoint_count
= prev_bkpt_count
;
9645 /* That's it. Discard the cleanups for data inserted into the
9647 discard_cleanups (bkpt_chain
);
9649 /* error call may happen here - have BKPT_CHAIN already discarded. */
9650 update_global_location_list (UGLL_MAY_INSERT
);
9655 /* Set a breakpoint.
9656 ARG is a string describing breakpoint address,
9657 condition, and thread.
9658 FLAG specifies if a breakpoint is hardware on,
9659 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9663 break_command_1 (const char *arg
, int flag
, int from_tty
)
9665 int tempflag
= flag
& BP_TEMPFLAG
;
9666 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9667 ? bp_hardware_breakpoint
9669 struct breakpoint_ops
*ops
;
9671 event_location_up location
= string_to_event_location (&arg
, current_language
);
9673 /* Matching breakpoints on probes. */
9674 if (location
!= NULL
9675 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9676 ops
= &bkpt_probe_breakpoint_ops
;
9678 ops
= &bkpt_breakpoint_ops
;
9680 create_breakpoint (get_current_arch (),
9682 NULL
, 0, arg
, 1 /* parse arg */,
9683 tempflag
, type_wanted
,
9684 0 /* Ignore count */,
9685 pending_break_support
,
9693 /* Helper function for break_command_1 and disassemble_command. */
9696 resolve_sal_pc (struct symtab_and_line
*sal
)
9700 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9702 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9703 error (_("No line %d in file \"%s\"."),
9704 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9707 /* If this SAL corresponds to a breakpoint inserted using a line
9708 number, then skip the function prologue if necessary. */
9709 if (sal
->explicit_line
)
9710 skip_prologue_sal (sal
);
9713 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9715 const struct blockvector
*bv
;
9716 const struct block
*b
;
9719 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9720 SYMTAB_COMPUNIT (sal
->symtab
));
9723 sym
= block_linkage_function (b
);
9726 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9727 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9732 /* It really is worthwhile to have the section, so we'll
9733 just have to look harder. This case can be executed
9734 if we have line numbers but no functions (as can
9735 happen in assembly source). */
9737 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9738 switch_to_program_space_and_thread (sal
->pspace
);
9740 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9742 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9749 break_command (char *arg
, int from_tty
)
9751 break_command_1 (arg
, 0, from_tty
);
9755 tbreak_command (char *arg
, int from_tty
)
9757 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9761 hbreak_command (char *arg
, int from_tty
)
9763 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9767 thbreak_command (char *arg
, int from_tty
)
9769 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9773 stop_command (char *arg
, int from_tty
)
9775 printf_filtered (_("Specify the type of breakpoint to set.\n\
9776 Usage: stop in <function | address>\n\
9777 stop at <line>\n"));
9781 stopin_command (const char *arg
, int from_tty
)
9785 if (arg
== (char *) NULL
)
9787 else if (*arg
!= '*')
9789 const char *argptr
= arg
;
9792 /* Look for a ':'. If this is a line number specification, then
9793 say it is bad, otherwise, it should be an address or
9794 function/method name. */
9795 while (*argptr
&& !hasColon
)
9797 hasColon
= (*argptr
== ':');
9802 badInput
= (*argptr
!= ':'); /* Not a class::method */
9804 badInput
= isdigit (*arg
); /* a simple line number */
9808 printf_filtered (_("Usage: stop in <function | address>\n"));
9810 break_command_1 (arg
, 0, from_tty
);
9814 stopat_command (const char *arg
, int from_tty
)
9818 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9822 const char *argptr
= arg
;
9825 /* Look for a ':'. If there is a '::' then get out, otherwise
9826 it is probably a line number. */
9827 while (*argptr
&& !hasColon
)
9829 hasColon
= (*argptr
== ':');
9834 badInput
= (*argptr
== ':'); /* we have class::method */
9836 badInput
= !isdigit (*arg
); /* not a line number */
9840 printf_filtered (_("Usage: stop at <line>\n"));
9842 break_command_1 (arg
, 0, from_tty
);
9845 /* The dynamic printf command is mostly like a regular breakpoint, but
9846 with a prewired command list consisting of a single output command,
9847 built from extra arguments supplied on the dprintf command
9851 dprintf_command (char *arg_in
, int from_tty
)
9853 const char *arg
= arg_in
;
9854 event_location_up location
= string_to_event_location (&arg
, current_language
);
9856 /* If non-NULL, ARG should have been advanced past the location;
9857 the next character must be ','. */
9860 if (arg
[0] != ',' || arg
[1] == '\0')
9861 error (_("Format string required"));
9864 /* Skip the comma. */
9869 create_breakpoint (get_current_arch (),
9871 NULL
, 0, arg
, 1 /* parse arg */,
9873 0 /* Ignore count */,
9874 pending_break_support
,
9875 &dprintf_breakpoint_ops
,
9883 agent_printf_command (char *arg
, int from_tty
)
9885 error (_("May only run agent-printf on the target"));
9888 /* Implement the "breakpoint_hit" breakpoint_ops method for
9889 ranged breakpoints. */
9892 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9893 struct address_space
*aspace
,
9895 const struct target_waitstatus
*ws
)
9897 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9898 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9901 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9902 bl
->length
, aspace
, bp_addr
);
9905 /* Implement the "resources_needed" breakpoint_ops method for
9906 ranged breakpoints. */
9909 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9911 return target_ranged_break_num_registers ();
9914 /* Implement the "print_it" breakpoint_ops method for
9915 ranged breakpoints. */
9917 static enum print_stop_action
9918 print_it_ranged_breakpoint (bpstat bs
)
9920 struct breakpoint
*b
= bs
->breakpoint_at
;
9921 struct bp_location
*bl
= b
->loc
;
9922 struct ui_out
*uiout
= current_uiout
;
9924 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9926 /* Ranged breakpoints have only one location. */
9927 gdb_assert (bl
&& bl
->next
== NULL
);
9929 annotate_breakpoint (b
->number
);
9931 maybe_print_thread_hit_breakpoint (uiout
);
9933 if (b
->disposition
== disp_del
)
9934 uiout
->text ("Temporary ranged breakpoint ");
9936 uiout
->text ("Ranged breakpoint ");
9937 if (uiout
->is_mi_like_p ())
9939 uiout
->field_string ("reason",
9940 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9941 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9943 uiout
->field_int ("bkptno", b
->number
);
9946 return PRINT_SRC_AND_LOC
;
9949 /* Implement the "print_one" breakpoint_ops method for
9950 ranged breakpoints. */
9953 print_one_ranged_breakpoint (struct breakpoint
*b
,
9954 struct bp_location
**last_loc
)
9956 struct bp_location
*bl
= b
->loc
;
9957 struct value_print_options opts
;
9958 struct ui_out
*uiout
= current_uiout
;
9960 /* Ranged breakpoints have only one location. */
9961 gdb_assert (bl
&& bl
->next
== NULL
);
9963 get_user_print_options (&opts
);
9965 if (opts
.addressprint
)
9966 /* We don't print the address range here, it will be printed later
9967 by print_one_detail_ranged_breakpoint. */
9968 uiout
->field_skip ("addr");
9970 print_breakpoint_location (b
, bl
);
9974 /* Implement the "print_one_detail" breakpoint_ops method for
9975 ranged breakpoints. */
9978 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9979 struct ui_out
*uiout
)
9981 CORE_ADDR address_start
, address_end
;
9982 struct bp_location
*bl
= b
->loc
;
9987 address_start
= bl
->address
;
9988 address_end
= address_start
+ bl
->length
- 1;
9990 uiout
->text ("\taddress range: ");
9991 stb
.printf ("[%s, %s]",
9992 print_core_address (bl
->gdbarch
, address_start
),
9993 print_core_address (bl
->gdbarch
, address_end
));
9994 uiout
->field_stream ("addr", stb
);
9998 /* Implement the "print_mention" breakpoint_ops method for
9999 ranged breakpoints. */
10002 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10004 struct bp_location
*bl
= b
->loc
;
10005 struct ui_out
*uiout
= current_uiout
;
10008 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10010 if (uiout
->is_mi_like_p ())
10013 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10014 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10015 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10018 /* Implement the "print_recreate" breakpoint_ops method for
10019 ranged breakpoints. */
10022 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10024 fprintf_unfiltered (fp
, "break-range %s, %s",
10025 event_location_to_string (b
->location
.get ()),
10026 event_location_to_string (b
->location_range_end
.get ()));
10027 print_recreate_thread (b
, fp
);
10030 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10032 static struct breakpoint_ops ranged_breakpoint_ops
;
10034 /* Find the address where the end of the breakpoint range should be
10035 placed, given the SAL of the end of the range. This is so that if
10036 the user provides a line number, the end of the range is set to the
10037 last instruction of the given line. */
10040 find_breakpoint_range_end (struct symtab_and_line sal
)
10044 /* If the user provided a PC value, use it. Otherwise,
10045 find the address of the end of the given location. */
10046 if (sal
.explicit_pc
)
10053 ret
= find_line_pc_range (sal
, &start
, &end
);
10055 error (_("Could not find location of the end of the range."));
10057 /* find_line_pc_range returns the start of the next line. */
10064 /* Implement the "break-range" CLI command. */
10067 break_range_command (char *arg_in
, int from_tty
)
10069 const char *arg
= arg_in
;
10070 const char *arg_start
;
10071 char *addr_string_start
;
10072 struct linespec_result canonical_start
, canonical_end
;
10073 int bp_count
, can_use_bp
, length
;
10075 struct breakpoint
*b
;
10076 struct cleanup
*cleanup_bkpt
;
10078 /* We don't support software ranged breakpoints. */
10079 if (target_ranged_break_num_registers () < 0)
10080 error (_("This target does not support hardware ranged breakpoints."));
10082 bp_count
= hw_breakpoint_used_count ();
10083 bp_count
+= target_ranged_break_num_registers ();
10084 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10086 if (can_use_bp
< 0)
10087 error (_("Hardware breakpoints used exceeds limit."));
10089 arg
= skip_spaces (arg
);
10090 if (arg
== NULL
|| arg
[0] == '\0')
10091 error(_("No address range specified."));
10094 event_location_up start_location
= string_to_event_location (&arg
,
10096 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10099 error (_("Too few arguments."));
10100 else if (canonical_start
.lsals
.empty ())
10101 error (_("Could not find location of the beginning of the range."));
10103 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10105 if (canonical_start
.lsals
.size () > 1
10106 || lsal_start
.sals
.size () != 1)
10107 error (_("Cannot create a ranged breakpoint with multiple locations."));
10109 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10110 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10111 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10113 arg
++; /* Skip the comma. */
10114 arg
= skip_spaces (arg
);
10116 /* Parse the end location. */
10120 /* We call decode_line_full directly here instead of using
10121 parse_breakpoint_sals because we need to specify the start location's
10122 symtab and line as the default symtab and line for the end of the
10123 range. This makes it possible to have ranges like "foo.c:27, +14",
10124 where +14 means 14 lines from the start location. */
10125 event_location_up end_location
= string_to_event_location (&arg
,
10127 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10128 sal_start
.symtab
, sal_start
.line
,
10129 &canonical_end
, NULL
, NULL
);
10131 if (canonical_end
.lsals
.empty ())
10132 error (_("Could not find location of the end of the range."));
10134 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10135 if (canonical_end
.lsals
.size () > 1
10136 || lsal_end
.sals
.size () != 1)
10137 error (_("Cannot create a ranged breakpoint with multiple locations."));
10139 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10141 end
= find_breakpoint_range_end (sal_end
);
10142 if (sal_start
.pc
> end
)
10143 error (_("Invalid address range, end precedes start."));
10145 length
= end
- sal_start
.pc
+ 1;
10147 /* Length overflowed. */
10148 error (_("Address range too large."));
10149 else if (length
== 1)
10151 /* This range is simple enough to be handled by
10152 the `hbreak' command. */
10153 hbreak_command (addr_string_start
, 1);
10155 do_cleanups (cleanup_bkpt
);
10160 /* Now set up the breakpoint. */
10161 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10162 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10163 set_breakpoint_count (breakpoint_count
+ 1);
10164 b
->number
= breakpoint_count
;
10165 b
->disposition
= disp_donttouch
;
10166 b
->location
= std::move (start_location
);
10167 b
->location_range_end
= std::move (end_location
);
10168 b
->loc
->length
= length
;
10170 do_cleanups (cleanup_bkpt
);
10173 observer_notify_breakpoint_created (b
);
10174 update_global_location_list (UGLL_MAY_INSERT
);
10177 /* Return non-zero if EXP is verified as constant. Returned zero
10178 means EXP is variable. Also the constant detection may fail for
10179 some constant expressions and in such case still falsely return
10183 watchpoint_exp_is_const (const struct expression
*exp
)
10185 int i
= exp
->nelts
;
10191 /* We are only interested in the descriptor of each element. */
10192 operator_length (exp
, i
, &oplenp
, &argsp
);
10195 switch (exp
->elts
[i
].opcode
)
10205 case BINOP_LOGICAL_AND
:
10206 case BINOP_LOGICAL_OR
:
10207 case BINOP_BITWISE_AND
:
10208 case BINOP_BITWISE_IOR
:
10209 case BINOP_BITWISE_XOR
:
10211 case BINOP_NOTEQUAL
:
10238 case OP_OBJC_NSSTRING
:
10241 case UNOP_LOGICAL_NOT
:
10242 case UNOP_COMPLEMENT
:
10247 case UNOP_CAST_TYPE
:
10248 case UNOP_REINTERPRET_CAST
:
10249 case UNOP_DYNAMIC_CAST
:
10250 /* Unary, binary and ternary operators: We have to check
10251 their operands. If they are constant, then so is the
10252 result of that operation. For instance, if A and B are
10253 determined to be constants, then so is "A + B".
10255 UNOP_IND is one exception to the rule above, because the
10256 value of *ADDR is not necessarily a constant, even when
10261 /* Check whether the associated symbol is a constant.
10263 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10264 possible that a buggy compiler could mark a variable as
10265 constant even when it is not, and TYPE_CONST would return
10266 true in this case, while SYMBOL_CLASS wouldn't.
10268 We also have to check for function symbols because they
10269 are always constant. */
10271 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10273 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10274 && SYMBOL_CLASS (s
) != LOC_CONST
10275 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10280 /* The default action is to return 0 because we are using
10281 the optimistic approach here: If we don't know something,
10282 then it is not a constant. */
10291 /* Watchpoint destructor. */
10293 watchpoint::~watchpoint ()
10295 xfree (this->exp_string
);
10296 xfree (this->exp_string_reparse
);
10297 value_free (this->val
);
10300 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10303 re_set_watchpoint (struct breakpoint
*b
)
10305 struct watchpoint
*w
= (struct watchpoint
*) b
;
10307 /* Watchpoint can be either on expression using entirely global
10308 variables, or it can be on local variables.
10310 Watchpoints of the first kind are never auto-deleted, and even
10311 persist across program restarts. Since they can use variables
10312 from shared libraries, we need to reparse expression as libraries
10313 are loaded and unloaded.
10315 Watchpoints on local variables can also change meaning as result
10316 of solib event. For example, if a watchpoint uses both a local
10317 and a global variables in expression, it's a local watchpoint,
10318 but unloading of a shared library will make the expression
10319 invalid. This is not a very common use case, but we still
10320 re-evaluate expression, to avoid surprises to the user.
10322 Note that for local watchpoints, we re-evaluate it only if
10323 watchpoints frame id is still valid. If it's not, it means the
10324 watchpoint is out of scope and will be deleted soon. In fact,
10325 I'm not sure we'll ever be called in this case.
10327 If a local watchpoint's frame id is still valid, then
10328 w->exp_valid_block is likewise valid, and we can safely use it.
10330 Don't do anything about disabled watchpoints, since they will be
10331 reevaluated again when enabled. */
10332 update_watchpoint (w
, 1 /* reparse */);
10335 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10338 insert_watchpoint (struct bp_location
*bl
)
10340 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10341 int length
= w
->exact
? 1 : bl
->length
;
10343 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10344 w
->cond_exp
.get ());
10347 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10350 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10352 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10353 int length
= w
->exact
? 1 : bl
->length
;
10355 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10356 w
->cond_exp
.get ());
10360 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10361 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10362 const struct target_waitstatus
*ws
)
10364 struct breakpoint
*b
= bl
->owner
;
10365 struct watchpoint
*w
= (struct watchpoint
*) b
;
10367 /* Continuable hardware watchpoints are treated as non-existent if the
10368 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10369 some data address). Otherwise gdb won't stop on a break instruction
10370 in the code (not from a breakpoint) when a hardware watchpoint has
10371 been defined. Also skip watchpoints which we know did not trigger
10372 (did not match the data address). */
10373 if (is_hardware_watchpoint (b
)
10374 && w
->watchpoint_triggered
== watch_triggered_no
)
10381 check_status_watchpoint (bpstat bs
)
10383 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10385 bpstat_check_watchpoint (bs
);
10388 /* Implement the "resources_needed" breakpoint_ops method for
10389 hardware watchpoints. */
10392 resources_needed_watchpoint (const struct bp_location
*bl
)
10394 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10395 int length
= w
->exact
? 1 : bl
->length
;
10397 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10400 /* Implement the "works_in_software_mode" breakpoint_ops method for
10401 hardware watchpoints. */
10404 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10406 /* Read and access watchpoints only work with hardware support. */
10407 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10410 static enum print_stop_action
10411 print_it_watchpoint (bpstat bs
)
10413 struct breakpoint
*b
;
10414 enum print_stop_action result
;
10415 struct watchpoint
*w
;
10416 struct ui_out
*uiout
= current_uiout
;
10418 gdb_assert (bs
->bp_location_at
!= NULL
);
10420 b
= bs
->breakpoint_at
;
10421 w
= (struct watchpoint
*) b
;
10423 annotate_watchpoint (b
->number
);
10424 maybe_print_thread_hit_breakpoint (uiout
);
10428 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10431 case bp_watchpoint
:
10432 case bp_hardware_watchpoint
:
10433 if (uiout
->is_mi_like_p ())
10434 uiout
->field_string
10435 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10437 tuple_emitter
.emplace (uiout
, "value");
10438 uiout
->text ("\nOld value = ");
10439 watchpoint_value_print (bs
->old_val
, &stb
);
10440 uiout
->field_stream ("old", stb
);
10441 uiout
->text ("\nNew value = ");
10442 watchpoint_value_print (w
->val
, &stb
);
10443 uiout
->field_stream ("new", stb
);
10444 uiout
->text ("\n");
10445 /* More than one watchpoint may have been triggered. */
10446 result
= PRINT_UNKNOWN
;
10449 case bp_read_watchpoint
:
10450 if (uiout
->is_mi_like_p ())
10451 uiout
->field_string
10452 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10454 tuple_emitter
.emplace (uiout
, "value");
10455 uiout
->text ("\nValue = ");
10456 watchpoint_value_print (w
->val
, &stb
);
10457 uiout
->field_stream ("value", stb
);
10458 uiout
->text ("\n");
10459 result
= PRINT_UNKNOWN
;
10462 case bp_access_watchpoint
:
10463 if (bs
->old_val
!= NULL
)
10465 if (uiout
->is_mi_like_p ())
10466 uiout
->field_string
10468 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10470 tuple_emitter
.emplace (uiout
, "value");
10471 uiout
->text ("\nOld value = ");
10472 watchpoint_value_print (bs
->old_val
, &stb
);
10473 uiout
->field_stream ("old", stb
);
10474 uiout
->text ("\nNew value = ");
10479 if (uiout
->is_mi_like_p ())
10480 uiout
->field_string
10482 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10483 tuple_emitter
.emplace (uiout
, "value");
10484 uiout
->text ("\nValue = ");
10486 watchpoint_value_print (w
->val
, &stb
);
10487 uiout
->field_stream ("new", stb
);
10488 uiout
->text ("\n");
10489 result
= PRINT_UNKNOWN
;
10492 result
= PRINT_UNKNOWN
;
10498 /* Implement the "print_mention" breakpoint_ops method for hardware
10502 print_mention_watchpoint (struct breakpoint
*b
)
10504 struct watchpoint
*w
= (struct watchpoint
*) b
;
10505 struct ui_out
*uiout
= current_uiout
;
10506 const char *tuple_name
;
10510 case bp_watchpoint
:
10511 uiout
->text ("Watchpoint ");
10512 tuple_name
= "wpt";
10514 case bp_hardware_watchpoint
:
10515 uiout
->text ("Hardware watchpoint ");
10516 tuple_name
= "wpt";
10518 case bp_read_watchpoint
:
10519 uiout
->text ("Hardware read watchpoint ");
10520 tuple_name
= "hw-rwpt";
10522 case bp_access_watchpoint
:
10523 uiout
->text ("Hardware access (read/write) watchpoint ");
10524 tuple_name
= "hw-awpt";
10527 internal_error (__FILE__
, __LINE__
,
10528 _("Invalid hardware watchpoint type."));
10531 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10532 uiout
->field_int ("number", b
->number
);
10533 uiout
->text (": ");
10534 uiout
->field_string ("exp", w
->exp_string
);
10537 /* Implement the "print_recreate" breakpoint_ops method for
10541 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10543 struct watchpoint
*w
= (struct watchpoint
*) b
;
10547 case bp_watchpoint
:
10548 case bp_hardware_watchpoint
:
10549 fprintf_unfiltered (fp
, "watch");
10551 case bp_read_watchpoint
:
10552 fprintf_unfiltered (fp
, "rwatch");
10554 case bp_access_watchpoint
:
10555 fprintf_unfiltered (fp
, "awatch");
10558 internal_error (__FILE__
, __LINE__
,
10559 _("Invalid watchpoint type."));
10562 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10563 print_recreate_thread (b
, fp
);
10566 /* Implement the "explains_signal" breakpoint_ops method for
10570 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10572 /* A software watchpoint cannot cause a signal other than
10573 GDB_SIGNAL_TRAP. */
10574 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10580 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10582 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10584 /* Implement the "insert" breakpoint_ops method for
10585 masked hardware watchpoints. */
10588 insert_masked_watchpoint (struct bp_location
*bl
)
10590 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10592 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10593 bl
->watchpoint_type
);
10596 /* Implement the "remove" breakpoint_ops method for
10597 masked hardware watchpoints. */
10600 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10602 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10604 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10605 bl
->watchpoint_type
);
10608 /* Implement the "resources_needed" breakpoint_ops method for
10609 masked hardware watchpoints. */
10612 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10614 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10616 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10619 /* Implement the "works_in_software_mode" breakpoint_ops method for
10620 masked hardware watchpoints. */
10623 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10628 /* Implement the "print_it" breakpoint_ops method for
10629 masked hardware watchpoints. */
10631 static enum print_stop_action
10632 print_it_masked_watchpoint (bpstat bs
)
10634 struct breakpoint
*b
= bs
->breakpoint_at
;
10635 struct ui_out
*uiout
= current_uiout
;
10637 /* Masked watchpoints have only one location. */
10638 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10640 annotate_watchpoint (b
->number
);
10641 maybe_print_thread_hit_breakpoint (uiout
);
10645 case bp_hardware_watchpoint
:
10646 if (uiout
->is_mi_like_p ())
10647 uiout
->field_string
10648 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10651 case bp_read_watchpoint
:
10652 if (uiout
->is_mi_like_p ())
10653 uiout
->field_string
10654 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10657 case bp_access_watchpoint
:
10658 if (uiout
->is_mi_like_p ())
10659 uiout
->field_string
10661 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10664 internal_error (__FILE__
, __LINE__
,
10665 _("Invalid hardware watchpoint type."));
10669 uiout
->text (_("\n\
10670 Check the underlying instruction at PC for the memory\n\
10671 address and value which triggered this watchpoint.\n"));
10672 uiout
->text ("\n");
10674 /* More than one watchpoint may have been triggered. */
10675 return PRINT_UNKNOWN
;
10678 /* Implement the "print_one_detail" breakpoint_ops method for
10679 masked hardware watchpoints. */
10682 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10683 struct ui_out
*uiout
)
10685 struct watchpoint
*w
= (struct watchpoint
*) b
;
10687 /* Masked watchpoints have only one location. */
10688 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10690 uiout
->text ("\tmask ");
10691 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10692 uiout
->text ("\n");
10695 /* Implement the "print_mention" breakpoint_ops method for
10696 masked hardware watchpoints. */
10699 print_mention_masked_watchpoint (struct breakpoint
*b
)
10701 struct watchpoint
*w
= (struct watchpoint
*) b
;
10702 struct ui_out
*uiout
= current_uiout
;
10703 const char *tuple_name
;
10707 case bp_hardware_watchpoint
:
10708 uiout
->text ("Masked hardware watchpoint ");
10709 tuple_name
= "wpt";
10711 case bp_read_watchpoint
:
10712 uiout
->text ("Masked hardware read watchpoint ");
10713 tuple_name
= "hw-rwpt";
10715 case bp_access_watchpoint
:
10716 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10717 tuple_name
= "hw-awpt";
10720 internal_error (__FILE__
, __LINE__
,
10721 _("Invalid hardware watchpoint type."));
10724 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10725 uiout
->field_int ("number", b
->number
);
10726 uiout
->text (": ");
10727 uiout
->field_string ("exp", w
->exp_string
);
10730 /* Implement the "print_recreate" breakpoint_ops method for
10731 masked hardware watchpoints. */
10734 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10736 struct watchpoint
*w
= (struct watchpoint
*) b
;
10741 case bp_hardware_watchpoint
:
10742 fprintf_unfiltered (fp
, "watch");
10744 case bp_read_watchpoint
:
10745 fprintf_unfiltered (fp
, "rwatch");
10747 case bp_access_watchpoint
:
10748 fprintf_unfiltered (fp
, "awatch");
10751 internal_error (__FILE__
, __LINE__
,
10752 _("Invalid hardware watchpoint type."));
10755 sprintf_vma (tmp
, w
->hw_wp_mask
);
10756 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10757 print_recreate_thread (b
, fp
);
10760 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10762 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10764 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10767 is_masked_watchpoint (const struct breakpoint
*b
)
10769 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10772 /* accessflag: hw_write: watch write,
10773 hw_read: watch read,
10774 hw_access: watch access (read or write) */
10776 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10777 int just_location
, int internal
)
10779 struct breakpoint
*scope_breakpoint
= NULL
;
10780 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10781 struct value
*val
, *mark
, *result
;
10782 int saved_bitpos
= 0, saved_bitsize
= 0;
10783 const char *exp_start
= NULL
;
10784 const char *exp_end
= NULL
;
10785 const char *tok
, *end_tok
;
10787 const char *cond_start
= NULL
;
10788 const char *cond_end
= NULL
;
10789 enum bptype bp_type
;
10792 /* Flag to indicate whether we are going to use masks for
10793 the hardware watchpoint. */
10795 CORE_ADDR mask
= 0;
10797 struct cleanup
*back_to
;
10799 /* Make sure that we actually have parameters to parse. */
10800 if (arg
!= NULL
&& arg
[0] != '\0')
10802 const char *value_start
;
10804 exp_end
= arg
+ strlen (arg
);
10806 /* Look for "parameter value" pairs at the end
10807 of the arguments string. */
10808 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10810 /* Skip whitespace at the end of the argument list. */
10811 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10814 /* Find the beginning of the last token.
10815 This is the value of the parameter. */
10816 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10818 value_start
= tok
+ 1;
10820 /* Skip whitespace. */
10821 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10826 /* Find the beginning of the second to last token.
10827 This is the parameter itself. */
10828 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10831 toklen
= end_tok
- tok
+ 1;
10833 if (toklen
== 6 && startswith (tok
, "thread"))
10835 struct thread_info
*thr
;
10836 /* At this point we've found a "thread" token, which means
10837 the user is trying to set a watchpoint that triggers
10838 only in a specific thread. */
10842 error(_("You can specify only one thread."));
10844 /* Extract the thread ID from the next token. */
10845 thr
= parse_thread_id (value_start
, &endp
);
10847 /* Check if the user provided a valid thread ID. */
10848 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10849 invalid_thread_id_error (value_start
);
10851 thread
= thr
->global_num
;
10853 else if (toklen
== 4 && startswith (tok
, "mask"))
10855 /* We've found a "mask" token, which means the user wants to
10856 create a hardware watchpoint that is going to have the mask
10858 struct value
*mask_value
, *mark
;
10861 error(_("You can specify only one mask."));
10863 use_mask
= just_location
= 1;
10865 mark
= value_mark ();
10866 mask_value
= parse_to_comma_and_eval (&value_start
);
10867 mask
= value_as_address (mask_value
);
10868 value_free_to_mark (mark
);
10871 /* We didn't recognize what we found. We should stop here. */
10874 /* Truncate the string and get rid of the "parameter value" pair before
10875 the arguments string is parsed by the parse_exp_1 function. */
10882 /* Parse the rest of the arguments. From here on out, everything
10883 is in terms of a newly allocated string instead of the original
10885 innermost_block
= NULL
;
10886 expression
= savestring (arg
, exp_end
- arg
);
10887 back_to
= make_cleanup (xfree
, expression
);
10888 exp_start
= arg
= expression
;
10889 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10891 /* Remove trailing whitespace from the expression before saving it.
10892 This makes the eventual display of the expression string a bit
10894 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10897 /* Checking if the expression is not constant. */
10898 if (watchpoint_exp_is_const (exp
.get ()))
10902 len
= exp_end
- exp_start
;
10903 while (len
> 0 && isspace (exp_start
[len
- 1]))
10905 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10908 exp_valid_block
= innermost_block
;
10909 mark
= value_mark ();
10910 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10912 if (val
!= NULL
&& just_location
)
10914 saved_bitpos
= value_bitpos (val
);
10915 saved_bitsize
= value_bitsize (val
);
10922 exp_valid_block
= NULL
;
10923 val
= value_addr (result
);
10924 release_value (val
);
10925 value_free_to_mark (mark
);
10929 ret
= target_masked_watch_num_registers (value_as_address (val
),
10932 error (_("This target does not support masked watchpoints."));
10933 else if (ret
== -2)
10934 error (_("Invalid mask or memory region."));
10937 else if (val
!= NULL
)
10938 release_value (val
);
10940 tok
= skip_spaces (arg
);
10941 end_tok
= skip_to_space (tok
);
10943 toklen
= end_tok
- tok
;
10944 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10946 innermost_block
= NULL
;
10947 tok
= cond_start
= end_tok
+ 1;
10948 parse_exp_1 (&tok
, 0, 0, 0);
10950 /* The watchpoint expression may not be local, but the condition
10951 may still be. E.g.: `watch global if local > 0'. */
10952 cond_exp_valid_block
= innermost_block
;
10957 error (_("Junk at end of command."));
10959 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10961 /* Save this because create_internal_breakpoint below invalidates
10963 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10965 /* If the expression is "local", then set up a "watchpoint scope"
10966 breakpoint at the point where we've left the scope of the watchpoint
10967 expression. Create the scope breakpoint before the watchpoint, so
10968 that we will encounter it first in bpstat_stop_status. */
10969 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10971 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10973 if (frame_id_p (caller_frame_id
))
10975 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10976 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10979 = create_internal_breakpoint (caller_arch
, caller_pc
,
10980 bp_watchpoint_scope
,
10981 &momentary_breakpoint_ops
);
10983 /* create_internal_breakpoint could invalidate WP_FRAME. */
10986 scope_breakpoint
->enable_state
= bp_enabled
;
10988 /* Automatically delete the breakpoint when it hits. */
10989 scope_breakpoint
->disposition
= disp_del
;
10991 /* Only break in the proper frame (help with recursion). */
10992 scope_breakpoint
->frame_id
= caller_frame_id
;
10994 /* Set the address at which we will stop. */
10995 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10996 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10997 scope_breakpoint
->loc
->address
10998 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10999 scope_breakpoint
->loc
->requested_address
,
11000 scope_breakpoint
->type
);
11004 /* Now set up the breakpoint. We create all watchpoints as hardware
11005 watchpoints here even if hardware watchpoints are turned off, a call
11006 to update_watchpoint later in this function will cause the type to
11007 drop back to bp_watchpoint (software watchpoint) if required. */
11009 if (accessflag
== hw_read
)
11010 bp_type
= bp_read_watchpoint
;
11011 else if (accessflag
== hw_access
)
11012 bp_type
= bp_access_watchpoint
;
11014 bp_type
= bp_hardware_watchpoint
;
11016 std::unique_ptr
<watchpoint
> w (new watchpoint ());
11019 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11020 &masked_watchpoint_breakpoint_ops
);
11022 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11023 &watchpoint_breakpoint_ops
);
11024 w
->thread
= thread
;
11025 w
->disposition
= disp_donttouch
;
11026 w
->pspace
= current_program_space
;
11027 w
->exp
= std::move (exp
);
11028 w
->exp_valid_block
= exp_valid_block
;
11029 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11032 struct type
*t
= value_type (val
);
11033 CORE_ADDR addr
= value_as_address (val
);
11035 w
->exp_string_reparse
11036 = current_language
->la_watch_location_expression (t
, addr
).release ();
11038 w
->exp_string
= xstrprintf ("-location %.*s",
11039 (int) (exp_end
- exp_start
), exp_start
);
11042 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11046 w
->hw_wp_mask
= mask
;
11051 w
->val_bitpos
= saved_bitpos
;
11052 w
->val_bitsize
= saved_bitsize
;
11057 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11059 w
->cond_string
= 0;
11061 if (frame_id_p (watchpoint_frame
))
11063 w
->watchpoint_frame
= watchpoint_frame
;
11064 w
->watchpoint_thread
= inferior_ptid
;
11068 w
->watchpoint_frame
= null_frame_id
;
11069 w
->watchpoint_thread
= null_ptid
;
11072 if (scope_breakpoint
!= NULL
)
11074 /* The scope breakpoint is related to the watchpoint. We will
11075 need to act on them together. */
11076 w
->related_breakpoint
= scope_breakpoint
;
11077 scope_breakpoint
->related_breakpoint
= w
.get ();
11080 if (!just_location
)
11081 value_free_to_mark (mark
);
11083 /* Finally update the new watchpoint. This creates the locations
11084 that should be inserted. */
11085 update_watchpoint (w
.get (), 1);
11087 install_breakpoint (internal
, std::move (w
), 1);
11088 do_cleanups (back_to
);
11091 /* Return count of debug registers needed to watch the given expression.
11092 If the watchpoint cannot be handled in hardware return zero. */
11095 can_use_hardware_watchpoint (struct value
*v
)
11097 int found_memory_cnt
= 0;
11098 struct value
*head
= v
;
11100 /* Did the user specifically forbid us to use hardware watchpoints? */
11101 if (!can_use_hw_watchpoints
)
11104 /* Make sure that the value of the expression depends only upon
11105 memory contents, and values computed from them within GDB. If we
11106 find any register references or function calls, we can't use a
11107 hardware watchpoint.
11109 The idea here is that evaluating an expression generates a series
11110 of values, one holding the value of every subexpression. (The
11111 expression a*b+c has five subexpressions: a, b, a*b, c, and
11112 a*b+c.) GDB's values hold almost enough information to establish
11113 the criteria given above --- they identify memory lvalues,
11114 register lvalues, computed values, etcetera. So we can evaluate
11115 the expression, and then scan the chain of values that leaves
11116 behind to decide whether we can detect any possible change to the
11117 expression's final value using only hardware watchpoints.
11119 However, I don't think that the values returned by inferior
11120 function calls are special in any way. So this function may not
11121 notice that an expression involving an inferior function call
11122 can't be watched with hardware watchpoints. FIXME. */
11123 for (; v
; v
= value_next (v
))
11125 if (VALUE_LVAL (v
) == lval_memory
)
11127 if (v
!= head
&& value_lazy (v
))
11128 /* A lazy memory lvalue in the chain is one that GDB never
11129 needed to fetch; we either just used its address (e.g.,
11130 `a' in `a.b') or we never needed it at all (e.g., `a'
11131 in `a,b'). This doesn't apply to HEAD; if that is
11132 lazy then it was not readable, but watch it anyway. */
11136 /* Ahh, memory we actually used! Check if we can cover
11137 it with hardware watchpoints. */
11138 struct type
*vtype
= check_typedef (value_type (v
));
11140 /* We only watch structs and arrays if user asked for it
11141 explicitly, never if they just happen to appear in a
11142 middle of some value chain. */
11144 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11145 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11147 CORE_ADDR vaddr
= value_address (v
);
11151 len
= (target_exact_watchpoints
11152 && is_scalar_type_recursive (vtype
))?
11153 1 : TYPE_LENGTH (value_type (v
));
11155 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11159 found_memory_cnt
+= num_regs
;
11163 else if (VALUE_LVAL (v
) != not_lval
11164 && deprecated_value_modifiable (v
) == 0)
11165 return 0; /* These are values from the history (e.g., $1). */
11166 else if (VALUE_LVAL (v
) == lval_register
)
11167 return 0; /* Cannot watch a register with a HW watchpoint. */
11170 /* The expression itself looks suitable for using a hardware
11171 watchpoint, but give the target machine a chance to reject it. */
11172 return found_memory_cnt
;
11176 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11178 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11181 /* A helper function that looks for the "-location" argument and then
11182 calls watch_command_1. */
11185 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11187 int just_location
= 0;
11190 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11191 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11193 arg
= skip_spaces (arg
);
11197 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11201 watch_command (char *arg
, int from_tty
)
11203 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11207 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11209 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11213 rwatch_command (char *arg
, int from_tty
)
11215 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11219 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11221 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11225 awatch_command (char *arg
, int from_tty
)
11227 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11231 /* Data for the FSM that manages the until(location)/advance commands
11232 in infcmd.c. Here because it uses the mechanisms of
11235 struct until_break_fsm
11237 /* The base class. */
11238 struct thread_fsm thread_fsm
;
11240 /* The thread that as current when the command was executed. */
11243 /* The breakpoint set at the destination location. */
11244 struct breakpoint
*location_breakpoint
;
11246 /* Breakpoint set at the return address in the caller frame. May be
11248 struct breakpoint
*caller_breakpoint
;
11251 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11252 struct thread_info
*thread
);
11253 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11254 struct thread_info
*thread
);
11255 static enum async_reply_reason
11256 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11258 /* until_break_fsm's vtable. */
11260 static struct thread_fsm_ops until_break_fsm_ops
=
11263 until_break_fsm_clean_up
,
11264 until_break_fsm_should_stop
,
11265 NULL
, /* return_value */
11266 until_break_fsm_async_reply_reason
,
11269 /* Allocate a new until_break_command_fsm. */
11271 static struct until_break_fsm
*
11272 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11273 struct breakpoint
*location_breakpoint
,
11274 struct breakpoint
*caller_breakpoint
)
11276 struct until_break_fsm
*sm
;
11278 sm
= XCNEW (struct until_break_fsm
);
11279 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11281 sm
->thread
= thread
;
11282 sm
->location_breakpoint
= location_breakpoint
;
11283 sm
->caller_breakpoint
= caller_breakpoint
;
11288 /* Implementation of the 'should_stop' FSM method for the
11289 until(location)/advance commands. */
11292 until_break_fsm_should_stop (struct thread_fsm
*self
,
11293 struct thread_info
*tp
)
11295 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11297 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11298 sm
->location_breakpoint
) != NULL
11299 || (sm
->caller_breakpoint
!= NULL
11300 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11301 sm
->caller_breakpoint
) != NULL
))
11302 thread_fsm_set_finished (self
);
11307 /* Implementation of the 'clean_up' FSM method for the
11308 until(location)/advance commands. */
11311 until_break_fsm_clean_up (struct thread_fsm
*self
,
11312 struct thread_info
*thread
)
11314 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11316 /* Clean up our temporary breakpoints. */
11317 if (sm
->location_breakpoint
!= NULL
)
11319 delete_breakpoint (sm
->location_breakpoint
);
11320 sm
->location_breakpoint
= NULL
;
11322 if (sm
->caller_breakpoint
!= NULL
)
11324 delete_breakpoint (sm
->caller_breakpoint
);
11325 sm
->caller_breakpoint
= NULL
;
11327 delete_longjmp_breakpoint (sm
->thread
);
11330 /* Implementation of the 'async_reply_reason' FSM method for the
11331 until(location)/advance commands. */
11333 static enum async_reply_reason
11334 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11336 return EXEC_ASYNC_LOCATION_REACHED
;
11340 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11342 struct frame_info
*frame
;
11343 struct gdbarch
*frame_gdbarch
;
11344 struct frame_id stack_frame_id
;
11345 struct frame_id caller_frame_id
;
11346 struct breakpoint
*location_breakpoint
;
11347 struct breakpoint
*caller_breakpoint
= NULL
;
11348 struct cleanup
*old_chain
;
11350 struct thread_info
*tp
;
11351 struct until_break_fsm
*sm
;
11353 clear_proceed_status (0);
11355 /* Set a breakpoint where the user wants it and at return from
11358 event_location_up location
= string_to_event_location (&arg
, current_language
);
11360 std::vector
<symtab_and_line
> sals
11361 = (last_displayed_sal_is_valid ()
11362 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11363 get_last_displayed_symtab (),
11364 get_last_displayed_line ())
11365 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11366 NULL
, (struct symtab
*) NULL
, 0));
11368 if (sals
.size () != 1)
11369 error (_("Couldn't get information on specified line."));
11371 symtab_and_line
&sal
= sals
[0];
11374 error (_("Junk at end of arguments."));
11376 resolve_sal_pc (&sal
);
11378 tp
= inferior_thread ();
11379 thread
= tp
->global_num
;
11381 old_chain
= make_cleanup (null_cleanup
, NULL
);
11383 /* Note linespec handling above invalidates the frame chain.
11384 Installing a breakpoint also invalidates the frame chain (as it
11385 may need to switch threads), so do any frame handling before
11388 frame
= get_selected_frame (NULL
);
11389 frame_gdbarch
= get_frame_arch (frame
);
11390 stack_frame_id
= get_stack_frame_id (frame
);
11391 caller_frame_id
= frame_unwind_caller_id (frame
);
11393 /* Keep within the current frame, or in frames called by the current
11396 if (frame_id_p (caller_frame_id
))
11398 struct symtab_and_line sal2
;
11399 struct gdbarch
*caller_gdbarch
;
11401 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11402 sal2
.pc
= frame_unwind_caller_pc (frame
);
11403 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11404 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11408 make_cleanup_delete_breakpoint (caller_breakpoint
);
11410 set_longjmp_breakpoint (tp
, caller_frame_id
);
11411 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11414 /* set_momentary_breakpoint could invalidate FRAME. */
11418 /* If the user told us to continue until a specified location,
11419 we don't specify a frame at which we need to stop. */
11420 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11421 null_frame_id
, bp_until
);
11423 /* Otherwise, specify the selected frame, because we want to stop
11424 only at the very same frame. */
11425 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11426 stack_frame_id
, bp_until
);
11427 make_cleanup_delete_breakpoint (location_breakpoint
);
11429 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11430 location_breakpoint
, caller_breakpoint
);
11431 tp
->thread_fsm
= &sm
->thread_fsm
;
11433 discard_cleanups (old_chain
);
11435 proceed (-1, GDB_SIGNAL_DEFAULT
);
11438 /* This function attempts to parse an optional "if <cond>" clause
11439 from the arg string. If one is not found, it returns NULL.
11441 Else, it returns a pointer to the condition string. (It does not
11442 attempt to evaluate the string against a particular block.) And,
11443 it updates arg to point to the first character following the parsed
11444 if clause in the arg string. */
11447 ep_parse_optional_if_clause (const char **arg
)
11449 const char *cond_string
;
11451 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11454 /* Skip the "if" keyword. */
11457 /* Skip any extra leading whitespace, and record the start of the
11458 condition string. */
11459 *arg
= skip_spaces (*arg
);
11460 cond_string
= *arg
;
11462 /* Assume that the condition occupies the remainder of the arg
11464 (*arg
) += strlen (cond_string
);
11466 return cond_string
;
11469 /* Commands to deal with catching events, such as signals, exceptions,
11470 process start/exit, etc. */
11474 catch_fork_temporary
, catch_vfork_temporary
,
11475 catch_fork_permanent
, catch_vfork_permanent
11480 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11481 struct cmd_list_element
*command
)
11483 const char *arg
= arg_entry
;
11484 struct gdbarch
*gdbarch
= get_current_arch ();
11485 const char *cond_string
= NULL
;
11486 catch_fork_kind fork_kind
;
11489 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11490 tempflag
= (fork_kind
== catch_fork_temporary
11491 || fork_kind
== catch_vfork_temporary
);
11495 arg
= skip_spaces (arg
);
11497 /* The allowed syntax is:
11499 catch [v]fork if <cond>
11501 First, check if there's an if clause. */
11502 cond_string
= ep_parse_optional_if_clause (&arg
);
11504 if ((*arg
!= '\0') && !isspace (*arg
))
11505 error (_("Junk at end of arguments."));
11507 /* If this target supports it, create a fork or vfork catchpoint
11508 and enable reporting of such events. */
11511 case catch_fork_temporary
:
11512 case catch_fork_permanent
:
11513 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11514 &catch_fork_breakpoint_ops
);
11516 case catch_vfork_temporary
:
11517 case catch_vfork_permanent
:
11518 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11519 &catch_vfork_breakpoint_ops
);
11522 error (_("unsupported or unknown fork kind; cannot catch it"));
11528 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11529 struct cmd_list_element
*command
)
11531 const char *arg
= arg_entry
;
11532 struct gdbarch
*gdbarch
= get_current_arch ();
11534 const char *cond_string
= NULL
;
11536 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11540 arg
= skip_spaces (arg
);
11542 /* The allowed syntax is:
11544 catch exec if <cond>
11546 First, check if there's an if clause. */
11547 cond_string
= ep_parse_optional_if_clause (&arg
);
11549 if ((*arg
!= '\0') && !isspace (*arg
))
11550 error (_("Junk at end of arguments."));
11552 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11553 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11554 &catch_exec_breakpoint_ops
);
11555 c
->exec_pathname
= NULL
;
11557 install_breakpoint (0, std::move (c
), 1);
11561 init_ada_exception_breakpoint (struct breakpoint
*b
,
11562 struct gdbarch
*gdbarch
,
11563 struct symtab_and_line sal
,
11564 const char *addr_string
,
11565 const struct breakpoint_ops
*ops
,
11572 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11574 loc_gdbarch
= gdbarch
;
11576 describe_other_breakpoints (loc_gdbarch
,
11577 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11578 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11579 version for exception catchpoints, because two catchpoints
11580 used for different exception names will use the same address.
11581 In this case, a "breakpoint ... also set at..." warning is
11582 unproductive. Besides, the warning phrasing is also a bit
11583 inappropriate, we should use the word catchpoint, and tell
11584 the user what type of catchpoint it is. The above is good
11585 enough for now, though. */
11588 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11590 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11591 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11592 b
->location
= string_to_event_location (&addr_string
,
11593 language_def (language_ada
));
11594 b
->language
= language_ada
;
11598 catch_command (char *arg
, int from_tty
)
11600 error (_("Catch requires an event name."));
11605 tcatch_command (char *arg
, int from_tty
)
11607 error (_("Catch requires an event name."));
11610 /* A qsort comparison function that sorts breakpoints in order. */
11613 compare_breakpoints (const void *a
, const void *b
)
11615 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11616 uintptr_t ua
= (uintptr_t) *ba
;
11617 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11618 uintptr_t ub
= (uintptr_t) *bb
;
11620 if ((*ba
)->number
< (*bb
)->number
)
11622 else if ((*ba
)->number
> (*bb
)->number
)
11625 /* Now sort by address, in case we see, e..g, two breakpoints with
11629 return ua
> ub
? 1 : 0;
11632 /* Delete breakpoints by address or line. */
11635 clear_command (char *arg
, int from_tty
)
11637 struct breakpoint
*b
, *prev
;
11638 VEC(breakpoint_p
) *found
= 0;
11642 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11644 std::vector
<symtab_and_line
> decoded_sals
;
11645 symtab_and_line last_sal
;
11646 gdb::array_view
<symtab_and_line
> sals
;
11650 = decode_line_with_current_source (arg
,
11651 (DECODE_LINE_FUNFIRSTLINE
11652 | DECODE_LINE_LIST_MODE
));
11654 sals
= decoded_sals
;
11658 /* Set sal's line, symtab, pc, and pspace to the values
11659 corresponding to the last call to print_frame_info. If the
11660 codepoint is not valid, this will set all the fields to 0. */
11661 last_sal
= get_last_displayed_sal ();
11662 if (last_sal
.symtab
== 0)
11663 error (_("No source file specified."));
11669 /* We don't call resolve_sal_pc here. That's not as bad as it
11670 seems, because all existing breakpoints typically have both
11671 file/line and pc set. So, if clear is given file/line, we can
11672 match this to existing breakpoint without obtaining pc at all.
11674 We only support clearing given the address explicitly
11675 present in breakpoint table. Say, we've set breakpoint
11676 at file:line. There were several PC values for that file:line,
11677 due to optimization, all in one block.
11679 We've picked one PC value. If "clear" is issued with another
11680 PC corresponding to the same file:line, the breakpoint won't
11681 be cleared. We probably can still clear the breakpoint, but
11682 since the other PC value is never presented to user, user
11683 can only find it by guessing, and it does not seem important
11684 to support that. */
11686 /* For each line spec given, delete bps which correspond to it. Do
11687 it in two passes, solely to preserve the current behavior that
11688 from_tty is forced true if we delete more than one
11692 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11693 for (const auto &sal
: sals
)
11695 const char *sal_fullname
;
11697 /* If exact pc given, clear bpts at that pc.
11698 If line given (pc == 0), clear all bpts on specified line.
11699 If defaulting, clear all bpts on default line
11702 defaulting sal.pc != 0 tests to do
11707 1 0 <can't happen> */
11709 sal_fullname
= (sal
.symtab
== NULL
11710 ? NULL
: symtab_to_fullname (sal
.symtab
));
11712 /* Find all matching breakpoints and add them to 'found'. */
11713 ALL_BREAKPOINTS (b
)
11716 /* Are we going to delete b? */
11717 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11719 struct bp_location
*loc
= b
->loc
;
11720 for (; loc
; loc
= loc
->next
)
11722 /* If the user specified file:line, don't allow a PC
11723 match. This matches historical gdb behavior. */
11724 int pc_match
= (!sal
.explicit_line
11726 && (loc
->pspace
== sal
.pspace
)
11727 && (loc
->address
== sal
.pc
)
11728 && (!section_is_overlay (loc
->section
)
11729 || loc
->section
== sal
.section
));
11730 int line_match
= 0;
11732 if ((default_match
|| sal
.explicit_line
)
11733 && loc
->symtab
!= NULL
11734 && sal_fullname
!= NULL
11735 && sal
.pspace
== loc
->pspace
11736 && loc
->line_number
== sal
.line
11737 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11738 sal_fullname
) == 0)
11741 if (pc_match
|| line_match
)
11750 VEC_safe_push(breakpoint_p
, found
, b
);
11754 /* Now go thru the 'found' chain and delete them. */
11755 if (VEC_empty(breakpoint_p
, found
))
11758 error (_("No breakpoint at %s."), arg
);
11760 error (_("No breakpoint at this line."));
11763 /* Remove duplicates from the vec. */
11764 qsort (VEC_address (breakpoint_p
, found
),
11765 VEC_length (breakpoint_p
, found
),
11766 sizeof (breakpoint_p
),
11767 compare_breakpoints
);
11768 prev
= VEC_index (breakpoint_p
, found
, 0);
11769 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11773 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11778 if (VEC_length(breakpoint_p
, found
) > 1)
11779 from_tty
= 1; /* Always report if deleted more than one. */
11782 if (VEC_length(breakpoint_p
, found
) == 1)
11783 printf_unfiltered (_("Deleted breakpoint "));
11785 printf_unfiltered (_("Deleted breakpoints "));
11788 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11791 printf_unfiltered ("%d ", b
->number
);
11792 delete_breakpoint (b
);
11795 putchar_unfiltered ('\n');
11797 do_cleanups (cleanups
);
11800 /* Delete breakpoint in BS if they are `delete' breakpoints and
11801 all breakpoints that are marked for deletion, whether hit or not.
11802 This is called after any breakpoint is hit, or after errors. */
11805 breakpoint_auto_delete (bpstat bs
)
11807 struct breakpoint
*b
, *b_tmp
;
11809 for (; bs
; bs
= bs
->next
)
11810 if (bs
->breakpoint_at
11811 && bs
->breakpoint_at
->disposition
== disp_del
11813 delete_breakpoint (bs
->breakpoint_at
);
11815 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11817 if (b
->disposition
== disp_del_at_next_stop
)
11818 delete_breakpoint (b
);
11822 /* A comparison function for bp_location AP and BP being interfaced to
11823 qsort. Sort elements primarily by their ADDRESS (no matter what
11824 does breakpoint_address_is_meaningful say for its OWNER),
11825 secondarily by ordering first permanent elements and
11826 terciarily just ensuring the array is sorted stable way despite
11827 qsort being an unstable algorithm. */
11830 bp_locations_compare (const void *ap
, const void *bp
)
11832 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11833 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11835 if (a
->address
!= b
->address
)
11836 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11838 /* Sort locations at the same address by their pspace number, keeping
11839 locations of the same inferior (in a multi-inferior environment)
11842 if (a
->pspace
->num
!= b
->pspace
->num
)
11843 return ((a
->pspace
->num
> b
->pspace
->num
)
11844 - (a
->pspace
->num
< b
->pspace
->num
));
11846 /* Sort permanent breakpoints first. */
11847 if (a
->permanent
!= b
->permanent
)
11848 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11850 /* Make the internal GDB representation stable across GDB runs
11851 where A and B memory inside GDB can differ. Breakpoint locations of
11852 the same type at the same address can be sorted in arbitrary order. */
11854 if (a
->owner
->number
!= b
->owner
->number
)
11855 return ((a
->owner
->number
> b
->owner
->number
)
11856 - (a
->owner
->number
< b
->owner
->number
));
11858 return (a
> b
) - (a
< b
);
11861 /* Set bp_locations_placed_address_before_address_max and
11862 bp_locations_shadow_len_after_address_max according to the current
11863 content of the bp_locations array. */
11866 bp_locations_target_extensions_update (void)
11868 struct bp_location
*bl
, **blp_tmp
;
11870 bp_locations_placed_address_before_address_max
= 0;
11871 bp_locations_shadow_len_after_address_max
= 0;
11873 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11875 CORE_ADDR start
, end
, addr
;
11877 if (!bp_location_has_shadow (bl
))
11880 start
= bl
->target_info
.placed_address
;
11881 end
= start
+ bl
->target_info
.shadow_len
;
11883 gdb_assert (bl
->address
>= start
);
11884 addr
= bl
->address
- start
;
11885 if (addr
> bp_locations_placed_address_before_address_max
)
11886 bp_locations_placed_address_before_address_max
= addr
;
11888 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11890 gdb_assert (bl
->address
< end
);
11891 addr
= end
- bl
->address
;
11892 if (addr
> bp_locations_shadow_len_after_address_max
)
11893 bp_locations_shadow_len_after_address_max
= addr
;
11897 /* Download tracepoint locations if they haven't been. */
11900 download_tracepoint_locations (void)
11902 struct breakpoint
*b
;
11903 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11905 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11907 ALL_TRACEPOINTS (b
)
11909 struct bp_location
*bl
;
11910 struct tracepoint
*t
;
11911 int bp_location_downloaded
= 0;
11913 if ((b
->type
== bp_fast_tracepoint
11914 ? !may_insert_fast_tracepoints
11915 : !may_insert_tracepoints
))
11918 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11920 if (target_can_download_tracepoint ())
11921 can_download_tracepoint
= TRIBOOL_TRUE
;
11923 can_download_tracepoint
= TRIBOOL_FALSE
;
11926 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11929 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11931 /* In tracepoint, locations are _never_ duplicated, so
11932 should_be_inserted is equivalent to
11933 unduplicated_should_be_inserted. */
11934 if (!should_be_inserted (bl
) || bl
->inserted
)
11937 switch_to_program_space_and_thread (bl
->pspace
);
11939 target_download_tracepoint (bl
);
11942 bp_location_downloaded
= 1;
11944 t
= (struct tracepoint
*) b
;
11945 t
->number_on_target
= b
->number
;
11946 if (bp_location_downloaded
)
11947 observer_notify_breakpoint_modified (b
);
11951 /* Swap the insertion/duplication state between two locations. */
11954 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11956 const int left_inserted
= left
->inserted
;
11957 const int left_duplicate
= left
->duplicate
;
11958 const int left_needs_update
= left
->needs_update
;
11959 const struct bp_target_info left_target_info
= left
->target_info
;
11961 /* Locations of tracepoints can never be duplicated. */
11962 if (is_tracepoint (left
->owner
))
11963 gdb_assert (!left
->duplicate
);
11964 if (is_tracepoint (right
->owner
))
11965 gdb_assert (!right
->duplicate
);
11967 left
->inserted
= right
->inserted
;
11968 left
->duplicate
= right
->duplicate
;
11969 left
->needs_update
= right
->needs_update
;
11970 left
->target_info
= right
->target_info
;
11971 right
->inserted
= left_inserted
;
11972 right
->duplicate
= left_duplicate
;
11973 right
->needs_update
= left_needs_update
;
11974 right
->target_info
= left_target_info
;
11977 /* Force the re-insertion of the locations at ADDRESS. This is called
11978 once a new/deleted/modified duplicate location is found and we are evaluating
11979 conditions on the target's side. Such conditions need to be updated on
11983 force_breakpoint_reinsertion (struct bp_location
*bl
)
11985 struct bp_location
**locp
= NULL
, **loc2p
;
11986 struct bp_location
*loc
;
11987 CORE_ADDR address
= 0;
11990 address
= bl
->address
;
11991 pspace_num
= bl
->pspace
->num
;
11993 /* This is only meaningful if the target is
11994 evaluating conditions and if the user has
11995 opted for condition evaluation on the target's
11997 if (gdb_evaluates_breakpoint_condition_p ()
11998 || !target_supports_evaluation_of_breakpoint_conditions ())
12001 /* Flag all breakpoint locations with this address and
12002 the same program space as the location
12003 as "its condition has changed". We need to
12004 update the conditions on the target's side. */
12005 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12009 if (!is_breakpoint (loc
->owner
)
12010 || pspace_num
!= loc
->pspace
->num
)
12013 /* Flag the location appropriately. We use a different state to
12014 let everyone know that we already updated the set of locations
12015 with addr bl->address and program space bl->pspace. This is so
12016 we don't have to keep calling these functions just to mark locations
12017 that have already been marked. */
12018 loc
->condition_changed
= condition_updated
;
12020 /* Free the agent expression bytecode as well. We will compute
12022 loc
->cond_bytecode
.reset ();
12025 /* Called whether new breakpoints are created, or existing breakpoints
12026 deleted, to update the global location list and recompute which
12027 locations are duplicate of which.
12029 The INSERT_MODE flag determines whether locations may not, may, or
12030 shall be inserted now. See 'enum ugll_insert_mode' for more
12034 update_global_location_list (enum ugll_insert_mode insert_mode
)
12036 struct breakpoint
*b
;
12037 struct bp_location
**locp
, *loc
;
12038 struct cleanup
*cleanups
;
12039 /* Last breakpoint location address that was marked for update. */
12040 CORE_ADDR last_addr
= 0;
12041 /* Last breakpoint location program space that was marked for update. */
12042 int last_pspace_num
= -1;
12044 /* Used in the duplicates detection below. When iterating over all
12045 bp_locations, points to the first bp_location of a given address.
12046 Breakpoints and watchpoints of different types are never
12047 duplicates of each other. Keep one pointer for each type of
12048 breakpoint/watchpoint, so we only need to loop over all locations
12050 struct bp_location
*bp_loc_first
; /* breakpoint */
12051 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12052 struct bp_location
*awp_loc_first
; /* access watchpoint */
12053 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12055 /* Saved former bp_locations array which we compare against the newly
12056 built bp_locations from the current state of ALL_BREAKPOINTS. */
12057 struct bp_location
**old_locations
, **old_locp
;
12058 unsigned old_locations_count
;
12060 old_locations
= bp_locations
;
12061 old_locations_count
= bp_locations_count
;
12062 bp_locations
= NULL
;
12063 bp_locations_count
= 0;
12064 cleanups
= make_cleanup (xfree
, old_locations
);
12066 ALL_BREAKPOINTS (b
)
12067 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12068 bp_locations_count
++;
12070 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12071 locp
= bp_locations
;
12072 ALL_BREAKPOINTS (b
)
12073 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12075 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12076 bp_locations_compare
);
12078 bp_locations_target_extensions_update ();
12080 /* Identify bp_location instances that are no longer present in the
12081 new list, and therefore should be freed. Note that it's not
12082 necessary that those locations should be removed from inferior --
12083 if there's another location at the same address (previously
12084 marked as duplicate), we don't need to remove/insert the
12087 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12088 and former bp_location array state respectively. */
12090 locp
= bp_locations
;
12091 for (old_locp
= old_locations
;
12092 old_locp
< old_locations
+ old_locations_count
;
12095 struct bp_location
*old_loc
= *old_locp
;
12096 struct bp_location
**loc2p
;
12098 /* Tells if 'old_loc' is found among the new locations. If
12099 not, we have to free it. */
12100 int found_object
= 0;
12101 /* Tells if the location should remain inserted in the target. */
12102 int keep_in_target
= 0;
12105 /* Skip LOCP entries which will definitely never be needed.
12106 Stop either at or being the one matching OLD_LOC. */
12107 while (locp
< bp_locations
+ bp_locations_count
12108 && (*locp
)->address
< old_loc
->address
)
12112 (loc2p
< bp_locations
+ bp_locations_count
12113 && (*loc2p
)->address
== old_loc
->address
);
12116 /* Check if this is a new/duplicated location or a duplicated
12117 location that had its condition modified. If so, we want to send
12118 its condition to the target if evaluation of conditions is taking
12120 if ((*loc2p
)->condition_changed
== condition_modified
12121 && (last_addr
!= old_loc
->address
12122 || last_pspace_num
!= old_loc
->pspace
->num
))
12124 force_breakpoint_reinsertion (*loc2p
);
12125 last_pspace_num
= old_loc
->pspace
->num
;
12128 if (*loc2p
== old_loc
)
12132 /* We have already handled this address, update it so that we don't
12133 have to go through updates again. */
12134 last_addr
= old_loc
->address
;
12136 /* Target-side condition evaluation: Handle deleted locations. */
12138 force_breakpoint_reinsertion (old_loc
);
12140 /* If this location is no longer present, and inserted, look if
12141 there's maybe a new location at the same address. If so,
12142 mark that one inserted, and don't remove this one. This is
12143 needed so that we don't have a time window where a breakpoint
12144 at certain location is not inserted. */
12146 if (old_loc
->inserted
)
12148 /* If the location is inserted now, we might have to remove
12151 if (found_object
&& should_be_inserted (old_loc
))
12153 /* The location is still present in the location list,
12154 and still should be inserted. Don't do anything. */
12155 keep_in_target
= 1;
12159 /* This location still exists, but it won't be kept in the
12160 target since it may have been disabled. We proceed to
12161 remove its target-side condition. */
12163 /* The location is either no longer present, or got
12164 disabled. See if there's another location at the
12165 same address, in which case we don't need to remove
12166 this one from the target. */
12168 /* OLD_LOC comes from existing struct breakpoint. */
12169 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12172 (loc2p
< bp_locations
+ bp_locations_count
12173 && (*loc2p
)->address
== old_loc
->address
);
12176 struct bp_location
*loc2
= *loc2p
;
12178 if (breakpoint_locations_match (loc2
, old_loc
))
12180 /* Read watchpoint locations are switched to
12181 access watchpoints, if the former are not
12182 supported, but the latter are. */
12183 if (is_hardware_watchpoint (old_loc
->owner
))
12185 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12186 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12189 /* loc2 is a duplicated location. We need to check
12190 if it should be inserted in case it will be
12192 if (loc2
!= old_loc
12193 && unduplicated_should_be_inserted (loc2
))
12195 swap_insertion (old_loc
, loc2
);
12196 keep_in_target
= 1;
12204 if (!keep_in_target
)
12206 if (remove_breakpoint (old_loc
))
12208 /* This is just about all we can do. We could keep
12209 this location on the global list, and try to
12210 remove it next time, but there's no particular
12211 reason why we will succeed next time.
12213 Note that at this point, old_loc->owner is still
12214 valid, as delete_breakpoint frees the breakpoint
12215 only after calling us. */
12216 printf_filtered (_("warning: Error removing "
12217 "breakpoint %d\n"),
12218 old_loc
->owner
->number
);
12226 if (removed
&& target_is_non_stop_p ()
12227 && need_moribund_for_location_type (old_loc
))
12229 /* This location was removed from the target. In
12230 non-stop mode, a race condition is possible where
12231 we've removed a breakpoint, but stop events for that
12232 breakpoint are already queued and will arrive later.
12233 We apply an heuristic to be able to distinguish such
12234 SIGTRAPs from other random SIGTRAPs: we keep this
12235 breakpoint location for a bit, and will retire it
12236 after we see some number of events. The theory here
12237 is that reporting of events should, "on the average",
12238 be fair, so after a while we'll see events from all
12239 threads that have anything of interest, and no longer
12240 need to keep this breakpoint location around. We
12241 don't hold locations forever so to reduce chances of
12242 mistaking a non-breakpoint SIGTRAP for a breakpoint
12245 The heuristic failing can be disastrous on
12246 decr_pc_after_break targets.
12248 On decr_pc_after_break targets, like e.g., x86-linux,
12249 if we fail to recognize a late breakpoint SIGTRAP,
12250 because events_till_retirement has reached 0 too
12251 soon, we'll fail to do the PC adjustment, and report
12252 a random SIGTRAP to the user. When the user resumes
12253 the inferior, it will most likely immediately crash
12254 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12255 corrupted, because of being resumed e.g., in the
12256 middle of a multi-byte instruction, or skipped a
12257 one-byte instruction. This was actually seen happen
12258 on native x86-linux, and should be less rare on
12259 targets that do not support new thread events, like
12260 remote, due to the heuristic depending on
12263 Mistaking a random SIGTRAP for a breakpoint trap
12264 causes similar symptoms (PC adjustment applied when
12265 it shouldn't), but then again, playing with SIGTRAPs
12266 behind the debugger's back is asking for trouble.
12268 Since hardware watchpoint traps are always
12269 distinguishable from other traps, so we don't need to
12270 apply keep hardware watchpoint moribund locations
12271 around. We simply always ignore hardware watchpoint
12272 traps we can no longer explain. */
12274 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12275 old_loc
->owner
= NULL
;
12277 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12281 old_loc
->owner
= NULL
;
12282 decref_bp_location (&old_loc
);
12287 /* Rescan breakpoints at the same address and section, marking the
12288 first one as "first" and any others as "duplicates". This is so
12289 that the bpt instruction is only inserted once. If we have a
12290 permanent breakpoint at the same place as BPT, make that one the
12291 official one, and the rest as duplicates. Permanent breakpoints
12292 are sorted first for the same address.
12294 Do the same for hardware watchpoints, but also considering the
12295 watchpoint's type (regular/access/read) and length. */
12297 bp_loc_first
= NULL
;
12298 wp_loc_first
= NULL
;
12299 awp_loc_first
= NULL
;
12300 rwp_loc_first
= NULL
;
12301 ALL_BP_LOCATIONS (loc
, locp
)
12303 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12305 struct bp_location
**loc_first_p
;
12308 if (!unduplicated_should_be_inserted (loc
)
12309 || !breakpoint_address_is_meaningful (b
)
12310 /* Don't detect duplicate for tracepoint locations because they are
12311 never duplicated. See the comments in field `duplicate' of
12312 `struct bp_location'. */
12313 || is_tracepoint (b
))
12315 /* Clear the condition modification flag. */
12316 loc
->condition_changed
= condition_unchanged
;
12320 if (b
->type
== bp_hardware_watchpoint
)
12321 loc_first_p
= &wp_loc_first
;
12322 else if (b
->type
== bp_read_watchpoint
)
12323 loc_first_p
= &rwp_loc_first
;
12324 else if (b
->type
== bp_access_watchpoint
)
12325 loc_first_p
= &awp_loc_first
;
12327 loc_first_p
= &bp_loc_first
;
12329 if (*loc_first_p
== NULL
12330 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12331 || !breakpoint_locations_match (loc
, *loc_first_p
))
12333 *loc_first_p
= loc
;
12334 loc
->duplicate
= 0;
12336 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12338 loc
->needs_update
= 1;
12339 /* Clear the condition modification flag. */
12340 loc
->condition_changed
= condition_unchanged
;
12346 /* This and the above ensure the invariant that the first location
12347 is not duplicated, and is the inserted one.
12348 All following are marked as duplicated, and are not inserted. */
12350 swap_insertion (loc
, *loc_first_p
);
12351 loc
->duplicate
= 1;
12353 /* Clear the condition modification flag. */
12354 loc
->condition_changed
= condition_unchanged
;
12357 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12359 if (insert_mode
!= UGLL_DONT_INSERT
)
12360 insert_breakpoint_locations ();
12363 /* Even though the caller told us to not insert new
12364 locations, we may still need to update conditions on the
12365 target's side of breakpoints that were already inserted
12366 if the target is evaluating breakpoint conditions. We
12367 only update conditions for locations that are marked
12369 update_inserted_breakpoint_locations ();
12373 if (insert_mode
!= UGLL_DONT_INSERT
)
12374 download_tracepoint_locations ();
12376 do_cleanups (cleanups
);
12380 breakpoint_retire_moribund (void)
12382 struct bp_location
*loc
;
12385 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12386 if (--(loc
->events_till_retirement
) == 0)
12388 decref_bp_location (&loc
);
12389 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12395 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12400 update_global_location_list (insert_mode
);
12402 CATCH (e
, RETURN_MASK_ERROR
)
12408 /* Clear BKP from a BPS. */
12411 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12415 for (bs
= bps
; bs
; bs
= bs
->next
)
12416 if (bs
->breakpoint_at
== bpt
)
12418 bs
->breakpoint_at
= NULL
;
12419 bs
->old_val
= NULL
;
12420 /* bs->commands will be freed later. */
12424 /* Callback for iterate_over_threads. */
12426 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12428 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12430 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12434 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12438 say_where (struct breakpoint
*b
)
12440 struct value_print_options opts
;
12442 get_user_print_options (&opts
);
12444 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12446 if (b
->loc
== NULL
)
12448 /* For pending locations, the output differs slightly based
12449 on b->extra_string. If this is non-NULL, it contains either
12450 a condition or dprintf arguments. */
12451 if (b
->extra_string
== NULL
)
12453 printf_filtered (_(" (%s) pending."),
12454 event_location_to_string (b
->location
.get ()));
12456 else if (b
->type
== bp_dprintf
)
12458 printf_filtered (_(" (%s,%s) pending."),
12459 event_location_to_string (b
->location
.get ()),
12464 printf_filtered (_(" (%s %s) pending."),
12465 event_location_to_string (b
->location
.get ()),
12471 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12473 printf_filtered (" at ");
12474 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12477 if (b
->loc
->symtab
!= NULL
)
12479 /* If there is a single location, we can print the location
12481 if (b
->loc
->next
== NULL
)
12482 printf_filtered (": file %s, line %d.",
12483 symtab_to_filename_for_display (b
->loc
->symtab
),
12484 b
->loc
->line_number
);
12486 /* This is not ideal, but each location may have a
12487 different file name, and this at least reflects the
12488 real situation somewhat. */
12489 printf_filtered (": %s.",
12490 event_location_to_string (b
->location
.get ()));
12495 struct bp_location
*loc
= b
->loc
;
12497 for (; loc
; loc
= loc
->next
)
12499 printf_filtered (" (%d locations)", n
);
12504 /* Default bp_location_ops methods. */
12507 bp_location_dtor (struct bp_location
*self
)
12509 xfree (self
->function_name
);
12512 static const struct bp_location_ops bp_location_ops
=
12517 /* Destructor for the breakpoint base class. */
12519 breakpoint::~breakpoint ()
12521 xfree (this->cond_string
);
12522 xfree (this->extra_string
);
12523 xfree (this->filter
);
12526 static struct bp_location
*
12527 base_breakpoint_allocate_location (struct breakpoint
*self
)
12529 return new bp_location (&bp_location_ops
, self
);
12533 base_breakpoint_re_set (struct breakpoint
*b
)
12535 /* Nothing to re-set. */
12538 #define internal_error_pure_virtual_called() \
12539 gdb_assert_not_reached ("pure virtual function called")
12542 base_breakpoint_insert_location (struct bp_location
*bl
)
12544 internal_error_pure_virtual_called ();
12548 base_breakpoint_remove_location (struct bp_location
*bl
,
12549 enum remove_bp_reason reason
)
12551 internal_error_pure_virtual_called ();
12555 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12556 struct address_space
*aspace
,
12558 const struct target_waitstatus
*ws
)
12560 internal_error_pure_virtual_called ();
12564 base_breakpoint_check_status (bpstat bs
)
12569 /* A "works_in_software_mode" breakpoint_ops method that just internal
12573 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12575 internal_error_pure_virtual_called ();
12578 /* A "resources_needed" breakpoint_ops method that just internal
12582 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12584 internal_error_pure_virtual_called ();
12587 static enum print_stop_action
12588 base_breakpoint_print_it (bpstat bs
)
12590 internal_error_pure_virtual_called ();
12594 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12595 struct ui_out
*uiout
)
12601 base_breakpoint_print_mention (struct breakpoint
*b
)
12603 internal_error_pure_virtual_called ();
12607 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12609 internal_error_pure_virtual_called ();
12613 base_breakpoint_create_sals_from_location
12614 (const struct event_location
*location
,
12615 struct linespec_result
*canonical
,
12616 enum bptype type_wanted
)
12618 internal_error_pure_virtual_called ();
12622 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12623 struct linespec_result
*c
,
12624 gdb::unique_xmalloc_ptr
<char> cond_string
,
12625 gdb::unique_xmalloc_ptr
<char> extra_string
,
12626 enum bptype type_wanted
,
12627 enum bpdisp disposition
,
12629 int task
, int ignore_count
,
12630 const struct breakpoint_ops
*o
,
12631 int from_tty
, int enabled
,
12632 int internal
, unsigned flags
)
12634 internal_error_pure_virtual_called ();
12637 static std::vector
<symtab_and_line
>
12638 base_breakpoint_decode_location (struct breakpoint
*b
,
12639 const struct event_location
*location
,
12640 struct program_space
*search_pspace
)
12642 internal_error_pure_virtual_called ();
12645 /* The default 'explains_signal' method. */
12648 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12653 /* The default "after_condition_true" method. */
12656 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12658 /* Nothing to do. */
12661 struct breakpoint_ops base_breakpoint_ops
=
12663 base_breakpoint_allocate_location
,
12664 base_breakpoint_re_set
,
12665 base_breakpoint_insert_location
,
12666 base_breakpoint_remove_location
,
12667 base_breakpoint_breakpoint_hit
,
12668 base_breakpoint_check_status
,
12669 base_breakpoint_resources_needed
,
12670 base_breakpoint_works_in_software_mode
,
12671 base_breakpoint_print_it
,
12673 base_breakpoint_print_one_detail
,
12674 base_breakpoint_print_mention
,
12675 base_breakpoint_print_recreate
,
12676 base_breakpoint_create_sals_from_location
,
12677 base_breakpoint_create_breakpoints_sal
,
12678 base_breakpoint_decode_location
,
12679 base_breakpoint_explains_signal
,
12680 base_breakpoint_after_condition_true
,
12683 /* Default breakpoint_ops methods. */
12686 bkpt_re_set (struct breakpoint
*b
)
12688 /* FIXME: is this still reachable? */
12689 if (breakpoint_event_location_empty_p (b
))
12691 /* Anything without a location can't be re-set. */
12692 delete_breakpoint (b
);
12696 breakpoint_re_set_default (b
);
12700 bkpt_insert_location (struct bp_location
*bl
)
12702 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12704 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12705 bl
->target_info
.placed_address
= addr
;
12707 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12708 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12710 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12714 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12716 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12717 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12719 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12723 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12724 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12725 const struct target_waitstatus
*ws
)
12727 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12728 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12731 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12735 if (overlay_debugging
/* unmapped overlay section */
12736 && section_is_overlay (bl
->section
)
12737 && !section_is_mapped (bl
->section
))
12744 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12745 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12746 const struct target_waitstatus
*ws
)
12748 if (dprintf_style
== dprintf_style_agent
12749 && target_can_run_breakpoint_commands ())
12751 /* An agent-style dprintf never causes a stop. If we see a trap
12752 for this address it must be for a breakpoint that happens to
12753 be set at the same address. */
12757 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12761 bkpt_resources_needed (const struct bp_location
*bl
)
12763 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12768 static enum print_stop_action
12769 bkpt_print_it (bpstat bs
)
12771 struct breakpoint
*b
;
12772 const struct bp_location
*bl
;
12774 struct ui_out
*uiout
= current_uiout
;
12776 gdb_assert (bs
->bp_location_at
!= NULL
);
12778 bl
= bs
->bp_location_at
;
12779 b
= bs
->breakpoint_at
;
12781 bp_temp
= b
->disposition
== disp_del
;
12782 if (bl
->address
!= bl
->requested_address
)
12783 breakpoint_adjustment_warning (bl
->requested_address
,
12786 annotate_breakpoint (b
->number
);
12787 maybe_print_thread_hit_breakpoint (uiout
);
12790 uiout
->text ("Temporary breakpoint ");
12792 uiout
->text ("Breakpoint ");
12793 if (uiout
->is_mi_like_p ())
12795 uiout
->field_string ("reason",
12796 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12797 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12799 uiout
->field_int ("bkptno", b
->number
);
12800 uiout
->text (", ");
12802 return PRINT_SRC_AND_LOC
;
12806 bkpt_print_mention (struct breakpoint
*b
)
12808 if (current_uiout
->is_mi_like_p ())
12813 case bp_breakpoint
:
12814 case bp_gnu_ifunc_resolver
:
12815 if (b
->disposition
== disp_del
)
12816 printf_filtered (_("Temporary breakpoint"));
12818 printf_filtered (_("Breakpoint"));
12819 printf_filtered (_(" %d"), b
->number
);
12820 if (b
->type
== bp_gnu_ifunc_resolver
)
12821 printf_filtered (_(" at gnu-indirect-function resolver"));
12823 case bp_hardware_breakpoint
:
12824 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12827 printf_filtered (_("Dprintf %d"), b
->number
);
12835 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12837 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12838 fprintf_unfiltered (fp
, "tbreak");
12839 else if (tp
->type
== bp_breakpoint
)
12840 fprintf_unfiltered (fp
, "break");
12841 else if (tp
->type
== bp_hardware_breakpoint
12842 && tp
->disposition
== disp_del
)
12843 fprintf_unfiltered (fp
, "thbreak");
12844 else if (tp
->type
== bp_hardware_breakpoint
)
12845 fprintf_unfiltered (fp
, "hbreak");
12847 internal_error (__FILE__
, __LINE__
,
12848 _("unhandled breakpoint type %d"), (int) tp
->type
);
12850 fprintf_unfiltered (fp
, " %s",
12851 event_location_to_string (tp
->location
.get ()));
12853 /* Print out extra_string if this breakpoint is pending. It might
12854 contain, for example, conditions that were set by the user. */
12855 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12856 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12858 print_recreate_thread (tp
, fp
);
12862 bkpt_create_sals_from_location (const struct event_location
*location
,
12863 struct linespec_result
*canonical
,
12864 enum bptype type_wanted
)
12866 create_sals_from_location_default (location
, canonical
, type_wanted
);
12870 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12871 struct linespec_result
*canonical
,
12872 gdb::unique_xmalloc_ptr
<char> cond_string
,
12873 gdb::unique_xmalloc_ptr
<char> extra_string
,
12874 enum bptype type_wanted
,
12875 enum bpdisp disposition
,
12877 int task
, int ignore_count
,
12878 const struct breakpoint_ops
*ops
,
12879 int from_tty
, int enabled
,
12880 int internal
, unsigned flags
)
12882 create_breakpoints_sal_default (gdbarch
, canonical
,
12883 std::move (cond_string
),
12884 std::move (extra_string
),
12886 disposition
, thread
, task
,
12887 ignore_count
, ops
, from_tty
,
12888 enabled
, internal
, flags
);
12891 static std::vector
<symtab_and_line
>
12892 bkpt_decode_location (struct breakpoint
*b
,
12893 const struct event_location
*location
,
12894 struct program_space
*search_pspace
)
12896 return decode_location_default (b
, location
, search_pspace
);
12899 /* Virtual table for internal breakpoints. */
12902 internal_bkpt_re_set (struct breakpoint
*b
)
12906 /* Delete overlay event and longjmp master breakpoints; they
12907 will be reset later by breakpoint_re_set. */
12908 case bp_overlay_event
:
12909 case bp_longjmp_master
:
12910 case bp_std_terminate_master
:
12911 case bp_exception_master
:
12912 delete_breakpoint (b
);
12915 /* This breakpoint is special, it's set up when the inferior
12916 starts and we really don't want to touch it. */
12917 case bp_shlib_event
:
12919 /* Like bp_shlib_event, this breakpoint type is special. Once
12920 it is set up, we do not want to touch it. */
12921 case bp_thread_event
:
12927 internal_bkpt_check_status (bpstat bs
)
12929 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12931 /* If requested, stop when the dynamic linker notifies GDB of
12932 events. This allows the user to get control and place
12933 breakpoints in initializer routines for dynamically loaded
12934 objects (among other things). */
12935 bs
->stop
= stop_on_solib_events
;
12936 bs
->print
= stop_on_solib_events
;
12942 static enum print_stop_action
12943 internal_bkpt_print_it (bpstat bs
)
12945 struct breakpoint
*b
;
12947 b
= bs
->breakpoint_at
;
12951 case bp_shlib_event
:
12952 /* Did we stop because the user set the stop_on_solib_events
12953 variable? (If so, we report this as a generic, "Stopped due
12954 to shlib event" message.) */
12955 print_solib_event (0);
12958 case bp_thread_event
:
12959 /* Not sure how we will get here.
12960 GDB should not stop for these breakpoints. */
12961 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12964 case bp_overlay_event
:
12965 /* By analogy with the thread event, GDB should not stop for these. */
12966 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12969 case bp_longjmp_master
:
12970 /* These should never be enabled. */
12971 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12974 case bp_std_terminate_master
:
12975 /* These should never be enabled. */
12976 printf_filtered (_("std::terminate Master Breakpoint: "
12977 "gdb should not stop!\n"));
12980 case bp_exception_master
:
12981 /* These should never be enabled. */
12982 printf_filtered (_("Exception Master Breakpoint: "
12983 "gdb should not stop!\n"));
12987 return PRINT_NOTHING
;
12991 internal_bkpt_print_mention (struct breakpoint
*b
)
12993 /* Nothing to mention. These breakpoints are internal. */
12996 /* Virtual table for momentary breakpoints */
12999 momentary_bkpt_re_set (struct breakpoint
*b
)
13001 /* Keep temporary breakpoints, which can be encountered when we step
13002 over a dlopen call and solib_add is resetting the breakpoints.
13003 Otherwise these should have been blown away via the cleanup chain
13004 or by breakpoint_init_inferior when we rerun the executable. */
13008 momentary_bkpt_check_status (bpstat bs
)
13010 /* Nothing. The point of these breakpoints is causing a stop. */
13013 static enum print_stop_action
13014 momentary_bkpt_print_it (bpstat bs
)
13016 return PRINT_UNKNOWN
;
13020 momentary_bkpt_print_mention (struct breakpoint
*b
)
13022 /* Nothing to mention. These breakpoints are internal. */
13025 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13027 It gets cleared already on the removal of the first one of such placed
13028 breakpoints. This is OK as they get all removed altogether. */
13030 longjmp_breakpoint::~longjmp_breakpoint ()
13032 thread_info
*tp
= find_thread_global_id (this->thread
);
13035 tp
->initiating_frame
= null_frame_id
;
13038 /* Specific methods for probe breakpoints. */
13041 bkpt_probe_insert_location (struct bp_location
*bl
)
13043 int v
= bkpt_insert_location (bl
);
13047 /* The insertion was successful, now let's set the probe's semaphore
13049 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13050 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13059 bkpt_probe_remove_location (struct bp_location
*bl
,
13060 enum remove_bp_reason reason
)
13062 /* Let's clear the semaphore before removing the location. */
13063 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13064 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13068 return bkpt_remove_location (bl
, reason
);
13072 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13073 struct linespec_result
*canonical
,
13074 enum bptype type_wanted
)
13076 struct linespec_sals lsal
;
13078 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13080 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13081 canonical
->lsals
.push_back (std::move (lsal
));
13084 static std::vector
<symtab_and_line
>
13085 bkpt_probe_decode_location (struct breakpoint
*b
,
13086 const struct event_location
*location
,
13087 struct program_space
*search_pspace
)
13089 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
13091 error (_("probe not found"));
13095 /* The breakpoint_ops structure to be used in tracepoints. */
13098 tracepoint_re_set (struct breakpoint
*b
)
13100 breakpoint_re_set_default (b
);
13104 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13105 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13106 const struct target_waitstatus
*ws
)
13108 /* By definition, the inferior does not report stops at
13114 tracepoint_print_one_detail (const struct breakpoint
*self
,
13115 struct ui_out
*uiout
)
13117 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13118 if (tp
->static_trace_marker_id
)
13120 gdb_assert (self
->type
== bp_static_tracepoint
);
13122 uiout
->text ("\tmarker id is ");
13123 uiout
->field_string ("static-tracepoint-marker-string-id",
13124 tp
->static_trace_marker_id
);
13125 uiout
->text ("\n");
13130 tracepoint_print_mention (struct breakpoint
*b
)
13132 if (current_uiout
->is_mi_like_p ())
13137 case bp_tracepoint
:
13138 printf_filtered (_("Tracepoint"));
13139 printf_filtered (_(" %d"), b
->number
);
13141 case bp_fast_tracepoint
:
13142 printf_filtered (_("Fast tracepoint"));
13143 printf_filtered (_(" %d"), b
->number
);
13145 case bp_static_tracepoint
:
13146 printf_filtered (_("Static tracepoint"));
13147 printf_filtered (_(" %d"), b
->number
);
13150 internal_error (__FILE__
, __LINE__
,
13151 _("unhandled tracepoint type %d"), (int) b
->type
);
13158 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13160 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13162 if (self
->type
== bp_fast_tracepoint
)
13163 fprintf_unfiltered (fp
, "ftrace");
13164 else if (self
->type
== bp_static_tracepoint
)
13165 fprintf_unfiltered (fp
, "strace");
13166 else if (self
->type
== bp_tracepoint
)
13167 fprintf_unfiltered (fp
, "trace");
13169 internal_error (__FILE__
, __LINE__
,
13170 _("unhandled tracepoint type %d"), (int) self
->type
);
13172 fprintf_unfiltered (fp
, " %s",
13173 event_location_to_string (self
->location
.get ()));
13174 print_recreate_thread (self
, fp
);
13176 if (tp
->pass_count
)
13177 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13181 tracepoint_create_sals_from_location (const struct event_location
*location
,
13182 struct linespec_result
*canonical
,
13183 enum bptype type_wanted
)
13185 create_sals_from_location_default (location
, canonical
, type_wanted
);
13189 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13190 struct linespec_result
*canonical
,
13191 gdb::unique_xmalloc_ptr
<char> cond_string
,
13192 gdb::unique_xmalloc_ptr
<char> extra_string
,
13193 enum bptype type_wanted
,
13194 enum bpdisp disposition
,
13196 int task
, int ignore_count
,
13197 const struct breakpoint_ops
*ops
,
13198 int from_tty
, int enabled
,
13199 int internal
, unsigned flags
)
13201 create_breakpoints_sal_default (gdbarch
, canonical
,
13202 std::move (cond_string
),
13203 std::move (extra_string
),
13205 disposition
, thread
, task
,
13206 ignore_count
, ops
, from_tty
,
13207 enabled
, internal
, flags
);
13210 static std::vector
<symtab_and_line
>
13211 tracepoint_decode_location (struct breakpoint
*b
,
13212 const struct event_location
*location
,
13213 struct program_space
*search_pspace
)
13215 return decode_location_default (b
, location
, search_pspace
);
13218 struct breakpoint_ops tracepoint_breakpoint_ops
;
13220 /* The breakpoint_ops structure to be use on tracepoints placed in a
13224 tracepoint_probe_create_sals_from_location
13225 (const struct event_location
*location
,
13226 struct linespec_result
*canonical
,
13227 enum bptype type_wanted
)
13229 /* We use the same method for breakpoint on probes. */
13230 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13233 static std::vector
<symtab_and_line
>
13234 tracepoint_probe_decode_location (struct breakpoint
*b
,
13235 const struct event_location
*location
,
13236 struct program_space
*search_pspace
)
13238 /* We use the same method for breakpoint on probes. */
13239 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13242 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13244 /* Dprintf breakpoint_ops methods. */
13247 dprintf_re_set (struct breakpoint
*b
)
13249 breakpoint_re_set_default (b
);
13251 /* extra_string should never be non-NULL for dprintf. */
13252 gdb_assert (b
->extra_string
!= NULL
);
13254 /* 1 - connect to target 1, that can run breakpoint commands.
13255 2 - create a dprintf, which resolves fine.
13256 3 - disconnect from target 1
13257 4 - connect to target 2, that can NOT run breakpoint commands.
13259 After steps #3/#4, you'll want the dprintf command list to
13260 be updated, because target 1 and 2 may well return different
13261 answers for target_can_run_breakpoint_commands().
13262 Given absence of finer grained resetting, we get to do
13263 it all the time. */
13264 if (b
->extra_string
!= NULL
)
13265 update_dprintf_command_list (b
);
13268 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13271 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13273 fprintf_unfiltered (fp
, "dprintf %s,%s",
13274 event_location_to_string (tp
->location
.get ()),
13276 print_recreate_thread (tp
, fp
);
13279 /* Implement the "after_condition_true" breakpoint_ops method for
13282 dprintf's are implemented with regular commands in their command
13283 list, but we run the commands here instead of before presenting the
13284 stop to the user, as dprintf's don't actually cause a stop. This
13285 also makes it so that the commands of multiple dprintfs at the same
13286 address are all handled. */
13289 dprintf_after_condition_true (struct bpstats
*bs
)
13291 struct bpstats tmp_bs
;
13292 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13294 /* dprintf's never cause a stop. This wasn't set in the
13295 check_status hook instead because that would make the dprintf's
13296 condition not be evaluated. */
13299 /* Run the command list here. Take ownership of it instead of
13300 copying. We never want these commands to run later in
13301 bpstat_do_actions, if a breakpoint that causes a stop happens to
13302 be set at same address as this dprintf, or even if running the
13303 commands here throws. */
13304 tmp_bs
.commands
= bs
->commands
;
13305 bs
->commands
= NULL
;
13307 bpstat_do_actions_1 (&tmp_bs_p
);
13309 /* 'tmp_bs.commands' will usually be NULL by now, but
13310 bpstat_do_actions_1 may return early without processing the whole
13314 /* The breakpoint_ops structure to be used on static tracepoints with
13318 strace_marker_create_sals_from_location (const struct event_location
*location
,
13319 struct linespec_result
*canonical
,
13320 enum bptype type_wanted
)
13322 struct linespec_sals lsal
;
13323 const char *arg_start
, *arg
;
13325 arg
= arg_start
= get_linespec_location (location
);
13326 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13328 std::string
str (arg_start
, arg
- arg_start
);
13329 const char *ptr
= str
.c_str ();
13330 canonical
->location
= new_linespec_location (&ptr
);
13333 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13334 canonical
->lsals
.push_back (std::move (lsal
));
13338 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13339 struct linespec_result
*canonical
,
13340 gdb::unique_xmalloc_ptr
<char> cond_string
,
13341 gdb::unique_xmalloc_ptr
<char> extra_string
,
13342 enum bptype type_wanted
,
13343 enum bpdisp disposition
,
13345 int task
, int ignore_count
,
13346 const struct breakpoint_ops
*ops
,
13347 int from_tty
, int enabled
,
13348 int internal
, unsigned flags
)
13350 const linespec_sals
&lsal
= canonical
->lsals
[0];
13352 /* If the user is creating a static tracepoint by marker id
13353 (strace -m MARKER_ID), then store the sals index, so that
13354 breakpoint_re_set can try to match up which of the newly
13355 found markers corresponds to this one, and, don't try to
13356 expand multiple locations for each sal, given than SALS
13357 already should contain all sals for MARKER_ID. */
13359 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13361 event_location_up location
13362 = copy_event_location (canonical
->location
.get ());
13364 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13365 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13366 std::move (location
), NULL
,
13367 std::move (cond_string
),
13368 std::move (extra_string
),
13369 type_wanted
, disposition
,
13370 thread
, task
, ignore_count
, ops
,
13371 from_tty
, enabled
, internal
, flags
,
13372 canonical
->special_display
);
13373 /* Given that its possible to have multiple markers with
13374 the same string id, if the user is creating a static
13375 tracepoint by marker id ("strace -m MARKER_ID"), then
13376 store the sals index, so that breakpoint_re_set can
13377 try to match up which of the newly found markers
13378 corresponds to this one */
13379 tp
->static_trace_marker_id_idx
= i
;
13381 install_breakpoint (internal
, std::move (tp
), 0);
13385 static std::vector
<symtab_and_line
>
13386 strace_marker_decode_location (struct breakpoint
*b
,
13387 const struct event_location
*location
,
13388 struct program_space
*search_pspace
)
13390 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13391 const char *s
= get_linespec_location (location
);
13393 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13394 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13396 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13401 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13404 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13407 strace_marker_p (struct breakpoint
*b
)
13409 return b
->ops
== &strace_marker_breakpoint_ops
;
13412 /* Delete a breakpoint and clean up all traces of it in the data
13416 delete_breakpoint (struct breakpoint
*bpt
)
13418 struct breakpoint
*b
;
13420 gdb_assert (bpt
!= NULL
);
13422 /* Has this bp already been deleted? This can happen because
13423 multiple lists can hold pointers to bp's. bpstat lists are
13426 One example of this happening is a watchpoint's scope bp. When
13427 the scope bp triggers, we notice that the watchpoint is out of
13428 scope, and delete it. We also delete its scope bp. But the
13429 scope bp is marked "auto-deleting", and is already on a bpstat.
13430 That bpstat is then checked for auto-deleting bp's, which are
13433 A real solution to this problem might involve reference counts in
13434 bp's, and/or giving them pointers back to their referencing
13435 bpstat's, and teaching delete_breakpoint to only free a bp's
13436 storage when no more references were extent. A cheaper bandaid
13438 if (bpt
->type
== bp_none
)
13441 /* At least avoid this stale reference until the reference counting
13442 of breakpoints gets resolved. */
13443 if (bpt
->related_breakpoint
!= bpt
)
13445 struct breakpoint
*related
;
13446 struct watchpoint
*w
;
13448 if (bpt
->type
== bp_watchpoint_scope
)
13449 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13450 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13451 w
= (struct watchpoint
*) bpt
;
13455 watchpoint_del_at_next_stop (w
);
13457 /* Unlink bpt from the bpt->related_breakpoint ring. */
13458 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13459 related
= related
->related_breakpoint
);
13460 related
->related_breakpoint
= bpt
->related_breakpoint
;
13461 bpt
->related_breakpoint
= bpt
;
13464 /* watch_command_1 creates a watchpoint but only sets its number if
13465 update_watchpoint succeeds in creating its bp_locations. If there's
13466 a problem in that process, we'll be asked to delete the half-created
13467 watchpoint. In that case, don't announce the deletion. */
13469 observer_notify_breakpoint_deleted (bpt
);
13471 if (breakpoint_chain
== bpt
)
13472 breakpoint_chain
= bpt
->next
;
13474 ALL_BREAKPOINTS (b
)
13475 if (b
->next
== bpt
)
13477 b
->next
= bpt
->next
;
13481 /* Be sure no bpstat's are pointing at the breakpoint after it's
13483 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13484 in all threads for now. Note that we cannot just remove bpstats
13485 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13486 commands are associated with the bpstat; if we remove it here,
13487 then the later call to bpstat_do_actions (&stop_bpstat); in
13488 event-top.c won't do anything, and temporary breakpoints with
13489 commands won't work. */
13491 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13493 /* Now that breakpoint is removed from breakpoint list, update the
13494 global location list. This will remove locations that used to
13495 belong to this breakpoint. Do this before freeing the breakpoint
13496 itself, since remove_breakpoint looks at location's owner. It
13497 might be better design to have location completely
13498 self-contained, but it's not the case now. */
13499 update_global_location_list (UGLL_DONT_INSERT
);
13501 /* On the chance that someone will soon try again to delete this
13502 same bp, we mark it as deleted before freeing its storage. */
13503 bpt
->type
= bp_none
;
13508 do_delete_breakpoint_cleanup (void *b
)
13510 delete_breakpoint ((struct breakpoint
*) b
);
13514 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13516 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13519 /* Iterator function to call a user-provided callback function once
13520 for each of B and its related breakpoints. */
13523 iterate_over_related_breakpoints (struct breakpoint
*b
,
13524 gdb::function_view
<void (breakpoint
*)> function
)
13526 struct breakpoint
*related
;
13531 struct breakpoint
*next
;
13533 /* FUNCTION may delete RELATED. */
13534 next
= related
->related_breakpoint
;
13536 if (next
== related
)
13538 /* RELATED is the last ring entry. */
13539 function (related
);
13541 /* FUNCTION may have deleted it, so we'd never reach back to
13542 B. There's nothing left to do anyway, so just break
13547 function (related
);
13551 while (related
!= b
);
13555 delete_command (char *arg
, int from_tty
)
13557 struct breakpoint
*b
, *b_tmp
;
13563 int breaks_to_delete
= 0;
13565 /* Delete all breakpoints if no argument. Do not delete
13566 internal breakpoints, these have to be deleted with an
13567 explicit breakpoint number argument. */
13568 ALL_BREAKPOINTS (b
)
13569 if (user_breakpoint_p (b
))
13571 breaks_to_delete
= 1;
13575 /* Ask user only if there are some breakpoints to delete. */
13577 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13579 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13580 if (user_breakpoint_p (b
))
13581 delete_breakpoint (b
);
13585 map_breakpoint_numbers
13586 (arg
, [&] (breakpoint
*b
)
13588 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13592 /* Return true if all locations of B bound to PSPACE are pending. If
13593 PSPACE is NULL, all locations of all program spaces are
13597 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13599 struct bp_location
*loc
;
13601 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13602 if ((pspace
== NULL
13603 || loc
->pspace
== pspace
)
13604 && !loc
->shlib_disabled
13605 && !loc
->pspace
->executing_startup
)
13610 /* Subroutine of update_breakpoint_locations to simplify it.
13611 Return non-zero if multiple fns in list LOC have the same name.
13612 Null names are ignored. */
13615 ambiguous_names_p (struct bp_location
*loc
)
13617 struct bp_location
*l
;
13618 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13619 (int (*) (const void *,
13620 const void *)) streq
,
13621 NULL
, xcalloc
, xfree
);
13623 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13626 const char *name
= l
->function_name
;
13628 /* Allow for some names to be NULL, ignore them. */
13632 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13634 /* NOTE: We can assume slot != NULL here because xcalloc never
13638 htab_delete (htab
);
13644 htab_delete (htab
);
13648 /* When symbols change, it probably means the sources changed as well,
13649 and it might mean the static tracepoint markers are no longer at
13650 the same address or line numbers they used to be at last we
13651 checked. Losing your static tracepoints whenever you rebuild is
13652 undesirable. This function tries to resync/rematch gdb static
13653 tracepoints with the markers on the target, for static tracepoints
13654 that have not been set by marker id. Static tracepoint that have
13655 been set by marker id are reset by marker id in breakpoint_re_set.
13658 1) For a tracepoint set at a specific address, look for a marker at
13659 the old PC. If one is found there, assume to be the same marker.
13660 If the name / string id of the marker found is different from the
13661 previous known name, assume that means the user renamed the marker
13662 in the sources, and output a warning.
13664 2) For a tracepoint set at a given line number, look for a marker
13665 at the new address of the old line number. If one is found there,
13666 assume to be the same marker. If the name / string id of the
13667 marker found is different from the previous known name, assume that
13668 means the user renamed the marker in the sources, and output a
13671 3) If a marker is no longer found at the same address or line, it
13672 may mean the marker no longer exists. But it may also just mean
13673 the code changed a bit. Maybe the user added a few lines of code
13674 that made the marker move up or down (in line number terms). Ask
13675 the target for info about the marker with the string id as we knew
13676 it. If found, update line number and address in the matching
13677 static tracepoint. This will get confused if there's more than one
13678 marker with the same ID (possible in UST, although unadvised
13679 precisely because it confuses tools). */
13681 static struct symtab_and_line
13682 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13684 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13685 struct static_tracepoint_marker marker
;
13690 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13692 if (target_static_tracepoint_marker_at (pc
, &marker
))
13694 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13695 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13697 tp
->static_trace_marker_id
, marker
.str_id
);
13699 xfree (tp
->static_trace_marker_id
);
13700 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13701 release_static_tracepoint_marker (&marker
);
13706 /* Old marker wasn't found on target at lineno. Try looking it up
13708 if (!sal
.explicit_pc
13710 && sal
.symtab
!= NULL
13711 && tp
->static_trace_marker_id
!= NULL
)
13713 VEC(static_tracepoint_marker_p
) *markers
;
13716 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13718 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13720 struct symbol
*sym
;
13721 struct static_tracepoint_marker
*tpmarker
;
13722 struct ui_out
*uiout
= current_uiout
;
13723 struct explicit_location explicit_loc
;
13725 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13727 xfree (tp
->static_trace_marker_id
);
13728 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13730 warning (_("marker for static tracepoint %d (%s) not "
13731 "found at previous line number"),
13732 b
->number
, tp
->static_trace_marker_id
);
13734 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13735 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13736 uiout
->text ("Now in ");
13739 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13740 uiout
->text (" at ");
13742 uiout
->field_string ("file",
13743 symtab_to_filename_for_display (sal2
.symtab
));
13746 if (uiout
->is_mi_like_p ())
13748 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13750 uiout
->field_string ("fullname", fullname
);
13753 uiout
->field_int ("line", sal2
.line
);
13754 uiout
->text ("\n");
13756 b
->loc
->line_number
= sal2
.line
;
13757 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13759 b
->location
.reset (NULL
);
13760 initialize_explicit_location (&explicit_loc
);
13761 explicit_loc
.source_filename
13762 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13763 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13764 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13765 b
->location
= new_explicit_location (&explicit_loc
);
13767 /* Might be nice to check if function changed, and warn if
13770 release_static_tracepoint_marker (tpmarker
);
13776 /* Returns 1 iff locations A and B are sufficiently same that
13777 we don't need to report breakpoint as changed. */
13780 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13784 if (a
->address
!= b
->address
)
13787 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13790 if (a
->enabled
!= b
->enabled
)
13797 if ((a
== NULL
) != (b
== NULL
))
13803 /* Split all locations of B that are bound to PSPACE out of B's
13804 location list to a separate list and return that list's head. If
13805 PSPACE is NULL, hoist out all locations of B. */
13807 static struct bp_location
*
13808 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13810 struct bp_location head
;
13811 struct bp_location
*i
= b
->loc
;
13812 struct bp_location
**i_link
= &b
->loc
;
13813 struct bp_location
*hoisted
= &head
;
13815 if (pspace
== NULL
)
13826 if (i
->pspace
== pspace
)
13841 /* Create new breakpoint locations for B (a hardware or software
13842 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13843 zero, then B is a ranged breakpoint. Only recreates locations for
13844 FILTER_PSPACE. Locations of other program spaces are left
13848 update_breakpoint_locations (struct breakpoint
*b
,
13849 struct program_space
*filter_pspace
,
13850 gdb::array_view
<const symtab_and_line
> sals
,
13851 gdb::array_view
<const symtab_and_line
> sals_end
)
13854 struct bp_location
*existing_locations
;
13856 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13858 /* Ranged breakpoints have only one start location and one end
13860 b
->enable_state
= bp_disabled
;
13861 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13862 "multiple locations found\n"),
13867 /* If there's no new locations, and all existing locations are
13868 pending, don't do anything. This optimizes the common case where
13869 all locations are in the same shared library, that was unloaded.
13870 We'd like to retain the location, so that when the library is
13871 loaded again, we don't loose the enabled/disabled status of the
13872 individual locations. */
13873 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13876 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13878 for (const auto &sal
: sals
)
13880 struct bp_location
*new_loc
;
13882 switch_to_program_space_and_thread (sal
.pspace
);
13884 new_loc
= add_location_to_breakpoint (b
, &sal
);
13886 /* Reparse conditions, they might contain references to the
13888 if (b
->cond_string
!= NULL
)
13892 s
= b
->cond_string
;
13895 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13896 block_for_pc (sal
.pc
),
13899 CATCH (e
, RETURN_MASK_ERROR
)
13901 warning (_("failed to reevaluate condition "
13902 "for breakpoint %d: %s"),
13903 b
->number
, e
.message
);
13904 new_loc
->enabled
= 0;
13909 if (!sals_end
.empty ())
13911 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13913 new_loc
->length
= end
- sals
[0].pc
+ 1;
13917 /* If possible, carry over 'disable' status from existing
13920 struct bp_location
*e
= existing_locations
;
13921 /* If there are multiple breakpoints with the same function name,
13922 e.g. for inline functions, comparing function names won't work.
13923 Instead compare pc addresses; this is just a heuristic as things
13924 may have moved, but in practice it gives the correct answer
13925 often enough until a better solution is found. */
13926 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13928 for (; e
; e
= e
->next
)
13930 if (!e
->enabled
&& e
->function_name
)
13932 struct bp_location
*l
= b
->loc
;
13933 if (have_ambiguous_names
)
13935 for (; l
; l
= l
->next
)
13936 if (breakpoint_locations_match (e
, l
))
13944 for (; l
; l
= l
->next
)
13945 if (l
->function_name
13946 && strcmp (e
->function_name
, l
->function_name
) == 0)
13956 if (!locations_are_equal (existing_locations
, b
->loc
))
13957 observer_notify_breakpoint_modified (b
);
13960 /* Find the SaL locations corresponding to the given LOCATION.
13961 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13963 static std::vector
<symtab_and_line
>
13964 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13965 struct program_space
*search_pspace
, int *found
)
13967 struct gdb_exception exception
= exception_none
;
13969 gdb_assert (b
->ops
!= NULL
);
13971 std::vector
<symtab_and_line
> sals
;
13975 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13977 CATCH (e
, RETURN_MASK_ERROR
)
13979 int not_found_and_ok
= 0;
13983 /* For pending breakpoints, it's expected that parsing will
13984 fail until the right shared library is loaded. User has
13985 already told to create pending breakpoints and don't need
13986 extra messages. If breakpoint is in bp_shlib_disabled
13987 state, then user already saw the message about that
13988 breakpoint being disabled, and don't want to see more
13990 if (e
.error
== NOT_FOUND_ERROR
13991 && (b
->condition_not_parsed
13993 && search_pspace
!= NULL
13994 && b
->loc
->pspace
!= search_pspace
)
13995 || (b
->loc
&& b
->loc
->shlib_disabled
)
13996 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13997 || b
->enable_state
== bp_disabled
))
13998 not_found_and_ok
= 1;
14000 if (!not_found_and_ok
)
14002 /* We surely don't want to warn about the same breakpoint
14003 10 times. One solution, implemented here, is disable
14004 the breakpoint on error. Another solution would be to
14005 have separate 'warning emitted' flag. Since this
14006 happens only when a binary has changed, I don't know
14007 which approach is better. */
14008 b
->enable_state
= bp_disabled
;
14009 throw_exception (e
);
14014 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14016 for (auto &sal
: sals
)
14017 resolve_sal_pc (&sal
);
14018 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14020 char *cond_string
, *extra_string
;
14023 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
14024 &cond_string
, &thread
, &task
,
14026 gdb_assert (b
->cond_string
== NULL
);
14028 b
->cond_string
= cond_string
;
14029 b
->thread
= thread
;
14033 xfree (b
->extra_string
);
14034 b
->extra_string
= extra_string
;
14036 b
->condition_not_parsed
= 0;
14039 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14040 sals
[0] = update_static_tracepoint (b
, sals
[0]);
14050 /* The default re_set method, for typical hardware or software
14051 breakpoints. Reevaluate the breakpoint and recreate its
14055 breakpoint_re_set_default (struct breakpoint
*b
)
14057 struct program_space
*filter_pspace
= current_program_space
;
14058 std::vector
<symtab_and_line
> expanded
, expanded_end
;
14061 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
14062 filter_pspace
, &found
);
14064 expanded
= std::move (sals
);
14066 if (b
->location_range_end
!= NULL
)
14068 std::vector
<symtab_and_line
> sals_end
14069 = location_to_sals (b
, b
->location_range_end
.get (),
14070 filter_pspace
, &found
);
14072 expanded_end
= std::move (sals_end
);
14075 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14078 /* Default method for creating SALs from an address string. It basically
14079 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14082 create_sals_from_location_default (const struct event_location
*location
,
14083 struct linespec_result
*canonical
,
14084 enum bptype type_wanted
)
14086 parse_breakpoint_sals (location
, canonical
);
14089 /* Call create_breakpoints_sal for the given arguments. This is the default
14090 function for the `create_breakpoints_sal' method of
14094 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14095 struct linespec_result
*canonical
,
14096 gdb::unique_xmalloc_ptr
<char> cond_string
,
14097 gdb::unique_xmalloc_ptr
<char> extra_string
,
14098 enum bptype type_wanted
,
14099 enum bpdisp disposition
,
14101 int task
, int ignore_count
,
14102 const struct breakpoint_ops
*ops
,
14103 int from_tty
, int enabled
,
14104 int internal
, unsigned flags
)
14106 create_breakpoints_sal (gdbarch
, canonical
,
14107 std::move (cond_string
),
14108 std::move (extra_string
),
14109 type_wanted
, disposition
,
14110 thread
, task
, ignore_count
, ops
, from_tty
,
14111 enabled
, internal
, flags
);
14114 /* Decode the line represented by S by calling decode_line_full. This is the
14115 default function for the `decode_location' method of breakpoint_ops. */
14117 static std::vector
<symtab_and_line
>
14118 decode_location_default (struct breakpoint
*b
,
14119 const struct event_location
*location
,
14120 struct program_space
*search_pspace
)
14122 struct linespec_result canonical
;
14124 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14125 (struct symtab
*) NULL
, 0,
14126 &canonical
, multiple_symbols_all
,
14129 /* We should get 0 or 1 resulting SALs. */
14130 gdb_assert (canonical
.lsals
.size () < 2);
14132 if (!canonical
.lsals
.empty ())
14134 const linespec_sals
&lsal
= canonical
.lsals
[0];
14135 return std::move (lsal
.sals
);
14140 /* Prepare the global context for a re-set of breakpoint B. */
14142 static struct cleanup
*
14143 prepare_re_set_context (struct breakpoint
*b
)
14145 input_radix
= b
->input_radix
;
14146 set_language (b
->language
);
14148 return make_cleanup (null_cleanup
, NULL
);
14151 /* Reset a breakpoint given it's struct breakpoint * BINT.
14152 The value we return ends up being the return value from catch_errors.
14153 Unused in this case. */
14156 breakpoint_re_set_one (void *bint
)
14158 /* Get past catch_errs. */
14159 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14160 struct cleanup
*cleanups
;
14162 cleanups
= prepare_re_set_context (b
);
14163 b
->ops
->re_set (b
);
14164 do_cleanups (cleanups
);
14168 /* Re-set breakpoint locations for the current program space.
14169 Locations bound to other program spaces are left untouched. */
14172 breakpoint_re_set (void)
14174 struct breakpoint
*b
, *b_tmp
;
14175 enum language save_language
;
14176 int save_input_radix
;
14178 save_language
= current_language
->la_language
;
14179 save_input_radix
= input_radix
;
14182 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14184 /* Note: we must not try to insert locations until after all
14185 breakpoints have been re-set. Otherwise, e.g., when re-setting
14186 breakpoint 1, we'd insert the locations of breakpoint 2, which
14187 hadn't been re-set yet, and thus may have stale locations. */
14189 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14191 /* Format possible error msg. */
14192 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14194 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14195 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14196 do_cleanups (cleanups
);
14198 set_language (save_language
);
14199 input_radix
= save_input_radix
;
14201 jit_breakpoint_re_set ();
14204 create_overlay_event_breakpoint ();
14205 create_longjmp_master_breakpoint ();
14206 create_std_terminate_master_breakpoint ();
14207 create_exception_master_breakpoint ();
14209 /* Now we can insert. */
14210 update_global_location_list (UGLL_MAY_INSERT
);
14213 /* Reset the thread number of this breakpoint:
14215 - If the breakpoint is for all threads, leave it as-is.
14216 - Else, reset it to the current thread for inferior_ptid. */
14218 breakpoint_re_set_thread (struct breakpoint
*b
)
14220 if (b
->thread
!= -1)
14222 if (in_thread_list (inferior_ptid
))
14223 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14225 /* We're being called after following a fork. The new fork is
14226 selected as current, and unless this was a vfork will have a
14227 different program space from the original thread. Reset that
14229 b
->loc
->pspace
= current_program_space
;
14233 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14234 If from_tty is nonzero, it prints a message to that effect,
14235 which ends with a period (no newline). */
14238 set_ignore_count (int bptnum
, int count
, int from_tty
)
14240 struct breakpoint
*b
;
14245 ALL_BREAKPOINTS (b
)
14246 if (b
->number
== bptnum
)
14248 if (is_tracepoint (b
))
14250 if (from_tty
&& count
!= 0)
14251 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14256 b
->ignore_count
= count
;
14260 printf_filtered (_("Will stop next time "
14261 "breakpoint %d is reached."),
14263 else if (count
== 1)
14264 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14267 printf_filtered (_("Will ignore next %d "
14268 "crossings of breakpoint %d."),
14271 observer_notify_breakpoint_modified (b
);
14275 error (_("No breakpoint number %d."), bptnum
);
14278 /* Command to set ignore-count of breakpoint N to COUNT. */
14281 ignore_command (char *args
, int from_tty
)
14287 error_no_arg (_("a breakpoint number"));
14289 num
= get_number (&p
);
14291 error (_("bad breakpoint number: '%s'"), args
);
14293 error (_("Second argument (specified ignore-count) is missing."));
14295 set_ignore_count (num
,
14296 longest_to_int (value_as_long (parse_and_eval (p
))),
14299 printf_filtered ("\n");
14302 /* Call FUNCTION on each of the breakpoints
14303 whose numbers are given in ARGS. */
14306 map_breakpoint_numbers (const char *args
,
14307 gdb::function_view
<void (breakpoint
*)> function
)
14310 struct breakpoint
*b
, *tmp
;
14312 if (args
== 0 || *args
== '\0')
14313 error_no_arg (_("one or more breakpoint numbers"));
14315 number_or_range_parser
parser (args
);
14317 while (!parser
.finished ())
14319 const char *p
= parser
.cur_tok ();
14320 bool match
= false;
14322 num
= parser
.get_number ();
14325 warning (_("bad breakpoint number at or near '%s'"), p
);
14329 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14330 if (b
->number
== num
)
14337 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14342 static struct bp_location
*
14343 find_location_by_number (const char *number
)
14348 struct breakpoint
*b
;
14349 struct bp_location
*loc
;
14352 bp_num
= get_number_trailer (&p1
, '.');
14353 if (bp_num
== 0 || p1
[0] != '.')
14354 error (_("Bad breakpoint number '%s'"), number
);
14356 ALL_BREAKPOINTS (b
)
14357 if (b
->number
== bp_num
)
14362 if (!b
|| b
->number
!= bp_num
)
14363 error (_("Bad breakpoint number '%s'"), number
);
14365 /* Skip the dot. */
14367 const char *save
= p1
;
14368 loc_num
= get_number (&p1
);
14370 error (_("Bad breakpoint location number '%s'"), number
);
14374 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14377 error (_("Bad breakpoint location number '%s'"), save
);
14383 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14384 If from_tty is nonzero, it prints a message to that effect,
14385 which ends with a period (no newline). */
14388 disable_breakpoint (struct breakpoint
*bpt
)
14390 /* Never disable a watchpoint scope breakpoint; we want to
14391 hit them when we leave scope so we can delete both the
14392 watchpoint and its scope breakpoint at that time. */
14393 if (bpt
->type
== bp_watchpoint_scope
)
14396 bpt
->enable_state
= bp_disabled
;
14398 /* Mark breakpoint locations modified. */
14399 mark_breakpoint_modified (bpt
);
14401 if (target_supports_enable_disable_tracepoint ()
14402 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14404 struct bp_location
*location
;
14406 for (location
= bpt
->loc
; location
; location
= location
->next
)
14407 target_disable_tracepoint (location
);
14410 update_global_location_list (UGLL_DONT_INSERT
);
14412 observer_notify_breakpoint_modified (bpt
);
14416 disable_command (char *args
, int from_tty
)
14420 struct breakpoint
*bpt
;
14422 ALL_BREAKPOINTS (bpt
)
14423 if (user_breakpoint_p (bpt
))
14424 disable_breakpoint (bpt
);
14428 std::string num
= extract_arg (&args
);
14430 while (!num
.empty ())
14432 if (num
.find ('.') != std::string::npos
)
14434 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14441 mark_breakpoint_location_modified (loc
);
14443 if (target_supports_enable_disable_tracepoint ()
14444 && current_trace_status ()->running
&& loc
->owner
14445 && is_tracepoint (loc
->owner
))
14446 target_disable_tracepoint (loc
);
14448 update_global_location_list (UGLL_DONT_INSERT
);
14451 map_breakpoint_numbers
14452 (num
.c_str (), [&] (breakpoint
*b
)
14454 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14456 num
= extract_arg (&args
);
14462 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14465 int target_resources_ok
;
14467 if (bpt
->type
== bp_hardware_breakpoint
)
14470 i
= hw_breakpoint_used_count ();
14471 target_resources_ok
=
14472 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14474 if (target_resources_ok
== 0)
14475 error (_("No hardware breakpoint support in the target."));
14476 else if (target_resources_ok
< 0)
14477 error (_("Hardware breakpoints used exceeds limit."));
14480 if (is_watchpoint (bpt
))
14482 /* Initialize it just to avoid a GCC false warning. */
14483 enum enable_state orig_enable_state
= bp_disabled
;
14487 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14489 orig_enable_state
= bpt
->enable_state
;
14490 bpt
->enable_state
= bp_enabled
;
14491 update_watchpoint (w
, 1 /* reparse */);
14493 CATCH (e
, RETURN_MASK_ALL
)
14495 bpt
->enable_state
= orig_enable_state
;
14496 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14503 bpt
->enable_state
= bp_enabled
;
14505 /* Mark breakpoint locations modified. */
14506 mark_breakpoint_modified (bpt
);
14508 if (target_supports_enable_disable_tracepoint ()
14509 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14511 struct bp_location
*location
;
14513 for (location
= bpt
->loc
; location
; location
= location
->next
)
14514 target_enable_tracepoint (location
);
14517 bpt
->disposition
= disposition
;
14518 bpt
->enable_count
= count
;
14519 update_global_location_list (UGLL_MAY_INSERT
);
14521 observer_notify_breakpoint_modified (bpt
);
14526 enable_breakpoint (struct breakpoint
*bpt
)
14528 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14531 /* The enable command enables the specified breakpoints (or all defined
14532 breakpoints) so they once again become (or continue to be) effective
14533 in stopping the inferior. */
14536 enable_command (char *args
, int from_tty
)
14540 struct breakpoint
*bpt
;
14542 ALL_BREAKPOINTS (bpt
)
14543 if (user_breakpoint_p (bpt
))
14544 enable_breakpoint (bpt
);
14548 std::string num
= extract_arg (&args
);
14550 while (!num
.empty ())
14552 if (num
.find ('.') != std::string::npos
)
14554 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14561 mark_breakpoint_location_modified (loc
);
14563 if (target_supports_enable_disable_tracepoint ()
14564 && current_trace_status ()->running
&& loc
->owner
14565 && is_tracepoint (loc
->owner
))
14566 target_enable_tracepoint (loc
);
14568 update_global_location_list (UGLL_MAY_INSERT
);
14571 map_breakpoint_numbers
14572 (num
.c_str (), [&] (breakpoint
*b
)
14574 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14576 num
= extract_arg (&args
);
14582 enable_once_command (const char *args
, int from_tty
)
14584 map_breakpoint_numbers
14585 (args
, [&] (breakpoint
*b
)
14587 iterate_over_related_breakpoints
14588 (b
, [&] (breakpoint
*bpt
)
14590 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14596 enable_count_command (const char *args
, int from_tty
)
14601 error_no_arg (_("hit count"));
14603 count
= get_number (&args
);
14605 map_breakpoint_numbers
14606 (args
, [&] (breakpoint
*b
)
14608 iterate_over_related_breakpoints
14609 (b
, [&] (breakpoint
*bpt
)
14611 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14617 enable_delete_command (const char *args
, int from_tty
)
14619 map_breakpoint_numbers
14620 (args
, [&] (breakpoint
*b
)
14622 iterate_over_related_breakpoints
14623 (b
, [&] (breakpoint
*bpt
)
14625 enable_breakpoint_disp (bpt
, disp_del
, 1);
14631 set_breakpoint_cmd (char *args
, int from_tty
)
14636 show_breakpoint_cmd (char *args
, int from_tty
)
14640 /* Invalidate last known value of any hardware watchpoint if
14641 the memory which that value represents has been written to by
14645 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14646 CORE_ADDR addr
, ssize_t len
,
14647 const bfd_byte
*data
)
14649 struct breakpoint
*bp
;
14651 ALL_BREAKPOINTS (bp
)
14652 if (bp
->enable_state
== bp_enabled
14653 && bp
->type
== bp_hardware_watchpoint
)
14655 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14657 if (wp
->val_valid
&& wp
->val
)
14659 struct bp_location
*loc
;
14661 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14662 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14663 && loc
->address
+ loc
->length
> addr
14664 && addr
+ len
> loc
->address
)
14666 value_free (wp
->val
);
14674 /* Create and insert a breakpoint for software single step. */
14677 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14678 struct address_space
*aspace
,
14681 struct thread_info
*tp
= inferior_thread ();
14682 struct symtab_and_line sal
;
14683 CORE_ADDR pc
= next_pc
;
14685 if (tp
->control
.single_step_breakpoints
== NULL
)
14687 tp
->control
.single_step_breakpoints
14688 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14691 sal
= find_pc_line (pc
, 0);
14693 sal
.section
= find_pc_overlay (pc
);
14694 sal
.explicit_pc
= 1;
14695 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14697 update_global_location_list (UGLL_INSERT
);
14700 /* Insert single step breakpoints according to the current state. */
14703 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14705 struct regcache
*regcache
= get_current_regcache ();
14706 std::vector
<CORE_ADDR
> next_pcs
;
14708 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14710 if (!next_pcs
.empty ())
14712 struct frame_info
*frame
= get_current_frame ();
14713 struct address_space
*aspace
= get_frame_address_space (frame
);
14715 for (CORE_ADDR pc
: next_pcs
)
14716 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14724 /* See breakpoint.h. */
14727 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14728 struct address_space
*aspace
,
14731 struct bp_location
*loc
;
14733 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14735 && breakpoint_location_address_match (loc
, aspace
, pc
))
14741 /* Check whether a software single-step breakpoint is inserted at
14745 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14748 struct breakpoint
*bpt
;
14750 ALL_BREAKPOINTS (bpt
)
14752 if (bpt
->type
== bp_single_step
14753 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14759 /* Tracepoint-specific operations. */
14761 /* Set tracepoint count to NUM. */
14763 set_tracepoint_count (int num
)
14765 tracepoint_count
= num
;
14766 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14770 trace_command (char *arg_in
, int from_tty
)
14772 const char *arg
= arg_in
;
14773 struct breakpoint_ops
*ops
;
14775 event_location_up location
= string_to_event_location (&arg
,
14777 if (location
!= NULL
14778 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14779 ops
= &tracepoint_probe_breakpoint_ops
;
14781 ops
= &tracepoint_breakpoint_ops
;
14783 create_breakpoint (get_current_arch (),
14785 NULL
, 0, arg
, 1 /* parse arg */,
14787 bp_tracepoint
/* type_wanted */,
14788 0 /* Ignore count */,
14789 pending_break_support
,
14793 0 /* internal */, 0);
14797 ftrace_command (char *arg_in
, int from_tty
)
14799 const char *arg
= arg_in
;
14800 event_location_up location
= string_to_event_location (&arg
,
14802 create_breakpoint (get_current_arch (),
14804 NULL
, 0, arg
, 1 /* parse arg */,
14806 bp_fast_tracepoint
/* type_wanted */,
14807 0 /* Ignore count */,
14808 pending_break_support
,
14809 &tracepoint_breakpoint_ops
,
14812 0 /* internal */, 0);
14815 /* strace command implementation. Creates a static tracepoint. */
14818 strace_command (char *arg_in
, int from_tty
)
14820 const char *arg
= arg_in
;
14821 struct breakpoint_ops
*ops
;
14822 event_location_up location
;
14823 struct cleanup
*back_to
;
14825 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14826 or with a normal static tracepoint. */
14827 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14829 ops
= &strace_marker_breakpoint_ops
;
14830 location
= new_linespec_location (&arg
);
14834 ops
= &tracepoint_breakpoint_ops
;
14835 location
= string_to_event_location (&arg
, current_language
);
14838 create_breakpoint (get_current_arch (),
14840 NULL
, 0, arg
, 1 /* parse arg */,
14842 bp_static_tracepoint
/* type_wanted */,
14843 0 /* Ignore count */,
14844 pending_break_support
,
14848 0 /* internal */, 0);
14851 /* Set up a fake reader function that gets command lines from a linked
14852 list that was acquired during tracepoint uploading. */
14854 static struct uploaded_tp
*this_utp
;
14855 static int next_cmd
;
14858 read_uploaded_action (void)
14862 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14869 /* Given information about a tracepoint as recorded on a target (which
14870 can be either a live system or a trace file), attempt to create an
14871 equivalent GDB tracepoint. This is not a reliable process, since
14872 the target does not necessarily have all the information used when
14873 the tracepoint was originally defined. */
14875 struct tracepoint
*
14876 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14878 const char *addr_str
;
14879 char small_buf
[100];
14880 struct tracepoint
*tp
;
14882 if (utp
->at_string
)
14883 addr_str
= utp
->at_string
;
14886 /* In the absence of a source location, fall back to raw
14887 address. Since there is no way to confirm that the address
14888 means the same thing as when the trace was started, warn the
14890 warning (_("Uploaded tracepoint %d has no "
14891 "source location, using raw address"),
14893 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14894 addr_str
= small_buf
;
14897 /* There's not much we can do with a sequence of bytecodes. */
14898 if (utp
->cond
&& !utp
->cond_string
)
14899 warning (_("Uploaded tracepoint %d condition "
14900 "has no source form, ignoring it"),
14903 event_location_up location
= string_to_event_location (&addr_str
,
14905 if (!create_breakpoint (get_current_arch (),
14907 utp
->cond_string
, -1, addr_str
,
14908 0 /* parse cond/thread */,
14910 utp
->type
/* type_wanted */,
14911 0 /* Ignore count */,
14912 pending_break_support
,
14913 &tracepoint_breakpoint_ops
,
14915 utp
->enabled
/* enabled */,
14917 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14920 /* Get the tracepoint we just created. */
14921 tp
= get_tracepoint (tracepoint_count
);
14922 gdb_assert (tp
!= NULL
);
14926 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14929 trace_pass_command (small_buf
, 0);
14932 /* If we have uploaded versions of the original commands, set up a
14933 special-purpose "reader" function and call the usual command line
14934 reader, then pass the result to the breakpoint command-setting
14936 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14938 command_line_up cmd_list
;
14943 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14945 breakpoint_set_commands (tp
, std::move (cmd_list
));
14947 else if (!VEC_empty (char_ptr
, utp
->actions
)
14948 || !VEC_empty (char_ptr
, utp
->step_actions
))
14949 warning (_("Uploaded tracepoint %d actions "
14950 "have no source form, ignoring them"),
14953 /* Copy any status information that might be available. */
14954 tp
->hit_count
= utp
->hit_count
;
14955 tp
->traceframe_usage
= utp
->traceframe_usage
;
14960 /* Print information on tracepoint number TPNUM_EXP, or all if
14964 info_tracepoints_command (char *args
, int from_tty
)
14966 struct ui_out
*uiout
= current_uiout
;
14969 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14971 if (num_printed
== 0)
14973 if (args
== NULL
|| *args
== '\0')
14974 uiout
->message ("No tracepoints.\n");
14976 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14979 default_collect_info ();
14982 /* The 'enable trace' command enables tracepoints.
14983 Not supported by all targets. */
14985 enable_trace_command (char *args
, int from_tty
)
14987 enable_command (args
, from_tty
);
14990 /* The 'disable trace' command disables tracepoints.
14991 Not supported by all targets. */
14993 disable_trace_command (char *args
, int from_tty
)
14995 disable_command (args
, from_tty
);
14998 /* Remove a tracepoint (or all if no argument). */
15000 delete_trace_command (const char *arg
, int from_tty
)
15002 struct breakpoint
*b
, *b_tmp
;
15008 int breaks_to_delete
= 0;
15010 /* Delete all breakpoints if no argument.
15011 Do not delete internal or call-dummy breakpoints, these
15012 have to be deleted with an explicit breakpoint number
15014 ALL_TRACEPOINTS (b
)
15015 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15017 breaks_to_delete
= 1;
15021 /* Ask user only if there are some breakpoints to delete. */
15023 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15025 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15026 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15027 delete_breakpoint (b
);
15031 map_breakpoint_numbers
15032 (arg
, [&] (breakpoint
*b
)
15034 iterate_over_related_breakpoints (b
, delete_breakpoint
);
15038 /* Helper function for trace_pass_command. */
15041 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15043 tp
->pass_count
= count
;
15044 observer_notify_breakpoint_modified (tp
);
15046 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15047 tp
->number
, count
);
15050 /* Set passcount for tracepoint.
15052 First command argument is passcount, second is tracepoint number.
15053 If tracepoint number omitted, apply to most recently defined.
15054 Also accepts special argument "all". */
15057 trace_pass_command (char *args
, int from_tty
)
15059 struct tracepoint
*t1
;
15060 unsigned int count
;
15062 if (args
== 0 || *args
== 0)
15063 error (_("passcount command requires an "
15064 "argument (count + optional TP num)"));
15066 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15068 args
= skip_spaces (args
);
15069 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15071 struct breakpoint
*b
;
15073 args
+= 3; /* Skip special argument "all". */
15075 error (_("Junk at end of arguments."));
15077 ALL_TRACEPOINTS (b
)
15079 t1
= (struct tracepoint
*) b
;
15080 trace_pass_set_count (t1
, count
, from_tty
);
15083 else if (*args
== '\0')
15085 t1
= get_tracepoint_by_number (&args
, NULL
);
15087 trace_pass_set_count (t1
, count
, from_tty
);
15091 number_or_range_parser
parser (args
);
15092 while (!parser
.finished ())
15094 t1
= get_tracepoint_by_number (&args
, &parser
);
15096 trace_pass_set_count (t1
, count
, from_tty
);
15101 struct tracepoint
*
15102 get_tracepoint (int num
)
15104 struct breakpoint
*t
;
15106 ALL_TRACEPOINTS (t
)
15107 if (t
->number
== num
)
15108 return (struct tracepoint
*) t
;
15113 /* Find the tracepoint with the given target-side number (which may be
15114 different from the tracepoint number after disconnecting and
15117 struct tracepoint
*
15118 get_tracepoint_by_number_on_target (int num
)
15120 struct breakpoint
*b
;
15122 ALL_TRACEPOINTS (b
)
15124 struct tracepoint
*t
= (struct tracepoint
*) b
;
15126 if (t
->number_on_target
== num
)
15133 /* Utility: parse a tracepoint number and look it up in the list.
15134 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15135 If the argument is missing, the most recent tracepoint
15136 (tracepoint_count) is returned. */
15138 struct tracepoint
*
15139 get_tracepoint_by_number (char **arg
,
15140 number_or_range_parser
*parser
)
15142 struct breakpoint
*t
;
15144 char *instring
= arg
== NULL
? NULL
: *arg
;
15146 if (parser
!= NULL
)
15148 gdb_assert (!parser
->finished ());
15149 tpnum
= parser
->get_number ();
15151 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15152 tpnum
= tracepoint_count
;
15154 tpnum
= get_number (arg
);
15158 if (instring
&& *instring
)
15159 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15162 printf_filtered (_("No previous tracepoint\n"));
15166 ALL_TRACEPOINTS (t
)
15167 if (t
->number
== tpnum
)
15169 return (struct tracepoint
*) t
;
15172 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15177 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15179 if (b
->thread
!= -1)
15180 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15183 fprintf_unfiltered (fp
, " task %d", b
->task
);
15185 fprintf_unfiltered (fp
, "\n");
15188 /* Save information on user settable breakpoints (watchpoints, etc) to
15189 a new script file named FILENAME. If FILTER is non-NULL, call it
15190 on each breakpoint and only include the ones for which it returns
15194 save_breakpoints (const char *filename
, int from_tty
,
15195 int (*filter
) (const struct breakpoint
*))
15197 struct breakpoint
*tp
;
15199 int extra_trace_bits
= 0;
15201 if (filename
== 0 || *filename
== 0)
15202 error (_("Argument required (file name in which to save)"));
15204 /* See if we have anything to save. */
15205 ALL_BREAKPOINTS (tp
)
15207 /* Skip internal and momentary breakpoints. */
15208 if (!user_breakpoint_p (tp
))
15211 /* If we have a filter, only save the breakpoints it accepts. */
15212 if (filter
&& !filter (tp
))
15217 if (is_tracepoint (tp
))
15219 extra_trace_bits
= 1;
15221 /* We can stop searching. */
15228 warning (_("Nothing to save."));
15232 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15236 if (!fp
.open (expanded_filename
.get (), "w"))
15237 error (_("Unable to open file '%s' for saving (%s)"),
15238 expanded_filename
.get (), safe_strerror (errno
));
15240 if (extra_trace_bits
)
15241 save_trace_state_variables (&fp
);
15243 ALL_BREAKPOINTS (tp
)
15245 /* Skip internal and momentary breakpoints. */
15246 if (!user_breakpoint_p (tp
))
15249 /* If we have a filter, only save the breakpoints it accepts. */
15250 if (filter
&& !filter (tp
))
15253 tp
->ops
->print_recreate (tp
, &fp
);
15255 /* Note, we can't rely on tp->number for anything, as we can't
15256 assume the recreated breakpoint numbers will match. Use $bpnum
15259 if (tp
->cond_string
)
15260 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15262 if (tp
->ignore_count
)
15263 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15265 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15267 fp
.puts (" commands\n");
15269 current_uiout
->redirect (&fp
);
15272 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15274 CATCH (ex
, RETURN_MASK_ALL
)
15276 current_uiout
->redirect (NULL
);
15277 throw_exception (ex
);
15281 current_uiout
->redirect (NULL
);
15282 fp
.puts (" end\n");
15285 if (tp
->enable_state
== bp_disabled
)
15286 fp
.puts ("disable $bpnum\n");
15288 /* If this is a multi-location breakpoint, check if the locations
15289 should be individually disabled. Watchpoint locations are
15290 special, and not user visible. */
15291 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15293 struct bp_location
*loc
;
15296 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15298 fp
.printf ("disable $bpnum.%d\n", n
);
15302 if (extra_trace_bits
&& *default_collect
)
15303 fp
.printf ("set default-collect %s\n", default_collect
);
15306 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15309 /* The `save breakpoints' command. */
15312 save_breakpoints_command (const char *args
, int from_tty
)
15314 save_breakpoints (args
, from_tty
, NULL
);
15317 /* The `save tracepoints' command. */
15320 save_tracepoints_command (const char *args
, int from_tty
)
15322 save_breakpoints (args
, from_tty
, is_tracepoint
);
15325 /* Create a vector of all tracepoints. */
15327 VEC(breakpoint_p
) *
15328 all_tracepoints (void)
15330 VEC(breakpoint_p
) *tp_vec
= 0;
15331 struct breakpoint
*tp
;
15333 ALL_TRACEPOINTS (tp
)
15335 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15342 /* This help string is used to consolidate all the help string for specifying
15343 locations used by several commands. */
15345 #define LOCATION_HELP_STRING \
15346 "Linespecs are colon-separated lists of location parameters, such as\n\
15347 source filename, function name, label name, and line number.\n\
15348 Example: To specify the start of a label named \"the_top\" in the\n\
15349 function \"fact\" in the file \"factorial.c\", use\n\
15350 \"factorial.c:fact:the_top\".\n\
15352 Address locations begin with \"*\" and specify an exact address in the\n\
15353 program. Example: To specify the fourth byte past the start function\n\
15354 \"main\", use \"*main + 4\".\n\
15356 Explicit locations are similar to linespecs but use an option/argument\n\
15357 syntax to specify location parameters.\n\
15358 Example: To specify the start of the label named \"the_top\" in the\n\
15359 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15360 -function fact -label the_top\".\n"
15362 /* This help string is used for the break, hbreak, tbreak and thbreak
15363 commands. It is defined as a macro to prevent duplication.
15364 COMMAND should be a string constant containing the name of the
15367 #define BREAK_ARGS_HELP(command) \
15368 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15369 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15370 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15371 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15372 `-probe-dtrace' (for a DTrace probe).\n\
15373 LOCATION may be a linespec, address, or explicit location as described\n\
15376 With no LOCATION, uses current execution address of the selected\n\
15377 stack frame. This is useful for breaking on return to a stack frame.\n\
15379 THREADNUM is the number from \"info threads\".\n\
15380 CONDITION is a boolean expression.\n\
15381 \n" LOCATION_HELP_STRING "\n\
15382 Multiple breakpoints at one place are permitted, and useful if their\n\
15383 conditions are different.\n\
15385 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15387 /* List of subcommands for "catch". */
15388 static struct cmd_list_element
*catch_cmdlist
;
15390 /* List of subcommands for "tcatch". */
15391 static struct cmd_list_element
*tcatch_cmdlist
;
15394 add_catch_command (const char *name
, const char *docstring
,
15395 cmd_sfunc_ftype
*sfunc
,
15396 completer_ftype
*completer
,
15397 void *user_data_catch
,
15398 void *user_data_tcatch
)
15400 struct cmd_list_element
*command
;
15402 command
= add_cmd (name
, class_breakpoint
, docstring
,
15404 set_cmd_sfunc (command
, sfunc
);
15405 set_cmd_context (command
, user_data_catch
);
15406 set_cmd_completer (command
, completer
);
15408 command
= add_cmd (name
, class_breakpoint
, docstring
,
15410 set_cmd_sfunc (command
, sfunc
);
15411 set_cmd_context (command
, user_data_tcatch
);
15412 set_cmd_completer (command
, completer
);
15416 save_command (char *arg
, int from_tty
)
15418 printf_unfiltered (_("\"save\" must be followed by "
15419 "the name of a save subcommand.\n"));
15420 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15423 struct breakpoint
*
15424 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15427 struct breakpoint
*b
, *b_tmp
;
15429 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15431 if ((*callback
) (b
, data
))
15438 /* Zero if any of the breakpoint's locations could be a location where
15439 functions have been inlined, nonzero otherwise. */
15442 is_non_inline_function (struct breakpoint
*b
)
15444 /* The shared library event breakpoint is set on the address of a
15445 non-inline function. */
15446 if (b
->type
== bp_shlib_event
)
15452 /* Nonzero if the specified PC cannot be a location where functions
15453 have been inlined. */
15456 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15457 const struct target_waitstatus
*ws
)
15459 struct breakpoint
*b
;
15460 struct bp_location
*bl
;
15462 ALL_BREAKPOINTS (b
)
15464 if (!is_non_inline_function (b
))
15467 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15469 if (!bl
->shlib_disabled
15470 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15478 /* Remove any references to OBJFILE which is going to be freed. */
15481 breakpoint_free_objfile (struct objfile
*objfile
)
15483 struct bp_location
**locp
, *loc
;
15485 ALL_BP_LOCATIONS (loc
, locp
)
15486 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15487 loc
->symtab
= NULL
;
15491 initialize_breakpoint_ops (void)
15493 static int initialized
= 0;
15495 struct breakpoint_ops
*ops
;
15501 /* The breakpoint_ops structure to be inherit by all kinds of
15502 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15503 internal and momentary breakpoints, etc.). */
15504 ops
= &bkpt_base_breakpoint_ops
;
15505 *ops
= base_breakpoint_ops
;
15506 ops
->re_set
= bkpt_re_set
;
15507 ops
->insert_location
= bkpt_insert_location
;
15508 ops
->remove_location
= bkpt_remove_location
;
15509 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15510 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15511 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15512 ops
->decode_location
= bkpt_decode_location
;
15514 /* The breakpoint_ops structure to be used in regular breakpoints. */
15515 ops
= &bkpt_breakpoint_ops
;
15516 *ops
= bkpt_base_breakpoint_ops
;
15517 ops
->re_set
= bkpt_re_set
;
15518 ops
->resources_needed
= bkpt_resources_needed
;
15519 ops
->print_it
= bkpt_print_it
;
15520 ops
->print_mention
= bkpt_print_mention
;
15521 ops
->print_recreate
= bkpt_print_recreate
;
15523 /* Ranged breakpoints. */
15524 ops
= &ranged_breakpoint_ops
;
15525 *ops
= bkpt_breakpoint_ops
;
15526 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15527 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15528 ops
->print_it
= print_it_ranged_breakpoint
;
15529 ops
->print_one
= print_one_ranged_breakpoint
;
15530 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15531 ops
->print_mention
= print_mention_ranged_breakpoint
;
15532 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15534 /* Internal breakpoints. */
15535 ops
= &internal_breakpoint_ops
;
15536 *ops
= bkpt_base_breakpoint_ops
;
15537 ops
->re_set
= internal_bkpt_re_set
;
15538 ops
->check_status
= internal_bkpt_check_status
;
15539 ops
->print_it
= internal_bkpt_print_it
;
15540 ops
->print_mention
= internal_bkpt_print_mention
;
15542 /* Momentary breakpoints. */
15543 ops
= &momentary_breakpoint_ops
;
15544 *ops
= bkpt_base_breakpoint_ops
;
15545 ops
->re_set
= momentary_bkpt_re_set
;
15546 ops
->check_status
= momentary_bkpt_check_status
;
15547 ops
->print_it
= momentary_bkpt_print_it
;
15548 ops
->print_mention
= momentary_bkpt_print_mention
;
15550 /* Probe breakpoints. */
15551 ops
= &bkpt_probe_breakpoint_ops
;
15552 *ops
= bkpt_breakpoint_ops
;
15553 ops
->insert_location
= bkpt_probe_insert_location
;
15554 ops
->remove_location
= bkpt_probe_remove_location
;
15555 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15556 ops
->decode_location
= bkpt_probe_decode_location
;
15559 ops
= &watchpoint_breakpoint_ops
;
15560 *ops
= base_breakpoint_ops
;
15561 ops
->re_set
= re_set_watchpoint
;
15562 ops
->insert_location
= insert_watchpoint
;
15563 ops
->remove_location
= remove_watchpoint
;
15564 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15565 ops
->check_status
= check_status_watchpoint
;
15566 ops
->resources_needed
= resources_needed_watchpoint
;
15567 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15568 ops
->print_it
= print_it_watchpoint
;
15569 ops
->print_mention
= print_mention_watchpoint
;
15570 ops
->print_recreate
= print_recreate_watchpoint
;
15571 ops
->explains_signal
= explains_signal_watchpoint
;
15573 /* Masked watchpoints. */
15574 ops
= &masked_watchpoint_breakpoint_ops
;
15575 *ops
= watchpoint_breakpoint_ops
;
15576 ops
->insert_location
= insert_masked_watchpoint
;
15577 ops
->remove_location
= remove_masked_watchpoint
;
15578 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15579 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15580 ops
->print_it
= print_it_masked_watchpoint
;
15581 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15582 ops
->print_mention
= print_mention_masked_watchpoint
;
15583 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15586 ops
= &tracepoint_breakpoint_ops
;
15587 *ops
= base_breakpoint_ops
;
15588 ops
->re_set
= tracepoint_re_set
;
15589 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15590 ops
->print_one_detail
= tracepoint_print_one_detail
;
15591 ops
->print_mention
= tracepoint_print_mention
;
15592 ops
->print_recreate
= tracepoint_print_recreate
;
15593 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15594 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15595 ops
->decode_location
= tracepoint_decode_location
;
15597 /* Probe tracepoints. */
15598 ops
= &tracepoint_probe_breakpoint_ops
;
15599 *ops
= tracepoint_breakpoint_ops
;
15600 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15601 ops
->decode_location
= tracepoint_probe_decode_location
;
15603 /* Static tracepoints with marker (`-m'). */
15604 ops
= &strace_marker_breakpoint_ops
;
15605 *ops
= tracepoint_breakpoint_ops
;
15606 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15607 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15608 ops
->decode_location
= strace_marker_decode_location
;
15610 /* Fork catchpoints. */
15611 ops
= &catch_fork_breakpoint_ops
;
15612 *ops
= base_breakpoint_ops
;
15613 ops
->insert_location
= insert_catch_fork
;
15614 ops
->remove_location
= remove_catch_fork
;
15615 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15616 ops
->print_it
= print_it_catch_fork
;
15617 ops
->print_one
= print_one_catch_fork
;
15618 ops
->print_mention
= print_mention_catch_fork
;
15619 ops
->print_recreate
= print_recreate_catch_fork
;
15621 /* Vfork catchpoints. */
15622 ops
= &catch_vfork_breakpoint_ops
;
15623 *ops
= base_breakpoint_ops
;
15624 ops
->insert_location
= insert_catch_vfork
;
15625 ops
->remove_location
= remove_catch_vfork
;
15626 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15627 ops
->print_it
= print_it_catch_vfork
;
15628 ops
->print_one
= print_one_catch_vfork
;
15629 ops
->print_mention
= print_mention_catch_vfork
;
15630 ops
->print_recreate
= print_recreate_catch_vfork
;
15632 /* Exec catchpoints. */
15633 ops
= &catch_exec_breakpoint_ops
;
15634 *ops
= base_breakpoint_ops
;
15635 ops
->insert_location
= insert_catch_exec
;
15636 ops
->remove_location
= remove_catch_exec
;
15637 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15638 ops
->print_it
= print_it_catch_exec
;
15639 ops
->print_one
= print_one_catch_exec
;
15640 ops
->print_mention
= print_mention_catch_exec
;
15641 ops
->print_recreate
= print_recreate_catch_exec
;
15643 /* Solib-related catchpoints. */
15644 ops
= &catch_solib_breakpoint_ops
;
15645 *ops
= base_breakpoint_ops
;
15646 ops
->insert_location
= insert_catch_solib
;
15647 ops
->remove_location
= remove_catch_solib
;
15648 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15649 ops
->check_status
= check_status_catch_solib
;
15650 ops
->print_it
= print_it_catch_solib
;
15651 ops
->print_one
= print_one_catch_solib
;
15652 ops
->print_mention
= print_mention_catch_solib
;
15653 ops
->print_recreate
= print_recreate_catch_solib
;
15655 ops
= &dprintf_breakpoint_ops
;
15656 *ops
= bkpt_base_breakpoint_ops
;
15657 ops
->re_set
= dprintf_re_set
;
15658 ops
->resources_needed
= bkpt_resources_needed
;
15659 ops
->print_it
= bkpt_print_it
;
15660 ops
->print_mention
= bkpt_print_mention
;
15661 ops
->print_recreate
= dprintf_print_recreate
;
15662 ops
->after_condition_true
= dprintf_after_condition_true
;
15663 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15666 /* Chain containing all defined "enable breakpoint" subcommands. */
15668 static struct cmd_list_element
*enablebreaklist
= NULL
;
15671 _initialize_breakpoint (void)
15673 struct cmd_list_element
*c
;
15675 initialize_breakpoint_ops ();
15677 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15678 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15679 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15681 breakpoint_objfile_key
15682 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15684 breakpoint_chain
= 0;
15685 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15686 before a breakpoint is set. */
15687 breakpoint_count
= 0;
15689 tracepoint_count
= 0;
15691 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15692 Set ignore-count of breakpoint number N to COUNT.\n\
15693 Usage is `ignore N COUNT'."));
15695 add_com ("commands", class_breakpoint
, commands_command
, _("\
15696 Set commands to be executed when the given breakpoints are hit.\n\
15697 Give a space-separated breakpoint list as argument after \"commands\".\n\
15698 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15700 With no argument, the targeted breakpoint is the last one set.\n\
15701 The commands themselves follow starting on the next line.\n\
15702 Type a line containing \"end\" to indicate the end of them.\n\
15703 Give \"silent\" as the first line to make the breakpoint silent;\n\
15704 then no output is printed when it is hit, except what the commands print."));
15706 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15707 Specify breakpoint number N to break only if COND is true.\n\
15708 Usage is `condition N COND', where N is an integer and COND is an\n\
15709 expression to be evaluated whenever breakpoint N is reached."));
15710 set_cmd_completer (c
, condition_completer
);
15712 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15713 Set a temporary breakpoint.\n\
15714 Like \"break\" except the breakpoint is only temporary,\n\
15715 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15716 by using \"enable delete\" on the breakpoint number.\n\
15718 BREAK_ARGS_HELP ("tbreak")));
15719 set_cmd_completer (c
, location_completer
);
15721 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15722 Set a hardware assisted breakpoint.\n\
15723 Like \"break\" except the breakpoint requires hardware support,\n\
15724 some target hardware may not have this support.\n\
15726 BREAK_ARGS_HELP ("hbreak")));
15727 set_cmd_completer (c
, location_completer
);
15729 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15730 Set a temporary hardware assisted breakpoint.\n\
15731 Like \"hbreak\" except the breakpoint is only temporary,\n\
15732 so it will be deleted when hit.\n\
15734 BREAK_ARGS_HELP ("thbreak")));
15735 set_cmd_completer (c
, location_completer
);
15737 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15738 Enable some breakpoints.\n\
15739 Give breakpoint numbers (separated by spaces) as arguments.\n\
15740 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15741 This is used to cancel the effect of the \"disable\" command.\n\
15742 With a subcommand you can enable temporarily."),
15743 &enablelist
, "enable ", 1, &cmdlist
);
15745 add_com_alias ("en", "enable", class_breakpoint
, 1);
15747 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15748 Enable some breakpoints.\n\
15749 Give breakpoint numbers (separated by spaces) as arguments.\n\
15750 This is used to cancel the effect of the \"disable\" command.\n\
15751 May be abbreviated to simply \"enable\".\n"),
15752 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15754 add_cmd ("once", no_class
, enable_once_command
, _("\
15755 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15756 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15759 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15760 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15761 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15764 add_cmd ("count", no_class
, enable_count_command
, _("\
15765 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15766 If a breakpoint is hit while enabled in this fashion,\n\
15767 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15770 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15771 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15772 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15775 add_cmd ("once", no_class
, enable_once_command
, _("\
15776 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15777 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15780 add_cmd ("count", no_class
, enable_count_command
, _("\
15781 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15782 If a breakpoint is hit while enabled in this fashion,\n\
15783 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15786 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15787 Disable some breakpoints.\n\
15788 Arguments are breakpoint numbers with spaces in between.\n\
15789 To disable all breakpoints, give no argument.\n\
15790 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15791 &disablelist
, "disable ", 1, &cmdlist
);
15792 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15793 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15795 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15796 Disable some breakpoints.\n\
15797 Arguments are breakpoint numbers with spaces in between.\n\
15798 To disable all breakpoints, give no argument.\n\
15799 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15800 This command may be abbreviated \"disable\"."),
15803 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15804 Delete some breakpoints or auto-display expressions.\n\
15805 Arguments are breakpoint numbers with spaces in between.\n\
15806 To delete all breakpoints, give no argument.\n\
15808 Also a prefix command for deletion of other GDB objects.\n\
15809 The \"unset\" command is also an alias for \"delete\"."),
15810 &deletelist
, "delete ", 1, &cmdlist
);
15811 add_com_alias ("d", "delete", class_breakpoint
, 1);
15812 add_com_alias ("del", "delete", class_breakpoint
, 1);
15814 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15815 Delete some breakpoints or auto-display expressions.\n\
15816 Arguments are breakpoint numbers with spaces in between.\n\
15817 To delete all breakpoints, give no argument.\n\
15818 This command may be abbreviated \"delete\"."),
15821 add_com ("clear", class_breakpoint
, clear_command
, _("\
15822 Clear breakpoint at specified location.\n\
15823 Argument may be a linespec, explicit, or address location as described below.\n\
15825 With no argument, clears all breakpoints in the line that the selected frame\n\
15826 is executing in.\n"
15827 "\n" LOCATION_HELP_STRING
"\n\
15828 See also the \"delete\" command which clears breakpoints by number."));
15829 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15831 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15832 Set breakpoint at specified location.\n"
15833 BREAK_ARGS_HELP ("break")));
15834 set_cmd_completer (c
, location_completer
);
15836 add_com_alias ("b", "break", class_run
, 1);
15837 add_com_alias ("br", "break", class_run
, 1);
15838 add_com_alias ("bre", "break", class_run
, 1);
15839 add_com_alias ("brea", "break", class_run
, 1);
15843 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15844 Break in function/address or break at a line in the current file."),
15845 &stoplist
, "stop ", 1, &cmdlist
);
15846 add_cmd ("in", class_breakpoint
, stopin_command
,
15847 _("Break in function or address."), &stoplist
);
15848 add_cmd ("at", class_breakpoint
, stopat_command
,
15849 _("Break at a line in the current file."), &stoplist
);
15850 add_com ("status", class_info
, info_breakpoints_command
, _("\
15851 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15852 The \"Type\" column indicates one of:\n\
15853 \tbreakpoint - normal breakpoint\n\
15854 \twatchpoint - watchpoint\n\
15855 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15856 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15857 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15858 address and file/line number respectively.\n\
15860 Convenience variable \"$_\" and default examine address for \"x\"\n\
15861 are set to the address of the last breakpoint listed unless the command\n\
15862 is prefixed with \"server \".\n\n\
15863 Convenience variable \"$bpnum\" contains the number of the last\n\
15864 breakpoint set."));
15867 add_info ("breakpoints", info_breakpoints_command
, _("\
15868 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15869 The \"Type\" column indicates one of:\n\
15870 \tbreakpoint - normal breakpoint\n\
15871 \twatchpoint - watchpoint\n\
15872 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15873 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15874 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15875 address and file/line number respectively.\n\
15877 Convenience variable \"$_\" and default examine address for \"x\"\n\
15878 are set to the address of the last breakpoint listed unless the command\n\
15879 is prefixed with \"server \".\n\n\
15880 Convenience variable \"$bpnum\" contains the number of the last\n\
15881 breakpoint set."));
15883 add_info_alias ("b", "breakpoints", 1);
15885 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15886 Status of all breakpoints, or breakpoint number NUMBER.\n\
15887 The \"Type\" column indicates one of:\n\
15888 \tbreakpoint - normal breakpoint\n\
15889 \twatchpoint - watchpoint\n\
15890 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15891 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15892 \tuntil - internal breakpoint used by the \"until\" command\n\
15893 \tfinish - internal breakpoint used by the \"finish\" command\n\
15894 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15895 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15896 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15897 address and file/line number respectively.\n\
15899 Convenience variable \"$_\" and default examine address for \"x\"\n\
15900 are set to the address of the last breakpoint listed unless the command\n\
15901 is prefixed with \"server \".\n\n\
15902 Convenience variable \"$bpnum\" contains the number of the last\n\
15904 &maintenanceinfolist
);
15906 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15907 Set catchpoints to catch events."),
15908 &catch_cmdlist
, "catch ",
15909 0/*allow-unknown*/, &cmdlist
);
15911 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15912 Set temporary catchpoints to catch events."),
15913 &tcatch_cmdlist
, "tcatch ",
15914 0/*allow-unknown*/, &cmdlist
);
15916 add_catch_command ("fork", _("Catch calls to fork."),
15917 catch_fork_command_1
,
15919 (void *) (uintptr_t) catch_fork_permanent
,
15920 (void *) (uintptr_t) catch_fork_temporary
);
15921 add_catch_command ("vfork", _("Catch calls to vfork."),
15922 catch_fork_command_1
,
15924 (void *) (uintptr_t) catch_vfork_permanent
,
15925 (void *) (uintptr_t) catch_vfork_temporary
);
15926 add_catch_command ("exec", _("Catch calls to exec."),
15927 catch_exec_command_1
,
15931 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15932 Usage: catch load [REGEX]\n\
15933 If REGEX is given, only stop for libraries matching the regular expression."),
15934 catch_load_command_1
,
15938 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15939 Usage: catch unload [REGEX]\n\
15940 If REGEX is given, only stop for libraries matching the regular expression."),
15941 catch_unload_command_1
,
15946 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15947 Set a watchpoint for an expression.\n\
15948 Usage: watch [-l|-location] EXPRESSION\n\
15949 A watchpoint stops execution of your program whenever the value of\n\
15950 an expression changes.\n\
15951 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15952 the memory to which it refers."));
15953 set_cmd_completer (c
, expression_completer
);
15955 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15956 Set a read watchpoint for an expression.\n\
15957 Usage: rwatch [-l|-location] EXPRESSION\n\
15958 A watchpoint stops execution of your program whenever the value of\n\
15959 an expression is read.\n\
15960 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15961 the memory to which it refers."));
15962 set_cmd_completer (c
, expression_completer
);
15964 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15965 Set a watchpoint for an expression.\n\
15966 Usage: awatch [-l|-location] EXPRESSION\n\
15967 A watchpoint stops execution of your program whenever the value of\n\
15968 an expression is either read or written.\n\
15969 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15970 the memory to which it refers."));
15971 set_cmd_completer (c
, expression_completer
);
15973 add_info ("watchpoints", info_watchpoints_command
, _("\
15974 Status of specified watchpoints (all watchpoints if no argument)."));
15976 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15977 respond to changes - contrary to the description. */
15978 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15979 &can_use_hw_watchpoints
, _("\
15980 Set debugger's willingness to use watchpoint hardware."), _("\
15981 Show debugger's willingness to use watchpoint hardware."), _("\
15982 If zero, gdb will not use hardware for new watchpoints, even if\n\
15983 such is available. (However, any hardware watchpoints that were\n\
15984 created before setting this to nonzero, will continue to use watchpoint\n\
15987 show_can_use_hw_watchpoints
,
15988 &setlist
, &showlist
);
15990 can_use_hw_watchpoints
= 1;
15992 /* Tracepoint manipulation commands. */
15994 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15995 Set a tracepoint at specified location.\n\
15997 BREAK_ARGS_HELP ("trace") "\n\
15998 Do \"help tracepoints\" for info on other tracepoint commands."));
15999 set_cmd_completer (c
, location_completer
);
16001 add_com_alias ("tp", "trace", class_alias
, 0);
16002 add_com_alias ("tr", "trace", class_alias
, 1);
16003 add_com_alias ("tra", "trace", class_alias
, 1);
16004 add_com_alias ("trac", "trace", class_alias
, 1);
16006 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16007 Set a fast tracepoint at specified location.\n\
16009 BREAK_ARGS_HELP ("ftrace") "\n\
16010 Do \"help tracepoints\" for info on other tracepoint commands."));
16011 set_cmd_completer (c
, location_completer
);
16013 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16014 Set a static tracepoint at location or marker.\n\
16016 strace [LOCATION] [if CONDITION]\n\
16017 LOCATION may be a linespec, explicit, or address location (described below) \n\
16018 or -m MARKER_ID.\n\n\
16019 If a marker id is specified, probe the marker with that name. With\n\
16020 no LOCATION, uses current execution address of the selected stack frame.\n\
16021 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16022 This collects arbitrary user data passed in the probe point call to the\n\
16023 tracing library. You can inspect it when analyzing the trace buffer,\n\
16024 by printing the $_sdata variable like any other convenience variable.\n\
16026 CONDITION is a boolean expression.\n\
16027 \n" LOCATION_HELP_STRING
"\n\
16028 Multiple tracepoints at one place are permitted, and useful if their\n\
16029 conditions are different.\n\
16031 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16032 Do \"help tracepoints\" for info on other tracepoint commands."));
16033 set_cmd_completer (c
, location_completer
);
16035 add_info ("tracepoints", info_tracepoints_command
, _("\
16036 Status of specified tracepoints (all tracepoints if no argument).\n\
16037 Convenience variable \"$tpnum\" contains the number of the\n\
16038 last tracepoint set."));
16040 add_info_alias ("tp", "tracepoints", 1);
16042 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16043 Delete specified tracepoints.\n\
16044 Arguments are tracepoint numbers, separated by spaces.\n\
16045 No argument means delete all tracepoints."),
16047 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16049 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16050 Disable specified tracepoints.\n\
16051 Arguments are tracepoint numbers, separated by spaces.\n\
16052 No argument means disable all tracepoints."),
16054 deprecate_cmd (c
, "disable");
16056 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16057 Enable specified tracepoints.\n\
16058 Arguments are tracepoint numbers, separated by spaces.\n\
16059 No argument means enable all tracepoints."),
16061 deprecate_cmd (c
, "enable");
16063 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16064 Set the passcount for a tracepoint.\n\
16065 The trace will end when the tracepoint has been passed 'count' times.\n\
16066 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16067 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16069 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16070 _("Save breakpoint definitions as a script."),
16071 &save_cmdlist
, "save ",
16072 0/*allow-unknown*/, &cmdlist
);
16074 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16075 Save current breakpoint definitions as a script.\n\
16076 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16077 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16078 session to restore them."),
16080 set_cmd_completer (c
, filename_completer
);
16082 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16083 Save current tracepoint definitions as a script.\n\
16084 Use the 'source' command in another debug session to restore them."),
16086 set_cmd_completer (c
, filename_completer
);
16088 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16089 deprecate_cmd (c
, "save tracepoints");
16091 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16092 Breakpoint specific settings\n\
16093 Configure various breakpoint-specific variables such as\n\
16094 pending breakpoint behavior"),
16095 &breakpoint_set_cmdlist
, "set breakpoint ",
16096 0/*allow-unknown*/, &setlist
);
16097 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16098 Breakpoint specific settings\n\
16099 Configure various breakpoint-specific variables such as\n\
16100 pending breakpoint behavior"),
16101 &breakpoint_show_cmdlist
, "show breakpoint ",
16102 0/*allow-unknown*/, &showlist
);
16104 add_setshow_auto_boolean_cmd ("pending", no_class
,
16105 &pending_break_support
, _("\
16106 Set debugger's behavior regarding pending breakpoints."), _("\
16107 Show debugger's behavior regarding pending breakpoints."), _("\
16108 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16109 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16110 an error. If auto, an unrecognized breakpoint location results in a\n\
16111 user-query to see if a pending breakpoint should be created."),
16113 show_pending_break_support
,
16114 &breakpoint_set_cmdlist
,
16115 &breakpoint_show_cmdlist
);
16117 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16119 add_setshow_boolean_cmd ("auto-hw", no_class
,
16120 &automatic_hardware_breakpoints
, _("\
16121 Set automatic usage of hardware breakpoints."), _("\
16122 Show automatic usage of hardware breakpoints."), _("\
16123 If set, the debugger will automatically use hardware breakpoints for\n\
16124 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16125 a warning will be emitted for such breakpoints."),
16127 show_automatic_hardware_breakpoints
,
16128 &breakpoint_set_cmdlist
,
16129 &breakpoint_show_cmdlist
);
16131 add_setshow_boolean_cmd ("always-inserted", class_support
,
16132 &always_inserted_mode
, _("\
16133 Set mode for inserting breakpoints."), _("\
16134 Show mode for inserting breakpoints."), _("\
16135 When this mode is on, breakpoints are inserted immediately as soon as\n\
16136 they're created, kept inserted even when execution stops, and removed\n\
16137 only when the user deletes them. When this mode is off (the default),\n\
16138 breakpoints are inserted only when execution continues, and removed\n\
16139 when execution stops."),
16141 &show_always_inserted_mode
,
16142 &breakpoint_set_cmdlist
,
16143 &breakpoint_show_cmdlist
);
16145 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16146 condition_evaluation_enums
,
16147 &condition_evaluation_mode_1
, _("\
16148 Set mode of breakpoint condition evaluation."), _("\
16149 Show mode of breakpoint condition evaluation."), _("\
16150 When this is set to \"host\", breakpoint conditions will be\n\
16151 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16152 breakpoint conditions will be downloaded to the target (if the target\n\
16153 supports such feature) and conditions will be evaluated on the target's side.\n\
16154 If this is set to \"auto\" (default), this will be automatically set to\n\
16155 \"target\" if it supports condition evaluation, otherwise it will\n\
16156 be set to \"gdb\""),
16157 &set_condition_evaluation_mode
,
16158 &show_condition_evaluation_mode
,
16159 &breakpoint_set_cmdlist
,
16160 &breakpoint_show_cmdlist
);
16162 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16163 Set a breakpoint for an address range.\n\
16164 break-range START-LOCATION, END-LOCATION\n\
16165 where START-LOCATION and END-LOCATION can be one of the following:\n\
16166 LINENUM, for that line in the current file,\n\
16167 FILE:LINENUM, for that line in that file,\n\
16168 +OFFSET, for that number of lines after the current line\n\
16169 or the start of the range\n\
16170 FUNCTION, for the first line in that function,\n\
16171 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16172 *ADDRESS, for the instruction at that address.\n\
16174 The breakpoint will stop execution of the inferior whenever it executes\n\
16175 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16176 range (including START-LOCATION and END-LOCATION)."));
16178 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16179 Set a dynamic printf at specified location.\n\
16180 dprintf location,format string,arg1,arg2,...\n\
16181 location may be a linespec, explicit, or address location.\n"
16182 "\n" LOCATION_HELP_STRING
));
16183 set_cmd_completer (c
, location_completer
);
16185 add_setshow_enum_cmd ("dprintf-style", class_support
,
16186 dprintf_style_enums
, &dprintf_style
, _("\
16187 Set the style of usage for dynamic printf."), _("\
16188 Show the style of usage for dynamic printf."), _("\
16189 This setting chooses how GDB will do a dynamic printf.\n\
16190 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16191 console, as with the \"printf\" command.\n\
16192 If the value is \"call\", the print is done by calling a function in your\n\
16193 program; by default printf(), but you can choose a different function or\n\
16194 output stream by setting dprintf-function and dprintf-channel."),
16195 update_dprintf_commands
, NULL
,
16196 &setlist
, &showlist
);
16198 dprintf_function
= xstrdup ("printf");
16199 add_setshow_string_cmd ("dprintf-function", class_support
,
16200 &dprintf_function
, _("\
16201 Set the function to use for dynamic printf"), _("\
16202 Show the function to use for dynamic printf"), NULL
,
16203 update_dprintf_commands
, NULL
,
16204 &setlist
, &showlist
);
16206 dprintf_channel
= xstrdup ("");
16207 add_setshow_string_cmd ("dprintf-channel", class_support
,
16208 &dprintf_channel
, _("\
16209 Set the channel to use for dynamic printf"), _("\
16210 Show the channel to use for dynamic printf"), NULL
,
16211 update_dprintf_commands
, NULL
,
16212 &setlist
, &showlist
);
16214 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16215 &disconnected_dprintf
, _("\
16216 Set whether dprintf continues after GDB disconnects."), _("\
16217 Show whether dprintf continues after GDB disconnects."), _("\
16218 Use this to let dprintf commands continue to hit and produce output\n\
16219 even if GDB disconnects or detaches from the target."),
16222 &setlist
, &showlist
);
16224 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16225 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16226 (target agent only) This is useful for formatted output in user-defined commands."));
16228 automatic_hardware_breakpoints
= 1;
16230 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16231 observer_attach_thread_exit (remove_threaded_breakpoints
);