1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2019 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/>. */
22 /* Standard C includes. */
25 /* Local non-gdb includes. */
28 #include "arch-utils.h"
31 #include "breakpoint.h"
32 #include "cli/cli-script.h"
33 #include "cli/cli-style.h"
34 #include "cli/cli-utils.h"
36 #include "common/format.h"
37 #include "completer.h"
38 #include "continuations.h"
39 #include "dummy-frame.h"
40 #include "expression.h"
41 #include "filenames.h"
43 #include "gdb-demangle.h"
44 #include "gdb_regex.h"
47 #include "gdbthread.h"
57 #include "mi/mi-main.h"
59 #include "observable.h"
60 #include "parser-defs.h"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 #include "tracepoint.h"
78 /* readline include files */
79 #include "readline/readline.h"
80 #include "readline/history.h"
82 /* readline defines this. */
85 #include "mi/mi-common.h"
86 #include "extension.h"
88 #include "progspace-and-thread.h"
89 #include "common/array-view.h"
90 #include "common/gdb_optional.h"
92 /* Enums for exception-handling support. */
93 enum exception_event_kind
100 /* Prototypes for local functions. */
102 static void map_breakpoint_numbers (const char *,
103 gdb::function_view<void (breakpoint *)>);
105 static void breakpoint_re_set_default (struct breakpoint *);
108 create_sals_from_location_default (const struct event_location *location,
109 struct linespec_result *canonical,
110 enum bptype type_wanted);
112 static void create_breakpoints_sal_default (struct gdbarch *,
113 struct linespec_result *,
114 gdb::unique_xmalloc_ptr<char>,
115 gdb::unique_xmalloc_ptr<char>,
117 enum bpdisp, int, int,
119 const struct breakpoint_ops *,
120 int, int, int, unsigned);
122 static std::vector<symtab_and_line> decode_location_default
123 (struct breakpoint *b, const struct event_location *location,
124 struct program_space *search_pspace);
126 static int can_use_hardware_watchpoint
127 (const std::vector<value_ref_ptr> &vals);
129 static void mention (struct breakpoint *);
131 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
133 const struct breakpoint_ops *);
134 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
135 const struct symtab_and_line *);
137 /* This function is used in gdbtk sources and thus can not be made
139 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
140 struct symtab_and_line,
142 const struct breakpoint_ops *);
144 static struct breakpoint *
145 momentary_breakpoint_from_master (struct breakpoint *orig,
147 const struct breakpoint_ops *ops,
150 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
152 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
156 static void describe_other_breakpoints (struct gdbarch *,
157 struct program_space *, CORE_ADDR,
158 struct obj_section *, int);
160 static int watchpoint_locations_match (struct bp_location *loc1,
161 struct bp_location *loc2);
163 static int breakpoint_location_address_match (struct bp_location *bl,
164 const struct address_space *aspace,
167 static int breakpoint_location_address_range_overlap (struct bp_location *,
168 const address_space *,
171 static int remove_breakpoint (struct bp_location *);
172 static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
174 static enum print_stop_action print_bp_stop_message (bpstat bs);
176 static int hw_breakpoint_used_count (void);
178 static int hw_watchpoint_use_count (struct breakpoint *);
180 static int hw_watchpoint_used_count_others (struct breakpoint *except,
182 int *other_type_used);
184 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
187 static void free_bp_location (struct bp_location *loc);
188 static void incref_bp_location (struct bp_location *loc);
189 static void decref_bp_location (struct bp_location **loc);
191 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
193 /* update_global_location_list's modes of operation wrt to whether to
194 insert locations now. */
195 enum ugll_insert_mode
197 /* Don't insert any breakpoint locations into the inferior, only
198 remove already-inserted locations that no longer should be
199 inserted. Functions that delete a breakpoint or breakpoints
200 should specify this mode, so that deleting a breakpoint doesn't
201 have the side effect of inserting the locations of other
202 breakpoints that are marked not-inserted, but should_be_inserted
203 returns true on them.
205 This behavior is useful is situations close to tear-down -- e.g.,
206 after an exec, while the target still has execution, but
207 breakpoint shadows of the previous executable image should *NOT*
208 be restored to the new image; or before detaching, where the
209 target still has execution and wants to delete breakpoints from
210 GDB's lists, and all breakpoints had already been removed from
214 /* May insert breakpoints iff breakpoints_should_be_inserted_now
215 claims breakpoints should be inserted now. */
218 /* Insert locations now, irrespective of
219 breakpoints_should_be_inserted_now. E.g., say all threads are
220 stopped right now, and the user did "continue". We need to
221 insert breakpoints _before_ resuming the target, but
222 UGLL_MAY_INSERT wouldn't insert them, because
223 breakpoints_should_be_inserted_now returns false at that point,
224 as no thread is running yet. */
228 static void update_global_location_list (enum ugll_insert_mode);
230 static void update_global_location_list_nothrow (enum ugll_insert_mode);
232 static int is_hardware_watchpoint (const struct breakpoint *bpt);
234 static void insert_breakpoint_locations (void);
236 static void trace_pass_command (const char *, int);
238 static void set_tracepoint_count (int num);
240 static int is_masked_watchpoint (const struct breakpoint *b);
242 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
244 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
247 static int strace_marker_p (struct breakpoint *b);
249 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
250 that are implemented on top of software or hardware breakpoints
251 (user breakpoints, internal and momentary breakpoints, etc.). */
252 static struct breakpoint_ops bkpt_base_breakpoint_ops;
254 /* Internal breakpoints class type. */
255 static struct breakpoint_ops internal_breakpoint_ops;
257 /* Momentary breakpoints class type. */
258 static struct breakpoint_ops momentary_breakpoint_ops;
260 /* The breakpoint_ops structure to be used in regular user created
262 struct breakpoint_ops bkpt_breakpoint_ops;
264 /* Breakpoints set on probes. */
265 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
267 /* Dynamic printf class type. */
268 struct breakpoint_ops dprintf_breakpoint_ops;
270 /* The style in which to perform a dynamic printf. This is a user
271 option because different output options have different tradeoffs;
272 if GDB does the printing, there is better error handling if there
273 is a problem with any of the arguments, but using an inferior
274 function lets you have special-purpose printers and sending of
275 output to the same place as compiled-in print functions. */
277 static const char dprintf_style_gdb[] = "gdb";
278 static const char dprintf_style_call[] = "call";
279 static const char dprintf_style_agent[] = "agent";
280 static const char *const dprintf_style_enums[] = {
286 static const char *dprintf_style = dprintf_style_gdb;
288 /* The function to use for dynamic printf if the preferred style is to
289 call into the inferior. The value is simply a string that is
290 copied into the command, so it can be anything that GDB can
291 evaluate to a callable address, not necessarily a function name. */
293 static char *dprintf_function;
295 /* The channel to use for dynamic printf if the preferred style is to
296 call into the inferior; if a nonempty string, it will be passed to
297 the call as the first argument, with the format string as the
298 second. As with the dprintf function, this can be anything that
299 GDB knows how to evaluate, so in addition to common choices like
300 "stderr", this could be an app-specific expression like
301 "mystreams[curlogger]". */
303 static char *dprintf_channel;
305 /* True if dprintf commands should continue to operate even if GDB
307 static int disconnected_dprintf = 1;
309 struct command_line *
310 breakpoint_commands (struct breakpoint *b)
312 return b->commands ? b->commands.get () : NULL;
315 /* Flag indicating that a command has proceeded the inferior past the
316 current breakpoint. */
318 static int breakpoint_proceeded;
321 bpdisp_text (enum bpdisp disp)
323 /* NOTE: the following values are a part of MI protocol and
324 represent values of 'disp' field returned when inferior stops at
326 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
328 return bpdisps[(int) disp];
331 /* Prototypes for exported functions. */
332 /* If FALSE, gdb will not use hardware support for watchpoints, even
333 if such is available. */
334 static int can_use_hw_watchpoints;
337 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
338 struct cmd_list_element *c,
341 fprintf_filtered (file,
342 _("Debugger's willingness to use "
343 "watchpoint hardware is %s.\n"),
347 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
348 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
349 for unrecognized breakpoint locations.
350 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
351 static enum auto_boolean pending_break_support;
353 show_pending_break_support (struct ui_file *file, int from_tty,
354 struct cmd_list_element *c,
357 fprintf_filtered (file,
358 _("Debugger's behavior regarding "
359 "pending breakpoints is %s.\n"),
363 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
364 set with "break" but falling in read-only memory.
365 If 0, gdb will warn about such breakpoints, but won't automatically
366 use hardware breakpoints. */
367 static int automatic_hardware_breakpoints;
369 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
370 struct cmd_list_element *c,
373 fprintf_filtered (file,
374 _("Automatic usage of hardware breakpoints is %s.\n"),
378 /* If on, GDB keeps breakpoints inserted even if the inferior is
379 stopped, and immediately inserts any new breakpoints as soon as
380 they're created. If off (default), GDB keeps breakpoints off of
381 the target as long as possible. That is, it delays inserting
382 breakpoints until the next resume, and removes them again when the
383 target fully stops. This is a bit safer in case GDB crashes while
384 processing user input. */
385 static int always_inserted_mode = 0;
388 show_always_inserted_mode (struct ui_file *file, int from_tty,
389 struct cmd_list_element *c, const char *value)
391 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
395 /* See breakpoint.h. */
398 breakpoints_should_be_inserted_now (void)
400 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
402 /* If breakpoints are global, they should be inserted even if no
403 thread under gdb's control is running, or even if there are
404 no threads under GDB's control yet. */
407 else if (target_has_execution)
409 if (always_inserted_mode)
411 /* The user wants breakpoints inserted even if all threads
416 if (threads_are_executing ())
419 /* Don't remove breakpoints yet if, even though all threads are
420 stopped, we still have events to process. */
421 for (thread_info *tp : all_non_exited_threads ())
423 && tp->suspend.waitstatus_pending_p)
429 static const char condition_evaluation_both[] = "host or target";
431 /* Modes for breakpoint condition evaluation. */
432 static const char condition_evaluation_auto[] = "auto";
433 static const char condition_evaluation_host[] = "host";
434 static const char condition_evaluation_target[] = "target";
435 static const char *const condition_evaluation_enums[] = {
436 condition_evaluation_auto,
437 condition_evaluation_host,
438 condition_evaluation_target,
442 /* Global that holds the current mode for breakpoint condition evaluation. */
443 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
445 /* Global that we use to display information to the user (gets its value from
446 condition_evaluation_mode_1. */
447 static const char *condition_evaluation_mode = condition_evaluation_auto;
449 /* Translate a condition evaluation mode MODE into either "host"
450 or "target". This is used mostly to translate from "auto" to the
451 real setting that is being used. It returns the translated
455 translate_condition_evaluation_mode (const char *mode)
457 if (mode == condition_evaluation_auto)
459 if (target_supports_evaluation_of_breakpoint_conditions ())
460 return condition_evaluation_target;
462 return condition_evaluation_host;
468 /* Discovers what condition_evaluation_auto translates to. */
471 breakpoint_condition_evaluation_mode (void)
473 return translate_condition_evaluation_mode (condition_evaluation_mode);
476 /* Return true if GDB should evaluate breakpoint conditions or false
480 gdb_evaluates_breakpoint_condition_p (void)
482 const char *mode = breakpoint_condition_evaluation_mode ();
484 return (mode == condition_evaluation_host);
487 /* Are we executing breakpoint commands? */
488 static int executing_breakpoint_commands;
490 /* Are overlay event breakpoints enabled? */
491 static int overlay_events_enabled;
493 /* See description in breakpoint.h. */
494 int target_exact_watchpoints = 0;
496 /* Walk the following statement or block through all breakpoints.
497 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
498 current breakpoint. */
500 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
502 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
503 for (B = breakpoint_chain; \
504 B ? (TMP=B->next, 1): 0; \
507 /* Similar iterator for the low-level breakpoints. SAFE variant is
508 not provided so update_global_location_list must not be called
509 while executing the block of ALL_BP_LOCATIONS. */
511 #define ALL_BP_LOCATIONS(B,BP_TMP) \
512 for (BP_TMP = bp_locations; \
513 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
516 /* Iterates through locations with address ADDRESS for the currently selected
517 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
518 to where the loop should start from.
519 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
520 appropriate location to start with. */
522 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
523 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
524 BP_LOCP_TMP = BP_LOCP_START; \
526 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
527 && (*BP_LOCP_TMP)->address == ADDRESS); \
530 /* Iterator for tracepoints only. */
532 #define ALL_TRACEPOINTS(B) \
533 for (B = breakpoint_chain; B; B = B->next) \
534 if (is_tracepoint (B))
536 /* Chains of all breakpoints defined. */
538 struct breakpoint *breakpoint_chain;
540 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
542 static struct bp_location **bp_locations;
544 /* Number of elements of BP_LOCATIONS. */
546 static unsigned bp_locations_count;
548 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
549 ADDRESS for the current elements of BP_LOCATIONS which get a valid
550 result from bp_location_has_shadow. You can use it for roughly
551 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
552 an address you need to read. */
554 static CORE_ADDR bp_locations_placed_address_before_address_max;
556 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
557 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
558 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
559 You can use it for roughly limiting the subrange of BP_LOCATIONS to
560 scan for shadow bytes for an address you need to read. */
562 static CORE_ADDR bp_locations_shadow_len_after_address_max;
564 /* The locations that no longer correspond to any breakpoint, unlinked
565 from the bp_locations array, but for which a hit may still be
566 reported by a target. */
567 static std::vector<bp_location *> moribund_locations;
569 /* Number of last breakpoint made. */
571 static int breakpoint_count;
573 /* The value of `breakpoint_count' before the last command that
574 created breakpoints. If the last (break-like) command created more
575 than one breakpoint, then the difference between BREAKPOINT_COUNT
576 and PREV_BREAKPOINT_COUNT is more than one. */
577 static int prev_breakpoint_count;
579 /* Number of last tracepoint made. */
581 static int tracepoint_count;
583 static struct cmd_list_element *breakpoint_set_cmdlist;
584 static struct cmd_list_element *breakpoint_show_cmdlist;
585 struct cmd_list_element *save_cmdlist;
587 /* See declaration at breakpoint.h. */
590 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
593 struct breakpoint *b = NULL;
597 if (func (b, user_data) != 0)
604 /* Return whether a breakpoint is an active enabled breakpoint. */
606 breakpoint_enabled (struct breakpoint *b)
608 return (b->enable_state == bp_enabled);
611 /* Set breakpoint count to NUM. */
614 set_breakpoint_count (int num)
616 prev_breakpoint_count = breakpoint_count;
617 breakpoint_count = num;
618 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
621 /* Used by `start_rbreak_breakpoints' below, to record the current
622 breakpoint count before "rbreak" creates any breakpoint. */
623 static int rbreak_start_breakpoint_count;
625 /* Called at the start an "rbreak" command to record the first
628 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
630 rbreak_start_breakpoint_count = breakpoint_count;
633 /* Called at the end of an "rbreak" command to record the last
636 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
638 prev_breakpoint_count = rbreak_start_breakpoint_count;
641 /* Used in run_command to zero the hit count when a new run starts. */
644 clear_breakpoint_hit_counts (void)
646 struct breakpoint *b;
653 /* Return the breakpoint with the specified number, or NULL
654 if the number does not refer to an existing breakpoint. */
657 get_breakpoint (int num)
659 struct breakpoint *b;
662 if (b->number == num)
670 /* Mark locations as "conditions have changed" in case the target supports
671 evaluating conditions on its side. */
674 mark_breakpoint_modified (struct breakpoint *b)
676 struct bp_location *loc;
678 /* This is only meaningful if the target is
679 evaluating conditions and if the user has
680 opted for condition evaluation on the target's
682 if (gdb_evaluates_breakpoint_condition_p ()
683 || !target_supports_evaluation_of_breakpoint_conditions ())
686 if (!is_breakpoint (b))
689 for (loc = b->loc; loc; loc = loc->next)
690 loc->condition_changed = condition_modified;
693 /* Mark location as "conditions have changed" in case the target supports
694 evaluating conditions on its side. */
697 mark_breakpoint_location_modified (struct bp_location *loc)
699 /* This is only meaningful if the target is
700 evaluating conditions and if the user has
701 opted for condition evaluation on the target's
703 if (gdb_evaluates_breakpoint_condition_p ()
704 || !target_supports_evaluation_of_breakpoint_conditions ())
708 if (!is_breakpoint (loc->owner))
711 loc->condition_changed = condition_modified;
714 /* Sets the condition-evaluation mode using the static global
715 condition_evaluation_mode. */
718 set_condition_evaluation_mode (const char *args, int from_tty,
719 struct cmd_list_element *c)
721 const char *old_mode, *new_mode;
723 if ((condition_evaluation_mode_1 == condition_evaluation_target)
724 && !target_supports_evaluation_of_breakpoint_conditions ())
726 condition_evaluation_mode_1 = condition_evaluation_mode;
727 warning (_("Target does not support breakpoint condition evaluation.\n"
728 "Using host evaluation mode instead."));
732 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
733 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
735 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
736 settings was "auto". */
737 condition_evaluation_mode = condition_evaluation_mode_1;
739 /* Only update the mode if the user picked a different one. */
740 if (new_mode != old_mode)
742 struct bp_location *loc, **loc_tmp;
743 /* If the user switched to a different evaluation mode, we
744 need to synch the changes with the target as follows:
746 "host" -> "target": Send all (valid) conditions to the target.
747 "target" -> "host": Remove all the conditions from the target.
750 if (new_mode == condition_evaluation_target)
752 /* Mark everything modified and synch conditions with the
754 ALL_BP_LOCATIONS (loc, loc_tmp)
755 mark_breakpoint_location_modified (loc);
759 /* Manually mark non-duplicate locations to synch conditions
760 with the target. We do this to remove all the conditions the
761 target knows about. */
762 ALL_BP_LOCATIONS (loc, loc_tmp)
763 if (is_breakpoint (loc->owner) && loc->inserted)
764 loc->needs_update = 1;
768 update_global_location_list (UGLL_MAY_INSERT);
774 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
775 what "auto" is translating to. */
778 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
779 struct cmd_list_element *c, const char *value)
781 if (condition_evaluation_mode == condition_evaluation_auto)
782 fprintf_filtered (file,
783 _("Breakpoint condition evaluation "
784 "mode is %s (currently %s).\n"),
786 breakpoint_condition_evaluation_mode ());
788 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
792 /* A comparison function for bp_location AP and BP that is used by
793 bsearch. This comparison function only cares about addresses, unlike
794 the more general bp_locations_compare function. */
797 bp_locations_compare_addrs (const void *ap, const void *bp)
799 const struct bp_location *a = *(const struct bp_location **) ap;
800 const struct bp_location *b = *(const struct bp_location **) bp;
802 if (a->address == b->address)
805 return ((a->address > b->address) - (a->address < b->address));
808 /* Helper function to skip all bp_locations with addresses
809 less than ADDRESS. It returns the first bp_location that
810 is greater than or equal to ADDRESS. If none is found, just
813 static struct bp_location **
814 get_first_locp_gte_addr (CORE_ADDR address)
816 struct bp_location dummy_loc;
817 struct bp_location *dummy_locp = &dummy_loc;
818 struct bp_location **locp_found = NULL;
820 /* Initialize the dummy location's address field. */
821 dummy_loc.address = address;
823 /* Find a close match to the first location at ADDRESS. */
824 locp_found = ((struct bp_location **)
825 bsearch (&dummy_locp, bp_locations, bp_locations_count,
826 sizeof (struct bp_location **),
827 bp_locations_compare_addrs));
829 /* Nothing was found, nothing left to do. */
830 if (locp_found == NULL)
833 /* We may have found a location that is at ADDRESS but is not the first in the
834 location's list. Go backwards (if possible) and locate the first one. */
835 while ((locp_found - 1) >= bp_locations
836 && (*(locp_found - 1))->address == address)
843 set_breakpoint_condition (struct breakpoint *b, const char *exp,
846 xfree (b->cond_string);
847 b->cond_string = NULL;
849 if (is_watchpoint (b))
851 struct watchpoint *w = (struct watchpoint *) b;
853 w->cond_exp.reset ();
857 struct bp_location *loc;
859 for (loc = b->loc; loc; loc = loc->next)
863 /* No need to free the condition agent expression
864 bytecode (if we have one). We will handle this
865 when we go through update_global_location_list. */
872 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
876 const char *arg = exp;
878 /* I don't know if it matters whether this is the string the user
879 typed in or the decompiled expression. */
880 b->cond_string = xstrdup (arg);
881 b->condition_not_parsed = 0;
883 if (is_watchpoint (b))
885 struct watchpoint *w = (struct watchpoint *) b;
887 innermost_block_tracker tracker;
889 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
891 error (_("Junk at end of expression"));
892 w->cond_exp_valid_block = tracker.block ();
896 struct bp_location *loc;
898 for (loc = b->loc; loc; loc = loc->next)
902 parse_exp_1 (&arg, loc->address,
903 block_for_pc (loc->address), 0);
905 error (_("Junk at end of expression"));
909 mark_breakpoint_modified (b);
911 gdb::observers::breakpoint_modified.notify (b);
914 /* Completion for the "condition" command. */
917 condition_completer (struct cmd_list_element *cmd,
918 completion_tracker &tracker,
919 const char *text, const char *word)
923 text = skip_spaces (text);
924 space = skip_to_space (text);
928 struct breakpoint *b;
932 /* We don't support completion of history indices. */
933 if (!isdigit (text[1]))
934 complete_internalvar (tracker, &text[1]);
938 /* We're completing the breakpoint number. */
945 xsnprintf (number, sizeof (number), "%d", b->number);
947 if (strncmp (number, text, len) == 0)
949 gdb::unique_xmalloc_ptr<char> copy (xstrdup (number));
950 tracker.add_completion (std::move (copy));
957 /* We're completing the expression part. */
958 text = skip_spaces (space);
959 expression_completer (cmd, tracker, text, word);
962 /* condition N EXP -- set break condition of breakpoint N to EXP. */
965 condition_command (const char *arg, int from_tty)
967 struct breakpoint *b;
972 error_no_arg (_("breakpoint number"));
975 bnum = get_number (&p);
977 error (_("Bad breakpoint argument: '%s'"), arg);
980 if (b->number == bnum)
982 /* Check if this breakpoint has a "stop" method implemented in an
983 extension language. This method and conditions entered into GDB
984 from the CLI are mutually exclusive. */
985 const struct extension_language_defn *extlang
986 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
990 error (_("Only one stop condition allowed. There is currently"
991 " a %s stop condition defined for this breakpoint."),
992 ext_lang_capitalized_name (extlang));
994 set_breakpoint_condition (b, p, from_tty);
996 if (is_breakpoint (b))
997 update_global_location_list (UGLL_MAY_INSERT);
1002 error (_("No breakpoint number %d."), bnum);
1005 /* Check that COMMAND do not contain commands that are suitable
1006 only for tracepoints and not suitable for ordinary breakpoints.
1007 Throw if any such commands is found. */
1010 check_no_tracepoint_commands (struct command_line *commands)
1012 struct command_line *c;
1014 for (c = commands; c; c = c->next)
1016 if (c->control_type == while_stepping_control)
1017 error (_("The 'while-stepping' command can "
1018 "only be used for tracepoints"));
1020 check_no_tracepoint_commands (c->body_list_0.get ());
1021 check_no_tracepoint_commands (c->body_list_1.get ());
1023 /* Not that command parsing removes leading whitespace and comment
1024 lines and also empty lines. So, we only need to check for
1025 command directly. */
1026 if (strstr (c->line, "collect ") == c->line)
1027 error (_("The 'collect' command can only be used for tracepoints"));
1029 if (strstr (c->line, "teval ") == c->line)
1030 error (_("The 'teval' command can only be used for tracepoints"));
1034 struct longjmp_breakpoint : public breakpoint
1036 ~longjmp_breakpoint () override;
1039 /* Encapsulate tests for different types of tracepoints. */
1042 is_tracepoint_type (bptype type)
1044 return (type == bp_tracepoint
1045 || type == bp_fast_tracepoint
1046 || type == bp_static_tracepoint);
1050 is_longjmp_type (bptype type)
1052 return type == bp_longjmp || type == bp_exception;
1056 is_tracepoint (const struct breakpoint *b)
1058 return is_tracepoint_type (b->type);
1061 /* Factory function to create an appropriate instance of breakpoint given
1064 static std::unique_ptr<breakpoint>
1065 new_breakpoint_from_type (bptype type)
1069 if (is_tracepoint_type (type))
1070 b = new tracepoint ();
1071 else if (is_longjmp_type (type))
1072 b = new longjmp_breakpoint ();
1074 b = new breakpoint ();
1076 return std::unique_ptr<breakpoint> (b);
1079 /* A helper function that validates that COMMANDS are valid for a
1080 breakpoint. This function will throw an exception if a problem is
1084 validate_commands_for_breakpoint (struct breakpoint *b,
1085 struct command_line *commands)
1087 if (is_tracepoint (b))
1089 struct tracepoint *t = (struct tracepoint *) b;
1090 struct command_line *c;
1091 struct command_line *while_stepping = 0;
1093 /* Reset the while-stepping step count. The previous commands
1094 might have included a while-stepping action, while the new
1098 /* We need to verify that each top-level element of commands is
1099 valid for tracepoints, that there's at most one
1100 while-stepping element, and that the while-stepping's body
1101 has valid tracing commands excluding nested while-stepping.
1102 We also need to validate the tracepoint action line in the
1103 context of the tracepoint --- validate_actionline actually
1104 has side effects, like setting the tracepoint's
1105 while-stepping STEP_COUNT, in addition to checking if the
1106 collect/teval actions parse and make sense in the
1107 tracepoint's context. */
1108 for (c = commands; c; c = c->next)
1110 if (c->control_type == while_stepping_control)
1112 if (b->type == bp_fast_tracepoint)
1113 error (_("The 'while-stepping' command "
1114 "cannot be used for fast tracepoint"));
1115 else if (b->type == bp_static_tracepoint)
1116 error (_("The 'while-stepping' command "
1117 "cannot be used for static tracepoint"));
1120 error (_("The 'while-stepping' command "
1121 "can be used only once"));
1126 validate_actionline (c->line, b);
1130 struct command_line *c2;
1132 gdb_assert (while_stepping->body_list_1 == nullptr);
1133 c2 = while_stepping->body_list_0.get ();
1134 for (; c2; c2 = c2->next)
1136 if (c2->control_type == while_stepping_control)
1137 error (_("The 'while-stepping' command cannot be nested"));
1143 check_no_tracepoint_commands (commands);
1147 /* Return a vector of all the static tracepoints set at ADDR. The
1148 caller is responsible for releasing the vector. */
1150 std::vector<breakpoint *>
1151 static_tracepoints_here (CORE_ADDR addr)
1153 struct breakpoint *b;
1154 std::vector<breakpoint *> found;
1155 struct bp_location *loc;
1158 if (b->type == bp_static_tracepoint)
1160 for (loc = b->loc; loc; loc = loc->next)
1161 if (loc->address == addr)
1162 found.push_back (b);
1168 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1169 validate that only allowed commands are included. */
1172 breakpoint_set_commands (struct breakpoint *b,
1173 counted_command_line &&commands)
1175 validate_commands_for_breakpoint (b, commands.get ());
1177 b->commands = std::move (commands);
1178 gdb::observers::breakpoint_modified.notify (b);
1181 /* Set the internal `silent' flag on the breakpoint. Note that this
1182 is not the same as the "silent" that may appear in the breakpoint's
1186 breakpoint_set_silent (struct breakpoint *b, int silent)
1188 int old_silent = b->silent;
1191 if (old_silent != silent)
1192 gdb::observers::breakpoint_modified.notify (b);
1195 /* Set the thread for this breakpoint. If THREAD is -1, make the
1196 breakpoint work for any thread. */
1199 breakpoint_set_thread (struct breakpoint *b, int thread)
1201 int old_thread = b->thread;
1204 if (old_thread != thread)
1205 gdb::observers::breakpoint_modified.notify (b);
1208 /* Set the task for this breakpoint. If TASK is 0, make the
1209 breakpoint work for any task. */
1212 breakpoint_set_task (struct breakpoint *b, int task)
1214 int old_task = b->task;
1217 if (old_task != task)
1218 gdb::observers::breakpoint_modified.notify (b);
1222 commands_command_1 (const char *arg, int from_tty,
1223 struct command_line *control)
1225 counted_command_line cmd;
1226 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1227 NULL after the call to read_command_lines if the user provides an empty
1228 list of command by just typing "end". */
1229 bool cmd_read = false;
1231 std::string new_arg;
1233 if (arg == NULL || !*arg)
1235 if (breakpoint_count - prev_breakpoint_count > 1)
1236 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1238 else if (breakpoint_count > 0)
1239 new_arg = string_printf ("%d", breakpoint_count);
1240 arg = new_arg.c_str ();
1243 map_breakpoint_numbers
1244 (arg, [&] (breakpoint *b)
1248 gdb_assert (cmd == NULL);
1249 if (control != NULL)
1250 cmd = control->body_list_0;
1254 = string_printf (_("Type commands for breakpoint(s) "
1255 "%s, one per line."),
1258 auto do_validate = [=] (const char *line)
1260 validate_actionline (line, b);
1262 gdb::function_view<void (const char *)> validator;
1263 if (is_tracepoint (b))
1264 validator = do_validate;
1266 cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
1271 /* If a breakpoint was on the list more than once, we don't need to
1273 if (b->commands != cmd)
1275 validate_commands_for_breakpoint (b, cmd.get ());
1277 gdb::observers::breakpoint_modified.notify (b);
1283 commands_command (const char *arg, int from_tty)
1285 commands_command_1 (arg, from_tty, NULL);
1288 /* Like commands_command, but instead of reading the commands from
1289 input stream, takes them from an already parsed command structure.
1291 This is used by cli-script.c to DTRT with breakpoint commands
1292 that are part of if and while bodies. */
1293 enum command_control_type
1294 commands_from_control_command (const char *arg, struct command_line *cmd)
1296 commands_command_1 (arg, 0, cmd);
1297 return simple_control;
1300 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1303 bp_location_has_shadow (struct bp_location *bl)
1305 if (bl->loc_type != bp_loc_software_breakpoint)
1309 if (bl->target_info.shadow_len == 0)
1310 /* BL isn't valid, or doesn't shadow memory. */
1315 /* Update BUF, which is LEN bytes read from the target address
1316 MEMADDR, by replacing a memory breakpoint with its shadowed
1319 If READBUF is not NULL, this buffer must not overlap with the of
1320 the breakpoint location's shadow_contents buffer. Otherwise, a
1321 failed assertion internal error will be raised. */
1324 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1325 const gdb_byte *writebuf_org,
1326 ULONGEST memaddr, LONGEST len,
1327 struct bp_target_info *target_info,
1328 struct gdbarch *gdbarch)
1330 /* Now do full processing of the found relevant range of elements. */
1331 CORE_ADDR bp_addr = 0;
1335 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1336 current_program_space->aspace, 0))
1338 /* The breakpoint is inserted in a different address space. */
1342 /* Addresses and length of the part of the breakpoint that
1344 bp_addr = target_info->placed_address;
1345 bp_size = target_info->shadow_len;
1347 if (bp_addr + bp_size <= memaddr)
1349 /* The breakpoint is entirely before the chunk of memory we are
1354 if (bp_addr >= memaddr + len)
1356 /* The breakpoint is entirely after the chunk of memory we are
1361 /* Offset within shadow_contents. */
1362 if (bp_addr < memaddr)
1364 /* Only copy the second part of the breakpoint. */
1365 bp_size -= memaddr - bp_addr;
1366 bptoffset = memaddr - bp_addr;
1370 if (bp_addr + bp_size > memaddr + len)
1372 /* Only copy the first part of the breakpoint. */
1373 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1376 if (readbuf != NULL)
1378 /* Verify that the readbuf buffer does not overlap with the
1379 shadow_contents buffer. */
1380 gdb_assert (target_info->shadow_contents >= readbuf + len
1381 || readbuf >= (target_info->shadow_contents
1382 + target_info->shadow_len));
1384 /* Update the read buffer with this inserted breakpoint's
1386 memcpy (readbuf + bp_addr - memaddr,
1387 target_info->shadow_contents + bptoffset, bp_size);
1391 const unsigned char *bp;
1392 CORE_ADDR addr = target_info->reqstd_address;
1395 /* Update the shadow with what we want to write to memory. */
1396 memcpy (target_info->shadow_contents + bptoffset,
1397 writebuf_org + bp_addr - memaddr, bp_size);
1399 /* Determine appropriate breakpoint contents and size for this
1401 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1403 /* Update the final write buffer with this inserted
1404 breakpoint's INSN. */
1405 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1409 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1410 by replacing any memory breakpoints with their shadowed contents.
1412 If READBUF is not NULL, this buffer must not overlap with any of
1413 the breakpoint location's shadow_contents buffers. Otherwise,
1414 a failed assertion internal error will be raised.
1416 The range of shadowed area by each bp_location is:
1417 bl->address - bp_locations_placed_address_before_address_max
1418 up to bl->address + bp_locations_shadow_len_after_address_max
1419 The range we were requested to resolve shadows for is:
1420 memaddr ... memaddr + len
1421 Thus the safe cutoff boundaries for performance optimization are
1422 memaddr + len <= (bl->address
1423 - bp_locations_placed_address_before_address_max)
1425 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1428 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1429 const gdb_byte *writebuf_org,
1430 ULONGEST memaddr, LONGEST len)
1432 /* Left boundary, right boundary and median element of our binary
1434 unsigned bc_l, bc_r, bc;
1436 /* Find BC_L which is a leftmost element which may affect BUF
1437 content. It is safe to report lower value but a failure to
1438 report higher one. */
1441 bc_r = bp_locations_count;
1442 while (bc_l + 1 < bc_r)
1444 struct bp_location *bl;
1446 bc = (bc_l + bc_r) / 2;
1447 bl = bp_locations[bc];
1449 /* Check first BL->ADDRESS will not overflow due to the added
1450 constant. Then advance the left boundary only if we are sure
1451 the BC element can in no way affect the BUF content (MEMADDR
1452 to MEMADDR + LEN range).
1454 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1455 offset so that we cannot miss a breakpoint with its shadow
1456 range tail still reaching MEMADDR. */
1458 if ((bl->address + bp_locations_shadow_len_after_address_max
1460 && (bl->address + bp_locations_shadow_len_after_address_max
1467 /* Due to the binary search above, we need to make sure we pick the
1468 first location that's at BC_L's address. E.g., if there are
1469 multiple locations at the same address, BC_L may end up pointing
1470 at a duplicate location, and miss the "master"/"inserted"
1471 location. Say, given locations L1, L2 and L3 at addresses A and
1474 L1@A, L2@A, L3@B, ...
1476 BC_L could end up pointing at location L2, while the "master"
1477 location could be L1. Since the `loc->inserted' flag is only set
1478 on "master" locations, we'd forget to restore the shadow of L1
1481 && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
1484 /* Now do full processing of the found relevant range of elements. */
1486 for (bc = bc_l; bc < bp_locations_count; bc++)
1488 struct bp_location *bl = bp_locations[bc];
1490 /* bp_location array has BL->OWNER always non-NULL. */
1491 if (bl->owner->type == bp_none)
1492 warning (_("reading through apparently deleted breakpoint #%d?"),
1495 /* Performance optimization: any further element can no longer affect BUF
1498 if (bl->address >= bp_locations_placed_address_before_address_max
1499 && memaddr + len <= (bl->address
1500 - bp_locations_placed_address_before_address_max))
1503 if (!bp_location_has_shadow (bl))
1506 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1507 memaddr, len, &bl->target_info, bl->gdbarch);
1513 /* Return true if BPT is either a software breakpoint or a hardware
1517 is_breakpoint (const struct breakpoint *bpt)
1519 return (bpt->type == bp_breakpoint
1520 || bpt->type == bp_hardware_breakpoint
1521 || bpt->type == bp_dprintf);
1524 /* Return true if BPT is of any hardware watchpoint kind. */
1527 is_hardware_watchpoint (const struct breakpoint *bpt)
1529 return (bpt->type == bp_hardware_watchpoint
1530 || bpt->type == bp_read_watchpoint
1531 || bpt->type == bp_access_watchpoint);
1534 /* Return true if BPT is of any watchpoint kind, hardware or
1538 is_watchpoint (const struct breakpoint *bpt)
1540 return (is_hardware_watchpoint (bpt)
1541 || bpt->type == bp_watchpoint);
1544 /* Returns true if the current thread and its running state are safe
1545 to evaluate or update watchpoint B. Watchpoints on local
1546 expressions need to be evaluated in the context of the thread that
1547 was current when the watchpoint was created, and, that thread needs
1548 to be stopped to be able to select the correct frame context.
1549 Watchpoints on global expressions can be evaluated on any thread,
1550 and in any state. It is presently left to the target allowing
1551 memory accesses when threads are running. */
1554 watchpoint_in_thread_scope (struct watchpoint *b)
1556 return (b->pspace == current_program_space
1557 && (b->watchpoint_thread == null_ptid
1558 || (inferior_ptid == b->watchpoint_thread
1559 && !inferior_thread ()->executing)));
1562 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1563 associated bp_watchpoint_scope breakpoint. */
1566 watchpoint_del_at_next_stop (struct watchpoint *w)
1568 if (w->related_breakpoint != w)
1570 gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope);
1571 gdb_assert (w->related_breakpoint->related_breakpoint == w);
1572 w->related_breakpoint->disposition = disp_del_at_next_stop;
1573 w->related_breakpoint->related_breakpoint = w->related_breakpoint;
1574 w->related_breakpoint = w;
1576 w->disposition = disp_del_at_next_stop;
1579 /* Extract a bitfield value from value VAL using the bit parameters contained in
1582 static struct value *
1583 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1585 struct value *bit_val;
1590 bit_val = allocate_value (value_type (val));
1592 unpack_value_bitfield (bit_val,
1595 value_contents_for_printing (val),
1602 /* Allocate a dummy location and add it to B, which must be a software
1603 watchpoint. This is required because even if a software watchpoint
1604 is not watching any memory, bpstat_stop_status requires a location
1605 to be able to report stops. */
1608 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1609 struct program_space *pspace)
1611 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1613 b->loc = allocate_bp_location (b);
1614 b->loc->pspace = pspace;
1615 b->loc->address = -1;
1616 b->loc->length = -1;
1619 /* Returns true if B is a software watchpoint that is not watching any
1620 memory (e.g., "watch $pc"). */
1623 is_no_memory_software_watchpoint (struct breakpoint *b)
1625 return (b->type == bp_watchpoint
1627 && b->loc->next == NULL
1628 && b->loc->address == -1
1629 && b->loc->length == -1);
1632 /* Assuming that B is a watchpoint:
1633 - Reparse watchpoint expression, if REPARSE is non-zero
1634 - Evaluate expression and store the result in B->val
1635 - Evaluate the condition if there is one, and store the result
1637 - Update the list of values that must be watched in B->loc.
1639 If the watchpoint disposition is disp_del_at_next_stop, then do
1640 nothing. If this is local watchpoint that is out of scope, delete
1643 Even with `set breakpoint always-inserted on' the watchpoints are
1644 removed + inserted on each stop here. Normal breakpoints must
1645 never be removed because they might be missed by a running thread
1646 when debugging in non-stop mode. On the other hand, hardware
1647 watchpoints (is_hardware_watchpoint; processed here) are specific
1648 to each LWP since they are stored in each LWP's hardware debug
1649 registers. Therefore, such LWP must be stopped first in order to
1650 be able to modify its hardware watchpoints.
1652 Hardware watchpoints must be reset exactly once after being
1653 presented to the user. It cannot be done sooner, because it would
1654 reset the data used to present the watchpoint hit to the user. And
1655 it must not be done later because it could display the same single
1656 watchpoint hit during multiple GDB stops. Note that the latter is
1657 relevant only to the hardware watchpoint types bp_read_watchpoint
1658 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1659 not user-visible - its hit is suppressed if the memory content has
1662 The following constraints influence the location where we can reset
1663 hardware watchpoints:
1665 * target_stopped_by_watchpoint and target_stopped_data_address are
1666 called several times when GDB stops.
1669 * Multiple hardware watchpoints can be hit at the same time,
1670 causing GDB to stop. GDB only presents one hardware watchpoint
1671 hit at a time as the reason for stopping, and all the other hits
1672 are presented later, one after the other, each time the user
1673 requests the execution to be resumed. Execution is not resumed
1674 for the threads still having pending hit event stored in
1675 LWP_INFO->STATUS. While the watchpoint is already removed from
1676 the inferior on the first stop the thread hit event is kept being
1677 reported from its cached value by linux_nat_stopped_data_address
1678 until the real thread resume happens after the watchpoint gets
1679 presented and thus its LWP_INFO->STATUS gets reset.
1681 Therefore the hardware watchpoint hit can get safely reset on the
1682 watchpoint removal from inferior. */
1685 update_watchpoint (struct watchpoint *b, int reparse)
1687 int within_current_scope;
1688 struct frame_id saved_frame_id;
1691 /* If this is a local watchpoint, we only want to check if the
1692 watchpoint frame is in scope if the current thread is the thread
1693 that was used to create the watchpoint. */
1694 if (!watchpoint_in_thread_scope (b))
1697 if (b->disposition == disp_del_at_next_stop)
1702 /* Determine if the watchpoint is within scope. */
1703 if (b->exp_valid_block == NULL)
1704 within_current_scope = 1;
1707 struct frame_info *fi = get_current_frame ();
1708 struct gdbarch *frame_arch = get_frame_arch (fi);
1709 CORE_ADDR frame_pc = get_frame_pc (fi);
1711 /* If we're at a point where the stack has been destroyed
1712 (e.g. in a function epilogue), unwinding may not work
1713 properly. Do not attempt to recreate locations at this
1714 point. See similar comments in watchpoint_check. */
1715 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1718 /* Save the current frame's ID so we can restore it after
1719 evaluating the watchpoint expression on its own frame. */
1720 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1721 took a frame parameter, so that we didn't have to change the
1724 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1726 fi = frame_find_by_id (b->watchpoint_frame);
1727 within_current_scope = (fi != NULL);
1728 if (within_current_scope)
1732 /* We don't free locations. They are stored in the bp_location array
1733 and update_global_location_list will eventually delete them and
1734 remove breakpoints if needed. */
1737 if (within_current_scope && reparse)
1742 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1743 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1744 /* If the meaning of expression itself changed, the old value is
1745 no longer relevant. We don't want to report a watchpoint hit
1746 to the user when the old value and the new value may actually
1747 be completely different objects. */
1751 /* Note that unlike with breakpoints, the watchpoint's condition
1752 expression is stored in the breakpoint object, not in the
1753 locations (re)created below. */
1754 if (b->cond_string != NULL)
1756 b->cond_exp.reset ();
1759 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1763 /* If we failed to parse the expression, for example because
1764 it refers to a global variable in a not-yet-loaded shared library,
1765 don't try to insert watchpoint. We don't automatically delete
1766 such watchpoint, though, since failure to parse expression
1767 is different from out-of-scope watchpoint. */
1768 if (!target_has_execution)
1770 /* Without execution, memory can't change. No use to try and
1771 set watchpoint locations. The watchpoint will be reset when
1772 the target gains execution, through breakpoint_re_set. */
1773 if (!can_use_hw_watchpoints)
1775 if (b->ops->works_in_software_mode (b))
1776 b->type = bp_watchpoint;
1778 error (_("Can't set read/access watchpoint when "
1779 "hardware watchpoints are disabled."));
1782 else if (within_current_scope && b->exp)
1785 std::vector<value_ref_ptr> val_chain;
1786 struct value *v, *result;
1787 struct program_space *frame_pspace;
1789 fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
1791 /* Avoid setting b->val if it's already set. The meaning of
1792 b->val is 'the last value' user saw, and we should update
1793 it only if we reported that last value to user. As it
1794 happens, the code that reports it updates b->val directly.
1795 We don't keep track of the memory value for masked
1797 if (!b->val_valid && !is_masked_watchpoint (b))
1799 if (b->val_bitsize != 0)
1800 v = extract_bitfield_from_watchpoint_value (b, v);
1801 b->val = release_value (v);
1805 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1807 /* Look at each value on the value chain. */
1808 gdb_assert (!val_chain.empty ());
1809 for (const value_ref_ptr &iter : val_chain)
1813 /* If it's a memory location, and GDB actually needed
1814 its contents to evaluate the expression, then we
1815 must watch it. If the first value returned is
1816 still lazy, that means an error occurred reading it;
1817 watch it anyway in case it becomes readable. */
1818 if (VALUE_LVAL (v) == lval_memory
1819 && (v == val_chain[0] || ! value_lazy (v)))
1821 struct type *vtype = check_typedef (value_type (v));
1823 /* We only watch structs and arrays if user asked
1824 for it explicitly, never if they just happen to
1825 appear in the middle of some value chain. */
1827 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1828 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1831 enum target_hw_bp_type type;
1832 struct bp_location *loc, **tmp;
1833 int bitpos = 0, bitsize = 0;
1835 if (value_bitsize (v) != 0)
1837 /* Extract the bit parameters out from the bitfield
1839 bitpos = value_bitpos (v);
1840 bitsize = value_bitsize (v);
1842 else if (v == result && b->val_bitsize != 0)
1844 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1845 lvalue whose bit parameters are saved in the fields
1846 VAL_BITPOS and VAL_BITSIZE. */
1847 bitpos = b->val_bitpos;
1848 bitsize = b->val_bitsize;
1851 addr = value_address (v);
1854 /* Skip the bytes that don't contain the bitfield. */
1859 if (b->type == bp_read_watchpoint)
1861 else if (b->type == bp_access_watchpoint)
1864 loc = allocate_bp_location (b);
1865 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1868 loc->gdbarch = get_type_arch (value_type (v));
1870 loc->pspace = frame_pspace;
1871 loc->address = address_significant (loc->gdbarch, addr);
1875 /* Just cover the bytes that make up the bitfield. */
1876 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
1879 loc->length = TYPE_LENGTH (value_type (v));
1881 loc->watchpoint_type = type;
1886 /* Change the type of breakpoint between hardware assisted or
1887 an ordinary watchpoint depending on the hardware support
1888 and free hardware slots. REPARSE is set when the inferior
1893 enum bp_loc_type loc_type;
1894 struct bp_location *bl;
1896 reg_cnt = can_use_hardware_watchpoint (val_chain);
1900 int i, target_resources_ok, other_type_used;
1903 /* Use an exact watchpoint when there's only one memory region to be
1904 watched, and only one debug register is needed to watch it. */
1905 b->exact = target_exact_watchpoints && reg_cnt == 1;
1907 /* We need to determine how many resources are already
1908 used for all other hardware watchpoints plus this one
1909 to see if we still have enough resources to also fit
1910 this watchpoint in as well. */
1912 /* If this is a software watchpoint, we try to turn it
1913 to a hardware one -- count resources as if B was of
1914 hardware watchpoint type. */
1916 if (type == bp_watchpoint)
1917 type = bp_hardware_watchpoint;
1919 /* This watchpoint may or may not have been placed on
1920 the list yet at this point (it won't be in the list
1921 if we're trying to create it for the first time,
1922 through watch_command), so always account for it
1925 /* Count resources used by all watchpoints except B. */
1926 i = hw_watchpoint_used_count_others (b, type, &other_type_used);
1928 /* Add in the resources needed for B. */
1929 i += hw_watchpoint_use_count (b);
1932 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1933 if (target_resources_ok <= 0)
1935 int sw_mode = b->ops->works_in_software_mode (b);
1937 if (target_resources_ok == 0 && !sw_mode)
1938 error (_("Target does not support this type of "
1939 "hardware watchpoint."));
1940 else if (target_resources_ok < 0 && !sw_mode)
1941 error (_("There are not enough available hardware "
1942 "resources for this watchpoint."));
1944 /* Downgrade to software watchpoint. */
1945 b->type = bp_watchpoint;
1949 /* If this was a software watchpoint, we've just
1950 found we have enough resources to turn it to a
1951 hardware watchpoint. Otherwise, this is a
1956 else if (!b->ops->works_in_software_mode (b))
1958 if (!can_use_hw_watchpoints)
1959 error (_("Can't set read/access watchpoint when "
1960 "hardware watchpoints are disabled."));
1962 error (_("Expression cannot be implemented with "
1963 "read/access watchpoint."));
1966 b->type = bp_watchpoint;
1968 loc_type = (b->type == bp_watchpoint? bp_loc_other
1969 : bp_loc_hardware_watchpoint);
1970 for (bl = b->loc; bl; bl = bl->next)
1971 bl->loc_type = loc_type;
1974 /* If a software watchpoint is not watching any memory, then the
1975 above left it without any location set up. But,
1976 bpstat_stop_status requires a location to be able to report
1977 stops, so make sure there's at least a dummy one. */
1978 if (b->type == bp_watchpoint && b->loc == NULL)
1979 software_watchpoint_add_no_memory_location (b, frame_pspace);
1981 else if (!within_current_scope)
1983 printf_filtered (_("\
1984 Watchpoint %d deleted because the program has left the block\n\
1985 in which its expression is valid.\n"),
1987 watchpoint_del_at_next_stop (b);
1990 /* Restore the selected frame. */
1992 select_frame (frame_find_by_id (saved_frame_id));
1996 /* Returns 1 iff breakpoint location should be
1997 inserted in the inferior. We don't differentiate the type of BL's owner
1998 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1999 breakpoint_ops is not defined, because in insert_bp_location,
2000 tracepoint's insert_location will not be called. */
2002 should_be_inserted (struct bp_location *bl)
2004 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2007 if (bl->owner->disposition == disp_del_at_next_stop)
2010 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2013 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2016 /* This is set for example, when we're attached to the parent of a
2017 vfork, and have detached from the child. The child is running
2018 free, and we expect it to do an exec or exit, at which point the
2019 OS makes the parent schedulable again (and the target reports
2020 that the vfork is done). Until the child is done with the shared
2021 memory region, do not insert breakpoints in the parent, otherwise
2022 the child could still trip on the parent's breakpoints. Since
2023 the parent is blocked anyway, it won't miss any breakpoint. */
2024 if (bl->pspace->breakpoints_not_allowed)
2027 /* Don't insert a breakpoint if we're trying to step past its
2028 location, except if the breakpoint is a single-step breakpoint,
2029 and the breakpoint's thread is the thread which is stepping past
2031 if ((bl->loc_type == bp_loc_software_breakpoint
2032 || bl->loc_type == bp_loc_hardware_breakpoint)
2033 && stepping_past_instruction_at (bl->pspace->aspace,
2035 /* The single-step breakpoint may be inserted at the location
2036 we're trying to step if the instruction branches to itself.
2037 However, the instruction won't be executed at all and it may
2038 break the semantics of the instruction, for example, the
2039 instruction is a conditional branch or updates some flags.
2040 We can't fix it unless GDB is able to emulate the instruction
2041 or switch to displaced stepping. */
2042 && !(bl->owner->type == bp_single_step
2043 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2047 fprintf_unfiltered (gdb_stdlog,
2048 "infrun: skipping breakpoint: "
2049 "stepping past insn at: %s\n",
2050 paddress (bl->gdbarch, bl->address));
2055 /* Don't insert watchpoints if we're trying to step past the
2056 instruction that triggered one. */
2057 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2058 && stepping_past_nonsteppable_watchpoint ())
2062 fprintf_unfiltered (gdb_stdlog,
2063 "infrun: stepping past non-steppable watchpoint. "
2064 "skipping watchpoint at %s:%d\n",
2065 paddress (bl->gdbarch, bl->address),
2074 /* Same as should_be_inserted but does the check assuming
2075 that the location is not duplicated. */
2078 unduplicated_should_be_inserted (struct bp_location *bl)
2081 const int save_duplicate = bl->duplicate;
2084 result = should_be_inserted (bl);
2085 bl->duplicate = save_duplicate;
2089 /* Parses a conditional described by an expression COND into an
2090 agent expression bytecode suitable for evaluation
2091 by the bytecode interpreter. Return NULL if there was
2092 any error during parsing. */
2094 static agent_expr_up
2095 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2100 agent_expr_up aexpr;
2102 /* We don't want to stop processing, so catch any errors
2103 that may show up. */
2106 aexpr = gen_eval_for_expr (scope, cond);
2109 CATCH (ex, RETURN_MASK_ERROR)
2111 /* If we got here, it means the condition could not be parsed to a valid
2112 bytecode expression and thus can't be evaluated on the target's side.
2113 It's no use iterating through the conditions. */
2117 /* We have a valid agent expression. */
2121 /* Based on location BL, create a list of breakpoint conditions to be
2122 passed on to the target. If we have duplicated locations with different
2123 conditions, we will add such conditions to the list. The idea is that the
2124 target will evaluate the list of conditions and will only notify GDB when
2125 one of them is true. */
2128 build_target_condition_list (struct bp_location *bl)
2130 struct bp_location **locp = NULL, **loc2p;
2131 int null_condition_or_parse_error = 0;
2132 int modified = bl->needs_update;
2133 struct bp_location *loc;
2135 /* Release conditions left over from a previous insert. */
2136 bl->target_info.conditions.clear ();
2138 /* This is only meaningful if the target is
2139 evaluating conditions and if the user has
2140 opted for condition evaluation on the target's
2142 if (gdb_evaluates_breakpoint_condition_p ()
2143 || !target_supports_evaluation_of_breakpoint_conditions ())
2146 /* Do a first pass to check for locations with no assigned
2147 conditions or conditions that fail to parse to a valid agent expression
2148 bytecode. If any of these happen, then it's no use to send conditions
2149 to the target since this location will always trigger and generate a
2150 response back to GDB. */
2151 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2154 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2158 /* Re-parse the conditions since something changed. In that
2159 case we already freed the condition bytecodes (see
2160 force_breakpoint_reinsertion). We just
2161 need to parse the condition to bytecodes again. */
2162 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2166 /* If we have a NULL bytecode expression, it means something
2167 went wrong or we have a null condition expression. */
2168 if (!loc->cond_bytecode)
2170 null_condition_or_parse_error = 1;
2176 /* If any of these happened, it means we will have to evaluate the conditions
2177 for the location's address on gdb's side. It is no use keeping bytecodes
2178 for all the other duplicate locations, thus we free all of them here.
2180 This is so we have a finer control over which locations' conditions are
2181 being evaluated by GDB or the remote stub. */
2182 if (null_condition_or_parse_error)
2184 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2187 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2189 /* Only go as far as the first NULL bytecode is
2191 if (!loc->cond_bytecode)
2194 loc->cond_bytecode.reset ();
2199 /* No NULL conditions or failed bytecode generation. Build a condition list
2200 for this location's address. */
2201 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2205 && is_breakpoint (loc->owner)
2206 && loc->pspace->num == bl->pspace->num
2207 && loc->owner->enable_state == bp_enabled
2210 /* Add the condition to the vector. This will be used later
2211 to send the conditions to the target. */
2212 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2219 /* Parses a command described by string CMD into an agent expression
2220 bytecode suitable for evaluation by the bytecode interpreter.
2221 Return NULL if there was any error during parsing. */
2223 static agent_expr_up
2224 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2226 const char *cmdrest;
2227 const char *format_start, *format_end;
2228 struct gdbarch *gdbarch = get_current_arch ();
2235 if (*cmdrest == ',')
2237 cmdrest = skip_spaces (cmdrest);
2239 if (*cmdrest++ != '"')
2240 error (_("No format string following the location"));
2242 format_start = cmdrest;
2244 format_pieces fpieces (&cmdrest);
2246 format_end = cmdrest;
2248 if (*cmdrest++ != '"')
2249 error (_("Bad format string, non-terminated '\"'."));
2251 cmdrest = skip_spaces (cmdrest);
2253 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2254 error (_("Invalid argument syntax"));
2256 if (*cmdrest == ',')
2258 cmdrest = skip_spaces (cmdrest);
2260 /* For each argument, make an expression. */
2262 std::vector<struct expression *> argvec;
2263 while (*cmdrest != '\0')
2268 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2269 argvec.push_back (expr.release ());
2271 if (*cmdrest == ',')
2275 agent_expr_up aexpr;
2277 /* We don't want to stop processing, so catch any errors
2278 that may show up. */
2281 aexpr = gen_printf (scope, gdbarch, 0, 0,
2282 format_start, format_end - format_start,
2283 argvec.size (), argvec.data ());
2285 CATCH (ex, RETURN_MASK_ERROR)
2287 /* If we got here, it means the command could not be parsed to a valid
2288 bytecode expression and thus can't be evaluated on the target's side.
2289 It's no use iterating through the other commands. */
2293 /* We have a valid agent expression, return it. */
2297 /* Based on location BL, create a list of breakpoint commands to be
2298 passed on to the target. If we have duplicated locations with
2299 different commands, we will add any such to the list. */
2302 build_target_command_list (struct bp_location *bl)
2304 struct bp_location **locp = NULL, **loc2p;
2305 int null_command_or_parse_error = 0;
2306 int modified = bl->needs_update;
2307 struct bp_location *loc;
2309 /* Clear commands left over from a previous insert. */
2310 bl->target_info.tcommands.clear ();
2312 if (!target_can_run_breakpoint_commands ())
2315 /* For now, limit to agent-style dprintf breakpoints. */
2316 if (dprintf_style != dprintf_style_agent)
2319 /* For now, if we have any duplicate location that isn't a dprintf,
2320 don't install the target-side commands, as that would make the
2321 breakpoint not be reported to the core, and we'd lose
2323 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2326 if (is_breakpoint (loc->owner)
2327 && loc->pspace->num == bl->pspace->num
2328 && loc->owner->type != bp_dprintf)
2332 /* Do a first pass to check for locations with no assigned
2333 conditions or conditions that fail to parse to a valid agent expression
2334 bytecode. If any of these happen, then it's no use to send conditions
2335 to the target since this location will always trigger and generate a
2336 response back to GDB. */
2337 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2340 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2344 /* Re-parse the commands since something changed. In that
2345 case we already freed the command bytecodes (see
2346 force_breakpoint_reinsertion). We just
2347 need to parse the command to bytecodes again. */
2349 = parse_cmd_to_aexpr (bl->address,
2350 loc->owner->extra_string);
2353 /* If we have a NULL bytecode expression, it means something
2354 went wrong or we have a null command expression. */
2355 if (!loc->cmd_bytecode)
2357 null_command_or_parse_error = 1;
2363 /* If anything failed, then we're not doing target-side commands,
2365 if (null_command_or_parse_error)
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2370 if (is_breakpoint (loc->owner)
2371 && loc->pspace->num == bl->pspace->num)
2373 /* Only go as far as the first NULL bytecode is
2375 if (loc->cmd_bytecode == NULL)
2378 loc->cmd_bytecode.reset ();
2383 /* No NULL commands or failed bytecode generation. Build a command list
2384 for this location's address. */
2385 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2388 if (loc->owner->extra_string
2389 && is_breakpoint (loc->owner)
2390 && loc->pspace->num == bl->pspace->num
2391 && loc->owner->enable_state == bp_enabled
2394 /* Add the command to the vector. This will be used later
2395 to send the commands to the target. */
2396 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2400 bl->target_info.persist = 0;
2401 /* Maybe flag this location as persistent. */
2402 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2403 bl->target_info.persist = 1;
2406 /* Return the kind of breakpoint on address *ADDR. Get the kind
2407 of breakpoint according to ADDR except single-step breakpoint.
2408 Get the kind of single-step breakpoint according to the current
2412 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2414 if (bl->owner->type == bp_single_step)
2416 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2417 struct regcache *regcache;
2419 regcache = get_thread_regcache (thr);
2421 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2425 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2428 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2429 location. Any error messages are printed to TMP_ERROR_STREAM; and
2430 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2431 Returns 0 for success, 1 if the bp_location type is not supported or
2434 NOTE drow/2003-09-09: This routine could be broken down to an
2435 object-style method for each breakpoint or catchpoint type. */
2437 insert_bp_location (struct bp_location *bl,
2438 struct ui_file *tmp_error_stream,
2439 int *disabled_breaks,
2440 int *hw_breakpoint_error,
2441 int *hw_bp_error_explained_already)
2443 gdb_exception bp_excpt = exception_none;
2445 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2448 /* Note we don't initialize bl->target_info, as that wipes out
2449 the breakpoint location's shadow_contents if the breakpoint
2450 is still inserted at that location. This in turn breaks
2451 target_read_memory which depends on these buffers when
2452 a memory read is requested at the breakpoint location:
2453 Once the target_info has been wiped, we fail to see that
2454 we have a breakpoint inserted at that address and thus
2455 read the breakpoint instead of returning the data saved in
2456 the breakpoint location's shadow contents. */
2457 bl->target_info.reqstd_address = bl->address;
2458 bl->target_info.placed_address_space = bl->pspace->aspace;
2459 bl->target_info.length = bl->length;
2461 /* When working with target-side conditions, we must pass all the conditions
2462 for the same breakpoint address down to the target since GDB will not
2463 insert those locations. With a list of breakpoint conditions, the target
2464 can decide when to stop and notify GDB. */
2466 if (is_breakpoint (bl->owner))
2468 build_target_condition_list (bl);
2469 build_target_command_list (bl);
2470 /* Reset the modification marker. */
2471 bl->needs_update = 0;
2474 if (bl->loc_type == bp_loc_software_breakpoint
2475 || bl->loc_type == bp_loc_hardware_breakpoint)
2477 if (bl->owner->type != bp_hardware_breakpoint)
2479 /* If the explicitly specified breakpoint type
2480 is not hardware breakpoint, check the memory map to see
2481 if the breakpoint address is in read only memory or not.
2483 Two important cases are:
2484 - location type is not hardware breakpoint, memory
2485 is readonly. We change the type of the location to
2486 hardware breakpoint.
2487 - location type is hardware breakpoint, memory is
2488 read-write. This means we've previously made the
2489 location hardware one, but then the memory map changed,
2492 When breakpoints are removed, remove_breakpoints will use
2493 location types we've just set here, the only possible
2494 problem is that memory map has changed during running
2495 program, but it's not going to work anyway with current
2497 struct mem_region *mr
2498 = lookup_mem_region (bl->target_info.reqstd_address);
2502 if (automatic_hardware_breakpoints)
2504 enum bp_loc_type new_type;
2506 if (mr->attrib.mode != MEM_RW)
2507 new_type = bp_loc_hardware_breakpoint;
2509 new_type = bp_loc_software_breakpoint;
2511 if (new_type != bl->loc_type)
2513 static int said = 0;
2515 bl->loc_type = new_type;
2518 fprintf_filtered (gdb_stdout,
2519 _("Note: automatically using "
2520 "hardware breakpoints for "
2521 "read-only addresses.\n"));
2526 else if (bl->loc_type == bp_loc_software_breakpoint
2527 && mr->attrib.mode != MEM_RW)
2529 fprintf_unfiltered (tmp_error_stream,
2530 _("Cannot insert breakpoint %d.\n"
2531 "Cannot set software breakpoint "
2532 "at read-only address %s\n"),
2534 paddress (bl->gdbarch, bl->address));
2540 /* First check to see if we have to handle an overlay. */
2541 if (overlay_debugging == ovly_off
2542 || bl->section == NULL
2543 || !(section_is_overlay (bl->section)))
2545 /* No overlay handling: just set the breakpoint. */
2550 val = bl->owner->ops->insert_location (bl);
2552 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2554 CATCH (e, RETURN_MASK_ALL)
2562 /* This breakpoint is in an overlay section.
2563 Shall we set a breakpoint at the LMA? */
2564 if (!overlay_events_enabled)
2566 /* Yes -- overlay event support is not active,
2567 so we must try to set a breakpoint at the LMA.
2568 This will not work for a hardware breakpoint. */
2569 if (bl->loc_type == bp_loc_hardware_breakpoint)
2570 warning (_("hardware breakpoint %d not supported in overlay!"),
2574 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2576 /* Set a software (trap) breakpoint at the LMA. */
2577 bl->overlay_target_info = bl->target_info;
2578 bl->overlay_target_info.reqstd_address = addr;
2580 /* No overlay handling: just set the breakpoint. */
2585 bl->overlay_target_info.kind
2586 = breakpoint_kind (bl, &addr);
2587 bl->overlay_target_info.placed_address = addr;
2588 val = target_insert_breakpoint (bl->gdbarch,
2589 &bl->overlay_target_info);
2592 = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2594 CATCH (e, RETURN_MASK_ALL)
2600 if (bp_excpt.reason != 0)
2601 fprintf_unfiltered (tmp_error_stream,
2602 "Overlay breakpoint %d "
2603 "failed: in ROM?\n",
2607 /* Shall we set a breakpoint at the VMA? */
2608 if (section_is_mapped (bl->section))
2610 /* Yes. This overlay section is mapped into memory. */
2615 val = bl->owner->ops->insert_location (bl);
2617 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2619 CATCH (e, RETURN_MASK_ALL)
2627 /* No. This breakpoint will not be inserted.
2628 No error, but do not mark the bp as 'inserted'. */
2633 if (bp_excpt.reason != 0)
2635 /* Can't set the breakpoint. */
2637 /* In some cases, we might not be able to insert a
2638 breakpoint in a shared library that has already been
2639 removed, but we have not yet processed the shlib unload
2640 event. Unfortunately, some targets that implement
2641 breakpoint insertion themselves can't tell why the
2642 breakpoint insertion failed (e.g., the remote target
2643 doesn't define error codes), so we must treat generic
2644 errors as memory errors. */
2645 if (bp_excpt.reason == RETURN_ERROR
2646 && (bp_excpt.error == GENERIC_ERROR
2647 || bp_excpt.error == MEMORY_ERROR)
2648 && bl->loc_type == bp_loc_software_breakpoint
2649 && (solib_name_from_address (bl->pspace, bl->address)
2650 || shared_objfile_contains_address_p (bl->pspace,
2653 /* See also: disable_breakpoints_in_shlibs. */
2654 bl->shlib_disabled = 1;
2655 gdb::observers::breakpoint_modified.notify (bl->owner);
2656 if (!*disabled_breaks)
2658 fprintf_unfiltered (tmp_error_stream,
2659 "Cannot insert breakpoint %d.\n",
2661 fprintf_unfiltered (tmp_error_stream,
2662 "Temporarily disabling shared "
2663 "library breakpoints:\n");
2665 *disabled_breaks = 1;
2666 fprintf_unfiltered (tmp_error_stream,
2667 "breakpoint #%d\n", bl->owner->number);
2672 if (bl->loc_type == bp_loc_hardware_breakpoint)
2674 *hw_breakpoint_error = 1;
2675 *hw_bp_error_explained_already = bp_excpt.message != NULL;
2676 fprintf_unfiltered (tmp_error_stream,
2677 "Cannot insert hardware breakpoint %d%s",
2679 bp_excpt.message ? ":" : ".\n");
2680 if (bp_excpt.message != NULL)
2681 fprintf_unfiltered (tmp_error_stream, "%s.\n",
2686 if (bp_excpt.message == NULL)
2689 = memory_error_message (TARGET_XFER_E_IO,
2690 bl->gdbarch, bl->address);
2692 fprintf_unfiltered (tmp_error_stream,
2693 "Cannot insert breakpoint %d.\n"
2695 bl->owner->number, message.c_str ());
2699 fprintf_unfiltered (tmp_error_stream,
2700 "Cannot insert breakpoint %d: %s\n",
2715 else if (bl->loc_type == bp_loc_hardware_watchpoint
2716 /* NOTE drow/2003-09-08: This state only exists for removing
2717 watchpoints. It's not clear that it's necessary... */
2718 && bl->owner->disposition != disp_del_at_next_stop)
2722 gdb_assert (bl->owner->ops != NULL
2723 && bl->owner->ops->insert_location != NULL);
2725 val = bl->owner->ops->insert_location (bl);
2727 /* If trying to set a read-watchpoint, and it turns out it's not
2728 supported, try emulating one with an access watchpoint. */
2729 if (val == 1 && bl->watchpoint_type == hw_read)
2731 struct bp_location *loc, **loc_temp;
2733 /* But don't try to insert it, if there's already another
2734 hw_access location that would be considered a duplicate
2736 ALL_BP_LOCATIONS (loc, loc_temp)
2738 && loc->watchpoint_type == hw_access
2739 && watchpoint_locations_match (bl, loc))
2743 bl->target_info = loc->target_info;
2744 bl->watchpoint_type = hw_access;
2751 bl->watchpoint_type = hw_access;
2752 val = bl->owner->ops->insert_location (bl);
2755 /* Back to the original value. */
2756 bl->watchpoint_type = hw_read;
2760 bl->inserted = (val == 0);
2763 else if (bl->owner->type == bp_catchpoint)
2767 gdb_assert (bl->owner->ops != NULL
2768 && bl->owner->ops->insert_location != NULL);
2770 val = bl->owner->ops->insert_location (bl);
2773 bl->owner->enable_state = bp_disabled;
2777 Error inserting catchpoint %d: Your system does not support this type\n\
2778 of catchpoint."), bl->owner->number);
2780 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2783 bl->inserted = (val == 0);
2785 /* We've already printed an error message if there was a problem
2786 inserting this catchpoint, and we've disabled the catchpoint,
2787 so just return success. */
2794 /* This function is called when program space PSPACE is about to be
2795 deleted. It takes care of updating breakpoints to not reference
2799 breakpoint_program_space_exit (struct program_space *pspace)
2801 struct breakpoint *b, *b_temp;
2802 struct bp_location *loc, **loc_temp;
2804 /* Remove any breakpoint that was set through this program space. */
2805 ALL_BREAKPOINTS_SAFE (b, b_temp)
2807 if (b->pspace == pspace)
2808 delete_breakpoint (b);
2811 /* Breakpoints set through other program spaces could have locations
2812 bound to PSPACE as well. Remove those. */
2813 ALL_BP_LOCATIONS (loc, loc_temp)
2815 struct bp_location *tmp;
2817 if (loc->pspace == pspace)
2819 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2820 if (loc->owner->loc == loc)
2821 loc->owner->loc = loc->next;
2823 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2824 if (tmp->next == loc)
2826 tmp->next = loc->next;
2832 /* Now update the global location list to permanently delete the
2833 removed locations above. */
2834 update_global_location_list (UGLL_DONT_INSERT);
2837 /* Make sure all breakpoints are inserted in inferior.
2838 Throws exception on any error.
2839 A breakpoint that is already inserted won't be inserted
2840 again, so calling this function twice is safe. */
2842 insert_breakpoints (void)
2844 struct breakpoint *bpt;
2846 ALL_BREAKPOINTS (bpt)
2847 if (is_hardware_watchpoint (bpt))
2849 struct watchpoint *w = (struct watchpoint *) bpt;
2851 update_watchpoint (w, 0 /* don't reparse. */);
2854 /* Updating watchpoints creates new locations, so update the global
2855 location list. Explicitly tell ugll to insert locations and
2856 ignore breakpoints_always_inserted_mode. */
2857 update_global_location_list (UGLL_INSERT);
2860 /* Invoke CALLBACK for each of bp_location. */
2863 iterate_over_bp_locations (walk_bp_location_callback callback)
2865 struct bp_location *loc, **loc_tmp;
2867 ALL_BP_LOCATIONS (loc, loc_tmp)
2869 callback (loc, NULL);
2873 /* This is used when we need to synch breakpoint conditions between GDB and the
2874 target. It is the case with deleting and disabling of breakpoints when using
2875 always-inserted mode. */
2878 update_inserted_breakpoint_locations (void)
2880 struct bp_location *bl, **blp_tmp;
2883 int disabled_breaks = 0;
2884 int hw_breakpoint_error = 0;
2885 int hw_bp_details_reported = 0;
2887 string_file tmp_error_stream;
2889 /* Explicitly mark the warning -- this will only be printed if
2890 there was an error. */
2891 tmp_error_stream.puts ("Warning:\n");
2893 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2895 ALL_BP_LOCATIONS (bl, blp_tmp)
2897 /* We only want to update software breakpoints and hardware
2899 if (!is_breakpoint (bl->owner))
2902 /* We only want to update locations that are already inserted
2903 and need updating. This is to avoid unwanted insertion during
2904 deletion of breakpoints. */
2905 if (!bl->inserted || !bl->needs_update)
2908 switch_to_program_space_and_thread (bl->pspace);
2910 /* For targets that support global breakpoints, there's no need
2911 to select an inferior to insert breakpoint to. In fact, even
2912 if we aren't attached to any process yet, we should still
2913 insert breakpoints. */
2914 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2915 && inferior_ptid == null_ptid)
2918 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
2919 &hw_breakpoint_error, &hw_bp_details_reported);
2926 target_terminal::ours_for_output ();
2927 error_stream (tmp_error_stream);
2931 /* Used when starting or continuing the program. */
2934 insert_breakpoint_locations (void)
2936 struct breakpoint *bpt;
2937 struct bp_location *bl, **blp_tmp;
2940 int disabled_breaks = 0;
2941 int hw_breakpoint_error = 0;
2942 int hw_bp_error_explained_already = 0;
2944 string_file tmp_error_stream;
2946 /* Explicitly mark the warning -- this will only be printed if
2947 there was an error. */
2948 tmp_error_stream.puts ("Warning:\n");
2950 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2952 ALL_BP_LOCATIONS (bl, blp_tmp)
2954 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2957 /* There is no point inserting thread-specific breakpoints if
2958 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2959 has BL->OWNER always non-NULL. */
2960 if (bl->owner->thread != -1
2961 && !valid_global_thread_id (bl->owner->thread))
2964 switch_to_program_space_and_thread (bl->pspace);
2966 /* For targets that support global breakpoints, there's no need
2967 to select an inferior to insert breakpoint to. In fact, even
2968 if we aren't attached to any process yet, we should still
2969 insert breakpoints. */
2970 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2971 && inferior_ptid == null_ptid)
2974 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
2975 &hw_breakpoint_error, &hw_bp_error_explained_already);
2980 /* If we failed to insert all locations of a watchpoint, remove
2981 them, as half-inserted watchpoint is of limited use. */
2982 ALL_BREAKPOINTS (bpt)
2984 int some_failed = 0;
2985 struct bp_location *loc;
2987 if (!is_hardware_watchpoint (bpt))
2990 if (!breakpoint_enabled (bpt))
2993 if (bpt->disposition == disp_del_at_next_stop)
2996 for (loc = bpt->loc; loc; loc = loc->next)
2997 if (!loc->inserted && should_be_inserted (loc))
3004 for (loc = bpt->loc; loc; loc = loc->next)
3006 remove_breakpoint (loc);
3008 hw_breakpoint_error = 1;
3009 tmp_error_stream.printf ("Could not insert "
3010 "hardware watchpoint %d.\n",
3018 /* If a hardware breakpoint or watchpoint was inserted, add a
3019 message about possibly exhausted resources. */
3020 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3022 tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
3023 You may have requested too many hardware breakpoints/watchpoints.\n");
3025 target_terminal::ours_for_output ();
3026 error_stream (tmp_error_stream);
3030 /* Used when the program stops.
3031 Returns zero if successful, or non-zero if there was a problem
3032 removing a breakpoint location. */
3035 remove_breakpoints (void)
3037 struct bp_location *bl, **blp_tmp;
3040 ALL_BP_LOCATIONS (bl, blp_tmp)
3042 if (bl->inserted && !is_tracepoint (bl->owner))
3043 val |= remove_breakpoint (bl);
3048 /* When a thread exits, remove breakpoints that are related to
3052 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3054 struct breakpoint *b, *b_tmp;
3056 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3058 if (b->thread == tp->global_num && user_breakpoint_p (b))
3060 b->disposition = disp_del_at_next_stop;
3062 printf_filtered (_("\
3063 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3064 b->number, print_thread_id (tp));
3066 /* Hide it from the user. */
3072 /* Remove breakpoints of inferior INF. */
3075 remove_breakpoints_inf (inferior *inf)
3077 struct bp_location *bl, **blp_tmp;
3080 ALL_BP_LOCATIONS (bl, blp_tmp)
3082 if (bl->pspace != inf->pspace)
3085 if (bl->inserted && !bl->target_info.persist)
3087 val = remove_breakpoint (bl);
3095 static int internal_breakpoint_number = -1;
3097 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3098 If INTERNAL is non-zero, the breakpoint number will be populated
3099 from internal_breakpoint_number and that variable decremented.
3100 Otherwise the breakpoint number will be populated from
3101 breakpoint_count and that value incremented. Internal breakpoints
3102 do not set the internal var bpnum. */
3104 set_breakpoint_number (int internal, struct breakpoint *b)
3107 b->number = internal_breakpoint_number--;
3110 set_breakpoint_count (breakpoint_count + 1);
3111 b->number = breakpoint_count;
3115 static struct breakpoint *
3116 create_internal_breakpoint (struct gdbarch *gdbarch,
3117 CORE_ADDR address, enum bptype type,
3118 const struct breakpoint_ops *ops)
3120 symtab_and_line sal;
3122 sal.section = find_pc_overlay (sal.pc);
3123 sal.pspace = current_program_space;
3125 breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops);
3126 b->number = internal_breakpoint_number--;
3127 b->disposition = disp_donttouch;
3132 static const char *const longjmp_names[] =
3134 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3136 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3138 /* Per-objfile data private to breakpoint.c. */
3139 struct breakpoint_objfile_data
3141 /* Minimal symbol for "_ovly_debug_event" (if any). */
3142 struct bound_minimal_symbol overlay_msym {};
3144 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3145 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {};
3147 /* True if we have looked for longjmp probes. */
3148 int longjmp_searched = 0;
3150 /* SystemTap probe points for longjmp (if any). These are non-owning
3152 std::vector<probe *> longjmp_probes;
3154 /* Minimal symbol for "std::terminate()" (if any). */
3155 struct bound_minimal_symbol terminate_msym {};
3157 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3158 struct bound_minimal_symbol exception_msym {};
3160 /* True if we have looked for exception probes. */
3161 int exception_searched = 0;
3163 /* SystemTap probe points for unwinding (if any). These are non-owning
3165 std::vector<probe *> exception_probes;
3168 static const struct objfile_data *breakpoint_objfile_key;
3170 /* Minimal symbol not found sentinel. */
3171 static struct minimal_symbol msym_not_found;
3173 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3176 msym_not_found_p (const struct minimal_symbol *msym)
3178 return msym == &msym_not_found;
3181 /* Return per-objfile data needed by breakpoint.c.
3182 Allocate the data if necessary. */
3184 static struct breakpoint_objfile_data *
3185 get_breakpoint_objfile_data (struct objfile *objfile)
3187 struct breakpoint_objfile_data *bp_objfile_data;
3189 bp_objfile_data = ((struct breakpoint_objfile_data *)
3190 objfile_data (objfile, breakpoint_objfile_key));
3191 if (bp_objfile_data == NULL)
3193 bp_objfile_data = new breakpoint_objfile_data ();
3194 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3196 return bp_objfile_data;
3200 free_breakpoint_objfile_data (struct objfile *obj, void *data)
3202 struct breakpoint_objfile_data *bp_objfile_data
3203 = (struct breakpoint_objfile_data *) data;
3205 delete bp_objfile_data;
3209 create_overlay_event_breakpoint (void)
3211 const char *const func_name = "_ovly_debug_event";
3213 for (objfile *objfile : current_program_space->objfiles ())
3215 struct breakpoint *b;
3216 struct breakpoint_objfile_data *bp_objfile_data;
3218 struct explicit_location explicit_loc;
3220 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3222 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3225 if (bp_objfile_data->overlay_msym.minsym == NULL)
3227 struct bound_minimal_symbol m;
3229 m = lookup_minimal_symbol_text (func_name, objfile);
3230 if (m.minsym == NULL)
3232 /* Avoid future lookups in this objfile. */
3233 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3236 bp_objfile_data->overlay_msym = m;
3239 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3240 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3242 &internal_breakpoint_ops);
3243 initialize_explicit_location (&explicit_loc);
3244 explicit_loc.function_name = ASTRDUP (func_name);
3245 b->location = new_explicit_location (&explicit_loc);
3247 if (overlay_debugging == ovly_auto)
3249 b->enable_state = bp_enabled;
3250 overlay_events_enabled = 1;
3254 b->enable_state = bp_disabled;
3255 overlay_events_enabled = 0;
3261 create_longjmp_master_breakpoint (void)
3263 struct program_space *pspace;
3265 scoped_restore_current_program_space restore_pspace;
3267 ALL_PSPACES (pspace)
3269 set_current_program_space (pspace);
3271 for (objfile *objfile : current_program_space->objfiles ())
3274 struct gdbarch *gdbarch;
3275 struct breakpoint_objfile_data *bp_objfile_data;
3277 gdbarch = get_objfile_arch (objfile);
3279 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3281 if (!bp_objfile_data->longjmp_searched)
3283 std::vector<probe *> ret
3284 = find_probes_in_objfile (objfile, "libc", "longjmp");
3288 /* We are only interested in checking one element. */
3291 if (!p->can_evaluate_arguments ())
3293 /* We cannot use the probe interface here, because it does
3294 not know how to evaluate arguments. */
3298 bp_objfile_data->longjmp_probes = ret;
3299 bp_objfile_data->longjmp_searched = 1;
3302 if (!bp_objfile_data->longjmp_probes.empty ())
3304 for (probe *p : bp_objfile_data->longjmp_probes)
3306 struct breakpoint *b;
3308 b = create_internal_breakpoint (gdbarch,
3309 p->get_relocated_address (objfile),
3311 &internal_breakpoint_ops);
3312 b->location = new_probe_location ("-probe-stap libc:longjmp");
3313 b->enable_state = bp_disabled;
3319 if (!gdbarch_get_longjmp_target_p (gdbarch))
3322 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3324 struct breakpoint *b;
3325 const char *func_name;
3327 struct explicit_location explicit_loc;
3329 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3332 func_name = longjmp_names[i];
3333 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3335 struct bound_minimal_symbol m;
3337 m = lookup_minimal_symbol_text (func_name, objfile);
3338 if (m.minsym == NULL)
3340 /* Prevent future lookups in this objfile. */
3341 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3344 bp_objfile_data->longjmp_msym[i] = m;
3347 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3348 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3349 &internal_breakpoint_ops);
3350 initialize_explicit_location (&explicit_loc);
3351 explicit_loc.function_name = ASTRDUP (func_name);
3352 b->location = new_explicit_location (&explicit_loc);
3353 b->enable_state = bp_disabled;
3359 /* Create a master std::terminate breakpoint. */
3361 create_std_terminate_master_breakpoint (void)
3363 struct program_space *pspace;
3364 const char *const func_name = "std::terminate()";
3366 scoped_restore_current_program_space restore_pspace;
3368 ALL_PSPACES (pspace)
3372 set_current_program_space (pspace);
3374 for (objfile *objfile : current_program_space->objfiles ())
3376 struct breakpoint *b;
3377 struct breakpoint_objfile_data *bp_objfile_data;
3378 struct explicit_location explicit_loc;
3380 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3382 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3385 if (bp_objfile_data->terminate_msym.minsym == NULL)
3387 struct bound_minimal_symbol m;
3389 m = lookup_minimal_symbol (func_name, NULL, objfile);
3390 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3391 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3393 /* Prevent future lookups in this objfile. */
3394 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3397 bp_objfile_data->terminate_msym = m;
3400 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3401 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3402 bp_std_terminate_master,
3403 &internal_breakpoint_ops);
3404 initialize_explicit_location (&explicit_loc);
3405 explicit_loc.function_name = ASTRDUP (func_name);
3406 b->location = new_explicit_location (&explicit_loc);
3407 b->enable_state = bp_disabled;
3412 /* Install a master breakpoint on the unwinder's debug hook. */
3415 create_exception_master_breakpoint (void)
3417 const char *const func_name = "_Unwind_DebugHook";
3419 for (objfile *objfile : current_program_space->objfiles ())
3421 struct breakpoint *b;
3422 struct gdbarch *gdbarch;
3423 struct breakpoint_objfile_data *bp_objfile_data;
3425 struct explicit_location explicit_loc;
3427 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3429 /* We prefer the SystemTap probe point if it exists. */
3430 if (!bp_objfile_data->exception_searched)
3432 std::vector<probe *> ret
3433 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3437 /* We are only interested in checking one element. */
3440 if (!p->can_evaluate_arguments ())
3442 /* We cannot use the probe interface here, because it does
3443 not know how to evaluate arguments. */
3447 bp_objfile_data->exception_probes = ret;
3448 bp_objfile_data->exception_searched = 1;
3451 if (!bp_objfile_data->exception_probes.empty ())
3453 gdbarch = get_objfile_arch (objfile);
3455 for (probe *p : bp_objfile_data->exception_probes)
3457 b = create_internal_breakpoint (gdbarch,
3458 p->get_relocated_address (objfile),
3459 bp_exception_master,
3460 &internal_breakpoint_ops);
3461 b->location = new_probe_location ("-probe-stap libgcc:unwind");
3462 b->enable_state = bp_disabled;
3468 /* Otherwise, try the hook function. */
3470 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3473 gdbarch = get_objfile_arch (objfile);
3475 if (bp_objfile_data->exception_msym.minsym == NULL)
3477 struct bound_minimal_symbol debug_hook;
3479 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3480 if (debug_hook.minsym == NULL)
3482 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3486 bp_objfile_data->exception_msym = debug_hook;
3489 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3490 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3491 current_top_target ());
3492 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3493 &internal_breakpoint_ops);
3494 initialize_explicit_location (&explicit_loc);
3495 explicit_loc.function_name = ASTRDUP (func_name);
3496 b->location = new_explicit_location (&explicit_loc);
3497 b->enable_state = bp_disabled;
3501 /* Does B have a location spec? */
3504 breakpoint_event_location_empty_p (const struct breakpoint *b)
3506 return b->location != NULL && event_location_empty_p (b->location.get ());
3510 update_breakpoints_after_exec (void)
3512 struct breakpoint *b, *b_tmp;
3513 struct bp_location *bploc, **bplocp_tmp;
3515 /* We're about to delete breakpoints from GDB's lists. If the
3516 INSERTED flag is true, GDB will try to lift the breakpoints by
3517 writing the breakpoints' "shadow contents" back into memory. The
3518 "shadow contents" are NOT valid after an exec, so GDB should not
3519 do that. Instead, the target is responsible from marking
3520 breakpoints out as soon as it detects an exec. We don't do that
3521 here instead, because there may be other attempts to delete
3522 breakpoints after detecting an exec and before reaching here. */
3523 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3524 if (bploc->pspace == current_program_space)
3525 gdb_assert (!bploc->inserted);
3527 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3529 if (b->pspace != current_program_space)
3532 /* Solib breakpoints must be explicitly reset after an exec(). */
3533 if (b->type == bp_shlib_event)
3535 delete_breakpoint (b);
3539 /* JIT breakpoints must be explicitly reset after an exec(). */
3540 if (b->type == bp_jit_event)
3542 delete_breakpoint (b);
3546 /* Thread event breakpoints must be set anew after an exec(),
3547 as must overlay event and longjmp master breakpoints. */
3548 if (b->type == bp_thread_event || b->type == bp_overlay_event
3549 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3550 || b->type == bp_exception_master)
3552 delete_breakpoint (b);
3556 /* Step-resume breakpoints are meaningless after an exec(). */
3557 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3559 delete_breakpoint (b);
3563 /* Just like single-step breakpoints. */
3564 if (b->type == bp_single_step)
3566 delete_breakpoint (b);
3570 /* Longjmp and longjmp-resume breakpoints are also meaningless
3572 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3573 || b->type == bp_longjmp_call_dummy
3574 || b->type == bp_exception || b->type == bp_exception_resume)
3576 delete_breakpoint (b);
3580 if (b->type == bp_catchpoint)
3582 /* For now, none of the bp_catchpoint breakpoints need to
3583 do anything at this point. In the future, if some of
3584 the catchpoints need to something, we will need to add
3585 a new method, and call this method from here. */
3589 /* bp_finish is a special case. The only way we ought to be able
3590 to see one of these when an exec() has happened, is if the user
3591 caught a vfork, and then said "finish". Ordinarily a finish just
3592 carries them to the call-site of the current callee, by setting
3593 a temporary bp there and resuming. But in this case, the finish
3594 will carry them entirely through the vfork & exec.
3596 We don't want to allow a bp_finish to remain inserted now. But
3597 we can't safely delete it, 'cause finish_command has a handle to
3598 the bp on a bpstat, and will later want to delete it. There's a
3599 chance (and I've seen it happen) that if we delete the bp_finish
3600 here, that its storage will get reused by the time finish_command
3601 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3602 We really must allow finish_command to delete a bp_finish.
3604 In the absence of a general solution for the "how do we know
3605 it's safe to delete something others may have handles to?"
3606 problem, what we'll do here is just uninsert the bp_finish, and
3607 let finish_command delete it.
3609 (We know the bp_finish is "doomed" in the sense that it's
3610 momentary, and will be deleted as soon as finish_command sees
3611 the inferior stopped. So it doesn't matter that the bp's
3612 address is probably bogus in the new a.out, unlike e.g., the
3613 solib breakpoints.) */
3615 if (b->type == bp_finish)
3620 /* Without a symbolic address, we have little hope of the
3621 pre-exec() address meaning the same thing in the post-exec()
3623 if (breakpoint_event_location_empty_p (b))
3625 delete_breakpoint (b);
3632 detach_breakpoints (ptid_t ptid)
3634 struct bp_location *bl, **blp_tmp;
3636 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
3637 struct inferior *inf = current_inferior ();
3639 if (ptid.pid () == inferior_ptid.pid ())
3640 error (_("Cannot detach breakpoints of inferior_ptid"));
3642 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3643 inferior_ptid = ptid;
3644 ALL_BP_LOCATIONS (bl, blp_tmp)
3646 if (bl->pspace != inf->pspace)
3649 /* This function must physically remove breakpoints locations
3650 from the specified ptid, without modifying the breakpoint
3651 package's state. Locations of type bp_loc_other are only
3652 maintained at GDB side. So, there is no need to remove
3653 these bp_loc_other locations. Moreover, removing these
3654 would modify the breakpoint package's state. */
3655 if (bl->loc_type == bp_loc_other)
3659 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3665 /* Remove the breakpoint location BL from the current address space.
3666 Note that this is used to detach breakpoints from a child fork.
3667 When we get here, the child isn't in the inferior list, and neither
3668 do we have objects to represent its address space --- we should
3669 *not* look at bl->pspace->aspace here. */
3672 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3676 /* BL is never in moribund_locations by our callers. */
3677 gdb_assert (bl->owner != NULL);
3679 /* The type of none suggests that owner is actually deleted.
3680 This should not ever happen. */
3681 gdb_assert (bl->owner->type != bp_none);
3683 if (bl->loc_type == bp_loc_software_breakpoint
3684 || bl->loc_type == bp_loc_hardware_breakpoint)
3686 /* "Normal" instruction breakpoint: either the standard
3687 trap-instruction bp (bp_breakpoint), or a
3688 bp_hardware_breakpoint. */
3690 /* First check to see if we have to handle an overlay. */
3691 if (overlay_debugging == ovly_off
3692 || bl->section == NULL
3693 || !(section_is_overlay (bl->section)))
3695 /* No overlay handling: just remove the breakpoint. */
3697 /* If we're trying to uninsert a memory breakpoint that we
3698 know is set in a dynamic object that is marked
3699 shlib_disabled, then either the dynamic object was
3700 removed with "remove-symbol-file" or with
3701 "nosharedlibrary". In the former case, we don't know
3702 whether another dynamic object might have loaded over the
3703 breakpoint's address -- the user might well let us know
3704 about it next with add-symbol-file (the whole point of
3705 add-symbol-file is letting the user manually maintain a
3706 list of dynamically loaded objects). If we have the
3707 breakpoint's shadow memory, that is, this is a software
3708 breakpoint managed by GDB, check whether the breakpoint
3709 is still inserted in memory, to avoid overwriting wrong
3710 code with stale saved shadow contents. Note that HW
3711 breakpoints don't have shadow memory, as they're
3712 implemented using a mechanism that is not dependent on
3713 being able to modify the target's memory, and as such
3714 they should always be removed. */
3715 if (bl->shlib_disabled
3716 && bl->target_info.shadow_len != 0
3717 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3720 val = bl->owner->ops->remove_location (bl, reason);
3724 /* This breakpoint is in an overlay section.
3725 Did we set a breakpoint at the LMA? */
3726 if (!overlay_events_enabled)
3728 /* Yes -- overlay event support is not active, so we
3729 should have set a breakpoint at the LMA. Remove it.
3731 /* Ignore any failures: if the LMA is in ROM, we will
3732 have already warned when we failed to insert it. */
3733 if (bl->loc_type == bp_loc_hardware_breakpoint)
3734 target_remove_hw_breakpoint (bl->gdbarch,
3735 &bl->overlay_target_info);
3737 target_remove_breakpoint (bl->gdbarch,
3738 &bl->overlay_target_info,
3741 /* Did we set a breakpoint at the VMA?
3742 If so, we will have marked the breakpoint 'inserted'. */
3745 /* Yes -- remove it. Previously we did not bother to
3746 remove the breakpoint if the section had been
3747 unmapped, but let's not rely on that being safe. We
3748 don't know what the overlay manager might do. */
3750 /* However, we should remove *software* breakpoints only
3751 if the section is still mapped, or else we overwrite
3752 wrong code with the saved shadow contents. */
3753 if (bl->loc_type == bp_loc_hardware_breakpoint
3754 || section_is_mapped (bl->section))
3755 val = bl->owner->ops->remove_location (bl, reason);
3761 /* No -- not inserted, so no need to remove. No error. */
3766 /* In some cases, we might not be able to remove a breakpoint in
3767 a shared library that has already been removed, but we have
3768 not yet processed the shlib unload event. Similarly for an
3769 unloaded add-symbol-file object - the user might not yet have
3770 had the chance to remove-symbol-file it. shlib_disabled will
3771 be set if the library/object has already been removed, but
3772 the breakpoint hasn't been uninserted yet, e.g., after
3773 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3774 always-inserted mode. */
3776 && (bl->loc_type == bp_loc_software_breakpoint
3777 && (bl->shlib_disabled
3778 || solib_name_from_address (bl->pspace, bl->address)
3779 || shared_objfile_contains_address_p (bl->pspace,
3785 bl->inserted = (reason == DETACH_BREAKPOINT);
3787 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3789 gdb_assert (bl->owner->ops != NULL
3790 && bl->owner->ops->remove_location != NULL);
3792 bl->inserted = (reason == DETACH_BREAKPOINT);
3793 bl->owner->ops->remove_location (bl, reason);
3795 /* Failure to remove any of the hardware watchpoints comes here. */
3796 if (reason == REMOVE_BREAKPOINT && bl->inserted)
3797 warning (_("Could not remove hardware watchpoint %d."),
3800 else if (bl->owner->type == bp_catchpoint
3801 && breakpoint_enabled (bl->owner)
3804 gdb_assert (bl->owner->ops != NULL
3805 && bl->owner->ops->remove_location != NULL);
3807 val = bl->owner->ops->remove_location (bl, reason);
3811 bl->inserted = (reason == DETACH_BREAKPOINT);
3818 remove_breakpoint (struct bp_location *bl)
3820 /* BL is never in moribund_locations by our callers. */
3821 gdb_assert (bl->owner != NULL);
3823 /* The type of none suggests that owner is actually deleted.
3824 This should not ever happen. */
3825 gdb_assert (bl->owner->type != bp_none);
3827 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3829 switch_to_program_space_and_thread (bl->pspace);
3831 return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
3834 /* Clear the "inserted" flag in all breakpoints. */
3837 mark_breakpoints_out (void)
3839 struct bp_location *bl, **blp_tmp;
3841 ALL_BP_LOCATIONS (bl, blp_tmp)
3842 if (bl->pspace == current_program_space)
3846 /* Clear the "inserted" flag in all breakpoints and delete any
3847 breakpoints which should go away between runs of the program.
3849 Plus other such housekeeping that has to be done for breakpoints
3852 Note: this function gets called at the end of a run (by
3853 generic_mourn_inferior) and when a run begins (by
3854 init_wait_for_inferior). */
3859 breakpoint_init_inferior (enum inf_context context)
3861 struct breakpoint *b, *b_tmp;
3862 struct program_space *pspace = current_program_space;
3864 /* If breakpoint locations are shared across processes, then there's
3866 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3869 mark_breakpoints_out ();
3871 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3873 if (b->loc && b->loc->pspace != pspace)
3879 case bp_longjmp_call_dummy:
3881 /* If the call dummy breakpoint is at the entry point it will
3882 cause problems when the inferior is rerun, so we better get
3885 case bp_watchpoint_scope:
3887 /* Also get rid of scope breakpoints. */
3889 case bp_shlib_event:
3891 /* Also remove solib event breakpoints. Their addresses may
3892 have changed since the last time we ran the program.
3893 Actually we may now be debugging against different target;
3894 and so the solib backend that installed this breakpoint may
3895 not be used in by the target. E.g.,
3897 (gdb) file prog-linux
3898 (gdb) run # native linux target
3901 (gdb) file prog-win.exe
3902 (gdb) tar rem :9999 # remote Windows gdbserver.
3905 case bp_step_resume:
3907 /* Also remove step-resume breakpoints. */
3909 case bp_single_step:
3911 /* Also remove single-step breakpoints. */
3913 delete_breakpoint (b);
3917 case bp_hardware_watchpoint:
3918 case bp_read_watchpoint:
3919 case bp_access_watchpoint:
3921 struct watchpoint *w = (struct watchpoint *) b;
3923 /* Likewise for watchpoints on local expressions. */
3924 if (w->exp_valid_block != NULL)
3925 delete_breakpoint (b);
3928 /* Get rid of existing locations, which are no longer
3929 valid. New ones will be created in
3930 update_watchpoint, when the inferior is restarted.
3931 The next update_global_location_list call will
3932 garbage collect them. */
3935 if (context == inf_starting)
3937 /* Reset val field to force reread of starting value in
3938 insert_breakpoints. */
3939 w->val.reset (nullptr);
3950 /* Get rid of the moribund locations. */
3951 for (bp_location *bl : moribund_locations)
3952 decref_bp_location (&bl);
3953 moribund_locations.clear ();
3956 /* These functions concern about actual breakpoints inserted in the
3957 target --- to e.g. check if we need to do decr_pc adjustment or if
3958 we need to hop over the bkpt --- so we check for address space
3959 match, not program space. */
3961 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3962 exists at PC. It returns ordinary_breakpoint_here if it's an
3963 ordinary breakpoint, or permanent_breakpoint_here if it's a
3964 permanent breakpoint.
3965 - When continuing from a location with an ordinary breakpoint, we
3966 actually single step once before calling insert_breakpoints.
3967 - When continuing from a location with a permanent breakpoint, we
3968 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3969 the target, to advance the PC past the breakpoint. */
3971 enum breakpoint_here
3972 breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
3974 struct bp_location *bl, **blp_tmp;
3975 int any_breakpoint_here = 0;
3977 ALL_BP_LOCATIONS (bl, blp_tmp)
3979 if (bl->loc_type != bp_loc_software_breakpoint
3980 && bl->loc_type != bp_loc_hardware_breakpoint)
3983 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3984 if ((breakpoint_enabled (bl->owner)
3986 && breakpoint_location_address_match (bl, aspace, pc))
3988 if (overlay_debugging
3989 && section_is_overlay (bl->section)
3990 && !section_is_mapped (bl->section))
3991 continue; /* unmapped overlay -- can't be a match */
3992 else if (bl->permanent)
3993 return permanent_breakpoint_here;
3995 any_breakpoint_here = 1;
3999 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4002 /* See breakpoint.h. */
4005 breakpoint_in_range_p (const address_space *aspace,
4006 CORE_ADDR addr, ULONGEST len)
4008 struct bp_location *bl, **blp_tmp;
4010 ALL_BP_LOCATIONS (bl, blp_tmp)
4012 if (bl->loc_type != bp_loc_software_breakpoint
4013 && bl->loc_type != bp_loc_hardware_breakpoint)
4016 if ((breakpoint_enabled (bl->owner)
4018 && breakpoint_location_address_range_overlap (bl, aspace,
4021 if (overlay_debugging
4022 && section_is_overlay (bl->section)
4023 && !section_is_mapped (bl->section))
4025 /* Unmapped overlay -- can't be a match. */
4036 /* Return true if there's a moribund breakpoint at PC. */
4039 moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
4041 for (bp_location *loc : moribund_locations)
4042 if (breakpoint_location_address_match (loc, aspace, pc))
4048 /* Returns non-zero iff BL is inserted at PC, in address space
4052 bp_location_inserted_here_p (struct bp_location *bl,
4053 const address_space *aspace, CORE_ADDR pc)
4056 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4059 if (overlay_debugging
4060 && section_is_overlay (bl->section)
4061 && !section_is_mapped (bl->section))
4062 return 0; /* unmapped overlay -- can't be a match */
4069 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4072 breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
4074 struct bp_location **blp, **blp_tmp = NULL;
4076 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4078 struct bp_location *bl = *blp;
4080 if (bl->loc_type != bp_loc_software_breakpoint
4081 && bl->loc_type != bp_loc_hardware_breakpoint)
4084 if (bp_location_inserted_here_p (bl, aspace, pc))
4090 /* This function returns non-zero iff there is a software breakpoint
4094 software_breakpoint_inserted_here_p (const address_space *aspace,
4097 struct bp_location **blp, **blp_tmp = NULL;
4099 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4101 struct bp_location *bl = *blp;
4103 if (bl->loc_type != bp_loc_software_breakpoint)
4106 if (bp_location_inserted_here_p (bl, aspace, pc))
4113 /* See breakpoint.h. */
4116 hardware_breakpoint_inserted_here_p (const address_space *aspace,
4119 struct bp_location **blp, **blp_tmp = NULL;
4121 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4123 struct bp_location *bl = *blp;
4125 if (bl->loc_type != bp_loc_hardware_breakpoint)
4128 if (bp_location_inserted_here_p (bl, aspace, pc))
4136 hardware_watchpoint_inserted_in_range (const address_space *aspace,
4137 CORE_ADDR addr, ULONGEST len)
4139 struct breakpoint *bpt;
4141 ALL_BREAKPOINTS (bpt)
4143 struct bp_location *loc;
4145 if (bpt->type != bp_hardware_watchpoint
4146 && bpt->type != bp_access_watchpoint)
4149 if (!breakpoint_enabled (bpt))
4152 for (loc = bpt->loc; loc; loc = loc->next)
4153 if (loc->pspace->aspace == aspace && loc->inserted)
4157 /* Check for intersection. */
4158 l = std::max<CORE_ADDR> (loc->address, addr);
4159 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4168 /* bpstat stuff. External routines' interfaces are documented
4172 is_catchpoint (struct breakpoint *ep)
4174 return (ep->type == bp_catchpoint);
4177 /* Frees any storage that is part of a bpstat. Does not walk the
4180 bpstats::~bpstats ()
4182 if (bp_location_at != NULL)
4183 decref_bp_location (&bp_location_at);
4186 /* Clear a bpstat so that it says we are not at any breakpoint.
4187 Also free any storage that is part of a bpstat. */
4190 bpstat_clear (bpstat *bsp)
4207 bpstats::bpstats (const bpstats &other)
4209 bp_location_at (other.bp_location_at),
4210 breakpoint_at (other.breakpoint_at),
4211 commands (other.commands),
4212 print (other.print),
4214 print_it (other.print_it)
4216 if (other.old_val != NULL)
4217 old_val = release_value (value_copy (other.old_val.get ()));
4218 incref_bp_location (bp_location_at);
4221 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4222 is part of the bpstat is copied as well. */
4225 bpstat_copy (bpstat bs)
4229 bpstat retval = NULL;
4234 for (; bs != NULL; bs = bs->next)
4236 tmp = new bpstats (*bs);
4239 /* This is the first thing in the chain. */
4249 /* Find the bpstat associated with this breakpoint. */
4252 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4257 for (; bsp != NULL; bsp = bsp->next)
4259 if (bsp->breakpoint_at == breakpoint)
4265 /* See breakpoint.h. */
4268 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4270 for (; bsp != NULL; bsp = bsp->next)
4272 if (bsp->breakpoint_at == NULL)
4274 /* A moribund location can never explain a signal other than
4276 if (sig == GDB_SIGNAL_TRAP)
4281 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4290 /* Put in *NUM the breakpoint number of the first breakpoint we are
4291 stopped at. *BSP upon return is a bpstat which points to the
4292 remaining breakpoints stopped at (but which is not guaranteed to be
4293 good for anything but further calls to bpstat_num).
4295 Return 0 if passed a bpstat which does not indicate any breakpoints.
4296 Return -1 if stopped at a breakpoint that has been deleted since
4298 Return 1 otherwise. */
4301 bpstat_num (bpstat *bsp, int *num)
4303 struct breakpoint *b;
4306 return 0; /* No more breakpoint values */
4308 /* We assume we'll never have several bpstats that correspond to a
4309 single breakpoint -- otherwise, this function might return the
4310 same number more than once and this will look ugly. */
4311 b = (*bsp)->breakpoint_at;
4312 *bsp = (*bsp)->next;
4314 return -1; /* breakpoint that's been deleted since */
4316 *num = b->number; /* We have its number */
4320 /* See breakpoint.h. */
4323 bpstat_clear_actions (void)
4327 if (inferior_ptid == null_ptid)
4330 thread_info *tp = inferior_thread ();
4331 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4333 bs->commands = NULL;
4334 bs->old_val.reset (nullptr);
4338 /* Called when a command is about to proceed the inferior. */
4341 breakpoint_about_to_proceed (void)
4343 if (inferior_ptid != null_ptid)
4345 struct thread_info *tp = inferior_thread ();
4347 /* Allow inferior function calls in breakpoint commands to not
4348 interrupt the command list. When the call finishes
4349 successfully, the inferior will be standing at the same
4350 breakpoint as if nothing happened. */
4351 if (tp->control.in_infcall)
4355 breakpoint_proceeded = 1;
4358 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4359 or its equivalent. */
4362 command_line_is_silent (struct command_line *cmd)
4364 return cmd && (strcmp ("silent", cmd->line) == 0);
4367 /* Execute all the commands associated with all the breakpoints at
4368 this location. Any of these commands could cause the process to
4369 proceed beyond this point, etc. We look out for such changes by
4370 checking the global "breakpoint_proceeded" after each command.
4372 Returns true if a breakpoint command resumed the inferior. In that
4373 case, it is the caller's responsibility to recall it again with the
4374 bpstat of the current thread. */
4377 bpstat_do_actions_1 (bpstat *bsp)
4382 /* Avoid endless recursion if a `source' command is contained
4384 if (executing_breakpoint_commands)
4387 scoped_restore save_executing
4388 = make_scoped_restore (&executing_breakpoint_commands, 1);
4390 scoped_restore preventer = prevent_dont_repeat ();
4392 /* This pointer will iterate over the list of bpstat's. */
4395 breakpoint_proceeded = 0;
4396 for (; bs != NULL; bs = bs->next)
4398 struct command_line *cmd = NULL;
4400 /* Take ownership of the BSP's command tree, if it has one.
4402 The command tree could legitimately contain commands like
4403 'step' and 'next', which call clear_proceed_status, which
4404 frees stop_bpstat's command tree. To make sure this doesn't
4405 free the tree we're executing out from under us, we need to
4406 take ownership of the tree ourselves. Since a given bpstat's
4407 commands are only executed once, we don't need to copy it; we
4408 can clear the pointer in the bpstat, and make sure we free
4409 the tree when we're done. */
4410 counted_command_line ccmd = bs->commands;
4411 bs->commands = NULL;
4414 if (command_line_is_silent (cmd))
4416 /* The action has been already done by bpstat_stop_status. */
4422 execute_control_command (cmd);
4424 if (breakpoint_proceeded)
4430 if (breakpoint_proceeded)
4432 if (current_ui->async)
4433 /* If we are in async mode, then the target might be still
4434 running, not stopped at any breakpoint, so nothing for
4435 us to do here -- just return to the event loop. */
4438 /* In sync mode, when execute_control_command returns
4439 we're already standing on the next breakpoint.
4440 Breakpoint commands for that stop were not run, since
4441 execute_command does not run breakpoint commands --
4442 only command_line_handler does, but that one is not
4443 involved in execution of breakpoint commands. So, we
4444 can now execute breakpoint commands. It should be
4445 noted that making execute_command do bpstat actions is
4446 not an option -- in this case we'll have recursive
4447 invocation of bpstat for each breakpoint with a
4448 command, and can easily blow up GDB stack. Instead, we
4449 return true, which will trigger the caller to recall us
4450 with the new stop_bpstat. */
4458 /* Helper for bpstat_do_actions. Get the current thread, if there's
4459 one, is alive and has execution. Return NULL otherwise. */
4461 static thread_info *
4462 get_bpstat_thread ()
4464 if (inferior_ptid == null_ptid || !target_has_execution)
4467 thread_info *tp = inferior_thread ();
4468 if (tp->state == THREAD_EXITED || tp->executing)
4474 bpstat_do_actions (void)
4476 auto cleanup_if_error = make_scope_exit (bpstat_clear_actions);
4479 /* Do any commands attached to breakpoint we are stopped at. */
4480 while ((tp = get_bpstat_thread ()) != NULL)
4482 /* Since in sync mode, bpstat_do_actions may resume the
4483 inferior, and only return when it is stopped at the next
4484 breakpoint, we keep doing breakpoint actions until it returns
4485 false to indicate the inferior was not resumed. */
4486 if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
4490 cleanup_if_error.release ();
4493 /* Print out the (old or new) value associated with a watchpoint. */
4496 watchpoint_value_print (struct value *val, struct ui_file *stream)
4499 fprintf_unfiltered (stream, _("<unreadable>"));
4502 struct value_print_options opts;
4503 get_user_print_options (&opts);
4504 value_print (val, stream, &opts);
4508 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4509 debugging multiple threads. */
4512 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4514 if (uiout->is_mi_like_p ())
4519 if (show_thread_that_caused_stop ())
4522 struct thread_info *thr = inferior_thread ();
4524 uiout->text ("Thread ");
4525 uiout->field_fmt ("thread-id", "%s", print_thread_id (thr));
4527 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4530 uiout->text (" \"");
4531 uiout->field_fmt ("name", "%s", name);
4535 uiout->text (" hit ");
4539 /* Generic routine for printing messages indicating why we
4540 stopped. The behavior of this function depends on the value
4541 'print_it' in the bpstat structure. Under some circumstances we
4542 may decide not to print anything here and delegate the task to
4545 static enum print_stop_action
4546 print_bp_stop_message (bpstat bs)
4548 switch (bs->print_it)
4551 /* Nothing should be printed for this bpstat entry. */
4552 return PRINT_UNKNOWN;
4556 /* We still want to print the frame, but we already printed the
4557 relevant messages. */
4558 return PRINT_SRC_AND_LOC;
4561 case print_it_normal:
4563 struct breakpoint *b = bs->breakpoint_at;
4565 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4566 which has since been deleted. */
4568 return PRINT_UNKNOWN;
4570 /* Normal case. Call the breakpoint's print_it method. */
4571 return b->ops->print_it (bs);
4576 internal_error (__FILE__, __LINE__,
4577 _("print_bp_stop_message: unrecognized enum value"));
4582 /* A helper function that prints a shared library stopped event. */
4585 print_solib_event (int is_catchpoint)
4587 bool any_deleted = !current_program_space->deleted_solibs.empty ();
4588 bool any_added = !current_program_space->added_solibs.empty ();
4592 if (any_added || any_deleted)
4593 current_uiout->text (_("Stopped due to shared library event:\n"));
4595 current_uiout->text (_("Stopped due to shared library event (no "
4596 "libraries added or removed)\n"));
4599 if (current_uiout->is_mi_like_p ())
4600 current_uiout->field_string ("reason",
4601 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4605 current_uiout->text (_(" Inferior unloaded "));
4606 ui_out_emit_list list_emitter (current_uiout, "removed");
4607 for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
4609 const std::string &name = current_program_space->deleted_solibs[ix];
4612 current_uiout->text (" ");
4613 current_uiout->field_string ("library", name);
4614 current_uiout->text ("\n");
4620 current_uiout->text (_(" Inferior loaded "));
4621 ui_out_emit_list list_emitter (current_uiout, "added");
4623 for (so_list *iter : current_program_space->added_solibs)
4626 current_uiout->text (" ");
4628 current_uiout->field_string ("library", iter->so_name);
4629 current_uiout->text ("\n");
4634 /* Print a message indicating what happened. This is called from
4635 normal_stop(). The input to this routine is the head of the bpstat
4636 list - a list of the eventpoints that caused this stop. KIND is
4637 the target_waitkind for the stopping event. This
4638 routine calls the generic print routine for printing a message
4639 about reasons for stopping. This will print (for example) the
4640 "Breakpoint n," part of the output. The return value of this
4643 PRINT_UNKNOWN: Means we printed nothing.
4644 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4645 code to print the location. An example is
4646 "Breakpoint 1, " which should be followed by
4648 PRINT_SRC_ONLY: Means we printed something, but there is no need
4649 to also print the location part of the message.
4650 An example is the catch/throw messages, which
4651 don't require a location appended to the end.
4652 PRINT_NOTHING: We have done some printing and we don't need any
4653 further info to be printed. */
4655 enum print_stop_action
4656 bpstat_print (bpstat bs, int kind)
4658 enum print_stop_action val;
4660 /* Maybe another breakpoint in the chain caused us to stop.
4661 (Currently all watchpoints go on the bpstat whether hit or not.
4662 That probably could (should) be changed, provided care is taken
4663 with respect to bpstat_explains_signal). */
4664 for (; bs; bs = bs->next)
4666 val = print_bp_stop_message (bs);
4667 if (val == PRINT_SRC_ONLY
4668 || val == PRINT_SRC_AND_LOC
4669 || val == PRINT_NOTHING)
4673 /* If we had hit a shared library event breakpoint,
4674 print_bp_stop_message would print out this message. If we hit an
4675 OS-level shared library event, do the same thing. */
4676 if (kind == TARGET_WAITKIND_LOADED)
4678 print_solib_event (0);
4679 return PRINT_NOTHING;
4682 /* We reached the end of the chain, or we got a null BS to start
4683 with and nothing was printed. */
4684 return PRINT_UNKNOWN;
4687 /* Evaluate the boolean expression EXP and return the result. */
4690 breakpoint_cond_eval (expression *exp)
4692 struct value *mark = value_mark ();
4693 bool res = value_true (evaluate_expression (exp));
4695 value_free_to_mark (mark);
4699 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4701 bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer)
4703 bp_location_at (bl),
4704 breakpoint_at (bl->owner),
4708 print_it (print_it_normal)
4710 incref_bp_location (bl);
4711 **bs_link_pointer = this;
4712 *bs_link_pointer = &next;
4717 bp_location_at (NULL),
4718 breakpoint_at (NULL),
4722 print_it (print_it_normal)
4726 /* The target has stopped with waitstatus WS. Check if any hardware
4727 watchpoints have triggered, according to the target. */
4730 watchpoints_triggered (struct target_waitstatus *ws)
4732 bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
4734 struct breakpoint *b;
4736 if (!stopped_by_watchpoint)
4738 /* We were not stopped by a watchpoint. Mark all watchpoints
4739 as not triggered. */
4741 if (is_hardware_watchpoint (b))
4743 struct watchpoint *w = (struct watchpoint *) b;
4745 w->watchpoint_triggered = watch_triggered_no;
4751 if (!target_stopped_data_address (current_top_target (), &addr))
4753 /* We were stopped by a watchpoint, but we don't know where.
4754 Mark all watchpoints as unknown. */
4756 if (is_hardware_watchpoint (b))
4758 struct watchpoint *w = (struct watchpoint *) b;
4760 w->watchpoint_triggered = watch_triggered_unknown;
4766 /* The target could report the data address. Mark watchpoints
4767 affected by this data address as triggered, and all others as not
4771 if (is_hardware_watchpoint (b))
4773 struct watchpoint *w = (struct watchpoint *) b;
4774 struct bp_location *loc;
4776 w->watchpoint_triggered = watch_triggered_no;
4777 for (loc = b->loc; loc; loc = loc->next)
4779 if (is_masked_watchpoint (b))
4781 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4782 CORE_ADDR start = loc->address & w->hw_wp_mask;
4784 if (newaddr == start)
4786 w->watchpoint_triggered = watch_triggered_yes;
4790 /* Exact match not required. Within range is sufficient. */
4791 else if (target_watchpoint_addr_within_range (current_top_target (),
4795 w->watchpoint_triggered = watch_triggered_yes;
4804 /* Possible return values for watchpoint_check. */
4805 enum wp_check_result
4807 /* The watchpoint has been deleted. */
4810 /* The value has changed. */
4811 WP_VALUE_CHANGED = 2,
4813 /* The value has not changed. */
4814 WP_VALUE_NOT_CHANGED = 3,
4816 /* Ignore this watchpoint, no matter if the value changed or not. */
4820 #define BP_TEMPFLAG 1
4821 #define BP_HARDWAREFLAG 2
4823 /* Evaluate watchpoint condition expression and check if its value
4826 static wp_check_result
4827 watchpoint_check (bpstat bs)
4829 struct watchpoint *b;
4830 struct frame_info *fr;
4831 int within_current_scope;
4833 /* BS is built from an existing struct breakpoint. */
4834 gdb_assert (bs->breakpoint_at != NULL);
4835 b = (struct watchpoint *) bs->breakpoint_at;
4837 /* If this is a local watchpoint, we only want to check if the
4838 watchpoint frame is in scope if the current thread is the thread
4839 that was used to create the watchpoint. */
4840 if (!watchpoint_in_thread_scope (b))
4843 if (b->exp_valid_block == NULL)
4844 within_current_scope = 1;
4847 struct frame_info *frame = get_current_frame ();
4848 struct gdbarch *frame_arch = get_frame_arch (frame);
4849 CORE_ADDR frame_pc = get_frame_pc (frame);
4851 /* stack_frame_destroyed_p() returns a non-zero value if we're
4852 still in the function but the stack frame has already been
4853 invalidated. Since we can't rely on the values of local
4854 variables after the stack has been destroyed, we are treating
4855 the watchpoint in that state as `not changed' without further
4856 checking. Don't mark watchpoints as changed if the current
4857 frame is in an epilogue - even if they are in some other
4858 frame, our view of the stack is likely to be wrong and
4859 frame_find_by_id could error out. */
4860 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
4863 fr = frame_find_by_id (b->watchpoint_frame);
4864 within_current_scope = (fr != NULL);
4866 /* If we've gotten confused in the unwinder, we might have
4867 returned a frame that can't describe this variable. */
4868 if (within_current_scope)
4870 struct symbol *function;
4872 function = get_frame_function (fr);
4873 if (function == NULL
4874 || !contained_in (b->exp_valid_block,
4875 SYMBOL_BLOCK_VALUE (function)))
4876 within_current_scope = 0;
4879 if (within_current_scope)
4880 /* If we end up stopping, the current frame will get selected
4881 in normal_stop. So this call to select_frame won't affect
4886 if (within_current_scope)
4888 /* We use value_{,free_to_}mark because it could be a *long*
4889 time before we return to the command level and call
4890 free_all_values. We can't call free_all_values because we
4891 might be in the middle of evaluating a function call. */
4895 struct value *new_val;
4897 if (is_masked_watchpoint (b))
4898 /* Since we don't know the exact trigger address (from
4899 stopped_data_address), just tell the user we've triggered
4900 a mask watchpoint. */
4901 return WP_VALUE_CHANGED;
4903 mark = value_mark ();
4904 fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
4906 if (b->val_bitsize != 0)
4907 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
4909 /* We use value_equal_contents instead of value_equal because
4910 the latter coerces an array to a pointer, thus comparing just
4911 the address of the array instead of its contents. This is
4912 not what we want. */
4913 if ((b->val != NULL) != (new_val != NULL)
4914 || (b->val != NULL && !value_equal_contents (b->val.get (),
4917 bs->old_val = b->val;
4918 b->val = release_value (new_val);
4920 if (new_val != NULL)
4921 value_free_to_mark (mark);
4922 return WP_VALUE_CHANGED;
4926 /* Nothing changed. */
4927 value_free_to_mark (mark);
4928 return WP_VALUE_NOT_CHANGED;
4933 /* This seems like the only logical thing to do because
4934 if we temporarily ignored the watchpoint, then when
4935 we reenter the block in which it is valid it contains
4936 garbage (in the case of a function, it may have two
4937 garbage values, one before and one after the prologue).
4938 So we can't even detect the first assignment to it and
4939 watch after that (since the garbage may or may not equal
4940 the first value assigned). */
4941 /* We print all the stop information in
4942 breakpoint_ops->print_it, but in this case, by the time we
4943 call breakpoint_ops->print_it this bp will be deleted
4944 already. So we have no choice but print the information
4947 SWITCH_THRU_ALL_UIS ()
4949 struct ui_out *uiout = current_uiout;
4951 if (uiout->is_mi_like_p ())
4953 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4954 uiout->text ("\nWatchpoint ");
4955 uiout->field_int ("wpnum", b->number);
4956 uiout->text (" deleted because the program has left the block in\n"
4957 "which its expression is valid.\n");
4960 /* Make sure the watchpoint's commands aren't executed. */
4962 watchpoint_del_at_next_stop (b);
4968 /* Return true if it looks like target has stopped due to hitting
4969 breakpoint location BL. This function does not check if we should
4970 stop, only if BL explains the stop. */
4973 bpstat_check_location (const struct bp_location *bl,
4974 const address_space *aspace, CORE_ADDR bp_addr,
4975 const struct target_waitstatus *ws)
4977 struct breakpoint *b = bl->owner;
4979 /* BL is from an existing breakpoint. */
4980 gdb_assert (b != NULL);
4982 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4985 /* Determine if the watched values have actually changed, and we
4986 should stop. If not, set BS->stop to 0. */
4989 bpstat_check_watchpoint (bpstat bs)
4991 const struct bp_location *bl;
4992 struct watchpoint *b;
4994 /* BS is built for existing struct breakpoint. */
4995 bl = bs->bp_location_at;
4996 gdb_assert (bl != NULL);
4997 b = (struct watchpoint *) bs->breakpoint_at;
4998 gdb_assert (b != NULL);
5001 int must_check_value = 0;
5003 if (b->type == bp_watchpoint)
5004 /* For a software watchpoint, we must always check the
5006 must_check_value = 1;
5007 else if (b->watchpoint_triggered == watch_triggered_yes)
5008 /* We have a hardware watchpoint (read, write, or access)
5009 and the target earlier reported an address watched by
5011 must_check_value = 1;
5012 else if (b->watchpoint_triggered == watch_triggered_unknown
5013 && b->type == bp_hardware_watchpoint)
5014 /* We were stopped by a hardware watchpoint, but the target could
5015 not report the data address. We must check the watchpoint's
5016 value. Access and read watchpoints are out of luck; without
5017 a data address, we can't figure it out. */
5018 must_check_value = 1;
5020 if (must_check_value)
5026 e = watchpoint_check (bs);
5028 CATCH (ex, RETURN_MASK_ALL)
5030 exception_fprintf (gdb_stderr, ex,
5031 "Error evaluating expression "
5032 "for watchpoint %d\n",
5035 SWITCH_THRU_ALL_UIS ()
5037 printf_filtered (_("Watchpoint %d deleted.\n"),
5040 watchpoint_del_at_next_stop (b);
5048 /* We've already printed what needs to be printed. */
5049 bs->print_it = print_it_done;
5053 bs->print_it = print_it_noop;
5056 case WP_VALUE_CHANGED:
5057 if (b->type == bp_read_watchpoint)
5059 /* There are two cases to consider here:
5061 1. We're watching the triggered memory for reads.
5062 In that case, trust the target, and always report
5063 the watchpoint hit to the user. Even though
5064 reads don't cause value changes, the value may
5065 have changed since the last time it was read, and
5066 since we're not trapping writes, we will not see
5067 those, and as such we should ignore our notion of
5070 2. We're watching the triggered memory for both
5071 reads and writes. There are two ways this may
5074 2.1. This is a target that can't break on data
5075 reads only, but can break on accesses (reads or
5076 writes), such as e.g., x86. We detect this case
5077 at the time we try to insert read watchpoints.
5079 2.2. Otherwise, the target supports read
5080 watchpoints, but, the user set an access or write
5081 watchpoint watching the same memory as this read
5084 If we're watching memory writes as well as reads,
5085 ignore watchpoint hits when we find that the
5086 value hasn't changed, as reads don't cause
5087 changes. This still gives false positives when
5088 the program writes the same value to memory as
5089 what there was already in memory (we will confuse
5090 it for a read), but it's much better than
5093 int other_write_watchpoint = 0;
5095 if (bl->watchpoint_type == hw_read)
5097 struct breakpoint *other_b;
5099 ALL_BREAKPOINTS (other_b)
5100 if (other_b->type == bp_hardware_watchpoint
5101 || other_b->type == bp_access_watchpoint)
5103 struct watchpoint *other_w =
5104 (struct watchpoint *) other_b;
5106 if (other_w->watchpoint_triggered
5107 == watch_triggered_yes)
5109 other_write_watchpoint = 1;
5115 if (other_write_watchpoint
5116 || bl->watchpoint_type == hw_access)
5118 /* We're watching the same memory for writes,
5119 and the value changed since the last time we
5120 updated it, so this trap must be for a write.
5122 bs->print_it = print_it_noop;
5127 case WP_VALUE_NOT_CHANGED:
5128 if (b->type == bp_hardware_watchpoint
5129 || b->type == bp_watchpoint)
5131 /* Don't stop: write watchpoints shouldn't fire if
5132 the value hasn't changed. */
5133 bs->print_it = print_it_noop;
5143 else /* must_check_value == 0 */
5145 /* This is a case where some watchpoint(s) triggered, but
5146 not at the address of this watchpoint, or else no
5147 watchpoint triggered after all. So don't print
5148 anything for this watchpoint. */
5149 bs->print_it = print_it_noop;
5155 /* For breakpoints that are currently marked as telling gdb to stop,
5156 check conditions (condition proper, frame, thread and ignore count)
5157 of breakpoint referred to by BS. If we should not stop for this
5158 breakpoint, set BS->stop to 0. */
5161 bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
5163 const struct bp_location *bl;
5164 struct breakpoint *b;
5166 bool condition_result = true;
5167 struct expression *cond;
5169 gdb_assert (bs->stop);
5171 /* BS is built for existing struct breakpoint. */
5172 bl = bs->bp_location_at;
5173 gdb_assert (bl != NULL);
5174 b = bs->breakpoint_at;
5175 gdb_assert (b != NULL);
5177 /* Even if the target evaluated the condition on its end and notified GDB, we
5178 need to do so again since GDB does not know if we stopped due to a
5179 breakpoint or a single step breakpoint. */
5181 if (frame_id_p (b->frame_id)
5182 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5188 /* If this is a thread/task-specific breakpoint, don't waste cpu
5189 evaluating the condition if this isn't the specified
5191 if ((b->thread != -1 && b->thread != thread->global_num)
5192 || (b->task != 0 && b->task != ada_get_task_number (thread)))
5198 /* Evaluate extension language breakpoints that have a "stop" method
5200 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5202 if (is_watchpoint (b))
5204 struct watchpoint *w = (struct watchpoint *) b;
5206 cond = w->cond_exp.get ();
5209 cond = bl->cond.get ();
5211 if (cond && b->disposition != disp_del_at_next_stop)
5213 int within_current_scope = 1;
5214 struct watchpoint * w;
5216 /* We use value_mark and value_free_to_mark because it could
5217 be a long time before we return to the command level and
5218 call free_all_values. We can't call free_all_values
5219 because we might be in the middle of evaluating a
5221 struct value *mark = value_mark ();
5223 if (is_watchpoint (b))
5224 w = (struct watchpoint *) b;
5228 /* Need to select the frame, with all that implies so that
5229 the conditions will have the right context. Because we
5230 use the frame, we will not see an inlined function's
5231 variables when we arrive at a breakpoint at the start
5232 of the inlined function; the current frame will be the
5234 if (w == NULL || w->cond_exp_valid_block == NULL)
5235 select_frame (get_current_frame ());
5238 struct frame_info *frame;
5240 /* For local watchpoint expressions, which particular
5241 instance of a local is being watched matters, so we
5242 keep track of the frame to evaluate the expression
5243 in. To evaluate the condition however, it doesn't
5244 really matter which instantiation of the function
5245 where the condition makes sense triggers the
5246 watchpoint. This allows an expression like "watch
5247 global if q > 10" set in `func', catch writes to
5248 global on all threads that call `func', or catch
5249 writes on all recursive calls of `func' by a single
5250 thread. We simply always evaluate the condition in
5251 the innermost frame that's executing where it makes
5252 sense to evaluate the condition. It seems
5254 frame = block_innermost_frame (w->cond_exp_valid_block);
5256 select_frame (frame);
5258 within_current_scope = 0;
5260 if (within_current_scope)
5264 condition_result = breakpoint_cond_eval (cond);
5266 CATCH (ex, RETURN_MASK_ALL)
5268 exception_fprintf (gdb_stderr, ex,
5269 "Error in testing breakpoint condition:\n");
5275 warning (_("Watchpoint condition cannot be tested "
5276 "in the current scope"));
5277 /* If we failed to set the right context for this
5278 watchpoint, unconditionally report it. */
5280 /* FIXME-someday, should give breakpoint #. */
5281 value_free_to_mark (mark);
5284 if (cond && !condition_result)
5288 else if (b->ignore_count > 0)
5292 /* Increase the hit count even though we don't stop. */
5294 gdb::observers::breakpoint_modified.notify (b);
5298 /* Returns true if we need to track moribund locations of LOC's type
5299 on the current target. */
5302 need_moribund_for_location_type (struct bp_location *loc)
5304 return ((loc->loc_type == bp_loc_software_breakpoint
5305 && !target_supports_stopped_by_sw_breakpoint ())
5306 || (loc->loc_type == bp_loc_hardware_breakpoint
5307 && !target_supports_stopped_by_hw_breakpoint ()));
5310 /* See breakpoint.h. */
5313 build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
5314 const struct target_waitstatus *ws)
5316 struct breakpoint *b;
5317 bpstat bs_head = NULL, *bs_link = &bs_head;
5321 if (!breakpoint_enabled (b))
5324 for (bp_location *bl = b->loc; bl != NULL; bl = bl->next)
5326 /* For hardware watchpoints, we look only at the first
5327 location. The watchpoint_check function will work on the
5328 entire expression, not the individual locations. For
5329 read watchpoints, the watchpoints_triggered function has
5330 checked all locations already. */
5331 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5334 if (!bl->enabled || bl->shlib_disabled)
5337 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5340 /* Come here if it's a watchpoint, or if the break address
5343 bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to
5346 /* Assume we stop. Should we find a watchpoint that is not
5347 actually triggered, or if the condition of the breakpoint
5348 evaluates as false, we'll reset 'stop' to 0. */
5352 /* If this is a scope breakpoint, mark the associated
5353 watchpoint as triggered so that we will handle the
5354 out-of-scope event. We'll get to the watchpoint next
5356 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5358 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5360 w->watchpoint_triggered = watch_triggered_yes;
5365 /* Check if a moribund breakpoint explains the stop. */
5366 if (!target_supports_stopped_by_sw_breakpoint ()
5367 || !target_supports_stopped_by_hw_breakpoint ())
5369 for (bp_location *loc : moribund_locations)
5371 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5372 && need_moribund_for_location_type (loc))
5374 bpstat bs = new bpstats (loc, &bs_link);
5375 /* For hits of moribund locations, we should just proceed. */
5378 bs->print_it = print_it_noop;
5386 /* See breakpoint.h. */
5389 bpstat_stop_status (const address_space *aspace,
5390 CORE_ADDR bp_addr, thread_info *thread,
5391 const struct target_waitstatus *ws,
5394 struct breakpoint *b = NULL;
5395 /* First item of allocated bpstat's. */
5396 bpstat bs_head = stop_chain;
5398 int need_remove_insert;
5401 /* First, build the bpstat chain with locations that explain a
5402 target stop, while being careful to not set the target running,
5403 as that may invalidate locations (in particular watchpoint
5404 locations are recreated). Resuming will happen here with
5405 breakpoint conditions or watchpoint expressions that include
5406 inferior function calls. */
5407 if (bs_head == NULL)
5408 bs_head = build_bpstat_chain (aspace, bp_addr, ws);
5410 /* A bit of special processing for shlib breakpoints. We need to
5411 process solib loading here, so that the lists of loaded and
5412 unloaded libraries are correct before we handle "catch load" and
5414 for (bs = bs_head; bs != NULL; bs = bs->next)
5416 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5418 handle_solib_event ();
5423 /* Now go through the locations that caused the target to stop, and
5424 check whether we're interested in reporting this stop to higher
5425 layers, or whether we should resume the target transparently. */
5429 for (bs = bs_head; bs != NULL; bs = bs->next)
5434 b = bs->breakpoint_at;
5435 b->ops->check_status (bs);
5438 bpstat_check_breakpoint_conditions (bs, thread);
5443 gdb::observers::breakpoint_modified.notify (b);
5445 /* We will stop here. */
5446 if (b->disposition == disp_disable)
5448 --(b->enable_count);
5449 if (b->enable_count <= 0)
5450 b->enable_state = bp_disabled;
5455 bs->commands = b->commands;
5456 if (command_line_is_silent (bs->commands
5457 ? bs->commands.get () : NULL))
5460 b->ops->after_condition_true (bs);
5465 /* Print nothing for this entry if we don't stop or don't
5467 if (!bs->stop || !bs->print)
5468 bs->print_it = print_it_noop;
5471 /* If we aren't stopping, the value of some hardware watchpoint may
5472 not have changed, but the intermediate memory locations we are
5473 watching may have. Don't bother if we're stopping; this will get
5475 need_remove_insert = 0;
5476 if (! bpstat_causes_stop (bs_head))
5477 for (bs = bs_head; bs != NULL; bs = bs->next)
5479 && bs->breakpoint_at
5480 && is_hardware_watchpoint (bs->breakpoint_at))
5482 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5484 update_watchpoint (w, 0 /* don't reparse. */);
5485 need_remove_insert = 1;
5488 if (need_remove_insert)
5489 update_global_location_list (UGLL_MAY_INSERT);
5490 else if (removed_any)
5491 update_global_location_list (UGLL_DONT_INSERT);
5497 handle_jit_event (void)
5499 struct frame_info *frame;
5500 struct gdbarch *gdbarch;
5503 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5505 /* Switch terminal for any messages produced by
5506 breakpoint_re_set. */
5507 target_terminal::ours_for_output ();
5509 frame = get_current_frame ();
5510 gdbarch = get_frame_arch (frame);
5512 jit_event_handler (gdbarch);
5514 target_terminal::inferior ();
5517 /* Prepare WHAT final decision for infrun. */
5519 /* Decide what infrun needs to do with this bpstat. */
5522 bpstat_what (bpstat bs_head)
5524 struct bpstat_what retval;
5527 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5528 retval.call_dummy = STOP_NONE;
5529 retval.is_longjmp = 0;
5531 for (bs = bs_head; bs != NULL; bs = bs->next)
5533 /* Extract this BS's action. After processing each BS, we check
5534 if its action overrides all we've seem so far. */
5535 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5538 if (bs->breakpoint_at == NULL)
5540 /* I suspect this can happen if it was a momentary
5541 breakpoint which has since been deleted. */
5545 bptype = bs->breakpoint_at->type;
5552 case bp_hardware_breakpoint:
5553 case bp_single_step:
5556 case bp_shlib_event:
5560 this_action = BPSTAT_WHAT_STOP_NOISY;
5562 this_action = BPSTAT_WHAT_STOP_SILENT;
5565 this_action = BPSTAT_WHAT_SINGLE;
5568 case bp_hardware_watchpoint:
5569 case bp_read_watchpoint:
5570 case bp_access_watchpoint:
5574 this_action = BPSTAT_WHAT_STOP_NOISY;
5576 this_action = BPSTAT_WHAT_STOP_SILENT;
5580 /* There was a watchpoint, but we're not stopping.
5581 This requires no further action. */
5585 case bp_longjmp_call_dummy:
5589 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5590 retval.is_longjmp = bptype != bp_exception;
5593 this_action = BPSTAT_WHAT_SINGLE;
5595 case bp_longjmp_resume:
5596 case bp_exception_resume:
5599 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5600 retval.is_longjmp = bptype == bp_longjmp_resume;
5603 this_action = BPSTAT_WHAT_SINGLE;
5605 case bp_step_resume:
5607 this_action = BPSTAT_WHAT_STEP_RESUME;
5610 /* It is for the wrong frame. */
5611 this_action = BPSTAT_WHAT_SINGLE;
5614 case bp_hp_step_resume:
5616 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5619 /* It is for the wrong frame. */
5620 this_action = BPSTAT_WHAT_SINGLE;
5623 case bp_watchpoint_scope:
5624 case bp_thread_event:
5625 case bp_overlay_event:
5626 case bp_longjmp_master:
5627 case bp_std_terminate_master:
5628 case bp_exception_master:
5629 this_action = BPSTAT_WHAT_SINGLE;
5635 this_action = BPSTAT_WHAT_STOP_NOISY;
5637 this_action = BPSTAT_WHAT_STOP_SILENT;
5641 /* There was a catchpoint, but we're not stopping.
5642 This requires no further action. */
5646 this_action = BPSTAT_WHAT_SINGLE;
5649 /* Make sure the action is stop (silent or noisy),
5650 so infrun.c pops the dummy frame. */
5651 retval.call_dummy = STOP_STACK_DUMMY;
5652 this_action = BPSTAT_WHAT_STOP_SILENT;
5654 case bp_std_terminate:
5655 /* Make sure the action is stop (silent or noisy),
5656 so infrun.c pops the dummy frame. */
5657 retval.call_dummy = STOP_STD_TERMINATE;
5658 this_action = BPSTAT_WHAT_STOP_SILENT;
5661 case bp_fast_tracepoint:
5662 case bp_static_tracepoint:
5663 /* Tracepoint hits should not be reported back to GDB, and
5664 if one got through somehow, it should have been filtered
5666 internal_error (__FILE__, __LINE__,
5667 _("bpstat_what: tracepoint encountered"));
5669 case bp_gnu_ifunc_resolver:
5670 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5671 this_action = BPSTAT_WHAT_SINGLE;
5673 case bp_gnu_ifunc_resolver_return:
5674 /* The breakpoint will be removed, execution will restart from the
5675 PC of the former breakpoint. */
5676 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5681 this_action = BPSTAT_WHAT_STOP_SILENT;
5683 this_action = BPSTAT_WHAT_SINGLE;
5687 internal_error (__FILE__, __LINE__,
5688 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5691 retval.main_action = std::max (retval.main_action, this_action);
5698 bpstat_run_callbacks (bpstat bs_head)
5702 for (bs = bs_head; bs != NULL; bs = bs->next)
5704 struct breakpoint *b = bs->breakpoint_at;
5711 handle_jit_event ();
5713 case bp_gnu_ifunc_resolver:
5714 gnu_ifunc_resolver_stop (b);
5716 case bp_gnu_ifunc_resolver_return:
5717 gnu_ifunc_resolver_return_stop (b);
5723 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5724 without hardware support). This isn't related to a specific bpstat,
5725 just to things like whether watchpoints are set. */
5728 bpstat_should_step (void)
5730 struct breakpoint *b;
5733 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5739 bpstat_causes_stop (bpstat bs)
5741 for (; bs != NULL; bs = bs->next)
5750 /* Compute a string of spaces suitable to indent the next line
5751 so it starts at the position corresponding to the table column
5752 named COL_NAME in the currently active table of UIOUT. */
5755 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5757 static char wrap_indent[80];
5758 int i, total_width, width, align;
5762 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
5764 if (strcmp (text, col_name) == 0)
5766 gdb_assert (total_width < sizeof wrap_indent);
5767 memset (wrap_indent, ' ', total_width);
5768 wrap_indent[total_width] = 0;
5773 total_width += width + 1;
5779 /* Determine if the locations of this breakpoint will have their conditions
5780 evaluated by the target, host or a mix of both. Returns the following:
5782 "host": Host evals condition.
5783 "host or target": Host or Target evals condition.
5784 "target": Target evals condition.
5788 bp_condition_evaluator (struct breakpoint *b)
5790 struct bp_location *bl;
5791 char host_evals = 0;
5792 char target_evals = 0;
5797 if (!is_breakpoint (b))
5800 if (gdb_evaluates_breakpoint_condition_p ()
5801 || !target_supports_evaluation_of_breakpoint_conditions ())
5802 return condition_evaluation_host;
5804 for (bl = b->loc; bl; bl = bl->next)
5806 if (bl->cond_bytecode)
5812 if (host_evals && target_evals)
5813 return condition_evaluation_both;
5814 else if (target_evals)
5815 return condition_evaluation_target;
5817 return condition_evaluation_host;
5820 /* Determine the breakpoint location's condition evaluator. This is
5821 similar to bp_condition_evaluator, but for locations. */
5824 bp_location_condition_evaluator (struct bp_location *bl)
5826 if (bl && !is_breakpoint (bl->owner))
5829 if (gdb_evaluates_breakpoint_condition_p ()
5830 || !target_supports_evaluation_of_breakpoint_conditions ())
5831 return condition_evaluation_host;
5833 if (bl && bl->cond_bytecode)
5834 return condition_evaluation_target;
5836 return condition_evaluation_host;
5839 /* Print the LOC location out of the list of B->LOC locations. */
5842 print_breakpoint_location (struct breakpoint *b,
5843 struct bp_location *loc)
5845 struct ui_out *uiout = current_uiout;
5847 scoped_restore_current_program_space restore_pspace;
5849 if (loc != NULL && loc->shlib_disabled)
5853 set_current_program_space (loc->pspace);
5855 if (b->display_canonical)
5856 uiout->field_string ("what", event_location_to_string (b->location.get ()));
5857 else if (loc && loc->symtab)
5859 const struct symbol *sym = loc->symbol;
5863 uiout->text ("in ");
5864 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
5865 ui_out_style_kind::FUNCTION);
5867 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
5868 uiout->text ("at ");
5870 uiout->field_string ("file",
5871 symtab_to_filename_for_display (loc->symtab),
5872 ui_out_style_kind::FILE);
5875 if (uiout->is_mi_like_p ())
5876 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
5878 uiout->field_int ("line", loc->line_number);
5884 print_address_symbolic (loc->gdbarch, loc->address, &stb,
5886 uiout->field_stream ("at", stb);
5890 uiout->field_string ("pending",
5891 event_location_to_string (b->location.get ()));
5892 /* If extra_string is available, it could be holding a condition
5893 or dprintf arguments. In either case, make sure it is printed,
5894 too, but only for non-MI streams. */
5895 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
5897 if (b->type == bp_dprintf)
5901 uiout->text (b->extra_string);
5905 if (loc && is_breakpoint (b)
5906 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5907 && bp_condition_evaluator (b) == condition_evaluation_both)
5910 uiout->field_string ("evaluated-by",
5911 bp_location_condition_evaluator (loc));
5917 bptype_string (enum bptype type)
5919 struct ep_type_description
5922 const char *description;
5924 static struct ep_type_description bptypes[] =
5926 {bp_none, "?deleted?"},
5927 {bp_breakpoint, "breakpoint"},
5928 {bp_hardware_breakpoint, "hw breakpoint"},
5929 {bp_single_step, "sw single-step"},
5930 {bp_until, "until"},
5931 {bp_finish, "finish"},
5932 {bp_watchpoint, "watchpoint"},
5933 {bp_hardware_watchpoint, "hw watchpoint"},
5934 {bp_read_watchpoint, "read watchpoint"},
5935 {bp_access_watchpoint, "acc watchpoint"},
5936 {bp_longjmp, "longjmp"},
5937 {bp_longjmp_resume, "longjmp resume"},
5938 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5939 {bp_exception, "exception"},
5940 {bp_exception_resume, "exception resume"},
5941 {bp_step_resume, "step resume"},
5942 {bp_hp_step_resume, "high-priority step resume"},
5943 {bp_watchpoint_scope, "watchpoint scope"},
5944 {bp_call_dummy, "call dummy"},
5945 {bp_std_terminate, "std::terminate"},
5946 {bp_shlib_event, "shlib events"},
5947 {bp_thread_event, "thread events"},
5948 {bp_overlay_event, "overlay events"},
5949 {bp_longjmp_master, "longjmp master"},
5950 {bp_std_terminate_master, "std::terminate master"},
5951 {bp_exception_master, "exception master"},
5952 {bp_catchpoint, "catchpoint"},
5953 {bp_tracepoint, "tracepoint"},
5954 {bp_fast_tracepoint, "fast tracepoint"},
5955 {bp_static_tracepoint, "static tracepoint"},
5956 {bp_dprintf, "dprintf"},
5957 {bp_jit_event, "jit events"},
5958 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5959 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5962 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5963 || ((int) type != bptypes[(int) type].type))
5964 internal_error (__FILE__, __LINE__,
5965 _("bptypes table does not describe type #%d."),
5968 return bptypes[(int) type].description;
5971 /* For MI, output a field named 'thread-groups' with a list as the value.
5972 For CLI, prefix the list with the string 'inf'. */
5975 output_thread_groups (struct ui_out *uiout,
5976 const char *field_name,
5977 const std::vector<int> &inf_nums,
5980 int is_mi = uiout->is_mi_like_p ();
5982 /* For backward compatibility, don't display inferiors in CLI unless
5983 there are several. Always display them for MI. */
5984 if (!is_mi && mi_only)
5987 ui_out_emit_list list_emitter (uiout, field_name);
5989 for (size_t i = 0; i < inf_nums.size (); i++)
5995 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]);
5996 uiout->field_string (NULL, mi_group);
6001 uiout->text (" inf ");
6005 uiout->text (plongest (inf_nums[i]));
6010 /* Print B to gdb_stdout. */
6013 print_one_breakpoint_location (struct breakpoint *b,
6014 struct bp_location *loc,
6016 struct bp_location **last_loc,
6019 struct command_line *l;
6020 static char bpenables[] = "nynny";
6022 struct ui_out *uiout = current_uiout;
6023 int header_of_multiple = 0;
6024 int part_of_multiple = (loc != NULL);
6025 struct value_print_options opts;
6027 get_user_print_options (&opts);
6029 gdb_assert (!loc || loc_number != 0);
6030 /* See comment in print_one_breakpoint concerning treatment of
6031 breakpoints with single disabled location. */
6034 && (b->loc->next != NULL || !b->loc->enabled)))
6035 header_of_multiple = 1;
6043 if (part_of_multiple)
6044 uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
6046 uiout->field_int ("number", b->number);
6050 if (part_of_multiple)
6051 uiout->field_skip ("type");
6053 uiout->field_string ("type", bptype_string (b->type));
6057 if (part_of_multiple)
6058 uiout->field_skip ("disp");
6060 uiout->field_string ("disp", bpdisp_text (b->disposition));
6064 if (part_of_multiple)
6065 uiout->field_string ("enabled", loc->enabled ? "y" : "n");
6067 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6070 if (b->ops != NULL && b->ops->print_one != NULL)
6072 /* Although the print_one can possibly print all locations,
6073 calling it here is not likely to get any nice result. So,
6074 make sure there's just one location. */
6075 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6076 b->ops->print_one (b, last_loc);
6082 internal_error (__FILE__, __LINE__,
6083 _("print_one_breakpoint: bp_none encountered\n"));
6087 case bp_hardware_watchpoint:
6088 case bp_read_watchpoint:
6089 case bp_access_watchpoint:
6091 struct watchpoint *w = (struct watchpoint *) b;
6093 /* Field 4, the address, is omitted (which makes the columns
6094 not line up too nicely with the headers, but the effect
6095 is relatively readable). */
6096 if (opts.addressprint)
6097 uiout->field_skip ("addr");
6099 uiout->field_string ("what", w->exp_string);
6104 case bp_hardware_breakpoint:
6105 case bp_single_step:
6109 case bp_longjmp_resume:
6110 case bp_longjmp_call_dummy:
6112 case bp_exception_resume:
6113 case bp_step_resume:
6114 case bp_hp_step_resume:
6115 case bp_watchpoint_scope:
6117 case bp_std_terminate:
6118 case bp_shlib_event:
6119 case bp_thread_event:
6120 case bp_overlay_event:
6121 case bp_longjmp_master:
6122 case bp_std_terminate_master:
6123 case bp_exception_master:
6125 case bp_fast_tracepoint:
6126 case bp_static_tracepoint:
6129 case bp_gnu_ifunc_resolver:
6130 case bp_gnu_ifunc_resolver_return:
6131 if (opts.addressprint)
6134 if (header_of_multiple)
6135 uiout->field_string ("addr", "<MULTIPLE>");
6136 else if (b->loc == NULL || loc->shlib_disabled)
6137 uiout->field_string ("addr", "<PENDING>");
6139 uiout->field_core_addr ("addr",
6140 loc->gdbarch, loc->address);
6143 if (!header_of_multiple)
6144 print_breakpoint_location (b, loc);
6151 if (loc != NULL && !header_of_multiple)
6153 std::vector<int> inf_nums;
6156 for (inferior *inf : all_inferiors ())
6158 if (inf->pspace == loc->pspace)
6159 inf_nums.push_back (inf->num);
6162 /* For backward compatibility, don't display inferiors in CLI unless
6163 there are several. Always display for MI. */
6165 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6166 && (number_of_program_spaces () > 1
6167 || number_of_inferiors () > 1)
6168 /* LOC is for existing B, it cannot be in
6169 moribund_locations and thus having NULL OWNER. */
6170 && loc->owner->type != bp_catchpoint))
6172 output_thread_groups (uiout, "thread-groups", inf_nums, mi_only);
6175 if (!part_of_multiple)
6177 if (b->thread != -1)
6179 /* FIXME: This seems to be redundant and lost here; see the
6180 "stop only in" line a little further down. */
6181 uiout->text (" thread ");
6182 uiout->field_int ("thread", b->thread);
6184 else if (b->task != 0)
6186 uiout->text (" task ");
6187 uiout->field_int ("task", b->task);
6193 if (!part_of_multiple)
6194 b->ops->print_one_detail (b, uiout);
6196 if (part_of_multiple && frame_id_p (b->frame_id))
6199 uiout->text ("\tstop only in stack frame at ");
6200 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6202 uiout->field_core_addr ("frame",
6203 b->gdbarch, b->frame_id.stack_addr);
6207 if (!part_of_multiple && b->cond_string)
6210 if (is_tracepoint (b))
6211 uiout->text ("\ttrace only if ");
6213 uiout->text ("\tstop only if ");
6214 uiout->field_string ("cond", b->cond_string);
6216 /* Print whether the target is doing the breakpoint's condition
6217 evaluation. If GDB is doing the evaluation, don't print anything. */
6218 if (is_breakpoint (b)
6219 && breakpoint_condition_evaluation_mode ()
6220 == condition_evaluation_target)
6223 uiout->field_string ("evaluated-by",
6224 bp_condition_evaluator (b));
6225 uiout->text (" evals)");
6230 if (!part_of_multiple && b->thread != -1)
6232 /* FIXME should make an annotation for this. */
6233 uiout->text ("\tstop only in thread ");
6234 if (uiout->is_mi_like_p ())
6235 uiout->field_int ("thread", b->thread);
6238 struct thread_info *thr = find_thread_global_id (b->thread);
6240 uiout->field_string ("thread", print_thread_id (thr));
6245 if (!part_of_multiple)
6249 /* FIXME should make an annotation for this. */
6250 if (is_catchpoint (b))
6251 uiout->text ("\tcatchpoint");
6252 else if (is_tracepoint (b))
6253 uiout->text ("\ttracepoint");
6255 uiout->text ("\tbreakpoint");
6256 uiout->text (" already hit ");
6257 uiout->field_int ("times", b->hit_count);
6258 if (b->hit_count == 1)
6259 uiout->text (" time\n");
6261 uiout->text (" times\n");
6265 /* Output the count also if it is zero, but only if this is mi. */
6266 if (uiout->is_mi_like_p ())
6267 uiout->field_int ("times", b->hit_count);
6271 if (!part_of_multiple && b->ignore_count)
6274 uiout->text ("\tignore next ");
6275 uiout->field_int ("ignore", b->ignore_count);
6276 uiout->text (" hits\n");
6279 /* Note that an enable count of 1 corresponds to "enable once"
6280 behavior, which is reported by the combination of enablement and
6281 disposition, so we don't need to mention it here. */
6282 if (!part_of_multiple && b->enable_count > 1)
6285 uiout->text ("\tdisable after ");
6286 /* Tweak the wording to clarify that ignore and enable counts
6287 are distinct, and have additive effect. */
6288 if (b->ignore_count)
6289 uiout->text ("additional ");
6291 uiout->text ("next ");
6292 uiout->field_int ("enable", b->enable_count);
6293 uiout->text (" hits\n");
6296 if (!part_of_multiple && is_tracepoint (b))
6298 struct tracepoint *tp = (struct tracepoint *) b;
6300 if (tp->traceframe_usage)
6302 uiout->text ("\ttrace buffer usage ");
6303 uiout->field_int ("traceframe-usage", tp->traceframe_usage);
6304 uiout->text (" bytes\n");
6308 l = b->commands ? b->commands.get () : NULL;
6309 if (!part_of_multiple && l)
6312 ui_out_emit_tuple tuple_emitter (uiout, "script");
6313 print_command_lines (uiout, l, 4);
6316 if (is_tracepoint (b))
6318 struct tracepoint *t = (struct tracepoint *) b;
6320 if (!part_of_multiple && t->pass_count)
6322 annotate_field (10);
6323 uiout->text ("\tpass count ");
6324 uiout->field_int ("pass", t->pass_count);
6325 uiout->text (" \n");
6328 /* Don't display it when tracepoint or tracepoint location is
6330 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6332 annotate_field (11);
6334 if (uiout->is_mi_like_p ())
6335 uiout->field_string ("installed",
6336 loc->inserted ? "y" : "n");
6342 uiout->text ("\tnot ");
6343 uiout->text ("installed on target\n");
6348 if (uiout->is_mi_like_p () && !part_of_multiple)
6350 if (is_watchpoint (b))
6352 struct watchpoint *w = (struct watchpoint *) b;
6354 uiout->field_string ("original-location", w->exp_string);
6356 else if (b->location != NULL
6357 && event_location_to_string (b->location.get ()) != NULL)
6358 uiout->field_string ("original-location",
6359 event_location_to_string (b->location.get ()));
6364 print_one_breakpoint (struct breakpoint *b,
6365 struct bp_location **last_loc,
6368 struct ui_out *uiout = current_uiout;
6369 bool use_fixed_output = mi_multi_location_breakpoint_output_fixed (uiout);
6371 gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt");
6372 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6374 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6376 if (!use_fixed_output)
6377 bkpt_tuple_emitter.reset ();
6379 /* If this breakpoint has custom print function,
6380 it's already printed. Otherwise, print individual
6381 locations, if any. */
6382 if (b->ops == NULL || b->ops->print_one == NULL)
6384 /* If breakpoint has a single location that is disabled, we
6385 print it as if it had several locations, since otherwise it's
6386 hard to represent "breakpoint enabled, location disabled"
6389 Note that while hardware watchpoints have several locations
6390 internally, that's not a property exposed to user. */
6392 && !is_hardware_watchpoint (b)
6393 && (b->loc->next || !b->loc->enabled))
6395 gdb::optional<ui_out_emit_list> locations_list;
6397 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6398 MI record. For later versions, place breakpoint locations in a
6400 if (uiout->is_mi_like_p () && use_fixed_output)
6401 locations_list.emplace (uiout, "locations");
6404 for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n)
6406 ui_out_emit_tuple loc_tuple_emitter (uiout, NULL);
6407 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6414 breakpoint_address_bits (struct breakpoint *b)
6416 int print_address_bits = 0;
6417 struct bp_location *loc;
6419 /* Software watchpoints that aren't watching memory don't have an
6420 address to print. */
6421 if (is_no_memory_software_watchpoint (b))
6424 for (loc = b->loc; loc; loc = loc->next)
6428 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6429 if (addr_bit > print_address_bits)
6430 print_address_bits = addr_bit;
6433 return print_address_bits;
6436 /* See breakpoint.h. */
6439 print_breakpoint (breakpoint *b)
6441 struct bp_location *dummy_loc = NULL;
6442 print_one_breakpoint (b, &dummy_loc, 0);
6445 /* Return true if this breakpoint was set by the user, false if it is
6446 internal or momentary. */
6449 user_breakpoint_p (struct breakpoint *b)
6451 return b->number > 0;
6454 /* See breakpoint.h. */
6457 pending_breakpoint_p (struct breakpoint *b)
6459 return b->loc == NULL;
6462 /* Print information on user settable breakpoint (watchpoint, etc)
6463 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6464 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6465 FILTER is non-NULL, call it on each breakpoint and only include the
6466 ones for which it returns non-zero. Return the total number of
6467 breakpoints listed. */
6470 breakpoint_1 (const char *args, int allflag,
6471 int (*filter) (const struct breakpoint *))
6473 struct breakpoint *b;
6474 struct bp_location *last_loc = NULL;
6475 int nr_printable_breakpoints;
6476 struct value_print_options opts;
6477 int print_address_bits = 0;
6478 int print_type_col_width = 14;
6479 struct ui_out *uiout = current_uiout;
6481 get_user_print_options (&opts);
6483 /* Compute the number of rows in the table, as well as the size
6484 required for address fields. */
6485 nr_printable_breakpoints = 0;
6488 /* If we have a filter, only list the breakpoints it accepts. */
6489 if (filter && !filter (b))
6492 /* If we have an "args" string, it is a list of breakpoints to
6493 accept. Skip the others. */
6494 if (args != NULL && *args != '\0')
6496 if (allflag && parse_and_eval_long (args) != b->number)
6498 if (!allflag && !number_is_in_list (args, b->number))
6502 if (allflag || user_breakpoint_p (b))
6504 int addr_bit, type_len;
6506 addr_bit = breakpoint_address_bits (b);
6507 if (addr_bit > print_address_bits)
6508 print_address_bits = addr_bit;
6510 type_len = strlen (bptype_string (b->type));
6511 if (type_len > print_type_col_width)
6512 print_type_col_width = type_len;
6514 nr_printable_breakpoints++;
6519 ui_out_emit_table table_emitter (uiout,
6520 opts.addressprint ? 6 : 5,
6521 nr_printable_breakpoints,
6524 if (nr_printable_breakpoints > 0)
6525 annotate_breakpoints_headers ();
6526 if (nr_printable_breakpoints > 0)
6528 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
6529 if (nr_printable_breakpoints > 0)
6531 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
6532 if (nr_printable_breakpoints > 0)
6534 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
6535 if (nr_printable_breakpoints > 0)
6537 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
6538 if (opts.addressprint)
6540 if (nr_printable_breakpoints > 0)
6542 if (print_address_bits <= 32)
6543 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
6545 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
6547 if (nr_printable_breakpoints > 0)
6549 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
6550 uiout->table_body ();
6551 if (nr_printable_breakpoints > 0)
6552 annotate_breakpoints_table ();
6557 /* If we have a filter, only list the breakpoints it accepts. */
6558 if (filter && !filter (b))
6561 /* If we have an "args" string, it is a list of breakpoints to
6562 accept. Skip the others. */
6564 if (args != NULL && *args != '\0')
6566 if (allflag) /* maintenance info breakpoint */
6568 if (parse_and_eval_long (args) != b->number)
6571 else /* all others */
6573 if (!number_is_in_list (args, b->number))
6577 /* We only print out user settable breakpoints unless the
6579 if (allflag || user_breakpoint_p (b))
6580 print_one_breakpoint (b, &last_loc, allflag);
6584 if (nr_printable_breakpoints == 0)
6586 /* If there's a filter, let the caller decide how to report
6590 if (args == NULL || *args == '\0')
6591 uiout->message ("No breakpoints or watchpoints.\n");
6593 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
6599 if (last_loc && !server_command)
6600 set_next_address (last_loc->gdbarch, last_loc->address);
6603 /* FIXME? Should this be moved up so that it is only called when
6604 there have been breakpoints? */
6605 annotate_breakpoints_table_end ();
6607 return nr_printable_breakpoints;
6610 /* Display the value of default-collect in a way that is generally
6611 compatible with the breakpoint list. */
6614 default_collect_info (void)
6616 struct ui_out *uiout = current_uiout;
6618 /* If it has no value (which is frequently the case), say nothing; a
6619 message like "No default-collect." gets in user's face when it's
6621 if (!*default_collect)
6624 /* The following phrase lines up nicely with per-tracepoint collect
6626 uiout->text ("default collect ");
6627 uiout->field_string ("default-collect", default_collect);
6628 uiout->text (" \n");
6632 info_breakpoints_command (const char *args, int from_tty)
6634 breakpoint_1 (args, 0, NULL);
6636 default_collect_info ();
6640 info_watchpoints_command (const char *args, int from_tty)
6642 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6643 struct ui_out *uiout = current_uiout;
6645 if (num_printed == 0)
6647 if (args == NULL || *args == '\0')
6648 uiout->message ("No watchpoints.\n");
6650 uiout->message ("No watchpoint matching '%s'.\n", args);
6655 maintenance_info_breakpoints (const char *args, int from_tty)
6657 breakpoint_1 (args, 1, NULL);
6659 default_collect_info ();
6663 breakpoint_has_pc (struct breakpoint *b,
6664 struct program_space *pspace,
6665 CORE_ADDR pc, struct obj_section *section)
6667 struct bp_location *bl = b->loc;
6669 for (; bl; bl = bl->next)
6671 if (bl->pspace == pspace
6672 && bl->address == pc
6673 && (!overlay_debugging || bl->section == section))
6679 /* Print a message describing any user-breakpoints set at PC. This
6680 concerns with logical breakpoints, so we match program spaces, not
6684 describe_other_breakpoints (struct gdbarch *gdbarch,
6685 struct program_space *pspace, CORE_ADDR pc,
6686 struct obj_section *section, int thread)
6689 struct breakpoint *b;
6692 others += (user_breakpoint_p (b)
6693 && breakpoint_has_pc (b, pspace, pc, section));
6697 printf_filtered (_("Note: breakpoint "));
6698 else /* if (others == ???) */
6699 printf_filtered (_("Note: breakpoints "));
6701 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6704 printf_filtered ("%d", b->number);
6705 if (b->thread == -1 && thread != -1)
6706 printf_filtered (" (all threads)");
6707 else if (b->thread != -1)
6708 printf_filtered (" (thread %d)", b->thread);
6709 printf_filtered ("%s%s ",
6710 ((b->enable_state == bp_disabled
6711 || b->enable_state == bp_call_disabled)
6715 : ((others == 1) ? " and" : ""));
6717 printf_filtered (_("also set at pc "));
6718 fputs_styled (paddress (gdbarch, pc), address_style.style (), gdb_stdout);
6719 printf_filtered (".\n");
6724 /* Return true iff it is meaningful to use the address member of
6725 BPT locations. For some breakpoint types, the locations' address members
6726 are irrelevant and it makes no sense to attempt to compare them to other
6727 addresses (or use them for any other purpose either).
6729 More specifically, each of the following breakpoint types will
6730 always have a zero valued location address and we don't want to mark
6731 breakpoints of any of these types to be a duplicate of an actual
6732 breakpoint location at address zero:
6740 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6742 enum bptype type = bpt->type;
6744 return (type != bp_watchpoint && type != bp_catchpoint);
6747 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6748 true if LOC1 and LOC2 represent the same watchpoint location. */
6751 watchpoint_locations_match (struct bp_location *loc1,
6752 struct bp_location *loc2)
6754 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6755 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6757 /* Both of them must exist. */
6758 gdb_assert (w1 != NULL);
6759 gdb_assert (w2 != NULL);
6761 /* If the target can evaluate the condition expression in hardware,
6762 then we we need to insert both watchpoints even if they are at
6763 the same place. Otherwise the watchpoint will only trigger when
6764 the condition of whichever watchpoint was inserted evaluates to
6765 true, not giving a chance for GDB to check the condition of the
6766 other watchpoint. */
6768 && target_can_accel_watchpoint_condition (loc1->address,
6770 loc1->watchpoint_type,
6771 w1->cond_exp.get ()))
6773 && target_can_accel_watchpoint_condition (loc2->address,
6775 loc2->watchpoint_type,
6776 w2->cond_exp.get ())))
6779 /* Note that this checks the owner's type, not the location's. In
6780 case the target does not support read watchpoints, but does
6781 support access watchpoints, we'll have bp_read_watchpoint
6782 watchpoints with hw_access locations. Those should be considered
6783 duplicates of hw_read locations. The hw_read locations will
6784 become hw_access locations later. */
6785 return (loc1->owner->type == loc2->owner->type
6786 && loc1->pspace->aspace == loc2->pspace->aspace
6787 && loc1->address == loc2->address
6788 && loc1->length == loc2->length);
6791 /* See breakpoint.h. */
6794 breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
6795 const address_space *aspace2, CORE_ADDR addr2)
6797 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6798 || aspace1 == aspace2)
6802 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6803 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6804 matches ASPACE2. On targets that have global breakpoints, the address
6805 space doesn't really matter. */
6808 breakpoint_address_match_range (const address_space *aspace1,
6810 int len1, const address_space *aspace2,
6813 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6814 || aspace1 == aspace2)
6815 && addr2 >= addr1 && addr2 < addr1 + len1);
6818 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6819 a ranged breakpoint. In most targets, a match happens only if ASPACE
6820 matches the breakpoint's address space. On targets that have global
6821 breakpoints, the address space doesn't really matter. */
6824 breakpoint_location_address_match (struct bp_location *bl,
6825 const address_space *aspace,
6828 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6831 && breakpoint_address_match_range (bl->pspace->aspace,
6832 bl->address, bl->length,
6836 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6837 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6838 match happens only if ASPACE matches the breakpoint's address
6839 space. On targets that have global breakpoints, the address space
6840 doesn't really matter. */
6843 breakpoint_location_address_range_overlap (struct bp_location *bl,
6844 const address_space *aspace,
6845 CORE_ADDR addr, int len)
6847 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6848 || bl->pspace->aspace == aspace)
6850 int bl_len = bl->length != 0 ? bl->length : 1;
6852 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
6858 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6859 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6860 true, otherwise returns false. */
6863 tracepoint_locations_match (struct bp_location *loc1,
6864 struct bp_location *loc2)
6866 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6867 /* Since tracepoint locations are never duplicated with others', tracepoint
6868 locations at the same address of different tracepoints are regarded as
6869 different locations. */
6870 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6875 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6876 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6877 represent the same location. */
6880 breakpoint_locations_match (struct bp_location *loc1,
6881 struct bp_location *loc2)
6883 int hw_point1, hw_point2;
6885 /* Both of them must not be in moribund_locations. */
6886 gdb_assert (loc1->owner != NULL);
6887 gdb_assert (loc2->owner != NULL);
6889 hw_point1 = is_hardware_watchpoint (loc1->owner);
6890 hw_point2 = is_hardware_watchpoint (loc2->owner);
6892 if (hw_point1 != hw_point2)
6895 return watchpoint_locations_match (loc1, loc2);
6896 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6897 return tracepoint_locations_match (loc1, loc2);
6899 /* We compare bp_location.length in order to cover ranged breakpoints. */
6900 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6901 loc2->pspace->aspace, loc2->address)
6902 && loc1->length == loc2->length);
6906 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6907 int bnum, int have_bnum)
6909 /* The longest string possibly returned by hex_string_custom
6910 is 50 chars. These must be at least that big for safety. */
6914 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6915 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6917 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6918 bnum, astr1, astr2);
6920 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6923 /* Adjust a breakpoint's address to account for architectural
6924 constraints on breakpoint placement. Return the adjusted address.
6925 Note: Very few targets require this kind of adjustment. For most
6926 targets, this function is simply the identity function. */
6929 adjust_breakpoint_address (struct gdbarch *gdbarch,
6930 CORE_ADDR bpaddr, enum bptype bptype)
6932 if (bptype == bp_watchpoint
6933 || bptype == bp_hardware_watchpoint
6934 || bptype == bp_read_watchpoint
6935 || bptype == bp_access_watchpoint
6936 || bptype == bp_catchpoint)
6938 /* Watchpoints and the various bp_catch_* eventpoints should not
6939 have their addresses modified. */
6942 else if (bptype == bp_single_step)
6944 /* Single-step breakpoints should not have their addresses
6945 modified. If there's any architectural constrain that
6946 applies to this address, then it should have already been
6947 taken into account when the breakpoint was created in the
6948 first place. If we didn't do this, stepping through e.g.,
6949 Thumb-2 IT blocks would break. */
6954 CORE_ADDR adjusted_bpaddr = bpaddr;
6956 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
6958 /* Some targets have architectural constraints on the placement
6959 of breakpoint instructions. Obtain the adjusted address. */
6960 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6963 adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
6965 /* An adjusted breakpoint address can significantly alter
6966 a user's expectations. Print a warning if an adjustment
6968 if (adjusted_bpaddr != bpaddr)
6969 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6971 return adjusted_bpaddr;
6975 bp_location::bp_location (breakpoint *owner)
6977 bp_location *loc = this;
6980 loc->cond_bytecode = NULL;
6981 loc->shlib_disabled = 0;
6984 switch (owner->type)
6987 case bp_single_step:
6991 case bp_longjmp_resume:
6992 case bp_longjmp_call_dummy:
6994 case bp_exception_resume:
6995 case bp_step_resume:
6996 case bp_hp_step_resume:
6997 case bp_watchpoint_scope:
6999 case bp_std_terminate:
7000 case bp_shlib_event:
7001 case bp_thread_event:
7002 case bp_overlay_event:
7004 case bp_longjmp_master:
7005 case bp_std_terminate_master:
7006 case bp_exception_master:
7007 case bp_gnu_ifunc_resolver:
7008 case bp_gnu_ifunc_resolver_return:
7010 loc->loc_type = bp_loc_software_breakpoint;
7011 mark_breakpoint_location_modified (loc);
7013 case bp_hardware_breakpoint:
7014 loc->loc_type = bp_loc_hardware_breakpoint;
7015 mark_breakpoint_location_modified (loc);
7017 case bp_hardware_watchpoint:
7018 case bp_read_watchpoint:
7019 case bp_access_watchpoint:
7020 loc->loc_type = bp_loc_hardware_watchpoint;
7025 case bp_fast_tracepoint:
7026 case bp_static_tracepoint:
7027 loc->loc_type = bp_loc_other;
7030 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7036 /* Allocate a struct bp_location. */
7038 static struct bp_location *
7039 allocate_bp_location (struct breakpoint *bpt)
7041 return bpt->ops->allocate_location (bpt);
7045 free_bp_location (struct bp_location *loc)
7050 /* Increment reference count. */
7053 incref_bp_location (struct bp_location *bl)
7058 /* Decrement reference count. If the reference count reaches 0,
7059 destroy the bp_location. Sets *BLP to NULL. */
7062 decref_bp_location (struct bp_location **blp)
7064 gdb_assert ((*blp)->refc > 0);
7066 if (--(*blp)->refc == 0)
7067 free_bp_location (*blp);
7071 /* Add breakpoint B at the end of the global breakpoint chain. */
7074 add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
7076 struct breakpoint *b1;
7077 struct breakpoint *result = b.get ();
7079 /* Add this breakpoint to the end of the chain so that a list of
7080 breakpoints will come out in order of increasing numbers. */
7082 b1 = breakpoint_chain;
7084 breakpoint_chain = b.release ();
7089 b1->next = b.release ();
7095 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7098 init_raw_breakpoint_without_location (struct breakpoint *b,
7099 struct gdbarch *gdbarch,
7101 const struct breakpoint_ops *ops)
7103 gdb_assert (ops != NULL);
7107 b->gdbarch = gdbarch;
7108 b->language = current_language->la_language;
7109 b->input_radix = input_radix;
7110 b->related_breakpoint = b;
7113 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7114 that has type BPTYPE and has no locations as yet. */
7116 static struct breakpoint *
7117 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7119 const struct breakpoint_ops *ops)
7121 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7123 init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops);
7124 return add_to_breakpoint_chain (std::move (b));
7127 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7128 resolutions should be made as the user specified the location explicitly
7132 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7134 gdb_assert (loc->owner != NULL);
7136 if (loc->owner->type == bp_breakpoint
7137 || loc->owner->type == bp_hardware_breakpoint
7138 || is_tracepoint (loc->owner))
7140 const char *function_name;
7142 if (loc->msymbol != NULL
7143 && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc
7144 || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)
7147 struct breakpoint *b = loc->owner;
7149 function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol);
7151 if (b->type == bp_breakpoint && b->loc == loc
7152 && loc->next == NULL && b->related_breakpoint == b)
7154 /* Create only the whole new breakpoint of this type but do not
7155 mess more complicated breakpoints with multiple locations. */
7156 b->type = bp_gnu_ifunc_resolver;
7157 /* Remember the resolver's address for use by the return
7159 loc->related_address = loc->address;
7163 find_pc_partial_function (loc->address, &function_name, NULL, NULL);
7166 loc->function_name = xstrdup (function_name);
7170 /* Attempt to determine architecture of location identified by SAL. */
7172 get_sal_arch (struct symtab_and_line sal)
7175 return get_objfile_arch (sal.section->objfile);
7177 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7182 /* Low level routine for partially initializing a breakpoint of type
7183 BPTYPE. The newly created breakpoint's address, section, source
7184 file name, and line number are provided by SAL.
7186 It is expected that the caller will complete the initialization of
7187 the newly created breakpoint struct as well as output any status
7188 information regarding the creation of a new breakpoint. */
7191 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7192 struct symtab_and_line sal, enum bptype bptype,
7193 const struct breakpoint_ops *ops)
7195 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7197 add_location_to_breakpoint (b, &sal);
7199 if (bptype != bp_catchpoint)
7200 gdb_assert (sal.pspace != NULL);
7202 /* Store the program space that was used to set the breakpoint,
7203 except for ordinary breakpoints, which are independent of the
7205 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7206 b->pspace = sal.pspace;
7209 /* set_raw_breakpoint is a low level routine for allocating and
7210 partially initializing a breakpoint of type BPTYPE. The newly
7211 created breakpoint's address, section, source file name, and line
7212 number are provided by SAL. The newly created and partially
7213 initialized breakpoint is added to the breakpoint chain and
7214 is also returned as the value of this function.
7216 It is expected that the caller will complete the initialization of
7217 the newly created breakpoint struct as well as output any status
7218 information regarding the creation of a new breakpoint. In
7219 particular, set_raw_breakpoint does NOT set the breakpoint
7220 number! Care should be taken to not allow an error to occur
7221 prior to completing the initialization of the breakpoint. If this
7222 should happen, a bogus breakpoint will be left on the chain. */
7225 set_raw_breakpoint (struct gdbarch *gdbarch,
7226 struct symtab_and_line sal, enum bptype bptype,
7227 const struct breakpoint_ops *ops)
7229 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7231 init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops);
7232 return add_to_breakpoint_chain (std::move (b));
7235 /* Call this routine when stepping and nexting to enable a breakpoint
7236 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7237 initiated the operation. */
7240 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7242 struct breakpoint *b, *b_tmp;
7243 int thread = tp->global_num;
7245 /* To avoid having to rescan all objfile symbols at every step,
7246 we maintain a list of continually-inserted but always disabled
7247 longjmp "master" breakpoints. Here, we simply create momentary
7248 clones of those and enable them for the requested thread. */
7249 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7250 if (b->pspace == current_program_space
7251 && (b->type == bp_longjmp_master
7252 || b->type == bp_exception_master))
7254 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7255 struct breakpoint *clone;
7257 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7258 after their removal. */
7259 clone = momentary_breakpoint_from_master (b, type,
7260 &momentary_breakpoint_ops, 1);
7261 clone->thread = thread;
7264 tp->initiating_frame = frame;
7267 /* Delete all longjmp breakpoints from THREAD. */
7269 delete_longjmp_breakpoint (int thread)
7271 struct breakpoint *b, *b_tmp;
7273 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7274 if (b->type == bp_longjmp || b->type == bp_exception)
7276 if (b->thread == thread)
7277 delete_breakpoint (b);
7282 delete_longjmp_breakpoint_at_next_stop (int thread)
7284 struct breakpoint *b, *b_tmp;
7286 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7287 if (b->type == bp_longjmp || b->type == bp_exception)
7289 if (b->thread == thread)
7290 b->disposition = disp_del_at_next_stop;
7294 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7295 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7296 pointer to any of them. Return NULL if this system cannot place longjmp
7300 set_longjmp_breakpoint_for_call_dummy (void)
7302 struct breakpoint *b, *retval = NULL;
7305 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7307 struct breakpoint *new_b;
7309 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7310 &momentary_breakpoint_ops,
7312 new_b->thread = inferior_thread ()->global_num;
7314 /* Link NEW_B into the chain of RETVAL breakpoints. */
7316 gdb_assert (new_b->related_breakpoint == new_b);
7319 new_b->related_breakpoint = retval;
7320 while (retval->related_breakpoint != new_b->related_breakpoint)
7321 retval = retval->related_breakpoint;
7322 retval->related_breakpoint = new_b;
7328 /* Verify all existing dummy frames and their associated breakpoints for
7329 TP. Remove those which can no longer be found in the current frame
7332 You should call this function only at places where it is safe to currently
7333 unwind the whole stack. Failed stack unwind would discard live dummy
7337 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7339 struct breakpoint *b, *b_tmp;
7341 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7342 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7344 struct breakpoint *dummy_b = b->related_breakpoint;
7346 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7347 dummy_b = dummy_b->related_breakpoint;
7348 if (dummy_b->type != bp_call_dummy
7349 || frame_find_by_id (dummy_b->frame_id) != NULL)
7352 dummy_frame_discard (dummy_b->frame_id, tp);
7354 while (b->related_breakpoint != b)
7356 if (b_tmp == b->related_breakpoint)
7357 b_tmp = b->related_breakpoint->next;
7358 delete_breakpoint (b->related_breakpoint);
7360 delete_breakpoint (b);
7365 enable_overlay_breakpoints (void)
7367 struct breakpoint *b;
7370 if (b->type == bp_overlay_event)
7372 b->enable_state = bp_enabled;
7373 update_global_location_list (UGLL_MAY_INSERT);
7374 overlay_events_enabled = 1;
7379 disable_overlay_breakpoints (void)
7381 struct breakpoint *b;
7384 if (b->type == bp_overlay_event)
7386 b->enable_state = bp_disabled;
7387 update_global_location_list (UGLL_DONT_INSERT);
7388 overlay_events_enabled = 0;
7392 /* Set an active std::terminate breakpoint for each std::terminate
7393 master breakpoint. */
7395 set_std_terminate_breakpoint (void)
7397 struct breakpoint *b, *b_tmp;
7399 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7400 if (b->pspace == current_program_space
7401 && b->type == bp_std_terminate_master)
7403 momentary_breakpoint_from_master (b, bp_std_terminate,
7404 &momentary_breakpoint_ops, 1);
7408 /* Delete all the std::terminate breakpoints. */
7410 delete_std_terminate_breakpoint (void)
7412 struct breakpoint *b, *b_tmp;
7414 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7415 if (b->type == bp_std_terminate)
7416 delete_breakpoint (b);
7420 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7422 struct breakpoint *b;
7424 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7425 &internal_breakpoint_ops);
7427 b->enable_state = bp_enabled;
7428 /* location has to be used or breakpoint_re_set will delete me. */
7429 b->location = new_address_location (b->loc->address, NULL, 0);
7431 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7436 struct lang_and_radix
7442 /* Create a breakpoint for JIT code registration and unregistration. */
7445 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7447 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7448 &internal_breakpoint_ops);
7451 /* Remove JIT code registration and unregistration breakpoint(s). */
7454 remove_jit_event_breakpoints (void)
7456 struct breakpoint *b, *b_tmp;
7458 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7459 if (b->type == bp_jit_event
7460 && b->loc->pspace == current_program_space)
7461 delete_breakpoint (b);
7465 remove_solib_event_breakpoints (void)
7467 struct breakpoint *b, *b_tmp;
7469 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7470 if (b->type == bp_shlib_event
7471 && b->loc->pspace == current_program_space)
7472 delete_breakpoint (b);
7475 /* See breakpoint.h. */
7478 remove_solib_event_breakpoints_at_next_stop (void)
7480 struct breakpoint *b, *b_tmp;
7482 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7483 if (b->type == bp_shlib_event
7484 && b->loc->pspace == current_program_space)
7485 b->disposition = disp_del_at_next_stop;
7488 /* Helper for create_solib_event_breakpoint /
7489 create_and_insert_solib_event_breakpoint. Allows specifying which
7490 INSERT_MODE to pass through to update_global_location_list. */
7492 static struct breakpoint *
7493 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7494 enum ugll_insert_mode insert_mode)
7496 struct breakpoint *b;
7498 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7499 &internal_breakpoint_ops);
7500 update_global_location_list_nothrow (insert_mode);
7505 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7507 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7510 /* See breakpoint.h. */
7513 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7515 struct breakpoint *b;
7517 /* Explicitly tell update_global_location_list to insert
7519 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7520 if (!b->loc->inserted)
7522 delete_breakpoint (b);
7528 /* Disable any breakpoints that are on code in shared libraries. Only
7529 apply to enabled breakpoints, disabled ones can just stay disabled. */
7532 disable_breakpoints_in_shlibs (void)
7534 struct bp_location *loc, **locp_tmp;
7536 ALL_BP_LOCATIONS (loc, locp_tmp)
7538 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7539 struct breakpoint *b = loc->owner;
7541 /* We apply the check to all breakpoints, including disabled for
7542 those with loc->duplicate set. This is so that when breakpoint
7543 becomes enabled, or the duplicate is removed, gdb will try to
7544 insert all breakpoints. If we don't set shlib_disabled here,
7545 we'll try to insert those breakpoints and fail. */
7546 if (((b->type == bp_breakpoint)
7547 || (b->type == bp_jit_event)
7548 || (b->type == bp_hardware_breakpoint)
7549 || (is_tracepoint (b)))
7550 && loc->pspace == current_program_space
7551 && !loc->shlib_disabled
7552 && solib_name_from_address (loc->pspace, loc->address)
7555 loc->shlib_disabled = 1;
7560 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7561 notification of unloaded_shlib. Only apply to enabled breakpoints,
7562 disabled ones can just stay disabled. */
7565 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7567 struct bp_location *loc, **locp_tmp;
7568 int disabled_shlib_breaks = 0;
7570 ALL_BP_LOCATIONS (loc, locp_tmp)
7572 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7573 struct breakpoint *b = loc->owner;
7575 if (solib->pspace == loc->pspace
7576 && !loc->shlib_disabled
7577 && (((b->type == bp_breakpoint
7578 || b->type == bp_jit_event
7579 || b->type == bp_hardware_breakpoint)
7580 && (loc->loc_type == bp_loc_hardware_breakpoint
7581 || loc->loc_type == bp_loc_software_breakpoint))
7582 || is_tracepoint (b))
7583 && solib_contains_address_p (solib, loc->address))
7585 loc->shlib_disabled = 1;
7586 /* At this point, we cannot rely on remove_breakpoint
7587 succeeding so we must mark the breakpoint as not inserted
7588 to prevent future errors occurring in remove_breakpoints. */
7591 /* This may cause duplicate notifications for the same breakpoint. */
7592 gdb::observers::breakpoint_modified.notify (b);
7594 if (!disabled_shlib_breaks)
7596 target_terminal::ours_for_output ();
7597 warning (_("Temporarily disabling breakpoints "
7598 "for unloaded shared library \"%s\""),
7601 disabled_shlib_breaks = 1;
7606 /* Disable any breakpoints and tracepoints in OBJFILE upon
7607 notification of free_objfile. Only apply to enabled breakpoints,
7608 disabled ones can just stay disabled. */
7611 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7613 struct breakpoint *b;
7615 if (objfile == NULL)
7618 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7619 managed by the user with add-symbol-file/remove-symbol-file.
7620 Similarly to how breakpoints in shared libraries are handled in
7621 response to "nosharedlibrary", mark breakpoints in such modules
7622 shlib_disabled so they end up uninserted on the next global
7623 location list update. Shared libraries not loaded by the user
7624 aren't handled here -- they're already handled in
7625 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7626 solib_unloaded observer. We skip objfiles that are not
7627 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7629 if ((objfile->flags & OBJF_SHARED) == 0
7630 || (objfile->flags & OBJF_USERLOADED) == 0)
7635 struct bp_location *loc;
7636 int bp_modified = 0;
7638 if (!is_breakpoint (b) && !is_tracepoint (b))
7641 for (loc = b->loc; loc != NULL; loc = loc->next)
7643 CORE_ADDR loc_addr = loc->address;
7645 if (loc->loc_type != bp_loc_hardware_breakpoint
7646 && loc->loc_type != bp_loc_software_breakpoint)
7649 if (loc->shlib_disabled != 0)
7652 if (objfile->pspace != loc->pspace)
7655 if (loc->loc_type != bp_loc_hardware_breakpoint
7656 && loc->loc_type != bp_loc_software_breakpoint)
7659 if (is_addr_in_objfile (loc_addr, objfile))
7661 loc->shlib_disabled = 1;
7662 /* At this point, we don't know whether the object was
7663 unmapped from the inferior or not, so leave the
7664 inserted flag alone. We'll handle failure to
7665 uninsert quietly, in case the object was indeed
7668 mark_breakpoint_location_modified (loc);
7675 gdb::observers::breakpoint_modified.notify (b);
7679 /* FORK & VFORK catchpoints. */
7681 /* An instance of this type is used to represent a fork or vfork
7682 catchpoint. A breakpoint is really of this type iff its ops pointer points
7683 to CATCH_FORK_BREAKPOINT_OPS. */
7685 struct fork_catchpoint : public breakpoint
7687 /* Process id of a child process whose forking triggered this
7688 catchpoint. This field is only valid immediately after this
7689 catchpoint has triggered. */
7690 ptid_t forked_inferior_pid;
7693 /* Implement the "insert" breakpoint_ops method for fork
7697 insert_catch_fork (struct bp_location *bl)
7699 return target_insert_fork_catchpoint (inferior_ptid.pid ());
7702 /* Implement the "remove" breakpoint_ops method for fork
7706 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
7708 return target_remove_fork_catchpoint (inferior_ptid.pid ());
7711 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7715 breakpoint_hit_catch_fork (const struct bp_location *bl,
7716 const address_space *aspace, CORE_ADDR bp_addr,
7717 const struct target_waitstatus *ws)
7719 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7721 if (ws->kind != TARGET_WAITKIND_FORKED)
7724 c->forked_inferior_pid = ws->value.related_pid;
7728 /* Implement the "print_it" breakpoint_ops method for fork
7731 static enum print_stop_action
7732 print_it_catch_fork (bpstat bs)
7734 struct ui_out *uiout = current_uiout;
7735 struct breakpoint *b = bs->breakpoint_at;
7736 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7738 annotate_catchpoint (b->number);
7739 maybe_print_thread_hit_breakpoint (uiout);
7740 if (b->disposition == disp_del)
7741 uiout->text ("Temporary catchpoint ");
7743 uiout->text ("Catchpoint ");
7744 if (uiout->is_mi_like_p ())
7746 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK));
7747 uiout->field_string ("disp", bpdisp_text (b->disposition));
7749 uiout->field_int ("bkptno", b->number);
7750 uiout->text (" (forked process ");
7751 uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
7752 uiout->text ("), ");
7753 return PRINT_SRC_AND_LOC;
7756 /* Implement the "print_one" breakpoint_ops method for fork
7760 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7762 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7763 struct value_print_options opts;
7764 struct ui_out *uiout = current_uiout;
7766 get_user_print_options (&opts);
7768 /* Field 4, the address, is omitted (which makes the columns not
7769 line up too nicely with the headers, but the effect is relatively
7771 if (opts.addressprint)
7772 uiout->field_skip ("addr");
7774 uiout->text ("fork");
7775 if (c->forked_inferior_pid != null_ptid)
7777 uiout->text (", process ");
7778 uiout->field_int ("what", c->forked_inferior_pid.pid ());
7782 if (uiout->is_mi_like_p ())
7783 uiout->field_string ("catch-type", "fork");
7786 /* Implement the "print_mention" breakpoint_ops method for fork
7790 print_mention_catch_fork (struct breakpoint *b)
7792 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7795 /* Implement the "print_recreate" breakpoint_ops method for fork
7799 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7801 fprintf_unfiltered (fp, "catch fork");
7802 print_recreate_thread (b, fp);
7805 /* The breakpoint_ops structure to be used in fork catchpoints. */
7807 static struct breakpoint_ops catch_fork_breakpoint_ops;
7809 /* Implement the "insert" breakpoint_ops method for vfork
7813 insert_catch_vfork (struct bp_location *bl)
7815 return target_insert_vfork_catchpoint (inferior_ptid.pid ());
7818 /* Implement the "remove" breakpoint_ops method for vfork
7822 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
7824 return target_remove_vfork_catchpoint (inferior_ptid.pid ());
7827 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7831 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7832 const address_space *aspace, CORE_ADDR bp_addr,
7833 const struct target_waitstatus *ws)
7835 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7837 if (ws->kind != TARGET_WAITKIND_VFORKED)
7840 c->forked_inferior_pid = ws->value.related_pid;
7844 /* Implement the "print_it" breakpoint_ops method for vfork
7847 static enum print_stop_action
7848 print_it_catch_vfork (bpstat bs)
7850 struct ui_out *uiout = current_uiout;
7851 struct breakpoint *b = bs->breakpoint_at;
7852 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7854 annotate_catchpoint (b->number);
7855 maybe_print_thread_hit_breakpoint (uiout);
7856 if (b->disposition == disp_del)
7857 uiout->text ("Temporary catchpoint ");
7859 uiout->text ("Catchpoint ");
7860 if (uiout->is_mi_like_p ())
7862 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK));
7863 uiout->field_string ("disp", bpdisp_text (b->disposition));
7865 uiout->field_int ("bkptno", b->number);
7866 uiout->text (" (vforked process ");
7867 uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
7868 uiout->text ("), ");
7869 return PRINT_SRC_AND_LOC;
7872 /* Implement the "print_one" breakpoint_ops method for vfork
7876 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7878 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7879 struct value_print_options opts;
7880 struct ui_out *uiout = current_uiout;
7882 get_user_print_options (&opts);
7883 /* Field 4, the address, is omitted (which makes the columns not
7884 line up too nicely with the headers, but the effect is relatively
7886 if (opts.addressprint)
7887 uiout->field_skip ("addr");
7889 uiout->text ("vfork");
7890 if (c->forked_inferior_pid != null_ptid)
7892 uiout->text (", process ");
7893 uiout->field_int ("what", c->forked_inferior_pid.pid ());
7897 if (uiout->is_mi_like_p ())
7898 uiout->field_string ("catch-type", "vfork");
7901 /* Implement the "print_mention" breakpoint_ops method for vfork
7905 print_mention_catch_vfork (struct breakpoint *b)
7907 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7910 /* Implement the "print_recreate" breakpoint_ops method for vfork
7914 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7916 fprintf_unfiltered (fp, "catch vfork");
7917 print_recreate_thread (b, fp);
7920 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7922 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7924 /* An instance of this type is used to represent an solib catchpoint.
7925 A breakpoint is really of this type iff its ops pointer points to
7926 CATCH_SOLIB_BREAKPOINT_OPS. */
7928 struct solib_catchpoint : public breakpoint
7930 ~solib_catchpoint () override;
7932 /* True for "catch load", false for "catch unload". */
7933 unsigned char is_load;
7935 /* Regular expression to match, if any. COMPILED is only valid when
7936 REGEX is non-NULL. */
7938 std::unique_ptr<compiled_regex> compiled;
7941 solib_catchpoint::~solib_catchpoint ()
7943 xfree (this->regex);
7947 insert_catch_solib (struct bp_location *ignore)
7953 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
7959 breakpoint_hit_catch_solib (const struct bp_location *bl,
7960 const address_space *aspace,
7962 const struct target_waitstatus *ws)
7964 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7965 struct breakpoint *other;
7967 if (ws->kind == TARGET_WAITKIND_LOADED)
7970 ALL_BREAKPOINTS (other)
7972 struct bp_location *other_bl;
7974 if (other == bl->owner)
7977 if (other->type != bp_shlib_event)
7980 if (self->pspace != NULL && other->pspace != self->pspace)
7983 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7985 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7994 check_status_catch_solib (struct bpstats *bs)
7996 struct solib_catchpoint *self
7997 = (struct solib_catchpoint *) bs->breakpoint_at;
8001 for (so_list *iter : current_program_space->added_solibs)
8004 || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
8010 for (const std::string &iter : current_program_space->deleted_solibs)
8013 || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
8019 bs->print_it = print_it_noop;
8022 static enum print_stop_action
8023 print_it_catch_solib (bpstat bs)
8025 struct breakpoint *b = bs->breakpoint_at;
8026 struct ui_out *uiout = current_uiout;
8028 annotate_catchpoint (b->number);
8029 maybe_print_thread_hit_breakpoint (uiout);
8030 if (b->disposition == disp_del)
8031 uiout->text ("Temporary catchpoint ");
8033 uiout->text ("Catchpoint ");
8034 uiout->field_int ("bkptno", b->number);
8036 if (uiout->is_mi_like_p ())
8037 uiout->field_string ("disp", bpdisp_text (b->disposition));
8038 print_solib_event (1);
8039 return PRINT_SRC_AND_LOC;
8043 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8045 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8046 struct value_print_options opts;
8047 struct ui_out *uiout = current_uiout;
8049 get_user_print_options (&opts);
8050 /* Field 4, the address, is omitted (which makes the columns not
8051 line up too nicely with the headers, but the effect is relatively
8053 if (opts.addressprint)
8056 uiout->field_skip ("addr");
8064 msg = string_printf (_("load of library matching %s"), self->regex);
8066 msg = _("load of library");
8071 msg = string_printf (_("unload of library matching %s"), self->regex);
8073 msg = _("unload of library");
8075 uiout->field_string ("what", msg);
8077 if (uiout->is_mi_like_p ())
8078 uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
8082 print_mention_catch_solib (struct breakpoint *b)
8084 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8086 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8087 self->is_load ? "load" : "unload");
8091 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8093 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8095 fprintf_unfiltered (fp, "%s %s",
8096 b->disposition == disp_del ? "tcatch" : "catch",
8097 self->is_load ? "load" : "unload");
8099 fprintf_unfiltered (fp, " %s", self->regex);
8100 fprintf_unfiltered (fp, "\n");
8103 static struct breakpoint_ops catch_solib_breakpoint_ops;
8105 /* Shared helper function (MI and CLI) for creating and installing
8106 a shared object event catchpoint. If IS_LOAD is non-zero then
8107 the events to be caught are load events, otherwise they are
8108 unload events. If IS_TEMP is non-zero the catchpoint is a
8109 temporary one. If ENABLED is non-zero the catchpoint is
8110 created in an enabled state. */
8113 add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
8115 struct gdbarch *gdbarch = get_current_arch ();
8119 arg = skip_spaces (arg);
8121 std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
8125 c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
8126 _("Invalid regexp")));
8127 c->regex = xstrdup (arg);
8130 c->is_load = is_load;
8131 init_catchpoint (c.get (), gdbarch, is_temp, NULL,
8132 &catch_solib_breakpoint_ops);
8134 c->enable_state = enabled ? bp_enabled : bp_disabled;
8136 install_breakpoint (0, std::move (c), 1);
8139 /* A helper function that does all the work for "catch load" and
8143 catch_load_or_unload (const char *arg, int from_tty, int is_load,
8144 struct cmd_list_element *command)
8147 const int enabled = 1;
8149 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8151 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8155 catch_load_command_1 (const char *arg, int from_tty,
8156 struct cmd_list_element *command)
8158 catch_load_or_unload (arg, from_tty, 1, command);
8162 catch_unload_command_1 (const char *arg, int from_tty,
8163 struct cmd_list_element *command)
8165 catch_load_or_unload (arg, from_tty, 0, command);
8168 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8169 is non-zero, then make the breakpoint temporary. If COND_STRING is
8170 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8171 the breakpoint_ops structure associated to the catchpoint. */
8174 init_catchpoint (struct breakpoint *b,
8175 struct gdbarch *gdbarch, int tempflag,
8176 const char *cond_string,
8177 const struct breakpoint_ops *ops)
8179 symtab_and_line sal;
8180 sal.pspace = current_program_space;
8182 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8184 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8185 b->disposition = tempflag ? disp_del : disp_donttouch;
8189 install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll)
8191 breakpoint *b = add_to_breakpoint_chain (std::move (arg));
8192 set_breakpoint_number (internal, b);
8193 if (is_tracepoint (b))
8194 set_tracepoint_count (breakpoint_count);
8197 gdb::observers::breakpoint_created.notify (b);
8200 update_global_location_list (UGLL_MAY_INSERT);
8204 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8205 int tempflag, const char *cond_string,
8206 const struct breakpoint_ops *ops)
8208 std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
8210 init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops);
8212 c->forked_inferior_pid = null_ptid;
8214 install_breakpoint (0, std::move (c), 1);
8217 /* Exec catchpoints. */
8219 /* An instance of this type is used to represent an exec catchpoint.
8220 A breakpoint is really of this type iff its ops pointer points to
8221 CATCH_EXEC_BREAKPOINT_OPS. */
8223 struct exec_catchpoint : public breakpoint
8225 ~exec_catchpoint () override;
8227 /* Filename of a program whose exec triggered this catchpoint.
8228 This field is only valid immediately after this catchpoint has
8230 char *exec_pathname;
8233 /* Exec catchpoint destructor. */
8235 exec_catchpoint::~exec_catchpoint ()
8237 xfree (this->exec_pathname);
8241 insert_catch_exec (struct bp_location *bl)
8243 return target_insert_exec_catchpoint (inferior_ptid.pid ());
8247 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8249 return target_remove_exec_catchpoint (inferior_ptid.pid ());
8253 breakpoint_hit_catch_exec (const struct bp_location *bl,
8254 const address_space *aspace, CORE_ADDR bp_addr,
8255 const struct target_waitstatus *ws)
8257 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8259 if (ws->kind != TARGET_WAITKIND_EXECD)
8262 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8266 static enum print_stop_action
8267 print_it_catch_exec (bpstat bs)
8269 struct ui_out *uiout = current_uiout;
8270 struct breakpoint *b = bs->breakpoint_at;
8271 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8273 annotate_catchpoint (b->number);
8274 maybe_print_thread_hit_breakpoint (uiout);
8275 if (b->disposition == disp_del)
8276 uiout->text ("Temporary catchpoint ");
8278 uiout->text ("Catchpoint ");
8279 if (uiout->is_mi_like_p ())
8281 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
8282 uiout->field_string ("disp", bpdisp_text (b->disposition));
8284 uiout->field_int ("bkptno", b->number);
8285 uiout->text (" (exec'd ");
8286 uiout->field_string ("new-exec", c->exec_pathname);
8287 uiout->text ("), ");
8289 return PRINT_SRC_AND_LOC;
8293 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8295 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8296 struct value_print_options opts;
8297 struct ui_out *uiout = current_uiout;
8299 get_user_print_options (&opts);
8301 /* Field 4, the address, is omitted (which makes the columns
8302 not line up too nicely with the headers, but the effect
8303 is relatively readable). */
8304 if (opts.addressprint)
8305 uiout->field_skip ("addr");
8307 uiout->text ("exec");
8308 if (c->exec_pathname != NULL)
8310 uiout->text (", program \"");
8311 uiout->field_string ("what", c->exec_pathname);
8312 uiout->text ("\" ");
8315 if (uiout->is_mi_like_p ())
8316 uiout->field_string ("catch-type", "exec");
8320 print_mention_catch_exec (struct breakpoint *b)
8322 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8325 /* Implement the "print_recreate" breakpoint_ops method for exec
8329 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8331 fprintf_unfiltered (fp, "catch exec");
8332 print_recreate_thread (b, fp);
8335 static struct breakpoint_ops catch_exec_breakpoint_ops;
8338 hw_breakpoint_used_count (void)
8341 struct breakpoint *b;
8342 struct bp_location *bl;
8346 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8347 for (bl = b->loc; bl; bl = bl->next)
8349 /* Special types of hardware breakpoints may use more than
8351 i += b->ops->resources_needed (bl);
8358 /* Returns the resources B would use if it were a hardware
8362 hw_watchpoint_use_count (struct breakpoint *b)
8365 struct bp_location *bl;
8367 if (!breakpoint_enabled (b))
8370 for (bl = b->loc; bl; bl = bl->next)
8372 /* Special types of hardware watchpoints may use more than
8374 i += b->ops->resources_needed (bl);
8380 /* Returns the sum the used resources of all hardware watchpoints of
8381 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8382 the sum of the used resources of all hardware watchpoints of other
8383 types _not_ TYPE. */
8386 hw_watchpoint_used_count_others (struct breakpoint *except,
8387 enum bptype type, int *other_type_used)
8390 struct breakpoint *b;
8392 *other_type_used = 0;
8397 if (!breakpoint_enabled (b))
8400 if (b->type == type)
8401 i += hw_watchpoint_use_count (b);
8402 else if (is_hardware_watchpoint (b))
8403 *other_type_used = 1;
8410 disable_watchpoints_before_interactive_call_start (void)
8412 struct breakpoint *b;
8416 if (is_watchpoint (b) && breakpoint_enabled (b))
8418 b->enable_state = bp_call_disabled;
8419 update_global_location_list (UGLL_DONT_INSERT);
8425 enable_watchpoints_after_interactive_call_stop (void)
8427 struct breakpoint *b;
8431 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8433 b->enable_state = bp_enabled;
8434 update_global_location_list (UGLL_MAY_INSERT);
8440 disable_breakpoints_before_startup (void)
8442 current_program_space->executing_startup = 1;
8443 update_global_location_list (UGLL_DONT_INSERT);
8447 enable_breakpoints_after_startup (void)
8449 current_program_space->executing_startup = 0;
8450 breakpoint_re_set ();
8453 /* Create a new single-step breakpoint for thread THREAD, with no
8456 static struct breakpoint *
8457 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8459 std::unique_ptr<breakpoint> b (new breakpoint ());
8461 init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
8462 &momentary_breakpoint_ops);
8464 b->disposition = disp_donttouch;
8465 b->frame_id = null_frame_id;
8468 gdb_assert (b->thread != 0);
8470 return add_to_breakpoint_chain (std::move (b));
8473 /* Set a momentary breakpoint of type TYPE at address specified by
8474 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8478 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8479 struct frame_id frame_id, enum bptype type)
8481 struct breakpoint *b;
8483 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8485 gdb_assert (!frame_id_artificial_p (frame_id));
8487 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8488 b->enable_state = bp_enabled;
8489 b->disposition = disp_donttouch;
8490 b->frame_id = frame_id;
8492 b->thread = inferior_thread ()->global_num;
8494 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8496 return breakpoint_up (b);
8499 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8500 The new breakpoint will have type TYPE, use OPS as its
8501 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8503 static struct breakpoint *
8504 momentary_breakpoint_from_master (struct breakpoint *orig,
8506 const struct breakpoint_ops *ops,
8509 struct breakpoint *copy;
8511 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8512 copy->loc = allocate_bp_location (copy);
8513 set_breakpoint_location_function (copy->loc, 1);
8515 copy->loc->gdbarch = orig->loc->gdbarch;
8516 copy->loc->requested_address = orig->loc->requested_address;
8517 copy->loc->address = orig->loc->address;
8518 copy->loc->section = orig->loc->section;
8519 copy->loc->pspace = orig->loc->pspace;
8520 copy->loc->probe = orig->loc->probe;
8521 copy->loc->line_number = orig->loc->line_number;
8522 copy->loc->symtab = orig->loc->symtab;
8523 copy->loc->enabled = loc_enabled;
8524 copy->frame_id = orig->frame_id;
8525 copy->thread = orig->thread;
8526 copy->pspace = orig->pspace;
8528 copy->enable_state = bp_enabled;
8529 copy->disposition = disp_donttouch;
8530 copy->number = internal_breakpoint_number--;
8532 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8536 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8540 clone_momentary_breakpoint (struct breakpoint *orig)
8542 /* If there's nothing to clone, then return nothing. */
8546 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8550 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8553 struct symtab_and_line sal;
8555 sal = find_pc_line (pc, 0);
8557 sal.section = find_pc_overlay (pc);
8558 sal.explicit_pc = 1;
8560 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8564 /* Tell the user we have just set a breakpoint B. */
8567 mention (struct breakpoint *b)
8569 b->ops->print_mention (b);
8570 current_uiout->text ("\n");
8574 static int bp_loc_is_permanent (struct bp_location *loc);
8576 static struct bp_location *
8577 add_location_to_breakpoint (struct breakpoint *b,
8578 const struct symtab_and_line *sal)
8580 struct bp_location *loc, **tmp;
8581 CORE_ADDR adjusted_address;
8582 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8584 if (loc_gdbarch == NULL)
8585 loc_gdbarch = b->gdbarch;
8587 /* Adjust the breakpoint's address prior to allocating a location.
8588 Once we call allocate_bp_location(), that mostly uninitialized
8589 location will be placed on the location chain. Adjustment of the
8590 breakpoint may cause target_read_memory() to be called and we do
8591 not want its scan of the location chain to find a breakpoint and
8592 location that's only been partially initialized. */
8593 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8596 /* Sort the locations by their ADDRESS. */
8597 loc = allocate_bp_location (b);
8598 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8599 tmp = &((*tmp)->next))
8604 loc->requested_address = sal->pc;
8605 loc->address = adjusted_address;
8606 loc->pspace = sal->pspace;
8607 loc->probe.prob = sal->prob;
8608 loc->probe.objfile = sal->objfile;
8609 gdb_assert (loc->pspace != NULL);
8610 loc->section = sal->section;
8611 loc->gdbarch = loc_gdbarch;
8612 loc->line_number = sal->line;
8613 loc->symtab = sal->symtab;
8614 loc->symbol = sal->symbol;
8615 loc->msymbol = sal->msymbol;
8616 loc->objfile = sal->objfile;
8618 set_breakpoint_location_function (loc,
8619 sal->explicit_pc || sal->explicit_line);
8621 /* While by definition, permanent breakpoints are already present in the
8622 code, we don't mark the location as inserted. Normally one would expect
8623 that GDB could rely on that breakpoint instruction to stop the program,
8624 thus removing the need to insert its own breakpoint, except that executing
8625 the breakpoint instruction can kill the target instead of reporting a
8626 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8627 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8628 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8629 breakpoint be inserted normally results in QEMU knowing about the GDB
8630 breakpoint, and thus trap before the breakpoint instruction is executed.
8631 (If GDB later needs to continue execution past the permanent breakpoint,
8632 it manually increments the PC, thus avoiding executing the breakpoint
8634 if (bp_loc_is_permanent (loc))
8641 /* See breakpoint.h. */
8644 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
8648 const gdb_byte *bpoint;
8649 gdb_byte *target_mem;
8652 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
8654 /* Software breakpoints unsupported? */
8658 target_mem = (gdb_byte *) alloca (len);
8660 /* Enable the automatic memory restoration from breakpoints while
8661 we read the memory. Otherwise we could say about our temporary
8662 breakpoints they are permanent. */
8663 scoped_restore restore_memory
8664 = make_scoped_restore_show_memory_breakpoints (0);
8666 if (target_read_memory (address, target_mem, len) == 0
8667 && memcmp (target_mem, bpoint, len) == 0)
8673 /* Return 1 if LOC is pointing to a permanent breakpoint,
8674 return 0 otherwise. */
8677 bp_loc_is_permanent (struct bp_location *loc)
8679 gdb_assert (loc != NULL);
8681 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8682 attempt to read from the addresses the locations of these breakpoint types
8683 point to. program_breakpoint_here_p, below, will attempt to read
8685 if (!breakpoint_address_is_meaningful (loc->owner))
8688 scoped_restore_current_pspace_and_thread restore_pspace_thread;
8689 switch_to_program_space_and_thread (loc->pspace);
8690 return program_breakpoint_here_p (loc->gdbarch, loc->address);
8693 /* Build a command list for the dprintf corresponding to the current
8694 settings of the dprintf style options. */
8697 update_dprintf_command_list (struct breakpoint *b)
8699 char *dprintf_args = b->extra_string;
8700 char *printf_line = NULL;
8705 dprintf_args = skip_spaces (dprintf_args);
8707 /* Allow a comma, as it may have terminated a location, but don't
8709 if (*dprintf_args == ',')
8711 dprintf_args = skip_spaces (dprintf_args);
8713 if (*dprintf_args != '"')
8714 error (_("Bad format string, missing '\"'."));
8716 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8717 printf_line = xstrprintf ("printf %s", dprintf_args);
8718 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8720 if (!dprintf_function)
8721 error (_("No function supplied for dprintf call"));
8723 if (dprintf_channel && strlen (dprintf_channel) > 0)
8724 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8729 printf_line = xstrprintf ("call (void) %s (%s)",
8733 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8735 if (target_can_run_breakpoint_commands ())
8736 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8739 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8740 printf_line = xstrprintf ("printf %s", dprintf_args);
8744 internal_error (__FILE__, __LINE__,
8745 _("Invalid dprintf style."));
8747 gdb_assert (printf_line != NULL);
8749 /* Manufacture a printf sequence. */
8750 struct command_line *printf_cmd_line
8751 = new struct command_line (simple_control, printf_line);
8752 breakpoint_set_commands (b, counted_command_line (printf_cmd_line,
8753 command_lines_deleter ()));
8756 /* Update all dprintf commands, making their command lists reflect
8757 current style settings. */
8760 update_dprintf_commands (const char *args, int from_tty,
8761 struct cmd_list_element *c)
8763 struct breakpoint *b;
8767 if (b->type == bp_dprintf)
8768 update_dprintf_command_list (b);
8772 /* Create a breakpoint with SAL as location. Use LOCATION
8773 as a description of the location, and COND_STRING
8774 as condition expression. If LOCATION is NULL then create an
8775 "address location" from the address in the SAL. */
8778 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8779 gdb::array_view<const symtab_and_line> sals,
8780 event_location_up &&location,
8781 gdb::unique_xmalloc_ptr<char> filter,
8782 gdb::unique_xmalloc_ptr<char> cond_string,
8783 gdb::unique_xmalloc_ptr<char> extra_string,
8784 enum bptype type, enum bpdisp disposition,
8785 int thread, int task, int ignore_count,
8786 const struct breakpoint_ops *ops, int from_tty,
8787 int enabled, int internal, unsigned flags,
8788 int display_canonical)
8792 if (type == bp_hardware_breakpoint)
8794 int target_resources_ok;
8796 i = hw_breakpoint_used_count ();
8797 target_resources_ok =
8798 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8800 if (target_resources_ok == 0)
8801 error (_("No hardware breakpoint support in the target."));
8802 else if (target_resources_ok < 0)
8803 error (_("Hardware breakpoints used exceeds limit."));
8806 gdb_assert (!sals.empty ());
8808 for (const auto &sal : sals)
8810 struct bp_location *loc;
8814 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8816 loc_gdbarch = gdbarch;
8818 describe_other_breakpoints (loc_gdbarch,
8819 sal.pspace, sal.pc, sal.section, thread);
8822 if (&sal == &sals[0])
8824 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8828 b->cond_string = cond_string.release ();
8829 b->extra_string = extra_string.release ();
8830 b->ignore_count = ignore_count;
8831 b->enable_state = enabled ? bp_enabled : bp_disabled;
8832 b->disposition = disposition;
8834 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8835 b->loc->inserted = 1;
8837 if (type == bp_static_tracepoint)
8839 struct tracepoint *t = (struct tracepoint *) b;
8840 struct static_tracepoint_marker marker;
8842 if (strace_marker_p (b))
8844 /* We already know the marker exists, otherwise, we
8845 wouldn't see a sal for it. */
8847 = &event_location_to_string (b->location.get ())[3];
8850 p = skip_spaces (p);
8852 endp = skip_to_space (p);
8854 t->static_trace_marker_id.assign (p, endp - p);
8856 printf_filtered (_("Probed static tracepoint "
8858 t->static_trace_marker_id.c_str ());
8860 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8862 t->static_trace_marker_id = std::move (marker.str_id);
8864 printf_filtered (_("Probed static tracepoint "
8866 t->static_trace_marker_id.c_str ());
8869 warning (_("Couldn't determine the static "
8870 "tracepoint marker to probe"));
8877 loc = add_location_to_breakpoint (b, &sal);
8878 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8884 const char *arg = b->cond_string;
8886 loc->cond = parse_exp_1 (&arg, loc->address,
8887 block_for_pc (loc->address), 0);
8889 error (_("Garbage '%s' follows condition"), arg);
8892 /* Dynamic printf requires and uses additional arguments on the
8893 command line, otherwise it's an error. */
8894 if (type == bp_dprintf)
8896 if (b->extra_string)
8897 update_dprintf_command_list (b);
8899 error (_("Format string required"));
8901 else if (b->extra_string)
8902 error (_("Garbage '%s' at end of command"), b->extra_string);
8905 b->display_canonical = display_canonical;
8906 if (location != NULL)
8907 b->location = std::move (location);
8909 b->location = new_address_location (b->loc->address, NULL, 0);
8910 b->filter = filter.release ();
8914 create_breakpoint_sal (struct gdbarch *gdbarch,
8915 gdb::array_view<const symtab_and_line> sals,
8916 event_location_up &&location,
8917 gdb::unique_xmalloc_ptr<char> filter,
8918 gdb::unique_xmalloc_ptr<char> cond_string,
8919 gdb::unique_xmalloc_ptr<char> extra_string,
8920 enum bptype type, enum bpdisp disposition,
8921 int thread, int task, int ignore_count,
8922 const struct breakpoint_ops *ops, int from_tty,
8923 int enabled, int internal, unsigned flags,
8924 int display_canonical)
8926 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type);
8928 init_breakpoint_sal (b.get (), gdbarch,
8929 sals, std::move (location),
8931 std::move (cond_string),
8932 std::move (extra_string),
8934 thread, task, ignore_count,
8936 enabled, internal, flags,
8939 install_breakpoint (internal, std::move (b), 0);
8942 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8943 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8944 value. COND_STRING, if not NULL, specified the condition to be
8945 used for all breakpoints. Essentially the only case where
8946 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8947 function. In that case, it's still not possible to specify
8948 separate conditions for different overloaded functions, so
8949 we take just a single condition string.
8951 NOTE: If the function succeeds, the caller is expected to cleanup
8952 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8953 array contents). If the function fails (error() is called), the
8954 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8955 COND and SALS arrays and each of those arrays contents. */
8958 create_breakpoints_sal (struct gdbarch *gdbarch,
8959 struct linespec_result *canonical,
8960 gdb::unique_xmalloc_ptr<char> cond_string,
8961 gdb::unique_xmalloc_ptr<char> extra_string,
8962 enum bptype type, enum bpdisp disposition,
8963 int thread, int task, int ignore_count,
8964 const struct breakpoint_ops *ops, int from_tty,
8965 int enabled, int internal, unsigned flags)
8967 if (canonical->pre_expanded)
8968 gdb_assert (canonical->lsals.size () == 1);
8970 for (const auto &lsal : canonical->lsals)
8972 /* Note that 'location' can be NULL in the case of a plain
8973 'break', without arguments. */
8974 event_location_up location
8975 = (canonical->location != NULL
8976 ? copy_event_location (canonical->location.get ()) : NULL);
8977 gdb::unique_xmalloc_ptr<char> filter_string
8978 (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
8980 create_breakpoint_sal (gdbarch, lsal.sals,
8981 std::move (location),
8982 std::move (filter_string),
8983 std::move (cond_string),
8984 std::move (extra_string),
8986 thread, task, ignore_count, ops,
8987 from_tty, enabled, internal, flags,
8988 canonical->special_display);
8992 /* Parse LOCATION which is assumed to be a SAL specification possibly
8993 followed by conditionals. On return, SALS contains an array of SAL
8994 addresses found. LOCATION points to the end of the SAL (for
8995 linespec locations).
8997 The array and the line spec strings are allocated on the heap, it is
8998 the caller's responsibility to free them. */
9001 parse_breakpoint_sals (const struct event_location *location,
9002 struct linespec_result *canonical)
9004 struct symtab_and_line cursal;
9006 if (event_location_type (location) == LINESPEC_LOCATION)
9008 const char *spec = get_linespec_location (location)->spec_string;
9012 /* The last displayed codepoint, if it's valid, is our default
9013 breakpoint address. */
9014 if (last_displayed_sal_is_valid ())
9016 /* Set sal's pspace, pc, symtab, and line to the values
9017 corresponding to the last call to print_frame_info.
9018 Be sure to reinitialize LINE with NOTCURRENT == 0
9019 as the breakpoint line number is inappropriate otherwise.
9020 find_pc_line would adjust PC, re-set it back. */
9021 symtab_and_line sal = get_last_displayed_sal ();
9022 CORE_ADDR pc = sal.pc;
9024 sal = find_pc_line (pc, 0);
9026 /* "break" without arguments is equivalent to "break *PC"
9027 where PC is the last displayed codepoint's address. So
9028 make sure to set sal.explicit_pc to prevent GDB from
9029 trying to expand the list of sals to include all other
9030 instances with the same symtab and line. */
9032 sal.explicit_pc = 1;
9034 struct linespec_sals lsal;
9036 lsal.canonical = NULL;
9038 canonical->lsals.push_back (std::move (lsal));
9042 error (_("No default breakpoint address now."));
9046 /* Force almost all breakpoints to be in terms of the
9047 current_source_symtab (which is decode_line_1's default).
9048 This should produce the results we want almost all of the
9049 time while leaving default_breakpoint_* alone.
9051 ObjC: However, don't match an Objective-C method name which
9052 may have a '+' or '-' succeeded by a '['. */
9053 cursal = get_current_source_symtab_and_line ();
9054 if (last_displayed_sal_is_valid ())
9056 const char *spec = NULL;
9058 if (event_location_type (location) == LINESPEC_LOCATION)
9059 spec = get_linespec_location (location)->spec_string;
9063 && strchr ("+-", spec[0]) != NULL
9066 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9067 get_last_displayed_symtab (),
9068 get_last_displayed_line (),
9069 canonical, NULL, NULL);
9074 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9075 cursal.symtab, cursal.line, canonical, NULL, NULL);
9079 /* Convert each SAL into a real PC. Verify that the PC can be
9080 inserted as a breakpoint. If it can't throw an error. */
9083 breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
9085 for (auto &sal : sals)
9086 resolve_sal_pc (&sal);
9089 /* Fast tracepoints may have restrictions on valid locations. For
9090 instance, a fast tracepoint using a jump instead of a trap will
9091 likely have to overwrite more bytes than a trap would, and so can
9092 only be placed where the instruction is longer than the jump, or a
9093 multi-instruction sequence does not have a jump into the middle of
9097 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9098 gdb::array_view<const symtab_and_line> sals)
9100 for (const auto &sal : sals)
9102 struct gdbarch *sarch;
9104 sarch = get_sal_arch (sal);
9105 /* We fall back to GDBARCH if there is no architecture
9106 associated with SAL. */
9110 if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg))
9111 error (_("May not have a fast tracepoint at %s%s"),
9112 paddress (sarch, sal.pc), msg.c_str ());
9116 /* Given TOK, a string specification of condition and thread, as
9117 accepted by the 'break' command, extract the condition
9118 string and thread number and set *COND_STRING and *THREAD.
9119 PC identifies the context at which the condition should be parsed.
9120 If no condition is found, *COND_STRING is set to NULL.
9121 If no thread is found, *THREAD is set to -1. */
9124 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9125 char **cond_string, int *thread, int *task,
9128 *cond_string = NULL;
9135 const char *end_tok;
9137 const char *cond_start = NULL;
9138 const char *cond_end = NULL;
9140 tok = skip_spaces (tok);
9142 if ((*tok == '"' || *tok == ',') && rest)
9144 *rest = savestring (tok, strlen (tok));
9148 end_tok = skip_to_space (tok);
9150 toklen = end_tok - tok;
9152 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9154 tok = cond_start = end_tok + 1;
9155 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9157 *cond_string = savestring (cond_start, cond_end - cond_start);
9159 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9162 struct thread_info *thr;
9165 thr = parse_thread_id (tok, &tmptok);
9167 error (_("Junk after thread keyword."));
9168 *thread = thr->global_num;
9171 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9176 *task = strtol (tok, &tmptok, 0);
9178 error (_("Junk after task keyword."));
9179 if (!valid_task_id (*task))
9180 error (_("Unknown task %d."), *task);
9185 *rest = savestring (tok, strlen (tok));
9189 error (_("Junk at end of arguments."));
9193 /* Decode a static tracepoint marker spec. */
9195 static std::vector<symtab_and_line>
9196 decode_static_tracepoint_spec (const char **arg_p)
9198 const char *p = &(*arg_p)[3];
9201 p = skip_spaces (p);
9203 endp = skip_to_space (p);
9205 std::string marker_str (p, endp - p);
9207 std::vector<static_tracepoint_marker> markers
9208 = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
9209 if (markers.empty ())
9210 error (_("No known static tracepoint marker named %s"),
9211 marker_str.c_str ());
9213 std::vector<symtab_and_line> sals;
9214 sals.reserve (markers.size ());
9216 for (const static_tracepoint_marker &marker : markers)
9218 symtab_and_line sal = find_pc_line (marker.address, 0);
9219 sal.pc = marker.address;
9220 sals.push_back (sal);
9227 /* See breakpoint.h. */
9230 create_breakpoint (struct gdbarch *gdbarch,
9231 const struct event_location *location,
9232 const char *cond_string,
9233 int thread, const char *extra_string,
9235 int tempflag, enum bptype type_wanted,
9237 enum auto_boolean pending_break_support,
9238 const struct breakpoint_ops *ops,
9239 int from_tty, int enabled, int internal,
9242 struct linespec_result canonical;
9245 int prev_bkpt_count = breakpoint_count;
9247 gdb_assert (ops != NULL);
9249 /* If extra_string isn't useful, set it to NULL. */
9250 if (extra_string != NULL && *extra_string == '\0')
9251 extra_string = NULL;
9255 ops->create_sals_from_location (location, &canonical, type_wanted);
9257 CATCH (e, RETURN_MASK_ERROR)
9259 /* If caller is interested in rc value from parse, set
9261 if (e.error == NOT_FOUND_ERROR)
9263 /* If pending breakpoint support is turned off, throw
9266 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9267 throw_exception (e);
9269 exception_print (gdb_stderr, e);
9271 /* If pending breakpoint support is auto query and the user
9272 selects no, then simply return the error code. */
9273 if (pending_break_support == AUTO_BOOLEAN_AUTO
9274 && !nquery (_("Make %s pending on future shared library load? "),
9275 bptype_string (type_wanted)))
9278 /* At this point, either the user was queried about setting
9279 a pending breakpoint and selected yes, or pending
9280 breakpoint behavior is on and thus a pending breakpoint
9281 is defaulted on behalf of the user. */
9285 throw_exception (e);
9289 if (!pending && canonical.lsals.empty ())
9292 /* Resolve all line numbers to PC's and verify that the addresses
9293 are ok for the target. */
9296 for (auto &lsal : canonical.lsals)
9297 breakpoint_sals_to_pc (lsal.sals);
9300 /* Fast tracepoints may have additional restrictions on location. */
9301 if (!pending && type_wanted == bp_fast_tracepoint)
9303 for (const auto &lsal : canonical.lsals)
9304 check_fast_tracepoint_sals (gdbarch, lsal.sals);
9307 /* Verify that condition can be parsed, before setting any
9308 breakpoints. Allocate a separate condition expression for each
9312 gdb::unique_xmalloc_ptr<char> cond_string_copy;
9313 gdb::unique_xmalloc_ptr<char> extra_string_copy;
9320 const linespec_sals &lsal = canonical.lsals[0];
9322 /* Here we only parse 'arg' to separate condition
9323 from thread number, so parsing in context of first
9324 sal is OK. When setting the breakpoint we'll
9325 re-parse it in context of each sal. */
9327 find_condition_and_thread (extra_string, lsal.sals[0].pc,
9328 &cond, &thread, &task, &rest);
9329 cond_string_copy.reset (cond);
9330 extra_string_copy.reset (rest);
9334 if (type_wanted != bp_dprintf
9335 && extra_string != NULL && *extra_string != '\0')
9336 error (_("Garbage '%s' at end of location"), extra_string);
9338 /* Create a private copy of condition string. */
9340 cond_string_copy.reset (xstrdup (cond_string));
9341 /* Create a private copy of any extra string. */
9343 extra_string_copy.reset (xstrdup (extra_string));
9346 ops->create_breakpoints_sal (gdbarch, &canonical,
9347 std::move (cond_string_copy),
9348 std::move (extra_string_copy),
9350 tempflag ? disp_del : disp_donttouch,
9351 thread, task, ignore_count, ops,
9352 from_tty, enabled, internal, flags);
9356 std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted);
9358 init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops);
9359 b->location = copy_event_location (location);
9362 b->cond_string = NULL;
9365 /* Create a private copy of condition string. */
9366 b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL;
9370 /* Create a private copy of any extra string. */
9371 b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL;
9372 b->ignore_count = ignore_count;
9373 b->disposition = tempflag ? disp_del : disp_donttouch;
9374 b->condition_not_parsed = 1;
9375 b->enable_state = enabled ? bp_enabled : bp_disabled;
9376 if ((type_wanted != bp_breakpoint
9377 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9378 b->pspace = current_program_space;
9380 install_breakpoint (internal, std::move (b), 0);
9383 if (canonical.lsals.size () > 1)
9385 warning (_("Multiple breakpoints were set.\nUse the "
9386 "\"delete\" command to delete unwanted breakpoints."));
9387 prev_breakpoint_count = prev_bkpt_count;
9390 update_global_location_list (UGLL_MAY_INSERT);
9395 /* Set a breakpoint.
9396 ARG is a string describing breakpoint address,
9397 condition, and thread.
9398 FLAG specifies if a breakpoint is hardware on,
9399 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9403 break_command_1 (const char *arg, int flag, int from_tty)
9405 int tempflag = flag & BP_TEMPFLAG;
9406 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9407 ? bp_hardware_breakpoint
9409 struct breakpoint_ops *ops;
9411 event_location_up location = string_to_event_location (&arg, current_language);
9413 /* Matching breakpoints on probes. */
9414 if (location != NULL
9415 && event_location_type (location.get ()) == PROBE_LOCATION)
9416 ops = &bkpt_probe_breakpoint_ops;
9418 ops = &bkpt_breakpoint_ops;
9420 create_breakpoint (get_current_arch (),
9422 NULL, 0, arg, 1 /* parse arg */,
9423 tempflag, type_wanted,
9424 0 /* Ignore count */,
9425 pending_break_support,
9433 /* Helper function for break_command_1 and disassemble_command. */
9436 resolve_sal_pc (struct symtab_and_line *sal)
9440 if (sal->pc == 0 && sal->symtab != NULL)
9442 if (!find_line_pc (sal->symtab, sal->line, &pc))
9443 error (_("No line %d in file \"%s\"."),
9444 sal->line, symtab_to_filename_for_display (sal->symtab));
9447 /* If this SAL corresponds to a breakpoint inserted using a line
9448 number, then skip the function prologue if necessary. */
9449 if (sal->explicit_line)
9450 skip_prologue_sal (sal);
9453 if (sal->section == 0 && sal->symtab != NULL)
9455 const struct blockvector *bv;
9456 const struct block *b;
9459 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9460 SYMTAB_COMPUNIT (sal->symtab));
9463 sym = block_linkage_function (b);
9466 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
9467 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
9472 /* It really is worthwhile to have the section, so we'll
9473 just have to look harder. This case can be executed
9474 if we have line numbers but no functions (as can
9475 happen in assembly source). */
9477 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9478 switch_to_program_space_and_thread (sal->pspace);
9480 bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
9482 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9489 break_command (const char *arg, int from_tty)
9491 break_command_1 (arg, 0, from_tty);
9495 tbreak_command (const char *arg, int from_tty)
9497 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9501 hbreak_command (const char *arg, int from_tty)
9503 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9507 thbreak_command (const char *arg, int from_tty)
9509 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9513 stop_command (const char *arg, int from_tty)
9515 printf_filtered (_("Specify the type of breakpoint to set.\n\
9516 Usage: stop in <function | address>\n\
9517 stop at <line>\n"));
9521 stopin_command (const char *arg, int from_tty)
9525 if (arg == (char *) NULL)
9527 else if (*arg != '*')
9529 const char *argptr = arg;
9532 /* Look for a ':'. If this is a line number specification, then
9533 say it is bad, otherwise, it should be an address or
9534 function/method name. */
9535 while (*argptr && !hasColon)
9537 hasColon = (*argptr == ':');
9542 badInput = (*argptr != ':'); /* Not a class::method */
9544 badInput = isdigit (*arg); /* a simple line number */
9548 printf_filtered (_("Usage: stop in <function | address>\n"));
9550 break_command_1 (arg, 0, from_tty);
9554 stopat_command (const char *arg, int from_tty)
9558 if (arg == (char *) NULL || *arg == '*') /* no line number */
9562 const char *argptr = arg;
9565 /* Look for a ':'. If there is a '::' then get out, otherwise
9566 it is probably a line number. */
9567 while (*argptr && !hasColon)
9569 hasColon = (*argptr == ':');
9574 badInput = (*argptr == ':'); /* we have class::method */
9576 badInput = !isdigit (*arg); /* not a line number */
9580 printf_filtered (_("Usage: stop at LINE\n"));
9582 break_command_1 (arg, 0, from_tty);
9585 /* The dynamic printf command is mostly like a regular breakpoint, but
9586 with a prewired command list consisting of a single output command,
9587 built from extra arguments supplied on the dprintf command
9591 dprintf_command (const char *arg, int from_tty)
9593 event_location_up location = string_to_event_location (&arg, current_language);
9595 /* If non-NULL, ARG should have been advanced past the location;
9596 the next character must be ','. */
9599 if (arg[0] != ',' || arg[1] == '\0')
9600 error (_("Format string required"));
9603 /* Skip the comma. */
9608 create_breakpoint (get_current_arch (),
9610 NULL, 0, arg, 1 /* parse arg */,
9612 0 /* Ignore count */,
9613 pending_break_support,
9614 &dprintf_breakpoint_ops,
9622 agent_printf_command (const char *arg, int from_tty)
9624 error (_("May only run agent-printf on the target"));
9627 /* Implement the "breakpoint_hit" breakpoint_ops method for
9628 ranged breakpoints. */
9631 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9632 const address_space *aspace,
9634 const struct target_waitstatus *ws)
9636 if (ws->kind != TARGET_WAITKIND_STOPPED
9637 || ws->value.sig != GDB_SIGNAL_TRAP)
9640 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9641 bl->length, aspace, bp_addr);
9644 /* Implement the "resources_needed" breakpoint_ops method for
9645 ranged breakpoints. */
9648 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9650 return target_ranged_break_num_registers ();
9653 /* Implement the "print_it" breakpoint_ops method for
9654 ranged breakpoints. */
9656 static enum print_stop_action
9657 print_it_ranged_breakpoint (bpstat bs)
9659 struct breakpoint *b = bs->breakpoint_at;
9660 struct bp_location *bl = b->loc;
9661 struct ui_out *uiout = current_uiout;
9663 gdb_assert (b->type == bp_hardware_breakpoint);
9665 /* Ranged breakpoints have only one location. */
9666 gdb_assert (bl && bl->next == NULL);
9668 annotate_breakpoint (b->number);
9670 maybe_print_thread_hit_breakpoint (uiout);
9672 if (b->disposition == disp_del)
9673 uiout->text ("Temporary ranged breakpoint ");
9675 uiout->text ("Ranged breakpoint ");
9676 if (uiout->is_mi_like_p ())
9678 uiout->field_string ("reason",
9679 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9680 uiout->field_string ("disp", bpdisp_text (b->disposition));
9682 uiout->field_int ("bkptno", b->number);
9685 return PRINT_SRC_AND_LOC;
9688 /* Implement the "print_one" breakpoint_ops method for
9689 ranged breakpoints. */
9692 print_one_ranged_breakpoint (struct breakpoint *b,
9693 struct bp_location **last_loc)
9695 struct bp_location *bl = b->loc;
9696 struct value_print_options opts;
9697 struct ui_out *uiout = current_uiout;
9699 /* Ranged breakpoints have only one location. */
9700 gdb_assert (bl && bl->next == NULL);
9702 get_user_print_options (&opts);
9704 if (opts.addressprint)
9705 /* We don't print the address range here, it will be printed later
9706 by print_one_detail_ranged_breakpoint. */
9707 uiout->field_skip ("addr");
9709 print_breakpoint_location (b, bl);
9713 /* Implement the "print_one_detail" breakpoint_ops method for
9714 ranged breakpoints. */
9717 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9718 struct ui_out *uiout)
9720 CORE_ADDR address_start, address_end;
9721 struct bp_location *bl = b->loc;
9726 address_start = bl->address;
9727 address_end = address_start + bl->length - 1;
9729 uiout->text ("\taddress range: ");
9730 stb.printf ("[%s, %s]",
9731 print_core_address (bl->gdbarch, address_start),
9732 print_core_address (bl->gdbarch, address_end));
9733 uiout->field_stream ("addr", stb);
9737 /* Implement the "print_mention" breakpoint_ops method for
9738 ranged breakpoints. */
9741 print_mention_ranged_breakpoint (struct breakpoint *b)
9743 struct bp_location *bl = b->loc;
9744 struct ui_out *uiout = current_uiout;
9747 gdb_assert (b->type == bp_hardware_breakpoint);
9749 uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9750 b->number, paddress (bl->gdbarch, bl->address),
9751 paddress (bl->gdbarch, bl->address + bl->length - 1));
9754 /* Implement the "print_recreate" breakpoint_ops method for
9755 ranged breakpoints. */
9758 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9760 fprintf_unfiltered (fp, "break-range %s, %s",
9761 event_location_to_string (b->location.get ()),
9762 event_location_to_string (b->location_range_end.get ()));
9763 print_recreate_thread (b, fp);
9766 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9768 static struct breakpoint_ops ranged_breakpoint_ops;
9770 /* Find the address where the end of the breakpoint range should be
9771 placed, given the SAL of the end of the range. This is so that if
9772 the user provides a line number, the end of the range is set to the
9773 last instruction of the given line. */
9776 find_breakpoint_range_end (struct symtab_and_line sal)
9780 /* If the user provided a PC value, use it. Otherwise,
9781 find the address of the end of the given location. */
9782 if (sal.explicit_pc)
9789 ret = find_line_pc_range (sal, &start, &end);
9791 error (_("Could not find location of the end of the range."));
9793 /* find_line_pc_range returns the start of the next line. */
9800 /* Implement the "break-range" CLI command. */
9803 break_range_command (const char *arg, int from_tty)
9805 const char *arg_start;
9806 struct linespec_result canonical_start, canonical_end;
9807 int bp_count, can_use_bp, length;
9809 struct breakpoint *b;
9811 /* We don't support software ranged breakpoints. */
9812 if (target_ranged_break_num_registers () < 0)
9813 error (_("This target does not support hardware ranged breakpoints."));
9815 bp_count = hw_breakpoint_used_count ();
9816 bp_count += target_ranged_break_num_registers ();
9817 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9820 error (_("Hardware breakpoints used exceeds limit."));
9822 arg = skip_spaces (arg);
9823 if (arg == NULL || arg[0] == '\0')
9824 error(_("No address range specified."));
9827 event_location_up start_location = string_to_event_location (&arg,
9829 parse_breakpoint_sals (start_location.get (), &canonical_start);
9832 error (_("Too few arguments."));
9833 else if (canonical_start.lsals.empty ())
9834 error (_("Could not find location of the beginning of the range."));
9836 const linespec_sals &lsal_start = canonical_start.lsals[0];
9838 if (canonical_start.lsals.size () > 1
9839 || lsal_start.sals.size () != 1)
9840 error (_("Cannot create a ranged breakpoint with multiple locations."));
9842 const symtab_and_line &sal_start = lsal_start.sals[0];
9843 std::string addr_string_start (arg_start, arg - arg_start);
9845 arg++; /* Skip the comma. */
9846 arg = skip_spaces (arg);
9848 /* Parse the end location. */
9852 /* We call decode_line_full directly here instead of using
9853 parse_breakpoint_sals because we need to specify the start location's
9854 symtab and line as the default symtab and line for the end of the
9855 range. This makes it possible to have ranges like "foo.c:27, +14",
9856 where +14 means 14 lines from the start location. */
9857 event_location_up end_location = string_to_event_location (&arg,
9859 decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
9860 sal_start.symtab, sal_start.line,
9861 &canonical_end, NULL, NULL);
9863 if (canonical_end.lsals.empty ())
9864 error (_("Could not find location of the end of the range."));
9866 const linespec_sals &lsal_end = canonical_end.lsals[0];
9867 if (canonical_end.lsals.size () > 1
9868 || lsal_end.sals.size () != 1)
9869 error (_("Cannot create a ranged breakpoint with multiple locations."));
9871 const symtab_and_line &sal_end = lsal_end.sals[0];
9873 end = find_breakpoint_range_end (sal_end);
9874 if (sal_start.pc > end)
9875 error (_("Invalid address range, end precedes start."));
9877 length = end - sal_start.pc + 1;
9879 /* Length overflowed. */
9880 error (_("Address range too large."));
9881 else if (length == 1)
9883 /* This range is simple enough to be handled by
9884 the `hbreak' command. */
9885 hbreak_command (&addr_string_start[0], 1);
9890 /* Now set up the breakpoint. */
9891 b = set_raw_breakpoint (get_current_arch (), sal_start,
9892 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9893 set_breakpoint_count (breakpoint_count + 1);
9894 b->number = breakpoint_count;
9895 b->disposition = disp_donttouch;
9896 b->location = std::move (start_location);
9897 b->location_range_end = std::move (end_location);
9898 b->loc->length = length;
9901 gdb::observers::breakpoint_created.notify (b);
9902 update_global_location_list (UGLL_MAY_INSERT);
9905 /* Return non-zero if EXP is verified as constant. Returned zero
9906 means EXP is variable. Also the constant detection may fail for
9907 some constant expressions and in such case still falsely return
9911 watchpoint_exp_is_const (const struct expression *exp)
9919 /* We are only interested in the descriptor of each element. */
9920 operator_length (exp, i, &oplenp, &argsp);
9923 switch (exp->elts[i].opcode)
9933 case BINOP_LOGICAL_AND:
9934 case BINOP_LOGICAL_OR:
9935 case BINOP_BITWISE_AND:
9936 case BINOP_BITWISE_IOR:
9937 case BINOP_BITWISE_XOR:
9939 case BINOP_NOTEQUAL:
9965 case OP_OBJC_NSSTRING:
9968 case UNOP_LOGICAL_NOT:
9969 case UNOP_COMPLEMENT:
9974 case UNOP_CAST_TYPE:
9975 case UNOP_REINTERPRET_CAST:
9976 case UNOP_DYNAMIC_CAST:
9977 /* Unary, binary and ternary operators: We have to check
9978 their operands. If they are constant, then so is the
9979 result of that operation. For instance, if A and B are
9980 determined to be constants, then so is "A + B".
9982 UNOP_IND is one exception to the rule above, because the
9983 value of *ADDR is not necessarily a constant, even when
9988 /* Check whether the associated symbol is a constant.
9990 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9991 possible that a buggy compiler could mark a variable as
9992 constant even when it is not, and TYPE_CONST would return
9993 true in this case, while SYMBOL_CLASS wouldn't.
9995 We also have to check for function symbols because they
9996 are always constant. */
9998 struct symbol *s = exp->elts[i + 2].symbol;
10000 if (SYMBOL_CLASS (s) != LOC_BLOCK
10001 && SYMBOL_CLASS (s) != LOC_CONST
10002 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10007 /* The default action is to return 0 because we are using
10008 the optimistic approach here: If we don't know something,
10009 then it is not a constant. */
10018 /* Watchpoint destructor. */
10020 watchpoint::~watchpoint ()
10022 xfree (this->exp_string);
10023 xfree (this->exp_string_reparse);
10026 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10029 re_set_watchpoint (struct breakpoint *b)
10031 struct watchpoint *w = (struct watchpoint *) b;
10033 /* Watchpoint can be either on expression using entirely global
10034 variables, or it can be on local variables.
10036 Watchpoints of the first kind are never auto-deleted, and even
10037 persist across program restarts. Since they can use variables
10038 from shared libraries, we need to reparse expression as libraries
10039 are loaded and unloaded.
10041 Watchpoints on local variables can also change meaning as result
10042 of solib event. For example, if a watchpoint uses both a local
10043 and a global variables in expression, it's a local watchpoint,
10044 but unloading of a shared library will make the expression
10045 invalid. This is not a very common use case, but we still
10046 re-evaluate expression, to avoid surprises to the user.
10048 Note that for local watchpoints, we re-evaluate it only if
10049 watchpoints frame id is still valid. If it's not, it means the
10050 watchpoint is out of scope and will be deleted soon. In fact,
10051 I'm not sure we'll ever be called in this case.
10053 If a local watchpoint's frame id is still valid, then
10054 w->exp_valid_block is likewise valid, and we can safely use it.
10056 Don't do anything about disabled watchpoints, since they will be
10057 reevaluated again when enabled. */
10058 update_watchpoint (w, 1 /* reparse */);
10061 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10064 insert_watchpoint (struct bp_location *bl)
10066 struct watchpoint *w = (struct watchpoint *) bl->owner;
10067 int length = w->exact ? 1 : bl->length;
10069 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10070 w->cond_exp.get ());
10073 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10076 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10078 struct watchpoint *w = (struct watchpoint *) bl->owner;
10079 int length = w->exact ? 1 : bl->length;
10081 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10082 w->cond_exp.get ());
10086 breakpoint_hit_watchpoint (const struct bp_location *bl,
10087 const address_space *aspace, CORE_ADDR bp_addr,
10088 const struct target_waitstatus *ws)
10090 struct breakpoint *b = bl->owner;
10091 struct watchpoint *w = (struct watchpoint *) b;
10093 /* Continuable hardware watchpoints are treated as non-existent if the
10094 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10095 some data address). Otherwise gdb won't stop on a break instruction
10096 in the code (not from a breakpoint) when a hardware watchpoint has
10097 been defined. Also skip watchpoints which we know did not trigger
10098 (did not match the data address). */
10099 if (is_hardware_watchpoint (b)
10100 && w->watchpoint_triggered == watch_triggered_no)
10107 check_status_watchpoint (bpstat bs)
10109 gdb_assert (is_watchpoint (bs->breakpoint_at));
10111 bpstat_check_watchpoint (bs);
10114 /* Implement the "resources_needed" breakpoint_ops method for
10115 hardware watchpoints. */
10118 resources_needed_watchpoint (const struct bp_location *bl)
10120 struct watchpoint *w = (struct watchpoint *) bl->owner;
10121 int length = w->exact? 1 : bl->length;
10123 return target_region_ok_for_hw_watchpoint (bl->address, length);
10126 /* Implement the "works_in_software_mode" breakpoint_ops method for
10127 hardware watchpoints. */
10130 works_in_software_mode_watchpoint (const struct breakpoint *b)
10132 /* Read and access watchpoints only work with hardware support. */
10133 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10136 static enum print_stop_action
10137 print_it_watchpoint (bpstat bs)
10139 struct breakpoint *b;
10140 enum print_stop_action result;
10141 struct watchpoint *w;
10142 struct ui_out *uiout = current_uiout;
10144 gdb_assert (bs->bp_location_at != NULL);
10146 b = bs->breakpoint_at;
10147 w = (struct watchpoint *) b;
10149 annotate_watchpoint (b->number);
10150 maybe_print_thread_hit_breakpoint (uiout);
10154 gdb::optional<ui_out_emit_tuple> tuple_emitter;
10157 case bp_watchpoint:
10158 case bp_hardware_watchpoint:
10159 if (uiout->is_mi_like_p ())
10160 uiout->field_string
10161 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10163 tuple_emitter.emplace (uiout, "value");
10164 uiout->text ("\nOld value = ");
10165 watchpoint_value_print (bs->old_val.get (), &stb);
10166 uiout->field_stream ("old", stb);
10167 uiout->text ("\nNew value = ");
10168 watchpoint_value_print (w->val.get (), &stb);
10169 uiout->field_stream ("new", stb);
10170 uiout->text ("\n");
10171 /* More than one watchpoint may have been triggered. */
10172 result = PRINT_UNKNOWN;
10175 case bp_read_watchpoint:
10176 if (uiout->is_mi_like_p ())
10177 uiout->field_string
10178 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10180 tuple_emitter.emplace (uiout, "value");
10181 uiout->text ("\nValue = ");
10182 watchpoint_value_print (w->val.get (), &stb);
10183 uiout->field_stream ("value", stb);
10184 uiout->text ("\n");
10185 result = PRINT_UNKNOWN;
10188 case bp_access_watchpoint:
10189 if (bs->old_val != NULL)
10191 if (uiout->is_mi_like_p ())
10192 uiout->field_string
10194 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10196 tuple_emitter.emplace (uiout, "value");
10197 uiout->text ("\nOld value = ");
10198 watchpoint_value_print (bs->old_val.get (), &stb);
10199 uiout->field_stream ("old", stb);
10200 uiout->text ("\nNew value = ");
10205 if (uiout->is_mi_like_p ())
10206 uiout->field_string
10208 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10209 tuple_emitter.emplace (uiout, "value");
10210 uiout->text ("\nValue = ");
10212 watchpoint_value_print (w->val.get (), &stb);
10213 uiout->field_stream ("new", stb);
10214 uiout->text ("\n");
10215 result = PRINT_UNKNOWN;
10218 result = PRINT_UNKNOWN;
10224 /* Implement the "print_mention" breakpoint_ops method for hardware
10228 print_mention_watchpoint (struct breakpoint *b)
10230 struct watchpoint *w = (struct watchpoint *) b;
10231 struct ui_out *uiout = current_uiout;
10232 const char *tuple_name;
10236 case bp_watchpoint:
10237 uiout->text ("Watchpoint ");
10238 tuple_name = "wpt";
10240 case bp_hardware_watchpoint:
10241 uiout->text ("Hardware watchpoint ");
10242 tuple_name = "wpt";
10244 case bp_read_watchpoint:
10245 uiout->text ("Hardware read watchpoint ");
10246 tuple_name = "hw-rwpt";
10248 case bp_access_watchpoint:
10249 uiout->text ("Hardware access (read/write) watchpoint ");
10250 tuple_name = "hw-awpt";
10253 internal_error (__FILE__, __LINE__,
10254 _("Invalid hardware watchpoint type."));
10257 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10258 uiout->field_int ("number", b->number);
10259 uiout->text (": ");
10260 uiout->field_string ("exp", w->exp_string);
10263 /* Implement the "print_recreate" breakpoint_ops method for
10267 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10269 struct watchpoint *w = (struct watchpoint *) b;
10273 case bp_watchpoint:
10274 case bp_hardware_watchpoint:
10275 fprintf_unfiltered (fp, "watch");
10277 case bp_read_watchpoint:
10278 fprintf_unfiltered (fp, "rwatch");
10280 case bp_access_watchpoint:
10281 fprintf_unfiltered (fp, "awatch");
10284 internal_error (__FILE__, __LINE__,
10285 _("Invalid watchpoint type."));
10288 fprintf_unfiltered (fp, " %s", w->exp_string);
10289 print_recreate_thread (b, fp);
10292 /* Implement the "explains_signal" breakpoint_ops method for
10296 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10298 /* A software watchpoint cannot cause a signal other than
10299 GDB_SIGNAL_TRAP. */
10300 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10306 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10308 static struct breakpoint_ops watchpoint_breakpoint_ops;
10310 /* Implement the "insert" breakpoint_ops method for
10311 masked hardware watchpoints. */
10314 insert_masked_watchpoint (struct bp_location *bl)
10316 struct watchpoint *w = (struct watchpoint *) bl->owner;
10318 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10319 bl->watchpoint_type);
10322 /* Implement the "remove" breakpoint_ops method for
10323 masked hardware watchpoints. */
10326 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10328 struct watchpoint *w = (struct watchpoint *) bl->owner;
10330 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10331 bl->watchpoint_type);
10334 /* Implement the "resources_needed" breakpoint_ops method for
10335 masked hardware watchpoints. */
10338 resources_needed_masked_watchpoint (const struct bp_location *bl)
10340 struct watchpoint *w = (struct watchpoint *) bl->owner;
10342 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10345 /* Implement the "works_in_software_mode" breakpoint_ops method for
10346 masked hardware watchpoints. */
10349 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10354 /* Implement the "print_it" breakpoint_ops method for
10355 masked hardware watchpoints. */
10357 static enum print_stop_action
10358 print_it_masked_watchpoint (bpstat bs)
10360 struct breakpoint *b = bs->breakpoint_at;
10361 struct ui_out *uiout = current_uiout;
10363 /* Masked watchpoints have only one location. */
10364 gdb_assert (b->loc && b->loc->next == NULL);
10366 annotate_watchpoint (b->number);
10367 maybe_print_thread_hit_breakpoint (uiout);
10371 case bp_hardware_watchpoint:
10372 if (uiout->is_mi_like_p ())
10373 uiout->field_string
10374 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10377 case bp_read_watchpoint:
10378 if (uiout->is_mi_like_p ())
10379 uiout->field_string
10380 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10383 case bp_access_watchpoint:
10384 if (uiout->is_mi_like_p ())
10385 uiout->field_string
10387 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10390 internal_error (__FILE__, __LINE__,
10391 _("Invalid hardware watchpoint type."));
10395 uiout->text (_("\n\
10396 Check the underlying instruction at PC for the memory\n\
10397 address and value which triggered this watchpoint.\n"));
10398 uiout->text ("\n");
10400 /* More than one watchpoint may have been triggered. */
10401 return PRINT_UNKNOWN;
10404 /* Implement the "print_one_detail" breakpoint_ops method for
10405 masked hardware watchpoints. */
10408 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10409 struct ui_out *uiout)
10411 struct watchpoint *w = (struct watchpoint *) b;
10413 /* Masked watchpoints have only one location. */
10414 gdb_assert (b->loc && b->loc->next == NULL);
10416 uiout->text ("\tmask ");
10417 uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
10418 uiout->text ("\n");
10421 /* Implement the "print_mention" breakpoint_ops method for
10422 masked hardware watchpoints. */
10425 print_mention_masked_watchpoint (struct breakpoint *b)
10427 struct watchpoint *w = (struct watchpoint *) b;
10428 struct ui_out *uiout = current_uiout;
10429 const char *tuple_name;
10433 case bp_hardware_watchpoint:
10434 uiout->text ("Masked hardware watchpoint ");
10435 tuple_name = "wpt";
10437 case bp_read_watchpoint:
10438 uiout->text ("Masked hardware read watchpoint ");
10439 tuple_name = "hw-rwpt";
10441 case bp_access_watchpoint:
10442 uiout->text ("Masked hardware access (read/write) watchpoint ");
10443 tuple_name = "hw-awpt";
10446 internal_error (__FILE__, __LINE__,
10447 _("Invalid hardware watchpoint type."));
10450 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10451 uiout->field_int ("number", b->number);
10452 uiout->text (": ");
10453 uiout->field_string ("exp", w->exp_string);
10456 /* Implement the "print_recreate" breakpoint_ops method for
10457 masked hardware watchpoints. */
10460 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10462 struct watchpoint *w = (struct watchpoint *) b;
10467 case bp_hardware_watchpoint:
10468 fprintf_unfiltered (fp, "watch");
10470 case bp_read_watchpoint:
10471 fprintf_unfiltered (fp, "rwatch");
10473 case bp_access_watchpoint:
10474 fprintf_unfiltered (fp, "awatch");
10477 internal_error (__FILE__, __LINE__,
10478 _("Invalid hardware watchpoint type."));
10481 sprintf_vma (tmp, w->hw_wp_mask);
10482 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10483 print_recreate_thread (b, fp);
10486 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10488 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10490 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10493 is_masked_watchpoint (const struct breakpoint *b)
10495 return b->ops == &masked_watchpoint_breakpoint_ops;
10498 /* accessflag: hw_write: watch write,
10499 hw_read: watch read,
10500 hw_access: watch access (read or write) */
10502 watch_command_1 (const char *arg, int accessflag, int from_tty,
10503 int just_location, int internal)
10505 struct breakpoint *scope_breakpoint = NULL;
10506 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10507 struct value *result;
10508 int saved_bitpos = 0, saved_bitsize = 0;
10509 const char *exp_start = NULL;
10510 const char *exp_end = NULL;
10511 const char *tok, *end_tok;
10513 const char *cond_start = NULL;
10514 const char *cond_end = NULL;
10515 enum bptype bp_type;
10518 /* Flag to indicate whether we are going to use masks for
10519 the hardware watchpoint. */
10521 CORE_ADDR mask = 0;
10523 /* Make sure that we actually have parameters to parse. */
10524 if (arg != NULL && arg[0] != '\0')
10526 const char *value_start;
10528 exp_end = arg + strlen (arg);
10530 /* Look for "parameter value" pairs at the end
10531 of the arguments string. */
10532 for (tok = exp_end - 1; tok > arg; tok--)
10534 /* Skip whitespace at the end of the argument list. */
10535 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10538 /* Find the beginning of the last token.
10539 This is the value of the parameter. */
10540 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10542 value_start = tok + 1;
10544 /* Skip whitespace. */
10545 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10550 /* Find the beginning of the second to last token.
10551 This is the parameter itself. */
10552 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10555 toklen = end_tok - tok + 1;
10557 if (toklen == 6 && startswith (tok, "thread"))
10559 struct thread_info *thr;
10560 /* At this point we've found a "thread" token, which means
10561 the user is trying to set a watchpoint that triggers
10562 only in a specific thread. */
10566 error(_("You can specify only one thread."));
10568 /* Extract the thread ID from the next token. */
10569 thr = parse_thread_id (value_start, &endp);
10571 /* Check if the user provided a valid thread ID. */
10572 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10573 invalid_thread_id_error (value_start);
10575 thread = thr->global_num;
10577 else if (toklen == 4 && startswith (tok, "mask"))
10579 /* We've found a "mask" token, which means the user wants to
10580 create a hardware watchpoint that is going to have the mask
10582 struct value *mask_value, *mark;
10585 error(_("You can specify only one mask."));
10587 use_mask = just_location = 1;
10589 mark = value_mark ();
10590 mask_value = parse_to_comma_and_eval (&value_start);
10591 mask = value_as_address (mask_value);
10592 value_free_to_mark (mark);
10595 /* We didn't recognize what we found. We should stop here. */
10598 /* Truncate the string and get rid of the "parameter value" pair before
10599 the arguments string is parsed by the parse_exp_1 function. */
10606 /* Parse the rest of the arguments. From here on out, everything
10607 is in terms of a newly allocated string instead of the original
10609 std::string expression (arg, exp_end - arg);
10610 exp_start = arg = expression.c_str ();
10611 innermost_block_tracker tracker;
10612 expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
10614 /* Remove trailing whitespace from the expression before saving it.
10615 This makes the eventual display of the expression string a bit
10617 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10620 /* Checking if the expression is not constant. */
10621 if (watchpoint_exp_is_const (exp.get ()))
10625 len = exp_end - exp_start;
10626 while (len > 0 && isspace (exp_start[len - 1]))
10628 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10631 exp_valid_block = tracker.block ();
10632 struct value *mark = value_mark ();
10633 struct value *val_as_value = nullptr;
10634 fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL,
10637 if (val_as_value != NULL && just_location)
10639 saved_bitpos = value_bitpos (val_as_value);
10640 saved_bitsize = value_bitsize (val_as_value);
10648 exp_valid_block = NULL;
10649 val = release_value (value_addr (result));
10650 value_free_to_mark (mark);
10654 ret = target_masked_watch_num_registers (value_as_address (val.get ()),
10657 error (_("This target does not support masked watchpoints."));
10658 else if (ret == -2)
10659 error (_("Invalid mask or memory region."));
10662 else if (val_as_value != NULL)
10663 val = release_value (val_as_value);
10665 tok = skip_spaces (arg);
10666 end_tok = skip_to_space (tok);
10668 toklen = end_tok - tok;
10669 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10671 tok = cond_start = end_tok + 1;
10672 innermost_block_tracker if_tracker;
10673 parse_exp_1 (&tok, 0, 0, 0, &if_tracker);
10675 /* The watchpoint expression may not be local, but the condition
10676 may still be. E.g.: `watch global if local > 0'. */
10677 cond_exp_valid_block = if_tracker.block ();
10682 error (_("Junk at end of command."));
10684 frame_info *wp_frame = block_innermost_frame (exp_valid_block);
10686 /* Save this because create_internal_breakpoint below invalidates
10688 frame_id watchpoint_frame = get_frame_id (wp_frame);
10690 /* If the expression is "local", then set up a "watchpoint scope"
10691 breakpoint at the point where we've left the scope of the watchpoint
10692 expression. Create the scope breakpoint before the watchpoint, so
10693 that we will encounter it first in bpstat_stop_status. */
10694 if (exp_valid_block != NULL && wp_frame != NULL)
10696 frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
10698 if (frame_id_p (caller_frame_id))
10700 gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
10701 CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
10704 = create_internal_breakpoint (caller_arch, caller_pc,
10705 bp_watchpoint_scope,
10706 &momentary_breakpoint_ops);
10708 /* create_internal_breakpoint could invalidate WP_FRAME. */
10711 scope_breakpoint->enable_state = bp_enabled;
10713 /* Automatically delete the breakpoint when it hits. */
10714 scope_breakpoint->disposition = disp_del;
10716 /* Only break in the proper frame (help with recursion). */
10717 scope_breakpoint->frame_id = caller_frame_id;
10719 /* Set the address at which we will stop. */
10720 scope_breakpoint->loc->gdbarch = caller_arch;
10721 scope_breakpoint->loc->requested_address = caller_pc;
10722 scope_breakpoint->loc->address
10723 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10724 scope_breakpoint->loc->requested_address,
10725 scope_breakpoint->type);
10729 /* Now set up the breakpoint. We create all watchpoints as hardware
10730 watchpoints here even if hardware watchpoints are turned off, a call
10731 to update_watchpoint later in this function will cause the type to
10732 drop back to bp_watchpoint (software watchpoint) if required. */
10734 if (accessflag == hw_read)
10735 bp_type = bp_read_watchpoint;
10736 else if (accessflag == hw_access)
10737 bp_type = bp_access_watchpoint;
10739 bp_type = bp_hardware_watchpoint;
10741 std::unique_ptr<watchpoint> w (new watchpoint ());
10744 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10745 &masked_watchpoint_breakpoint_ops);
10747 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10748 &watchpoint_breakpoint_ops);
10749 w->thread = thread;
10750 w->disposition = disp_donttouch;
10751 w->pspace = current_program_space;
10752 w->exp = std::move (exp);
10753 w->exp_valid_block = exp_valid_block;
10754 w->cond_exp_valid_block = cond_exp_valid_block;
10757 struct type *t = value_type (val.get ());
10758 CORE_ADDR addr = value_as_address (val.get ());
10760 w->exp_string_reparse
10761 = current_language->la_watch_location_expression (t, addr).release ();
10763 w->exp_string = xstrprintf ("-location %.*s",
10764 (int) (exp_end - exp_start), exp_start);
10767 w->exp_string = savestring (exp_start, exp_end - exp_start);
10771 w->hw_wp_mask = mask;
10776 w->val_bitpos = saved_bitpos;
10777 w->val_bitsize = saved_bitsize;
10782 w->cond_string = savestring (cond_start, cond_end - cond_start);
10784 w->cond_string = 0;
10786 if (frame_id_p (watchpoint_frame))
10788 w->watchpoint_frame = watchpoint_frame;
10789 w->watchpoint_thread = inferior_ptid;
10793 w->watchpoint_frame = null_frame_id;
10794 w->watchpoint_thread = null_ptid;
10797 if (scope_breakpoint != NULL)
10799 /* The scope breakpoint is related to the watchpoint. We will
10800 need to act on them together. */
10801 w->related_breakpoint = scope_breakpoint;
10802 scope_breakpoint->related_breakpoint = w.get ();
10805 if (!just_location)
10806 value_free_to_mark (mark);
10808 /* Finally update the new watchpoint. This creates the locations
10809 that should be inserted. */
10810 update_watchpoint (w.get (), 1);
10812 install_breakpoint (internal, std::move (w), 1);
10815 /* Return count of debug registers needed to watch the given expression.
10816 If the watchpoint cannot be handled in hardware return zero. */
10819 can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
10821 int found_memory_cnt = 0;
10823 /* Did the user specifically forbid us to use hardware watchpoints? */
10824 if (!can_use_hw_watchpoints)
10827 gdb_assert (!vals.empty ());
10828 struct value *head = vals[0].get ();
10830 /* Make sure that the value of the expression depends only upon
10831 memory contents, and values computed from them within GDB. If we
10832 find any register references or function calls, we can't use a
10833 hardware watchpoint.
10835 The idea here is that evaluating an expression generates a series
10836 of values, one holding the value of every subexpression. (The
10837 expression a*b+c has five subexpressions: a, b, a*b, c, and
10838 a*b+c.) GDB's values hold almost enough information to establish
10839 the criteria given above --- they identify memory lvalues,
10840 register lvalues, computed values, etcetera. So we can evaluate
10841 the expression, and then scan the chain of values that leaves
10842 behind to decide whether we can detect any possible change to the
10843 expression's final value using only hardware watchpoints.
10845 However, I don't think that the values returned by inferior
10846 function calls are special in any way. So this function may not
10847 notice that an expression involving an inferior function call
10848 can't be watched with hardware watchpoints. FIXME. */
10849 for (const value_ref_ptr &iter : vals)
10851 struct value *v = iter.get ();
10853 if (VALUE_LVAL (v) == lval_memory)
10855 if (v != head && value_lazy (v))
10856 /* A lazy memory lvalue in the chain is one that GDB never
10857 needed to fetch; we either just used its address (e.g.,
10858 `a' in `a.b') or we never needed it at all (e.g., `a'
10859 in `a,b'). This doesn't apply to HEAD; if that is
10860 lazy then it was not readable, but watch it anyway. */
10864 /* Ahh, memory we actually used! Check if we can cover
10865 it with hardware watchpoints. */
10866 struct type *vtype = check_typedef (value_type (v));
10868 /* We only watch structs and arrays if user asked for it
10869 explicitly, never if they just happen to appear in a
10870 middle of some value chain. */
10872 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10873 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10875 CORE_ADDR vaddr = value_address (v);
10879 len = (target_exact_watchpoints
10880 && is_scalar_type_recursive (vtype))?
10881 1 : TYPE_LENGTH (value_type (v));
10883 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10887 found_memory_cnt += num_regs;
10891 else if (VALUE_LVAL (v) != not_lval
10892 && deprecated_value_modifiable (v) == 0)
10893 return 0; /* These are values from the history (e.g., $1). */
10894 else if (VALUE_LVAL (v) == lval_register)
10895 return 0; /* Cannot watch a register with a HW watchpoint. */
10898 /* The expression itself looks suitable for using a hardware
10899 watchpoint, but give the target machine a chance to reject it. */
10900 return found_memory_cnt;
10904 watch_command_wrapper (const char *arg, int from_tty, int internal)
10906 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10909 /* A helper function that looks for the "-location" argument and then
10910 calls watch_command_1. */
10913 watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
10915 int just_location = 0;
10918 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10919 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10921 arg = skip_spaces (arg);
10925 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10929 watch_command (const char *arg, int from_tty)
10931 watch_maybe_just_location (arg, hw_write, from_tty);
10935 rwatch_command_wrapper (const char *arg, int from_tty, int internal)
10937 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10941 rwatch_command (const char *arg, int from_tty)
10943 watch_maybe_just_location (arg, hw_read, from_tty);
10947 awatch_command_wrapper (const char *arg, int from_tty, int internal)
10949 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10953 awatch_command (const char *arg, int from_tty)
10955 watch_maybe_just_location (arg, hw_access, from_tty);
10959 /* Data for the FSM that manages the until(location)/advance commands
10960 in infcmd.c. Here because it uses the mechanisms of
10963 struct until_break_fsm : public thread_fsm
10965 /* The thread that was current when the command was executed. */
10968 /* The breakpoint set at the destination location. */
10969 breakpoint_up location_breakpoint;
10971 /* Breakpoint set at the return address in the caller frame. May be
10973 breakpoint_up caller_breakpoint;
10975 until_break_fsm (struct interp *cmd_interp, int thread,
10976 breakpoint_up &&location_breakpoint,
10977 breakpoint_up &&caller_breakpoint)
10978 : thread_fsm (cmd_interp),
10980 location_breakpoint (std::move (location_breakpoint)),
10981 caller_breakpoint (std::move (caller_breakpoint))
10985 void clean_up (struct thread_info *thread) override;
10986 bool should_stop (struct thread_info *thread) override;
10987 enum async_reply_reason do_async_reply_reason () override;
10990 /* Implementation of the 'should_stop' FSM method for the
10991 until(location)/advance commands. */
10994 until_break_fsm::should_stop (struct thread_info *tp)
10996 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
10997 location_breakpoint.get ()) != NULL
10998 || (caller_breakpoint != NULL
10999 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11000 caller_breakpoint.get ()) != NULL))
11006 /* Implementation of the 'clean_up' FSM method for the
11007 until(location)/advance commands. */
11010 until_break_fsm::clean_up (struct thread_info *)
11012 /* Clean up our temporary breakpoints. */
11013 location_breakpoint.reset ();
11014 caller_breakpoint.reset ();
11015 delete_longjmp_breakpoint (thread);
11018 /* Implementation of the 'async_reply_reason' FSM method for the
11019 until(location)/advance commands. */
11021 enum async_reply_reason
11022 until_break_fsm::do_async_reply_reason ()
11024 return EXEC_ASYNC_LOCATION_REACHED;
11028 until_break_command (const char *arg, int from_tty, int anywhere)
11030 struct frame_info *frame;
11031 struct gdbarch *frame_gdbarch;
11032 struct frame_id stack_frame_id;
11033 struct frame_id caller_frame_id;
11035 struct thread_info *tp;
11037 clear_proceed_status (0);
11039 /* Set a breakpoint where the user wants it and at return from
11042 event_location_up location = string_to_event_location (&arg, current_language);
11044 std::vector<symtab_and_line> sals
11045 = (last_displayed_sal_is_valid ()
11046 ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
11047 get_last_displayed_symtab (),
11048 get_last_displayed_line ())
11049 : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
11050 NULL, (struct symtab *) NULL, 0));
11052 if (sals.size () != 1)
11053 error (_("Couldn't get information on specified line."));
11055 symtab_and_line &sal = sals[0];
11058 error (_("Junk at end of arguments."));
11060 resolve_sal_pc (&sal);
11062 tp = inferior_thread ();
11063 thread = tp->global_num;
11065 /* Note linespec handling above invalidates the frame chain.
11066 Installing a breakpoint also invalidates the frame chain (as it
11067 may need to switch threads), so do any frame handling before
11070 frame = get_selected_frame (NULL);
11071 frame_gdbarch = get_frame_arch (frame);
11072 stack_frame_id = get_stack_frame_id (frame);
11073 caller_frame_id = frame_unwind_caller_id (frame);
11075 /* Keep within the current frame, or in frames called by the current
11078 breakpoint_up caller_breakpoint;
11080 gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter;
11082 if (frame_id_p (caller_frame_id))
11084 struct symtab_and_line sal2;
11085 struct gdbarch *caller_gdbarch;
11087 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11088 sal2.pc = frame_unwind_caller_pc (frame);
11089 caller_gdbarch = frame_unwind_caller_arch (frame);
11090 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11095 set_longjmp_breakpoint (tp, caller_frame_id);
11096 lj_deleter.emplace (thread);
11099 /* set_momentary_breakpoint could invalidate FRAME. */
11102 breakpoint_up location_breakpoint;
11104 /* If the user told us to continue until a specified location,
11105 we don't specify a frame at which we need to stop. */
11106 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11107 null_frame_id, bp_until);
11109 /* Otherwise, specify the selected frame, because we want to stop
11110 only at the very same frame. */
11111 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11112 stack_frame_id, bp_until);
11114 tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num,
11115 std::move (location_breakpoint),
11116 std::move (caller_breakpoint));
11119 lj_deleter->release ();
11121 proceed (-1, GDB_SIGNAL_DEFAULT);
11124 /* This function attempts to parse an optional "if <cond>" clause
11125 from the arg string. If one is not found, it returns NULL.
11127 Else, it returns a pointer to the condition string. (It does not
11128 attempt to evaluate the string against a particular block.) And,
11129 it updates arg to point to the first character following the parsed
11130 if clause in the arg string. */
11133 ep_parse_optional_if_clause (const char **arg)
11135 const char *cond_string;
11137 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11140 /* Skip the "if" keyword. */
11143 /* Skip any extra leading whitespace, and record the start of the
11144 condition string. */
11145 *arg = skip_spaces (*arg);
11146 cond_string = *arg;
11148 /* Assume that the condition occupies the remainder of the arg
11150 (*arg) += strlen (cond_string);
11152 return cond_string;
11155 /* Commands to deal with catching events, such as signals, exceptions,
11156 process start/exit, etc. */
11160 catch_fork_temporary, catch_vfork_temporary,
11161 catch_fork_permanent, catch_vfork_permanent
11166 catch_fork_command_1 (const char *arg, int from_tty,
11167 struct cmd_list_element *command)
11169 struct gdbarch *gdbarch = get_current_arch ();
11170 const char *cond_string = NULL;
11171 catch_fork_kind fork_kind;
11174 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11175 tempflag = (fork_kind == catch_fork_temporary
11176 || fork_kind == catch_vfork_temporary);
11180 arg = skip_spaces (arg);
11182 /* The allowed syntax is:
11184 catch [v]fork if <cond>
11186 First, check if there's an if clause. */
11187 cond_string = ep_parse_optional_if_clause (&arg);
11189 if ((*arg != '\0') && !isspace (*arg))
11190 error (_("Junk at end of arguments."));
11192 /* If this target supports it, create a fork or vfork catchpoint
11193 and enable reporting of such events. */
11196 case catch_fork_temporary:
11197 case catch_fork_permanent:
11198 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11199 &catch_fork_breakpoint_ops);
11201 case catch_vfork_temporary:
11202 case catch_vfork_permanent:
11203 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11204 &catch_vfork_breakpoint_ops);
11207 error (_("unsupported or unknown fork kind; cannot catch it"));
11213 catch_exec_command_1 (const char *arg, int from_tty,
11214 struct cmd_list_element *command)
11216 struct gdbarch *gdbarch = get_current_arch ();
11218 const char *cond_string = NULL;
11220 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11224 arg = skip_spaces (arg);
11226 /* The allowed syntax is:
11228 catch exec if <cond>
11230 First, check if there's an if clause. */
11231 cond_string = ep_parse_optional_if_clause (&arg);
11233 if ((*arg != '\0') && !isspace (*arg))
11234 error (_("Junk at end of arguments."));
11236 std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
11237 init_catchpoint (c.get (), gdbarch, tempflag, cond_string,
11238 &catch_exec_breakpoint_ops);
11239 c->exec_pathname = NULL;
11241 install_breakpoint (0, std::move (c), 1);
11245 init_ada_exception_breakpoint (struct breakpoint *b,
11246 struct gdbarch *gdbarch,
11247 struct symtab_and_line sal,
11248 const char *addr_string,
11249 const struct breakpoint_ops *ops,
11256 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11258 loc_gdbarch = gdbarch;
11260 describe_other_breakpoints (loc_gdbarch,
11261 sal.pspace, sal.pc, sal.section, -1);
11262 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11263 version for exception catchpoints, because two catchpoints
11264 used for different exception names will use the same address.
11265 In this case, a "breakpoint ... also set at..." warning is
11266 unproductive. Besides, the warning phrasing is also a bit
11267 inappropriate, we should use the word catchpoint, and tell
11268 the user what type of catchpoint it is. The above is good
11269 enough for now, though. */
11272 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11274 b->enable_state = enabled ? bp_enabled : bp_disabled;
11275 b->disposition = tempflag ? disp_del : disp_donttouch;
11276 b->location = string_to_event_location (&addr_string,
11277 language_def (language_ada));
11278 b->language = language_ada;
11282 catch_command (const char *arg, int from_tty)
11284 error (_("Catch requires an event name."));
11289 tcatch_command (const char *arg, int from_tty)
11291 error (_("Catch requires an event name."));
11294 /* Compare two breakpoints and return a strcmp-like result. */
11297 compare_breakpoints (const breakpoint *a, const breakpoint *b)
11299 uintptr_t ua = (uintptr_t) a;
11300 uintptr_t ub = (uintptr_t) b;
11302 if (a->number < b->number)
11304 else if (a->number > b->number)
11307 /* Now sort by address, in case we see, e..g, two breakpoints with
11311 return ua > ub ? 1 : 0;
11314 /* Delete breakpoints by address or line. */
11317 clear_command (const char *arg, int from_tty)
11319 struct breakpoint *b;
11322 std::vector<symtab_and_line> decoded_sals;
11323 symtab_and_line last_sal;
11324 gdb::array_view<symtab_and_line> sals;
11328 = decode_line_with_current_source (arg,
11329 (DECODE_LINE_FUNFIRSTLINE
11330 | DECODE_LINE_LIST_MODE));
11332 sals = decoded_sals;
11336 /* Set sal's line, symtab, pc, and pspace to the values
11337 corresponding to the last call to print_frame_info. If the
11338 codepoint is not valid, this will set all the fields to 0. */
11339 last_sal = get_last_displayed_sal ();
11340 if (last_sal.symtab == 0)
11341 error (_("No source file specified."));
11347 /* We don't call resolve_sal_pc here. That's not as bad as it
11348 seems, because all existing breakpoints typically have both
11349 file/line and pc set. So, if clear is given file/line, we can
11350 match this to existing breakpoint without obtaining pc at all.
11352 We only support clearing given the address explicitly
11353 present in breakpoint table. Say, we've set breakpoint
11354 at file:line. There were several PC values for that file:line,
11355 due to optimization, all in one block.
11357 We've picked one PC value. If "clear" is issued with another
11358 PC corresponding to the same file:line, the breakpoint won't
11359 be cleared. We probably can still clear the breakpoint, but
11360 since the other PC value is never presented to user, user
11361 can only find it by guessing, and it does not seem important
11362 to support that. */
11364 /* For each line spec given, delete bps which correspond to it. Do
11365 it in two passes, solely to preserve the current behavior that
11366 from_tty is forced true if we delete more than one
11369 std::vector<struct breakpoint *> found;
11370 for (const auto &sal : sals)
11372 const char *sal_fullname;
11374 /* If exact pc given, clear bpts at that pc.
11375 If line given (pc == 0), clear all bpts on specified line.
11376 If defaulting, clear all bpts on default line
11379 defaulting sal.pc != 0 tests to do
11384 1 0 <can't happen> */
11386 sal_fullname = (sal.symtab == NULL
11387 ? NULL : symtab_to_fullname (sal.symtab));
11389 /* Find all matching breakpoints and add them to 'found'. */
11390 ALL_BREAKPOINTS (b)
11393 /* Are we going to delete b? */
11394 if (b->type != bp_none && !is_watchpoint (b))
11396 struct bp_location *loc = b->loc;
11397 for (; loc; loc = loc->next)
11399 /* If the user specified file:line, don't allow a PC
11400 match. This matches historical gdb behavior. */
11401 int pc_match = (!sal.explicit_line
11403 && (loc->pspace == sal.pspace)
11404 && (loc->address == sal.pc)
11405 && (!section_is_overlay (loc->section)
11406 || loc->section == sal.section));
11407 int line_match = 0;
11409 if ((default_match || sal.explicit_line)
11410 && loc->symtab != NULL
11411 && sal_fullname != NULL
11412 && sal.pspace == loc->pspace
11413 && loc->line_number == sal.line
11414 && filename_cmp (symtab_to_fullname (loc->symtab),
11415 sal_fullname) == 0)
11418 if (pc_match || line_match)
11427 found.push_back (b);
11431 /* Now go thru the 'found' chain and delete them. */
11432 if (found.empty ())
11435 error (_("No breakpoint at %s."), arg);
11437 error (_("No breakpoint at this line."));
11440 /* Remove duplicates from the vec. */
11441 std::sort (found.begin (), found.end (),
11442 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11444 return compare_breakpoints (bp_a, bp_b) < 0;
11446 found.erase (std::unique (found.begin (), found.end (),
11447 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11449 return compare_breakpoints (bp_a, bp_b) == 0;
11453 if (found.size () > 1)
11454 from_tty = 1; /* Always report if deleted more than one. */
11457 if (found.size () == 1)
11458 printf_unfiltered (_("Deleted breakpoint "));
11460 printf_unfiltered (_("Deleted breakpoints "));
11463 for (breakpoint *iter : found)
11466 printf_unfiltered ("%d ", iter->number);
11467 delete_breakpoint (iter);
11470 putchar_unfiltered ('\n');
11473 /* Delete breakpoint in BS if they are `delete' breakpoints and
11474 all breakpoints that are marked for deletion, whether hit or not.
11475 This is called after any breakpoint is hit, or after errors. */
11478 breakpoint_auto_delete (bpstat bs)
11480 struct breakpoint *b, *b_tmp;
11482 for (; bs; bs = bs->next)
11483 if (bs->breakpoint_at
11484 && bs->breakpoint_at->disposition == disp_del
11486 delete_breakpoint (bs->breakpoint_at);
11488 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11490 if (b->disposition == disp_del_at_next_stop)
11491 delete_breakpoint (b);
11495 /* A comparison function for bp_location AP and BP being interfaced to
11496 qsort. Sort elements primarily by their ADDRESS (no matter what
11497 does breakpoint_address_is_meaningful say for its OWNER),
11498 secondarily by ordering first permanent elements and
11499 terciarily just ensuring the array is sorted stable way despite
11500 qsort being an unstable algorithm. */
11503 bp_locations_compare (const void *ap, const void *bp)
11505 const struct bp_location *a = *(const struct bp_location **) ap;
11506 const struct bp_location *b = *(const struct bp_location **) bp;
11508 if (a->address != b->address)
11509 return (a->address > b->address) - (a->address < b->address);
11511 /* Sort locations at the same address by their pspace number, keeping
11512 locations of the same inferior (in a multi-inferior environment)
11515 if (a->pspace->num != b->pspace->num)
11516 return ((a->pspace->num > b->pspace->num)
11517 - (a->pspace->num < b->pspace->num));
11519 /* Sort permanent breakpoints first. */
11520 if (a->permanent != b->permanent)
11521 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
11523 /* Make the internal GDB representation stable across GDB runs
11524 where A and B memory inside GDB can differ. Breakpoint locations of
11525 the same type at the same address can be sorted in arbitrary order. */
11527 if (a->owner->number != b->owner->number)
11528 return ((a->owner->number > b->owner->number)
11529 - (a->owner->number < b->owner->number));
11531 return (a > b) - (a < b);
11534 /* Set bp_locations_placed_address_before_address_max and
11535 bp_locations_shadow_len_after_address_max according to the current
11536 content of the bp_locations array. */
11539 bp_locations_target_extensions_update (void)
11541 struct bp_location *bl, **blp_tmp;
11543 bp_locations_placed_address_before_address_max = 0;
11544 bp_locations_shadow_len_after_address_max = 0;
11546 ALL_BP_LOCATIONS (bl, blp_tmp)
11548 CORE_ADDR start, end, addr;
11550 if (!bp_location_has_shadow (bl))
11553 start = bl->target_info.placed_address;
11554 end = start + bl->target_info.shadow_len;
11556 gdb_assert (bl->address >= start);
11557 addr = bl->address - start;
11558 if (addr > bp_locations_placed_address_before_address_max)
11559 bp_locations_placed_address_before_address_max = addr;
11561 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11563 gdb_assert (bl->address < end);
11564 addr = end - bl->address;
11565 if (addr > bp_locations_shadow_len_after_address_max)
11566 bp_locations_shadow_len_after_address_max = addr;
11570 /* Download tracepoint locations if they haven't been. */
11573 download_tracepoint_locations (void)
11575 struct breakpoint *b;
11576 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
11578 scoped_restore_current_pspace_and_thread restore_pspace_thread;
11580 ALL_TRACEPOINTS (b)
11582 struct bp_location *bl;
11583 struct tracepoint *t;
11584 int bp_location_downloaded = 0;
11586 if ((b->type == bp_fast_tracepoint
11587 ? !may_insert_fast_tracepoints
11588 : !may_insert_tracepoints))
11591 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
11593 if (target_can_download_tracepoint ())
11594 can_download_tracepoint = TRIBOOL_TRUE;
11596 can_download_tracepoint = TRIBOOL_FALSE;
11599 if (can_download_tracepoint == TRIBOOL_FALSE)
11602 for (bl = b->loc; bl; bl = bl->next)
11604 /* In tracepoint, locations are _never_ duplicated, so
11605 should_be_inserted is equivalent to
11606 unduplicated_should_be_inserted. */
11607 if (!should_be_inserted (bl) || bl->inserted)
11610 switch_to_program_space_and_thread (bl->pspace);
11612 target_download_tracepoint (bl);
11615 bp_location_downloaded = 1;
11617 t = (struct tracepoint *) b;
11618 t->number_on_target = b->number;
11619 if (bp_location_downloaded)
11620 gdb::observers::breakpoint_modified.notify (b);
11624 /* Swap the insertion/duplication state between two locations. */
11627 swap_insertion (struct bp_location *left, struct bp_location *right)
11629 const int left_inserted = left->inserted;
11630 const int left_duplicate = left->duplicate;
11631 const int left_needs_update = left->needs_update;
11632 const struct bp_target_info left_target_info = left->target_info;
11634 /* Locations of tracepoints can never be duplicated. */
11635 if (is_tracepoint (left->owner))
11636 gdb_assert (!left->duplicate);
11637 if (is_tracepoint (right->owner))
11638 gdb_assert (!right->duplicate);
11640 left->inserted = right->inserted;
11641 left->duplicate = right->duplicate;
11642 left->needs_update = right->needs_update;
11643 left->target_info = right->target_info;
11644 right->inserted = left_inserted;
11645 right->duplicate = left_duplicate;
11646 right->needs_update = left_needs_update;
11647 right->target_info = left_target_info;
11650 /* Force the re-insertion of the locations at ADDRESS. This is called
11651 once a new/deleted/modified duplicate location is found and we are evaluating
11652 conditions on the target's side. Such conditions need to be updated on
11656 force_breakpoint_reinsertion (struct bp_location *bl)
11658 struct bp_location **locp = NULL, **loc2p;
11659 struct bp_location *loc;
11660 CORE_ADDR address = 0;
11663 address = bl->address;
11664 pspace_num = bl->pspace->num;
11666 /* This is only meaningful if the target is
11667 evaluating conditions and if the user has
11668 opted for condition evaluation on the target's
11670 if (gdb_evaluates_breakpoint_condition_p ()
11671 || !target_supports_evaluation_of_breakpoint_conditions ())
11674 /* Flag all breakpoint locations with this address and
11675 the same program space as the location
11676 as "its condition has changed". We need to
11677 update the conditions on the target's side. */
11678 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11682 if (!is_breakpoint (loc->owner)
11683 || pspace_num != loc->pspace->num)
11686 /* Flag the location appropriately. We use a different state to
11687 let everyone know that we already updated the set of locations
11688 with addr bl->address and program space bl->pspace. This is so
11689 we don't have to keep calling these functions just to mark locations
11690 that have already been marked. */
11691 loc->condition_changed = condition_updated;
11693 /* Free the agent expression bytecode as well. We will compute
11695 loc->cond_bytecode.reset ();
11698 /* Called whether new breakpoints are created, or existing breakpoints
11699 deleted, to update the global location list and recompute which
11700 locations are duplicate of which.
11702 The INSERT_MODE flag determines whether locations may not, may, or
11703 shall be inserted now. See 'enum ugll_insert_mode' for more
11707 update_global_location_list (enum ugll_insert_mode insert_mode)
11709 struct breakpoint *b;
11710 struct bp_location **locp, *loc;
11711 /* Last breakpoint location address that was marked for update. */
11712 CORE_ADDR last_addr = 0;
11713 /* Last breakpoint location program space that was marked for update. */
11714 int last_pspace_num = -1;
11716 /* Used in the duplicates detection below. When iterating over all
11717 bp_locations, points to the first bp_location of a given address.
11718 Breakpoints and watchpoints of different types are never
11719 duplicates of each other. Keep one pointer for each type of
11720 breakpoint/watchpoint, so we only need to loop over all locations
11722 struct bp_location *bp_loc_first; /* breakpoint */
11723 struct bp_location *wp_loc_first; /* hardware watchpoint */
11724 struct bp_location *awp_loc_first; /* access watchpoint */
11725 struct bp_location *rwp_loc_first; /* read watchpoint */
11727 /* Saved former bp_locations array which we compare against the newly
11728 built bp_locations from the current state of ALL_BREAKPOINTS. */
11729 struct bp_location **old_locp;
11730 unsigned old_locations_count;
11731 gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations);
11733 old_locations_count = bp_locations_count;
11734 bp_locations = NULL;
11735 bp_locations_count = 0;
11737 ALL_BREAKPOINTS (b)
11738 for (loc = b->loc; loc; loc = loc->next)
11739 bp_locations_count++;
11741 bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
11742 locp = bp_locations;
11743 ALL_BREAKPOINTS (b)
11744 for (loc = b->loc; loc; loc = loc->next)
11746 qsort (bp_locations, bp_locations_count, sizeof (*bp_locations),
11747 bp_locations_compare);
11749 bp_locations_target_extensions_update ();
11751 /* Identify bp_location instances that are no longer present in the
11752 new list, and therefore should be freed. Note that it's not
11753 necessary that those locations should be removed from inferior --
11754 if there's another location at the same address (previously
11755 marked as duplicate), we don't need to remove/insert the
11758 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11759 and former bp_location array state respectively. */
11761 locp = bp_locations;
11762 for (old_locp = old_locations.get ();
11763 old_locp < old_locations.get () + old_locations_count;
11766 struct bp_location *old_loc = *old_locp;
11767 struct bp_location **loc2p;
11769 /* Tells if 'old_loc' is found among the new locations. If
11770 not, we have to free it. */
11771 int found_object = 0;
11772 /* Tells if the location should remain inserted in the target. */
11773 int keep_in_target = 0;
11776 /* Skip LOCP entries which will definitely never be needed.
11777 Stop either at or being the one matching OLD_LOC. */
11778 while (locp < bp_locations + bp_locations_count
11779 && (*locp)->address < old_loc->address)
11783 (loc2p < bp_locations + bp_locations_count
11784 && (*loc2p)->address == old_loc->address);
11787 /* Check if this is a new/duplicated location or a duplicated
11788 location that had its condition modified. If so, we want to send
11789 its condition to the target if evaluation of conditions is taking
11791 if ((*loc2p)->condition_changed == condition_modified
11792 && (last_addr != old_loc->address
11793 || last_pspace_num != old_loc->pspace->num))
11795 force_breakpoint_reinsertion (*loc2p);
11796 last_pspace_num = old_loc->pspace->num;
11799 if (*loc2p == old_loc)
11803 /* We have already handled this address, update it so that we don't
11804 have to go through updates again. */
11805 last_addr = old_loc->address;
11807 /* Target-side condition evaluation: Handle deleted locations. */
11809 force_breakpoint_reinsertion (old_loc);
11811 /* If this location is no longer present, and inserted, look if
11812 there's maybe a new location at the same address. If so,
11813 mark that one inserted, and don't remove this one. This is
11814 needed so that we don't have a time window where a breakpoint
11815 at certain location is not inserted. */
11817 if (old_loc->inserted)
11819 /* If the location is inserted now, we might have to remove
11822 if (found_object && should_be_inserted (old_loc))
11824 /* The location is still present in the location list,
11825 and still should be inserted. Don't do anything. */
11826 keep_in_target = 1;
11830 /* This location still exists, but it won't be kept in the
11831 target since it may have been disabled. We proceed to
11832 remove its target-side condition. */
11834 /* The location is either no longer present, or got
11835 disabled. See if there's another location at the
11836 same address, in which case we don't need to remove
11837 this one from the target. */
11839 /* OLD_LOC comes from existing struct breakpoint. */
11840 if (breakpoint_address_is_meaningful (old_loc->owner))
11843 (loc2p < bp_locations + bp_locations_count
11844 && (*loc2p)->address == old_loc->address);
11847 struct bp_location *loc2 = *loc2p;
11849 if (breakpoint_locations_match (loc2, old_loc))
11851 /* Read watchpoint locations are switched to
11852 access watchpoints, if the former are not
11853 supported, but the latter are. */
11854 if (is_hardware_watchpoint (old_loc->owner))
11856 gdb_assert (is_hardware_watchpoint (loc2->owner));
11857 loc2->watchpoint_type = old_loc->watchpoint_type;
11860 /* loc2 is a duplicated location. We need to check
11861 if it should be inserted in case it will be
11863 if (loc2 != old_loc
11864 && unduplicated_should_be_inserted (loc2))
11866 swap_insertion (old_loc, loc2);
11867 keep_in_target = 1;
11875 if (!keep_in_target)
11877 if (remove_breakpoint (old_loc))
11879 /* This is just about all we can do. We could keep
11880 this location on the global list, and try to
11881 remove it next time, but there's no particular
11882 reason why we will succeed next time.
11884 Note that at this point, old_loc->owner is still
11885 valid, as delete_breakpoint frees the breakpoint
11886 only after calling us. */
11887 printf_filtered (_("warning: Error removing "
11888 "breakpoint %d\n"),
11889 old_loc->owner->number);
11897 if (removed && target_is_non_stop_p ()
11898 && need_moribund_for_location_type (old_loc))
11900 /* This location was removed from the target. In
11901 non-stop mode, a race condition is possible where
11902 we've removed a breakpoint, but stop events for that
11903 breakpoint are already queued and will arrive later.
11904 We apply an heuristic to be able to distinguish such
11905 SIGTRAPs from other random SIGTRAPs: we keep this
11906 breakpoint location for a bit, and will retire it
11907 after we see some number of events. The theory here
11908 is that reporting of events should, "on the average",
11909 be fair, so after a while we'll see events from all
11910 threads that have anything of interest, and no longer
11911 need to keep this breakpoint location around. We
11912 don't hold locations forever so to reduce chances of
11913 mistaking a non-breakpoint SIGTRAP for a breakpoint
11916 The heuristic failing can be disastrous on
11917 decr_pc_after_break targets.
11919 On decr_pc_after_break targets, like e.g., x86-linux,
11920 if we fail to recognize a late breakpoint SIGTRAP,
11921 because events_till_retirement has reached 0 too
11922 soon, we'll fail to do the PC adjustment, and report
11923 a random SIGTRAP to the user. When the user resumes
11924 the inferior, it will most likely immediately crash
11925 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11926 corrupted, because of being resumed e.g., in the
11927 middle of a multi-byte instruction, or skipped a
11928 one-byte instruction. This was actually seen happen
11929 on native x86-linux, and should be less rare on
11930 targets that do not support new thread events, like
11931 remote, due to the heuristic depending on
11934 Mistaking a random SIGTRAP for a breakpoint trap
11935 causes similar symptoms (PC adjustment applied when
11936 it shouldn't), but then again, playing with SIGTRAPs
11937 behind the debugger's back is asking for trouble.
11939 Since hardware watchpoint traps are always
11940 distinguishable from other traps, so we don't need to
11941 apply keep hardware watchpoint moribund locations
11942 around. We simply always ignore hardware watchpoint
11943 traps we can no longer explain. */
11945 old_loc->events_till_retirement = 3 * (thread_count () + 1);
11946 old_loc->owner = NULL;
11948 moribund_locations.push_back (old_loc);
11952 old_loc->owner = NULL;
11953 decref_bp_location (&old_loc);
11958 /* Rescan breakpoints at the same address and section, marking the
11959 first one as "first" and any others as "duplicates". This is so
11960 that the bpt instruction is only inserted once. If we have a
11961 permanent breakpoint at the same place as BPT, make that one the
11962 official one, and the rest as duplicates. Permanent breakpoints
11963 are sorted first for the same address.
11965 Do the same for hardware watchpoints, but also considering the
11966 watchpoint's type (regular/access/read) and length. */
11968 bp_loc_first = NULL;
11969 wp_loc_first = NULL;
11970 awp_loc_first = NULL;
11971 rwp_loc_first = NULL;
11972 ALL_BP_LOCATIONS (loc, locp)
11974 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11976 struct bp_location **loc_first_p;
11979 if (!unduplicated_should_be_inserted (loc)
11980 || !breakpoint_address_is_meaningful (b)
11981 /* Don't detect duplicate for tracepoint locations because they are
11982 never duplicated. See the comments in field `duplicate' of
11983 `struct bp_location'. */
11984 || is_tracepoint (b))
11986 /* Clear the condition modification flag. */
11987 loc->condition_changed = condition_unchanged;
11991 if (b->type == bp_hardware_watchpoint)
11992 loc_first_p = &wp_loc_first;
11993 else if (b->type == bp_read_watchpoint)
11994 loc_first_p = &rwp_loc_first;
11995 else if (b->type == bp_access_watchpoint)
11996 loc_first_p = &awp_loc_first;
11998 loc_first_p = &bp_loc_first;
12000 if (*loc_first_p == NULL
12001 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12002 || !breakpoint_locations_match (loc, *loc_first_p))
12004 *loc_first_p = loc;
12005 loc->duplicate = 0;
12007 if (is_breakpoint (loc->owner) && loc->condition_changed)
12009 loc->needs_update = 1;
12010 /* Clear the condition modification flag. */
12011 loc->condition_changed = condition_unchanged;
12017 /* This and the above ensure the invariant that the first location
12018 is not duplicated, and is the inserted one.
12019 All following are marked as duplicated, and are not inserted. */
12021 swap_insertion (loc, *loc_first_p);
12022 loc->duplicate = 1;
12024 /* Clear the condition modification flag. */
12025 loc->condition_changed = condition_unchanged;
12028 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12030 if (insert_mode != UGLL_DONT_INSERT)
12031 insert_breakpoint_locations ();
12034 /* Even though the caller told us to not insert new
12035 locations, we may still need to update conditions on the
12036 target's side of breakpoints that were already inserted
12037 if the target is evaluating breakpoint conditions. We
12038 only update conditions for locations that are marked
12040 update_inserted_breakpoint_locations ();
12044 if (insert_mode != UGLL_DONT_INSERT)
12045 download_tracepoint_locations ();
12049 breakpoint_retire_moribund (void)
12051 for (int ix = 0; ix < moribund_locations.size (); ++ix)
12053 struct bp_location *loc = moribund_locations[ix];
12054 if (--(loc->events_till_retirement) == 0)
12056 decref_bp_location (&loc);
12057 unordered_remove (moribund_locations, ix);
12064 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12069 update_global_location_list (insert_mode);
12071 CATCH (e, RETURN_MASK_ERROR)
12077 /* Clear BKP from a BPS. */
12080 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12084 for (bs = bps; bs; bs = bs->next)
12085 if (bs->breakpoint_at == bpt)
12087 bs->breakpoint_at = NULL;
12088 bs->old_val = NULL;
12089 /* bs->commands will be freed later. */
12093 /* Callback for iterate_over_threads. */
12095 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12097 struct breakpoint *bpt = (struct breakpoint *) data;
12099 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12103 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12107 say_where (struct breakpoint *b)
12109 struct value_print_options opts;
12111 get_user_print_options (&opts);
12113 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12115 if (b->loc == NULL)
12117 /* For pending locations, the output differs slightly based
12118 on b->extra_string. If this is non-NULL, it contains either
12119 a condition or dprintf arguments. */
12120 if (b->extra_string == NULL)
12122 printf_filtered (_(" (%s) pending."),
12123 event_location_to_string (b->location.get ()));
12125 else if (b->type == bp_dprintf)
12127 printf_filtered (_(" (%s,%s) pending."),
12128 event_location_to_string (b->location.get ()),
12133 printf_filtered (_(" (%s %s) pending."),
12134 event_location_to_string (b->location.get ()),
12140 if (opts.addressprint || b->loc->symtab == NULL)
12142 printf_filtered (" at ");
12143 fputs_styled (paddress (b->loc->gdbarch, b->loc->address),
12144 address_style.style (),
12147 if (b->loc->symtab != NULL)
12149 /* If there is a single location, we can print the location
12151 if (b->loc->next == NULL)
12153 puts_filtered (": file ");
12154 fputs_styled (symtab_to_filename_for_display (b->loc->symtab),
12155 file_name_style.style (),
12157 printf_filtered (", line %d.",
12158 b->loc->line_number);
12161 /* This is not ideal, but each location may have a
12162 different file name, and this at least reflects the
12163 real situation somewhat. */
12164 printf_filtered (": %s.",
12165 event_location_to_string (b->location.get ()));
12170 struct bp_location *loc = b->loc;
12172 for (; loc; loc = loc->next)
12174 printf_filtered (" (%d locations)", n);
12179 bp_location::~bp_location ()
12181 xfree (function_name);
12184 /* Destructor for the breakpoint base class. */
12186 breakpoint::~breakpoint ()
12188 xfree (this->cond_string);
12189 xfree (this->extra_string);
12190 xfree (this->filter);
12193 static struct bp_location *
12194 base_breakpoint_allocate_location (struct breakpoint *self)
12196 return new bp_location (self);
12200 base_breakpoint_re_set (struct breakpoint *b)
12202 /* Nothing to re-set. */
12205 #define internal_error_pure_virtual_called() \
12206 gdb_assert_not_reached ("pure virtual function called")
12209 base_breakpoint_insert_location (struct bp_location *bl)
12211 internal_error_pure_virtual_called ();
12215 base_breakpoint_remove_location (struct bp_location *bl,
12216 enum remove_bp_reason reason)
12218 internal_error_pure_virtual_called ();
12222 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12223 const address_space *aspace,
12225 const struct target_waitstatus *ws)
12227 internal_error_pure_virtual_called ();
12231 base_breakpoint_check_status (bpstat bs)
12236 /* A "works_in_software_mode" breakpoint_ops method that just internal
12240 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12242 internal_error_pure_virtual_called ();
12245 /* A "resources_needed" breakpoint_ops method that just internal
12249 base_breakpoint_resources_needed (const struct bp_location *bl)
12251 internal_error_pure_virtual_called ();
12254 static enum print_stop_action
12255 base_breakpoint_print_it (bpstat bs)
12257 internal_error_pure_virtual_called ();
12261 base_breakpoint_print_one_detail (const struct breakpoint *self,
12262 struct ui_out *uiout)
12268 base_breakpoint_print_mention (struct breakpoint *b)
12270 internal_error_pure_virtual_called ();
12274 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12276 internal_error_pure_virtual_called ();
12280 base_breakpoint_create_sals_from_location
12281 (const struct event_location *location,
12282 struct linespec_result *canonical,
12283 enum bptype type_wanted)
12285 internal_error_pure_virtual_called ();
12289 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12290 struct linespec_result *c,
12291 gdb::unique_xmalloc_ptr<char> cond_string,
12292 gdb::unique_xmalloc_ptr<char> extra_string,
12293 enum bptype type_wanted,
12294 enum bpdisp disposition,
12296 int task, int ignore_count,
12297 const struct breakpoint_ops *o,
12298 int from_tty, int enabled,
12299 int internal, unsigned flags)
12301 internal_error_pure_virtual_called ();
12304 static std::vector<symtab_and_line>
12305 base_breakpoint_decode_location (struct breakpoint *b,
12306 const struct event_location *location,
12307 struct program_space *search_pspace)
12309 internal_error_pure_virtual_called ();
12312 /* The default 'explains_signal' method. */
12315 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12320 /* The default "after_condition_true" method. */
12323 base_breakpoint_after_condition_true (struct bpstats *bs)
12325 /* Nothing to do. */
12328 struct breakpoint_ops base_breakpoint_ops =
12330 base_breakpoint_allocate_location,
12331 base_breakpoint_re_set,
12332 base_breakpoint_insert_location,
12333 base_breakpoint_remove_location,
12334 base_breakpoint_breakpoint_hit,
12335 base_breakpoint_check_status,
12336 base_breakpoint_resources_needed,
12337 base_breakpoint_works_in_software_mode,
12338 base_breakpoint_print_it,
12340 base_breakpoint_print_one_detail,
12341 base_breakpoint_print_mention,
12342 base_breakpoint_print_recreate,
12343 base_breakpoint_create_sals_from_location,
12344 base_breakpoint_create_breakpoints_sal,
12345 base_breakpoint_decode_location,
12346 base_breakpoint_explains_signal,
12347 base_breakpoint_after_condition_true,
12350 /* Default breakpoint_ops methods. */
12353 bkpt_re_set (struct breakpoint *b)
12355 /* FIXME: is this still reachable? */
12356 if (breakpoint_event_location_empty_p (b))
12358 /* Anything without a location can't be re-set. */
12359 delete_breakpoint (b);
12363 breakpoint_re_set_default (b);
12367 bkpt_insert_location (struct bp_location *bl)
12369 CORE_ADDR addr = bl->target_info.reqstd_address;
12371 bl->target_info.kind = breakpoint_kind (bl, &addr);
12372 bl->target_info.placed_address = addr;
12374 if (bl->loc_type == bp_loc_hardware_breakpoint)
12375 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
12377 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
12381 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
12383 if (bl->loc_type == bp_loc_hardware_breakpoint)
12384 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12386 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
12390 bkpt_breakpoint_hit (const struct bp_location *bl,
12391 const address_space *aspace, CORE_ADDR bp_addr,
12392 const struct target_waitstatus *ws)
12394 if (ws->kind != TARGET_WAITKIND_STOPPED
12395 || ws->value.sig != GDB_SIGNAL_TRAP)
12398 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12402 if (overlay_debugging /* unmapped overlay section */
12403 && section_is_overlay (bl->section)
12404 && !section_is_mapped (bl->section))
12411 dprintf_breakpoint_hit (const struct bp_location *bl,
12412 const address_space *aspace, CORE_ADDR bp_addr,
12413 const struct target_waitstatus *ws)
12415 if (dprintf_style == dprintf_style_agent
12416 && target_can_run_breakpoint_commands ())
12418 /* An agent-style dprintf never causes a stop. If we see a trap
12419 for this address it must be for a breakpoint that happens to
12420 be set at the same address. */
12424 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
12428 bkpt_resources_needed (const struct bp_location *bl)
12430 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12435 static enum print_stop_action
12436 bkpt_print_it (bpstat bs)
12438 struct breakpoint *b;
12439 const struct bp_location *bl;
12441 struct ui_out *uiout = current_uiout;
12443 gdb_assert (bs->bp_location_at != NULL);
12445 bl = bs->bp_location_at;
12446 b = bs->breakpoint_at;
12448 bp_temp = b->disposition == disp_del;
12449 if (bl->address != bl->requested_address)
12450 breakpoint_adjustment_warning (bl->requested_address,
12453 annotate_breakpoint (b->number);
12454 maybe_print_thread_hit_breakpoint (uiout);
12457 uiout->text ("Temporary breakpoint ");
12459 uiout->text ("Breakpoint ");
12460 if (uiout->is_mi_like_p ())
12462 uiout->field_string ("reason",
12463 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12464 uiout->field_string ("disp", bpdisp_text (b->disposition));
12466 uiout->field_int ("bkptno", b->number);
12467 uiout->text (", ");
12469 return PRINT_SRC_AND_LOC;
12473 bkpt_print_mention (struct breakpoint *b)
12475 if (current_uiout->is_mi_like_p ())
12480 case bp_breakpoint:
12481 case bp_gnu_ifunc_resolver:
12482 if (b->disposition == disp_del)
12483 printf_filtered (_("Temporary breakpoint"));
12485 printf_filtered (_("Breakpoint"));
12486 printf_filtered (_(" %d"), b->number);
12487 if (b->type == bp_gnu_ifunc_resolver)
12488 printf_filtered (_(" at gnu-indirect-function resolver"));
12490 case bp_hardware_breakpoint:
12491 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12494 printf_filtered (_("Dprintf %d"), b->number);
12502 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12504 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12505 fprintf_unfiltered (fp, "tbreak");
12506 else if (tp->type == bp_breakpoint)
12507 fprintf_unfiltered (fp, "break");
12508 else if (tp->type == bp_hardware_breakpoint
12509 && tp->disposition == disp_del)
12510 fprintf_unfiltered (fp, "thbreak");
12511 else if (tp->type == bp_hardware_breakpoint)
12512 fprintf_unfiltered (fp, "hbreak");
12514 internal_error (__FILE__, __LINE__,
12515 _("unhandled breakpoint type %d"), (int) tp->type);
12517 fprintf_unfiltered (fp, " %s",
12518 event_location_to_string (tp->location.get ()));
12520 /* Print out extra_string if this breakpoint is pending. It might
12521 contain, for example, conditions that were set by the user. */
12522 if (tp->loc == NULL && tp->extra_string != NULL)
12523 fprintf_unfiltered (fp, " %s", tp->extra_string);
12525 print_recreate_thread (tp, fp);
12529 bkpt_create_sals_from_location (const struct event_location *location,
12530 struct linespec_result *canonical,
12531 enum bptype type_wanted)
12533 create_sals_from_location_default (location, canonical, type_wanted);
12537 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12538 struct linespec_result *canonical,
12539 gdb::unique_xmalloc_ptr<char> cond_string,
12540 gdb::unique_xmalloc_ptr<char> extra_string,
12541 enum bptype type_wanted,
12542 enum bpdisp disposition,
12544 int task, int ignore_count,
12545 const struct breakpoint_ops *ops,
12546 int from_tty, int enabled,
12547 int internal, unsigned flags)
12549 create_breakpoints_sal_default (gdbarch, canonical,
12550 std::move (cond_string),
12551 std::move (extra_string),
12553 disposition, thread, task,
12554 ignore_count, ops, from_tty,
12555 enabled, internal, flags);
12558 static std::vector<symtab_and_line>
12559 bkpt_decode_location (struct breakpoint *b,
12560 const struct event_location *location,
12561 struct program_space *search_pspace)
12563 return decode_location_default (b, location, search_pspace);
12566 /* Virtual table for internal breakpoints. */
12569 internal_bkpt_re_set (struct breakpoint *b)
12573 /* Delete overlay event and longjmp master breakpoints; they
12574 will be reset later by breakpoint_re_set. */
12575 case bp_overlay_event:
12576 case bp_longjmp_master:
12577 case bp_std_terminate_master:
12578 case bp_exception_master:
12579 delete_breakpoint (b);
12582 /* This breakpoint is special, it's set up when the inferior
12583 starts and we really don't want to touch it. */
12584 case bp_shlib_event:
12586 /* Like bp_shlib_event, this breakpoint type is special. Once
12587 it is set up, we do not want to touch it. */
12588 case bp_thread_event:
12594 internal_bkpt_check_status (bpstat bs)
12596 if (bs->breakpoint_at->type == bp_shlib_event)
12598 /* If requested, stop when the dynamic linker notifies GDB of
12599 events. This allows the user to get control and place
12600 breakpoints in initializer routines for dynamically loaded
12601 objects (among other things). */
12602 bs->stop = stop_on_solib_events;
12603 bs->print = stop_on_solib_events;
12609 static enum print_stop_action
12610 internal_bkpt_print_it (bpstat bs)
12612 struct breakpoint *b;
12614 b = bs->breakpoint_at;
12618 case bp_shlib_event:
12619 /* Did we stop because the user set the stop_on_solib_events
12620 variable? (If so, we report this as a generic, "Stopped due
12621 to shlib event" message.) */
12622 print_solib_event (0);
12625 case bp_thread_event:
12626 /* Not sure how we will get here.
12627 GDB should not stop for these breakpoints. */
12628 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12631 case bp_overlay_event:
12632 /* By analogy with the thread event, GDB should not stop for these. */
12633 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12636 case bp_longjmp_master:
12637 /* These should never be enabled. */
12638 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12641 case bp_std_terminate_master:
12642 /* These should never be enabled. */
12643 printf_filtered (_("std::terminate Master Breakpoint: "
12644 "gdb should not stop!\n"));
12647 case bp_exception_master:
12648 /* These should never be enabled. */
12649 printf_filtered (_("Exception Master Breakpoint: "
12650 "gdb should not stop!\n"));
12654 return PRINT_NOTHING;
12658 internal_bkpt_print_mention (struct breakpoint *b)
12660 /* Nothing to mention. These breakpoints are internal. */
12663 /* Virtual table for momentary breakpoints */
12666 momentary_bkpt_re_set (struct breakpoint *b)
12668 /* Keep temporary breakpoints, which can be encountered when we step
12669 over a dlopen call and solib_add is resetting the breakpoints.
12670 Otherwise these should have been blown away via the cleanup chain
12671 or by breakpoint_init_inferior when we rerun the executable. */
12675 momentary_bkpt_check_status (bpstat bs)
12677 /* Nothing. The point of these breakpoints is causing a stop. */
12680 static enum print_stop_action
12681 momentary_bkpt_print_it (bpstat bs)
12683 return PRINT_UNKNOWN;
12687 momentary_bkpt_print_mention (struct breakpoint *b)
12689 /* Nothing to mention. These breakpoints are internal. */
12692 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12694 It gets cleared already on the removal of the first one of such placed
12695 breakpoints. This is OK as they get all removed altogether. */
12697 longjmp_breakpoint::~longjmp_breakpoint ()
12699 thread_info *tp = find_thread_global_id (this->thread);
12702 tp->initiating_frame = null_frame_id;
12705 /* Specific methods for probe breakpoints. */
12708 bkpt_probe_insert_location (struct bp_location *bl)
12710 int v = bkpt_insert_location (bl);
12714 /* The insertion was successful, now let's set the probe's semaphore
12716 bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
12723 bkpt_probe_remove_location (struct bp_location *bl,
12724 enum remove_bp_reason reason)
12726 /* Let's clear the semaphore before removing the location. */
12727 bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
12729 return bkpt_remove_location (bl, reason);
12733 bkpt_probe_create_sals_from_location (const struct event_location *location,
12734 struct linespec_result *canonical,
12735 enum bptype type_wanted)
12737 struct linespec_sals lsal;
12739 lsal.sals = parse_probes (location, NULL, canonical);
12741 = xstrdup (event_location_to_string (canonical->location.get ()));
12742 canonical->lsals.push_back (std::move (lsal));
12745 static std::vector<symtab_and_line>
12746 bkpt_probe_decode_location (struct breakpoint *b,
12747 const struct event_location *location,
12748 struct program_space *search_pspace)
12750 std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
12752 error (_("probe not found"));
12756 /* The breakpoint_ops structure to be used in tracepoints. */
12759 tracepoint_re_set (struct breakpoint *b)
12761 breakpoint_re_set_default (b);
12765 tracepoint_breakpoint_hit (const struct bp_location *bl,
12766 const address_space *aspace, CORE_ADDR bp_addr,
12767 const struct target_waitstatus *ws)
12769 /* By definition, the inferior does not report stops at
12775 tracepoint_print_one_detail (const struct breakpoint *self,
12776 struct ui_out *uiout)
12778 struct tracepoint *tp = (struct tracepoint *) self;
12779 if (!tp->static_trace_marker_id.empty ())
12781 gdb_assert (self->type == bp_static_tracepoint);
12783 uiout->text ("\tmarker id is ");
12784 uiout->field_string ("static-tracepoint-marker-string-id",
12785 tp->static_trace_marker_id);
12786 uiout->text ("\n");
12791 tracepoint_print_mention (struct breakpoint *b)
12793 if (current_uiout->is_mi_like_p ())
12798 case bp_tracepoint:
12799 printf_filtered (_("Tracepoint"));
12800 printf_filtered (_(" %d"), b->number);
12802 case bp_fast_tracepoint:
12803 printf_filtered (_("Fast tracepoint"));
12804 printf_filtered (_(" %d"), b->number);
12806 case bp_static_tracepoint:
12807 printf_filtered (_("Static tracepoint"));
12808 printf_filtered (_(" %d"), b->number);
12811 internal_error (__FILE__, __LINE__,
12812 _("unhandled tracepoint type %d"), (int) b->type);
12819 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12821 struct tracepoint *tp = (struct tracepoint *) self;
12823 if (self->type == bp_fast_tracepoint)
12824 fprintf_unfiltered (fp, "ftrace");
12825 else if (self->type == bp_static_tracepoint)
12826 fprintf_unfiltered (fp, "strace");
12827 else if (self->type == bp_tracepoint)
12828 fprintf_unfiltered (fp, "trace");
12830 internal_error (__FILE__, __LINE__,
12831 _("unhandled tracepoint type %d"), (int) self->type);
12833 fprintf_unfiltered (fp, " %s",
12834 event_location_to_string (self->location.get ()));
12835 print_recreate_thread (self, fp);
12837 if (tp->pass_count)
12838 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12842 tracepoint_create_sals_from_location (const struct event_location *location,
12843 struct linespec_result *canonical,
12844 enum bptype type_wanted)
12846 create_sals_from_location_default (location, canonical, type_wanted);
12850 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12851 struct linespec_result *canonical,
12852 gdb::unique_xmalloc_ptr<char> cond_string,
12853 gdb::unique_xmalloc_ptr<char> extra_string,
12854 enum bptype type_wanted,
12855 enum bpdisp disposition,
12857 int task, int ignore_count,
12858 const struct breakpoint_ops *ops,
12859 int from_tty, int enabled,
12860 int internal, unsigned flags)
12862 create_breakpoints_sal_default (gdbarch, canonical,
12863 std::move (cond_string),
12864 std::move (extra_string),
12866 disposition, thread, task,
12867 ignore_count, ops, from_tty,
12868 enabled, internal, flags);
12871 static std::vector<symtab_and_line>
12872 tracepoint_decode_location (struct breakpoint *b,
12873 const struct event_location *location,
12874 struct program_space *search_pspace)
12876 return decode_location_default (b, location, search_pspace);
12879 struct breakpoint_ops tracepoint_breakpoint_ops;
12881 /* The breakpoint_ops structure to be use on tracepoints placed in a
12885 tracepoint_probe_create_sals_from_location
12886 (const struct event_location *location,
12887 struct linespec_result *canonical,
12888 enum bptype type_wanted)
12890 /* We use the same method for breakpoint on probes. */
12891 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
12894 static std::vector<symtab_and_line>
12895 tracepoint_probe_decode_location (struct breakpoint *b,
12896 const struct event_location *location,
12897 struct program_space *search_pspace)
12899 /* We use the same method for breakpoint on probes. */
12900 return bkpt_probe_decode_location (b, location, search_pspace);
12903 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
12905 /* Dprintf breakpoint_ops methods. */
12908 dprintf_re_set (struct breakpoint *b)
12910 breakpoint_re_set_default (b);
12912 /* extra_string should never be non-NULL for dprintf. */
12913 gdb_assert (b->extra_string != NULL);
12915 /* 1 - connect to target 1, that can run breakpoint commands.
12916 2 - create a dprintf, which resolves fine.
12917 3 - disconnect from target 1
12918 4 - connect to target 2, that can NOT run breakpoint commands.
12920 After steps #3/#4, you'll want the dprintf command list to
12921 be updated, because target 1 and 2 may well return different
12922 answers for target_can_run_breakpoint_commands().
12923 Given absence of finer grained resetting, we get to do
12924 it all the time. */
12925 if (b->extra_string != NULL)
12926 update_dprintf_command_list (b);
12929 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12932 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12934 fprintf_unfiltered (fp, "dprintf %s,%s",
12935 event_location_to_string (tp->location.get ()),
12937 print_recreate_thread (tp, fp);
12940 /* Implement the "after_condition_true" breakpoint_ops method for
12943 dprintf's are implemented with regular commands in their command
12944 list, but we run the commands here instead of before presenting the
12945 stop to the user, as dprintf's don't actually cause a stop. This
12946 also makes it so that the commands of multiple dprintfs at the same
12947 address are all handled. */
12950 dprintf_after_condition_true (struct bpstats *bs)
12952 struct bpstats tmp_bs;
12953 struct bpstats *tmp_bs_p = &tmp_bs;
12955 /* dprintf's never cause a stop. This wasn't set in the
12956 check_status hook instead because that would make the dprintf's
12957 condition not be evaluated. */
12960 /* Run the command list here. Take ownership of it instead of
12961 copying. We never want these commands to run later in
12962 bpstat_do_actions, if a breakpoint that causes a stop happens to
12963 be set at same address as this dprintf, or even if running the
12964 commands here throws. */
12965 tmp_bs.commands = bs->commands;
12966 bs->commands = NULL;
12968 bpstat_do_actions_1 (&tmp_bs_p);
12970 /* 'tmp_bs.commands' will usually be NULL by now, but
12971 bpstat_do_actions_1 may return early without processing the whole
12975 /* The breakpoint_ops structure to be used on static tracepoints with
12979 strace_marker_create_sals_from_location (const struct event_location *location,
12980 struct linespec_result *canonical,
12981 enum bptype type_wanted)
12983 struct linespec_sals lsal;
12984 const char *arg_start, *arg;
12986 arg = arg_start = get_linespec_location (location)->spec_string;
12987 lsal.sals = decode_static_tracepoint_spec (&arg);
12989 std::string str (arg_start, arg - arg_start);
12990 const char *ptr = str.c_str ();
12991 canonical->location
12992 = new_linespec_location (&ptr, symbol_name_match_type::FULL);
12995 = xstrdup (event_location_to_string (canonical->location.get ()));
12996 canonical->lsals.push_back (std::move (lsal));
13000 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13001 struct linespec_result *canonical,
13002 gdb::unique_xmalloc_ptr<char> cond_string,
13003 gdb::unique_xmalloc_ptr<char> extra_string,
13004 enum bptype type_wanted,
13005 enum bpdisp disposition,
13007 int task, int ignore_count,
13008 const struct breakpoint_ops *ops,
13009 int from_tty, int enabled,
13010 int internal, unsigned flags)
13012 const linespec_sals &lsal = canonical->lsals[0];
13014 /* If the user is creating a static tracepoint by marker id
13015 (strace -m MARKER_ID), then store the sals index, so that
13016 breakpoint_re_set can try to match up which of the newly
13017 found markers corresponds to this one, and, don't try to
13018 expand multiple locations for each sal, given than SALS
13019 already should contain all sals for MARKER_ID. */
13021 for (size_t i = 0; i < lsal.sals.size (); i++)
13023 event_location_up location
13024 = copy_event_location (canonical->location.get ());
13026 std::unique_ptr<tracepoint> tp (new tracepoint ());
13027 init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i],
13028 std::move (location), NULL,
13029 std::move (cond_string),
13030 std::move (extra_string),
13031 type_wanted, disposition,
13032 thread, task, ignore_count, ops,
13033 from_tty, enabled, internal, flags,
13034 canonical->special_display);
13035 /* Given that its possible to have multiple markers with
13036 the same string id, if the user is creating a static
13037 tracepoint by marker id ("strace -m MARKER_ID"), then
13038 store the sals index, so that breakpoint_re_set can
13039 try to match up which of the newly found markers
13040 corresponds to this one */
13041 tp->static_trace_marker_id_idx = i;
13043 install_breakpoint (internal, std::move (tp), 0);
13047 static std::vector<symtab_and_line>
13048 strace_marker_decode_location (struct breakpoint *b,
13049 const struct event_location *location,
13050 struct program_space *search_pspace)
13052 struct tracepoint *tp = (struct tracepoint *) b;
13053 const char *s = get_linespec_location (location)->spec_string;
13055 std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
13056 if (sals.size () > tp->static_trace_marker_id_idx)
13058 sals[0] = sals[tp->static_trace_marker_id_idx];
13063 error (_("marker %s not found"), tp->static_trace_marker_id.c_str ());
13066 static struct breakpoint_ops strace_marker_breakpoint_ops;
13069 strace_marker_p (struct breakpoint *b)
13071 return b->ops == &strace_marker_breakpoint_ops;
13074 /* Delete a breakpoint and clean up all traces of it in the data
13078 delete_breakpoint (struct breakpoint *bpt)
13080 struct breakpoint *b;
13082 gdb_assert (bpt != NULL);
13084 /* Has this bp already been deleted? This can happen because
13085 multiple lists can hold pointers to bp's. bpstat lists are
13088 One example of this happening is a watchpoint's scope bp. When
13089 the scope bp triggers, we notice that the watchpoint is out of
13090 scope, and delete it. We also delete its scope bp. But the
13091 scope bp is marked "auto-deleting", and is already on a bpstat.
13092 That bpstat is then checked for auto-deleting bp's, which are
13095 A real solution to this problem might involve reference counts in
13096 bp's, and/or giving them pointers back to their referencing
13097 bpstat's, and teaching delete_breakpoint to only free a bp's
13098 storage when no more references were extent. A cheaper bandaid
13100 if (bpt->type == bp_none)
13103 /* At least avoid this stale reference until the reference counting
13104 of breakpoints gets resolved. */
13105 if (bpt->related_breakpoint != bpt)
13107 struct breakpoint *related;
13108 struct watchpoint *w;
13110 if (bpt->type == bp_watchpoint_scope)
13111 w = (struct watchpoint *) bpt->related_breakpoint;
13112 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13113 w = (struct watchpoint *) bpt;
13117 watchpoint_del_at_next_stop (w);
13119 /* Unlink bpt from the bpt->related_breakpoint ring. */
13120 for (related = bpt; related->related_breakpoint != bpt;
13121 related = related->related_breakpoint);
13122 related->related_breakpoint = bpt->related_breakpoint;
13123 bpt->related_breakpoint = bpt;
13126 /* watch_command_1 creates a watchpoint but only sets its number if
13127 update_watchpoint succeeds in creating its bp_locations. If there's
13128 a problem in that process, we'll be asked to delete the half-created
13129 watchpoint. In that case, don't announce the deletion. */
13131 gdb::observers::breakpoint_deleted.notify (bpt);
13133 if (breakpoint_chain == bpt)
13134 breakpoint_chain = bpt->next;
13136 ALL_BREAKPOINTS (b)
13137 if (b->next == bpt)
13139 b->next = bpt->next;
13143 /* Be sure no bpstat's are pointing at the breakpoint after it's
13145 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13146 in all threads for now. Note that we cannot just remove bpstats
13147 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13148 commands are associated with the bpstat; if we remove it here,
13149 then the later call to bpstat_do_actions (&stop_bpstat); in
13150 event-top.c won't do anything, and temporary breakpoints with
13151 commands won't work. */
13153 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13155 /* Now that breakpoint is removed from breakpoint list, update the
13156 global location list. This will remove locations that used to
13157 belong to this breakpoint. Do this before freeing the breakpoint
13158 itself, since remove_breakpoint looks at location's owner. It
13159 might be better design to have location completely
13160 self-contained, but it's not the case now. */
13161 update_global_location_list (UGLL_DONT_INSERT);
13163 /* On the chance that someone will soon try again to delete this
13164 same bp, we mark it as deleted before freeing its storage. */
13165 bpt->type = bp_none;
13169 /* Iterator function to call a user-provided callback function once
13170 for each of B and its related breakpoints. */
13173 iterate_over_related_breakpoints (struct breakpoint *b,
13174 gdb::function_view<void (breakpoint *)> function)
13176 struct breakpoint *related;
13181 struct breakpoint *next;
13183 /* FUNCTION may delete RELATED. */
13184 next = related->related_breakpoint;
13186 if (next == related)
13188 /* RELATED is the last ring entry. */
13189 function (related);
13191 /* FUNCTION may have deleted it, so we'd never reach back to
13192 B. There's nothing left to do anyway, so just break
13197 function (related);
13201 while (related != b);
13205 delete_command (const char *arg, int from_tty)
13207 struct breakpoint *b, *b_tmp;
13213 int breaks_to_delete = 0;
13215 /* Delete all breakpoints if no argument. Do not delete
13216 internal breakpoints, these have to be deleted with an
13217 explicit breakpoint number argument. */
13218 ALL_BREAKPOINTS (b)
13219 if (user_breakpoint_p (b))
13221 breaks_to_delete = 1;
13225 /* Ask user only if there are some breakpoints to delete. */
13227 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13229 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13230 if (user_breakpoint_p (b))
13231 delete_breakpoint (b);
13235 map_breakpoint_numbers
13236 (arg, [&] (breakpoint *br)
13238 iterate_over_related_breakpoints (br, delete_breakpoint);
13242 /* Return true if all locations of B bound to PSPACE are pending. If
13243 PSPACE is NULL, all locations of all program spaces are
13247 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
13249 struct bp_location *loc;
13251 for (loc = b->loc; loc != NULL; loc = loc->next)
13252 if ((pspace == NULL
13253 || loc->pspace == pspace)
13254 && !loc->shlib_disabled
13255 && !loc->pspace->executing_startup)
13260 /* Subroutine of update_breakpoint_locations to simplify it.
13261 Return non-zero if multiple fns in list LOC have the same name.
13262 Null names are ignored. */
13265 ambiguous_names_p (struct bp_location *loc)
13267 struct bp_location *l;
13268 htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL,
13271 for (l = loc; l != NULL; l = l->next)
13274 const char *name = l->function_name;
13276 /* Allow for some names to be NULL, ignore them. */
13280 slot = (const char **) htab_find_slot (htab, (const void *) name,
13282 /* NOTE: We can assume slot != NULL here because xcalloc never
13286 htab_delete (htab);
13292 htab_delete (htab);
13296 /* When symbols change, it probably means the sources changed as well,
13297 and it might mean the static tracepoint markers are no longer at
13298 the same address or line numbers they used to be at last we
13299 checked. Losing your static tracepoints whenever you rebuild is
13300 undesirable. This function tries to resync/rematch gdb static
13301 tracepoints with the markers on the target, for static tracepoints
13302 that have not been set by marker id. Static tracepoint that have
13303 been set by marker id are reset by marker id in breakpoint_re_set.
13306 1) For a tracepoint set at a specific address, look for a marker at
13307 the old PC. If one is found there, assume to be the same marker.
13308 If the name / string id of the marker found is different from the
13309 previous known name, assume that means the user renamed the marker
13310 in the sources, and output a warning.
13312 2) For a tracepoint set at a given line number, look for a marker
13313 at the new address of the old line number. If one is found there,
13314 assume to be the same marker. If the name / string id of the
13315 marker found is different from the previous known name, assume that
13316 means the user renamed the marker in the sources, and output a
13319 3) If a marker is no longer found at the same address or line, it
13320 may mean the marker no longer exists. But it may also just mean
13321 the code changed a bit. Maybe the user added a few lines of code
13322 that made the marker move up or down (in line number terms). Ask
13323 the target for info about the marker with the string id as we knew
13324 it. If found, update line number and address in the matching
13325 static tracepoint. This will get confused if there's more than one
13326 marker with the same ID (possible in UST, although unadvised
13327 precisely because it confuses tools). */
13329 static struct symtab_and_line
13330 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13332 struct tracepoint *tp = (struct tracepoint *) b;
13333 struct static_tracepoint_marker marker;
13338 find_line_pc (sal.symtab, sal.line, &pc);
13340 if (target_static_tracepoint_marker_at (pc, &marker))
13342 if (tp->static_trace_marker_id != marker.str_id)
13343 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13344 b->number, tp->static_trace_marker_id.c_str (),
13345 marker.str_id.c_str ());
13347 tp->static_trace_marker_id = std::move (marker.str_id);
13352 /* Old marker wasn't found on target at lineno. Try looking it up
13354 if (!sal.explicit_pc
13356 && sal.symtab != NULL
13357 && !tp->static_trace_marker_id.empty ())
13359 std::vector<static_tracepoint_marker> markers
13360 = target_static_tracepoint_markers_by_strid
13361 (tp->static_trace_marker_id.c_str ());
13363 if (!markers.empty ())
13365 struct symbol *sym;
13366 struct static_tracepoint_marker *tpmarker;
13367 struct ui_out *uiout = current_uiout;
13368 struct explicit_location explicit_loc;
13370 tpmarker = &markers[0];
13372 tp->static_trace_marker_id = std::move (tpmarker->str_id);
13374 warning (_("marker for static tracepoint %d (%s) not "
13375 "found at previous line number"),
13376 b->number, tp->static_trace_marker_id.c_str ());
13378 symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
13379 sym = find_pc_sect_function (tpmarker->address, NULL);
13380 uiout->text ("Now in ");
13383 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
13384 ui_out_style_kind::FUNCTION);
13385 uiout->text (" at ");
13387 uiout->field_string ("file",
13388 symtab_to_filename_for_display (sal2.symtab),
13389 ui_out_style_kind::FILE);
13392 if (uiout->is_mi_like_p ())
13394 const char *fullname = symtab_to_fullname (sal2.symtab);
13396 uiout->field_string ("fullname", fullname);
13399 uiout->field_int ("line", sal2.line);
13400 uiout->text ("\n");
13402 b->loc->line_number = sal2.line;
13403 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13405 b->location.reset (NULL);
13406 initialize_explicit_location (&explicit_loc);
13407 explicit_loc.source_filename
13408 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
13409 explicit_loc.line_offset.offset = b->loc->line_number;
13410 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
13411 b->location = new_explicit_location (&explicit_loc);
13413 /* Might be nice to check if function changed, and warn if
13420 /* Returns 1 iff locations A and B are sufficiently same that
13421 we don't need to report breakpoint as changed. */
13424 locations_are_equal (struct bp_location *a, struct bp_location *b)
13428 if (a->address != b->address)
13431 if (a->shlib_disabled != b->shlib_disabled)
13434 if (a->enabled != b->enabled)
13441 if ((a == NULL) != (b == NULL))
13447 /* Split all locations of B that are bound to PSPACE out of B's
13448 location list to a separate list and return that list's head. If
13449 PSPACE is NULL, hoist out all locations of B. */
13451 static struct bp_location *
13452 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
13454 struct bp_location head;
13455 struct bp_location *i = b->loc;
13456 struct bp_location **i_link = &b->loc;
13457 struct bp_location *hoisted = &head;
13459 if (pspace == NULL)
13470 if (i->pspace == pspace)
13485 /* Create new breakpoint locations for B (a hardware or software
13486 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13487 zero, then B is a ranged breakpoint. Only recreates locations for
13488 FILTER_PSPACE. Locations of other program spaces are left
13492 update_breakpoint_locations (struct breakpoint *b,
13493 struct program_space *filter_pspace,
13494 gdb::array_view<const symtab_and_line> sals,
13495 gdb::array_view<const symtab_and_line> sals_end)
13497 struct bp_location *existing_locations;
13499 if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
13501 /* Ranged breakpoints have only one start location and one end
13503 b->enable_state = bp_disabled;
13504 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13505 "multiple locations found\n"),
13510 /* If there's no new locations, and all existing locations are
13511 pending, don't do anything. This optimizes the common case where
13512 all locations are in the same shared library, that was unloaded.
13513 We'd like to retain the location, so that when the library is
13514 loaded again, we don't loose the enabled/disabled status of the
13515 individual locations. */
13516 if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
13519 existing_locations = hoist_existing_locations (b, filter_pspace);
13521 for (const auto &sal : sals)
13523 struct bp_location *new_loc;
13525 switch_to_program_space_and_thread (sal.pspace);
13527 new_loc = add_location_to_breakpoint (b, &sal);
13529 /* Reparse conditions, they might contain references to the
13531 if (b->cond_string != NULL)
13535 s = b->cond_string;
13538 new_loc->cond = parse_exp_1 (&s, sal.pc,
13539 block_for_pc (sal.pc),
13542 CATCH (e, RETURN_MASK_ERROR)
13544 warning (_("failed to reevaluate condition "
13545 "for breakpoint %d: %s"),
13546 b->number, e.message);
13547 new_loc->enabled = 0;
13552 if (!sals_end.empty ())
13554 CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
13556 new_loc->length = end - sals[0].pc + 1;
13560 /* If possible, carry over 'disable' status from existing
13563 struct bp_location *e = existing_locations;
13564 /* If there are multiple breakpoints with the same function name,
13565 e.g. for inline functions, comparing function names won't work.
13566 Instead compare pc addresses; this is just a heuristic as things
13567 may have moved, but in practice it gives the correct answer
13568 often enough until a better solution is found. */
13569 int have_ambiguous_names = ambiguous_names_p (b->loc);
13571 for (; e; e = e->next)
13573 if (!e->enabled && e->function_name)
13575 struct bp_location *l = b->loc;
13576 if (have_ambiguous_names)
13578 for (; l; l = l->next)
13579 if (breakpoint_locations_match (e, l))
13587 for (; l; l = l->next)
13588 if (l->function_name
13589 && strcmp (e->function_name, l->function_name) == 0)
13599 if (!locations_are_equal (existing_locations, b->loc))
13600 gdb::observers::breakpoint_modified.notify (b);
13603 /* Find the SaL locations corresponding to the given LOCATION.
13604 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13606 static std::vector<symtab_and_line>
13607 location_to_sals (struct breakpoint *b, struct event_location *location,
13608 struct program_space *search_pspace, int *found)
13610 struct gdb_exception exception = exception_none;
13612 gdb_assert (b->ops != NULL);
13614 std::vector<symtab_and_line> sals;
13618 sals = b->ops->decode_location (b, location, search_pspace);
13620 CATCH (e, RETURN_MASK_ERROR)
13622 int not_found_and_ok = 0;
13626 /* For pending breakpoints, it's expected that parsing will
13627 fail until the right shared library is loaded. User has
13628 already told to create pending breakpoints and don't need
13629 extra messages. If breakpoint is in bp_shlib_disabled
13630 state, then user already saw the message about that
13631 breakpoint being disabled, and don't want to see more
13633 if (e.error == NOT_FOUND_ERROR
13634 && (b->condition_not_parsed
13636 && search_pspace != NULL
13637 && b->loc->pspace != search_pspace)
13638 || (b->loc && b->loc->shlib_disabled)
13639 || (b->loc && b->loc->pspace->executing_startup)
13640 || b->enable_state == bp_disabled))
13641 not_found_and_ok = 1;
13643 if (!not_found_and_ok)
13645 /* We surely don't want to warn about the same breakpoint
13646 10 times. One solution, implemented here, is disable
13647 the breakpoint on error. Another solution would be to
13648 have separate 'warning emitted' flag. Since this
13649 happens only when a binary has changed, I don't know
13650 which approach is better. */
13651 b->enable_state = bp_disabled;
13652 throw_exception (e);
13657 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
13659 for (auto &sal : sals)
13660 resolve_sal_pc (&sal);
13661 if (b->condition_not_parsed && b->extra_string != NULL)
13663 char *cond_string, *extra_string;
13666 find_condition_and_thread (b->extra_string, sals[0].pc,
13667 &cond_string, &thread, &task,
13669 gdb_assert (b->cond_string == NULL);
13671 b->cond_string = cond_string;
13672 b->thread = thread;
13676 xfree (b->extra_string);
13677 b->extra_string = extra_string;
13679 b->condition_not_parsed = 0;
13682 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13683 sals[0] = update_static_tracepoint (b, sals[0]);
13693 /* The default re_set method, for typical hardware or software
13694 breakpoints. Reevaluate the breakpoint and recreate its
13698 breakpoint_re_set_default (struct breakpoint *b)
13700 struct program_space *filter_pspace = current_program_space;
13701 std::vector<symtab_and_line> expanded, expanded_end;
13704 std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
13705 filter_pspace, &found);
13707 expanded = std::move (sals);
13709 if (b->location_range_end != NULL)
13711 std::vector<symtab_and_line> sals_end
13712 = location_to_sals (b, b->location_range_end.get (),
13713 filter_pspace, &found);
13715 expanded_end = std::move (sals_end);
13718 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
13721 /* Default method for creating SALs from an address string. It basically
13722 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13725 create_sals_from_location_default (const struct event_location *location,
13726 struct linespec_result *canonical,
13727 enum bptype type_wanted)
13729 parse_breakpoint_sals (location, canonical);
13732 /* Call create_breakpoints_sal for the given arguments. This is the default
13733 function for the `create_breakpoints_sal' method of
13737 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13738 struct linespec_result *canonical,
13739 gdb::unique_xmalloc_ptr<char> cond_string,
13740 gdb::unique_xmalloc_ptr<char> extra_string,
13741 enum bptype type_wanted,
13742 enum bpdisp disposition,
13744 int task, int ignore_count,
13745 const struct breakpoint_ops *ops,
13746 int from_tty, int enabled,
13747 int internal, unsigned flags)
13749 create_breakpoints_sal (gdbarch, canonical,
13750 std::move (cond_string),
13751 std::move (extra_string),
13752 type_wanted, disposition,
13753 thread, task, ignore_count, ops, from_tty,
13754 enabled, internal, flags);
13757 /* Decode the line represented by S by calling decode_line_full. This is the
13758 default function for the `decode_location' method of breakpoint_ops. */
13760 static std::vector<symtab_and_line>
13761 decode_location_default (struct breakpoint *b,
13762 const struct event_location *location,
13763 struct program_space *search_pspace)
13765 struct linespec_result canonical;
13767 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
13768 (struct symtab *) NULL, 0,
13769 &canonical, multiple_symbols_all,
13772 /* We should get 0 or 1 resulting SALs. */
13773 gdb_assert (canonical.lsals.size () < 2);
13775 if (!canonical.lsals.empty ())
13777 const linespec_sals &lsal = canonical.lsals[0];
13778 return std::move (lsal.sals);
13783 /* Reset a breakpoint. */
13786 breakpoint_re_set_one (breakpoint *b)
13788 input_radix = b->input_radix;
13789 set_language (b->language);
13791 b->ops->re_set (b);
13794 /* Re-set breakpoint locations for the current program space.
13795 Locations bound to other program spaces are left untouched. */
13798 breakpoint_re_set (void)
13800 struct breakpoint *b, *b_tmp;
13803 scoped_restore_current_language save_language;
13804 scoped_restore save_input_radix = make_scoped_restore (&input_radix);
13805 scoped_restore_current_pspace_and_thread restore_pspace_thread;
13807 /* breakpoint_re_set_one sets the current_language to the language
13808 of the breakpoint it is resetting (see prepare_re_set_context)
13809 before re-evaluating the breakpoint's location. This change can
13810 unfortunately get undone by accident if the language_mode is set
13811 to auto, and we either switch frames, or more likely in this context,
13812 we select the current frame.
13814 We prevent this by temporarily turning the language_mode to
13815 language_mode_manual. We restore it once all breakpoints
13816 have been reset. */
13817 scoped_restore save_language_mode = make_scoped_restore (&language_mode);
13818 language_mode = language_mode_manual;
13820 /* Note: we must not try to insert locations until after all
13821 breakpoints have been re-set. Otherwise, e.g., when re-setting
13822 breakpoint 1, we'd insert the locations of breakpoint 2, which
13823 hadn't been re-set yet, and thus may have stale locations. */
13825 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13829 breakpoint_re_set_one (b);
13831 CATCH (ex, RETURN_MASK_ALL)
13833 exception_fprintf (gdb_stderr, ex,
13834 "Error in re-setting breakpoint %d: ",
13840 jit_breakpoint_re_set ();
13843 create_overlay_event_breakpoint ();
13844 create_longjmp_master_breakpoint ();
13845 create_std_terminate_master_breakpoint ();
13846 create_exception_master_breakpoint ();
13848 /* Now we can insert. */
13849 update_global_location_list (UGLL_MAY_INSERT);
13852 /* Reset the thread number of this breakpoint:
13854 - If the breakpoint is for all threads, leave it as-is.
13855 - Else, reset it to the current thread for inferior_ptid. */
13857 breakpoint_re_set_thread (struct breakpoint *b)
13859 if (b->thread != -1)
13861 b->thread = inferior_thread ()->global_num;
13863 /* We're being called after following a fork. The new fork is
13864 selected as current, and unless this was a vfork will have a
13865 different program space from the original thread. Reset that
13867 b->loc->pspace = current_program_space;
13871 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13872 If from_tty is nonzero, it prints a message to that effect,
13873 which ends with a period (no newline). */
13876 set_ignore_count (int bptnum, int count, int from_tty)
13878 struct breakpoint *b;
13883 ALL_BREAKPOINTS (b)
13884 if (b->number == bptnum)
13886 if (is_tracepoint (b))
13888 if (from_tty && count != 0)
13889 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13894 b->ignore_count = count;
13898 printf_filtered (_("Will stop next time "
13899 "breakpoint %d is reached."),
13901 else if (count == 1)
13902 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13905 printf_filtered (_("Will ignore next %d "
13906 "crossings of breakpoint %d."),
13909 gdb::observers::breakpoint_modified.notify (b);
13913 error (_("No breakpoint number %d."), bptnum);
13916 /* Command to set ignore-count of breakpoint N to COUNT. */
13919 ignore_command (const char *args, int from_tty)
13921 const char *p = args;
13925 error_no_arg (_("a breakpoint number"));
13927 num = get_number (&p);
13929 error (_("bad breakpoint number: '%s'"), args);
13931 error (_("Second argument (specified ignore-count) is missing."));
13933 set_ignore_count (num,
13934 longest_to_int (value_as_long (parse_and_eval (p))),
13937 printf_filtered ("\n");
13941 /* Call FUNCTION on each of the breakpoints with numbers in the range
13942 defined by BP_NUM_RANGE (an inclusive range). */
13945 map_breakpoint_number_range (std::pair<int, int> bp_num_range,
13946 gdb::function_view<void (breakpoint *)> function)
13948 if (bp_num_range.first == 0)
13950 warning (_("bad breakpoint number at or near '%d'"),
13951 bp_num_range.first);
13955 struct breakpoint *b, *tmp;
13957 for (int i = bp_num_range.first; i <= bp_num_range.second; i++)
13959 bool match = false;
13961 ALL_BREAKPOINTS_SAFE (b, tmp)
13962 if (b->number == i)
13969 printf_unfiltered (_("No breakpoint number %d.\n"), i);
13974 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13978 map_breakpoint_numbers (const char *args,
13979 gdb::function_view<void (breakpoint *)> function)
13981 if (args == NULL || *args == '\0')
13982 error_no_arg (_("one or more breakpoint numbers"));
13984 number_or_range_parser parser (args);
13986 while (!parser.finished ())
13988 int num = parser.get_number ();
13989 map_breakpoint_number_range (std::make_pair (num, num), function);
13993 /* Return the breakpoint location structure corresponding to the
13994 BP_NUM and LOC_NUM values. */
13996 static struct bp_location *
13997 find_location_by_number (int bp_num, int loc_num)
13999 struct breakpoint *b;
14001 ALL_BREAKPOINTS (b)
14002 if (b->number == bp_num)
14007 if (!b || b->number != bp_num)
14008 error (_("Bad breakpoint number '%d'"), bp_num);
14011 error (_("Bad breakpoint location number '%d'"), loc_num);
14014 for (bp_location *loc = b->loc; loc != NULL; loc = loc->next)
14015 if (++n == loc_num)
14018 error (_("Bad breakpoint location number '%d'"), loc_num);
14021 /* Modes of operation for extract_bp_num. */
14022 enum class extract_bp_kind
14024 /* Extracting a breakpoint number. */
14027 /* Extracting a location number. */
14031 /* Extract a breakpoint or location number (as determined by KIND)
14032 from the string starting at START. TRAILER is a character which
14033 can be found after the number. If you don't want a trailer, use
14034 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14035 string. This always returns a positive integer. */
14038 extract_bp_num (extract_bp_kind kind, const char *start,
14039 int trailer, const char **end_out = NULL)
14041 const char *end = start;
14042 int num = get_number_trailer (&end, trailer);
14044 error (kind == extract_bp_kind::bp
14045 ? _("Negative breakpoint number '%.*s'")
14046 : _("Negative breakpoint location number '%.*s'"),
14047 int (end - start), start);
14049 error (kind == extract_bp_kind::bp
14050 ? _("Bad breakpoint number '%.*s'")
14051 : _("Bad breakpoint location number '%.*s'"),
14052 int (end - start), start);
14054 if (end_out != NULL)
14059 /* Extract a breakpoint or location range (as determined by KIND) in
14060 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14061 representing the (inclusive) range. The returned pair's elements
14062 are always positive integers. */
14064 static std::pair<int, int>
14065 extract_bp_or_bp_range (extract_bp_kind kind,
14066 const std::string &arg,
14067 std::string::size_type arg_offset)
14069 std::pair<int, int> range;
14070 const char *bp_loc = &arg[arg_offset];
14071 std::string::size_type dash = arg.find ('-', arg_offset);
14072 if (dash != std::string::npos)
14074 /* bp_loc is a range (x-z). */
14075 if (arg.length () == dash + 1)
14076 error (kind == extract_bp_kind::bp
14077 ? _("Bad breakpoint number at or near: '%s'")
14078 : _("Bad breakpoint location number at or near: '%s'"),
14082 const char *start_first = bp_loc;
14083 const char *start_second = &arg[dash + 1];
14084 range.first = extract_bp_num (kind, start_first, '-');
14085 range.second = extract_bp_num (kind, start_second, '\0', &end);
14087 if (range.first > range.second)
14088 error (kind == extract_bp_kind::bp
14089 ? _("Inverted breakpoint range at '%.*s'")
14090 : _("Inverted breakpoint location range at '%.*s'"),
14091 int (end - start_first), start_first);
14095 /* bp_loc is a single value. */
14096 range.first = extract_bp_num (kind, bp_loc, '\0');
14097 range.second = range.first;
14102 /* Extract the breakpoint/location range specified by ARG. Returns
14103 the breakpoint range in BP_NUM_RANGE, and the location range in
14106 ARG may be in any of the following forms:
14108 x where 'x' is a breakpoint number.
14109 x-y where 'x' and 'y' specify a breakpoint numbers range.
14110 x.y where 'x' is a breakpoint number and 'y' a location number.
14111 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14112 location number range.
14116 extract_bp_number_and_location (const std::string &arg,
14117 std::pair<int, int> &bp_num_range,
14118 std::pair<int, int> &bp_loc_range)
14120 std::string::size_type dot = arg.find ('.');
14122 if (dot != std::string::npos)
14124 /* Handle 'x.y' and 'x.y-z' cases. */
14126 if (arg.length () == dot + 1 || dot == 0)
14127 error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ());
14130 = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.');
14131 bp_num_range.second = bp_num_range.first;
14133 bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc,
14138 /* Handle x and x-y cases. */
14140 bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0);
14141 bp_loc_range.first = 0;
14142 bp_loc_range.second = 0;
14146 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14147 specifies whether to enable or disable. */
14150 enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
14152 struct bp_location *loc = find_location_by_number (bp_num, loc_num);
14155 if (loc->enabled != enable)
14157 loc->enabled = enable;
14158 mark_breakpoint_location_modified (loc);
14160 if (target_supports_enable_disable_tracepoint ()
14161 && current_trace_status ()->running && loc->owner
14162 && is_tracepoint (loc->owner))
14163 target_disable_tracepoint (loc);
14165 update_global_location_list (UGLL_DONT_INSERT);
14167 gdb::observers::breakpoint_modified.notify (loc->owner);
14170 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14171 number of the breakpoint, and BP_LOC_RANGE specifies the
14172 (inclusive) range of location numbers of that breakpoint to
14173 enable/disable. ENABLE specifies whether to enable or disable the
14177 enable_disable_breakpoint_location_range (int bp_num,
14178 std::pair<int, int> &bp_loc_range,
14181 for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++)
14182 enable_disable_bp_num_loc (bp_num, i, enable);
14185 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14186 If from_tty is nonzero, it prints a message to that effect,
14187 which ends with a period (no newline). */
14190 disable_breakpoint (struct breakpoint *bpt)
14192 /* Never disable a watchpoint scope breakpoint; we want to
14193 hit them when we leave scope so we can delete both the
14194 watchpoint and its scope breakpoint at that time. */
14195 if (bpt->type == bp_watchpoint_scope)
14198 bpt->enable_state = bp_disabled;
14200 /* Mark breakpoint locations modified. */
14201 mark_breakpoint_modified (bpt);
14203 if (target_supports_enable_disable_tracepoint ()
14204 && current_trace_status ()->running && is_tracepoint (bpt))
14206 struct bp_location *location;
14208 for (location = bpt->loc; location; location = location->next)
14209 target_disable_tracepoint (location);
14212 update_global_location_list (UGLL_DONT_INSERT);
14214 gdb::observers::breakpoint_modified.notify (bpt);
14217 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14218 specified in ARGS. ARGS may be in any of the formats handled by
14219 extract_bp_number_and_location. ENABLE specifies whether to enable
14220 or disable the breakpoints/locations. */
14223 enable_disable_command (const char *args, int from_tty, bool enable)
14227 struct breakpoint *bpt;
14229 ALL_BREAKPOINTS (bpt)
14230 if (user_breakpoint_p (bpt))
14233 enable_breakpoint (bpt);
14235 disable_breakpoint (bpt);
14240 std::string num = extract_arg (&args);
14242 while (!num.empty ())
14244 std::pair<int, int> bp_num_range, bp_loc_range;
14246 extract_bp_number_and_location (num, bp_num_range, bp_loc_range);
14248 if (bp_loc_range.first == bp_loc_range.second
14249 && bp_loc_range.first == 0)
14251 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14252 map_breakpoint_number_range (bp_num_range,
14254 ? enable_breakpoint
14255 : disable_breakpoint);
14259 /* Handle breakpoint ids with formats 'x.y' or
14261 enable_disable_breakpoint_location_range
14262 (bp_num_range.first, bp_loc_range, enable);
14264 num = extract_arg (&args);
14269 /* The disable command disables the specified breakpoints/locations
14270 (or all defined breakpoints) so they're no longer effective in
14271 stopping the inferior. ARGS may be in any of the forms defined in
14272 extract_bp_number_and_location. */
14275 disable_command (const char *args, int from_tty)
14277 enable_disable_command (args, from_tty, false);
14281 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14284 int target_resources_ok;
14286 if (bpt->type == bp_hardware_breakpoint)
14289 i = hw_breakpoint_used_count ();
14290 target_resources_ok =
14291 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14293 if (target_resources_ok == 0)
14294 error (_("No hardware breakpoint support in the target."));
14295 else if (target_resources_ok < 0)
14296 error (_("Hardware breakpoints used exceeds limit."));
14299 if (is_watchpoint (bpt))
14301 /* Initialize it just to avoid a GCC false warning. */
14302 enum enable_state orig_enable_state = bp_disabled;
14306 struct watchpoint *w = (struct watchpoint *) bpt;
14308 orig_enable_state = bpt->enable_state;
14309 bpt->enable_state = bp_enabled;
14310 update_watchpoint (w, 1 /* reparse */);
14312 CATCH (e, RETURN_MASK_ALL)
14314 bpt->enable_state = orig_enable_state;
14315 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14322 bpt->enable_state = bp_enabled;
14324 /* Mark breakpoint locations modified. */
14325 mark_breakpoint_modified (bpt);
14327 if (target_supports_enable_disable_tracepoint ()
14328 && current_trace_status ()->running && is_tracepoint (bpt))
14330 struct bp_location *location;
14332 for (location = bpt->loc; location; location = location->next)
14333 target_enable_tracepoint (location);
14336 bpt->disposition = disposition;
14337 bpt->enable_count = count;
14338 update_global_location_list (UGLL_MAY_INSERT);
14340 gdb::observers::breakpoint_modified.notify (bpt);
14345 enable_breakpoint (struct breakpoint *bpt)
14347 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14350 /* The enable command enables the specified breakpoints/locations (or
14351 all defined breakpoints) so they once again become (or continue to
14352 be) effective in stopping the inferior. ARGS may be in any of the
14353 forms defined in extract_bp_number_and_location. */
14356 enable_command (const char *args, int from_tty)
14358 enable_disable_command (args, from_tty, true);
14362 enable_once_command (const char *args, int from_tty)
14364 map_breakpoint_numbers
14365 (args, [&] (breakpoint *b)
14367 iterate_over_related_breakpoints
14368 (b, [&] (breakpoint *bpt)
14370 enable_breakpoint_disp (bpt, disp_disable, 1);
14376 enable_count_command (const char *args, int from_tty)
14381 error_no_arg (_("hit count"));
14383 count = get_number (&args);
14385 map_breakpoint_numbers
14386 (args, [&] (breakpoint *b)
14388 iterate_over_related_breakpoints
14389 (b, [&] (breakpoint *bpt)
14391 enable_breakpoint_disp (bpt, disp_disable, count);
14397 enable_delete_command (const char *args, int from_tty)
14399 map_breakpoint_numbers
14400 (args, [&] (breakpoint *b)
14402 iterate_over_related_breakpoints
14403 (b, [&] (breakpoint *bpt)
14405 enable_breakpoint_disp (bpt, disp_del, 1);
14411 set_breakpoint_cmd (const char *args, int from_tty)
14416 show_breakpoint_cmd (const char *args, int from_tty)
14420 /* Invalidate last known value of any hardware watchpoint if
14421 the memory which that value represents has been written to by
14425 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14426 CORE_ADDR addr, ssize_t len,
14427 const bfd_byte *data)
14429 struct breakpoint *bp;
14431 ALL_BREAKPOINTS (bp)
14432 if (bp->enable_state == bp_enabled
14433 && bp->type == bp_hardware_watchpoint)
14435 struct watchpoint *wp = (struct watchpoint *) bp;
14437 if (wp->val_valid && wp->val != nullptr)
14439 struct bp_location *loc;
14441 for (loc = bp->loc; loc != NULL; loc = loc->next)
14442 if (loc->loc_type == bp_loc_hardware_watchpoint
14443 && loc->address + loc->length > addr
14444 && addr + len > loc->address)
14453 /* Create and insert a breakpoint for software single step. */
14456 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14457 const address_space *aspace,
14460 struct thread_info *tp = inferior_thread ();
14461 struct symtab_and_line sal;
14462 CORE_ADDR pc = next_pc;
14464 if (tp->control.single_step_breakpoints == NULL)
14466 tp->control.single_step_breakpoints
14467 = new_single_step_breakpoint (tp->global_num, gdbarch);
14470 sal = find_pc_line (pc, 0);
14472 sal.section = find_pc_overlay (pc);
14473 sal.explicit_pc = 1;
14474 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
14476 update_global_location_list (UGLL_INSERT);
14479 /* Insert single step breakpoints according to the current state. */
14482 insert_single_step_breakpoints (struct gdbarch *gdbarch)
14484 struct regcache *regcache = get_current_regcache ();
14485 std::vector<CORE_ADDR> next_pcs;
14487 next_pcs = gdbarch_software_single_step (gdbarch, regcache);
14489 if (!next_pcs.empty ())
14491 struct frame_info *frame = get_current_frame ();
14492 const address_space *aspace = get_frame_address_space (frame);
14494 for (CORE_ADDR pc : next_pcs)
14495 insert_single_step_breakpoint (gdbarch, aspace, pc);
14503 /* See breakpoint.h. */
14506 breakpoint_has_location_inserted_here (struct breakpoint *bp,
14507 const address_space *aspace,
14510 struct bp_location *loc;
14512 for (loc = bp->loc; loc != NULL; loc = loc->next)
14514 && breakpoint_location_address_match (loc, aspace, pc))
14520 /* Check whether a software single-step breakpoint is inserted at
14524 single_step_breakpoint_inserted_here_p (const address_space *aspace,
14527 struct breakpoint *bpt;
14529 ALL_BREAKPOINTS (bpt)
14531 if (bpt->type == bp_single_step
14532 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
14538 /* Tracepoint-specific operations. */
14540 /* Set tracepoint count to NUM. */
14542 set_tracepoint_count (int num)
14544 tracepoint_count = num;
14545 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14549 trace_command (const char *arg, int from_tty)
14551 struct breakpoint_ops *ops;
14553 event_location_up location = string_to_event_location (&arg,
14555 if (location != NULL
14556 && event_location_type (location.get ()) == PROBE_LOCATION)
14557 ops = &tracepoint_probe_breakpoint_ops;
14559 ops = &tracepoint_breakpoint_ops;
14561 create_breakpoint (get_current_arch (),
14563 NULL, 0, arg, 1 /* parse arg */,
14565 bp_tracepoint /* type_wanted */,
14566 0 /* Ignore count */,
14567 pending_break_support,
14571 0 /* internal */, 0);
14575 ftrace_command (const char *arg, int from_tty)
14577 event_location_up location = string_to_event_location (&arg,
14579 create_breakpoint (get_current_arch (),
14581 NULL, 0, arg, 1 /* parse arg */,
14583 bp_fast_tracepoint /* type_wanted */,
14584 0 /* Ignore count */,
14585 pending_break_support,
14586 &tracepoint_breakpoint_ops,
14589 0 /* internal */, 0);
14592 /* strace command implementation. Creates a static tracepoint. */
14595 strace_command (const char *arg, int from_tty)
14597 struct breakpoint_ops *ops;
14598 event_location_up location;
14600 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14601 or with a normal static tracepoint. */
14602 if (arg && startswith (arg, "-m") && isspace (arg[2]))
14604 ops = &strace_marker_breakpoint_ops;
14605 location = new_linespec_location (&arg, symbol_name_match_type::FULL);
14609 ops = &tracepoint_breakpoint_ops;
14610 location = string_to_event_location (&arg, current_language);
14613 create_breakpoint (get_current_arch (),
14615 NULL, 0, arg, 1 /* parse arg */,
14617 bp_static_tracepoint /* type_wanted */,
14618 0 /* Ignore count */,
14619 pending_break_support,
14623 0 /* internal */, 0);
14626 /* Set up a fake reader function that gets command lines from a linked
14627 list that was acquired during tracepoint uploading. */
14629 static struct uploaded_tp *this_utp;
14630 static int next_cmd;
14633 read_uploaded_action (void)
14635 char *rslt = nullptr;
14637 if (next_cmd < this_utp->cmd_strings.size ())
14639 rslt = this_utp->cmd_strings[next_cmd].get ();
14646 /* Given information about a tracepoint as recorded on a target (which
14647 can be either a live system or a trace file), attempt to create an
14648 equivalent GDB tracepoint. This is not a reliable process, since
14649 the target does not necessarily have all the information used when
14650 the tracepoint was originally defined. */
14652 struct tracepoint *
14653 create_tracepoint_from_upload (struct uploaded_tp *utp)
14655 const char *addr_str;
14656 char small_buf[100];
14657 struct tracepoint *tp;
14659 if (utp->at_string)
14660 addr_str = utp->at_string.get ();
14663 /* In the absence of a source location, fall back to raw
14664 address. Since there is no way to confirm that the address
14665 means the same thing as when the trace was started, warn the
14667 warning (_("Uploaded tracepoint %d has no "
14668 "source location, using raw address"),
14670 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
14671 addr_str = small_buf;
14674 /* There's not much we can do with a sequence of bytecodes. */
14675 if (utp->cond && !utp->cond_string)
14676 warning (_("Uploaded tracepoint %d condition "
14677 "has no source form, ignoring it"),
14680 event_location_up location = string_to_event_location (&addr_str,
14682 if (!create_breakpoint (get_current_arch (),
14684 utp->cond_string.get (), -1, addr_str,
14685 0 /* parse cond/thread */,
14687 utp->type /* type_wanted */,
14688 0 /* Ignore count */,
14689 pending_break_support,
14690 &tracepoint_breakpoint_ops,
14692 utp->enabled /* enabled */,
14694 CREATE_BREAKPOINT_FLAGS_INSERTED))
14697 /* Get the tracepoint we just created. */
14698 tp = get_tracepoint (tracepoint_count);
14699 gdb_assert (tp != NULL);
14703 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
14706 trace_pass_command (small_buf, 0);
14709 /* If we have uploaded versions of the original commands, set up a
14710 special-purpose "reader" function and call the usual command line
14711 reader, then pass the result to the breakpoint command-setting
14713 if (!utp->cmd_strings.empty ())
14715 counted_command_line cmd_list;
14720 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL);
14722 breakpoint_set_commands (tp, std::move (cmd_list));
14724 else if (!utp->actions.empty ()
14725 || !utp->step_actions.empty ())
14726 warning (_("Uploaded tracepoint %d actions "
14727 "have no source form, ignoring them"),
14730 /* Copy any status information that might be available. */
14731 tp->hit_count = utp->hit_count;
14732 tp->traceframe_usage = utp->traceframe_usage;
14737 /* Print information on tracepoint number TPNUM_EXP, or all if
14741 info_tracepoints_command (const char *args, int from_tty)
14743 struct ui_out *uiout = current_uiout;
14746 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14748 if (num_printed == 0)
14750 if (args == NULL || *args == '\0')
14751 uiout->message ("No tracepoints.\n");
14753 uiout->message ("No tracepoint matching '%s'.\n", args);
14756 default_collect_info ();
14759 /* The 'enable trace' command enables tracepoints.
14760 Not supported by all targets. */
14762 enable_trace_command (const char *args, int from_tty)
14764 enable_command (args, from_tty);
14767 /* The 'disable trace' command disables tracepoints.
14768 Not supported by all targets. */
14770 disable_trace_command (const char *args, int from_tty)
14772 disable_command (args, from_tty);
14775 /* Remove a tracepoint (or all if no argument). */
14777 delete_trace_command (const char *arg, int from_tty)
14779 struct breakpoint *b, *b_tmp;
14785 int breaks_to_delete = 0;
14787 /* Delete all breakpoints if no argument.
14788 Do not delete internal or call-dummy breakpoints, these
14789 have to be deleted with an explicit breakpoint number
14791 ALL_TRACEPOINTS (b)
14792 if (is_tracepoint (b) && user_breakpoint_p (b))
14794 breaks_to_delete = 1;
14798 /* Ask user only if there are some breakpoints to delete. */
14800 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14802 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14803 if (is_tracepoint (b) && user_breakpoint_p (b))
14804 delete_breakpoint (b);
14808 map_breakpoint_numbers
14809 (arg, [&] (breakpoint *br)
14811 iterate_over_related_breakpoints (br, delete_breakpoint);
14815 /* Helper function for trace_pass_command. */
14818 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14820 tp->pass_count = count;
14821 gdb::observers::breakpoint_modified.notify (tp);
14823 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14824 tp->number, count);
14827 /* Set passcount for tracepoint.
14829 First command argument is passcount, second is tracepoint number.
14830 If tracepoint number omitted, apply to most recently defined.
14831 Also accepts special argument "all". */
14834 trace_pass_command (const char *args, int from_tty)
14836 struct tracepoint *t1;
14839 if (args == 0 || *args == 0)
14840 error (_("passcount command requires an "
14841 "argument (count + optional TP num)"));
14843 count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */
14845 args = skip_spaces (args);
14846 if (*args && strncasecmp (args, "all", 3) == 0)
14848 struct breakpoint *b;
14850 args += 3; /* Skip special argument "all". */
14852 error (_("Junk at end of arguments."));
14854 ALL_TRACEPOINTS (b)
14856 t1 = (struct tracepoint *) b;
14857 trace_pass_set_count (t1, count, from_tty);
14860 else if (*args == '\0')
14862 t1 = get_tracepoint_by_number (&args, NULL);
14864 trace_pass_set_count (t1, count, from_tty);
14868 number_or_range_parser parser (args);
14869 while (!parser.finished ())
14871 t1 = get_tracepoint_by_number (&args, &parser);
14873 trace_pass_set_count (t1, count, from_tty);
14878 struct tracepoint *
14879 get_tracepoint (int num)
14881 struct breakpoint *t;
14883 ALL_TRACEPOINTS (t)
14884 if (t->number == num)
14885 return (struct tracepoint *) t;
14890 /* Find the tracepoint with the given target-side number (which may be
14891 different from the tracepoint number after disconnecting and
14894 struct tracepoint *
14895 get_tracepoint_by_number_on_target (int num)
14897 struct breakpoint *b;
14899 ALL_TRACEPOINTS (b)
14901 struct tracepoint *t = (struct tracepoint *) b;
14903 if (t->number_on_target == num)
14910 /* Utility: parse a tracepoint number and look it up in the list.
14911 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14912 If the argument is missing, the most recent tracepoint
14913 (tracepoint_count) is returned. */
14915 struct tracepoint *
14916 get_tracepoint_by_number (const char **arg,
14917 number_or_range_parser *parser)
14919 struct breakpoint *t;
14921 const char *instring = arg == NULL ? NULL : *arg;
14923 if (parser != NULL)
14925 gdb_assert (!parser->finished ());
14926 tpnum = parser->get_number ();
14928 else if (arg == NULL || *arg == NULL || ! **arg)
14929 tpnum = tracepoint_count;
14931 tpnum = get_number (arg);
14935 if (instring && *instring)
14936 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14939 printf_filtered (_("No previous tracepoint\n"));
14943 ALL_TRACEPOINTS (t)
14944 if (t->number == tpnum)
14946 return (struct tracepoint *) t;
14949 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14954 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14956 if (b->thread != -1)
14957 fprintf_unfiltered (fp, " thread %d", b->thread);
14960 fprintf_unfiltered (fp, " task %d", b->task);
14962 fprintf_unfiltered (fp, "\n");
14965 /* Save information on user settable breakpoints (watchpoints, etc) to
14966 a new script file named FILENAME. If FILTER is non-NULL, call it
14967 on each breakpoint and only include the ones for which it returns
14971 save_breakpoints (const char *filename, int from_tty,
14972 int (*filter) (const struct breakpoint *))
14974 struct breakpoint *tp;
14976 int extra_trace_bits = 0;
14978 if (filename == 0 || *filename == 0)
14979 error (_("Argument required (file name in which to save)"));
14981 /* See if we have anything to save. */
14982 ALL_BREAKPOINTS (tp)
14984 /* Skip internal and momentary breakpoints. */
14985 if (!user_breakpoint_p (tp))
14988 /* If we have a filter, only save the breakpoints it accepts. */
14989 if (filter && !filter (tp))
14994 if (is_tracepoint (tp))
14996 extra_trace_bits = 1;
14998 /* We can stop searching. */
15005 warning (_("Nothing to save."));
15009 gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
15013 if (!fp.open (expanded_filename.get (), "w"))
15014 error (_("Unable to open file '%s' for saving (%s)"),
15015 expanded_filename.get (), safe_strerror (errno));
15017 if (extra_trace_bits)
15018 save_trace_state_variables (&fp);
15020 ALL_BREAKPOINTS (tp)
15022 /* Skip internal and momentary breakpoints. */
15023 if (!user_breakpoint_p (tp))
15026 /* If we have a filter, only save the breakpoints it accepts. */
15027 if (filter && !filter (tp))
15030 tp->ops->print_recreate (tp, &fp);
15032 /* Note, we can't rely on tp->number for anything, as we can't
15033 assume the recreated breakpoint numbers will match. Use $bpnum
15036 if (tp->cond_string)
15037 fp.printf (" condition $bpnum %s\n", tp->cond_string);
15039 if (tp->ignore_count)
15040 fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
15042 if (tp->type != bp_dprintf && tp->commands)
15044 fp.puts (" commands\n");
15046 current_uiout->redirect (&fp);
15049 print_command_lines (current_uiout, tp->commands.get (), 2);
15051 CATCH (ex, RETURN_MASK_ALL)
15053 current_uiout->redirect (NULL);
15054 throw_exception (ex);
15058 current_uiout->redirect (NULL);
15059 fp.puts (" end\n");
15062 if (tp->enable_state == bp_disabled)
15063 fp.puts ("disable $bpnum\n");
15065 /* If this is a multi-location breakpoint, check if the locations
15066 should be individually disabled. Watchpoint locations are
15067 special, and not user visible. */
15068 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15070 struct bp_location *loc;
15073 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15075 fp.printf ("disable $bpnum.%d\n", n);
15079 if (extra_trace_bits && *default_collect)
15080 fp.printf ("set default-collect %s\n", default_collect);
15083 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ());
15086 /* The `save breakpoints' command. */
15089 save_breakpoints_command (const char *args, int from_tty)
15091 save_breakpoints (args, from_tty, NULL);
15094 /* The `save tracepoints' command. */
15097 save_tracepoints_command (const char *args, int from_tty)
15099 save_breakpoints (args, from_tty, is_tracepoint);
15102 /* Create a vector of all tracepoints. */
15104 std::vector<breakpoint *>
15105 all_tracepoints (void)
15107 std::vector<breakpoint *> tp_vec;
15108 struct breakpoint *tp;
15110 ALL_TRACEPOINTS (tp)
15112 tp_vec.push_back (tp);
15119 /* This help string is used to consolidate all the help string for specifying
15120 locations used by several commands. */
15122 #define LOCATION_HELP_STRING \
15123 "Linespecs are colon-separated lists of location parameters, such as\n\
15124 source filename, function name, label name, and line number.\n\
15125 Example: To specify the start of a label named \"the_top\" in the\n\
15126 function \"fact\" in the file \"factorial.c\", use\n\
15127 \"factorial.c:fact:the_top\".\n\
15129 Address locations begin with \"*\" and specify an exact address in the\n\
15130 program. Example: To specify the fourth byte past the start function\n\
15131 \"main\", use \"*main + 4\".\n\
15133 Explicit locations are similar to linespecs but use an option/argument\n\
15134 syntax to specify location parameters.\n\
15135 Example: To specify the start of the label named \"the_top\" in the\n\
15136 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15137 -function fact -label the_top\".\n\
15139 By default, a specified function is matched against the program's\n\
15140 functions in all scopes. For C++, this means in all namespaces and\n\
15141 classes. For Ada, this means in all packages. E.g., in C++,\n\
15142 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15143 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15144 specified name as a complete fully-qualified name instead.\n"
15146 /* This help string is used for the break, hbreak, tbreak and thbreak
15147 commands. It is defined as a macro to prevent duplication.
15148 COMMAND should be a string constant containing the name of the
15151 #define BREAK_ARGS_HELP(command) \
15152 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15153 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15154 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15155 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15156 `-probe-dtrace' (for a DTrace probe).\n\
15157 LOCATION may be a linespec, address, or explicit location as described\n\
15160 With no LOCATION, uses current execution address of the selected\n\
15161 stack frame. This is useful for breaking on return to a stack frame.\n\
15163 THREADNUM is the number from \"info threads\".\n\
15164 CONDITION is a boolean expression.\n\
15165 \n" LOCATION_HELP_STRING "\n\
15166 Multiple breakpoints at one place are permitted, and useful if their\n\
15167 conditions are different.\n\
15169 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15171 /* List of subcommands for "catch". */
15172 static struct cmd_list_element *catch_cmdlist;
15174 /* List of subcommands for "tcatch". */
15175 static struct cmd_list_element *tcatch_cmdlist;
15178 add_catch_command (const char *name, const char *docstring,
15179 cmd_const_sfunc_ftype *sfunc,
15180 completer_ftype *completer,
15181 void *user_data_catch,
15182 void *user_data_tcatch)
15184 struct cmd_list_element *command;
15186 command = add_cmd (name, class_breakpoint, docstring,
15188 set_cmd_sfunc (command, sfunc);
15189 set_cmd_context (command, user_data_catch);
15190 set_cmd_completer (command, completer);
15192 command = add_cmd (name, class_breakpoint, docstring,
15194 set_cmd_sfunc (command, sfunc);
15195 set_cmd_context (command, user_data_tcatch);
15196 set_cmd_completer (command, completer);
15200 save_command (const char *arg, int from_tty)
15202 printf_unfiltered (_("\"save\" must be followed by "
15203 "the name of a save subcommand.\n"));
15204 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15207 struct breakpoint *
15208 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15211 struct breakpoint *b, *b_tmp;
15213 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15215 if ((*callback) (b, data))
15222 /* Zero if any of the breakpoint's locations could be a location where
15223 functions have been inlined, nonzero otherwise. */
15226 is_non_inline_function (struct breakpoint *b)
15228 /* The shared library event breakpoint is set on the address of a
15229 non-inline function. */
15230 if (b->type == bp_shlib_event)
15236 /* Nonzero if the specified PC cannot be a location where functions
15237 have been inlined. */
15240 pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
15241 const struct target_waitstatus *ws)
15243 struct breakpoint *b;
15244 struct bp_location *bl;
15246 ALL_BREAKPOINTS (b)
15248 if (!is_non_inline_function (b))
15251 for (bl = b->loc; bl != NULL; bl = bl->next)
15253 if (!bl->shlib_disabled
15254 && bpstat_check_location (bl, aspace, pc, ws))
15262 /* Remove any references to OBJFILE which is going to be freed. */
15265 breakpoint_free_objfile (struct objfile *objfile)
15267 struct bp_location **locp, *loc;
15269 ALL_BP_LOCATIONS (loc, locp)
15270 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15271 loc->symtab = NULL;
15275 initialize_breakpoint_ops (void)
15277 static int initialized = 0;
15279 struct breakpoint_ops *ops;
15285 /* The breakpoint_ops structure to be inherit by all kinds of
15286 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15287 internal and momentary breakpoints, etc.). */
15288 ops = &bkpt_base_breakpoint_ops;
15289 *ops = base_breakpoint_ops;
15290 ops->re_set = bkpt_re_set;
15291 ops->insert_location = bkpt_insert_location;
15292 ops->remove_location = bkpt_remove_location;
15293 ops->breakpoint_hit = bkpt_breakpoint_hit;
15294 ops->create_sals_from_location = bkpt_create_sals_from_location;
15295 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15296 ops->decode_location = bkpt_decode_location;
15298 /* The breakpoint_ops structure to be used in regular breakpoints. */
15299 ops = &bkpt_breakpoint_ops;
15300 *ops = bkpt_base_breakpoint_ops;
15301 ops->re_set = bkpt_re_set;
15302 ops->resources_needed = bkpt_resources_needed;
15303 ops->print_it = bkpt_print_it;
15304 ops->print_mention = bkpt_print_mention;
15305 ops->print_recreate = bkpt_print_recreate;
15307 /* Ranged breakpoints. */
15308 ops = &ranged_breakpoint_ops;
15309 *ops = bkpt_breakpoint_ops;
15310 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15311 ops->resources_needed = resources_needed_ranged_breakpoint;
15312 ops->print_it = print_it_ranged_breakpoint;
15313 ops->print_one = print_one_ranged_breakpoint;
15314 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15315 ops->print_mention = print_mention_ranged_breakpoint;
15316 ops->print_recreate = print_recreate_ranged_breakpoint;
15318 /* Internal breakpoints. */
15319 ops = &internal_breakpoint_ops;
15320 *ops = bkpt_base_breakpoint_ops;
15321 ops->re_set = internal_bkpt_re_set;
15322 ops->check_status = internal_bkpt_check_status;
15323 ops->print_it = internal_bkpt_print_it;
15324 ops->print_mention = internal_bkpt_print_mention;
15326 /* Momentary breakpoints. */
15327 ops = &momentary_breakpoint_ops;
15328 *ops = bkpt_base_breakpoint_ops;
15329 ops->re_set = momentary_bkpt_re_set;
15330 ops->check_status = momentary_bkpt_check_status;
15331 ops->print_it = momentary_bkpt_print_it;
15332 ops->print_mention = momentary_bkpt_print_mention;
15334 /* Probe breakpoints. */
15335 ops = &bkpt_probe_breakpoint_ops;
15336 *ops = bkpt_breakpoint_ops;
15337 ops->insert_location = bkpt_probe_insert_location;
15338 ops->remove_location = bkpt_probe_remove_location;
15339 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
15340 ops->decode_location = bkpt_probe_decode_location;
15343 ops = &watchpoint_breakpoint_ops;
15344 *ops = base_breakpoint_ops;
15345 ops->re_set = re_set_watchpoint;
15346 ops->insert_location = insert_watchpoint;
15347 ops->remove_location = remove_watchpoint;
15348 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15349 ops->check_status = check_status_watchpoint;
15350 ops->resources_needed = resources_needed_watchpoint;
15351 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15352 ops->print_it = print_it_watchpoint;
15353 ops->print_mention = print_mention_watchpoint;
15354 ops->print_recreate = print_recreate_watchpoint;
15355 ops->explains_signal = explains_signal_watchpoint;
15357 /* Masked watchpoints. */
15358 ops = &masked_watchpoint_breakpoint_ops;
15359 *ops = watchpoint_breakpoint_ops;
15360 ops->insert_location = insert_masked_watchpoint;
15361 ops->remove_location = remove_masked_watchpoint;
15362 ops->resources_needed = resources_needed_masked_watchpoint;
15363 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15364 ops->print_it = print_it_masked_watchpoint;
15365 ops->print_one_detail = print_one_detail_masked_watchpoint;
15366 ops->print_mention = print_mention_masked_watchpoint;
15367 ops->print_recreate = print_recreate_masked_watchpoint;
15370 ops = &tracepoint_breakpoint_ops;
15371 *ops = base_breakpoint_ops;
15372 ops->re_set = tracepoint_re_set;
15373 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15374 ops->print_one_detail = tracepoint_print_one_detail;
15375 ops->print_mention = tracepoint_print_mention;
15376 ops->print_recreate = tracepoint_print_recreate;
15377 ops->create_sals_from_location = tracepoint_create_sals_from_location;
15378 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15379 ops->decode_location = tracepoint_decode_location;
15381 /* Probe tracepoints. */
15382 ops = &tracepoint_probe_breakpoint_ops;
15383 *ops = tracepoint_breakpoint_ops;
15384 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
15385 ops->decode_location = tracepoint_probe_decode_location;
15387 /* Static tracepoints with marker (`-m'). */
15388 ops = &strace_marker_breakpoint_ops;
15389 *ops = tracepoint_breakpoint_ops;
15390 ops->create_sals_from_location = strace_marker_create_sals_from_location;
15391 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15392 ops->decode_location = strace_marker_decode_location;
15394 /* Fork catchpoints. */
15395 ops = &catch_fork_breakpoint_ops;
15396 *ops = base_breakpoint_ops;
15397 ops->insert_location = insert_catch_fork;
15398 ops->remove_location = remove_catch_fork;
15399 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15400 ops->print_it = print_it_catch_fork;
15401 ops->print_one = print_one_catch_fork;
15402 ops->print_mention = print_mention_catch_fork;
15403 ops->print_recreate = print_recreate_catch_fork;
15405 /* Vfork catchpoints. */
15406 ops = &catch_vfork_breakpoint_ops;
15407 *ops = base_breakpoint_ops;
15408 ops->insert_location = insert_catch_vfork;
15409 ops->remove_location = remove_catch_vfork;
15410 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15411 ops->print_it = print_it_catch_vfork;
15412 ops->print_one = print_one_catch_vfork;
15413 ops->print_mention = print_mention_catch_vfork;
15414 ops->print_recreate = print_recreate_catch_vfork;
15416 /* Exec catchpoints. */
15417 ops = &catch_exec_breakpoint_ops;
15418 *ops = base_breakpoint_ops;
15419 ops->insert_location = insert_catch_exec;
15420 ops->remove_location = remove_catch_exec;
15421 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15422 ops->print_it = print_it_catch_exec;
15423 ops->print_one = print_one_catch_exec;
15424 ops->print_mention = print_mention_catch_exec;
15425 ops->print_recreate = print_recreate_catch_exec;
15427 /* Solib-related catchpoints. */
15428 ops = &catch_solib_breakpoint_ops;
15429 *ops = base_breakpoint_ops;
15430 ops->insert_location = insert_catch_solib;
15431 ops->remove_location = remove_catch_solib;
15432 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15433 ops->check_status = check_status_catch_solib;
15434 ops->print_it = print_it_catch_solib;
15435 ops->print_one = print_one_catch_solib;
15436 ops->print_mention = print_mention_catch_solib;
15437 ops->print_recreate = print_recreate_catch_solib;
15439 ops = &dprintf_breakpoint_ops;
15440 *ops = bkpt_base_breakpoint_ops;
15441 ops->re_set = dprintf_re_set;
15442 ops->resources_needed = bkpt_resources_needed;
15443 ops->print_it = bkpt_print_it;
15444 ops->print_mention = bkpt_print_mention;
15445 ops->print_recreate = dprintf_print_recreate;
15446 ops->after_condition_true = dprintf_after_condition_true;
15447 ops->breakpoint_hit = dprintf_breakpoint_hit;
15450 /* Chain containing all defined "enable breakpoint" subcommands. */
15452 static struct cmd_list_element *enablebreaklist = NULL;
15454 /* See breakpoint.h. */
15456 cmd_list_element *commands_cmd_element = nullptr;
15459 _initialize_breakpoint (void)
15461 struct cmd_list_element *c;
15463 initialize_breakpoint_ops ();
15465 gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib);
15466 gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile);
15467 gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change);
15469 breakpoint_objfile_key
15470 = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data);
15472 breakpoint_chain = 0;
15473 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15474 before a breakpoint is set. */
15475 breakpoint_count = 0;
15477 tracepoint_count = 0;
15479 add_com ("ignore", class_breakpoint, ignore_command, _("\
15480 Set ignore-count of breakpoint number N to COUNT.\n\
15481 Usage is `ignore N COUNT'."));
15483 commands_cmd_element = add_com ("commands", class_breakpoint,
15484 commands_command, _("\
15485 Set commands to be executed when the given breakpoints are hit.\n\
15486 Give a space-separated breakpoint list as argument after \"commands\".\n\
15487 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15489 With no argument, the targeted breakpoint is the last one set.\n\
15490 The commands themselves follow starting on the next line.\n\
15491 Type a line containing \"end\" to indicate the end of them.\n\
15492 Give \"silent\" as the first line to make the breakpoint silent;\n\
15493 then no output is printed when it is hit, except what the commands print."));
15495 c = add_com ("condition", class_breakpoint, condition_command, _("\
15496 Specify breakpoint number N to break only if COND is true.\n\
15497 Usage is `condition N COND', where N is an integer and COND is an\n\
15498 expression to be evaluated whenever breakpoint N is reached."));
15499 set_cmd_completer (c, condition_completer);
15501 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15502 Set a temporary breakpoint.\n\
15503 Like \"break\" except the breakpoint is only temporary,\n\
15504 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15505 by using \"enable delete\" on the breakpoint number.\n\
15507 BREAK_ARGS_HELP ("tbreak")));
15508 set_cmd_completer (c, location_completer);
15510 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15511 Set a hardware assisted breakpoint.\n\
15512 Like \"break\" except the breakpoint requires hardware support,\n\
15513 some target hardware may not have this support.\n\
15515 BREAK_ARGS_HELP ("hbreak")));
15516 set_cmd_completer (c, location_completer);
15518 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15519 Set a temporary hardware assisted breakpoint.\n\
15520 Like \"hbreak\" except the breakpoint is only temporary,\n\
15521 so it will be deleted when hit.\n\
15523 BREAK_ARGS_HELP ("thbreak")));
15524 set_cmd_completer (c, location_completer);
15526 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15527 Enable some breakpoints.\n\
15528 Give breakpoint numbers (separated by spaces) as arguments.\n\
15529 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15530 This is used to cancel the effect of the \"disable\" command.\n\
15531 With a subcommand you can enable temporarily."),
15532 &enablelist, "enable ", 1, &cmdlist);
15534 add_com_alias ("en", "enable", class_breakpoint, 1);
15536 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15537 Enable some breakpoints.\n\
15538 Give breakpoint numbers (separated by spaces) as arguments.\n\
15539 This is used to cancel the effect of the \"disable\" command.\n\
15540 May be abbreviated to simply \"enable\".\n"),
15541 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15543 add_cmd ("once", no_class, enable_once_command, _("\
15544 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15545 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15548 add_cmd ("delete", no_class, enable_delete_command, _("\
15549 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15550 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15553 add_cmd ("count", no_class, enable_count_command, _("\
15554 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15555 If a breakpoint is hit while enabled in this fashion,\n\
15556 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15559 add_cmd ("delete", no_class, enable_delete_command, _("\
15560 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15561 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15564 add_cmd ("once", no_class, enable_once_command, _("\
15565 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15566 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15569 add_cmd ("count", no_class, enable_count_command, _("\
15570 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15571 If a breakpoint is hit while enabled in this fashion,\n\
15572 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15575 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15576 Disable some breakpoints.\n\
15577 Arguments are breakpoint numbers with spaces in between.\n\
15578 To disable all breakpoints, give no argument.\n\
15579 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15580 &disablelist, "disable ", 1, &cmdlist);
15581 add_com_alias ("dis", "disable", class_breakpoint, 1);
15582 add_com_alias ("disa", "disable", class_breakpoint, 1);
15584 add_cmd ("breakpoints", class_alias, disable_command, _("\
15585 Disable some breakpoints.\n\
15586 Arguments are breakpoint numbers with spaces in between.\n\
15587 To disable all breakpoints, give no argument.\n\
15588 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15589 This command may be abbreviated \"disable\"."),
15592 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15593 Delete some breakpoints or auto-display expressions.\n\
15594 Arguments are breakpoint numbers with spaces in between.\n\
15595 To delete all breakpoints, give no argument.\n\
15597 Also a prefix command for deletion of other GDB objects.\n\
15598 The \"unset\" command is also an alias for \"delete\"."),
15599 &deletelist, "delete ", 1, &cmdlist);
15600 add_com_alias ("d", "delete", class_breakpoint, 1);
15601 add_com_alias ("del", "delete", class_breakpoint, 1);
15603 add_cmd ("breakpoints", class_alias, delete_command, _("\
15604 Delete some breakpoints or auto-display expressions.\n\
15605 Arguments are breakpoint numbers with spaces in between.\n\
15606 To delete all breakpoints, give no argument.\n\
15607 This command may be abbreviated \"delete\"."),
15610 add_com ("clear", class_breakpoint, clear_command, _("\
15611 Clear breakpoint at specified location.\n\
15612 Argument may be a linespec, explicit, or address location as described below.\n\
15614 With no argument, clears all breakpoints in the line that the selected frame\n\
15615 is executing in.\n"
15616 "\n" LOCATION_HELP_STRING "\n\
15617 See also the \"delete\" command which clears breakpoints by number."));
15618 add_com_alias ("cl", "clear", class_breakpoint, 1);
15620 c = add_com ("break", class_breakpoint, break_command, _("\
15621 Set breakpoint at specified location.\n"
15622 BREAK_ARGS_HELP ("break")));
15623 set_cmd_completer (c, location_completer);
15625 add_com_alias ("b", "break", class_run, 1);
15626 add_com_alias ("br", "break", class_run, 1);
15627 add_com_alias ("bre", "break", class_run, 1);
15628 add_com_alias ("brea", "break", class_run, 1);
15632 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15633 Break in function/address or break at a line in the current file."),
15634 &stoplist, "stop ", 1, &cmdlist);
15635 add_cmd ("in", class_breakpoint, stopin_command,
15636 _("Break in function or address."), &stoplist);
15637 add_cmd ("at", class_breakpoint, stopat_command,
15638 _("Break at a line in the current file."), &stoplist);
15639 add_com ("status", class_info, info_breakpoints_command, _("\
15640 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15641 The \"Type\" column indicates one of:\n\
15642 \tbreakpoint - normal breakpoint\n\
15643 \twatchpoint - watchpoint\n\
15644 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15645 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15646 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15647 address and file/line number respectively.\n\
15649 Convenience variable \"$_\" and default examine address for \"x\"\n\
15650 are set to the address of the last breakpoint listed unless the command\n\
15651 is prefixed with \"server \".\n\n\
15652 Convenience variable \"$bpnum\" contains the number of the last\n\
15653 breakpoint set."));
15656 add_info ("breakpoints", info_breakpoints_command, _("\
15657 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15658 The \"Type\" column indicates one of:\n\
15659 \tbreakpoint - normal breakpoint\n\
15660 \twatchpoint - watchpoint\n\
15661 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15662 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15663 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15664 address and file/line number respectively.\n\
15666 Convenience variable \"$_\" and default examine address for \"x\"\n\
15667 are set to the address of the last breakpoint listed unless the command\n\
15668 is prefixed with \"server \".\n\n\
15669 Convenience variable \"$bpnum\" contains the number of the last\n\
15670 breakpoint set."));
15672 add_info_alias ("b", "breakpoints", 1);
15674 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15675 Status of all breakpoints, or breakpoint number NUMBER.\n\
15676 The \"Type\" column indicates one of:\n\
15677 \tbreakpoint - normal breakpoint\n\
15678 \twatchpoint - watchpoint\n\
15679 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15680 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15681 \tuntil - internal breakpoint used by the \"until\" command\n\
15682 \tfinish - internal breakpoint used by the \"finish\" command\n\
15683 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15684 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15685 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15686 address and file/line number respectively.\n\
15688 Convenience variable \"$_\" and default examine address for \"x\"\n\
15689 are set to the address of the last breakpoint listed unless the command\n\
15690 is prefixed with \"server \".\n\n\
15691 Convenience variable \"$bpnum\" contains the number of the last\n\
15693 &maintenanceinfolist);
15695 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15696 Set catchpoints to catch events."),
15697 &catch_cmdlist, "catch ",
15698 0/*allow-unknown*/, &cmdlist);
15700 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15701 Set temporary catchpoints to catch events."),
15702 &tcatch_cmdlist, "tcatch ",
15703 0/*allow-unknown*/, &cmdlist);
15705 add_catch_command ("fork", _("Catch calls to fork."),
15706 catch_fork_command_1,
15708 (void *) (uintptr_t) catch_fork_permanent,
15709 (void *) (uintptr_t) catch_fork_temporary);
15710 add_catch_command ("vfork", _("Catch calls to vfork."),
15711 catch_fork_command_1,
15713 (void *) (uintptr_t) catch_vfork_permanent,
15714 (void *) (uintptr_t) catch_vfork_temporary);
15715 add_catch_command ("exec", _("Catch calls to exec."),
15716 catch_exec_command_1,
15720 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15721 Usage: catch load [REGEX]\n\
15722 If REGEX is given, only stop for libraries matching the regular expression."),
15723 catch_load_command_1,
15727 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15728 Usage: catch unload [REGEX]\n\
15729 If REGEX is given, only stop for libraries matching the regular expression."),
15730 catch_unload_command_1,
15735 c = add_com ("watch", class_breakpoint, watch_command, _("\
15736 Set a watchpoint for an expression.\n\
15737 Usage: watch [-l|-location] EXPRESSION\n\
15738 A watchpoint stops execution of your program whenever the value of\n\
15739 an expression changes.\n\
15740 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15741 the memory to which it refers."));
15742 set_cmd_completer (c, expression_completer);
15744 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15745 Set a read watchpoint for an expression.\n\
15746 Usage: rwatch [-l|-location] EXPRESSION\n\
15747 A watchpoint stops execution of your program whenever the value of\n\
15748 an expression is read.\n\
15749 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15750 the memory to which it refers."));
15751 set_cmd_completer (c, expression_completer);
15753 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15754 Set a watchpoint for an expression.\n\
15755 Usage: awatch [-l|-location] EXPRESSION\n\
15756 A watchpoint stops execution of your program whenever the value of\n\
15757 an expression is either read or written.\n\
15758 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15759 the memory to which it refers."));
15760 set_cmd_completer (c, expression_completer);
15762 add_info ("watchpoints", info_watchpoints_command, _("\
15763 Status of specified watchpoints (all watchpoints if no argument)."));
15765 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15766 respond to changes - contrary to the description. */
15767 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15768 &can_use_hw_watchpoints, _("\
15769 Set debugger's willingness to use watchpoint hardware."), _("\
15770 Show debugger's willingness to use watchpoint hardware."), _("\
15771 If zero, gdb will not use hardware for new watchpoints, even if\n\
15772 such is available. (However, any hardware watchpoints that were\n\
15773 created before setting this to nonzero, will continue to use watchpoint\n\
15776 show_can_use_hw_watchpoints,
15777 &setlist, &showlist);
15779 can_use_hw_watchpoints = 1;
15781 /* Tracepoint manipulation commands. */
15783 c = add_com ("trace", class_breakpoint, trace_command, _("\
15784 Set a tracepoint at specified location.\n\
15786 BREAK_ARGS_HELP ("trace") "\n\
15787 Do \"help tracepoints\" for info on other tracepoint commands."));
15788 set_cmd_completer (c, location_completer);
15790 add_com_alias ("tp", "trace", class_alias, 0);
15791 add_com_alias ("tr", "trace", class_alias, 1);
15792 add_com_alias ("tra", "trace", class_alias, 1);
15793 add_com_alias ("trac", "trace", class_alias, 1);
15795 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15796 Set a fast tracepoint at specified location.\n\
15798 BREAK_ARGS_HELP ("ftrace") "\n\
15799 Do \"help tracepoints\" for info on other tracepoint commands."));
15800 set_cmd_completer (c, location_completer);
15802 c = add_com ("strace", class_breakpoint, strace_command, _("\
15803 Set a static tracepoint at location or marker.\n\
15805 strace [LOCATION] [if CONDITION]\n\
15806 LOCATION may be a linespec, explicit, or address location (described below) \n\
15807 or -m MARKER_ID.\n\n\
15808 If a marker id is specified, probe the marker with that name. With\n\
15809 no LOCATION, uses current execution address of the selected stack frame.\n\
15810 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15811 This collects arbitrary user data passed in the probe point call to the\n\
15812 tracing library. You can inspect it when analyzing the trace buffer,\n\
15813 by printing the $_sdata variable like any other convenience variable.\n\
15815 CONDITION is a boolean expression.\n\
15816 \n" LOCATION_HELP_STRING "\n\
15817 Multiple tracepoints at one place are permitted, and useful if their\n\
15818 conditions are different.\n\
15820 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15821 Do \"help tracepoints\" for info on other tracepoint commands."));
15822 set_cmd_completer (c, location_completer);
15824 add_info ("tracepoints", info_tracepoints_command, _("\
15825 Status of specified tracepoints (all tracepoints if no argument).\n\
15826 Convenience variable \"$tpnum\" contains the number of the\n\
15827 last tracepoint set."));
15829 add_info_alias ("tp", "tracepoints", 1);
15831 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15832 Delete specified tracepoints.\n\
15833 Arguments are tracepoint numbers, separated by spaces.\n\
15834 No argument means delete all tracepoints."),
15836 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
15838 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15839 Disable specified tracepoints.\n\
15840 Arguments are tracepoint numbers, separated by spaces.\n\
15841 No argument means disable all tracepoints."),
15843 deprecate_cmd (c, "disable");
15845 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15846 Enable specified tracepoints.\n\
15847 Arguments are tracepoint numbers, separated by spaces.\n\
15848 No argument means enable all tracepoints."),
15850 deprecate_cmd (c, "enable");
15852 add_com ("passcount", class_trace, trace_pass_command, _("\
15853 Set the passcount for a tracepoint.\n\
15854 The trace will end when the tracepoint has been passed 'count' times.\n\
15855 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15856 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15858 add_prefix_cmd ("save", class_breakpoint, save_command,
15859 _("Save breakpoint definitions as a script."),
15860 &save_cmdlist, "save ",
15861 0/*allow-unknown*/, &cmdlist);
15863 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15864 Save current breakpoint definitions as a script.\n\
15865 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15866 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15867 session to restore them."),
15869 set_cmd_completer (c, filename_completer);
15871 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15872 Save current tracepoint definitions as a script.\n\
15873 Use the 'source' command in another debug session to restore them."),
15875 set_cmd_completer (c, filename_completer);
15877 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15878 deprecate_cmd (c, "save tracepoints");
15880 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15881 Breakpoint specific settings\n\
15882 Configure various breakpoint-specific variables such as\n\
15883 pending breakpoint behavior"),
15884 &breakpoint_set_cmdlist, "set breakpoint ",
15885 0/*allow-unknown*/, &setlist);
15886 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15887 Breakpoint specific settings\n\
15888 Configure various breakpoint-specific variables such as\n\
15889 pending breakpoint behavior"),
15890 &breakpoint_show_cmdlist, "show breakpoint ",
15891 0/*allow-unknown*/, &showlist);
15893 add_setshow_auto_boolean_cmd ("pending", no_class,
15894 &pending_break_support, _("\
15895 Set debugger's behavior regarding pending breakpoints."), _("\
15896 Show debugger's behavior regarding pending breakpoints."), _("\
15897 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15898 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15899 an error. If auto, an unrecognized breakpoint location results in a\n\
15900 user-query to see if a pending breakpoint should be created."),
15902 show_pending_break_support,
15903 &breakpoint_set_cmdlist,
15904 &breakpoint_show_cmdlist);
15906 pending_break_support = AUTO_BOOLEAN_AUTO;
15908 add_setshow_boolean_cmd ("auto-hw", no_class,
15909 &automatic_hardware_breakpoints, _("\
15910 Set automatic usage of hardware breakpoints."), _("\
15911 Show automatic usage of hardware breakpoints."), _("\
15912 If set, the debugger will automatically use hardware breakpoints for\n\
15913 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15914 a warning will be emitted for such breakpoints."),
15916 show_automatic_hardware_breakpoints,
15917 &breakpoint_set_cmdlist,
15918 &breakpoint_show_cmdlist);
15920 add_setshow_boolean_cmd ("always-inserted", class_support,
15921 &always_inserted_mode, _("\
15922 Set mode for inserting breakpoints."), _("\
15923 Show mode for inserting breakpoints."), _("\
15924 When this mode is on, breakpoints are inserted immediately as soon as\n\
15925 they're created, kept inserted even when execution stops, and removed\n\
15926 only when the user deletes them. When this mode is off (the default),\n\
15927 breakpoints are inserted only when execution continues, and removed\n\
15928 when execution stops."),
15930 &show_always_inserted_mode,
15931 &breakpoint_set_cmdlist,
15932 &breakpoint_show_cmdlist);
15934 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15935 condition_evaluation_enums,
15936 &condition_evaluation_mode_1, _("\
15937 Set mode of breakpoint condition evaluation."), _("\
15938 Show mode of breakpoint condition evaluation."), _("\
15939 When this is set to \"host\", breakpoint conditions will be\n\
15940 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15941 breakpoint conditions will be downloaded to the target (if the target\n\
15942 supports such feature) and conditions will be evaluated on the target's side.\n\
15943 If this is set to \"auto\" (default), this will be automatically set to\n\
15944 \"target\" if it supports condition evaluation, otherwise it will\n\
15945 be set to \"gdb\""),
15946 &set_condition_evaluation_mode,
15947 &show_condition_evaluation_mode,
15948 &breakpoint_set_cmdlist,
15949 &breakpoint_show_cmdlist);
15951 add_com ("break-range", class_breakpoint, break_range_command, _("\
15952 Set a breakpoint for an address range.\n\
15953 break-range START-LOCATION, END-LOCATION\n\
15954 where START-LOCATION and END-LOCATION can be one of the following:\n\
15955 LINENUM, for that line in the current file,\n\
15956 FILE:LINENUM, for that line in that file,\n\
15957 +OFFSET, for that number of lines after the current line\n\
15958 or the start of the range\n\
15959 FUNCTION, for the first line in that function,\n\
15960 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15961 *ADDRESS, for the instruction at that address.\n\
15963 The breakpoint will stop execution of the inferior whenever it executes\n\
15964 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15965 range (including START-LOCATION and END-LOCATION)."));
15967 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
15968 Set a dynamic printf at specified location.\n\
15969 dprintf location,format string,arg1,arg2,...\n\
15970 location may be a linespec, explicit, or address location.\n"
15971 "\n" LOCATION_HELP_STRING));
15972 set_cmd_completer (c, location_completer);
15974 add_setshow_enum_cmd ("dprintf-style", class_support,
15975 dprintf_style_enums, &dprintf_style, _("\
15976 Set the style of usage for dynamic printf."), _("\
15977 Show the style of usage for dynamic printf."), _("\
15978 This setting chooses how GDB will do a dynamic printf.\n\
15979 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15980 console, as with the \"printf\" command.\n\
15981 If the value is \"call\", the print is done by calling a function in your\n\
15982 program; by default printf(), but you can choose a different function or\n\
15983 output stream by setting dprintf-function and dprintf-channel."),
15984 update_dprintf_commands, NULL,
15985 &setlist, &showlist);
15987 dprintf_function = xstrdup ("printf");
15988 add_setshow_string_cmd ("dprintf-function", class_support,
15989 &dprintf_function, _("\
15990 Set the function to use for dynamic printf"), _("\
15991 Show the function to use for dynamic printf"), NULL,
15992 update_dprintf_commands, NULL,
15993 &setlist, &showlist);
15995 dprintf_channel = xstrdup ("");
15996 add_setshow_string_cmd ("dprintf-channel", class_support,
15997 &dprintf_channel, _("\
15998 Set the channel to use for dynamic printf"), _("\
15999 Show the channel to use for dynamic printf"), NULL,
16000 update_dprintf_commands, NULL,
16001 &setlist, &showlist);
16003 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16004 &disconnected_dprintf, _("\
16005 Set whether dprintf continues after GDB disconnects."), _("\
16006 Show whether dprintf continues after GDB disconnects."), _("\
16007 Use this to let dprintf commands continue to hit and produce output\n\
16008 even if GDB disconnects or detaches from the target."),
16011 &setlist, &showlist);
16013 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16014 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16015 (target agent only) This is useful for formatted output in user-defined commands."));
16017 automatic_hardware_breakpoints = 1;
16019 gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed);
16020 gdb::observers::thread_exit.attach (remove_threaded_breakpoints);