1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.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 ignore_command (char *, int);
101 static void breakpoint_re_set_default (struct breakpoint *);
104 create_sals_from_location_default (const struct event_location *location,
105 struct linespec_result *canonical,
106 enum bptype type_wanted);
108 static void create_breakpoints_sal_default (struct gdbarch *,
109 struct linespec_result *,
110 gdb::unique_xmalloc_ptr<char>,
111 gdb::unique_xmalloc_ptr<char>,
113 enum bpdisp, int, int,
115 const struct breakpoint_ops *,
116 int, int, int, unsigned);
118 static std::vector<symtab_and_line> decode_location_default
119 (struct breakpoint *b, const struct event_location *location,
120 struct program_space *search_pspace);
122 static void clear_command (char *, int);
124 static int can_use_hardware_watchpoint (struct value *);
126 static void mention (struct breakpoint *);
128 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
130 const struct breakpoint_ops *);
131 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
132 const struct symtab_and_line *);
134 /* This function is used in gdbtk sources and thus can not be made
136 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
137 struct symtab_and_line,
139 const struct breakpoint_ops *);
141 static struct breakpoint *
142 momentary_breakpoint_from_master (struct breakpoint *orig,
144 const struct breakpoint_ops *ops,
147 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
149 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
153 static void describe_other_breakpoints (struct gdbarch *,
154 struct program_space *, CORE_ADDR,
155 struct obj_section *, int);
157 static int watchpoint_locations_match (struct bp_location *loc1,
158 struct bp_location *loc2);
160 static int breakpoint_location_address_match (struct bp_location *bl,
161 const struct address_space *aspace,
164 static int breakpoint_location_address_range_overlap (struct bp_location *,
165 const address_space *,
168 static void info_breakpoints_command (char *, int);
170 static void info_watchpoints_command (char *, int);
172 static void commands_command (char *, int);
174 static void condition_command (char *, int);
176 static int remove_breakpoint (struct bp_location *);
177 static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
179 static enum print_stop_action print_bp_stop_message (bpstat bs);
181 static int hw_breakpoint_used_count (void);
183 static int hw_watchpoint_use_count (struct breakpoint *);
185 static int hw_watchpoint_used_count_others (struct breakpoint *except,
187 int *other_type_used);
189 static void hbreak_command (char *, int);
191 static void thbreak_command (char *, int);
193 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
196 static void stop_command (char *arg, int from_tty);
198 static void free_bp_location (struct bp_location *loc);
199 static void incref_bp_location (struct bp_location *loc);
200 static void decref_bp_location (struct bp_location **loc);
202 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
204 /* update_global_location_list's modes of operation wrt to whether to
205 insert locations now. */
206 enum ugll_insert_mode
208 /* Don't insert any breakpoint locations into the inferior, only
209 remove already-inserted locations that no longer should be
210 inserted. Functions that delete a breakpoint or breakpoints
211 should specify this mode, so that deleting a breakpoint doesn't
212 have the side effect of inserting the locations of other
213 breakpoints that are marked not-inserted, but should_be_inserted
214 returns true on them.
216 This behavior is useful is situations close to tear-down -- e.g.,
217 after an exec, while the target still has execution, but
218 breakpoint shadows of the previous executable image should *NOT*
219 be restored to the new image; or before detaching, where the
220 target still has execution and wants to delete breakpoints from
221 GDB's lists, and all breakpoints had already been removed from
225 /* May insert breakpoints iff breakpoints_should_be_inserted_now
226 claims breakpoints should be inserted now. */
229 /* Insert locations now, irrespective of
230 breakpoints_should_be_inserted_now. E.g., say all threads are
231 stopped right now, and the user did "continue". We need to
232 insert breakpoints _before_ resuming the target, but
233 UGLL_MAY_INSERT wouldn't insert them, because
234 breakpoints_should_be_inserted_now returns false at that point,
235 as no thread is running yet. */
239 static void update_global_location_list (enum ugll_insert_mode);
241 static void update_global_location_list_nothrow (enum ugll_insert_mode);
243 static int is_hardware_watchpoint (const struct breakpoint *bpt);
245 static void insert_breakpoint_locations (void);
247 static void info_tracepoints_command (char *, int);
249 static void enable_trace_command (char *, int);
251 static void disable_trace_command (char *, int);
253 static void trace_pass_command (char *, int);
255 static void set_tracepoint_count (int num);
257 static int is_masked_watchpoint (const struct breakpoint *b);
259 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
261 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
264 static int strace_marker_p (struct breakpoint *b);
266 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
267 that are implemented on top of software or hardware breakpoints
268 (user breakpoints, internal and momentary breakpoints, etc.). */
269 static struct breakpoint_ops bkpt_base_breakpoint_ops;
271 /* Internal breakpoints class type. */
272 static struct breakpoint_ops internal_breakpoint_ops;
274 /* Momentary breakpoints class type. */
275 static struct breakpoint_ops momentary_breakpoint_ops;
277 /* The breakpoint_ops structure to be used in regular user created
279 struct breakpoint_ops bkpt_breakpoint_ops;
281 /* Breakpoints set on probes. */
282 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
284 /* Dynamic printf class type. */
285 struct breakpoint_ops dprintf_breakpoint_ops;
287 /* The style in which to perform a dynamic printf. This is a user
288 option because different output options have different tradeoffs;
289 if GDB does the printing, there is better error handling if there
290 is a problem with any of the arguments, but using an inferior
291 function lets you have special-purpose printers and sending of
292 output to the same place as compiled-in print functions. */
294 static const char dprintf_style_gdb[] = "gdb";
295 static const char dprintf_style_call[] = "call";
296 static const char dprintf_style_agent[] = "agent";
297 static const char *const dprintf_style_enums[] = {
303 static const char *dprintf_style = dprintf_style_gdb;
305 /* The function to use for dynamic printf if the preferred style is to
306 call into the inferior. The value is simply a string that is
307 copied into the command, so it can be anything that GDB can
308 evaluate to a callable address, not necessarily a function name. */
310 static char *dprintf_function;
312 /* The channel to use for dynamic printf if the preferred style is to
313 call into the inferior; if a nonempty string, it will be passed to
314 the call as the first argument, with the format string as the
315 second. As with the dprintf function, this can be anything that
316 GDB knows how to evaluate, so in addition to common choices like
317 "stderr", this could be an app-specific expression like
318 "mystreams[curlogger]". */
320 static char *dprintf_channel;
322 /* True if dprintf commands should continue to operate even if GDB
324 static int disconnected_dprintf = 1;
326 struct command_line *
327 breakpoint_commands (struct breakpoint *b)
329 return b->commands ? b->commands.get () : NULL;
332 /* Flag indicating that a command has proceeded the inferior past the
333 current breakpoint. */
335 static int breakpoint_proceeded;
338 bpdisp_text (enum bpdisp disp)
340 /* NOTE: the following values are a part of MI protocol and
341 represent values of 'disp' field returned when inferior stops at
343 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
345 return bpdisps[(int) disp];
348 /* Prototypes for exported functions. */
349 /* If FALSE, gdb will not use hardware support for watchpoints, even
350 if such is available. */
351 static int can_use_hw_watchpoints;
354 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
355 struct cmd_list_element *c,
358 fprintf_filtered (file,
359 _("Debugger's willingness to use "
360 "watchpoint hardware is %s.\n"),
364 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
365 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
366 for unrecognized breakpoint locations.
367 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
368 static enum auto_boolean pending_break_support;
370 show_pending_break_support (struct ui_file *file, int from_tty,
371 struct cmd_list_element *c,
374 fprintf_filtered (file,
375 _("Debugger's behavior regarding "
376 "pending breakpoints is %s.\n"),
380 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
381 set with "break" but falling in read-only memory.
382 If 0, gdb will warn about such breakpoints, but won't automatically
383 use hardware breakpoints. */
384 static int automatic_hardware_breakpoints;
386 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
387 struct cmd_list_element *c,
390 fprintf_filtered (file,
391 _("Automatic usage of hardware breakpoints is %s.\n"),
395 /* If on, GDB keeps breakpoints inserted even if the inferior is
396 stopped, and immediately inserts any new breakpoints as soon as
397 they're created. If off (default), GDB keeps breakpoints off of
398 the target as long as possible. That is, it delays inserting
399 breakpoints until the next resume, and removes them again when the
400 target fully stops. This is a bit safer in case GDB crashes while
401 processing user input. */
402 static int always_inserted_mode = 0;
405 show_always_inserted_mode (struct ui_file *file, int from_tty,
406 struct cmd_list_element *c, const char *value)
408 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
412 /* See breakpoint.h. */
415 breakpoints_should_be_inserted_now (void)
417 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
419 /* If breakpoints are global, they should be inserted even if no
420 thread under gdb's control is running, or even if there are
421 no threads under GDB's control yet. */
424 else if (target_has_execution)
426 struct thread_info *tp;
428 if (always_inserted_mode)
430 /* The user wants breakpoints inserted even if all threads
435 if (threads_are_executing ())
438 /* Don't remove breakpoints yet if, even though all threads are
439 stopped, we still have events to process. */
440 ALL_NON_EXITED_THREADS (tp)
442 && tp->suspend.waitstatus_pending_p)
448 static const char condition_evaluation_both[] = "host or target";
450 /* Modes for breakpoint condition evaluation. */
451 static const char condition_evaluation_auto[] = "auto";
452 static const char condition_evaluation_host[] = "host";
453 static const char condition_evaluation_target[] = "target";
454 static const char *const condition_evaluation_enums[] = {
455 condition_evaluation_auto,
456 condition_evaluation_host,
457 condition_evaluation_target,
461 /* Global that holds the current mode for breakpoint condition evaluation. */
462 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
464 /* Global that we use to display information to the user (gets its value from
465 condition_evaluation_mode_1. */
466 static const char *condition_evaluation_mode = condition_evaluation_auto;
468 /* Translate a condition evaluation mode MODE into either "host"
469 or "target". This is used mostly to translate from "auto" to the
470 real setting that is being used. It returns the translated
474 translate_condition_evaluation_mode (const char *mode)
476 if (mode == condition_evaluation_auto)
478 if (target_supports_evaluation_of_breakpoint_conditions ())
479 return condition_evaluation_target;
481 return condition_evaluation_host;
487 /* Discovers what condition_evaluation_auto translates to. */
490 breakpoint_condition_evaluation_mode (void)
492 return translate_condition_evaluation_mode (condition_evaluation_mode);
495 /* Return true if GDB should evaluate breakpoint conditions or false
499 gdb_evaluates_breakpoint_condition_p (void)
501 const char *mode = breakpoint_condition_evaluation_mode ();
503 return (mode == condition_evaluation_host);
506 /* Are we executing breakpoint commands? */
507 static int executing_breakpoint_commands;
509 /* Are overlay event breakpoints enabled? */
510 static int overlay_events_enabled;
512 /* See description in breakpoint.h. */
513 int target_exact_watchpoints = 0;
515 /* Walk the following statement or block through all breakpoints.
516 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
517 current breakpoint. */
519 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
521 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
522 for (B = breakpoint_chain; \
523 B ? (TMP=B->next, 1): 0; \
526 /* Similar iterator for the low-level breakpoints. SAFE variant is
527 not provided so update_global_location_list must not be called
528 while executing the block of ALL_BP_LOCATIONS. */
530 #define ALL_BP_LOCATIONS(B,BP_TMP) \
531 for (BP_TMP = bp_locations; \
532 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
535 /* Iterates through locations with address ADDRESS for the currently selected
536 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
537 to where the loop should start from.
538 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
539 appropriate location to start with. */
541 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
542 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
543 BP_LOCP_TMP = BP_LOCP_START; \
545 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
546 && (*BP_LOCP_TMP)->address == ADDRESS); \
549 /* Iterator for tracepoints only. */
551 #define ALL_TRACEPOINTS(B) \
552 for (B = breakpoint_chain; B; B = B->next) \
553 if (is_tracepoint (B))
555 /* Chains of all breakpoints defined. */
557 struct breakpoint *breakpoint_chain;
559 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
561 static struct bp_location **bp_locations;
563 /* Number of elements of BP_LOCATIONS. */
565 static unsigned bp_locations_count;
567 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
568 ADDRESS for the current elements of BP_LOCATIONS which get a valid
569 result from bp_location_has_shadow. You can use it for roughly
570 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
571 an address you need to read. */
573 static CORE_ADDR bp_locations_placed_address_before_address_max;
575 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
576 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
577 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
578 You can use it for roughly limiting the subrange of BP_LOCATIONS to
579 scan for shadow bytes for an address you need to read. */
581 static CORE_ADDR bp_locations_shadow_len_after_address_max;
583 /* The locations that no longer correspond to any breakpoint, unlinked
584 from the bp_locations array, but for which a hit may still be
585 reported by a target. */
586 VEC(bp_location_p) *moribund_locations = NULL;
588 /* Number of last breakpoint made. */
590 static int breakpoint_count;
592 /* The value of `breakpoint_count' before the last command that
593 created breakpoints. If the last (break-like) command created more
594 than one breakpoint, then the difference between BREAKPOINT_COUNT
595 and PREV_BREAKPOINT_COUNT is more than one. */
596 static int prev_breakpoint_count;
598 /* Number of last tracepoint made. */
600 static int tracepoint_count;
602 static struct cmd_list_element *breakpoint_set_cmdlist;
603 static struct cmd_list_element *breakpoint_show_cmdlist;
604 struct cmd_list_element *save_cmdlist;
606 /* See declaration at breakpoint.h. */
609 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
612 struct breakpoint *b = NULL;
616 if (func (b, user_data) != 0)
623 /* Return whether a breakpoint is an active enabled breakpoint. */
625 breakpoint_enabled (struct breakpoint *b)
627 return (b->enable_state == bp_enabled);
630 /* Set breakpoint count to NUM. */
633 set_breakpoint_count (int num)
635 prev_breakpoint_count = breakpoint_count;
636 breakpoint_count = num;
637 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
640 /* Used by `start_rbreak_breakpoints' below, to record the current
641 breakpoint count before "rbreak" creates any breakpoint. */
642 static int rbreak_start_breakpoint_count;
644 /* Called at the start an "rbreak" command to record the first
648 start_rbreak_breakpoints (void)
650 rbreak_start_breakpoint_count = breakpoint_count;
653 /* Called at the end of an "rbreak" command to record the last
657 end_rbreak_breakpoints (void)
659 prev_breakpoint_count = rbreak_start_breakpoint_count;
662 /* Used in run_command to zero the hit count when a new run starts. */
665 clear_breakpoint_hit_counts (void)
667 struct breakpoint *b;
674 /* Return the breakpoint with the specified number, or NULL
675 if the number does not refer to an existing breakpoint. */
678 get_breakpoint (int num)
680 struct breakpoint *b;
683 if (b->number == num)
691 /* Mark locations as "conditions have changed" in case the target supports
692 evaluating conditions on its side. */
695 mark_breakpoint_modified (struct breakpoint *b)
697 struct bp_location *loc;
699 /* This is only meaningful if the target is
700 evaluating conditions and if the user has
701 opted for condition evaluation on the target's
703 if (gdb_evaluates_breakpoint_condition_p ()
704 || !target_supports_evaluation_of_breakpoint_conditions ())
707 if (!is_breakpoint (b))
710 for (loc = b->loc; loc; loc = loc->next)
711 loc->condition_changed = condition_modified;
714 /* Mark location as "conditions have changed" in case the target supports
715 evaluating conditions on its side. */
718 mark_breakpoint_location_modified (struct bp_location *loc)
720 /* This is only meaningful if the target is
721 evaluating conditions and if the user has
722 opted for condition evaluation on the target's
724 if (gdb_evaluates_breakpoint_condition_p ()
725 || !target_supports_evaluation_of_breakpoint_conditions ())
729 if (!is_breakpoint (loc->owner))
732 loc->condition_changed = condition_modified;
735 /* Sets the condition-evaluation mode using the static global
736 condition_evaluation_mode. */
739 set_condition_evaluation_mode (char *args, int from_tty,
740 struct cmd_list_element *c)
742 const char *old_mode, *new_mode;
744 if ((condition_evaluation_mode_1 == condition_evaluation_target)
745 && !target_supports_evaluation_of_breakpoint_conditions ())
747 condition_evaluation_mode_1 = condition_evaluation_mode;
748 warning (_("Target does not support breakpoint condition evaluation.\n"
749 "Using host evaluation mode instead."));
753 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
754 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
756 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
757 settings was "auto". */
758 condition_evaluation_mode = condition_evaluation_mode_1;
760 /* Only update the mode if the user picked a different one. */
761 if (new_mode != old_mode)
763 struct bp_location *loc, **loc_tmp;
764 /* If the user switched to a different evaluation mode, we
765 need to synch the changes with the target as follows:
767 "host" -> "target": Send all (valid) conditions to the target.
768 "target" -> "host": Remove all the conditions from the target.
771 if (new_mode == condition_evaluation_target)
773 /* Mark everything modified and synch conditions with the
775 ALL_BP_LOCATIONS (loc, loc_tmp)
776 mark_breakpoint_location_modified (loc);
780 /* Manually mark non-duplicate locations to synch conditions
781 with the target. We do this to remove all the conditions the
782 target knows about. */
783 ALL_BP_LOCATIONS (loc, loc_tmp)
784 if (is_breakpoint (loc->owner) && loc->inserted)
785 loc->needs_update = 1;
789 update_global_location_list (UGLL_MAY_INSERT);
795 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
796 what "auto" is translating to. */
799 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
800 struct cmd_list_element *c, const char *value)
802 if (condition_evaluation_mode == condition_evaluation_auto)
803 fprintf_filtered (file,
804 _("Breakpoint condition evaluation "
805 "mode is %s (currently %s).\n"),
807 breakpoint_condition_evaluation_mode ());
809 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
813 /* A comparison function for bp_location AP and BP that is used by
814 bsearch. This comparison function only cares about addresses, unlike
815 the more general bp_locations_compare function. */
818 bp_locations_compare_addrs (const void *ap, const void *bp)
820 const struct bp_location *a = *(const struct bp_location **) ap;
821 const struct bp_location *b = *(const struct bp_location **) bp;
823 if (a->address == b->address)
826 return ((a->address > b->address) - (a->address < b->address));
829 /* Helper function to skip all bp_locations with addresses
830 less than ADDRESS. It returns the first bp_location that
831 is greater than or equal to ADDRESS. If none is found, just
834 static struct bp_location **
835 get_first_locp_gte_addr (CORE_ADDR address)
837 struct bp_location dummy_loc;
838 struct bp_location *dummy_locp = &dummy_loc;
839 struct bp_location **locp_found = NULL;
841 /* Initialize the dummy location's address field. */
842 dummy_loc.address = address;
844 /* Find a close match to the first location at ADDRESS. */
845 locp_found = ((struct bp_location **)
846 bsearch (&dummy_locp, bp_locations, bp_locations_count,
847 sizeof (struct bp_location **),
848 bp_locations_compare_addrs));
850 /* Nothing was found, nothing left to do. */
851 if (locp_found == NULL)
854 /* We may have found a location that is at ADDRESS but is not the first in the
855 location's list. Go backwards (if possible) and locate the first one. */
856 while ((locp_found - 1) >= bp_locations
857 && (*(locp_found - 1))->address == address)
864 set_breakpoint_condition (struct breakpoint *b, const char *exp,
867 xfree (b->cond_string);
868 b->cond_string = NULL;
870 if (is_watchpoint (b))
872 struct watchpoint *w = (struct watchpoint *) b;
874 w->cond_exp.reset ();
878 struct bp_location *loc;
880 for (loc = b->loc; loc; loc = loc->next)
884 /* No need to free the condition agent expression
885 bytecode (if we have one). We will handle this
886 when we go through update_global_location_list. */
893 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
897 const char *arg = exp;
899 /* I don't know if it matters whether this is the string the user
900 typed in or the decompiled expression. */
901 b->cond_string = xstrdup (arg);
902 b->condition_not_parsed = 0;
904 if (is_watchpoint (b))
906 struct watchpoint *w = (struct watchpoint *) b;
908 innermost_block = NULL;
910 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
912 error (_("Junk at end of expression"));
913 w->cond_exp_valid_block = innermost_block;
917 struct bp_location *loc;
919 for (loc = b->loc; loc; loc = loc->next)
923 parse_exp_1 (&arg, loc->address,
924 block_for_pc (loc->address), 0);
926 error (_("Junk at end of expression"));
930 mark_breakpoint_modified (b);
932 observer_notify_breakpoint_modified (b);
935 /* Completion for the "condition" command. */
938 condition_completer (struct cmd_list_element *cmd,
939 completion_tracker &tracker,
940 const char *text, const char *word)
944 text = skip_spaces (text);
945 space = skip_to_space (text);
949 struct breakpoint *b;
950 VEC (char_ptr) *result = NULL;
954 /* We don't support completion of history indices. */
955 if (!isdigit (text[1]))
956 complete_internalvar (tracker, &text[1]);
960 /* We're completing the breakpoint number. */
967 xsnprintf (number, sizeof (number), "%d", b->number);
969 if (strncmp (number, text, len) == 0)
971 gdb::unique_xmalloc_ptr<char> copy (xstrdup (number));
972 tracker.add_completion (std::move (copy));
979 /* We're completing the expression part. */
980 text = skip_spaces (space);
981 expression_completer (cmd, tracker, text, word);
984 /* condition N EXP -- set break condition of breakpoint N to EXP. */
987 condition_command (char *arg, int from_tty)
989 struct breakpoint *b;
994 error_no_arg (_("breakpoint number"));
997 bnum = get_number (&p);
999 error (_("Bad breakpoint argument: '%s'"), arg);
1002 if (b->number == bnum)
1004 /* Check if this breakpoint has a "stop" method implemented in an
1005 extension language. This method and conditions entered into GDB
1006 from the CLI are mutually exclusive. */
1007 const struct extension_language_defn *extlang
1008 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1010 if (extlang != NULL)
1012 error (_("Only one stop condition allowed. There is currently"
1013 " a %s stop condition defined for this breakpoint."),
1014 ext_lang_capitalized_name (extlang));
1016 set_breakpoint_condition (b, p, from_tty);
1018 if (is_breakpoint (b))
1019 update_global_location_list (UGLL_MAY_INSERT);
1024 error (_("No breakpoint number %d."), bnum);
1027 /* Check that COMMAND do not contain commands that are suitable
1028 only for tracepoints and not suitable for ordinary breakpoints.
1029 Throw if any such commands is found. */
1032 check_no_tracepoint_commands (struct command_line *commands)
1034 struct command_line *c;
1036 for (c = commands; c; c = c->next)
1040 if (c->control_type == while_stepping_control)
1041 error (_("The 'while-stepping' command can "
1042 "only be used for tracepoints"));
1044 for (i = 0; i < c->body_count; ++i)
1045 check_no_tracepoint_commands ((c->body_list)[i]);
1047 /* Not that command parsing removes leading whitespace and comment
1048 lines and also empty lines. So, we only need to check for
1049 command directly. */
1050 if (strstr (c->line, "collect ") == c->line)
1051 error (_("The 'collect' command can only be used for tracepoints"));
1053 if (strstr (c->line, "teval ") == c->line)
1054 error (_("The 'teval' command can only be used for tracepoints"));
1058 struct longjmp_breakpoint : public breakpoint
1060 ~longjmp_breakpoint () override;
1063 /* Encapsulate tests for different types of tracepoints. */
1066 is_tracepoint_type (bptype type)
1068 return (type == bp_tracepoint
1069 || type == bp_fast_tracepoint
1070 || type == bp_static_tracepoint);
1074 is_longjmp_type (bptype type)
1076 return type == bp_longjmp || type == bp_exception;
1080 is_tracepoint (const struct breakpoint *b)
1082 return is_tracepoint_type (b->type);
1085 /* Factory function to create an appropriate instance of breakpoint given
1088 static std::unique_ptr<breakpoint>
1089 new_breakpoint_from_type (bptype type)
1093 if (is_tracepoint_type (type))
1094 b = new tracepoint ();
1095 else if (is_longjmp_type (type))
1096 b = new longjmp_breakpoint ();
1098 b = new breakpoint ();
1100 return std::unique_ptr<breakpoint> (b);
1103 /* A helper function that validates that COMMANDS are valid for a
1104 breakpoint. This function will throw an exception if a problem is
1108 validate_commands_for_breakpoint (struct breakpoint *b,
1109 struct command_line *commands)
1111 if (is_tracepoint (b))
1113 struct tracepoint *t = (struct tracepoint *) b;
1114 struct command_line *c;
1115 struct command_line *while_stepping = 0;
1117 /* Reset the while-stepping step count. The previous commands
1118 might have included a while-stepping action, while the new
1122 /* We need to verify that each top-level element of commands is
1123 valid for tracepoints, that there's at most one
1124 while-stepping element, and that the while-stepping's body
1125 has valid tracing commands excluding nested while-stepping.
1126 We also need to validate the tracepoint action line in the
1127 context of the tracepoint --- validate_actionline actually
1128 has side effects, like setting the tracepoint's
1129 while-stepping STEP_COUNT, in addition to checking if the
1130 collect/teval actions parse and make sense in the
1131 tracepoint's context. */
1132 for (c = commands; c; c = c->next)
1134 if (c->control_type == while_stepping_control)
1136 if (b->type == bp_fast_tracepoint)
1137 error (_("The 'while-stepping' command "
1138 "cannot be used for fast tracepoint"));
1139 else if (b->type == bp_static_tracepoint)
1140 error (_("The 'while-stepping' command "
1141 "cannot be used for static tracepoint"));
1144 error (_("The 'while-stepping' command "
1145 "can be used only once"));
1150 validate_actionline (c->line, b);
1154 struct command_line *c2;
1156 gdb_assert (while_stepping->body_count == 1);
1157 c2 = while_stepping->body_list[0];
1158 for (; c2; c2 = c2->next)
1160 if (c2->control_type == while_stepping_control)
1161 error (_("The 'while-stepping' command cannot be nested"));
1167 check_no_tracepoint_commands (commands);
1171 /* Return a vector of all the static tracepoints set at ADDR. The
1172 caller is responsible for releasing the vector. */
1175 static_tracepoints_here (CORE_ADDR addr)
1177 struct breakpoint *b;
1178 VEC(breakpoint_p) *found = 0;
1179 struct bp_location *loc;
1182 if (b->type == bp_static_tracepoint)
1184 for (loc = b->loc; loc; loc = loc->next)
1185 if (loc->address == addr)
1186 VEC_safe_push(breakpoint_p, found, b);
1192 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1193 validate that only allowed commands are included. */
1196 breakpoint_set_commands (struct breakpoint *b,
1197 command_line_up &&commands)
1199 validate_commands_for_breakpoint (b, commands.get ());
1201 b->commands = std::move (commands);
1202 observer_notify_breakpoint_modified (b);
1205 /* Set the internal `silent' flag on the breakpoint. Note that this
1206 is not the same as the "silent" that may appear in the breakpoint's
1210 breakpoint_set_silent (struct breakpoint *b, int silent)
1212 int old_silent = b->silent;
1215 if (old_silent != silent)
1216 observer_notify_breakpoint_modified (b);
1219 /* Set the thread for this breakpoint. If THREAD is -1, make the
1220 breakpoint work for any thread. */
1223 breakpoint_set_thread (struct breakpoint *b, int thread)
1225 int old_thread = b->thread;
1228 if (old_thread != thread)
1229 observer_notify_breakpoint_modified (b);
1232 /* Set the task for this breakpoint. If TASK is 0, make the
1233 breakpoint work for any task. */
1236 breakpoint_set_task (struct breakpoint *b, int task)
1238 int old_task = b->task;
1241 if (old_task != task)
1242 observer_notify_breakpoint_modified (b);
1246 check_tracepoint_command (char *line, void *closure)
1248 struct breakpoint *b = (struct breakpoint *) closure;
1250 validate_actionline (line, b);
1254 commands_command_1 (const char *arg, int from_tty,
1255 struct command_line *control)
1257 counted_command_line cmd;
1259 std::string new_arg;
1261 if (arg == NULL || !*arg)
1263 if (breakpoint_count - prev_breakpoint_count > 1)
1264 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1266 else if (breakpoint_count > 0)
1267 new_arg = string_printf ("%d", breakpoint_count);
1268 arg = new_arg.c_str ();
1271 map_breakpoint_numbers
1272 (arg, [&] (breakpoint *b)
1276 if (control != NULL)
1277 cmd = copy_command_lines (control->body_list[0]);
1281 = string_printf (_("Type commands for breakpoint(s) "
1282 "%s, one per line."),
1285 cmd = read_command_lines (&str[0],
1288 ? check_tracepoint_command : 0),
1293 /* If a breakpoint was on the list more than once, we don't need to
1295 if (b->commands != cmd)
1297 validate_commands_for_breakpoint (b, cmd.get ());
1299 observer_notify_breakpoint_modified (b);
1304 error (_("No breakpoints specified."));
1308 commands_command (char *arg, int from_tty)
1310 commands_command_1 (arg, from_tty, NULL);
1313 /* Like commands_command, but instead of reading the commands from
1314 input stream, takes them from an already parsed command structure.
1316 This is used by cli-script.c to DTRT with breakpoint commands
1317 that are part of if and while bodies. */
1318 enum command_control_type
1319 commands_from_control_command (const char *arg, struct command_line *cmd)
1321 commands_command_1 (arg, 0, cmd);
1322 return simple_control;
1325 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1328 bp_location_has_shadow (struct bp_location *bl)
1330 if (bl->loc_type != bp_loc_software_breakpoint)
1334 if (bl->target_info.shadow_len == 0)
1335 /* BL isn't valid, or doesn't shadow memory. */
1340 /* Update BUF, which is LEN bytes read from the target address
1341 MEMADDR, by replacing a memory breakpoint with its shadowed
1344 If READBUF is not NULL, this buffer must not overlap with the of
1345 the breakpoint location's shadow_contents buffer. Otherwise, a
1346 failed assertion internal error will be raised. */
1349 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1350 const gdb_byte *writebuf_org,
1351 ULONGEST memaddr, LONGEST len,
1352 struct bp_target_info *target_info,
1353 struct gdbarch *gdbarch)
1355 /* Now do full processing of the found relevant range of elements. */
1356 CORE_ADDR bp_addr = 0;
1360 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1361 current_program_space->aspace, 0))
1363 /* The breakpoint is inserted in a different address space. */
1367 /* Addresses and length of the part of the breakpoint that
1369 bp_addr = target_info->placed_address;
1370 bp_size = target_info->shadow_len;
1372 if (bp_addr + bp_size <= memaddr)
1374 /* The breakpoint is entirely before the chunk of memory we are
1379 if (bp_addr >= memaddr + len)
1381 /* The breakpoint is entirely after the chunk of memory we are
1386 /* Offset within shadow_contents. */
1387 if (bp_addr < memaddr)
1389 /* Only copy the second part of the breakpoint. */
1390 bp_size -= memaddr - bp_addr;
1391 bptoffset = memaddr - bp_addr;
1395 if (bp_addr + bp_size > memaddr + len)
1397 /* Only copy the first part of the breakpoint. */
1398 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1401 if (readbuf != NULL)
1403 /* Verify that the readbuf buffer does not overlap with the
1404 shadow_contents buffer. */
1405 gdb_assert (target_info->shadow_contents >= readbuf + len
1406 || readbuf >= (target_info->shadow_contents
1407 + target_info->shadow_len));
1409 /* Update the read buffer with this inserted breakpoint's
1411 memcpy (readbuf + bp_addr - memaddr,
1412 target_info->shadow_contents + bptoffset, bp_size);
1416 const unsigned char *bp;
1417 CORE_ADDR addr = target_info->reqstd_address;
1420 /* Update the shadow with what we want to write to memory. */
1421 memcpy (target_info->shadow_contents + bptoffset,
1422 writebuf_org + bp_addr - memaddr, bp_size);
1424 /* Determine appropriate breakpoint contents and size for this
1426 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1428 /* Update the final write buffer with this inserted
1429 breakpoint's INSN. */
1430 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1434 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1435 by replacing any memory breakpoints with their shadowed contents.
1437 If READBUF is not NULL, this buffer must not overlap with any of
1438 the breakpoint location's shadow_contents buffers. Otherwise,
1439 a failed assertion internal error will be raised.
1441 The range of shadowed area by each bp_location is:
1442 bl->address - bp_locations_placed_address_before_address_max
1443 up to bl->address + bp_locations_shadow_len_after_address_max
1444 The range we were requested to resolve shadows for is:
1445 memaddr ... memaddr + len
1446 Thus the safe cutoff boundaries for performance optimization are
1447 memaddr + len <= (bl->address
1448 - bp_locations_placed_address_before_address_max)
1450 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1453 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1454 const gdb_byte *writebuf_org,
1455 ULONGEST memaddr, LONGEST len)
1457 /* Left boundary, right boundary and median element of our binary
1459 unsigned bc_l, bc_r, bc;
1461 /* Find BC_L which is a leftmost element which may affect BUF
1462 content. It is safe to report lower value but a failure to
1463 report higher one. */
1466 bc_r = bp_locations_count;
1467 while (bc_l + 1 < bc_r)
1469 struct bp_location *bl;
1471 bc = (bc_l + bc_r) / 2;
1472 bl = bp_locations[bc];
1474 /* Check first BL->ADDRESS will not overflow due to the added
1475 constant. Then advance the left boundary only if we are sure
1476 the BC element can in no way affect the BUF content (MEMADDR
1477 to MEMADDR + LEN range).
1479 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1480 offset so that we cannot miss a breakpoint with its shadow
1481 range tail still reaching MEMADDR. */
1483 if ((bl->address + bp_locations_shadow_len_after_address_max
1485 && (bl->address + bp_locations_shadow_len_after_address_max
1492 /* Due to the binary search above, we need to make sure we pick the
1493 first location that's at BC_L's address. E.g., if there are
1494 multiple locations at the same address, BC_L may end up pointing
1495 at a duplicate location, and miss the "master"/"inserted"
1496 location. Say, given locations L1, L2 and L3 at addresses A and
1499 L1@A, L2@A, L3@B, ...
1501 BC_L could end up pointing at location L2, while the "master"
1502 location could be L1. Since the `loc->inserted' flag is only set
1503 on "master" locations, we'd forget to restore the shadow of L1
1506 && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
1509 /* Now do full processing of the found relevant range of elements. */
1511 for (bc = bc_l; bc < bp_locations_count; bc++)
1513 struct bp_location *bl = bp_locations[bc];
1515 /* bp_location array has BL->OWNER always non-NULL. */
1516 if (bl->owner->type == bp_none)
1517 warning (_("reading through apparently deleted breakpoint #%d?"),
1520 /* Performance optimization: any further element can no longer affect BUF
1523 if (bl->address >= bp_locations_placed_address_before_address_max
1524 && memaddr + len <= (bl->address
1525 - bp_locations_placed_address_before_address_max))
1528 if (!bp_location_has_shadow (bl))
1531 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1532 memaddr, len, &bl->target_info, bl->gdbarch);
1538 /* Return true if BPT is either a software breakpoint or a hardware
1542 is_breakpoint (const struct breakpoint *bpt)
1544 return (bpt->type == bp_breakpoint
1545 || bpt->type == bp_hardware_breakpoint
1546 || bpt->type == bp_dprintf);
1549 /* Return true if BPT is of any hardware watchpoint kind. */
1552 is_hardware_watchpoint (const struct breakpoint *bpt)
1554 return (bpt->type == bp_hardware_watchpoint
1555 || bpt->type == bp_read_watchpoint
1556 || bpt->type == bp_access_watchpoint);
1559 /* Return true if BPT is of any watchpoint kind, hardware or
1563 is_watchpoint (const struct breakpoint *bpt)
1565 return (is_hardware_watchpoint (bpt)
1566 || bpt->type == bp_watchpoint);
1569 /* Returns true if the current thread and its running state are safe
1570 to evaluate or update watchpoint B. Watchpoints on local
1571 expressions need to be evaluated in the context of the thread that
1572 was current when the watchpoint was created, and, that thread needs
1573 to be stopped to be able to select the correct frame context.
1574 Watchpoints on global expressions can be evaluated on any thread,
1575 and in any state. It is presently left to the target allowing
1576 memory accesses when threads are running. */
1579 watchpoint_in_thread_scope (struct watchpoint *b)
1581 return (b->pspace == current_program_space
1582 && (ptid_equal (b->watchpoint_thread, null_ptid)
1583 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1584 && !is_executing (inferior_ptid))));
1587 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1588 associated bp_watchpoint_scope breakpoint. */
1591 watchpoint_del_at_next_stop (struct watchpoint *w)
1593 if (w->related_breakpoint != w)
1595 gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope);
1596 gdb_assert (w->related_breakpoint->related_breakpoint == w);
1597 w->related_breakpoint->disposition = disp_del_at_next_stop;
1598 w->related_breakpoint->related_breakpoint = w->related_breakpoint;
1599 w->related_breakpoint = w;
1601 w->disposition = disp_del_at_next_stop;
1604 /* Extract a bitfield value from value VAL using the bit parameters contained in
1607 static struct value *
1608 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1610 struct value *bit_val;
1615 bit_val = allocate_value (value_type (val));
1617 unpack_value_bitfield (bit_val,
1620 value_contents_for_printing (val),
1627 /* Allocate a dummy location and add it to B, which must be a software
1628 watchpoint. This is required because even if a software watchpoint
1629 is not watching any memory, bpstat_stop_status requires a location
1630 to be able to report stops. */
1633 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1634 struct program_space *pspace)
1636 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1638 b->loc = allocate_bp_location (b);
1639 b->loc->pspace = pspace;
1640 b->loc->address = -1;
1641 b->loc->length = -1;
1644 /* Returns true if B is a software watchpoint that is not watching any
1645 memory (e.g., "watch $pc"). */
1648 is_no_memory_software_watchpoint (struct breakpoint *b)
1650 return (b->type == bp_watchpoint
1652 && b->loc->next == NULL
1653 && b->loc->address == -1
1654 && b->loc->length == -1);
1657 /* Assuming that B is a watchpoint:
1658 - Reparse watchpoint expression, if REPARSE is non-zero
1659 - Evaluate expression and store the result in B->val
1660 - Evaluate the condition if there is one, and store the result
1662 - Update the list of values that must be watched in B->loc.
1664 If the watchpoint disposition is disp_del_at_next_stop, then do
1665 nothing. If this is local watchpoint that is out of scope, delete
1668 Even with `set breakpoint always-inserted on' the watchpoints are
1669 removed + inserted on each stop here. Normal breakpoints must
1670 never be removed because they might be missed by a running thread
1671 when debugging in non-stop mode. On the other hand, hardware
1672 watchpoints (is_hardware_watchpoint; processed here) are specific
1673 to each LWP since they are stored in each LWP's hardware debug
1674 registers. Therefore, such LWP must be stopped first in order to
1675 be able to modify its hardware watchpoints.
1677 Hardware watchpoints must be reset exactly once after being
1678 presented to the user. It cannot be done sooner, because it would
1679 reset the data used to present the watchpoint hit to the user. And
1680 it must not be done later because it could display the same single
1681 watchpoint hit during multiple GDB stops. Note that the latter is
1682 relevant only to the hardware watchpoint types bp_read_watchpoint
1683 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1684 not user-visible - its hit is suppressed if the memory content has
1687 The following constraints influence the location where we can reset
1688 hardware watchpoints:
1690 * target_stopped_by_watchpoint and target_stopped_data_address are
1691 called several times when GDB stops.
1694 * Multiple hardware watchpoints can be hit at the same time,
1695 causing GDB to stop. GDB only presents one hardware watchpoint
1696 hit at a time as the reason for stopping, and all the other hits
1697 are presented later, one after the other, each time the user
1698 requests the execution to be resumed. Execution is not resumed
1699 for the threads still having pending hit event stored in
1700 LWP_INFO->STATUS. While the watchpoint is already removed from
1701 the inferior on the first stop the thread hit event is kept being
1702 reported from its cached value by linux_nat_stopped_data_address
1703 until the real thread resume happens after the watchpoint gets
1704 presented and thus its LWP_INFO->STATUS gets reset.
1706 Therefore the hardware watchpoint hit can get safely reset on the
1707 watchpoint removal from inferior. */
1710 update_watchpoint (struct watchpoint *b, int reparse)
1712 int within_current_scope;
1713 struct frame_id saved_frame_id;
1716 /* If this is a local watchpoint, we only want to check if the
1717 watchpoint frame is in scope if the current thread is the thread
1718 that was used to create the watchpoint. */
1719 if (!watchpoint_in_thread_scope (b))
1722 if (b->disposition == disp_del_at_next_stop)
1727 /* Determine if the watchpoint is within scope. */
1728 if (b->exp_valid_block == NULL)
1729 within_current_scope = 1;
1732 struct frame_info *fi = get_current_frame ();
1733 struct gdbarch *frame_arch = get_frame_arch (fi);
1734 CORE_ADDR frame_pc = get_frame_pc (fi);
1736 /* If we're at a point where the stack has been destroyed
1737 (e.g. in a function epilogue), unwinding may not work
1738 properly. Do not attempt to recreate locations at this
1739 point. See similar comments in watchpoint_check. */
1740 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1743 /* Save the current frame's ID so we can restore it after
1744 evaluating the watchpoint expression on its own frame. */
1745 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1746 took a frame parameter, so that we didn't have to change the
1749 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1751 fi = frame_find_by_id (b->watchpoint_frame);
1752 within_current_scope = (fi != NULL);
1753 if (within_current_scope)
1757 /* We don't free locations. They are stored in the bp_location array
1758 and update_global_location_list will eventually delete them and
1759 remove breakpoints if needed. */
1762 if (within_current_scope && reparse)
1767 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1768 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1769 /* If the meaning of expression itself changed, the old value is
1770 no longer relevant. We don't want to report a watchpoint hit
1771 to the user when the old value and the new value may actually
1772 be completely different objects. */
1773 value_free (b->val);
1777 /* Note that unlike with breakpoints, the watchpoint's condition
1778 expression is stored in the breakpoint object, not in the
1779 locations (re)created below. */
1780 if (b->cond_string != NULL)
1782 b->cond_exp.reset ();
1785 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1789 /* If we failed to parse the expression, for example because
1790 it refers to a global variable in a not-yet-loaded shared library,
1791 don't try to insert watchpoint. We don't automatically delete
1792 such watchpoint, though, since failure to parse expression
1793 is different from out-of-scope watchpoint. */
1794 if (!target_has_execution)
1796 /* Without execution, memory can't change. No use to try and
1797 set watchpoint locations. The watchpoint will be reset when
1798 the target gains execution, through breakpoint_re_set. */
1799 if (!can_use_hw_watchpoints)
1801 if (b->ops->works_in_software_mode (b))
1802 b->type = bp_watchpoint;
1804 error (_("Can't set read/access watchpoint when "
1805 "hardware watchpoints are disabled."));
1808 else if (within_current_scope && b->exp)
1811 struct value *val_chain, *v, *result, *next;
1812 struct program_space *frame_pspace;
1814 fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
1816 /* Avoid setting b->val if it's already set. The meaning of
1817 b->val is 'the last value' user saw, and we should update
1818 it only if we reported that last value to user. As it
1819 happens, the code that reports it updates b->val directly.
1820 We don't keep track of the memory value for masked
1822 if (!b->val_valid && !is_masked_watchpoint (b))
1824 if (b->val_bitsize != 0)
1826 v = extract_bitfield_from_watchpoint_value (b, v);
1834 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1836 /* Look at each value on the value chain. */
1837 for (v = val_chain; v; v = value_next (v))
1839 /* If it's a memory location, and GDB actually needed
1840 its contents to evaluate the expression, then we
1841 must watch it. If the first value returned is
1842 still lazy, that means an error occurred reading it;
1843 watch it anyway in case it becomes readable. */
1844 if (VALUE_LVAL (v) == lval_memory
1845 && (v == val_chain || ! value_lazy (v)))
1847 struct type *vtype = check_typedef (value_type (v));
1849 /* We only watch structs and arrays if user asked
1850 for it explicitly, never if they just happen to
1851 appear in the middle of some value chain. */
1853 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1854 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1857 enum target_hw_bp_type type;
1858 struct bp_location *loc, **tmp;
1859 int bitpos = 0, bitsize = 0;
1861 if (value_bitsize (v) != 0)
1863 /* Extract the bit parameters out from the bitfield
1865 bitpos = value_bitpos (v);
1866 bitsize = value_bitsize (v);
1868 else if (v == result && b->val_bitsize != 0)
1870 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1871 lvalue whose bit parameters are saved in the fields
1872 VAL_BITPOS and VAL_BITSIZE. */
1873 bitpos = b->val_bitpos;
1874 bitsize = b->val_bitsize;
1877 addr = value_address (v);
1880 /* Skip the bytes that don't contain the bitfield. */
1885 if (b->type == bp_read_watchpoint)
1887 else if (b->type == bp_access_watchpoint)
1890 loc = allocate_bp_location (b);
1891 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1894 loc->gdbarch = get_type_arch (value_type (v));
1896 loc->pspace = frame_pspace;
1897 loc->address = addr;
1901 /* Just cover the bytes that make up the bitfield. */
1902 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
1905 loc->length = TYPE_LENGTH (value_type (v));
1907 loc->watchpoint_type = type;
1912 /* Change the type of breakpoint between hardware assisted or
1913 an ordinary watchpoint depending on the hardware support
1914 and free hardware slots. REPARSE is set when the inferior
1919 enum bp_loc_type loc_type;
1920 struct bp_location *bl;
1922 reg_cnt = can_use_hardware_watchpoint (val_chain);
1926 int i, target_resources_ok, other_type_used;
1929 /* Use an exact watchpoint when there's only one memory region to be
1930 watched, and only one debug register is needed to watch it. */
1931 b->exact = target_exact_watchpoints && reg_cnt == 1;
1933 /* We need to determine how many resources are already
1934 used for all other hardware watchpoints plus this one
1935 to see if we still have enough resources to also fit
1936 this watchpoint in as well. */
1938 /* If this is a software watchpoint, we try to turn it
1939 to a hardware one -- count resources as if B was of
1940 hardware watchpoint type. */
1942 if (type == bp_watchpoint)
1943 type = bp_hardware_watchpoint;
1945 /* This watchpoint may or may not have been placed on
1946 the list yet at this point (it won't be in the list
1947 if we're trying to create it for the first time,
1948 through watch_command), so always account for it
1951 /* Count resources used by all watchpoints except B. */
1952 i = hw_watchpoint_used_count_others (b, type, &other_type_used);
1954 /* Add in the resources needed for B. */
1955 i += hw_watchpoint_use_count (b);
1958 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1959 if (target_resources_ok <= 0)
1961 int sw_mode = b->ops->works_in_software_mode (b);
1963 if (target_resources_ok == 0 && !sw_mode)
1964 error (_("Target does not support this type of "
1965 "hardware watchpoint."));
1966 else if (target_resources_ok < 0 && !sw_mode)
1967 error (_("There are not enough available hardware "
1968 "resources for this watchpoint."));
1970 /* Downgrade to software watchpoint. */
1971 b->type = bp_watchpoint;
1975 /* If this was a software watchpoint, we've just
1976 found we have enough resources to turn it to a
1977 hardware watchpoint. Otherwise, this is a
1982 else if (!b->ops->works_in_software_mode (b))
1984 if (!can_use_hw_watchpoints)
1985 error (_("Can't set read/access watchpoint when "
1986 "hardware watchpoints are disabled."));
1988 error (_("Expression cannot be implemented with "
1989 "read/access watchpoint."));
1992 b->type = bp_watchpoint;
1994 loc_type = (b->type == bp_watchpoint? bp_loc_other
1995 : bp_loc_hardware_watchpoint);
1996 for (bl = b->loc; bl; bl = bl->next)
1997 bl->loc_type = loc_type;
2000 for (v = val_chain; v; v = next)
2002 next = value_next (v);
2007 /* If a software watchpoint is not watching any memory, then the
2008 above left it without any location set up. But,
2009 bpstat_stop_status requires a location to be able to report
2010 stops, so make sure there's at least a dummy one. */
2011 if (b->type == bp_watchpoint && b->loc == NULL)
2012 software_watchpoint_add_no_memory_location (b, frame_pspace);
2014 else if (!within_current_scope)
2016 printf_filtered (_("\
2017 Watchpoint %d deleted because the program has left the block\n\
2018 in which its expression is valid.\n"),
2020 watchpoint_del_at_next_stop (b);
2023 /* Restore the selected frame. */
2025 select_frame (frame_find_by_id (saved_frame_id));
2029 /* Returns 1 iff breakpoint location should be
2030 inserted in the inferior. We don't differentiate the type of BL's owner
2031 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2032 breakpoint_ops is not defined, because in insert_bp_location,
2033 tracepoint's insert_location will not be called. */
2035 should_be_inserted (struct bp_location *bl)
2037 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2040 if (bl->owner->disposition == disp_del_at_next_stop)
2043 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2046 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2049 /* This is set for example, when we're attached to the parent of a
2050 vfork, and have detached from the child. The child is running
2051 free, and we expect it to do an exec or exit, at which point the
2052 OS makes the parent schedulable again (and the target reports
2053 that the vfork is done). Until the child is done with the shared
2054 memory region, do not insert breakpoints in the parent, otherwise
2055 the child could still trip on the parent's breakpoints. Since
2056 the parent is blocked anyway, it won't miss any breakpoint. */
2057 if (bl->pspace->breakpoints_not_allowed)
2060 /* Don't insert a breakpoint if we're trying to step past its
2061 location, except if the breakpoint is a single-step breakpoint,
2062 and the breakpoint's thread is the thread which is stepping past
2064 if ((bl->loc_type == bp_loc_software_breakpoint
2065 || bl->loc_type == bp_loc_hardware_breakpoint)
2066 && stepping_past_instruction_at (bl->pspace->aspace,
2068 /* The single-step breakpoint may be inserted at the location
2069 we're trying to step if the instruction branches to itself.
2070 However, the instruction won't be executed at all and it may
2071 break the semantics of the instruction, for example, the
2072 instruction is a conditional branch or updates some flags.
2073 We can't fix it unless GDB is able to emulate the instruction
2074 or switch to displaced stepping. */
2075 && !(bl->owner->type == bp_single_step
2076 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2080 fprintf_unfiltered (gdb_stdlog,
2081 "infrun: skipping breakpoint: "
2082 "stepping past insn at: %s\n",
2083 paddress (bl->gdbarch, bl->address));
2088 /* Don't insert watchpoints if we're trying to step past the
2089 instruction that triggered one. */
2090 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2091 && stepping_past_nonsteppable_watchpoint ())
2095 fprintf_unfiltered (gdb_stdlog,
2096 "infrun: stepping past non-steppable watchpoint. "
2097 "skipping watchpoint at %s:%d\n",
2098 paddress (bl->gdbarch, bl->address),
2107 /* Same as should_be_inserted but does the check assuming
2108 that the location is not duplicated. */
2111 unduplicated_should_be_inserted (struct bp_location *bl)
2114 const int save_duplicate = bl->duplicate;
2117 result = should_be_inserted (bl);
2118 bl->duplicate = save_duplicate;
2122 /* Parses a conditional described by an expression COND into an
2123 agent expression bytecode suitable for evaluation
2124 by the bytecode interpreter. Return NULL if there was
2125 any error during parsing. */
2127 static agent_expr_up
2128 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2133 agent_expr_up aexpr;
2135 /* We don't want to stop processing, so catch any errors
2136 that may show up. */
2139 aexpr = gen_eval_for_expr (scope, cond);
2142 CATCH (ex, RETURN_MASK_ERROR)
2144 /* If we got here, it means the condition could not be parsed to a valid
2145 bytecode expression and thus can't be evaluated on the target's side.
2146 It's no use iterating through the conditions. */
2150 /* We have a valid agent expression. */
2154 /* Based on location BL, create a list of breakpoint conditions to be
2155 passed on to the target. If we have duplicated locations with different
2156 conditions, we will add such conditions to the list. The idea is that the
2157 target will evaluate the list of conditions and will only notify GDB when
2158 one of them is true. */
2161 build_target_condition_list (struct bp_location *bl)
2163 struct bp_location **locp = NULL, **loc2p;
2164 int null_condition_or_parse_error = 0;
2165 int modified = bl->needs_update;
2166 struct bp_location *loc;
2168 /* Release conditions left over from a previous insert. */
2169 bl->target_info.conditions.clear ();
2171 /* This is only meaningful if the target is
2172 evaluating conditions and if the user has
2173 opted for condition evaluation on the target's
2175 if (gdb_evaluates_breakpoint_condition_p ()
2176 || !target_supports_evaluation_of_breakpoint_conditions ())
2179 /* Do a first pass to check for locations with no assigned
2180 conditions or conditions that fail to parse to a valid agent expression
2181 bytecode. If any of these happen, then it's no use to send conditions
2182 to the target since this location will always trigger and generate a
2183 response back to GDB. */
2184 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2187 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2191 /* Re-parse the conditions since something changed. In that
2192 case we already freed the condition bytecodes (see
2193 force_breakpoint_reinsertion). We just
2194 need to parse the condition to bytecodes again. */
2195 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2199 /* If we have a NULL bytecode expression, it means something
2200 went wrong or we have a null condition expression. */
2201 if (!loc->cond_bytecode)
2203 null_condition_or_parse_error = 1;
2209 /* If any of these happened, it means we will have to evaluate the conditions
2210 for the location's address on gdb's side. It is no use keeping bytecodes
2211 for all the other duplicate locations, thus we free all of them here.
2213 This is so we have a finer control over which locations' conditions are
2214 being evaluated by GDB or the remote stub. */
2215 if (null_condition_or_parse_error)
2217 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2220 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2222 /* Only go as far as the first NULL bytecode is
2224 if (!loc->cond_bytecode)
2227 loc->cond_bytecode.reset ();
2232 /* No NULL conditions or failed bytecode generation. Build a condition list
2233 for this location's address. */
2234 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2238 && is_breakpoint (loc->owner)
2239 && loc->pspace->num == bl->pspace->num
2240 && loc->owner->enable_state == bp_enabled
2243 /* Add the condition to the vector. This will be used later
2244 to send the conditions to the target. */
2245 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2252 /* Parses a command described by string CMD into an agent expression
2253 bytecode suitable for evaluation by the bytecode interpreter.
2254 Return NULL if there was any error during parsing. */
2256 static agent_expr_up
2257 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2259 struct cleanup *old_cleanups = 0;
2260 struct expression **argvec;
2261 const char *cmdrest;
2262 const char *format_start, *format_end;
2263 struct format_piece *fpieces;
2265 struct gdbarch *gdbarch = get_current_arch ();
2272 if (*cmdrest == ',')
2274 cmdrest = skip_spaces (cmdrest);
2276 if (*cmdrest++ != '"')
2277 error (_("No format string following the location"));
2279 format_start = cmdrest;
2281 fpieces = parse_format_string (&cmdrest);
2283 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2285 format_end = cmdrest;
2287 if (*cmdrest++ != '"')
2288 error (_("Bad format string, non-terminated '\"'."));
2290 cmdrest = skip_spaces (cmdrest);
2292 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2293 error (_("Invalid argument syntax"));
2295 if (*cmdrest == ',')
2297 cmdrest = skip_spaces (cmdrest);
2299 /* For each argument, make an expression. */
2301 argvec = (struct expression **) alloca (strlen (cmd)
2302 * sizeof (struct expression *));
2305 while (*cmdrest != '\0')
2310 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2311 argvec[nargs++] = expr.release ();
2313 if (*cmdrest == ',')
2317 agent_expr_up aexpr;
2319 /* We don't want to stop processing, so catch any errors
2320 that may show up. */
2323 aexpr = gen_printf (scope, gdbarch, 0, 0,
2324 format_start, format_end - format_start,
2325 fpieces, nargs, argvec);
2327 CATCH (ex, RETURN_MASK_ERROR)
2329 /* If we got here, it means the command could not be parsed to a valid
2330 bytecode expression and thus can't be evaluated on the target's side.
2331 It's no use iterating through the other commands. */
2335 do_cleanups (old_cleanups);
2337 /* We have a valid agent expression, return it. */
2341 /* Based on location BL, create a list of breakpoint commands to be
2342 passed on to the target. If we have duplicated locations with
2343 different commands, we will add any such to the list. */
2346 build_target_command_list (struct bp_location *bl)
2348 struct bp_location **locp = NULL, **loc2p;
2349 int null_command_or_parse_error = 0;
2350 int modified = bl->needs_update;
2351 struct bp_location *loc;
2353 /* Clear commands left over from a previous insert. */
2354 bl->target_info.tcommands.clear ();
2356 if (!target_can_run_breakpoint_commands ())
2359 /* For now, limit to agent-style dprintf breakpoints. */
2360 if (dprintf_style != dprintf_style_agent)
2363 /* For now, if we have any duplicate location that isn't a dprintf,
2364 don't install the target-side commands, as that would make the
2365 breakpoint not be reported to the core, and we'd lose
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2370 if (is_breakpoint (loc->owner)
2371 && loc->pspace->num == bl->pspace->num
2372 && loc->owner->type != bp_dprintf)
2376 /* Do a first pass to check for locations with no assigned
2377 conditions or conditions that fail to parse to a valid agent expression
2378 bytecode. If any of these happen, then it's no use to send conditions
2379 to the target since this location will always trigger and generate a
2380 response back to GDB. */
2381 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2384 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2388 /* Re-parse the commands since something changed. In that
2389 case we already freed the command bytecodes (see
2390 force_breakpoint_reinsertion). We just
2391 need to parse the command to bytecodes again. */
2393 = parse_cmd_to_aexpr (bl->address,
2394 loc->owner->extra_string);
2397 /* If we have a NULL bytecode expression, it means something
2398 went wrong or we have a null command expression. */
2399 if (!loc->cmd_bytecode)
2401 null_command_or_parse_error = 1;
2407 /* If anything failed, then we're not doing target-side commands,
2409 if (null_command_or_parse_error)
2411 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2414 if (is_breakpoint (loc->owner)
2415 && loc->pspace->num == bl->pspace->num)
2417 /* Only go as far as the first NULL bytecode is
2419 if (loc->cmd_bytecode == NULL)
2422 loc->cmd_bytecode.reset ();
2427 /* No NULL commands or failed bytecode generation. Build a command list
2428 for this location's address. */
2429 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2432 if (loc->owner->extra_string
2433 && is_breakpoint (loc->owner)
2434 && loc->pspace->num == bl->pspace->num
2435 && loc->owner->enable_state == bp_enabled
2438 /* Add the command to the vector. This will be used later
2439 to send the commands to the target. */
2440 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2444 bl->target_info.persist = 0;
2445 /* Maybe flag this location as persistent. */
2446 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2447 bl->target_info.persist = 1;
2450 /* Return the kind of breakpoint on address *ADDR. Get the kind
2451 of breakpoint according to ADDR except single-step breakpoint.
2452 Get the kind of single-step breakpoint according to the current
2456 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2458 if (bl->owner->type == bp_single_step)
2460 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2461 struct regcache *regcache;
2463 regcache = get_thread_regcache (thr->ptid);
2465 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2469 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2472 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2473 location. Any error messages are printed to TMP_ERROR_STREAM; and
2474 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2475 Returns 0 for success, 1 if the bp_location type is not supported or
2478 NOTE drow/2003-09-09: This routine could be broken down to an
2479 object-style method for each breakpoint or catchpoint type. */
2481 insert_bp_location (struct bp_location *bl,
2482 struct ui_file *tmp_error_stream,
2483 int *disabled_breaks,
2484 int *hw_breakpoint_error,
2485 int *hw_bp_error_explained_already)
2487 enum errors bp_err = GDB_NO_ERROR;
2488 const char *bp_err_message = NULL;
2490 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2493 /* Note we don't initialize bl->target_info, as that wipes out
2494 the breakpoint location's shadow_contents if the breakpoint
2495 is still inserted at that location. This in turn breaks
2496 target_read_memory which depends on these buffers when
2497 a memory read is requested at the breakpoint location:
2498 Once the target_info has been wiped, we fail to see that
2499 we have a breakpoint inserted at that address and thus
2500 read the breakpoint instead of returning the data saved in
2501 the breakpoint location's shadow contents. */
2502 bl->target_info.reqstd_address = bl->address;
2503 bl->target_info.placed_address_space = bl->pspace->aspace;
2504 bl->target_info.length = bl->length;
2506 /* When working with target-side conditions, we must pass all the conditions
2507 for the same breakpoint address down to the target since GDB will not
2508 insert those locations. With a list of breakpoint conditions, the target
2509 can decide when to stop and notify GDB. */
2511 if (is_breakpoint (bl->owner))
2513 build_target_condition_list (bl);
2514 build_target_command_list (bl);
2515 /* Reset the modification marker. */
2516 bl->needs_update = 0;
2519 if (bl->loc_type == bp_loc_software_breakpoint
2520 || bl->loc_type == bp_loc_hardware_breakpoint)
2522 if (bl->owner->type != bp_hardware_breakpoint)
2524 /* If the explicitly specified breakpoint type
2525 is not hardware breakpoint, check the memory map to see
2526 if the breakpoint address is in read only memory or not.
2528 Two important cases are:
2529 - location type is not hardware breakpoint, memory
2530 is readonly. We change the type of the location to
2531 hardware breakpoint.
2532 - location type is hardware breakpoint, memory is
2533 read-write. This means we've previously made the
2534 location hardware one, but then the memory map changed,
2537 When breakpoints are removed, remove_breakpoints will use
2538 location types we've just set here, the only possible
2539 problem is that memory map has changed during running
2540 program, but it's not going to work anyway with current
2542 struct mem_region *mr
2543 = lookup_mem_region (bl->target_info.reqstd_address);
2547 if (automatic_hardware_breakpoints)
2549 enum bp_loc_type new_type;
2551 if (mr->attrib.mode != MEM_RW)
2552 new_type = bp_loc_hardware_breakpoint;
2554 new_type = bp_loc_software_breakpoint;
2556 if (new_type != bl->loc_type)
2558 static int said = 0;
2560 bl->loc_type = new_type;
2563 fprintf_filtered (gdb_stdout,
2564 _("Note: automatically using "
2565 "hardware breakpoints for "
2566 "read-only addresses.\n"));
2571 else if (bl->loc_type == bp_loc_software_breakpoint
2572 && mr->attrib.mode != MEM_RW)
2574 fprintf_unfiltered (tmp_error_stream,
2575 _("Cannot insert breakpoint %d.\n"
2576 "Cannot set software breakpoint "
2577 "at read-only address %s\n"),
2579 paddress (bl->gdbarch, bl->address));
2585 /* First check to see if we have to handle an overlay. */
2586 if (overlay_debugging == ovly_off
2587 || bl->section == NULL
2588 || !(section_is_overlay (bl->section)))
2590 /* No overlay handling: just set the breakpoint. */
2595 val = bl->owner->ops->insert_location (bl);
2597 bp_err = GENERIC_ERROR;
2599 CATCH (e, RETURN_MASK_ALL)
2602 bp_err_message = e.message;
2608 /* This breakpoint is in an overlay section.
2609 Shall we set a breakpoint at the LMA? */
2610 if (!overlay_events_enabled)
2612 /* Yes -- overlay event support is not active,
2613 so we must try to set a breakpoint at the LMA.
2614 This will not work for a hardware breakpoint. */
2615 if (bl->loc_type == bp_loc_hardware_breakpoint)
2616 warning (_("hardware breakpoint %d not supported in overlay!"),
2620 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2622 /* Set a software (trap) breakpoint at the LMA. */
2623 bl->overlay_target_info = bl->target_info;
2624 bl->overlay_target_info.reqstd_address = addr;
2626 /* No overlay handling: just set the breakpoint. */
2631 bl->overlay_target_info.kind
2632 = breakpoint_kind (bl, &addr);
2633 bl->overlay_target_info.placed_address = addr;
2634 val = target_insert_breakpoint (bl->gdbarch,
2635 &bl->overlay_target_info);
2637 bp_err = GENERIC_ERROR;
2639 CATCH (e, RETURN_MASK_ALL)
2642 bp_err_message = e.message;
2646 if (bp_err != GDB_NO_ERROR)
2647 fprintf_unfiltered (tmp_error_stream,
2648 "Overlay breakpoint %d "
2649 "failed: in ROM?\n",
2653 /* Shall we set a breakpoint at the VMA? */
2654 if (section_is_mapped (bl->section))
2656 /* Yes. This overlay section is mapped into memory. */
2661 val = bl->owner->ops->insert_location (bl);
2663 bp_err = GENERIC_ERROR;
2665 CATCH (e, RETURN_MASK_ALL)
2668 bp_err_message = e.message;
2674 /* No. This breakpoint will not be inserted.
2675 No error, but do not mark the bp as 'inserted'. */
2680 if (bp_err != GDB_NO_ERROR)
2682 /* Can't set the breakpoint. */
2684 /* In some cases, we might not be able to insert a
2685 breakpoint in a shared library that has already been
2686 removed, but we have not yet processed the shlib unload
2687 event. Unfortunately, some targets that implement
2688 breakpoint insertion themselves can't tell why the
2689 breakpoint insertion failed (e.g., the remote target
2690 doesn't define error codes), so we must treat generic
2691 errors as memory errors. */
2692 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2693 && bl->loc_type == bp_loc_software_breakpoint
2694 && (solib_name_from_address (bl->pspace, bl->address)
2695 || shared_objfile_contains_address_p (bl->pspace,
2698 /* See also: disable_breakpoints_in_shlibs. */
2699 bl->shlib_disabled = 1;
2700 observer_notify_breakpoint_modified (bl->owner);
2701 if (!*disabled_breaks)
2703 fprintf_unfiltered (tmp_error_stream,
2704 "Cannot insert breakpoint %d.\n",
2706 fprintf_unfiltered (tmp_error_stream,
2707 "Temporarily disabling shared "
2708 "library breakpoints:\n");
2710 *disabled_breaks = 1;
2711 fprintf_unfiltered (tmp_error_stream,
2712 "breakpoint #%d\n", bl->owner->number);
2717 if (bl->loc_type == bp_loc_hardware_breakpoint)
2719 *hw_breakpoint_error = 1;
2720 *hw_bp_error_explained_already = bp_err_message != NULL;
2721 fprintf_unfiltered (tmp_error_stream,
2722 "Cannot insert hardware breakpoint %d%s",
2723 bl->owner->number, bp_err_message ? ":" : ".\n");
2724 if (bp_err_message != NULL)
2725 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2729 if (bp_err_message == NULL)
2732 = memory_error_message (TARGET_XFER_E_IO,
2733 bl->gdbarch, bl->address);
2735 fprintf_unfiltered (tmp_error_stream,
2736 "Cannot insert breakpoint %d.\n"
2738 bl->owner->number, message.c_str ());
2742 fprintf_unfiltered (tmp_error_stream,
2743 "Cannot insert breakpoint %d: %s\n",
2758 else if (bl->loc_type == bp_loc_hardware_watchpoint
2759 /* NOTE drow/2003-09-08: This state only exists for removing
2760 watchpoints. It's not clear that it's necessary... */
2761 && bl->owner->disposition != disp_del_at_next_stop)
2765 gdb_assert (bl->owner->ops != NULL
2766 && bl->owner->ops->insert_location != NULL);
2768 val = bl->owner->ops->insert_location (bl);
2770 /* If trying to set a read-watchpoint, and it turns out it's not
2771 supported, try emulating one with an access watchpoint. */
2772 if (val == 1 && bl->watchpoint_type == hw_read)
2774 struct bp_location *loc, **loc_temp;
2776 /* But don't try to insert it, if there's already another
2777 hw_access location that would be considered a duplicate
2779 ALL_BP_LOCATIONS (loc, loc_temp)
2781 && loc->watchpoint_type == hw_access
2782 && watchpoint_locations_match (bl, loc))
2786 bl->target_info = loc->target_info;
2787 bl->watchpoint_type = hw_access;
2794 bl->watchpoint_type = hw_access;
2795 val = bl->owner->ops->insert_location (bl);
2798 /* Back to the original value. */
2799 bl->watchpoint_type = hw_read;
2803 bl->inserted = (val == 0);
2806 else if (bl->owner->type == bp_catchpoint)
2810 gdb_assert (bl->owner->ops != NULL
2811 && bl->owner->ops->insert_location != NULL);
2813 val = bl->owner->ops->insert_location (bl);
2816 bl->owner->enable_state = bp_disabled;
2820 Error inserting catchpoint %d: Your system does not support this type\n\
2821 of catchpoint."), bl->owner->number);
2823 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2826 bl->inserted = (val == 0);
2828 /* We've already printed an error message if there was a problem
2829 inserting this catchpoint, and we've disabled the catchpoint,
2830 so just return success. */
2837 /* This function is called when program space PSPACE is about to be
2838 deleted. It takes care of updating breakpoints to not reference
2842 breakpoint_program_space_exit (struct program_space *pspace)
2844 struct breakpoint *b, *b_temp;
2845 struct bp_location *loc, **loc_temp;
2847 /* Remove any breakpoint that was set through this program space. */
2848 ALL_BREAKPOINTS_SAFE (b, b_temp)
2850 if (b->pspace == pspace)
2851 delete_breakpoint (b);
2854 /* Breakpoints set through other program spaces could have locations
2855 bound to PSPACE as well. Remove those. */
2856 ALL_BP_LOCATIONS (loc, loc_temp)
2858 struct bp_location *tmp;
2860 if (loc->pspace == pspace)
2862 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2863 if (loc->owner->loc == loc)
2864 loc->owner->loc = loc->next;
2866 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2867 if (tmp->next == loc)
2869 tmp->next = loc->next;
2875 /* Now update the global location list to permanently delete the
2876 removed locations above. */
2877 update_global_location_list (UGLL_DONT_INSERT);
2880 /* Make sure all breakpoints are inserted in inferior.
2881 Throws exception on any error.
2882 A breakpoint that is already inserted won't be inserted
2883 again, so calling this function twice is safe. */
2885 insert_breakpoints (void)
2887 struct breakpoint *bpt;
2889 ALL_BREAKPOINTS (bpt)
2890 if (is_hardware_watchpoint (bpt))
2892 struct watchpoint *w = (struct watchpoint *) bpt;
2894 update_watchpoint (w, 0 /* don't reparse. */);
2897 /* Updating watchpoints creates new locations, so update the global
2898 location list. Explicitly tell ugll to insert locations and
2899 ignore breakpoints_always_inserted_mode. */
2900 update_global_location_list (UGLL_INSERT);
2903 /* Invoke CALLBACK for each of bp_location. */
2906 iterate_over_bp_locations (walk_bp_location_callback callback)
2908 struct bp_location *loc, **loc_tmp;
2910 ALL_BP_LOCATIONS (loc, loc_tmp)
2912 callback (loc, NULL);
2916 /* This is used when we need to synch breakpoint conditions between GDB and the
2917 target. It is the case with deleting and disabling of breakpoints when using
2918 always-inserted mode. */
2921 update_inserted_breakpoint_locations (void)
2923 struct bp_location *bl, **blp_tmp;
2926 int disabled_breaks = 0;
2927 int hw_breakpoint_error = 0;
2928 int hw_bp_details_reported = 0;
2930 string_file tmp_error_stream;
2932 /* Explicitly mark the warning -- this will only be printed if
2933 there was an error. */
2934 tmp_error_stream.puts ("Warning:\n");
2936 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2938 ALL_BP_LOCATIONS (bl, blp_tmp)
2940 /* We only want to update software breakpoints and hardware
2942 if (!is_breakpoint (bl->owner))
2945 /* We only want to update locations that are already inserted
2946 and need updating. This is to avoid unwanted insertion during
2947 deletion of breakpoints. */
2948 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2951 switch_to_program_space_and_thread (bl->pspace);
2953 /* For targets that support global breakpoints, there's no need
2954 to select an inferior to insert breakpoint to. In fact, even
2955 if we aren't attached to any process yet, we should still
2956 insert breakpoints. */
2957 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2958 && ptid_equal (inferior_ptid, null_ptid))
2961 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
2962 &hw_breakpoint_error, &hw_bp_details_reported);
2969 target_terminal::ours_for_output ();
2970 error_stream (tmp_error_stream);
2974 /* Used when starting or continuing the program. */
2977 insert_breakpoint_locations (void)
2979 struct breakpoint *bpt;
2980 struct bp_location *bl, **blp_tmp;
2983 int disabled_breaks = 0;
2984 int hw_breakpoint_error = 0;
2985 int hw_bp_error_explained_already = 0;
2987 string_file tmp_error_stream;
2989 /* Explicitly mark the warning -- this will only be printed if
2990 there was an error. */
2991 tmp_error_stream.puts ("Warning:\n");
2993 scoped_restore_current_pspace_and_thread restore_pspace_thread;
2995 ALL_BP_LOCATIONS (bl, blp_tmp)
2997 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3000 /* There is no point inserting thread-specific breakpoints if
3001 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3002 has BL->OWNER always non-NULL. */
3003 if (bl->owner->thread != -1
3004 && !valid_global_thread_id (bl->owner->thread))
3007 switch_to_program_space_and_thread (bl->pspace);
3009 /* For targets that support global breakpoints, there's no need
3010 to select an inferior to insert breakpoint to. In fact, even
3011 if we aren't attached to any process yet, we should still
3012 insert breakpoints. */
3013 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3014 && ptid_equal (inferior_ptid, null_ptid))
3017 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
3018 &hw_breakpoint_error, &hw_bp_error_explained_already);
3023 /* If we failed to insert all locations of a watchpoint, remove
3024 them, as half-inserted watchpoint is of limited use. */
3025 ALL_BREAKPOINTS (bpt)
3027 int some_failed = 0;
3028 struct bp_location *loc;
3030 if (!is_hardware_watchpoint (bpt))
3033 if (!breakpoint_enabled (bpt))
3036 if (bpt->disposition == disp_del_at_next_stop)
3039 for (loc = bpt->loc; loc; loc = loc->next)
3040 if (!loc->inserted && should_be_inserted (loc))
3047 for (loc = bpt->loc; loc; loc = loc->next)
3049 remove_breakpoint (loc);
3051 hw_breakpoint_error = 1;
3052 tmp_error_stream.printf ("Could not insert "
3053 "hardware watchpoint %d.\n",
3061 /* If a hardware breakpoint or watchpoint was inserted, add a
3062 message about possibly exhausted resources. */
3063 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3065 tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
3066 You may have requested too many hardware breakpoints/watchpoints.\n");
3068 target_terminal::ours_for_output ();
3069 error_stream (tmp_error_stream);
3073 /* Used when the program stops.
3074 Returns zero if successful, or non-zero if there was a problem
3075 removing a breakpoint location. */
3078 remove_breakpoints (void)
3080 struct bp_location *bl, **blp_tmp;
3083 ALL_BP_LOCATIONS (bl, blp_tmp)
3085 if (bl->inserted && !is_tracepoint (bl->owner))
3086 val |= remove_breakpoint (bl);
3091 /* When a thread exits, remove breakpoints that are related to
3095 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3097 struct breakpoint *b, *b_tmp;
3099 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3101 if (b->thread == tp->global_num && user_breakpoint_p (b))
3103 b->disposition = disp_del_at_next_stop;
3105 printf_filtered (_("\
3106 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3107 b->number, print_thread_id (tp));
3109 /* Hide it from the user. */
3115 /* Remove breakpoints of process PID. */
3118 remove_breakpoints_pid (int pid)
3120 struct bp_location *bl, **blp_tmp;
3122 struct inferior *inf = find_inferior_pid (pid);
3124 ALL_BP_LOCATIONS (bl, blp_tmp)
3126 if (bl->pspace != inf->pspace)
3129 if (bl->inserted && !bl->target_info.persist)
3131 val = remove_breakpoint (bl);
3139 static int internal_breakpoint_number = -1;
3141 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3142 If INTERNAL is non-zero, the breakpoint number will be populated
3143 from internal_breakpoint_number and that variable decremented.
3144 Otherwise the breakpoint number will be populated from
3145 breakpoint_count and that value incremented. Internal breakpoints
3146 do not set the internal var bpnum. */
3148 set_breakpoint_number (int internal, struct breakpoint *b)
3151 b->number = internal_breakpoint_number--;
3154 set_breakpoint_count (breakpoint_count + 1);
3155 b->number = breakpoint_count;
3159 static struct breakpoint *
3160 create_internal_breakpoint (struct gdbarch *gdbarch,
3161 CORE_ADDR address, enum bptype type,
3162 const struct breakpoint_ops *ops)
3164 symtab_and_line sal;
3166 sal.section = find_pc_overlay (sal.pc);
3167 sal.pspace = current_program_space;
3169 breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops);
3170 b->number = internal_breakpoint_number--;
3171 b->disposition = disp_donttouch;
3176 static const char *const longjmp_names[] =
3178 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3180 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3182 /* Per-objfile data private to breakpoint.c. */
3183 struct breakpoint_objfile_data
3185 /* Minimal symbol for "_ovly_debug_event" (if any). */
3186 struct bound_minimal_symbol overlay_msym;
3188 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3189 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3191 /* True if we have looked for longjmp probes. */
3192 int longjmp_searched;
3194 /* SystemTap probe points for longjmp (if any). */
3195 VEC (probe_p) *longjmp_probes;
3197 /* Minimal symbol for "std::terminate()" (if any). */
3198 struct bound_minimal_symbol terminate_msym;
3200 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3201 struct bound_minimal_symbol exception_msym;
3203 /* True if we have looked for exception probes. */
3204 int exception_searched;
3206 /* SystemTap probe points for unwinding (if any). */
3207 VEC (probe_p) *exception_probes;
3210 static const struct objfile_data *breakpoint_objfile_key;
3212 /* Minimal symbol not found sentinel. */
3213 static struct minimal_symbol msym_not_found;
3215 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3218 msym_not_found_p (const struct minimal_symbol *msym)
3220 return msym == &msym_not_found;
3223 /* Return per-objfile data needed by breakpoint.c.
3224 Allocate the data if necessary. */
3226 static struct breakpoint_objfile_data *
3227 get_breakpoint_objfile_data (struct objfile *objfile)
3229 struct breakpoint_objfile_data *bp_objfile_data;
3231 bp_objfile_data = ((struct breakpoint_objfile_data *)
3232 objfile_data (objfile, breakpoint_objfile_key));
3233 if (bp_objfile_data == NULL)
3236 XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
3238 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3239 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3241 return bp_objfile_data;
3245 free_breakpoint_probes (struct objfile *obj, void *data)
3247 struct breakpoint_objfile_data *bp_objfile_data
3248 = (struct breakpoint_objfile_data *) data;
3250 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3251 VEC_free (probe_p, bp_objfile_data->exception_probes);
3255 create_overlay_event_breakpoint (void)
3257 struct objfile *objfile;
3258 const char *const func_name = "_ovly_debug_event";
3260 ALL_OBJFILES (objfile)
3262 struct breakpoint *b;
3263 struct breakpoint_objfile_data *bp_objfile_data;
3265 struct explicit_location explicit_loc;
3267 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3269 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3272 if (bp_objfile_data->overlay_msym.minsym == NULL)
3274 struct bound_minimal_symbol m;
3276 m = lookup_minimal_symbol_text (func_name, objfile);
3277 if (m.minsym == NULL)
3279 /* Avoid future lookups in this objfile. */
3280 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3283 bp_objfile_data->overlay_msym = m;
3286 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3287 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3289 &internal_breakpoint_ops);
3290 initialize_explicit_location (&explicit_loc);
3291 explicit_loc.function_name = ASTRDUP (func_name);
3292 b->location = new_explicit_location (&explicit_loc);
3294 if (overlay_debugging == ovly_auto)
3296 b->enable_state = bp_enabled;
3297 overlay_events_enabled = 1;
3301 b->enable_state = bp_disabled;
3302 overlay_events_enabled = 0;
3308 create_longjmp_master_breakpoint (void)
3310 struct program_space *pspace;
3312 scoped_restore_current_program_space restore_pspace;
3314 ALL_PSPACES (pspace)
3316 struct objfile *objfile;
3318 set_current_program_space (pspace);
3320 ALL_OBJFILES (objfile)
3323 struct gdbarch *gdbarch;
3324 struct breakpoint_objfile_data *bp_objfile_data;
3326 gdbarch = get_objfile_arch (objfile);
3328 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3330 if (!bp_objfile_data->longjmp_searched)
3334 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3337 /* We are only interested in checking one element. */
3338 struct probe *p = VEC_index (probe_p, ret, 0);
3340 if (!can_evaluate_probe_arguments (p))
3342 /* We cannot use the probe interface here, because it does
3343 not know how to evaluate arguments. */
3344 VEC_free (probe_p, ret);
3348 bp_objfile_data->longjmp_probes = ret;
3349 bp_objfile_data->longjmp_searched = 1;
3352 if (bp_objfile_data->longjmp_probes != NULL)
3355 struct probe *probe;
3356 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3359 VEC_iterate (probe_p,
3360 bp_objfile_data->longjmp_probes,
3364 struct breakpoint *b;
3366 b = create_internal_breakpoint (gdbarch,
3367 get_probe_address (probe,
3370 &internal_breakpoint_ops);
3371 b->location = new_probe_location ("-probe-stap libc:longjmp");
3372 b->enable_state = bp_disabled;
3378 if (!gdbarch_get_longjmp_target_p (gdbarch))
3381 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3383 struct breakpoint *b;
3384 const char *func_name;
3386 struct explicit_location explicit_loc;
3388 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3391 func_name = longjmp_names[i];
3392 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3394 struct bound_minimal_symbol m;
3396 m = lookup_minimal_symbol_text (func_name, objfile);
3397 if (m.minsym == NULL)
3399 /* Prevent future lookups in this objfile. */
3400 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3403 bp_objfile_data->longjmp_msym[i] = m;
3406 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3407 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3408 &internal_breakpoint_ops);
3409 initialize_explicit_location (&explicit_loc);
3410 explicit_loc.function_name = ASTRDUP (func_name);
3411 b->location = new_explicit_location (&explicit_loc);
3412 b->enable_state = bp_disabled;
3418 /* Create a master std::terminate breakpoint. */
3420 create_std_terminate_master_breakpoint (void)
3422 struct program_space *pspace;
3423 const char *const func_name = "std::terminate()";
3425 scoped_restore_current_program_space restore_pspace;
3427 ALL_PSPACES (pspace)
3429 struct objfile *objfile;
3432 set_current_program_space (pspace);
3434 ALL_OBJFILES (objfile)
3436 struct breakpoint *b;
3437 struct breakpoint_objfile_data *bp_objfile_data;
3438 struct explicit_location explicit_loc;
3440 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3442 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3445 if (bp_objfile_data->terminate_msym.minsym == NULL)
3447 struct bound_minimal_symbol m;
3449 m = lookup_minimal_symbol (func_name, NULL, objfile);
3450 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3451 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3453 /* Prevent future lookups in this objfile. */
3454 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3457 bp_objfile_data->terminate_msym = m;
3460 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3461 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3462 bp_std_terminate_master,
3463 &internal_breakpoint_ops);
3464 initialize_explicit_location (&explicit_loc);
3465 explicit_loc.function_name = ASTRDUP (func_name);
3466 b->location = new_explicit_location (&explicit_loc);
3467 b->enable_state = bp_disabled;
3472 /* Install a master breakpoint on the unwinder's debug hook. */
3475 create_exception_master_breakpoint (void)
3477 struct objfile *objfile;
3478 const char *const func_name = "_Unwind_DebugHook";
3480 ALL_OBJFILES (objfile)
3482 struct breakpoint *b;
3483 struct gdbarch *gdbarch;
3484 struct breakpoint_objfile_data *bp_objfile_data;
3486 struct explicit_location explicit_loc;
3488 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3490 /* We prefer the SystemTap probe point if it exists. */
3491 if (!bp_objfile_data->exception_searched)
3495 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3499 /* We are only interested in checking one element. */
3500 struct probe *p = VEC_index (probe_p, ret, 0);
3502 if (!can_evaluate_probe_arguments (p))
3504 /* We cannot use the probe interface here, because it does
3505 not know how to evaluate arguments. */
3506 VEC_free (probe_p, ret);
3510 bp_objfile_data->exception_probes = ret;
3511 bp_objfile_data->exception_searched = 1;
3514 if (bp_objfile_data->exception_probes != NULL)
3516 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3518 struct probe *probe;
3521 VEC_iterate (probe_p,
3522 bp_objfile_data->exception_probes,
3526 struct breakpoint *b;
3528 b = create_internal_breakpoint (gdbarch,
3529 get_probe_address (probe,
3531 bp_exception_master,
3532 &internal_breakpoint_ops);
3533 b->location = new_probe_location ("-probe-stap libgcc:unwind");
3534 b->enable_state = bp_disabled;
3540 /* Otherwise, try the hook function. */
3542 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3545 gdbarch = get_objfile_arch (objfile);
3547 if (bp_objfile_data->exception_msym.minsym == NULL)
3549 struct bound_minimal_symbol debug_hook;
3551 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3552 if (debug_hook.minsym == NULL)
3554 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3558 bp_objfile_data->exception_msym = debug_hook;
3561 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3562 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3564 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3565 &internal_breakpoint_ops);
3566 initialize_explicit_location (&explicit_loc);
3567 explicit_loc.function_name = ASTRDUP (func_name);
3568 b->location = new_explicit_location (&explicit_loc);
3569 b->enable_state = bp_disabled;
3573 /* Does B have a location spec? */
3576 breakpoint_event_location_empty_p (const struct breakpoint *b)
3578 return b->location != NULL && event_location_empty_p (b->location.get ());
3582 update_breakpoints_after_exec (void)
3584 struct breakpoint *b, *b_tmp;
3585 struct bp_location *bploc, **bplocp_tmp;
3587 /* We're about to delete breakpoints from GDB's lists. If the
3588 INSERTED flag is true, GDB will try to lift the breakpoints by
3589 writing the breakpoints' "shadow contents" back into memory. The
3590 "shadow contents" are NOT valid after an exec, so GDB should not
3591 do that. Instead, the target is responsible from marking
3592 breakpoints out as soon as it detects an exec. We don't do that
3593 here instead, because there may be other attempts to delete
3594 breakpoints after detecting an exec and before reaching here. */
3595 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3596 if (bploc->pspace == current_program_space)
3597 gdb_assert (!bploc->inserted);
3599 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3601 if (b->pspace != current_program_space)
3604 /* Solib breakpoints must be explicitly reset after an exec(). */
3605 if (b->type == bp_shlib_event)
3607 delete_breakpoint (b);
3611 /* JIT breakpoints must be explicitly reset after an exec(). */
3612 if (b->type == bp_jit_event)
3614 delete_breakpoint (b);
3618 /* Thread event breakpoints must be set anew after an exec(),
3619 as must overlay event and longjmp master breakpoints. */
3620 if (b->type == bp_thread_event || b->type == bp_overlay_event
3621 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3622 || b->type == bp_exception_master)
3624 delete_breakpoint (b);
3628 /* Step-resume breakpoints are meaningless after an exec(). */
3629 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3631 delete_breakpoint (b);
3635 /* Just like single-step breakpoints. */
3636 if (b->type == bp_single_step)
3638 delete_breakpoint (b);
3642 /* Longjmp and longjmp-resume breakpoints are also meaningless
3644 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3645 || b->type == bp_longjmp_call_dummy
3646 || b->type == bp_exception || b->type == bp_exception_resume)
3648 delete_breakpoint (b);
3652 if (b->type == bp_catchpoint)
3654 /* For now, none of the bp_catchpoint breakpoints need to
3655 do anything at this point. In the future, if some of
3656 the catchpoints need to something, we will need to add
3657 a new method, and call this method from here. */
3661 /* bp_finish is a special case. The only way we ought to be able
3662 to see one of these when an exec() has happened, is if the user
3663 caught a vfork, and then said "finish". Ordinarily a finish just
3664 carries them to the call-site of the current callee, by setting
3665 a temporary bp there and resuming. But in this case, the finish
3666 will carry them entirely through the vfork & exec.
3668 We don't want to allow a bp_finish to remain inserted now. But
3669 we can't safely delete it, 'cause finish_command has a handle to
3670 the bp on a bpstat, and will later want to delete it. There's a
3671 chance (and I've seen it happen) that if we delete the bp_finish
3672 here, that its storage will get reused by the time finish_command
3673 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3674 We really must allow finish_command to delete a bp_finish.
3676 In the absence of a general solution for the "how do we know
3677 it's safe to delete something others may have handles to?"
3678 problem, what we'll do here is just uninsert the bp_finish, and
3679 let finish_command delete it.
3681 (We know the bp_finish is "doomed" in the sense that it's
3682 momentary, and will be deleted as soon as finish_command sees
3683 the inferior stopped. So it doesn't matter that the bp's
3684 address is probably bogus in the new a.out, unlike e.g., the
3685 solib breakpoints.) */
3687 if (b->type == bp_finish)
3692 /* Without a symbolic address, we have little hope of the
3693 pre-exec() address meaning the same thing in the post-exec()
3695 if (breakpoint_event_location_empty_p (b))
3697 delete_breakpoint (b);
3704 detach_breakpoints (ptid_t ptid)
3706 struct bp_location *bl, **blp_tmp;
3708 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
3709 struct inferior *inf = current_inferior ();
3711 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3712 error (_("Cannot detach breakpoints of inferior_ptid"));
3714 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3715 inferior_ptid = ptid;
3716 ALL_BP_LOCATIONS (bl, blp_tmp)
3718 if (bl->pspace != inf->pspace)
3721 /* This function must physically remove breakpoints locations
3722 from the specified ptid, without modifying the breakpoint
3723 package's state. Locations of type bp_loc_other are only
3724 maintained at GDB side. So, there is no need to remove
3725 these bp_loc_other locations. Moreover, removing these
3726 would modify the breakpoint package's state. */
3727 if (bl->loc_type == bp_loc_other)
3731 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3737 /* Remove the breakpoint location BL from the current address space.
3738 Note that this is used to detach breakpoints from a child fork.
3739 When we get here, the child isn't in the inferior list, and neither
3740 do we have objects to represent its address space --- we should
3741 *not* look at bl->pspace->aspace here. */
3744 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3748 /* BL is never in moribund_locations by our callers. */
3749 gdb_assert (bl->owner != NULL);
3751 /* The type of none suggests that owner is actually deleted.
3752 This should not ever happen. */
3753 gdb_assert (bl->owner->type != bp_none);
3755 if (bl->loc_type == bp_loc_software_breakpoint
3756 || bl->loc_type == bp_loc_hardware_breakpoint)
3758 /* "Normal" instruction breakpoint: either the standard
3759 trap-instruction bp (bp_breakpoint), or a
3760 bp_hardware_breakpoint. */
3762 /* First check to see if we have to handle an overlay. */
3763 if (overlay_debugging == ovly_off
3764 || bl->section == NULL
3765 || !(section_is_overlay (bl->section)))
3767 /* No overlay handling: just remove the breakpoint. */
3769 /* If we're trying to uninsert a memory breakpoint that we
3770 know is set in a dynamic object that is marked
3771 shlib_disabled, then either the dynamic object was
3772 removed with "remove-symbol-file" or with
3773 "nosharedlibrary". In the former case, we don't know
3774 whether another dynamic object might have loaded over the
3775 breakpoint's address -- the user might well let us know
3776 about it next with add-symbol-file (the whole point of
3777 add-symbol-file is letting the user manually maintain a
3778 list of dynamically loaded objects). If we have the
3779 breakpoint's shadow memory, that is, this is a software
3780 breakpoint managed by GDB, check whether the breakpoint
3781 is still inserted in memory, to avoid overwriting wrong
3782 code with stale saved shadow contents. Note that HW
3783 breakpoints don't have shadow memory, as they're
3784 implemented using a mechanism that is not dependent on
3785 being able to modify the target's memory, and as such
3786 they should always be removed. */
3787 if (bl->shlib_disabled
3788 && bl->target_info.shadow_len != 0
3789 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3792 val = bl->owner->ops->remove_location (bl, reason);
3796 /* This breakpoint is in an overlay section.
3797 Did we set a breakpoint at the LMA? */
3798 if (!overlay_events_enabled)
3800 /* Yes -- overlay event support is not active, so we
3801 should have set a breakpoint at the LMA. Remove it.
3803 /* Ignore any failures: if the LMA is in ROM, we will
3804 have already warned when we failed to insert it. */
3805 if (bl->loc_type == bp_loc_hardware_breakpoint)
3806 target_remove_hw_breakpoint (bl->gdbarch,
3807 &bl->overlay_target_info);
3809 target_remove_breakpoint (bl->gdbarch,
3810 &bl->overlay_target_info,
3813 /* Did we set a breakpoint at the VMA?
3814 If so, we will have marked the breakpoint 'inserted'. */
3817 /* Yes -- remove it. Previously we did not bother to
3818 remove the breakpoint if the section had been
3819 unmapped, but let's not rely on that being safe. We
3820 don't know what the overlay manager might do. */
3822 /* However, we should remove *software* breakpoints only
3823 if the section is still mapped, or else we overwrite
3824 wrong code with the saved shadow contents. */
3825 if (bl->loc_type == bp_loc_hardware_breakpoint
3826 || section_is_mapped (bl->section))
3827 val = bl->owner->ops->remove_location (bl, reason);
3833 /* No -- not inserted, so no need to remove. No error. */
3838 /* In some cases, we might not be able to remove a breakpoint in
3839 a shared library that has already been removed, but we have
3840 not yet processed the shlib unload event. Similarly for an
3841 unloaded add-symbol-file object - the user might not yet have
3842 had the chance to remove-symbol-file it. shlib_disabled will
3843 be set if the library/object has already been removed, but
3844 the breakpoint hasn't been uninserted yet, e.g., after
3845 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3846 always-inserted mode. */
3848 && (bl->loc_type == bp_loc_software_breakpoint
3849 && (bl->shlib_disabled
3850 || solib_name_from_address (bl->pspace, bl->address)
3851 || shared_objfile_contains_address_p (bl->pspace,
3857 bl->inserted = (reason == DETACH_BREAKPOINT);
3859 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3861 gdb_assert (bl->owner->ops != NULL
3862 && bl->owner->ops->remove_location != NULL);
3864 bl->inserted = (reason == DETACH_BREAKPOINT);
3865 bl->owner->ops->remove_location (bl, reason);
3867 /* Failure to remove any of the hardware watchpoints comes here. */
3868 if (reason == REMOVE_BREAKPOINT && bl->inserted)
3869 warning (_("Could not remove hardware watchpoint %d."),
3872 else if (bl->owner->type == bp_catchpoint
3873 && breakpoint_enabled (bl->owner)
3876 gdb_assert (bl->owner->ops != NULL
3877 && bl->owner->ops->remove_location != NULL);
3879 val = bl->owner->ops->remove_location (bl, reason);
3883 bl->inserted = (reason == DETACH_BREAKPOINT);
3890 remove_breakpoint (struct bp_location *bl)
3892 /* BL is never in moribund_locations by our callers. */
3893 gdb_assert (bl->owner != NULL);
3895 /* The type of none suggests that owner is actually deleted.
3896 This should not ever happen. */
3897 gdb_assert (bl->owner->type != bp_none);
3899 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3901 switch_to_program_space_and_thread (bl->pspace);
3903 return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
3906 /* Clear the "inserted" flag in all breakpoints. */
3909 mark_breakpoints_out (void)
3911 struct bp_location *bl, **blp_tmp;
3913 ALL_BP_LOCATIONS (bl, blp_tmp)
3914 if (bl->pspace == current_program_space)
3918 /* Clear the "inserted" flag in all breakpoints and delete any
3919 breakpoints which should go away between runs of the program.
3921 Plus other such housekeeping that has to be done for breakpoints
3924 Note: this function gets called at the end of a run (by
3925 generic_mourn_inferior) and when a run begins (by
3926 init_wait_for_inferior). */
3931 breakpoint_init_inferior (enum inf_context context)
3933 struct breakpoint *b, *b_tmp;
3934 struct bp_location *bl;
3936 struct program_space *pspace = current_program_space;
3938 /* If breakpoint locations are shared across processes, then there's
3940 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3943 mark_breakpoints_out ();
3945 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3947 if (b->loc && b->loc->pspace != pspace)
3953 case bp_longjmp_call_dummy:
3955 /* If the call dummy breakpoint is at the entry point it will
3956 cause problems when the inferior is rerun, so we better get
3959 case bp_watchpoint_scope:
3961 /* Also get rid of scope breakpoints. */
3963 case bp_shlib_event:
3965 /* Also remove solib event breakpoints. Their addresses may
3966 have changed since the last time we ran the program.
3967 Actually we may now be debugging against different target;
3968 and so the solib backend that installed this breakpoint may
3969 not be used in by the target. E.g.,
3971 (gdb) file prog-linux
3972 (gdb) run # native linux target
3975 (gdb) file prog-win.exe
3976 (gdb) tar rem :9999 # remote Windows gdbserver.
3979 case bp_step_resume:
3981 /* Also remove step-resume breakpoints. */
3983 case bp_single_step:
3985 /* Also remove single-step breakpoints. */
3987 delete_breakpoint (b);
3991 case bp_hardware_watchpoint:
3992 case bp_read_watchpoint:
3993 case bp_access_watchpoint:
3995 struct watchpoint *w = (struct watchpoint *) b;
3997 /* Likewise for watchpoints on local expressions. */
3998 if (w->exp_valid_block != NULL)
3999 delete_breakpoint (b);
4002 /* Get rid of existing locations, which are no longer
4003 valid. New ones will be created in
4004 update_watchpoint, when the inferior is restarted.
4005 The next update_global_location_list call will
4006 garbage collect them. */
4009 if (context == inf_starting)
4011 /* Reset val field to force reread of starting value in
4012 insert_breakpoints. */
4014 value_free (w->val);
4026 /* Get rid of the moribund locations. */
4027 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4028 decref_bp_location (&bl);
4029 VEC_free (bp_location_p, moribund_locations);
4032 /* These functions concern about actual breakpoints inserted in the
4033 target --- to e.g. check if we need to do decr_pc adjustment or if
4034 we need to hop over the bkpt --- so we check for address space
4035 match, not program space. */
4037 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4038 exists at PC. It returns ordinary_breakpoint_here if it's an
4039 ordinary breakpoint, or permanent_breakpoint_here if it's a
4040 permanent breakpoint.
4041 - When continuing from a location with an ordinary breakpoint, we
4042 actually single step once before calling insert_breakpoints.
4043 - When continuing from a location with a permanent breakpoint, we
4044 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4045 the target, to advance the PC past the breakpoint. */
4047 enum breakpoint_here
4048 breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
4050 struct bp_location *bl, **blp_tmp;
4051 int any_breakpoint_here = 0;
4053 ALL_BP_LOCATIONS (bl, blp_tmp)
4055 if (bl->loc_type != bp_loc_software_breakpoint
4056 && bl->loc_type != bp_loc_hardware_breakpoint)
4059 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4060 if ((breakpoint_enabled (bl->owner)
4062 && breakpoint_location_address_match (bl, aspace, pc))
4064 if (overlay_debugging
4065 && section_is_overlay (bl->section)
4066 && !section_is_mapped (bl->section))
4067 continue; /* unmapped overlay -- can't be a match */
4068 else if (bl->permanent)
4069 return permanent_breakpoint_here;
4071 any_breakpoint_here = 1;
4075 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4078 /* See breakpoint.h. */
4081 breakpoint_in_range_p (const address_space *aspace,
4082 CORE_ADDR addr, ULONGEST len)
4084 struct bp_location *bl, **blp_tmp;
4086 ALL_BP_LOCATIONS (bl, blp_tmp)
4088 if (bl->loc_type != bp_loc_software_breakpoint
4089 && bl->loc_type != bp_loc_hardware_breakpoint)
4092 if ((breakpoint_enabled (bl->owner)
4094 && breakpoint_location_address_range_overlap (bl, aspace,
4097 if (overlay_debugging
4098 && section_is_overlay (bl->section)
4099 && !section_is_mapped (bl->section))
4101 /* Unmapped overlay -- can't be a match. */
4112 /* Return true if there's a moribund breakpoint at PC. */
4115 moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
4117 struct bp_location *loc;
4120 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4121 if (breakpoint_location_address_match (loc, aspace, pc))
4127 /* Returns non-zero iff BL is inserted at PC, in address space
4131 bp_location_inserted_here_p (struct bp_location *bl,
4132 const address_space *aspace, CORE_ADDR pc)
4135 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4138 if (overlay_debugging
4139 && section_is_overlay (bl->section)
4140 && !section_is_mapped (bl->section))
4141 return 0; /* unmapped overlay -- can't be a match */
4148 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4151 breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
4153 struct bp_location **blp, **blp_tmp = NULL;
4155 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4157 struct bp_location *bl = *blp;
4159 if (bl->loc_type != bp_loc_software_breakpoint
4160 && bl->loc_type != bp_loc_hardware_breakpoint)
4163 if (bp_location_inserted_here_p (bl, aspace, pc))
4169 /* This function returns non-zero iff there is a software breakpoint
4173 software_breakpoint_inserted_here_p (const address_space *aspace,
4176 struct bp_location **blp, **blp_tmp = NULL;
4178 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4180 struct bp_location *bl = *blp;
4182 if (bl->loc_type != bp_loc_software_breakpoint)
4185 if (bp_location_inserted_here_p (bl, aspace, pc))
4192 /* See breakpoint.h. */
4195 hardware_breakpoint_inserted_here_p (const address_space *aspace,
4198 struct bp_location **blp, **blp_tmp = NULL;
4200 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4202 struct bp_location *bl = *blp;
4204 if (bl->loc_type != bp_loc_hardware_breakpoint)
4207 if (bp_location_inserted_here_p (bl, aspace, pc))
4215 hardware_watchpoint_inserted_in_range (const address_space *aspace,
4216 CORE_ADDR addr, ULONGEST len)
4218 struct breakpoint *bpt;
4220 ALL_BREAKPOINTS (bpt)
4222 struct bp_location *loc;
4224 if (bpt->type != bp_hardware_watchpoint
4225 && bpt->type != bp_access_watchpoint)
4228 if (!breakpoint_enabled (bpt))
4231 for (loc = bpt->loc; loc; loc = loc->next)
4232 if (loc->pspace->aspace == aspace && loc->inserted)
4236 /* Check for intersection. */
4237 l = std::max<CORE_ADDR> (loc->address, addr);
4238 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4247 /* bpstat stuff. External routines' interfaces are documented
4251 is_catchpoint (struct breakpoint *ep)
4253 return (ep->type == bp_catchpoint);
4256 /* Frees any storage that is part of a bpstat. Does not walk the
4259 bpstats::~bpstats ()
4261 if (old_val != NULL)
4262 value_free (old_val);
4263 if (bp_location_at != NULL)
4264 decref_bp_location (&bp_location_at);
4267 /* Clear a bpstat so that it says we are not at any breakpoint.
4268 Also free any storage that is part of a bpstat. */
4271 bpstat_clear (bpstat *bsp)
4288 bpstats::bpstats (const bpstats &other)
4290 bp_location_at (other.bp_location_at),
4291 breakpoint_at (other.breakpoint_at),
4292 commands (other.commands),
4293 old_val (other.old_val),
4294 print (other.print),
4296 print_it (other.print_it)
4298 if (old_val != NULL)
4300 old_val = value_copy (old_val);
4301 release_value (old_val);
4303 incref_bp_location (bp_location_at);
4306 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4307 is part of the bpstat is copied as well. */
4310 bpstat_copy (bpstat bs)
4314 bpstat retval = NULL;
4319 for (; bs != NULL; bs = bs->next)
4321 tmp = new bpstats (*bs);
4324 /* This is the first thing in the chain. */
4334 /* Find the bpstat associated with this breakpoint. */
4337 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4342 for (; bsp != NULL; bsp = bsp->next)
4344 if (bsp->breakpoint_at == breakpoint)
4350 /* See breakpoint.h. */
4353 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4355 for (; bsp != NULL; bsp = bsp->next)
4357 if (bsp->breakpoint_at == NULL)
4359 /* A moribund location can never explain a signal other than
4361 if (sig == GDB_SIGNAL_TRAP)
4366 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4375 /* Put in *NUM the breakpoint number of the first breakpoint we are
4376 stopped at. *BSP upon return is a bpstat which points to the
4377 remaining breakpoints stopped at (but which is not guaranteed to be
4378 good for anything but further calls to bpstat_num).
4380 Return 0 if passed a bpstat which does not indicate any breakpoints.
4381 Return -1 if stopped at a breakpoint that has been deleted since
4383 Return 1 otherwise. */
4386 bpstat_num (bpstat *bsp, int *num)
4388 struct breakpoint *b;
4391 return 0; /* No more breakpoint values */
4393 /* We assume we'll never have several bpstats that correspond to a
4394 single breakpoint -- otherwise, this function might return the
4395 same number more than once and this will look ugly. */
4396 b = (*bsp)->breakpoint_at;
4397 *bsp = (*bsp)->next;
4399 return -1; /* breakpoint that's been deleted since */
4401 *num = b->number; /* We have its number */
4405 /* See breakpoint.h. */
4408 bpstat_clear_actions (void)
4410 struct thread_info *tp;
4413 if (ptid_equal (inferior_ptid, null_ptid))
4416 tp = find_thread_ptid (inferior_ptid);
4420 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4422 bs->commands = NULL;
4424 if (bs->old_val != NULL)
4426 value_free (bs->old_val);
4432 /* Called when a command is about to proceed the inferior. */
4435 breakpoint_about_to_proceed (void)
4437 if (!ptid_equal (inferior_ptid, null_ptid))
4439 struct thread_info *tp = inferior_thread ();
4441 /* Allow inferior function calls in breakpoint commands to not
4442 interrupt the command list. When the call finishes
4443 successfully, the inferior will be standing at the same
4444 breakpoint as if nothing happened. */
4445 if (tp->control.in_infcall)
4449 breakpoint_proceeded = 1;
4452 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4453 or its equivalent. */
4456 command_line_is_silent (struct command_line *cmd)
4458 return cmd && (strcmp ("silent", cmd->line) == 0);
4461 /* Execute all the commands associated with all the breakpoints at
4462 this location. Any of these commands could cause the process to
4463 proceed beyond this point, etc. We look out for such changes by
4464 checking the global "breakpoint_proceeded" after each command.
4466 Returns true if a breakpoint command resumed the inferior. In that
4467 case, it is the caller's responsibility to recall it again with the
4468 bpstat of the current thread. */
4471 bpstat_do_actions_1 (bpstat *bsp)
4476 /* Avoid endless recursion if a `source' command is contained
4478 if (executing_breakpoint_commands)
4481 scoped_restore save_executing
4482 = make_scoped_restore (&executing_breakpoint_commands, 1);
4484 scoped_restore preventer = prevent_dont_repeat ();
4486 /* This pointer will iterate over the list of bpstat's. */
4489 breakpoint_proceeded = 0;
4490 for (; bs != NULL; bs = bs->next)
4492 struct command_line *cmd = NULL;
4494 /* Take ownership of the BSP's command tree, if it has one.
4496 The command tree could legitimately contain commands like
4497 'step' and 'next', which call clear_proceed_status, which
4498 frees stop_bpstat's command tree. To make sure this doesn't
4499 free the tree we're executing out from under us, we need to
4500 take ownership of the tree ourselves. Since a given bpstat's
4501 commands are only executed once, we don't need to copy it; we
4502 can clear the pointer in the bpstat, and make sure we free
4503 the tree when we're done. */
4504 counted_command_line ccmd = bs->commands;
4505 bs->commands = NULL;
4508 if (command_line_is_silent (cmd))
4510 /* The action has been already done by bpstat_stop_status. */
4516 execute_control_command (cmd);
4518 if (breakpoint_proceeded)
4524 if (breakpoint_proceeded)
4526 if (current_ui->async)
4527 /* If we are in async mode, then the target might be still
4528 running, not stopped at any breakpoint, so nothing for
4529 us to do here -- just return to the event loop. */
4532 /* In sync mode, when execute_control_command returns
4533 we're already standing on the next breakpoint.
4534 Breakpoint commands for that stop were not run, since
4535 execute_command does not run breakpoint commands --
4536 only command_line_handler does, but that one is not
4537 involved in execution of breakpoint commands. So, we
4538 can now execute breakpoint commands. It should be
4539 noted that making execute_command do bpstat actions is
4540 not an option -- in this case we'll have recursive
4541 invocation of bpstat for each breakpoint with a
4542 command, and can easily blow up GDB stack. Instead, we
4543 return true, which will trigger the caller to recall us
4544 with the new stop_bpstat. */
4553 bpstat_do_actions (void)
4555 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4557 /* Do any commands attached to breakpoint we are stopped at. */
4558 while (!ptid_equal (inferior_ptid, null_ptid)
4559 && target_has_execution
4560 && !is_exited (inferior_ptid)
4561 && !is_executing (inferior_ptid))
4562 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4563 and only return when it is stopped at the next breakpoint, we
4564 keep doing breakpoint actions until it returns false to
4565 indicate the inferior was not resumed. */
4566 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4569 discard_cleanups (cleanup_if_error);
4572 /* Print out the (old or new) value associated with a watchpoint. */
4575 watchpoint_value_print (struct value *val, struct ui_file *stream)
4578 fprintf_unfiltered (stream, _("<unreadable>"));
4581 struct value_print_options opts;
4582 get_user_print_options (&opts);
4583 value_print (val, stream, &opts);
4587 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4588 debugging multiple threads. */
4591 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4593 if (uiout->is_mi_like_p ())
4598 if (show_thread_that_caused_stop ())
4601 struct thread_info *thr = inferior_thread ();
4603 uiout->text ("Thread ");
4604 uiout->field_fmt ("thread-id", "%s", print_thread_id (thr));
4606 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4609 uiout->text (" \"");
4610 uiout->field_fmt ("name", "%s", name);
4614 uiout->text (" hit ");
4618 /* Generic routine for printing messages indicating why we
4619 stopped. The behavior of this function depends on the value
4620 'print_it' in the bpstat structure. Under some circumstances we
4621 may decide not to print anything here and delegate the task to
4624 static enum print_stop_action
4625 print_bp_stop_message (bpstat bs)
4627 switch (bs->print_it)
4630 /* Nothing should be printed for this bpstat entry. */
4631 return PRINT_UNKNOWN;
4635 /* We still want to print the frame, but we already printed the
4636 relevant messages. */
4637 return PRINT_SRC_AND_LOC;
4640 case print_it_normal:
4642 struct breakpoint *b = bs->breakpoint_at;
4644 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4645 which has since been deleted. */
4647 return PRINT_UNKNOWN;
4649 /* Normal case. Call the breakpoint's print_it method. */
4650 return b->ops->print_it (bs);
4655 internal_error (__FILE__, __LINE__,
4656 _("print_bp_stop_message: unrecognized enum value"));
4661 /* A helper function that prints a shared library stopped event. */
4664 print_solib_event (int is_catchpoint)
4667 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4669 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4673 if (any_added || any_deleted)
4674 current_uiout->text (_("Stopped due to shared library event:\n"));
4676 current_uiout->text (_("Stopped due to shared library event (no "
4677 "libraries added or removed)\n"));
4680 if (current_uiout->is_mi_like_p ())
4681 current_uiout->field_string ("reason",
4682 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4689 current_uiout->text (_(" Inferior unloaded "));
4690 ui_out_emit_list list_emitter (current_uiout, "removed");
4692 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4697 current_uiout->text (" ");
4698 current_uiout->field_string ("library", name);
4699 current_uiout->text ("\n");
4705 struct so_list *iter;
4708 current_uiout->text (_(" Inferior loaded "));
4709 ui_out_emit_list list_emitter (current_uiout, "added");
4711 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4716 current_uiout->text (" ");
4717 current_uiout->field_string ("library", iter->so_name);
4718 current_uiout->text ("\n");
4723 /* Print a message indicating what happened. This is called from
4724 normal_stop(). The input to this routine is the head of the bpstat
4725 list - a list of the eventpoints that caused this stop. KIND is
4726 the target_waitkind for the stopping event. This
4727 routine calls the generic print routine for printing a message
4728 about reasons for stopping. This will print (for example) the
4729 "Breakpoint n," part of the output. The return value of this
4732 PRINT_UNKNOWN: Means we printed nothing.
4733 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4734 code to print the location. An example is
4735 "Breakpoint 1, " which should be followed by
4737 PRINT_SRC_ONLY: Means we printed something, but there is no need
4738 to also print the location part of the message.
4739 An example is the catch/throw messages, which
4740 don't require a location appended to the end.
4741 PRINT_NOTHING: We have done some printing and we don't need any
4742 further info to be printed. */
4744 enum print_stop_action
4745 bpstat_print (bpstat bs, int kind)
4747 enum print_stop_action val;
4749 /* Maybe another breakpoint in the chain caused us to stop.
4750 (Currently all watchpoints go on the bpstat whether hit or not.
4751 That probably could (should) be changed, provided care is taken
4752 with respect to bpstat_explains_signal). */
4753 for (; bs; bs = bs->next)
4755 val = print_bp_stop_message (bs);
4756 if (val == PRINT_SRC_ONLY
4757 || val == PRINT_SRC_AND_LOC
4758 || val == PRINT_NOTHING)
4762 /* If we had hit a shared library event breakpoint,
4763 print_bp_stop_message would print out this message. If we hit an
4764 OS-level shared library event, do the same thing. */
4765 if (kind == TARGET_WAITKIND_LOADED)
4767 print_solib_event (0);
4768 return PRINT_NOTHING;
4771 /* We reached the end of the chain, or we got a null BS to start
4772 with and nothing was printed. */
4773 return PRINT_UNKNOWN;
4776 /* Evaluate the boolean expression EXP and return the result. */
4779 breakpoint_cond_eval (expression *exp)
4781 struct value *mark = value_mark ();
4782 bool res = value_true (evaluate_expression (exp));
4784 value_free_to_mark (mark);
4788 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4790 bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer)
4792 bp_location_at (bl),
4793 breakpoint_at (bl->owner),
4798 print_it (print_it_normal)
4800 incref_bp_location (bl);
4801 **bs_link_pointer = this;
4802 *bs_link_pointer = &next;
4807 bp_location_at (NULL),
4808 breakpoint_at (NULL),
4813 print_it (print_it_normal)
4817 /* The target has stopped with waitstatus WS. Check if any hardware
4818 watchpoints have triggered, according to the target. */
4821 watchpoints_triggered (struct target_waitstatus *ws)
4823 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4825 struct breakpoint *b;
4827 if (!stopped_by_watchpoint)
4829 /* We were not stopped by a watchpoint. Mark all watchpoints
4830 as not triggered. */
4832 if (is_hardware_watchpoint (b))
4834 struct watchpoint *w = (struct watchpoint *) b;
4836 w->watchpoint_triggered = watch_triggered_no;
4842 if (!target_stopped_data_address (¤t_target, &addr))
4844 /* We were stopped by a watchpoint, but we don't know where.
4845 Mark all watchpoints as unknown. */
4847 if (is_hardware_watchpoint (b))
4849 struct watchpoint *w = (struct watchpoint *) b;
4851 w->watchpoint_triggered = watch_triggered_unknown;
4857 /* The target could report the data address. Mark watchpoints
4858 affected by this data address as triggered, and all others as not
4862 if (is_hardware_watchpoint (b))
4864 struct watchpoint *w = (struct watchpoint *) b;
4865 struct bp_location *loc;
4867 w->watchpoint_triggered = watch_triggered_no;
4868 for (loc = b->loc; loc; loc = loc->next)
4870 if (is_masked_watchpoint (b))
4872 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4873 CORE_ADDR start = loc->address & w->hw_wp_mask;
4875 if (newaddr == start)
4877 w->watchpoint_triggered = watch_triggered_yes;
4881 /* Exact match not required. Within range is sufficient. */
4882 else if (target_watchpoint_addr_within_range (¤t_target,
4886 w->watchpoint_triggered = watch_triggered_yes;
4895 /* Possible return values for watchpoint_check. */
4896 enum wp_check_result
4898 /* The watchpoint has been deleted. */
4901 /* The value has changed. */
4902 WP_VALUE_CHANGED = 2,
4904 /* The value has not changed. */
4905 WP_VALUE_NOT_CHANGED = 3,
4907 /* Ignore this watchpoint, no matter if the value changed or not. */
4911 #define BP_TEMPFLAG 1
4912 #define BP_HARDWAREFLAG 2
4914 /* Evaluate watchpoint condition expression and check if its value
4917 static wp_check_result
4918 watchpoint_check (bpstat bs)
4920 struct watchpoint *b;
4921 struct frame_info *fr;
4922 int within_current_scope;
4924 /* BS is built from an existing struct breakpoint. */
4925 gdb_assert (bs->breakpoint_at != NULL);
4926 b = (struct watchpoint *) bs->breakpoint_at;
4928 /* If this is a local watchpoint, we only want to check if the
4929 watchpoint frame is in scope if the current thread is the thread
4930 that was used to create the watchpoint. */
4931 if (!watchpoint_in_thread_scope (b))
4934 if (b->exp_valid_block == NULL)
4935 within_current_scope = 1;
4938 struct frame_info *frame = get_current_frame ();
4939 struct gdbarch *frame_arch = get_frame_arch (frame);
4940 CORE_ADDR frame_pc = get_frame_pc (frame);
4942 /* stack_frame_destroyed_p() returns a non-zero value if we're
4943 still in the function but the stack frame has already been
4944 invalidated. Since we can't rely on the values of local
4945 variables after the stack has been destroyed, we are treating
4946 the watchpoint in that state as `not changed' without further
4947 checking. Don't mark watchpoints as changed if the current
4948 frame is in an epilogue - even if they are in some other
4949 frame, our view of the stack is likely to be wrong and
4950 frame_find_by_id could error out. */
4951 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
4954 fr = frame_find_by_id (b->watchpoint_frame);
4955 within_current_scope = (fr != NULL);
4957 /* If we've gotten confused in the unwinder, we might have
4958 returned a frame that can't describe this variable. */
4959 if (within_current_scope)
4961 struct symbol *function;
4963 function = get_frame_function (fr);
4964 if (function == NULL
4965 || !contained_in (b->exp_valid_block,
4966 SYMBOL_BLOCK_VALUE (function)))
4967 within_current_scope = 0;
4970 if (within_current_scope)
4971 /* If we end up stopping, the current frame will get selected
4972 in normal_stop. So this call to select_frame won't affect
4977 if (within_current_scope)
4979 /* We use value_{,free_to_}mark because it could be a *long*
4980 time before we return to the command level and call
4981 free_all_values. We can't call free_all_values because we
4982 might be in the middle of evaluating a function call. */
4986 struct value *new_val;
4988 if (is_masked_watchpoint (b))
4989 /* Since we don't know the exact trigger address (from
4990 stopped_data_address), just tell the user we've triggered
4991 a mask watchpoint. */
4992 return WP_VALUE_CHANGED;
4994 mark = value_mark ();
4995 fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
4997 if (b->val_bitsize != 0)
4998 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5000 /* We use value_equal_contents instead of value_equal because
5001 the latter coerces an array to a pointer, thus comparing just
5002 the address of the array instead of its contents. This is
5003 not what we want. */
5004 if ((b->val != NULL) != (new_val != NULL)
5005 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5007 if (new_val != NULL)
5009 release_value (new_val);
5010 value_free_to_mark (mark);
5012 bs->old_val = b->val;
5015 return WP_VALUE_CHANGED;
5019 /* Nothing changed. */
5020 value_free_to_mark (mark);
5021 return WP_VALUE_NOT_CHANGED;
5026 /* This seems like the only logical thing to do because
5027 if we temporarily ignored the watchpoint, then when
5028 we reenter the block in which it is valid it contains
5029 garbage (in the case of a function, it may have two
5030 garbage values, one before and one after the prologue).
5031 So we can't even detect the first assignment to it and
5032 watch after that (since the garbage may or may not equal
5033 the first value assigned). */
5034 /* We print all the stop information in
5035 breakpoint_ops->print_it, but in this case, by the time we
5036 call breakpoint_ops->print_it this bp will be deleted
5037 already. So we have no choice but print the information
5040 SWITCH_THRU_ALL_UIS ()
5042 struct ui_out *uiout = current_uiout;
5044 if (uiout->is_mi_like_p ())
5046 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5047 uiout->text ("\nWatchpoint ");
5048 uiout->field_int ("wpnum", b->number);
5049 uiout->text (" deleted because the program has left the block in\n"
5050 "which its expression is valid.\n");
5053 /* Make sure the watchpoint's commands aren't executed. */
5055 watchpoint_del_at_next_stop (b);
5061 /* Return true if it looks like target has stopped due to hitting
5062 breakpoint location BL. This function does not check if we should
5063 stop, only if BL explains the stop. */
5066 bpstat_check_location (const struct bp_location *bl,
5067 const address_space *aspace, CORE_ADDR bp_addr,
5068 const struct target_waitstatus *ws)
5070 struct breakpoint *b = bl->owner;
5072 /* BL is from an existing breakpoint. */
5073 gdb_assert (b != NULL);
5075 return b->ops->breakpoint_hit (bl, const_cast<address_space *> (aspace),
5079 /* Determine if the watched values have actually changed, and we
5080 should stop. If not, set BS->stop to 0. */
5083 bpstat_check_watchpoint (bpstat bs)
5085 const struct bp_location *bl;
5086 struct watchpoint *b;
5088 /* BS is built for existing struct breakpoint. */
5089 bl = bs->bp_location_at;
5090 gdb_assert (bl != NULL);
5091 b = (struct watchpoint *) bs->breakpoint_at;
5092 gdb_assert (b != NULL);
5095 int must_check_value = 0;
5097 if (b->type == bp_watchpoint)
5098 /* For a software watchpoint, we must always check the
5100 must_check_value = 1;
5101 else if (b->watchpoint_triggered == watch_triggered_yes)
5102 /* We have a hardware watchpoint (read, write, or access)
5103 and the target earlier reported an address watched by
5105 must_check_value = 1;
5106 else if (b->watchpoint_triggered == watch_triggered_unknown
5107 && b->type == bp_hardware_watchpoint)
5108 /* We were stopped by a hardware watchpoint, but the target could
5109 not report the data address. We must check the watchpoint's
5110 value. Access and read watchpoints are out of luck; without
5111 a data address, we can't figure it out. */
5112 must_check_value = 1;
5114 if (must_check_value)
5120 e = watchpoint_check (bs);
5122 CATCH (ex, RETURN_MASK_ALL)
5124 exception_fprintf (gdb_stderr, ex,
5125 "Error evaluating expression "
5126 "for watchpoint %d\n",
5129 SWITCH_THRU_ALL_UIS ()
5131 printf_filtered (_("Watchpoint %d deleted.\n"),
5134 watchpoint_del_at_next_stop (b);
5142 /* We've already printed what needs to be printed. */
5143 bs->print_it = print_it_done;
5147 bs->print_it = print_it_noop;
5150 case WP_VALUE_CHANGED:
5151 if (b->type == bp_read_watchpoint)
5153 /* There are two cases to consider here:
5155 1. We're watching the triggered memory for reads.
5156 In that case, trust the target, and always report
5157 the watchpoint hit to the user. Even though
5158 reads don't cause value changes, the value may
5159 have changed since the last time it was read, and
5160 since we're not trapping writes, we will not see
5161 those, and as such we should ignore our notion of
5164 2. We're watching the triggered memory for both
5165 reads and writes. There are two ways this may
5168 2.1. This is a target that can't break on data
5169 reads only, but can break on accesses (reads or
5170 writes), such as e.g., x86. We detect this case
5171 at the time we try to insert read watchpoints.
5173 2.2. Otherwise, the target supports read
5174 watchpoints, but, the user set an access or write
5175 watchpoint watching the same memory as this read
5178 If we're watching memory writes as well as reads,
5179 ignore watchpoint hits when we find that the
5180 value hasn't changed, as reads don't cause
5181 changes. This still gives false positives when
5182 the program writes the same value to memory as
5183 what there was already in memory (we will confuse
5184 it for a read), but it's much better than
5187 int other_write_watchpoint = 0;
5189 if (bl->watchpoint_type == hw_read)
5191 struct breakpoint *other_b;
5193 ALL_BREAKPOINTS (other_b)
5194 if (other_b->type == bp_hardware_watchpoint
5195 || other_b->type == bp_access_watchpoint)
5197 struct watchpoint *other_w =
5198 (struct watchpoint *) other_b;
5200 if (other_w->watchpoint_triggered
5201 == watch_triggered_yes)
5203 other_write_watchpoint = 1;
5209 if (other_write_watchpoint
5210 || bl->watchpoint_type == hw_access)
5212 /* We're watching the same memory for writes,
5213 and the value changed since the last time we
5214 updated it, so this trap must be for a write.
5216 bs->print_it = print_it_noop;
5221 case WP_VALUE_NOT_CHANGED:
5222 if (b->type == bp_hardware_watchpoint
5223 || b->type == bp_watchpoint)
5225 /* Don't stop: write watchpoints shouldn't fire if
5226 the value hasn't changed. */
5227 bs->print_it = print_it_noop;
5237 else /* must_check_value == 0 */
5239 /* This is a case where some watchpoint(s) triggered, but
5240 not at the address of this watchpoint, or else no
5241 watchpoint triggered after all. So don't print
5242 anything for this watchpoint. */
5243 bs->print_it = print_it_noop;
5249 /* For breakpoints that are currently marked as telling gdb to stop,
5250 check conditions (condition proper, frame, thread and ignore count)
5251 of breakpoint referred to by BS. If we should not stop for this
5252 breakpoint, set BS->stop to 0. */
5255 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5257 const struct bp_location *bl;
5258 struct breakpoint *b;
5260 bool condition_result = true;
5261 struct expression *cond;
5263 gdb_assert (bs->stop);
5265 /* BS is built for existing struct breakpoint. */
5266 bl = bs->bp_location_at;
5267 gdb_assert (bl != NULL);
5268 b = bs->breakpoint_at;
5269 gdb_assert (b != NULL);
5271 /* Even if the target evaluated the condition on its end and notified GDB, we
5272 need to do so again since GDB does not know if we stopped due to a
5273 breakpoint or a single step breakpoint. */
5275 if (frame_id_p (b->frame_id)
5276 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5282 /* If this is a thread/task-specific breakpoint, don't waste cpu
5283 evaluating the condition if this isn't the specified
5285 if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
5286 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5293 /* Evaluate extension language breakpoints that have a "stop" method
5295 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5297 if (is_watchpoint (b))
5299 struct watchpoint *w = (struct watchpoint *) b;
5301 cond = w->cond_exp.get ();
5304 cond = bl->cond.get ();
5306 if (cond && b->disposition != disp_del_at_next_stop)
5308 int within_current_scope = 1;
5309 struct watchpoint * w;
5311 /* We use value_mark and value_free_to_mark because it could
5312 be a long time before we return to the command level and
5313 call free_all_values. We can't call free_all_values
5314 because we might be in the middle of evaluating a
5316 struct value *mark = value_mark ();
5318 if (is_watchpoint (b))
5319 w = (struct watchpoint *) b;
5323 /* Need to select the frame, with all that implies so that
5324 the conditions will have the right context. Because we
5325 use the frame, we will not see an inlined function's
5326 variables when we arrive at a breakpoint at the start
5327 of the inlined function; the current frame will be the
5329 if (w == NULL || w->cond_exp_valid_block == NULL)
5330 select_frame (get_current_frame ());
5333 struct frame_info *frame;
5335 /* For local watchpoint expressions, which particular
5336 instance of a local is being watched matters, so we
5337 keep track of the frame to evaluate the expression
5338 in. To evaluate the condition however, it doesn't
5339 really matter which instantiation of the function
5340 where the condition makes sense triggers the
5341 watchpoint. This allows an expression like "watch
5342 global if q > 10" set in `func', catch writes to
5343 global on all threads that call `func', or catch
5344 writes on all recursive calls of `func' by a single
5345 thread. We simply always evaluate the condition in
5346 the innermost frame that's executing where it makes
5347 sense to evaluate the condition. It seems
5349 frame = block_innermost_frame (w->cond_exp_valid_block);
5351 select_frame (frame);
5353 within_current_scope = 0;
5355 if (within_current_scope)
5359 condition_result = breakpoint_cond_eval (cond);
5361 CATCH (ex, RETURN_MASK_ALL)
5363 exception_fprintf (gdb_stderr, ex,
5364 "Error in testing breakpoint condition:\n");
5370 warning (_("Watchpoint condition cannot be tested "
5371 "in the current scope"));
5372 /* If we failed to set the right context for this
5373 watchpoint, unconditionally report it. */
5375 /* FIXME-someday, should give breakpoint #. */
5376 value_free_to_mark (mark);
5379 if (cond && !condition_result)
5383 else if (b->ignore_count > 0)
5387 /* Increase the hit count even though we don't stop. */
5389 observer_notify_breakpoint_modified (b);
5393 /* Returns true if we need to track moribund locations of LOC's type
5394 on the current target. */
5397 need_moribund_for_location_type (struct bp_location *loc)
5399 return ((loc->loc_type == bp_loc_software_breakpoint
5400 && !target_supports_stopped_by_sw_breakpoint ())
5401 || (loc->loc_type == bp_loc_hardware_breakpoint
5402 && !target_supports_stopped_by_hw_breakpoint ()));
5406 /* Get a bpstat associated with having just stopped at address
5407 BP_ADDR in thread PTID.
5409 Determine whether we stopped at a breakpoint, etc, or whether we
5410 don't understand this stop. Result is a chain of bpstat's such
5413 if we don't understand the stop, the result is a null pointer.
5415 if we understand why we stopped, the result is not null.
5417 Each element of the chain refers to a particular breakpoint or
5418 watchpoint at which we have stopped. (We may have stopped for
5419 several reasons concurrently.)
5421 Each element of the chain has valid next, breakpoint_at,
5422 commands, FIXME??? fields. */
5425 bpstat_stop_status (const address_space *aspace,
5426 CORE_ADDR bp_addr, ptid_t ptid,
5427 const struct target_waitstatus *ws)
5429 struct breakpoint *b = NULL;
5430 struct bp_location *bl;
5431 struct bp_location *loc;
5432 /* First item of allocated bpstat's. */
5433 bpstat bs_head = NULL, *bs_link = &bs_head;
5434 /* Pointer to the last thing in the chain currently. */
5437 int need_remove_insert;
5440 /* First, build the bpstat chain with locations that explain a
5441 target stop, while being careful to not set the target running,
5442 as that may invalidate locations (in particular watchpoint
5443 locations are recreated). Resuming will happen here with
5444 breakpoint conditions or watchpoint expressions that include
5445 inferior function calls. */
5449 if (!breakpoint_enabled (b))
5452 for (bl = b->loc; bl != NULL; bl = bl->next)
5454 /* For hardware watchpoints, we look only at the first
5455 location. The watchpoint_check function will work on the
5456 entire expression, not the individual locations. For
5457 read watchpoints, the watchpoints_triggered function has
5458 checked all locations already. */
5459 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5462 if (!bl->enabled || bl->shlib_disabled)
5465 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5468 /* Come here if it's a watchpoint, or if the break address
5471 bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to
5474 /* Assume we stop. Should we find a watchpoint that is not
5475 actually triggered, or if the condition of the breakpoint
5476 evaluates as false, we'll reset 'stop' to 0. */
5480 /* If this is a scope breakpoint, mark the associated
5481 watchpoint as triggered so that we will handle the
5482 out-of-scope event. We'll get to the watchpoint next
5484 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5486 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5488 w->watchpoint_triggered = watch_triggered_yes;
5493 /* Check if a moribund breakpoint explains the stop. */
5494 if (!target_supports_stopped_by_sw_breakpoint ()
5495 || !target_supports_stopped_by_hw_breakpoint ())
5497 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5499 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5500 && need_moribund_for_location_type (loc))
5502 bs = new bpstats (loc, &bs_link);
5503 /* For hits of moribund locations, we should just proceed. */
5506 bs->print_it = print_it_noop;
5511 /* A bit of special processing for shlib breakpoints. We need to
5512 process solib loading here, so that the lists of loaded and
5513 unloaded libraries are correct before we handle "catch load" and
5515 for (bs = bs_head; bs != NULL; bs = bs->next)
5517 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5519 handle_solib_event ();
5524 /* Now go through the locations that caused the target to stop, and
5525 check whether we're interested in reporting this stop to higher
5526 layers, or whether we should resume the target transparently. */
5530 for (bs = bs_head; bs != NULL; bs = bs->next)
5535 b = bs->breakpoint_at;
5536 b->ops->check_status (bs);
5539 bpstat_check_breakpoint_conditions (bs, ptid);
5544 observer_notify_breakpoint_modified (b);
5546 /* We will stop here. */
5547 if (b->disposition == disp_disable)
5549 --(b->enable_count);
5550 if (b->enable_count <= 0)
5551 b->enable_state = bp_disabled;
5556 bs->commands = b->commands;
5557 if (command_line_is_silent (bs->commands
5558 ? bs->commands.get () : NULL))
5561 b->ops->after_condition_true (bs);
5566 /* Print nothing for this entry if we don't stop or don't
5568 if (!bs->stop || !bs->print)
5569 bs->print_it = print_it_noop;
5572 /* If we aren't stopping, the value of some hardware watchpoint may
5573 not have changed, but the intermediate memory locations we are
5574 watching may have. Don't bother if we're stopping; this will get
5576 need_remove_insert = 0;
5577 if (! bpstat_causes_stop (bs_head))
5578 for (bs = bs_head; bs != NULL; bs = bs->next)
5580 && bs->breakpoint_at
5581 && is_hardware_watchpoint (bs->breakpoint_at))
5583 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5585 update_watchpoint (w, 0 /* don't reparse. */);
5586 need_remove_insert = 1;
5589 if (need_remove_insert)
5590 update_global_location_list (UGLL_MAY_INSERT);
5591 else if (removed_any)
5592 update_global_location_list (UGLL_DONT_INSERT);
5598 handle_jit_event (void)
5600 struct frame_info *frame;
5601 struct gdbarch *gdbarch;
5604 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5606 /* Switch terminal for any messages produced by
5607 breakpoint_re_set. */
5608 target_terminal::ours_for_output ();
5610 frame = get_current_frame ();
5611 gdbarch = get_frame_arch (frame);
5613 jit_event_handler (gdbarch);
5615 target_terminal::inferior ();
5618 /* Prepare WHAT final decision for infrun. */
5620 /* Decide what infrun needs to do with this bpstat. */
5623 bpstat_what (bpstat bs_head)
5625 struct bpstat_what retval;
5628 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5629 retval.call_dummy = STOP_NONE;
5630 retval.is_longjmp = 0;
5632 for (bs = bs_head; bs != NULL; bs = bs->next)
5634 /* Extract this BS's action. After processing each BS, we check
5635 if its action overrides all we've seem so far. */
5636 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5639 if (bs->breakpoint_at == NULL)
5641 /* I suspect this can happen if it was a momentary
5642 breakpoint which has since been deleted. */
5646 bptype = bs->breakpoint_at->type;
5653 case bp_hardware_breakpoint:
5654 case bp_single_step:
5657 case bp_shlib_event:
5661 this_action = BPSTAT_WHAT_STOP_NOISY;
5663 this_action = BPSTAT_WHAT_STOP_SILENT;
5666 this_action = BPSTAT_WHAT_SINGLE;
5669 case bp_hardware_watchpoint:
5670 case bp_read_watchpoint:
5671 case bp_access_watchpoint:
5675 this_action = BPSTAT_WHAT_STOP_NOISY;
5677 this_action = BPSTAT_WHAT_STOP_SILENT;
5681 /* There was a watchpoint, but we're not stopping.
5682 This requires no further action. */
5686 case bp_longjmp_call_dummy:
5690 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5691 retval.is_longjmp = bptype != bp_exception;
5694 this_action = BPSTAT_WHAT_SINGLE;
5696 case bp_longjmp_resume:
5697 case bp_exception_resume:
5700 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5701 retval.is_longjmp = bptype == bp_longjmp_resume;
5704 this_action = BPSTAT_WHAT_SINGLE;
5706 case bp_step_resume:
5708 this_action = BPSTAT_WHAT_STEP_RESUME;
5711 /* It is for the wrong frame. */
5712 this_action = BPSTAT_WHAT_SINGLE;
5715 case bp_hp_step_resume:
5717 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5720 /* It is for the wrong frame. */
5721 this_action = BPSTAT_WHAT_SINGLE;
5724 case bp_watchpoint_scope:
5725 case bp_thread_event:
5726 case bp_overlay_event:
5727 case bp_longjmp_master:
5728 case bp_std_terminate_master:
5729 case bp_exception_master:
5730 this_action = BPSTAT_WHAT_SINGLE;
5736 this_action = BPSTAT_WHAT_STOP_NOISY;
5738 this_action = BPSTAT_WHAT_STOP_SILENT;
5742 /* There was a catchpoint, but we're not stopping.
5743 This requires no further action. */
5747 this_action = BPSTAT_WHAT_SINGLE;
5750 /* Make sure the action is stop (silent or noisy),
5751 so infrun.c pops the dummy frame. */
5752 retval.call_dummy = STOP_STACK_DUMMY;
5753 this_action = BPSTAT_WHAT_STOP_SILENT;
5755 case bp_std_terminate:
5756 /* Make sure the action is stop (silent or noisy),
5757 so infrun.c pops the dummy frame. */
5758 retval.call_dummy = STOP_STD_TERMINATE;
5759 this_action = BPSTAT_WHAT_STOP_SILENT;
5762 case bp_fast_tracepoint:
5763 case bp_static_tracepoint:
5764 /* Tracepoint hits should not be reported back to GDB, and
5765 if one got through somehow, it should have been filtered
5767 internal_error (__FILE__, __LINE__,
5768 _("bpstat_what: tracepoint encountered"));
5770 case bp_gnu_ifunc_resolver:
5771 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5772 this_action = BPSTAT_WHAT_SINGLE;
5774 case bp_gnu_ifunc_resolver_return:
5775 /* The breakpoint will be removed, execution will restart from the
5776 PC of the former breakpoint. */
5777 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5782 this_action = BPSTAT_WHAT_STOP_SILENT;
5784 this_action = BPSTAT_WHAT_SINGLE;
5788 internal_error (__FILE__, __LINE__,
5789 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5792 retval.main_action = std::max (retval.main_action, this_action);
5799 bpstat_run_callbacks (bpstat bs_head)
5803 for (bs = bs_head; bs != NULL; bs = bs->next)
5805 struct breakpoint *b = bs->breakpoint_at;
5812 handle_jit_event ();
5814 case bp_gnu_ifunc_resolver:
5815 gnu_ifunc_resolver_stop (b);
5817 case bp_gnu_ifunc_resolver_return:
5818 gnu_ifunc_resolver_return_stop (b);
5824 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5825 without hardware support). This isn't related to a specific bpstat,
5826 just to things like whether watchpoints are set. */
5829 bpstat_should_step (void)
5831 struct breakpoint *b;
5834 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5840 bpstat_causes_stop (bpstat bs)
5842 for (; bs != NULL; bs = bs->next)
5851 /* Compute a string of spaces suitable to indent the next line
5852 so it starts at the position corresponding to the table column
5853 named COL_NAME in the currently active table of UIOUT. */
5856 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5858 static char wrap_indent[80];
5859 int i, total_width, width, align;
5863 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
5865 if (strcmp (text, col_name) == 0)
5867 gdb_assert (total_width < sizeof wrap_indent);
5868 memset (wrap_indent, ' ', total_width);
5869 wrap_indent[total_width] = 0;
5874 total_width += width + 1;
5880 /* Determine if the locations of this breakpoint will have their conditions
5881 evaluated by the target, host or a mix of both. Returns the following:
5883 "host": Host evals condition.
5884 "host or target": Host or Target evals condition.
5885 "target": Target evals condition.
5889 bp_condition_evaluator (struct breakpoint *b)
5891 struct bp_location *bl;
5892 char host_evals = 0;
5893 char target_evals = 0;
5898 if (!is_breakpoint (b))
5901 if (gdb_evaluates_breakpoint_condition_p ()
5902 || !target_supports_evaluation_of_breakpoint_conditions ())
5903 return condition_evaluation_host;
5905 for (bl = b->loc; bl; bl = bl->next)
5907 if (bl->cond_bytecode)
5913 if (host_evals && target_evals)
5914 return condition_evaluation_both;
5915 else if (target_evals)
5916 return condition_evaluation_target;
5918 return condition_evaluation_host;
5921 /* Determine the breakpoint location's condition evaluator. This is
5922 similar to bp_condition_evaluator, but for locations. */
5925 bp_location_condition_evaluator (struct bp_location *bl)
5927 if (bl && !is_breakpoint (bl->owner))
5930 if (gdb_evaluates_breakpoint_condition_p ()
5931 || !target_supports_evaluation_of_breakpoint_conditions ())
5932 return condition_evaluation_host;
5934 if (bl && bl->cond_bytecode)
5935 return condition_evaluation_target;
5937 return condition_evaluation_host;
5940 /* Print the LOC location out of the list of B->LOC locations. */
5943 print_breakpoint_location (struct breakpoint *b,
5944 struct bp_location *loc)
5946 struct ui_out *uiout = current_uiout;
5948 scoped_restore_current_program_space restore_pspace;
5950 if (loc != NULL && loc->shlib_disabled)
5954 set_current_program_space (loc->pspace);
5956 if (b->display_canonical)
5957 uiout->field_string ("what", event_location_to_string (b->location.get ()));
5958 else if (loc && loc->symtab)
5961 = find_pc_sect_function (loc->address, loc->section);
5964 uiout->text ("in ");
5965 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
5967 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
5968 uiout->text ("at ");
5970 uiout->field_string ("file",
5971 symtab_to_filename_for_display (loc->symtab));
5974 if (uiout->is_mi_like_p ())
5975 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
5977 uiout->field_int ("line", loc->line_number);
5983 print_address_symbolic (loc->gdbarch, loc->address, &stb,
5985 uiout->field_stream ("at", stb);
5989 uiout->field_string ("pending",
5990 event_location_to_string (b->location.get ()));
5991 /* If extra_string is available, it could be holding a condition
5992 or dprintf arguments. In either case, make sure it is printed,
5993 too, but only for non-MI streams. */
5994 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
5996 if (b->type == bp_dprintf)
6000 uiout->text (b->extra_string);
6004 if (loc && is_breakpoint (b)
6005 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6006 && bp_condition_evaluator (b) == condition_evaluation_both)
6009 uiout->field_string ("evaluated-by",
6010 bp_location_condition_evaluator (loc));
6016 bptype_string (enum bptype type)
6018 struct ep_type_description
6021 const char *description;
6023 static struct ep_type_description bptypes[] =
6025 {bp_none, "?deleted?"},
6026 {bp_breakpoint, "breakpoint"},
6027 {bp_hardware_breakpoint, "hw breakpoint"},
6028 {bp_single_step, "sw single-step"},
6029 {bp_until, "until"},
6030 {bp_finish, "finish"},
6031 {bp_watchpoint, "watchpoint"},
6032 {bp_hardware_watchpoint, "hw watchpoint"},
6033 {bp_read_watchpoint, "read watchpoint"},
6034 {bp_access_watchpoint, "acc watchpoint"},
6035 {bp_longjmp, "longjmp"},
6036 {bp_longjmp_resume, "longjmp resume"},
6037 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6038 {bp_exception, "exception"},
6039 {bp_exception_resume, "exception resume"},
6040 {bp_step_resume, "step resume"},
6041 {bp_hp_step_resume, "high-priority step resume"},
6042 {bp_watchpoint_scope, "watchpoint scope"},
6043 {bp_call_dummy, "call dummy"},
6044 {bp_std_terminate, "std::terminate"},
6045 {bp_shlib_event, "shlib events"},
6046 {bp_thread_event, "thread events"},
6047 {bp_overlay_event, "overlay events"},
6048 {bp_longjmp_master, "longjmp master"},
6049 {bp_std_terminate_master, "std::terminate master"},
6050 {bp_exception_master, "exception master"},
6051 {bp_catchpoint, "catchpoint"},
6052 {bp_tracepoint, "tracepoint"},
6053 {bp_fast_tracepoint, "fast tracepoint"},
6054 {bp_static_tracepoint, "static tracepoint"},
6055 {bp_dprintf, "dprintf"},
6056 {bp_jit_event, "jit events"},
6057 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6058 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6061 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6062 || ((int) type != bptypes[(int) type].type))
6063 internal_error (__FILE__, __LINE__,
6064 _("bptypes table does not describe type #%d."),
6067 return bptypes[(int) type].description;
6070 /* For MI, output a field named 'thread-groups' with a list as the value.
6071 For CLI, prefix the list with the string 'inf'. */
6074 output_thread_groups (struct ui_out *uiout,
6075 const char *field_name,
6079 int is_mi = uiout->is_mi_like_p ();
6083 /* For backward compatibility, don't display inferiors in CLI unless
6084 there are several. Always display them for MI. */
6085 if (!is_mi && mi_only)
6088 ui_out_emit_list list_emitter (uiout, field_name);
6090 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6096 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6097 uiout->field_string (NULL, mi_group);
6102 uiout->text (" inf ");
6106 uiout->text (plongest (inf));
6111 /* Print B to gdb_stdout. */
6114 print_one_breakpoint_location (struct breakpoint *b,
6115 struct bp_location *loc,
6117 struct bp_location **last_loc,
6120 struct command_line *l;
6121 static char bpenables[] = "nynny";
6123 struct ui_out *uiout = current_uiout;
6124 int header_of_multiple = 0;
6125 int part_of_multiple = (loc != NULL);
6126 struct value_print_options opts;
6128 get_user_print_options (&opts);
6130 gdb_assert (!loc || loc_number != 0);
6131 /* See comment in print_one_breakpoint concerning treatment of
6132 breakpoints with single disabled location. */
6135 && (b->loc->next != NULL || !b->loc->enabled)))
6136 header_of_multiple = 1;
6144 if (part_of_multiple)
6147 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6148 uiout->field_string ("number", formatted);
6153 uiout->field_int ("number", b->number);
6158 if (part_of_multiple)
6159 uiout->field_skip ("type");
6161 uiout->field_string ("type", bptype_string (b->type));
6165 if (part_of_multiple)
6166 uiout->field_skip ("disp");
6168 uiout->field_string ("disp", bpdisp_text (b->disposition));
6173 if (part_of_multiple)
6174 uiout->field_string ("enabled", loc->enabled ? "y" : "n");
6176 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6181 if (b->ops != NULL && b->ops->print_one != NULL)
6183 /* Although the print_one can possibly print all locations,
6184 calling it here is not likely to get any nice result. So,
6185 make sure there's just one location. */
6186 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6187 b->ops->print_one (b, last_loc);
6193 internal_error (__FILE__, __LINE__,
6194 _("print_one_breakpoint: bp_none encountered\n"));
6198 case bp_hardware_watchpoint:
6199 case bp_read_watchpoint:
6200 case bp_access_watchpoint:
6202 struct watchpoint *w = (struct watchpoint *) b;
6204 /* Field 4, the address, is omitted (which makes the columns
6205 not line up too nicely with the headers, but the effect
6206 is relatively readable). */
6207 if (opts.addressprint)
6208 uiout->field_skip ("addr");
6210 uiout->field_string ("what", w->exp_string);
6215 case bp_hardware_breakpoint:
6216 case bp_single_step:
6220 case bp_longjmp_resume:
6221 case bp_longjmp_call_dummy:
6223 case bp_exception_resume:
6224 case bp_step_resume:
6225 case bp_hp_step_resume:
6226 case bp_watchpoint_scope:
6228 case bp_std_terminate:
6229 case bp_shlib_event:
6230 case bp_thread_event:
6231 case bp_overlay_event:
6232 case bp_longjmp_master:
6233 case bp_std_terminate_master:
6234 case bp_exception_master:
6236 case bp_fast_tracepoint:
6237 case bp_static_tracepoint:
6240 case bp_gnu_ifunc_resolver:
6241 case bp_gnu_ifunc_resolver_return:
6242 if (opts.addressprint)
6245 if (header_of_multiple)
6246 uiout->field_string ("addr", "<MULTIPLE>");
6247 else if (b->loc == NULL || loc->shlib_disabled)
6248 uiout->field_string ("addr", "<PENDING>");
6250 uiout->field_core_addr ("addr",
6251 loc->gdbarch, loc->address);
6254 if (!header_of_multiple)
6255 print_breakpoint_location (b, loc);
6262 if (loc != NULL && !header_of_multiple)
6264 struct inferior *inf;
6265 VEC(int) *inf_num = NULL;
6270 if (inf->pspace == loc->pspace)
6271 VEC_safe_push (int, inf_num, inf->num);
6274 /* For backward compatibility, don't display inferiors in CLI unless
6275 there are several. Always display for MI. */
6277 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6278 && (number_of_program_spaces () > 1
6279 || number_of_inferiors () > 1)
6280 /* LOC is for existing B, it cannot be in
6281 moribund_locations and thus having NULL OWNER. */
6282 && loc->owner->type != bp_catchpoint))
6284 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6285 VEC_free (int, inf_num);
6288 if (!part_of_multiple)
6290 if (b->thread != -1)
6292 /* FIXME: This seems to be redundant and lost here; see the
6293 "stop only in" line a little further down. */
6294 uiout->text (" thread ");
6295 uiout->field_int ("thread", b->thread);
6297 else if (b->task != 0)
6299 uiout->text (" task ");
6300 uiout->field_int ("task", b->task);
6306 if (!part_of_multiple)
6307 b->ops->print_one_detail (b, uiout);
6309 if (part_of_multiple && frame_id_p (b->frame_id))
6312 uiout->text ("\tstop only in stack frame at ");
6313 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6315 uiout->field_core_addr ("frame",
6316 b->gdbarch, b->frame_id.stack_addr);
6320 if (!part_of_multiple && b->cond_string)
6323 if (is_tracepoint (b))
6324 uiout->text ("\ttrace only if ");
6326 uiout->text ("\tstop only if ");
6327 uiout->field_string ("cond", b->cond_string);
6329 /* Print whether the target is doing the breakpoint's condition
6330 evaluation. If GDB is doing the evaluation, don't print anything. */
6331 if (is_breakpoint (b)
6332 && breakpoint_condition_evaluation_mode ()
6333 == condition_evaluation_target)
6336 uiout->field_string ("evaluated-by",
6337 bp_condition_evaluator (b));
6338 uiout->text (" evals)");
6343 if (!part_of_multiple && b->thread != -1)
6345 /* FIXME should make an annotation for this. */
6346 uiout->text ("\tstop only in thread ");
6347 if (uiout->is_mi_like_p ())
6348 uiout->field_int ("thread", b->thread);
6351 struct thread_info *thr = find_thread_global_id (b->thread);
6353 uiout->field_string ("thread", print_thread_id (thr));
6358 if (!part_of_multiple)
6362 /* FIXME should make an annotation for this. */
6363 if (is_catchpoint (b))
6364 uiout->text ("\tcatchpoint");
6365 else if (is_tracepoint (b))
6366 uiout->text ("\ttracepoint");
6368 uiout->text ("\tbreakpoint");
6369 uiout->text (" already hit ");
6370 uiout->field_int ("times", b->hit_count);
6371 if (b->hit_count == 1)
6372 uiout->text (" time\n");
6374 uiout->text (" times\n");
6378 /* Output the count also if it is zero, but only if this is mi. */
6379 if (uiout->is_mi_like_p ())
6380 uiout->field_int ("times", b->hit_count);
6384 if (!part_of_multiple && b->ignore_count)
6387 uiout->text ("\tignore next ");
6388 uiout->field_int ("ignore", b->ignore_count);
6389 uiout->text (" hits\n");
6392 /* Note that an enable count of 1 corresponds to "enable once"
6393 behavior, which is reported by the combination of enablement and
6394 disposition, so we don't need to mention it here. */
6395 if (!part_of_multiple && b->enable_count > 1)
6398 uiout->text ("\tdisable after ");
6399 /* Tweak the wording to clarify that ignore and enable counts
6400 are distinct, and have additive effect. */
6401 if (b->ignore_count)
6402 uiout->text ("additional ");
6404 uiout->text ("next ");
6405 uiout->field_int ("enable", b->enable_count);
6406 uiout->text (" hits\n");
6409 if (!part_of_multiple && is_tracepoint (b))
6411 struct tracepoint *tp = (struct tracepoint *) b;
6413 if (tp->traceframe_usage)
6415 uiout->text ("\ttrace buffer usage ");
6416 uiout->field_int ("traceframe-usage", tp->traceframe_usage);
6417 uiout->text (" bytes\n");
6421 l = b->commands ? b->commands.get () : NULL;
6422 if (!part_of_multiple && l)
6425 ui_out_emit_tuple tuple_emitter (uiout, "script");
6426 print_command_lines (uiout, l, 4);
6429 if (is_tracepoint (b))
6431 struct tracepoint *t = (struct tracepoint *) b;
6433 if (!part_of_multiple && t->pass_count)
6435 annotate_field (10);
6436 uiout->text ("\tpass count ");
6437 uiout->field_int ("pass", t->pass_count);
6438 uiout->text (" \n");
6441 /* Don't display it when tracepoint or tracepoint location is
6443 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6445 annotate_field (11);
6447 if (uiout->is_mi_like_p ())
6448 uiout->field_string ("installed",
6449 loc->inserted ? "y" : "n");
6455 uiout->text ("\tnot ");
6456 uiout->text ("installed on target\n");
6461 if (uiout->is_mi_like_p () && !part_of_multiple)
6463 if (is_watchpoint (b))
6465 struct watchpoint *w = (struct watchpoint *) b;
6467 uiout->field_string ("original-location", w->exp_string);
6469 else if (b->location != NULL
6470 && event_location_to_string (b->location.get ()) != NULL)
6471 uiout->field_string ("original-location",
6472 event_location_to_string (b->location.get ()));
6477 print_one_breakpoint (struct breakpoint *b,
6478 struct bp_location **last_loc,
6481 struct ui_out *uiout = current_uiout;
6484 ui_out_emit_tuple tuple_emitter (uiout, "bkpt");
6486 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6489 /* If this breakpoint has custom print function,
6490 it's already printed. Otherwise, print individual
6491 locations, if any. */
6492 if (b->ops == NULL || b->ops->print_one == NULL)
6494 /* If breakpoint has a single location that is disabled, we
6495 print it as if it had several locations, since otherwise it's
6496 hard to represent "breakpoint enabled, location disabled"
6499 Note that while hardware watchpoints have several locations
6500 internally, that's not a property exposed to user. */
6502 && !is_hardware_watchpoint (b)
6503 && (b->loc->next || !b->loc->enabled))
6505 struct bp_location *loc;
6508 for (loc = b->loc; loc; loc = loc->next, ++n)
6510 ui_out_emit_tuple tuple_emitter (uiout, NULL);
6511 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6518 breakpoint_address_bits (struct breakpoint *b)
6520 int print_address_bits = 0;
6521 struct bp_location *loc;
6523 /* Software watchpoints that aren't watching memory don't have an
6524 address to print. */
6525 if (is_no_memory_software_watchpoint (b))
6528 for (loc = b->loc; loc; loc = loc->next)
6532 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6533 if (addr_bit > print_address_bits)
6534 print_address_bits = addr_bit;
6537 return print_address_bits;
6540 /* See breakpoint.h. */
6543 print_breakpoint (breakpoint *b)
6545 struct bp_location *dummy_loc = NULL;
6546 print_one_breakpoint (b, &dummy_loc, 0);
6549 /* Return true if this breakpoint was set by the user, false if it is
6550 internal or momentary. */
6553 user_breakpoint_p (struct breakpoint *b)
6555 return b->number > 0;
6558 /* See breakpoint.h. */
6561 pending_breakpoint_p (struct breakpoint *b)
6563 return b->loc == NULL;
6566 /* Print information on user settable breakpoint (watchpoint, etc)
6567 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6568 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6569 FILTER is non-NULL, call it on each breakpoint and only include the
6570 ones for which it returns non-zero. Return the total number of
6571 breakpoints listed. */
6574 breakpoint_1 (const char *args, int allflag,
6575 int (*filter) (const struct breakpoint *))
6577 struct breakpoint *b;
6578 struct bp_location *last_loc = NULL;
6579 int nr_printable_breakpoints;
6580 struct value_print_options opts;
6581 int print_address_bits = 0;
6582 int print_type_col_width = 14;
6583 struct ui_out *uiout = current_uiout;
6585 get_user_print_options (&opts);
6587 /* Compute the number of rows in the table, as well as the size
6588 required for address fields. */
6589 nr_printable_breakpoints = 0;
6592 /* If we have a filter, only list the breakpoints it accepts. */
6593 if (filter && !filter (b))
6596 /* If we have an "args" string, it is a list of breakpoints to
6597 accept. Skip the others. */
6598 if (args != NULL && *args != '\0')
6600 if (allflag && parse_and_eval_long (args) != b->number)
6602 if (!allflag && !number_is_in_list (args, b->number))
6606 if (allflag || user_breakpoint_p (b))
6608 int addr_bit, type_len;
6610 addr_bit = breakpoint_address_bits (b);
6611 if (addr_bit > print_address_bits)
6612 print_address_bits = addr_bit;
6614 type_len = strlen (bptype_string (b->type));
6615 if (type_len > print_type_col_width)
6616 print_type_col_width = type_len;
6618 nr_printable_breakpoints++;
6623 ui_out_emit_table table_emitter (uiout,
6624 opts.addressprint ? 6 : 5,
6625 nr_printable_breakpoints,
6628 if (nr_printable_breakpoints > 0)
6629 annotate_breakpoints_headers ();
6630 if (nr_printable_breakpoints > 0)
6632 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
6633 if (nr_printable_breakpoints > 0)
6635 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
6636 if (nr_printable_breakpoints > 0)
6638 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
6639 if (nr_printable_breakpoints > 0)
6641 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
6642 if (opts.addressprint)
6644 if (nr_printable_breakpoints > 0)
6646 if (print_address_bits <= 32)
6647 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
6649 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
6651 if (nr_printable_breakpoints > 0)
6653 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
6654 uiout->table_body ();
6655 if (nr_printable_breakpoints > 0)
6656 annotate_breakpoints_table ();
6661 /* If we have a filter, only list the breakpoints it accepts. */
6662 if (filter && !filter (b))
6665 /* If we have an "args" string, it is a list of breakpoints to
6666 accept. Skip the others. */
6668 if (args != NULL && *args != '\0')
6670 if (allflag) /* maintenance info breakpoint */
6672 if (parse_and_eval_long (args) != b->number)
6675 else /* all others */
6677 if (!number_is_in_list (args, b->number))
6681 /* We only print out user settable breakpoints unless the
6683 if (allflag || user_breakpoint_p (b))
6684 print_one_breakpoint (b, &last_loc, allflag);
6688 if (nr_printable_breakpoints == 0)
6690 /* If there's a filter, let the caller decide how to report
6694 if (args == NULL || *args == '\0')
6695 uiout->message ("No breakpoints or watchpoints.\n");
6697 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
6703 if (last_loc && !server_command)
6704 set_next_address (last_loc->gdbarch, last_loc->address);
6707 /* FIXME? Should this be moved up so that it is only called when
6708 there have been breakpoints? */
6709 annotate_breakpoints_table_end ();
6711 return nr_printable_breakpoints;
6714 /* Display the value of default-collect in a way that is generally
6715 compatible with the breakpoint list. */
6718 default_collect_info (void)
6720 struct ui_out *uiout = current_uiout;
6722 /* If it has no value (which is frequently the case), say nothing; a
6723 message like "No default-collect." gets in user's face when it's
6725 if (!*default_collect)
6728 /* The following phrase lines up nicely with per-tracepoint collect
6730 uiout->text ("default collect ");
6731 uiout->field_string ("default-collect", default_collect);
6732 uiout->text (" \n");
6736 info_breakpoints_command (char *args, int from_tty)
6738 breakpoint_1 (args, 0, NULL);
6740 default_collect_info ();
6744 info_watchpoints_command (char *args, int from_tty)
6746 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6747 struct ui_out *uiout = current_uiout;
6749 if (num_printed == 0)
6751 if (args == NULL || *args == '\0')
6752 uiout->message ("No watchpoints.\n");
6754 uiout->message ("No watchpoint matching '%s'.\n", args);
6759 maintenance_info_breakpoints (const char *args, int from_tty)
6761 breakpoint_1 (args, 1, NULL);
6763 default_collect_info ();
6767 breakpoint_has_pc (struct breakpoint *b,
6768 struct program_space *pspace,
6769 CORE_ADDR pc, struct obj_section *section)
6771 struct bp_location *bl = b->loc;
6773 for (; bl; bl = bl->next)
6775 if (bl->pspace == pspace
6776 && bl->address == pc
6777 && (!overlay_debugging || bl->section == section))
6783 /* Print a message describing any user-breakpoints set at PC. This
6784 concerns with logical breakpoints, so we match program spaces, not
6788 describe_other_breakpoints (struct gdbarch *gdbarch,
6789 struct program_space *pspace, CORE_ADDR pc,
6790 struct obj_section *section, int thread)
6793 struct breakpoint *b;
6796 others += (user_breakpoint_p (b)
6797 && breakpoint_has_pc (b, pspace, pc, section));
6801 printf_filtered (_("Note: breakpoint "));
6802 else /* if (others == ???) */
6803 printf_filtered (_("Note: breakpoints "));
6805 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6808 printf_filtered ("%d", b->number);
6809 if (b->thread == -1 && thread != -1)
6810 printf_filtered (" (all threads)");
6811 else if (b->thread != -1)
6812 printf_filtered (" (thread %d)", b->thread);
6813 printf_filtered ("%s%s ",
6814 ((b->enable_state == bp_disabled
6815 || b->enable_state == bp_call_disabled)
6819 : ((others == 1) ? " and" : ""));
6821 printf_filtered (_("also set at pc "));
6822 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6823 printf_filtered (".\n");
6828 /* Return true iff it is meaningful to use the address member of
6829 BPT locations. For some breakpoint types, the locations' address members
6830 are irrelevant and it makes no sense to attempt to compare them to other
6831 addresses (or use them for any other purpose either).
6833 More specifically, each of the following breakpoint types will
6834 always have a zero valued location address and we don't want to mark
6835 breakpoints of any of these types to be a duplicate of an actual
6836 breakpoint location at address zero:
6844 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6846 enum bptype type = bpt->type;
6848 return (type != bp_watchpoint && type != bp_catchpoint);
6851 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6852 true if LOC1 and LOC2 represent the same watchpoint location. */
6855 watchpoint_locations_match (struct bp_location *loc1,
6856 struct bp_location *loc2)
6858 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6859 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6861 /* Both of them must exist. */
6862 gdb_assert (w1 != NULL);
6863 gdb_assert (w2 != NULL);
6865 /* If the target can evaluate the condition expression in hardware,
6866 then we we need to insert both watchpoints even if they are at
6867 the same place. Otherwise the watchpoint will only trigger when
6868 the condition of whichever watchpoint was inserted evaluates to
6869 true, not giving a chance for GDB to check the condition of the
6870 other watchpoint. */
6872 && target_can_accel_watchpoint_condition (loc1->address,
6874 loc1->watchpoint_type,
6875 w1->cond_exp.get ()))
6877 && target_can_accel_watchpoint_condition (loc2->address,
6879 loc2->watchpoint_type,
6880 w2->cond_exp.get ())))
6883 /* Note that this checks the owner's type, not the location's. In
6884 case the target does not support read watchpoints, but does
6885 support access watchpoints, we'll have bp_read_watchpoint
6886 watchpoints with hw_access locations. Those should be considered
6887 duplicates of hw_read locations. The hw_read locations will
6888 become hw_access locations later. */
6889 return (loc1->owner->type == loc2->owner->type
6890 && loc1->pspace->aspace == loc2->pspace->aspace
6891 && loc1->address == loc2->address
6892 && loc1->length == loc2->length);
6895 /* See breakpoint.h. */
6898 breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
6899 const address_space *aspace2, CORE_ADDR addr2)
6901 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6902 || aspace1 == aspace2)
6906 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6907 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6908 matches ASPACE2. On targets that have global breakpoints, the address
6909 space doesn't really matter. */
6912 breakpoint_address_match_range (const address_space *aspace1,
6914 int len1, const address_space *aspace2,
6917 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6918 || aspace1 == aspace2)
6919 && addr2 >= addr1 && addr2 < addr1 + len1);
6922 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6923 a ranged breakpoint. In most targets, a match happens only if ASPACE
6924 matches the breakpoint's address space. On targets that have global
6925 breakpoints, the address space doesn't really matter. */
6928 breakpoint_location_address_match (struct bp_location *bl,
6929 const address_space *aspace,
6932 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6935 && breakpoint_address_match_range (bl->pspace->aspace,
6936 bl->address, bl->length,
6940 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6941 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6942 match happens only if ASPACE matches the breakpoint's address
6943 space. On targets that have global breakpoints, the address space
6944 doesn't really matter. */
6947 breakpoint_location_address_range_overlap (struct bp_location *bl,
6948 const address_space *aspace,
6949 CORE_ADDR addr, int len)
6951 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6952 || bl->pspace->aspace == aspace)
6954 int bl_len = bl->length != 0 ? bl->length : 1;
6956 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
6962 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6963 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6964 true, otherwise returns false. */
6967 tracepoint_locations_match (struct bp_location *loc1,
6968 struct bp_location *loc2)
6970 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6971 /* Since tracepoint locations are never duplicated with others', tracepoint
6972 locations at the same address of different tracepoints are regarded as
6973 different locations. */
6974 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6979 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6980 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6981 represent the same location. */
6984 breakpoint_locations_match (struct bp_location *loc1,
6985 struct bp_location *loc2)
6987 int hw_point1, hw_point2;
6989 /* Both of them must not be in moribund_locations. */
6990 gdb_assert (loc1->owner != NULL);
6991 gdb_assert (loc2->owner != NULL);
6993 hw_point1 = is_hardware_watchpoint (loc1->owner);
6994 hw_point2 = is_hardware_watchpoint (loc2->owner);
6996 if (hw_point1 != hw_point2)
6999 return watchpoint_locations_match (loc1, loc2);
7000 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7001 return tracepoint_locations_match (loc1, loc2);
7003 /* We compare bp_location.length in order to cover ranged breakpoints. */
7004 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7005 loc2->pspace->aspace, loc2->address)
7006 && loc1->length == loc2->length);
7010 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7011 int bnum, int have_bnum)
7013 /* The longest string possibly returned by hex_string_custom
7014 is 50 chars. These must be at least that big for safety. */
7018 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7019 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7021 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7022 bnum, astr1, astr2);
7024 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7027 /* Adjust a breakpoint's address to account for architectural
7028 constraints on breakpoint placement. Return the adjusted address.
7029 Note: Very few targets require this kind of adjustment. For most
7030 targets, this function is simply the identity function. */
7033 adjust_breakpoint_address (struct gdbarch *gdbarch,
7034 CORE_ADDR bpaddr, enum bptype bptype)
7036 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7038 /* Very few targets need any kind of breakpoint adjustment. */
7041 else if (bptype == bp_watchpoint
7042 || bptype == bp_hardware_watchpoint
7043 || bptype == bp_read_watchpoint
7044 || bptype == bp_access_watchpoint
7045 || bptype == bp_catchpoint)
7047 /* Watchpoints and the various bp_catch_* eventpoints should not
7048 have their addresses modified. */
7051 else if (bptype == bp_single_step)
7053 /* Single-step breakpoints should not have their addresses
7054 modified. If there's any architectural constrain that
7055 applies to this address, then it should have already been
7056 taken into account when the breakpoint was created in the
7057 first place. If we didn't do this, stepping through e.g.,
7058 Thumb-2 IT blocks would break. */
7063 CORE_ADDR adjusted_bpaddr;
7065 /* Some targets have architectural constraints on the placement
7066 of breakpoint instructions. Obtain the adjusted address. */
7067 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7069 /* An adjusted breakpoint address can significantly alter
7070 a user's expectations. Print a warning if an adjustment
7072 if (adjusted_bpaddr != bpaddr)
7073 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7075 return adjusted_bpaddr;
7079 bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner)
7081 bp_location *loc = this;
7083 gdb_assert (ops != NULL);
7087 loc->cond_bytecode = NULL;
7088 loc->shlib_disabled = 0;
7091 switch (owner->type)
7094 case bp_single_step:
7098 case bp_longjmp_resume:
7099 case bp_longjmp_call_dummy:
7101 case bp_exception_resume:
7102 case bp_step_resume:
7103 case bp_hp_step_resume:
7104 case bp_watchpoint_scope:
7106 case bp_std_terminate:
7107 case bp_shlib_event:
7108 case bp_thread_event:
7109 case bp_overlay_event:
7111 case bp_longjmp_master:
7112 case bp_std_terminate_master:
7113 case bp_exception_master:
7114 case bp_gnu_ifunc_resolver:
7115 case bp_gnu_ifunc_resolver_return:
7117 loc->loc_type = bp_loc_software_breakpoint;
7118 mark_breakpoint_location_modified (loc);
7120 case bp_hardware_breakpoint:
7121 loc->loc_type = bp_loc_hardware_breakpoint;
7122 mark_breakpoint_location_modified (loc);
7124 case bp_hardware_watchpoint:
7125 case bp_read_watchpoint:
7126 case bp_access_watchpoint:
7127 loc->loc_type = bp_loc_hardware_watchpoint;
7132 case bp_fast_tracepoint:
7133 case bp_static_tracepoint:
7134 loc->loc_type = bp_loc_other;
7137 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7143 /* Allocate a struct bp_location. */
7145 static struct bp_location *
7146 allocate_bp_location (struct breakpoint *bpt)
7148 return bpt->ops->allocate_location (bpt);
7152 free_bp_location (struct bp_location *loc)
7154 loc->ops->dtor (loc);
7158 /* Increment reference count. */
7161 incref_bp_location (struct bp_location *bl)
7166 /* Decrement reference count. If the reference count reaches 0,
7167 destroy the bp_location. Sets *BLP to NULL. */
7170 decref_bp_location (struct bp_location **blp)
7172 gdb_assert ((*blp)->refc > 0);
7174 if (--(*blp)->refc == 0)
7175 free_bp_location (*blp);
7179 /* Add breakpoint B at the end of the global breakpoint chain. */
7182 add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b)
7184 struct breakpoint *b1;
7185 struct breakpoint *result = b.get ();
7187 /* Add this breakpoint to the end of the chain so that a list of
7188 breakpoints will come out in order of increasing numbers. */
7190 b1 = breakpoint_chain;
7192 breakpoint_chain = b.release ();
7197 b1->next = b.release ();
7203 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7206 init_raw_breakpoint_without_location (struct breakpoint *b,
7207 struct gdbarch *gdbarch,
7209 const struct breakpoint_ops *ops)
7211 gdb_assert (ops != NULL);
7215 b->gdbarch = gdbarch;
7216 b->language = current_language->la_language;
7217 b->input_radix = input_radix;
7218 b->related_breakpoint = b;
7221 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7222 that has type BPTYPE and has no locations as yet. */
7224 static struct breakpoint *
7225 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7227 const struct breakpoint_ops *ops)
7229 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7231 init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops);
7232 return add_to_breakpoint_chain (std::move (b));
7235 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7236 resolutions should be made as the user specified the location explicitly
7240 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7242 gdb_assert (loc->owner != NULL);
7244 if (loc->owner->type == bp_breakpoint
7245 || loc->owner->type == bp_hardware_breakpoint
7246 || is_tracepoint (loc->owner))
7249 const char *function_name;
7250 CORE_ADDR func_addr;
7252 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7253 &func_addr, NULL, &is_gnu_ifunc);
7255 if (is_gnu_ifunc && !explicit_loc)
7257 struct breakpoint *b = loc->owner;
7259 gdb_assert (loc->pspace == current_program_space);
7260 if (gnu_ifunc_resolve_name (function_name,
7261 &loc->requested_address))
7263 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7264 loc->address = adjust_breakpoint_address (loc->gdbarch,
7265 loc->requested_address,
7268 else if (b->type == bp_breakpoint && b->loc == loc
7269 && loc->next == NULL && b->related_breakpoint == b)
7271 /* Create only the whole new breakpoint of this type but do not
7272 mess more complicated breakpoints with multiple locations. */
7273 b->type = bp_gnu_ifunc_resolver;
7274 /* Remember the resolver's address for use by the return
7276 loc->related_address = func_addr;
7281 loc->function_name = xstrdup (function_name);
7285 /* Attempt to determine architecture of location identified by SAL. */
7287 get_sal_arch (struct symtab_and_line sal)
7290 return get_objfile_arch (sal.section->objfile);
7292 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7297 /* Low level routine for partially initializing a breakpoint of type
7298 BPTYPE. The newly created breakpoint's address, section, source
7299 file name, and line number are provided by SAL.
7301 It is expected that the caller will complete the initialization of
7302 the newly created breakpoint struct as well as output any status
7303 information regarding the creation of a new breakpoint. */
7306 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7307 struct symtab_and_line sal, enum bptype bptype,
7308 const struct breakpoint_ops *ops)
7310 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7312 add_location_to_breakpoint (b, &sal);
7314 if (bptype != bp_catchpoint)
7315 gdb_assert (sal.pspace != NULL);
7317 /* Store the program space that was used to set the breakpoint,
7318 except for ordinary breakpoints, which are independent of the
7320 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7321 b->pspace = sal.pspace;
7324 /* set_raw_breakpoint is a low level routine for allocating and
7325 partially initializing a breakpoint of type BPTYPE. The newly
7326 created breakpoint's address, section, source file name, and line
7327 number are provided by SAL. The newly created and partially
7328 initialized breakpoint is added to the breakpoint chain and
7329 is also returned as the value of this function.
7331 It is expected that the caller will complete the initialization of
7332 the newly created breakpoint struct as well as output any status
7333 information regarding the creation of a new breakpoint. In
7334 particular, set_raw_breakpoint does NOT set the breakpoint
7335 number! Care should be taken to not allow an error to occur
7336 prior to completing the initialization of the breakpoint. If this
7337 should happen, a bogus breakpoint will be left on the chain. */
7340 set_raw_breakpoint (struct gdbarch *gdbarch,
7341 struct symtab_and_line sal, enum bptype bptype,
7342 const struct breakpoint_ops *ops)
7344 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7346 init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops);
7347 return add_to_breakpoint_chain (std::move (b));
7350 /* Call this routine when stepping and nexting to enable a breakpoint
7351 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7352 initiated the operation. */
7355 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7357 struct breakpoint *b, *b_tmp;
7358 int thread = tp->global_num;
7360 /* To avoid having to rescan all objfile symbols at every step,
7361 we maintain a list of continually-inserted but always disabled
7362 longjmp "master" breakpoints. Here, we simply create momentary
7363 clones of those and enable them for the requested thread. */
7364 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7365 if (b->pspace == current_program_space
7366 && (b->type == bp_longjmp_master
7367 || b->type == bp_exception_master))
7369 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7370 struct breakpoint *clone;
7372 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7373 after their removal. */
7374 clone = momentary_breakpoint_from_master (b, type,
7375 &momentary_breakpoint_ops, 1);
7376 clone->thread = thread;
7379 tp->initiating_frame = frame;
7382 /* Delete all longjmp breakpoints from THREAD. */
7384 delete_longjmp_breakpoint (int thread)
7386 struct breakpoint *b, *b_tmp;
7388 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7389 if (b->type == bp_longjmp || b->type == bp_exception)
7391 if (b->thread == thread)
7392 delete_breakpoint (b);
7397 delete_longjmp_breakpoint_at_next_stop (int thread)
7399 struct breakpoint *b, *b_tmp;
7401 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7402 if (b->type == bp_longjmp || b->type == bp_exception)
7404 if (b->thread == thread)
7405 b->disposition = disp_del_at_next_stop;
7409 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7410 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7411 pointer to any of them. Return NULL if this system cannot place longjmp
7415 set_longjmp_breakpoint_for_call_dummy (void)
7417 struct breakpoint *b, *retval = NULL;
7420 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7422 struct breakpoint *new_b;
7424 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7425 &momentary_breakpoint_ops,
7427 new_b->thread = ptid_to_global_thread_id (inferior_ptid);
7429 /* Link NEW_B into the chain of RETVAL breakpoints. */
7431 gdb_assert (new_b->related_breakpoint == new_b);
7434 new_b->related_breakpoint = retval;
7435 while (retval->related_breakpoint != new_b->related_breakpoint)
7436 retval = retval->related_breakpoint;
7437 retval->related_breakpoint = new_b;
7443 /* Verify all existing dummy frames and their associated breakpoints for
7444 TP. Remove those which can no longer be found in the current frame
7447 You should call this function only at places where it is safe to currently
7448 unwind the whole stack. Failed stack unwind would discard live dummy
7452 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7454 struct breakpoint *b, *b_tmp;
7456 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7457 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7459 struct breakpoint *dummy_b = b->related_breakpoint;
7461 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7462 dummy_b = dummy_b->related_breakpoint;
7463 if (dummy_b->type != bp_call_dummy
7464 || frame_find_by_id (dummy_b->frame_id) != NULL)
7467 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7469 while (b->related_breakpoint != b)
7471 if (b_tmp == b->related_breakpoint)
7472 b_tmp = b->related_breakpoint->next;
7473 delete_breakpoint (b->related_breakpoint);
7475 delete_breakpoint (b);
7480 enable_overlay_breakpoints (void)
7482 struct breakpoint *b;
7485 if (b->type == bp_overlay_event)
7487 b->enable_state = bp_enabled;
7488 update_global_location_list (UGLL_MAY_INSERT);
7489 overlay_events_enabled = 1;
7494 disable_overlay_breakpoints (void)
7496 struct breakpoint *b;
7499 if (b->type == bp_overlay_event)
7501 b->enable_state = bp_disabled;
7502 update_global_location_list (UGLL_DONT_INSERT);
7503 overlay_events_enabled = 0;
7507 /* Set an active std::terminate breakpoint for each std::terminate
7508 master breakpoint. */
7510 set_std_terminate_breakpoint (void)
7512 struct breakpoint *b, *b_tmp;
7514 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7515 if (b->pspace == current_program_space
7516 && b->type == bp_std_terminate_master)
7518 momentary_breakpoint_from_master (b, bp_std_terminate,
7519 &momentary_breakpoint_ops, 1);
7523 /* Delete all the std::terminate breakpoints. */
7525 delete_std_terminate_breakpoint (void)
7527 struct breakpoint *b, *b_tmp;
7529 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7530 if (b->type == bp_std_terminate)
7531 delete_breakpoint (b);
7535 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7537 struct breakpoint *b;
7539 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7540 &internal_breakpoint_ops);
7542 b->enable_state = bp_enabled;
7543 /* location has to be used or breakpoint_re_set will delete me. */
7544 b->location = new_address_location (b->loc->address, NULL, 0);
7546 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7551 struct lang_and_radix
7557 /* Create a breakpoint for JIT code registration and unregistration. */
7560 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7562 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7563 &internal_breakpoint_ops);
7566 /* Remove JIT code registration and unregistration breakpoint(s). */
7569 remove_jit_event_breakpoints (void)
7571 struct breakpoint *b, *b_tmp;
7573 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7574 if (b->type == bp_jit_event
7575 && b->loc->pspace == current_program_space)
7576 delete_breakpoint (b);
7580 remove_solib_event_breakpoints (void)
7582 struct breakpoint *b, *b_tmp;
7584 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7585 if (b->type == bp_shlib_event
7586 && b->loc->pspace == current_program_space)
7587 delete_breakpoint (b);
7590 /* See breakpoint.h. */
7593 remove_solib_event_breakpoints_at_next_stop (void)
7595 struct breakpoint *b, *b_tmp;
7597 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7598 if (b->type == bp_shlib_event
7599 && b->loc->pspace == current_program_space)
7600 b->disposition = disp_del_at_next_stop;
7603 /* Helper for create_solib_event_breakpoint /
7604 create_and_insert_solib_event_breakpoint. Allows specifying which
7605 INSERT_MODE to pass through to update_global_location_list. */
7607 static struct breakpoint *
7608 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7609 enum ugll_insert_mode insert_mode)
7611 struct breakpoint *b;
7613 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7614 &internal_breakpoint_ops);
7615 update_global_location_list_nothrow (insert_mode);
7620 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7622 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7625 /* See breakpoint.h. */
7628 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7630 struct breakpoint *b;
7632 /* Explicitly tell update_global_location_list to insert
7634 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7635 if (!b->loc->inserted)
7637 delete_breakpoint (b);
7643 /* Disable any breakpoints that are on code in shared libraries. Only
7644 apply to enabled breakpoints, disabled ones can just stay disabled. */
7647 disable_breakpoints_in_shlibs (void)
7649 struct bp_location *loc, **locp_tmp;
7651 ALL_BP_LOCATIONS (loc, locp_tmp)
7653 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7654 struct breakpoint *b = loc->owner;
7656 /* We apply the check to all breakpoints, including disabled for
7657 those with loc->duplicate set. This is so that when breakpoint
7658 becomes enabled, or the duplicate is removed, gdb will try to
7659 insert all breakpoints. If we don't set shlib_disabled here,
7660 we'll try to insert those breakpoints and fail. */
7661 if (((b->type == bp_breakpoint)
7662 || (b->type == bp_jit_event)
7663 || (b->type == bp_hardware_breakpoint)
7664 || (is_tracepoint (b)))
7665 && loc->pspace == current_program_space
7666 && !loc->shlib_disabled
7667 && solib_name_from_address (loc->pspace, loc->address)
7670 loc->shlib_disabled = 1;
7675 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7676 notification of unloaded_shlib. Only apply to enabled breakpoints,
7677 disabled ones can just stay disabled. */
7680 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7682 struct bp_location *loc, **locp_tmp;
7683 int disabled_shlib_breaks = 0;
7685 ALL_BP_LOCATIONS (loc, locp_tmp)
7687 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7688 struct breakpoint *b = loc->owner;
7690 if (solib->pspace == loc->pspace
7691 && !loc->shlib_disabled
7692 && (((b->type == bp_breakpoint
7693 || b->type == bp_jit_event
7694 || b->type == bp_hardware_breakpoint)
7695 && (loc->loc_type == bp_loc_hardware_breakpoint
7696 || loc->loc_type == bp_loc_software_breakpoint))
7697 || is_tracepoint (b))
7698 && solib_contains_address_p (solib, loc->address))
7700 loc->shlib_disabled = 1;
7701 /* At this point, we cannot rely on remove_breakpoint
7702 succeeding so we must mark the breakpoint as not inserted
7703 to prevent future errors occurring in remove_breakpoints. */
7706 /* This may cause duplicate notifications for the same breakpoint. */
7707 observer_notify_breakpoint_modified (b);
7709 if (!disabled_shlib_breaks)
7711 target_terminal::ours_for_output ();
7712 warning (_("Temporarily disabling breakpoints "
7713 "for unloaded shared library \"%s\""),
7716 disabled_shlib_breaks = 1;
7721 /* Disable any breakpoints and tracepoints in OBJFILE upon
7722 notification of free_objfile. Only apply to enabled breakpoints,
7723 disabled ones can just stay disabled. */
7726 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7728 struct breakpoint *b;
7730 if (objfile == NULL)
7733 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7734 managed by the user with add-symbol-file/remove-symbol-file.
7735 Similarly to how breakpoints in shared libraries are handled in
7736 response to "nosharedlibrary", mark breakpoints in such modules
7737 shlib_disabled so they end up uninserted on the next global
7738 location list update. Shared libraries not loaded by the user
7739 aren't handled here -- they're already handled in
7740 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7741 solib_unloaded observer. We skip objfiles that are not
7742 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7744 if ((objfile->flags & OBJF_SHARED) == 0
7745 || (objfile->flags & OBJF_USERLOADED) == 0)
7750 struct bp_location *loc;
7751 int bp_modified = 0;
7753 if (!is_breakpoint (b) && !is_tracepoint (b))
7756 for (loc = b->loc; loc != NULL; loc = loc->next)
7758 CORE_ADDR loc_addr = loc->address;
7760 if (loc->loc_type != bp_loc_hardware_breakpoint
7761 && loc->loc_type != bp_loc_software_breakpoint)
7764 if (loc->shlib_disabled != 0)
7767 if (objfile->pspace != loc->pspace)
7770 if (loc->loc_type != bp_loc_hardware_breakpoint
7771 && loc->loc_type != bp_loc_software_breakpoint)
7774 if (is_addr_in_objfile (loc_addr, objfile))
7776 loc->shlib_disabled = 1;
7777 /* At this point, we don't know whether the object was
7778 unmapped from the inferior or not, so leave the
7779 inserted flag alone. We'll handle failure to
7780 uninsert quietly, in case the object was indeed
7783 mark_breakpoint_location_modified (loc);
7790 observer_notify_breakpoint_modified (b);
7794 /* FORK & VFORK catchpoints. */
7796 /* An instance of this type is used to represent a fork or vfork
7797 catchpoint. A breakpoint is really of this type iff its ops pointer points
7798 to CATCH_FORK_BREAKPOINT_OPS. */
7800 struct fork_catchpoint : public breakpoint
7802 /* Process id of a child process whose forking triggered this
7803 catchpoint. This field is only valid immediately after this
7804 catchpoint has triggered. */
7805 ptid_t forked_inferior_pid;
7808 /* Implement the "insert" breakpoint_ops method for fork
7812 insert_catch_fork (struct bp_location *bl)
7814 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7817 /* Implement the "remove" breakpoint_ops method for fork
7821 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
7823 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7826 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7830 breakpoint_hit_catch_fork (const struct bp_location *bl,
7831 struct address_space *aspace, CORE_ADDR bp_addr,
7832 const struct target_waitstatus *ws)
7834 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7836 if (ws->kind != TARGET_WAITKIND_FORKED)
7839 c->forked_inferior_pid = ws->value.related_pid;
7843 /* Implement the "print_it" breakpoint_ops method for fork
7846 static enum print_stop_action
7847 print_it_catch_fork (bpstat bs)
7849 struct ui_out *uiout = current_uiout;
7850 struct breakpoint *b = bs->breakpoint_at;
7851 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7853 annotate_catchpoint (b->number);
7854 maybe_print_thread_hit_breakpoint (uiout);
7855 if (b->disposition == disp_del)
7856 uiout->text ("Temporary catchpoint ");
7858 uiout->text ("Catchpoint ");
7859 if (uiout->is_mi_like_p ())
7861 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK));
7862 uiout->field_string ("disp", bpdisp_text (b->disposition));
7864 uiout->field_int ("bkptno", b->number);
7865 uiout->text (" (forked process ");
7866 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
7867 uiout->text ("), ");
7868 return PRINT_SRC_AND_LOC;
7871 /* Implement the "print_one" breakpoint_ops method for fork
7875 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7877 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7878 struct value_print_options opts;
7879 struct ui_out *uiout = current_uiout;
7881 get_user_print_options (&opts);
7883 /* Field 4, the address, is omitted (which makes the columns not
7884 line up too nicely with the headers, but the effect is relatively
7886 if (opts.addressprint)
7887 uiout->field_skip ("addr");
7889 uiout->text ("fork");
7890 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7892 uiout->text (", process ");
7893 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
7897 if (uiout->is_mi_like_p ())
7898 uiout->field_string ("catch-type", "fork");
7901 /* Implement the "print_mention" breakpoint_ops method for fork
7905 print_mention_catch_fork (struct breakpoint *b)
7907 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7910 /* Implement the "print_recreate" breakpoint_ops method for fork
7914 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7916 fprintf_unfiltered (fp, "catch fork");
7917 print_recreate_thread (b, fp);
7920 /* The breakpoint_ops structure to be used in fork catchpoints. */
7922 static struct breakpoint_ops catch_fork_breakpoint_ops;
7924 /* Implement the "insert" breakpoint_ops method for vfork
7928 insert_catch_vfork (struct bp_location *bl)
7930 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7933 /* Implement the "remove" breakpoint_ops method for vfork
7937 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
7939 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
7942 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7946 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7947 struct address_space *aspace, CORE_ADDR bp_addr,
7948 const struct target_waitstatus *ws)
7950 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7952 if (ws->kind != TARGET_WAITKIND_VFORKED)
7955 c->forked_inferior_pid = ws->value.related_pid;
7959 /* Implement the "print_it" breakpoint_ops method for vfork
7962 static enum print_stop_action
7963 print_it_catch_vfork (bpstat bs)
7965 struct ui_out *uiout = current_uiout;
7966 struct breakpoint *b = bs->breakpoint_at;
7967 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7969 annotate_catchpoint (b->number);
7970 maybe_print_thread_hit_breakpoint (uiout);
7971 if (b->disposition == disp_del)
7972 uiout->text ("Temporary catchpoint ");
7974 uiout->text ("Catchpoint ");
7975 if (uiout->is_mi_like_p ())
7977 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK));
7978 uiout->field_string ("disp", bpdisp_text (b->disposition));
7980 uiout->field_int ("bkptno", b->number);
7981 uiout->text (" (vforked process ");
7982 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
7983 uiout->text ("), ");
7984 return PRINT_SRC_AND_LOC;
7987 /* Implement the "print_one" breakpoint_ops method for vfork
7991 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7993 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7994 struct value_print_options opts;
7995 struct ui_out *uiout = current_uiout;
7997 get_user_print_options (&opts);
7998 /* Field 4, the address, is omitted (which makes the columns not
7999 line up too nicely with the headers, but the effect is relatively
8001 if (opts.addressprint)
8002 uiout->field_skip ("addr");
8004 uiout->text ("vfork");
8005 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8007 uiout->text (", process ");
8008 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
8012 if (uiout->is_mi_like_p ())
8013 uiout->field_string ("catch-type", "vfork");
8016 /* Implement the "print_mention" breakpoint_ops method for vfork
8020 print_mention_catch_vfork (struct breakpoint *b)
8022 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8025 /* Implement the "print_recreate" breakpoint_ops method for vfork
8029 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8031 fprintf_unfiltered (fp, "catch vfork");
8032 print_recreate_thread (b, fp);
8035 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8037 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8039 /* An instance of this type is used to represent an solib catchpoint.
8040 A breakpoint is really of this type iff its ops pointer points to
8041 CATCH_SOLIB_BREAKPOINT_OPS. */
8043 struct solib_catchpoint : public breakpoint
8045 ~solib_catchpoint () override;
8047 /* True for "catch load", false for "catch unload". */
8048 unsigned char is_load;
8050 /* Regular expression to match, if any. COMPILED is only valid when
8051 REGEX is non-NULL. */
8053 std::unique_ptr<compiled_regex> compiled;
8056 solib_catchpoint::~solib_catchpoint ()
8058 xfree (this->regex);
8062 insert_catch_solib (struct bp_location *ignore)
8068 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
8074 breakpoint_hit_catch_solib (const struct bp_location *bl,
8075 struct address_space *aspace,
8077 const struct target_waitstatus *ws)
8079 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8080 struct breakpoint *other;
8082 if (ws->kind == TARGET_WAITKIND_LOADED)
8085 ALL_BREAKPOINTS (other)
8087 struct bp_location *other_bl;
8089 if (other == bl->owner)
8092 if (other->type != bp_shlib_event)
8095 if (self->pspace != NULL && other->pspace != self->pspace)
8098 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8100 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8109 check_status_catch_solib (struct bpstats *bs)
8111 struct solib_catchpoint *self
8112 = (struct solib_catchpoint *) bs->breakpoint_at;
8117 struct so_list *iter;
8120 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8125 || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
8134 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8139 || self->compiled->exec (iter, 0, NULL, 0) == 0)
8145 bs->print_it = print_it_noop;
8148 static enum print_stop_action
8149 print_it_catch_solib (bpstat bs)
8151 struct breakpoint *b = bs->breakpoint_at;
8152 struct ui_out *uiout = current_uiout;
8154 annotate_catchpoint (b->number);
8155 maybe_print_thread_hit_breakpoint (uiout);
8156 if (b->disposition == disp_del)
8157 uiout->text ("Temporary catchpoint ");
8159 uiout->text ("Catchpoint ");
8160 uiout->field_int ("bkptno", b->number);
8162 if (uiout->is_mi_like_p ())
8163 uiout->field_string ("disp", bpdisp_text (b->disposition));
8164 print_solib_event (1);
8165 return PRINT_SRC_AND_LOC;
8169 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8171 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8172 struct value_print_options opts;
8173 struct ui_out *uiout = current_uiout;
8176 get_user_print_options (&opts);
8177 /* Field 4, the address, is omitted (which makes the columns not
8178 line up too nicely with the headers, but the effect is relatively
8180 if (opts.addressprint)
8183 uiout->field_skip ("addr");
8190 msg = xstrprintf (_("load of library matching %s"), self->regex);
8192 msg = xstrdup (_("load of library"));
8197 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8199 msg = xstrdup (_("unload of library"));
8201 uiout->field_string ("what", msg);
8204 if (uiout->is_mi_like_p ())
8205 uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
8209 print_mention_catch_solib (struct breakpoint *b)
8211 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8213 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8214 self->is_load ? "load" : "unload");
8218 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8220 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8222 fprintf_unfiltered (fp, "%s %s",
8223 b->disposition == disp_del ? "tcatch" : "catch",
8224 self->is_load ? "load" : "unload");
8226 fprintf_unfiltered (fp, " %s", self->regex);
8227 fprintf_unfiltered (fp, "\n");
8230 static struct breakpoint_ops catch_solib_breakpoint_ops;
8232 /* Shared helper function (MI and CLI) for creating and installing
8233 a shared object event catchpoint. If IS_LOAD is non-zero then
8234 the events to be caught are load events, otherwise they are
8235 unload events. If IS_TEMP is non-zero the catchpoint is a
8236 temporary one. If ENABLED is non-zero the catchpoint is
8237 created in an enabled state. */
8240 add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
8242 struct gdbarch *gdbarch = get_current_arch ();
8246 arg = skip_spaces (arg);
8248 std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
8252 c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
8253 _("Invalid regexp")));
8254 c->regex = xstrdup (arg);
8257 c->is_load = is_load;
8258 init_catchpoint (c.get (), gdbarch, is_temp, NULL,
8259 &catch_solib_breakpoint_ops);
8261 c->enable_state = enabled ? bp_enabled : bp_disabled;
8263 install_breakpoint (0, std::move (c), 1);
8266 /* A helper function that does all the work for "catch load" and
8270 catch_load_or_unload (char *arg, int from_tty, int is_load,
8271 struct cmd_list_element *command)
8274 const int enabled = 1;
8276 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8278 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8282 catch_load_command_1 (char *arg, int from_tty,
8283 struct cmd_list_element *command)
8285 catch_load_or_unload (arg, from_tty, 1, command);
8289 catch_unload_command_1 (char *arg, int from_tty,
8290 struct cmd_list_element *command)
8292 catch_load_or_unload (arg, from_tty, 0, command);
8295 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8296 is non-zero, then make the breakpoint temporary. If COND_STRING is
8297 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8298 the breakpoint_ops structure associated to the catchpoint. */
8301 init_catchpoint (struct breakpoint *b,
8302 struct gdbarch *gdbarch, int tempflag,
8303 const char *cond_string,
8304 const struct breakpoint_ops *ops)
8306 symtab_and_line sal;
8307 sal.pspace = current_program_space;
8309 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8311 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8312 b->disposition = tempflag ? disp_del : disp_donttouch;
8316 install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll)
8318 breakpoint *b = add_to_breakpoint_chain (std::move (arg));
8319 set_breakpoint_number (internal, b);
8320 if (is_tracepoint (b))
8321 set_tracepoint_count (breakpoint_count);
8324 observer_notify_breakpoint_created (b);
8327 update_global_location_list (UGLL_MAY_INSERT);
8331 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8332 int tempflag, const char *cond_string,
8333 const struct breakpoint_ops *ops)
8335 std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ());
8337 init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops);
8339 c->forked_inferior_pid = null_ptid;
8341 install_breakpoint (0, std::move (c), 1);
8344 /* Exec catchpoints. */
8346 /* An instance of this type is used to represent an exec catchpoint.
8347 A breakpoint is really of this type iff its ops pointer points to
8348 CATCH_EXEC_BREAKPOINT_OPS. */
8350 struct exec_catchpoint : public breakpoint
8352 ~exec_catchpoint () override;
8354 /* Filename of a program whose exec triggered this catchpoint.
8355 This field is only valid immediately after this catchpoint has
8357 char *exec_pathname;
8360 /* Exec catchpoint destructor. */
8362 exec_catchpoint::~exec_catchpoint ()
8364 xfree (this->exec_pathname);
8368 insert_catch_exec (struct bp_location *bl)
8370 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8374 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8376 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8380 breakpoint_hit_catch_exec (const struct bp_location *bl,
8381 struct address_space *aspace, CORE_ADDR bp_addr,
8382 const struct target_waitstatus *ws)
8384 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8386 if (ws->kind != TARGET_WAITKIND_EXECD)
8389 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8393 static enum print_stop_action
8394 print_it_catch_exec (bpstat bs)
8396 struct ui_out *uiout = current_uiout;
8397 struct breakpoint *b = bs->breakpoint_at;
8398 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8400 annotate_catchpoint (b->number);
8401 maybe_print_thread_hit_breakpoint (uiout);
8402 if (b->disposition == disp_del)
8403 uiout->text ("Temporary catchpoint ");
8405 uiout->text ("Catchpoint ");
8406 if (uiout->is_mi_like_p ())
8408 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
8409 uiout->field_string ("disp", bpdisp_text (b->disposition));
8411 uiout->field_int ("bkptno", b->number);
8412 uiout->text (" (exec'd ");
8413 uiout->field_string ("new-exec", c->exec_pathname);
8414 uiout->text ("), ");
8416 return PRINT_SRC_AND_LOC;
8420 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8422 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8423 struct value_print_options opts;
8424 struct ui_out *uiout = current_uiout;
8426 get_user_print_options (&opts);
8428 /* Field 4, the address, is omitted (which makes the columns
8429 not line up too nicely with the headers, but the effect
8430 is relatively readable). */
8431 if (opts.addressprint)
8432 uiout->field_skip ("addr");
8434 uiout->text ("exec");
8435 if (c->exec_pathname != NULL)
8437 uiout->text (", program \"");
8438 uiout->field_string ("what", c->exec_pathname);
8439 uiout->text ("\" ");
8442 if (uiout->is_mi_like_p ())
8443 uiout->field_string ("catch-type", "exec");
8447 print_mention_catch_exec (struct breakpoint *b)
8449 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8452 /* Implement the "print_recreate" breakpoint_ops method for exec
8456 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8458 fprintf_unfiltered (fp, "catch exec");
8459 print_recreate_thread (b, fp);
8462 static struct breakpoint_ops catch_exec_breakpoint_ops;
8465 hw_breakpoint_used_count (void)
8468 struct breakpoint *b;
8469 struct bp_location *bl;
8473 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8474 for (bl = b->loc; bl; bl = bl->next)
8476 /* Special types of hardware breakpoints may use more than
8478 i += b->ops->resources_needed (bl);
8485 /* Returns the resources B would use if it were a hardware
8489 hw_watchpoint_use_count (struct breakpoint *b)
8492 struct bp_location *bl;
8494 if (!breakpoint_enabled (b))
8497 for (bl = b->loc; bl; bl = bl->next)
8499 /* Special types of hardware watchpoints may use more than
8501 i += b->ops->resources_needed (bl);
8507 /* Returns the sum the used resources of all hardware watchpoints of
8508 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8509 the sum of the used resources of all hardware watchpoints of other
8510 types _not_ TYPE. */
8513 hw_watchpoint_used_count_others (struct breakpoint *except,
8514 enum bptype type, int *other_type_used)
8517 struct breakpoint *b;
8519 *other_type_used = 0;
8524 if (!breakpoint_enabled (b))
8527 if (b->type == type)
8528 i += hw_watchpoint_use_count (b);
8529 else if (is_hardware_watchpoint (b))
8530 *other_type_used = 1;
8537 disable_watchpoints_before_interactive_call_start (void)
8539 struct breakpoint *b;
8543 if (is_watchpoint (b) && breakpoint_enabled (b))
8545 b->enable_state = bp_call_disabled;
8546 update_global_location_list (UGLL_DONT_INSERT);
8552 enable_watchpoints_after_interactive_call_stop (void)
8554 struct breakpoint *b;
8558 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8560 b->enable_state = bp_enabled;
8561 update_global_location_list (UGLL_MAY_INSERT);
8567 disable_breakpoints_before_startup (void)
8569 current_program_space->executing_startup = 1;
8570 update_global_location_list (UGLL_DONT_INSERT);
8574 enable_breakpoints_after_startup (void)
8576 current_program_space->executing_startup = 0;
8577 breakpoint_re_set ();
8580 /* Create a new single-step breakpoint for thread THREAD, with no
8583 static struct breakpoint *
8584 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8586 std::unique_ptr<breakpoint> b (new breakpoint ());
8588 init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step,
8589 &momentary_breakpoint_ops);
8591 b->disposition = disp_donttouch;
8592 b->frame_id = null_frame_id;
8595 gdb_assert (b->thread != 0);
8597 return add_to_breakpoint_chain (std::move (b));
8600 /* Set a momentary breakpoint of type TYPE at address specified by
8601 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8605 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8606 struct frame_id frame_id, enum bptype type)
8608 struct breakpoint *b;
8610 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8612 gdb_assert (!frame_id_artificial_p (frame_id));
8614 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8615 b->enable_state = bp_enabled;
8616 b->disposition = disp_donttouch;
8617 b->frame_id = frame_id;
8619 /* If we're debugging a multi-threaded program, then we want
8620 momentary breakpoints to be active in only a single thread of
8622 if (in_thread_list (inferior_ptid))
8623 b->thread = ptid_to_global_thread_id (inferior_ptid);
8625 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8630 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8631 The new breakpoint will have type TYPE, use OPS as its
8632 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8634 static struct breakpoint *
8635 momentary_breakpoint_from_master (struct breakpoint *orig,
8637 const struct breakpoint_ops *ops,
8640 struct breakpoint *copy;
8642 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8643 copy->loc = allocate_bp_location (copy);
8644 set_breakpoint_location_function (copy->loc, 1);
8646 copy->loc->gdbarch = orig->loc->gdbarch;
8647 copy->loc->requested_address = orig->loc->requested_address;
8648 copy->loc->address = orig->loc->address;
8649 copy->loc->section = orig->loc->section;
8650 copy->loc->pspace = orig->loc->pspace;
8651 copy->loc->probe = orig->loc->probe;
8652 copy->loc->line_number = orig->loc->line_number;
8653 copy->loc->symtab = orig->loc->symtab;
8654 copy->loc->enabled = loc_enabled;
8655 copy->frame_id = orig->frame_id;
8656 copy->thread = orig->thread;
8657 copy->pspace = orig->pspace;
8659 copy->enable_state = bp_enabled;
8660 copy->disposition = disp_donttouch;
8661 copy->number = internal_breakpoint_number--;
8663 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8667 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8671 clone_momentary_breakpoint (struct breakpoint *orig)
8673 /* If there's nothing to clone, then return nothing. */
8677 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8681 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8684 struct symtab_and_line sal;
8686 sal = find_pc_line (pc, 0);
8688 sal.section = find_pc_overlay (pc);
8689 sal.explicit_pc = 1;
8691 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8695 /* Tell the user we have just set a breakpoint B. */
8698 mention (struct breakpoint *b)
8700 b->ops->print_mention (b);
8701 if (current_uiout->is_mi_like_p ())
8703 printf_filtered ("\n");
8707 static int bp_loc_is_permanent (struct bp_location *loc);
8709 static struct bp_location *
8710 add_location_to_breakpoint (struct breakpoint *b,
8711 const struct symtab_and_line *sal)
8713 struct bp_location *loc, **tmp;
8714 CORE_ADDR adjusted_address;
8715 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8717 if (loc_gdbarch == NULL)
8718 loc_gdbarch = b->gdbarch;
8720 /* Adjust the breakpoint's address prior to allocating a location.
8721 Once we call allocate_bp_location(), that mostly uninitialized
8722 location will be placed on the location chain. Adjustment of the
8723 breakpoint may cause target_read_memory() to be called and we do
8724 not want its scan of the location chain to find a breakpoint and
8725 location that's only been partially initialized. */
8726 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8729 /* Sort the locations by their ADDRESS. */
8730 loc = allocate_bp_location (b);
8731 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8732 tmp = &((*tmp)->next))
8737 loc->requested_address = sal->pc;
8738 loc->address = adjusted_address;
8739 loc->pspace = sal->pspace;
8740 loc->probe.probe = sal->probe;
8741 loc->probe.objfile = sal->objfile;
8742 gdb_assert (loc->pspace != NULL);
8743 loc->section = sal->section;
8744 loc->gdbarch = loc_gdbarch;
8745 loc->line_number = sal->line;
8746 loc->symtab = sal->symtab;
8748 set_breakpoint_location_function (loc,
8749 sal->explicit_pc || sal->explicit_line);
8751 /* While by definition, permanent breakpoints are already present in the
8752 code, we don't mark the location as inserted. Normally one would expect
8753 that GDB could rely on that breakpoint instruction to stop the program,
8754 thus removing the need to insert its own breakpoint, except that executing
8755 the breakpoint instruction can kill the target instead of reporting a
8756 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8757 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8758 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8759 breakpoint be inserted normally results in QEMU knowing about the GDB
8760 breakpoint, and thus trap before the breakpoint instruction is executed.
8761 (If GDB later needs to continue execution past the permanent breakpoint,
8762 it manually increments the PC, thus avoiding executing the breakpoint
8764 if (bp_loc_is_permanent (loc))
8771 /* See breakpoint.h. */
8774 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
8778 const gdb_byte *bpoint;
8779 gdb_byte *target_mem;
8782 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
8784 /* Software breakpoints unsupported? */
8788 target_mem = (gdb_byte *) alloca (len);
8790 /* Enable the automatic memory restoration from breakpoints while
8791 we read the memory. Otherwise we could say about our temporary
8792 breakpoints they are permanent. */
8793 scoped_restore restore_memory
8794 = make_scoped_restore_show_memory_breakpoints (0);
8796 if (target_read_memory (address, target_mem, len) == 0
8797 && memcmp (target_mem, bpoint, len) == 0)
8803 /* Return 1 if LOC is pointing to a permanent breakpoint,
8804 return 0 otherwise. */
8807 bp_loc_is_permanent (struct bp_location *loc)
8809 gdb_assert (loc != NULL);
8811 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8812 attempt to read from the addresses the locations of these breakpoint types
8813 point to. program_breakpoint_here_p, below, will attempt to read
8815 if (!breakpoint_address_is_meaningful (loc->owner))
8818 scoped_restore_current_pspace_and_thread restore_pspace_thread;
8819 switch_to_program_space_and_thread (loc->pspace);
8820 return program_breakpoint_here_p (loc->gdbarch, loc->address);
8823 /* Build a command list for the dprintf corresponding to the current
8824 settings of the dprintf style options. */
8827 update_dprintf_command_list (struct breakpoint *b)
8829 char *dprintf_args = b->extra_string;
8830 char *printf_line = NULL;
8835 dprintf_args = skip_spaces (dprintf_args);
8837 /* Allow a comma, as it may have terminated a location, but don't
8839 if (*dprintf_args == ',')
8841 dprintf_args = skip_spaces (dprintf_args);
8843 if (*dprintf_args != '"')
8844 error (_("Bad format string, missing '\"'."));
8846 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8847 printf_line = xstrprintf ("printf %s", dprintf_args);
8848 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8850 if (!dprintf_function)
8851 error (_("No function supplied for dprintf call"));
8853 if (dprintf_channel && strlen (dprintf_channel) > 0)
8854 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8859 printf_line = xstrprintf ("call (void) %s (%s)",
8863 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8865 if (target_can_run_breakpoint_commands ())
8866 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8869 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8870 printf_line = xstrprintf ("printf %s", dprintf_args);
8874 internal_error (__FILE__, __LINE__,
8875 _("Invalid dprintf style."));
8877 gdb_assert (printf_line != NULL);
8878 /* Manufacture a printf sequence. */
8880 struct command_line *printf_cmd_line = XNEW (struct command_line);
8882 printf_cmd_line->control_type = simple_control;
8883 printf_cmd_line->body_count = 0;
8884 printf_cmd_line->body_list = NULL;
8885 printf_cmd_line->next = NULL;
8886 printf_cmd_line->line = printf_line;
8888 breakpoint_set_commands (b, command_line_up (printf_cmd_line));
8892 /* Update all dprintf commands, making their command lists reflect
8893 current style settings. */
8896 update_dprintf_commands (char *args, int from_tty,
8897 struct cmd_list_element *c)
8899 struct breakpoint *b;
8903 if (b->type == bp_dprintf)
8904 update_dprintf_command_list (b);
8908 /* Create a breakpoint with SAL as location. Use LOCATION
8909 as a description of the location, and COND_STRING
8910 as condition expression. If LOCATION is NULL then create an
8911 "address location" from the address in the SAL. */
8914 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8915 gdb::array_view<const symtab_and_line> sals,
8916 event_location_up &&location,
8917 gdb::unique_xmalloc_ptr<char> filter,
8918 gdb::unique_xmalloc_ptr<char> cond_string,
8919 gdb::unique_xmalloc_ptr<char> extra_string,
8920 enum bptype type, enum bpdisp disposition,
8921 int thread, int task, int ignore_count,
8922 const struct breakpoint_ops *ops, int from_tty,
8923 int enabled, int internal, unsigned flags,
8924 int display_canonical)
8928 if (type == bp_hardware_breakpoint)
8930 int target_resources_ok;
8932 i = hw_breakpoint_used_count ();
8933 target_resources_ok =
8934 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8936 if (target_resources_ok == 0)
8937 error (_("No hardware breakpoint support in the target."));
8938 else if (target_resources_ok < 0)
8939 error (_("Hardware breakpoints used exceeds limit."));
8942 gdb_assert (!sals.empty ());
8944 for (const auto &sal : sals)
8946 struct bp_location *loc;
8950 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8952 loc_gdbarch = gdbarch;
8954 describe_other_breakpoints (loc_gdbarch,
8955 sal.pspace, sal.pc, sal.section, thread);
8958 if (&sal == &sals[0])
8960 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8964 b->cond_string = cond_string.release ();
8965 b->extra_string = extra_string.release ();
8966 b->ignore_count = ignore_count;
8967 b->enable_state = enabled ? bp_enabled : bp_disabled;
8968 b->disposition = disposition;
8970 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8971 b->loc->inserted = 1;
8973 if (type == bp_static_tracepoint)
8975 struct tracepoint *t = (struct tracepoint *) b;
8976 struct static_tracepoint_marker marker;
8978 if (strace_marker_p (b))
8980 /* We already know the marker exists, otherwise, we
8981 wouldn't see a sal for it. */
8983 = &event_location_to_string (b->location.get ())[3];
8987 p = skip_spaces (p);
8989 endp = skip_to_space (p);
8991 marker_str = savestring (p, endp - p);
8992 t->static_trace_marker_id = marker_str;
8994 printf_filtered (_("Probed static tracepoint "
8996 t->static_trace_marker_id);
8998 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9000 t->static_trace_marker_id = xstrdup (marker.str_id);
9001 release_static_tracepoint_marker (&marker);
9003 printf_filtered (_("Probed static tracepoint "
9005 t->static_trace_marker_id);
9008 warning (_("Couldn't determine the static "
9009 "tracepoint marker to probe"));
9016 loc = add_location_to_breakpoint (b, &sal);
9017 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9023 const char *arg = b->cond_string;
9025 loc->cond = parse_exp_1 (&arg, loc->address,
9026 block_for_pc (loc->address), 0);
9028 error (_("Garbage '%s' follows condition"), arg);
9031 /* Dynamic printf requires and uses additional arguments on the
9032 command line, otherwise it's an error. */
9033 if (type == bp_dprintf)
9035 if (b->extra_string)
9036 update_dprintf_command_list (b);
9038 error (_("Format string required"));
9040 else if (b->extra_string)
9041 error (_("Garbage '%s' at end of command"), b->extra_string);
9044 b->display_canonical = display_canonical;
9045 if (location != NULL)
9046 b->location = std::move (location);
9048 b->location = new_address_location (b->loc->address, NULL, 0);
9049 b->filter = filter.release ();
9053 create_breakpoint_sal (struct gdbarch *gdbarch,
9054 gdb::array_view<const symtab_and_line> sals,
9055 event_location_up &&location,
9056 gdb::unique_xmalloc_ptr<char> filter,
9057 gdb::unique_xmalloc_ptr<char> cond_string,
9058 gdb::unique_xmalloc_ptr<char> extra_string,
9059 enum bptype type, enum bpdisp disposition,
9060 int thread, int task, int ignore_count,
9061 const struct breakpoint_ops *ops, int from_tty,
9062 int enabled, int internal, unsigned flags,
9063 int display_canonical)
9065 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type);
9067 init_breakpoint_sal (b.get (), gdbarch,
9068 sals, std::move (location),
9070 std::move (cond_string),
9071 std::move (extra_string),
9073 thread, task, ignore_count,
9075 enabled, internal, flags,
9078 install_breakpoint (internal, std::move (b), 0);
9081 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9082 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9083 value. COND_STRING, if not NULL, specified the condition to be
9084 used for all breakpoints. Essentially the only case where
9085 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9086 function. In that case, it's still not possible to specify
9087 separate conditions for different overloaded functions, so
9088 we take just a single condition string.
9090 NOTE: If the function succeeds, the caller is expected to cleanup
9091 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9092 array contents). If the function fails (error() is called), the
9093 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9094 COND and SALS arrays and each of those arrays contents. */
9097 create_breakpoints_sal (struct gdbarch *gdbarch,
9098 struct linespec_result *canonical,
9099 gdb::unique_xmalloc_ptr<char> cond_string,
9100 gdb::unique_xmalloc_ptr<char> extra_string,
9101 enum bptype type, enum bpdisp disposition,
9102 int thread, int task, int ignore_count,
9103 const struct breakpoint_ops *ops, int from_tty,
9104 int enabled, int internal, unsigned flags)
9106 if (canonical->pre_expanded)
9107 gdb_assert (canonical->lsals.size () == 1);
9109 for (const auto &lsal : canonical->lsals)
9111 /* Note that 'location' can be NULL in the case of a plain
9112 'break', without arguments. */
9113 event_location_up location
9114 = (canonical->location != NULL
9115 ? copy_event_location (canonical->location.get ()) : NULL);
9116 gdb::unique_xmalloc_ptr<char> filter_string
9117 (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
9119 create_breakpoint_sal (gdbarch, lsal.sals,
9120 std::move (location),
9121 std::move (filter_string),
9122 std::move (cond_string),
9123 std::move (extra_string),
9125 thread, task, ignore_count, ops,
9126 from_tty, enabled, internal, flags,
9127 canonical->special_display);
9131 /* Parse LOCATION which is assumed to be a SAL specification possibly
9132 followed by conditionals. On return, SALS contains an array of SAL
9133 addresses found. LOCATION points to the end of the SAL (for
9134 linespec locations).
9136 The array and the line spec strings are allocated on the heap, it is
9137 the caller's responsibility to free them. */
9140 parse_breakpoint_sals (const struct event_location *location,
9141 struct linespec_result *canonical)
9143 struct symtab_and_line cursal;
9145 if (event_location_type (location) == LINESPEC_LOCATION)
9147 const char *address = get_linespec_location (location);
9149 if (address == NULL)
9151 /* The last displayed codepoint, if it's valid, is our default
9152 breakpoint address. */
9153 if (last_displayed_sal_is_valid ())
9155 /* Set sal's pspace, pc, symtab, and line to the values
9156 corresponding to the last call to print_frame_info.
9157 Be sure to reinitialize LINE with NOTCURRENT == 0
9158 as the breakpoint line number is inappropriate otherwise.
9159 find_pc_line would adjust PC, re-set it back. */
9160 symtab_and_line sal = get_last_displayed_sal ();
9161 CORE_ADDR pc = sal.pc;
9163 sal = find_pc_line (pc, 0);
9165 /* "break" without arguments is equivalent to "break *PC"
9166 where PC is the last displayed codepoint's address. So
9167 make sure to set sal.explicit_pc to prevent GDB from
9168 trying to expand the list of sals to include all other
9169 instances with the same symtab and line. */
9171 sal.explicit_pc = 1;
9173 struct linespec_sals lsal;
9175 lsal.canonical = NULL;
9177 canonical->lsals.push_back (std::move (lsal));
9181 error (_("No default breakpoint address now."));
9185 /* Force almost all breakpoints to be in terms of the
9186 current_source_symtab (which is decode_line_1's default).
9187 This should produce the results we want almost all of the
9188 time while leaving default_breakpoint_* alone.
9190 ObjC: However, don't match an Objective-C method name which
9191 may have a '+' or '-' succeeded by a '['. */
9192 cursal = get_current_source_symtab_and_line ();
9193 if (last_displayed_sal_is_valid ())
9195 const char *address = NULL;
9197 if (event_location_type (location) == LINESPEC_LOCATION)
9198 address = get_linespec_location (location);
9202 && strchr ("+-", address[0]) != NULL
9203 && address[1] != '['))
9205 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9206 get_last_displayed_symtab (),
9207 get_last_displayed_line (),
9208 canonical, NULL, NULL);
9213 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9214 cursal.symtab, cursal.line, canonical, NULL, NULL);
9218 /* Convert each SAL into a real PC. Verify that the PC can be
9219 inserted as a breakpoint. If it can't throw an error. */
9222 breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals)
9224 for (auto &sal : sals)
9225 resolve_sal_pc (&sal);
9228 /* Fast tracepoints may have restrictions on valid locations. For
9229 instance, a fast tracepoint using a jump instead of a trap will
9230 likely have to overwrite more bytes than a trap would, and so can
9231 only be placed where the instruction is longer than the jump, or a
9232 multi-instruction sequence does not have a jump into the middle of
9236 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9237 gdb::array_view<const symtab_and_line> sals)
9241 struct cleanup *old_chain;
9243 for (const auto &sal : sals)
9245 struct gdbarch *sarch;
9247 sarch = get_sal_arch (sal);
9248 /* We fall back to GDBARCH if there is no architecture
9249 associated with SAL. */
9252 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg);
9253 old_chain = make_cleanup (xfree, msg);
9256 error (_("May not have a fast tracepoint at %s%s"),
9257 paddress (sarch, sal.pc), (msg ? msg : ""));
9259 do_cleanups (old_chain);
9263 /* Given TOK, a string specification of condition and thread, as
9264 accepted by the 'break' command, extract the condition
9265 string and thread number and set *COND_STRING and *THREAD.
9266 PC identifies the context at which the condition should be parsed.
9267 If no condition is found, *COND_STRING is set to NULL.
9268 If no thread is found, *THREAD is set to -1. */
9271 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9272 char **cond_string, int *thread, int *task,
9275 *cond_string = NULL;
9282 const char *end_tok;
9284 const char *cond_start = NULL;
9285 const char *cond_end = NULL;
9287 tok = skip_spaces (tok);
9289 if ((*tok == '"' || *tok == ',') && rest)
9291 *rest = savestring (tok, strlen (tok));
9295 end_tok = skip_to_space (tok);
9297 toklen = end_tok - tok;
9299 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9301 tok = cond_start = end_tok + 1;
9302 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9304 *cond_string = savestring (cond_start, cond_end - cond_start);
9306 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9309 struct thread_info *thr;
9312 thr = parse_thread_id (tok, &tmptok);
9314 error (_("Junk after thread keyword."));
9315 *thread = thr->global_num;
9318 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9323 *task = strtol (tok, &tmptok, 0);
9325 error (_("Junk after task keyword."));
9326 if (!valid_task_id (*task))
9327 error (_("Unknown task %d."), *task);
9332 *rest = savestring (tok, strlen (tok));
9336 error (_("Junk at end of arguments."));
9340 /* Decode a static tracepoint marker spec. */
9342 static std::vector<symtab_and_line>
9343 decode_static_tracepoint_spec (const char **arg_p)
9345 VEC(static_tracepoint_marker_p) *markers = NULL;
9346 const char *p = &(*arg_p)[3];
9350 p = skip_spaces (p);
9352 endp = skip_to_space (p);
9354 std::string marker_str (p, endp - p);
9356 markers = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
9357 if (VEC_empty(static_tracepoint_marker_p, markers))
9358 error (_("No known static tracepoint marker named %s"),
9359 marker_str.c_str ());
9361 std::vector<symtab_and_line> sals;
9362 sals.reserve (VEC_length(static_tracepoint_marker_p, markers));
9364 for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++)
9366 struct static_tracepoint_marker *marker;
9368 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9370 symtab_and_line sal = find_pc_line (marker->address, 0);
9371 sal.pc = marker->address;
9372 sals.push_back (sal);
9374 release_static_tracepoint_marker (marker);
9381 /* See breakpoint.h. */
9384 create_breakpoint (struct gdbarch *gdbarch,
9385 const struct event_location *location,
9386 const char *cond_string,
9387 int thread, const char *extra_string,
9389 int tempflag, enum bptype type_wanted,
9391 enum auto_boolean pending_break_support,
9392 const struct breakpoint_ops *ops,
9393 int from_tty, int enabled, int internal,
9396 struct linespec_result canonical;
9397 struct cleanup *bkpt_chain = NULL;
9400 int prev_bkpt_count = breakpoint_count;
9402 gdb_assert (ops != NULL);
9404 /* If extra_string isn't useful, set it to NULL. */
9405 if (extra_string != NULL && *extra_string == '\0')
9406 extra_string = NULL;
9410 ops->create_sals_from_location (location, &canonical, type_wanted);
9412 CATCH (e, RETURN_MASK_ERROR)
9414 /* If caller is interested in rc value from parse, set
9416 if (e.error == NOT_FOUND_ERROR)
9418 /* If pending breakpoint support is turned off, throw
9421 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9422 throw_exception (e);
9424 exception_print (gdb_stderr, e);
9426 /* If pending breakpoint support is auto query and the user
9427 selects no, then simply return the error code. */
9428 if (pending_break_support == AUTO_BOOLEAN_AUTO
9429 && !nquery (_("Make %s pending on future shared library load? "),
9430 bptype_string (type_wanted)))
9433 /* At this point, either the user was queried about setting
9434 a pending breakpoint and selected yes, or pending
9435 breakpoint behavior is on and thus a pending breakpoint
9436 is defaulted on behalf of the user. */
9440 throw_exception (e);
9444 if (!pending && canonical.lsals.empty ())
9447 /* ----------------------------- SNIP -----------------------------
9448 Anything added to the cleanup chain beyond this point is assumed
9449 to be part of a breakpoint. If the breakpoint create succeeds
9450 then the memory is not reclaimed. */
9451 bkpt_chain = make_cleanup (null_cleanup, 0);
9453 /* Resolve all line numbers to PC's and verify that the addresses
9454 are ok for the target. */
9457 for (auto &lsal : canonical.lsals)
9458 breakpoint_sals_to_pc (lsal.sals);
9461 /* Fast tracepoints may have additional restrictions on location. */
9462 if (!pending && type_wanted == bp_fast_tracepoint)
9464 for (const auto &lsal : canonical.lsals)
9465 check_fast_tracepoint_sals (gdbarch, lsal.sals);
9468 /* Verify that condition can be parsed, before setting any
9469 breakpoints. Allocate a separate condition expression for each
9473 gdb::unique_xmalloc_ptr<char> cond_string_copy;
9474 gdb::unique_xmalloc_ptr<char> extra_string_copy;
9481 const linespec_sals &lsal = canonical.lsals[0];
9483 /* Here we only parse 'arg' to separate condition
9484 from thread number, so parsing in context of first
9485 sal is OK. When setting the breakpoint we'll
9486 re-parse it in context of each sal. */
9488 find_condition_and_thread (extra_string, lsal.sals[0].pc,
9489 &cond, &thread, &task, &rest);
9490 cond_string_copy.reset (cond);
9491 extra_string_copy.reset (rest);
9495 if (type_wanted != bp_dprintf
9496 && extra_string != NULL && *extra_string != '\0')
9497 error (_("Garbage '%s' at end of location"), extra_string);
9499 /* Create a private copy of condition string. */
9501 cond_string_copy.reset (xstrdup (cond_string));
9502 /* Create a private copy of any extra string. */
9504 extra_string_copy.reset (xstrdup (extra_string));
9507 ops->create_breakpoints_sal (gdbarch, &canonical,
9508 std::move (cond_string_copy),
9509 std::move (extra_string_copy),
9511 tempflag ? disp_del : disp_donttouch,
9512 thread, task, ignore_count, ops,
9513 from_tty, enabled, internal, flags);
9517 std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted);
9519 init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops);
9520 b->location = copy_event_location (location);
9523 b->cond_string = NULL;
9526 /* Create a private copy of condition string. */
9527 b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL;
9531 /* Create a private copy of any extra string. */
9532 b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL;
9533 b->ignore_count = ignore_count;
9534 b->disposition = tempflag ? disp_del : disp_donttouch;
9535 b->condition_not_parsed = 1;
9536 b->enable_state = enabled ? bp_enabled : bp_disabled;
9537 if ((type_wanted != bp_breakpoint
9538 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9539 b->pspace = current_program_space;
9541 install_breakpoint (internal, std::move (b), 0);
9544 if (canonical.lsals.size () > 1)
9546 warning (_("Multiple breakpoints were set.\nUse the "
9547 "\"delete\" command to delete unwanted breakpoints."));
9548 prev_breakpoint_count = prev_bkpt_count;
9551 /* That's it. Discard the cleanups for data inserted into the
9553 discard_cleanups (bkpt_chain);
9555 /* error call may happen here - have BKPT_CHAIN already discarded. */
9556 update_global_location_list (UGLL_MAY_INSERT);
9561 /* Set a breakpoint.
9562 ARG is a string describing breakpoint address,
9563 condition, and thread.
9564 FLAG specifies if a breakpoint is hardware on,
9565 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9569 break_command_1 (const char *arg, int flag, int from_tty)
9571 int tempflag = flag & BP_TEMPFLAG;
9572 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9573 ? bp_hardware_breakpoint
9575 struct breakpoint_ops *ops;
9577 event_location_up location = string_to_event_location (&arg, current_language);
9579 /* Matching breakpoints on probes. */
9580 if (location != NULL
9581 && event_location_type (location.get ()) == PROBE_LOCATION)
9582 ops = &bkpt_probe_breakpoint_ops;
9584 ops = &bkpt_breakpoint_ops;
9586 create_breakpoint (get_current_arch (),
9588 NULL, 0, arg, 1 /* parse arg */,
9589 tempflag, type_wanted,
9590 0 /* Ignore count */,
9591 pending_break_support,
9599 /* Helper function for break_command_1 and disassemble_command. */
9602 resolve_sal_pc (struct symtab_and_line *sal)
9606 if (sal->pc == 0 && sal->symtab != NULL)
9608 if (!find_line_pc (sal->symtab, sal->line, &pc))
9609 error (_("No line %d in file \"%s\"."),
9610 sal->line, symtab_to_filename_for_display (sal->symtab));
9613 /* If this SAL corresponds to a breakpoint inserted using a line
9614 number, then skip the function prologue if necessary. */
9615 if (sal->explicit_line)
9616 skip_prologue_sal (sal);
9619 if (sal->section == 0 && sal->symtab != NULL)
9621 const struct blockvector *bv;
9622 const struct block *b;
9625 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9626 SYMTAB_COMPUNIT (sal->symtab));
9629 sym = block_linkage_function (b);
9632 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
9633 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
9638 /* It really is worthwhile to have the section, so we'll
9639 just have to look harder. This case can be executed
9640 if we have line numbers but no functions (as can
9641 happen in assembly source). */
9643 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9644 switch_to_program_space_and_thread (sal->pspace);
9646 bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
9648 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9655 break_command (char *arg, int from_tty)
9657 break_command_1 (arg, 0, from_tty);
9661 tbreak_command (char *arg, int from_tty)
9663 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9667 hbreak_command (char *arg, int from_tty)
9669 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9673 thbreak_command (char *arg, int from_tty)
9675 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9679 stop_command (char *arg, int from_tty)
9681 printf_filtered (_("Specify the type of breakpoint to set.\n\
9682 Usage: stop in <function | address>\n\
9683 stop at <line>\n"));
9687 stopin_command (const char *arg, int from_tty)
9691 if (arg == (char *) NULL)
9693 else if (*arg != '*')
9695 const char *argptr = arg;
9698 /* Look for a ':'. If this is a line number specification, then
9699 say it is bad, otherwise, it should be an address or
9700 function/method name. */
9701 while (*argptr && !hasColon)
9703 hasColon = (*argptr == ':');
9708 badInput = (*argptr != ':'); /* Not a class::method */
9710 badInput = isdigit (*arg); /* a simple line number */
9714 printf_filtered (_("Usage: stop in <function | address>\n"));
9716 break_command_1 (arg, 0, from_tty);
9720 stopat_command (const char *arg, int from_tty)
9724 if (arg == (char *) NULL || *arg == '*') /* no line number */
9728 const char *argptr = arg;
9731 /* Look for a ':'. If there is a '::' then get out, otherwise
9732 it is probably a line number. */
9733 while (*argptr && !hasColon)
9735 hasColon = (*argptr == ':');
9740 badInput = (*argptr == ':'); /* we have class::method */
9742 badInput = !isdigit (*arg); /* not a line number */
9746 printf_filtered (_("Usage: stop at <line>\n"));
9748 break_command_1 (arg, 0, from_tty);
9751 /* The dynamic printf command is mostly like a regular breakpoint, but
9752 with a prewired command list consisting of a single output command,
9753 built from extra arguments supplied on the dprintf command
9757 dprintf_command (char *arg_in, int from_tty)
9759 const char *arg = arg_in;
9760 event_location_up location = string_to_event_location (&arg, current_language);
9762 /* If non-NULL, ARG should have been advanced past the location;
9763 the next character must be ','. */
9766 if (arg[0] != ',' || arg[1] == '\0')
9767 error (_("Format string required"));
9770 /* Skip the comma. */
9775 create_breakpoint (get_current_arch (),
9777 NULL, 0, arg, 1 /* parse arg */,
9779 0 /* Ignore count */,
9780 pending_break_support,
9781 &dprintf_breakpoint_ops,
9789 agent_printf_command (char *arg, int from_tty)
9791 error (_("May only run agent-printf on the target"));
9794 /* Implement the "breakpoint_hit" breakpoint_ops method for
9795 ranged breakpoints. */
9798 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9799 struct address_space *aspace,
9801 const struct target_waitstatus *ws)
9803 if (ws->kind != TARGET_WAITKIND_STOPPED
9804 || ws->value.sig != GDB_SIGNAL_TRAP)
9807 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9808 bl->length, aspace, bp_addr);
9811 /* Implement the "resources_needed" breakpoint_ops method for
9812 ranged breakpoints. */
9815 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9817 return target_ranged_break_num_registers ();
9820 /* Implement the "print_it" breakpoint_ops method for
9821 ranged breakpoints. */
9823 static enum print_stop_action
9824 print_it_ranged_breakpoint (bpstat bs)
9826 struct breakpoint *b = bs->breakpoint_at;
9827 struct bp_location *bl = b->loc;
9828 struct ui_out *uiout = current_uiout;
9830 gdb_assert (b->type == bp_hardware_breakpoint);
9832 /* Ranged breakpoints have only one location. */
9833 gdb_assert (bl && bl->next == NULL);
9835 annotate_breakpoint (b->number);
9837 maybe_print_thread_hit_breakpoint (uiout);
9839 if (b->disposition == disp_del)
9840 uiout->text ("Temporary ranged breakpoint ");
9842 uiout->text ("Ranged breakpoint ");
9843 if (uiout->is_mi_like_p ())
9845 uiout->field_string ("reason",
9846 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9847 uiout->field_string ("disp", bpdisp_text (b->disposition));
9849 uiout->field_int ("bkptno", b->number);
9852 return PRINT_SRC_AND_LOC;
9855 /* Implement the "print_one" breakpoint_ops method for
9856 ranged breakpoints. */
9859 print_one_ranged_breakpoint (struct breakpoint *b,
9860 struct bp_location **last_loc)
9862 struct bp_location *bl = b->loc;
9863 struct value_print_options opts;
9864 struct ui_out *uiout = current_uiout;
9866 /* Ranged breakpoints have only one location. */
9867 gdb_assert (bl && bl->next == NULL);
9869 get_user_print_options (&opts);
9871 if (opts.addressprint)
9872 /* We don't print the address range here, it will be printed later
9873 by print_one_detail_ranged_breakpoint. */
9874 uiout->field_skip ("addr");
9876 print_breakpoint_location (b, bl);
9880 /* Implement the "print_one_detail" breakpoint_ops method for
9881 ranged breakpoints. */
9884 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9885 struct ui_out *uiout)
9887 CORE_ADDR address_start, address_end;
9888 struct bp_location *bl = b->loc;
9893 address_start = bl->address;
9894 address_end = address_start + bl->length - 1;
9896 uiout->text ("\taddress range: ");
9897 stb.printf ("[%s, %s]",
9898 print_core_address (bl->gdbarch, address_start),
9899 print_core_address (bl->gdbarch, address_end));
9900 uiout->field_stream ("addr", stb);
9904 /* Implement the "print_mention" breakpoint_ops method for
9905 ranged breakpoints. */
9908 print_mention_ranged_breakpoint (struct breakpoint *b)
9910 struct bp_location *bl = b->loc;
9911 struct ui_out *uiout = current_uiout;
9914 gdb_assert (b->type == bp_hardware_breakpoint);
9916 if (uiout->is_mi_like_p ())
9919 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9920 b->number, paddress (bl->gdbarch, bl->address),
9921 paddress (bl->gdbarch, bl->address + bl->length - 1));
9924 /* Implement the "print_recreate" breakpoint_ops method for
9925 ranged breakpoints. */
9928 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9930 fprintf_unfiltered (fp, "break-range %s, %s",
9931 event_location_to_string (b->location.get ()),
9932 event_location_to_string (b->location_range_end.get ()));
9933 print_recreate_thread (b, fp);
9936 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9938 static struct breakpoint_ops ranged_breakpoint_ops;
9940 /* Find the address where the end of the breakpoint range should be
9941 placed, given the SAL of the end of the range. This is so that if
9942 the user provides a line number, the end of the range is set to the
9943 last instruction of the given line. */
9946 find_breakpoint_range_end (struct symtab_and_line sal)
9950 /* If the user provided a PC value, use it. Otherwise,
9951 find the address of the end of the given location. */
9952 if (sal.explicit_pc)
9959 ret = find_line_pc_range (sal, &start, &end);
9961 error (_("Could not find location of the end of the range."));
9963 /* find_line_pc_range returns the start of the next line. */
9970 /* Implement the "break-range" CLI command. */
9973 break_range_command (char *arg_in, int from_tty)
9975 const char *arg = arg_in;
9976 const char *arg_start;
9977 struct linespec_result canonical_start, canonical_end;
9978 int bp_count, can_use_bp, length;
9980 struct breakpoint *b;
9982 /* We don't support software ranged breakpoints. */
9983 if (target_ranged_break_num_registers () < 0)
9984 error (_("This target does not support hardware ranged breakpoints."));
9986 bp_count = hw_breakpoint_used_count ();
9987 bp_count += target_ranged_break_num_registers ();
9988 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9991 error (_("Hardware breakpoints used exceeds limit."));
9993 arg = skip_spaces (arg);
9994 if (arg == NULL || arg[0] == '\0')
9995 error(_("No address range specified."));
9998 event_location_up start_location = string_to_event_location (&arg,
10000 parse_breakpoint_sals (start_location.get (), &canonical_start);
10003 error (_("Too few arguments."));
10004 else if (canonical_start.lsals.empty ())
10005 error (_("Could not find location of the beginning of the range."));
10007 const linespec_sals &lsal_start = canonical_start.lsals[0];
10009 if (canonical_start.lsals.size () > 1
10010 || lsal_start.sals.size () != 1)
10011 error (_("Cannot create a ranged breakpoint with multiple locations."));
10013 const symtab_and_line &sal_start = lsal_start.sals[0];
10014 std::string addr_string_start (arg_start, arg - arg_start);
10016 arg++; /* Skip the comma. */
10017 arg = skip_spaces (arg);
10019 /* Parse the end location. */
10023 /* We call decode_line_full directly here instead of using
10024 parse_breakpoint_sals because we need to specify the start location's
10025 symtab and line as the default symtab and line for the end of the
10026 range. This makes it possible to have ranges like "foo.c:27, +14",
10027 where +14 means 14 lines from the start location. */
10028 event_location_up end_location = string_to_event_location (&arg,
10030 decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
10031 sal_start.symtab, sal_start.line,
10032 &canonical_end, NULL, NULL);
10034 if (canonical_end.lsals.empty ())
10035 error (_("Could not find location of the end of the range."));
10037 const linespec_sals &lsal_end = canonical_end.lsals[0];
10038 if (canonical_end.lsals.size () > 1
10039 || lsal_end.sals.size () != 1)
10040 error (_("Cannot create a ranged breakpoint with multiple locations."));
10042 const symtab_and_line &sal_end = lsal_end.sals[0];
10044 end = find_breakpoint_range_end (sal_end);
10045 if (sal_start.pc > end)
10046 error (_("Invalid address range, end precedes start."));
10048 length = end - sal_start.pc + 1;
10050 /* Length overflowed. */
10051 error (_("Address range too large."));
10052 else if (length == 1)
10054 /* This range is simple enough to be handled by
10055 the `hbreak' command. */
10056 hbreak_command (&addr_string_start[0], 1);
10061 /* Now set up the breakpoint. */
10062 b = set_raw_breakpoint (get_current_arch (), sal_start,
10063 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10064 set_breakpoint_count (breakpoint_count + 1);
10065 b->number = breakpoint_count;
10066 b->disposition = disp_donttouch;
10067 b->location = std::move (start_location);
10068 b->location_range_end = std::move (end_location);
10069 b->loc->length = length;
10072 observer_notify_breakpoint_created (b);
10073 update_global_location_list (UGLL_MAY_INSERT);
10076 /* Return non-zero if EXP is verified as constant. Returned zero
10077 means EXP is variable. Also the constant detection may fail for
10078 some constant expressions and in such case still falsely return
10082 watchpoint_exp_is_const (const struct expression *exp)
10084 int i = exp->nelts;
10090 /* We are only interested in the descriptor of each element. */
10091 operator_length (exp, i, &oplenp, &argsp);
10094 switch (exp->elts[i].opcode)
10104 case BINOP_LOGICAL_AND:
10105 case BINOP_LOGICAL_OR:
10106 case BINOP_BITWISE_AND:
10107 case BINOP_BITWISE_IOR:
10108 case BINOP_BITWISE_XOR:
10110 case BINOP_NOTEQUAL:
10136 case OP_OBJC_NSSTRING:
10139 case UNOP_LOGICAL_NOT:
10140 case UNOP_COMPLEMENT:
10145 case UNOP_CAST_TYPE:
10146 case UNOP_REINTERPRET_CAST:
10147 case UNOP_DYNAMIC_CAST:
10148 /* Unary, binary and ternary operators: We have to check
10149 their operands. If they are constant, then so is the
10150 result of that operation. For instance, if A and B are
10151 determined to be constants, then so is "A + B".
10153 UNOP_IND is one exception to the rule above, because the
10154 value of *ADDR is not necessarily a constant, even when
10159 /* Check whether the associated symbol is a constant.
10161 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10162 possible that a buggy compiler could mark a variable as
10163 constant even when it is not, and TYPE_CONST would return
10164 true in this case, while SYMBOL_CLASS wouldn't.
10166 We also have to check for function symbols because they
10167 are always constant. */
10169 struct symbol *s = exp->elts[i + 2].symbol;
10171 if (SYMBOL_CLASS (s) != LOC_BLOCK
10172 && SYMBOL_CLASS (s) != LOC_CONST
10173 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10178 /* The default action is to return 0 because we are using
10179 the optimistic approach here: If we don't know something,
10180 then it is not a constant. */
10189 /* Watchpoint destructor. */
10191 watchpoint::~watchpoint ()
10193 xfree (this->exp_string);
10194 xfree (this->exp_string_reparse);
10195 value_free (this->val);
10198 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10201 re_set_watchpoint (struct breakpoint *b)
10203 struct watchpoint *w = (struct watchpoint *) b;
10205 /* Watchpoint can be either on expression using entirely global
10206 variables, or it can be on local variables.
10208 Watchpoints of the first kind are never auto-deleted, and even
10209 persist across program restarts. Since they can use variables
10210 from shared libraries, we need to reparse expression as libraries
10211 are loaded and unloaded.
10213 Watchpoints on local variables can also change meaning as result
10214 of solib event. For example, if a watchpoint uses both a local
10215 and a global variables in expression, it's a local watchpoint,
10216 but unloading of a shared library will make the expression
10217 invalid. This is not a very common use case, but we still
10218 re-evaluate expression, to avoid surprises to the user.
10220 Note that for local watchpoints, we re-evaluate it only if
10221 watchpoints frame id is still valid. If it's not, it means the
10222 watchpoint is out of scope and will be deleted soon. In fact,
10223 I'm not sure we'll ever be called in this case.
10225 If a local watchpoint's frame id is still valid, then
10226 w->exp_valid_block is likewise valid, and we can safely use it.
10228 Don't do anything about disabled watchpoints, since they will be
10229 reevaluated again when enabled. */
10230 update_watchpoint (w, 1 /* reparse */);
10233 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10236 insert_watchpoint (struct bp_location *bl)
10238 struct watchpoint *w = (struct watchpoint *) bl->owner;
10239 int length = w->exact ? 1 : bl->length;
10241 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10242 w->cond_exp.get ());
10245 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10248 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10250 struct watchpoint *w = (struct watchpoint *) bl->owner;
10251 int length = w->exact ? 1 : bl->length;
10253 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10254 w->cond_exp.get ());
10258 breakpoint_hit_watchpoint (const struct bp_location *bl,
10259 struct address_space *aspace, CORE_ADDR bp_addr,
10260 const struct target_waitstatus *ws)
10262 struct breakpoint *b = bl->owner;
10263 struct watchpoint *w = (struct watchpoint *) b;
10265 /* Continuable hardware watchpoints are treated as non-existent if the
10266 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10267 some data address). Otherwise gdb won't stop on a break instruction
10268 in the code (not from a breakpoint) when a hardware watchpoint has
10269 been defined. Also skip watchpoints which we know did not trigger
10270 (did not match the data address). */
10271 if (is_hardware_watchpoint (b)
10272 && w->watchpoint_triggered == watch_triggered_no)
10279 check_status_watchpoint (bpstat bs)
10281 gdb_assert (is_watchpoint (bs->breakpoint_at));
10283 bpstat_check_watchpoint (bs);
10286 /* Implement the "resources_needed" breakpoint_ops method for
10287 hardware watchpoints. */
10290 resources_needed_watchpoint (const struct bp_location *bl)
10292 struct watchpoint *w = (struct watchpoint *) bl->owner;
10293 int length = w->exact? 1 : bl->length;
10295 return target_region_ok_for_hw_watchpoint (bl->address, length);
10298 /* Implement the "works_in_software_mode" breakpoint_ops method for
10299 hardware watchpoints. */
10302 works_in_software_mode_watchpoint (const struct breakpoint *b)
10304 /* Read and access watchpoints only work with hardware support. */
10305 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10308 static enum print_stop_action
10309 print_it_watchpoint (bpstat bs)
10311 struct breakpoint *b;
10312 enum print_stop_action result;
10313 struct watchpoint *w;
10314 struct ui_out *uiout = current_uiout;
10316 gdb_assert (bs->bp_location_at != NULL);
10318 b = bs->breakpoint_at;
10319 w = (struct watchpoint *) b;
10321 annotate_watchpoint (b->number);
10322 maybe_print_thread_hit_breakpoint (uiout);
10326 gdb::optional<ui_out_emit_tuple> tuple_emitter;
10329 case bp_watchpoint:
10330 case bp_hardware_watchpoint:
10331 if (uiout->is_mi_like_p ())
10332 uiout->field_string
10333 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10335 tuple_emitter.emplace (uiout, "value");
10336 uiout->text ("\nOld value = ");
10337 watchpoint_value_print (bs->old_val, &stb);
10338 uiout->field_stream ("old", stb);
10339 uiout->text ("\nNew value = ");
10340 watchpoint_value_print (w->val, &stb);
10341 uiout->field_stream ("new", stb);
10342 uiout->text ("\n");
10343 /* More than one watchpoint may have been triggered. */
10344 result = PRINT_UNKNOWN;
10347 case bp_read_watchpoint:
10348 if (uiout->is_mi_like_p ())
10349 uiout->field_string
10350 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10352 tuple_emitter.emplace (uiout, "value");
10353 uiout->text ("\nValue = ");
10354 watchpoint_value_print (w->val, &stb);
10355 uiout->field_stream ("value", stb);
10356 uiout->text ("\n");
10357 result = PRINT_UNKNOWN;
10360 case bp_access_watchpoint:
10361 if (bs->old_val != NULL)
10363 if (uiout->is_mi_like_p ())
10364 uiout->field_string
10366 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10368 tuple_emitter.emplace (uiout, "value");
10369 uiout->text ("\nOld value = ");
10370 watchpoint_value_print (bs->old_val, &stb);
10371 uiout->field_stream ("old", stb);
10372 uiout->text ("\nNew value = ");
10377 if (uiout->is_mi_like_p ())
10378 uiout->field_string
10380 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10381 tuple_emitter.emplace (uiout, "value");
10382 uiout->text ("\nValue = ");
10384 watchpoint_value_print (w->val, &stb);
10385 uiout->field_stream ("new", stb);
10386 uiout->text ("\n");
10387 result = PRINT_UNKNOWN;
10390 result = PRINT_UNKNOWN;
10396 /* Implement the "print_mention" breakpoint_ops method for hardware
10400 print_mention_watchpoint (struct breakpoint *b)
10402 struct watchpoint *w = (struct watchpoint *) b;
10403 struct ui_out *uiout = current_uiout;
10404 const char *tuple_name;
10408 case bp_watchpoint:
10409 uiout->text ("Watchpoint ");
10410 tuple_name = "wpt";
10412 case bp_hardware_watchpoint:
10413 uiout->text ("Hardware watchpoint ");
10414 tuple_name = "wpt";
10416 case bp_read_watchpoint:
10417 uiout->text ("Hardware read watchpoint ");
10418 tuple_name = "hw-rwpt";
10420 case bp_access_watchpoint:
10421 uiout->text ("Hardware access (read/write) watchpoint ");
10422 tuple_name = "hw-awpt";
10425 internal_error (__FILE__, __LINE__,
10426 _("Invalid hardware watchpoint type."));
10429 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10430 uiout->field_int ("number", b->number);
10431 uiout->text (": ");
10432 uiout->field_string ("exp", w->exp_string);
10435 /* Implement the "print_recreate" breakpoint_ops method for
10439 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10441 struct watchpoint *w = (struct watchpoint *) b;
10445 case bp_watchpoint:
10446 case bp_hardware_watchpoint:
10447 fprintf_unfiltered (fp, "watch");
10449 case bp_read_watchpoint:
10450 fprintf_unfiltered (fp, "rwatch");
10452 case bp_access_watchpoint:
10453 fprintf_unfiltered (fp, "awatch");
10456 internal_error (__FILE__, __LINE__,
10457 _("Invalid watchpoint type."));
10460 fprintf_unfiltered (fp, " %s", w->exp_string);
10461 print_recreate_thread (b, fp);
10464 /* Implement the "explains_signal" breakpoint_ops method for
10468 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10470 /* A software watchpoint cannot cause a signal other than
10471 GDB_SIGNAL_TRAP. */
10472 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10478 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10480 static struct breakpoint_ops watchpoint_breakpoint_ops;
10482 /* Implement the "insert" breakpoint_ops method for
10483 masked hardware watchpoints. */
10486 insert_masked_watchpoint (struct bp_location *bl)
10488 struct watchpoint *w = (struct watchpoint *) bl->owner;
10490 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10491 bl->watchpoint_type);
10494 /* Implement the "remove" breakpoint_ops method for
10495 masked hardware watchpoints. */
10498 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10500 struct watchpoint *w = (struct watchpoint *) bl->owner;
10502 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10503 bl->watchpoint_type);
10506 /* Implement the "resources_needed" breakpoint_ops method for
10507 masked hardware watchpoints. */
10510 resources_needed_masked_watchpoint (const struct bp_location *bl)
10512 struct watchpoint *w = (struct watchpoint *) bl->owner;
10514 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10517 /* Implement the "works_in_software_mode" breakpoint_ops method for
10518 masked hardware watchpoints. */
10521 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10526 /* Implement the "print_it" breakpoint_ops method for
10527 masked hardware watchpoints. */
10529 static enum print_stop_action
10530 print_it_masked_watchpoint (bpstat bs)
10532 struct breakpoint *b = bs->breakpoint_at;
10533 struct ui_out *uiout = current_uiout;
10535 /* Masked watchpoints have only one location. */
10536 gdb_assert (b->loc && b->loc->next == NULL);
10538 annotate_watchpoint (b->number);
10539 maybe_print_thread_hit_breakpoint (uiout);
10543 case bp_hardware_watchpoint:
10544 if (uiout->is_mi_like_p ())
10545 uiout->field_string
10546 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10549 case bp_read_watchpoint:
10550 if (uiout->is_mi_like_p ())
10551 uiout->field_string
10552 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10555 case bp_access_watchpoint:
10556 if (uiout->is_mi_like_p ())
10557 uiout->field_string
10559 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10562 internal_error (__FILE__, __LINE__,
10563 _("Invalid hardware watchpoint type."));
10567 uiout->text (_("\n\
10568 Check the underlying instruction at PC for the memory\n\
10569 address and value which triggered this watchpoint.\n"));
10570 uiout->text ("\n");
10572 /* More than one watchpoint may have been triggered. */
10573 return PRINT_UNKNOWN;
10576 /* Implement the "print_one_detail" breakpoint_ops method for
10577 masked hardware watchpoints. */
10580 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10581 struct ui_out *uiout)
10583 struct watchpoint *w = (struct watchpoint *) b;
10585 /* Masked watchpoints have only one location. */
10586 gdb_assert (b->loc && b->loc->next == NULL);
10588 uiout->text ("\tmask ");
10589 uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
10590 uiout->text ("\n");
10593 /* Implement the "print_mention" breakpoint_ops method for
10594 masked hardware watchpoints. */
10597 print_mention_masked_watchpoint (struct breakpoint *b)
10599 struct watchpoint *w = (struct watchpoint *) b;
10600 struct ui_out *uiout = current_uiout;
10601 const char *tuple_name;
10605 case bp_hardware_watchpoint:
10606 uiout->text ("Masked hardware watchpoint ");
10607 tuple_name = "wpt";
10609 case bp_read_watchpoint:
10610 uiout->text ("Masked hardware read watchpoint ");
10611 tuple_name = "hw-rwpt";
10613 case bp_access_watchpoint:
10614 uiout->text ("Masked hardware access (read/write) watchpoint ");
10615 tuple_name = "hw-awpt";
10618 internal_error (__FILE__, __LINE__,
10619 _("Invalid hardware watchpoint type."));
10622 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10623 uiout->field_int ("number", b->number);
10624 uiout->text (": ");
10625 uiout->field_string ("exp", w->exp_string);
10628 /* Implement the "print_recreate" breakpoint_ops method for
10629 masked hardware watchpoints. */
10632 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10634 struct watchpoint *w = (struct watchpoint *) b;
10639 case bp_hardware_watchpoint:
10640 fprintf_unfiltered (fp, "watch");
10642 case bp_read_watchpoint:
10643 fprintf_unfiltered (fp, "rwatch");
10645 case bp_access_watchpoint:
10646 fprintf_unfiltered (fp, "awatch");
10649 internal_error (__FILE__, __LINE__,
10650 _("Invalid hardware watchpoint type."));
10653 sprintf_vma (tmp, w->hw_wp_mask);
10654 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10655 print_recreate_thread (b, fp);
10658 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10660 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10662 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10665 is_masked_watchpoint (const struct breakpoint *b)
10667 return b->ops == &masked_watchpoint_breakpoint_ops;
10670 /* accessflag: hw_write: watch write,
10671 hw_read: watch read,
10672 hw_access: watch access (read or write) */
10674 watch_command_1 (const char *arg, int accessflag, int from_tty,
10675 int just_location, int internal)
10677 struct breakpoint *scope_breakpoint = NULL;
10678 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10679 struct value *val, *mark, *result;
10680 int saved_bitpos = 0, saved_bitsize = 0;
10681 const char *exp_start = NULL;
10682 const char *exp_end = NULL;
10683 const char *tok, *end_tok;
10685 const char *cond_start = NULL;
10686 const char *cond_end = NULL;
10687 enum bptype bp_type;
10690 /* Flag to indicate whether we are going to use masks for
10691 the hardware watchpoint. */
10693 CORE_ADDR mask = 0;
10695 /* Make sure that we actually have parameters to parse. */
10696 if (arg != NULL && arg[0] != '\0')
10698 const char *value_start;
10700 exp_end = arg + strlen (arg);
10702 /* Look for "parameter value" pairs at the end
10703 of the arguments string. */
10704 for (tok = exp_end - 1; tok > arg; tok--)
10706 /* Skip whitespace at the end of the argument list. */
10707 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10710 /* Find the beginning of the last token.
10711 This is the value of the parameter. */
10712 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10714 value_start = tok + 1;
10716 /* Skip whitespace. */
10717 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10722 /* Find the beginning of the second to last token.
10723 This is the parameter itself. */
10724 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10727 toklen = end_tok - tok + 1;
10729 if (toklen == 6 && startswith (tok, "thread"))
10731 struct thread_info *thr;
10732 /* At this point we've found a "thread" token, which means
10733 the user is trying to set a watchpoint that triggers
10734 only in a specific thread. */
10738 error(_("You can specify only one thread."));
10740 /* Extract the thread ID from the next token. */
10741 thr = parse_thread_id (value_start, &endp);
10743 /* Check if the user provided a valid thread ID. */
10744 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10745 invalid_thread_id_error (value_start);
10747 thread = thr->global_num;
10749 else if (toklen == 4 && startswith (tok, "mask"))
10751 /* We've found a "mask" token, which means the user wants to
10752 create a hardware watchpoint that is going to have the mask
10754 struct value *mask_value, *mark;
10757 error(_("You can specify only one mask."));
10759 use_mask = just_location = 1;
10761 mark = value_mark ();
10762 mask_value = parse_to_comma_and_eval (&value_start);
10763 mask = value_as_address (mask_value);
10764 value_free_to_mark (mark);
10767 /* We didn't recognize what we found. We should stop here. */
10770 /* Truncate the string and get rid of the "parameter value" pair before
10771 the arguments string is parsed by the parse_exp_1 function. */
10778 /* Parse the rest of the arguments. From here on out, everything
10779 is in terms of a newly allocated string instead of the original
10781 innermost_block = NULL;
10782 std::string expression (arg, exp_end - arg);
10783 exp_start = arg = expression.c_str ();
10784 expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
10786 /* Remove trailing whitespace from the expression before saving it.
10787 This makes the eventual display of the expression string a bit
10789 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10792 /* Checking if the expression is not constant. */
10793 if (watchpoint_exp_is_const (exp.get ()))
10797 len = exp_end - exp_start;
10798 while (len > 0 && isspace (exp_start[len - 1]))
10800 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10803 exp_valid_block = innermost_block;
10804 mark = value_mark ();
10805 fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location);
10807 if (val != NULL && just_location)
10809 saved_bitpos = value_bitpos (val);
10810 saved_bitsize = value_bitsize (val);
10817 exp_valid_block = NULL;
10818 val = value_addr (result);
10819 release_value (val);
10820 value_free_to_mark (mark);
10824 ret = target_masked_watch_num_registers (value_as_address (val),
10827 error (_("This target does not support masked watchpoints."));
10828 else if (ret == -2)
10829 error (_("Invalid mask or memory region."));
10832 else if (val != NULL)
10833 release_value (val);
10835 tok = skip_spaces (arg);
10836 end_tok = skip_to_space (tok);
10838 toklen = end_tok - tok;
10839 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10841 innermost_block = NULL;
10842 tok = cond_start = end_tok + 1;
10843 parse_exp_1 (&tok, 0, 0, 0);
10845 /* The watchpoint expression may not be local, but the condition
10846 may still be. E.g.: `watch global if local > 0'. */
10847 cond_exp_valid_block = innermost_block;
10852 error (_("Junk at end of command."));
10854 frame_info *wp_frame = block_innermost_frame (exp_valid_block);
10856 /* Save this because create_internal_breakpoint below invalidates
10858 frame_id watchpoint_frame = get_frame_id (wp_frame);
10860 /* If the expression is "local", then set up a "watchpoint scope"
10861 breakpoint at the point where we've left the scope of the watchpoint
10862 expression. Create the scope breakpoint before the watchpoint, so
10863 that we will encounter it first in bpstat_stop_status. */
10864 if (exp_valid_block != NULL && wp_frame != NULL)
10866 frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
10868 if (frame_id_p (caller_frame_id))
10870 gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
10871 CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
10874 = create_internal_breakpoint (caller_arch, caller_pc,
10875 bp_watchpoint_scope,
10876 &momentary_breakpoint_ops);
10878 /* create_internal_breakpoint could invalidate WP_FRAME. */
10881 scope_breakpoint->enable_state = bp_enabled;
10883 /* Automatically delete the breakpoint when it hits. */
10884 scope_breakpoint->disposition = disp_del;
10886 /* Only break in the proper frame (help with recursion). */
10887 scope_breakpoint->frame_id = caller_frame_id;
10889 /* Set the address at which we will stop. */
10890 scope_breakpoint->loc->gdbarch = caller_arch;
10891 scope_breakpoint->loc->requested_address = caller_pc;
10892 scope_breakpoint->loc->address
10893 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10894 scope_breakpoint->loc->requested_address,
10895 scope_breakpoint->type);
10899 /* Now set up the breakpoint. We create all watchpoints as hardware
10900 watchpoints here even if hardware watchpoints are turned off, a call
10901 to update_watchpoint later in this function will cause the type to
10902 drop back to bp_watchpoint (software watchpoint) if required. */
10904 if (accessflag == hw_read)
10905 bp_type = bp_read_watchpoint;
10906 else if (accessflag == hw_access)
10907 bp_type = bp_access_watchpoint;
10909 bp_type = bp_hardware_watchpoint;
10911 std::unique_ptr<watchpoint> w (new watchpoint ());
10914 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10915 &masked_watchpoint_breakpoint_ops);
10917 init_raw_breakpoint_without_location (w.get (), NULL, bp_type,
10918 &watchpoint_breakpoint_ops);
10919 w->thread = thread;
10920 w->disposition = disp_donttouch;
10921 w->pspace = current_program_space;
10922 w->exp = std::move (exp);
10923 w->exp_valid_block = exp_valid_block;
10924 w->cond_exp_valid_block = cond_exp_valid_block;
10927 struct type *t = value_type (val);
10928 CORE_ADDR addr = value_as_address (val);
10930 w->exp_string_reparse
10931 = current_language->la_watch_location_expression (t, addr).release ();
10933 w->exp_string = xstrprintf ("-location %.*s",
10934 (int) (exp_end - exp_start), exp_start);
10937 w->exp_string = savestring (exp_start, exp_end - exp_start);
10941 w->hw_wp_mask = mask;
10946 w->val_bitpos = saved_bitpos;
10947 w->val_bitsize = saved_bitsize;
10952 w->cond_string = savestring (cond_start, cond_end - cond_start);
10954 w->cond_string = 0;
10956 if (frame_id_p (watchpoint_frame))
10958 w->watchpoint_frame = watchpoint_frame;
10959 w->watchpoint_thread = inferior_ptid;
10963 w->watchpoint_frame = null_frame_id;
10964 w->watchpoint_thread = null_ptid;
10967 if (scope_breakpoint != NULL)
10969 /* The scope breakpoint is related to the watchpoint. We will
10970 need to act on them together. */
10971 w->related_breakpoint = scope_breakpoint;
10972 scope_breakpoint->related_breakpoint = w.get ();
10975 if (!just_location)
10976 value_free_to_mark (mark);
10978 /* Finally update the new watchpoint. This creates the locations
10979 that should be inserted. */
10980 update_watchpoint (w.get (), 1);
10982 install_breakpoint (internal, std::move (w), 1);
10985 /* Return count of debug registers needed to watch the given expression.
10986 If the watchpoint cannot be handled in hardware return zero. */
10989 can_use_hardware_watchpoint (struct value *v)
10991 int found_memory_cnt = 0;
10992 struct value *head = v;
10994 /* Did the user specifically forbid us to use hardware watchpoints? */
10995 if (!can_use_hw_watchpoints)
10998 /* Make sure that the value of the expression depends only upon
10999 memory contents, and values computed from them within GDB. If we
11000 find any register references or function calls, we can't use a
11001 hardware watchpoint.
11003 The idea here is that evaluating an expression generates a series
11004 of values, one holding the value of every subexpression. (The
11005 expression a*b+c has five subexpressions: a, b, a*b, c, and
11006 a*b+c.) GDB's values hold almost enough information to establish
11007 the criteria given above --- they identify memory lvalues,
11008 register lvalues, computed values, etcetera. So we can evaluate
11009 the expression, and then scan the chain of values that leaves
11010 behind to decide whether we can detect any possible change to the
11011 expression's final value using only hardware watchpoints.
11013 However, I don't think that the values returned by inferior
11014 function calls are special in any way. So this function may not
11015 notice that an expression involving an inferior function call
11016 can't be watched with hardware watchpoints. FIXME. */
11017 for (; v; v = value_next (v))
11019 if (VALUE_LVAL (v) == lval_memory)
11021 if (v != head && value_lazy (v))
11022 /* A lazy memory lvalue in the chain is one that GDB never
11023 needed to fetch; we either just used its address (e.g.,
11024 `a' in `a.b') or we never needed it at all (e.g., `a'
11025 in `a,b'). This doesn't apply to HEAD; if that is
11026 lazy then it was not readable, but watch it anyway. */
11030 /* Ahh, memory we actually used! Check if we can cover
11031 it with hardware watchpoints. */
11032 struct type *vtype = check_typedef (value_type (v));
11034 /* We only watch structs and arrays if user asked for it
11035 explicitly, never if they just happen to appear in a
11036 middle of some value chain. */
11038 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11039 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11041 CORE_ADDR vaddr = value_address (v);
11045 len = (target_exact_watchpoints
11046 && is_scalar_type_recursive (vtype))?
11047 1 : TYPE_LENGTH (value_type (v));
11049 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11053 found_memory_cnt += num_regs;
11057 else if (VALUE_LVAL (v) != not_lval
11058 && deprecated_value_modifiable (v) == 0)
11059 return 0; /* These are values from the history (e.g., $1). */
11060 else if (VALUE_LVAL (v) == lval_register)
11061 return 0; /* Cannot watch a register with a HW watchpoint. */
11064 /* The expression itself looks suitable for using a hardware
11065 watchpoint, but give the target machine a chance to reject it. */
11066 return found_memory_cnt;
11070 watch_command_wrapper (const char *arg, int from_tty, int internal)
11072 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11075 /* A helper function that looks for the "-location" argument and then
11076 calls watch_command_1. */
11079 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11081 int just_location = 0;
11084 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11085 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11087 arg = skip_spaces (arg);
11091 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11095 watch_command (char *arg, int from_tty)
11097 watch_maybe_just_location (arg, hw_write, from_tty);
11101 rwatch_command_wrapper (const char *arg, int from_tty, int internal)
11103 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11107 rwatch_command (char *arg, int from_tty)
11109 watch_maybe_just_location (arg, hw_read, from_tty);
11113 awatch_command_wrapper (const char *arg, int from_tty, int internal)
11115 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11119 awatch_command (char *arg, int from_tty)
11121 watch_maybe_just_location (arg, hw_access, from_tty);
11125 /* Data for the FSM that manages the until(location)/advance commands
11126 in infcmd.c. Here because it uses the mechanisms of
11129 struct until_break_fsm
11131 /* The base class. */
11132 struct thread_fsm thread_fsm;
11134 /* The thread that as current when the command was executed. */
11137 /* The breakpoint set at the destination location. */
11138 struct breakpoint *location_breakpoint;
11140 /* Breakpoint set at the return address in the caller frame. May be
11142 struct breakpoint *caller_breakpoint;
11145 static void until_break_fsm_clean_up (struct thread_fsm *self,
11146 struct thread_info *thread);
11147 static int until_break_fsm_should_stop (struct thread_fsm *self,
11148 struct thread_info *thread);
11149 static enum async_reply_reason
11150 until_break_fsm_async_reply_reason (struct thread_fsm *self);
11152 /* until_break_fsm's vtable. */
11154 static struct thread_fsm_ops until_break_fsm_ops =
11157 until_break_fsm_clean_up,
11158 until_break_fsm_should_stop,
11159 NULL, /* return_value */
11160 until_break_fsm_async_reply_reason,
11163 /* Allocate a new until_break_command_fsm. */
11165 static struct until_break_fsm *
11166 new_until_break_fsm (struct interp *cmd_interp, int thread,
11167 struct breakpoint *location_breakpoint,
11168 struct breakpoint *caller_breakpoint)
11170 struct until_break_fsm *sm;
11172 sm = XCNEW (struct until_break_fsm);
11173 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
11175 sm->thread = thread;
11176 sm->location_breakpoint = location_breakpoint;
11177 sm->caller_breakpoint = caller_breakpoint;
11182 /* Implementation of the 'should_stop' FSM method for the
11183 until(location)/advance commands. */
11186 until_break_fsm_should_stop (struct thread_fsm *self,
11187 struct thread_info *tp)
11189 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11191 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11192 sm->location_breakpoint) != NULL
11193 || (sm->caller_breakpoint != NULL
11194 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11195 sm->caller_breakpoint) != NULL))
11196 thread_fsm_set_finished (self);
11201 /* Implementation of the 'clean_up' FSM method for the
11202 until(location)/advance commands. */
11205 until_break_fsm_clean_up (struct thread_fsm *self,
11206 struct thread_info *thread)
11208 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11210 /* Clean up our temporary breakpoints. */
11211 if (sm->location_breakpoint != NULL)
11213 delete_breakpoint (sm->location_breakpoint);
11214 sm->location_breakpoint = NULL;
11216 if (sm->caller_breakpoint != NULL)
11218 delete_breakpoint (sm->caller_breakpoint);
11219 sm->caller_breakpoint = NULL;
11221 delete_longjmp_breakpoint (sm->thread);
11224 /* Implementation of the 'async_reply_reason' FSM method for the
11225 until(location)/advance commands. */
11227 static enum async_reply_reason
11228 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11230 return EXEC_ASYNC_LOCATION_REACHED;
11234 until_break_command (const char *arg, int from_tty, int anywhere)
11236 struct frame_info *frame;
11237 struct gdbarch *frame_gdbarch;
11238 struct frame_id stack_frame_id;
11239 struct frame_id caller_frame_id;
11240 struct breakpoint *location_breakpoint;
11241 struct breakpoint *caller_breakpoint = NULL;
11242 struct cleanup *old_chain;
11244 struct thread_info *tp;
11245 struct until_break_fsm *sm;
11247 clear_proceed_status (0);
11249 /* Set a breakpoint where the user wants it and at return from
11252 event_location_up location = string_to_event_location (&arg, current_language);
11254 std::vector<symtab_and_line> sals
11255 = (last_displayed_sal_is_valid ()
11256 ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
11257 get_last_displayed_symtab (),
11258 get_last_displayed_line ())
11259 : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
11260 NULL, (struct symtab *) NULL, 0));
11262 if (sals.size () != 1)
11263 error (_("Couldn't get information on specified line."));
11265 symtab_and_line &sal = sals[0];
11268 error (_("Junk at end of arguments."));
11270 resolve_sal_pc (&sal);
11272 tp = inferior_thread ();
11273 thread = tp->global_num;
11275 old_chain = make_cleanup (null_cleanup, NULL);
11277 /* Note linespec handling above invalidates the frame chain.
11278 Installing a breakpoint also invalidates the frame chain (as it
11279 may need to switch threads), so do any frame handling before
11282 frame = get_selected_frame (NULL);
11283 frame_gdbarch = get_frame_arch (frame);
11284 stack_frame_id = get_stack_frame_id (frame);
11285 caller_frame_id = frame_unwind_caller_id (frame);
11287 /* Keep within the current frame, or in frames called by the current
11290 if (frame_id_p (caller_frame_id))
11292 struct symtab_and_line sal2;
11293 struct gdbarch *caller_gdbarch;
11295 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11296 sal2.pc = frame_unwind_caller_pc (frame);
11297 caller_gdbarch = frame_unwind_caller_arch (frame);
11298 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11302 make_cleanup_delete_breakpoint (caller_breakpoint);
11304 set_longjmp_breakpoint (tp, caller_frame_id);
11305 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11308 /* set_momentary_breakpoint could invalidate FRAME. */
11312 /* If the user told us to continue until a specified location,
11313 we don't specify a frame at which we need to stop. */
11314 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11315 null_frame_id, bp_until);
11317 /* Otherwise, specify the selected frame, because we want to stop
11318 only at the very same frame. */
11319 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11320 stack_frame_id, bp_until);
11321 make_cleanup_delete_breakpoint (location_breakpoint);
11323 sm = new_until_break_fsm (command_interp (), tp->global_num,
11324 location_breakpoint, caller_breakpoint);
11325 tp->thread_fsm = &sm->thread_fsm;
11327 discard_cleanups (old_chain);
11329 proceed (-1, GDB_SIGNAL_DEFAULT);
11332 /* This function attempts to parse an optional "if <cond>" clause
11333 from the arg string. If one is not found, it returns NULL.
11335 Else, it returns a pointer to the condition string. (It does not
11336 attempt to evaluate the string against a particular block.) And,
11337 it updates arg to point to the first character following the parsed
11338 if clause in the arg string. */
11341 ep_parse_optional_if_clause (const char **arg)
11343 const char *cond_string;
11345 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11348 /* Skip the "if" keyword. */
11351 /* Skip any extra leading whitespace, and record the start of the
11352 condition string. */
11353 *arg = skip_spaces (*arg);
11354 cond_string = *arg;
11356 /* Assume that the condition occupies the remainder of the arg
11358 (*arg) += strlen (cond_string);
11360 return cond_string;
11363 /* Commands to deal with catching events, such as signals, exceptions,
11364 process start/exit, etc. */
11368 catch_fork_temporary, catch_vfork_temporary,
11369 catch_fork_permanent, catch_vfork_permanent
11374 catch_fork_command_1 (char *arg_entry, int from_tty,
11375 struct cmd_list_element *command)
11377 const char *arg = arg_entry;
11378 struct gdbarch *gdbarch = get_current_arch ();
11379 const char *cond_string = NULL;
11380 catch_fork_kind fork_kind;
11383 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11384 tempflag = (fork_kind == catch_fork_temporary
11385 || fork_kind == catch_vfork_temporary);
11389 arg = skip_spaces (arg);
11391 /* The allowed syntax is:
11393 catch [v]fork if <cond>
11395 First, check if there's an if clause. */
11396 cond_string = ep_parse_optional_if_clause (&arg);
11398 if ((*arg != '\0') && !isspace (*arg))
11399 error (_("Junk at end of arguments."));
11401 /* If this target supports it, create a fork or vfork catchpoint
11402 and enable reporting of such events. */
11405 case catch_fork_temporary:
11406 case catch_fork_permanent:
11407 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11408 &catch_fork_breakpoint_ops);
11410 case catch_vfork_temporary:
11411 case catch_vfork_permanent:
11412 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11413 &catch_vfork_breakpoint_ops);
11416 error (_("unsupported or unknown fork kind; cannot catch it"));
11422 catch_exec_command_1 (char *arg_entry, int from_tty,
11423 struct cmd_list_element *command)
11425 const char *arg = arg_entry;
11426 struct gdbarch *gdbarch = get_current_arch ();
11428 const char *cond_string = NULL;
11430 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11434 arg = skip_spaces (arg);
11436 /* The allowed syntax is:
11438 catch exec if <cond>
11440 First, check if there's an if clause. */
11441 cond_string = ep_parse_optional_if_clause (&arg);
11443 if ((*arg != '\0') && !isspace (*arg))
11444 error (_("Junk at end of arguments."));
11446 std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ());
11447 init_catchpoint (c.get (), gdbarch, tempflag, cond_string,
11448 &catch_exec_breakpoint_ops);
11449 c->exec_pathname = NULL;
11451 install_breakpoint (0, std::move (c), 1);
11455 init_ada_exception_breakpoint (struct breakpoint *b,
11456 struct gdbarch *gdbarch,
11457 struct symtab_and_line sal,
11458 const char *addr_string,
11459 const struct breakpoint_ops *ops,
11466 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11468 loc_gdbarch = gdbarch;
11470 describe_other_breakpoints (loc_gdbarch,
11471 sal.pspace, sal.pc, sal.section, -1);
11472 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11473 version for exception catchpoints, because two catchpoints
11474 used for different exception names will use the same address.
11475 In this case, a "breakpoint ... also set at..." warning is
11476 unproductive. Besides, the warning phrasing is also a bit
11477 inappropriate, we should use the word catchpoint, and tell
11478 the user what type of catchpoint it is. The above is good
11479 enough for now, though. */
11482 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11484 b->enable_state = enabled ? bp_enabled : bp_disabled;
11485 b->disposition = tempflag ? disp_del : disp_donttouch;
11486 b->location = string_to_event_location (&addr_string,
11487 language_def (language_ada));
11488 b->language = language_ada;
11492 catch_command (const char *arg, int from_tty)
11494 error (_("Catch requires an event name."));
11499 tcatch_command (const char *arg, int from_tty)
11501 error (_("Catch requires an event name."));
11504 /* Compare two breakpoints and return a strcmp-like result. */
11507 compare_breakpoints (const breakpoint *a, const breakpoint *b)
11509 uintptr_t ua = (uintptr_t) a;
11510 uintptr_t ub = (uintptr_t) b;
11512 if (a->number < b->number)
11514 else if (a->number > b->number)
11517 /* Now sort by address, in case we see, e..g, two breakpoints with
11521 return ua > ub ? 1 : 0;
11524 /* Delete breakpoints by address or line. */
11527 clear_command (char *arg, int from_tty)
11529 struct breakpoint *b;
11533 std::vector<symtab_and_line> decoded_sals;
11534 symtab_and_line last_sal;
11535 gdb::array_view<symtab_and_line> sals;
11539 = decode_line_with_current_source (arg,
11540 (DECODE_LINE_FUNFIRSTLINE
11541 | DECODE_LINE_LIST_MODE));
11543 sals = decoded_sals;
11547 /* Set sal's line, symtab, pc, and pspace to the values
11548 corresponding to the last call to print_frame_info. If the
11549 codepoint is not valid, this will set all the fields to 0. */
11550 last_sal = get_last_displayed_sal ();
11551 if (last_sal.symtab == 0)
11552 error (_("No source file specified."));
11558 /* We don't call resolve_sal_pc here. That's not as bad as it
11559 seems, because all existing breakpoints typically have both
11560 file/line and pc set. So, if clear is given file/line, we can
11561 match this to existing breakpoint without obtaining pc at all.
11563 We only support clearing given the address explicitly
11564 present in breakpoint table. Say, we've set breakpoint
11565 at file:line. There were several PC values for that file:line,
11566 due to optimization, all in one block.
11568 We've picked one PC value. If "clear" is issued with another
11569 PC corresponding to the same file:line, the breakpoint won't
11570 be cleared. We probably can still clear the breakpoint, but
11571 since the other PC value is never presented to user, user
11572 can only find it by guessing, and it does not seem important
11573 to support that. */
11575 /* For each line spec given, delete bps which correspond to it. Do
11576 it in two passes, solely to preserve the current behavior that
11577 from_tty is forced true if we delete more than one
11580 std::vector<struct breakpoint *> found;
11581 for (const auto &sal : sals)
11583 const char *sal_fullname;
11585 /* If exact pc given, clear bpts at that pc.
11586 If line given (pc == 0), clear all bpts on specified line.
11587 If defaulting, clear all bpts on default line
11590 defaulting sal.pc != 0 tests to do
11595 1 0 <can't happen> */
11597 sal_fullname = (sal.symtab == NULL
11598 ? NULL : symtab_to_fullname (sal.symtab));
11600 /* Find all matching breakpoints and add them to 'found'. */
11601 ALL_BREAKPOINTS (b)
11604 /* Are we going to delete b? */
11605 if (b->type != bp_none && !is_watchpoint (b))
11607 struct bp_location *loc = b->loc;
11608 for (; loc; loc = loc->next)
11610 /* If the user specified file:line, don't allow a PC
11611 match. This matches historical gdb behavior. */
11612 int pc_match = (!sal.explicit_line
11614 && (loc->pspace == sal.pspace)
11615 && (loc->address == sal.pc)
11616 && (!section_is_overlay (loc->section)
11617 || loc->section == sal.section));
11618 int line_match = 0;
11620 if ((default_match || sal.explicit_line)
11621 && loc->symtab != NULL
11622 && sal_fullname != NULL
11623 && sal.pspace == loc->pspace
11624 && loc->line_number == sal.line
11625 && filename_cmp (symtab_to_fullname (loc->symtab),
11626 sal_fullname) == 0)
11629 if (pc_match || line_match)
11638 found.push_back (b);
11642 /* Now go thru the 'found' chain and delete them. */
11643 if (found.empty ())
11646 error (_("No breakpoint at %s."), arg);
11648 error (_("No breakpoint at this line."));
11651 /* Remove duplicates from the vec. */
11652 std::sort (found.begin (), found.end (),
11653 [] (const breakpoint *a, const breakpoint *b)
11655 return compare_breakpoints (a, b) < 0;
11657 found.erase (std::unique (found.begin (), found.end (),
11658 [] (const breakpoint *a, const breakpoint *b)
11660 return compare_breakpoints (a, b) == 0;
11664 if (found.size () > 1)
11665 from_tty = 1; /* Always report if deleted more than one. */
11668 if (found.size () == 1)
11669 printf_unfiltered (_("Deleted breakpoint "));
11671 printf_unfiltered (_("Deleted breakpoints "));
11674 for (breakpoint *iter : found)
11677 printf_unfiltered ("%d ", iter->number);
11678 delete_breakpoint (iter);
11681 putchar_unfiltered ('\n');
11684 /* Delete breakpoint in BS if they are `delete' breakpoints and
11685 all breakpoints that are marked for deletion, whether hit or not.
11686 This is called after any breakpoint is hit, or after errors. */
11689 breakpoint_auto_delete (bpstat bs)
11691 struct breakpoint *b, *b_tmp;
11693 for (; bs; bs = bs->next)
11694 if (bs->breakpoint_at
11695 && bs->breakpoint_at->disposition == disp_del
11697 delete_breakpoint (bs->breakpoint_at);
11699 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11701 if (b->disposition == disp_del_at_next_stop)
11702 delete_breakpoint (b);
11706 /* A comparison function for bp_location AP and BP being interfaced to
11707 qsort. Sort elements primarily by their ADDRESS (no matter what
11708 does breakpoint_address_is_meaningful say for its OWNER),
11709 secondarily by ordering first permanent elements and
11710 terciarily just ensuring the array is sorted stable way despite
11711 qsort being an unstable algorithm. */
11714 bp_locations_compare (const void *ap, const void *bp)
11716 const struct bp_location *a = *(const struct bp_location **) ap;
11717 const struct bp_location *b = *(const struct bp_location **) bp;
11719 if (a->address != b->address)
11720 return (a->address > b->address) - (a->address < b->address);
11722 /* Sort locations at the same address by their pspace number, keeping
11723 locations of the same inferior (in a multi-inferior environment)
11726 if (a->pspace->num != b->pspace->num)
11727 return ((a->pspace->num > b->pspace->num)
11728 - (a->pspace->num < b->pspace->num));
11730 /* Sort permanent breakpoints first. */
11731 if (a->permanent != b->permanent)
11732 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
11734 /* Make the internal GDB representation stable across GDB runs
11735 where A and B memory inside GDB can differ. Breakpoint locations of
11736 the same type at the same address can be sorted in arbitrary order. */
11738 if (a->owner->number != b->owner->number)
11739 return ((a->owner->number > b->owner->number)
11740 - (a->owner->number < b->owner->number));
11742 return (a > b) - (a < b);
11745 /* Set bp_locations_placed_address_before_address_max and
11746 bp_locations_shadow_len_after_address_max according to the current
11747 content of the bp_locations array. */
11750 bp_locations_target_extensions_update (void)
11752 struct bp_location *bl, **blp_tmp;
11754 bp_locations_placed_address_before_address_max = 0;
11755 bp_locations_shadow_len_after_address_max = 0;
11757 ALL_BP_LOCATIONS (bl, blp_tmp)
11759 CORE_ADDR start, end, addr;
11761 if (!bp_location_has_shadow (bl))
11764 start = bl->target_info.placed_address;
11765 end = start + bl->target_info.shadow_len;
11767 gdb_assert (bl->address >= start);
11768 addr = bl->address - start;
11769 if (addr > bp_locations_placed_address_before_address_max)
11770 bp_locations_placed_address_before_address_max = addr;
11772 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11774 gdb_assert (bl->address < end);
11775 addr = end - bl->address;
11776 if (addr > bp_locations_shadow_len_after_address_max)
11777 bp_locations_shadow_len_after_address_max = addr;
11781 /* Download tracepoint locations if they haven't been. */
11784 download_tracepoint_locations (void)
11786 struct breakpoint *b;
11787 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
11789 scoped_restore_current_pspace_and_thread restore_pspace_thread;
11791 ALL_TRACEPOINTS (b)
11793 struct bp_location *bl;
11794 struct tracepoint *t;
11795 int bp_location_downloaded = 0;
11797 if ((b->type == bp_fast_tracepoint
11798 ? !may_insert_fast_tracepoints
11799 : !may_insert_tracepoints))
11802 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
11804 if (target_can_download_tracepoint ())
11805 can_download_tracepoint = TRIBOOL_TRUE;
11807 can_download_tracepoint = TRIBOOL_FALSE;
11810 if (can_download_tracepoint == TRIBOOL_FALSE)
11813 for (bl = b->loc; bl; bl = bl->next)
11815 /* In tracepoint, locations are _never_ duplicated, so
11816 should_be_inserted is equivalent to
11817 unduplicated_should_be_inserted. */
11818 if (!should_be_inserted (bl) || bl->inserted)
11821 switch_to_program_space_and_thread (bl->pspace);
11823 target_download_tracepoint (bl);
11826 bp_location_downloaded = 1;
11828 t = (struct tracepoint *) b;
11829 t->number_on_target = b->number;
11830 if (bp_location_downloaded)
11831 observer_notify_breakpoint_modified (b);
11835 /* Swap the insertion/duplication state between two locations. */
11838 swap_insertion (struct bp_location *left, struct bp_location *right)
11840 const int left_inserted = left->inserted;
11841 const int left_duplicate = left->duplicate;
11842 const int left_needs_update = left->needs_update;
11843 const struct bp_target_info left_target_info = left->target_info;
11845 /* Locations of tracepoints can never be duplicated. */
11846 if (is_tracepoint (left->owner))
11847 gdb_assert (!left->duplicate);
11848 if (is_tracepoint (right->owner))
11849 gdb_assert (!right->duplicate);
11851 left->inserted = right->inserted;
11852 left->duplicate = right->duplicate;
11853 left->needs_update = right->needs_update;
11854 left->target_info = right->target_info;
11855 right->inserted = left_inserted;
11856 right->duplicate = left_duplicate;
11857 right->needs_update = left_needs_update;
11858 right->target_info = left_target_info;
11861 /* Force the re-insertion of the locations at ADDRESS. This is called
11862 once a new/deleted/modified duplicate location is found and we are evaluating
11863 conditions on the target's side. Such conditions need to be updated on
11867 force_breakpoint_reinsertion (struct bp_location *bl)
11869 struct bp_location **locp = NULL, **loc2p;
11870 struct bp_location *loc;
11871 CORE_ADDR address = 0;
11874 address = bl->address;
11875 pspace_num = bl->pspace->num;
11877 /* This is only meaningful if the target is
11878 evaluating conditions and if the user has
11879 opted for condition evaluation on the target's
11881 if (gdb_evaluates_breakpoint_condition_p ()
11882 || !target_supports_evaluation_of_breakpoint_conditions ())
11885 /* Flag all breakpoint locations with this address and
11886 the same program space as the location
11887 as "its condition has changed". We need to
11888 update the conditions on the target's side. */
11889 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11893 if (!is_breakpoint (loc->owner)
11894 || pspace_num != loc->pspace->num)
11897 /* Flag the location appropriately. We use a different state to
11898 let everyone know that we already updated the set of locations
11899 with addr bl->address and program space bl->pspace. This is so
11900 we don't have to keep calling these functions just to mark locations
11901 that have already been marked. */
11902 loc->condition_changed = condition_updated;
11904 /* Free the agent expression bytecode as well. We will compute
11906 loc->cond_bytecode.reset ();
11909 /* Called whether new breakpoints are created, or existing breakpoints
11910 deleted, to update the global location list and recompute which
11911 locations are duplicate of which.
11913 The INSERT_MODE flag determines whether locations may not, may, or
11914 shall be inserted now. See 'enum ugll_insert_mode' for more
11918 update_global_location_list (enum ugll_insert_mode insert_mode)
11920 struct breakpoint *b;
11921 struct bp_location **locp, *loc;
11922 /* Last breakpoint location address that was marked for update. */
11923 CORE_ADDR last_addr = 0;
11924 /* Last breakpoint location program space that was marked for update. */
11925 int last_pspace_num = -1;
11927 /* Used in the duplicates detection below. When iterating over all
11928 bp_locations, points to the first bp_location of a given address.
11929 Breakpoints and watchpoints of different types are never
11930 duplicates of each other. Keep one pointer for each type of
11931 breakpoint/watchpoint, so we only need to loop over all locations
11933 struct bp_location *bp_loc_first; /* breakpoint */
11934 struct bp_location *wp_loc_first; /* hardware watchpoint */
11935 struct bp_location *awp_loc_first; /* access watchpoint */
11936 struct bp_location *rwp_loc_first; /* read watchpoint */
11938 /* Saved former bp_locations array which we compare against the newly
11939 built bp_locations from the current state of ALL_BREAKPOINTS. */
11940 struct bp_location **old_locp;
11941 unsigned old_locations_count;
11942 gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations);
11944 old_locations_count = bp_locations_count;
11945 bp_locations = NULL;
11946 bp_locations_count = 0;
11948 ALL_BREAKPOINTS (b)
11949 for (loc = b->loc; loc; loc = loc->next)
11950 bp_locations_count++;
11952 bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
11953 locp = bp_locations;
11954 ALL_BREAKPOINTS (b)
11955 for (loc = b->loc; loc; loc = loc->next)
11957 qsort (bp_locations, bp_locations_count, sizeof (*bp_locations),
11958 bp_locations_compare);
11960 bp_locations_target_extensions_update ();
11962 /* Identify bp_location instances that are no longer present in the
11963 new list, and therefore should be freed. Note that it's not
11964 necessary that those locations should be removed from inferior --
11965 if there's another location at the same address (previously
11966 marked as duplicate), we don't need to remove/insert the
11969 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11970 and former bp_location array state respectively. */
11972 locp = bp_locations;
11973 for (old_locp = old_locations.get ();
11974 old_locp < old_locations.get () + old_locations_count;
11977 struct bp_location *old_loc = *old_locp;
11978 struct bp_location **loc2p;
11980 /* Tells if 'old_loc' is found among the new locations. If
11981 not, we have to free it. */
11982 int found_object = 0;
11983 /* Tells if the location should remain inserted in the target. */
11984 int keep_in_target = 0;
11987 /* Skip LOCP entries which will definitely never be needed.
11988 Stop either at or being the one matching OLD_LOC. */
11989 while (locp < bp_locations + bp_locations_count
11990 && (*locp)->address < old_loc->address)
11994 (loc2p < bp_locations + bp_locations_count
11995 && (*loc2p)->address == old_loc->address);
11998 /* Check if this is a new/duplicated location or a duplicated
11999 location that had its condition modified. If so, we want to send
12000 its condition to the target if evaluation of conditions is taking
12002 if ((*loc2p)->condition_changed == condition_modified
12003 && (last_addr != old_loc->address
12004 || last_pspace_num != old_loc->pspace->num))
12006 force_breakpoint_reinsertion (*loc2p);
12007 last_pspace_num = old_loc->pspace->num;
12010 if (*loc2p == old_loc)
12014 /* We have already handled this address, update it so that we don't
12015 have to go through updates again. */
12016 last_addr = old_loc->address;
12018 /* Target-side condition evaluation: Handle deleted locations. */
12020 force_breakpoint_reinsertion (old_loc);
12022 /* If this location is no longer present, and inserted, look if
12023 there's maybe a new location at the same address. If so,
12024 mark that one inserted, and don't remove this one. This is
12025 needed so that we don't have a time window where a breakpoint
12026 at certain location is not inserted. */
12028 if (old_loc->inserted)
12030 /* If the location is inserted now, we might have to remove
12033 if (found_object && should_be_inserted (old_loc))
12035 /* The location is still present in the location list,
12036 and still should be inserted. Don't do anything. */
12037 keep_in_target = 1;
12041 /* This location still exists, but it won't be kept in the
12042 target since it may have been disabled. We proceed to
12043 remove its target-side condition. */
12045 /* The location is either no longer present, or got
12046 disabled. See if there's another location at the
12047 same address, in which case we don't need to remove
12048 this one from the target. */
12050 /* OLD_LOC comes from existing struct breakpoint. */
12051 if (breakpoint_address_is_meaningful (old_loc->owner))
12054 (loc2p < bp_locations + bp_locations_count
12055 && (*loc2p)->address == old_loc->address);
12058 struct bp_location *loc2 = *loc2p;
12060 if (breakpoint_locations_match (loc2, old_loc))
12062 /* Read watchpoint locations are switched to
12063 access watchpoints, if the former are not
12064 supported, but the latter are. */
12065 if (is_hardware_watchpoint (old_loc->owner))
12067 gdb_assert (is_hardware_watchpoint (loc2->owner));
12068 loc2->watchpoint_type = old_loc->watchpoint_type;
12071 /* loc2 is a duplicated location. We need to check
12072 if it should be inserted in case it will be
12074 if (loc2 != old_loc
12075 && unduplicated_should_be_inserted (loc2))
12077 swap_insertion (old_loc, loc2);
12078 keep_in_target = 1;
12086 if (!keep_in_target)
12088 if (remove_breakpoint (old_loc))
12090 /* This is just about all we can do. We could keep
12091 this location on the global list, and try to
12092 remove it next time, but there's no particular
12093 reason why we will succeed next time.
12095 Note that at this point, old_loc->owner is still
12096 valid, as delete_breakpoint frees the breakpoint
12097 only after calling us. */
12098 printf_filtered (_("warning: Error removing "
12099 "breakpoint %d\n"),
12100 old_loc->owner->number);
12108 if (removed && target_is_non_stop_p ()
12109 && need_moribund_for_location_type (old_loc))
12111 /* This location was removed from the target. In
12112 non-stop mode, a race condition is possible where
12113 we've removed a breakpoint, but stop events for that
12114 breakpoint are already queued and will arrive later.
12115 We apply an heuristic to be able to distinguish such
12116 SIGTRAPs from other random SIGTRAPs: we keep this
12117 breakpoint location for a bit, and will retire it
12118 after we see some number of events. The theory here
12119 is that reporting of events should, "on the average",
12120 be fair, so after a while we'll see events from all
12121 threads that have anything of interest, and no longer
12122 need to keep this breakpoint location around. We
12123 don't hold locations forever so to reduce chances of
12124 mistaking a non-breakpoint SIGTRAP for a breakpoint
12127 The heuristic failing can be disastrous on
12128 decr_pc_after_break targets.
12130 On decr_pc_after_break targets, like e.g., x86-linux,
12131 if we fail to recognize a late breakpoint SIGTRAP,
12132 because events_till_retirement has reached 0 too
12133 soon, we'll fail to do the PC adjustment, and report
12134 a random SIGTRAP to the user. When the user resumes
12135 the inferior, it will most likely immediately crash
12136 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12137 corrupted, because of being resumed e.g., in the
12138 middle of a multi-byte instruction, or skipped a
12139 one-byte instruction. This was actually seen happen
12140 on native x86-linux, and should be less rare on
12141 targets that do not support new thread events, like
12142 remote, due to the heuristic depending on
12145 Mistaking a random SIGTRAP for a breakpoint trap
12146 causes similar symptoms (PC adjustment applied when
12147 it shouldn't), but then again, playing with SIGTRAPs
12148 behind the debugger's back is asking for trouble.
12150 Since hardware watchpoint traps are always
12151 distinguishable from other traps, so we don't need to
12152 apply keep hardware watchpoint moribund locations
12153 around. We simply always ignore hardware watchpoint
12154 traps we can no longer explain. */
12156 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12157 old_loc->owner = NULL;
12159 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12163 old_loc->owner = NULL;
12164 decref_bp_location (&old_loc);
12169 /* Rescan breakpoints at the same address and section, marking the
12170 first one as "first" and any others as "duplicates". This is so
12171 that the bpt instruction is only inserted once. If we have a
12172 permanent breakpoint at the same place as BPT, make that one the
12173 official one, and the rest as duplicates. Permanent breakpoints
12174 are sorted first for the same address.
12176 Do the same for hardware watchpoints, but also considering the
12177 watchpoint's type (regular/access/read) and length. */
12179 bp_loc_first = NULL;
12180 wp_loc_first = NULL;
12181 awp_loc_first = NULL;
12182 rwp_loc_first = NULL;
12183 ALL_BP_LOCATIONS (loc, locp)
12185 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12187 struct bp_location **loc_first_p;
12190 if (!unduplicated_should_be_inserted (loc)
12191 || !breakpoint_address_is_meaningful (b)
12192 /* Don't detect duplicate for tracepoint locations because they are
12193 never duplicated. See the comments in field `duplicate' of
12194 `struct bp_location'. */
12195 || is_tracepoint (b))
12197 /* Clear the condition modification flag. */
12198 loc->condition_changed = condition_unchanged;
12202 if (b->type == bp_hardware_watchpoint)
12203 loc_first_p = &wp_loc_first;
12204 else if (b->type == bp_read_watchpoint)
12205 loc_first_p = &rwp_loc_first;
12206 else if (b->type == bp_access_watchpoint)
12207 loc_first_p = &awp_loc_first;
12209 loc_first_p = &bp_loc_first;
12211 if (*loc_first_p == NULL
12212 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12213 || !breakpoint_locations_match (loc, *loc_first_p))
12215 *loc_first_p = loc;
12216 loc->duplicate = 0;
12218 if (is_breakpoint (loc->owner) && loc->condition_changed)
12220 loc->needs_update = 1;
12221 /* Clear the condition modification flag. */
12222 loc->condition_changed = condition_unchanged;
12228 /* This and the above ensure the invariant that the first location
12229 is not duplicated, and is the inserted one.
12230 All following are marked as duplicated, and are not inserted. */
12232 swap_insertion (loc, *loc_first_p);
12233 loc->duplicate = 1;
12235 /* Clear the condition modification flag. */
12236 loc->condition_changed = condition_unchanged;
12239 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12241 if (insert_mode != UGLL_DONT_INSERT)
12242 insert_breakpoint_locations ();
12245 /* Even though the caller told us to not insert new
12246 locations, we may still need to update conditions on the
12247 target's side of breakpoints that were already inserted
12248 if the target is evaluating breakpoint conditions. We
12249 only update conditions for locations that are marked
12251 update_inserted_breakpoint_locations ();
12255 if (insert_mode != UGLL_DONT_INSERT)
12256 download_tracepoint_locations ();
12260 breakpoint_retire_moribund (void)
12262 struct bp_location *loc;
12265 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12266 if (--(loc->events_till_retirement) == 0)
12268 decref_bp_location (&loc);
12269 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12275 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12280 update_global_location_list (insert_mode);
12282 CATCH (e, RETURN_MASK_ERROR)
12288 /* Clear BKP from a BPS. */
12291 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12295 for (bs = bps; bs; bs = bs->next)
12296 if (bs->breakpoint_at == bpt)
12298 bs->breakpoint_at = NULL;
12299 bs->old_val = NULL;
12300 /* bs->commands will be freed later. */
12304 /* Callback for iterate_over_threads. */
12306 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12308 struct breakpoint *bpt = (struct breakpoint *) data;
12310 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12314 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12318 say_where (struct breakpoint *b)
12320 struct value_print_options opts;
12322 get_user_print_options (&opts);
12324 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12326 if (b->loc == NULL)
12328 /* For pending locations, the output differs slightly based
12329 on b->extra_string. If this is non-NULL, it contains either
12330 a condition or dprintf arguments. */
12331 if (b->extra_string == NULL)
12333 printf_filtered (_(" (%s) pending."),
12334 event_location_to_string (b->location.get ()));
12336 else if (b->type == bp_dprintf)
12338 printf_filtered (_(" (%s,%s) pending."),
12339 event_location_to_string (b->location.get ()),
12344 printf_filtered (_(" (%s %s) pending."),
12345 event_location_to_string (b->location.get ()),
12351 if (opts.addressprint || b->loc->symtab == NULL)
12353 printf_filtered (" at ");
12354 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12357 if (b->loc->symtab != NULL)
12359 /* If there is a single location, we can print the location
12361 if (b->loc->next == NULL)
12362 printf_filtered (": file %s, line %d.",
12363 symtab_to_filename_for_display (b->loc->symtab),
12364 b->loc->line_number);
12366 /* This is not ideal, but each location may have a
12367 different file name, and this at least reflects the
12368 real situation somewhat. */
12369 printf_filtered (": %s.",
12370 event_location_to_string (b->location.get ()));
12375 struct bp_location *loc = b->loc;
12377 for (; loc; loc = loc->next)
12379 printf_filtered (" (%d locations)", n);
12384 /* Default bp_location_ops methods. */
12387 bp_location_dtor (struct bp_location *self)
12389 xfree (self->function_name);
12392 static const struct bp_location_ops bp_location_ops =
12397 /* Destructor for the breakpoint base class. */
12399 breakpoint::~breakpoint ()
12401 xfree (this->cond_string);
12402 xfree (this->extra_string);
12403 xfree (this->filter);
12406 static struct bp_location *
12407 base_breakpoint_allocate_location (struct breakpoint *self)
12409 return new bp_location (&bp_location_ops, self);
12413 base_breakpoint_re_set (struct breakpoint *b)
12415 /* Nothing to re-set. */
12418 #define internal_error_pure_virtual_called() \
12419 gdb_assert_not_reached ("pure virtual function called")
12422 base_breakpoint_insert_location (struct bp_location *bl)
12424 internal_error_pure_virtual_called ();
12428 base_breakpoint_remove_location (struct bp_location *bl,
12429 enum remove_bp_reason reason)
12431 internal_error_pure_virtual_called ();
12435 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12436 struct address_space *aspace,
12438 const struct target_waitstatus *ws)
12440 internal_error_pure_virtual_called ();
12444 base_breakpoint_check_status (bpstat bs)
12449 /* A "works_in_software_mode" breakpoint_ops method that just internal
12453 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12455 internal_error_pure_virtual_called ();
12458 /* A "resources_needed" breakpoint_ops method that just internal
12462 base_breakpoint_resources_needed (const struct bp_location *bl)
12464 internal_error_pure_virtual_called ();
12467 static enum print_stop_action
12468 base_breakpoint_print_it (bpstat bs)
12470 internal_error_pure_virtual_called ();
12474 base_breakpoint_print_one_detail (const struct breakpoint *self,
12475 struct ui_out *uiout)
12481 base_breakpoint_print_mention (struct breakpoint *b)
12483 internal_error_pure_virtual_called ();
12487 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12489 internal_error_pure_virtual_called ();
12493 base_breakpoint_create_sals_from_location
12494 (const struct event_location *location,
12495 struct linespec_result *canonical,
12496 enum bptype type_wanted)
12498 internal_error_pure_virtual_called ();
12502 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12503 struct linespec_result *c,
12504 gdb::unique_xmalloc_ptr<char> cond_string,
12505 gdb::unique_xmalloc_ptr<char> extra_string,
12506 enum bptype type_wanted,
12507 enum bpdisp disposition,
12509 int task, int ignore_count,
12510 const struct breakpoint_ops *o,
12511 int from_tty, int enabled,
12512 int internal, unsigned flags)
12514 internal_error_pure_virtual_called ();
12517 static std::vector<symtab_and_line>
12518 base_breakpoint_decode_location (struct breakpoint *b,
12519 const struct event_location *location,
12520 struct program_space *search_pspace)
12522 internal_error_pure_virtual_called ();
12525 /* The default 'explains_signal' method. */
12528 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12533 /* The default "after_condition_true" method. */
12536 base_breakpoint_after_condition_true (struct bpstats *bs)
12538 /* Nothing to do. */
12541 struct breakpoint_ops base_breakpoint_ops =
12543 base_breakpoint_allocate_location,
12544 base_breakpoint_re_set,
12545 base_breakpoint_insert_location,
12546 base_breakpoint_remove_location,
12547 base_breakpoint_breakpoint_hit,
12548 base_breakpoint_check_status,
12549 base_breakpoint_resources_needed,
12550 base_breakpoint_works_in_software_mode,
12551 base_breakpoint_print_it,
12553 base_breakpoint_print_one_detail,
12554 base_breakpoint_print_mention,
12555 base_breakpoint_print_recreate,
12556 base_breakpoint_create_sals_from_location,
12557 base_breakpoint_create_breakpoints_sal,
12558 base_breakpoint_decode_location,
12559 base_breakpoint_explains_signal,
12560 base_breakpoint_after_condition_true,
12563 /* Default breakpoint_ops methods. */
12566 bkpt_re_set (struct breakpoint *b)
12568 /* FIXME: is this still reachable? */
12569 if (breakpoint_event_location_empty_p (b))
12571 /* Anything without a location can't be re-set. */
12572 delete_breakpoint (b);
12576 breakpoint_re_set_default (b);
12580 bkpt_insert_location (struct bp_location *bl)
12582 CORE_ADDR addr = bl->target_info.reqstd_address;
12584 bl->target_info.kind = breakpoint_kind (bl, &addr);
12585 bl->target_info.placed_address = addr;
12587 if (bl->loc_type == bp_loc_hardware_breakpoint)
12588 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
12590 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
12594 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
12596 if (bl->loc_type == bp_loc_hardware_breakpoint)
12597 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12599 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
12603 bkpt_breakpoint_hit (const struct bp_location *bl,
12604 struct address_space *aspace, CORE_ADDR bp_addr,
12605 const struct target_waitstatus *ws)
12607 if (ws->kind != TARGET_WAITKIND_STOPPED
12608 || ws->value.sig != GDB_SIGNAL_TRAP)
12611 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12615 if (overlay_debugging /* unmapped overlay section */
12616 && section_is_overlay (bl->section)
12617 && !section_is_mapped (bl->section))
12624 dprintf_breakpoint_hit (const struct bp_location *bl,
12625 struct address_space *aspace, CORE_ADDR bp_addr,
12626 const struct target_waitstatus *ws)
12628 if (dprintf_style == dprintf_style_agent
12629 && target_can_run_breakpoint_commands ())
12631 /* An agent-style dprintf never causes a stop. If we see a trap
12632 for this address it must be for a breakpoint that happens to
12633 be set at the same address. */
12637 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
12641 bkpt_resources_needed (const struct bp_location *bl)
12643 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12648 static enum print_stop_action
12649 bkpt_print_it (bpstat bs)
12651 struct breakpoint *b;
12652 const struct bp_location *bl;
12654 struct ui_out *uiout = current_uiout;
12656 gdb_assert (bs->bp_location_at != NULL);
12658 bl = bs->bp_location_at;
12659 b = bs->breakpoint_at;
12661 bp_temp = b->disposition == disp_del;
12662 if (bl->address != bl->requested_address)
12663 breakpoint_adjustment_warning (bl->requested_address,
12666 annotate_breakpoint (b->number);
12667 maybe_print_thread_hit_breakpoint (uiout);
12670 uiout->text ("Temporary breakpoint ");
12672 uiout->text ("Breakpoint ");
12673 if (uiout->is_mi_like_p ())
12675 uiout->field_string ("reason",
12676 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12677 uiout->field_string ("disp", bpdisp_text (b->disposition));
12679 uiout->field_int ("bkptno", b->number);
12680 uiout->text (", ");
12682 return PRINT_SRC_AND_LOC;
12686 bkpt_print_mention (struct breakpoint *b)
12688 if (current_uiout->is_mi_like_p ())
12693 case bp_breakpoint:
12694 case bp_gnu_ifunc_resolver:
12695 if (b->disposition == disp_del)
12696 printf_filtered (_("Temporary breakpoint"));
12698 printf_filtered (_("Breakpoint"));
12699 printf_filtered (_(" %d"), b->number);
12700 if (b->type == bp_gnu_ifunc_resolver)
12701 printf_filtered (_(" at gnu-indirect-function resolver"));
12703 case bp_hardware_breakpoint:
12704 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12707 printf_filtered (_("Dprintf %d"), b->number);
12715 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12717 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12718 fprintf_unfiltered (fp, "tbreak");
12719 else if (tp->type == bp_breakpoint)
12720 fprintf_unfiltered (fp, "break");
12721 else if (tp->type == bp_hardware_breakpoint
12722 && tp->disposition == disp_del)
12723 fprintf_unfiltered (fp, "thbreak");
12724 else if (tp->type == bp_hardware_breakpoint)
12725 fprintf_unfiltered (fp, "hbreak");
12727 internal_error (__FILE__, __LINE__,
12728 _("unhandled breakpoint type %d"), (int) tp->type);
12730 fprintf_unfiltered (fp, " %s",
12731 event_location_to_string (tp->location.get ()));
12733 /* Print out extra_string if this breakpoint is pending. It might
12734 contain, for example, conditions that were set by the user. */
12735 if (tp->loc == NULL && tp->extra_string != NULL)
12736 fprintf_unfiltered (fp, " %s", tp->extra_string);
12738 print_recreate_thread (tp, fp);
12742 bkpt_create_sals_from_location (const struct event_location *location,
12743 struct linespec_result *canonical,
12744 enum bptype type_wanted)
12746 create_sals_from_location_default (location, canonical, type_wanted);
12750 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12751 struct linespec_result *canonical,
12752 gdb::unique_xmalloc_ptr<char> cond_string,
12753 gdb::unique_xmalloc_ptr<char> extra_string,
12754 enum bptype type_wanted,
12755 enum bpdisp disposition,
12757 int task, int ignore_count,
12758 const struct breakpoint_ops *ops,
12759 int from_tty, int enabled,
12760 int internal, unsigned flags)
12762 create_breakpoints_sal_default (gdbarch, canonical,
12763 std::move (cond_string),
12764 std::move (extra_string),
12766 disposition, thread, task,
12767 ignore_count, ops, from_tty,
12768 enabled, internal, flags);
12771 static std::vector<symtab_and_line>
12772 bkpt_decode_location (struct breakpoint *b,
12773 const struct event_location *location,
12774 struct program_space *search_pspace)
12776 return decode_location_default (b, location, search_pspace);
12779 /* Virtual table for internal breakpoints. */
12782 internal_bkpt_re_set (struct breakpoint *b)
12786 /* Delete overlay event and longjmp master breakpoints; they
12787 will be reset later by breakpoint_re_set. */
12788 case bp_overlay_event:
12789 case bp_longjmp_master:
12790 case bp_std_terminate_master:
12791 case bp_exception_master:
12792 delete_breakpoint (b);
12795 /* This breakpoint is special, it's set up when the inferior
12796 starts and we really don't want to touch it. */
12797 case bp_shlib_event:
12799 /* Like bp_shlib_event, this breakpoint type is special. Once
12800 it is set up, we do not want to touch it. */
12801 case bp_thread_event:
12807 internal_bkpt_check_status (bpstat bs)
12809 if (bs->breakpoint_at->type == bp_shlib_event)
12811 /* If requested, stop when the dynamic linker notifies GDB of
12812 events. This allows the user to get control and place
12813 breakpoints in initializer routines for dynamically loaded
12814 objects (among other things). */
12815 bs->stop = stop_on_solib_events;
12816 bs->print = stop_on_solib_events;
12822 static enum print_stop_action
12823 internal_bkpt_print_it (bpstat bs)
12825 struct breakpoint *b;
12827 b = bs->breakpoint_at;
12831 case bp_shlib_event:
12832 /* Did we stop because the user set the stop_on_solib_events
12833 variable? (If so, we report this as a generic, "Stopped due
12834 to shlib event" message.) */
12835 print_solib_event (0);
12838 case bp_thread_event:
12839 /* Not sure how we will get here.
12840 GDB should not stop for these breakpoints. */
12841 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12844 case bp_overlay_event:
12845 /* By analogy with the thread event, GDB should not stop for these. */
12846 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12849 case bp_longjmp_master:
12850 /* These should never be enabled. */
12851 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12854 case bp_std_terminate_master:
12855 /* These should never be enabled. */
12856 printf_filtered (_("std::terminate Master Breakpoint: "
12857 "gdb should not stop!\n"));
12860 case bp_exception_master:
12861 /* These should never be enabled. */
12862 printf_filtered (_("Exception Master Breakpoint: "
12863 "gdb should not stop!\n"));
12867 return PRINT_NOTHING;
12871 internal_bkpt_print_mention (struct breakpoint *b)
12873 /* Nothing to mention. These breakpoints are internal. */
12876 /* Virtual table for momentary breakpoints */
12879 momentary_bkpt_re_set (struct breakpoint *b)
12881 /* Keep temporary breakpoints, which can be encountered when we step
12882 over a dlopen call and solib_add is resetting the breakpoints.
12883 Otherwise these should have been blown away via the cleanup chain
12884 or by breakpoint_init_inferior when we rerun the executable. */
12888 momentary_bkpt_check_status (bpstat bs)
12890 /* Nothing. The point of these breakpoints is causing a stop. */
12893 static enum print_stop_action
12894 momentary_bkpt_print_it (bpstat bs)
12896 return PRINT_UNKNOWN;
12900 momentary_bkpt_print_mention (struct breakpoint *b)
12902 /* Nothing to mention. These breakpoints are internal. */
12905 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12907 It gets cleared already on the removal of the first one of such placed
12908 breakpoints. This is OK as they get all removed altogether. */
12910 longjmp_breakpoint::~longjmp_breakpoint ()
12912 thread_info *tp = find_thread_global_id (this->thread);
12915 tp->initiating_frame = null_frame_id;
12918 /* Specific methods for probe breakpoints. */
12921 bkpt_probe_insert_location (struct bp_location *bl)
12923 int v = bkpt_insert_location (bl);
12927 /* The insertion was successful, now let's set the probe's semaphore
12929 if (bl->probe.probe->pops->set_semaphore != NULL)
12930 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
12939 bkpt_probe_remove_location (struct bp_location *bl,
12940 enum remove_bp_reason reason)
12942 /* Let's clear the semaphore before removing the location. */
12943 if (bl->probe.probe->pops->clear_semaphore != NULL)
12944 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
12948 return bkpt_remove_location (bl, reason);
12952 bkpt_probe_create_sals_from_location (const struct event_location *location,
12953 struct linespec_result *canonical,
12954 enum bptype type_wanted)
12956 struct linespec_sals lsal;
12958 lsal.sals = parse_probes (location, NULL, canonical);
12960 = xstrdup (event_location_to_string (canonical->location.get ()));
12961 canonical->lsals.push_back (std::move (lsal));
12964 static std::vector<symtab_and_line>
12965 bkpt_probe_decode_location (struct breakpoint *b,
12966 const struct event_location *location,
12967 struct program_space *search_pspace)
12969 std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
12971 error (_("probe not found"));
12975 /* The breakpoint_ops structure to be used in tracepoints. */
12978 tracepoint_re_set (struct breakpoint *b)
12980 breakpoint_re_set_default (b);
12984 tracepoint_breakpoint_hit (const struct bp_location *bl,
12985 struct address_space *aspace, CORE_ADDR bp_addr,
12986 const struct target_waitstatus *ws)
12988 /* By definition, the inferior does not report stops at
12994 tracepoint_print_one_detail (const struct breakpoint *self,
12995 struct ui_out *uiout)
12997 struct tracepoint *tp = (struct tracepoint *) self;
12998 if (tp->static_trace_marker_id)
13000 gdb_assert (self->type == bp_static_tracepoint);
13002 uiout->text ("\tmarker id is ");
13003 uiout->field_string ("static-tracepoint-marker-string-id",
13004 tp->static_trace_marker_id);
13005 uiout->text ("\n");
13010 tracepoint_print_mention (struct breakpoint *b)
13012 if (current_uiout->is_mi_like_p ())
13017 case bp_tracepoint:
13018 printf_filtered (_("Tracepoint"));
13019 printf_filtered (_(" %d"), b->number);
13021 case bp_fast_tracepoint:
13022 printf_filtered (_("Fast tracepoint"));
13023 printf_filtered (_(" %d"), b->number);
13025 case bp_static_tracepoint:
13026 printf_filtered (_("Static tracepoint"));
13027 printf_filtered (_(" %d"), b->number);
13030 internal_error (__FILE__, __LINE__,
13031 _("unhandled tracepoint type %d"), (int) b->type);
13038 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13040 struct tracepoint *tp = (struct tracepoint *) self;
13042 if (self->type == bp_fast_tracepoint)
13043 fprintf_unfiltered (fp, "ftrace");
13044 else if (self->type == bp_static_tracepoint)
13045 fprintf_unfiltered (fp, "strace");
13046 else if (self->type == bp_tracepoint)
13047 fprintf_unfiltered (fp, "trace");
13049 internal_error (__FILE__, __LINE__,
13050 _("unhandled tracepoint type %d"), (int) self->type);
13052 fprintf_unfiltered (fp, " %s",
13053 event_location_to_string (self->location.get ()));
13054 print_recreate_thread (self, fp);
13056 if (tp->pass_count)
13057 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13061 tracepoint_create_sals_from_location (const struct event_location *location,
13062 struct linespec_result *canonical,
13063 enum bptype type_wanted)
13065 create_sals_from_location_default (location, canonical, type_wanted);
13069 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13070 struct linespec_result *canonical,
13071 gdb::unique_xmalloc_ptr<char> cond_string,
13072 gdb::unique_xmalloc_ptr<char> extra_string,
13073 enum bptype type_wanted,
13074 enum bpdisp disposition,
13076 int task, int ignore_count,
13077 const struct breakpoint_ops *ops,
13078 int from_tty, int enabled,
13079 int internal, unsigned flags)
13081 create_breakpoints_sal_default (gdbarch, canonical,
13082 std::move (cond_string),
13083 std::move (extra_string),
13085 disposition, thread, task,
13086 ignore_count, ops, from_tty,
13087 enabled, internal, flags);
13090 static std::vector<symtab_and_line>
13091 tracepoint_decode_location (struct breakpoint *b,
13092 const struct event_location *location,
13093 struct program_space *search_pspace)
13095 return decode_location_default (b, location, search_pspace);
13098 struct breakpoint_ops tracepoint_breakpoint_ops;
13100 /* The breakpoint_ops structure to be use on tracepoints placed in a
13104 tracepoint_probe_create_sals_from_location
13105 (const struct event_location *location,
13106 struct linespec_result *canonical,
13107 enum bptype type_wanted)
13109 /* We use the same method for breakpoint on probes. */
13110 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
13113 static std::vector<symtab_and_line>
13114 tracepoint_probe_decode_location (struct breakpoint *b,
13115 const struct event_location *location,
13116 struct program_space *search_pspace)
13118 /* We use the same method for breakpoint on probes. */
13119 return bkpt_probe_decode_location (b, location, search_pspace);
13122 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13124 /* Dprintf breakpoint_ops methods. */
13127 dprintf_re_set (struct breakpoint *b)
13129 breakpoint_re_set_default (b);
13131 /* extra_string should never be non-NULL for dprintf. */
13132 gdb_assert (b->extra_string != NULL);
13134 /* 1 - connect to target 1, that can run breakpoint commands.
13135 2 - create a dprintf, which resolves fine.
13136 3 - disconnect from target 1
13137 4 - connect to target 2, that can NOT run breakpoint commands.
13139 After steps #3/#4, you'll want the dprintf command list to
13140 be updated, because target 1 and 2 may well return different
13141 answers for target_can_run_breakpoint_commands().
13142 Given absence of finer grained resetting, we get to do
13143 it all the time. */
13144 if (b->extra_string != NULL)
13145 update_dprintf_command_list (b);
13148 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13151 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13153 fprintf_unfiltered (fp, "dprintf %s,%s",
13154 event_location_to_string (tp->location.get ()),
13156 print_recreate_thread (tp, fp);
13159 /* Implement the "after_condition_true" breakpoint_ops method for
13162 dprintf's are implemented with regular commands in their command
13163 list, but we run the commands here instead of before presenting the
13164 stop to the user, as dprintf's don't actually cause a stop. This
13165 also makes it so that the commands of multiple dprintfs at the same
13166 address are all handled. */
13169 dprintf_after_condition_true (struct bpstats *bs)
13171 struct bpstats tmp_bs;
13172 struct bpstats *tmp_bs_p = &tmp_bs;
13174 /* dprintf's never cause a stop. This wasn't set in the
13175 check_status hook instead because that would make the dprintf's
13176 condition not be evaluated. */
13179 /* Run the command list here. Take ownership of it instead of
13180 copying. We never want these commands to run later in
13181 bpstat_do_actions, if a breakpoint that causes a stop happens to
13182 be set at same address as this dprintf, or even if running the
13183 commands here throws. */
13184 tmp_bs.commands = bs->commands;
13185 bs->commands = NULL;
13187 bpstat_do_actions_1 (&tmp_bs_p);
13189 /* 'tmp_bs.commands' will usually be NULL by now, but
13190 bpstat_do_actions_1 may return early without processing the whole
13194 /* The breakpoint_ops structure to be used on static tracepoints with
13198 strace_marker_create_sals_from_location (const struct event_location *location,
13199 struct linespec_result *canonical,
13200 enum bptype type_wanted)
13202 struct linespec_sals lsal;
13203 const char *arg_start, *arg;
13205 arg = arg_start = get_linespec_location (location);
13206 lsal.sals = decode_static_tracepoint_spec (&arg);
13208 std::string str (arg_start, arg - arg_start);
13209 const char *ptr = str.c_str ();
13210 canonical->location = new_linespec_location (&ptr);
13213 = xstrdup (event_location_to_string (canonical->location.get ()));
13214 canonical->lsals.push_back (std::move (lsal));
13218 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13219 struct linespec_result *canonical,
13220 gdb::unique_xmalloc_ptr<char> cond_string,
13221 gdb::unique_xmalloc_ptr<char> extra_string,
13222 enum bptype type_wanted,
13223 enum bpdisp disposition,
13225 int task, int ignore_count,
13226 const struct breakpoint_ops *ops,
13227 int from_tty, int enabled,
13228 int internal, unsigned flags)
13230 const linespec_sals &lsal = canonical->lsals[0];
13232 /* If the user is creating a static tracepoint by marker id
13233 (strace -m MARKER_ID), then store the sals index, so that
13234 breakpoint_re_set can try to match up which of the newly
13235 found markers corresponds to this one, and, don't try to
13236 expand multiple locations for each sal, given than SALS
13237 already should contain all sals for MARKER_ID. */
13239 for (size_t i = 0; i < lsal.sals.size (); i++)
13241 event_location_up location
13242 = copy_event_location (canonical->location.get ());
13244 std::unique_ptr<tracepoint> tp (new tracepoint ());
13245 init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i],
13246 std::move (location), NULL,
13247 std::move (cond_string),
13248 std::move (extra_string),
13249 type_wanted, disposition,
13250 thread, task, ignore_count, ops,
13251 from_tty, enabled, internal, flags,
13252 canonical->special_display);
13253 /* Given that its possible to have multiple markers with
13254 the same string id, if the user is creating a static
13255 tracepoint by marker id ("strace -m MARKER_ID"), then
13256 store the sals index, so that breakpoint_re_set can
13257 try to match up which of the newly found markers
13258 corresponds to this one */
13259 tp->static_trace_marker_id_idx = i;
13261 install_breakpoint (internal, std::move (tp), 0);
13265 static std::vector<symtab_and_line>
13266 strace_marker_decode_location (struct breakpoint *b,
13267 const struct event_location *location,
13268 struct program_space *search_pspace)
13270 struct tracepoint *tp = (struct tracepoint *) b;
13271 const char *s = get_linespec_location (location);
13273 std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
13274 if (sals.size () > tp->static_trace_marker_id_idx)
13276 sals[0] = sals[tp->static_trace_marker_id_idx];
13281 error (_("marker %s not found"), tp->static_trace_marker_id);
13284 static struct breakpoint_ops strace_marker_breakpoint_ops;
13287 strace_marker_p (struct breakpoint *b)
13289 return b->ops == &strace_marker_breakpoint_ops;
13292 /* Delete a breakpoint and clean up all traces of it in the data
13296 delete_breakpoint (struct breakpoint *bpt)
13298 struct breakpoint *b;
13300 gdb_assert (bpt != NULL);
13302 /* Has this bp already been deleted? This can happen because
13303 multiple lists can hold pointers to bp's. bpstat lists are
13306 One example of this happening is a watchpoint's scope bp. When
13307 the scope bp triggers, we notice that the watchpoint is out of
13308 scope, and delete it. We also delete its scope bp. But the
13309 scope bp is marked "auto-deleting", and is already on a bpstat.
13310 That bpstat is then checked for auto-deleting bp's, which are
13313 A real solution to this problem might involve reference counts in
13314 bp's, and/or giving them pointers back to their referencing
13315 bpstat's, and teaching delete_breakpoint to only free a bp's
13316 storage when no more references were extent. A cheaper bandaid
13318 if (bpt->type == bp_none)
13321 /* At least avoid this stale reference until the reference counting
13322 of breakpoints gets resolved. */
13323 if (bpt->related_breakpoint != bpt)
13325 struct breakpoint *related;
13326 struct watchpoint *w;
13328 if (bpt->type == bp_watchpoint_scope)
13329 w = (struct watchpoint *) bpt->related_breakpoint;
13330 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13331 w = (struct watchpoint *) bpt;
13335 watchpoint_del_at_next_stop (w);
13337 /* Unlink bpt from the bpt->related_breakpoint ring. */
13338 for (related = bpt; related->related_breakpoint != bpt;
13339 related = related->related_breakpoint);
13340 related->related_breakpoint = bpt->related_breakpoint;
13341 bpt->related_breakpoint = bpt;
13344 /* watch_command_1 creates a watchpoint but only sets its number if
13345 update_watchpoint succeeds in creating its bp_locations. If there's
13346 a problem in that process, we'll be asked to delete the half-created
13347 watchpoint. In that case, don't announce the deletion. */
13349 observer_notify_breakpoint_deleted (bpt);
13351 if (breakpoint_chain == bpt)
13352 breakpoint_chain = bpt->next;
13354 ALL_BREAKPOINTS (b)
13355 if (b->next == bpt)
13357 b->next = bpt->next;
13361 /* Be sure no bpstat's are pointing at the breakpoint after it's
13363 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13364 in all threads for now. Note that we cannot just remove bpstats
13365 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13366 commands are associated with the bpstat; if we remove it here,
13367 then the later call to bpstat_do_actions (&stop_bpstat); in
13368 event-top.c won't do anything, and temporary breakpoints with
13369 commands won't work. */
13371 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13373 /* Now that breakpoint is removed from breakpoint list, update the
13374 global location list. This will remove locations that used to
13375 belong to this breakpoint. Do this before freeing the breakpoint
13376 itself, since remove_breakpoint looks at location's owner. It
13377 might be better design to have location completely
13378 self-contained, but it's not the case now. */
13379 update_global_location_list (UGLL_DONT_INSERT);
13381 /* On the chance that someone will soon try again to delete this
13382 same bp, we mark it as deleted before freeing its storage. */
13383 bpt->type = bp_none;
13388 do_delete_breakpoint_cleanup (void *b)
13390 delete_breakpoint ((struct breakpoint *) b);
13394 make_cleanup_delete_breakpoint (struct breakpoint *b)
13396 return make_cleanup (do_delete_breakpoint_cleanup, b);
13399 /* Iterator function to call a user-provided callback function once
13400 for each of B and its related breakpoints. */
13403 iterate_over_related_breakpoints (struct breakpoint *b,
13404 gdb::function_view<void (breakpoint *)> function)
13406 struct breakpoint *related;
13411 struct breakpoint *next;
13413 /* FUNCTION may delete RELATED. */
13414 next = related->related_breakpoint;
13416 if (next == related)
13418 /* RELATED is the last ring entry. */
13419 function (related);
13421 /* FUNCTION may have deleted it, so we'd never reach back to
13422 B. There's nothing left to do anyway, so just break
13427 function (related);
13431 while (related != b);
13435 delete_command (const char *arg, int from_tty)
13437 struct breakpoint *b, *b_tmp;
13443 int breaks_to_delete = 0;
13445 /* Delete all breakpoints if no argument. Do not delete
13446 internal breakpoints, these have to be deleted with an
13447 explicit breakpoint number argument. */
13448 ALL_BREAKPOINTS (b)
13449 if (user_breakpoint_p (b))
13451 breaks_to_delete = 1;
13455 /* Ask user only if there are some breakpoints to delete. */
13457 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13459 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13460 if (user_breakpoint_p (b))
13461 delete_breakpoint (b);
13465 map_breakpoint_numbers
13466 (arg, [&] (breakpoint *b)
13468 iterate_over_related_breakpoints (b, delete_breakpoint);
13472 /* Return true if all locations of B bound to PSPACE are pending. If
13473 PSPACE is NULL, all locations of all program spaces are
13477 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
13479 struct bp_location *loc;
13481 for (loc = b->loc; loc != NULL; loc = loc->next)
13482 if ((pspace == NULL
13483 || loc->pspace == pspace)
13484 && !loc->shlib_disabled
13485 && !loc->pspace->executing_startup)
13490 /* Subroutine of update_breakpoint_locations to simplify it.
13491 Return non-zero if multiple fns in list LOC have the same name.
13492 Null names are ignored. */
13495 ambiguous_names_p (struct bp_location *loc)
13497 struct bp_location *l;
13498 htab_t htab = htab_create_alloc (13, htab_hash_string,
13499 (int (*) (const void *,
13500 const void *)) streq,
13501 NULL, xcalloc, xfree);
13503 for (l = loc; l != NULL; l = l->next)
13506 const char *name = l->function_name;
13508 /* Allow for some names to be NULL, ignore them. */
13512 slot = (const char **) htab_find_slot (htab, (const void *) name,
13514 /* NOTE: We can assume slot != NULL here because xcalloc never
13518 htab_delete (htab);
13524 htab_delete (htab);
13528 /* When symbols change, it probably means the sources changed as well,
13529 and it might mean the static tracepoint markers are no longer at
13530 the same address or line numbers they used to be at last we
13531 checked. Losing your static tracepoints whenever you rebuild is
13532 undesirable. This function tries to resync/rematch gdb static
13533 tracepoints with the markers on the target, for static tracepoints
13534 that have not been set by marker id. Static tracepoint that have
13535 been set by marker id are reset by marker id in breakpoint_re_set.
13538 1) For a tracepoint set at a specific address, look for a marker at
13539 the old PC. If one is found there, assume to be the same marker.
13540 If the name / string id of the marker found is different from the
13541 previous known name, assume that means the user renamed the marker
13542 in the sources, and output a warning.
13544 2) For a tracepoint set at a given line number, look for a marker
13545 at the new address of the old line number. If one is found there,
13546 assume to be the same marker. If the name / string id of the
13547 marker found is different from the previous known name, assume that
13548 means the user renamed the marker in the sources, and output a
13551 3) If a marker is no longer found at the same address or line, it
13552 may mean the marker no longer exists. But it may also just mean
13553 the code changed a bit. Maybe the user added a few lines of code
13554 that made the marker move up or down (in line number terms). Ask
13555 the target for info about the marker with the string id as we knew
13556 it. If found, update line number and address in the matching
13557 static tracepoint. This will get confused if there's more than one
13558 marker with the same ID (possible in UST, although unadvised
13559 precisely because it confuses tools). */
13561 static struct symtab_and_line
13562 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13564 struct tracepoint *tp = (struct tracepoint *) b;
13565 struct static_tracepoint_marker marker;
13570 find_line_pc (sal.symtab, sal.line, &pc);
13572 if (target_static_tracepoint_marker_at (pc, &marker))
13574 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13575 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13577 tp->static_trace_marker_id, marker.str_id);
13579 xfree (tp->static_trace_marker_id);
13580 tp->static_trace_marker_id = xstrdup (marker.str_id);
13581 release_static_tracepoint_marker (&marker);
13586 /* Old marker wasn't found on target at lineno. Try looking it up
13588 if (!sal.explicit_pc
13590 && sal.symtab != NULL
13591 && tp->static_trace_marker_id != NULL)
13593 VEC(static_tracepoint_marker_p) *markers;
13596 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13598 if (!VEC_empty(static_tracepoint_marker_p, markers))
13600 struct symbol *sym;
13601 struct static_tracepoint_marker *tpmarker;
13602 struct ui_out *uiout = current_uiout;
13603 struct explicit_location explicit_loc;
13605 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13607 xfree (tp->static_trace_marker_id);
13608 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13610 warning (_("marker for static tracepoint %d (%s) not "
13611 "found at previous line number"),
13612 b->number, tp->static_trace_marker_id);
13614 symtab_and_line sal2 = find_pc_line (tpmarker->address, 0);
13615 sym = find_pc_sect_function (tpmarker->address, NULL);
13616 uiout->text ("Now in ");
13619 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
13620 uiout->text (" at ");
13622 uiout->field_string ("file",
13623 symtab_to_filename_for_display (sal2.symtab));
13626 if (uiout->is_mi_like_p ())
13628 const char *fullname = symtab_to_fullname (sal2.symtab);
13630 uiout->field_string ("fullname", fullname);
13633 uiout->field_int ("line", sal2.line);
13634 uiout->text ("\n");
13636 b->loc->line_number = sal2.line;
13637 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13639 b->location.reset (NULL);
13640 initialize_explicit_location (&explicit_loc);
13641 explicit_loc.source_filename
13642 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
13643 explicit_loc.line_offset.offset = b->loc->line_number;
13644 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
13645 b->location = new_explicit_location (&explicit_loc);
13647 /* Might be nice to check if function changed, and warn if
13650 release_static_tracepoint_marker (tpmarker);
13656 /* Returns 1 iff locations A and B are sufficiently same that
13657 we don't need to report breakpoint as changed. */
13660 locations_are_equal (struct bp_location *a, struct bp_location *b)
13664 if (a->address != b->address)
13667 if (a->shlib_disabled != b->shlib_disabled)
13670 if (a->enabled != b->enabled)
13677 if ((a == NULL) != (b == NULL))
13683 /* Split all locations of B that are bound to PSPACE out of B's
13684 location list to a separate list and return that list's head. If
13685 PSPACE is NULL, hoist out all locations of B. */
13687 static struct bp_location *
13688 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
13690 struct bp_location head;
13691 struct bp_location *i = b->loc;
13692 struct bp_location **i_link = &b->loc;
13693 struct bp_location *hoisted = &head;
13695 if (pspace == NULL)
13706 if (i->pspace == pspace)
13721 /* Create new breakpoint locations for B (a hardware or software
13722 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13723 zero, then B is a ranged breakpoint. Only recreates locations for
13724 FILTER_PSPACE. Locations of other program spaces are left
13728 update_breakpoint_locations (struct breakpoint *b,
13729 struct program_space *filter_pspace,
13730 gdb::array_view<const symtab_and_line> sals,
13731 gdb::array_view<const symtab_and_line> sals_end)
13734 struct bp_location *existing_locations;
13736 if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1))
13738 /* Ranged breakpoints have only one start location and one end
13740 b->enable_state = bp_disabled;
13741 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13742 "multiple locations found\n"),
13747 /* If there's no new locations, and all existing locations are
13748 pending, don't do anything. This optimizes the common case where
13749 all locations are in the same shared library, that was unloaded.
13750 We'd like to retain the location, so that when the library is
13751 loaded again, we don't loose the enabled/disabled status of the
13752 individual locations. */
13753 if (all_locations_are_pending (b, filter_pspace) && sals.empty ())
13756 existing_locations = hoist_existing_locations (b, filter_pspace);
13758 for (const auto &sal : sals)
13760 struct bp_location *new_loc;
13762 switch_to_program_space_and_thread (sal.pspace);
13764 new_loc = add_location_to_breakpoint (b, &sal);
13766 /* Reparse conditions, they might contain references to the
13768 if (b->cond_string != NULL)
13772 s = b->cond_string;
13775 new_loc->cond = parse_exp_1 (&s, sal.pc,
13776 block_for_pc (sal.pc),
13779 CATCH (e, RETURN_MASK_ERROR)
13781 warning (_("failed to reevaluate condition "
13782 "for breakpoint %d: %s"),
13783 b->number, e.message);
13784 new_loc->enabled = 0;
13789 if (!sals_end.empty ())
13791 CORE_ADDR end = find_breakpoint_range_end (sals_end[0]);
13793 new_loc->length = end - sals[0].pc + 1;
13797 /* If possible, carry over 'disable' status from existing
13800 struct bp_location *e = existing_locations;
13801 /* If there are multiple breakpoints with the same function name,
13802 e.g. for inline functions, comparing function names won't work.
13803 Instead compare pc addresses; this is just a heuristic as things
13804 may have moved, but in practice it gives the correct answer
13805 often enough until a better solution is found. */
13806 int have_ambiguous_names = ambiguous_names_p (b->loc);
13808 for (; e; e = e->next)
13810 if (!e->enabled && e->function_name)
13812 struct bp_location *l = b->loc;
13813 if (have_ambiguous_names)
13815 for (; l; l = l->next)
13816 if (breakpoint_locations_match (e, l))
13824 for (; l; l = l->next)
13825 if (l->function_name
13826 && strcmp (e->function_name, l->function_name) == 0)
13836 if (!locations_are_equal (existing_locations, b->loc))
13837 observer_notify_breakpoint_modified (b);
13840 /* Find the SaL locations corresponding to the given LOCATION.
13841 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13843 static std::vector<symtab_and_line>
13844 location_to_sals (struct breakpoint *b, struct event_location *location,
13845 struct program_space *search_pspace, int *found)
13847 struct gdb_exception exception = exception_none;
13849 gdb_assert (b->ops != NULL);
13851 std::vector<symtab_and_line> sals;
13855 sals = b->ops->decode_location (b, location, search_pspace);
13857 CATCH (e, RETURN_MASK_ERROR)
13859 int not_found_and_ok = 0;
13863 /* For pending breakpoints, it's expected that parsing will
13864 fail until the right shared library is loaded. User has
13865 already told to create pending breakpoints and don't need
13866 extra messages. If breakpoint is in bp_shlib_disabled
13867 state, then user already saw the message about that
13868 breakpoint being disabled, and don't want to see more
13870 if (e.error == NOT_FOUND_ERROR
13871 && (b->condition_not_parsed
13873 && search_pspace != NULL
13874 && b->loc->pspace != search_pspace)
13875 || (b->loc && b->loc->shlib_disabled)
13876 || (b->loc && b->loc->pspace->executing_startup)
13877 || b->enable_state == bp_disabled))
13878 not_found_and_ok = 1;
13880 if (!not_found_and_ok)
13882 /* We surely don't want to warn about the same breakpoint
13883 10 times. One solution, implemented here, is disable
13884 the breakpoint on error. Another solution would be to
13885 have separate 'warning emitted' flag. Since this
13886 happens only when a binary has changed, I don't know
13887 which approach is better. */
13888 b->enable_state = bp_disabled;
13889 throw_exception (e);
13894 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
13896 for (auto &sal : sals)
13897 resolve_sal_pc (&sal);
13898 if (b->condition_not_parsed && b->extra_string != NULL)
13900 char *cond_string, *extra_string;
13903 find_condition_and_thread (b->extra_string, sals[0].pc,
13904 &cond_string, &thread, &task,
13906 gdb_assert (b->cond_string == NULL);
13908 b->cond_string = cond_string;
13909 b->thread = thread;
13913 xfree (b->extra_string);
13914 b->extra_string = extra_string;
13916 b->condition_not_parsed = 0;
13919 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13920 sals[0] = update_static_tracepoint (b, sals[0]);
13930 /* The default re_set method, for typical hardware or software
13931 breakpoints. Reevaluate the breakpoint and recreate its
13935 breakpoint_re_set_default (struct breakpoint *b)
13937 struct program_space *filter_pspace = current_program_space;
13938 std::vector<symtab_and_line> expanded, expanded_end;
13941 std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
13942 filter_pspace, &found);
13944 expanded = std::move (sals);
13946 if (b->location_range_end != NULL)
13948 std::vector<symtab_and_line> sals_end
13949 = location_to_sals (b, b->location_range_end.get (),
13950 filter_pspace, &found);
13952 expanded_end = std::move (sals_end);
13955 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
13958 /* Default method for creating SALs from an address string. It basically
13959 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13962 create_sals_from_location_default (const struct event_location *location,
13963 struct linespec_result *canonical,
13964 enum bptype type_wanted)
13966 parse_breakpoint_sals (location, canonical);
13969 /* Call create_breakpoints_sal for the given arguments. This is the default
13970 function for the `create_breakpoints_sal' method of
13974 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13975 struct linespec_result *canonical,
13976 gdb::unique_xmalloc_ptr<char> cond_string,
13977 gdb::unique_xmalloc_ptr<char> extra_string,
13978 enum bptype type_wanted,
13979 enum bpdisp disposition,
13981 int task, int ignore_count,
13982 const struct breakpoint_ops *ops,
13983 int from_tty, int enabled,
13984 int internal, unsigned flags)
13986 create_breakpoints_sal (gdbarch, canonical,
13987 std::move (cond_string),
13988 std::move (extra_string),
13989 type_wanted, disposition,
13990 thread, task, ignore_count, ops, from_tty,
13991 enabled, internal, flags);
13994 /* Decode the line represented by S by calling decode_line_full. This is the
13995 default function for the `decode_location' method of breakpoint_ops. */
13997 static std::vector<symtab_and_line>
13998 decode_location_default (struct breakpoint *b,
13999 const struct event_location *location,
14000 struct program_space *search_pspace)
14002 struct linespec_result canonical;
14004 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
14005 (struct symtab *) NULL, 0,
14006 &canonical, multiple_symbols_all,
14009 /* We should get 0 or 1 resulting SALs. */
14010 gdb_assert (canonical.lsals.size () < 2);
14012 if (!canonical.lsals.empty ())
14014 const linespec_sals &lsal = canonical.lsals[0];
14015 return std::move (lsal.sals);
14020 /* Reset a breakpoint. */
14023 breakpoint_re_set_one (breakpoint *b)
14025 input_radix = b->input_radix;
14026 set_language (b->language);
14028 b->ops->re_set (b);
14031 /* Re-set breakpoint locations for the current program space.
14032 Locations bound to other program spaces are left untouched. */
14035 breakpoint_re_set (void)
14037 struct breakpoint *b, *b_tmp;
14040 scoped_restore_current_language save_language;
14041 scoped_restore save_input_radix = make_scoped_restore (&input_radix);
14042 scoped_restore_current_pspace_and_thread restore_pspace_thread;
14044 /* Note: we must not try to insert locations until after all
14045 breakpoints have been re-set. Otherwise, e.g., when re-setting
14046 breakpoint 1, we'd insert the locations of breakpoint 2, which
14047 hadn't been re-set yet, and thus may have stale locations. */
14049 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14053 breakpoint_re_set_one (b);
14055 CATCH (ex, RETURN_MASK_ALL)
14057 exception_fprintf (gdb_stderr, ex,
14058 "Error in re-setting breakpoint %d: ",
14064 jit_breakpoint_re_set ();
14067 create_overlay_event_breakpoint ();
14068 create_longjmp_master_breakpoint ();
14069 create_std_terminate_master_breakpoint ();
14070 create_exception_master_breakpoint ();
14072 /* Now we can insert. */
14073 update_global_location_list (UGLL_MAY_INSERT);
14076 /* Reset the thread number of this breakpoint:
14078 - If the breakpoint is for all threads, leave it as-is.
14079 - Else, reset it to the current thread for inferior_ptid. */
14081 breakpoint_re_set_thread (struct breakpoint *b)
14083 if (b->thread != -1)
14085 if (in_thread_list (inferior_ptid))
14086 b->thread = ptid_to_global_thread_id (inferior_ptid);
14088 /* We're being called after following a fork. The new fork is
14089 selected as current, and unless this was a vfork will have a
14090 different program space from the original thread. Reset that
14092 b->loc->pspace = current_program_space;
14096 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14097 If from_tty is nonzero, it prints a message to that effect,
14098 which ends with a period (no newline). */
14101 set_ignore_count (int bptnum, int count, int from_tty)
14103 struct breakpoint *b;
14108 ALL_BREAKPOINTS (b)
14109 if (b->number == bptnum)
14111 if (is_tracepoint (b))
14113 if (from_tty && count != 0)
14114 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14119 b->ignore_count = count;
14123 printf_filtered (_("Will stop next time "
14124 "breakpoint %d is reached."),
14126 else if (count == 1)
14127 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14130 printf_filtered (_("Will ignore next %d "
14131 "crossings of breakpoint %d."),
14134 observer_notify_breakpoint_modified (b);
14138 error (_("No breakpoint number %d."), bptnum);
14141 /* Command to set ignore-count of breakpoint N to COUNT. */
14144 ignore_command (char *args, int from_tty)
14150 error_no_arg (_("a breakpoint number"));
14152 num = get_number (&p);
14154 error (_("bad breakpoint number: '%s'"), args);
14156 error (_("Second argument (specified ignore-count) is missing."));
14158 set_ignore_count (num,
14159 longest_to_int (value_as_long (parse_and_eval (p))),
14162 printf_filtered ("\n");
14165 /* Call FUNCTION on each of the breakpoints
14166 whose numbers are given in ARGS. */
14169 map_breakpoint_numbers (const char *args,
14170 gdb::function_view<void (breakpoint *)> function)
14173 struct breakpoint *b, *tmp;
14175 if (args == 0 || *args == '\0')
14176 error_no_arg (_("one or more breakpoint numbers"));
14178 number_or_range_parser parser (args);
14180 while (!parser.finished ())
14182 const char *p = parser.cur_tok ();
14183 bool match = false;
14185 num = parser.get_number ();
14188 warning (_("bad breakpoint number at or near '%s'"), p);
14192 ALL_BREAKPOINTS_SAFE (b, tmp)
14193 if (b->number == num)
14200 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14205 static struct bp_location *
14206 find_location_by_number (const char *number)
14211 struct breakpoint *b;
14212 struct bp_location *loc;
14215 bp_num = get_number_trailer (&p1, '.');
14216 if (bp_num == 0 || p1[0] != '.')
14217 error (_("Bad breakpoint number '%s'"), number);
14219 ALL_BREAKPOINTS (b)
14220 if (b->number == bp_num)
14225 if (!b || b->number != bp_num)
14226 error (_("Bad breakpoint number '%s'"), number);
14228 /* Skip the dot. */
14230 const char *save = p1;
14231 loc_num = get_number (&p1);
14233 error (_("Bad breakpoint location number '%s'"), number);
14237 for (;loc_num && loc; --loc_num, loc = loc->next)
14240 error (_("Bad breakpoint location number '%s'"), save);
14246 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14247 If from_tty is nonzero, it prints a message to that effect,
14248 which ends with a period (no newline). */
14251 disable_breakpoint (struct breakpoint *bpt)
14253 /* Never disable a watchpoint scope breakpoint; we want to
14254 hit them when we leave scope so we can delete both the
14255 watchpoint and its scope breakpoint at that time. */
14256 if (bpt->type == bp_watchpoint_scope)
14259 bpt->enable_state = bp_disabled;
14261 /* Mark breakpoint locations modified. */
14262 mark_breakpoint_modified (bpt);
14264 if (target_supports_enable_disable_tracepoint ()
14265 && current_trace_status ()->running && is_tracepoint (bpt))
14267 struct bp_location *location;
14269 for (location = bpt->loc; location; location = location->next)
14270 target_disable_tracepoint (location);
14273 update_global_location_list (UGLL_DONT_INSERT);
14275 observer_notify_breakpoint_modified (bpt);
14279 disable_command (const char *args, int from_tty)
14283 struct breakpoint *bpt;
14285 ALL_BREAKPOINTS (bpt)
14286 if (user_breakpoint_p (bpt))
14287 disable_breakpoint (bpt);
14291 std::string num = extract_arg (&args);
14293 while (!num.empty ())
14295 if (num.find ('.') != std::string::npos)
14297 struct bp_location *loc = find_location_by_number (num.c_str ());
14304 mark_breakpoint_location_modified (loc);
14306 if (target_supports_enable_disable_tracepoint ()
14307 && current_trace_status ()->running && loc->owner
14308 && is_tracepoint (loc->owner))
14309 target_disable_tracepoint (loc);
14311 update_global_location_list (UGLL_DONT_INSERT);
14314 map_breakpoint_numbers
14315 (num.c_str (), [&] (breakpoint *b)
14317 iterate_over_related_breakpoints (b, disable_breakpoint);
14319 num = extract_arg (&args);
14325 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14328 int target_resources_ok;
14330 if (bpt->type == bp_hardware_breakpoint)
14333 i = hw_breakpoint_used_count ();
14334 target_resources_ok =
14335 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14337 if (target_resources_ok == 0)
14338 error (_("No hardware breakpoint support in the target."));
14339 else if (target_resources_ok < 0)
14340 error (_("Hardware breakpoints used exceeds limit."));
14343 if (is_watchpoint (bpt))
14345 /* Initialize it just to avoid a GCC false warning. */
14346 enum enable_state orig_enable_state = bp_disabled;
14350 struct watchpoint *w = (struct watchpoint *) bpt;
14352 orig_enable_state = bpt->enable_state;
14353 bpt->enable_state = bp_enabled;
14354 update_watchpoint (w, 1 /* reparse */);
14356 CATCH (e, RETURN_MASK_ALL)
14358 bpt->enable_state = orig_enable_state;
14359 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14366 bpt->enable_state = bp_enabled;
14368 /* Mark breakpoint locations modified. */
14369 mark_breakpoint_modified (bpt);
14371 if (target_supports_enable_disable_tracepoint ()
14372 && current_trace_status ()->running && is_tracepoint (bpt))
14374 struct bp_location *location;
14376 for (location = bpt->loc; location; location = location->next)
14377 target_enable_tracepoint (location);
14380 bpt->disposition = disposition;
14381 bpt->enable_count = count;
14382 update_global_location_list (UGLL_MAY_INSERT);
14384 observer_notify_breakpoint_modified (bpt);
14389 enable_breakpoint (struct breakpoint *bpt)
14391 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14394 /* The enable command enables the specified breakpoints (or all defined
14395 breakpoints) so they once again become (or continue to be) effective
14396 in stopping the inferior. */
14399 enable_command (const char *args, int from_tty)
14403 struct breakpoint *bpt;
14405 ALL_BREAKPOINTS (bpt)
14406 if (user_breakpoint_p (bpt))
14407 enable_breakpoint (bpt);
14411 std::string num = extract_arg (&args);
14413 while (!num.empty ())
14415 if (num.find ('.') != std::string::npos)
14417 struct bp_location *loc = find_location_by_number (num.c_str ());
14424 mark_breakpoint_location_modified (loc);
14426 if (target_supports_enable_disable_tracepoint ()
14427 && current_trace_status ()->running && loc->owner
14428 && is_tracepoint (loc->owner))
14429 target_enable_tracepoint (loc);
14431 update_global_location_list (UGLL_MAY_INSERT);
14434 map_breakpoint_numbers
14435 (num.c_str (), [&] (breakpoint *b)
14437 iterate_over_related_breakpoints (b, enable_breakpoint);
14439 num = extract_arg (&args);
14445 enable_once_command (const char *args, int from_tty)
14447 map_breakpoint_numbers
14448 (args, [&] (breakpoint *b)
14450 iterate_over_related_breakpoints
14451 (b, [&] (breakpoint *bpt)
14453 enable_breakpoint_disp (bpt, disp_disable, 1);
14459 enable_count_command (const char *args, int from_tty)
14464 error_no_arg (_("hit count"));
14466 count = get_number (&args);
14468 map_breakpoint_numbers
14469 (args, [&] (breakpoint *b)
14471 iterate_over_related_breakpoints
14472 (b, [&] (breakpoint *bpt)
14474 enable_breakpoint_disp (bpt, disp_disable, count);
14480 enable_delete_command (const char *args, int from_tty)
14482 map_breakpoint_numbers
14483 (args, [&] (breakpoint *b)
14485 iterate_over_related_breakpoints
14486 (b, [&] (breakpoint *bpt)
14488 enable_breakpoint_disp (bpt, disp_del, 1);
14494 set_breakpoint_cmd (const char *args, int from_tty)
14499 show_breakpoint_cmd (const char *args, int from_tty)
14503 /* Invalidate last known value of any hardware watchpoint if
14504 the memory which that value represents has been written to by
14508 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14509 CORE_ADDR addr, ssize_t len,
14510 const bfd_byte *data)
14512 struct breakpoint *bp;
14514 ALL_BREAKPOINTS (bp)
14515 if (bp->enable_state == bp_enabled
14516 && bp->type == bp_hardware_watchpoint)
14518 struct watchpoint *wp = (struct watchpoint *) bp;
14520 if (wp->val_valid && wp->val)
14522 struct bp_location *loc;
14524 for (loc = bp->loc; loc != NULL; loc = loc->next)
14525 if (loc->loc_type == bp_loc_hardware_watchpoint
14526 && loc->address + loc->length > addr
14527 && addr + len > loc->address)
14529 value_free (wp->val);
14537 /* Create and insert a breakpoint for software single step. */
14540 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14541 const address_space *aspace,
14544 struct thread_info *tp = inferior_thread ();
14545 struct symtab_and_line sal;
14546 CORE_ADDR pc = next_pc;
14548 if (tp->control.single_step_breakpoints == NULL)
14550 tp->control.single_step_breakpoints
14551 = new_single_step_breakpoint (tp->global_num, gdbarch);
14554 sal = find_pc_line (pc, 0);
14556 sal.section = find_pc_overlay (pc);
14557 sal.explicit_pc = 1;
14558 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
14560 update_global_location_list (UGLL_INSERT);
14563 /* Insert single step breakpoints according to the current state. */
14566 insert_single_step_breakpoints (struct gdbarch *gdbarch)
14568 struct regcache *regcache = get_current_regcache ();
14569 std::vector<CORE_ADDR> next_pcs;
14571 next_pcs = gdbarch_software_single_step (gdbarch, regcache);
14573 if (!next_pcs.empty ())
14575 struct frame_info *frame = get_current_frame ();
14576 struct address_space *aspace = get_frame_address_space (frame);
14578 for (CORE_ADDR pc : next_pcs)
14579 insert_single_step_breakpoint (gdbarch, aspace, pc);
14587 /* See breakpoint.h. */
14590 breakpoint_has_location_inserted_here (struct breakpoint *bp,
14591 const address_space *aspace,
14594 struct bp_location *loc;
14596 for (loc = bp->loc; loc != NULL; loc = loc->next)
14598 && breakpoint_location_address_match (loc, aspace, pc))
14604 /* Check whether a software single-step breakpoint is inserted at
14608 single_step_breakpoint_inserted_here_p (const address_space *aspace,
14611 struct breakpoint *bpt;
14613 ALL_BREAKPOINTS (bpt)
14615 if (bpt->type == bp_single_step
14616 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
14622 /* Tracepoint-specific operations. */
14624 /* Set tracepoint count to NUM. */
14626 set_tracepoint_count (int num)
14628 tracepoint_count = num;
14629 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14633 trace_command (char *arg_in, int from_tty)
14635 const char *arg = arg_in;
14636 struct breakpoint_ops *ops;
14638 event_location_up location = string_to_event_location (&arg,
14640 if (location != NULL
14641 && event_location_type (location.get ()) == PROBE_LOCATION)
14642 ops = &tracepoint_probe_breakpoint_ops;
14644 ops = &tracepoint_breakpoint_ops;
14646 create_breakpoint (get_current_arch (),
14648 NULL, 0, arg, 1 /* parse arg */,
14650 bp_tracepoint /* type_wanted */,
14651 0 /* Ignore count */,
14652 pending_break_support,
14656 0 /* internal */, 0);
14660 ftrace_command (char *arg_in, int from_tty)
14662 const char *arg = arg_in;
14663 event_location_up location = string_to_event_location (&arg,
14665 create_breakpoint (get_current_arch (),
14667 NULL, 0, arg, 1 /* parse arg */,
14669 bp_fast_tracepoint /* type_wanted */,
14670 0 /* Ignore count */,
14671 pending_break_support,
14672 &tracepoint_breakpoint_ops,
14675 0 /* internal */, 0);
14678 /* strace command implementation. Creates a static tracepoint. */
14681 strace_command (char *arg_in, int from_tty)
14683 const char *arg = arg_in;
14684 struct breakpoint_ops *ops;
14685 event_location_up location;
14687 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14688 or with a normal static tracepoint. */
14689 if (arg && startswith (arg, "-m") && isspace (arg[2]))
14691 ops = &strace_marker_breakpoint_ops;
14692 location = new_linespec_location (&arg);
14696 ops = &tracepoint_breakpoint_ops;
14697 location = string_to_event_location (&arg, current_language);
14700 create_breakpoint (get_current_arch (),
14702 NULL, 0, arg, 1 /* parse arg */,
14704 bp_static_tracepoint /* type_wanted */,
14705 0 /* Ignore count */,
14706 pending_break_support,
14710 0 /* internal */, 0);
14713 /* Set up a fake reader function that gets command lines from a linked
14714 list that was acquired during tracepoint uploading. */
14716 static struct uploaded_tp *this_utp;
14717 static int next_cmd;
14720 read_uploaded_action (void)
14724 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14731 /* Given information about a tracepoint as recorded on a target (which
14732 can be either a live system or a trace file), attempt to create an
14733 equivalent GDB tracepoint. This is not a reliable process, since
14734 the target does not necessarily have all the information used when
14735 the tracepoint was originally defined. */
14737 struct tracepoint *
14738 create_tracepoint_from_upload (struct uploaded_tp *utp)
14740 const char *addr_str;
14741 char small_buf[100];
14742 struct tracepoint *tp;
14744 if (utp->at_string)
14745 addr_str = utp->at_string;
14748 /* In the absence of a source location, fall back to raw
14749 address. Since there is no way to confirm that the address
14750 means the same thing as when the trace was started, warn the
14752 warning (_("Uploaded tracepoint %d has no "
14753 "source location, using raw address"),
14755 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
14756 addr_str = small_buf;
14759 /* There's not much we can do with a sequence of bytecodes. */
14760 if (utp->cond && !utp->cond_string)
14761 warning (_("Uploaded tracepoint %d condition "
14762 "has no source form, ignoring it"),
14765 event_location_up location = string_to_event_location (&addr_str,
14767 if (!create_breakpoint (get_current_arch (),
14769 utp->cond_string, -1, addr_str,
14770 0 /* parse cond/thread */,
14772 utp->type /* type_wanted */,
14773 0 /* Ignore count */,
14774 pending_break_support,
14775 &tracepoint_breakpoint_ops,
14777 utp->enabled /* enabled */,
14779 CREATE_BREAKPOINT_FLAGS_INSERTED))
14782 /* Get the tracepoint we just created. */
14783 tp = get_tracepoint (tracepoint_count);
14784 gdb_assert (tp != NULL);
14788 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
14791 trace_pass_command (small_buf, 0);
14794 /* If we have uploaded versions of the original commands, set up a
14795 special-purpose "reader" function and call the usual command line
14796 reader, then pass the result to the breakpoint command-setting
14798 if (!VEC_empty (char_ptr, utp->cmd_strings))
14800 command_line_up cmd_list;
14805 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14807 breakpoint_set_commands (tp, std::move (cmd_list));
14809 else if (!VEC_empty (char_ptr, utp->actions)
14810 || !VEC_empty (char_ptr, utp->step_actions))
14811 warning (_("Uploaded tracepoint %d actions "
14812 "have no source form, ignoring them"),
14815 /* Copy any status information that might be available. */
14816 tp->hit_count = utp->hit_count;
14817 tp->traceframe_usage = utp->traceframe_usage;
14822 /* Print information on tracepoint number TPNUM_EXP, or all if
14826 info_tracepoints_command (char *args, int from_tty)
14828 struct ui_out *uiout = current_uiout;
14831 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14833 if (num_printed == 0)
14835 if (args == NULL || *args == '\0')
14836 uiout->message ("No tracepoints.\n");
14838 uiout->message ("No tracepoint matching '%s'.\n", args);
14841 default_collect_info ();
14844 /* The 'enable trace' command enables tracepoints.
14845 Not supported by all targets. */
14847 enable_trace_command (char *args, int from_tty)
14849 enable_command (args, from_tty);
14852 /* The 'disable trace' command disables tracepoints.
14853 Not supported by all targets. */
14855 disable_trace_command (char *args, int from_tty)
14857 disable_command (args, from_tty);
14860 /* Remove a tracepoint (or all if no argument). */
14862 delete_trace_command (const char *arg, int from_tty)
14864 struct breakpoint *b, *b_tmp;
14870 int breaks_to_delete = 0;
14872 /* Delete all breakpoints if no argument.
14873 Do not delete internal or call-dummy breakpoints, these
14874 have to be deleted with an explicit breakpoint number
14876 ALL_TRACEPOINTS (b)
14877 if (is_tracepoint (b) && user_breakpoint_p (b))
14879 breaks_to_delete = 1;
14883 /* Ask user only if there are some breakpoints to delete. */
14885 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14887 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14888 if (is_tracepoint (b) && user_breakpoint_p (b))
14889 delete_breakpoint (b);
14893 map_breakpoint_numbers
14894 (arg, [&] (breakpoint *b)
14896 iterate_over_related_breakpoints (b, delete_breakpoint);
14900 /* Helper function for trace_pass_command. */
14903 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14905 tp->pass_count = count;
14906 observer_notify_breakpoint_modified (tp);
14908 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14909 tp->number, count);
14912 /* Set passcount for tracepoint.
14914 First command argument is passcount, second is tracepoint number.
14915 If tracepoint number omitted, apply to most recently defined.
14916 Also accepts special argument "all". */
14919 trace_pass_command (char *args, int from_tty)
14921 struct tracepoint *t1;
14922 unsigned int count;
14924 if (args == 0 || *args == 0)
14925 error (_("passcount command requires an "
14926 "argument (count + optional TP num)"));
14928 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14930 args = skip_spaces (args);
14931 if (*args && strncasecmp (args, "all", 3) == 0)
14933 struct breakpoint *b;
14935 args += 3; /* Skip special argument "all". */
14937 error (_("Junk at end of arguments."));
14939 ALL_TRACEPOINTS (b)
14941 t1 = (struct tracepoint *) b;
14942 trace_pass_set_count (t1, count, from_tty);
14945 else if (*args == '\0')
14947 t1 = get_tracepoint_by_number (&args, NULL);
14949 trace_pass_set_count (t1, count, from_tty);
14953 number_or_range_parser parser (args);
14954 while (!parser.finished ())
14956 t1 = get_tracepoint_by_number (&args, &parser);
14958 trace_pass_set_count (t1, count, from_tty);
14963 struct tracepoint *
14964 get_tracepoint (int num)
14966 struct breakpoint *t;
14968 ALL_TRACEPOINTS (t)
14969 if (t->number == num)
14970 return (struct tracepoint *) t;
14975 /* Find the tracepoint with the given target-side number (which may be
14976 different from the tracepoint number after disconnecting and
14979 struct tracepoint *
14980 get_tracepoint_by_number_on_target (int num)
14982 struct breakpoint *b;
14984 ALL_TRACEPOINTS (b)
14986 struct tracepoint *t = (struct tracepoint *) b;
14988 if (t->number_on_target == num)
14995 /* Utility: parse a tracepoint number and look it up in the list.
14996 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14997 If the argument is missing, the most recent tracepoint
14998 (tracepoint_count) is returned. */
15000 struct tracepoint *
15001 get_tracepoint_by_number (char **arg,
15002 number_or_range_parser *parser)
15004 struct breakpoint *t;
15006 char *instring = arg == NULL ? NULL : *arg;
15008 if (parser != NULL)
15010 gdb_assert (!parser->finished ());
15011 tpnum = parser->get_number ();
15013 else if (arg == NULL || *arg == NULL || ! **arg)
15014 tpnum = tracepoint_count;
15016 tpnum = get_number (arg);
15020 if (instring && *instring)
15021 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15024 printf_filtered (_("No previous tracepoint\n"));
15028 ALL_TRACEPOINTS (t)
15029 if (t->number == tpnum)
15031 return (struct tracepoint *) t;
15034 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15039 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15041 if (b->thread != -1)
15042 fprintf_unfiltered (fp, " thread %d", b->thread);
15045 fprintf_unfiltered (fp, " task %d", b->task);
15047 fprintf_unfiltered (fp, "\n");
15050 /* Save information on user settable breakpoints (watchpoints, etc) to
15051 a new script file named FILENAME. If FILTER is non-NULL, call it
15052 on each breakpoint and only include the ones for which it returns
15056 save_breakpoints (const char *filename, int from_tty,
15057 int (*filter) (const struct breakpoint *))
15059 struct breakpoint *tp;
15061 int extra_trace_bits = 0;
15063 if (filename == 0 || *filename == 0)
15064 error (_("Argument required (file name in which to save)"));
15066 /* See if we have anything to save. */
15067 ALL_BREAKPOINTS (tp)
15069 /* Skip internal and momentary breakpoints. */
15070 if (!user_breakpoint_p (tp))
15073 /* If we have a filter, only save the breakpoints it accepts. */
15074 if (filter && !filter (tp))
15079 if (is_tracepoint (tp))
15081 extra_trace_bits = 1;
15083 /* We can stop searching. */
15090 warning (_("Nothing to save."));
15094 gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
15098 if (!fp.open (expanded_filename.get (), "w"))
15099 error (_("Unable to open file '%s' for saving (%s)"),
15100 expanded_filename.get (), safe_strerror (errno));
15102 if (extra_trace_bits)
15103 save_trace_state_variables (&fp);
15105 ALL_BREAKPOINTS (tp)
15107 /* Skip internal and momentary breakpoints. */
15108 if (!user_breakpoint_p (tp))
15111 /* If we have a filter, only save the breakpoints it accepts. */
15112 if (filter && !filter (tp))
15115 tp->ops->print_recreate (tp, &fp);
15117 /* Note, we can't rely on tp->number for anything, as we can't
15118 assume the recreated breakpoint numbers will match. Use $bpnum
15121 if (tp->cond_string)
15122 fp.printf (" condition $bpnum %s\n", tp->cond_string);
15124 if (tp->ignore_count)
15125 fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
15127 if (tp->type != bp_dprintf && tp->commands)
15129 fp.puts (" commands\n");
15131 current_uiout->redirect (&fp);
15134 print_command_lines (current_uiout, tp->commands.get (), 2);
15136 CATCH (ex, RETURN_MASK_ALL)
15138 current_uiout->redirect (NULL);
15139 throw_exception (ex);
15143 current_uiout->redirect (NULL);
15144 fp.puts (" end\n");
15147 if (tp->enable_state == bp_disabled)
15148 fp.puts ("disable $bpnum\n");
15150 /* If this is a multi-location breakpoint, check if the locations
15151 should be individually disabled. Watchpoint locations are
15152 special, and not user visible. */
15153 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15155 struct bp_location *loc;
15158 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15160 fp.printf ("disable $bpnum.%d\n", n);
15164 if (extra_trace_bits && *default_collect)
15165 fp.printf ("set default-collect %s\n", default_collect);
15168 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ());
15171 /* The `save breakpoints' command. */
15174 save_breakpoints_command (const char *args, int from_tty)
15176 save_breakpoints (args, from_tty, NULL);
15179 /* The `save tracepoints' command. */
15182 save_tracepoints_command (const char *args, int from_tty)
15184 save_breakpoints (args, from_tty, is_tracepoint);
15187 /* Create a vector of all tracepoints. */
15189 VEC(breakpoint_p) *
15190 all_tracepoints (void)
15192 VEC(breakpoint_p) *tp_vec = 0;
15193 struct breakpoint *tp;
15195 ALL_TRACEPOINTS (tp)
15197 VEC_safe_push (breakpoint_p, tp_vec, tp);
15204 /* This help string is used to consolidate all the help string for specifying
15205 locations used by several commands. */
15207 #define LOCATION_HELP_STRING \
15208 "Linespecs are colon-separated lists of location parameters, such as\n\
15209 source filename, function name, label name, and line number.\n\
15210 Example: To specify the start of a label named \"the_top\" in the\n\
15211 function \"fact\" in the file \"factorial.c\", use\n\
15212 \"factorial.c:fact:the_top\".\n\
15214 Address locations begin with \"*\" and specify an exact address in the\n\
15215 program. Example: To specify the fourth byte past the start function\n\
15216 \"main\", use \"*main + 4\".\n\
15218 Explicit locations are similar to linespecs but use an option/argument\n\
15219 syntax to specify location parameters.\n\
15220 Example: To specify the start of the label named \"the_top\" in the\n\
15221 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15222 -function fact -label the_top\".\n"
15224 /* This help string is used for the break, hbreak, tbreak and thbreak
15225 commands. It is defined as a macro to prevent duplication.
15226 COMMAND should be a string constant containing the name of the
15229 #define BREAK_ARGS_HELP(command) \
15230 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15231 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15232 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15233 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15234 `-probe-dtrace' (for a DTrace probe).\n\
15235 LOCATION may be a linespec, address, or explicit location as described\n\
15238 With no LOCATION, uses current execution address of the selected\n\
15239 stack frame. This is useful for breaking on return to a stack frame.\n\
15241 THREADNUM is the number from \"info threads\".\n\
15242 CONDITION is a boolean expression.\n\
15243 \n" LOCATION_HELP_STRING "\n\
15244 Multiple breakpoints at one place are permitted, and useful if their\n\
15245 conditions are different.\n\
15247 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15249 /* List of subcommands for "catch". */
15250 static struct cmd_list_element *catch_cmdlist;
15252 /* List of subcommands for "tcatch". */
15253 static struct cmd_list_element *tcatch_cmdlist;
15256 add_catch_command (const char *name, const char *docstring,
15257 cmd_sfunc_ftype *sfunc,
15258 completer_ftype *completer,
15259 void *user_data_catch,
15260 void *user_data_tcatch)
15262 struct cmd_list_element *command;
15264 command = add_cmd (name, class_breakpoint, docstring,
15266 set_cmd_sfunc (command, sfunc);
15267 set_cmd_context (command, user_data_catch);
15268 set_cmd_completer (command, completer);
15270 command = add_cmd (name, class_breakpoint, docstring,
15272 set_cmd_sfunc (command, sfunc);
15273 set_cmd_context (command, user_data_tcatch);
15274 set_cmd_completer (command, completer);
15278 save_command (const char *arg, int from_tty)
15280 printf_unfiltered (_("\"save\" must be followed by "
15281 "the name of a save subcommand.\n"));
15282 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15285 struct breakpoint *
15286 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15289 struct breakpoint *b, *b_tmp;
15291 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15293 if ((*callback) (b, data))
15300 /* Zero if any of the breakpoint's locations could be a location where
15301 functions have been inlined, nonzero otherwise. */
15304 is_non_inline_function (struct breakpoint *b)
15306 /* The shared library event breakpoint is set on the address of a
15307 non-inline function. */
15308 if (b->type == bp_shlib_event)
15314 /* Nonzero if the specified PC cannot be a location where functions
15315 have been inlined. */
15318 pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
15319 const struct target_waitstatus *ws)
15321 struct breakpoint *b;
15322 struct bp_location *bl;
15324 ALL_BREAKPOINTS (b)
15326 if (!is_non_inline_function (b))
15329 for (bl = b->loc; bl != NULL; bl = bl->next)
15331 if (!bl->shlib_disabled
15332 && bpstat_check_location (bl, aspace, pc, ws))
15340 /* Remove any references to OBJFILE which is going to be freed. */
15343 breakpoint_free_objfile (struct objfile *objfile)
15345 struct bp_location **locp, *loc;
15347 ALL_BP_LOCATIONS (loc, locp)
15348 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15349 loc->symtab = NULL;
15353 initialize_breakpoint_ops (void)
15355 static int initialized = 0;
15357 struct breakpoint_ops *ops;
15363 /* The breakpoint_ops structure to be inherit by all kinds of
15364 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15365 internal and momentary breakpoints, etc.). */
15366 ops = &bkpt_base_breakpoint_ops;
15367 *ops = base_breakpoint_ops;
15368 ops->re_set = bkpt_re_set;
15369 ops->insert_location = bkpt_insert_location;
15370 ops->remove_location = bkpt_remove_location;
15371 ops->breakpoint_hit = bkpt_breakpoint_hit;
15372 ops->create_sals_from_location = bkpt_create_sals_from_location;
15373 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15374 ops->decode_location = bkpt_decode_location;
15376 /* The breakpoint_ops structure to be used in regular breakpoints. */
15377 ops = &bkpt_breakpoint_ops;
15378 *ops = bkpt_base_breakpoint_ops;
15379 ops->re_set = bkpt_re_set;
15380 ops->resources_needed = bkpt_resources_needed;
15381 ops->print_it = bkpt_print_it;
15382 ops->print_mention = bkpt_print_mention;
15383 ops->print_recreate = bkpt_print_recreate;
15385 /* Ranged breakpoints. */
15386 ops = &ranged_breakpoint_ops;
15387 *ops = bkpt_breakpoint_ops;
15388 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15389 ops->resources_needed = resources_needed_ranged_breakpoint;
15390 ops->print_it = print_it_ranged_breakpoint;
15391 ops->print_one = print_one_ranged_breakpoint;
15392 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15393 ops->print_mention = print_mention_ranged_breakpoint;
15394 ops->print_recreate = print_recreate_ranged_breakpoint;
15396 /* Internal breakpoints. */
15397 ops = &internal_breakpoint_ops;
15398 *ops = bkpt_base_breakpoint_ops;
15399 ops->re_set = internal_bkpt_re_set;
15400 ops->check_status = internal_bkpt_check_status;
15401 ops->print_it = internal_bkpt_print_it;
15402 ops->print_mention = internal_bkpt_print_mention;
15404 /* Momentary breakpoints. */
15405 ops = &momentary_breakpoint_ops;
15406 *ops = bkpt_base_breakpoint_ops;
15407 ops->re_set = momentary_bkpt_re_set;
15408 ops->check_status = momentary_bkpt_check_status;
15409 ops->print_it = momentary_bkpt_print_it;
15410 ops->print_mention = momentary_bkpt_print_mention;
15412 /* Probe breakpoints. */
15413 ops = &bkpt_probe_breakpoint_ops;
15414 *ops = bkpt_breakpoint_ops;
15415 ops->insert_location = bkpt_probe_insert_location;
15416 ops->remove_location = bkpt_probe_remove_location;
15417 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
15418 ops->decode_location = bkpt_probe_decode_location;
15421 ops = &watchpoint_breakpoint_ops;
15422 *ops = base_breakpoint_ops;
15423 ops->re_set = re_set_watchpoint;
15424 ops->insert_location = insert_watchpoint;
15425 ops->remove_location = remove_watchpoint;
15426 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15427 ops->check_status = check_status_watchpoint;
15428 ops->resources_needed = resources_needed_watchpoint;
15429 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15430 ops->print_it = print_it_watchpoint;
15431 ops->print_mention = print_mention_watchpoint;
15432 ops->print_recreate = print_recreate_watchpoint;
15433 ops->explains_signal = explains_signal_watchpoint;
15435 /* Masked watchpoints. */
15436 ops = &masked_watchpoint_breakpoint_ops;
15437 *ops = watchpoint_breakpoint_ops;
15438 ops->insert_location = insert_masked_watchpoint;
15439 ops->remove_location = remove_masked_watchpoint;
15440 ops->resources_needed = resources_needed_masked_watchpoint;
15441 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15442 ops->print_it = print_it_masked_watchpoint;
15443 ops->print_one_detail = print_one_detail_masked_watchpoint;
15444 ops->print_mention = print_mention_masked_watchpoint;
15445 ops->print_recreate = print_recreate_masked_watchpoint;
15448 ops = &tracepoint_breakpoint_ops;
15449 *ops = base_breakpoint_ops;
15450 ops->re_set = tracepoint_re_set;
15451 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15452 ops->print_one_detail = tracepoint_print_one_detail;
15453 ops->print_mention = tracepoint_print_mention;
15454 ops->print_recreate = tracepoint_print_recreate;
15455 ops->create_sals_from_location = tracepoint_create_sals_from_location;
15456 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15457 ops->decode_location = tracepoint_decode_location;
15459 /* Probe tracepoints. */
15460 ops = &tracepoint_probe_breakpoint_ops;
15461 *ops = tracepoint_breakpoint_ops;
15462 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
15463 ops->decode_location = tracepoint_probe_decode_location;
15465 /* Static tracepoints with marker (`-m'). */
15466 ops = &strace_marker_breakpoint_ops;
15467 *ops = tracepoint_breakpoint_ops;
15468 ops->create_sals_from_location = strace_marker_create_sals_from_location;
15469 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15470 ops->decode_location = strace_marker_decode_location;
15472 /* Fork catchpoints. */
15473 ops = &catch_fork_breakpoint_ops;
15474 *ops = base_breakpoint_ops;
15475 ops->insert_location = insert_catch_fork;
15476 ops->remove_location = remove_catch_fork;
15477 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15478 ops->print_it = print_it_catch_fork;
15479 ops->print_one = print_one_catch_fork;
15480 ops->print_mention = print_mention_catch_fork;
15481 ops->print_recreate = print_recreate_catch_fork;
15483 /* Vfork catchpoints. */
15484 ops = &catch_vfork_breakpoint_ops;
15485 *ops = base_breakpoint_ops;
15486 ops->insert_location = insert_catch_vfork;
15487 ops->remove_location = remove_catch_vfork;
15488 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15489 ops->print_it = print_it_catch_vfork;
15490 ops->print_one = print_one_catch_vfork;
15491 ops->print_mention = print_mention_catch_vfork;
15492 ops->print_recreate = print_recreate_catch_vfork;
15494 /* Exec catchpoints. */
15495 ops = &catch_exec_breakpoint_ops;
15496 *ops = base_breakpoint_ops;
15497 ops->insert_location = insert_catch_exec;
15498 ops->remove_location = remove_catch_exec;
15499 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15500 ops->print_it = print_it_catch_exec;
15501 ops->print_one = print_one_catch_exec;
15502 ops->print_mention = print_mention_catch_exec;
15503 ops->print_recreate = print_recreate_catch_exec;
15505 /* Solib-related catchpoints. */
15506 ops = &catch_solib_breakpoint_ops;
15507 *ops = base_breakpoint_ops;
15508 ops->insert_location = insert_catch_solib;
15509 ops->remove_location = remove_catch_solib;
15510 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15511 ops->check_status = check_status_catch_solib;
15512 ops->print_it = print_it_catch_solib;
15513 ops->print_one = print_one_catch_solib;
15514 ops->print_mention = print_mention_catch_solib;
15515 ops->print_recreate = print_recreate_catch_solib;
15517 ops = &dprintf_breakpoint_ops;
15518 *ops = bkpt_base_breakpoint_ops;
15519 ops->re_set = dprintf_re_set;
15520 ops->resources_needed = bkpt_resources_needed;
15521 ops->print_it = bkpt_print_it;
15522 ops->print_mention = bkpt_print_mention;
15523 ops->print_recreate = dprintf_print_recreate;
15524 ops->after_condition_true = dprintf_after_condition_true;
15525 ops->breakpoint_hit = dprintf_breakpoint_hit;
15528 /* Chain containing all defined "enable breakpoint" subcommands. */
15530 static struct cmd_list_element *enablebreaklist = NULL;
15533 _initialize_breakpoint (void)
15535 struct cmd_list_element *c;
15537 initialize_breakpoint_ops ();
15539 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15540 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
15541 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15543 breakpoint_objfile_key
15544 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15546 breakpoint_chain = 0;
15547 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15548 before a breakpoint is set. */
15549 breakpoint_count = 0;
15551 tracepoint_count = 0;
15553 add_com ("ignore", class_breakpoint, ignore_command, _("\
15554 Set ignore-count of breakpoint number N to COUNT.\n\
15555 Usage is `ignore N COUNT'."));
15557 add_com ("commands", class_breakpoint, commands_command, _("\
15558 Set commands to be executed when the given breakpoints are hit.\n\
15559 Give a space-separated breakpoint list as argument after \"commands\".\n\
15560 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15562 With no argument, the targeted breakpoint is the last one set.\n\
15563 The commands themselves follow starting on the next line.\n\
15564 Type a line containing \"end\" to indicate the end of them.\n\
15565 Give \"silent\" as the first line to make the breakpoint silent;\n\
15566 then no output is printed when it is hit, except what the commands print."));
15568 c = add_com ("condition", class_breakpoint, condition_command, _("\
15569 Specify breakpoint number N to break only if COND is true.\n\
15570 Usage is `condition N COND', where N is an integer and COND is an\n\
15571 expression to be evaluated whenever breakpoint N is reached."));
15572 set_cmd_completer (c, condition_completer);
15574 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15575 Set a temporary breakpoint.\n\
15576 Like \"break\" except the breakpoint is only temporary,\n\
15577 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15578 by using \"enable delete\" on the breakpoint number.\n\
15580 BREAK_ARGS_HELP ("tbreak")));
15581 set_cmd_completer (c, location_completer);
15583 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15584 Set a hardware assisted breakpoint.\n\
15585 Like \"break\" except the breakpoint requires hardware support,\n\
15586 some target hardware may not have this support.\n\
15588 BREAK_ARGS_HELP ("hbreak")));
15589 set_cmd_completer (c, location_completer);
15591 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15592 Set a temporary hardware assisted breakpoint.\n\
15593 Like \"hbreak\" except the breakpoint is only temporary,\n\
15594 so it will be deleted when hit.\n\
15596 BREAK_ARGS_HELP ("thbreak")));
15597 set_cmd_completer (c, location_completer);
15599 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15600 Enable some breakpoints.\n\
15601 Give breakpoint numbers (separated by spaces) as arguments.\n\
15602 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15603 This is used to cancel the effect of the \"disable\" command.\n\
15604 With a subcommand you can enable temporarily."),
15605 &enablelist, "enable ", 1, &cmdlist);
15607 add_com_alias ("en", "enable", class_breakpoint, 1);
15609 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15610 Enable some breakpoints.\n\
15611 Give breakpoint numbers (separated by spaces) as arguments.\n\
15612 This is used to cancel the effect of the \"disable\" command.\n\
15613 May be abbreviated to simply \"enable\".\n"),
15614 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15616 add_cmd ("once", no_class, enable_once_command, _("\
15617 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15618 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15621 add_cmd ("delete", no_class, enable_delete_command, _("\
15622 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15623 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15626 add_cmd ("count", no_class, enable_count_command, _("\
15627 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15628 If a breakpoint is hit while enabled in this fashion,\n\
15629 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15632 add_cmd ("delete", no_class, enable_delete_command, _("\
15633 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15634 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15637 add_cmd ("once", no_class, enable_once_command, _("\
15638 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15639 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15642 add_cmd ("count", no_class, enable_count_command, _("\
15643 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15644 If a breakpoint is hit while enabled in this fashion,\n\
15645 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15648 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15649 Disable some breakpoints.\n\
15650 Arguments are breakpoint numbers with spaces in between.\n\
15651 To disable all breakpoints, give no argument.\n\
15652 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15653 &disablelist, "disable ", 1, &cmdlist);
15654 add_com_alias ("dis", "disable", class_breakpoint, 1);
15655 add_com_alias ("disa", "disable", class_breakpoint, 1);
15657 add_cmd ("breakpoints", class_alias, disable_command, _("\
15658 Disable some breakpoints.\n\
15659 Arguments are breakpoint numbers with spaces in between.\n\
15660 To disable all breakpoints, give no argument.\n\
15661 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15662 This command may be abbreviated \"disable\"."),
15665 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15666 Delete some breakpoints or auto-display expressions.\n\
15667 Arguments are breakpoint numbers with spaces in between.\n\
15668 To delete all breakpoints, give no argument.\n\
15670 Also a prefix command for deletion of other GDB objects.\n\
15671 The \"unset\" command is also an alias for \"delete\"."),
15672 &deletelist, "delete ", 1, &cmdlist);
15673 add_com_alias ("d", "delete", class_breakpoint, 1);
15674 add_com_alias ("del", "delete", class_breakpoint, 1);
15676 add_cmd ("breakpoints", class_alias, delete_command, _("\
15677 Delete some breakpoints or auto-display expressions.\n\
15678 Arguments are breakpoint numbers with spaces in between.\n\
15679 To delete all breakpoints, give no argument.\n\
15680 This command may be abbreviated \"delete\"."),
15683 add_com ("clear", class_breakpoint, clear_command, _("\
15684 Clear breakpoint at specified location.\n\
15685 Argument may be a linespec, explicit, or address location as described below.\n\
15687 With no argument, clears all breakpoints in the line that the selected frame\n\
15688 is executing in.\n"
15689 "\n" LOCATION_HELP_STRING "\n\
15690 See also the \"delete\" command which clears breakpoints by number."));
15691 add_com_alias ("cl", "clear", class_breakpoint, 1);
15693 c = add_com ("break", class_breakpoint, break_command, _("\
15694 Set breakpoint at specified location.\n"
15695 BREAK_ARGS_HELP ("break")));
15696 set_cmd_completer (c, location_completer);
15698 add_com_alias ("b", "break", class_run, 1);
15699 add_com_alias ("br", "break", class_run, 1);
15700 add_com_alias ("bre", "break", class_run, 1);
15701 add_com_alias ("brea", "break", class_run, 1);
15705 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15706 Break in function/address or break at a line in the current file."),
15707 &stoplist, "stop ", 1, &cmdlist);
15708 add_cmd ("in", class_breakpoint, stopin_command,
15709 _("Break in function or address."), &stoplist);
15710 add_cmd ("at", class_breakpoint, stopat_command,
15711 _("Break at a line in the current file."), &stoplist);
15712 add_com ("status", class_info, info_breakpoints_command, _("\
15713 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15714 The \"Type\" column indicates one of:\n\
15715 \tbreakpoint - normal breakpoint\n\
15716 \twatchpoint - watchpoint\n\
15717 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15718 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15719 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15720 address and file/line number respectively.\n\
15722 Convenience variable \"$_\" and default examine address for \"x\"\n\
15723 are set to the address of the last breakpoint listed unless the command\n\
15724 is prefixed with \"server \".\n\n\
15725 Convenience variable \"$bpnum\" contains the number of the last\n\
15726 breakpoint set."));
15729 add_info ("breakpoints", info_breakpoints_command, _("\
15730 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15731 The \"Type\" column indicates one of:\n\
15732 \tbreakpoint - normal breakpoint\n\
15733 \twatchpoint - watchpoint\n\
15734 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15735 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15736 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15737 address and file/line number respectively.\n\
15739 Convenience variable \"$_\" and default examine address for \"x\"\n\
15740 are set to the address of the last breakpoint listed unless the command\n\
15741 is prefixed with \"server \".\n\n\
15742 Convenience variable \"$bpnum\" contains the number of the last\n\
15743 breakpoint set."));
15745 add_info_alias ("b", "breakpoints", 1);
15747 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15748 Status of all breakpoints, or breakpoint number NUMBER.\n\
15749 The \"Type\" column indicates one of:\n\
15750 \tbreakpoint - normal breakpoint\n\
15751 \twatchpoint - watchpoint\n\
15752 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15753 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15754 \tuntil - internal breakpoint used by the \"until\" command\n\
15755 \tfinish - internal breakpoint used by the \"finish\" command\n\
15756 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15757 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15758 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15759 address and file/line number respectively.\n\
15761 Convenience variable \"$_\" and default examine address for \"x\"\n\
15762 are set to the address of the last breakpoint listed unless the command\n\
15763 is prefixed with \"server \".\n\n\
15764 Convenience variable \"$bpnum\" contains the number of the last\n\
15766 &maintenanceinfolist);
15768 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15769 Set catchpoints to catch events."),
15770 &catch_cmdlist, "catch ",
15771 0/*allow-unknown*/, &cmdlist);
15773 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15774 Set temporary catchpoints to catch events."),
15775 &tcatch_cmdlist, "tcatch ",
15776 0/*allow-unknown*/, &cmdlist);
15778 add_catch_command ("fork", _("Catch calls to fork."),
15779 catch_fork_command_1,
15781 (void *) (uintptr_t) catch_fork_permanent,
15782 (void *) (uintptr_t) catch_fork_temporary);
15783 add_catch_command ("vfork", _("Catch calls to vfork."),
15784 catch_fork_command_1,
15786 (void *) (uintptr_t) catch_vfork_permanent,
15787 (void *) (uintptr_t) catch_vfork_temporary);
15788 add_catch_command ("exec", _("Catch calls to exec."),
15789 catch_exec_command_1,
15793 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15794 Usage: catch load [REGEX]\n\
15795 If REGEX is given, only stop for libraries matching the regular expression."),
15796 catch_load_command_1,
15800 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15801 Usage: catch unload [REGEX]\n\
15802 If REGEX is given, only stop for libraries matching the regular expression."),
15803 catch_unload_command_1,
15808 c = add_com ("watch", class_breakpoint, watch_command, _("\
15809 Set a watchpoint for an expression.\n\
15810 Usage: watch [-l|-location] EXPRESSION\n\
15811 A watchpoint stops execution of your program whenever the value of\n\
15812 an expression changes.\n\
15813 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15814 the memory to which it refers."));
15815 set_cmd_completer (c, expression_completer);
15817 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15818 Set a read watchpoint for an expression.\n\
15819 Usage: rwatch [-l|-location] EXPRESSION\n\
15820 A watchpoint stops execution of your program whenever the value of\n\
15821 an expression is read.\n\
15822 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15823 the memory to which it refers."));
15824 set_cmd_completer (c, expression_completer);
15826 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15827 Set a watchpoint for an expression.\n\
15828 Usage: awatch [-l|-location] EXPRESSION\n\
15829 A watchpoint stops execution of your program whenever the value of\n\
15830 an expression is either read or written.\n\
15831 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15832 the memory to which it refers."));
15833 set_cmd_completer (c, expression_completer);
15835 add_info ("watchpoints", info_watchpoints_command, _("\
15836 Status of specified watchpoints (all watchpoints if no argument)."));
15838 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15839 respond to changes - contrary to the description. */
15840 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15841 &can_use_hw_watchpoints, _("\
15842 Set debugger's willingness to use watchpoint hardware."), _("\
15843 Show debugger's willingness to use watchpoint hardware."), _("\
15844 If zero, gdb will not use hardware for new watchpoints, even if\n\
15845 such is available. (However, any hardware watchpoints that were\n\
15846 created before setting this to nonzero, will continue to use watchpoint\n\
15849 show_can_use_hw_watchpoints,
15850 &setlist, &showlist);
15852 can_use_hw_watchpoints = 1;
15854 /* Tracepoint manipulation commands. */
15856 c = add_com ("trace", class_breakpoint, trace_command, _("\
15857 Set a tracepoint at specified location.\n\
15859 BREAK_ARGS_HELP ("trace") "\n\
15860 Do \"help tracepoints\" for info on other tracepoint commands."));
15861 set_cmd_completer (c, location_completer);
15863 add_com_alias ("tp", "trace", class_alias, 0);
15864 add_com_alias ("tr", "trace", class_alias, 1);
15865 add_com_alias ("tra", "trace", class_alias, 1);
15866 add_com_alias ("trac", "trace", class_alias, 1);
15868 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15869 Set a fast tracepoint at specified location.\n\
15871 BREAK_ARGS_HELP ("ftrace") "\n\
15872 Do \"help tracepoints\" for info on other tracepoint commands."));
15873 set_cmd_completer (c, location_completer);
15875 c = add_com ("strace", class_breakpoint, strace_command, _("\
15876 Set a static tracepoint at location or marker.\n\
15878 strace [LOCATION] [if CONDITION]\n\
15879 LOCATION may be a linespec, explicit, or address location (described below) \n\
15880 or -m MARKER_ID.\n\n\
15881 If a marker id is specified, probe the marker with that name. With\n\
15882 no LOCATION, uses current execution address of the selected stack frame.\n\
15883 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15884 This collects arbitrary user data passed in the probe point call to the\n\
15885 tracing library. You can inspect it when analyzing the trace buffer,\n\
15886 by printing the $_sdata variable like any other convenience variable.\n\
15888 CONDITION is a boolean expression.\n\
15889 \n" LOCATION_HELP_STRING "\n\
15890 Multiple tracepoints at one place are permitted, and useful if their\n\
15891 conditions are different.\n\
15893 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15894 Do \"help tracepoints\" for info on other tracepoint commands."));
15895 set_cmd_completer (c, location_completer);
15897 add_info ("tracepoints", info_tracepoints_command, _("\
15898 Status of specified tracepoints (all tracepoints if no argument).\n\
15899 Convenience variable \"$tpnum\" contains the number of the\n\
15900 last tracepoint set."));
15902 add_info_alias ("tp", "tracepoints", 1);
15904 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15905 Delete specified tracepoints.\n\
15906 Arguments are tracepoint numbers, separated by spaces.\n\
15907 No argument means delete all tracepoints."),
15909 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
15911 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15912 Disable specified tracepoints.\n\
15913 Arguments are tracepoint numbers, separated by spaces.\n\
15914 No argument means disable all tracepoints."),
15916 deprecate_cmd (c, "disable");
15918 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15919 Enable specified tracepoints.\n\
15920 Arguments are tracepoint numbers, separated by spaces.\n\
15921 No argument means enable all tracepoints."),
15923 deprecate_cmd (c, "enable");
15925 add_com ("passcount", class_trace, trace_pass_command, _("\
15926 Set the passcount for a tracepoint.\n\
15927 The trace will end when the tracepoint has been passed 'count' times.\n\
15928 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15929 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15931 add_prefix_cmd ("save", class_breakpoint, save_command,
15932 _("Save breakpoint definitions as a script."),
15933 &save_cmdlist, "save ",
15934 0/*allow-unknown*/, &cmdlist);
15936 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15937 Save current breakpoint definitions as a script.\n\
15938 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15939 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15940 session to restore them."),
15942 set_cmd_completer (c, filename_completer);
15944 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15945 Save current tracepoint definitions as a script.\n\
15946 Use the 'source' command in another debug session to restore them."),
15948 set_cmd_completer (c, filename_completer);
15950 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15951 deprecate_cmd (c, "save tracepoints");
15953 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15954 Breakpoint specific settings\n\
15955 Configure various breakpoint-specific variables such as\n\
15956 pending breakpoint behavior"),
15957 &breakpoint_set_cmdlist, "set breakpoint ",
15958 0/*allow-unknown*/, &setlist);
15959 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15960 Breakpoint specific settings\n\
15961 Configure various breakpoint-specific variables such as\n\
15962 pending breakpoint behavior"),
15963 &breakpoint_show_cmdlist, "show breakpoint ",
15964 0/*allow-unknown*/, &showlist);
15966 add_setshow_auto_boolean_cmd ("pending", no_class,
15967 &pending_break_support, _("\
15968 Set debugger's behavior regarding pending breakpoints."), _("\
15969 Show debugger's behavior regarding pending breakpoints."), _("\
15970 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15971 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15972 an error. If auto, an unrecognized breakpoint location results in a\n\
15973 user-query to see if a pending breakpoint should be created."),
15975 show_pending_break_support,
15976 &breakpoint_set_cmdlist,
15977 &breakpoint_show_cmdlist);
15979 pending_break_support = AUTO_BOOLEAN_AUTO;
15981 add_setshow_boolean_cmd ("auto-hw", no_class,
15982 &automatic_hardware_breakpoints, _("\
15983 Set automatic usage of hardware breakpoints."), _("\
15984 Show automatic usage of hardware breakpoints."), _("\
15985 If set, the debugger will automatically use hardware breakpoints for\n\
15986 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15987 a warning will be emitted for such breakpoints."),
15989 show_automatic_hardware_breakpoints,
15990 &breakpoint_set_cmdlist,
15991 &breakpoint_show_cmdlist);
15993 add_setshow_boolean_cmd ("always-inserted", class_support,
15994 &always_inserted_mode, _("\
15995 Set mode for inserting breakpoints."), _("\
15996 Show mode for inserting breakpoints."), _("\
15997 When this mode is on, breakpoints are inserted immediately as soon as\n\
15998 they're created, kept inserted even when execution stops, and removed\n\
15999 only when the user deletes them. When this mode is off (the default),\n\
16000 breakpoints are inserted only when execution continues, and removed\n\
16001 when execution stops."),
16003 &show_always_inserted_mode,
16004 &breakpoint_set_cmdlist,
16005 &breakpoint_show_cmdlist);
16007 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16008 condition_evaluation_enums,
16009 &condition_evaluation_mode_1, _("\
16010 Set mode of breakpoint condition evaluation."), _("\
16011 Show mode of breakpoint condition evaluation."), _("\
16012 When this is set to \"host\", breakpoint conditions will be\n\
16013 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16014 breakpoint conditions will be downloaded to the target (if the target\n\
16015 supports such feature) and conditions will be evaluated on the target's side.\n\
16016 If this is set to \"auto\" (default), this will be automatically set to\n\
16017 \"target\" if it supports condition evaluation, otherwise it will\n\
16018 be set to \"gdb\""),
16019 &set_condition_evaluation_mode,
16020 &show_condition_evaluation_mode,
16021 &breakpoint_set_cmdlist,
16022 &breakpoint_show_cmdlist);
16024 add_com ("break-range", class_breakpoint, break_range_command, _("\
16025 Set a breakpoint for an address range.\n\
16026 break-range START-LOCATION, END-LOCATION\n\
16027 where START-LOCATION and END-LOCATION can be one of the following:\n\
16028 LINENUM, for that line in the current file,\n\
16029 FILE:LINENUM, for that line in that file,\n\
16030 +OFFSET, for that number of lines after the current line\n\
16031 or the start of the range\n\
16032 FUNCTION, for the first line in that function,\n\
16033 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16034 *ADDRESS, for the instruction at that address.\n\
16036 The breakpoint will stop execution of the inferior whenever it executes\n\
16037 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16038 range (including START-LOCATION and END-LOCATION)."));
16040 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16041 Set a dynamic printf at specified location.\n\
16042 dprintf location,format string,arg1,arg2,...\n\
16043 location may be a linespec, explicit, or address location.\n"
16044 "\n" LOCATION_HELP_STRING));
16045 set_cmd_completer (c, location_completer);
16047 add_setshow_enum_cmd ("dprintf-style", class_support,
16048 dprintf_style_enums, &dprintf_style, _("\
16049 Set the style of usage for dynamic printf."), _("\
16050 Show the style of usage for dynamic printf."), _("\
16051 This setting chooses how GDB will do a dynamic printf.\n\
16052 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16053 console, as with the \"printf\" command.\n\
16054 If the value is \"call\", the print is done by calling a function in your\n\
16055 program; by default printf(), but you can choose a different function or\n\
16056 output stream by setting dprintf-function and dprintf-channel."),
16057 update_dprintf_commands, NULL,
16058 &setlist, &showlist);
16060 dprintf_function = xstrdup ("printf");
16061 add_setshow_string_cmd ("dprintf-function", class_support,
16062 &dprintf_function, _("\
16063 Set the function to use for dynamic printf"), _("\
16064 Show the function to use for dynamic printf"), NULL,
16065 update_dprintf_commands, NULL,
16066 &setlist, &showlist);
16068 dprintf_channel = xstrdup ("");
16069 add_setshow_string_cmd ("dprintf-channel", class_support,
16070 &dprintf_channel, _("\
16071 Set the channel to use for dynamic printf"), _("\
16072 Show the channel to use for dynamic printf"), NULL,
16073 update_dprintf_commands, NULL,
16074 &setlist, &showlist);
16076 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16077 &disconnected_dprintf, _("\
16078 Set whether dprintf continues after GDB disconnects."), _("\
16079 Show whether dprintf continues after GDB disconnects."), _("\
16080 Use this to let dprintf commands continue to hit and produce output\n\
16081 even if GDB disconnects or detaches from the target."),
16084 &setlist, &showlist);
16086 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16087 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16088 (target agent only) This is useful for formatted output in user-defined commands."));
16090 automatic_hardware_breakpoints = 1;
16092 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16093 observer_attach_thread_exit (remove_threaded_breakpoints);