1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdb_regex.h"
61 #include "cli/cli-utils.h"
62 #include "continuations.h"
66 #include "dummy-frame.h"
69 #include "thread-fsm.h"
70 #include "tid-parse.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 #include "progspace-and-thread.h"
83 #include "common/array-view.h"
84 #include "common/gdb_optional.h"
86 /* Enums for exception-handling support. */
87 enum exception_event_kind
94 /* Prototypes for local functions. */
96 static void map_breakpoint_numbers (const char *,
97 gdb::function_view<void (breakpoint *)>);
99 static void breakpoint_re_set_default (struct breakpoint *);
102 create_sals_from_location_default (const struct event_location *location,
103 struct linespec_result *canonical,
104 enum bptype type_wanted);
106 static void create_breakpoints_sal_default (struct gdbarch *,
107 struct linespec_result *,
108 gdb::unique_xmalloc_ptr<char>,
109 gdb::unique_xmalloc_ptr<char>,
111 enum bpdisp, int, int,
113 const struct breakpoint_ops *,
114 int, int, int, unsigned);
116 static std::vector<symtab_and_line> decode_location_default
117 (struct breakpoint *b, const struct event_location *location,
118 struct program_space *search_pspace);
120 static int can_use_hardware_watchpoint
121 (const std::vector<value_ref_ptr> &vals);
123 static void mention (struct breakpoint *);
125 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
127 const struct breakpoint_ops *);
128 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
129 const struct symtab_and_line *);
131 /* This function is used in gdbtk sources and thus can not be made
133 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
134 struct symtab_and_line,
136 const struct breakpoint_ops *);
138 static struct breakpoint *
139 momentary_breakpoint_from_master (struct breakpoint *orig,
141 const struct breakpoint_ops *ops,
144 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
146 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
150 static void describe_other_breakpoints (struct gdbarch *,
151 struct program_space *, CORE_ADDR,
152 struct obj_section *, int);
154 static int watchpoint_locations_match (struct bp_location *loc1,
155 struct bp_location *loc2);
157 static int breakpoint_location_address_match (struct bp_location *bl,
158 const struct address_space *aspace,
161 static int breakpoint_location_address_range_overlap (struct bp_location *,
162 const address_space *,
165 static int remove_breakpoint (struct bp_location *);
166 static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
168 static enum print_stop_action print_bp_stop_message (bpstat bs);
170 static int hw_breakpoint_used_count (void);
172 static int hw_watchpoint_use_count (struct breakpoint *);
174 static int hw_watchpoint_used_count_others (struct breakpoint *except,
176 int *other_type_used);
178 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
181 static void free_bp_location (struct bp_location *loc);
182 static void incref_bp_location (struct bp_location *loc);
183 static void decref_bp_location (struct bp_location **loc);
185 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
187 /* update_global_location_list's modes of operation wrt to whether to
188 insert locations now. */
189 enum ugll_insert_mode
191 /* Don't insert any breakpoint locations into the inferior, only
192 remove already-inserted locations that no longer should be
193 inserted. Functions that delete a breakpoint or breakpoints
194 should specify this mode, so that deleting a breakpoint doesn't
195 have the side effect of inserting the locations of other
196 breakpoints that are marked not-inserted, but should_be_inserted
197 returns true on them.
199 This behavior is useful is situations close to tear-down -- e.g.,
200 after an exec, while the target still has execution, but
201 breakpoint shadows of the previous executable image should *NOT*
202 be restored to the new image; or before detaching, where the
203 target still has execution and wants to delete breakpoints from
204 GDB's lists, and all breakpoints had already been removed from
208 /* May insert breakpoints iff breakpoints_should_be_inserted_now
209 claims breakpoints should be inserted now. */
212 /* Insert locations now, irrespective of
213 breakpoints_should_be_inserted_now. E.g., say all threads are
214 stopped right now, and the user did "continue". We need to
215 insert breakpoints _before_ resuming the target, but
216 UGLL_MAY_INSERT wouldn't insert them, because
217 breakpoints_should_be_inserted_now returns false at that point,
218 as no thread is running yet. */
222 static void update_global_location_list (enum ugll_insert_mode);
224 static void update_global_location_list_nothrow (enum ugll_insert_mode);
226 static int is_hardware_watchpoint (const struct breakpoint *bpt);
228 static void insert_breakpoint_locations (void);
230 static void trace_pass_command (const char *, int);
232 static void set_tracepoint_count (int num);
234 static int is_masked_watchpoint (const struct breakpoint *b);
236 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
238 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
241 static int strace_marker_p (struct breakpoint *b);
243 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
244 that are implemented on top of software or hardware breakpoints
245 (user breakpoints, internal and momentary breakpoints, etc.). */
246 static struct breakpoint_ops bkpt_base_breakpoint_ops;
248 /* Internal breakpoints class type. */
249 static struct breakpoint_ops internal_breakpoint_ops;
251 /* Momentary breakpoints class type. */
252 static struct breakpoint_ops momentary_breakpoint_ops;
254 /* The breakpoint_ops structure to be used in regular user created
256 struct breakpoint_ops bkpt_breakpoint_ops;
258 /* Breakpoints set on probes. */
259 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
261 /* Dynamic printf class type. */
262 struct breakpoint_ops dprintf_breakpoint_ops;
264 /* The style in which to perform a dynamic printf. This is a user
265 option because different output options have different tradeoffs;
266 if GDB does the printing, there is better error handling if there
267 is a problem with any of the arguments, but using an inferior
268 function lets you have special-purpose printers and sending of
269 output to the same place as compiled-in print functions. */
271 static const char dprintf_style_gdb[] = "gdb";
272 static const char dprintf_style_call[] = "call";
273 static const char dprintf_style_agent[] = "agent";
274 static const char *const dprintf_style_enums[] = {
280 static const char *dprintf_style = dprintf_style_gdb;
282 /* The function to use for dynamic printf if the preferred style is to
283 call into the inferior. The value is simply a string that is
284 copied into the command, so it can be anything that GDB can
285 evaluate to a callable address, not necessarily a function name. */
287 static char *dprintf_function;
289 /* The channel to use for dynamic printf if the preferred style is to
290 call into the inferior; if a nonempty string, it will be passed to
291 the call as the first argument, with the format string as the
292 second. As with the dprintf function, this can be anything that
293 GDB knows how to evaluate, so in addition to common choices like
294 "stderr", this could be an app-specific expression like
295 "mystreams[curlogger]". */
297 static char *dprintf_channel;
299 /* True if dprintf commands should continue to operate even if GDB
301 static int disconnected_dprintf = 1;
303 struct command_line *
304 breakpoint_commands (struct breakpoint *b)
306 return b->commands ? b->commands.get () : NULL;
309 /* Flag indicating that a command has proceeded the inferior past the
310 current breakpoint. */
312 static int breakpoint_proceeded;
315 bpdisp_text (enum bpdisp disp)
317 /* NOTE: the following values are a part of MI protocol and
318 represent values of 'disp' field returned when inferior stops at
320 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
322 return bpdisps[(int) disp];
325 /* Prototypes for exported functions. */
326 /* If FALSE, gdb will not use hardware support for watchpoints, even
327 if such is available. */
328 static int can_use_hw_watchpoints;
331 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
332 struct cmd_list_element *c,
335 fprintf_filtered (file,
336 _("Debugger's willingness to use "
337 "watchpoint hardware is %s.\n"),
341 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
342 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
343 for unrecognized breakpoint locations.
344 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
345 static enum auto_boolean pending_break_support;
347 show_pending_break_support (struct ui_file *file, int from_tty,
348 struct cmd_list_element *c,
351 fprintf_filtered (file,
352 _("Debugger's behavior regarding "
353 "pending breakpoints is %s.\n"),
357 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
358 set with "break" but falling in read-only memory.
359 If 0, gdb will warn about such breakpoints, but won't automatically
360 use hardware breakpoints. */
361 static int automatic_hardware_breakpoints;
363 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
364 struct cmd_list_element *c,
367 fprintf_filtered (file,
368 _("Automatic usage of hardware breakpoints is %s.\n"),
372 /* If on, GDB keeps breakpoints inserted even if the inferior is
373 stopped, and immediately inserts any new breakpoints as soon as
374 they're created. If off (default), GDB keeps breakpoints off of
375 the target as long as possible. That is, it delays inserting
376 breakpoints until the next resume, and removes them again when the
377 target fully stops. This is a bit safer in case GDB crashes while
378 processing user input. */
379 static int always_inserted_mode = 0;
382 show_always_inserted_mode (struct ui_file *file, int from_tty,
383 struct cmd_list_element *c, const char *value)
385 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
389 /* See breakpoint.h. */
392 breakpoints_should_be_inserted_now (void)
394 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
396 /* If breakpoints are global, they should be inserted even if no
397 thread under gdb's control is running, or even if there are
398 no threads under GDB's control yet. */
401 else if (target_has_execution)
403 if (always_inserted_mode)
405 /* The user wants breakpoints inserted even if all threads
410 if (threads_are_executing ())
413 /* Don't remove breakpoints yet if, even though all threads are
414 stopped, we still have events to process. */
415 for (thread_info *tp : all_non_exited_threads ())
417 && tp->suspend.waitstatus_pending_p)
423 static const char condition_evaluation_both[] = "host or target";
425 /* Modes for breakpoint condition evaluation. */
426 static const char condition_evaluation_auto[] = "auto";
427 static const char condition_evaluation_host[] = "host";
428 static const char condition_evaluation_target[] = "target";
429 static const char *const condition_evaluation_enums[] = {
430 condition_evaluation_auto,
431 condition_evaluation_host,
432 condition_evaluation_target,
436 /* Global that holds the current mode for breakpoint condition evaluation. */
437 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
439 /* Global that we use to display information to the user (gets its value from
440 condition_evaluation_mode_1. */
441 static const char *condition_evaluation_mode = condition_evaluation_auto;
443 /* Translate a condition evaluation mode MODE into either "host"
444 or "target". This is used mostly to translate from "auto" to the
445 real setting that is being used. It returns the translated
449 translate_condition_evaluation_mode (const char *mode)
451 if (mode == condition_evaluation_auto)
453 if (target_supports_evaluation_of_breakpoint_conditions ())
454 return condition_evaluation_target;
456 return condition_evaluation_host;
462 /* Discovers what condition_evaluation_auto translates to. */
465 breakpoint_condition_evaluation_mode (void)
467 return translate_condition_evaluation_mode (condition_evaluation_mode);
470 /* Return true if GDB should evaluate breakpoint conditions or false
474 gdb_evaluates_breakpoint_condition_p (void)
476 const char *mode = breakpoint_condition_evaluation_mode ();
478 return (mode == condition_evaluation_host);
481 /* Are we executing breakpoint commands? */
482 static int executing_breakpoint_commands;
484 /* Are overlay event breakpoints enabled? */
485 static int overlay_events_enabled;
487 /* See description in breakpoint.h. */
488 int target_exact_watchpoints = 0;
490 /* Walk the following statement or block through all breakpoints.
491 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
492 current breakpoint. */
494 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
496 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
497 for (B = breakpoint_chain; \
498 B ? (TMP=B->next, 1): 0; \
501 /* Similar iterator for the low-level breakpoints. SAFE variant is
502 not provided so update_global_location_list must not be called
503 while executing the block of ALL_BP_LOCATIONS. */
505 #define ALL_BP_LOCATIONS(B,BP_TMP) \
506 for (BP_TMP = bp_locations; \
507 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
510 /* Iterates through locations with address ADDRESS for the currently selected
511 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
512 to where the loop should start from.
513 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
514 appropriate location to start with. */
516 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
517 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
518 BP_LOCP_TMP = BP_LOCP_START; \
520 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
521 && (*BP_LOCP_TMP)->address == ADDRESS); \
524 /* Iterator for tracepoints only. */
526 #define ALL_TRACEPOINTS(B) \
527 for (B = breakpoint_chain; B; B = B->next) \
528 if (is_tracepoint (B))
530 /* Chains of all breakpoints defined. */
532 struct breakpoint *breakpoint_chain;
534 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
536 static struct bp_location **bp_locations;
538 /* Number of elements of BP_LOCATIONS. */
540 static unsigned bp_locations_count;
542 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
543 ADDRESS for the current elements of BP_LOCATIONS which get a valid
544 result from bp_location_has_shadow. You can use it for roughly
545 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
546 an address you need to read. */
548 static CORE_ADDR bp_locations_placed_address_before_address_max;
550 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
551 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
552 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
553 You can use it for roughly limiting the subrange of BP_LOCATIONS to
554 scan for shadow bytes for an address you need to read. */
556 static CORE_ADDR bp_locations_shadow_len_after_address_max;
558 /* The locations that no longer correspond to any breakpoint, unlinked
559 from the bp_locations array, but for which a hit may still be
560 reported by a target. */
561 static std::vector<bp_location *> moribund_locations;
563 /* Number of last breakpoint made. */
565 static int breakpoint_count;
567 /* The value of `breakpoint_count' before the last command that
568 created breakpoints. If the last (break-like) command created more
569 than one breakpoint, then the difference between BREAKPOINT_COUNT
570 and PREV_BREAKPOINT_COUNT is more than one. */
571 static int prev_breakpoint_count;
573 /* Number of last tracepoint made. */
575 static int tracepoint_count;
577 static struct cmd_list_element *breakpoint_set_cmdlist;
578 static struct cmd_list_element *breakpoint_show_cmdlist;
579 struct cmd_list_element *save_cmdlist;
581 /* See declaration at breakpoint.h. */
584 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
587 struct breakpoint *b = NULL;
591 if (func (b, user_data) != 0)
598 /* Return whether a breakpoint is an active enabled breakpoint. */
600 breakpoint_enabled (struct breakpoint *b)
602 return (b->enable_state == bp_enabled);
605 /* Set breakpoint count to NUM. */
608 set_breakpoint_count (int num)
610 prev_breakpoint_count = breakpoint_count;
611 breakpoint_count = num;
612 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
615 /* Used by `start_rbreak_breakpoints' below, to record the current
616 breakpoint count before "rbreak" creates any breakpoint. */
617 static int rbreak_start_breakpoint_count;
619 /* Called at the start an "rbreak" command to record the first
622 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
624 rbreak_start_breakpoint_count = breakpoint_count;
627 /* Called at the end of an "rbreak" command to record the last
630 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
632 prev_breakpoint_count = rbreak_start_breakpoint_count;
635 /* Used in run_command to zero the hit count when a new run starts. */
638 clear_breakpoint_hit_counts (void)
640 struct breakpoint *b;
647 /* Return the breakpoint with the specified number, or NULL
648 if the number does not refer to an existing breakpoint. */
651 get_breakpoint (int num)
653 struct breakpoint *b;
656 if (b->number == num)
664 /* Mark locations as "conditions have changed" in case the target supports
665 evaluating conditions on its side. */
668 mark_breakpoint_modified (struct breakpoint *b)
670 struct bp_location *loc;
672 /* This is only meaningful if the target is
673 evaluating conditions and if the user has
674 opted for condition evaluation on the target's
676 if (gdb_evaluates_breakpoint_condition_p ()
677 || !target_supports_evaluation_of_breakpoint_conditions ())
680 if (!is_breakpoint (b))
683 for (loc = b->loc; loc; loc = loc->next)
684 loc->condition_changed = condition_modified;
687 /* Mark location as "conditions have changed" in case the target supports
688 evaluating conditions on its side. */
691 mark_breakpoint_location_modified (struct bp_location *loc)
693 /* This is only meaningful if the target is
694 evaluating conditions and if the user has
695 opted for condition evaluation on the target's
697 if (gdb_evaluates_breakpoint_condition_p ()
698 || !target_supports_evaluation_of_breakpoint_conditions ())
702 if (!is_breakpoint (loc->owner))
705 loc->condition_changed = condition_modified;
708 /* Sets the condition-evaluation mode using the static global
709 condition_evaluation_mode. */
712 set_condition_evaluation_mode (const char *args, int from_tty,
713 struct cmd_list_element *c)
715 const char *old_mode, *new_mode;
717 if ((condition_evaluation_mode_1 == condition_evaluation_target)
718 && !target_supports_evaluation_of_breakpoint_conditions ())
720 condition_evaluation_mode_1 = condition_evaluation_mode;
721 warning (_("Target does not support breakpoint condition evaluation.\n"
722 "Using host evaluation mode instead."));
726 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
727 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
729 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
730 settings was "auto". */
731 condition_evaluation_mode = condition_evaluation_mode_1;
733 /* Only update the mode if the user picked a different one. */
734 if (new_mode != old_mode)
736 struct bp_location *loc, **loc_tmp;
737 /* If the user switched to a different evaluation mode, we
738 need to synch the changes with the target as follows:
740 "host" -> "target": Send all (valid) conditions to the target.
741 "target" -> "host": Remove all the conditions from the target.
744 if (new_mode == condition_evaluation_target)
746 /* Mark everything modified and synch conditions with the
748 ALL_BP_LOCATIONS (loc, loc_tmp)
749 mark_breakpoint_location_modified (loc);
753 /* Manually mark non-duplicate locations to synch conditions
754 with the target. We do this to remove all the conditions the
755 target knows about. */
756 ALL_BP_LOCATIONS (loc, loc_tmp)
757 if (is_breakpoint (loc->owner) && loc->inserted)
758 loc->needs_update = 1;
762 update_global_location_list (UGLL_MAY_INSERT);
768 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
769 what "auto" is translating to. */
772 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
773 struct cmd_list_element *c, const char *value)
775 if (condition_evaluation_mode == condition_evaluation_auto)
776 fprintf_filtered (file,
777 _("Breakpoint condition evaluation "
778 "mode is %s (currently %s).\n"),
780 breakpoint_condition_evaluation_mode ());
782 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
786 /* A comparison function for bp_location AP and BP that is used by
787 bsearch. This comparison function only cares about addresses, unlike
788 the more general bp_locations_compare function. */
791 bp_locations_compare_addrs (const void *ap, const void *bp)
793 const struct bp_location *a = *(const struct bp_location **) ap;
794 const struct bp_location *b = *(const struct bp_location **) bp;
796 if (a->address == b->address)
799 return ((a->address > b->address) - (a->address < b->address));
802 /* Helper function to skip all bp_locations with addresses
803 less than ADDRESS. It returns the first bp_location that
804 is greater than or equal to ADDRESS. If none is found, just
807 static struct bp_location **
808 get_first_locp_gte_addr (CORE_ADDR address)
810 struct bp_location dummy_loc;
811 struct bp_location *dummy_locp = &dummy_loc;
812 struct bp_location **locp_found = NULL;
814 /* Initialize the dummy location's address field. */
815 dummy_loc.address = address;
817 /* Find a close match to the first location at ADDRESS. */
818 locp_found = ((struct bp_location **)
819 bsearch (&dummy_locp, bp_locations, bp_locations_count,
820 sizeof (struct bp_location **),
821 bp_locations_compare_addrs));
823 /* Nothing was found, nothing left to do. */
824 if (locp_found == NULL)
827 /* We may have found a location that is at ADDRESS but is not the first in the
828 location's list. Go backwards (if possible) and locate the first one. */
829 while ((locp_found - 1) >= bp_locations
830 && (*(locp_found - 1))->address == address)
837 set_breakpoint_condition (struct breakpoint *b, const char *exp,
840 xfree (b->cond_string);
841 b->cond_string = NULL;
843 if (is_watchpoint (b))
845 struct watchpoint *w = (struct watchpoint *) b;
847 w->cond_exp.reset ();
851 struct bp_location *loc;
853 for (loc = b->loc; loc; loc = loc->next)
857 /* No need to free the condition agent expression
858 bytecode (if we have one). We will handle this
859 when we go through update_global_location_list. */
866 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
870 const char *arg = exp;
872 /* I don't know if it matters whether this is the string the user
873 typed in or the decompiled expression. */
874 b->cond_string = xstrdup (arg);
875 b->condition_not_parsed = 0;
877 if (is_watchpoint (b))
879 struct watchpoint *w = (struct watchpoint *) b;
881 innermost_block.reset ();
883 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
885 error (_("Junk at end of expression"));
886 w->cond_exp_valid_block = innermost_block.block ();
890 struct bp_location *loc;
892 for (loc = b->loc; loc; loc = loc->next)
896 parse_exp_1 (&arg, loc->address,
897 block_for_pc (loc->address), 0);
899 error (_("Junk at end of expression"));
903 mark_breakpoint_modified (b);
905 gdb::observers::breakpoint_modified.notify (b);
908 /* Completion for the "condition" command. */
911 condition_completer (struct cmd_list_element *cmd,
912 completion_tracker &tracker,
913 const char *text, const char *word)
917 text = skip_spaces (text);
918 space = skip_to_space (text);
922 struct breakpoint *b;
926 /* We don't support completion of history indices. */
927 if (!isdigit (text[1]))
928 complete_internalvar (tracker, &text[1]);
932 /* We're completing the breakpoint number. */
939 xsnprintf (number, sizeof (number), "%d", b->number);
941 if (strncmp (number, text, len) == 0)
943 gdb::unique_xmalloc_ptr<char> copy (xstrdup (number));
944 tracker.add_completion (std::move (copy));
951 /* We're completing the expression part. */
952 text = skip_spaces (space);
953 expression_completer (cmd, tracker, text, word);
956 /* condition N EXP -- set break condition of breakpoint N to EXP. */
959 condition_command (const char *arg, int from_tty)
961 struct breakpoint *b;
966 error_no_arg (_("breakpoint number"));
969 bnum = get_number (&p);
971 error (_("Bad breakpoint argument: '%s'"), arg);
974 if (b->number == bnum)
976 /* Check if this breakpoint has a "stop" method implemented in an
977 extension language. This method and conditions entered into GDB
978 from the CLI are mutually exclusive. */
979 const struct extension_language_defn *extlang
980 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
984 error (_("Only one stop condition allowed. There is currently"
985 " a %s stop condition defined for this breakpoint."),
986 ext_lang_capitalized_name (extlang));
988 set_breakpoint_condition (b, p, from_tty);
990 if (is_breakpoint (b))
991 update_global_location_list (UGLL_MAY_INSERT);
996 error (_("No breakpoint number %d."), bnum);
999 /* Check that COMMAND do not contain commands that are suitable
1000 only for tracepoints and not suitable for ordinary breakpoints.
1001 Throw if any such commands is found. */
1004 check_no_tracepoint_commands (struct command_line *commands)
1006 struct command_line *c;
1008 for (c = commands; c; c = c->next)
1010 if (c->control_type == while_stepping_control)
1011 error (_("The 'while-stepping' command can "
1012 "only be used for tracepoints"));
1014 check_no_tracepoint_commands (c->body_list_0.get ());
1015 check_no_tracepoint_commands (c->body_list_1.get ());
1017 /* Not that command parsing removes leading whitespace and comment
1018 lines and also empty lines. So, we only need to check for
1019 command directly. */
1020 if (strstr (c->line, "collect ") == c->line)
1021 error (_("The 'collect' command can only be used for tracepoints"));
1023 if (strstr (c->line, "teval ") == c->line)
1024 error (_("The 'teval' command can only be used for tracepoints"));
1028 struct longjmp_breakpoint : public breakpoint
1030 ~longjmp_breakpoint () override;
1033 /* Encapsulate tests for different types of tracepoints. */
1036 is_tracepoint_type (bptype type)
1038 return (type == bp_tracepoint
1039 || type == bp_fast_tracepoint
1040 || type == bp_static_tracepoint);
1044 is_longjmp_type (bptype type)
1046 return type == bp_longjmp || type == bp_exception;
1050 is_tracepoint (const struct breakpoint *b)
1052 return is_tracepoint_type (b->type);
1055 /* Factory function to create an appropriate instance of breakpoint given
1058 static std::unique_ptr<breakpoint>
1059 new_breakpoint_from_type (bptype type)
1063 if (is_tracepoint_type (type))
1064 b = new tracepoint ();
1065 else if (is_longjmp_type (type))
1066 b = new longjmp_breakpoint ();
1068 b = new breakpoint ();
1070 return std::unique_ptr<breakpoint> (b);
1073 /* A helper function that validates that COMMANDS are valid for a
1074 breakpoint. This function will throw an exception if a problem is
1078 validate_commands_for_breakpoint (struct breakpoint *b,
1079 struct command_line *commands)
1081 if (is_tracepoint (b))
1083 struct tracepoint *t = (struct tracepoint *) b;
1084 struct command_line *c;
1085 struct command_line *while_stepping = 0;
1087 /* Reset the while-stepping step count. The previous commands
1088 might have included a while-stepping action, while the new
1092 /* We need to verify that each top-level element of commands is
1093 valid for tracepoints, that there's at most one
1094 while-stepping element, and that the while-stepping's body
1095 has valid tracing commands excluding nested while-stepping.
1096 We also need to validate the tracepoint action line in the
1097 context of the tracepoint --- validate_actionline actually
1098 has side effects, like setting the tracepoint's
1099 while-stepping STEP_COUNT, in addition to checking if the
1100 collect/teval actions parse and make sense in the
1101 tracepoint's context. */
1102 for (c = commands; c; c = c->next)
1104 if (c->control_type == while_stepping_control)
1106 if (b->type == bp_fast_tracepoint)
1107 error (_("The 'while-stepping' command "
1108 "cannot be used for fast tracepoint"));
1109 else if (b->type == bp_static_tracepoint)
1110 error (_("The 'while-stepping' command "
1111 "cannot be used for static tracepoint"));
1114 error (_("The 'while-stepping' command "
1115 "can be used only once"));
1120 validate_actionline (c->line, b);
1124 struct command_line *c2;
1126 gdb_assert (while_stepping->body_list_1 == nullptr);
1127 c2 = while_stepping->body_list_0.get ();
1128 for (; c2; c2 = c2->next)
1130 if (c2->control_type == while_stepping_control)
1131 error (_("The 'while-stepping' command cannot be nested"));
1137 check_no_tracepoint_commands (commands);
1141 /* Return a vector of all the static tracepoints set at ADDR. The
1142 caller is responsible for releasing the vector. */
1144 std::vector<breakpoint *>
1145 static_tracepoints_here (CORE_ADDR addr)
1147 struct breakpoint *b;
1148 std::vector<breakpoint *> found;
1149 struct bp_location *loc;
1152 if (b->type == bp_static_tracepoint)
1154 for (loc = b->loc; loc; loc = loc->next)
1155 if (loc->address == addr)
1156 found.push_back (b);
1162 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1163 validate that only allowed commands are included. */
1166 breakpoint_set_commands (struct breakpoint *b,
1167 counted_command_line &&commands)
1169 validate_commands_for_breakpoint (b, commands.get ());
1171 b->commands = std::move (commands);
1172 gdb::observers::breakpoint_modified.notify (b);
1175 /* Set the internal `silent' flag on the breakpoint. Note that this
1176 is not the same as the "silent" that may appear in the breakpoint's
1180 breakpoint_set_silent (struct breakpoint *b, int silent)
1182 int old_silent = b->silent;
1185 if (old_silent != silent)
1186 gdb::observers::breakpoint_modified.notify (b);
1189 /* Set the thread for this breakpoint. If THREAD is -1, make the
1190 breakpoint work for any thread. */
1193 breakpoint_set_thread (struct breakpoint *b, int thread)
1195 int old_thread = b->thread;
1198 if (old_thread != thread)
1199 gdb::observers::breakpoint_modified.notify (b);
1202 /* Set the task for this breakpoint. If TASK is 0, make the
1203 breakpoint work for any task. */
1206 breakpoint_set_task (struct breakpoint *b, int task)
1208 int old_task = b->task;
1211 if (old_task != task)
1212 gdb::observers::breakpoint_modified.notify (b);
1216 commands_command_1 (const char *arg, int from_tty,
1217 struct command_line *control)
1219 counted_command_line cmd;
1220 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1221 NULL after the call to read_command_lines if the user provides an empty
1222 list of command by just typing "end". */
1223 bool cmd_read = false;
1225 std::string new_arg;
1227 if (arg == NULL || !*arg)
1229 if (breakpoint_count - prev_breakpoint_count > 1)
1230 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1232 else if (breakpoint_count > 0)
1233 new_arg = string_printf ("%d", breakpoint_count);
1234 arg = new_arg.c_str ();
1237 map_breakpoint_numbers
1238 (arg, [&] (breakpoint *b)
1242 gdb_assert (cmd == NULL);
1243 if (control != NULL)
1244 cmd = control->body_list_0;
1248 = string_printf (_("Type commands for breakpoint(s) "
1249 "%s, one per line."),
1252 auto do_validate = [=] (const char *line)
1254 validate_actionline (line, b);
1256 gdb::function_view<void (const char *)> validator;
1257 if (is_tracepoint (b))
1258 validator = do_validate;
1260 cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
1265 /* If a breakpoint was on the list more than once, we don't need to
1267 if (b->commands != cmd)
1269 validate_commands_for_breakpoint (b, cmd.get ());
1271 gdb::observers::breakpoint_modified.notify (b);
1277 commands_command (const char *arg, int from_tty)
1279 commands_command_1 (arg, from_tty, NULL);
1282 /* Like commands_command, but instead of reading the commands from
1283 input stream, takes them from an already parsed command structure.
1285 This is used by cli-script.c to DTRT with breakpoint commands
1286 that are part of if and while bodies. */
1287 enum command_control_type
1288 commands_from_control_command (const char *arg, struct command_line *cmd)
1290 commands_command_1 (arg, 0, cmd);
1291 return simple_control;
1294 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1297 bp_location_has_shadow (struct bp_location *bl)
1299 if (bl->loc_type != bp_loc_software_breakpoint)
1303 if (bl->target_info.shadow_len == 0)
1304 /* BL isn't valid, or doesn't shadow memory. */
1309 /* Update BUF, which is LEN bytes read from the target address
1310 MEMADDR, by replacing a memory breakpoint with its shadowed
1313 If READBUF is not NULL, this buffer must not overlap with the of
1314 the breakpoint location's shadow_contents buffer. Otherwise, a
1315 failed assertion internal error will be raised. */
1318 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1319 const gdb_byte *writebuf_org,
1320 ULONGEST memaddr, LONGEST len,
1321 struct bp_target_info *target_info,
1322 struct gdbarch *gdbarch)
1324 /* Now do full processing of the found relevant range of elements. */
1325 CORE_ADDR bp_addr = 0;
1329 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1330 current_program_space->aspace, 0))
1332 /* The breakpoint is inserted in a different address space. */
1336 /* Addresses and length of the part of the breakpoint that
1338 bp_addr = target_info->placed_address;
1339 bp_size = target_info->shadow_len;
1341 if (bp_addr + bp_size <= memaddr)
1343 /* The breakpoint is entirely before the chunk of memory we are
1348 if (bp_addr >= memaddr + len)
1350 /* The breakpoint is entirely after the chunk of memory we are
1355 /* Offset within shadow_contents. */
1356 if (bp_addr < memaddr)
1358 /* Only copy the second part of the breakpoint. */
1359 bp_size -= memaddr - bp_addr;
1360 bptoffset = memaddr - bp_addr;
1364 if (bp_addr + bp_size > memaddr + len)
1366 /* Only copy the first part of the breakpoint. */
1367 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1370 if (readbuf != NULL)
1372 /* Verify that the readbuf buffer does not overlap with the
1373 shadow_contents buffer. */
1374 gdb_assert (target_info->shadow_contents >= readbuf + len
1375 || readbuf >= (target_info->shadow_contents
1376 + target_info->shadow_len));
1378 /* Update the read buffer with this inserted breakpoint's
1380 memcpy (readbuf + bp_addr - memaddr,
1381 target_info->shadow_contents + bptoffset, bp_size);
1385 const unsigned char *bp;
1386 CORE_ADDR addr = target_info->reqstd_address;
1389 /* Update the shadow with what we want to write to memory. */
1390 memcpy (target_info->shadow_contents + bptoffset,
1391 writebuf_org + bp_addr - memaddr, bp_size);
1393 /* Determine appropriate breakpoint contents and size for this
1395 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1397 /* Update the final write buffer with this inserted
1398 breakpoint's INSN. */
1399 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1403 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1404 by replacing any memory breakpoints with their shadowed contents.
1406 If READBUF is not NULL, this buffer must not overlap with any of
1407 the breakpoint location's shadow_contents buffers. Otherwise,
1408 a failed assertion internal error will be raised.
1410 The range of shadowed area by each bp_location is:
1411 bl->address - bp_locations_placed_address_before_address_max
1412 up to bl->address + bp_locations_shadow_len_after_address_max
1413 The range we were requested to resolve shadows for is:
1414 memaddr ... memaddr + len
1415 Thus the safe cutoff boundaries for performance optimization are
1416 memaddr + len <= (bl->address
1417 - bp_locations_placed_address_before_address_max)
1419 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1422 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1423 const gdb_byte *writebuf_org,
1424 ULONGEST memaddr, LONGEST len)
1426 /* Left boundary, right boundary and median element of our binary
1428 unsigned bc_l, bc_r, bc;
1430 /* Find BC_L which is a leftmost element which may affect BUF
1431 content. It is safe to report lower value but a failure to
1432 report higher one. */
1435 bc_r = bp_locations_count;
1436 while (bc_l + 1 < bc_r)
1438 struct bp_location *bl;
1440 bc = (bc_l + bc_r) / 2;
1441 bl = bp_locations[bc];
1443 /* Check first BL->ADDRESS will not overflow due to the added
1444 constant. Then advance the left boundary only if we are sure
1445 the BC element can in no way affect the BUF content (MEMADDR
1446 to MEMADDR + LEN range).
1448 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1449 offset so that we cannot miss a breakpoint with its shadow
1450 range tail still reaching MEMADDR. */
1452 if ((bl->address + bp_locations_shadow_len_after_address_max
1454 && (bl->address + bp_locations_shadow_len_after_address_max
1461 /* Due to the binary search above, we need to make sure we pick the
1462 first location that's at BC_L's address. E.g., if there are
1463 multiple locations at the same address, BC_L may end up pointing
1464 at a duplicate location, and miss the "master"/"inserted"
1465 location. Say, given locations L1, L2 and L3 at addresses A and
1468 L1@A, L2@A, L3@B, ...
1470 BC_L could end up pointing at location L2, while the "master"
1471 location could be L1. Since the `loc->inserted' flag is only set
1472 on "master" locations, we'd forget to restore the shadow of L1
1475 && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
1478 /* Now do full processing of the found relevant range of elements. */
1480 for (bc = bc_l; bc < bp_locations_count; bc++)
1482 struct bp_location *bl = bp_locations[bc];
1484 /* bp_location array has BL->OWNER always non-NULL. */
1485 if (bl->owner->type == bp_none)
1486 warning (_("reading through apparently deleted breakpoint #%d?"),
1489 /* Performance optimization: any further element can no longer affect BUF
1492 if (bl->address >= bp_locations_placed_address_before_address_max
1493 && memaddr + len <= (bl->address
1494 - bp_locations_placed_address_before_address_max))
1497 if (!bp_location_has_shadow (bl))
1500 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1501 memaddr, len, &bl->target_info, bl->gdbarch);
1507 /* Return true if BPT is either a software breakpoint or a hardware
1511 is_breakpoint (const struct breakpoint *bpt)
1513 return (bpt->type == bp_breakpoint
1514 || bpt->type == bp_hardware_breakpoint
1515 || bpt->type == bp_dprintf);
1518 /* Return true if BPT is of any hardware watchpoint kind. */
1521 is_hardware_watchpoint (const struct breakpoint *bpt)
1523 return (bpt->type == bp_hardware_watchpoint
1524 || bpt->type == bp_read_watchpoint
1525 || bpt->type == bp_access_watchpoint);
1528 /* Return true if BPT is of any watchpoint kind, hardware or
1532 is_watchpoint (const struct breakpoint *bpt)
1534 return (is_hardware_watchpoint (bpt)
1535 || bpt->type == bp_watchpoint);
1538 /* Returns true if the current thread and its running state are safe
1539 to evaluate or update watchpoint B. Watchpoints on local
1540 expressions need to be evaluated in the context of the thread that
1541 was current when the watchpoint was created, and, that thread needs
1542 to be stopped to be able to select the correct frame context.
1543 Watchpoints on global expressions can be evaluated on any thread,
1544 and in any state. It is presently left to the target allowing
1545 memory accesses when threads are running. */
1548 watchpoint_in_thread_scope (struct watchpoint *b)
1550 return (b->pspace == current_program_space
1551 && (b->watchpoint_thread == null_ptid
1552 || (inferior_ptid == b->watchpoint_thread
1553 && !inferior_thread ()->executing)));
1556 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1557 associated bp_watchpoint_scope breakpoint. */
1560 watchpoint_del_at_next_stop (struct watchpoint *w)
1562 if (w->related_breakpoint != w)
1564 gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope);
1565 gdb_assert (w->related_breakpoint->related_breakpoint == w);
1566 w->related_breakpoint->disposition = disp_del_at_next_stop;
1567 w->related_breakpoint->related_breakpoint = w->related_breakpoint;
1568 w->related_breakpoint = w;
1570 w->disposition = disp_del_at_next_stop;
1573 /* Extract a bitfield value from value VAL using the bit parameters contained in
1576 static struct value *
1577 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1579 struct value *bit_val;
1584 bit_val = allocate_value (value_type (val));
1586 unpack_value_bitfield (bit_val,
1589 value_contents_for_printing (val),
1596 /* Allocate a dummy location and add it to B, which must be a software
1597 watchpoint. This is required because even if a software watchpoint
1598 is not watching any memory, bpstat_stop_status requires a location
1599 to be able to report stops. */
1602 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1603 struct program_space *pspace)
1605 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1607 b->loc = allocate_bp_location (b);
1608 b->loc->pspace = pspace;
1609 b->loc->address = -1;
1610 b->loc->length = -1;
1613 /* Returns true if B is a software watchpoint that is not watching any
1614 memory (e.g., "watch $pc"). */
1617 is_no_memory_software_watchpoint (struct breakpoint *b)
1619 return (b->type == bp_watchpoint
1621 && b->loc->next == NULL
1622 && b->loc->address == -1
1623 && b->loc->length == -1);
1626 /* Assuming that B is a watchpoint:
1627 - Reparse watchpoint expression, if REPARSE is non-zero
1628 - Evaluate expression and store the result in B->val
1629 - Evaluate the condition if there is one, and store the result
1631 - Update the list of values that must be watched in B->loc.
1633 If the watchpoint disposition is disp_del_at_next_stop, then do
1634 nothing. If this is local watchpoint that is out of scope, delete
1637 Even with `set breakpoint always-inserted on' the watchpoints are
1638 removed + inserted on each stop here. Normal breakpoints must
1639 never be removed because they might be missed by a running thread
1640 when debugging in non-stop mode. On the other hand, hardware
1641 watchpoints (is_hardware_watchpoint; processed here) are specific
1642 to each LWP since they are stored in each LWP's hardware debug
1643 registers. Therefore, such LWP must be stopped first in order to
1644 be able to modify its hardware watchpoints.
1646 Hardware watchpoints must be reset exactly once after being
1647 presented to the user. It cannot be done sooner, because it would
1648 reset the data used to present the watchpoint hit to the user. And
1649 it must not be done later because it could display the same single
1650 watchpoint hit during multiple GDB stops. Note that the latter is
1651 relevant only to the hardware watchpoint types bp_read_watchpoint
1652 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1653 not user-visible - its hit is suppressed if the memory content has
1656 The following constraints influence the location where we can reset
1657 hardware watchpoints:
1659 * target_stopped_by_watchpoint and target_stopped_data_address are
1660 called several times when GDB stops.
1663 * Multiple hardware watchpoints can be hit at the same time,
1664 causing GDB to stop. GDB only presents one hardware watchpoint
1665 hit at a time as the reason for stopping, and all the other hits
1666 are presented later, one after the other, each time the user
1667 requests the execution to be resumed. Execution is not resumed
1668 for the threads still having pending hit event stored in
1669 LWP_INFO->STATUS. While the watchpoint is already removed from
1670 the inferior on the first stop the thread hit event is kept being
1671 reported from its cached value by linux_nat_stopped_data_address
1672 until the real thread resume happens after the watchpoint gets
1673 presented and thus its LWP_INFO->STATUS gets reset.
1675 Therefore the hardware watchpoint hit can get safely reset on the
1676 watchpoint removal from inferior. */
1679 update_watchpoint (struct watchpoint *b, int reparse)
1681 int within_current_scope;
1682 struct frame_id saved_frame_id;
1685 /* If this is a local watchpoint, we only want to check if the
1686 watchpoint frame is in scope if the current thread is the thread
1687 that was used to create the watchpoint. */
1688 if (!watchpoint_in_thread_scope (b))
1691 if (b->disposition == disp_del_at_next_stop)
1696 /* Determine if the watchpoint is within scope. */
1697 if (b->exp_valid_block == NULL)
1698 within_current_scope = 1;
1701 struct frame_info *fi = get_current_frame ();
1702 struct gdbarch *frame_arch = get_frame_arch (fi);
1703 CORE_ADDR frame_pc = get_frame_pc (fi);
1705 /* If we're at a point where the stack has been destroyed
1706 (e.g. in a function epilogue), unwinding may not work
1707 properly. Do not attempt to recreate locations at this
1708 point. See similar comments in watchpoint_check. */
1709 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1712 /* Save the current frame's ID so we can restore it after
1713 evaluating the watchpoint expression on its own frame. */
1714 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1715 took a frame parameter, so that we didn't have to change the
1718 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1720 fi = frame_find_by_id (b->watchpoint_frame);
1721 within_current_scope = (fi != NULL);
1722 if (within_current_scope)
1726 /* We don't free locations. They are stored in the bp_location array
1727 and update_global_location_list will eventually delete them and
1728 remove breakpoints if needed. */
1731 if (within_current_scope && reparse)
1736 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1737 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1738 /* If the meaning of expression itself changed, the old value is
1739 no longer relevant. We don't want to report a watchpoint hit
1740 to the user when the old value and the new value may actually
1741 be completely different objects. */
1745 /* Note that unlike with breakpoints, the watchpoint's condition
1746 expression is stored in the breakpoint object, not in the
1747 locations (re)created below. */
1748 if (b->cond_string != NULL)
1750 b->cond_exp.reset ();
1753 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1757 /* If we failed to parse the expression, for example because
1758 it refers to a global variable in a not-yet-loaded shared library,
1759 don't try to insert watchpoint. We don't automatically delete
1760 such watchpoint, though, since failure to parse expression
1761 is different from out-of-scope watchpoint. */
1762 if (!target_has_execution)
1764 /* Without execution, memory can't change. No use to try and
1765 set watchpoint locations. The watchpoint will be reset when
1766 the target gains execution, through breakpoint_re_set. */
1767 if (!can_use_hw_watchpoints)
1769 if (b->ops->works_in_software_mode (b))
1770 b->type = bp_watchpoint;
1772 error (_("Can't set read/access watchpoint when "
1773 "hardware watchpoints are disabled."));
1776 else if (within_current_scope && b->exp)
1779 std::vector<value_ref_ptr> val_chain;
1780 struct value *v, *result;
1781 struct program_space *frame_pspace;
1783 fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
1785 /* Avoid setting b->val if it's already set. The meaning of
1786 b->val is 'the last value' user saw, and we should update
1787 it only if we reported that last value to user. As it
1788 happens, the code that reports it updates b->val directly.
1789 We don't keep track of the memory value for masked
1791 if (!b->val_valid && !is_masked_watchpoint (b))
1793 if (b->val_bitsize != 0)
1794 v = extract_bitfield_from_watchpoint_value (b, v);
1795 b->val = release_value (v);
1799 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1801 /* Look at each value on the value chain. */
1802 gdb_assert (!val_chain.empty ());
1803 for (const value_ref_ptr &iter : val_chain)
1807 /* If it's a memory location, and GDB actually needed
1808 its contents to evaluate the expression, then we
1809 must watch it. If the first value returned is
1810 still lazy, that means an error occurred reading it;
1811 watch it anyway in case it becomes readable. */
1812 if (VALUE_LVAL (v) == lval_memory
1813 && (v == val_chain[0] || ! value_lazy (v)))
1815 struct type *vtype = check_typedef (value_type (v));
1817 /* We only watch structs and arrays if user asked
1818 for it explicitly, never if they just happen to
1819 appear in the middle of some value chain. */
1821 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1822 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1825 enum target_hw_bp_type type;
1826 struct bp_location *loc, **tmp;
1827 int bitpos = 0, bitsize = 0;
1829 if (value_bitsize (v) != 0)
1831 /* Extract the bit parameters out from the bitfield
1833 bitpos = value_bitpos (v);
1834 bitsize = value_bitsize (v);
1836 else if (v == result && b->val_bitsize != 0)
1838 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1839 lvalue whose bit parameters are saved in the fields
1840 VAL_BITPOS and VAL_BITSIZE. */
1841 bitpos = b->val_bitpos;
1842 bitsize = b->val_bitsize;
1845 addr = value_address (v);
1848 /* Skip the bytes that don't contain the bitfield. */
1853 if (b->type == bp_read_watchpoint)
1855 else if (b->type == bp_access_watchpoint)
1858 loc = allocate_bp_location (b);
1859 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1862 loc->gdbarch = get_type_arch (value_type (v));
1864 loc->pspace = frame_pspace;
1865 loc->address = address_significant (loc->gdbarch, addr);
1869 /* Just cover the bytes that make up the bitfield. */
1870 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
1873 loc->length = TYPE_LENGTH (value_type (v));
1875 loc->watchpoint_type = type;
1880 /* Change the type of breakpoint between hardware assisted or
1881 an ordinary watchpoint depending on the hardware support
1882 and free hardware slots. REPARSE is set when the inferior
1887 enum bp_loc_type loc_type;
1888 struct bp_location *bl;
1890 reg_cnt = can_use_hardware_watchpoint (val_chain);
1894 int i, target_resources_ok, other_type_used;
1897 /* Use an exact watchpoint when there's only one memory region to be
1898 watched, and only one debug register is needed to watch it. */
1899 b->exact = target_exact_watchpoints && reg_cnt == 1;
1901 /* We need to determine how many resources are already
1902 used for all other hardware watchpoints plus this one
1903 to see if we still have enough resources to also fit
1904 this watchpoint in as well. */
1906 /* If this is a software watchpoint, we try to turn it
1907 to a hardware one -- count resources as if B was of
1908 hardware watchpoint type. */
1910 if (type == bp_watchpoint)
1911 type = bp_hardware_watchpoint;
1913 /* This watchpoint may or may not have been placed on
1914 the list yet at this point (it won't be in the list
1915 if we're trying to create it for the first time,
1916 through watch_command), so always account for it
1919 /* Count resources used by all watchpoints except B. */
1920 i = hw_watchpoint_used_count_others (b, type, &other_type_used);
1922 /* Add in the resources needed for B. */
1923 i += hw_watchpoint_use_count (b);
1926 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1927 if (target_resources_ok <= 0)
1929 int sw_mode = b->ops->works_in_software_mode (b);
1931 if (target_resources_ok == 0 && !sw_mode)
1932 error (_("Target does not support this type of "
1933 "hardware watchpoint."));
1934 else if (target_resources_ok < 0 && !sw_mode)
1935 error (_("There are not enough available hardware "
1936 "resources for this watchpoint."));
1938 /* Downgrade to software watchpoint. */
1939 b->type = bp_watchpoint;
1943 /* If this was a software watchpoint, we've just
1944 found we have enough resources to turn it to a
1945 hardware watchpoint. Otherwise, this is a
1950 else if (!b->ops->works_in_software_mode (b))
1952 if (!can_use_hw_watchpoints)
1953 error (_("Can't set read/access watchpoint when "
1954 "hardware watchpoints are disabled."));
1956 error (_("Expression cannot be implemented with "
1957 "read/access watchpoint."));
1960 b->type = bp_watchpoint;
1962 loc_type = (b->type == bp_watchpoint? bp_loc_other
1963 : bp_loc_hardware_watchpoint);
1964 for (bl = b->loc; bl; bl = bl->next)
1965 bl->loc_type = loc_type;
1968 /* If a software watchpoint is not watching any memory, then the
1969 above left it without any location set up. But,
1970 bpstat_stop_status requires a location to be able to report
1971 stops, so make sure there's at least a dummy one. */
1972 if (b->type == bp_watchpoint && b->loc == NULL)
1973 software_watchpoint_add_no_memory_location (b, frame_pspace);
1975 else if (!within_current_scope)
1977 printf_filtered (_("\
1978 Watchpoint %d deleted because the program has left the block\n\
1979 in which its expression is valid.\n"),
1981 watchpoint_del_at_next_stop (b);
1984 /* Restore the selected frame. */
1986 select_frame (frame_find_by_id (saved_frame_id));
1990 /* Returns 1 iff breakpoint location should be
1991 inserted in the inferior. We don't differentiate the type of BL's owner
1992 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1993 breakpoint_ops is not defined, because in insert_bp_location,
1994 tracepoint's insert_location will not be called. */
1996 should_be_inserted (struct bp_location *bl)
1998 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2001 if (bl->owner->disposition == disp_del_at_next_stop)
2004 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2007 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2010 /* This is set for example, when we're attached to the parent of a
2011 vfork, and have detached from the child. The child is running
2012 free, and we expect it to do an exec or exit, at which point the
2013 OS makes the parent schedulable again (and the target reports
2014 that the vfork is done). Until the child is done with the shared
2015 memory region, do not insert breakpoints in the parent, otherwise
2016 the child could still trip on the parent's breakpoints. Since
2017 the parent is blocked anyway, it won't miss any breakpoint. */
2018 if (bl->pspace->breakpoints_not_allowed)
2021 /* Don't insert a breakpoint if we're trying to step past its
2022 location, except if the breakpoint is a single-step breakpoint,
2023 and the breakpoint's thread is the thread which is stepping past
2025 if ((bl->loc_type == bp_loc_software_breakpoint
2026 || bl->loc_type == bp_loc_hardware_breakpoint)
2027 && stepping_past_instruction_at (bl->pspace->aspace,
2029 /* The single-step breakpoint may be inserted at the location
2030 we're trying to step if the instruction branches to itself.
2031 However, the instruction won't be executed at all and it may
2032 break the semantics of the instruction, for example, the
2033 instruction is a conditional branch or updates some flags.
2034 We can't fix it unless GDB is able to emulate the instruction
2035 or switch to displaced stepping. */
2036 && !(bl->owner->type == bp_single_step
2037 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2041 fprintf_unfiltered (gdb_stdlog,
2042 "infrun: skipping breakpoint: "
2043 "stepping past insn at: %s\n",
2044 paddress (bl->gdbarch, bl->address));
2049 /* Don't insert watchpoints if we're trying to step past the
2050 instruction that triggered one. */
2051 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2052 && stepping_past_nonsteppable_watchpoint ())
2056 fprintf_unfiltered (gdb_stdlog,
2057 "infrun: stepping past non-steppable watchpoint. "
2058 "skipping watchpoint at %s:%d\n",
2059 paddress (bl->gdbarch, bl->address),
2068 /* Same as should_be_inserted but does the check assuming
2069 that the location is not duplicated. */
2072 unduplicated_should_be_inserted (struct bp_location *bl)
2075 const int save_duplicate = bl->duplicate;
2078 result = should_be_inserted (bl);
2079 bl->duplicate = save_duplicate;
2083 /* Parses a conditional described by an expression COND into an
2084 agent expression bytecode suitable for evaluation
2085 by the bytecode interpreter. Return NULL if there was
2086 any error during parsing. */
2088 static agent_expr_up
2089 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2094 agent_expr_up aexpr;
2096 /* We don't want to stop processing, so catch any errors
2097 that may show up. */
2100 aexpr = gen_eval_for_expr (scope, cond);
2103 CATCH (ex, RETURN_MASK_ERROR)
2105 /* If we got here, it means the condition could not be parsed to a valid
2106 bytecode expression and thus can't be evaluated on the target's side.
2107 It's no use iterating through the conditions. */
2111 /* We have a valid agent expression. */
2115 /* Based on location BL, create a list of breakpoint conditions to be
2116 passed on to the target. If we have duplicated locations with different
2117 conditions, we will add such conditions to the list. The idea is that the
2118 target will evaluate the list of conditions and will only notify GDB when
2119 one of them is true. */
2122 build_target_condition_list (struct bp_location *bl)
2124 struct bp_location **locp = NULL, **loc2p;
2125 int null_condition_or_parse_error = 0;
2126 int modified = bl->needs_update;
2127 struct bp_location *loc;
2129 /* Release conditions left over from a previous insert. */
2130 bl->target_info.conditions.clear ();
2132 /* This is only meaningful if the target is
2133 evaluating conditions and if the user has
2134 opted for condition evaluation on the target's
2136 if (gdb_evaluates_breakpoint_condition_p ()
2137 || !target_supports_evaluation_of_breakpoint_conditions ())
2140 /* Do a first pass to check for locations with no assigned
2141 conditions or conditions that fail to parse to a valid agent expression
2142 bytecode. If any of these happen, then it's no use to send conditions
2143 to the target since this location will always trigger and generate a
2144 response back to GDB. */
2145 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2148 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2152 /* Re-parse the conditions since something changed. In that
2153 case we already freed the condition bytecodes (see
2154 force_breakpoint_reinsertion). We just
2155 need to parse the condition to bytecodes again. */
2156 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2160 /* If we have a NULL bytecode expression, it means something
2161 went wrong or we have a null condition expression. */
2162 if (!loc->cond_bytecode)
2164 null_condition_or_parse_error = 1;
2170 /* If any of these happened, it means we will have to evaluate the conditions
2171 for the location's address on gdb's side. It is no use keeping bytecodes
2172 for all the other duplicate locations, thus we free all of them here.
2174 This is so we have a finer control over which locations' conditions are
2175 being evaluated by GDB or the remote stub. */
2176 if (null_condition_or_parse_error)
2178 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2181 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2183 /* Only go as far as the first NULL bytecode is
2185 if (!loc->cond_bytecode)
2188 loc->cond_bytecode.reset ();
2193 /* No NULL conditions or failed bytecode generation. Build a condition list
2194 for this location's address. */
2195 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2199 && is_breakpoint (loc->owner)
2200 && loc->pspace->num == bl->pspace->num
2201 && loc->owner->enable_state == bp_enabled
2204 /* Add the condition to the vector. This will be used later
2205 to send the conditions to the target. */
2206 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2213 /* Parses a command described by string CMD into an agent expression
2214 bytecode suitable for evaluation by the bytecode interpreter.
2215 Return NULL if there was any error during parsing. */
2217 static agent_expr_up
2218 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2220 const char *cmdrest;
2221 const char *format_start, *format_end;
2222 struct gdbarch *gdbarch = get_current_arch ();
2229 if (*cmdrest == ',')
2231 cmdrest = skip_spaces (cmdrest);
2233 if (*cmdrest++ != '"')
2234 error (_("No format string following the location"));
2236 format_start = cmdrest;
2238 format_pieces fpieces (&cmdrest);
2240 format_end = cmdrest;
2242 if (*cmdrest++ != '"')
2243 error (_("Bad format string, non-terminated '\"'."));
2245 cmdrest = skip_spaces (cmdrest);
2247 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2248 error (_("Invalid argument syntax"));
2250 if (*cmdrest == ',')
2252 cmdrest = skip_spaces (cmdrest);
2254 /* For each argument, make an expression. */
2256 std::vector<struct expression *> argvec;
2257 while (*cmdrest != '\0')
2262 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2263 argvec.push_back (expr.release ());
2265 if (*cmdrest == ',')
2269 agent_expr_up aexpr;
2271 /* We don't want to stop processing, so catch any errors
2272 that may show up. */
2275 aexpr = gen_printf (scope, gdbarch, 0, 0,
2276 format_start, format_end - format_start,
2277 argvec.size (), argvec.data ());
2279 CATCH (ex, RETURN_MASK_ERROR)
2281 /* If we got here, it means the command could not be parsed to a valid
2282 bytecode expression and thus can't be evaluated on the target's side.
2283 It's no use iterating through the other commands. */
2287 /* We have a valid agent expression, return it. */
2291 /* Based on location BL, create a list of breakpoint commands to be
2292 passed on to the target. If we have duplicated locations with
2293 different commands, we will add any such to the list. */
2296 build_target_command_list (struct bp_location *bl)
2298 struct bp_location **locp = NULL, **loc2p;
2299 int null_command_or_parse_error = 0;
2300 int modified = bl->needs_update;
2301 struct bp_location *loc;
2303 /* Clear commands left over from a previous insert. */
2304 bl->target_info.tcommands.clear ();
2306 if (!target_can_run_breakpoint_commands ())
2309 /* For now, limit to agent-style dprintf breakpoints. */
2310 if (dprintf_style != dprintf_style_agent)
2313 /* For now, if we have any duplicate location that isn't a dprintf,
2314 don't install the target-side commands, as that would make the
2315 breakpoint not be reported to the core, and we'd lose
2317 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2320 if (is_breakpoint (loc->owner)
2321 && loc->pspace->num == bl->pspace->num
2322 && loc->owner->type != bp_dprintf)
2326 /* Do a first pass to check for locations with no assigned
2327 conditions or conditions that fail to parse to a valid agent expression
2328 bytecode. If any of these happen, then it's no use to send conditions
2329 to the target since this location will always trigger and generate a
2330 response back to GDB. */
2331 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2334 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2338 /* Re-parse the commands since something changed. In that
2339 case we already freed the command bytecodes (see
2340 force_breakpoint_reinsertion). We just
2341 need to parse the command to bytecodes again. */
2343 = parse_cmd_to_aexpr (bl->address,
2344 loc->owner->extra_string);
2347 /* If we have a NULL bytecode expression, it means something
2348 went wrong or we have a null command expression. */
2349 if (!loc->cmd_bytecode)
2351 null_command_or_parse_error = 1;
2357 /* If anything failed, then we're not doing target-side commands,
2359 if (null_command_or_parse_error)
2361 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2364 if (is_breakpoint (loc->owner)
2365 && loc->pspace->num == bl->pspace->num)
2367 /* Only go as far as the first NULL bytecode is
2369 if (loc->cmd_bytecode == NULL)
2372 loc->cmd_bytecode.reset ();
2377 /* No NULL commands or failed bytecode generation. Build a command list
2378 for this location's address. */
2379 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2382 if (loc->owner->extra_string
2383 && is_breakpoint (loc->owner)
2384 && loc->pspace->num == bl->pspace->num
2385 && loc->owner->enable_state == bp_enabled
2388 /* Add the command to the vector. This will be used later
2389 to send the commands to the target. */
2390 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2394 bl->target_info.persist = 0;
2395 /* Maybe flag this location as persistent. */
2396 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2397 bl->target_info.persist = 1;
2400 /* Return the kind of breakpoint on address *ADDR. Get the kind
2401 of breakpoint according to ADDR except single-step breakpoint.
2402 Get the kind of single-step breakpoint according to the current
2406 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2408 if (bl->owner->type == bp_single_step)
2410 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2411 struct regcache *regcache;
2413 regcache = get_thread_regcache (thr);
2415 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2419 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2422 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2423 location. Any error messages are printed to TMP_ERROR_STREAM; and
2424 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2425 Returns 0 for success, 1 if the bp_location type is not supported or
2428 NOTE drow/2003-09-09: This routine could be broken down to an
2429 object-style method for each breakpoint or catchpoint type. */
2431 insert_bp_location (struct bp_location *bl,
2432 struct ui_file *tmp_error_stream,
2433 int *disabled_breaks,
2434 int *hw_breakpoint_error,
2435 int *hw_bp_error_explained_already)
2437 gdb_exception bp_excpt = exception_none;
2439 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2442 /* Note we don't initialize bl->target_info, as that wipes out
2443 the breakpoint location's shadow_contents if the breakpoint
2444 is still inserted at that location. This in turn breaks
2445 target_read_memory which depends on these buffers when
2446 a memory read is requested at the breakpoint location:
2447 Once the target_info has been wiped, we fail to see that
2448 we have a breakpoint inserted at that address and thus
2449 read the breakpoint instead of returning the data saved in
2450 the breakpoint location's shadow contents. */
2451 bl->target_info.reqstd_address = bl->address;
2452 bl->target_info.placed_address_space = bl->pspace->aspace;
2453 bl->target_info.length = bl->length;
2455 /* When working with target-side conditions, we must pass all the conditions
2456 for the same breakpoint address down to the target since GDB will not
2457 insert those locations. With a list of breakpoint conditions, the target
2458 can decide when to stop and notify GDB. */
2460 if (is_breakpoint (bl->owner))
2462 build_target_condition_list (bl);
2463 build_target_command_list (bl);
2464 /* Reset the modification marker. */
2465 bl->needs_update = 0;
2468 if (bl->loc_type == bp_loc_software_breakpoint
2469 || bl->loc_type == bp_loc_hardware_breakpoint)
2471 if (bl->owner->type != bp_hardware_breakpoint)
2473 /* If the explicitly specified breakpoint type
2474 is not hardware breakpoint, check the memory map to see
2475 if the breakpoint address is in read only memory or not.
2477 Two important cases are:
2478 - location type is not hardware breakpoint, memory
2479 is readonly. We change the type of the location to
2480 hardware breakpoint.
2481 - location type is hardware breakpoint, memory is
2482 read-write. This means we've previously made the
2483 location hardware one, but then the memory map changed,
2486 When breakpoints are removed, remove_breakpoints will use
2487 location types we've just set here, the only possible
2488 problem is that memory map has changed during running
2489 program, but it's not going to work anyway with current
2491 struct mem_region *mr
2492 = lookup_mem_region (bl->target_info.reqstd_address);
2496 if (automatic_hardware_breakpoints)
2498 enum bp_loc_type new_type;
2500 if (mr->attrib.mode != MEM_RW)
2501 new_type = bp_loc_hardware_breakpoint;
2503 new_type = bp_loc_software_breakpoint;
2505 if (new_type != bl->loc_type)
2507 static int said = 0;
2509 bl->loc_type = new_type;
2512 fprintf_filtered (gdb_stdout,
2513 _("Note: automatically using "
2514 "hardware breakpoints for "
2515 "read-only addresses.\n"));
2520 else if (bl->loc_type == bp_loc_software_breakpoint
2521 && mr->attrib.mode != MEM_RW)
2523 fprintf_unfiltered (tmp_error_stream,
2524 _("Cannot insert breakpoint %d.\n"
2525 "Cannot set software breakpoint "
2526 "at read-only address %s\n"),
2528 paddress (bl->gdbarch, bl->address));
2534 /* First check to see if we have to handle an overlay. */
2535 if (overlay_debugging == ovly_off
2536 || bl->section == NULL
2537 || !(section_is_overlay (bl->section)))
2539 /* No overlay handling: just set the breakpoint. */
2544 val = bl->owner->ops->insert_location (bl);
2546 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2548 CATCH (e, RETURN_MASK_ALL)
2556 /* This breakpoint is in an overlay section.
2557 Shall we set a breakpoint at the LMA? */
2558 if (!overlay_events_enabled)
2560 /* Yes -- overlay event support is not active,
2561 so we must try to set a breakpoint at the LMA.
2562 This will not work for a hardware breakpoint. */
2563 if (bl->loc_type == bp_loc_hardware_breakpoint)
2564 warning (_("hardware breakpoint %d not supported in overlay!"),
2568 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2570 /* Set a software (trap) breakpoint at the LMA. */
2571 bl->overlay_target_info = bl->target_info;
2572 bl->overlay_target_info.reqstd_address = addr;
2574 /* No overlay handling: just set the breakpoint. */
2579 bl->overlay_target_info.kind
2580 = breakpoint_kind (bl, &addr);
2581 bl->overlay_target_info.placed_address = addr;
2582 val = target_insert_breakpoint (bl->gdbarch,
2583 &bl->overlay_target_info);
2586 = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2588 CATCH (e, RETURN_MASK_ALL)
2594 if (bp_excpt.reason != 0)
2595 fprintf_unfiltered (tmp_error_stream,
2596 "Overlay breakpoint %d "
2597 "failed: in ROM?\n",
2601 /* Shall we set a breakpoint at the VMA? */
2602 if (section_is_mapped (bl->section))
2604 /* Yes. This overlay section is mapped into memory. */
2609 val = bl->owner->ops->insert_location (bl);
2611 bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
2613 CATCH (e, RETURN_MASK_ALL)
2621 /* No. This breakpoint will not be inserted.
2622 No error, but do not mark the bp as 'inserted'. */
2627 if (bp_excpt.reason != 0)
2629 /* Can't set the breakpoint. */
2631 /* In some cases, we might not be able to insert a
2632 breakpoint in a shared library that has already been
2633 removed, but we have not yet processed the shlib unload
2634 event. Unfortunately, some targets that implement
2635 breakpoint insertion themselves can't tell why the
2636 breakpoint insertion failed (e.g., the remote target
2637 doesn't define error codes), so we must treat generic
2638 errors as memory errors. */
2639 if (bp_excpt.reason == RETURN_ERROR
2640 && (bp_excpt.error == GENERIC_ERROR
2641 || bp_excpt.error == MEMORY_ERROR)
2642 && bl->loc_type == bp_loc_software_breakpoint
2643 && (solib_name_from_address (bl->pspace, bl->address)
2644 || shared_objfile_contains_address_p (bl->pspace,
2647 /* See also: disable_breakpoints_in_shlibs. */
2648 bl->shlib_disabled = 1;
2649 gdb::observers::breakpoint_modified.notify (bl->owner);
2650 if (!*disabled_breaks)
2652 fprintf_unfiltered (tmp_error_stream,
2653 "Cannot insert breakpoint %d.\n",
2655 fprintf_unfiltered (tmp_error_stream,
2656 "Temporarily disabling shared "
2657 "library breakpoints:\n");
2659 *disabled_breaks = 1;
2660 fprintf_unfiltered (tmp_error_stream,
2661 "breakpoint #%d\n", bl->owner->number);
2666 if (bl->loc_type == bp_loc_hardware_breakpoint)
2668 *hw_breakpoint_error = 1;
2669 *hw_bp_error_explained_already = bp_excpt.message != NULL;
2670 fprintf_unfiltered (tmp_error_stream,
2671 "Cannot insert hardware breakpoint %d%s",
2673 bp_excpt.message ? ":" : ".\n");
2674 if (bp_excpt.message != NULL)
2675 fprintf_unfiltered (tmp_error_stream, "%s.\n",
2680 if (bp_excpt.message == NULL)
2683 = memory_error_message (TARGET_XFER_E_IO,
2684 bl->gdbarch, bl->address);
2686 fprintf_unfiltered (tmp_error_stream,
2687 "Cannot insert breakpoint %d.\n"
2689 bl->owner->number, message.c_str ());
2693 fprintf_unfiltered (tmp_error_stream,
2694 "Cannot insert breakpoint %d: %s\n",
2709 else if (bl->loc_type == bp_loc_hardware_watchpoint
2710 /* NOTE drow/2003-09-08: This state only exists for removing
2711 watchpoints. It's not clear that it's necessary... */
2712 && bl->owner->disposition != disp_del_at_next_stop)
2716 gdb_assert (bl->owner->ops != NULL
2717 && bl->owner->ops->insert_location != NULL);
2719 val = bl->owner->ops->insert_location (bl);
2721 /* If trying to set a read-watchpoint, and it turns out it's not
2722 supported, try emulating one with an access watchpoint. */
2723 if (val == 1 && bl->watchpoint_type == hw_read)
2725 struct bp_location *loc, **loc_temp;
2727 /* But don't try to insert it, if there's already another
2728 hw_access location that would be considered a duplicate
2730 ALL_BP_LOCATIONS (loc, loc_temp)
2732 && loc->watchpoint_type == hw_access
2733 && watchpoint_locations_match (bl, loc))
2737 bl->target_info = loc->target_info;
2738 bl->watchpoint_type = hw_access;
2745 bl->watchpoint_type = hw_access;
2746 val = bl->owner->ops->insert_location (bl);
2749 /* Back to the original value. */
2750 bl->watchpoint_type = hw_read;
2754 bl->inserted = (val == 0);
2757 else if (bl->owner->type == bp_catchpoint)
2761 gdb_assert (bl->owner->ops != NULL
2762 && bl->owner->ops->insert_location != NULL);
2764 val = bl->owner->ops->insert_location (bl);
2767 bl->owner->enable_state = bp_disabled;
2771 Error inserting catchpoint %d: Your system does not support this type\n\
2772 of catchpoint."), bl->owner->number);
2774 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2777 bl->inserted = (val == 0);
2779 /* We've already printed an error message if there was a problem
2780 inserting this catchpoint, and we've disabled the catchpoint,
2781 so just return success. */
2788 /* This function is called when program space PSPACE is about to be
2789 deleted. It takes care of updating breakpoints to not reference
2793 breakpoint_program_space_exit (struct program_space *pspace)
2795 struct breakpoint *b, *b_temp;
2796 struct bp_location *loc, **loc_temp;
2798 /* Remove any breakpoint that was set through this program space. */
2799 ALL_BREAKPOINTS_SAFE (b, b_temp)
2801 if (b->pspace == pspace)
2802 delete_breakpoint (b);
2805 /* Breakpoints set through other program spaces could have locations
2806 bound to PSPACE as well. Remove those. */
2807 ALL_BP_LOCATIONS (loc, loc_temp)
2809 struct bp_location *tmp;
2811 if (loc->pspace == pspace)
2813 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2814 if (loc->owner->loc == loc)
2815 loc->owner->loc = loc->next;
2817 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2818 if (tmp->next == loc)
2820 tmp->next = loc->next;
2826 /* Now update the global location list to permanently delete the
2827 removed locations above. */
2828 update_global_location_list (UGLL_DONT_INSERT);
2831 /* Make sure all breakpoints are inserted in inferior.
2832 Throws exception on any error.
2833 A breakpoint that is already inserted won't be inserted
2834 again, so calling this function twice is safe. */
2836 insert_breakpoints (void)
2838 struct breakpoint *bpt;
2840 ALL_BREAKPOINTS (bpt)
2841 if (is_hardware_watchpoint (bpt))
2843 struct watchpoint *w = (struct watchpoint *) bpt;
2845 update_watchpoint (w, 0 /* don't reparse. */);
2848 /* Updating watchpoints creates new locations, so update the global
2849 location list. Explicitly tell ugll to insert locations and
2850 ignore breakpoints_always_inserted_mode. */
2851 update_global_location_list (UGLL_INSERT);
2854 /* Invoke CALLBACK for each of bp_location. */
2857 iterate_over_bp_locations (walk_bp_location_callback callback)
2859 struct bp_location *loc, **loc_tmp;
2861 ALL_BP_LOCATIONS (loc, loc_tmp)
2863 callback (loc, NULL);
2867 /* This is used when we need to synch breakpoint conditions between GDB and the
2868 target. It is the case with deleting and disabling of breakpoints when using
2869 always-inserted mode. */
2872 update_inserted_breakpoint_locations (void)
2874 struct bp_location *bl, **blp_tmp;
2877 int disabled_breaks = 0;
2878 int hw_breakpoint_error = 0;
2879 int hw_bp_details_reported = 0;
2881 string_file tmp_error_stream;
2883 /* Explicitly mark the warning -- this will only be printed if
2884 there was an error. */
2885 tmp_error_stream.puts ("Warning:\n");
2887 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2889 ALL_BP_LOCATIONS (bl, blp_tmp)
2891 /* We only want to update software breakpoints and hardware
2893 if (!is_breakpoint (bl->owner))
2896 /* We only want to update locations that are already inserted
2897 and need updating. This is to avoid unwanted insertion during
2898 deletion of breakpoints. */
2899 if (!bl->inserted || !bl->needs_update)
2902 switch_to_program_space_and_thread (bl->pspace);
2904 /* For targets that support global breakpoints, there's no need
2905 to select an inferior to insert breakpoint to. In fact, even
2906 if we aren't attached to any process yet, we should still
2907 insert breakpoints. */
2908 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2909 && inferior_ptid == null_ptid)
2912 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
2913 &hw_breakpoint_error, &hw_bp_details_reported);
2920 target_terminal::ours_for_output ();
2921 error_stream (tmp_error_stream);
2925 /* Used when starting or continuing the program. */
2928 insert_breakpoint_locations (void)
2930 struct breakpoint *bpt;
2931 struct bp_location *bl, **blp_tmp;
2934 int disabled_breaks = 0;
2935 int hw_breakpoint_error = 0;
2936 int hw_bp_error_explained_already = 0;
2938 string_file tmp_error_stream;
2940 /* Explicitly mark the warning -- this will only be printed if
2941 there was an error. */
2942 tmp_error_stream.puts ("Warning:\n");
2944 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2946 ALL_BP_LOCATIONS (bl, blp_tmp)
2948 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2951 /* There is no point inserting thread-specific breakpoints if
2952 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2953 has BL->OWNER always non-NULL. */
2954 if (bl->owner->thread != -1
2955 && !valid_global_thread_id (bl->owner->thread))
2958 switch_to_program_space_and_thread (bl->pspace);
2960 /* For targets that support global breakpoints, there's no need
2961 to select an inferior to insert breakpoint to. In fact, even
2962 if we aren't attached to any process yet, we should still
2963 insert breakpoints. */
2964 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2965 && inferior_ptid == null_ptid)
2968 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
2969 &hw_breakpoint_error, &hw_bp_error_explained_already);
2974 /* If we failed to insert all locations of a watchpoint, remove
2975 them, as half-inserted watchpoint is of limited use. */
2976 ALL_BREAKPOINTS (bpt)
2978 int some_failed = 0;
2979 struct bp_location *loc;
2981 if (!is_hardware_watchpoint (bpt))
2984 if (!breakpoint_enabled (bpt))
2987 if (bpt->disposition == disp_del_at_next_stop)
2990 for (loc = bpt->loc; loc; loc = loc->next)
2991 if (!loc->inserted && should_be_inserted (loc))
2998 for (loc = bpt->loc; loc; loc = loc->next)
3000 remove_breakpoint (loc);
3002 hw_breakpoint_error = 1;
3003 tmp_error_stream.printf ("Could not insert "
3004 "hardware watchpoint %d.\n",
3012 /* If a hardware breakpoint or watchpoint was inserted, add a
3013 message about possibly exhausted resources. */
3014 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3016 tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
3017 You may have requested too many hardware breakpoints/watchpoints.\n");
3019 target_terminal::ours_for_output ();
3020 error_stream (tmp_error_stream);
3024 /* Used when the program stops.
3025 Returns zero if successful, or non-zero if there was a problem
3026 removing a breakpoint location. */
3029 remove_breakpoints (void)
3031 struct bp_location *bl, **blp_tmp;
3034 ALL_BP_LOCATIONS (bl, blp_tmp)
3036 if (bl->inserted && !is_tracepoint (bl->owner))
3037 val |= remove_breakpoint (bl);
3042 /* When a thread exits, remove breakpoints that are related to
3046 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3048 struct breakpoint *b, *b_tmp;
3050 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3052 if (b->thread == tp->global_num && user_breakpoint_p (b))
3054 b->disposition = disp_del_at_next_stop;
3056 printf_filtered (_("\
3057 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3058 b->number, print_thread_id (tp));
3060 /* Hide it from the user. */
3066 /* Remove breakpoints of inferior INF. */
3069 remove_breakpoints_inf (inferior *inf)
3071 struct bp_location *bl, **blp_tmp;
3074 ALL_BP_LOCATIONS (bl, blp_tmp)
3076 if (bl->pspace != inf->pspace)
3079 if (bl->inserted && !bl->target_info.persist)
3081 val = remove_breakpoint (bl);
3089 static int internal_breakpoint_number = -1;
3091 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3092 If INTERNAL is non-zero, the breakpoint number will be populated
3093 from internal_breakpoint_number and that variable decremented.
3094 Otherwise the breakpoint number will be populated from
3095 breakpoint_count and that value incremented. Internal breakpoints
3096 do not set the internal var bpnum. */
3098 set_breakpoint_number (int internal, struct breakpoint *b)
3101 b->number = internal_breakpoint_number--;
3104 set_breakpoint_count (breakpoint_count + 1);
3105 b->number = breakpoint_count;
3109 static struct breakpoint *
3110 create_internal_breakpoint (struct gdbarch *gdbarch,
3111 CORE_ADDR address, enum bptype type,
3112 const struct breakpoint_ops *ops)
3114 symtab_and_line sal;
3116 sal.section = find_pc_overlay (sal.pc);
3117 sal.pspace = current_program_space;
3119 breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops);
3120 b->number = internal_breakpoint_number--;
3121 b->disposition = disp_donttouch;
3126 static const char *const longjmp_names[] =
3128 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3130 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3132 /* Per-objfile data private to breakpoint.c. */
3133 struct breakpoint_objfile_data
3135 /* Minimal symbol for "_ovly_debug_event" (if any). */
3136 struct bound_minimal_symbol overlay_msym {};
3138 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3139 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {};
3141 /* True if we have looked for longjmp probes. */
3142 int longjmp_searched = 0;
3144 /* SystemTap probe points for longjmp (if any). These are non-owning
3146 std::vector<probe *> longjmp_probes;
3148 /* Minimal symbol for "std::terminate()" (if any). */
3149 struct bound_minimal_symbol terminate_msym {};
3151 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3152 struct bound_minimal_symbol exception_msym {};
3154 /* True if we have looked for exception probes. */
3155 int exception_searched = 0;
3157 /* SystemTap probe points for unwinding (if any). These are non-owning
3159 std::vector<probe *> exception_probes;
3162 static const struct objfile_data *breakpoint_objfile_key;
3164 /* Minimal symbol not found sentinel. */
3165 static struct minimal_symbol msym_not_found;
3167 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3170 msym_not_found_p (const struct minimal_symbol *msym)
3172 return msym == &msym_not_found;
3175 /* Return per-objfile data needed by breakpoint.c.
3176 Allocate the data if necessary. */
3178 static struct breakpoint_objfile_data *
3179 get_breakpoint_objfile_data (struct objfile *objfile)
3181 struct breakpoint_objfile_data *bp_objfile_data;
3183 bp_objfile_data = ((struct breakpoint_objfile_data *)
3184 objfile_data (objfile, breakpoint_objfile_key));
3185 if (bp_objfile_data == NULL)
3187 bp_objfile_data = new breakpoint_objfile_data ();
3188 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3190 return bp_objfile_data;
3194 free_breakpoint_objfile_data (struct objfile *obj, void *data)
3196 struct breakpoint_objfile_data *bp_objfile_data
3197 = (struct breakpoint_objfile_data *) data;
3199 delete bp_objfile_data;
3203 create_overlay_event_breakpoint (void)
3205 struct objfile *objfile;
3206 const char *const func_name = "_ovly_debug_event";
3208 ALL_OBJFILES (objfile)
3210 struct breakpoint *b;
3211 struct breakpoint_objfile_data *bp_objfile_data;
3213 struct explicit_location explicit_loc;
3215 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3217 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3220 if (bp_objfile_data->overlay_msym.minsym == NULL)
3222 struct bound_minimal_symbol m;
3224 m = lookup_minimal_symbol_text (func_name, objfile);
3225 if (m.minsym == NULL)
3227 /* Avoid future lookups in this objfile. */
3228 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3231 bp_objfile_data->overlay_msym = m;
3234 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3235 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3237 &internal_breakpoint_ops);
3238 initialize_explicit_location (&explicit_loc);
3239 explicit_loc.function_name = ASTRDUP (func_name);
3240 b->location = new_explicit_location (&explicit_loc);
3242 if (overlay_debugging == ovly_auto)
3244 b->enable_state = bp_enabled;
3245 overlay_events_enabled = 1;
3249 b->enable_state = bp_disabled;
3250 overlay_events_enabled = 0;
3256 create_longjmp_master_breakpoint (void)
3258 struct program_space *pspace;
3260 scoped_restore_current_program_space restore_pspace;
3262 ALL_PSPACES (pspace)
3264 struct objfile *objfile;
3266 set_current_program_space (pspace);
3268 ALL_OBJFILES (objfile)
3271 struct gdbarch *gdbarch;
3272 struct breakpoint_objfile_data *bp_objfile_data;
3274 gdbarch = get_objfile_arch (objfile);
3276 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3278 if (!bp_objfile_data->longjmp_searched)
3280 std::vector<probe *> ret
3281 = find_probes_in_objfile (objfile, "libc", "longjmp");
3285 /* We are only interested in checking one element. */
3288 if (!p->can_evaluate_arguments ())
3290 /* We cannot use the probe interface here, because it does
3291 not know how to evaluate arguments. */
3295 bp_objfile_data->longjmp_probes = ret;
3296 bp_objfile_data->longjmp_searched = 1;
3299 if (!bp_objfile_data->longjmp_probes.empty ())
3301 for (probe *p : bp_objfile_data->longjmp_probes)
3303 struct breakpoint *b;
3305 b = create_internal_breakpoint (gdbarch,
3306 p->get_relocated_address (objfile),
3308 &internal_breakpoint_ops);
3309 b->location = new_probe_location ("-probe-stap libc:longjmp");
3310 b->enable_state = bp_disabled;
3316 if (!gdbarch_get_longjmp_target_p (gdbarch))
3319 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3321 struct breakpoint *b;
3322 const char *func_name;
3324 struct explicit_location explicit_loc;
3326 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3329 func_name = longjmp_names[i];
3330 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3332 struct bound_minimal_symbol m;
3334 m = lookup_minimal_symbol_text (func_name, objfile);
3335 if (m.minsym == NULL)
3337 /* Prevent future lookups in this objfile. */
3338 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3341 bp_objfile_data->longjmp_msym[i] = m;
3344 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3345 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3346 &internal_breakpoint_ops);
3347 initialize_explicit_location (&explicit_loc);
3348 explicit_loc.function_name = ASTRDUP (func_name);
3349 b->location = new_explicit_location (&explicit_loc);
3350 b->enable_state = bp_disabled;
3356 /* Create a master std::terminate breakpoint. */
3358 create_std_terminate_master_breakpoint (void)
3360 struct program_space *pspace;
3361 const char *const func_name = "std::terminate()";
3363 scoped_restore_current_program_space restore_pspace;
3365 ALL_PSPACES (pspace)
3367 struct objfile *objfile;
3370 set_current_program_space (pspace);
3372 ALL_OBJFILES (objfile)
3374 struct breakpoint *b;
3375 struct breakpoint_objfile_data *bp_objfile_data;
3376 struct explicit_location explicit_loc;
3378 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3380 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3383 if (bp_objfile_data->terminate_msym.minsym == NULL)
3385 struct bound_minimal_symbol m;
3387 m = lookup_minimal_symbol (func_name, NULL, objfile);
3388 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3389 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3391 /* Prevent future lookups in this objfile. */
3392 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3395 bp_objfile_data->terminate_msym = m;
3398 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3399 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3400 bp_std_terminate_master,
3401 &internal_breakpoint_ops);
3402 initialize_explicit_location (&explicit_loc);
3403 explicit_loc.function_name = ASTRDUP (func_name);
3404 b->location = new_explicit_location (&explicit_loc);
3405 b->enable_state = bp_disabled;
3410 /* Install a master breakpoint on the unwinder's debug hook. */
3413 create_exception_master_breakpoint (void)
3415 struct objfile *objfile;
3416 const char *const func_name = "_Unwind_DebugHook";
3418 ALL_OBJFILES (objfile)
3420 struct breakpoint *b;
3421 struct gdbarch *gdbarch;
3422 struct breakpoint_objfile_data *bp_objfile_data;
3424 struct explicit_location explicit_loc;
3426 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3428 /* We prefer the SystemTap probe point if it exists. */
3429 if (!bp_objfile_data->exception_searched)
3431 std::vector<probe *> ret
3432 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3436 /* We are only interested in checking one element. */
3439 if (!p->can_evaluate_arguments ())
3441 /* We cannot use the probe interface here, because it does
3442 not know how to evaluate arguments. */
3446 bp_objfile_data->exception_probes = ret;
3447 bp_objfile_data->exception_searched = 1;
3450 if (!bp_objfile_data->exception_probes.empty ())
3452 gdbarch = get_objfile_arch (objfile);
3454 for (probe *p : bp_objfile_data->exception_probes)
3456 b = create_internal_breakpoint (gdbarch,
3457 p->get_relocated_address (objfile),
3458 bp_exception_master,
3459 &internal_breakpoint_ops);
3460 b->location = new_probe_location ("-probe-stap libgcc:unwind");
3461 b->enable_state = bp_disabled;
3467 /* Otherwise, try the hook function. */
3469 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3472 gdbarch = get_objfile_arch (objfile);
3474 if (bp_objfile_data->exception_msym.minsym == NULL)
3476 struct bound_minimal_symbol debug_hook;
3478 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3479 if (debug_hook.minsym == NULL)
3481 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3485 bp_objfile_data->exception_msym = debug_hook;
3488 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3489 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3490 current_top_target ());
3491 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3492 &internal_breakpoint_ops);
3493 initialize_explicit_location (&explicit_loc);
3494 explicit_loc.function_name = ASTRDUP (func_name);
3495 b->location = new_explicit_location (&explicit_loc);
3496 b->enable_state = bp_disabled;
3500 /* Does B have a location spec? */
3503 breakpoint_event_location_empty_p (const struct breakpoint *b)
3505 return b->location != NULL && event_location_empty_p (b->location.get ());
3509 update_breakpoints_after_exec (void)
3511 struct breakpoint *b, *b_tmp;
3512 struct bp_location *bploc, **bplocp_tmp;
3514 /* We're about to delete breakpoints from GDB's lists. If the
3515 INSERTED flag is true, GDB will try to lift the breakpoints by
3516 writing the breakpoints' "shadow contents" back into memory. The
3517 "shadow contents" are NOT valid after an exec, so GDB should not
3518 do that. Instead, the target is responsible from marking
3519 breakpoints out as soon as it detects an exec. We don't do that
3520 here instead, because there may be other attempts to delete
3521 breakpoints after detecting an exec and before reaching here. */
3522 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3523 if (bploc->pspace == current_program_space)
3524 gdb_assert (!bploc->inserted);
3526 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3528 if (b->pspace != current_program_space)
3531 /* Solib breakpoints must be explicitly reset after an exec(). */
3532 if (b->type == bp_shlib_event)
3534 delete_breakpoint (b);
3538 /* JIT breakpoints must be explicitly reset after an exec(). */
3539 if (b->type == bp_jit_event)
3541 delete_breakpoint (b);
3545 /* Thread event breakpoints must be set anew after an exec(),
3546 as must overlay event and longjmp master breakpoints. */
3547 if (b->type == bp_thread_event || b->type == bp_overlay_event
3548 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3549 || b->type == bp_exception_master)
3551 delete_breakpoint (b);
3555 /* Step-resume breakpoints are meaningless after an exec(). */
3556 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3558 delete_breakpoint (b);
3562 /* Just like single-step breakpoints. */
3563 if (b->type == bp_single_step)
3565 delete_breakpoint (b);
3569 /* Longjmp and longjmp-resume breakpoints are also meaningless
3571 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3572 || b->type == bp_longjmp_call_dummy
3573 || b->type == bp_exception || b->type == bp_exception_resume)
3575 delete_breakpoint (b);
3579 if (b->type == bp_catchpoint)
3581 /* For now, none of the bp_catchpoint breakpoints need to
3582 do anything at this point. In the future, if some of
3583 the catchpoints need to something, we will need to add
3584 a new method, and call this method from here. */
3588 /* bp_finish is a special case. The only way we ought to be able
3589 to see one of these when an exec() has happened, is if the user
3590 caught a vfork, and then said "finish". Ordinarily a finish just
3591 carries them to the call-site of the current callee, by setting
3592 a temporary bp there and resuming. But in this case, the finish
3593 will carry them entirely through the vfork & exec.
3595 We don't want to allow a bp_finish to remain inserted now. But
3596 we can't safely delete it, 'cause finish_command has a handle to
3597 the bp on a bpstat, and will later want to delete it. There's a
3598 chance (and I've seen it happen) that if we delete the bp_finish
3599 here, that its storage will get reused by the time finish_command
3600 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3601 We really must allow finish_command to delete a bp_finish.
3603 In the absence of a general solution for the "how do we know
3604 it's safe to delete something others may have handles to?"
3605 problem, what we'll do here is just uninsert the bp_finish, and
3606 let finish_command delete it.
3608 (We know the bp_finish is "doomed" in the sense that it's
3609 momentary, and will be deleted as soon as finish_command sees
3610 the inferior stopped. So it doesn't matter that the bp's
3611 address is probably bogus in the new a.out, unlike e.g., the
3612 solib breakpoints.) */
3614 if (b->type == bp_finish)
3619 /* Without a symbolic address, we have little hope of the
3620 pre-exec() address meaning the same thing in the post-exec()
3622 if (breakpoint_event_location_empty_p (b))
3624 delete_breakpoint (b);
3631 detach_breakpoints (ptid_t ptid)
3633 struct bp_location *bl, **blp_tmp;
3635 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
3636 struct inferior *inf = current_inferior ();
3638 if (ptid.pid () == inferior_ptid.pid ())
3639 error (_("Cannot detach breakpoints of inferior_ptid"));
3641 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3642 inferior_ptid = ptid;
3643 ALL_BP_LOCATIONS (bl, blp_tmp)
3645 if (bl->pspace != inf->pspace)
3648 /* This function must physically remove breakpoints locations
3649 from the specified ptid, without modifying the breakpoint
3650 package's state. Locations of type bp_loc_other are only
3651 maintained at GDB side. So, there is no need to remove
3652 these bp_loc_other locations. Moreover, removing these
3653 would modify the breakpoint package's state. */
3654 if (bl->loc_type == bp_loc_other)
3658 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3664 /* Remove the breakpoint location BL from the current address space.
3665 Note that this is used to detach breakpoints from a child fork.
3666 When we get here, the child isn't in the inferior list, and neither
3667 do we have objects to represent its address space --- we should
3668 *not* look at bl->pspace->aspace here. */
3671 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3675 /* BL is never in moribund_locations by our callers. */
3676 gdb_assert (bl->owner != NULL);
3678 /* The type of none suggests that owner is actually deleted.
3679 This should not ever happen. */
3680 gdb_assert (bl->owner->type != bp_none);
3682 if (bl->loc_type == bp_loc_software_breakpoint
3683 || bl->loc_type == bp_loc_hardware_breakpoint)
3685 /* "Normal" instruction breakpoint: either the standard
3686 trap-instruction bp (bp_breakpoint), or a
3687 bp_hardware_breakpoint. */
3689 /* First check to see if we have to handle an overlay. */
3690 if (overlay_debugging == ovly_off
3691 || bl->section == NULL
3692 || !(section_is_overlay (bl->section)))
3694 /* No overlay handling: just remove the breakpoint. */
3696 /* If we're trying to uninsert a memory breakpoint that we
3697 know is set in a dynamic object that is marked
3698 shlib_disabled, then either the dynamic object was
3699 removed with "remove-symbol-file" or with
3700 "nosharedlibrary". In the former case, we don't know
3701 whether another dynamic object might have loaded over the
3702 breakpoint's address -- the user might well let us know
3703 about it next with add-symbol-file (the whole point of
3704 add-symbol-file is letting the user manually maintain a
3705 list of dynamically loaded objects). If we have the
3706 breakpoint's shadow memory, that is, this is a software
3707 breakpoint managed by GDB, check whether the breakpoint
3708 is still inserted in memory, to avoid overwriting wrong
3709 code with stale saved shadow contents. Note that HW
3710 breakpoints don't have shadow memory, as they're
3711 implemented using a mechanism that is not dependent on
3712 being able to modify the target's memory, and as such
3713 they should always be removed. */
3714 if (bl->shlib_disabled
3715 && bl->target_info.shadow_len != 0
3716 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3719 val = bl->owner->ops->remove_location (bl, reason);
3723 /* This breakpoint is in an overlay section.
3724 Did we set a breakpoint at the LMA? */
3725 if (!overlay_events_enabled)
3727 /* Yes -- overlay event support is not active, so we
3728 should have set a breakpoint at the LMA. Remove it.
3730 /* Ignore any failures: if the LMA is in ROM, we will
3731 have already warned when we failed to insert it. */
3732 if (bl->loc_type == bp_loc_hardware_breakpoint)
3733 target_remove_hw_breakpoint (bl->gdbarch,
3734 &bl->overlay_target_info);
3736 target_remove_breakpoint (bl->gdbarch,
3737 &bl->overlay_target_info,
3740 /* Did we set a breakpoint at the VMA?
3741 If so, we will have marked the breakpoint 'inserted'. */
3744 /* Yes -- remove it. Previously we did not bother to
3745 remove the breakpoint if the section had been
3746 unmapped, but let's not rely on that being safe. We
3747 don't know what the overlay manager might do. */
3749 /* However, we should remove *software* breakpoints only
3750 if the section is still mapped, or else we overwrite
3751 wrong code with the saved shadow contents. */
3752 if (bl->loc_type == bp_loc_hardware_breakpoint
3753 || section_is_mapped (bl->section))
3754 val = bl->owner->ops->remove_location (bl, reason);
3760 /* No -- not inserted, so no need to remove. No error. */
3765 /* In some cases, we might not be able to remove a breakpoint in
3766 a shared library that has already been removed, but we have
3767 not yet processed the shlib unload event. Similarly for an
3768 unloaded add-symbol-file object - the user might not yet have
3769 had the chance to remove-symbol-file it. shlib_disabled will
3770 be set if the library/object has already been removed, but
3771 the breakpoint hasn't been uninserted yet, e.g., after
3772 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3773 always-inserted mode. */
3775 && (bl->loc_type == bp_loc_software_breakpoint
3776 && (bl->shlib_disabled
3777 || solib_name_from_address (bl->pspace, bl->address)
3778 || shared_objfile_contains_address_p (bl->pspace,
3784 bl->inserted = (reason == DETACH_BREAKPOINT);
3786 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3788 gdb_assert (bl->owner->ops != NULL
3789 && bl->owner->ops->remove_location != NULL);
3791 bl->inserted = (reason == DETACH_BREAKPOINT);
3792 bl->owner->ops->remove_location (bl, reason);
3794 /* Failure to remove any of the hardware watchpoints comes here. */
3795 if (reason == REMOVE_BREAKPOINT && bl->inserted)
3796 warning (_("Could not remove hardware watchpoint %d."),
3799 else if (bl->owner->type == bp_catchpoint
3800 && breakpoint_enabled (bl->owner)
3803 gdb_assert (bl->owner->ops != NULL
3804 && bl->owner->ops->remove_location != NULL);
3806 val = bl->owner->ops->remove_location (bl, reason);
3810 bl->inserted = (reason == DETACH_BREAKPOINT);
3817 remove_breakpoint (struct bp_location *bl)
3819 /* BL is never in moribund_locations by our callers. */
3820 gdb_assert (bl->owner != NULL);
3822 /* The type of none suggests that owner is actually deleted.
3823 This should not ever happen. */
3824 gdb_assert (bl->owner->type != bp_none);
3826 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3828 switch_to_program_space_and_thread (bl->pspace);
3830 return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
3833 /* Clear the "inserted" flag in all breakpoints. */
3836 mark_breakpoints_out (void)
3838 struct bp_location *bl, **blp_tmp;
3840 ALL_BP_LOCATIONS (bl, blp_tmp)
3841 if (bl->pspace == current_program_space)
3845 /* Clear the "inserted" flag in all breakpoints and delete any
3846 breakpoints which should go away between runs of the program.
3848 Plus other such housekeeping that has to be done for breakpoints
3851 Note: this function gets called at the end of a run (by
3852 generic_mourn_inferior) and when a run begins (by
3853 init_wait_for_inferior). */
3858 breakpoint_init_inferior (enum inf_context context)
3860 struct breakpoint *b, *b_tmp;
3861 struct program_space *pspace = current_program_space;
3863 /* If breakpoint locations are shared across processes, then there's
3865 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3868 mark_breakpoints_out ();
3870 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3872 if (b->loc && b->loc->pspace != pspace)
3878 case bp_longjmp_call_dummy:
3880 /* If the call dummy breakpoint is at the entry point it will
3881 cause problems when the inferior is rerun, so we better get
3884 case bp_watchpoint_scope:
3886 /* Also get rid of scope breakpoints. */
3888 case bp_shlib_event:
3890 /* Also remove solib event breakpoints. Their addresses may
3891 have changed since the last time we ran the program.
3892 Actually we may now be debugging against different target;
3893 and so the solib backend that installed this breakpoint may
3894 not be used in by the target. E.g.,
3896 (gdb) file prog-linux
3897 (gdb) run # native linux target
3900 (gdb) file prog-win.exe
3901 (gdb) tar rem :9999 # remote Windows gdbserver.
3904 case bp_step_resume:
3906 /* Also remove step-resume breakpoints. */
3908 case bp_single_step:
3910 /* Also remove single-step breakpoints. */
3912 delete_breakpoint (b);
3916 case bp_hardware_watchpoint:
3917 case bp_read_watchpoint:
3918 case bp_access_watchpoint:
3920 struct watchpoint *w = (struct watchpoint *) b;
3922 /* Likewise for watchpoints on local expressions. */
3923 if (w->exp_valid_block != NULL)
3924 delete_breakpoint (b);
3927 /* Get rid of existing locations, which are no longer
3928 valid. New ones will be created in
3929 update_watchpoint, when the inferior is restarted.
3930 The next update_global_location_list call will
3931 garbage collect them. */
3934 if (context == inf_starting)
3936 /* Reset val field to force reread of starting value in
3937 insert_breakpoints. */
3938 w->val.reset (nullptr);
3949 /* Get rid of the moribund locations. */
3950 for (bp_location *bl : moribund_locations)
3951 decref_bp_location (&bl);
3952 moribund_locations.clear ();
3955 /* These functions concern about actual breakpoints inserted in the
3956 target --- to e.g. check if we need to do decr_pc adjustment or if
3957 we need to hop over the bkpt --- so we check for address space
3958 match, not program space. */
3960 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3961 exists at PC. It returns ordinary_breakpoint_here if it's an
3962 ordinary breakpoint, or permanent_breakpoint_here if it's a
3963 permanent breakpoint.
3964 - When continuing from a location with an ordinary breakpoint, we
3965 actually single step once before calling insert_breakpoints.
3966 - When continuing from a location with a permanent breakpoint, we
3967 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3968 the target, to advance the PC past the breakpoint. */
3970 enum breakpoint_here
3971 breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
3973 struct bp_location *bl, **blp_tmp;
3974 int any_breakpoint_here = 0;
3976 ALL_BP_LOCATIONS (bl, blp_tmp)
3978 if (bl->loc_type != bp_loc_software_breakpoint
3979 && bl->loc_type != bp_loc_hardware_breakpoint)
3982 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3983 if ((breakpoint_enabled (bl->owner)
3985 && breakpoint_location_address_match (bl, aspace, pc))
3987 if (overlay_debugging
3988 && section_is_overlay (bl->section)
3989 && !section_is_mapped (bl->section))
3990 continue; /* unmapped overlay -- can't be a match */
3991 else if (bl->permanent)
3992 return permanent_breakpoint_here;
3994 any_breakpoint_here = 1;
3998 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4001 /* See breakpoint.h. */
4004 breakpoint_in_range_p (const address_space *aspace,
4005 CORE_ADDR addr, ULONGEST len)
4007 struct bp_location *bl, **blp_tmp;
4009 ALL_BP_LOCATIONS (bl, blp_tmp)
4011 if (bl->loc_type != bp_loc_software_breakpoint
4012 && bl->loc_type != bp_loc_hardware_breakpoint)
4015 if ((breakpoint_enabled (bl->owner)
4017 && breakpoint_location_address_range_overlap (bl, aspace,
4020 if (overlay_debugging
4021 && section_is_overlay (bl->section)
4022 && !section_is_mapped (bl->section))
4024 /* Unmapped overlay -- can't be a match. */
4035 /* Return true if there's a moribund breakpoint at PC. */
4038 moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
4040 for (bp_location *loc : moribund_locations)
4041 if (breakpoint_location_address_match (loc, aspace, pc))
4047 /* Returns non-zero iff BL is inserted at PC, in address space
4051 bp_location_inserted_here_p (struct bp_location *bl,
4052 const address_space *aspace, CORE_ADDR pc)
4055 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4058 if (overlay_debugging
4059 && section_is_overlay (bl->section)
4060 && !section_is_mapped (bl->section))
4061 return 0; /* unmapped overlay -- can't be a match */
4068 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4071 breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
4073 struct bp_location **blp, **blp_tmp = NULL;
4075 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4077 struct bp_location *bl = *blp;
4079 if (bl->loc_type != bp_loc_software_breakpoint
4080 && bl->loc_type != bp_loc_hardware_breakpoint)
4083 if (bp_location_inserted_here_p (bl, aspace, pc))
4089 /* This function returns non-zero iff there is a software breakpoint
4093 software_breakpoint_inserted_here_p (const address_space *aspace,
4096 struct bp_location **blp, **blp_tmp = NULL;
4098 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4100 struct bp_location *bl = *blp;
4102 if (bl->loc_type != bp_loc_software_breakpoint)
4105 if (bp_location_inserted_here_p (bl, aspace, pc))
4112 /* See breakpoint.h. */
4115 hardware_breakpoint_inserted_here_p (const address_space *aspace,
4118 struct bp_location **blp, **blp_tmp = NULL;
4120 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4122 struct bp_location *bl = *blp;
4124 if (bl->loc_type != bp_loc_hardware_breakpoint)
4127 if (bp_location_inserted_here_p (bl, aspace, pc))
4135 hardware_watchpoint_inserted_in_range (const address_space *aspace,
4136 CORE_ADDR addr, ULONGEST len)
4138 struct breakpoint *bpt;
4140 ALL_BREAKPOINTS (bpt)
4142 struct bp_location *loc;
4144 if (bpt->type != bp_hardware_watchpoint
4145 && bpt->type != bp_access_watchpoint)
4148 if (!breakpoint_enabled (bpt))
4151 for (loc = bpt->loc; loc; loc = loc->next)
4152 if (loc->pspace->aspace == aspace && loc->inserted)
4156 /* Check for intersection. */
4157 l = std::max<CORE_ADDR> (loc->address, addr);
4158 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4167 /* bpstat stuff. External routines' interfaces are documented
4171 is_catchpoint (struct breakpoint *ep)
4173 return (ep->type == bp_catchpoint);
4176 /* Frees any storage that is part of a bpstat. Does not walk the
4179 bpstats::~bpstats ()
4181 if (bp_location_at != NULL)
4182 decref_bp_location (&bp_location_at);
4185 /* Clear a bpstat so that it says we are not at any breakpoint.
4186 Also free any storage that is part of a bpstat. */
4189 bpstat_clear (bpstat *bsp)
4206 bpstats::bpstats (const bpstats &other)
4208 bp_location_at (other.bp_location_at),
4209 breakpoint_at (other.breakpoint_at),
4210 commands (other.commands),
4211 print (other.print),
4213 print_it (other.print_it)
4215 if (other.old_val != NULL)
4216 old_val = release_value (value_copy (other.old_val.get ()));
4217 incref_bp_location (bp_location_at);
4220 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4221 is part of the bpstat is copied as well. */
4224 bpstat_copy (bpstat bs)
4228 bpstat retval = NULL;
4233 for (; bs != NULL; bs = bs->next)
4235 tmp = new bpstats (*bs);
4238 /* This is the first thing in the chain. */
4248 /* Find the bpstat associated with this breakpoint. */
4251 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4256 for (; bsp != NULL; bsp = bsp->next)
4258 if (bsp->breakpoint_at == breakpoint)
4264 /* See breakpoint.h. */
4267 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4269 for (; bsp != NULL; bsp = bsp->next)
4271 if (bsp->breakpoint_at == NULL)
4273 /* A moribund location can never explain a signal other than
4275 if (sig == GDB_SIGNAL_TRAP)
4280 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4289 /* Put in *NUM the breakpoint number of the first breakpoint we are
4290 stopped at. *BSP upon return is a bpstat which points to the
4291 remaining breakpoints stopped at (but which is not guaranteed to be
4292 good for anything but further calls to bpstat_num).
4294 Return 0 if passed a bpstat which does not indicate any breakpoints.
4295 Return -1 if stopped at a breakpoint that has been deleted since
4297 Return 1 otherwise. */
4300 bpstat_num (bpstat *bsp, int *num)
4302 struct breakpoint *b;
4305 return 0; /* No more breakpoint values */
4307 /* We assume we'll never have several bpstats that correspond to a
4308 single breakpoint -- otherwise, this function might return the
4309 same number more than once and this will look ugly. */
4310 b = (*bsp)->breakpoint_at;
4311 *bsp = (*bsp)->next;
4313 return -1; /* breakpoint that's been deleted since */
4315 *num = b->number; /* We have its number */
4319 /* See breakpoint.h. */
4322 bpstat_clear_actions (void)
4326 if (inferior_ptid == null_ptid)
4329 thread_info *tp = inferior_thread ();
4330 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4332 bs->commands = NULL;
4333 bs->old_val.reset (nullptr);
4337 /* Called when a command is about to proceed the inferior. */
4340 breakpoint_about_to_proceed (void)
4342 if (inferior_ptid != null_ptid)
4344 struct thread_info *tp = inferior_thread ();
4346 /* Allow inferior function calls in breakpoint commands to not
4347 interrupt the command list. When the call finishes
4348 successfully, the inferior will be standing at the same
4349 breakpoint as if nothing happened. */
4350 if (tp->control.in_infcall)
4354 breakpoint_proceeded = 1;
4357 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4358 or its equivalent. */
4361 command_line_is_silent (struct command_line *cmd)
4363 return cmd && (strcmp ("silent", cmd->line) == 0);
4366 /* Execute all the commands associated with all the breakpoints at
4367 this location. Any of these commands could cause the process to
4368 proceed beyond this point, etc. We look out for such changes by
4369 checking the global "breakpoint_proceeded" after each command.
4371 Returns true if a breakpoint command resumed the inferior. In that
4372 case, it is the caller's responsibility to recall it again with the
4373 bpstat of the current thread. */
4376 bpstat_do_actions_1 (bpstat *bsp)
4381 /* Avoid endless recursion if a `source' command is contained
4383 if (executing_breakpoint_commands)
4386 scoped_restore save_executing
4387 = make_scoped_restore (&executing_breakpoint_commands, 1);
4389 scoped_restore preventer = prevent_dont_repeat ();
4391 /* This pointer will iterate over the list of bpstat's. */
4394 breakpoint_proceeded = 0;
4395 for (; bs != NULL; bs = bs->next)
4397 struct command_line *cmd = NULL;
4399 /* Take ownership of the BSP's command tree, if it has one.
4401 The command tree could legitimately contain commands like
4402 'step' and 'next', which call clear_proceed_status, which
4403 frees stop_bpstat's command tree. To make sure this doesn't
4404 free the tree we're executing out from under us, we need to
4405 take ownership of the tree ourselves. Since a given bpstat's
4406 commands are only executed once, we don't need to copy it; we
4407 can clear the pointer in the bpstat, and make sure we free
4408 the tree when we're done. */
4409 counted_command_line ccmd = bs->commands;
4410 bs->commands = NULL;
4413 if (command_line_is_silent (cmd))
4415 /* The action has been already done by bpstat_stop_status. */
4421 execute_control_command (cmd);
4423 if (breakpoint_proceeded)
4429 if (breakpoint_proceeded)
4431 if (current_ui->async)
4432 /* If we are in async mode, then the target might be still
4433 running, not stopped at any breakpoint, so nothing for
4434 us to do here -- just return to the event loop. */
4437 /* In sync mode, when execute_control_command returns
4438 we're already standing on the next breakpoint.
4439 Breakpoint commands for that stop were not run, since
4440 execute_command does not run breakpoint commands --
4441 only command_line_handler does, but that one is not
4442 involved in execution of breakpoint commands. So, we
4443 can now execute breakpoint commands. It should be
4444 noted that making execute_command do bpstat actions is
4445 not an option -- in this case we'll have recursive
4446 invocation of bpstat for each breakpoint with a
4447 command, and can easily blow up GDB stack. Instead, we
4448 return true, which will trigger the caller to recall us
4449 with the new stop_bpstat. */
4457 /* Helper for bpstat_do_actions. Get the current thread, if there's
4458 one, is alive and has execution. Return NULL otherwise. */
4460 static thread_info *
4461 get_bpstat_thread ()
4463 if (inferior_ptid == null_ptid || !target_has_execution)
4466 thread_info *tp = inferior_thread ();
4467 if (tp->state == THREAD_EXITED || tp->executing)
4473 bpstat_do_actions (void)
4475 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4478 /* Do any commands attached to breakpoint we are stopped at. */
4479 while ((tp = get_bpstat_thread ()) != NULL)
4481 /* Since in sync mode, bpstat_do_actions may resume the
4482 inferior, and only return when it is stopped at the next
4483 breakpoint, we keep doing breakpoint actions until it returns
4484 false to indicate the inferior was not resumed. */
4485 if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
4489 discard_cleanups (cleanup_if_error);
4492 /* Print out the (old or new) value associated with a watchpoint. */
4495 watchpoint_value_print (struct value *val, struct ui_file *stream)
4498 fprintf_unfiltered (stream, _("<unreadable>"));
4501 struct value_print_options opts;
4502 get_user_print_options (&opts);
4503 value_print (val, stream, &opts);
4507 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4508 debugging multiple threads. */
4511 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4513 if (uiout->is_mi_like_p ())
4518 if (show_thread_that_caused_stop ())
4521 struct thread_info *thr = inferior_thread ();
4523 uiout->text ("Thread ");
4524 uiout->field_fmt ("thread-id", "%s", print_thread_id (thr));
4526 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4529 uiout->text (" \"");
4530 uiout->field_fmt ("name", "%s", name);
4534 uiout->text (" hit ");
4538 /* Generic routine for printing messages indicating why we
4539 stopped. The behavior of this function depends on the value
4540 'print_it' in the bpstat structure. Under some circumstances we
4541 may decide not to print anything here and delegate the task to
4544 static enum print_stop_action
4545 print_bp_stop_message (bpstat bs)
4547 switch (bs->print_it)
4550 /* Nothing should be printed for this bpstat entry. */
4551 return PRINT_UNKNOWN;
4555 /* We still want to print the frame, but we already printed the
4556 relevant messages. */
4557 return PRINT_SRC_AND_LOC;
4560 case print_it_normal:
4562 struct breakpoint *b = bs->breakpoint_at;
4564 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4565 which has since been deleted. */
4567 return PRINT_UNKNOWN;
4569 /* Normal case. Call the breakpoint's print_it method. */
4570 return b->ops->print_it (bs);
4575 internal_error (__FILE__, __LINE__,
4576 _("print_bp_stop_message: unrecognized enum value"));
4581 /* A helper function that prints a shared library stopped event. */
4584 print_solib_event (int is_catchpoint)
4586 bool any_deleted = !current_program_space->deleted_solibs.empty ();
4587 bool any_added = !current_program_space->added_solibs.empty ();
4591 if (any_added || any_deleted)
4592 current_uiout->text (_("Stopped due to shared library event:\n"));
4594 current_uiout->text (_("Stopped due to shared library event (no "
4595 "libraries added or removed)\n"));
4598 if (current_uiout->is_mi_like_p ())
4599 current_uiout->field_string ("reason",
4600 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4604 current_uiout->text (_(" Inferior unloaded "));
4605 ui_out_emit_list list_emitter (current_uiout, "removed");
4606 for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++)
4608 const std::string &name = current_program_space->deleted_solibs[ix];
4611 current_uiout->text (" ");
4612 current_uiout->field_string ("library", name);
4613 current_uiout->text ("\n");
4619 current_uiout->text (_(" Inferior loaded "));
4620 ui_out_emit_list list_emitter (current_uiout, "added");
4622 for (so_list *iter : current_program_space->added_solibs)
4625 current_uiout->text (" ");
4627 current_uiout->field_string ("library", iter->so_name);
4628 current_uiout->text ("\n");
4633 /* Print a message indicating what happened. This is called from
4634 normal_stop(). The input to this routine is the head of the bpstat
4635 list - a list of the eventpoints that caused this stop. KIND is
4636 the target_waitkind for the stopping event. This
4637 routine calls the generic print routine for printing a message
4638 about reasons for stopping. This will print (for example) the
4639 "Breakpoint n," part of the output. The return value of this
4642 PRINT_UNKNOWN: Means we printed nothing.
4643 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4644 code to print the location. An example is
4645 "Breakpoint 1, " which should be followed by
4647 PRINT_SRC_ONLY: Means we printed something, but there is no need
4648 to also print the location part of the message.
4649 An example is the catch/throw messages, which
4650 don't require a location appended to the end.
4651 PRINT_NOTHING: We have done some printing and we don't need any
4652 further info to be printed. */
4654 enum print_stop_action
4655 bpstat_print (bpstat bs, int kind)
4657 enum print_stop_action val;
4659 /* Maybe another breakpoint in the chain caused us to stop.
4660 (Currently all watchpoints go on the bpstat whether hit or not.
4661 That probably could (should) be changed, provided care is taken
4662 with respect to bpstat_explains_signal). */
4663 for (; bs; bs = bs->next)
4665 val = print_bp_stop_message (bs);
4666 if (val == PRINT_SRC_ONLY
4667 || val == PRINT_SRC_AND_LOC
4668 || val == PRINT_NOTHING)
4672 /* If we had hit a shared library event breakpoint,
4673 print_bp_stop_message would print out this message. If we hit an
4674 OS-level shared library event, do the same thing. */
4675 if (kind == TARGET_WAITKIND_LOADED)
4677 print_solib_event (0);
4678 return PRINT_NOTHING;
4681 /* We reached the end of the chain, or we got a null BS to start
4682 with and nothing was printed. */
4683 return PRINT_UNKNOWN;
4686 /* Evaluate the boolean expression EXP and return the result. */
4689 breakpoint_cond_eval (expression *exp)
4691 struct value *mark = value_mark ();
4692 bool res = value_true (evaluate_expression (exp));
4694 value_free_to_mark (mark);
4698 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4700 bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer)
4702 bp_location_at (bl),
4703 breakpoint_at (bl->owner),
4707 print_it (print_it_normal)
4709 incref_bp_location (bl);
4710 **bs_link_pointer = this;
4711 *bs_link_pointer = &next;
4716 bp_location_at (NULL),
4717 breakpoint_at (NULL),
4721 print_it (print_it_normal)
4725 /* The target has stopped with waitstatus WS. Check if any hardware
4726 watchpoints have triggered, according to the target. */
4729 watchpoints_triggered (struct target_waitstatus *ws)
4731 bool stopped_by_watchpoint = target_stopped_by_watchpoint ();
4733 struct breakpoint *b;
4735 if (!stopped_by_watchpoint)
4737 /* We were not stopped by a watchpoint. Mark all watchpoints
4738 as not triggered. */
4740 if (is_hardware_watchpoint (b))
4742 struct watchpoint *w = (struct watchpoint *) b;
4744 w->watchpoint_triggered = watch_triggered_no;
4750 if (!target_stopped_data_address (current_top_target (), &addr))
4752 /* We were stopped by a watchpoint, but we don't know where.
4753 Mark all watchpoints as unknown. */
4755 if (is_hardware_watchpoint (b))
4757 struct watchpoint *w = (struct watchpoint *) b;
4759 w->watchpoint_triggered = watch_triggered_unknown;
4765 /* The target could report the data address. Mark watchpoints
4766 affected by this data address as triggered, and all others as not
4770 if (is_hardware_watchpoint (b))
4772 struct watchpoint *w = (struct watchpoint *) b;
4773 struct bp_location *loc;
4775 w->watchpoint_triggered = watch_triggered_no;
4776 for (loc = b->loc; loc; loc = loc->next)
4778 if (is_masked_watchpoint (b))
4780 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4781 CORE_ADDR start = loc->address & w->hw_wp_mask;
4783 if (newaddr == start)
4785 w->watchpoint_triggered = watch_triggered_yes;
4789 /* Exact match not required. Within range is sufficient. */
4790 else if (target_watchpoint_addr_within_range (current_top_target (),
4794 w->watchpoint_triggered = watch_triggered_yes;
4803 /* Possible return values for watchpoint_check. */
4804 enum wp_check_result
4806 /* The watchpoint has been deleted. */
4809 /* The value has changed. */
4810 WP_VALUE_CHANGED = 2,
4812 /* The value has not changed. */
4813 WP_VALUE_NOT_CHANGED = 3,
4815 /* Ignore this watchpoint, no matter if the value changed or not. */
4819 #define BP_TEMPFLAG 1
4820 #define BP_HARDWAREFLAG 2
4822 /* Evaluate watchpoint condition expression and check if its value
4825 static wp_check_result
4826 watchpoint_check (bpstat bs)
4828 struct watchpoint *b;
4829 struct frame_info *fr;
4830 int within_current_scope;
4832 /* BS is built from an existing struct breakpoint. */
4833 gdb_assert (bs->breakpoint_at != NULL);
4834 b = (struct watchpoint *) bs->breakpoint_at;
4836 /* If this is a local watchpoint, we only want to check if the
4837 watchpoint frame is in scope if the current thread is the thread
4838 that was used to create the watchpoint. */
4839 if (!watchpoint_in_thread_scope (b))
4842 if (b->exp_valid_block == NULL)
4843 within_current_scope = 1;
4846 struct frame_info *frame = get_current_frame ();
4847 struct gdbarch *frame_arch = get_frame_arch (frame);
4848 CORE_ADDR frame_pc = get_frame_pc (frame);
4850 /* stack_frame_destroyed_p() returns a non-zero value if we're
4851 still in the function but the stack frame has already been
4852 invalidated. Since we can't rely on the values of local
4853 variables after the stack has been destroyed, we are treating
4854 the watchpoint in that state as `not changed' without further
4855 checking. Don't mark watchpoints as changed if the current
4856 frame is in an epilogue - even if they are in some other
4857 frame, our view of the stack is likely to be wrong and
4858 frame_find_by_id could error out. */
4859 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
4862 fr = frame_find_by_id (b->watchpoint_frame);
4863 within_current_scope = (fr != NULL);
4865 /* If we've gotten confused in the unwinder, we might have
4866 returned a frame that can't describe this variable. */
4867 if (within_current_scope)
4869 struct symbol *function;
4871 function = get_frame_function (fr);
4872 if (function == NULL
4873 || !contained_in (b->exp_valid_block,
4874 SYMBOL_BLOCK_VALUE (function)))
4875 within_current_scope = 0;
4878 if (within_current_scope)
4879 /* If we end up stopping, the current frame will get selected
4880 in normal_stop. So this call to select_frame won't affect
4885 if (within_current_scope)
4887 /* We use value_{,free_to_}mark because it could be a *long*
4888 time before we return to the command level and call
4889 free_all_values. We can't call free_all_values because we
4890 might be in the middle of evaluating a function call. */
4894 struct value *new_val;
4896 if (is_masked_watchpoint (b))
4897 /* Since we don't know the exact trigger address (from
4898 stopped_data_address), just tell the user we've triggered
4899 a mask watchpoint. */
4900 return WP_VALUE_CHANGED;
4902 mark = value_mark ();
4903 fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
4905 if (b->val_bitsize != 0)
4906 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
4908 /* We use value_equal_contents instead of value_equal because
4909 the latter coerces an array to a pointer, thus comparing just
4910 the address of the array instead of its contents. This is
4911 not what we want. */
4912 if ((b->val != NULL) != (new_val != NULL)
4913 || (b->val != NULL && !value_equal_contents (b->val.get (),
4916 bs->old_val = b->val;
4917 b->val = release_value (new_val);
4919 if (new_val != NULL)
4920 value_free_to_mark (mark);
4921 return WP_VALUE_CHANGED;
4925 /* Nothing changed. */
4926 value_free_to_mark (mark);
4927 return WP_VALUE_NOT_CHANGED;
4932 /* This seems like the only logical thing to do because
4933 if we temporarily ignored the watchpoint, then when
4934 we reenter the block in which it is valid it contains
4935 garbage (in the case of a function, it may have two
4936 garbage values, one before and one after the prologue).
4937 So we can't even detect the first assignment to it and
4938 watch after that (since the garbage may or may not equal
4939 the first value assigned). */
4940 /* We print all the stop information in
4941 breakpoint_ops->print_it, but in this case, by the time we
4942 call breakpoint_ops->print_it this bp will be deleted
4943 already. So we have no choice but print the information
4946 SWITCH_THRU_ALL_UIS ()
4948 struct ui_out *uiout = current_uiout;
4950 if (uiout->is_mi_like_p ())
4952 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4953 uiout->text ("\nWatchpoint ");
4954 uiout->field_int ("wpnum", b->number);
4955 uiout->text (" deleted because the program has left the block in\n"
4956 "which its expression is valid.\n");
4959 /* Make sure the watchpoint's commands aren't executed. */
4961 watchpoint_del_at_next_stop (b);
4967 /* Return true if it looks like target has stopped due to hitting
4968 breakpoint location BL. This function does not check if we should
4969 stop, only if BL explains the stop. */
4972 bpstat_check_location (const struct bp_location *bl,
4973 const address_space *aspace, CORE_ADDR bp_addr,
4974 const struct target_waitstatus *ws)
4976 struct breakpoint *b = bl->owner;
4978 /* BL is from an existing breakpoint. */
4979 gdb_assert (b != NULL);
4981 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4984 /* Determine if the watched values have actually changed, and we
4985 should stop. If not, set BS->stop to 0. */
4988 bpstat_check_watchpoint (bpstat bs)
4990 const struct bp_location *bl;
4991 struct watchpoint *b;
4993 /* BS is built for existing struct breakpoint. */
4994 bl = bs->bp_location_at;
4995 gdb_assert (bl != NULL);
4996 b = (struct watchpoint *) bs->breakpoint_at;
4997 gdb_assert (b != NULL);
5000 int must_check_value = 0;
5002 if (b->type == bp_watchpoint)
5003 /* For a software watchpoint, we must always check the
5005 must_check_value = 1;
5006 else if (b->watchpoint_triggered == watch_triggered_yes)
5007 /* We have a hardware watchpoint (read, write, or access)
5008 and the target earlier reported an address watched by
5010 must_check_value = 1;
5011 else if (b->watchpoint_triggered == watch_triggered_unknown
5012 && b->type == bp_hardware_watchpoint)
5013 /* We were stopped by a hardware watchpoint, but the target could
5014 not report the data address. We must check the watchpoint's
5015 value. Access and read watchpoints are out of luck; without
5016 a data address, we can't figure it out. */
5017 must_check_value = 1;
5019 if (must_check_value)
5025 e = watchpoint_check (bs);
5027 CATCH (ex, RETURN_MASK_ALL)
5029 exception_fprintf (gdb_stderr, ex,
5030 "Error evaluating expression "
5031 "for watchpoint %d\n",
5034 SWITCH_THRU_ALL_UIS ()
5036 printf_filtered (_("Watchpoint %d deleted.\n"),
5039 watchpoint_del_at_next_stop (b);
5047 /* We've already printed what needs to be printed. */
5048 bs->print_it = print_it_done;
5052 bs->print_it = print_it_noop;
5055 case WP_VALUE_CHANGED:
5056 if (b->type == bp_read_watchpoint)
5058 /* There are two cases to consider here:
5060 1. We're watching the triggered memory for reads.
5061 In that case, trust the target, and always report
5062 the watchpoint hit to the user. Even though
5063 reads don't cause value changes, the value may
5064 have changed since the last time it was read, and
5065 since we're not trapping writes, we will not see
5066 those, and as such we should ignore our notion of
5069 2. We're watching the triggered memory for both
5070 reads and writes. There are two ways this may
5073 2.1. This is a target that can't break on data
5074 reads only, but can break on accesses (reads or
5075 writes), such as e.g., x86. We detect this case
5076 at the time we try to insert read watchpoints.
5078 2.2. Otherwise, the target supports read
5079 watchpoints, but, the user set an access or write
5080 watchpoint watching the same memory as this read
5083 If we're watching memory writes as well as reads,
5084 ignore watchpoint hits when we find that the
5085 value hasn't changed, as reads don't cause
5086 changes. This still gives false positives when
5087 the program writes the same value to memory as
5088 what there was already in memory (we will confuse
5089 it for a read), but it's much better than
5092 int other_write_watchpoint = 0;
5094 if (bl->watchpoint_type == hw_read)
5096 struct breakpoint *other_b;
5098 ALL_BREAKPOINTS (other_b)
5099 if (other_b->type == bp_hardware_watchpoint
5100 || other_b->type == bp_access_watchpoint)
5102 struct watchpoint *other_w =
5103 (struct watchpoint *) other_b;
5105 if (other_w->watchpoint_triggered
5106 == watch_triggered_yes)
5108 other_write_watchpoint = 1;
5114 if (other_write_watchpoint
5115 || bl->watchpoint_type == hw_access)
5117 /* We're watching the same memory for writes,
5118 and the value changed since the last time we
5119 updated it, so this trap must be for a write.
5121 bs->print_it = print_it_noop;
5126 case WP_VALUE_NOT_CHANGED:
5127 if (b->type == bp_hardware_watchpoint
5128 || b->type == bp_watchpoint)
5130 /* Don't stop: write watchpoints shouldn't fire if
5131 the value hasn't changed. */
5132 bs->print_it = print_it_noop;
5142 else /* must_check_value == 0 */
5144 /* This is a case where some watchpoint(s) triggered, but
5145 not at the address of this watchpoint, or else no
5146 watchpoint triggered after all. So don't print
5147 anything for this watchpoint. */
5148 bs->print_it = print_it_noop;
5154 /* For breakpoints that are currently marked as telling gdb to stop,
5155 check conditions (condition proper, frame, thread and ignore count)
5156 of breakpoint referred to by BS. If we should not stop for this
5157 breakpoint, set BS->stop to 0. */
5160 bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
5162 const struct bp_location *bl;
5163 struct breakpoint *b;
5165 bool condition_result = true;
5166 struct expression *cond;
5168 gdb_assert (bs->stop);
5170 /* BS is built for existing struct breakpoint. */
5171 bl = bs->bp_location_at;
5172 gdb_assert (bl != NULL);
5173 b = bs->breakpoint_at;
5174 gdb_assert (b != NULL);
5176 /* Even if the target evaluated the condition on its end and notified GDB, we
5177 need to do so again since GDB does not know if we stopped due to a
5178 breakpoint or a single step breakpoint. */
5180 if (frame_id_p (b->frame_id)
5181 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5187 /* If this is a thread/task-specific breakpoint, don't waste cpu
5188 evaluating the condition if this isn't the specified
5190 if ((b->thread != -1 && b->thread != thread->global_num)
5191 || (b->task != 0 && b->task != ada_get_task_number (thread)))
5197 /* Evaluate extension language breakpoints that have a "stop" method
5199 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5201 if (is_watchpoint (b))
5203 struct watchpoint *w = (struct watchpoint *) b;
5205 cond = w->cond_exp.get ();
5208 cond = bl->cond.get ();
5210 if (cond && b->disposition != disp_del_at_next_stop)
5212 int within_current_scope = 1;
5213 struct watchpoint * w;
5215 /* We use value_mark and value_free_to_mark because it could
5216 be a long time before we return to the command level and
5217 call free_all_values. We can't call free_all_values
5218 because we might be in the middle of evaluating a
5220 struct value *mark = value_mark ();
5222 if (is_watchpoint (b))
5223 w = (struct watchpoint *) b;
5227 /* Need to select the frame, with all that implies so that
5228 the conditions will have the right context. Because we
5229 use the frame, we will not see an inlined function's
5230 variables when we arrive at a breakpoint at the start
5231 of the inlined function; the current frame will be the
5233 if (w == NULL || w->cond_exp_valid_block == NULL)
5234 select_frame (get_current_frame ());
5237 struct frame_info *frame;
5239 /* For local watchpoint expressions, which particular
5240 instance of a local is being watched matters, so we
5241 keep track of the frame to evaluate the expression
5242 in. To evaluate the condition however, it doesn't
5243 really matter which instantiation of the function
5244 where the condition makes sense triggers the
5245 watchpoint. This allows an expression like "watch
5246 global if q > 10" set in `func', catch writes to
5247 global on all threads that call `func', or catch
5248 writes on all recursive calls of `func' by a single
5249 thread. We simply always evaluate the condition in
5250 the innermost frame that's executing where it makes
5251 sense to evaluate the condition. It seems
5253 frame = block_innermost_frame (w->cond_exp_valid_block);
5255 select_frame (frame);
5257 within_current_scope = 0;
5259 if (within_current_scope)
5263 condition_result = breakpoint_cond_eval (cond);
5265 CATCH (ex, RETURN_MASK_ALL)
5267 exception_fprintf (gdb_stderr, ex,
5268 "Error in testing breakpoint condition:\n");
5274 warning (_("Watchpoint condition cannot be tested "
5275 "in the current scope"));
5276 /* If we failed to set the right context for this
5277 watchpoint, unconditionally report it. */
5279 /* FIXME-someday, should give breakpoint #. */
5280 value_free_to_mark (mark);
5283 if (cond && !condition_result)
5287 else if (b->ignore_count > 0)
5291 /* Increase the hit count even though we don't stop. */
5293 gdb::observers::breakpoint_modified.notify (b);
5297 /* Returns true if we need to track moribund locations of LOC's type
5298 on the current target. */
5301 need_moribund_for_location_type (struct bp_location *loc)
5303 return ((loc->loc_type == bp_loc_software_breakpoint
5304 && !target_supports_stopped_by_sw_breakpoint ())
5305 || (loc->loc_type == bp_loc_hardware_breakpoint
5306 && !target_supports_stopped_by_hw_breakpoint ()));
5309 /* See breakpoint.h. */
5312 build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr,
5313 const struct target_waitstatus *ws)
5315 struct breakpoint *b;
5316 bpstat bs_head = NULL, *bs_link = &bs_head;
5320 if (!breakpoint_enabled (b))
5323 for (bp_location *bl = b->loc; bl != NULL; bl = bl->next)
5325 /* For hardware watchpoints, we look only at the first
5326 location. The watchpoint_check function will work on the
5327 entire expression, not the individual locations. For
5328 read watchpoints, the watchpoints_triggered function has
5329 checked all locations already. */
5330 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5333 if (!bl->enabled || bl->shlib_disabled)
5336 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5339 /* Come here if it's a watchpoint, or if the break address
5342 bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to
5345 /* Assume we stop. Should we find a watchpoint that is not
5346 actually triggered, or if the condition of the breakpoint
5347 evaluates as false, we'll reset 'stop' to 0. */
5351 /* If this is a scope breakpoint, mark the associated
5352 watchpoint as triggered so that we will handle the
5353 out-of-scope event. We'll get to the watchpoint next
5355 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5357 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5359 w->watchpoint_triggered = watch_triggered_yes;
5364 /* Check if a moribund breakpoint explains the stop. */
5365 if (!target_supports_stopped_by_sw_breakpoint ()
5366 || !target_supports_stopped_by_hw_breakpoint ())
5368 for (bp_location *loc : moribund_locations)
5370 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5371 && need_moribund_for_location_type (loc))
5373 bpstat bs = new bpstats (loc, &bs_link);
5374 /* For hits of moribund locations, we should just proceed. */
5377 bs->print_it = print_it_noop;
5385 /* See breakpoint.h. */
5388 bpstat_stop_status (const address_space *aspace,
5389 CORE_ADDR bp_addr, thread_info *thread,
5390 const struct target_waitstatus *ws,
5393 struct breakpoint *b = NULL;
5394 /* First item of allocated bpstat's. */
5395 bpstat bs_head = stop_chain;
5397 int need_remove_insert;
5400 /* First, build the bpstat chain with locations that explain a
5401 target stop, while being careful to not set the target running,
5402 as that may invalidate locations (in particular watchpoint
5403 locations are recreated). Resuming will happen here with
5404 breakpoint conditions or watchpoint expressions that include
5405 inferior function calls. */
5406 if (bs_head == NULL)
5407 bs_head = build_bpstat_chain (aspace, bp_addr, ws);
5409 /* A bit of special processing for shlib breakpoints. We need to
5410 process solib loading here, so that the lists of loaded and
5411 unloaded libraries are correct before we handle "catch load" and
5413 for (bs = bs_head; bs != NULL; bs = bs->next)
5415 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5417 handle_solib_event ();
5422 /* Now go through the locations that caused the target to stop, and
5423 check whether we're interested in reporting this stop to higher
5424 layers, or whether we should resume the target transparently. */
5428 for (bs = bs_head; bs != NULL; bs = bs->next)
5433 b = bs->breakpoint_at;
5434 b->ops->check_status (bs);
5437 bpstat_check_breakpoint_conditions (bs, thread);
5442 gdb::observers::breakpoint_modified.notify (b);
5444 /* We will stop here. */
5445 if (b->disposition == disp_disable)
5447 --(b->enable_count);
5448 if (b->enable_count <= 0)
5449 b->enable_state = bp_disabled;
5454 bs->commands = b->commands;
5455 if (command_line_is_silent (bs->commands
5456 ? bs->commands.get () : NULL))
5459 b->ops->after_condition_true (bs);
5464 /* Print nothing for this entry if we don't stop or don't
5466 if (!bs->stop || !bs->print)
5467 bs->print_it = print_it_noop;
5470 /* If we aren't stopping, the value of some hardware watchpoint may
5471 not have changed, but the intermediate memory locations we are
5472 watching may have. Don't bother if we're stopping; this will get
5474 need_remove_insert = 0;
5475 if (! bpstat_causes_stop (bs_head))
5476 for (bs = bs_head; bs != NULL; bs = bs->next)
5478 && bs->breakpoint_at
5479 && is_hardware_watchpoint (bs->breakpoint_at))
5481 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5483 update_watchpoint (w, 0 /* don't reparse. */);
5484 need_remove_insert = 1;
5487 if (need_remove_insert)
5488 update_global_location_list (UGLL_MAY_INSERT);
5489 else if (removed_any)
5490 update_global_location_list (UGLL_DONT_INSERT);
5496 handle_jit_event (void)
5498 struct frame_info *frame;
5499 struct gdbarch *gdbarch;
5502 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5504 /* Switch terminal for any messages produced by
5505 breakpoint_re_set. */
5506 target_terminal::ours_for_output ();
5508 frame = get_current_frame ();
5509 gdbarch = get_frame_arch (frame);
5511 jit_event_handler (gdbarch);
5513 target_terminal::inferior ();
5516 /* Prepare WHAT final decision for infrun. */
5518 /* Decide what infrun needs to do with this bpstat. */
5521 bpstat_what (bpstat bs_head)
5523 struct bpstat_what retval;
5526 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5527 retval.call_dummy = STOP_NONE;
5528 retval.is_longjmp = 0;
5530 for (bs = bs_head; bs != NULL; bs = bs->next)
5532 /* Extract this BS's action. After processing each BS, we check
5533 if its action overrides all we've seem so far. */
5534 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5537 if (bs->breakpoint_at == NULL)
5539 /* I suspect this can happen if it was a momentary
5540 breakpoint which has since been deleted. */
5544 bptype = bs->breakpoint_at->type;
5551 case bp_hardware_breakpoint:
5552 case bp_single_step:
5555 case bp_shlib_event:
5559 this_action = BPSTAT_WHAT_STOP_NOISY;
5561 this_action = BPSTAT_WHAT_STOP_SILENT;
5564 this_action = BPSTAT_WHAT_SINGLE;
5567 case bp_hardware_watchpoint:
5568 case bp_read_watchpoint:
5569 case bp_access_watchpoint:
5573 this_action = BPSTAT_WHAT_STOP_NOISY;
5575 this_action = BPSTAT_WHAT_STOP_SILENT;
5579 /* There was a watchpoint, but we're not stopping.
5580 This requires no further action. */
5584 case bp_longjmp_call_dummy:
5588 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5589 retval.is_longjmp = bptype != bp_exception;
5592 this_action = BPSTAT_WHAT_SINGLE;
5594 case bp_longjmp_resume:
5595 case bp_exception_resume:
5598 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5599 retval.is_longjmp = bptype == bp_longjmp_resume;
5602 this_action = BPSTAT_WHAT_SINGLE;
5604 case bp_step_resume:
5606 this_action = BPSTAT_WHAT_STEP_RESUME;
5609 /* It is for the wrong frame. */
5610 this_action = BPSTAT_WHAT_SINGLE;
5613 case bp_hp_step_resume:
5615 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5618 /* It is for the wrong frame. */
5619 this_action = BPSTAT_WHAT_SINGLE;
5622 case bp_watchpoint_scope:
5623 case bp_thread_event:
5624 case bp_overlay_event:
5625 case bp_longjmp_master:
5626 case bp_std_terminate_master:
5627 case bp_exception_master:
5628 this_action = BPSTAT_WHAT_SINGLE;
5634 this_action = BPSTAT_WHAT_STOP_NOISY;
5636 this_action = BPSTAT_WHAT_STOP_SILENT;
5640 /* There was a catchpoint, but we're not stopping.
5641 This requires no further action. */
5645 this_action = BPSTAT_WHAT_SINGLE;
5648 /* Make sure the action is stop (silent or noisy),
5649 so infrun.c pops the dummy frame. */
5650 retval.call_dummy = STOP_STACK_DUMMY;
5651 this_action = BPSTAT_WHAT_STOP_SILENT;
5653 case bp_std_terminate:
5654 /* Make sure the action is stop (silent or noisy),
5655 so infrun.c pops the dummy frame. */
5656 retval.call_dummy = STOP_STD_TERMINATE;
5657 this_action = BPSTAT_WHAT_STOP_SILENT;
5660 case bp_fast_tracepoint:
5661 case bp_static_tracepoint:
5662 /* Tracepoint hits should not be reported back to GDB, and
5663 if one got through somehow, it should have been filtered
5665 internal_error (__FILE__, __LINE__,
5666 _("bpstat_what: tracepoint encountered"));
5668 case bp_gnu_ifunc_resolver:
5669 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5670 this_action = BPSTAT_WHAT_SINGLE;
5672 case bp_gnu_ifunc_resolver_return:
5673 /* The breakpoint will be removed, execution will restart from the
5674 PC of the former breakpoint. */
5675 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5680 this_action = BPSTAT_WHAT_STOP_SILENT;
5682 this_action = BPSTAT_WHAT_SINGLE;
5686 internal_error (__FILE__, __LINE__,
5687 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5690 retval.main_action = std::max (retval.main_action, this_action);
5697 bpstat_run_callbacks (bpstat bs_head)
5701 for (bs = bs_head; bs != NULL; bs = bs->next)
5703 struct breakpoint *b = bs->breakpoint_at;
5710 handle_jit_event ();
5712 case bp_gnu_ifunc_resolver:
5713 gnu_ifunc_resolver_stop (b);
5715 case bp_gnu_ifunc_resolver_return:
5716 gnu_ifunc_resolver_return_stop (b);
5722 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5723 without hardware support). This isn't related to a specific bpstat,
5724 just to things like whether watchpoints are set. */
5727 bpstat_should_step (void)
5729 struct breakpoint *b;
5732 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5738 bpstat_causes_stop (bpstat bs)
5740 for (; bs != NULL; bs = bs->next)
5749 /* Compute a string of spaces suitable to indent the next line
5750 so it starts at the position corresponding to the table column
5751 named COL_NAME in the currently active table of UIOUT. */
5754 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5756 static char wrap_indent[80];
5757 int i, total_width, width, align;
5761 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
5763 if (strcmp (text, col_name) == 0)
5765 gdb_assert (total_width < sizeof wrap_indent);
5766 memset (wrap_indent, ' ', total_width);
5767 wrap_indent[total_width] = 0;
5772 total_width += width + 1;
5778 /* Determine if the locations of this breakpoint will have their conditions
5779 evaluated by the target, host or a mix of both. Returns the following:
5781 "host": Host evals condition.
5782 "host or target": Host or Target evals condition.
5783 "target": Target evals condition.
5787 bp_condition_evaluator (struct breakpoint *b)
5789 struct bp_location *bl;
5790 char host_evals = 0;
5791 char target_evals = 0;
5796 if (!is_breakpoint (b))
5799 if (gdb_evaluates_breakpoint_condition_p ()
5800 || !target_supports_evaluation_of_breakpoint_conditions ())
5801 return condition_evaluation_host;
5803 for (bl = b->loc; bl; bl = bl->next)
5805 if (bl->cond_bytecode)
5811 if (host_evals && target_evals)
5812 return condition_evaluation_both;
5813 else if (target_evals)
5814 return condition_evaluation_target;
5816 return condition_evaluation_host;
5819 /* Determine the breakpoint location's condition evaluator. This is
5820 similar to bp_condition_evaluator, but for locations. */
5823 bp_location_condition_evaluator (struct bp_location *bl)
5825 if (bl && !is_breakpoint (bl->owner))
5828 if (gdb_evaluates_breakpoint_condition_p ()
5829 || !target_supports_evaluation_of_breakpoint_conditions ())
5830 return condition_evaluation_host;
5832 if (bl && bl->cond_bytecode)
5833 return condition_evaluation_target;
5835 return condition_evaluation_host;
5838 /* Print the LOC location out of the list of B->LOC locations. */
5841 print_breakpoint_location (struct breakpoint *b,
5842 struct bp_location *loc)
5844 struct ui_out *uiout = current_uiout;
5846 scoped_restore_current_program_space restore_pspace;
5848 if (loc != NULL && loc->shlib_disabled)
5852 set_current_program_space (loc->pspace);
5854 if (b->display_canonical)
5855 uiout->field_string ("what", event_location_to_string (b->location.get ()));
5856 else if (loc && loc->symtab)
5858 const struct symbol *sym = loc->symbol;
5862 uiout->text ("in ");
5863 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
5864 ui_out_style_kind::FUNCTION);
5866 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
5867 uiout->text ("at ");
5869 uiout->field_string ("file",
5870 symtab_to_filename_for_display (loc->symtab),
5871 ui_out_style_kind::FILE);
5874 if (uiout->is_mi_like_p ())
5875 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
5877 uiout->field_int ("line", loc->line_number);
5883 print_address_symbolic (loc->gdbarch, loc->address, &stb,
5885 uiout->field_stream ("at", stb);
5889 uiout->field_string ("pending",
5890 event_location_to_string (b->location.get ()));
5891 /* If extra_string is available, it could be holding a condition
5892 or dprintf arguments. In either case, make sure it is printed,
5893 too, but only for non-MI streams. */
5894 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
5896 if (b->type == bp_dprintf)
5900 uiout->text (b->extra_string);
5904 if (loc && is_breakpoint (b)
5905 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5906 && bp_condition_evaluator (b) == condition_evaluation_both)
5909 uiout->field_string ("evaluated-by",
5910 bp_location_condition_evaluator (loc));
5916 bptype_string (enum bptype type)
5918 struct ep_type_description
5921 const char *description;
5923 static struct ep_type_description bptypes[] =
5925 {bp_none, "?deleted?"},
5926 {bp_breakpoint, "breakpoint"},
5927 {bp_hardware_breakpoint, "hw breakpoint"},
5928 {bp_single_step, "sw single-step"},
5929 {bp_until, "until"},
5930 {bp_finish, "finish"},
5931 {bp_watchpoint, "watchpoint"},
5932 {bp_hardware_watchpoint, "hw watchpoint"},
5933 {bp_read_watchpoint, "read watchpoint"},
5934 {bp_access_watchpoint, "acc watchpoint"},
5935 {bp_longjmp, "longjmp"},
5936 {bp_longjmp_resume, "longjmp resume"},
5937 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5938 {bp_exception, "exception"},
5939 {bp_exception_resume, "exception resume"},
5940 {bp_step_resume, "step resume"},
5941 {bp_hp_step_resume, "high-priority step resume"},
5942 {bp_watchpoint_scope, "watchpoint scope"},
5943 {bp_call_dummy, "call dummy"},
5944 {bp_std_terminate, "std::terminate"},
5945 {bp_shlib_event, "shlib events"},
5946 {bp_thread_event, "thread events"},
5947 {bp_overlay_event, "overlay events"},
5948 {bp_longjmp_master, "longjmp master"},
5949 {bp_std_terminate_master, "std::terminate master"},
5950 {bp_exception_master, "exception master"},
5951 {bp_catchpoint, "catchpoint"},
5952 {bp_tracepoint, "tracepoint"},
5953 {bp_fast_tracepoint, "fast tracepoint"},
5954 {bp_static_tracepoint, "static tracepoint"},
5955 {bp_dprintf, "dprintf"},
5956 {bp_jit_event, "jit events"},
5957 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5958 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5961 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5962 || ((int) type != bptypes[(int) type].type))
5963 internal_error (__FILE__, __LINE__,
5964 _("bptypes table does not describe type #%d."),
5967 return bptypes[(int) type].description;
5970 /* For MI, output a field named 'thread-groups' with a list as the value.
5971 For CLI, prefix the list with the string 'inf'. */
5974 output_thread_groups (struct ui_out *uiout,
5975 const char *field_name,
5976 const std::vector<int> &inf_nums,
5979 int is_mi = uiout->is_mi_like_p ();
5981 /* For backward compatibility, don't display inferiors in CLI unless
5982 there are several. Always display them for MI. */
5983 if (!is_mi && mi_only)
5986 ui_out_emit_list list_emitter (uiout, field_name);
5988 for (size_t i = 0; i < inf_nums.size (); i++)
5994 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]);
5995 uiout->field_string (NULL, mi_group);
6000 uiout->text (" inf ");
6004 uiout->text (plongest (inf_nums[i]));
6009 /* Print B to gdb_stdout. */
6012 print_one_breakpoint_location (struct breakpoint *b,
6013 struct bp_location *loc,
6015 struct bp_location **last_loc,
6018 struct command_line *l;
6019 static char bpenables[] = "nynny";
6021 struct ui_out *uiout = current_uiout;
6022 int header_of_multiple = 0;
6023 int part_of_multiple = (loc != NULL);
6024 struct value_print_options opts;
6026 get_user_print_options (&opts);
6028 gdb_assert (!loc || loc_number != 0);
6029 /* See comment in print_one_breakpoint concerning treatment of
6030 breakpoints with single disabled location. */
6033 && (b->loc->next != NULL || !b->loc->enabled)))
6034 header_of_multiple = 1;
6042 if (part_of_multiple)
6043 uiout->field_fmt ("number", "%d.%d", b->number, loc_number);
6045 uiout->field_int ("number", b->number);
6049 if (part_of_multiple)
6050 uiout->field_skip ("type");
6052 uiout->field_string ("type", bptype_string (b->type));
6056 if (part_of_multiple)
6057 uiout->field_skip ("disp");
6059 uiout->field_string ("disp", bpdisp_text (b->disposition));
6063 if (part_of_multiple)
6064 uiout->field_string ("enabled", loc->enabled ? "y" : "n");
6066 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6069 if (b->ops != NULL && b->ops->print_one != NULL)
6071 /* Although the print_one can possibly print all locations,
6072 calling it here is not likely to get any nice result. So,
6073 make sure there's just one location. */
6074 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6075 b->ops->print_one (b, last_loc);
6081 internal_error (__FILE__, __LINE__,
6082 _("print_one_breakpoint: bp_none encountered\n"));
6086 case bp_hardware_watchpoint:
6087 case bp_read_watchpoint:
6088 case bp_access_watchpoint:
6090 struct watchpoint *w = (struct watchpoint *) b;
6092 /* Field 4, the address, is omitted (which makes the columns
6093 not line up too nicely with the headers, but the effect
6094 is relatively readable). */
6095 if (opts.addressprint)
6096 uiout->field_skip ("addr");
6098 uiout->field_string ("what", w->exp_string);
6103 case bp_hardware_breakpoint:
6104 case bp_single_step:
6108 case bp_longjmp_resume:
6109 case bp_longjmp_call_dummy:
6111 case bp_exception_resume:
6112 case bp_step_resume:
6113 case bp_hp_step_resume:
6114 case bp_watchpoint_scope:
6116 case bp_std_terminate:
6117 case bp_shlib_event:
6118 case bp_thread_event:
6119 case bp_overlay_event:
6120 case bp_longjmp_master:
6121 case bp_std_terminate_master:
6122 case bp_exception_master:
6124 case bp_fast_tracepoint:
6125 case bp_static_tracepoint:
6128 case bp_gnu_ifunc_resolver:
6129 case bp_gnu_ifunc_resolver_return:
6130 if (opts.addressprint)
6133 if (header_of_multiple)
6134 uiout->field_string ("addr", "<MULTIPLE>");
6135 else if (b->loc == NULL || loc->shlib_disabled)
6136 uiout->field_string ("addr", "<PENDING>");
6138 uiout->field_core_addr ("addr",
6139 loc->gdbarch, loc->address);
6142 if (!header_of_multiple)
6143 print_breakpoint_location (b, loc);
6150 if (loc != NULL && !header_of_multiple)
6152 std::vector<int> inf_nums;
6155 for (inferior *inf : all_inferiors ())
6157 if (inf->pspace == loc->pspace)
6158 inf_nums.push_back (inf->num);
6161 /* For backward compatibility, don't display inferiors in CLI unless
6162 there are several. Always display for MI. */
6164 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6165 && (number_of_program_spaces () > 1
6166 || number_of_inferiors () > 1)
6167 /* LOC is for existing B, it cannot be in
6168 moribund_locations and thus having NULL OWNER. */
6169 && loc->owner->type != bp_catchpoint))
6171 output_thread_groups (uiout, "thread-groups", inf_nums, mi_only);
6174 if (!part_of_multiple)
6176 if (b->thread != -1)
6178 /* FIXME: This seems to be redundant and lost here; see the
6179 "stop only in" line a little further down. */
6180 uiout->text (" thread ");
6181 uiout->field_int ("thread", b->thread);
6183 else if (b->task != 0)
6185 uiout->text (" task ");
6186 uiout->field_int ("task", b->task);
6192 if (!part_of_multiple)
6193 b->ops->print_one_detail (b, uiout);
6195 if (part_of_multiple && frame_id_p (b->frame_id))
6198 uiout->text ("\tstop only in stack frame at ");
6199 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6201 uiout->field_core_addr ("frame",
6202 b->gdbarch, b->frame_id.stack_addr);
6206 if (!part_of_multiple && b->cond_string)
6209 if (is_tracepoint (b))
6210 uiout->text ("\ttrace only if ");
6212 uiout->text ("\tstop only if ");
6213 uiout->field_string ("cond", b->cond_string);
6215 /* Print whether the target is doing the breakpoint's condition
6216 evaluation. If GDB is doing the evaluation, don't print anything. */
6217 if (is_breakpoint (b)
6218 && breakpoint_condition_evaluation_mode ()
6219 == condition_evaluation_target)
6222 uiout->field_string ("evaluated-by",
6223 bp_condition_evaluator (b));
6224 uiout->text (" evals)");
6229 if (!part_of_multiple && b->thread != -1)
6231 /* FIXME should make an annotation for this. */
6232 uiout->text ("\tstop only in thread ");
6233 if (uiout->is_mi_like_p ())
6234 uiout->field_int ("thread", b->thread);
6237 struct thread_info *thr = find_thread_global_id (b->thread);
6239 uiout->field_string ("thread", print_thread_id (thr));
6244 if (!part_of_multiple)
6248 /* FIXME should make an annotation for this. */
6249 if (is_catchpoint (b))
6250 uiout->text ("\tcatchpoint");
6251 else if (is_tracepoint (b))
6252 uiout->text ("\ttracepoint");
6254 uiout->text ("\tbreakpoint");
6255 uiout->text (" already hit ");
6256 uiout->field_int ("times", b->hit_count);
6257 if (b->hit_count == 1)
6258 uiout->text (" time\n");
6260 uiout->text (" times\n");
6264 /* Output the count also if it is zero, but only if this is mi. */
6265 if (uiout->is_mi_like_p ())
6266 uiout->field_int ("times", b->hit_count);
6270 if (!part_of_multiple && b->ignore_count)
6273 uiout->text ("\tignore next ");
6274 uiout->field_int ("ignore", b->ignore_count);
6275 uiout->text (" hits\n");
6278 /* Note that an enable count of 1 corresponds to "enable once"
6279 behavior, which is reported by the combination of enablement and
6280 disposition, so we don't need to mention it here. */
6281 if (!part_of_multiple && b->enable_count > 1)
6284 uiout->text ("\tdisable after ");
6285 /* Tweak the wording to clarify that ignore and enable counts
6286 are distinct, and have additive effect. */
6287 if (b->ignore_count)
6288 uiout->text ("additional ");
6290 uiout->text ("next ");
6291 uiout->field_int ("enable", b->enable_count);
6292 uiout->text (" hits\n");
6295 if (!part_of_multiple && is_tracepoint (b))
6297 struct tracepoint *tp = (struct tracepoint *) b;
6299 if (tp->traceframe_usage)
6301 uiout->text ("\ttrace buffer usage ");
6302 uiout->field_int ("traceframe-usage", tp->traceframe_usage);
6303 uiout->text (" bytes\n");
6307 l = b->commands ? b->commands.get () : NULL;
6308 if (!part_of_multiple && l)
6311 ui_out_emit_tuple tuple_emitter (uiout, "script");
6312 print_command_lines (uiout, l, 4);
6315 if (is_tracepoint (b))
6317 struct tracepoint *t = (struct tracepoint *) b;
6319 if (!part_of_multiple && t->pass_count)
6321 annotate_field (10);
6322 uiout->text ("\tpass count ");
6323 uiout->field_int ("pass", t->pass_count);
6324 uiout->text (" \n");
6327 /* Don't display it when tracepoint or tracepoint location is
6329 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6331 annotate_field (11);
6333 if (uiout->is_mi_like_p ())
6334 uiout->field_string ("installed",
6335 loc->inserted ? "y" : "n");
6341 uiout->text ("\tnot ");
6342 uiout->text ("installed on target\n");
6347 if (uiout->is_mi_like_p () && !part_of_multiple)
6349 if (is_watchpoint (b))
6351 struct watchpoint *w = (struct watchpoint *) b;
6353 uiout->field_string ("original-location", w->exp_string);
6355 else if (b->location != NULL
6356 && event_location_to_string (b->location.get ()) != NULL)
6357 uiout->field_string ("original-location",
6358 event_location_to_string (b->location.get ()));
6363 print_one_breakpoint (struct breakpoint *b,
6364 struct bp_location **last_loc,
6367 struct ui_out *uiout = current_uiout;
6370 ui_out_emit_tuple tuple_emitter (uiout, "bkpt");
6372 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6375 /* If this breakpoint has custom print function,
6376 it's already printed. Otherwise, print individual
6377 locations, if any. */
6378 if (b->ops == NULL || b->ops->print_one == NULL)
6380 /* If breakpoint has a single location that is disabled, we
6381 print it as if it had several locations, since otherwise it's
6382 hard to represent "breakpoint enabled, location disabled"
6385 Note that while hardware watchpoints have several locations
6386 internally, that's not a property exposed to user. */
6388 && !is_hardware_watchpoint (b)
6389 && (b->loc->next || !b->loc->enabled))
6391 struct bp_location *loc;
6394 for (loc = b->loc; loc; loc = loc->next, ++n)
6396 ui_out_emit_tuple tuple_emitter (uiout, NULL);
6397 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6404 breakpoint_address_bits (struct breakpoint *b)
6406 int print_address_bits = 0;
6407 struct bp_location *loc;
6409 /* Software watchpoints that aren't watching memory don't have an
6410 address to print. */
6411 if (is_no_memory_software_watchpoint (b))
6414 for (loc = b->loc; loc; loc = loc->next)
6418 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6419 if (addr_bit > print_address_bits)
6420 print_address_bits = addr_bit;
6423 return print_address_bits;
6426 /* See breakpoint.h. */
6429 print_breakpoint (breakpoint *b)
6431 struct bp_location *dummy_loc = NULL;
6432 print_one_breakpoint (b, &dummy_loc, 0);
6435 /* Return true if this breakpoint was set by the user, false if it is
6436 internal or momentary. */
6439 user_breakpoint_p (struct breakpoint *b)
6441 return b->number > 0;
6444 /* See breakpoint.h. */
6447 pending_breakpoint_p (struct breakpoint *b)
6449 return b->loc == NULL;
6452 /* Print information on user settable breakpoint (watchpoint, etc)
6453 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6454 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6455 FILTER is non-NULL, call it on each breakpoint and only include the
6456 ones for which it returns non-zero. Return the total number of
6457 breakpoints listed. */
6460 breakpoint_1 (const char *args, int allflag,
6461 int (*filter) (const struct breakpoint *))
6463 struct breakpoint *b;
6464 struct bp_location *last_loc = NULL;
6465 int nr_printable_breakpoints;
6466 struct value_print_options opts;
6467 int print_address_bits = 0;
6468 int print_type_col_width = 14;
6469 struct ui_out *uiout = current_uiout;
6471 get_user_print_options (&opts);
6473 /* Compute the number of rows in the table, as well as the size
6474 required for address fields. */
6475 nr_printable_breakpoints = 0;
6478 /* If we have a filter, only list the breakpoints it accepts. */
6479 if (filter && !filter (b))
6482 /* If we have an "args" string, it is a list of breakpoints to
6483 accept. Skip the others. */
6484 if (args != NULL && *args != '\0')
6486 if (allflag && parse_and_eval_long (args) != b->number)
6488 if (!allflag && !number_is_in_list (args, b->number))
6492 if (allflag || user_breakpoint_p (b))
6494 int addr_bit, type_len;
6496 addr_bit = breakpoint_address_bits (b);
6497 if (addr_bit > print_address_bits)
6498 print_address_bits = addr_bit;
6500 type_len = strlen (bptype_string (b->type));
6501 if (type_len > print_type_col_width)
6502 print_type_col_width = type_len;
6504 nr_printable_breakpoints++;
6509 ui_out_emit_table table_emitter (uiout,
6510 opts.addressprint ? 6 : 5,
6511 nr_printable_breakpoints,
6514 if (nr_printable_breakpoints > 0)
6515 annotate_breakpoints_headers ();
6516 if (nr_printable_breakpoints > 0)
6518 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
6519 if (nr_printable_breakpoints > 0)
6521 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
6522 if (nr_printable_breakpoints > 0)
6524 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
6525 if (nr_printable_breakpoints > 0)
6527 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
6528 if (opts.addressprint)
6530 if (nr_printable_breakpoints > 0)
6532 if (print_address_bits <= 32)
6533 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
6535 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
6537 if (nr_printable_breakpoints > 0)
6539 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
6540 uiout->table_body ();
6541 if (nr_printable_breakpoints > 0)
6542 annotate_breakpoints_table ();
6547 /* If we have a filter, only list the breakpoints it accepts. */
6548 if (filter && !filter (b))
6551 /* If we have an "args" string, it is a list of breakpoints to
6552 accept. Skip the others. */
6554 if (args != NULL && *args != '\0')
6556 if (allflag) /* maintenance info breakpoint */
6558 if (parse_and_eval_long (args) != b->number)
6561 else /* all others */
6563 if (!number_is_in_list (args, b->number))
6567 /* We only print out user settable breakpoints unless the
6569 if (allflag || user_breakpoint_p (b))
6570 print_one_breakpoint (b, &last_loc, allflag);
6574 if (nr_printable_breakpoints == 0)
6576 /* If there's a filter, let the caller decide how to report
6580 if (args == NULL || *args == '\0')
6581 uiout->message ("No breakpoints or watchpoints.\n");
6583 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
6589 if (last_loc && !server_command)
6590 set_next_address (last_loc->gdbarch, last_loc->address);
6593 /* FIXME? Should this be moved up so that it is only called when
6594 there have been breakpoints? */
6595 annotate_breakpoints_table_end ();
6597 return nr_printable_breakpoints;
6600 /* Display the value of default-collect in a way that is generally
6601 compatible with the breakpoint list. */
6604 default_collect_info (void)
6606 struct ui_out *uiout = current_uiout;
6608 /* If it has no value (which is frequently the case), say nothing; a
6609 message like "No default-collect." gets in user's face when it's
6611 if (!*default_collect)
6614 /* The following phrase lines up nicely with per-tracepoint collect
6616 uiout->text ("default collect ");
6617 uiout->field_string ("default-collect", default_collect);
6618 uiout->text (" \n");
6622 info_breakpoints_command (const char *args, int from_tty)
6624 breakpoint_1 (args, 0, NULL);
6626 default_collect_info ();
6630 info_watchpoints_command (const char *args, int from_tty)
6632 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6633 struct ui_out *uiout = current_uiout;
6635 if (num_printed == 0)
6637 if (args == NULL || *args == '\0')
6638 uiout->message ("No watchpoints.\n");
6640 uiout->message ("No watchpoint matching '%s'.\n", args);
6645 maintenance_info_breakpoints (const char *args, int from_tty)
6647 breakpoint_1 (args, 1, NULL);
6649 default_collect_info ();
6653 breakpoint_has_pc (struct breakpoint *b,
6654 struct program_space *pspace,
6655 CORE_ADDR pc, struct obj_section *section)
6657 struct bp_location *bl = b->loc;
6659 for (; bl; bl = bl->next)
6661 if (bl->pspace == pspace
6662 && bl->address == pc
6663 && (!overlay_debugging || bl->section == section))
6669 /* Print a message describing any user-breakpoints set at PC. This
6670 concerns with logical breakpoints, so we match program spaces, not
6674 describe_other_breakpoints (struct gdbarch *gdbarch,
6675 struct program_space *pspace, CORE_ADDR pc,
6676 struct obj_section *section, int thread)
6679 struct breakpoint *b;
6682 others += (user_breakpoint_p (b)
6683 && breakpoint_has_pc (b, pspace, pc, section));
6687 printf_filtered (_("Note: breakpoint "));
6688 else /* if (others == ???) */
6689 printf_filtered (_("Note: breakpoints "));
6691 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6694 printf_filtered ("%d", b->number);
6695 if (b->thread == -1 && thread != -1)
6696 printf_filtered (" (all threads)");
6697 else if (b->thread != -1)
6698 printf_filtered (" (thread %d)", b->thread);
6699 printf_filtered ("%s%s ",
6700 ((b->enable_state == bp_disabled
6701 || b->enable_state == bp_call_disabled)
6705 : ((others == 1) ? " and" : ""));
6707 printf_filtered (_("also set at pc "));
6708 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6709 printf_filtered (".\n");
6714 /* Return true iff it is meaningful to use the address member of
6715 BPT locations. For some breakpoint types, the locations' address members
6716 are irrelevant and it makes no sense to attempt to compare them to other
6717 addresses (or use them for any other purpose either).
6719 More specifically, each of the following breakpoint types will
6720 always have a zero valued location address and we don't want to mark
6721 breakpoints of any of these types to be a duplicate of an actual
6722 breakpoint location at address zero:
6730 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6732 enum bptype type = bpt->type;
6734 return (type != bp_watchpoint && type != bp_catchpoint);
6737 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6738 true if LOC1 and LOC2 represent the same watchpoint location. */
6741 watchpoint_locations_match (struct bp_location *loc1,
6742 struct bp_location *loc2)
6744 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6745 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6747 /* Both of them must exist. */
6748 gdb_assert (w1 != NULL);
6749 gdb_assert (w2 != NULL);
6751 /* If the target can evaluate the condition expression in hardware,
6752 then we we need to insert both watchpoints even if they are at
6753 the same place. Otherwise the watchpoint will only trigger when
6754 the condition of whichever watchpoint was inserted evaluates to
6755 true, not giving a chance for GDB to check the condition of the
6756 other watchpoint. */
6758 && target_can_accel_watchpoint_condition (loc1->address,
6760 loc1->watchpoint_type,
6761 w1->cond_exp.get ()))
6763 && target_can_accel_watchpoint_condition (loc2->address,
6765 loc2->watchpoint_type,
6766 w2->cond_exp.get ())))
6769 /* Note that this checks the owner's type, not the location's. In
6770 case the target does not support read watchpoints, but does
6771 support access watchpoints, we'll have bp_read_watchpoint
6772 watchpoints with hw_access locations. Those should be considered
6773 duplicates of hw_read locations. The hw_read locations will
6774 become hw_access locations later. */
6775 return (loc1->owner->type == loc2->owner->type
6776 && loc1->pspace->aspace == loc2->pspace->aspace
6777 && loc1->address == loc2->address
6778 && loc1->length == loc2->length);
6781 /* See breakpoint.h. */
6784 breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
6785 const address_space *aspace2, CORE_ADDR addr2)
6787 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6788 || aspace1 == aspace2)
6792 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6793 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6794 matches ASPACE2. On targets that have global breakpoints, the address
6795 space doesn't really matter. */
6798 breakpoint_address_match_range (const address_space *aspace1,
6800 int len1, const address_space *aspace2,
6803 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6804 || aspace1 == aspace2)
6805 && addr2 >= addr1 && addr2 < addr1 + len1);
6808 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6809 a ranged breakpoint. In most targets, a match happens only if ASPACE
6810 matches the breakpoint's address space. On targets that have global
6811 breakpoints, the address space doesn't really matter. */
6814 breakpoint_location_address_match (struct bp_location *bl,
6815 const address_space *aspace,
6818 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6821 && breakpoint_address_match_range (bl->pspace->aspace,
6822 bl->address, bl->length,
6826 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6827 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6828 match happens only if ASPACE matches the breakpoint's address
6829 space. On targets that have global breakpoints, the address space
6830 doesn't really matter. */
6833 breakpoint_location_address_range_overlap (struct bp_location *bl,
6834 const address_space *aspace,
6835 CORE_ADDR addr, int len)
6837 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6838 || bl->pspace->aspace == aspace)
6840 int bl_len = bl->length != 0 ? bl->length : 1;
6842 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
6848 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6849 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6850 true, otherwise returns false. */
6853 tracepoint_locations_match (struct bp_location *loc1,
6854 struct bp_location *loc2)
6856 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6857 /* Since tracepoint locations are never duplicated with others', tracepoint
6858 locations at the same address of different tracepoints are regarded as
6859 different locations. */
6860 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6865 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6866 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6867 represent the same location. */
6870 breakpoint_locations_match (struct bp_location *loc1,
6871 struct bp_location *loc2)
6873 int hw_point1, hw_point2;
6875 /* Both of them must not be in moribund_locations. */
6876 gdb_assert (loc1->owner != NULL);
6877 gdb_assert (loc2->owner != NULL);
6879 hw_point1 = is_hardware_watchpoint (loc1->owner);
6880 hw_point2 = is_hardware_watchpoint (loc2->owner);
6882 if (hw_point1 != hw_point2)
6885 return watchpoint_locations_match (loc1, loc2);
6886 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6887 return tracepoint_locations_match (loc1, loc2);
6889 /* We compare bp_location.length in order to cover ranged breakpoints. */
6890 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6891 loc2->pspace->aspace, loc2->address)
6892 && loc1->length == loc2->length);
6896 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6897 int bnum, int have_bnum)
6899 /* The longest string possibly returned by hex_string_custom
6900 is 50 chars. These must be at least that big for safety. */
6904 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6905 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6907 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6908 bnum, astr1, astr2);
6910 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6913 /* Adjust a breakpoint's address to account for architectural
6914 constraints on breakpoint placement. Return the adjusted address.
6915 Note: Very few targets require this kind of adjustment. For most
6916 targets, this function is simply the identity function. */
6919 adjust_breakpoint_address (struct gdbarch *gdbarch,
6920 CORE_ADDR bpaddr, enum bptype bptype)
6922 if (bptype == bp_watchpoint
6923 || bptype == bp_hardware_watchpoint
6924 || bptype == bp_read_watchpoint
6925 || bptype == bp_access_watchpoint
6926 || bptype == bp_catchpoint)
6928 /* Watchpoints and the various bp_catch_* eventpoints should not
6929 have their addresses modified. */
6932 else if (bptype == bp_single_step)
6934 /* Single-step breakpoints should not have their addresses
6935 modified. If there's any architectural constrain that
6936 applies to this address, then it should have already been
6937 taken into account when the breakpoint was created in the
6938 first place. If we didn't do this, stepping through e.g.,
6939 Thumb-2 IT blocks would break. */
6944 CORE_ADDR adjusted_bpaddr = bpaddr;
6946 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
6948 /* Some targets have architectural constraints on the placement
6949 of breakpoint instructions. Obtain the adjusted address. */
6950 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6953 adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
6955 /* An adjusted breakpoint address can significantly alter
6956 a user's expectations. Print a warning if an adjustment
6958 if (adjusted_bpaddr != bpaddr)
6959 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6961 return adjusted_bpaddr;
6965 bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner)
6967 bp_location *loc = this;
6969 gdb_assert (ops != NULL);
6973 loc->cond_bytecode = NULL;
6974 loc->shlib_disabled = 0;
6977 switch (owner->type)
6980 case bp_single_step:
6984 case bp_longjmp_resume:
6985 case bp_longjmp_call_dummy:
6987 case bp_exception_resume:
6988 case bp_step_resume:
6989 case bp_hp_step_resume:
6990 case bp_watchpoint_scope:
6992 case bp_std_terminate:
6993 case bp_shlib_event:
6994 case bp_thread_event:
6995 case bp_overlay_event:
6997 case bp_longjmp_master:
6998 case bp_std_terminate_master:
6999 case bp_exception_master:
7000 case bp_gnu_ifunc_resolver:
7001 case bp_gnu_ifunc_resolver_return:
7003 loc->loc_type = bp_loc_software_breakpoint;
7004 mark_breakpoint_location_modified (loc);
7006 case bp_hardware_breakpoint:
7007 loc->loc_type = bp_loc_hardware_breakpoint;
7008 mark_breakpoint_location_modified (loc);
7010 case bp_hardware_watchpoint:
7011 case bp_read_watchpoint:
7012 case bp_access_watchpoint:
7013 loc->loc_type = bp_loc_hardware_watchpoint;
7018 case bp_fast_tracepoint:
7019 case bp_static_tracepoint:
7020 loc->loc_type = bp_loc_other;
7023 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7029 /* Allocate a struct bp_location. */
7031 static struct bp_location *
7032 allocate_bp_location (struct breakpoint *bpt)
7034 return bpt->ops->allocate_location (bpt);
7038 free_bp_location (struct bp_location *loc)
7040 loc->ops->dtor (loc);
7044 /* Increment reference count. */
7047 incref_bp_location (struct bp_location *bl)
7052 /* Decrement reference count. If the reference count reaches 0,
7053 destroy the bp_location. Sets *BLP to NULL. */
7056 decref_bp_location (struct bp_location **blp)
7058 gdb_assert ((*blp)->refc > 0);
7060 if (--(*blp)->refc == 0)
7061 free_bp_location (*blp);
7065 /* Add breakpoint B at the end of the global breakpoint chain. */
7068 add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
7070 struct breakpoint *b1;
7071 struct breakpoint *result = b.get ();
7073 /* Add this breakpoint to the end of the chain so that a list of
7074 breakpoints will come out in order of increasing numbers. */
7076 b1 = breakpoint_chain;
7078 breakpoint_chain = b.release ();
7083 b1->next = b.release ();
7089 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7092 init_raw_breakpoint_without_location (struct breakpoint *b,
7093 struct gdbarch *gdbarch,
7095 const struct breakpoint_ops *ops)
7097 gdb_assert (ops != NULL);
7101 b->gdbarch = gdbarch;
7102 b->language = current_language->la_language;
7103 b->input_radix = input_radix;
7104 b->related_breakpoint = b;
7107 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7108 that has type BPTYPE and has no locations as yet. */
7110 static struct breakpoint *
7111 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7113 const struct breakpoint_ops *ops)
7115 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7117 init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops);
7118 return add_to_breakpoint_chain (std::move (b));
7121 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7122 resolutions should be made as the user specified the location explicitly
7126 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7128 gdb_assert (loc->owner != NULL);
7130 if (loc->owner->type == bp_breakpoint
7131 || loc->owner->type == bp_hardware_breakpoint
7132 || is_tracepoint (loc->owner))
7134 const char *function_name;
7136 if (loc->msymbol != NULL
7137 && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc
7138 || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)
7141 struct breakpoint *b = loc->owner;
7143 function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol);
7145 if (b->type == bp_breakpoint && b->loc == loc
7146 && loc->next == NULL && b->related_breakpoint == b)
7148 /* Create only the whole new breakpoint of this type but do not
7149 mess more complicated breakpoints with multiple locations. */
7150 b->type = bp_gnu_ifunc_resolver;
7151 /* Remember the resolver's address for use by the return
7153 loc->related_address = loc->address;
7157 find_pc_partial_function (loc->address, &function_name, NULL, NULL);
7160 loc->function_name = xstrdup (function_name);
7164 /* Attempt to determine architecture of location identified by SAL. */
7166 get_sal_arch (struct symtab_and_line sal)
7169 return get_objfile_arch (sal.section->objfile);
7171 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7176 /* Low level routine for partially initializing a breakpoint of type
7177 BPTYPE. The newly created breakpoint's address, section, source
7178 file name, and line number are provided by SAL.
7180 It is expected that the caller will complete the initialization of
7181 the newly created breakpoint struct as well as output any status
7182 information regarding the creation of a new breakpoint. */
7185 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7186 struct symtab_and_line sal, enum bptype bptype,
7187 const struct breakpoint_ops *ops)
7189 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7191 add_location_to_breakpoint (b, &sal);
7193 if (bptype != bp_catchpoint)
7194 gdb_assert (sal.pspace != NULL);
7196 /* Store the program space that was used to set the breakpoint,
7197 except for ordinary breakpoints, which are independent of the
7199 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7200 b->pspace = sal.pspace;
7203 /* set_raw_breakpoint is a low level routine for allocating and
7204 partially initializing a breakpoint of type BPTYPE. The newly
7205 created breakpoint's address, section, source file name, and line
7206 number are provided by SAL. The newly created and partially
7207 initialized breakpoint is added to the breakpoint chain and
7208 is also returned as the value of this function.
7210 It is expected that the caller will complete the initialization of
7211 the newly created breakpoint struct as well as output any status
7212 information regarding the creation of a new breakpoint. In
7213 particular, set_raw_breakpoint does NOT set the breakpoint
7214 number! Care should be taken to not allow an error to occur
7215 prior to completing the initialization of the breakpoint. If this
7216 should happen, a bogus breakpoint will be left on the chain. */
7219 set_raw_breakpoint (struct gdbarch *gdbarch,
7220 struct symtab_and_line sal, enum bptype bptype,
7221 const struct breakpoint_ops *ops)
7223 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7225 init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops);
7226 return add_to_breakpoint_chain (std::move (b));
7229 /* Call this routine when stepping and nexting to enable a breakpoint
7230 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7231 initiated the operation. */
7234 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7236 struct breakpoint *b, *b_tmp;
7237 int thread = tp->global_num;
7239 /* To avoid having to rescan all objfile symbols at every step,
7240 we maintain a list of continually-inserted but always disabled
7241 longjmp "master" breakpoints. Here, we simply create momentary
7242 clones of those and enable them for the requested thread. */
7243 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7244 if (b->pspace == current_program_space
7245 && (b->type == bp_longjmp_master
7246 || b->type == bp_exception_master))
7248 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7249 struct breakpoint *clone;
7251 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7252 after their removal. */
7253 clone = momentary_breakpoint_from_master (b, type,
7254 &momentary_breakpoint_ops, 1);
7255 clone->thread = thread;
7258 tp->initiating_frame = frame;
7261 /* Delete all longjmp breakpoints from THREAD. */
7263 delete_longjmp_breakpoint (int thread)
7265 struct breakpoint *b, *b_tmp;
7267 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7268 if (b->type == bp_longjmp || b->type == bp_exception)
7270 if (b->thread == thread)
7271 delete_breakpoint (b);
7276 delete_longjmp_breakpoint_at_next_stop (int thread)
7278 struct breakpoint *b, *b_tmp;
7280 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7281 if (b->type == bp_longjmp || b->type == bp_exception)
7283 if (b->thread == thread)
7284 b->disposition = disp_del_at_next_stop;
7288 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7289 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7290 pointer to any of them. Return NULL if this system cannot place longjmp
7294 set_longjmp_breakpoint_for_call_dummy (void)
7296 struct breakpoint *b, *retval = NULL;
7299 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7301 struct breakpoint *new_b;
7303 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7304 &momentary_breakpoint_ops,
7306 new_b->thread = inferior_thread ()->global_num;
7308 /* Link NEW_B into the chain of RETVAL breakpoints. */
7310 gdb_assert (new_b->related_breakpoint == new_b);
7313 new_b->related_breakpoint = retval;
7314 while (retval->related_breakpoint != new_b->related_breakpoint)
7315 retval = retval->related_breakpoint;
7316 retval->related_breakpoint = new_b;
7322 /* Verify all existing dummy frames and their associated breakpoints for
7323 TP. Remove those which can no longer be found in the current frame
7326 You should call this function only at places where it is safe to currently
7327 unwind the whole stack. Failed stack unwind would discard live dummy
7331 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7333 struct breakpoint *b, *b_tmp;
7335 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7336 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7338 struct breakpoint *dummy_b = b->related_breakpoint;
7340 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7341 dummy_b = dummy_b->related_breakpoint;
7342 if (dummy_b->type != bp_call_dummy
7343 || frame_find_by_id (dummy_b->frame_id) != NULL)
7346 dummy_frame_discard (dummy_b->frame_id, tp);
7348 while (b->related_breakpoint != b)
7350 if (b_tmp == b->related_breakpoint)
7351 b_tmp = b->related_breakpoint->next;
7352 delete_breakpoint (b->related_breakpoint);
7354 delete_breakpoint (b);
7359 enable_overlay_breakpoints (void)
7361 struct breakpoint *b;
7364 if (b->type == bp_overlay_event)
7366 b->enable_state = bp_enabled;
7367 update_global_location_list (UGLL_MAY_INSERT);
7368 overlay_events_enabled = 1;
7373 disable_overlay_breakpoints (void)
7375 struct breakpoint *b;
7378 if (b->type == bp_overlay_event)
7380 b->enable_state = bp_disabled;
7381 update_global_location_list (UGLL_DONT_INSERT);
7382 overlay_events_enabled = 0;
7386 /* Set an active std::terminate breakpoint for each std::terminate
7387 master breakpoint. */
7389 set_std_terminate_breakpoint (void)
7391 struct breakpoint *b, *b_tmp;
7393 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7394 if (b->pspace == current_program_space
7395 && b->type == bp_std_terminate_master)
7397 momentary_breakpoint_from_master (b, bp_std_terminate,
7398 &momentary_breakpoint_ops, 1);
7402 /* Delete all the std::terminate breakpoints. */
7404 delete_std_terminate_breakpoint (void)
7406 struct breakpoint *b, *b_tmp;
7408 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7409 if (b->type == bp_std_terminate)
7410 delete_breakpoint (b);
7414 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7416 struct breakpoint *b;
7418 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7419 &internal_breakpoint_ops);
7421 b->enable_state = bp_enabled;
7422 /* location has to be used or breakpoint_re_set will delete me. */
7423 b->location = new_address_location (b->loc->address, NULL, 0);
7425 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7430 struct lang_and_radix
7436 /* Create a breakpoint for JIT code registration and unregistration. */
7439 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7441 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7442 &internal_breakpoint_ops);
7445 /* Remove JIT code registration and unregistration breakpoint(s). */
7448 remove_jit_event_breakpoints (void)
7450 struct breakpoint *b, *b_tmp;
7452 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7453 if (b->type == bp_jit_event
7454 && b->loc->pspace == current_program_space)
7455 delete_breakpoint (b);
7459 remove_solib_event_breakpoints (void)
7461 struct breakpoint *b, *b_tmp;
7463 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7464 if (b->type == bp_shlib_event
7465 && b->loc->pspace == current_program_space)
7466 delete_breakpoint (b);
7469 /* See breakpoint.h. */
7472 remove_solib_event_breakpoints_at_next_stop (void)
7474 struct breakpoint *b, *b_tmp;
7476 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7477 if (b->type == bp_shlib_event
7478 && b->loc->pspace == current_program_space)
7479 b->disposition = disp_del_at_next_stop;
7482 /* Helper for create_solib_event_breakpoint /
7483 create_and_insert_solib_event_breakpoint. Allows specifying which
7484 INSERT_MODE to pass through to update_global_location_list. */
7486 static struct breakpoint *
7487 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7488 enum ugll_insert_mode insert_mode)
7490 struct breakpoint *b;
7492 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7493 &internal_breakpoint_ops);
7494 update_global_location_list_nothrow (insert_mode);
7499 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7501 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7504 /* See breakpoint.h. */
7507 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7509 struct breakpoint *b;
7511 /* Explicitly tell update_global_location_list to insert
7513 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7514 if (!b->loc->inserted)
7516 delete_breakpoint (b);
7522 /* Disable any breakpoints that are on code in shared libraries. Only
7523 apply to enabled breakpoints, disabled ones can just stay disabled. */
7526 disable_breakpoints_in_shlibs (void)
7528 struct bp_location *loc, **locp_tmp;
7530 ALL_BP_LOCATIONS (loc, locp_tmp)
7532 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7533 struct breakpoint *b = loc->owner;
7535 /* We apply the check to all breakpoints, including disabled for
7536 those with loc->duplicate set. This is so that when breakpoint
7537 becomes enabled, or the duplicate is removed, gdb will try to
7538 insert all breakpoints. If we don't set shlib_disabled here,
7539 we'll try to insert those breakpoints and fail. */
7540 if (((b->type == bp_breakpoint)
7541 || (b->type == bp_jit_event)
7542 || (b->type == bp_hardware_breakpoint)
7543 || (is_tracepoint (b)))
7544 && loc->pspace == current_program_space
7545 && !loc->shlib_disabled
7546 && solib_name_from_address (loc->pspace, loc->address)
7549 loc->shlib_disabled = 1;
7554 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7555 notification of unloaded_shlib. Only apply to enabled breakpoints,
7556 disabled ones can just stay disabled. */
7559 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7561 struct bp_location *loc, **locp_tmp;
7562 int disabled_shlib_breaks = 0;
7564 ALL_BP_LOCATIONS (loc, locp_tmp)
7566 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7567 struct breakpoint *b = loc->owner;
7569 if (solib->pspace == loc->pspace
7570 && !loc->shlib_disabled
7571 && (((b->type == bp_breakpoint
7572 || b->type == bp_jit_event
7573 || b->type == bp_hardware_breakpoint)
7574 && (loc->loc_type == bp_loc_hardware_breakpoint
7575 || loc->loc_type == bp_loc_software_breakpoint))
7576 || is_tracepoint (b))
7577 && solib_contains_address_p (solib, loc->address))
7579 loc->shlib_disabled = 1;
7580 /* At this point, we cannot rely on remove_breakpoint
7581 succeeding so we must mark the breakpoint as not inserted
7582 to prevent future errors occurring in remove_breakpoints. */
7585 /* This may cause duplicate notifications for the same breakpoint. */
7586 gdb::observers::breakpoint_modified.notify (b);
7588 if (!disabled_shlib_breaks)
7590 target_terminal::ours_for_output ();
7591 warning (_("Temporarily disabling breakpoints "
7592 "for unloaded shared library \"%s\""),
7595 disabled_shlib_breaks = 1;
7600 /* Disable any breakpoints and tracepoints in OBJFILE upon
7601 notification of free_objfile. Only apply to enabled breakpoints,
7602 disabled ones can just stay disabled. */
7605 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7607 struct breakpoint *b;
7609 if (objfile == NULL)
7612 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7613 managed by the user with add-symbol-file/remove-symbol-file.
7614 Similarly to how breakpoints in shared libraries are handled in
7615 response to "nosharedlibrary", mark breakpoints in such modules
7616 shlib_disabled so they end up uninserted on the next global
7617 location list update. Shared libraries not loaded by the user
7618 aren't handled here -- they're already handled in
7619 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7620 solib_unloaded observer. We skip objfiles that are not
7621 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7623 if ((objfile->flags & OBJF_SHARED) == 0
7624 || (objfile->flags & OBJF_USERLOADED) == 0)
7629 struct bp_location *loc;
7630 int bp_modified = 0;
7632 if (!is_breakpoint (b) && !is_tracepoint (b))
7635 for (loc = b->loc; loc != NULL; loc = loc->next)
7637 CORE_ADDR loc_addr = loc->address;
7639 if (loc->loc_type != bp_loc_hardware_breakpoint
7640 && loc->loc_type != bp_loc_software_breakpoint)
7643 if (loc->shlib_disabled != 0)
7646 if (objfile->pspace != loc->pspace)
7649 if (loc->loc_type != bp_loc_hardware_breakpoint
7650 && loc->loc_type != bp_loc_software_breakpoint)
7653 if (is_addr_in_objfile (loc_addr, objfile))
7655 loc->shlib_disabled = 1;
7656 /* At this point, we don't know whether the object was
7657 unmapped from the inferior or not, so leave the
7658 inserted flag alone. We'll handle failure to
7659 uninsert quietly, in case the object was indeed
7662 mark_breakpoint_location_modified (loc);
7669 gdb::observers::breakpoint_modified.notify (b);
7673 /* FORK & VFORK catchpoints. */
7675 /* An instance of this type is used to represent a fork or vfork
7676 catchpoint. A breakpoint is really of this type iff its ops pointer points
7677 to CATCH_FORK_BREAKPOINT_OPS. */
7679 struct fork_catchpoint : public breakpoint
7681 /* Process id of a child process whose forking triggered this
7682 catchpoint. This field is only valid immediately after this
7683 catchpoint has triggered. */
7684 ptid_t forked_inferior_pid;
7687 /* Implement the "insert" breakpoint_ops method for fork
7691 insert_catch_fork (struct bp_location *bl)
7693 return target_insert_fork_catchpoint (inferior_ptid.pid ());
7696 /* Implement the "remove" breakpoint_ops method for fork
7700 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
7702 return target_remove_fork_catchpoint (inferior_ptid.pid ());
7705 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7709 breakpoint_hit_catch_fork (const struct bp_location *bl,
7710 const address_space *aspace, CORE_ADDR bp_addr,
7711 const struct target_waitstatus *ws)
7713 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7715 if (ws->kind != TARGET_WAITKIND_FORKED)
7718 c->forked_inferior_pid = ws->value.related_pid;
7722 /* Implement the "print_it" breakpoint_ops method for fork
7725 static enum print_stop_action
7726 print_it_catch_fork (bpstat bs)
7728 struct ui_out *uiout = current_uiout;
7729 struct breakpoint *b = bs->breakpoint_at;
7730 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7732 annotate_catchpoint (b->number);
7733 maybe_print_thread_hit_breakpoint (uiout);
7734 if (b->disposition == disp_del)
7735 uiout->text ("Temporary catchpoint ");
7737 uiout->text ("Catchpoint ");
7738 if (uiout->is_mi_like_p ())
7740 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK));
7741 uiout->field_string ("disp", bpdisp_text (b->disposition));
7743 uiout->field_int ("bkptno", b->number);
7744 uiout->text (" (forked process ");
7745 uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
7746 uiout->text ("), ");
7747 return PRINT_SRC_AND_LOC;
7750 /* Implement the "print_one" breakpoint_ops method for fork
7754 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7756 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7757 struct value_print_options opts;
7758 struct ui_out *uiout = current_uiout;
7760 get_user_print_options (&opts);
7762 /* Field 4, the address, is omitted (which makes the columns not
7763 line up too nicely with the headers, but the effect is relatively
7765 if (opts.addressprint)
7766 uiout->field_skip ("addr");
7768 uiout->text ("fork");
7769 if (c->forked_inferior_pid != null_ptid)
7771 uiout->text (", process ");
7772 uiout->field_int ("what", c->forked_inferior_pid.pid ());
7776 if (uiout->is_mi_like_p ())
7777 uiout->field_string ("catch-type", "fork");
7780 /* Implement the "print_mention" breakpoint_ops method for fork
7784 print_mention_catch_fork (struct breakpoint *b)
7786 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7789 /* Implement the "print_recreate" breakpoint_ops method for fork
7793 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7795 fprintf_unfiltered (fp, "catch fork");
7796 print_recreate_thread (b, fp);
7799 /* The breakpoint_ops structure to be used in fork catchpoints. */
7801 static struct breakpoint_ops catch_fork_breakpoint_ops;
7803 /* Implement the "insert" breakpoint_ops method for vfork
7807 insert_catch_vfork (struct bp_location *bl)
7809 return target_insert_vfork_catchpoint (inferior_ptid.pid ());
7812 /* Implement the "remove" breakpoint_ops method for vfork
7816 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
7818 return target_remove_vfork_catchpoint (inferior_ptid.pid ());
7821 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7825 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7826 const address_space *aspace, CORE_ADDR bp_addr,
7827 const struct target_waitstatus *ws)
7829 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7831 if (ws->kind != TARGET_WAITKIND_VFORKED)
7834 c->forked_inferior_pid = ws->value.related_pid;
7838 /* Implement the "print_it" breakpoint_ops method for vfork
7841 static enum print_stop_action
7842 print_it_catch_vfork (bpstat bs)
7844 struct ui_out *uiout = current_uiout;
7845 struct breakpoint *b = bs->breakpoint_at;
7846 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7848 annotate_catchpoint (b->number);
7849 maybe_print_thread_hit_breakpoint (uiout);
7850 if (b->disposition == disp_del)
7851 uiout->text ("Temporary catchpoint ");
7853 uiout->text ("Catchpoint ");
7854 if (uiout->is_mi_like_p ())
7856 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK));
7857 uiout->field_string ("disp", bpdisp_text (b->disposition));
7859 uiout->field_int ("bkptno", b->number);
7860 uiout->text (" (vforked process ");
7861 uiout->field_int ("newpid", c->forked_inferior_pid.pid ());
7862 uiout->text ("), ");
7863 return PRINT_SRC_AND_LOC;
7866 /* Implement the "print_one" breakpoint_ops method for vfork
7870 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7872 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7873 struct value_print_options opts;
7874 struct ui_out *uiout = current_uiout;
7876 get_user_print_options (&opts);
7877 /* Field 4, the address, is omitted (which makes the columns not
7878 line up too nicely with the headers, but the effect is relatively
7880 if (opts.addressprint)
7881 uiout->field_skip ("addr");
7883 uiout->text ("vfork");
7884 if (c->forked_inferior_pid != null_ptid)
7886 uiout->text (", process ");
7887 uiout->field_int ("what", c->forked_inferior_pid.pid ());
7891 if (uiout->is_mi_like_p ())
7892 uiout->field_string ("catch-type", "vfork");
7895 /* Implement the "print_mention" breakpoint_ops method for vfork
7899 print_mention_catch_vfork (struct breakpoint *b)
7901 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7904 /* Implement the "print_recreate" breakpoint_ops method for vfork
7908 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7910 fprintf_unfiltered (fp, "catch vfork");
7911 print_recreate_thread (b, fp);
7914 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7916 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7918 /* An instance of this type is used to represent an solib catchpoint.
7919 A breakpoint is really of this type iff its ops pointer points to
7920 CATCH_SOLIB_BREAKPOINT_OPS. */
7922 struct solib_catchpoint : public breakpoint
7924 ~solib_catchpoint () override;
7926 /* True for "catch load", false for "catch unload". */
7927 unsigned char is_load;
7929 /* Regular expression to match, if any. COMPILED is only valid when
7930 REGEX is non-NULL. */
7932 std::unique_ptr<compiled_regex> compiled;
7935 solib_catchpoint::~solib_catchpoint ()
7937 xfree (this->regex);
7941 insert_catch_solib (struct bp_location *ignore)
7947 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
7953 breakpoint_hit_catch_solib (const struct bp_location *bl,
7954 const address_space *aspace,
7956 const struct target_waitstatus *ws)
7958 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7959 struct breakpoint *other;
7961 if (ws->kind == TARGET_WAITKIND_LOADED)
7964 ALL_BREAKPOINTS (other)
7966 struct bp_location *other_bl;
7968 if (other == bl->owner)
7971 if (other->type != bp_shlib_event)
7974 if (self->pspace != NULL && other->pspace != self->pspace)
7977 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7979 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7988 check_status_catch_solib (struct bpstats *bs)
7990 struct solib_catchpoint *self
7991 = (struct solib_catchpoint *) bs->breakpoint_at;
7995 for (so_list *iter : current_program_space->added_solibs)
7998 || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
8004 for (const std::string &iter : current_program_space->deleted_solibs)
8007 || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0)
8013 bs->print_it = print_it_noop;
8016 static enum print_stop_action
8017 print_it_catch_solib (bpstat bs)
8019 struct breakpoint *b = bs->breakpoint_at;
8020 struct ui_out *uiout = current_uiout;
8022 annotate_catchpoint (b->number);
8023 maybe_print_thread_hit_breakpoint (uiout);
8024 if (b->disposition == disp_del)
8025 uiout->text ("Temporary catchpoint ");
8027 uiout->text ("Catchpoint ");
8028 uiout->field_int ("bkptno", b->number);
8030 if (uiout->is_mi_like_p ())
8031 uiout->field_string ("disp", bpdisp_text (b->disposition));
8032 print_solib_event (1);
8033 return PRINT_SRC_AND_LOC;
8037 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8039 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8040 struct value_print_options opts;
8041 struct ui_out *uiout = current_uiout;
8043 get_user_print_options (&opts);
8044 /* Field 4, the address, is omitted (which makes the columns not
8045 line up too nicely with the headers, but the effect is relatively
8047 if (opts.addressprint)
8050 uiout->field_skip ("addr");
8058 msg = string_printf (_("load of library matching %s"), self->regex);
8060 msg = _("load of library");
8065 msg = string_printf (_("unload of library matching %s"), self->regex);
8067 msg = _("unload of library");
8069 uiout->field_string ("what", msg);
8071 if (uiout->is_mi_like_p ())
8072 uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
8076 print_mention_catch_solib (struct breakpoint *b)
8078 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8080 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8081 self->is_load ? "load" : "unload");
8085 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8087 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8089 fprintf_unfiltered (fp, "%s %s",
8090 b->disposition == disp_del ? "tcatch" : "catch",
8091 self->is_load ? "load" : "unload");
8093 fprintf_unfiltered (fp, " %s", self->regex);
8094 fprintf_unfiltered (fp, "\n");
8097 static struct breakpoint_ops catch_solib_breakpoint_ops;
8099 /* Shared helper function (MI and CLI) for creating and installing
8100 a shared object event catchpoint. If IS_LOAD is non-zero then
8101 the events to be caught are load events, otherwise they are
8102 unload events. If IS_TEMP is non-zero the catchpoint is a
8103 temporary one. If ENABLED is non-zero the catchpoint is
8104 created in an enabled state. */
8107 add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
8109 struct gdbarch *gdbarch = get_current_arch ();
8113 arg = skip_spaces (arg);
8115 std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
8119 c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
8120 _("Invalid regexp")));
8121 c->regex = xstrdup (arg);
8124 c->is_load = is_load;
8125 init_catchpoint (c.get (), gdbarch, is_temp, NULL,
8126 &catch_solib_breakpoint_ops);
8128 c->enable_state = enabled ? bp_enabled : bp_disabled;
8130 install_breakpoint (0, std::move (c), 1);
8133 /* A helper function that does all the work for "catch load" and
8137 catch_load_or_unload (const char *arg, int from_tty, int is_load,
8138 struct cmd_list_element *command)
8141 const int enabled = 1;
8143 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8145 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8149 catch_load_command_1 (const char *arg, int from_tty,
8150 struct cmd_list_element *command)
8152 catch_load_or_unload (arg, from_tty, 1, command);
8156 catch_unload_command_1 (const char *arg, int from_tty,
8157 struct cmd_list_element *command)
8159 catch_load_or_unload (arg, from_tty, 0, command);
8162 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8163 is non-zero, then make the breakpoint temporary. If COND_STRING is
8164 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8165 the breakpoint_ops structure associated to the catchpoint. */
8168 init_catchpoint (struct breakpoint *b,
8169 struct gdbarch *gdbarch, int tempflag,
8170 const char *cond_string,
8171 const struct breakpoint_ops *ops)
8173 symtab_and_line sal;
8174 sal.pspace = current_program_space;
8176 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8178 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8179 b->disposition = tempflag ? disp_del : disp_donttouch;
8183 install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll)
8185 breakpoint *b = add_to_breakpoint_chain (std::move (arg));
8186 set_breakpoint_number (internal, b);
8187 if (is_tracepoint (b))
8188 set_tracepoint_count (breakpoint_count);
8191 gdb::observers::breakpoint_created.notify (b);
8194 update_global_location_list (UGLL_MAY_INSERT);
8198 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8199 int tempflag, const char *cond_string,
8200 const struct breakpoint_ops *ops)
8202 std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
8204 init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops);
8206 c->forked_inferior_pid = null_ptid;
8208 install_breakpoint (0, std::move (c), 1);
8211 /* Exec catchpoints. */
8213 /* An instance of this type is used to represent an exec catchpoint.
8214 A breakpoint is really of this type iff its ops pointer points to
8215 CATCH_EXEC_BREAKPOINT_OPS. */
8217 struct exec_catchpoint : public breakpoint
8219 ~exec_catchpoint () override;
8221 /* Filename of a program whose exec triggered this catchpoint.
8222 This field is only valid immediately after this catchpoint has
8224 char *exec_pathname;
8227 /* Exec catchpoint destructor. */
8229 exec_catchpoint::~exec_catchpoint ()
8231 xfree (this->exec_pathname);
8235 insert_catch_exec (struct bp_location *bl)
8237 return target_insert_exec_catchpoint (inferior_ptid.pid ());
8241 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8243 return target_remove_exec_catchpoint (inferior_ptid.pid ());
8247 breakpoint_hit_catch_exec (const struct bp_location *bl,
8248 const address_space *aspace, CORE_ADDR bp_addr,
8249 const struct target_waitstatus *ws)
8251 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8253 if (ws->kind != TARGET_WAITKIND_EXECD)
8256 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8260 static enum print_stop_action
8261 print_it_catch_exec (bpstat bs)
8263 struct ui_out *uiout = current_uiout;
8264 struct breakpoint *b = bs->breakpoint_at;
8265 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8267 annotate_catchpoint (b->number);
8268 maybe_print_thread_hit_breakpoint (uiout);
8269 if (b->disposition == disp_del)
8270 uiout->text ("Temporary catchpoint ");
8272 uiout->text ("Catchpoint ");
8273 if (uiout->is_mi_like_p ())
8275 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
8276 uiout->field_string ("disp", bpdisp_text (b->disposition));
8278 uiout->field_int ("bkptno", b->number);
8279 uiout->text (" (exec'd ");
8280 uiout->field_string ("new-exec", c->exec_pathname);
8281 uiout->text ("), ");
8283 return PRINT_SRC_AND_LOC;
8287 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8289 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8290 struct value_print_options opts;
8291 struct ui_out *uiout = current_uiout;
8293 get_user_print_options (&opts);
8295 /* Field 4, the address, is omitted (which makes the columns
8296 not line up too nicely with the headers, but the effect
8297 is relatively readable). */
8298 if (opts.addressprint)
8299 uiout->field_skip ("addr");
8301 uiout->text ("exec");
8302 if (c->exec_pathname != NULL)
8304 uiout->text (", program \"");
8305 uiout->field_string ("what", c->exec_pathname);
8306 uiout->text ("\" ");
8309 if (uiout->is_mi_like_p ())
8310 uiout->field_string ("catch-type", "exec");
8314 print_mention_catch_exec (struct breakpoint *b)
8316 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8319 /* Implement the "print_recreate" breakpoint_ops method for exec
8323 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8325 fprintf_unfiltered (fp, "catch exec");
8326 print_recreate_thread (b, fp);
8329 static struct breakpoint_ops catch_exec_breakpoint_ops;
8332 hw_breakpoint_used_count (void)
8335 struct breakpoint *b;
8336 struct bp_location *bl;
8340 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8341 for (bl = b->loc; bl; bl = bl->next)
8343 /* Special types of hardware breakpoints may use more than
8345 i += b->ops->resources_needed (bl);
8352 /* Returns the resources B would use if it were a hardware
8356 hw_watchpoint_use_count (struct breakpoint *b)
8359 struct bp_location *bl;
8361 if (!breakpoint_enabled (b))
8364 for (bl = b->loc; bl; bl = bl->next)
8366 /* Special types of hardware watchpoints may use more than
8368 i += b->ops->resources_needed (bl);
8374 /* Returns the sum the used resources of all hardware watchpoints of
8375 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8376 the sum of the used resources of all hardware watchpoints of other
8377 types _not_ TYPE. */
8380 hw_watchpoint_used_count_others (struct breakpoint *except,
8381 enum bptype type, int *other_type_used)
8384 struct breakpoint *b;
8386 *other_type_used = 0;
8391 if (!breakpoint_enabled (b))
8394 if (b->type == type)
8395 i += hw_watchpoint_use_count (b);
8396 else if (is_hardware_watchpoint (b))
8397 *other_type_used = 1;
8404 disable_watchpoints_before_interactive_call_start (void)
8406 struct breakpoint *b;
8410 if (is_watchpoint (b) && breakpoint_enabled (b))
8412 b->enable_state = bp_call_disabled;
8413 update_global_location_list (UGLL_DONT_INSERT);
8419 enable_watchpoints_after_interactive_call_stop (void)
8421 struct breakpoint *b;
8425 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8427 b->enable_state = bp_enabled;
8428 update_global_location_list (UGLL_MAY_INSERT);
8434 disable_breakpoints_before_startup (void)
8436 current_program_space->executing_startup = 1;
8437 update_global_location_list (UGLL_DONT_INSERT);
8441 enable_breakpoints_after_startup (void)
8443 current_program_space->executing_startup = 0;
8444 breakpoint_re_set ();
8447 /* Create a new single-step breakpoint for thread THREAD, with no
8450 static struct breakpoint *
8451 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8453 std::unique_ptr<breakpoint> b (new breakpoint ());
8455 init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
8456 &momentary_breakpoint_ops);
8458 b->disposition = disp_donttouch;
8459 b->frame_id = null_frame_id;
8462 gdb_assert (b->thread != 0);
8464 return add_to_breakpoint_chain (std::move (b));
8467 /* Set a momentary breakpoint of type TYPE at address specified by
8468 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8472 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8473 struct frame_id frame_id, enum bptype type)
8475 struct breakpoint *b;
8477 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8479 gdb_assert (!frame_id_artificial_p (frame_id));
8481 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8482 b->enable_state = bp_enabled;
8483 b->disposition = disp_donttouch;
8484 b->frame_id = frame_id;
8486 b->thread = inferior_thread ()->global_num;
8488 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8490 return breakpoint_up (b);
8493 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8494 The new breakpoint will have type TYPE, use OPS as its
8495 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8497 static struct breakpoint *
8498 momentary_breakpoint_from_master (struct breakpoint *orig,
8500 const struct breakpoint_ops *ops,
8503 struct breakpoint *copy;
8505 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8506 copy->loc = allocate_bp_location (copy);
8507 set_breakpoint_location_function (copy->loc, 1);
8509 copy->loc->gdbarch = orig->loc->gdbarch;
8510 copy->loc->requested_address = orig->loc->requested_address;
8511 copy->loc->address = orig->loc->address;
8512 copy->loc->section = orig->loc->section;
8513 copy->loc->pspace = orig->loc->pspace;
8514 copy->loc->probe = orig->loc->probe;
8515 copy->loc->line_number = orig->loc->line_number;
8516 copy->loc->symtab = orig->loc->symtab;
8517 copy->loc->enabled = loc_enabled;
8518 copy->frame_id = orig->frame_id;
8519 copy->thread = orig->thread;
8520 copy->pspace = orig->pspace;
8522 copy->enable_state = bp_enabled;
8523 copy->disposition = disp_donttouch;
8524 copy->number = internal_breakpoint_number--;
8526 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8530 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8534 clone_momentary_breakpoint (struct breakpoint *orig)
8536 /* If there's nothing to clone, then return nothing. */
8540 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8544 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8547 struct symtab_and_line sal;
8549 sal = find_pc_line (pc, 0);
8551 sal.section = find_pc_overlay (pc);
8552 sal.explicit_pc = 1;
8554 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8558 /* Tell the user we have just set a breakpoint B. */
8561 mention (struct breakpoint *b)
8563 b->ops->print_mention (b);
8564 current_uiout->text ("\n");
8568 static int bp_loc_is_permanent (struct bp_location *loc);
8570 static struct bp_location *
8571 add_location_to_breakpoint (struct breakpoint *b,
8572 const struct symtab_and_line *sal)
8574 struct bp_location *loc, **tmp;
8575 CORE_ADDR adjusted_address;
8576 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8578 if (loc_gdbarch == NULL)
8579 loc_gdbarch = b->gdbarch;
8581 /* Adjust the breakpoint's address prior to allocating a location.
8582 Once we call allocate_bp_location(), that mostly uninitialized
8583 location will be placed on the location chain. Adjustment of the
8584 breakpoint may cause target_read_memory() to be called and we do
8585 not want its scan of the location chain to find a breakpoint and
8586 location that's only been partially initialized. */
8587 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8590 /* Sort the locations by their ADDRESS. */
8591 loc = allocate_bp_location (b);
8592 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8593 tmp = &((*tmp)->next))
8598 loc->requested_address = sal->pc;
8599 loc->address = adjusted_address;
8600 loc->pspace = sal->pspace;
8601 loc->probe.prob = sal->prob;
8602 loc->probe.objfile = sal->objfile;
8603 gdb_assert (loc->pspace != NULL);
8604 loc->section = sal->section;
8605 loc->gdbarch = loc_gdbarch;
8606 loc->line_number = sal->line;
8607 loc->symtab = sal->symtab;
8608 loc->symbol = sal->symbol;
8609 loc->msymbol = sal->msymbol;
8610 loc->objfile = sal->objfile;
8612 set_breakpoint_location_function (loc,
8613 sal->explicit_pc || sal->explicit_line);
8615 /* While by definition, permanent breakpoints are already present in the
8616 code, we don't mark the location as inserted. Normally one would expect
8617 that GDB could rely on that breakpoint instruction to stop the program,
8618 thus removing the need to insert its own breakpoint, except that executing
8619 the breakpoint instruction can kill the target instead of reporting a
8620 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8621 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8622 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8623 breakpoint be inserted normally results in QEMU knowing about the GDB
8624 breakpoint, and thus trap before the breakpoint instruction is executed.
8625 (If GDB later needs to continue execution past the permanent breakpoint,
8626 it manually increments the PC, thus avoiding executing the breakpoint
8628 if (bp_loc_is_permanent (loc))
8635 /* See breakpoint.h. */
8638 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
8642 const gdb_byte *bpoint;
8643 gdb_byte *target_mem;
8646 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
8648 /* Software breakpoints unsupported? */
8652 target_mem = (gdb_byte *) alloca (len);
8654 /* Enable the automatic memory restoration from breakpoints while
8655 we read the memory. Otherwise we could say about our temporary
8656 breakpoints they are permanent. */
8657 scoped_restore restore_memory
8658 = make_scoped_restore_show_memory_breakpoints (0);
8660 if (target_read_memory (address, target_mem, len) == 0
8661 && memcmp (target_mem, bpoint, len) == 0)
8667 /* Return 1 if LOC is pointing to a permanent breakpoint,
8668 return 0 otherwise. */
8671 bp_loc_is_permanent (struct bp_location *loc)
8673 gdb_assert (loc != NULL);
8675 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8676 attempt to read from the addresses the locations of these breakpoint types
8677 point to. program_breakpoint_here_p, below, will attempt to read
8679 if (!breakpoint_address_is_meaningful (loc->owner))
8682 scoped_restore_current_pspace_and_thread restore_pspace_thread;
8683 switch_to_program_space_and_thread (loc->pspace);
8684 return program_breakpoint_here_p (loc->gdbarch, loc->address);
8687 /* Build a command list for the dprintf corresponding to the current
8688 settings of the dprintf style options. */
8691 update_dprintf_command_list (struct breakpoint *b)
8693 char *dprintf_args = b->extra_string;
8694 char *printf_line = NULL;
8699 dprintf_args = skip_spaces (dprintf_args);
8701 /* Allow a comma, as it may have terminated a location, but don't
8703 if (*dprintf_args == ',')
8705 dprintf_args = skip_spaces (dprintf_args);
8707 if (*dprintf_args != '"')
8708 error (_("Bad format string, missing '\"'."));
8710 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8711 printf_line = xstrprintf ("printf %s", dprintf_args);
8712 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8714 if (!dprintf_function)
8715 error (_("No function supplied for dprintf call"));
8717 if (dprintf_channel && strlen (dprintf_channel) > 0)
8718 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8723 printf_line = xstrprintf ("call (void) %s (%s)",
8727 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8729 if (target_can_run_breakpoint_commands ())
8730 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8733 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8734 printf_line = xstrprintf ("printf %s", dprintf_args);
8738 internal_error (__FILE__, __LINE__,
8739 _("Invalid dprintf style."));
8741 gdb_assert (printf_line != NULL);
8743 /* Manufacture a printf sequence. */
8744 struct command_line *printf_cmd_line
8745 = new struct command_line (simple_control, printf_line);
8746 breakpoint_set_commands (b, counted_command_line (printf_cmd_line,
8747 command_lines_deleter ()));
8750 /* Update all dprintf commands, making their command lists reflect
8751 current style settings. */
8754 update_dprintf_commands (const char *args, int from_tty,
8755 struct cmd_list_element *c)
8757 struct breakpoint *b;
8761 if (b->type == bp_dprintf)
8762 update_dprintf_command_list (b);
8766 /* Create a breakpoint with SAL as location. Use LOCATION
8767 as a description of the location, and COND_STRING
8768 as condition expression. If LOCATION is NULL then create an
8769 "address location" from the address in the SAL. */
8772 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8773 gdb::array_view<const symtab_and_line> sals,
8774 event_location_up &&location,
8775 gdb::unique_xmalloc_ptr<char> filter,
8776 gdb::unique_xmalloc_ptr<char> cond_string,
8777 gdb::unique_xmalloc_ptr<char> extra_string,
8778 enum bptype type, enum bpdisp disposition,
8779 int thread, int task, int ignore_count,
8780 const struct breakpoint_ops *ops, int from_tty,
8781 int enabled, int internal, unsigned flags,
8782 int display_canonical)
8786 if (type == bp_hardware_breakpoint)
8788 int target_resources_ok;
8790 i = hw_breakpoint_used_count ();
8791 target_resources_ok =
8792 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8794 if (target_resources_ok == 0)
8795 error (_("No hardware breakpoint support in the target."));
8796 else if (target_resources_ok < 0)
8797 error (_("Hardware breakpoints used exceeds limit."));
8800 gdb_assert (!sals.empty ());
8802 for (const auto &sal : sals)
8804 struct bp_location *loc;
8808 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8810 loc_gdbarch = gdbarch;
8812 describe_other_breakpoints (loc_gdbarch,
8813 sal.pspace, sal.pc, sal.section, thread);
8816 if (&sal == &sals[0])
8818 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8822 b->cond_string = cond_string.release ();
8823 b->extra_string = extra_string.release ();
8824 b->ignore_count = ignore_count;
8825 b->enable_state = enabled ? bp_enabled : bp_disabled;
8826 b->disposition = disposition;
8828 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8829 b->loc->inserted = 1;
8831 if (type == bp_static_tracepoint)
8833 struct tracepoint *t = (struct tracepoint *) b;
8834 struct static_tracepoint_marker marker;
8836 if (strace_marker_p (b))
8838 /* We already know the marker exists, otherwise, we
8839 wouldn't see a sal for it. */
8841 = &event_location_to_string (b->location.get ())[3];
8844 p = skip_spaces (p);
8846 endp = skip_to_space (p);
8848 t->static_trace_marker_id.assign (p, endp - p);
8850 printf_filtered (_("Probed static tracepoint "
8852 t->static_trace_marker_id.c_str ());
8854 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8856 t->static_trace_marker_id = std::move (marker.str_id);
8858 printf_filtered (_("Probed static tracepoint "
8860 t->static_trace_marker_id.c_str ());
8863 warning (_("Couldn't determine the static "
8864 "tracepoint marker to probe"));
8871 loc = add_location_to_breakpoint (b, &sal);
8872 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8878 const char *arg = b->cond_string;
8880 loc->cond = parse_exp_1 (&arg, loc->address,
8881 block_for_pc (loc->address), 0);
8883 error (_("Garbage '%s' follows condition"), arg);
8886 /* Dynamic printf requires and uses additional arguments on the
8887 command line, otherwise it's an error. */
8888 if (type == bp_dprintf)
8890 if (b->extra_string)
8891 update_dprintf_command_list (b);
8893 error (_("Format string required"));
8895 else if (b->extra_string)
8896 error (_("Garbage '%s' at end of command"), b->extra_string);
8899 b->display_canonical = display_canonical;
8900 if (location != NULL)
8901 b->location = std::move (location);
8903 b->location = new_address_location (b->loc->address, NULL, 0);
8904 b->filter = filter.release ();
8908 create_breakpoint_sal (struct gdbarch *gdbarch,
8909 gdb::array_view<const symtab_and_line> sals,
8910 event_location_up &&location,
8911 gdb::unique_xmalloc_ptr<char> filter,
8912 gdb::unique_xmalloc_ptr<char> cond_string,
8913 gdb::unique_xmalloc_ptr<char> extra_string,
8914 enum bptype type, enum bpdisp disposition,
8915 int thread, int task, int ignore_count,
8916 const struct breakpoint_ops *ops, int from_tty,
8917 int enabled, int internal, unsigned flags,
8918 int display_canonical)
8920 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type);
8922 init_breakpoint_sal (b.get (), gdbarch,
8923 sals, std::move (location),
8925 std::move (cond_string),
8926 std::move (extra_string),
8928 thread, task, ignore_count,
8930 enabled, internal, flags,
8933 install_breakpoint (internal, std::move (b), 0);
8936 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8937 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8938 value. COND_STRING, if not NULL, specified the condition to be
8939 used for all breakpoints. Essentially the only case where
8940 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8941 function. In that case, it's still not possible to specify
8942 separate conditions for different overloaded functions, so
8943 we take just a single condition string.
8945 NOTE: If the function succeeds, the caller is expected to cleanup
8946 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8947 array contents). If the function fails (error() is called), the
8948 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8949 COND and SALS arrays and each of those arrays contents. */
8952 create_breakpoints_sal (struct gdbarch *gdbarch,
8953 struct linespec_result *canonical,
8954 gdb::unique_xmalloc_ptr<char> cond_string,
8955 gdb::unique_xmalloc_ptr<char> extra_string,
8956 enum bptype type, enum bpdisp disposition,
8957 int thread, int task, int ignore_count,
8958 const struct breakpoint_ops *ops, int from_tty,
8959 int enabled, int internal, unsigned flags)
8961 if (canonical->pre_expanded)
8962 gdb_assert (canonical->lsals.size () == 1);
8964 for (const auto &lsal : canonical->lsals)
8966 /* Note that 'location' can be NULL in the case of a plain
8967 'break', without arguments. */
8968 event_location_up location
8969 = (canonical->location != NULL
8970 ? copy_event_location (canonical->location.get ()) : NULL);
8971 gdb::unique_xmalloc_ptr<char> filter_string
8972 (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
8974 create_breakpoint_sal (gdbarch, lsal.sals,
8975 std::move (location),
8976 std::move (filter_string),
8977 std::move (cond_string),
8978 std::move (extra_string),
8980 thread, task, ignore_count, ops,
8981 from_tty, enabled, internal, flags,
8982 canonical->special_display);
8986 /* Parse LOCATION which is assumed to be a SAL specification possibly
8987 followed by conditionals. On return, SALS contains an array of SAL
8988 addresses found. LOCATION points to the end of the SAL (for
8989 linespec locations).
8991 The array and the line spec strings are allocated on the heap, it is
8992 the caller's responsibility to free them. */
8995 parse_breakpoint_sals (const struct event_location *location,
8996 struct linespec_result *canonical)
8998 struct symtab_and_line cursal;
9000 if (event_location_type (location) == LINESPEC_LOCATION)
9002 const char *spec = get_linespec_location (location)->spec_string;
9006 /* The last displayed codepoint, if it's valid, is our default
9007 breakpoint address. */
9008 if (last_displayed_sal_is_valid ())
9010 /* Set sal's pspace, pc, symtab, and line to the values
9011 corresponding to the last call to print_frame_info.
9012 Be sure to reinitialize LINE with NOTCURRENT == 0
9013 as the breakpoint line number is inappropriate otherwise.
9014 find_pc_line would adjust PC, re-set it back. */
9015 symtab_and_line sal = get_last_displayed_sal ();
9016 CORE_ADDR pc = sal.pc;
9018 sal = find_pc_line (pc, 0);
9020 /* "break" without arguments is equivalent to "break *PC"
9021 where PC is the last displayed codepoint's address. So
9022 make sure to set sal.explicit_pc to prevent GDB from
9023 trying to expand the list of sals to include all other
9024 instances with the same symtab and line. */
9026 sal.explicit_pc = 1;
9028 struct linespec_sals lsal;
9030 lsal.canonical = NULL;
9032 canonical->lsals.push_back (std::move (lsal));
9036 error (_("No default breakpoint address now."));
9040 /* Force almost all breakpoints to be in terms of the
9041 current_source_symtab (which is decode_line_1's default).
9042 This should produce the results we want almost all of the
9043 time while leaving default_breakpoint_* alone.
9045 ObjC: However, don't match an Objective-C method name which
9046 may have a '+' or '-' succeeded by a '['. */
9047 cursal = get_current_source_symtab_and_line ();
9048 if (last_displayed_sal_is_valid ())
9050 const char *spec = NULL;
9052 if (event_location_type (location) == LINESPEC_LOCATION)
9053 spec = get_linespec_location (location)->spec_string;
9057 && strchr ("+-", spec[0]) != NULL
9060 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9061 get_last_displayed_symtab (),
9062 get_last_displayed_line (),
9063 canonical, NULL, NULL);
9068 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9069 cursal.symtab, cursal.line, canonical, NULL, NULL);
9073 /* Convert each SAL into a real PC. Verify that the PC can be
9074 inserted as a breakpoint. If it can't throw an error. */
9077 breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
9079 for (auto &sal : sals)
9080 resolve_sal_pc (&sal);
9083 /* Fast tracepoints may have restrictions on valid locations. For
9084 instance, a fast tracepoint using a jump instead of a trap will
9085 likely have to overwrite more bytes than a trap would, and so can
9086 only be placed where the instruction is longer than the jump, or a
9087 multi-instruction sequence does not have a jump into the middle of
9091 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9092 gdb::array_view<const symtab_and_line> sals)
9094 for (const auto &sal : sals)
9096 struct gdbarch *sarch;
9098 sarch = get_sal_arch (sal);
9099 /* We fall back to GDBARCH if there is no architecture
9100 associated with SAL. */
9104 if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg))
9105 error (_("May not have a fast tracepoint at %s%s"),
9106 paddress (sarch, sal.pc), msg.c_str ());
9110 /* Given TOK, a string specification of condition and thread, as
9111 accepted by the 'break' command, extract the condition
9112 string and thread number and set *COND_STRING and *THREAD.
9113 PC identifies the context at which the condition should be parsed.
9114 If no condition is found, *COND_STRING is set to NULL.
9115 If no thread is found, *THREAD is set to -1. */
9118 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9119 char **cond_string, int *thread, int *task,
9122 *cond_string = NULL;
9129 const char *end_tok;
9131 const char *cond_start = NULL;
9132 const char *cond_end = NULL;
9134 tok = skip_spaces (tok);
9136 if ((*tok == '"' || *tok == ',') && rest)
9138 *rest = savestring (tok, strlen (tok));
9142 end_tok = skip_to_space (tok);
9144 toklen = end_tok - tok;
9146 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9148 tok = cond_start = end_tok + 1;
9149 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9151 *cond_string = savestring (cond_start, cond_end - cond_start);
9153 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9156 struct thread_info *thr;
9159 thr = parse_thread_id (tok, &tmptok);
9161 error (_("Junk after thread keyword."));
9162 *thread = thr->global_num;
9165 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9170 *task = strtol (tok, &tmptok, 0);
9172 error (_("Junk after task keyword."));
9173 if (!valid_task_id (*task))
9174 error (_("Unknown task %d."), *task);
9179 *rest = savestring (tok, strlen (tok));
9183 error (_("Junk at end of arguments."));
9187 /* Decode a static tracepoint marker spec. */
9189 static std::vector<symtab_and_line>
9190 decode_static_tracepoint_spec (const char **arg_p)
9192 const char *p = &(*arg_p)[3];
9195 p = skip_spaces (p);
9197 endp = skip_to_space (p);
9199 std::string marker_str (p, endp - p);
9201 std::vector<static_tracepoint_marker> markers
9202 = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
9203 if (markers.empty ())
9204 error (_("No known static tracepoint marker named %s"),
9205 marker_str.c_str ());
9207 std::vector<symtab_and_line> sals;
9208 sals.reserve (markers.size ());
9210 for (const static_tracepoint_marker &marker : markers)
9212 symtab_and_line sal = find_pc_line (marker.address, 0);
9213 sal.pc = marker.address;
9214 sals.push_back (sal);
9221 /* See breakpoint.h. */
9224 create_breakpoint (struct gdbarch *gdbarch,
9225 const struct event_location *location,
9226 const char *cond_string,
9227 int thread, const char *extra_string,
9229 int tempflag, enum bptype type_wanted,
9231 enum auto_boolean pending_break_support,
9232 const struct breakpoint_ops *ops,
9233 int from_tty, int enabled, int internal,
9236 struct linespec_result canonical;
9237 struct cleanup *bkpt_chain = NULL;
9240 int prev_bkpt_count = breakpoint_count;
9242 gdb_assert (ops != NULL);
9244 /* If extra_string isn't useful, set it to NULL. */
9245 if (extra_string != NULL && *extra_string == '\0')
9246 extra_string = NULL;
9250 ops->create_sals_from_location (location, &canonical, type_wanted);
9252 CATCH (e, RETURN_MASK_ERROR)
9254 /* If caller is interested in rc value from parse, set
9256 if (e.error == NOT_FOUND_ERROR)
9258 /* If pending breakpoint support is turned off, throw
9261 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9262 throw_exception (e);
9264 exception_print (gdb_stderr, e);
9266 /* If pending breakpoint support is auto query and the user
9267 selects no, then simply return the error code. */
9268 if (pending_break_support == AUTO_BOOLEAN_AUTO
9269 && !nquery (_("Make %s pending on future shared library load? "),
9270 bptype_string (type_wanted)))
9273 /* At this point, either the user was queried about setting
9274 a pending breakpoint and selected yes, or pending
9275 breakpoint behavior is on and thus a pending breakpoint
9276 is defaulted on behalf of the user. */
9280 throw_exception (e);
9284 if (!pending && canonical.lsals.empty ())
9287 /* ----------------------------- SNIP -----------------------------
9288 Anything added to the cleanup chain beyond this point is assumed
9289 to be part of a breakpoint. If the breakpoint create succeeds
9290 then the memory is not reclaimed. */
9291 bkpt_chain = make_cleanup (null_cleanup, 0);
9293 /* Resolve all line numbers to PC's and verify that the addresses
9294 are ok for the target. */
9297 for (auto &lsal : canonical.lsals)
9298 breakpoint_sals_to_pc (lsal.sals);
9301 /* Fast tracepoints may have additional restrictions on location. */
9302 if (!pending && type_wanted == bp_fast_tracepoint)
9304 for (const auto &lsal : canonical.lsals)
9305 check_fast_tracepoint_sals (gdbarch, lsal.sals);
9308 /* Verify that condition can be parsed, before setting any
9309 breakpoints. Allocate a separate condition expression for each
9313 gdb::unique_xmalloc_ptr<char> cond_string_copy;
9314 gdb::unique_xmalloc_ptr<char> extra_string_copy;
9321 const linespec_sals &lsal = canonical.lsals[0];
9323 /* Here we only parse 'arg' to separate condition
9324 from thread number, so parsing in context of first
9325 sal is OK. When setting the breakpoint we'll
9326 re-parse it in context of each sal. */
9328 find_condition_and_thread (extra_string, lsal.sals[0].pc,
9329 &cond, &thread, &task, &rest);
9330 cond_string_copy.reset (cond);
9331 extra_string_copy.reset (rest);
9335 if (type_wanted != bp_dprintf
9336 && extra_string != NULL && *extra_string != '\0')
9337 error (_("Garbage '%s' at end of location"), extra_string);
9339 /* Create a private copy of condition string. */
9341 cond_string_copy.reset (xstrdup (cond_string));
9342 /* Create a private copy of any extra string. */
9344 extra_string_copy.reset (xstrdup (extra_string));
9347 ops->create_breakpoints_sal (gdbarch, &canonical,
9348 std::move (cond_string_copy),
9349 std::move (extra_string_copy),
9351 tempflag ? disp_del : disp_donttouch,
9352 thread, task, ignore_count, ops,
9353 from_tty, enabled, internal, flags);
9357 std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted);
9359 init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops);
9360 b->location = copy_event_location (location);
9363 b->cond_string = NULL;
9366 /* Create a private copy of condition string. */
9367 b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL;
9371 /* Create a private copy of any extra string. */
9372 b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL;
9373 b->ignore_count = ignore_count;
9374 b->disposition = tempflag ? disp_del : disp_donttouch;
9375 b->condition_not_parsed = 1;
9376 b->enable_state = enabled ? bp_enabled : bp_disabled;
9377 if ((type_wanted != bp_breakpoint
9378 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9379 b->pspace = current_program_space;
9381 install_breakpoint (internal, std::move (b), 0);
9384 if (canonical.lsals.size () > 1)
9386 warning (_("Multiple breakpoints were set.\nUse the "
9387 "\"delete\" command to delete unwanted breakpoints."));
9388 prev_breakpoint_count = prev_bkpt_count;
9391 /* That's it. Discard the cleanups for data inserted into the
9393 discard_cleanups (bkpt_chain);
9395 /* error call may happen here - have BKPT_CHAIN already discarded. */
9396 update_global_location_list (UGLL_MAY_INSERT);
9401 /* Set a breakpoint.
9402 ARG is a string describing breakpoint address,
9403 condition, and thread.
9404 FLAG specifies if a breakpoint is hardware on,
9405 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9409 break_command_1 (const char *arg, int flag, int from_tty)
9411 int tempflag = flag & BP_TEMPFLAG;
9412 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9413 ? bp_hardware_breakpoint
9415 struct breakpoint_ops *ops;
9417 event_location_up location = string_to_event_location (&arg, current_language);
9419 /* Matching breakpoints on probes. */
9420 if (location != NULL
9421 && event_location_type (location.get ()) == PROBE_LOCATION)
9422 ops = &bkpt_probe_breakpoint_ops;
9424 ops = &bkpt_breakpoint_ops;
9426 create_breakpoint (get_current_arch (),
9428 NULL, 0, arg, 1 /* parse arg */,
9429 tempflag, type_wanted,
9430 0 /* Ignore count */,
9431 pending_break_support,
9439 /* Helper function for break_command_1 and disassemble_command. */
9442 resolve_sal_pc (struct symtab_and_line *sal)
9446 if (sal->pc == 0 && sal->symtab != NULL)
9448 if (!find_line_pc (sal->symtab, sal->line, &pc))
9449 error (_("No line %d in file \"%s\"."),
9450 sal->line, symtab_to_filename_for_display (sal->symtab));
9453 /* If this SAL corresponds to a breakpoint inserted using a line
9454 number, then skip the function prologue if necessary. */
9455 if (sal->explicit_line)
9456 skip_prologue_sal (sal);
9459 if (sal->section == 0 && sal->symtab != NULL)
9461 const struct blockvector *bv;
9462 const struct block *b;
9465 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9466 SYMTAB_COMPUNIT (sal->symtab));
9469 sym = block_linkage_function (b);
9472 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
9473 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
9478 /* It really is worthwhile to have the section, so we'll
9479 just have to look harder. This case can be executed
9480 if we have line numbers but no functions (as can
9481 happen in assembly source). */
9483 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9484 switch_to_program_space_and_thread (sal->pspace);
9486 bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
9488 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9495 break_command (const char *arg, int from_tty)
9497 break_command_1 (arg, 0, from_tty);
9501 tbreak_command (const char *arg, int from_tty)
9503 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9507 hbreak_command (const char *arg, int from_tty)
9509 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9513 thbreak_command (const char *arg, int from_tty)
9515 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9519 stop_command (const char *arg, int from_tty)
9521 printf_filtered (_("Specify the type of breakpoint to set.\n\
9522 Usage: stop in <function | address>\n\
9523 stop at <line>\n"));
9527 stopin_command (const char *arg, int from_tty)
9531 if (arg == (char *) NULL)
9533 else if (*arg != '*')
9535 const char *argptr = arg;
9538 /* Look for a ':'. If this is a line number specification, then
9539 say it is bad, otherwise, it should be an address or
9540 function/method name. */
9541 while (*argptr && !hasColon)
9543 hasColon = (*argptr == ':');
9548 badInput = (*argptr != ':'); /* Not a class::method */
9550 badInput = isdigit (*arg); /* a simple line number */
9554 printf_filtered (_("Usage: stop in <function | address>\n"));
9556 break_command_1 (arg, 0, from_tty);
9560 stopat_command (const char *arg, int from_tty)
9564 if (arg == (char *) NULL || *arg == '*') /* no line number */
9568 const char *argptr = arg;
9571 /* Look for a ':'. If there is a '::' then get out, otherwise
9572 it is probably a line number. */
9573 while (*argptr && !hasColon)
9575 hasColon = (*argptr == ':');
9580 badInput = (*argptr == ':'); /* we have class::method */
9582 badInput = !isdigit (*arg); /* not a line number */
9586 printf_filtered (_("Usage: stop at LINE\n"));
9588 break_command_1 (arg, 0, from_tty);
9591 /* The dynamic printf command is mostly like a regular breakpoint, but
9592 with a prewired command list consisting of a single output command,
9593 built from extra arguments supplied on the dprintf command
9597 dprintf_command (const char *arg, int from_tty)
9599 event_location_up location = string_to_event_location (&arg, current_language);
9601 /* If non-NULL, ARG should have been advanced past the location;
9602 the next character must be ','. */
9605 if (arg[0] != ',' || arg[1] == '\0')
9606 error (_("Format string required"));
9609 /* Skip the comma. */
9614 create_breakpoint (get_current_arch (),
9616 NULL, 0, arg, 1 /* parse arg */,
9618 0 /* Ignore count */,
9619 pending_break_support,
9620 &dprintf_breakpoint_ops,
9628 agent_printf_command (const char *arg, int from_tty)
9630 error (_("May only run agent-printf on the target"));
9633 /* Implement the "breakpoint_hit" breakpoint_ops method for
9634 ranged breakpoints. */
9637 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9638 const address_space *aspace,
9640 const struct target_waitstatus *ws)
9642 if (ws->kind != TARGET_WAITKIND_STOPPED
9643 || ws->value.sig != GDB_SIGNAL_TRAP)
9646 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9647 bl->length, aspace, bp_addr);
9650 /* Implement the "resources_needed" breakpoint_ops method for
9651 ranged breakpoints. */
9654 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9656 return target_ranged_break_num_registers ();
9659 /* Implement the "print_it" breakpoint_ops method for
9660 ranged breakpoints. */
9662 static enum print_stop_action
9663 print_it_ranged_breakpoint (bpstat bs)
9665 struct breakpoint *b = bs->breakpoint_at;
9666 struct bp_location *bl = b->loc;
9667 struct ui_out *uiout = current_uiout;
9669 gdb_assert (b->type == bp_hardware_breakpoint);
9671 /* Ranged breakpoints have only one location. */
9672 gdb_assert (bl && bl->next == NULL);
9674 annotate_breakpoint (b->number);
9676 maybe_print_thread_hit_breakpoint (uiout);
9678 if (b->disposition == disp_del)
9679 uiout->text ("Temporary ranged breakpoint ");
9681 uiout->text ("Ranged breakpoint ");
9682 if (uiout->is_mi_like_p ())
9684 uiout->field_string ("reason",
9685 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9686 uiout->field_string ("disp", bpdisp_text (b->disposition));
9688 uiout->field_int ("bkptno", b->number);
9691 return PRINT_SRC_AND_LOC;
9694 /* Implement the "print_one" breakpoint_ops method for
9695 ranged breakpoints. */
9698 print_one_ranged_breakpoint (struct breakpoint *b,
9699 struct bp_location **last_loc)
9701 struct bp_location *bl = b->loc;
9702 struct value_print_options opts;
9703 struct ui_out *uiout = current_uiout;
9705 /* Ranged breakpoints have only one location. */
9706 gdb_assert (bl && bl->next == NULL);
9708 get_user_print_options (&opts);
9710 if (opts.addressprint)
9711 /* We don't print the address range here, it will be printed later
9712 by print_one_detail_ranged_breakpoint. */
9713 uiout->field_skip ("addr");
9715 print_breakpoint_location (b, bl);
9719 /* Implement the "print_one_detail" breakpoint_ops method for
9720 ranged breakpoints. */
9723 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9724 struct ui_out *uiout)
9726 CORE_ADDR address_start, address_end;
9727 struct bp_location *bl = b->loc;
9732 address_start = bl->address;
9733 address_end = address_start + bl->length - 1;
9735 uiout->text ("\taddress range: ");
9736 stb.printf ("[%s, %s]",
9737 print_core_address (bl->gdbarch, address_start),
9738 print_core_address (bl->gdbarch, address_end));
9739 uiout->field_stream ("addr", stb);
9743 /* Implement the "print_mention" breakpoint_ops method for
9744 ranged breakpoints. */
9747 print_mention_ranged_breakpoint (struct breakpoint *b)
9749 struct bp_location *bl = b->loc;
9750 struct ui_out *uiout = current_uiout;
9753 gdb_assert (b->type == bp_hardware_breakpoint);
9755 uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9756 b->number, paddress (bl->gdbarch, bl->address),
9757 paddress (bl->gdbarch, bl->address + bl->length - 1));
9760 /* Implement the "print_recreate" breakpoint_ops method for
9761 ranged breakpoints. */
9764 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9766 fprintf_unfiltered (fp, "break-range %s, %s",
9767 event_location_to_string (b->location.get ()),
9768 event_location_to_string (b->location_range_end.get ()));
9769 print_recreate_thread (b, fp);
9772 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9774 static struct breakpoint_ops ranged_breakpoint_ops;
9776 /* Find the address where the end of the breakpoint range should be
9777 placed, given the SAL of the end of the range. This is so that if
9778 the user provides a line number, the end of the range is set to the
9779 last instruction of the given line. */
9782 find_breakpoint_range_end (struct symtab_and_line sal)
9786 /* If the user provided a PC value, use it. Otherwise,
9787 find the address of the end of the given location. */
9788 if (sal.explicit_pc)
9795 ret = find_line_pc_range (sal, &start, &end);
9797 error (_("Could not find location of the end of the range."));
9799 /* find_line_pc_range returns the start of the next line. */
9806 /* Implement the "break-range" CLI command. */
9809 break_range_command (const char *arg, int from_tty)
9811 const char *arg_start;
9812 struct linespec_result canonical_start, canonical_end;
9813 int bp_count, can_use_bp, length;
9815 struct breakpoint *b;
9817 /* We don't support software ranged breakpoints. */
9818 if (target_ranged_break_num_registers () < 0)
9819 error (_("This target does not support hardware ranged breakpoints."));
9821 bp_count = hw_breakpoint_used_count ();
9822 bp_count += target_ranged_break_num_registers ();
9823 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9826 error (_("Hardware breakpoints used exceeds limit."));
9828 arg = skip_spaces (arg);
9829 if (arg == NULL || arg[0] == '\0')
9830 error(_("No address range specified."));
9833 event_location_up start_location = string_to_event_location (&arg,
9835 parse_breakpoint_sals (start_location.get (), &canonical_start);
9838 error (_("Too few arguments."));
9839 else if (canonical_start.lsals.empty ())
9840 error (_("Could not find location of the beginning of the range."));
9842 const linespec_sals &lsal_start = canonical_start.lsals[0];
9844 if (canonical_start.lsals.size () > 1
9845 || lsal_start.sals.size () != 1)
9846 error (_("Cannot create a ranged breakpoint with multiple locations."));
9848 const symtab_and_line &sal_start = lsal_start.sals[0];
9849 std::string addr_string_start (arg_start, arg - arg_start);
9851 arg++; /* Skip the comma. */
9852 arg = skip_spaces (arg);
9854 /* Parse the end location. */
9858 /* We call decode_line_full directly here instead of using
9859 parse_breakpoint_sals because we need to specify the start location's
9860 symtab and line as the default symtab and line for the end of the
9861 range. This makes it possible to have ranges like "foo.c:27, +14",
9862 where +14 means 14 lines from the start location. */
9863 event_location_up end_location = string_to_event_location (&arg,
9865 decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
9866 sal_start.symtab, sal_start.line,
9867 &canonical_end, NULL, NULL);
9869 if (canonical_end.lsals.empty ())
9870 error (_("Could not find location of the end of the range."));
9872 const linespec_sals &lsal_end = canonical_end.lsals[0];
9873 if (canonical_end.lsals.size () > 1
9874 || lsal_end.sals.size () != 1)
9875 error (_("Cannot create a ranged breakpoint with multiple locations."));
9877 const symtab_and_line &sal_end = lsal_end.sals[0];
9879 end = find_breakpoint_range_end (sal_end);
9880 if (sal_start.pc > end)
9881 error (_("Invalid address range, end precedes start."));
9883 length = end - sal_start.pc + 1;
9885 /* Length overflowed. */
9886 error (_("Address range too large."));
9887 else if (length == 1)
9889 /* This range is simple enough to be handled by
9890 the `hbreak' command. */
9891 hbreak_command (&addr_string_start[0], 1);
9896 /* Now set up the breakpoint. */
9897 b = set_raw_breakpoint (get_current_arch (), sal_start,
9898 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9899 set_breakpoint_count (breakpoint_count + 1);
9900 b->number = breakpoint_count;
9901 b->disposition = disp_donttouch;
9902 b->location = std::move (start_location);
9903 b->location_range_end = std::move (end_location);
9904 b->loc->length = length;
9907 gdb::observers::breakpoint_created.notify (b);
9908 update_global_location_list (UGLL_MAY_INSERT);
9911 /* Return non-zero if EXP is verified as constant. Returned zero
9912 means EXP is variable. Also the constant detection may fail for
9913 some constant expressions and in such case still falsely return
9917 watchpoint_exp_is_const (const struct expression *exp)
9925 /* We are only interested in the descriptor of each element. */
9926 operator_length (exp, i, &oplenp, &argsp);
9929 switch (exp->elts[i].opcode)
9939 case BINOP_LOGICAL_AND:
9940 case BINOP_LOGICAL_OR:
9941 case BINOP_BITWISE_AND:
9942 case BINOP_BITWISE_IOR:
9943 case BINOP_BITWISE_XOR:
9945 case BINOP_NOTEQUAL:
9971 case OP_OBJC_NSSTRING:
9974 case UNOP_LOGICAL_NOT:
9975 case UNOP_COMPLEMENT:
9980 case UNOP_CAST_TYPE:
9981 case UNOP_REINTERPRET_CAST:
9982 case UNOP_DYNAMIC_CAST:
9983 /* Unary, binary and ternary operators: We have to check
9984 their operands. If they are constant, then so is the
9985 result of that operation. For instance, if A and B are
9986 determined to be constants, then so is "A + B".
9988 UNOP_IND is one exception to the rule above, because the
9989 value of *ADDR is not necessarily a constant, even when
9994 /* Check whether the associated symbol is a constant.
9996 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9997 possible that a buggy compiler could mark a variable as
9998 constant even when it is not, and TYPE_CONST would return
9999 true in this case, while SYMBOL_CLASS wouldn't.
10001 We also have to check for function symbols because they
10002 are always constant. */
10004 struct symbol *s = exp->elts[i + 2].symbol;
10006 if (SYMBOL_CLASS (s) != LOC_BLOCK
10007 && SYMBOL_CLASS (s) != LOC_CONST
10008 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10013 /* The default action is to return 0 because we are using
10014 the optimistic approach here: If we don't know something,
10015 then it is not a constant. */
10024 /* Watchpoint destructor. */
10026 watchpoint::~watchpoint ()
10028 xfree (this->exp_string);
10029 xfree (this->exp_string_reparse);
10032 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10035 re_set_watchpoint (struct breakpoint *b)
10037 struct watchpoint *w = (struct watchpoint *) b;
10039 /* Watchpoint can be either on expression using entirely global
10040 variables, or it can be on local variables.
10042 Watchpoints of the first kind are never auto-deleted, and even
10043 persist across program restarts. Since they can use variables
10044 from shared libraries, we need to reparse expression as libraries
10045 are loaded and unloaded.
10047 Watchpoints on local variables can also change meaning as result
10048 of solib event. For example, if a watchpoint uses both a local
10049 and a global variables in expression, it's a local watchpoint,
10050 but unloading of a shared library will make the expression
10051 invalid. This is not a very common use case, but we still
10052 re-evaluate expression, to avoid surprises to the user.
10054 Note that for local watchpoints, we re-evaluate it only if
10055 watchpoints frame id is still valid. If it's not, it means the
10056 watchpoint is out of scope and will be deleted soon. In fact,
10057 I'm not sure we'll ever be called in this case.
10059 If a local watchpoint's frame id is still valid, then
10060 w->exp_valid_block is likewise valid, and we can safely use it.
10062 Don't do anything about disabled watchpoints, since they will be
10063 reevaluated again when enabled. */
10064 update_watchpoint (w, 1 /* reparse */);
10067 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10070 insert_watchpoint (struct bp_location *bl)
10072 struct watchpoint *w = (struct watchpoint *) bl->owner;
10073 int length = w->exact ? 1 : bl->length;
10075 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10076 w->cond_exp.get ());
10079 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10082 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10084 struct watchpoint *w = (struct watchpoint *) bl->owner;
10085 int length = w->exact ? 1 : bl->length;
10087 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10088 w->cond_exp.get ());
10092 breakpoint_hit_watchpoint (const struct bp_location *bl,
10093 const address_space *aspace, CORE_ADDR bp_addr,
10094 const struct target_waitstatus *ws)
10096 struct breakpoint *b = bl->owner;
10097 struct watchpoint *w = (struct watchpoint *) b;
10099 /* Continuable hardware watchpoints are treated as non-existent if the
10100 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10101 some data address). Otherwise gdb won't stop on a break instruction
10102 in the code (not from a breakpoint) when a hardware watchpoint has
10103 been defined. Also skip watchpoints which we know did not trigger
10104 (did not match the data address). */
10105 if (is_hardware_watchpoint (b)
10106 && w->watchpoint_triggered == watch_triggered_no)
10113 check_status_watchpoint (bpstat bs)
10115 gdb_assert (is_watchpoint (bs->breakpoint_at));
10117 bpstat_check_watchpoint (bs);
10120 /* Implement the "resources_needed" breakpoint_ops method for
10121 hardware watchpoints. */
10124 resources_needed_watchpoint (const struct bp_location *bl)
10126 struct watchpoint *w = (struct watchpoint *) bl->owner;
10127 int length = w->exact? 1 : bl->length;
10129 return target_region_ok_for_hw_watchpoint (bl->address, length);
10132 /* Implement the "works_in_software_mode" breakpoint_ops method for
10133 hardware watchpoints. */
10136 works_in_software_mode_watchpoint (const struct breakpoint *b)
10138 /* Read and access watchpoints only work with hardware support. */
10139 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10142 static enum print_stop_action
10143 print_it_watchpoint (bpstat bs)
10145 struct breakpoint *b;
10146 enum print_stop_action result;
10147 struct watchpoint *w;
10148 struct ui_out *uiout = current_uiout;
10150 gdb_assert (bs->bp_location_at != NULL);
10152 b = bs->breakpoint_at;
10153 w = (struct watchpoint *) b;
10155 annotate_watchpoint (b->number);
10156 maybe_print_thread_hit_breakpoint (uiout);
10160 gdb::optional<ui_out_emit_tuple> tuple_emitter;
10163 case bp_watchpoint:
10164 case bp_hardware_watchpoint:
10165 if (uiout->is_mi_like_p ())
10166 uiout->field_string
10167 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10169 tuple_emitter.emplace (uiout, "value");
10170 uiout->text ("\nOld value = ");
10171 watchpoint_value_print (bs->old_val.get (), &stb);
10172 uiout->field_stream ("old", stb);
10173 uiout->text ("\nNew value = ");
10174 watchpoint_value_print (w->val.get (), &stb);
10175 uiout->field_stream ("new", stb);
10176 uiout->text ("\n");
10177 /* More than one watchpoint may have been triggered. */
10178 result = PRINT_UNKNOWN;
10181 case bp_read_watchpoint:
10182 if (uiout->is_mi_like_p ())
10183 uiout->field_string
10184 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10186 tuple_emitter.emplace (uiout, "value");
10187 uiout->text ("\nValue = ");
10188 watchpoint_value_print (w->val.get (), &stb);
10189 uiout->field_stream ("value", stb);
10190 uiout->text ("\n");
10191 result = PRINT_UNKNOWN;
10194 case bp_access_watchpoint:
10195 if (bs->old_val != NULL)
10197 if (uiout->is_mi_like_p ())
10198 uiout->field_string
10200 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10202 tuple_emitter.emplace (uiout, "value");
10203 uiout->text ("\nOld value = ");
10204 watchpoint_value_print (bs->old_val.get (), &stb);
10205 uiout->field_stream ("old", stb);
10206 uiout->text ("\nNew value = ");
10211 if (uiout->is_mi_like_p ())
10212 uiout->field_string
10214 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10215 tuple_emitter.emplace (uiout, "value");
10216 uiout->text ("\nValue = ");
10218 watchpoint_value_print (w->val.get (), &stb);
10219 uiout->field_stream ("new", stb);
10220 uiout->text ("\n");
10221 result = PRINT_UNKNOWN;
10224 result = PRINT_UNKNOWN;
10230 /* Implement the "print_mention" breakpoint_ops method for hardware
10234 print_mention_watchpoint (struct breakpoint *b)
10236 struct watchpoint *w = (struct watchpoint *) b;
10237 struct ui_out *uiout = current_uiout;
10238 const char *tuple_name;
10242 case bp_watchpoint:
10243 uiout->text ("Watchpoint ");
10244 tuple_name = "wpt";
10246 case bp_hardware_watchpoint:
10247 uiout->text ("Hardware watchpoint ");
10248 tuple_name = "wpt";
10250 case bp_read_watchpoint:
10251 uiout->text ("Hardware read watchpoint ");
10252 tuple_name = "hw-rwpt";
10254 case bp_access_watchpoint:
10255 uiout->text ("Hardware access (read/write) watchpoint ");
10256 tuple_name = "hw-awpt";
10259 internal_error (__FILE__, __LINE__,
10260 _("Invalid hardware watchpoint type."));
10263 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10264 uiout->field_int ("number", b->number);
10265 uiout->text (": ");
10266 uiout->field_string ("exp", w->exp_string);
10269 /* Implement the "print_recreate" breakpoint_ops method for
10273 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10275 struct watchpoint *w = (struct watchpoint *) b;
10279 case bp_watchpoint:
10280 case bp_hardware_watchpoint:
10281 fprintf_unfiltered (fp, "watch");
10283 case bp_read_watchpoint:
10284 fprintf_unfiltered (fp, "rwatch");
10286 case bp_access_watchpoint:
10287 fprintf_unfiltered (fp, "awatch");
10290 internal_error (__FILE__, __LINE__,
10291 _("Invalid watchpoint type."));
10294 fprintf_unfiltered (fp, " %s", w->exp_string);
10295 print_recreate_thread (b, fp);
10298 /* Implement the "explains_signal" breakpoint_ops method for
10302 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10304 /* A software watchpoint cannot cause a signal other than
10305 GDB_SIGNAL_TRAP. */
10306 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10312 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10314 static struct breakpoint_ops watchpoint_breakpoint_ops;
10316 /* Implement the "insert" breakpoint_ops method for
10317 masked hardware watchpoints. */
10320 insert_masked_watchpoint (struct bp_location *bl)
10322 struct watchpoint *w = (struct watchpoint *) bl->owner;
10324 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10325 bl->watchpoint_type);
10328 /* Implement the "remove" breakpoint_ops method for
10329 masked hardware watchpoints. */
10332 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10334 struct watchpoint *w = (struct watchpoint *) bl->owner;
10336 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10337 bl->watchpoint_type);
10340 /* Implement the "resources_needed" breakpoint_ops method for
10341 masked hardware watchpoints. */
10344 resources_needed_masked_watchpoint (const struct bp_location *bl)
10346 struct watchpoint *w = (struct watchpoint *) bl->owner;
10348 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10351 /* Implement the "works_in_software_mode" breakpoint_ops method for
10352 masked hardware watchpoints. */
10355 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10360 /* Implement the "print_it" breakpoint_ops method for
10361 masked hardware watchpoints. */
10363 static enum print_stop_action
10364 print_it_masked_watchpoint (bpstat bs)
10366 struct breakpoint *b = bs->breakpoint_at;
10367 struct ui_out *uiout = current_uiout;
10369 /* Masked watchpoints have only one location. */
10370 gdb_assert (b->loc && b->loc->next == NULL);
10372 annotate_watchpoint (b->number);
10373 maybe_print_thread_hit_breakpoint (uiout);
10377 case bp_hardware_watchpoint:
10378 if (uiout->is_mi_like_p ())
10379 uiout->field_string
10380 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10383 case bp_read_watchpoint:
10384 if (uiout->is_mi_like_p ())
10385 uiout->field_string
10386 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10389 case bp_access_watchpoint:
10390 if (uiout->is_mi_like_p ())
10391 uiout->field_string
10393 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10396 internal_error (__FILE__, __LINE__,
10397 _("Invalid hardware watchpoint type."));
10401 uiout->text (_("\n\
10402 Check the underlying instruction at PC for the memory\n\
10403 address and value which triggered this watchpoint.\n"));
10404 uiout->text ("\n");
10406 /* More than one watchpoint may have been triggered. */
10407 return PRINT_UNKNOWN;
10410 /* Implement the "print_one_detail" breakpoint_ops method for
10411 masked hardware watchpoints. */
10414 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10415 struct ui_out *uiout)
10417 struct watchpoint *w = (struct watchpoint *) b;
10419 /* Masked watchpoints have only one location. */
10420 gdb_assert (b->loc && b->loc->next == NULL);
10422 uiout->text ("\tmask ");
10423 uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
10424 uiout->text ("\n");
10427 /* Implement the "print_mention" breakpoint_ops method for
10428 masked hardware watchpoints. */
10431 print_mention_masked_watchpoint (struct breakpoint *b)
10433 struct watchpoint *w = (struct watchpoint *) b;
10434 struct ui_out *uiout = current_uiout;
10435 const char *tuple_name;
10439 case bp_hardware_watchpoint:
10440 uiout->text ("Masked hardware watchpoint ");
10441 tuple_name = "wpt";
10443 case bp_read_watchpoint:
10444 uiout->text ("Masked hardware read watchpoint ");
10445 tuple_name = "hw-rwpt";
10447 case bp_access_watchpoint:
10448 uiout->text ("Masked hardware access (read/write) watchpoint ");
10449 tuple_name = "hw-awpt";
10452 internal_error (__FILE__, __LINE__,
10453 _("Invalid hardware watchpoint type."));
10456 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10457 uiout->field_int ("number", b->number);
10458 uiout->text (": ");
10459 uiout->field_string ("exp", w->exp_string);
10462 /* Implement the "print_recreate" breakpoint_ops method for
10463 masked hardware watchpoints. */
10466 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10468 struct watchpoint *w = (struct watchpoint *) b;
10473 case bp_hardware_watchpoint:
10474 fprintf_unfiltered (fp, "watch");
10476 case bp_read_watchpoint:
10477 fprintf_unfiltered (fp, "rwatch");
10479 case bp_access_watchpoint:
10480 fprintf_unfiltered (fp, "awatch");
10483 internal_error (__FILE__, __LINE__,
10484 _("Invalid hardware watchpoint type."));
10487 sprintf_vma (tmp, w->hw_wp_mask);
10488 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10489 print_recreate_thread (b, fp);
10492 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10494 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10496 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10499 is_masked_watchpoint (const struct breakpoint *b)
10501 return b->ops == &masked_watchpoint_breakpoint_ops;
10504 /* accessflag: hw_write: watch write,
10505 hw_read: watch read,
10506 hw_access: watch access (read or write) */
10508 watch_command_1 (const char *arg, int accessflag, int from_tty,
10509 int just_location, int internal)
10511 struct breakpoint *scope_breakpoint = NULL;
10512 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10513 struct value *result;
10514 int saved_bitpos = 0, saved_bitsize = 0;
10515 const char *exp_start = NULL;
10516 const char *exp_end = NULL;
10517 const char *tok, *end_tok;
10519 const char *cond_start = NULL;
10520 const char *cond_end = NULL;
10521 enum bptype bp_type;
10524 /* Flag to indicate whether we are going to use masks for
10525 the hardware watchpoint. */
10527 CORE_ADDR mask = 0;
10529 /* Make sure that we actually have parameters to parse. */
10530 if (arg != NULL && arg[0] != '\0')
10532 const char *value_start;
10534 exp_end = arg + strlen (arg);
10536 /* Look for "parameter value" pairs at the end
10537 of the arguments string. */
10538 for (tok = exp_end - 1; tok > arg; tok--)
10540 /* Skip whitespace at the end of the argument list. */
10541 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10544 /* Find the beginning of the last token.
10545 This is the value of the parameter. */
10546 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10548 value_start = tok + 1;
10550 /* Skip whitespace. */
10551 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10556 /* Find the beginning of the second to last token.
10557 This is the parameter itself. */
10558 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10561 toklen = end_tok - tok + 1;
10563 if (toklen == 6 && startswith (tok, "thread"))
10565 struct thread_info *thr;
10566 /* At this point we've found a "thread" token, which means
10567 the user is trying to set a watchpoint that triggers
10568 only in a specific thread. */
10572 error(_("You can specify only one thread."));
10574 /* Extract the thread ID from the next token. */
10575 thr = parse_thread_id (value_start, &endp);
10577 /* Check if the user provided a valid thread ID. */
10578 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10579 invalid_thread_id_error (value_start);
10581 thread = thr->global_num;
10583 else if (toklen == 4 && startswith (tok, "mask"))
10585 /* We've found a "mask" token, which means the user wants to
10586 create a hardware watchpoint that is going to have the mask
10588 struct value *mask_value, *mark;
10591 error(_("You can specify only one mask."));
10593 use_mask = just_location = 1;
10595 mark = value_mark ();
10596 mask_value = parse_to_comma_and_eval (&value_start);
10597 mask = value_as_address (mask_value);
10598 value_free_to_mark (mark);
10601 /* We didn't recognize what we found. We should stop here. */
10604 /* Truncate the string and get rid of the "parameter value" pair before
10605 the arguments string is parsed by the parse_exp_1 function. */
10612 /* Parse the rest of the arguments. From here on out, everything
10613 is in terms of a newly allocated string instead of the original
10615 innermost_block.reset ();
10616 std::string expression (arg, exp_end - arg);
10617 exp_start = arg = expression.c_str ();
10618 expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
10620 /* Remove trailing whitespace from the expression before saving it.
10621 This makes the eventual display of the expression string a bit
10623 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10626 /* Checking if the expression is not constant. */
10627 if (watchpoint_exp_is_const (exp.get ()))
10631 len = exp_end - exp_start;
10632 while (len > 0 && isspace (exp_start[len - 1]))
10634 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10637 exp_valid_block = innermost_block.block ();
10638 struct value *mark = value_mark ();
10639 struct value *val_as_value = nullptr;
10640 fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL,
10643 if (val_as_value != NULL && just_location)
10645 saved_bitpos = value_bitpos (val_as_value);
10646 saved_bitsize = value_bitsize (val_as_value);
10654 exp_valid_block = NULL;
10655 val = release_value (value_addr (result));
10656 value_free_to_mark (mark);
10660 ret = target_masked_watch_num_registers (value_as_address (val.get ()),
10663 error (_("This target does not support masked watchpoints."));
10664 else if (ret == -2)
10665 error (_("Invalid mask or memory region."));
10668 else if (val_as_value != NULL)
10669 val = release_value (val_as_value);
10671 tok = skip_spaces (arg);
10672 end_tok = skip_to_space (tok);
10674 toklen = end_tok - tok;
10675 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10677 innermost_block.reset ();
10678 tok = cond_start = end_tok + 1;
10679 parse_exp_1 (&tok, 0, 0, 0);
10681 /* The watchpoint expression may not be local, but the condition
10682 may still be. E.g.: `watch global if local > 0'. */
10683 cond_exp_valid_block = innermost_block.block ();
10688 error (_("Junk at end of command."));
10690 frame_info *wp_frame = block_innermost_frame (exp_valid_block);
10692 /* Save this because create_internal_breakpoint below invalidates
10694 frame_id watchpoint_frame = get_frame_id (wp_frame);
10696 /* If the expression is "local", then set up a "watchpoint scope"
10697 breakpoint at the point where we've left the scope of the watchpoint
10698 expression. Create the scope breakpoint before the watchpoint, so
10699 that we will encounter it first in bpstat_stop_status. */
10700 if (exp_valid_block != NULL && wp_frame != NULL)
10702 frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
10704 if (frame_id_p (caller_frame_id))
10706 gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
10707 CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
10710 = create_internal_breakpoint (caller_arch, caller_pc,
10711 bp_watchpoint_scope,
10712 &momentary_breakpoint_ops);
10714 /* create_internal_breakpoint could invalidate WP_FRAME. */
10717 scope_breakpoint->enable_state = bp_enabled;
10719 /* Automatically delete the breakpoint when it hits. */
10720 scope_breakpoint->disposition = disp_del;
10722 /* Only break in the proper frame (help with recursion). */
10723 scope_breakpoint->frame_id = caller_frame_id;
10725 /* Set the address at which we will stop. */
10726 scope_breakpoint->loc->gdbarch = caller_arch;
10727 scope_breakpoint->loc->requested_address = caller_pc;
10728 scope_breakpoint->loc->address
10729 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10730 scope_breakpoint->loc->requested_address,
10731 scope_breakpoint->type);
10735 /* Now set up the breakpoint. We create all watchpoints as hardware
10736 watchpoints here even if hardware watchpoints are turned off, a call
10737 to update_watchpoint later in this function will cause the type to
10738 drop back to bp_watchpoint (software watchpoint) if required. */
10740 if (accessflag == hw_read)
10741 bp_type = bp_read_watchpoint;
10742 else if (accessflag == hw_access)
10743 bp_type = bp_access_watchpoint;
10745 bp_type = bp_hardware_watchpoint;
10747 std::unique_ptr<watchpoint> w (new watchpoint ());
10750 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10751 &masked_watchpoint_breakpoint_ops);
10753 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10754 &watchpoint_breakpoint_ops);
10755 w->thread = thread;
10756 w->disposition = disp_donttouch;
10757 w->pspace = current_program_space;
10758 w->exp = std::move (exp);
10759 w->exp_valid_block = exp_valid_block;
10760 w->cond_exp_valid_block = cond_exp_valid_block;
10763 struct type *t = value_type (val.get ());
10764 CORE_ADDR addr = value_as_address (val.get ());
10766 w->exp_string_reparse
10767 = current_language->la_watch_location_expression (t, addr).release ();
10769 w->exp_string = xstrprintf ("-location %.*s",
10770 (int) (exp_end - exp_start), exp_start);
10773 w->exp_string = savestring (exp_start, exp_end - exp_start);
10777 w->hw_wp_mask = mask;
10782 w->val_bitpos = saved_bitpos;
10783 w->val_bitsize = saved_bitsize;
10788 w->cond_string = savestring (cond_start, cond_end - cond_start);
10790 w->cond_string = 0;
10792 if (frame_id_p (watchpoint_frame))
10794 w->watchpoint_frame = watchpoint_frame;
10795 w->watchpoint_thread = inferior_ptid;
10799 w->watchpoint_frame = null_frame_id;
10800 w->watchpoint_thread = null_ptid;
10803 if (scope_breakpoint != NULL)
10805 /* The scope breakpoint is related to the watchpoint. We will
10806 need to act on them together. */
10807 w->related_breakpoint = scope_breakpoint;
10808 scope_breakpoint->related_breakpoint = w.get ();
10811 if (!just_location)
10812 value_free_to_mark (mark);
10814 /* Finally update the new watchpoint. This creates the locations
10815 that should be inserted. */
10816 update_watchpoint (w.get (), 1);
10818 install_breakpoint (internal, std::move (w), 1);
10821 /* Return count of debug registers needed to watch the given expression.
10822 If the watchpoint cannot be handled in hardware return zero. */
10825 can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
10827 int found_memory_cnt = 0;
10829 /* Did the user specifically forbid us to use hardware watchpoints? */
10830 if (!can_use_hw_watchpoints)
10833 gdb_assert (!vals.empty ());
10834 struct value *head = vals[0].get ();
10836 /* Make sure that the value of the expression depends only upon
10837 memory contents, and values computed from them within GDB. If we
10838 find any register references or function calls, we can't use a
10839 hardware watchpoint.
10841 The idea here is that evaluating an expression generates a series
10842 of values, one holding the value of every subexpression. (The
10843 expression a*b+c has five subexpressions: a, b, a*b, c, and
10844 a*b+c.) GDB's values hold almost enough information to establish
10845 the criteria given above --- they identify memory lvalues,
10846 register lvalues, computed values, etcetera. So we can evaluate
10847 the expression, and then scan the chain of values that leaves
10848 behind to decide whether we can detect any possible change to the
10849 expression's final value using only hardware watchpoints.
10851 However, I don't think that the values returned by inferior
10852 function calls are special in any way. So this function may not
10853 notice that an expression involving an inferior function call
10854 can't be watched with hardware watchpoints. FIXME. */
10855 for (const value_ref_ptr &iter : vals)
10857 struct value *v = iter.get ();
10859 if (VALUE_LVAL (v) == lval_memory)
10861 if (v != head && value_lazy (v))
10862 /* A lazy memory lvalue in the chain is one that GDB never
10863 needed to fetch; we either just used its address (e.g.,
10864 `a' in `a.b') or we never needed it at all (e.g., `a'
10865 in `a,b'). This doesn't apply to HEAD; if that is
10866 lazy then it was not readable, but watch it anyway. */
10870 /* Ahh, memory we actually used! Check if we can cover
10871 it with hardware watchpoints. */
10872 struct type *vtype = check_typedef (value_type (v));
10874 /* We only watch structs and arrays if user asked for it
10875 explicitly, never if they just happen to appear in a
10876 middle of some value chain. */
10878 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10879 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10881 CORE_ADDR vaddr = value_address (v);
10885 len = (target_exact_watchpoints
10886 && is_scalar_type_recursive (vtype))?
10887 1 : TYPE_LENGTH (value_type (v));
10889 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10893 found_memory_cnt += num_regs;
10897 else if (VALUE_LVAL (v) != not_lval
10898 && deprecated_value_modifiable (v) == 0)
10899 return 0; /* These are values from the history (e.g., $1). */
10900 else if (VALUE_LVAL (v) == lval_register)
10901 return 0; /* Cannot watch a register with a HW watchpoint. */
10904 /* The expression itself looks suitable for using a hardware
10905 watchpoint, but give the target machine a chance to reject it. */
10906 return found_memory_cnt;
10910 watch_command_wrapper (const char *arg, int from_tty, int internal)
10912 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10915 /* A helper function that looks for the "-location" argument and then
10916 calls watch_command_1. */
10919 watch_maybe_just_location (const char *arg, int accessflag, int from_tty)
10921 int just_location = 0;
10924 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10925 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10927 arg = skip_spaces (arg);
10931 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10935 watch_command (const char *arg, int from_tty)
10937 watch_maybe_just_location (arg, hw_write, from_tty);
10941 rwatch_command_wrapper (const char *arg, int from_tty, int internal)
10943 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10947 rwatch_command (const char *arg, int from_tty)
10949 watch_maybe_just_location (arg, hw_read, from_tty);
10953 awatch_command_wrapper (const char *arg, int from_tty, int internal)
10955 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10959 awatch_command (const char *arg, int from_tty)
10961 watch_maybe_just_location (arg, hw_access, from_tty);
10965 /* Data for the FSM that manages the until(location)/advance commands
10966 in infcmd.c. Here because it uses the mechanisms of
10969 struct until_break_fsm
10971 /* The base class. */
10972 struct thread_fsm thread_fsm;
10974 /* The thread that as current when the command was executed. */
10977 /* The breakpoint set at the destination location. */
10978 struct breakpoint *location_breakpoint;
10980 /* Breakpoint set at the return address in the caller frame. May be
10982 struct breakpoint *caller_breakpoint;
10985 static void until_break_fsm_clean_up (struct thread_fsm *self,
10986 struct thread_info *thread);
10987 static int until_break_fsm_should_stop (struct thread_fsm *self,
10988 struct thread_info *thread);
10989 static enum async_reply_reason
10990 until_break_fsm_async_reply_reason (struct thread_fsm *self);
10992 /* until_break_fsm's vtable. */
10994 static struct thread_fsm_ops until_break_fsm_ops =
10997 until_break_fsm_clean_up,
10998 until_break_fsm_should_stop,
10999 NULL, /* return_value */
11000 until_break_fsm_async_reply_reason,
11003 /* Allocate a new until_break_command_fsm. */
11005 static struct until_break_fsm *
11006 new_until_break_fsm (struct interp *cmd_interp, int thread,
11007 breakpoint_up &&location_breakpoint,
11008 breakpoint_up &&caller_breakpoint)
11010 struct until_break_fsm *sm;
11012 sm = XCNEW (struct until_break_fsm);
11013 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
11015 sm->thread = thread;
11016 sm->location_breakpoint = location_breakpoint.release ();
11017 sm->caller_breakpoint = caller_breakpoint.release ();
11022 /* Implementation of the 'should_stop' FSM method for the
11023 until(location)/advance commands. */
11026 until_break_fsm_should_stop (struct thread_fsm *self,
11027 struct thread_info *tp)
11029 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11031 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11032 sm->location_breakpoint) != NULL
11033 || (sm->caller_breakpoint != NULL
11034 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11035 sm->caller_breakpoint) != NULL))
11036 thread_fsm_set_finished (self);
11041 /* Implementation of the 'clean_up' FSM method for the
11042 until(location)/advance commands. */
11045 until_break_fsm_clean_up (struct thread_fsm *self,
11046 struct thread_info *thread)
11048 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11050 /* Clean up our temporary breakpoints. */
11051 if (sm->location_breakpoint != NULL)
11053 delete_breakpoint (sm->location_breakpoint);
11054 sm->location_breakpoint = NULL;
11056 if (sm->caller_breakpoint != NULL)
11058 delete_breakpoint (sm->caller_breakpoint);
11059 sm->caller_breakpoint = NULL;
11061 delete_longjmp_breakpoint (sm->thread);
11064 /* Implementation of the 'async_reply_reason' FSM method for the
11065 until(location)/advance commands. */
11067 static enum async_reply_reason
11068 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11070 return EXEC_ASYNC_LOCATION_REACHED;
11074 until_break_command (const char *arg, int from_tty, int anywhere)
11076 struct frame_info *frame;
11077 struct gdbarch *frame_gdbarch;
11078 struct frame_id stack_frame_id;
11079 struct frame_id caller_frame_id;
11080 struct cleanup *old_chain;
11082 struct thread_info *tp;
11083 struct until_break_fsm *sm;
11085 clear_proceed_status (0);
11087 /* Set a breakpoint where the user wants it and at return from
11090 event_location_up location = string_to_event_location (&arg, current_language);
11092 std::vector<symtab_and_line> sals
11093 = (last_displayed_sal_is_valid ()
11094 ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
11095 get_last_displayed_symtab (),
11096 get_last_displayed_line ())
11097 : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
11098 NULL, (struct symtab *) NULL, 0));
11100 if (sals.size () != 1)
11101 error (_("Couldn't get information on specified line."));
11103 symtab_and_line &sal = sals[0];
11106 error (_("Junk at end of arguments."));
11108 resolve_sal_pc (&sal);
11110 tp = inferior_thread ();
11111 thread = tp->global_num;
11113 old_chain = make_cleanup (null_cleanup, NULL);
11115 /* Note linespec handling above invalidates the frame chain.
11116 Installing a breakpoint also invalidates the frame chain (as it
11117 may need to switch threads), so do any frame handling before
11120 frame = get_selected_frame (NULL);
11121 frame_gdbarch = get_frame_arch (frame);
11122 stack_frame_id = get_stack_frame_id (frame);
11123 caller_frame_id = frame_unwind_caller_id (frame);
11125 /* Keep within the current frame, or in frames called by the current
11128 breakpoint_up caller_breakpoint;
11129 if (frame_id_p (caller_frame_id))
11131 struct symtab_and_line sal2;
11132 struct gdbarch *caller_gdbarch;
11134 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11135 sal2.pc = frame_unwind_caller_pc (frame);
11136 caller_gdbarch = frame_unwind_caller_arch (frame);
11137 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11142 set_longjmp_breakpoint (tp, caller_frame_id);
11143 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11146 /* set_momentary_breakpoint could invalidate FRAME. */
11149 breakpoint_up location_breakpoint;
11151 /* If the user told us to continue until a specified location,
11152 we don't specify a frame at which we need to stop. */
11153 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11154 null_frame_id, bp_until);
11156 /* Otherwise, specify the selected frame, because we want to stop
11157 only at the very same frame. */
11158 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11159 stack_frame_id, bp_until);
11161 sm = new_until_break_fsm (command_interp (), tp->global_num,
11162 std::move (location_breakpoint),
11163 std::move (caller_breakpoint));
11164 tp->thread_fsm = &sm->thread_fsm;
11166 discard_cleanups (old_chain);
11168 proceed (-1, GDB_SIGNAL_DEFAULT);
11171 /* This function attempts to parse an optional "if <cond>" clause
11172 from the arg string. If one is not found, it returns NULL.
11174 Else, it returns a pointer to the condition string. (It does not
11175 attempt to evaluate the string against a particular block.) And,
11176 it updates arg to point to the first character following the parsed
11177 if clause in the arg string. */
11180 ep_parse_optional_if_clause (const char **arg)
11182 const char *cond_string;
11184 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11187 /* Skip the "if" keyword. */
11190 /* Skip any extra leading whitespace, and record the start of the
11191 condition string. */
11192 *arg = skip_spaces (*arg);
11193 cond_string = *arg;
11195 /* Assume that the condition occupies the remainder of the arg
11197 (*arg) += strlen (cond_string);
11199 return cond_string;
11202 /* Commands to deal with catching events, such as signals, exceptions,
11203 process start/exit, etc. */
11207 catch_fork_temporary, catch_vfork_temporary,
11208 catch_fork_permanent, catch_vfork_permanent
11213 catch_fork_command_1 (const char *arg, int from_tty,
11214 struct cmd_list_element *command)
11216 struct gdbarch *gdbarch = get_current_arch ();
11217 const char *cond_string = NULL;
11218 catch_fork_kind fork_kind;
11221 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11222 tempflag = (fork_kind == catch_fork_temporary
11223 || fork_kind == catch_vfork_temporary);
11227 arg = skip_spaces (arg);
11229 /* The allowed syntax is:
11231 catch [v]fork if <cond>
11233 First, check if there's an if clause. */
11234 cond_string = ep_parse_optional_if_clause (&arg);
11236 if ((*arg != '\0') && !isspace (*arg))
11237 error (_("Junk at end of arguments."));
11239 /* If this target supports it, create a fork or vfork catchpoint
11240 and enable reporting of such events. */
11243 case catch_fork_temporary:
11244 case catch_fork_permanent:
11245 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11246 &catch_fork_breakpoint_ops);
11248 case catch_vfork_temporary:
11249 case catch_vfork_permanent:
11250 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11251 &catch_vfork_breakpoint_ops);
11254 error (_("unsupported or unknown fork kind; cannot catch it"));
11260 catch_exec_command_1 (const char *arg, int from_tty,
11261 struct cmd_list_element *command)
11263 struct gdbarch *gdbarch = get_current_arch ();
11265 const char *cond_string = NULL;
11267 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11271 arg = skip_spaces (arg);
11273 /* The allowed syntax is:
11275 catch exec if <cond>
11277 First, check if there's an if clause. */
11278 cond_string = ep_parse_optional_if_clause (&arg);
11280 if ((*arg != '\0') && !isspace (*arg))
11281 error (_("Junk at end of arguments."));
11283 std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
11284 init_catchpoint (c.get (), gdbarch, tempflag, cond_string,
11285 &catch_exec_breakpoint_ops);
11286 c->exec_pathname = NULL;
11288 install_breakpoint (0, std::move (c), 1);
11292 init_ada_exception_breakpoint (struct breakpoint *b,
11293 struct gdbarch *gdbarch,
11294 struct symtab_and_line sal,
11295 const char *addr_string,
11296 const struct breakpoint_ops *ops,
11303 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11305 loc_gdbarch = gdbarch;
11307 describe_other_breakpoints (loc_gdbarch,
11308 sal.pspace, sal.pc, sal.section, -1);
11309 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11310 version for exception catchpoints, because two catchpoints
11311 used for different exception names will use the same address.
11312 In this case, a "breakpoint ... also set at..." warning is
11313 unproductive. Besides, the warning phrasing is also a bit
11314 inappropriate, we should use the word catchpoint, and tell
11315 the user what type of catchpoint it is. The above is good
11316 enough for now, though. */
11319 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11321 b->enable_state = enabled ? bp_enabled : bp_disabled;
11322 b->disposition = tempflag ? disp_del : disp_donttouch;
11323 b->location = string_to_event_location (&addr_string,
11324 language_def (language_ada));
11325 b->language = language_ada;
11329 catch_command (const char *arg, int from_tty)
11331 error (_("Catch requires an event name."));
11336 tcatch_command (const char *arg, int from_tty)
11338 error (_("Catch requires an event name."));
11341 /* Compare two breakpoints and return a strcmp-like result. */
11344 compare_breakpoints (const breakpoint *a, const breakpoint *b)
11346 uintptr_t ua = (uintptr_t) a;
11347 uintptr_t ub = (uintptr_t) b;
11349 if (a->number < b->number)
11351 else if (a->number > b->number)
11354 /* Now sort by address, in case we see, e..g, two breakpoints with
11358 return ua > ub ? 1 : 0;
11361 /* Delete breakpoints by address or line. */
11364 clear_command (const char *arg, int from_tty)
11366 struct breakpoint *b;
11369 std::vector<symtab_and_line> decoded_sals;
11370 symtab_and_line last_sal;
11371 gdb::array_view<symtab_and_line> sals;
11375 = decode_line_with_current_source (arg,
11376 (DECODE_LINE_FUNFIRSTLINE
11377 | DECODE_LINE_LIST_MODE));
11379 sals = decoded_sals;
11383 /* Set sal's line, symtab, pc, and pspace to the values
11384 corresponding to the last call to print_frame_info. If the
11385 codepoint is not valid, this will set all the fields to 0. */
11386 last_sal = get_last_displayed_sal ();
11387 if (last_sal.symtab == 0)
11388 error (_("No source file specified."));
11394 /* We don't call resolve_sal_pc here. That's not as bad as it
11395 seems, because all existing breakpoints typically have both
11396 file/line and pc set. So, if clear is given file/line, we can
11397 match this to existing breakpoint without obtaining pc at all.
11399 We only support clearing given the address explicitly
11400 present in breakpoint table. Say, we've set breakpoint
11401 at file:line. There were several PC values for that file:line,
11402 due to optimization, all in one block.
11404 We've picked one PC value. If "clear" is issued with another
11405 PC corresponding to the same file:line, the breakpoint won't
11406 be cleared. We probably can still clear the breakpoint, but
11407 since the other PC value is never presented to user, user
11408 can only find it by guessing, and it does not seem important
11409 to support that. */
11411 /* For each line spec given, delete bps which correspond to it. Do
11412 it in two passes, solely to preserve the current behavior that
11413 from_tty is forced true if we delete more than one
11416 std::vector<struct breakpoint *> found;
11417 for (const auto &sal : sals)
11419 const char *sal_fullname;
11421 /* If exact pc given, clear bpts at that pc.
11422 If line given (pc == 0), clear all bpts on specified line.
11423 If defaulting, clear all bpts on default line
11426 defaulting sal.pc != 0 tests to do
11431 1 0 <can't happen> */
11433 sal_fullname = (sal.symtab == NULL
11434 ? NULL : symtab_to_fullname (sal.symtab));
11436 /* Find all matching breakpoints and add them to 'found'. */
11437 ALL_BREAKPOINTS (b)
11440 /* Are we going to delete b? */
11441 if (b->type != bp_none && !is_watchpoint (b))
11443 struct bp_location *loc = b->loc;
11444 for (; loc; loc = loc->next)
11446 /* If the user specified file:line, don't allow a PC
11447 match. This matches historical gdb behavior. */
11448 int pc_match = (!sal.explicit_line
11450 && (loc->pspace == sal.pspace)
11451 && (loc->address == sal.pc)
11452 && (!section_is_overlay (loc->section)
11453 || loc->section == sal.section));
11454 int line_match = 0;
11456 if ((default_match || sal.explicit_line)
11457 && loc->symtab != NULL
11458 && sal_fullname != NULL
11459 && sal.pspace == loc->pspace
11460 && loc->line_number == sal.line
11461 && filename_cmp (symtab_to_fullname (loc->symtab),
11462 sal_fullname) == 0)
11465 if (pc_match || line_match)
11474 found.push_back (b);
11478 /* Now go thru the 'found' chain and delete them. */
11479 if (found.empty ())
11482 error (_("No breakpoint at %s."), arg);
11484 error (_("No breakpoint at this line."));
11487 /* Remove duplicates from the vec. */
11488 std::sort (found.begin (), found.end (),
11489 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11491 return compare_breakpoints (bp_a, bp_b) < 0;
11493 found.erase (std::unique (found.begin (), found.end (),
11494 [] (const breakpoint *bp_a, const breakpoint *bp_b)
11496 return compare_breakpoints (bp_a, bp_b) == 0;
11500 if (found.size () > 1)
11501 from_tty = 1; /* Always report if deleted more than one. */
11504 if (found.size () == 1)
11505 printf_unfiltered (_("Deleted breakpoint "));
11507 printf_unfiltered (_("Deleted breakpoints "));
11510 for (breakpoint *iter : found)
11513 printf_unfiltered ("%d ", iter->number);
11514 delete_breakpoint (iter);
11517 putchar_unfiltered ('\n');
11520 /* Delete breakpoint in BS if they are `delete' breakpoints and
11521 all breakpoints that are marked for deletion, whether hit or not.
11522 This is called after any breakpoint is hit, or after errors. */
11525 breakpoint_auto_delete (bpstat bs)
11527 struct breakpoint *b, *b_tmp;
11529 for (; bs; bs = bs->next)
11530 if (bs->breakpoint_at
11531 && bs->breakpoint_at->disposition == disp_del
11533 delete_breakpoint (bs->breakpoint_at);
11535 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11537 if (b->disposition == disp_del_at_next_stop)
11538 delete_breakpoint (b);
11542 /* A comparison function for bp_location AP and BP being interfaced to
11543 qsort. Sort elements primarily by their ADDRESS (no matter what
11544 does breakpoint_address_is_meaningful say for its OWNER),
11545 secondarily by ordering first permanent elements and
11546 terciarily just ensuring the array is sorted stable way despite
11547 qsort being an unstable algorithm. */
11550 bp_locations_compare (const void *ap, const void *bp)
11552 const struct bp_location *a = *(const struct bp_location **) ap;
11553 const struct bp_location *b = *(const struct bp_location **) bp;
11555 if (a->address != b->address)
11556 return (a->address > b->address) - (a->address < b->address);
11558 /* Sort locations at the same address by their pspace number, keeping
11559 locations of the same inferior (in a multi-inferior environment)
11562 if (a->pspace->num != b->pspace->num)
11563 return ((a->pspace->num > b->pspace->num)
11564 - (a->pspace->num < b->pspace->num));
11566 /* Sort permanent breakpoints first. */
11567 if (a->permanent != b->permanent)
11568 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
11570 /* Make the internal GDB representation stable across GDB runs
11571 where A and B memory inside GDB can differ. Breakpoint locations of
11572 the same type at the same address can be sorted in arbitrary order. */
11574 if (a->owner->number != b->owner->number)
11575 return ((a->owner->number > b->owner->number)
11576 - (a->owner->number < b->owner->number));
11578 return (a > b) - (a < b);
11581 /* Set bp_locations_placed_address_before_address_max and
11582 bp_locations_shadow_len_after_address_max according to the current
11583 content of the bp_locations array. */
11586 bp_locations_target_extensions_update (void)
11588 struct bp_location *bl, **blp_tmp;
11590 bp_locations_placed_address_before_address_max = 0;
11591 bp_locations_shadow_len_after_address_max = 0;
11593 ALL_BP_LOCATIONS (bl, blp_tmp)
11595 CORE_ADDR start, end, addr;
11597 if (!bp_location_has_shadow (bl))
11600 start = bl->target_info.placed_address;
11601 end = start + bl->target_info.shadow_len;
11603 gdb_assert (bl->address >= start);
11604 addr = bl->address - start;
11605 if (addr > bp_locations_placed_address_before_address_max)
11606 bp_locations_placed_address_before_address_max = addr;
11608 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11610 gdb_assert (bl->address < end);
11611 addr = end - bl->address;
11612 if (addr > bp_locations_shadow_len_after_address_max)
11613 bp_locations_shadow_len_after_address_max = addr;
11617 /* Download tracepoint locations if they haven't been. */
11620 download_tracepoint_locations (void)
11622 struct breakpoint *b;
11623 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
11625 scoped_restore_current_pspace_and_thread restore_pspace_thread;
11627 ALL_TRACEPOINTS (b)
11629 struct bp_location *bl;
11630 struct tracepoint *t;
11631 int bp_location_downloaded = 0;
11633 if ((b->type == bp_fast_tracepoint
11634 ? !may_insert_fast_tracepoints
11635 : !may_insert_tracepoints))
11638 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
11640 if (target_can_download_tracepoint ())
11641 can_download_tracepoint = TRIBOOL_TRUE;
11643 can_download_tracepoint = TRIBOOL_FALSE;
11646 if (can_download_tracepoint == TRIBOOL_FALSE)
11649 for (bl = b->loc; bl; bl = bl->next)
11651 /* In tracepoint, locations are _never_ duplicated, so
11652 should_be_inserted is equivalent to
11653 unduplicated_should_be_inserted. */
11654 if (!should_be_inserted (bl) || bl->inserted)
11657 switch_to_program_space_and_thread (bl->pspace);
11659 target_download_tracepoint (bl);
11662 bp_location_downloaded = 1;
11664 t = (struct tracepoint *) b;
11665 t->number_on_target = b->number;
11666 if (bp_location_downloaded)
11667 gdb::observers::breakpoint_modified.notify (b);
11671 /* Swap the insertion/duplication state between two locations. */
11674 swap_insertion (struct bp_location *left, struct bp_location *right)
11676 const int left_inserted = left->inserted;
11677 const int left_duplicate = left->duplicate;
11678 const int left_needs_update = left->needs_update;
11679 const struct bp_target_info left_target_info = left->target_info;
11681 /* Locations of tracepoints can never be duplicated. */
11682 if (is_tracepoint (left->owner))
11683 gdb_assert (!left->duplicate);
11684 if (is_tracepoint (right->owner))
11685 gdb_assert (!right->duplicate);
11687 left->inserted = right->inserted;
11688 left->duplicate = right->duplicate;
11689 left->needs_update = right->needs_update;
11690 left->target_info = right->target_info;
11691 right->inserted = left_inserted;
11692 right->duplicate = left_duplicate;
11693 right->needs_update = left_needs_update;
11694 right->target_info = left_target_info;
11697 /* Force the re-insertion of the locations at ADDRESS. This is called
11698 once a new/deleted/modified duplicate location is found and we are evaluating
11699 conditions on the target's side. Such conditions need to be updated on
11703 force_breakpoint_reinsertion (struct bp_location *bl)
11705 struct bp_location **locp = NULL, **loc2p;
11706 struct bp_location *loc;
11707 CORE_ADDR address = 0;
11710 address = bl->address;
11711 pspace_num = bl->pspace->num;
11713 /* This is only meaningful if the target is
11714 evaluating conditions and if the user has
11715 opted for condition evaluation on the target's
11717 if (gdb_evaluates_breakpoint_condition_p ()
11718 || !target_supports_evaluation_of_breakpoint_conditions ())
11721 /* Flag all breakpoint locations with this address and
11722 the same program space as the location
11723 as "its condition has changed". We need to
11724 update the conditions on the target's side. */
11725 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11729 if (!is_breakpoint (loc->owner)
11730 || pspace_num != loc->pspace->num)
11733 /* Flag the location appropriately. We use a different state to
11734 let everyone know that we already updated the set of locations
11735 with addr bl->address and program space bl->pspace. This is so
11736 we don't have to keep calling these functions just to mark locations
11737 that have already been marked. */
11738 loc->condition_changed = condition_updated;
11740 /* Free the agent expression bytecode as well. We will compute
11742 loc->cond_bytecode.reset ();
11745 /* Called whether new breakpoints are created, or existing breakpoints
11746 deleted, to update the global location list and recompute which
11747 locations are duplicate of which.
11749 The INSERT_MODE flag determines whether locations may not, may, or
11750 shall be inserted now. See 'enum ugll_insert_mode' for more
11754 update_global_location_list (enum ugll_insert_mode insert_mode)
11756 struct breakpoint *b;
11757 struct bp_location **locp, *loc;
11758 /* Last breakpoint location address that was marked for update. */
11759 CORE_ADDR last_addr = 0;
11760 /* Last breakpoint location program space that was marked for update. */
11761 int last_pspace_num = -1;
11763 /* Used in the duplicates detection below. When iterating over all
11764 bp_locations, points to the first bp_location of a given address.
11765 Breakpoints and watchpoints of different types are never
11766 duplicates of each other. Keep one pointer for each type of
11767 breakpoint/watchpoint, so we only need to loop over all locations
11769 struct bp_location *bp_loc_first; /* breakpoint */
11770 struct bp_location *wp_loc_first; /* hardware watchpoint */
11771 struct bp_location *awp_loc_first; /* access watchpoint */
11772 struct bp_location *rwp_loc_first; /* read watchpoint */
11774 /* Saved former bp_locations array which we compare against the newly
11775 built bp_locations from the current state of ALL_BREAKPOINTS. */
11776 struct bp_location **old_locp;
11777 unsigned old_locations_count;
11778 gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations);
11780 old_locations_count = bp_locations_count;
11781 bp_locations = NULL;
11782 bp_locations_count = 0;
11784 ALL_BREAKPOINTS (b)
11785 for (loc = b->loc; loc; loc = loc->next)
11786 bp_locations_count++;
11788 bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
11789 locp = bp_locations;
11790 ALL_BREAKPOINTS (b)
11791 for (loc = b->loc; loc; loc = loc->next)
11793 qsort (bp_locations, bp_locations_count, sizeof (*bp_locations),
11794 bp_locations_compare);
11796 bp_locations_target_extensions_update ();
11798 /* Identify bp_location instances that are no longer present in the
11799 new list, and therefore should be freed. Note that it's not
11800 necessary that those locations should be removed from inferior --
11801 if there's another location at the same address (previously
11802 marked as duplicate), we don't need to remove/insert the
11805 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11806 and former bp_location array state respectively. */
11808 locp = bp_locations;
11809 for (old_locp = old_locations.get ();
11810 old_locp < old_locations.get () + old_locations_count;
11813 struct bp_location *old_loc = *old_locp;
11814 struct bp_location **loc2p;
11816 /* Tells if 'old_loc' is found among the new locations. If
11817 not, we have to free it. */
11818 int found_object = 0;
11819 /* Tells if the location should remain inserted in the target. */
11820 int keep_in_target = 0;
11823 /* Skip LOCP entries which will definitely never be needed.
11824 Stop either at or being the one matching OLD_LOC. */
11825 while (locp < bp_locations + bp_locations_count
11826 && (*locp)->address < old_loc->address)
11830 (loc2p < bp_locations + bp_locations_count
11831 && (*loc2p)->address == old_loc->address);
11834 /* Check if this is a new/duplicated location or a duplicated
11835 location that had its condition modified. If so, we want to send
11836 its condition to the target if evaluation of conditions is taking
11838 if ((*loc2p)->condition_changed == condition_modified
11839 && (last_addr != old_loc->address
11840 || last_pspace_num != old_loc->pspace->num))
11842 force_breakpoint_reinsertion (*loc2p);
11843 last_pspace_num = old_loc->pspace->num;
11846 if (*loc2p == old_loc)
11850 /* We have already handled this address, update it so that we don't
11851 have to go through updates again. */
11852 last_addr = old_loc->address;
11854 /* Target-side condition evaluation: Handle deleted locations. */
11856 force_breakpoint_reinsertion (old_loc);
11858 /* If this location is no longer present, and inserted, look if
11859 there's maybe a new location at the same address. If so,
11860 mark that one inserted, and don't remove this one. This is
11861 needed so that we don't have a time window where a breakpoint
11862 at certain location is not inserted. */
11864 if (old_loc->inserted)
11866 /* If the location is inserted now, we might have to remove
11869 if (found_object && should_be_inserted (old_loc))
11871 /* The location is still present in the location list,
11872 and still should be inserted. Don't do anything. */
11873 keep_in_target = 1;
11877 /* This location still exists, but it won't be kept in the
11878 target since it may have been disabled. We proceed to
11879 remove its target-side condition. */
11881 /* The location is either no longer present, or got
11882 disabled. See if there's another location at the
11883 same address, in which case we don't need to remove
11884 this one from the target. */
11886 /* OLD_LOC comes from existing struct breakpoint. */
11887 if (breakpoint_address_is_meaningful (old_loc->owner))
11890 (loc2p < bp_locations + bp_locations_count
11891 && (*loc2p)->address == old_loc->address);
11894 struct bp_location *loc2 = *loc2p;
11896 if (breakpoint_locations_match (loc2, old_loc))
11898 /* Read watchpoint locations are switched to
11899 access watchpoints, if the former are not
11900 supported, but the latter are. */
11901 if (is_hardware_watchpoint (old_loc->owner))
11903 gdb_assert (is_hardware_watchpoint (loc2->owner));
11904 loc2->watchpoint_type = old_loc->watchpoint_type;
11907 /* loc2 is a duplicated location. We need to check
11908 if it should be inserted in case it will be
11910 if (loc2 != old_loc
11911 && unduplicated_should_be_inserted (loc2))
11913 swap_insertion (old_loc, loc2);
11914 keep_in_target = 1;
11922 if (!keep_in_target)
11924 if (remove_breakpoint (old_loc))
11926 /* This is just about all we can do. We could keep
11927 this location on the global list, and try to
11928 remove it next time, but there's no particular
11929 reason why we will succeed next time.
11931 Note that at this point, old_loc->owner is still
11932 valid, as delete_breakpoint frees the breakpoint
11933 only after calling us. */
11934 printf_filtered (_("warning: Error removing "
11935 "breakpoint %d\n"),
11936 old_loc->owner->number);
11944 if (removed && target_is_non_stop_p ()
11945 && need_moribund_for_location_type (old_loc))
11947 /* This location was removed from the target. In
11948 non-stop mode, a race condition is possible where
11949 we've removed a breakpoint, but stop events for that
11950 breakpoint are already queued and will arrive later.
11951 We apply an heuristic to be able to distinguish such
11952 SIGTRAPs from other random SIGTRAPs: we keep this
11953 breakpoint location for a bit, and will retire it
11954 after we see some number of events. The theory here
11955 is that reporting of events should, "on the average",
11956 be fair, so after a while we'll see events from all
11957 threads that have anything of interest, and no longer
11958 need to keep this breakpoint location around. We
11959 don't hold locations forever so to reduce chances of
11960 mistaking a non-breakpoint SIGTRAP for a breakpoint
11963 The heuristic failing can be disastrous on
11964 decr_pc_after_break targets.
11966 On decr_pc_after_break targets, like e.g., x86-linux,
11967 if we fail to recognize a late breakpoint SIGTRAP,
11968 because events_till_retirement has reached 0 too
11969 soon, we'll fail to do the PC adjustment, and report
11970 a random SIGTRAP to the user. When the user resumes
11971 the inferior, it will most likely immediately crash
11972 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11973 corrupted, because of being resumed e.g., in the
11974 middle of a multi-byte instruction, or skipped a
11975 one-byte instruction. This was actually seen happen
11976 on native x86-linux, and should be less rare on
11977 targets that do not support new thread events, like
11978 remote, due to the heuristic depending on
11981 Mistaking a random SIGTRAP for a breakpoint trap
11982 causes similar symptoms (PC adjustment applied when
11983 it shouldn't), but then again, playing with SIGTRAPs
11984 behind the debugger's back is asking for trouble.
11986 Since hardware watchpoint traps are always
11987 distinguishable from other traps, so we don't need to
11988 apply keep hardware watchpoint moribund locations
11989 around. We simply always ignore hardware watchpoint
11990 traps we can no longer explain. */
11992 old_loc->events_till_retirement = 3 * (thread_count () + 1);
11993 old_loc->owner = NULL;
11995 moribund_locations.push_back (old_loc);
11999 old_loc->owner = NULL;
12000 decref_bp_location (&old_loc);
12005 /* Rescan breakpoints at the same address and section, marking the
12006 first one as "first" and any others as "duplicates". This is so
12007 that the bpt instruction is only inserted once. If we have a
12008 permanent breakpoint at the same place as BPT, make that one the
12009 official one, and the rest as duplicates. Permanent breakpoints
12010 are sorted first for the same address.
12012 Do the same for hardware watchpoints, but also considering the
12013 watchpoint's type (regular/access/read) and length. */
12015 bp_loc_first = NULL;
12016 wp_loc_first = NULL;
12017 awp_loc_first = NULL;
12018 rwp_loc_first = NULL;
12019 ALL_BP_LOCATIONS (loc, locp)
12021 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12023 struct bp_location **loc_first_p;
12026 if (!unduplicated_should_be_inserted (loc)
12027 || !breakpoint_address_is_meaningful (b)
12028 /* Don't detect duplicate for tracepoint locations because they are
12029 never duplicated. See the comments in field `duplicate' of
12030 `struct bp_location'. */
12031 || is_tracepoint (b))
12033 /* Clear the condition modification flag. */
12034 loc->condition_changed = condition_unchanged;
12038 if (b->type == bp_hardware_watchpoint)
12039 loc_first_p = &wp_loc_first;
12040 else if (b->type == bp_read_watchpoint)
12041 loc_first_p = &rwp_loc_first;
12042 else if (b->type == bp_access_watchpoint)
12043 loc_first_p = &awp_loc_first;
12045 loc_first_p = &bp_loc_first;
12047 if (*loc_first_p == NULL
12048 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12049 || !breakpoint_locations_match (loc, *loc_first_p))
12051 *loc_first_p = loc;
12052 loc->duplicate = 0;
12054 if (is_breakpoint (loc->owner) && loc->condition_changed)
12056 loc->needs_update = 1;
12057 /* Clear the condition modification flag. */
12058 loc->condition_changed = condition_unchanged;
12064 /* This and the above ensure the invariant that the first location
12065 is not duplicated, and is the inserted one.
12066 All following are marked as duplicated, and are not inserted. */
12068 swap_insertion (loc, *loc_first_p);
12069 loc->duplicate = 1;
12071 /* Clear the condition modification flag. */
12072 loc->condition_changed = condition_unchanged;
12075 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12077 if (insert_mode != UGLL_DONT_INSERT)
12078 insert_breakpoint_locations ();
12081 /* Even though the caller told us to not insert new
12082 locations, we may still need to update conditions on the
12083 target's side of breakpoints that were already inserted
12084 if the target is evaluating breakpoint conditions. We
12085 only update conditions for locations that are marked
12087 update_inserted_breakpoint_locations ();
12091 if (insert_mode != UGLL_DONT_INSERT)
12092 download_tracepoint_locations ();
12096 breakpoint_retire_moribund (void)
12098 for (int ix = 0; ix < moribund_locations.size (); ++ix)
12100 struct bp_location *loc = moribund_locations[ix];
12101 if (--(loc->events_till_retirement) == 0)
12103 decref_bp_location (&loc);
12104 unordered_remove (moribund_locations, ix);
12111 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12116 update_global_location_list (insert_mode);
12118 CATCH (e, RETURN_MASK_ERROR)
12124 /* Clear BKP from a BPS. */
12127 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12131 for (bs = bps; bs; bs = bs->next)
12132 if (bs->breakpoint_at == bpt)
12134 bs->breakpoint_at = NULL;
12135 bs->old_val = NULL;
12136 /* bs->commands will be freed later. */
12140 /* Callback for iterate_over_threads. */
12142 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12144 struct breakpoint *bpt = (struct breakpoint *) data;
12146 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12150 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12154 say_where (struct breakpoint *b)
12156 struct value_print_options opts;
12158 get_user_print_options (&opts);
12160 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12162 if (b->loc == NULL)
12164 /* For pending locations, the output differs slightly based
12165 on b->extra_string. If this is non-NULL, it contains either
12166 a condition or dprintf arguments. */
12167 if (b->extra_string == NULL)
12169 printf_filtered (_(" (%s) pending."),
12170 event_location_to_string (b->location.get ()));
12172 else if (b->type == bp_dprintf)
12174 printf_filtered (_(" (%s,%s) pending."),
12175 event_location_to_string (b->location.get ()),
12180 printf_filtered (_(" (%s %s) pending."),
12181 event_location_to_string (b->location.get ()),
12187 if (opts.addressprint || b->loc->symtab == NULL)
12189 printf_filtered (" at ");
12190 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12193 if (b->loc->symtab != NULL)
12195 /* If there is a single location, we can print the location
12197 if (b->loc->next == NULL)
12198 printf_filtered (": file %s, line %d.",
12199 symtab_to_filename_for_display (b->loc->symtab),
12200 b->loc->line_number);
12202 /* This is not ideal, but each location may have a
12203 different file name, and this at least reflects the
12204 real situation somewhat. */
12205 printf_filtered (": %s.",
12206 event_location_to_string (b->location.get ()));
12211 struct bp_location *loc = b->loc;
12213 for (; loc; loc = loc->next)
12215 printf_filtered (" (%d locations)", n);
12220 /* Default bp_location_ops methods. */
12223 bp_location_dtor (struct bp_location *self)
12225 xfree (self->function_name);
12228 static const struct bp_location_ops bp_location_ops =
12233 /* Destructor for the breakpoint base class. */
12235 breakpoint::~breakpoint ()
12237 xfree (this->cond_string);
12238 xfree (this->extra_string);
12239 xfree (this->filter);
12242 static struct bp_location *
12243 base_breakpoint_allocate_location (struct breakpoint *self)
12245 return new bp_location (&bp_location_ops, self);
12249 base_breakpoint_re_set (struct breakpoint *b)
12251 /* Nothing to re-set. */
12254 #define internal_error_pure_virtual_called() \
12255 gdb_assert_not_reached ("pure virtual function called")
12258 base_breakpoint_insert_location (struct bp_location *bl)
12260 internal_error_pure_virtual_called ();
12264 base_breakpoint_remove_location (struct bp_location *bl,
12265 enum remove_bp_reason reason)
12267 internal_error_pure_virtual_called ();
12271 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12272 const address_space *aspace,
12274 const struct target_waitstatus *ws)
12276 internal_error_pure_virtual_called ();
12280 base_breakpoint_check_status (bpstat bs)
12285 /* A "works_in_software_mode" breakpoint_ops method that just internal
12289 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12291 internal_error_pure_virtual_called ();
12294 /* A "resources_needed" breakpoint_ops method that just internal
12298 base_breakpoint_resources_needed (const struct bp_location *bl)
12300 internal_error_pure_virtual_called ();
12303 static enum print_stop_action
12304 base_breakpoint_print_it (bpstat bs)
12306 internal_error_pure_virtual_called ();
12310 base_breakpoint_print_one_detail (const struct breakpoint *self,
12311 struct ui_out *uiout)
12317 base_breakpoint_print_mention (struct breakpoint *b)
12319 internal_error_pure_virtual_called ();
12323 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12325 internal_error_pure_virtual_called ();
12329 base_breakpoint_create_sals_from_location
12330 (const struct event_location *location,
12331 struct linespec_result *canonical,
12332 enum bptype type_wanted)
12334 internal_error_pure_virtual_called ();
12338 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12339 struct linespec_result *c,
12340 gdb::unique_xmalloc_ptr<char> cond_string,
12341 gdb::unique_xmalloc_ptr<char> extra_string,
12342 enum bptype type_wanted,
12343 enum bpdisp disposition,
12345 int task, int ignore_count,
12346 const struct breakpoint_ops *o,
12347 int from_tty, int enabled,
12348 int internal, unsigned flags)
12350 internal_error_pure_virtual_called ();
12353 static std::vector<symtab_and_line>
12354 base_breakpoint_decode_location (struct breakpoint *b,
12355 const struct event_location *location,
12356 struct program_space *search_pspace)
12358 internal_error_pure_virtual_called ();
12361 /* The default 'explains_signal' method. */
12364 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12369 /* The default "after_condition_true" method. */
12372 base_breakpoint_after_condition_true (struct bpstats *bs)
12374 /* Nothing to do. */
12377 struct breakpoint_ops base_breakpoint_ops =
12379 base_breakpoint_allocate_location,
12380 base_breakpoint_re_set,
12381 base_breakpoint_insert_location,
12382 base_breakpoint_remove_location,
12383 base_breakpoint_breakpoint_hit,
12384 base_breakpoint_check_status,
12385 base_breakpoint_resources_needed,
12386 base_breakpoint_works_in_software_mode,
12387 base_breakpoint_print_it,
12389 base_breakpoint_print_one_detail,
12390 base_breakpoint_print_mention,
12391 base_breakpoint_print_recreate,
12392 base_breakpoint_create_sals_from_location,
12393 base_breakpoint_create_breakpoints_sal,
12394 base_breakpoint_decode_location,
12395 base_breakpoint_explains_signal,
12396 base_breakpoint_after_condition_true,
12399 /* Default breakpoint_ops methods. */
12402 bkpt_re_set (struct breakpoint *b)
12404 /* FIXME: is this still reachable? */
12405 if (breakpoint_event_location_empty_p (b))
12407 /* Anything without a location can't be re-set. */
12408 delete_breakpoint (b);
12412 breakpoint_re_set_default (b);
12416 bkpt_insert_location (struct bp_location *bl)
12418 CORE_ADDR addr = bl->target_info.reqstd_address;
12420 bl->target_info.kind = breakpoint_kind (bl, &addr);
12421 bl->target_info.placed_address = addr;
12423 if (bl->loc_type == bp_loc_hardware_breakpoint)
12424 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
12426 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
12430 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
12432 if (bl->loc_type == bp_loc_hardware_breakpoint)
12433 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12435 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
12439 bkpt_breakpoint_hit (const struct bp_location *bl,
12440 const address_space *aspace, CORE_ADDR bp_addr,
12441 const struct target_waitstatus *ws)
12443 if (ws->kind != TARGET_WAITKIND_STOPPED
12444 || ws->value.sig != GDB_SIGNAL_TRAP)
12447 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12451 if (overlay_debugging /* unmapped overlay section */
12452 && section_is_overlay (bl->section)
12453 && !section_is_mapped (bl->section))
12460 dprintf_breakpoint_hit (const struct bp_location *bl,
12461 const address_space *aspace, CORE_ADDR bp_addr,
12462 const struct target_waitstatus *ws)
12464 if (dprintf_style == dprintf_style_agent
12465 && target_can_run_breakpoint_commands ())
12467 /* An agent-style dprintf never causes a stop. If we see a trap
12468 for this address it must be for a breakpoint that happens to
12469 be set at the same address. */
12473 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
12477 bkpt_resources_needed (const struct bp_location *bl)
12479 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12484 static enum print_stop_action
12485 bkpt_print_it (bpstat bs)
12487 struct breakpoint *b;
12488 const struct bp_location *bl;
12490 struct ui_out *uiout = current_uiout;
12492 gdb_assert (bs->bp_location_at != NULL);
12494 bl = bs->bp_location_at;
12495 b = bs->breakpoint_at;
12497 bp_temp = b->disposition == disp_del;
12498 if (bl->address != bl->requested_address)
12499 breakpoint_adjustment_warning (bl->requested_address,
12502 annotate_breakpoint (b->number);
12503 maybe_print_thread_hit_breakpoint (uiout);
12506 uiout->text ("Temporary breakpoint ");
12508 uiout->text ("Breakpoint ");
12509 if (uiout->is_mi_like_p ())
12511 uiout->field_string ("reason",
12512 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12513 uiout->field_string ("disp", bpdisp_text (b->disposition));
12515 uiout->field_int ("bkptno", b->number);
12516 uiout->text (", ");
12518 return PRINT_SRC_AND_LOC;
12522 bkpt_print_mention (struct breakpoint *b)
12524 if (current_uiout->is_mi_like_p ())
12529 case bp_breakpoint:
12530 case bp_gnu_ifunc_resolver:
12531 if (b->disposition == disp_del)
12532 printf_filtered (_("Temporary breakpoint"));
12534 printf_filtered (_("Breakpoint"));
12535 printf_filtered (_(" %d"), b->number);
12536 if (b->type == bp_gnu_ifunc_resolver)
12537 printf_filtered (_(" at gnu-indirect-function resolver"));
12539 case bp_hardware_breakpoint:
12540 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12543 printf_filtered (_("Dprintf %d"), b->number);
12551 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12553 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12554 fprintf_unfiltered (fp, "tbreak");
12555 else if (tp->type == bp_breakpoint)
12556 fprintf_unfiltered (fp, "break");
12557 else if (tp->type == bp_hardware_breakpoint
12558 && tp->disposition == disp_del)
12559 fprintf_unfiltered (fp, "thbreak");
12560 else if (tp->type == bp_hardware_breakpoint)
12561 fprintf_unfiltered (fp, "hbreak");
12563 internal_error (__FILE__, __LINE__,
12564 _("unhandled breakpoint type %d"), (int) tp->type);
12566 fprintf_unfiltered (fp, " %s",
12567 event_location_to_string (tp->location.get ()));
12569 /* Print out extra_string if this breakpoint is pending. It might
12570 contain, for example, conditions that were set by the user. */
12571 if (tp->loc == NULL && tp->extra_string != NULL)
12572 fprintf_unfiltered (fp, " %s", tp->extra_string);
12574 print_recreate_thread (tp, fp);
12578 bkpt_create_sals_from_location (const struct event_location *location,
12579 struct linespec_result *canonical,
12580 enum bptype type_wanted)
12582 create_sals_from_location_default (location, canonical, type_wanted);
12586 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12587 struct linespec_result *canonical,
12588 gdb::unique_xmalloc_ptr<char> cond_string,
12589 gdb::unique_xmalloc_ptr<char> extra_string,
12590 enum bptype type_wanted,
12591 enum bpdisp disposition,
12593 int task, int ignore_count,
12594 const struct breakpoint_ops *ops,
12595 int from_tty, int enabled,
12596 int internal, unsigned flags)
12598 create_breakpoints_sal_default (gdbarch, canonical,
12599 std::move (cond_string),
12600 std::move (extra_string),
12602 disposition, thread, task,
12603 ignore_count, ops, from_tty,
12604 enabled, internal, flags);
12607 static std::vector<symtab_and_line>
12608 bkpt_decode_location (struct breakpoint *b,
12609 const struct event_location *location,
12610 struct program_space *search_pspace)
12612 return decode_location_default (b, location, search_pspace);
12615 /* Virtual table for internal breakpoints. */
12618 internal_bkpt_re_set (struct breakpoint *b)
12622 /* Delete overlay event and longjmp master breakpoints; they
12623 will be reset later by breakpoint_re_set. */
12624 case bp_overlay_event:
12625 case bp_longjmp_master:
12626 case bp_std_terminate_master:
12627 case bp_exception_master:
12628 delete_breakpoint (b);
12631 /* This breakpoint is special, it's set up when the inferior
12632 starts and we really don't want to touch it. */
12633 case bp_shlib_event:
12635 /* Like bp_shlib_event, this breakpoint type is special. Once
12636 it is set up, we do not want to touch it. */
12637 case bp_thread_event:
12643 internal_bkpt_check_status (bpstat bs)
12645 if (bs->breakpoint_at->type == bp_shlib_event)
12647 /* If requested, stop when the dynamic linker notifies GDB of
12648 events. This allows the user to get control and place
12649 breakpoints in initializer routines for dynamically loaded
12650 objects (among other things). */
12651 bs->stop = stop_on_solib_events;
12652 bs->print = stop_on_solib_events;
12658 static enum print_stop_action
12659 internal_bkpt_print_it (bpstat bs)
12661 struct breakpoint *b;
12663 b = bs->breakpoint_at;
12667 case bp_shlib_event:
12668 /* Did we stop because the user set the stop_on_solib_events
12669 variable? (If so, we report this as a generic, "Stopped due
12670 to shlib event" message.) */
12671 print_solib_event (0);
12674 case bp_thread_event:
12675 /* Not sure how we will get here.
12676 GDB should not stop for these breakpoints. */
12677 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12680 case bp_overlay_event:
12681 /* By analogy with the thread event, GDB should not stop for these. */
12682 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12685 case bp_longjmp_master:
12686 /* These should never be enabled. */
12687 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12690 case bp_std_terminate_master:
12691 /* These should never be enabled. */
12692 printf_filtered (_("std::terminate Master Breakpoint: "
12693 "gdb should not stop!\n"));
12696 case bp_exception_master:
12697 /* These should never be enabled. */
12698 printf_filtered (_("Exception Master Breakpoint: "
12699 "gdb should not stop!\n"));
12703 return PRINT_NOTHING;
12707 internal_bkpt_print_mention (struct breakpoint *b)
12709 /* Nothing to mention. These breakpoints are internal. */
12712 /* Virtual table for momentary breakpoints */
12715 momentary_bkpt_re_set (struct breakpoint *b)
12717 /* Keep temporary breakpoints, which can be encountered when we step
12718 over a dlopen call and solib_add is resetting the breakpoints.
12719 Otherwise these should have been blown away via the cleanup chain
12720 or by breakpoint_init_inferior when we rerun the executable. */
12724 momentary_bkpt_check_status (bpstat bs)
12726 /* Nothing. The point of these breakpoints is causing a stop. */
12729 static enum print_stop_action
12730 momentary_bkpt_print_it (bpstat bs)
12732 return PRINT_UNKNOWN;
12736 momentary_bkpt_print_mention (struct breakpoint *b)
12738 /* Nothing to mention. These breakpoints are internal. */
12741 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12743 It gets cleared already on the removal of the first one of such placed
12744 breakpoints. This is OK as they get all removed altogether. */
12746 longjmp_breakpoint::~longjmp_breakpoint ()
12748 thread_info *tp = find_thread_global_id (this->thread);
12751 tp->initiating_frame = null_frame_id;
12754 /* Specific methods for probe breakpoints. */
12757 bkpt_probe_insert_location (struct bp_location *bl)
12759 int v = bkpt_insert_location (bl);
12763 /* The insertion was successful, now let's set the probe's semaphore
12765 bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
12772 bkpt_probe_remove_location (struct bp_location *bl,
12773 enum remove_bp_reason reason)
12775 /* Let's clear the semaphore before removing the location. */
12776 bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
12778 return bkpt_remove_location (bl, reason);
12782 bkpt_probe_create_sals_from_location (const struct event_location *location,
12783 struct linespec_result *canonical,
12784 enum bptype type_wanted)
12786 struct linespec_sals lsal;
12788 lsal.sals = parse_probes (location, NULL, canonical);
12790 = xstrdup (event_location_to_string (canonical->location.get ()));
12791 canonical->lsals.push_back (std::move (lsal));
12794 static std::vector<symtab_and_line>
12795 bkpt_probe_decode_location (struct breakpoint *b,
12796 const struct event_location *location,
12797 struct program_space *search_pspace)
12799 std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
12801 error (_("probe not found"));
12805 /* The breakpoint_ops structure to be used in tracepoints. */
12808 tracepoint_re_set (struct breakpoint *b)
12810 breakpoint_re_set_default (b);
12814 tracepoint_breakpoint_hit (const struct bp_location *bl,
12815 const address_space *aspace, CORE_ADDR bp_addr,
12816 const struct target_waitstatus *ws)
12818 /* By definition, the inferior does not report stops at
12824 tracepoint_print_one_detail (const struct breakpoint *self,
12825 struct ui_out *uiout)
12827 struct tracepoint *tp = (struct tracepoint *) self;
12828 if (!tp->static_trace_marker_id.empty ())
12830 gdb_assert (self->type == bp_static_tracepoint);
12832 uiout->text ("\tmarker id is ");
12833 uiout->field_string ("static-tracepoint-marker-string-id",
12834 tp->static_trace_marker_id);
12835 uiout->text ("\n");
12840 tracepoint_print_mention (struct breakpoint *b)
12842 if (current_uiout->is_mi_like_p ())
12847 case bp_tracepoint:
12848 printf_filtered (_("Tracepoint"));
12849 printf_filtered (_(" %d"), b->number);
12851 case bp_fast_tracepoint:
12852 printf_filtered (_("Fast tracepoint"));
12853 printf_filtered (_(" %d"), b->number);
12855 case bp_static_tracepoint:
12856 printf_filtered (_("Static tracepoint"));
12857 printf_filtered (_(" %d"), b->number);
12860 internal_error (__FILE__, __LINE__,
12861 _("unhandled tracepoint type %d"), (int) b->type);
12868 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12870 struct tracepoint *tp = (struct tracepoint *) self;
12872 if (self->type == bp_fast_tracepoint)
12873 fprintf_unfiltered (fp, "ftrace");
12874 else if (self->type == bp_static_tracepoint)
12875 fprintf_unfiltered (fp, "strace");
12876 else if (self->type == bp_tracepoint)
12877 fprintf_unfiltered (fp, "trace");
12879 internal_error (__FILE__, __LINE__,
12880 _("unhandled tracepoint type %d"), (int) self->type);
12882 fprintf_unfiltered (fp, " %s",
12883 event_location_to_string (self->location.get ()));
12884 print_recreate_thread (self, fp);
12886 if (tp->pass_count)
12887 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12891 tracepoint_create_sals_from_location (const struct event_location *location,
12892 struct linespec_result *canonical,
12893 enum bptype type_wanted)
12895 create_sals_from_location_default (location, canonical, type_wanted);
12899 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12900 struct linespec_result *canonical,
12901 gdb::unique_xmalloc_ptr<char> cond_string,
12902 gdb::unique_xmalloc_ptr<char> extra_string,
12903 enum bptype type_wanted,
12904 enum bpdisp disposition,
12906 int task, int ignore_count,
12907 const struct breakpoint_ops *ops,
12908 int from_tty, int enabled,
12909 int internal, unsigned flags)
12911 create_breakpoints_sal_default (gdbarch, canonical,
12912 std::move (cond_string),
12913 std::move (extra_string),
12915 disposition, thread, task,
12916 ignore_count, ops, from_tty,
12917 enabled, internal, flags);
12920 static std::vector<symtab_and_line>
12921 tracepoint_decode_location (struct breakpoint *b,
12922 const struct event_location *location,
12923 struct program_space *search_pspace)
12925 return decode_location_default (b, location, search_pspace);
12928 struct breakpoint_ops tracepoint_breakpoint_ops;
12930 /* The breakpoint_ops structure to be use on tracepoints placed in a
12934 tracepoint_probe_create_sals_from_location
12935 (const struct event_location *location,
12936 struct linespec_result *canonical,
12937 enum bptype type_wanted)
12939 /* We use the same method for breakpoint on probes. */
12940 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
12943 static std::vector<symtab_and_line>
12944 tracepoint_probe_decode_location (struct breakpoint *b,
12945 const struct event_location *location,
12946 struct program_space *search_pspace)
12948 /* We use the same method for breakpoint on probes. */
12949 return bkpt_probe_decode_location (b, location, search_pspace);
12952 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
12954 /* Dprintf breakpoint_ops methods. */
12957 dprintf_re_set (struct breakpoint *b)
12959 breakpoint_re_set_default (b);
12961 /* extra_string should never be non-NULL for dprintf. */
12962 gdb_assert (b->extra_string != NULL);
12964 /* 1 - connect to target 1, that can run breakpoint commands.
12965 2 - create a dprintf, which resolves fine.
12966 3 - disconnect from target 1
12967 4 - connect to target 2, that can NOT run breakpoint commands.
12969 After steps #3/#4, you'll want the dprintf command list to
12970 be updated, because target 1 and 2 may well return different
12971 answers for target_can_run_breakpoint_commands().
12972 Given absence of finer grained resetting, we get to do
12973 it all the time. */
12974 if (b->extra_string != NULL)
12975 update_dprintf_command_list (b);
12978 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12981 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12983 fprintf_unfiltered (fp, "dprintf %s,%s",
12984 event_location_to_string (tp->location.get ()),
12986 print_recreate_thread (tp, fp);
12989 /* Implement the "after_condition_true" breakpoint_ops method for
12992 dprintf's are implemented with regular commands in their command
12993 list, but we run the commands here instead of before presenting the
12994 stop to the user, as dprintf's don't actually cause a stop. This
12995 also makes it so that the commands of multiple dprintfs at the same
12996 address are all handled. */
12999 dprintf_after_condition_true (struct bpstats *bs)
13001 struct bpstats tmp_bs;
13002 struct bpstats *tmp_bs_p = &tmp_bs;
13004 /* dprintf's never cause a stop. This wasn't set in the
13005 check_status hook instead because that would make the dprintf's
13006 condition not be evaluated. */
13009 /* Run the command list here. Take ownership of it instead of
13010 copying. We never want these commands to run later in
13011 bpstat_do_actions, if a breakpoint that causes a stop happens to
13012 be set at same address as this dprintf, or even if running the
13013 commands here throws. */
13014 tmp_bs.commands = bs->commands;
13015 bs->commands = NULL;
13017 bpstat_do_actions_1 (&tmp_bs_p);
13019 /* 'tmp_bs.commands' will usually be NULL by now, but
13020 bpstat_do_actions_1 may return early without processing the whole
13024 /* The breakpoint_ops structure to be used on static tracepoints with
13028 strace_marker_create_sals_from_location (const struct event_location *location,
13029 struct linespec_result *canonical,
13030 enum bptype type_wanted)
13032 struct linespec_sals lsal;
13033 const char *arg_start, *arg;
13035 arg = arg_start = get_linespec_location (location)->spec_string;
13036 lsal.sals = decode_static_tracepoint_spec (&arg);
13038 std::string str (arg_start, arg - arg_start);
13039 const char *ptr = str.c_str ();
13040 canonical->location
13041 = new_linespec_location (&ptr, symbol_name_match_type::FULL);
13044 = xstrdup (event_location_to_string (canonical->location.get ()));
13045 canonical->lsals.push_back (std::move (lsal));
13049 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13050 struct linespec_result *canonical,
13051 gdb::unique_xmalloc_ptr<char> cond_string,
13052 gdb::unique_xmalloc_ptr<char> extra_string,
13053 enum bptype type_wanted,
13054 enum bpdisp disposition,
13056 int task, int ignore_count,
13057 const struct breakpoint_ops *ops,
13058 int from_tty, int enabled,
13059 int internal, unsigned flags)
13061 const linespec_sals &lsal = canonical->lsals[0];
13063 /* If the user is creating a static tracepoint by marker id
13064 (strace -m MARKER_ID), then store the sals index, so that
13065 breakpoint_re_set can try to match up which of the newly
13066 found markers corresponds to this one, and, don't try to
13067 expand multiple locations for each sal, given than SALS
13068 already should contain all sals for MARKER_ID. */
13070 for (size_t i = 0; i < lsal.sals.size (); i++)
13072 event_location_up location
13073 = copy_event_location (canonical->location.get ());
13075 std::unique_ptr<tracepoint> tp (new tracepoint ());
13076 init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i],
13077 std::move (location), NULL,
13078 std::move (cond_string),
13079 std::move (extra_string),
13080 type_wanted, disposition,
13081 thread, task, ignore_count, ops,
13082 from_tty, enabled, internal, flags,
13083 canonical->special_display);
13084 /* Given that its possible to have multiple markers with
13085 the same string id, if the user is creating a static
13086 tracepoint by marker id ("strace -m MARKER_ID"), then
13087 store the sals index, so that breakpoint_re_set can
13088 try to match up which of the newly found markers
13089 corresponds to this one */
13090 tp->static_trace_marker_id_idx = i;
13092 install_breakpoint (internal, std::move (tp), 0);
13096 static std::vector<symtab_and_line>
13097 strace_marker_decode_location (struct breakpoint *b,
13098 const struct event_location *location,
13099 struct program_space *search_pspace)
13101 struct tracepoint *tp = (struct tracepoint *) b;
13102 const char *s = get_linespec_location (location)->spec_string;
13104 std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
13105 if (sals.size () > tp->static_trace_marker_id_idx)
13107 sals[0] = sals[tp->static_trace_marker_id_idx];
13112 error (_("marker %s not found"), tp->static_trace_marker_id.c_str ());
13115 static struct breakpoint_ops strace_marker_breakpoint_ops;
13118 strace_marker_p (struct breakpoint *b)
13120 return b->ops == &strace_marker_breakpoint_ops;
13123 /* Delete a breakpoint and clean up all traces of it in the data
13127 delete_breakpoint (struct breakpoint *bpt)
13129 struct breakpoint *b;
13131 gdb_assert (bpt != NULL);
13133 /* Has this bp already been deleted? This can happen because
13134 multiple lists can hold pointers to bp's. bpstat lists are
13137 One example of this happening is a watchpoint's scope bp. When
13138 the scope bp triggers, we notice that the watchpoint is out of
13139 scope, and delete it. We also delete its scope bp. But the
13140 scope bp is marked "auto-deleting", and is already on a bpstat.
13141 That bpstat is then checked for auto-deleting bp's, which are
13144 A real solution to this problem might involve reference counts in
13145 bp's, and/or giving them pointers back to their referencing
13146 bpstat's, and teaching delete_breakpoint to only free a bp's
13147 storage when no more references were extent. A cheaper bandaid
13149 if (bpt->type == bp_none)
13152 /* At least avoid this stale reference until the reference counting
13153 of breakpoints gets resolved. */
13154 if (bpt->related_breakpoint != bpt)
13156 struct breakpoint *related;
13157 struct watchpoint *w;
13159 if (bpt->type == bp_watchpoint_scope)
13160 w = (struct watchpoint *) bpt->related_breakpoint;
13161 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13162 w = (struct watchpoint *) bpt;
13166 watchpoint_del_at_next_stop (w);
13168 /* Unlink bpt from the bpt->related_breakpoint ring. */
13169 for (related = bpt; related->related_breakpoint != bpt;
13170 related = related->related_breakpoint);
13171 related->related_breakpoint = bpt->related_breakpoint;
13172 bpt->related_breakpoint = bpt;
13175 /* watch_command_1 creates a watchpoint but only sets its number if
13176 update_watchpoint succeeds in creating its bp_locations. If there's
13177 a problem in that process, we'll be asked to delete the half-created
13178 watchpoint. In that case, don't announce the deletion. */
13180 gdb::observers::breakpoint_deleted.notify (bpt);
13182 if (breakpoint_chain == bpt)
13183 breakpoint_chain = bpt->next;
13185 ALL_BREAKPOINTS (b)
13186 if (b->next == bpt)
13188 b->next = bpt->next;
13192 /* Be sure no bpstat's are pointing at the breakpoint after it's
13194 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13195 in all threads for now. Note that we cannot just remove bpstats
13196 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13197 commands are associated with the bpstat; if we remove it here,
13198 then the later call to bpstat_do_actions (&stop_bpstat); in
13199 event-top.c won't do anything, and temporary breakpoints with
13200 commands won't work. */
13202 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13204 /* Now that breakpoint is removed from breakpoint list, update the
13205 global location list. This will remove locations that used to
13206 belong to this breakpoint. Do this before freeing the breakpoint
13207 itself, since remove_breakpoint looks at location's owner. It
13208 might be better design to have location completely
13209 self-contained, but it's not the case now. */
13210 update_global_location_list (UGLL_DONT_INSERT);
13212 /* On the chance that someone will soon try again to delete this
13213 same bp, we mark it as deleted before freeing its storage. */
13214 bpt->type = bp_none;
13218 /* Iterator function to call a user-provided callback function once
13219 for each of B and its related breakpoints. */
13222 iterate_over_related_breakpoints (struct breakpoint *b,
13223 gdb::function_view<void (breakpoint *)> function)
13225 struct breakpoint *related;
13230 struct breakpoint *next;
13232 /* FUNCTION may delete RELATED. */
13233 next = related->related_breakpoint;
13235 if (next == related)
13237 /* RELATED is the last ring entry. */
13238 function (related);
13240 /* FUNCTION may have deleted it, so we'd never reach back to
13241 B. There's nothing left to do anyway, so just break
13246 function (related);
13250 while (related != b);
13254 delete_command (const char *arg, int from_tty)
13256 struct breakpoint *b, *b_tmp;
13262 int breaks_to_delete = 0;
13264 /* Delete all breakpoints if no argument. Do not delete
13265 internal breakpoints, these have to be deleted with an
13266 explicit breakpoint number argument. */
13267 ALL_BREAKPOINTS (b)
13268 if (user_breakpoint_p (b))
13270 breaks_to_delete = 1;
13274 /* Ask user only if there are some breakpoints to delete. */
13276 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13278 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13279 if (user_breakpoint_p (b))
13280 delete_breakpoint (b);
13284 map_breakpoint_numbers
13285 (arg, [&] (breakpoint *br)
13287 iterate_over_related_breakpoints (br, delete_breakpoint);
13291 /* Return true if all locations of B bound to PSPACE are pending. If
13292 PSPACE is NULL, all locations of all program spaces are
13296 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
13298 struct bp_location *loc;
13300 for (loc = b->loc; loc != NULL; loc = loc->next)
13301 if ((pspace == NULL
13302 || loc->pspace == pspace)
13303 && !loc->shlib_disabled
13304 && !loc->pspace->executing_startup)
13309 /* Subroutine of update_breakpoint_locations to simplify it.
13310 Return non-zero if multiple fns in list LOC have the same name.
13311 Null names are ignored. */
13314 ambiguous_names_p (struct bp_location *loc)
13316 struct bp_location *l;
13317 htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL,
13320 for (l = loc; l != NULL; l = l->next)
13323 const char *name = l->function_name;
13325 /* Allow for some names to be NULL, ignore them. */
13329 slot = (const char **) htab_find_slot (htab, (const void *) name,
13331 /* NOTE: We can assume slot != NULL here because xcalloc never
13335 htab_delete (htab);
13341 htab_delete (htab);
13345 /* When symbols change, it probably means the sources changed as well,
13346 and it might mean the static tracepoint markers are no longer at
13347 the same address or line numbers they used to be at last we
13348 checked. Losing your static tracepoints whenever you rebuild is
13349 undesirable. This function tries to resync/rematch gdb static
13350 tracepoints with the markers on the target, for static tracepoints
13351 that have not been set by marker id. Static tracepoint that have
13352 been set by marker id are reset by marker id in breakpoint_re_set.
13355 1) For a tracepoint set at a specific address, look for a marker at
13356 the old PC. If one is found there, assume to be the same marker.
13357 If the name / string id of the marker found is different from the
13358 previous known name, assume that means the user renamed the marker
13359 in the sources, and output a warning.
13361 2) For a tracepoint set at a given line number, look for a marker
13362 at the new address of the old line number. If one is found there,
13363 assume to be the same marker. If the name / string id of the
13364 marker found is different from the previous known name, assume that
13365 means the user renamed the marker in the sources, and output a
13368 3) If a marker is no longer found at the same address or line, it
13369 may mean the marker no longer exists. But it may also just mean
13370 the code changed a bit. Maybe the user added a few lines of code
13371 that made the marker move up or down (in line number terms). Ask
13372 the target for info about the marker with the string id as we knew
13373 it. If found, update line number and address in the matching
13374 static tracepoint. This will get confused if there's more than one
13375 marker with the same ID (possible in UST, although unadvised
13376 precisely because it confuses tools). */
13378 static struct symtab_and_line
13379 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13381 struct tracepoint *tp = (struct tracepoint *) b;
13382 struct static_tracepoint_marker marker;
13387 find_line_pc (sal.symtab, sal.line, &pc);
13389 if (target_static_tracepoint_marker_at (pc, &marker))
13391 if (tp->static_trace_marker_id != marker.str_id)
13392 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13393 b->number, tp->static_trace_marker_id.c_str (),
13394 marker.str_id.c_str ());
13396 tp->static_trace_marker_id = std::move (marker.str_id);
13401 /* Old marker wasn't found on target at lineno. Try looking it up
13403 if (!sal.explicit_pc
13405 && sal.symtab != NULL
13406 && !tp->static_trace_marker_id.empty ())
13408 std::vector<static_tracepoint_marker> markers
13409 = target_static_tracepoint_markers_by_strid
13410 (tp->static_trace_marker_id.c_str ());
13412 if (!markers.empty ())
13414 struct symbol *sym;
13415 struct static_tracepoint_marker *tpmarker;
13416 struct ui_out *uiout = current_uiout;
13417 struct explicit_location explicit_loc;
13419 tpmarker = &markers[0];
13421 tp->static_trace_marker_id = std::move (tpmarker->str_id);
13423 warning (_("marker for static tracepoint %d (%s) not "
13424 "found at previous line number"),
13425 b->number, tp->static_trace_marker_id.c_str ());
13427 symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
13428 sym = find_pc_sect_function (tpmarker->address, NULL);
13429 uiout->text ("Now in ");
13432 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
13433 ui_out_style_kind::FUNCTION);
13434 uiout->text (" at ");
13436 uiout->field_string ("file",
13437 symtab_to_filename_for_display (sal2.symtab),
13438 ui_out_style_kind::FILE);
13441 if (uiout->is_mi_like_p ())
13443 const char *fullname = symtab_to_fullname (sal2.symtab);
13445 uiout->field_string ("fullname", fullname);
13448 uiout->field_int ("line", sal2.line);
13449 uiout->text ("\n");
13451 b->loc->line_number = sal2.line;
13452 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13454 b->location.reset (NULL);
13455 initialize_explicit_location (&explicit_loc);
13456 explicit_loc.source_filename
13457 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
13458 explicit_loc.line_offset.offset = b->loc->line_number;
13459 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
13460 b->location = new_explicit_location (&explicit_loc);
13462 /* Might be nice to check if function changed, and warn if
13469 /* Returns 1 iff locations A and B are sufficiently same that
13470 we don't need to report breakpoint as changed. */
13473 locations_are_equal (struct bp_location *a, struct bp_location *b)
13477 if (a->address != b->address)
13480 if (a->shlib_disabled != b->shlib_disabled)
13483 if (a->enabled != b->enabled)
13490 if ((a == NULL) != (b == NULL))
13496 /* Split all locations of B that are bound to PSPACE out of B's
13497 location list to a separate list and return that list's head. If
13498 PSPACE is NULL, hoist out all locations of B. */
13500 static struct bp_location *
13501 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
13503 struct bp_location head;
13504 struct bp_location *i = b->loc;
13505 struct bp_location **i_link = &b->loc;
13506 struct bp_location *hoisted = &head;
13508 if (pspace == NULL)
13519 if (i->pspace == pspace)
13534 /* Create new breakpoint locations for B (a hardware or software
13535 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13536 zero, then B is a ranged breakpoint. Only recreates locations for
13537 FILTER_PSPACE. Locations of other program spaces are left
13541 update_breakpoint_locations (struct breakpoint *b,
13542 struct program_space *filter_pspace,
13543 gdb::array_view<const symtab_and_line> sals,
13544 gdb::array_view<const symtab_and_line> sals_end)
13546 struct bp_location *existing_locations;
13548 if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
13550 /* Ranged breakpoints have only one start location and one end
13552 b->enable_state = bp_disabled;
13553 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13554 "multiple locations found\n"),
13559 /* If there's no new locations, and all existing locations are
13560 pending, don't do anything. This optimizes the common case where
13561 all locations are in the same shared library, that was unloaded.
13562 We'd like to retain the location, so that when the library is
13563 loaded again, we don't loose the enabled/disabled status of the
13564 individual locations. */
13565 if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
13568 existing_locations = hoist_existing_locations (b, filter_pspace);
13570 for (const auto &sal : sals)
13572 struct bp_location *new_loc;
13574 switch_to_program_space_and_thread (sal.pspace);
13576 new_loc = add_location_to_breakpoint (b, &sal);
13578 /* Reparse conditions, they might contain references to the
13580 if (b->cond_string != NULL)
13584 s = b->cond_string;
13587 new_loc->cond = parse_exp_1 (&s, sal.pc,
13588 block_for_pc (sal.pc),
13591 CATCH (e, RETURN_MASK_ERROR)
13593 warning (_("failed to reevaluate condition "
13594 "for breakpoint %d: %s"),
13595 b->number, e.message);
13596 new_loc->enabled = 0;
13601 if (!sals_end.empty ())
13603 CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
13605 new_loc->length = end - sals[0].pc + 1;
13609 /* If possible, carry over 'disable' status from existing
13612 struct bp_location *e = existing_locations;
13613 /* If there are multiple breakpoints with the same function name,
13614 e.g. for inline functions, comparing function names won't work.
13615 Instead compare pc addresses; this is just a heuristic as things
13616 may have moved, but in practice it gives the correct answer
13617 often enough until a better solution is found. */
13618 int have_ambiguous_names = ambiguous_names_p (b->loc);
13620 for (; e; e = e->next)
13622 if (!e->enabled && e->function_name)
13624 struct bp_location *l = b->loc;
13625 if (have_ambiguous_names)
13627 for (; l; l = l->next)
13628 if (breakpoint_locations_match (e, l))
13636 for (; l; l = l->next)
13637 if (l->function_name
13638 && strcmp (e->function_name, l->function_name) == 0)
13648 if (!locations_are_equal (existing_locations, b->loc))
13649 gdb::observers::breakpoint_modified.notify (b);
13652 /* Find the SaL locations corresponding to the given LOCATION.
13653 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13655 static std::vector<symtab_and_line>
13656 location_to_sals (struct breakpoint *b, struct event_location *location,
13657 struct program_space *search_pspace, int *found)
13659 struct gdb_exception exception = exception_none;
13661 gdb_assert (b->ops != NULL);
13663 std::vector<symtab_and_line> sals;
13667 sals = b->ops->decode_location (b, location, search_pspace);
13669 CATCH (e, RETURN_MASK_ERROR)
13671 int not_found_and_ok = 0;
13675 /* For pending breakpoints, it's expected that parsing will
13676 fail until the right shared library is loaded. User has
13677 already told to create pending breakpoints and don't need
13678 extra messages. If breakpoint is in bp_shlib_disabled
13679 state, then user already saw the message about that
13680 breakpoint being disabled, and don't want to see more
13682 if (e.error == NOT_FOUND_ERROR
13683 && (b->condition_not_parsed
13685 && search_pspace != NULL
13686 && b->loc->pspace != search_pspace)
13687 || (b->loc && b->loc->shlib_disabled)
13688 || (b->loc && b->loc->pspace->executing_startup)
13689 || b->enable_state == bp_disabled))
13690 not_found_and_ok = 1;
13692 if (!not_found_and_ok)
13694 /* We surely don't want to warn about the same breakpoint
13695 10 times. One solution, implemented here, is disable
13696 the breakpoint on error. Another solution would be to
13697 have separate 'warning emitted' flag. Since this
13698 happens only when a binary has changed, I don't know
13699 which approach is better. */
13700 b->enable_state = bp_disabled;
13701 throw_exception (e);
13706 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
13708 for (auto &sal : sals)
13709 resolve_sal_pc (&sal);
13710 if (b->condition_not_parsed && b->extra_string != NULL)
13712 char *cond_string, *extra_string;
13715 find_condition_and_thread (b->extra_string, sals[0].pc,
13716 &cond_string, &thread, &task,
13718 gdb_assert (b->cond_string == NULL);
13720 b->cond_string = cond_string;
13721 b->thread = thread;
13725 xfree (b->extra_string);
13726 b->extra_string = extra_string;
13728 b->condition_not_parsed = 0;
13731 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13732 sals[0] = update_static_tracepoint (b, sals[0]);
13742 /* The default re_set method, for typical hardware or software
13743 breakpoints. Reevaluate the breakpoint and recreate its
13747 breakpoint_re_set_default (struct breakpoint *b)
13749 struct program_space *filter_pspace = current_program_space;
13750 std::vector<symtab_and_line> expanded, expanded_end;
13753 std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
13754 filter_pspace, &found);
13756 expanded = std::move (sals);
13758 if (b->location_range_end != NULL)
13760 std::vector<symtab_and_line> sals_end
13761 = location_to_sals (b, b->location_range_end.get (),
13762 filter_pspace, &found);
13764 expanded_end = std::move (sals_end);
13767 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
13770 /* Default method for creating SALs from an address string. It basically
13771 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13774 create_sals_from_location_default (const struct event_location *location,
13775 struct linespec_result *canonical,
13776 enum bptype type_wanted)
13778 parse_breakpoint_sals (location, canonical);
13781 /* Call create_breakpoints_sal for the given arguments. This is the default
13782 function for the `create_breakpoints_sal' method of
13786 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13787 struct linespec_result *canonical,
13788 gdb::unique_xmalloc_ptr<char> cond_string,
13789 gdb::unique_xmalloc_ptr<char> extra_string,
13790 enum bptype type_wanted,
13791 enum bpdisp disposition,
13793 int task, int ignore_count,
13794 const struct breakpoint_ops *ops,
13795 int from_tty, int enabled,
13796 int internal, unsigned flags)
13798 create_breakpoints_sal (gdbarch, canonical,
13799 std::move (cond_string),
13800 std::move (extra_string),
13801 type_wanted, disposition,
13802 thread, task, ignore_count, ops, from_tty,
13803 enabled, internal, flags);
13806 /* Decode the line represented by S by calling decode_line_full. This is the
13807 default function for the `decode_location' method of breakpoint_ops. */
13809 static std::vector<symtab_and_line>
13810 decode_location_default (struct breakpoint *b,
13811 const struct event_location *location,
13812 struct program_space *search_pspace)
13814 struct linespec_result canonical;
13816 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
13817 (struct symtab *) NULL, 0,
13818 &canonical, multiple_symbols_all,
13821 /* We should get 0 or 1 resulting SALs. */
13822 gdb_assert (canonical.lsals.size () < 2);
13824 if (!canonical.lsals.empty ())
13826 const linespec_sals &lsal = canonical.lsals[0];
13827 return std::move (lsal.sals);
13832 /* Reset a breakpoint. */
13835 breakpoint_re_set_one (breakpoint *b)
13837 input_radix = b->input_radix;
13838 set_language (b->language);
13840 b->ops->re_set (b);
13843 /* Re-set breakpoint locations for the current program space.
13844 Locations bound to other program spaces are left untouched. */
13847 breakpoint_re_set (void)
13849 struct breakpoint *b, *b_tmp;
13852 scoped_restore_current_language save_language;
13853 scoped_restore save_input_radix = make_scoped_restore (&input_radix);
13854 scoped_restore_current_pspace_and_thread restore_pspace_thread;
13856 /* breakpoint_re_set_one sets the current_language to the language
13857 of the breakpoint it is resetting (see prepare_re_set_context)
13858 before re-evaluating the breakpoint's location. This change can
13859 unfortunately get undone by accident if the language_mode is set
13860 to auto, and we either switch frames, or more likely in this context,
13861 we select the current frame.
13863 We prevent this by temporarily turning the language_mode to
13864 language_mode_manual. We restore it once all breakpoints
13865 have been reset. */
13866 scoped_restore save_language_mode = make_scoped_restore (&language_mode);
13867 language_mode = language_mode_manual;
13869 /* Note: we must not try to insert locations until after all
13870 breakpoints have been re-set. Otherwise, e.g., when re-setting
13871 breakpoint 1, we'd insert the locations of breakpoint 2, which
13872 hadn't been re-set yet, and thus may have stale locations. */
13874 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13878 breakpoint_re_set_one (b);
13880 CATCH (ex, RETURN_MASK_ALL)
13882 exception_fprintf (gdb_stderr, ex,
13883 "Error in re-setting breakpoint %d: ",
13889 jit_breakpoint_re_set ();
13892 create_overlay_event_breakpoint ();
13893 create_longjmp_master_breakpoint ();
13894 create_std_terminate_master_breakpoint ();
13895 create_exception_master_breakpoint ();
13897 /* Now we can insert. */
13898 update_global_location_list (UGLL_MAY_INSERT);
13901 /* Reset the thread number of this breakpoint:
13903 - If the breakpoint is for all threads, leave it as-is.
13904 - Else, reset it to the current thread for inferior_ptid. */
13906 breakpoint_re_set_thread (struct breakpoint *b)
13908 if (b->thread != -1)
13910 b->thread = inferior_thread ()->global_num;
13912 /* We're being called after following a fork. The new fork is
13913 selected as current, and unless this was a vfork will have a
13914 different program space from the original thread. Reset that
13916 b->loc->pspace = current_program_space;
13920 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13921 If from_tty is nonzero, it prints a message to that effect,
13922 which ends with a period (no newline). */
13925 set_ignore_count (int bptnum, int count, int from_tty)
13927 struct breakpoint *b;
13932 ALL_BREAKPOINTS (b)
13933 if (b->number == bptnum)
13935 if (is_tracepoint (b))
13937 if (from_tty && count != 0)
13938 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13943 b->ignore_count = count;
13947 printf_filtered (_("Will stop next time "
13948 "breakpoint %d is reached."),
13950 else if (count == 1)
13951 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13954 printf_filtered (_("Will ignore next %d "
13955 "crossings of breakpoint %d."),
13958 gdb::observers::breakpoint_modified.notify (b);
13962 error (_("No breakpoint number %d."), bptnum);
13965 /* Command to set ignore-count of breakpoint N to COUNT. */
13968 ignore_command (const char *args, int from_tty)
13970 const char *p = args;
13974 error_no_arg (_("a breakpoint number"));
13976 num = get_number (&p);
13978 error (_("bad breakpoint number: '%s'"), args);
13980 error (_("Second argument (specified ignore-count) is missing."));
13982 set_ignore_count (num,
13983 longest_to_int (value_as_long (parse_and_eval (p))),
13986 printf_filtered ("\n");
13990 /* Call FUNCTION on each of the breakpoints with numbers in the range
13991 defined by BP_NUM_RANGE (an inclusive range). */
13994 map_breakpoint_number_range (std::pair<int, int> bp_num_range,
13995 gdb::function_view<void (breakpoint *)> function)
13997 if (bp_num_range.first == 0)
13999 warning (_("bad breakpoint number at or near '%d'"),
14000 bp_num_range.first);
14004 struct breakpoint *b, *tmp;
14006 for (int i = bp_num_range.first; i <= bp_num_range.second; i++)
14008 bool match = false;
14010 ALL_BREAKPOINTS_SAFE (b, tmp)
14011 if (b->number == i)
14018 printf_unfiltered (_("No breakpoint number %d.\n"), i);
14023 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14027 map_breakpoint_numbers (const char *args,
14028 gdb::function_view<void (breakpoint *)> function)
14030 if (args == NULL || *args == '\0')
14031 error_no_arg (_("one or more breakpoint numbers"));
14033 number_or_range_parser parser (args);
14035 while (!parser.finished ())
14037 int num = parser.get_number ();
14038 map_breakpoint_number_range (std::make_pair (num, num), function);
14042 /* Return the breakpoint location structure corresponding to the
14043 BP_NUM and LOC_NUM values. */
14045 static struct bp_location *
14046 find_location_by_number (int bp_num, int loc_num)
14048 struct breakpoint *b;
14050 ALL_BREAKPOINTS (b)
14051 if (b->number == bp_num)
14056 if (!b || b->number != bp_num)
14057 error (_("Bad breakpoint number '%d'"), bp_num);
14060 error (_("Bad breakpoint location number '%d'"), loc_num);
14063 for (bp_location *loc = b->loc; loc != NULL; loc = loc->next)
14064 if (++n == loc_num)
14067 error (_("Bad breakpoint location number '%d'"), loc_num);
14070 /* Modes of operation for extract_bp_num. */
14071 enum class extract_bp_kind
14073 /* Extracting a breakpoint number. */
14076 /* Extracting a location number. */
14080 /* Extract a breakpoint or location number (as determined by KIND)
14081 from the string starting at START. TRAILER is a character which
14082 can be found after the number. If you don't want a trailer, use
14083 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14084 string. This always returns a positive integer. */
14087 extract_bp_num (extract_bp_kind kind, const char *start,
14088 int trailer, const char **end_out = NULL)
14090 const char *end = start;
14091 int num = get_number_trailer (&end, trailer);
14093 error (kind == extract_bp_kind::bp
14094 ? _("Negative breakpoint number '%.*s'")
14095 : _("Negative breakpoint location number '%.*s'"),
14096 int (end - start), start);
14098 error (kind == extract_bp_kind::bp
14099 ? _("Bad breakpoint number '%.*s'")
14100 : _("Bad breakpoint location number '%.*s'"),
14101 int (end - start), start);
14103 if (end_out != NULL)
14108 /* Extract a breakpoint or location range (as determined by KIND) in
14109 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14110 representing the (inclusive) range. The returned pair's elements
14111 are always positive integers. */
14113 static std::pair<int, int>
14114 extract_bp_or_bp_range (extract_bp_kind kind,
14115 const std::string &arg,
14116 std::string::size_type arg_offset)
14118 std::pair<int, int> range;
14119 const char *bp_loc = &arg[arg_offset];
14120 std::string::size_type dash = arg.find ('-', arg_offset);
14121 if (dash != std::string::npos)
14123 /* bp_loc is a range (x-z). */
14124 if (arg.length () == dash + 1)
14125 error (kind == extract_bp_kind::bp
14126 ? _("Bad breakpoint number at or near: '%s'")
14127 : _("Bad breakpoint location number at or near: '%s'"),
14131 const char *start_first = bp_loc;
14132 const char *start_second = &arg[dash + 1];
14133 range.first = extract_bp_num (kind, start_first, '-');
14134 range.second = extract_bp_num (kind, start_second, '\0', &end);
14136 if (range.first > range.second)
14137 error (kind == extract_bp_kind::bp
14138 ? _("Inverted breakpoint range at '%.*s'")
14139 : _("Inverted breakpoint location range at '%.*s'"),
14140 int (end - start_first), start_first);
14144 /* bp_loc is a single value. */
14145 range.first = extract_bp_num (kind, bp_loc, '\0');
14146 range.second = range.first;
14151 /* Extract the breakpoint/location range specified by ARG. Returns
14152 the breakpoint range in BP_NUM_RANGE, and the location range in
14155 ARG may be in any of the following forms:
14157 x where 'x' is a breakpoint number.
14158 x-y where 'x' and 'y' specify a breakpoint numbers range.
14159 x.y where 'x' is a breakpoint number and 'y' a location number.
14160 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14161 location number range.
14165 extract_bp_number_and_location (const std::string &arg,
14166 std::pair<int, int> &bp_num_range,
14167 std::pair<int, int> &bp_loc_range)
14169 std::string::size_type dot = arg.find ('.');
14171 if (dot != std::string::npos)
14173 /* Handle 'x.y' and 'x.y-z' cases. */
14175 if (arg.length () == dot + 1 || dot == 0)
14176 error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ());
14179 = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.');
14180 bp_num_range.second = bp_num_range.first;
14182 bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc,
14187 /* Handle x and x-y cases. */
14189 bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0);
14190 bp_loc_range.first = 0;
14191 bp_loc_range.second = 0;
14195 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14196 specifies whether to enable or disable. */
14199 enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
14201 struct bp_location *loc = find_location_by_number (bp_num, loc_num);
14204 if (loc->enabled != enable)
14206 loc->enabled = enable;
14207 mark_breakpoint_location_modified (loc);
14209 if (target_supports_enable_disable_tracepoint ()
14210 && current_trace_status ()->running && loc->owner
14211 && is_tracepoint (loc->owner))
14212 target_disable_tracepoint (loc);
14214 update_global_location_list (UGLL_DONT_INSERT);
14216 gdb::observers::breakpoint_modified.notify (loc->owner);
14219 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14220 number of the breakpoint, and BP_LOC_RANGE specifies the
14221 (inclusive) range of location numbers of that breakpoint to
14222 enable/disable. ENABLE specifies whether to enable or disable the
14226 enable_disable_breakpoint_location_range (int bp_num,
14227 std::pair<int, int> &bp_loc_range,
14230 for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++)
14231 enable_disable_bp_num_loc (bp_num, i, enable);
14234 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14235 If from_tty is nonzero, it prints a message to that effect,
14236 which ends with a period (no newline). */
14239 disable_breakpoint (struct breakpoint *bpt)
14241 /* Never disable a watchpoint scope breakpoint; we want to
14242 hit them when we leave scope so we can delete both the
14243 watchpoint and its scope breakpoint at that time. */
14244 if (bpt->type == bp_watchpoint_scope)
14247 bpt->enable_state = bp_disabled;
14249 /* Mark breakpoint locations modified. */
14250 mark_breakpoint_modified (bpt);
14252 if (target_supports_enable_disable_tracepoint ()
14253 && current_trace_status ()->running && is_tracepoint (bpt))
14255 struct bp_location *location;
14257 for (location = bpt->loc; location; location = location->next)
14258 target_disable_tracepoint (location);
14261 update_global_location_list (UGLL_DONT_INSERT);
14263 gdb::observers::breakpoint_modified.notify (bpt);
14266 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14267 specified in ARGS. ARGS may be in any of the formats handled by
14268 extract_bp_number_and_location. ENABLE specifies whether to enable
14269 or disable the breakpoints/locations. */
14272 enable_disable_command (const char *args, int from_tty, bool enable)
14276 struct breakpoint *bpt;
14278 ALL_BREAKPOINTS (bpt)
14279 if (user_breakpoint_p (bpt))
14282 enable_breakpoint (bpt);
14284 disable_breakpoint (bpt);
14289 std::string num = extract_arg (&args);
14291 while (!num.empty ())
14293 std::pair<int, int> bp_num_range, bp_loc_range;
14295 extract_bp_number_and_location (num, bp_num_range, bp_loc_range);
14297 if (bp_loc_range.first == bp_loc_range.second
14298 && bp_loc_range.first == 0)
14300 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14301 map_breakpoint_number_range (bp_num_range,
14303 ? enable_breakpoint
14304 : disable_breakpoint);
14308 /* Handle breakpoint ids with formats 'x.y' or
14310 enable_disable_breakpoint_location_range
14311 (bp_num_range.first, bp_loc_range, enable);
14313 num = extract_arg (&args);
14318 /* The disable command disables the specified breakpoints/locations
14319 (or all defined breakpoints) so they're no longer effective in
14320 stopping the inferior. ARGS may be in any of the forms defined in
14321 extract_bp_number_and_location. */
14324 disable_command (const char *args, int from_tty)
14326 enable_disable_command (args, from_tty, false);
14330 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14333 int target_resources_ok;
14335 if (bpt->type == bp_hardware_breakpoint)
14338 i = hw_breakpoint_used_count ();
14339 target_resources_ok =
14340 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14342 if (target_resources_ok == 0)
14343 error (_("No hardware breakpoint support in the target."));
14344 else if (target_resources_ok < 0)
14345 error (_("Hardware breakpoints used exceeds limit."));
14348 if (is_watchpoint (bpt))
14350 /* Initialize it just to avoid a GCC false warning. */
14351 enum enable_state orig_enable_state = bp_disabled;
14355 struct watchpoint *w = (struct watchpoint *) bpt;
14357 orig_enable_state = bpt->enable_state;
14358 bpt->enable_state = bp_enabled;
14359 update_watchpoint (w, 1 /* reparse */);
14361 CATCH (e, RETURN_MASK_ALL)
14363 bpt->enable_state = orig_enable_state;
14364 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14371 bpt->enable_state = bp_enabled;
14373 /* Mark breakpoint locations modified. */
14374 mark_breakpoint_modified (bpt);
14376 if (target_supports_enable_disable_tracepoint ()
14377 && current_trace_status ()->running && is_tracepoint (bpt))
14379 struct bp_location *location;
14381 for (location = bpt->loc; location; location = location->next)
14382 target_enable_tracepoint (location);
14385 bpt->disposition = disposition;
14386 bpt->enable_count = count;
14387 update_global_location_list (UGLL_MAY_INSERT);
14389 gdb::observers::breakpoint_modified.notify (bpt);
14394 enable_breakpoint (struct breakpoint *bpt)
14396 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14399 /* The enable command enables the specified breakpoints/locations (or
14400 all defined breakpoints) so they once again become (or continue to
14401 be) effective in stopping the inferior. ARGS may be in any of the
14402 forms defined in extract_bp_number_and_location. */
14405 enable_command (const char *args, int from_tty)
14407 enable_disable_command (args, from_tty, true);
14411 enable_once_command (const char *args, int from_tty)
14413 map_breakpoint_numbers
14414 (args, [&] (breakpoint *b)
14416 iterate_over_related_breakpoints
14417 (b, [&] (breakpoint *bpt)
14419 enable_breakpoint_disp (bpt, disp_disable, 1);
14425 enable_count_command (const char *args, int from_tty)
14430 error_no_arg (_("hit count"));
14432 count = get_number (&args);
14434 map_breakpoint_numbers
14435 (args, [&] (breakpoint *b)
14437 iterate_over_related_breakpoints
14438 (b, [&] (breakpoint *bpt)
14440 enable_breakpoint_disp (bpt, disp_disable, count);
14446 enable_delete_command (const char *args, int from_tty)
14448 map_breakpoint_numbers
14449 (args, [&] (breakpoint *b)
14451 iterate_over_related_breakpoints
14452 (b, [&] (breakpoint *bpt)
14454 enable_breakpoint_disp (bpt, disp_del, 1);
14460 set_breakpoint_cmd (const char *args, int from_tty)
14465 show_breakpoint_cmd (const char *args, int from_tty)
14469 /* Invalidate last known value of any hardware watchpoint if
14470 the memory which that value represents has been written to by
14474 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14475 CORE_ADDR addr, ssize_t len,
14476 const bfd_byte *data)
14478 struct breakpoint *bp;
14480 ALL_BREAKPOINTS (bp)
14481 if (bp->enable_state == bp_enabled
14482 && bp->type == bp_hardware_watchpoint)
14484 struct watchpoint *wp = (struct watchpoint *) bp;
14486 if (wp->val_valid && wp->val != nullptr)
14488 struct bp_location *loc;
14490 for (loc = bp->loc; loc != NULL; loc = loc->next)
14491 if (loc->loc_type == bp_loc_hardware_watchpoint
14492 && loc->address + loc->length > addr
14493 && addr + len > loc->address)
14502 /* Create and insert a breakpoint for software single step. */
14505 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14506 const address_space *aspace,
14509 struct thread_info *tp = inferior_thread ();
14510 struct symtab_and_line sal;
14511 CORE_ADDR pc = next_pc;
14513 if (tp->control.single_step_breakpoints == NULL)
14515 tp->control.single_step_breakpoints
14516 = new_single_step_breakpoint (tp->global_num, gdbarch);
14519 sal = find_pc_line (pc, 0);
14521 sal.section = find_pc_overlay (pc);
14522 sal.explicit_pc = 1;
14523 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
14525 update_global_location_list (UGLL_INSERT);
14528 /* Insert single step breakpoints according to the current state. */
14531 insert_single_step_breakpoints (struct gdbarch *gdbarch)
14533 struct regcache *regcache = get_current_regcache ();
14534 std::vector<CORE_ADDR> next_pcs;
14536 next_pcs = gdbarch_software_single_step (gdbarch, regcache);
14538 if (!next_pcs.empty ())
14540 struct frame_info *frame = get_current_frame ();
14541 const address_space *aspace = get_frame_address_space (frame);
14543 for (CORE_ADDR pc : next_pcs)
14544 insert_single_step_breakpoint (gdbarch, aspace, pc);
14552 /* See breakpoint.h. */
14555 breakpoint_has_location_inserted_here (struct breakpoint *bp,
14556 const address_space *aspace,
14559 struct bp_location *loc;
14561 for (loc = bp->loc; loc != NULL; loc = loc->next)
14563 && breakpoint_location_address_match (loc, aspace, pc))
14569 /* Check whether a software single-step breakpoint is inserted at
14573 single_step_breakpoint_inserted_here_p (const address_space *aspace,
14576 struct breakpoint *bpt;
14578 ALL_BREAKPOINTS (bpt)
14580 if (bpt->type == bp_single_step
14581 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
14587 /* Tracepoint-specific operations. */
14589 /* Set tracepoint count to NUM. */
14591 set_tracepoint_count (int num)
14593 tracepoint_count = num;
14594 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14598 trace_command (const char *arg, int from_tty)
14600 struct breakpoint_ops *ops;
14602 event_location_up location = string_to_event_location (&arg,
14604 if (location != NULL
14605 && event_location_type (location.get ()) == PROBE_LOCATION)
14606 ops = &tracepoint_probe_breakpoint_ops;
14608 ops = &tracepoint_breakpoint_ops;
14610 create_breakpoint (get_current_arch (),
14612 NULL, 0, arg, 1 /* parse arg */,
14614 bp_tracepoint /* type_wanted */,
14615 0 /* Ignore count */,
14616 pending_break_support,
14620 0 /* internal */, 0);
14624 ftrace_command (const char *arg, int from_tty)
14626 event_location_up location = string_to_event_location (&arg,
14628 create_breakpoint (get_current_arch (),
14630 NULL, 0, arg, 1 /* parse arg */,
14632 bp_fast_tracepoint /* type_wanted */,
14633 0 /* Ignore count */,
14634 pending_break_support,
14635 &tracepoint_breakpoint_ops,
14638 0 /* internal */, 0);
14641 /* strace command implementation. Creates a static tracepoint. */
14644 strace_command (const char *arg, int from_tty)
14646 struct breakpoint_ops *ops;
14647 event_location_up location;
14649 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14650 or with a normal static tracepoint. */
14651 if (arg && startswith (arg, "-m") && isspace (arg[2]))
14653 ops = &strace_marker_breakpoint_ops;
14654 location = new_linespec_location (&arg, symbol_name_match_type::FULL);
14658 ops = &tracepoint_breakpoint_ops;
14659 location = string_to_event_location (&arg, current_language);
14662 create_breakpoint (get_current_arch (),
14664 NULL, 0, arg, 1 /* parse arg */,
14666 bp_static_tracepoint /* type_wanted */,
14667 0 /* Ignore count */,
14668 pending_break_support,
14672 0 /* internal */, 0);
14675 /* Set up a fake reader function that gets command lines from a linked
14676 list that was acquired during tracepoint uploading. */
14678 static struct uploaded_tp *this_utp;
14679 static int next_cmd;
14682 read_uploaded_action (void)
14684 char *rslt = nullptr;
14686 if (next_cmd < this_utp->cmd_strings.size ())
14688 rslt = this_utp->cmd_strings[next_cmd];
14695 /* Given information about a tracepoint as recorded on a target (which
14696 can be either a live system or a trace file), attempt to create an
14697 equivalent GDB tracepoint. This is not a reliable process, since
14698 the target does not necessarily have all the information used when
14699 the tracepoint was originally defined. */
14701 struct tracepoint *
14702 create_tracepoint_from_upload (struct uploaded_tp *utp)
14704 const char *addr_str;
14705 char small_buf[100];
14706 struct tracepoint *tp;
14708 if (utp->at_string)
14709 addr_str = utp->at_string;
14712 /* In the absence of a source location, fall back to raw
14713 address. Since there is no way to confirm that the address
14714 means the same thing as when the trace was started, warn the
14716 warning (_("Uploaded tracepoint %d has no "
14717 "source location, using raw address"),
14719 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
14720 addr_str = small_buf;
14723 /* There's not much we can do with a sequence of bytecodes. */
14724 if (utp->cond && !utp->cond_string)
14725 warning (_("Uploaded tracepoint %d condition "
14726 "has no source form, ignoring it"),
14729 event_location_up location = string_to_event_location (&addr_str,
14731 if (!create_breakpoint (get_current_arch (),
14733 utp->cond_string, -1, addr_str,
14734 0 /* parse cond/thread */,
14736 utp->type /* type_wanted */,
14737 0 /* Ignore count */,
14738 pending_break_support,
14739 &tracepoint_breakpoint_ops,
14741 utp->enabled /* enabled */,
14743 CREATE_BREAKPOINT_FLAGS_INSERTED))
14746 /* Get the tracepoint we just created. */
14747 tp = get_tracepoint (tracepoint_count);
14748 gdb_assert (tp != NULL);
14752 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
14755 trace_pass_command (small_buf, 0);
14758 /* If we have uploaded versions of the original commands, set up a
14759 special-purpose "reader" function and call the usual command line
14760 reader, then pass the result to the breakpoint command-setting
14762 if (!utp->cmd_strings.empty ())
14764 counted_command_line cmd_list;
14769 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL);
14771 breakpoint_set_commands (tp, std::move (cmd_list));
14773 else if (!utp->actions.empty ()
14774 || !utp->step_actions.empty ())
14775 warning (_("Uploaded tracepoint %d actions "
14776 "have no source form, ignoring them"),
14779 /* Copy any status information that might be available. */
14780 tp->hit_count = utp->hit_count;
14781 tp->traceframe_usage = utp->traceframe_usage;
14786 /* Print information on tracepoint number TPNUM_EXP, or all if
14790 info_tracepoints_command (const char *args, int from_tty)
14792 struct ui_out *uiout = current_uiout;
14795 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14797 if (num_printed == 0)
14799 if (args == NULL || *args == '\0')
14800 uiout->message ("No tracepoints.\n");
14802 uiout->message ("No tracepoint matching '%s'.\n", args);
14805 default_collect_info ();
14808 /* The 'enable trace' command enables tracepoints.
14809 Not supported by all targets. */
14811 enable_trace_command (const char *args, int from_tty)
14813 enable_command (args, from_tty);
14816 /* The 'disable trace' command disables tracepoints.
14817 Not supported by all targets. */
14819 disable_trace_command (const char *args, int from_tty)
14821 disable_command (args, from_tty);
14824 /* Remove a tracepoint (or all if no argument). */
14826 delete_trace_command (const char *arg, int from_tty)
14828 struct breakpoint *b, *b_tmp;
14834 int breaks_to_delete = 0;
14836 /* Delete all breakpoints if no argument.
14837 Do not delete internal or call-dummy breakpoints, these
14838 have to be deleted with an explicit breakpoint number
14840 ALL_TRACEPOINTS (b)
14841 if (is_tracepoint (b) && user_breakpoint_p (b))
14843 breaks_to_delete = 1;
14847 /* Ask user only if there are some breakpoints to delete. */
14849 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14851 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14852 if (is_tracepoint (b) && user_breakpoint_p (b))
14853 delete_breakpoint (b);
14857 map_breakpoint_numbers
14858 (arg, [&] (breakpoint *br)
14860 iterate_over_related_breakpoints (br, delete_breakpoint);
14864 /* Helper function for trace_pass_command. */
14867 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14869 tp->pass_count = count;
14870 gdb::observers::breakpoint_modified.notify (tp);
14872 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14873 tp->number, count);
14876 /* Set passcount for tracepoint.
14878 First command argument is passcount, second is tracepoint number.
14879 If tracepoint number omitted, apply to most recently defined.
14880 Also accepts special argument "all". */
14883 trace_pass_command (const char *args, int from_tty)
14885 struct tracepoint *t1;
14888 if (args == 0 || *args == 0)
14889 error (_("passcount command requires an "
14890 "argument (count + optional TP num)"));
14892 count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */
14894 args = skip_spaces (args);
14895 if (*args && strncasecmp (args, "all", 3) == 0)
14897 struct breakpoint *b;
14899 args += 3; /* Skip special argument "all". */
14901 error (_("Junk at end of arguments."));
14903 ALL_TRACEPOINTS (b)
14905 t1 = (struct tracepoint *) b;
14906 trace_pass_set_count (t1, count, from_tty);
14909 else if (*args == '\0')
14911 t1 = get_tracepoint_by_number (&args, NULL);
14913 trace_pass_set_count (t1, count, from_tty);
14917 number_or_range_parser parser (args);
14918 while (!parser.finished ())
14920 t1 = get_tracepoint_by_number (&args, &parser);
14922 trace_pass_set_count (t1, count, from_tty);
14927 struct tracepoint *
14928 get_tracepoint (int num)
14930 struct breakpoint *t;
14932 ALL_TRACEPOINTS (t)
14933 if (t->number == num)
14934 return (struct tracepoint *) t;
14939 /* Find the tracepoint with the given target-side number (which may be
14940 different from the tracepoint number after disconnecting and
14943 struct tracepoint *
14944 get_tracepoint_by_number_on_target (int num)
14946 struct breakpoint *b;
14948 ALL_TRACEPOINTS (b)
14950 struct tracepoint *t = (struct tracepoint *) b;
14952 if (t->number_on_target == num)
14959 /* Utility: parse a tracepoint number and look it up in the list.
14960 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14961 If the argument is missing, the most recent tracepoint
14962 (tracepoint_count) is returned. */
14964 struct tracepoint *
14965 get_tracepoint_by_number (const char **arg,
14966 number_or_range_parser *parser)
14968 struct breakpoint *t;
14970 const char *instring = arg == NULL ? NULL : *arg;
14972 if (parser != NULL)
14974 gdb_assert (!parser->finished ());
14975 tpnum = parser->get_number ();
14977 else if (arg == NULL || *arg == NULL || ! **arg)
14978 tpnum = tracepoint_count;
14980 tpnum = get_number (arg);
14984 if (instring && *instring)
14985 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14988 printf_filtered (_("No previous tracepoint\n"));
14992 ALL_TRACEPOINTS (t)
14993 if (t->number == tpnum)
14995 return (struct tracepoint *) t;
14998 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15003 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15005 if (b->thread != -1)
15006 fprintf_unfiltered (fp, " thread %d", b->thread);
15009 fprintf_unfiltered (fp, " task %d", b->task);
15011 fprintf_unfiltered (fp, "\n");
15014 /* Save information on user settable breakpoints (watchpoints, etc) to
15015 a new script file named FILENAME. If FILTER is non-NULL, call it
15016 on each breakpoint and only include the ones for which it returns
15020 save_breakpoints (const char *filename, int from_tty,
15021 int (*filter) (const struct breakpoint *))
15023 struct breakpoint *tp;
15025 int extra_trace_bits = 0;
15027 if (filename == 0 || *filename == 0)
15028 error (_("Argument required (file name in which to save)"));
15030 /* See if we have anything to save. */
15031 ALL_BREAKPOINTS (tp)
15033 /* Skip internal and momentary breakpoints. */
15034 if (!user_breakpoint_p (tp))
15037 /* If we have a filter, only save the breakpoints it accepts. */
15038 if (filter && !filter (tp))
15043 if (is_tracepoint (tp))
15045 extra_trace_bits = 1;
15047 /* We can stop searching. */
15054 warning (_("Nothing to save."));
15058 gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
15062 if (!fp.open (expanded_filename.get (), "w"))
15063 error (_("Unable to open file '%s' for saving (%s)"),
15064 expanded_filename.get (), safe_strerror (errno));
15066 if (extra_trace_bits)
15067 save_trace_state_variables (&fp);
15069 ALL_BREAKPOINTS (tp)
15071 /* Skip internal and momentary breakpoints. */
15072 if (!user_breakpoint_p (tp))
15075 /* If we have a filter, only save the breakpoints it accepts. */
15076 if (filter && !filter (tp))
15079 tp->ops->print_recreate (tp, &fp);
15081 /* Note, we can't rely on tp->number for anything, as we can't
15082 assume the recreated breakpoint numbers will match. Use $bpnum
15085 if (tp->cond_string)
15086 fp.printf (" condition $bpnum %s\n", tp->cond_string);
15088 if (tp->ignore_count)
15089 fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
15091 if (tp->type != bp_dprintf && tp->commands)
15093 fp.puts (" commands\n");
15095 current_uiout->redirect (&fp);
15098 print_command_lines (current_uiout, tp->commands.get (), 2);
15100 CATCH (ex, RETURN_MASK_ALL)
15102 current_uiout->redirect (NULL);
15103 throw_exception (ex);
15107 current_uiout->redirect (NULL);
15108 fp.puts (" end\n");
15111 if (tp->enable_state == bp_disabled)
15112 fp.puts ("disable $bpnum\n");
15114 /* If this is a multi-location breakpoint, check if the locations
15115 should be individually disabled. Watchpoint locations are
15116 special, and not user visible. */
15117 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15119 struct bp_location *loc;
15122 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15124 fp.printf ("disable $bpnum.%d\n", n);
15128 if (extra_trace_bits && *default_collect)
15129 fp.printf ("set default-collect %s\n", default_collect);
15132 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ());
15135 /* The `save breakpoints' command. */
15138 save_breakpoints_command (const char *args, int from_tty)
15140 save_breakpoints (args, from_tty, NULL);
15143 /* The `save tracepoints' command. */
15146 save_tracepoints_command (const char *args, int from_tty)
15148 save_breakpoints (args, from_tty, is_tracepoint);
15151 /* Create a vector of all tracepoints. */
15153 std::vector<breakpoint *>
15154 all_tracepoints (void)
15156 std::vector<breakpoint *> tp_vec;
15157 struct breakpoint *tp;
15159 ALL_TRACEPOINTS (tp)
15161 tp_vec.push_back (tp);
15168 /* This help string is used to consolidate all the help string for specifying
15169 locations used by several commands. */
15171 #define LOCATION_HELP_STRING \
15172 "Linespecs are colon-separated lists of location parameters, such as\n\
15173 source filename, function name, label name, and line number.\n\
15174 Example: To specify the start of a label named \"the_top\" in the\n\
15175 function \"fact\" in the file \"factorial.c\", use\n\
15176 \"factorial.c:fact:the_top\".\n\
15178 Address locations begin with \"*\" and specify an exact address in the\n\
15179 program. Example: To specify the fourth byte past the start function\n\
15180 \"main\", use \"*main + 4\".\n\
15182 Explicit locations are similar to linespecs but use an option/argument\n\
15183 syntax to specify location parameters.\n\
15184 Example: To specify the start of the label named \"the_top\" in the\n\
15185 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15186 -function fact -label the_top\".\n\
15188 By default, a specified function is matched against the program's\n\
15189 functions in all scopes. For C++, this means in all namespaces and\n\
15190 classes. For Ada, this means in all packages. E.g., in C++,\n\
15191 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15192 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15193 specified name as a complete fully-qualified name instead.\n"
15195 /* This help string is used for the break, hbreak, tbreak and thbreak
15196 commands. It is defined as a macro to prevent duplication.
15197 COMMAND should be a string constant containing the name of the
15200 #define BREAK_ARGS_HELP(command) \
15201 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15202 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15203 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15204 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15205 `-probe-dtrace' (for a DTrace probe).\n\
15206 LOCATION may be a linespec, address, or explicit location as described\n\
15209 With no LOCATION, uses current execution address of the selected\n\
15210 stack frame. This is useful for breaking on return to a stack frame.\n\
15212 THREADNUM is the number from \"info threads\".\n\
15213 CONDITION is a boolean expression.\n\
15214 \n" LOCATION_HELP_STRING "\n\
15215 Multiple breakpoints at one place are permitted, and useful if their\n\
15216 conditions are different.\n\
15218 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15220 /* List of subcommands for "catch". */
15221 static struct cmd_list_element *catch_cmdlist;
15223 /* List of subcommands for "tcatch". */
15224 static struct cmd_list_element *tcatch_cmdlist;
15227 add_catch_command (const char *name, const char *docstring,
15228 cmd_const_sfunc_ftype *sfunc,
15229 completer_ftype *completer,
15230 void *user_data_catch,
15231 void *user_data_tcatch)
15233 struct cmd_list_element *command;
15235 command = add_cmd (name, class_breakpoint, docstring,
15237 set_cmd_sfunc (command, sfunc);
15238 set_cmd_context (command, user_data_catch);
15239 set_cmd_completer (command, completer);
15241 command = add_cmd (name, class_breakpoint, docstring,
15243 set_cmd_sfunc (command, sfunc);
15244 set_cmd_context (command, user_data_tcatch);
15245 set_cmd_completer (command, completer);
15249 save_command (const char *arg, int from_tty)
15251 printf_unfiltered (_("\"save\" must be followed by "
15252 "the name of a save subcommand.\n"));
15253 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15256 struct breakpoint *
15257 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15260 struct breakpoint *b, *b_tmp;
15262 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15264 if ((*callback) (b, data))
15271 /* Zero if any of the breakpoint's locations could be a location where
15272 functions have been inlined, nonzero otherwise. */
15275 is_non_inline_function (struct breakpoint *b)
15277 /* The shared library event breakpoint is set on the address of a
15278 non-inline function. */
15279 if (b->type == bp_shlib_event)
15285 /* Nonzero if the specified PC cannot be a location where functions
15286 have been inlined. */
15289 pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
15290 const struct target_waitstatus *ws)
15292 struct breakpoint *b;
15293 struct bp_location *bl;
15295 ALL_BREAKPOINTS (b)
15297 if (!is_non_inline_function (b))
15300 for (bl = b->loc; bl != NULL; bl = bl->next)
15302 if (!bl->shlib_disabled
15303 && bpstat_check_location (bl, aspace, pc, ws))
15311 /* Remove any references to OBJFILE which is going to be freed. */
15314 breakpoint_free_objfile (struct objfile *objfile)
15316 struct bp_location **locp, *loc;
15318 ALL_BP_LOCATIONS (loc, locp)
15319 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15320 loc->symtab = NULL;
15324 initialize_breakpoint_ops (void)
15326 static int initialized = 0;
15328 struct breakpoint_ops *ops;
15334 /* The breakpoint_ops structure to be inherit by all kinds of
15335 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15336 internal and momentary breakpoints, etc.). */
15337 ops = &bkpt_base_breakpoint_ops;
15338 *ops = base_breakpoint_ops;
15339 ops->re_set = bkpt_re_set;
15340 ops->insert_location = bkpt_insert_location;
15341 ops->remove_location = bkpt_remove_location;
15342 ops->breakpoint_hit = bkpt_breakpoint_hit;
15343 ops->create_sals_from_location = bkpt_create_sals_from_location;
15344 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15345 ops->decode_location = bkpt_decode_location;
15347 /* The breakpoint_ops structure to be used in regular breakpoints. */
15348 ops = &bkpt_breakpoint_ops;
15349 *ops = bkpt_base_breakpoint_ops;
15350 ops->re_set = bkpt_re_set;
15351 ops->resources_needed = bkpt_resources_needed;
15352 ops->print_it = bkpt_print_it;
15353 ops->print_mention = bkpt_print_mention;
15354 ops->print_recreate = bkpt_print_recreate;
15356 /* Ranged breakpoints. */
15357 ops = &ranged_breakpoint_ops;
15358 *ops = bkpt_breakpoint_ops;
15359 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15360 ops->resources_needed = resources_needed_ranged_breakpoint;
15361 ops->print_it = print_it_ranged_breakpoint;
15362 ops->print_one = print_one_ranged_breakpoint;
15363 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15364 ops->print_mention = print_mention_ranged_breakpoint;
15365 ops->print_recreate = print_recreate_ranged_breakpoint;
15367 /* Internal breakpoints. */
15368 ops = &internal_breakpoint_ops;
15369 *ops = bkpt_base_breakpoint_ops;
15370 ops->re_set = internal_bkpt_re_set;
15371 ops->check_status = internal_bkpt_check_status;
15372 ops->print_it = internal_bkpt_print_it;
15373 ops->print_mention = internal_bkpt_print_mention;
15375 /* Momentary breakpoints. */
15376 ops = &momentary_breakpoint_ops;
15377 *ops = bkpt_base_breakpoint_ops;
15378 ops->re_set = momentary_bkpt_re_set;
15379 ops->check_status = momentary_bkpt_check_status;
15380 ops->print_it = momentary_bkpt_print_it;
15381 ops->print_mention = momentary_bkpt_print_mention;
15383 /* Probe breakpoints. */
15384 ops = &bkpt_probe_breakpoint_ops;
15385 *ops = bkpt_breakpoint_ops;
15386 ops->insert_location = bkpt_probe_insert_location;
15387 ops->remove_location = bkpt_probe_remove_location;
15388 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
15389 ops->decode_location = bkpt_probe_decode_location;
15392 ops = &watchpoint_breakpoint_ops;
15393 *ops = base_breakpoint_ops;
15394 ops->re_set = re_set_watchpoint;
15395 ops->insert_location = insert_watchpoint;
15396 ops->remove_location = remove_watchpoint;
15397 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15398 ops->check_status = check_status_watchpoint;
15399 ops->resources_needed = resources_needed_watchpoint;
15400 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15401 ops->print_it = print_it_watchpoint;
15402 ops->print_mention = print_mention_watchpoint;
15403 ops->print_recreate = print_recreate_watchpoint;
15404 ops->explains_signal = explains_signal_watchpoint;
15406 /* Masked watchpoints. */
15407 ops = &masked_watchpoint_breakpoint_ops;
15408 *ops = watchpoint_breakpoint_ops;
15409 ops->insert_location = insert_masked_watchpoint;
15410 ops->remove_location = remove_masked_watchpoint;
15411 ops->resources_needed = resources_needed_masked_watchpoint;
15412 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15413 ops->print_it = print_it_masked_watchpoint;
15414 ops->print_one_detail = print_one_detail_masked_watchpoint;
15415 ops->print_mention = print_mention_masked_watchpoint;
15416 ops->print_recreate = print_recreate_masked_watchpoint;
15419 ops = &tracepoint_breakpoint_ops;
15420 *ops = base_breakpoint_ops;
15421 ops->re_set = tracepoint_re_set;
15422 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15423 ops->print_one_detail = tracepoint_print_one_detail;
15424 ops->print_mention = tracepoint_print_mention;
15425 ops->print_recreate = tracepoint_print_recreate;
15426 ops->create_sals_from_location = tracepoint_create_sals_from_location;
15427 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15428 ops->decode_location = tracepoint_decode_location;
15430 /* Probe tracepoints. */
15431 ops = &tracepoint_probe_breakpoint_ops;
15432 *ops = tracepoint_breakpoint_ops;
15433 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
15434 ops->decode_location = tracepoint_probe_decode_location;
15436 /* Static tracepoints with marker (`-m'). */
15437 ops = &strace_marker_breakpoint_ops;
15438 *ops = tracepoint_breakpoint_ops;
15439 ops->create_sals_from_location = strace_marker_create_sals_from_location;
15440 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15441 ops->decode_location = strace_marker_decode_location;
15443 /* Fork catchpoints. */
15444 ops = &catch_fork_breakpoint_ops;
15445 *ops = base_breakpoint_ops;
15446 ops->insert_location = insert_catch_fork;
15447 ops->remove_location = remove_catch_fork;
15448 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15449 ops->print_it = print_it_catch_fork;
15450 ops->print_one = print_one_catch_fork;
15451 ops->print_mention = print_mention_catch_fork;
15452 ops->print_recreate = print_recreate_catch_fork;
15454 /* Vfork catchpoints. */
15455 ops = &catch_vfork_breakpoint_ops;
15456 *ops = base_breakpoint_ops;
15457 ops->insert_location = insert_catch_vfork;
15458 ops->remove_location = remove_catch_vfork;
15459 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15460 ops->print_it = print_it_catch_vfork;
15461 ops->print_one = print_one_catch_vfork;
15462 ops->print_mention = print_mention_catch_vfork;
15463 ops->print_recreate = print_recreate_catch_vfork;
15465 /* Exec catchpoints. */
15466 ops = &catch_exec_breakpoint_ops;
15467 *ops = base_breakpoint_ops;
15468 ops->insert_location = insert_catch_exec;
15469 ops->remove_location = remove_catch_exec;
15470 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15471 ops->print_it = print_it_catch_exec;
15472 ops->print_one = print_one_catch_exec;
15473 ops->print_mention = print_mention_catch_exec;
15474 ops->print_recreate = print_recreate_catch_exec;
15476 /* Solib-related catchpoints. */
15477 ops = &catch_solib_breakpoint_ops;
15478 *ops = base_breakpoint_ops;
15479 ops->insert_location = insert_catch_solib;
15480 ops->remove_location = remove_catch_solib;
15481 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15482 ops->check_status = check_status_catch_solib;
15483 ops->print_it = print_it_catch_solib;
15484 ops->print_one = print_one_catch_solib;
15485 ops->print_mention = print_mention_catch_solib;
15486 ops->print_recreate = print_recreate_catch_solib;
15488 ops = &dprintf_breakpoint_ops;
15489 *ops = bkpt_base_breakpoint_ops;
15490 ops->re_set = dprintf_re_set;
15491 ops->resources_needed = bkpt_resources_needed;
15492 ops->print_it = bkpt_print_it;
15493 ops->print_mention = bkpt_print_mention;
15494 ops->print_recreate = dprintf_print_recreate;
15495 ops->after_condition_true = dprintf_after_condition_true;
15496 ops->breakpoint_hit = dprintf_breakpoint_hit;
15499 /* Chain containing all defined "enable breakpoint" subcommands. */
15501 static struct cmd_list_element *enablebreaklist = NULL;
15503 /* See breakpoint.h. */
15505 cmd_list_element *commands_cmd_element = nullptr;
15508 _initialize_breakpoint (void)
15510 struct cmd_list_element *c;
15512 initialize_breakpoint_ops ();
15514 gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib);
15515 gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile);
15516 gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change);
15518 breakpoint_objfile_key
15519 = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data);
15521 breakpoint_chain = 0;
15522 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15523 before a breakpoint is set. */
15524 breakpoint_count = 0;
15526 tracepoint_count = 0;
15528 add_com ("ignore", class_breakpoint, ignore_command, _("\
15529 Set ignore-count of breakpoint number N to COUNT.\n\
15530 Usage is `ignore N COUNT'."));
15532 commands_cmd_element = add_com ("commands", class_breakpoint,
15533 commands_command, _("\
15534 Set commands to be executed when the given breakpoints are hit.\n\
15535 Give a space-separated breakpoint list as argument after \"commands\".\n\
15536 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15538 With no argument, the targeted breakpoint is the last one set.\n\
15539 The commands themselves follow starting on the next line.\n\
15540 Type a line containing \"end\" to indicate the end of them.\n\
15541 Give \"silent\" as the first line to make the breakpoint silent;\n\
15542 then no output is printed when it is hit, except what the commands print."));
15544 c = add_com ("condition", class_breakpoint, condition_command, _("\
15545 Specify breakpoint number N to break only if COND is true.\n\
15546 Usage is `condition N COND', where N is an integer and COND is an\n\
15547 expression to be evaluated whenever breakpoint N is reached."));
15548 set_cmd_completer (c, condition_completer);
15550 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15551 Set a temporary breakpoint.\n\
15552 Like \"break\" except the breakpoint is only temporary,\n\
15553 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15554 by using \"enable delete\" on the breakpoint number.\n\
15556 BREAK_ARGS_HELP ("tbreak")));
15557 set_cmd_completer (c, location_completer);
15559 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15560 Set a hardware assisted breakpoint.\n\
15561 Like \"break\" except the breakpoint requires hardware support,\n\
15562 some target hardware may not have this support.\n\
15564 BREAK_ARGS_HELP ("hbreak")));
15565 set_cmd_completer (c, location_completer);
15567 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15568 Set a temporary hardware assisted breakpoint.\n\
15569 Like \"hbreak\" except the breakpoint is only temporary,\n\
15570 so it will be deleted when hit.\n\
15572 BREAK_ARGS_HELP ("thbreak")));
15573 set_cmd_completer (c, location_completer);
15575 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15576 Enable some breakpoints.\n\
15577 Give breakpoint numbers (separated by spaces) as arguments.\n\
15578 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15579 This is used to cancel the effect of the \"disable\" command.\n\
15580 With a subcommand you can enable temporarily."),
15581 &enablelist, "enable ", 1, &cmdlist);
15583 add_com_alias ("en", "enable", class_breakpoint, 1);
15585 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15586 Enable some breakpoints.\n\
15587 Give breakpoint numbers (separated by spaces) as arguments.\n\
15588 This is used to cancel the effect of the \"disable\" command.\n\
15589 May be abbreviated to simply \"enable\".\n"),
15590 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15592 add_cmd ("once", no_class, enable_once_command, _("\
15593 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15594 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15597 add_cmd ("delete", no_class, enable_delete_command, _("\
15598 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15599 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15602 add_cmd ("count", no_class, enable_count_command, _("\
15603 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15604 If a breakpoint is hit while enabled in this fashion,\n\
15605 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15608 add_cmd ("delete", no_class, enable_delete_command, _("\
15609 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15610 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15613 add_cmd ("once", no_class, enable_once_command, _("\
15614 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15615 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15618 add_cmd ("count", no_class, enable_count_command, _("\
15619 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15620 If a breakpoint is hit while enabled in this fashion,\n\
15621 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15624 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15625 Disable some breakpoints.\n\
15626 Arguments are breakpoint numbers with spaces in between.\n\
15627 To disable all breakpoints, give no argument.\n\
15628 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15629 &disablelist, "disable ", 1, &cmdlist);
15630 add_com_alias ("dis", "disable", class_breakpoint, 1);
15631 add_com_alias ("disa", "disable", class_breakpoint, 1);
15633 add_cmd ("breakpoints", class_alias, disable_command, _("\
15634 Disable some breakpoints.\n\
15635 Arguments are breakpoint numbers with spaces in between.\n\
15636 To disable all breakpoints, give no argument.\n\
15637 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15638 This command may be abbreviated \"disable\"."),
15641 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15642 Delete some breakpoints or auto-display expressions.\n\
15643 Arguments are breakpoint numbers with spaces in between.\n\
15644 To delete all breakpoints, give no argument.\n\
15646 Also a prefix command for deletion of other GDB objects.\n\
15647 The \"unset\" command is also an alias for \"delete\"."),
15648 &deletelist, "delete ", 1, &cmdlist);
15649 add_com_alias ("d", "delete", class_breakpoint, 1);
15650 add_com_alias ("del", "delete", class_breakpoint, 1);
15652 add_cmd ("breakpoints", class_alias, delete_command, _("\
15653 Delete some breakpoints or auto-display expressions.\n\
15654 Arguments are breakpoint numbers with spaces in between.\n\
15655 To delete all breakpoints, give no argument.\n\
15656 This command may be abbreviated \"delete\"."),
15659 add_com ("clear", class_breakpoint, clear_command, _("\
15660 Clear breakpoint at specified location.\n\
15661 Argument may be a linespec, explicit, or address location as described below.\n\
15663 With no argument, clears all breakpoints in the line that the selected frame\n\
15664 is executing in.\n"
15665 "\n" LOCATION_HELP_STRING "\n\
15666 See also the \"delete\" command which clears breakpoints by number."));
15667 add_com_alias ("cl", "clear", class_breakpoint, 1);
15669 c = add_com ("break", class_breakpoint, break_command, _("\
15670 Set breakpoint at specified location.\n"
15671 BREAK_ARGS_HELP ("break")));
15672 set_cmd_completer (c, location_completer);
15674 add_com_alias ("b", "break", class_run, 1);
15675 add_com_alias ("br", "break", class_run, 1);
15676 add_com_alias ("bre", "break", class_run, 1);
15677 add_com_alias ("brea", "break", class_run, 1);
15681 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15682 Break in function/address or break at a line in the current file."),
15683 &stoplist, "stop ", 1, &cmdlist);
15684 add_cmd ("in", class_breakpoint, stopin_command,
15685 _("Break in function or address."), &stoplist);
15686 add_cmd ("at", class_breakpoint, stopat_command,
15687 _("Break at a line in the current file."), &stoplist);
15688 add_com ("status", class_info, info_breakpoints_command, _("\
15689 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15690 The \"Type\" column indicates one of:\n\
15691 \tbreakpoint - normal breakpoint\n\
15692 \twatchpoint - watchpoint\n\
15693 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15694 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15695 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15696 address and file/line number respectively.\n\
15698 Convenience variable \"$_\" and default examine address for \"x\"\n\
15699 are set to the address of the last breakpoint listed unless the command\n\
15700 is prefixed with \"server \".\n\n\
15701 Convenience variable \"$bpnum\" contains the number of the last\n\
15702 breakpoint set."));
15705 add_info ("breakpoints", info_breakpoints_command, _("\
15706 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15707 The \"Type\" column indicates one of:\n\
15708 \tbreakpoint - normal breakpoint\n\
15709 \twatchpoint - watchpoint\n\
15710 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15711 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15712 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15713 address and file/line number respectively.\n\
15715 Convenience variable \"$_\" and default examine address for \"x\"\n\
15716 are set to the address of the last breakpoint listed unless the command\n\
15717 is prefixed with \"server \".\n\n\
15718 Convenience variable \"$bpnum\" contains the number of the last\n\
15719 breakpoint set."));
15721 add_info_alias ("b", "breakpoints", 1);
15723 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15724 Status of all breakpoints, or breakpoint number NUMBER.\n\
15725 The \"Type\" column indicates one of:\n\
15726 \tbreakpoint - normal breakpoint\n\
15727 \twatchpoint - watchpoint\n\
15728 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15729 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15730 \tuntil - internal breakpoint used by the \"until\" command\n\
15731 \tfinish - internal breakpoint used by the \"finish\" command\n\
15732 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15733 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15734 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15735 address and file/line number respectively.\n\
15737 Convenience variable \"$_\" and default examine address for \"x\"\n\
15738 are set to the address of the last breakpoint listed unless the command\n\
15739 is prefixed with \"server \".\n\n\
15740 Convenience variable \"$bpnum\" contains the number of the last\n\
15742 &maintenanceinfolist);
15744 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15745 Set catchpoints to catch events."),
15746 &catch_cmdlist, "catch ",
15747 0/*allow-unknown*/, &cmdlist);
15749 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15750 Set temporary catchpoints to catch events."),
15751 &tcatch_cmdlist, "tcatch ",
15752 0/*allow-unknown*/, &cmdlist);
15754 add_catch_command ("fork", _("Catch calls to fork."),
15755 catch_fork_command_1,
15757 (void *) (uintptr_t) catch_fork_permanent,
15758 (void *) (uintptr_t) catch_fork_temporary);
15759 add_catch_command ("vfork", _("Catch calls to vfork."),
15760 catch_fork_command_1,
15762 (void *) (uintptr_t) catch_vfork_permanent,
15763 (void *) (uintptr_t) catch_vfork_temporary);
15764 add_catch_command ("exec", _("Catch calls to exec."),
15765 catch_exec_command_1,
15769 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15770 Usage: catch load [REGEX]\n\
15771 If REGEX is given, only stop for libraries matching the regular expression."),
15772 catch_load_command_1,
15776 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15777 Usage: catch unload [REGEX]\n\
15778 If REGEX is given, only stop for libraries matching the regular expression."),
15779 catch_unload_command_1,
15784 c = add_com ("watch", class_breakpoint, watch_command, _("\
15785 Set a watchpoint for an expression.\n\
15786 Usage: watch [-l|-location] EXPRESSION\n\
15787 A watchpoint stops execution of your program whenever the value of\n\
15788 an expression changes.\n\
15789 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15790 the memory to which it refers."));
15791 set_cmd_completer (c, expression_completer);
15793 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15794 Set a read watchpoint for an expression.\n\
15795 Usage: rwatch [-l|-location] EXPRESSION\n\
15796 A watchpoint stops execution of your program whenever the value of\n\
15797 an expression is read.\n\
15798 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15799 the memory to which it refers."));
15800 set_cmd_completer (c, expression_completer);
15802 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15803 Set a watchpoint for an expression.\n\
15804 Usage: awatch [-l|-location] EXPRESSION\n\
15805 A watchpoint stops execution of your program whenever the value of\n\
15806 an expression is either read or written.\n\
15807 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15808 the memory to which it refers."));
15809 set_cmd_completer (c, expression_completer);
15811 add_info ("watchpoints", info_watchpoints_command, _("\
15812 Status of specified watchpoints (all watchpoints if no argument)."));
15814 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15815 respond to changes - contrary to the description. */
15816 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15817 &can_use_hw_watchpoints, _("\
15818 Set debugger's willingness to use watchpoint hardware."), _("\
15819 Show debugger's willingness to use watchpoint hardware."), _("\
15820 If zero, gdb will not use hardware for new watchpoints, even if\n\
15821 such is available. (However, any hardware watchpoints that were\n\
15822 created before setting this to nonzero, will continue to use watchpoint\n\
15825 show_can_use_hw_watchpoints,
15826 &setlist, &showlist);
15828 can_use_hw_watchpoints = 1;
15830 /* Tracepoint manipulation commands. */
15832 c = add_com ("trace", class_breakpoint, trace_command, _("\
15833 Set a tracepoint at specified location.\n\
15835 BREAK_ARGS_HELP ("trace") "\n\
15836 Do \"help tracepoints\" for info on other tracepoint commands."));
15837 set_cmd_completer (c, location_completer);
15839 add_com_alias ("tp", "trace", class_alias, 0);
15840 add_com_alias ("tr", "trace", class_alias, 1);
15841 add_com_alias ("tra", "trace", class_alias, 1);
15842 add_com_alias ("trac", "trace", class_alias, 1);
15844 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15845 Set a fast tracepoint at specified location.\n\
15847 BREAK_ARGS_HELP ("ftrace") "\n\
15848 Do \"help tracepoints\" for info on other tracepoint commands."));
15849 set_cmd_completer (c, location_completer);
15851 c = add_com ("strace", class_breakpoint, strace_command, _("\
15852 Set a static tracepoint at location or marker.\n\
15854 strace [LOCATION] [if CONDITION]\n\
15855 LOCATION may be a linespec, explicit, or address location (described below) \n\
15856 or -m MARKER_ID.\n\n\
15857 If a marker id is specified, probe the marker with that name. With\n\
15858 no LOCATION, uses current execution address of the selected stack frame.\n\
15859 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15860 This collects arbitrary user data passed in the probe point call to the\n\
15861 tracing library. You can inspect it when analyzing the trace buffer,\n\
15862 by printing the $_sdata variable like any other convenience variable.\n\
15864 CONDITION is a boolean expression.\n\
15865 \n" LOCATION_HELP_STRING "\n\
15866 Multiple tracepoints at one place are permitted, and useful if their\n\
15867 conditions are different.\n\
15869 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15870 Do \"help tracepoints\" for info on other tracepoint commands."));
15871 set_cmd_completer (c, location_completer);
15873 add_info ("tracepoints", info_tracepoints_command, _("\
15874 Status of specified tracepoints (all tracepoints if no argument).\n\
15875 Convenience variable \"$tpnum\" contains the number of the\n\
15876 last tracepoint set."));
15878 add_info_alias ("tp", "tracepoints", 1);
15880 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15881 Delete specified tracepoints.\n\
15882 Arguments are tracepoint numbers, separated by spaces.\n\
15883 No argument means delete all tracepoints."),
15885 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
15887 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15888 Disable specified tracepoints.\n\
15889 Arguments are tracepoint numbers, separated by spaces.\n\
15890 No argument means disable all tracepoints."),
15892 deprecate_cmd (c, "disable");
15894 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15895 Enable specified tracepoints.\n\
15896 Arguments are tracepoint numbers, separated by spaces.\n\
15897 No argument means enable all tracepoints."),
15899 deprecate_cmd (c, "enable");
15901 add_com ("passcount", class_trace, trace_pass_command, _("\
15902 Set the passcount for a tracepoint.\n\
15903 The trace will end when the tracepoint has been passed 'count' times.\n\
15904 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15905 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15907 add_prefix_cmd ("save", class_breakpoint, save_command,
15908 _("Save breakpoint definitions as a script."),
15909 &save_cmdlist, "save ",
15910 0/*allow-unknown*/, &cmdlist);
15912 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15913 Save current breakpoint definitions as a script.\n\
15914 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15915 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15916 session to restore them."),
15918 set_cmd_completer (c, filename_completer);
15920 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15921 Save current tracepoint definitions as a script.\n\
15922 Use the 'source' command in another debug session to restore them."),
15924 set_cmd_completer (c, filename_completer);
15926 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15927 deprecate_cmd (c, "save tracepoints");
15929 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15930 Breakpoint specific settings\n\
15931 Configure various breakpoint-specific variables such as\n\
15932 pending breakpoint behavior"),
15933 &breakpoint_set_cmdlist, "set breakpoint ",
15934 0/*allow-unknown*/, &setlist);
15935 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15936 Breakpoint specific settings\n\
15937 Configure various breakpoint-specific variables such as\n\
15938 pending breakpoint behavior"),
15939 &breakpoint_show_cmdlist, "show breakpoint ",
15940 0/*allow-unknown*/, &showlist);
15942 add_setshow_auto_boolean_cmd ("pending", no_class,
15943 &pending_break_support, _("\
15944 Set debugger's behavior regarding pending breakpoints."), _("\
15945 Show debugger's behavior regarding pending breakpoints."), _("\
15946 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15947 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15948 an error. If auto, an unrecognized breakpoint location results in a\n\
15949 user-query to see if a pending breakpoint should be created."),
15951 show_pending_break_support,
15952 &breakpoint_set_cmdlist,
15953 &breakpoint_show_cmdlist);
15955 pending_break_support = AUTO_BOOLEAN_AUTO;
15957 add_setshow_boolean_cmd ("auto-hw", no_class,
15958 &automatic_hardware_breakpoints, _("\
15959 Set automatic usage of hardware breakpoints."), _("\
15960 Show automatic usage of hardware breakpoints."), _("\
15961 If set, the debugger will automatically use hardware breakpoints for\n\
15962 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15963 a warning will be emitted for such breakpoints."),
15965 show_automatic_hardware_breakpoints,
15966 &breakpoint_set_cmdlist,
15967 &breakpoint_show_cmdlist);
15969 add_setshow_boolean_cmd ("always-inserted", class_support,
15970 &always_inserted_mode, _("\
15971 Set mode for inserting breakpoints."), _("\
15972 Show mode for inserting breakpoints."), _("\
15973 When this mode is on, breakpoints are inserted immediately as soon as\n\
15974 they're created, kept inserted even when execution stops, and removed\n\
15975 only when the user deletes them. When this mode is off (the default),\n\
15976 breakpoints are inserted only when execution continues, and removed\n\
15977 when execution stops."),
15979 &show_always_inserted_mode,
15980 &breakpoint_set_cmdlist,
15981 &breakpoint_show_cmdlist);
15983 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
15984 condition_evaluation_enums,
15985 &condition_evaluation_mode_1, _("\
15986 Set mode of breakpoint condition evaluation."), _("\
15987 Show mode of breakpoint condition evaluation."), _("\
15988 When this is set to \"host\", breakpoint conditions will be\n\
15989 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15990 breakpoint conditions will be downloaded to the target (if the target\n\
15991 supports such feature) and conditions will be evaluated on the target's side.\n\
15992 If this is set to \"auto\" (default), this will be automatically set to\n\
15993 \"target\" if it supports condition evaluation, otherwise it will\n\
15994 be set to \"gdb\""),
15995 &set_condition_evaluation_mode,
15996 &show_condition_evaluation_mode,
15997 &breakpoint_set_cmdlist,
15998 &breakpoint_show_cmdlist);
16000 add_com ("break-range", class_breakpoint, break_range_command, _("\
16001 Set a breakpoint for an address range.\n\
16002 break-range START-LOCATION, END-LOCATION\n\
16003 where START-LOCATION and END-LOCATION can be one of the following:\n\
16004 LINENUM, for that line in the current file,\n\
16005 FILE:LINENUM, for that line in that file,\n\
16006 +OFFSET, for that number of lines after the current line\n\
16007 or the start of the range\n\
16008 FUNCTION, for the first line in that function,\n\
16009 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16010 *ADDRESS, for the instruction at that address.\n\
16012 The breakpoint will stop execution of the inferior whenever it executes\n\
16013 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16014 range (including START-LOCATION and END-LOCATION)."));
16016 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16017 Set a dynamic printf at specified location.\n\
16018 dprintf location,format string,arg1,arg2,...\n\
16019 location may be a linespec, explicit, or address location.\n"
16020 "\n" LOCATION_HELP_STRING));
16021 set_cmd_completer (c, location_completer);
16023 add_setshow_enum_cmd ("dprintf-style", class_support,
16024 dprintf_style_enums, &dprintf_style, _("\
16025 Set the style of usage for dynamic printf."), _("\
16026 Show the style of usage for dynamic printf."), _("\
16027 This setting chooses how GDB will do a dynamic printf.\n\
16028 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16029 console, as with the \"printf\" command.\n\
16030 If the value is \"call\", the print is done by calling a function in your\n\
16031 program; by default printf(), but you can choose a different function or\n\
16032 output stream by setting dprintf-function and dprintf-channel."),
16033 update_dprintf_commands, NULL,
16034 &setlist, &showlist);
16036 dprintf_function = xstrdup ("printf");
16037 add_setshow_string_cmd ("dprintf-function", class_support,
16038 &dprintf_function, _("\
16039 Set the function to use for dynamic printf"), _("\
16040 Show the function to use for dynamic printf"), NULL,
16041 update_dprintf_commands, NULL,
16042 &setlist, &showlist);
16044 dprintf_channel = xstrdup ("");
16045 add_setshow_string_cmd ("dprintf-channel", class_support,
16046 &dprintf_channel, _("\
16047 Set the channel to use for dynamic printf"), _("\
16048 Show the channel to use for dynamic printf"), NULL,
16049 update_dprintf_commands, NULL,
16050 &setlist, &showlist);
16052 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16053 &disconnected_dprintf, _("\
16054 Set whether dprintf continues after GDB disconnects."), _("\
16055 Show whether dprintf continues after GDB disconnects."), _("\
16056 Use this to let dprintf commands continue to hit and produce output\n\
16057 even if GDB disconnects or detaches from the target."),
16060 &setlist, &showlist);
16062 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16063 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16064 (target agent only) This is useful for formatted output in user-defined commands."));
16066 automatic_hardware_breakpoints = 1;
16068 gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed);
16069 gdb::observers::thread_exit.attach (remove_threaded_breakpoints);