1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "xml-syscall.h"
60 #include "parser-defs.h"
61 #include "gdb_regex.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "dummy-frame.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 /* Enums for exception-handling support. */
83 enum exception_event_kind
90 /* Prototypes for local functions. */
92 static void enable_delete_command (char *, int);
94 static void enable_once_command (char *, int);
96 static void enable_count_command (char *, int);
98 static void disable_command (char *, int);
100 static void enable_command (char *, int);
102 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
106 static void ignore_command (char *, int);
108 static int breakpoint_re_set_one (void *);
110 static void breakpoint_re_set_default (struct breakpoint *);
112 static void create_sals_from_address_default (char **,
113 struct linespec_result *,
117 static void create_breakpoints_sal_default (struct gdbarch *,
118 struct linespec_result *,
119 char *, char *, enum bptype,
120 enum bpdisp, int, int,
122 const struct breakpoint_ops *,
123 int, int, int, unsigned);
125 static void decode_linespec_default (struct breakpoint *, char **,
126 struct symtabs_and_lines *);
128 static void clear_command (char *, int);
130 static void catch_command (char *, int);
132 static int can_use_hardware_watchpoint (struct value *);
134 static void break_command_1 (char *, int, int);
136 static void mention (struct breakpoint *);
138 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
140 const struct breakpoint_ops *);
141 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
142 const struct symtab_and_line *);
144 /* This function is used in gdbtk sources and thus can not be made
146 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
147 struct symtab_and_line,
149 const struct breakpoint_ops *);
151 static struct breakpoint *
152 momentary_breakpoint_from_master (struct breakpoint *orig,
154 const struct breakpoint_ops *ops,
157 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
159 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
163 static void describe_other_breakpoints (struct gdbarch *,
164 struct program_space *, CORE_ADDR,
165 struct obj_section *, int);
167 static int watchpoint_locations_match (struct bp_location *loc1,
168 struct bp_location *loc2);
170 static int breakpoint_location_address_match (struct bp_location *bl,
171 struct address_space *aspace,
174 static void breakpoints_info (char *, int);
176 static void watchpoints_info (char *, int);
178 static int breakpoint_1 (char *, int,
179 int (*) (const struct breakpoint *));
181 static int breakpoint_cond_eval (void *);
183 static void cleanup_executing_breakpoints (void *);
185 static void commands_command (char *, int);
187 static void condition_command (char *, int);
196 static int remove_breakpoint (struct bp_location *, insertion_state_t);
197 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
199 static enum print_stop_action print_bp_stop_message (bpstat bs);
201 static int watchpoint_check (void *);
203 static void maintenance_info_breakpoints (char *, int);
205 static int hw_breakpoint_used_count (void);
207 static int hw_watchpoint_use_count (struct breakpoint *);
209 static int hw_watchpoint_used_count_others (struct breakpoint *except,
211 int *other_type_used);
213 static void hbreak_command (char *, int);
215 static void thbreak_command (char *, int);
217 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
220 static void stop_command (char *arg, int from_tty);
222 static void stopin_command (char *arg, int from_tty);
224 static void stopat_command (char *arg, int from_tty);
226 static void tcatch_command (char *arg, int from_tty);
228 static void free_bp_location (struct bp_location *loc);
229 static void incref_bp_location (struct bp_location *loc);
230 static void decref_bp_location (struct bp_location **loc);
232 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
234 /* update_global_location_list's modes of operation wrt to whether to
235 insert locations now. */
236 enum ugll_insert_mode
238 /* Don't insert any breakpoint locations into the inferior, only
239 remove already-inserted locations that no longer should be
240 inserted. Functions that delete a breakpoint or breakpoints
241 should specify this mode, so that deleting a breakpoint doesn't
242 have the side effect of inserting the locations of other
243 breakpoints that are marked not-inserted, but should_be_inserted
244 returns true on them.
246 This behavior is useful is situations close to tear-down -- e.g.,
247 after an exec, while the target still has execution, but
248 breakpoint shadows of the previous executable image should *NOT*
249 be restored to the new image; or before detaching, where the
250 target still has execution and wants to delete breakpoints from
251 GDB's lists, and all breakpoints had already been removed from
255 /* May insert breakpoints iff breakpoints_should_be_inserted_now
256 claims breakpoints should be inserted now. */
259 /* Insert locations now, irrespective of
260 breakpoints_should_be_inserted_now. E.g., say all threads are
261 stopped right now, and the user did "continue". We need to
262 insert breakpoints _before_ resuming the target, but
263 UGLL_MAY_INSERT wouldn't insert them, because
264 breakpoints_should_be_inserted_now returns false at that point,
265 as no thread is running yet. */
269 static void update_global_location_list (enum ugll_insert_mode);
271 static void update_global_location_list_nothrow (enum ugll_insert_mode);
273 static int is_hardware_watchpoint (const struct breakpoint *bpt);
275 static void insert_breakpoint_locations (void);
277 static int syscall_catchpoint_p (struct breakpoint *b);
279 static void tracepoints_info (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num);
291 static int is_masked_watchpoint (const struct breakpoint *b);
293 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint *b);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops;
311 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
312 static struct breakpoint_ops longjmp_breakpoint_ops;
314 /* The breakpoint_ops structure to be used in regular user created
316 struct breakpoint_ops bkpt_breakpoint_ops;
318 /* Breakpoints set on probes. */
319 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
321 /* Dynamic printf class type. */
322 struct breakpoint_ops dprintf_breakpoint_ops;
324 /* The style in which to perform a dynamic printf. This is a user
325 option because different output options have different tradeoffs;
326 if GDB does the printing, there is better error handling if there
327 is a problem with any of the arguments, but using an inferior
328 function lets you have special-purpose printers and sending of
329 output to the same place as compiled-in print functions. */
331 static const char dprintf_style_gdb[] = "gdb";
332 static const char dprintf_style_call[] = "call";
333 static const char dprintf_style_agent[] = "agent";
334 static const char *const dprintf_style_enums[] = {
340 static const char *dprintf_style = dprintf_style_gdb;
342 /* The function to use for dynamic printf if the preferred style is to
343 call into the inferior. The value is simply a string that is
344 copied into the command, so it can be anything that GDB can
345 evaluate to a callable address, not necessarily a function name. */
347 static char *dprintf_function = "";
349 /* The channel to use for dynamic printf if the preferred style is to
350 call into the inferior; if a nonempty string, it will be passed to
351 the call as the first argument, with the format string as the
352 second. As with the dprintf function, this can be anything that
353 GDB knows how to evaluate, so in addition to common choices like
354 "stderr", this could be an app-specific expression like
355 "mystreams[curlogger]". */
357 static char *dprintf_channel = "";
359 /* True if dprintf commands should continue to operate even if GDB
361 static int disconnected_dprintf = 1;
363 /* A reference-counted struct command_line. This lets multiple
364 breakpoints share a single command list. */
365 struct counted_command_line
367 /* The reference count. */
370 /* The command list. */
371 struct command_line *commands;
374 struct command_line *
375 breakpoint_commands (struct breakpoint *b)
377 return b->commands ? b->commands->commands : NULL;
380 /* Flag indicating that a command has proceeded the inferior past the
381 current breakpoint. */
383 static int breakpoint_proceeded;
386 bpdisp_text (enum bpdisp disp)
388 /* NOTE: the following values are a part of MI protocol and
389 represent values of 'disp' field returned when inferior stops at
391 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
393 return bpdisps[(int) disp];
396 /* Prototypes for exported functions. */
397 /* If FALSE, gdb will not use hardware support for watchpoints, even
398 if such is available. */
399 static int can_use_hw_watchpoints;
402 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
403 struct cmd_list_element *c,
406 fprintf_filtered (file,
407 _("Debugger's willingness to use "
408 "watchpoint hardware is %s.\n"),
412 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
413 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
414 for unrecognized breakpoint locations.
415 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
416 static enum auto_boolean pending_break_support;
418 show_pending_break_support (struct ui_file *file, int from_tty,
419 struct cmd_list_element *c,
422 fprintf_filtered (file,
423 _("Debugger's behavior regarding "
424 "pending breakpoints is %s.\n"),
428 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
429 set with "break" but falling in read-only memory.
430 If 0, gdb will warn about such breakpoints, but won't automatically
431 use hardware breakpoints. */
432 static int automatic_hardware_breakpoints;
434 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
435 struct cmd_list_element *c,
438 fprintf_filtered (file,
439 _("Automatic usage of hardware breakpoints is %s.\n"),
443 /* If on, GDB keeps breakpoints inserted even if the inferior is
444 stopped, and immediately inserts any new breakpoints as soon as
445 they're created. If off (default), GDB keeps breakpoints off of
446 the target as long as possible. That is, it delays inserting
447 breakpoints until the next resume, and removes them again when the
448 target fully stops. This is a bit safer in case GDB crashes while
449 processing user input. */
450 static int always_inserted_mode = 0;
453 show_always_inserted_mode (struct ui_file *file, int from_tty,
454 struct cmd_list_element *c, const char *value)
456 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
460 /* See breakpoint.h. */
463 breakpoints_should_be_inserted_now (void)
465 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
467 /* If breakpoints are global, they should be inserted even if no
468 thread under gdb's control is running, or even if there are
469 no threads under GDB's control yet. */
472 else if (target_has_execution)
474 if (always_inserted_mode)
476 /* The user wants breakpoints inserted even if all threads
481 if (threads_are_executing ())
487 static const char condition_evaluation_both[] = "host or target";
489 /* Modes for breakpoint condition evaluation. */
490 static const char condition_evaluation_auto[] = "auto";
491 static const char condition_evaluation_host[] = "host";
492 static const char condition_evaluation_target[] = "target";
493 static const char *const condition_evaluation_enums[] = {
494 condition_evaluation_auto,
495 condition_evaluation_host,
496 condition_evaluation_target,
500 /* Global that holds the current mode for breakpoint condition evaluation. */
501 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
503 /* Global that we use to display information to the user (gets its value from
504 condition_evaluation_mode_1. */
505 static const char *condition_evaluation_mode = condition_evaluation_auto;
507 /* Translate a condition evaluation mode MODE into either "host"
508 or "target". This is used mostly to translate from "auto" to the
509 real setting that is being used. It returns the translated
513 translate_condition_evaluation_mode (const char *mode)
515 if (mode == condition_evaluation_auto)
517 if (target_supports_evaluation_of_breakpoint_conditions ())
518 return condition_evaluation_target;
520 return condition_evaluation_host;
526 /* Discovers what condition_evaluation_auto translates to. */
529 breakpoint_condition_evaluation_mode (void)
531 return translate_condition_evaluation_mode (condition_evaluation_mode);
534 /* Return true if GDB should evaluate breakpoint conditions or false
538 gdb_evaluates_breakpoint_condition_p (void)
540 const char *mode = breakpoint_condition_evaluation_mode ();
542 return (mode == condition_evaluation_host);
545 void _initialize_breakpoint (void);
547 /* Are we executing breakpoint commands? */
548 static int executing_breakpoint_commands;
550 /* Are overlay event breakpoints enabled? */
551 static int overlay_events_enabled;
553 /* See description in breakpoint.h. */
554 int target_exact_watchpoints = 0;
556 /* Walk the following statement or block through all breakpoints.
557 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
558 current breakpoint. */
560 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
562 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
563 for (B = breakpoint_chain; \
564 B ? (TMP=B->next, 1): 0; \
567 /* Similar iterator for the low-level breakpoints. SAFE variant is
568 not provided so update_global_location_list must not be called
569 while executing the block of ALL_BP_LOCATIONS. */
571 #define ALL_BP_LOCATIONS(B,BP_TMP) \
572 for (BP_TMP = bp_location; \
573 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
576 /* Iterates through locations with address ADDRESS for the currently selected
577 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
578 to where the loop should start from.
579 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
580 appropriate location to start with. */
582 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
583 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
584 BP_LOCP_TMP = BP_LOCP_START; \
586 && (BP_LOCP_TMP < bp_location + bp_location_count \
587 && (*BP_LOCP_TMP)->address == ADDRESS); \
590 /* Iterator for tracepoints only. */
592 #define ALL_TRACEPOINTS(B) \
593 for (B = breakpoint_chain; B; B = B->next) \
594 if (is_tracepoint (B))
596 /* Chains of all breakpoints defined. */
598 struct breakpoint *breakpoint_chain;
600 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
602 static struct bp_location **bp_location;
604 /* Number of elements of BP_LOCATION. */
606 static unsigned bp_location_count;
608 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
609 ADDRESS for the current elements of BP_LOCATION which get a valid
610 result from bp_location_has_shadow. You can use it for roughly
611 limiting the subrange of BP_LOCATION to scan for shadow bytes for
612 an address you need to read. */
614 static CORE_ADDR bp_location_placed_address_before_address_max;
616 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
617 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
618 BP_LOCATION which get a valid result from bp_location_has_shadow.
619 You can use it for roughly limiting the subrange of BP_LOCATION to
620 scan for shadow bytes for an address you need to read. */
622 static CORE_ADDR bp_location_shadow_len_after_address_max;
624 /* The locations that no longer correspond to any breakpoint, unlinked
625 from bp_location array, but for which a hit may still be reported
627 VEC(bp_location_p) *moribund_locations = NULL;
629 /* Number of last breakpoint made. */
631 static int breakpoint_count;
633 /* The value of `breakpoint_count' before the last command that
634 created breakpoints. If the last (break-like) command created more
635 than one breakpoint, then the difference between BREAKPOINT_COUNT
636 and PREV_BREAKPOINT_COUNT is more than one. */
637 static int prev_breakpoint_count;
639 /* Number of last tracepoint made. */
641 static int tracepoint_count;
643 static struct cmd_list_element *breakpoint_set_cmdlist;
644 static struct cmd_list_element *breakpoint_show_cmdlist;
645 struct cmd_list_element *save_cmdlist;
647 /* Return whether a breakpoint is an active enabled breakpoint. */
649 breakpoint_enabled (struct breakpoint *b)
651 return (b->enable_state == bp_enabled);
654 /* Set breakpoint count to NUM. */
657 set_breakpoint_count (int num)
659 prev_breakpoint_count = breakpoint_count;
660 breakpoint_count = num;
661 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
664 /* Used by `start_rbreak_breakpoints' below, to record the current
665 breakpoint count before "rbreak" creates any breakpoint. */
666 static int rbreak_start_breakpoint_count;
668 /* Called at the start an "rbreak" command to record the first
672 start_rbreak_breakpoints (void)
674 rbreak_start_breakpoint_count = breakpoint_count;
677 /* Called at the end of an "rbreak" command to record the last
681 end_rbreak_breakpoints (void)
683 prev_breakpoint_count = rbreak_start_breakpoint_count;
686 /* Used in run_command to zero the hit count when a new run starts. */
689 clear_breakpoint_hit_counts (void)
691 struct breakpoint *b;
697 /* Allocate a new counted_command_line with reference count of 1.
698 The new structure owns COMMANDS. */
700 static struct counted_command_line *
701 alloc_counted_command_line (struct command_line *commands)
703 struct counted_command_line *result
704 = xmalloc (sizeof (struct counted_command_line));
707 result->commands = commands;
711 /* Increment reference count. This does nothing if CMD is NULL. */
714 incref_counted_command_line (struct counted_command_line *cmd)
720 /* Decrement reference count. If the reference count reaches 0,
721 destroy the counted_command_line. Sets *CMDP to NULL. This does
722 nothing if *CMDP is NULL. */
725 decref_counted_command_line (struct counted_command_line **cmdp)
729 if (--(*cmdp)->refc == 0)
731 free_command_lines (&(*cmdp)->commands);
738 /* A cleanup function that calls decref_counted_command_line. */
741 do_cleanup_counted_command_line (void *arg)
743 decref_counted_command_line (arg);
746 /* Create a cleanup that calls decref_counted_command_line on the
749 static struct cleanup *
750 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
752 return make_cleanup (do_cleanup_counted_command_line, cmdp);
756 /* Return the breakpoint with the specified number, or NULL
757 if the number does not refer to an existing breakpoint. */
760 get_breakpoint (int num)
762 struct breakpoint *b;
765 if (b->number == num)
773 /* Mark locations as "conditions have changed" in case the target supports
774 evaluating conditions on its side. */
777 mark_breakpoint_modified (struct breakpoint *b)
779 struct bp_location *loc;
781 /* This is only meaningful if the target is
782 evaluating conditions and if the user has
783 opted for condition evaluation on the target's
785 if (gdb_evaluates_breakpoint_condition_p ()
786 || !target_supports_evaluation_of_breakpoint_conditions ())
789 if (!is_breakpoint (b))
792 for (loc = b->loc; loc; loc = loc->next)
793 loc->condition_changed = condition_modified;
796 /* Mark location as "conditions have changed" in case the target supports
797 evaluating conditions on its side. */
800 mark_breakpoint_location_modified (struct bp_location *loc)
802 /* This is only meaningful if the target is
803 evaluating conditions and if the user has
804 opted for condition evaluation on the target's
806 if (gdb_evaluates_breakpoint_condition_p ()
807 || !target_supports_evaluation_of_breakpoint_conditions ())
811 if (!is_breakpoint (loc->owner))
814 loc->condition_changed = condition_modified;
817 /* Sets the condition-evaluation mode using the static global
818 condition_evaluation_mode. */
821 set_condition_evaluation_mode (char *args, int from_tty,
822 struct cmd_list_element *c)
824 const char *old_mode, *new_mode;
826 if ((condition_evaluation_mode_1 == condition_evaluation_target)
827 && !target_supports_evaluation_of_breakpoint_conditions ())
829 condition_evaluation_mode_1 = condition_evaluation_mode;
830 warning (_("Target does not support breakpoint condition evaluation.\n"
831 "Using host evaluation mode instead."));
835 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
836 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
838 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
839 settings was "auto". */
840 condition_evaluation_mode = condition_evaluation_mode_1;
842 /* Only update the mode if the user picked a different one. */
843 if (new_mode != old_mode)
845 struct bp_location *loc, **loc_tmp;
846 /* If the user switched to a different evaluation mode, we
847 need to synch the changes with the target as follows:
849 "host" -> "target": Send all (valid) conditions to the target.
850 "target" -> "host": Remove all the conditions from the target.
853 if (new_mode == condition_evaluation_target)
855 /* Mark everything modified and synch conditions with the
857 ALL_BP_LOCATIONS (loc, loc_tmp)
858 mark_breakpoint_location_modified (loc);
862 /* Manually mark non-duplicate locations to synch conditions
863 with the target. We do this to remove all the conditions the
864 target knows about. */
865 ALL_BP_LOCATIONS (loc, loc_tmp)
866 if (is_breakpoint (loc->owner) && loc->inserted)
867 loc->needs_update = 1;
871 update_global_location_list (UGLL_MAY_INSERT);
877 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
878 what "auto" is translating to. */
881 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
882 struct cmd_list_element *c, const char *value)
884 if (condition_evaluation_mode == condition_evaluation_auto)
885 fprintf_filtered (file,
886 _("Breakpoint condition evaluation "
887 "mode is %s (currently %s).\n"),
889 breakpoint_condition_evaluation_mode ());
891 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
895 /* A comparison function for bp_location AP and BP that is used by
896 bsearch. This comparison function only cares about addresses, unlike
897 the more general bp_location_compare function. */
900 bp_location_compare_addrs (const void *ap, const void *bp)
902 struct bp_location *a = *(void **) ap;
903 struct bp_location *b = *(void **) bp;
905 if (a->address == b->address)
908 return ((a->address > b->address) - (a->address < b->address));
911 /* Helper function to skip all bp_locations with addresses
912 less than ADDRESS. It returns the first bp_location that
913 is greater than or equal to ADDRESS. If none is found, just
916 static struct bp_location **
917 get_first_locp_gte_addr (CORE_ADDR address)
919 struct bp_location dummy_loc;
920 struct bp_location *dummy_locp = &dummy_loc;
921 struct bp_location **locp_found = NULL;
923 /* Initialize the dummy location's address field. */
924 memset (&dummy_loc, 0, sizeof (struct bp_location));
925 dummy_loc.address = address;
927 /* Find a close match to the first location at ADDRESS. */
928 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
929 sizeof (struct bp_location **),
930 bp_location_compare_addrs);
932 /* Nothing was found, nothing left to do. */
933 if (locp_found == NULL)
936 /* We may have found a location that is at ADDRESS but is not the first in the
937 location's list. Go backwards (if possible) and locate the first one. */
938 while ((locp_found - 1) >= bp_location
939 && (*(locp_found - 1))->address == address)
946 set_breakpoint_condition (struct breakpoint *b, char *exp,
949 xfree (b->cond_string);
950 b->cond_string = NULL;
952 if (is_watchpoint (b))
954 struct watchpoint *w = (struct watchpoint *) b;
961 struct bp_location *loc;
963 for (loc = b->loc; loc; loc = loc->next)
968 /* No need to free the condition agent expression
969 bytecode (if we have one). We will handle this
970 when we go through update_global_location_list. */
977 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
981 const char *arg = exp;
983 /* I don't know if it matters whether this is the string the user
984 typed in or the decompiled expression. */
985 b->cond_string = xstrdup (arg);
986 b->condition_not_parsed = 0;
988 if (is_watchpoint (b))
990 struct watchpoint *w = (struct watchpoint *) b;
992 innermost_block = NULL;
994 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
996 error (_("Junk at end of expression"));
997 w->cond_exp_valid_block = innermost_block;
1001 struct bp_location *loc;
1003 for (loc = b->loc; loc; loc = loc->next)
1007 parse_exp_1 (&arg, loc->address,
1008 block_for_pc (loc->address), 0);
1010 error (_("Junk at end of expression"));
1014 mark_breakpoint_modified (b);
1016 observer_notify_breakpoint_modified (b);
1019 /* Completion for the "condition" command. */
1021 static VEC (char_ptr) *
1022 condition_completer (struct cmd_list_element *cmd,
1023 const char *text, const char *word)
1027 text = skip_spaces_const (text);
1028 space = skip_to_space_const (text);
1032 struct breakpoint *b;
1033 VEC (char_ptr) *result = NULL;
1037 /* We don't support completion of history indices. */
1038 if (isdigit (text[1]))
1040 return complete_internalvar (&text[1]);
1043 /* We're completing the breakpoint number. */
1044 len = strlen (text);
1050 xsnprintf (number, sizeof (number), "%d", b->number);
1052 if (strncmp (number, text, len) == 0)
1053 VEC_safe_push (char_ptr, result, xstrdup (number));
1059 /* We're completing the expression part. */
1060 text = skip_spaces_const (space);
1061 return expression_completer (cmd, text, word);
1064 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1067 condition_command (char *arg, int from_tty)
1069 struct breakpoint *b;
1074 error_no_arg (_("breakpoint number"));
1077 bnum = get_number (&p);
1079 error (_("Bad breakpoint argument: '%s'"), arg);
1082 if (b->number == bnum)
1084 /* Check if this breakpoint has a "stop" method implemented in an
1085 extension language. This method and conditions entered into GDB
1086 from the CLI are mutually exclusive. */
1087 const struct extension_language_defn *extlang
1088 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1090 if (extlang != NULL)
1092 error (_("Only one stop condition allowed. There is currently"
1093 " a %s stop condition defined for this breakpoint."),
1094 ext_lang_capitalized_name (extlang));
1096 set_breakpoint_condition (b, p, from_tty);
1098 if (is_breakpoint (b))
1099 update_global_location_list (UGLL_MAY_INSERT);
1104 error (_("No breakpoint number %d."), bnum);
1107 /* Check that COMMAND do not contain commands that are suitable
1108 only for tracepoints and not suitable for ordinary breakpoints.
1109 Throw if any such commands is found. */
1112 check_no_tracepoint_commands (struct command_line *commands)
1114 struct command_line *c;
1116 for (c = commands; c; c = c->next)
1120 if (c->control_type == while_stepping_control)
1121 error (_("The 'while-stepping' command can "
1122 "only be used for tracepoints"));
1124 for (i = 0; i < c->body_count; ++i)
1125 check_no_tracepoint_commands ((c->body_list)[i]);
1127 /* Not that command parsing removes leading whitespace and comment
1128 lines and also empty lines. So, we only need to check for
1129 command directly. */
1130 if (strstr (c->line, "collect ") == c->line)
1131 error (_("The 'collect' command can only be used for tracepoints"));
1133 if (strstr (c->line, "teval ") == c->line)
1134 error (_("The 'teval' command can only be used for tracepoints"));
1138 /* Encapsulate tests for different types of tracepoints. */
1141 is_tracepoint_type (enum bptype type)
1143 return (type == bp_tracepoint
1144 || type == bp_fast_tracepoint
1145 || type == bp_static_tracepoint);
1149 is_tracepoint (const struct breakpoint *b)
1151 return is_tracepoint_type (b->type);
1154 /* A helper function that validates that COMMANDS are valid for a
1155 breakpoint. This function will throw an exception if a problem is
1159 validate_commands_for_breakpoint (struct breakpoint *b,
1160 struct command_line *commands)
1162 if (is_tracepoint (b))
1164 struct tracepoint *t = (struct tracepoint *) b;
1165 struct command_line *c;
1166 struct command_line *while_stepping = 0;
1168 /* Reset the while-stepping step count. The previous commands
1169 might have included a while-stepping action, while the new
1173 /* We need to verify that each top-level element of commands is
1174 valid for tracepoints, that there's at most one
1175 while-stepping element, and that the while-stepping's body
1176 has valid tracing commands excluding nested while-stepping.
1177 We also need to validate the tracepoint action line in the
1178 context of the tracepoint --- validate_actionline actually
1179 has side effects, like setting the tracepoint's
1180 while-stepping STEP_COUNT, in addition to checking if the
1181 collect/teval actions parse and make sense in the
1182 tracepoint's context. */
1183 for (c = commands; c; c = c->next)
1185 if (c->control_type == while_stepping_control)
1187 if (b->type == bp_fast_tracepoint)
1188 error (_("The 'while-stepping' command "
1189 "cannot be used for fast tracepoint"));
1190 else if (b->type == bp_static_tracepoint)
1191 error (_("The 'while-stepping' command "
1192 "cannot be used for static tracepoint"));
1195 error (_("The 'while-stepping' command "
1196 "can be used only once"));
1201 validate_actionline (c->line, b);
1205 struct command_line *c2;
1207 gdb_assert (while_stepping->body_count == 1);
1208 c2 = while_stepping->body_list[0];
1209 for (; c2; c2 = c2->next)
1211 if (c2->control_type == while_stepping_control)
1212 error (_("The 'while-stepping' command cannot be nested"));
1218 check_no_tracepoint_commands (commands);
1222 /* Return a vector of all the static tracepoints set at ADDR. The
1223 caller is responsible for releasing the vector. */
1226 static_tracepoints_here (CORE_ADDR addr)
1228 struct breakpoint *b;
1229 VEC(breakpoint_p) *found = 0;
1230 struct bp_location *loc;
1233 if (b->type == bp_static_tracepoint)
1235 for (loc = b->loc; loc; loc = loc->next)
1236 if (loc->address == addr)
1237 VEC_safe_push(breakpoint_p, found, b);
1243 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1244 validate that only allowed commands are included. */
1247 breakpoint_set_commands (struct breakpoint *b,
1248 struct command_line *commands)
1250 validate_commands_for_breakpoint (b, commands);
1252 decref_counted_command_line (&b->commands);
1253 b->commands = alloc_counted_command_line (commands);
1254 observer_notify_breakpoint_modified (b);
1257 /* Set the internal `silent' flag on the breakpoint. Note that this
1258 is not the same as the "silent" that may appear in the breakpoint's
1262 breakpoint_set_silent (struct breakpoint *b, int silent)
1264 int old_silent = b->silent;
1267 if (old_silent != silent)
1268 observer_notify_breakpoint_modified (b);
1271 /* Set the thread for this breakpoint. If THREAD is -1, make the
1272 breakpoint work for any thread. */
1275 breakpoint_set_thread (struct breakpoint *b, int thread)
1277 int old_thread = b->thread;
1280 if (old_thread != thread)
1281 observer_notify_breakpoint_modified (b);
1284 /* Set the task for this breakpoint. If TASK is 0, make the
1285 breakpoint work for any task. */
1288 breakpoint_set_task (struct breakpoint *b, int task)
1290 int old_task = b->task;
1293 if (old_task != task)
1294 observer_notify_breakpoint_modified (b);
1298 check_tracepoint_command (char *line, void *closure)
1300 struct breakpoint *b = closure;
1302 validate_actionline (line, b);
1305 /* A structure used to pass information through
1306 map_breakpoint_numbers. */
1308 struct commands_info
1310 /* True if the command was typed at a tty. */
1313 /* The breakpoint range spec. */
1316 /* Non-NULL if the body of the commands are being read from this
1317 already-parsed command. */
1318 struct command_line *control;
1320 /* The command lines read from the user, or NULL if they have not
1322 struct counted_command_line *cmd;
1325 /* A callback for map_breakpoint_numbers that sets the commands for
1326 commands_command. */
1329 do_map_commands_command (struct breakpoint *b, void *data)
1331 struct commands_info *info = data;
1333 if (info->cmd == NULL)
1335 struct command_line *l;
1337 if (info->control != NULL)
1338 l = copy_command_lines (info->control->body_list[0]);
1341 struct cleanup *old_chain;
1344 str = xstrprintf (_("Type commands for breakpoint(s) "
1345 "%s, one per line."),
1348 old_chain = make_cleanup (xfree, str);
1350 l = read_command_lines (str,
1353 ? check_tracepoint_command : 0),
1356 do_cleanups (old_chain);
1359 info->cmd = alloc_counted_command_line (l);
1362 /* If a breakpoint was on the list more than once, we don't need to
1364 if (b->commands != info->cmd)
1366 validate_commands_for_breakpoint (b, info->cmd->commands);
1367 incref_counted_command_line (info->cmd);
1368 decref_counted_command_line (&b->commands);
1369 b->commands = info->cmd;
1370 observer_notify_breakpoint_modified (b);
1375 commands_command_1 (char *arg, int from_tty,
1376 struct command_line *control)
1378 struct cleanup *cleanups;
1379 struct commands_info info;
1381 info.from_tty = from_tty;
1382 info.control = control;
1384 /* If we read command lines from the user, then `info' will hold an
1385 extra reference to the commands that we must clean up. */
1386 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1388 if (arg == NULL || !*arg)
1390 if (breakpoint_count - prev_breakpoint_count > 1)
1391 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1393 else if (breakpoint_count > 0)
1394 arg = xstrprintf ("%d", breakpoint_count);
1397 /* So that we don't try to free the incoming non-NULL
1398 argument in the cleanup below. Mapping breakpoint
1399 numbers will fail in this case. */
1404 /* The command loop has some static state, so we need to preserve
1406 arg = xstrdup (arg);
1409 make_cleanup (xfree, arg);
1413 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1415 if (info.cmd == NULL)
1416 error (_("No breakpoints specified."));
1418 do_cleanups (cleanups);
1422 commands_command (char *arg, int from_tty)
1424 commands_command_1 (arg, from_tty, NULL);
1427 /* Like commands_command, but instead of reading the commands from
1428 input stream, takes them from an already parsed command structure.
1430 This is used by cli-script.c to DTRT with breakpoint commands
1431 that are part of if and while bodies. */
1432 enum command_control_type
1433 commands_from_control_command (char *arg, struct command_line *cmd)
1435 commands_command_1 (arg, 0, cmd);
1436 return simple_control;
1439 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1442 bp_location_has_shadow (struct bp_location *bl)
1444 if (bl->loc_type != bp_loc_software_breakpoint)
1448 if (bl->target_info.shadow_len == 0)
1449 /* BL isn't valid, or doesn't shadow memory. */
1454 /* Update BUF, which is LEN bytes read from the target address
1455 MEMADDR, by replacing a memory breakpoint with its shadowed
1458 If READBUF is not NULL, this buffer must not overlap with the of
1459 the breakpoint location's shadow_contents buffer. Otherwise, a
1460 failed assertion internal error will be raised. */
1463 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1464 const gdb_byte *writebuf_org,
1465 ULONGEST memaddr, LONGEST len,
1466 struct bp_target_info *target_info,
1467 struct gdbarch *gdbarch)
1469 /* Now do full processing of the found relevant range of elements. */
1470 CORE_ADDR bp_addr = 0;
1474 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1475 current_program_space->aspace, 0))
1477 /* The breakpoint is inserted in a different address space. */
1481 /* Addresses and length of the part of the breakpoint that
1483 bp_addr = target_info->placed_address;
1484 bp_size = target_info->shadow_len;
1486 if (bp_addr + bp_size <= memaddr)
1488 /* The breakpoint is entirely before the chunk of memory we are
1493 if (bp_addr >= memaddr + len)
1495 /* The breakpoint is entirely after the chunk of memory we are
1500 /* Offset within shadow_contents. */
1501 if (bp_addr < memaddr)
1503 /* Only copy the second part of the breakpoint. */
1504 bp_size -= memaddr - bp_addr;
1505 bptoffset = memaddr - bp_addr;
1509 if (bp_addr + bp_size > memaddr + len)
1511 /* Only copy the first part of the breakpoint. */
1512 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1515 if (readbuf != NULL)
1517 /* Verify that the readbuf buffer does not overlap with the
1518 shadow_contents buffer. */
1519 gdb_assert (target_info->shadow_contents >= readbuf + len
1520 || readbuf >= (target_info->shadow_contents
1521 + target_info->shadow_len));
1523 /* Update the read buffer with this inserted breakpoint's
1525 memcpy (readbuf + bp_addr - memaddr,
1526 target_info->shadow_contents + bptoffset, bp_size);
1530 const unsigned char *bp;
1531 CORE_ADDR addr = target_info->reqstd_address;
1534 /* Update the shadow with what we want to write to memory. */
1535 memcpy (target_info->shadow_contents + bptoffset,
1536 writebuf_org + bp_addr - memaddr, bp_size);
1538 /* Determine appropriate breakpoint contents and size for this
1540 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1542 /* Update the final write buffer with this inserted
1543 breakpoint's INSN. */
1544 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1548 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1549 by replacing any memory breakpoints with their shadowed contents.
1551 If READBUF is not NULL, this buffer must not overlap with any of
1552 the breakpoint location's shadow_contents buffers. Otherwise,
1553 a failed assertion internal error will be raised.
1555 The range of shadowed area by each bp_location is:
1556 bl->address - bp_location_placed_address_before_address_max
1557 up to bl->address + bp_location_shadow_len_after_address_max
1558 The range we were requested to resolve shadows for is:
1559 memaddr ... memaddr + len
1560 Thus the safe cutoff boundaries for performance optimization are
1561 memaddr + len <= (bl->address
1562 - bp_location_placed_address_before_address_max)
1564 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1567 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1568 const gdb_byte *writebuf_org,
1569 ULONGEST memaddr, LONGEST len)
1571 /* Left boundary, right boundary and median element of our binary
1573 unsigned bc_l, bc_r, bc;
1576 /* Find BC_L which is a leftmost element which may affect BUF
1577 content. It is safe to report lower value but a failure to
1578 report higher one. */
1581 bc_r = bp_location_count;
1582 while (bc_l + 1 < bc_r)
1584 struct bp_location *bl;
1586 bc = (bc_l + bc_r) / 2;
1587 bl = bp_location[bc];
1589 /* Check first BL->ADDRESS will not overflow due to the added
1590 constant. Then advance the left boundary only if we are sure
1591 the BC element can in no way affect the BUF content (MEMADDR
1592 to MEMADDR + LEN range).
1594 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1595 offset so that we cannot miss a breakpoint with its shadow
1596 range tail still reaching MEMADDR. */
1598 if ((bl->address + bp_location_shadow_len_after_address_max
1600 && (bl->address + bp_location_shadow_len_after_address_max
1607 /* Due to the binary search above, we need to make sure we pick the
1608 first location that's at BC_L's address. E.g., if there are
1609 multiple locations at the same address, BC_L may end up pointing
1610 at a duplicate location, and miss the "master"/"inserted"
1611 location. Say, given locations L1, L2 and L3 at addresses A and
1614 L1@A, L2@A, L3@B, ...
1616 BC_L could end up pointing at location L2, while the "master"
1617 location could be L1. Since the `loc->inserted' flag is only set
1618 on "master" locations, we'd forget to restore the shadow of L1
1621 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1624 /* Now do full processing of the found relevant range of elements. */
1626 for (bc = bc_l; bc < bp_location_count; bc++)
1628 struct bp_location *bl = bp_location[bc];
1629 CORE_ADDR bp_addr = 0;
1633 /* bp_location array has BL->OWNER always non-NULL. */
1634 if (bl->owner->type == bp_none)
1635 warning (_("reading through apparently deleted breakpoint #%d?"),
1638 /* Performance optimization: any further element can no longer affect BUF
1641 if (bl->address >= bp_location_placed_address_before_address_max
1642 && memaddr + len <= (bl->address
1643 - bp_location_placed_address_before_address_max))
1646 if (!bp_location_has_shadow (bl))
1649 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1650 memaddr, len, &bl->target_info, bl->gdbarch);
1656 /* Return true if BPT is either a software breakpoint or a hardware
1660 is_breakpoint (const struct breakpoint *bpt)
1662 return (bpt->type == bp_breakpoint
1663 || bpt->type == bp_hardware_breakpoint
1664 || bpt->type == bp_dprintf);
1667 /* Return true if BPT is of any hardware watchpoint kind. */
1670 is_hardware_watchpoint (const struct breakpoint *bpt)
1672 return (bpt->type == bp_hardware_watchpoint
1673 || bpt->type == bp_read_watchpoint
1674 || bpt->type == bp_access_watchpoint);
1677 /* Return true if BPT is of any watchpoint kind, hardware or
1681 is_watchpoint (const struct breakpoint *bpt)
1683 return (is_hardware_watchpoint (bpt)
1684 || bpt->type == bp_watchpoint);
1687 /* Returns true if the current thread and its running state are safe
1688 to evaluate or update watchpoint B. Watchpoints on local
1689 expressions need to be evaluated in the context of the thread that
1690 was current when the watchpoint was created, and, that thread needs
1691 to be stopped to be able to select the correct frame context.
1692 Watchpoints on global expressions can be evaluated on any thread,
1693 and in any state. It is presently left to the target allowing
1694 memory accesses when threads are running. */
1697 watchpoint_in_thread_scope (struct watchpoint *b)
1699 return (b->base.pspace == current_program_space
1700 && (ptid_equal (b->watchpoint_thread, null_ptid)
1701 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1702 && !is_executing (inferior_ptid))));
1705 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1706 associated bp_watchpoint_scope breakpoint. */
1709 watchpoint_del_at_next_stop (struct watchpoint *w)
1711 struct breakpoint *b = &w->base;
1713 if (b->related_breakpoint != b)
1715 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1716 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1717 b->related_breakpoint->disposition = disp_del_at_next_stop;
1718 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1719 b->related_breakpoint = b;
1721 b->disposition = disp_del_at_next_stop;
1724 /* Extract a bitfield value from value VAL using the bit parameters contained in
1727 static struct value *
1728 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1730 struct value *bit_val;
1735 bit_val = allocate_value (value_type (val));
1737 unpack_value_bitfield (bit_val,
1740 value_contents_for_printing (val),
1747 /* Assuming that B is a watchpoint:
1748 - Reparse watchpoint expression, if REPARSE is non-zero
1749 - Evaluate expression and store the result in B->val
1750 - Evaluate the condition if there is one, and store the result
1752 - Update the list of values that must be watched in B->loc.
1754 If the watchpoint disposition is disp_del_at_next_stop, then do
1755 nothing. If this is local watchpoint that is out of scope, delete
1758 Even with `set breakpoint always-inserted on' the watchpoints are
1759 removed + inserted on each stop here. Normal breakpoints must
1760 never be removed because they might be missed by a running thread
1761 when debugging in non-stop mode. On the other hand, hardware
1762 watchpoints (is_hardware_watchpoint; processed here) are specific
1763 to each LWP since they are stored in each LWP's hardware debug
1764 registers. Therefore, such LWP must be stopped first in order to
1765 be able to modify its hardware watchpoints.
1767 Hardware watchpoints must be reset exactly once after being
1768 presented to the user. It cannot be done sooner, because it would
1769 reset the data used to present the watchpoint hit to the user. And
1770 it must not be done later because it could display the same single
1771 watchpoint hit during multiple GDB stops. Note that the latter is
1772 relevant only to the hardware watchpoint types bp_read_watchpoint
1773 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1774 not user-visible - its hit is suppressed if the memory content has
1777 The following constraints influence the location where we can reset
1778 hardware watchpoints:
1780 * target_stopped_by_watchpoint and target_stopped_data_address are
1781 called several times when GDB stops.
1784 * Multiple hardware watchpoints can be hit at the same time,
1785 causing GDB to stop. GDB only presents one hardware watchpoint
1786 hit at a time as the reason for stopping, and all the other hits
1787 are presented later, one after the other, each time the user
1788 requests the execution to be resumed. Execution is not resumed
1789 for the threads still having pending hit event stored in
1790 LWP_INFO->STATUS. While the watchpoint is already removed from
1791 the inferior on the first stop the thread hit event is kept being
1792 reported from its cached value by linux_nat_stopped_data_address
1793 until the real thread resume happens after the watchpoint gets
1794 presented and thus its LWP_INFO->STATUS gets reset.
1796 Therefore the hardware watchpoint hit can get safely reset on the
1797 watchpoint removal from inferior. */
1800 update_watchpoint (struct watchpoint *b, int reparse)
1802 int within_current_scope;
1803 struct frame_id saved_frame_id;
1806 /* If this is a local watchpoint, we only want to check if the
1807 watchpoint frame is in scope if the current thread is the thread
1808 that was used to create the watchpoint. */
1809 if (!watchpoint_in_thread_scope (b))
1812 if (b->base.disposition == disp_del_at_next_stop)
1817 /* Determine if the watchpoint is within scope. */
1818 if (b->exp_valid_block == NULL)
1819 within_current_scope = 1;
1822 struct frame_info *fi = get_current_frame ();
1823 struct gdbarch *frame_arch = get_frame_arch (fi);
1824 CORE_ADDR frame_pc = get_frame_pc (fi);
1826 /* If we're in a function epilogue, unwinding may not work
1827 properly, so do not attempt to recreate locations at this
1828 point. See similar comments in watchpoint_check. */
1829 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1832 /* Save the current frame's ID so we can restore it after
1833 evaluating the watchpoint expression on its own frame. */
1834 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1835 took a frame parameter, so that we didn't have to change the
1838 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1840 fi = frame_find_by_id (b->watchpoint_frame);
1841 within_current_scope = (fi != NULL);
1842 if (within_current_scope)
1846 /* We don't free locations. They are stored in the bp_location array
1847 and update_global_location_list will eventually delete them and
1848 remove breakpoints if needed. */
1851 if (within_current_scope && reparse)
1860 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1861 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1862 /* If the meaning of expression itself changed, the old value is
1863 no longer relevant. We don't want to report a watchpoint hit
1864 to the user when the old value and the new value may actually
1865 be completely different objects. */
1866 value_free (b->val);
1870 /* Note that unlike with breakpoints, the watchpoint's condition
1871 expression is stored in the breakpoint object, not in the
1872 locations (re)created below. */
1873 if (b->base.cond_string != NULL)
1875 if (b->cond_exp != NULL)
1877 xfree (b->cond_exp);
1881 s = b->base.cond_string;
1882 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1886 /* If we failed to parse the expression, for example because
1887 it refers to a global variable in a not-yet-loaded shared library,
1888 don't try to insert watchpoint. We don't automatically delete
1889 such watchpoint, though, since failure to parse expression
1890 is different from out-of-scope watchpoint. */
1891 if (!target_has_execution)
1893 /* Without execution, memory can't change. No use to try and
1894 set watchpoint locations. The watchpoint will be reset when
1895 the target gains execution, through breakpoint_re_set. */
1896 if (!can_use_hw_watchpoints)
1898 if (b->base.ops->works_in_software_mode (&b->base))
1899 b->base.type = bp_watchpoint;
1901 error (_("Can't set read/access watchpoint when "
1902 "hardware watchpoints are disabled."));
1905 else if (within_current_scope && b->exp)
1908 struct value *val_chain, *v, *result, *next;
1909 struct program_space *frame_pspace;
1911 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1913 /* Avoid setting b->val if it's already set. The meaning of
1914 b->val is 'the last value' user saw, and we should update
1915 it only if we reported that last value to user. As it
1916 happens, the code that reports it updates b->val directly.
1917 We don't keep track of the memory value for masked
1919 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1921 if (b->val_bitsize != 0)
1923 v = extract_bitfield_from_watchpoint_value (b, v);
1931 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1933 /* Look at each value on the value chain. */
1934 for (v = val_chain; v; v = value_next (v))
1936 /* If it's a memory location, and GDB actually needed
1937 its contents to evaluate the expression, then we
1938 must watch it. If the first value returned is
1939 still lazy, that means an error occurred reading it;
1940 watch it anyway in case it becomes readable. */
1941 if (VALUE_LVAL (v) == lval_memory
1942 && (v == val_chain || ! value_lazy (v)))
1944 struct type *vtype = check_typedef (value_type (v));
1946 /* We only watch structs and arrays if user asked
1947 for it explicitly, never if they just happen to
1948 appear in the middle of some value chain. */
1950 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1951 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1955 struct bp_location *loc, **tmp;
1956 int bitpos = 0, bitsize = 0;
1958 if (value_bitsize (v) != 0)
1960 /* Extract the bit parameters out from the bitfield
1962 bitpos = value_bitpos (v);
1963 bitsize = value_bitsize (v);
1965 else if (v == result && b->val_bitsize != 0)
1967 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1968 lvalue whose bit parameters are saved in the fields
1969 VAL_BITPOS and VAL_BITSIZE. */
1970 bitpos = b->val_bitpos;
1971 bitsize = b->val_bitsize;
1974 addr = value_address (v);
1977 /* Skip the bytes that don't contain the bitfield. */
1982 if (b->base.type == bp_read_watchpoint)
1984 else if (b->base.type == bp_access_watchpoint)
1987 loc = allocate_bp_location (&b->base);
1988 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1991 loc->gdbarch = get_type_arch (value_type (v));
1993 loc->pspace = frame_pspace;
1994 loc->address = addr;
1998 /* Just cover the bytes that make up the bitfield. */
1999 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2002 loc->length = TYPE_LENGTH (value_type (v));
2004 loc->watchpoint_type = type;
2009 /* Change the type of breakpoint between hardware assisted or
2010 an ordinary watchpoint depending on the hardware support
2011 and free hardware slots. REPARSE is set when the inferior
2016 enum bp_loc_type loc_type;
2017 struct bp_location *bl;
2019 reg_cnt = can_use_hardware_watchpoint (val_chain);
2023 int i, target_resources_ok, other_type_used;
2026 /* Use an exact watchpoint when there's only one memory region to be
2027 watched, and only one debug register is needed to watch it. */
2028 b->exact = target_exact_watchpoints && reg_cnt == 1;
2030 /* We need to determine how many resources are already
2031 used for all other hardware watchpoints plus this one
2032 to see if we still have enough resources to also fit
2033 this watchpoint in as well. */
2035 /* If this is a software watchpoint, we try to turn it
2036 to a hardware one -- count resources as if B was of
2037 hardware watchpoint type. */
2038 type = b->base.type;
2039 if (type == bp_watchpoint)
2040 type = bp_hardware_watchpoint;
2042 /* This watchpoint may or may not have been placed on
2043 the list yet at this point (it won't be in the list
2044 if we're trying to create it for the first time,
2045 through watch_command), so always account for it
2048 /* Count resources used by all watchpoints except B. */
2049 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2051 /* Add in the resources needed for B. */
2052 i += hw_watchpoint_use_count (&b->base);
2055 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2056 if (target_resources_ok <= 0)
2058 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2060 if (target_resources_ok == 0 && !sw_mode)
2061 error (_("Target does not support this type of "
2062 "hardware watchpoint."));
2063 else if (target_resources_ok < 0 && !sw_mode)
2064 error (_("There are not enough available hardware "
2065 "resources for this watchpoint."));
2067 /* Downgrade to software watchpoint. */
2068 b->base.type = bp_watchpoint;
2072 /* If this was a software watchpoint, we've just
2073 found we have enough resources to turn it to a
2074 hardware watchpoint. Otherwise, this is a
2076 b->base.type = type;
2079 else if (!b->base.ops->works_in_software_mode (&b->base))
2081 if (!can_use_hw_watchpoints)
2082 error (_("Can't set read/access watchpoint when "
2083 "hardware watchpoints are disabled."));
2085 error (_("Expression cannot be implemented with "
2086 "read/access watchpoint."));
2089 b->base.type = bp_watchpoint;
2091 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2092 : bp_loc_hardware_watchpoint);
2093 for (bl = b->base.loc; bl; bl = bl->next)
2094 bl->loc_type = loc_type;
2097 for (v = val_chain; v; v = next)
2099 next = value_next (v);
2104 /* If a software watchpoint is not watching any memory, then the
2105 above left it without any location set up. But,
2106 bpstat_stop_status requires a location to be able to report
2107 stops, so make sure there's at least a dummy one. */
2108 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2110 struct breakpoint *base = &b->base;
2111 base->loc = allocate_bp_location (base);
2112 base->loc->pspace = frame_pspace;
2113 base->loc->address = -1;
2114 base->loc->length = -1;
2115 base->loc->watchpoint_type = -1;
2118 else if (!within_current_scope)
2120 printf_filtered (_("\
2121 Watchpoint %d deleted because the program has left the block\n\
2122 in which its expression is valid.\n"),
2124 watchpoint_del_at_next_stop (b);
2127 /* Restore the selected frame. */
2129 select_frame (frame_find_by_id (saved_frame_id));
2133 /* Returns 1 iff breakpoint location should be
2134 inserted in the inferior. We don't differentiate the type of BL's owner
2135 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2136 breakpoint_ops is not defined, because in insert_bp_location,
2137 tracepoint's insert_location will not be called. */
2139 should_be_inserted (struct bp_location *bl)
2141 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2144 if (bl->owner->disposition == disp_del_at_next_stop)
2147 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2150 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2153 /* This is set for example, when we're attached to the parent of a
2154 vfork, and have detached from the child. The child is running
2155 free, and we expect it to do an exec or exit, at which point the
2156 OS makes the parent schedulable again (and the target reports
2157 that the vfork is done). Until the child is done with the shared
2158 memory region, do not insert breakpoints in the parent, otherwise
2159 the child could still trip on the parent's breakpoints. Since
2160 the parent is blocked anyway, it won't miss any breakpoint. */
2161 if (bl->pspace->breakpoints_not_allowed)
2164 /* Don't insert a breakpoint if we're trying to step past its
2166 if ((bl->loc_type == bp_loc_software_breakpoint
2167 || bl->loc_type == bp_loc_hardware_breakpoint)
2168 && stepping_past_instruction_at (bl->pspace->aspace,
2173 fprintf_unfiltered (gdb_stdlog,
2174 "infrun: skipping breakpoint: "
2175 "stepping past insn at: %s\n",
2176 paddress (bl->gdbarch, bl->address));
2181 /* Don't insert watchpoints if we're trying to step past the
2182 instruction that triggered one. */
2183 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2184 && stepping_past_nonsteppable_watchpoint ())
2188 fprintf_unfiltered (gdb_stdlog,
2189 "infrun: stepping past non-steppable watchpoint. "
2190 "skipping watchpoint at %s:%d\n",
2191 paddress (bl->gdbarch, bl->address),
2200 /* Same as should_be_inserted but does the check assuming
2201 that the location is not duplicated. */
2204 unduplicated_should_be_inserted (struct bp_location *bl)
2207 const int save_duplicate = bl->duplicate;
2210 result = should_be_inserted (bl);
2211 bl->duplicate = save_duplicate;
2215 /* Parses a conditional described by an expression COND into an
2216 agent expression bytecode suitable for evaluation
2217 by the bytecode interpreter. Return NULL if there was
2218 any error during parsing. */
2220 static struct agent_expr *
2221 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2223 struct agent_expr *aexpr = NULL;
2224 volatile struct gdb_exception ex;
2229 /* We don't want to stop processing, so catch any errors
2230 that may show up. */
2231 TRY_CATCH (ex, RETURN_MASK_ERROR)
2233 aexpr = gen_eval_for_expr (scope, cond);
2238 /* If we got here, it means the condition could not be parsed to a valid
2239 bytecode expression and thus can't be evaluated on the target's side.
2240 It's no use iterating through the conditions. */
2244 /* We have a valid agent expression. */
2248 /* Based on location BL, create a list of breakpoint conditions to be
2249 passed on to the target. If we have duplicated locations with different
2250 conditions, we will add such conditions to the list. The idea is that the
2251 target will evaluate the list of conditions and will only notify GDB when
2252 one of them is true. */
2255 build_target_condition_list (struct bp_location *bl)
2257 struct bp_location **locp = NULL, **loc2p;
2258 int null_condition_or_parse_error = 0;
2259 int modified = bl->needs_update;
2260 struct bp_location *loc;
2262 /* Release conditions left over from a previous insert. */
2263 VEC_free (agent_expr_p, bl->target_info.conditions);
2265 /* This is only meaningful if the target is
2266 evaluating conditions and if the user has
2267 opted for condition evaluation on the target's
2269 if (gdb_evaluates_breakpoint_condition_p ()
2270 || !target_supports_evaluation_of_breakpoint_conditions ())
2273 /* Do a first pass to check for locations with no assigned
2274 conditions or conditions that fail to parse to a valid agent expression
2275 bytecode. If any of these happen, then it's no use to send conditions
2276 to the target since this location will always trigger and generate a
2277 response back to GDB. */
2278 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2281 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2285 struct agent_expr *aexpr;
2287 /* Re-parse the conditions since something changed. In that
2288 case we already freed the condition bytecodes (see
2289 force_breakpoint_reinsertion). We just
2290 need to parse the condition to bytecodes again. */
2291 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2292 loc->cond_bytecode = aexpr;
2294 /* Check if we managed to parse the conditional expression
2295 correctly. If not, we will not send this condition
2301 /* If we have a NULL bytecode expression, it means something
2302 went wrong or we have a null condition expression. */
2303 if (!loc->cond_bytecode)
2305 null_condition_or_parse_error = 1;
2311 /* If any of these happened, it means we will have to evaluate the conditions
2312 for the location's address on gdb's side. It is no use keeping bytecodes
2313 for all the other duplicate locations, thus we free all of them here.
2315 This is so we have a finer control over which locations' conditions are
2316 being evaluated by GDB or the remote stub. */
2317 if (null_condition_or_parse_error)
2319 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2322 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2324 /* Only go as far as the first NULL bytecode is
2326 if (!loc->cond_bytecode)
2329 free_agent_expr (loc->cond_bytecode);
2330 loc->cond_bytecode = NULL;
2335 /* No NULL conditions or failed bytecode generation. Build a condition list
2336 for this location's address. */
2337 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2341 && is_breakpoint (loc->owner)
2342 && loc->pspace->num == bl->pspace->num
2343 && loc->owner->enable_state == bp_enabled
2345 /* Add the condition to the vector. This will be used later to send the
2346 conditions to the target. */
2347 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2348 loc->cond_bytecode);
2354 /* Parses a command described by string CMD into an agent expression
2355 bytecode suitable for evaluation by the bytecode interpreter.
2356 Return NULL if there was any error during parsing. */
2358 static struct agent_expr *
2359 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2361 struct cleanup *old_cleanups = 0;
2362 struct expression *expr, **argvec;
2363 struct agent_expr *aexpr = NULL;
2364 volatile struct gdb_exception ex;
2365 const char *cmdrest;
2366 const char *format_start, *format_end;
2367 struct format_piece *fpieces;
2369 struct gdbarch *gdbarch = get_current_arch ();
2376 if (*cmdrest == ',')
2378 cmdrest = skip_spaces_const (cmdrest);
2380 if (*cmdrest++ != '"')
2381 error (_("No format string following the location"));
2383 format_start = cmdrest;
2385 fpieces = parse_format_string (&cmdrest);
2387 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2389 format_end = cmdrest;
2391 if (*cmdrest++ != '"')
2392 error (_("Bad format string, non-terminated '\"'."));
2394 cmdrest = skip_spaces_const (cmdrest);
2396 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2397 error (_("Invalid argument syntax"));
2399 if (*cmdrest == ',')
2401 cmdrest = skip_spaces_const (cmdrest);
2403 /* For each argument, make an expression. */
2405 argvec = (struct expression **) alloca (strlen (cmd)
2406 * sizeof (struct expression *));
2409 while (*cmdrest != '\0')
2414 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2415 argvec[nargs++] = expr;
2417 if (*cmdrest == ',')
2421 /* We don't want to stop processing, so catch any errors
2422 that may show up. */
2423 TRY_CATCH (ex, RETURN_MASK_ERROR)
2425 aexpr = gen_printf (scope, gdbarch, 0, 0,
2426 format_start, format_end - format_start,
2427 fpieces, nargs, argvec);
2430 do_cleanups (old_cleanups);
2434 /* If we got here, it means the command could not be parsed to a valid
2435 bytecode expression and thus can't be evaluated on the target's side.
2436 It's no use iterating through the other commands. */
2440 /* We have a valid agent expression, return it. */
2444 /* Based on location BL, create a list of breakpoint commands to be
2445 passed on to the target. If we have duplicated locations with
2446 different commands, we will add any such to the list. */
2449 build_target_command_list (struct bp_location *bl)
2451 struct bp_location **locp = NULL, **loc2p;
2452 int null_command_or_parse_error = 0;
2453 int modified = bl->needs_update;
2454 struct bp_location *loc;
2456 /* Release commands left over from a previous insert. */
2457 VEC_free (agent_expr_p, bl->target_info.tcommands);
2459 if (!target_can_run_breakpoint_commands ())
2462 /* For now, limit to agent-style dprintf breakpoints. */
2463 if (dprintf_style != dprintf_style_agent)
2466 /* For now, if we have any duplicate location that isn't a dprintf,
2467 don't install the target-side commands, as that would make the
2468 breakpoint not be reported to the core, and we'd lose
2470 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2473 if (is_breakpoint (loc->owner)
2474 && loc->pspace->num == bl->pspace->num
2475 && loc->owner->type != bp_dprintf)
2479 /* Do a first pass to check for locations with no assigned
2480 conditions or conditions that fail to parse to a valid agent expression
2481 bytecode. If any of these happen, then it's no use to send conditions
2482 to the target since this location will always trigger and generate a
2483 response back to GDB. */
2484 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2487 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2491 struct agent_expr *aexpr;
2493 /* Re-parse the commands since something changed. In that
2494 case we already freed the command bytecodes (see
2495 force_breakpoint_reinsertion). We just
2496 need to parse the command to bytecodes again. */
2497 aexpr = parse_cmd_to_aexpr (bl->address,
2498 loc->owner->extra_string);
2499 loc->cmd_bytecode = aexpr;
2505 /* If we have a NULL bytecode expression, it means something
2506 went wrong or we have a null command expression. */
2507 if (!loc->cmd_bytecode)
2509 null_command_or_parse_error = 1;
2515 /* If anything failed, then we're not doing target-side commands,
2517 if (null_command_or_parse_error)
2519 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2522 if (is_breakpoint (loc->owner)
2523 && loc->pspace->num == bl->pspace->num)
2525 /* Only go as far as the first NULL bytecode is
2527 if (loc->cmd_bytecode == NULL)
2530 free_agent_expr (loc->cmd_bytecode);
2531 loc->cmd_bytecode = NULL;
2536 /* No NULL commands or failed bytecode generation. Build a command list
2537 for this location's address. */
2538 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2541 if (loc->owner->extra_string
2542 && is_breakpoint (loc->owner)
2543 && loc->pspace->num == bl->pspace->num
2544 && loc->owner->enable_state == bp_enabled
2546 /* Add the command to the vector. This will be used later
2547 to send the commands to the target. */
2548 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2552 bl->target_info.persist = 0;
2553 /* Maybe flag this location as persistent. */
2554 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2555 bl->target_info.persist = 1;
2558 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2559 location. Any error messages are printed to TMP_ERROR_STREAM; and
2560 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2561 Returns 0 for success, 1 if the bp_location type is not supported or
2564 NOTE drow/2003-09-09: This routine could be broken down to an
2565 object-style method for each breakpoint or catchpoint type. */
2567 insert_bp_location (struct bp_location *bl,
2568 struct ui_file *tmp_error_stream,
2569 int *disabled_breaks,
2570 int *hw_breakpoint_error,
2571 int *hw_bp_error_explained_already)
2573 enum errors bp_err = GDB_NO_ERROR;
2574 const char *bp_err_message = NULL;
2575 volatile struct gdb_exception e;
2577 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2580 /* Note we don't initialize bl->target_info, as that wipes out
2581 the breakpoint location's shadow_contents if the breakpoint
2582 is still inserted at that location. This in turn breaks
2583 target_read_memory which depends on these buffers when
2584 a memory read is requested at the breakpoint location:
2585 Once the target_info has been wiped, we fail to see that
2586 we have a breakpoint inserted at that address and thus
2587 read the breakpoint instead of returning the data saved in
2588 the breakpoint location's shadow contents. */
2589 bl->target_info.reqstd_address = bl->address;
2590 bl->target_info.placed_address_space = bl->pspace->aspace;
2591 bl->target_info.length = bl->length;
2593 /* When working with target-side conditions, we must pass all the conditions
2594 for the same breakpoint address down to the target since GDB will not
2595 insert those locations. With a list of breakpoint conditions, the target
2596 can decide when to stop and notify GDB. */
2598 if (is_breakpoint (bl->owner))
2600 build_target_condition_list (bl);
2601 build_target_command_list (bl);
2602 /* Reset the modification marker. */
2603 bl->needs_update = 0;
2606 if (bl->loc_type == bp_loc_software_breakpoint
2607 || bl->loc_type == bp_loc_hardware_breakpoint)
2609 if (bl->owner->type != bp_hardware_breakpoint)
2611 /* If the explicitly specified breakpoint type
2612 is not hardware breakpoint, check the memory map to see
2613 if the breakpoint address is in read only memory or not.
2615 Two important cases are:
2616 - location type is not hardware breakpoint, memory
2617 is readonly. We change the type of the location to
2618 hardware breakpoint.
2619 - location type is hardware breakpoint, memory is
2620 read-write. This means we've previously made the
2621 location hardware one, but then the memory map changed,
2624 When breakpoints are removed, remove_breakpoints will use
2625 location types we've just set here, the only possible
2626 problem is that memory map has changed during running
2627 program, but it's not going to work anyway with current
2629 struct mem_region *mr
2630 = lookup_mem_region (bl->target_info.reqstd_address);
2634 if (automatic_hardware_breakpoints)
2636 enum bp_loc_type new_type;
2638 if (mr->attrib.mode != MEM_RW)
2639 new_type = bp_loc_hardware_breakpoint;
2641 new_type = bp_loc_software_breakpoint;
2643 if (new_type != bl->loc_type)
2645 static int said = 0;
2647 bl->loc_type = new_type;
2650 fprintf_filtered (gdb_stdout,
2651 _("Note: automatically using "
2652 "hardware breakpoints for "
2653 "read-only addresses.\n"));
2658 else if (bl->loc_type == bp_loc_software_breakpoint
2659 && mr->attrib.mode != MEM_RW)
2661 fprintf_unfiltered (tmp_error_stream,
2662 _("Cannot insert breakpoint %d.\n"
2663 "Cannot set software breakpoint "
2664 "at read-only address %s\n"),
2666 paddress (bl->gdbarch, bl->address));
2672 /* First check to see if we have to handle an overlay. */
2673 if (overlay_debugging == ovly_off
2674 || bl->section == NULL
2675 || !(section_is_overlay (bl->section)))
2677 /* No overlay handling: just set the breakpoint. */
2678 TRY_CATCH (e, RETURN_MASK_ALL)
2682 val = bl->owner->ops->insert_location (bl);
2684 bp_err = GENERIC_ERROR;
2689 bp_err_message = e.message;
2694 /* This breakpoint is in an overlay section.
2695 Shall we set a breakpoint at the LMA? */
2696 if (!overlay_events_enabled)
2698 /* Yes -- overlay event support is not active,
2699 so we must try to set a breakpoint at the LMA.
2700 This will not work for a hardware breakpoint. */
2701 if (bl->loc_type == bp_loc_hardware_breakpoint)
2702 warning (_("hardware breakpoint %d not supported in overlay!"),
2706 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2708 /* Set a software (trap) breakpoint at the LMA. */
2709 bl->overlay_target_info = bl->target_info;
2710 bl->overlay_target_info.reqstd_address = addr;
2712 /* No overlay handling: just set the breakpoint. */
2713 TRY_CATCH (e, RETURN_MASK_ALL)
2717 val = target_insert_breakpoint (bl->gdbarch,
2718 &bl->overlay_target_info);
2720 bp_err = GENERIC_ERROR;
2725 bp_err_message = e.message;
2728 if (bp_err != GDB_NO_ERROR)
2729 fprintf_unfiltered (tmp_error_stream,
2730 "Overlay breakpoint %d "
2731 "failed: in ROM?\n",
2735 /* Shall we set a breakpoint at the VMA? */
2736 if (section_is_mapped (bl->section))
2738 /* Yes. This overlay section is mapped into memory. */
2739 TRY_CATCH (e, RETURN_MASK_ALL)
2743 val = bl->owner->ops->insert_location (bl);
2745 bp_err = GENERIC_ERROR;
2750 bp_err_message = e.message;
2755 /* No. This breakpoint will not be inserted.
2756 No error, but do not mark the bp as 'inserted'. */
2761 if (bp_err != GDB_NO_ERROR)
2763 /* Can't set the breakpoint. */
2765 /* In some cases, we might not be able to insert a
2766 breakpoint in a shared library that has already been
2767 removed, but we have not yet processed the shlib unload
2768 event. Unfortunately, some targets that implement
2769 breakpoint insertion themselves can't tell why the
2770 breakpoint insertion failed (e.g., the remote target
2771 doesn't define error codes), so we must treat generic
2772 errors as memory errors. */
2773 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2774 && bl->loc_type == bp_loc_software_breakpoint
2775 && (solib_name_from_address (bl->pspace, bl->address)
2776 || shared_objfile_contains_address_p (bl->pspace,
2779 /* See also: disable_breakpoints_in_shlibs. */
2780 bl->shlib_disabled = 1;
2781 observer_notify_breakpoint_modified (bl->owner);
2782 if (!*disabled_breaks)
2784 fprintf_unfiltered (tmp_error_stream,
2785 "Cannot insert breakpoint %d.\n",
2787 fprintf_unfiltered (tmp_error_stream,
2788 "Temporarily disabling shared "
2789 "library breakpoints:\n");
2791 *disabled_breaks = 1;
2792 fprintf_unfiltered (tmp_error_stream,
2793 "breakpoint #%d\n", bl->owner->number);
2798 if (bl->loc_type == bp_loc_hardware_breakpoint)
2800 *hw_breakpoint_error = 1;
2801 *hw_bp_error_explained_already = bp_err_message != NULL;
2802 fprintf_unfiltered (tmp_error_stream,
2803 "Cannot insert hardware breakpoint %d%s",
2804 bl->owner->number, bp_err_message ? ":" : ".\n");
2805 if (bp_err_message != NULL)
2806 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2810 if (bp_err_message == NULL)
2813 = memory_error_message (TARGET_XFER_E_IO,
2814 bl->gdbarch, bl->address);
2815 struct cleanup *old_chain = make_cleanup (xfree, message);
2817 fprintf_unfiltered (tmp_error_stream,
2818 "Cannot insert breakpoint %d.\n"
2820 bl->owner->number, message);
2821 do_cleanups (old_chain);
2825 fprintf_unfiltered (tmp_error_stream,
2826 "Cannot insert breakpoint %d: %s\n",
2841 else if (bl->loc_type == bp_loc_hardware_watchpoint
2842 /* NOTE drow/2003-09-08: This state only exists for removing
2843 watchpoints. It's not clear that it's necessary... */
2844 && bl->owner->disposition != disp_del_at_next_stop)
2848 gdb_assert (bl->owner->ops != NULL
2849 && bl->owner->ops->insert_location != NULL);
2851 val = bl->owner->ops->insert_location (bl);
2853 /* If trying to set a read-watchpoint, and it turns out it's not
2854 supported, try emulating one with an access watchpoint. */
2855 if (val == 1 && bl->watchpoint_type == hw_read)
2857 struct bp_location *loc, **loc_temp;
2859 /* But don't try to insert it, if there's already another
2860 hw_access location that would be considered a duplicate
2862 ALL_BP_LOCATIONS (loc, loc_temp)
2864 && loc->watchpoint_type == hw_access
2865 && watchpoint_locations_match (bl, loc))
2869 bl->target_info = loc->target_info;
2870 bl->watchpoint_type = hw_access;
2877 bl->watchpoint_type = hw_access;
2878 val = bl->owner->ops->insert_location (bl);
2881 /* Back to the original value. */
2882 bl->watchpoint_type = hw_read;
2886 bl->inserted = (val == 0);
2889 else if (bl->owner->type == bp_catchpoint)
2893 gdb_assert (bl->owner->ops != NULL
2894 && bl->owner->ops->insert_location != NULL);
2896 val = bl->owner->ops->insert_location (bl);
2899 bl->owner->enable_state = bp_disabled;
2903 Error inserting catchpoint %d: Your system does not support this type\n\
2904 of catchpoint."), bl->owner->number);
2906 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2909 bl->inserted = (val == 0);
2911 /* We've already printed an error message if there was a problem
2912 inserting this catchpoint, and we've disabled the catchpoint,
2913 so just return success. */
2920 /* This function is called when program space PSPACE is about to be
2921 deleted. It takes care of updating breakpoints to not reference
2925 breakpoint_program_space_exit (struct program_space *pspace)
2927 struct breakpoint *b, *b_temp;
2928 struct bp_location *loc, **loc_temp;
2930 /* Remove any breakpoint that was set through this program space. */
2931 ALL_BREAKPOINTS_SAFE (b, b_temp)
2933 if (b->pspace == pspace)
2934 delete_breakpoint (b);
2937 /* Breakpoints set through other program spaces could have locations
2938 bound to PSPACE as well. Remove those. */
2939 ALL_BP_LOCATIONS (loc, loc_temp)
2941 struct bp_location *tmp;
2943 if (loc->pspace == pspace)
2945 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2946 if (loc->owner->loc == loc)
2947 loc->owner->loc = loc->next;
2949 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2950 if (tmp->next == loc)
2952 tmp->next = loc->next;
2958 /* Now update the global location list to permanently delete the
2959 removed locations above. */
2960 update_global_location_list (UGLL_DONT_INSERT);
2963 /* Make sure all breakpoints are inserted in inferior.
2964 Throws exception on any error.
2965 A breakpoint that is already inserted won't be inserted
2966 again, so calling this function twice is safe. */
2968 insert_breakpoints (void)
2970 struct breakpoint *bpt;
2972 ALL_BREAKPOINTS (bpt)
2973 if (is_hardware_watchpoint (bpt))
2975 struct watchpoint *w = (struct watchpoint *) bpt;
2977 update_watchpoint (w, 0 /* don't reparse. */);
2980 /* Updating watchpoints creates new locations, so update the global
2981 location list. Explicitly tell ugll to insert locations and
2982 ignore breakpoints_always_inserted_mode. */
2983 update_global_location_list (UGLL_INSERT);
2986 /* Invoke CALLBACK for each of bp_location. */
2989 iterate_over_bp_locations (walk_bp_location_callback callback)
2991 struct bp_location *loc, **loc_tmp;
2993 ALL_BP_LOCATIONS (loc, loc_tmp)
2995 callback (loc, NULL);
2999 /* This is used when we need to synch breakpoint conditions between GDB and the
3000 target. It is the case with deleting and disabling of breakpoints when using
3001 always-inserted mode. */
3004 update_inserted_breakpoint_locations (void)
3006 struct bp_location *bl, **blp_tmp;
3009 int disabled_breaks = 0;
3010 int hw_breakpoint_error = 0;
3011 int hw_bp_details_reported = 0;
3013 struct ui_file *tmp_error_stream = mem_fileopen ();
3014 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3016 /* Explicitly mark the warning -- this will only be printed if
3017 there was an error. */
3018 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3020 save_current_space_and_thread ();
3022 ALL_BP_LOCATIONS (bl, blp_tmp)
3024 /* We only want to update software breakpoints and hardware
3026 if (!is_breakpoint (bl->owner))
3029 /* We only want to update locations that are already inserted
3030 and need updating. This is to avoid unwanted insertion during
3031 deletion of breakpoints. */
3032 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3035 switch_to_program_space_and_thread (bl->pspace);
3037 /* For targets that support global breakpoints, there's no need
3038 to select an inferior to insert breakpoint to. In fact, even
3039 if we aren't attached to any process yet, we should still
3040 insert breakpoints. */
3041 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3042 && ptid_equal (inferior_ptid, null_ptid))
3045 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3046 &hw_breakpoint_error, &hw_bp_details_reported);
3053 target_terminal_ours_for_output ();
3054 error_stream (tmp_error_stream);
3057 do_cleanups (cleanups);
3060 /* Used when starting or continuing the program. */
3063 insert_breakpoint_locations (void)
3065 struct breakpoint *bpt;
3066 struct bp_location *bl, **blp_tmp;
3069 int disabled_breaks = 0;
3070 int hw_breakpoint_error = 0;
3071 int hw_bp_error_explained_already = 0;
3073 struct ui_file *tmp_error_stream = mem_fileopen ();
3074 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3076 /* Explicitly mark the warning -- this will only be printed if
3077 there was an error. */
3078 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3080 save_current_space_and_thread ();
3082 ALL_BP_LOCATIONS (bl, blp_tmp)
3084 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3087 /* There is no point inserting thread-specific breakpoints if
3088 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3089 has BL->OWNER always non-NULL. */
3090 if (bl->owner->thread != -1
3091 && !valid_thread_id (bl->owner->thread))
3094 switch_to_program_space_and_thread (bl->pspace);
3096 /* For targets that support global breakpoints, there's no need
3097 to select an inferior to insert breakpoint to. In fact, even
3098 if we aren't attached to any process yet, we should still
3099 insert breakpoints. */
3100 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3101 && ptid_equal (inferior_ptid, null_ptid))
3104 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3105 &hw_breakpoint_error, &hw_bp_error_explained_already);
3110 /* If we failed to insert all locations of a watchpoint, remove
3111 them, as half-inserted watchpoint is of limited use. */
3112 ALL_BREAKPOINTS (bpt)
3114 int some_failed = 0;
3115 struct bp_location *loc;
3117 if (!is_hardware_watchpoint (bpt))
3120 if (!breakpoint_enabled (bpt))
3123 if (bpt->disposition == disp_del_at_next_stop)
3126 for (loc = bpt->loc; loc; loc = loc->next)
3127 if (!loc->inserted && should_be_inserted (loc))
3134 for (loc = bpt->loc; loc; loc = loc->next)
3136 remove_breakpoint (loc, mark_uninserted);
3138 hw_breakpoint_error = 1;
3139 fprintf_unfiltered (tmp_error_stream,
3140 "Could not insert hardware watchpoint %d.\n",
3148 /* If a hardware breakpoint or watchpoint was inserted, add a
3149 message about possibly exhausted resources. */
3150 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3152 fprintf_unfiltered (tmp_error_stream,
3153 "Could not insert hardware breakpoints:\n\
3154 You may have requested too many hardware breakpoints/watchpoints.\n");
3156 target_terminal_ours_for_output ();
3157 error_stream (tmp_error_stream);
3160 do_cleanups (cleanups);
3163 /* Used when the program stops.
3164 Returns zero if successful, or non-zero if there was a problem
3165 removing a breakpoint location. */
3168 remove_breakpoints (void)
3170 struct bp_location *bl, **blp_tmp;
3173 ALL_BP_LOCATIONS (bl, blp_tmp)
3175 if (bl->inserted && !is_tracepoint (bl->owner))
3176 val |= remove_breakpoint (bl, mark_uninserted);
3181 /* When a thread exits, remove breakpoints that are related to
3185 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3187 struct breakpoint *b, *b_tmp;
3189 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3191 if (b->thread == tp->num && user_breakpoint_p (b))
3193 b->disposition = disp_del_at_next_stop;
3195 printf_filtered (_("\
3196 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3197 b->number, tp->num);
3199 /* Hide it from the user. */
3205 /* Remove breakpoints of process PID. */
3208 remove_breakpoints_pid (int pid)
3210 struct bp_location *bl, **blp_tmp;
3212 struct inferior *inf = find_inferior_pid (pid);
3214 ALL_BP_LOCATIONS (bl, blp_tmp)
3216 if (bl->pspace != inf->pspace)
3219 if (bl->inserted && !bl->target_info.persist)
3221 val = remove_breakpoint (bl, mark_uninserted);
3230 reattach_breakpoints (int pid)
3232 struct cleanup *old_chain;
3233 struct bp_location *bl, **blp_tmp;
3235 struct ui_file *tmp_error_stream;
3236 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3237 struct inferior *inf;
3238 struct thread_info *tp;
3240 tp = any_live_thread_of_process (pid);
3244 inf = find_inferior_pid (pid);
3245 old_chain = save_inferior_ptid ();
3247 inferior_ptid = tp->ptid;
3249 tmp_error_stream = mem_fileopen ();
3250 make_cleanup_ui_file_delete (tmp_error_stream);
3252 ALL_BP_LOCATIONS (bl, blp_tmp)
3254 if (bl->pspace != inf->pspace)
3260 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3263 do_cleanups (old_chain);
3268 do_cleanups (old_chain);
3272 static int internal_breakpoint_number = -1;
3274 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3275 If INTERNAL is non-zero, the breakpoint number will be populated
3276 from internal_breakpoint_number and that variable decremented.
3277 Otherwise the breakpoint number will be populated from
3278 breakpoint_count and that value incremented. Internal breakpoints
3279 do not set the internal var bpnum. */
3281 set_breakpoint_number (int internal, struct breakpoint *b)
3284 b->number = internal_breakpoint_number--;
3287 set_breakpoint_count (breakpoint_count + 1);
3288 b->number = breakpoint_count;
3292 static struct breakpoint *
3293 create_internal_breakpoint (struct gdbarch *gdbarch,
3294 CORE_ADDR address, enum bptype type,
3295 const struct breakpoint_ops *ops)
3297 struct symtab_and_line sal;
3298 struct breakpoint *b;
3300 init_sal (&sal); /* Initialize to zeroes. */
3303 sal.section = find_pc_overlay (sal.pc);
3304 sal.pspace = current_program_space;
3306 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3307 b->number = internal_breakpoint_number--;
3308 b->disposition = disp_donttouch;
3313 static const char *const longjmp_names[] =
3315 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3317 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3319 /* Per-objfile data private to breakpoint.c. */
3320 struct breakpoint_objfile_data
3322 /* Minimal symbol for "_ovly_debug_event" (if any). */
3323 struct bound_minimal_symbol overlay_msym;
3325 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3326 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3328 /* True if we have looked for longjmp probes. */
3329 int longjmp_searched;
3331 /* SystemTap probe points for longjmp (if any). */
3332 VEC (probe_p) *longjmp_probes;
3334 /* Minimal symbol for "std::terminate()" (if any). */
3335 struct bound_minimal_symbol terminate_msym;
3337 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3338 struct bound_minimal_symbol exception_msym;
3340 /* True if we have looked for exception probes. */
3341 int exception_searched;
3343 /* SystemTap probe points for unwinding (if any). */
3344 VEC (probe_p) *exception_probes;
3347 static const struct objfile_data *breakpoint_objfile_key;
3349 /* Minimal symbol not found sentinel. */
3350 static struct minimal_symbol msym_not_found;
3352 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3355 msym_not_found_p (const struct minimal_symbol *msym)
3357 return msym == &msym_not_found;
3360 /* Return per-objfile data needed by breakpoint.c.
3361 Allocate the data if necessary. */
3363 static struct breakpoint_objfile_data *
3364 get_breakpoint_objfile_data (struct objfile *objfile)
3366 struct breakpoint_objfile_data *bp_objfile_data;
3368 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3369 if (bp_objfile_data == NULL)
3371 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3372 sizeof (*bp_objfile_data));
3374 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3375 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3377 return bp_objfile_data;
3381 free_breakpoint_probes (struct objfile *obj, void *data)
3383 struct breakpoint_objfile_data *bp_objfile_data = data;
3385 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3386 VEC_free (probe_p, bp_objfile_data->exception_probes);
3390 create_overlay_event_breakpoint (void)
3392 struct objfile *objfile;
3393 const char *const func_name = "_ovly_debug_event";
3395 ALL_OBJFILES (objfile)
3397 struct breakpoint *b;
3398 struct breakpoint_objfile_data *bp_objfile_data;
3401 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3403 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3406 if (bp_objfile_data->overlay_msym.minsym == NULL)
3408 struct bound_minimal_symbol m;
3410 m = lookup_minimal_symbol_text (func_name, objfile);
3411 if (m.minsym == NULL)
3413 /* Avoid future lookups in this objfile. */
3414 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3417 bp_objfile_data->overlay_msym = m;
3420 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3421 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3423 &internal_breakpoint_ops);
3424 b->addr_string = xstrdup (func_name);
3426 if (overlay_debugging == ovly_auto)
3428 b->enable_state = bp_enabled;
3429 overlay_events_enabled = 1;
3433 b->enable_state = bp_disabled;
3434 overlay_events_enabled = 0;
3437 update_global_location_list (UGLL_MAY_INSERT);
3441 create_longjmp_master_breakpoint (void)
3443 struct program_space *pspace;
3444 struct cleanup *old_chain;
3446 old_chain = save_current_program_space ();
3448 ALL_PSPACES (pspace)
3450 struct objfile *objfile;
3452 set_current_program_space (pspace);
3454 ALL_OBJFILES (objfile)
3457 struct gdbarch *gdbarch;
3458 struct breakpoint_objfile_data *bp_objfile_data;
3460 gdbarch = get_objfile_arch (objfile);
3462 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3464 if (!bp_objfile_data->longjmp_searched)
3468 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3471 /* We are only interested in checking one element. */
3472 struct probe *p = VEC_index (probe_p, ret, 0);
3474 if (!can_evaluate_probe_arguments (p))
3476 /* We cannot use the probe interface here, because it does
3477 not know how to evaluate arguments. */
3478 VEC_free (probe_p, ret);
3482 bp_objfile_data->longjmp_probes = ret;
3483 bp_objfile_data->longjmp_searched = 1;
3486 if (bp_objfile_data->longjmp_probes != NULL)
3489 struct probe *probe;
3490 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3493 VEC_iterate (probe_p,
3494 bp_objfile_data->longjmp_probes,
3498 struct breakpoint *b;
3500 b = create_internal_breakpoint (gdbarch,
3501 get_probe_address (probe,
3504 &internal_breakpoint_ops);
3505 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3506 b->enable_state = bp_disabled;
3512 if (!gdbarch_get_longjmp_target_p (gdbarch))
3515 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3517 struct breakpoint *b;
3518 const char *func_name;
3521 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3524 func_name = longjmp_names[i];
3525 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3527 struct bound_minimal_symbol m;
3529 m = lookup_minimal_symbol_text (func_name, objfile);
3530 if (m.minsym == NULL)
3532 /* Prevent future lookups in this objfile. */
3533 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3536 bp_objfile_data->longjmp_msym[i] = m;
3539 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3540 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3541 &internal_breakpoint_ops);
3542 b->addr_string = xstrdup (func_name);
3543 b->enable_state = bp_disabled;
3547 update_global_location_list (UGLL_MAY_INSERT);
3549 do_cleanups (old_chain);
3552 /* Create a master std::terminate breakpoint. */
3554 create_std_terminate_master_breakpoint (void)
3556 struct program_space *pspace;
3557 struct cleanup *old_chain;
3558 const char *const func_name = "std::terminate()";
3560 old_chain = save_current_program_space ();
3562 ALL_PSPACES (pspace)
3564 struct objfile *objfile;
3567 set_current_program_space (pspace);
3569 ALL_OBJFILES (objfile)
3571 struct breakpoint *b;
3572 struct breakpoint_objfile_data *bp_objfile_data;
3574 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3576 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3579 if (bp_objfile_data->terminate_msym.minsym == NULL)
3581 struct bound_minimal_symbol m;
3583 m = lookup_minimal_symbol (func_name, NULL, objfile);
3584 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3585 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3587 /* Prevent future lookups in this objfile. */
3588 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3591 bp_objfile_data->terminate_msym = m;
3594 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3595 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3596 bp_std_terminate_master,
3597 &internal_breakpoint_ops);
3598 b->addr_string = xstrdup (func_name);
3599 b->enable_state = bp_disabled;
3603 update_global_location_list (UGLL_MAY_INSERT);
3605 do_cleanups (old_chain);
3608 /* Install a master breakpoint on the unwinder's debug hook. */
3611 create_exception_master_breakpoint (void)
3613 struct objfile *objfile;
3614 const char *const func_name = "_Unwind_DebugHook";
3616 ALL_OBJFILES (objfile)
3618 struct breakpoint *b;
3619 struct gdbarch *gdbarch;
3620 struct breakpoint_objfile_data *bp_objfile_data;
3623 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3625 /* We prefer the SystemTap probe point if it exists. */
3626 if (!bp_objfile_data->exception_searched)
3630 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3634 /* We are only interested in checking one element. */
3635 struct probe *p = VEC_index (probe_p, ret, 0);
3637 if (!can_evaluate_probe_arguments (p))
3639 /* We cannot use the probe interface here, because it does
3640 not know how to evaluate arguments. */
3641 VEC_free (probe_p, ret);
3645 bp_objfile_data->exception_probes = ret;
3646 bp_objfile_data->exception_searched = 1;
3649 if (bp_objfile_data->exception_probes != NULL)
3651 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3653 struct probe *probe;
3656 VEC_iterate (probe_p,
3657 bp_objfile_data->exception_probes,
3661 struct breakpoint *b;
3663 b = create_internal_breakpoint (gdbarch,
3664 get_probe_address (probe,
3666 bp_exception_master,
3667 &internal_breakpoint_ops);
3668 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3669 b->enable_state = bp_disabled;
3675 /* Otherwise, try the hook function. */
3677 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3680 gdbarch = get_objfile_arch (objfile);
3682 if (bp_objfile_data->exception_msym.minsym == NULL)
3684 struct bound_minimal_symbol debug_hook;
3686 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3687 if (debug_hook.minsym == NULL)
3689 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3693 bp_objfile_data->exception_msym = debug_hook;
3696 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3697 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3699 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3700 &internal_breakpoint_ops);
3701 b->addr_string = xstrdup (func_name);
3702 b->enable_state = bp_disabled;
3705 update_global_location_list (UGLL_MAY_INSERT);
3709 update_breakpoints_after_exec (void)
3711 struct breakpoint *b, *b_tmp;
3712 struct bp_location *bploc, **bplocp_tmp;
3714 /* We're about to delete breakpoints from GDB's lists. If the
3715 INSERTED flag is true, GDB will try to lift the breakpoints by
3716 writing the breakpoints' "shadow contents" back into memory. The
3717 "shadow contents" are NOT valid after an exec, so GDB should not
3718 do that. Instead, the target is responsible from marking
3719 breakpoints out as soon as it detects an exec. We don't do that
3720 here instead, because there may be other attempts to delete
3721 breakpoints after detecting an exec and before reaching here. */
3722 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3723 if (bploc->pspace == current_program_space)
3724 gdb_assert (!bploc->inserted);
3726 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3728 if (b->pspace != current_program_space)
3731 /* Solib breakpoints must be explicitly reset after an exec(). */
3732 if (b->type == bp_shlib_event)
3734 delete_breakpoint (b);
3738 /* JIT breakpoints must be explicitly reset after an exec(). */
3739 if (b->type == bp_jit_event)
3741 delete_breakpoint (b);
3745 /* Thread event breakpoints must be set anew after an exec(),
3746 as must overlay event and longjmp master breakpoints. */
3747 if (b->type == bp_thread_event || b->type == bp_overlay_event
3748 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3749 || b->type == bp_exception_master)
3751 delete_breakpoint (b);
3755 /* Step-resume breakpoints are meaningless after an exec(). */
3756 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3758 delete_breakpoint (b);
3762 /* Just like single-step breakpoints. */
3763 if (b->type == bp_single_step)
3765 delete_breakpoint (b);
3769 /* Longjmp and longjmp-resume breakpoints are also meaningless
3771 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3772 || b->type == bp_longjmp_call_dummy
3773 || b->type == bp_exception || b->type == bp_exception_resume)
3775 delete_breakpoint (b);
3779 if (b->type == bp_catchpoint)
3781 /* For now, none of the bp_catchpoint breakpoints need to
3782 do anything at this point. In the future, if some of
3783 the catchpoints need to something, we will need to add
3784 a new method, and call this method from here. */
3788 /* bp_finish is a special case. The only way we ought to be able
3789 to see one of these when an exec() has happened, is if the user
3790 caught a vfork, and then said "finish". Ordinarily a finish just
3791 carries them to the call-site of the current callee, by setting
3792 a temporary bp there and resuming. But in this case, the finish
3793 will carry them entirely through the vfork & exec.
3795 We don't want to allow a bp_finish to remain inserted now. But
3796 we can't safely delete it, 'cause finish_command has a handle to
3797 the bp on a bpstat, and will later want to delete it. There's a
3798 chance (and I've seen it happen) that if we delete the bp_finish
3799 here, that its storage will get reused by the time finish_command
3800 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3801 We really must allow finish_command to delete a bp_finish.
3803 In the absence of a general solution for the "how do we know
3804 it's safe to delete something others may have handles to?"
3805 problem, what we'll do here is just uninsert the bp_finish, and
3806 let finish_command delete it.
3808 (We know the bp_finish is "doomed" in the sense that it's
3809 momentary, and will be deleted as soon as finish_command sees
3810 the inferior stopped. So it doesn't matter that the bp's
3811 address is probably bogus in the new a.out, unlike e.g., the
3812 solib breakpoints.) */
3814 if (b->type == bp_finish)
3819 /* Without a symbolic address, we have little hope of the
3820 pre-exec() address meaning the same thing in the post-exec()
3822 if (b->addr_string == NULL)
3824 delete_breakpoint (b);
3831 detach_breakpoints (ptid_t ptid)
3833 struct bp_location *bl, **blp_tmp;
3835 struct cleanup *old_chain = save_inferior_ptid ();
3836 struct inferior *inf = current_inferior ();
3838 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3839 error (_("Cannot detach breakpoints of inferior_ptid"));
3841 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3842 inferior_ptid = ptid;
3843 ALL_BP_LOCATIONS (bl, blp_tmp)
3845 if (bl->pspace != inf->pspace)
3848 /* This function must physically remove breakpoints locations
3849 from the specified ptid, without modifying the breakpoint
3850 package's state. Locations of type bp_loc_other are only
3851 maintained at GDB side. So, there is no need to remove
3852 these bp_loc_other locations. Moreover, removing these
3853 would modify the breakpoint package's state. */
3854 if (bl->loc_type == bp_loc_other)
3858 val |= remove_breakpoint_1 (bl, mark_inserted);
3861 do_cleanups (old_chain);
3865 /* Remove the breakpoint location BL from the current address space.
3866 Note that this is used to detach breakpoints from a child fork.
3867 When we get here, the child isn't in the inferior list, and neither
3868 do we have objects to represent its address space --- we should
3869 *not* look at bl->pspace->aspace here. */
3872 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3876 /* BL is never in moribund_locations by our callers. */
3877 gdb_assert (bl->owner != NULL);
3880 /* Permanent breakpoints cannot be inserted or removed. */
3883 /* The type of none suggests that owner is actually deleted.
3884 This should not ever happen. */
3885 gdb_assert (bl->owner->type != bp_none);
3887 if (bl->loc_type == bp_loc_software_breakpoint
3888 || bl->loc_type == bp_loc_hardware_breakpoint)
3890 /* "Normal" instruction breakpoint: either the standard
3891 trap-instruction bp (bp_breakpoint), or a
3892 bp_hardware_breakpoint. */
3894 /* First check to see if we have to handle an overlay. */
3895 if (overlay_debugging == ovly_off
3896 || bl->section == NULL
3897 || !(section_is_overlay (bl->section)))
3899 /* No overlay handling: just remove the breakpoint. */
3901 /* If we're trying to uninsert a memory breakpoint that we
3902 know is set in a dynamic object that is marked
3903 shlib_disabled, then either the dynamic object was
3904 removed with "remove-symbol-file" or with
3905 "nosharedlibrary". In the former case, we don't know
3906 whether another dynamic object might have loaded over the
3907 breakpoint's address -- the user might well let us know
3908 about it next with add-symbol-file (the whole point of
3909 add-symbol-file is letting the user manually maintain a
3910 list of dynamically loaded objects). If we have the
3911 breakpoint's shadow memory, that is, this is a software
3912 breakpoint managed by GDB, check whether the breakpoint
3913 is still inserted in memory, to avoid overwriting wrong
3914 code with stale saved shadow contents. Note that HW
3915 breakpoints don't have shadow memory, as they're
3916 implemented using a mechanism that is not dependent on
3917 being able to modify the target's memory, and as such
3918 they should always be removed. */
3919 if (bl->shlib_disabled
3920 && bl->target_info.shadow_len != 0
3921 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3924 val = bl->owner->ops->remove_location (bl);
3928 /* This breakpoint is in an overlay section.
3929 Did we set a breakpoint at the LMA? */
3930 if (!overlay_events_enabled)
3932 /* Yes -- overlay event support is not active, so we
3933 should have set a breakpoint at the LMA. Remove it.
3935 /* Ignore any failures: if the LMA is in ROM, we will
3936 have already warned when we failed to insert it. */
3937 if (bl->loc_type == bp_loc_hardware_breakpoint)
3938 target_remove_hw_breakpoint (bl->gdbarch,
3939 &bl->overlay_target_info);
3941 target_remove_breakpoint (bl->gdbarch,
3942 &bl->overlay_target_info);
3944 /* Did we set a breakpoint at the VMA?
3945 If so, we will have marked the breakpoint 'inserted'. */
3948 /* Yes -- remove it. Previously we did not bother to
3949 remove the breakpoint if the section had been
3950 unmapped, but let's not rely on that being safe. We
3951 don't know what the overlay manager might do. */
3953 /* However, we should remove *software* breakpoints only
3954 if the section is still mapped, or else we overwrite
3955 wrong code with the saved shadow contents. */
3956 if (bl->loc_type == bp_loc_hardware_breakpoint
3957 || section_is_mapped (bl->section))
3958 val = bl->owner->ops->remove_location (bl);
3964 /* No -- not inserted, so no need to remove. No error. */
3969 /* In some cases, we might not be able to remove a breakpoint in
3970 a shared library that has already been removed, but we have
3971 not yet processed the shlib unload event. Similarly for an
3972 unloaded add-symbol-file object - the user might not yet have
3973 had the chance to remove-symbol-file it. shlib_disabled will
3974 be set if the library/object has already been removed, but
3975 the breakpoint hasn't been uninserted yet, e.g., after
3976 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3977 always-inserted mode. */
3979 && (bl->loc_type == bp_loc_software_breakpoint
3980 && (bl->shlib_disabled
3981 || solib_name_from_address (bl->pspace, bl->address)
3982 || shared_objfile_contains_address_p (bl->pspace,
3988 bl->inserted = (is == mark_inserted);
3990 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3992 gdb_assert (bl->owner->ops != NULL
3993 && bl->owner->ops->remove_location != NULL);
3995 bl->inserted = (is == mark_inserted);
3996 bl->owner->ops->remove_location (bl);
3998 /* Failure to remove any of the hardware watchpoints comes here. */
3999 if ((is == mark_uninserted) && (bl->inserted))
4000 warning (_("Could not remove hardware watchpoint %d."),
4003 else if (bl->owner->type == bp_catchpoint
4004 && breakpoint_enabled (bl->owner)
4007 gdb_assert (bl->owner->ops != NULL
4008 && bl->owner->ops->remove_location != NULL);
4010 val = bl->owner->ops->remove_location (bl);
4014 bl->inserted = (is == mark_inserted);
4021 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
4024 struct cleanup *old_chain;
4026 /* BL is never in moribund_locations by our callers. */
4027 gdb_assert (bl->owner != NULL);
4030 /* Permanent breakpoints cannot be inserted or removed. */
4033 /* The type of none suggests that owner is actually deleted.
4034 This should not ever happen. */
4035 gdb_assert (bl->owner->type != bp_none);
4037 old_chain = save_current_space_and_thread ();
4039 switch_to_program_space_and_thread (bl->pspace);
4041 ret = remove_breakpoint_1 (bl, is);
4043 do_cleanups (old_chain);
4047 /* Clear the "inserted" flag in all breakpoints. */
4050 mark_breakpoints_out (void)
4052 struct bp_location *bl, **blp_tmp;
4054 ALL_BP_LOCATIONS (bl, blp_tmp)
4055 if (bl->pspace == current_program_space
4060 /* Clear the "inserted" flag in all breakpoints and delete any
4061 breakpoints which should go away between runs of the program.
4063 Plus other such housekeeping that has to be done for breakpoints
4066 Note: this function gets called at the end of a run (by
4067 generic_mourn_inferior) and when a run begins (by
4068 init_wait_for_inferior). */
4073 breakpoint_init_inferior (enum inf_context context)
4075 struct breakpoint *b, *b_tmp;
4076 struct bp_location *bl, **blp_tmp;
4078 struct program_space *pspace = current_program_space;
4080 /* If breakpoint locations are shared across processes, then there's
4082 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4085 mark_breakpoints_out ();
4087 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4089 if (b->loc && b->loc->pspace != pspace)
4095 case bp_longjmp_call_dummy:
4097 /* If the call dummy breakpoint is at the entry point it will
4098 cause problems when the inferior is rerun, so we better get
4101 case bp_watchpoint_scope:
4103 /* Also get rid of scope breakpoints. */
4105 case bp_shlib_event:
4107 /* Also remove solib event breakpoints. Their addresses may
4108 have changed since the last time we ran the program.
4109 Actually we may now be debugging against different target;
4110 and so the solib backend that installed this breakpoint may
4111 not be used in by the target. E.g.,
4113 (gdb) file prog-linux
4114 (gdb) run # native linux target
4117 (gdb) file prog-win.exe
4118 (gdb) tar rem :9999 # remote Windows gdbserver.
4121 case bp_step_resume:
4123 /* Also remove step-resume breakpoints. */
4125 case bp_single_step:
4127 /* Also remove single-step breakpoints. */
4129 delete_breakpoint (b);
4133 case bp_hardware_watchpoint:
4134 case bp_read_watchpoint:
4135 case bp_access_watchpoint:
4137 struct watchpoint *w = (struct watchpoint *) b;
4139 /* Likewise for watchpoints on local expressions. */
4140 if (w->exp_valid_block != NULL)
4141 delete_breakpoint (b);
4142 else if (context == inf_starting)
4144 /* Reset val field to force reread of starting value in
4145 insert_breakpoints. */
4147 value_free (w->val);
4158 /* Get rid of the moribund locations. */
4159 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4160 decref_bp_location (&bl);
4161 VEC_free (bp_location_p, moribund_locations);
4164 /* These functions concern about actual breakpoints inserted in the
4165 target --- to e.g. check if we need to do decr_pc adjustment or if
4166 we need to hop over the bkpt --- so we check for address space
4167 match, not program space. */
4169 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4170 exists at PC. It returns ordinary_breakpoint_here if it's an
4171 ordinary breakpoint, or permanent_breakpoint_here if it's a
4172 permanent breakpoint.
4173 - When continuing from a location with an ordinary breakpoint, we
4174 actually single step once before calling insert_breakpoints.
4175 - When continuing from a location with a permanent breakpoint, we
4176 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4177 the target, to advance the PC past the breakpoint. */
4179 enum breakpoint_here
4180 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4182 struct bp_location *bl, **blp_tmp;
4183 int any_breakpoint_here = 0;
4185 ALL_BP_LOCATIONS (bl, blp_tmp)
4187 if (bl->loc_type != bp_loc_software_breakpoint
4188 && bl->loc_type != bp_loc_hardware_breakpoint)
4191 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4192 if ((breakpoint_enabled (bl->owner)
4194 && breakpoint_location_address_match (bl, aspace, pc))
4196 if (overlay_debugging
4197 && section_is_overlay (bl->section)
4198 && !section_is_mapped (bl->section))
4199 continue; /* unmapped overlay -- can't be a match */
4200 else if (bl->permanent)
4201 return permanent_breakpoint_here;
4203 any_breakpoint_here = 1;
4207 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
4210 /* Return true if there's a moribund breakpoint at PC. */
4213 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4215 struct bp_location *loc;
4218 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4219 if (breakpoint_location_address_match (loc, aspace, pc))
4225 /* Returns non-zero iff BL is inserted at PC, in address space
4229 bp_location_inserted_here_p (struct bp_location *bl,
4230 struct address_space *aspace, CORE_ADDR pc)
4233 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4236 if (overlay_debugging
4237 && section_is_overlay (bl->section)
4238 && !section_is_mapped (bl->section))
4239 return 0; /* unmapped overlay -- can't be a match */
4246 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4249 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4251 struct bp_location **blp, **blp_tmp = NULL;
4252 struct bp_location *bl;
4254 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4256 struct bp_location *bl = *blp;
4258 if (bl->loc_type != bp_loc_software_breakpoint
4259 && bl->loc_type != bp_loc_hardware_breakpoint)
4262 if (bp_location_inserted_here_p (bl, aspace, pc))
4268 /* This function returns non-zero iff there is a software breakpoint
4272 software_breakpoint_inserted_here_p (struct address_space *aspace,
4275 struct bp_location **blp, **blp_tmp = NULL;
4276 struct bp_location *bl;
4278 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4280 struct bp_location *bl = *blp;
4282 if (bl->loc_type != bp_loc_software_breakpoint)
4285 if (bp_location_inserted_here_p (bl, aspace, pc))
4292 /* See breakpoint.h. */
4295 hardware_breakpoint_inserted_here_p (struct address_space *aspace,
4298 struct bp_location **blp, **blp_tmp = NULL;
4299 struct bp_location *bl;
4301 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4303 struct bp_location *bl = *blp;
4305 if (bl->loc_type != bp_loc_hardware_breakpoint)
4308 if (bp_location_inserted_here_p (bl, aspace, pc))
4316 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4317 CORE_ADDR addr, ULONGEST len)
4319 struct breakpoint *bpt;
4321 ALL_BREAKPOINTS (bpt)
4323 struct bp_location *loc;
4325 if (bpt->type != bp_hardware_watchpoint
4326 && bpt->type != bp_access_watchpoint)
4329 if (!breakpoint_enabled (bpt))
4332 for (loc = bpt->loc; loc; loc = loc->next)
4333 if (loc->pspace->aspace == aspace && loc->inserted)
4337 /* Check for intersection. */
4338 l = max (loc->address, addr);
4339 h = min (loc->address + loc->length, addr + len);
4348 /* bpstat stuff. External routines' interfaces are documented
4352 is_catchpoint (struct breakpoint *ep)
4354 return (ep->type == bp_catchpoint);
4357 /* Frees any storage that is part of a bpstat. Does not walk the
4361 bpstat_free (bpstat bs)
4363 if (bs->old_val != NULL)
4364 value_free (bs->old_val);
4365 decref_counted_command_line (&bs->commands);
4366 decref_bp_location (&bs->bp_location_at);
4370 /* Clear a bpstat so that it says we are not at any breakpoint.
4371 Also free any storage that is part of a bpstat. */
4374 bpstat_clear (bpstat *bsp)
4391 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4392 is part of the bpstat is copied as well. */
4395 bpstat_copy (bpstat bs)
4399 bpstat retval = NULL;
4404 for (; bs != NULL; bs = bs->next)
4406 tmp = (bpstat) xmalloc (sizeof (*tmp));
4407 memcpy (tmp, bs, sizeof (*tmp));
4408 incref_counted_command_line (tmp->commands);
4409 incref_bp_location (tmp->bp_location_at);
4410 if (bs->old_val != NULL)
4412 tmp->old_val = value_copy (bs->old_val);
4413 release_value (tmp->old_val);
4417 /* This is the first thing in the chain. */
4427 /* Find the bpstat associated with this breakpoint. */
4430 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4435 for (; bsp != NULL; bsp = bsp->next)
4437 if (bsp->breakpoint_at == breakpoint)
4443 /* See breakpoint.h. */
4446 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4448 for (; bsp != NULL; bsp = bsp->next)
4450 if (bsp->breakpoint_at == NULL)
4452 /* A moribund location can never explain a signal other than
4454 if (sig == GDB_SIGNAL_TRAP)
4459 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4468 /* Put in *NUM the breakpoint number of the first breakpoint we are
4469 stopped at. *BSP upon return is a bpstat which points to the
4470 remaining breakpoints stopped at (but which is not guaranteed to be
4471 good for anything but further calls to bpstat_num).
4473 Return 0 if passed a bpstat which does not indicate any breakpoints.
4474 Return -1 if stopped at a breakpoint that has been deleted since
4476 Return 1 otherwise. */
4479 bpstat_num (bpstat *bsp, int *num)
4481 struct breakpoint *b;
4484 return 0; /* No more breakpoint values */
4486 /* We assume we'll never have several bpstats that correspond to a
4487 single breakpoint -- otherwise, this function might return the
4488 same number more than once and this will look ugly. */
4489 b = (*bsp)->breakpoint_at;
4490 *bsp = (*bsp)->next;
4492 return -1; /* breakpoint that's been deleted since */
4494 *num = b->number; /* We have its number */
4498 /* See breakpoint.h. */
4501 bpstat_clear_actions (void)
4503 struct thread_info *tp;
4506 if (ptid_equal (inferior_ptid, null_ptid))
4509 tp = find_thread_ptid (inferior_ptid);
4513 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4515 decref_counted_command_line (&bs->commands);
4517 if (bs->old_val != NULL)
4519 value_free (bs->old_val);
4525 /* Called when a command is about to proceed the inferior. */
4528 breakpoint_about_to_proceed (void)
4530 if (!ptid_equal (inferior_ptid, null_ptid))
4532 struct thread_info *tp = inferior_thread ();
4534 /* Allow inferior function calls in breakpoint commands to not
4535 interrupt the command list. When the call finishes
4536 successfully, the inferior will be standing at the same
4537 breakpoint as if nothing happened. */
4538 if (tp->control.in_infcall)
4542 breakpoint_proceeded = 1;
4545 /* Stub for cleaning up our state if we error-out of a breakpoint
4548 cleanup_executing_breakpoints (void *ignore)
4550 executing_breakpoint_commands = 0;
4553 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4554 or its equivalent. */
4557 command_line_is_silent (struct command_line *cmd)
4559 return cmd && (strcmp ("silent", cmd->line) == 0
4560 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4563 /* Execute all the commands associated with all the breakpoints at
4564 this location. Any of these commands could cause the process to
4565 proceed beyond this point, etc. We look out for such changes by
4566 checking the global "breakpoint_proceeded" after each command.
4568 Returns true if a breakpoint command resumed the inferior. In that
4569 case, it is the caller's responsibility to recall it again with the
4570 bpstat of the current thread. */
4573 bpstat_do_actions_1 (bpstat *bsp)
4576 struct cleanup *old_chain;
4579 /* Avoid endless recursion if a `source' command is contained
4581 if (executing_breakpoint_commands)
4584 executing_breakpoint_commands = 1;
4585 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4587 prevent_dont_repeat ();
4589 /* This pointer will iterate over the list of bpstat's. */
4592 breakpoint_proceeded = 0;
4593 for (; bs != NULL; bs = bs->next)
4595 struct counted_command_line *ccmd;
4596 struct command_line *cmd;
4597 struct cleanup *this_cmd_tree_chain;
4599 /* Take ownership of the BSP's command tree, if it has one.
4601 The command tree could legitimately contain commands like
4602 'step' and 'next', which call clear_proceed_status, which
4603 frees stop_bpstat's command tree. To make sure this doesn't
4604 free the tree we're executing out from under us, we need to
4605 take ownership of the tree ourselves. Since a given bpstat's
4606 commands are only executed once, we don't need to copy it; we
4607 can clear the pointer in the bpstat, and make sure we free
4608 the tree when we're done. */
4609 ccmd = bs->commands;
4610 bs->commands = NULL;
4611 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4612 cmd = ccmd ? ccmd->commands : NULL;
4613 if (command_line_is_silent (cmd))
4615 /* The action has been already done by bpstat_stop_status. */
4621 execute_control_command (cmd);
4623 if (breakpoint_proceeded)
4629 /* We can free this command tree now. */
4630 do_cleanups (this_cmd_tree_chain);
4632 if (breakpoint_proceeded)
4634 if (interpreter_async && target_can_async_p ())
4635 /* If we are in async mode, then the target might be still
4636 running, not stopped at any breakpoint, so nothing for
4637 us to do here -- just return to the event loop. */
4640 /* In sync mode, when execute_control_command returns
4641 we're already standing on the next breakpoint.
4642 Breakpoint commands for that stop were not run, since
4643 execute_command does not run breakpoint commands --
4644 only command_line_handler does, but that one is not
4645 involved in execution of breakpoint commands. So, we
4646 can now execute breakpoint commands. It should be
4647 noted that making execute_command do bpstat actions is
4648 not an option -- in this case we'll have recursive
4649 invocation of bpstat for each breakpoint with a
4650 command, and can easily blow up GDB stack. Instead, we
4651 return true, which will trigger the caller to recall us
4652 with the new stop_bpstat. */
4657 do_cleanups (old_chain);
4662 bpstat_do_actions (void)
4664 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4666 /* Do any commands attached to breakpoint we are stopped at. */
4667 while (!ptid_equal (inferior_ptid, null_ptid)
4668 && target_has_execution
4669 && !is_exited (inferior_ptid)
4670 && !is_executing (inferior_ptid))
4671 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4672 and only return when it is stopped at the next breakpoint, we
4673 keep doing breakpoint actions until it returns false to
4674 indicate the inferior was not resumed. */
4675 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4678 discard_cleanups (cleanup_if_error);
4681 /* Print out the (old or new) value associated with a watchpoint. */
4684 watchpoint_value_print (struct value *val, struct ui_file *stream)
4687 fprintf_unfiltered (stream, _("<unreadable>"));
4690 struct value_print_options opts;
4691 get_user_print_options (&opts);
4692 value_print (val, stream, &opts);
4696 /* Generic routine for printing messages indicating why we
4697 stopped. The behavior of this function depends on the value
4698 'print_it' in the bpstat structure. Under some circumstances we
4699 may decide not to print anything here and delegate the task to
4702 static enum print_stop_action
4703 print_bp_stop_message (bpstat bs)
4705 switch (bs->print_it)
4708 /* Nothing should be printed for this bpstat entry. */
4709 return PRINT_UNKNOWN;
4713 /* We still want to print the frame, but we already printed the
4714 relevant messages. */
4715 return PRINT_SRC_AND_LOC;
4718 case print_it_normal:
4720 struct breakpoint *b = bs->breakpoint_at;
4722 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4723 which has since been deleted. */
4725 return PRINT_UNKNOWN;
4727 /* Normal case. Call the breakpoint's print_it method. */
4728 return b->ops->print_it (bs);
4733 internal_error (__FILE__, __LINE__,
4734 _("print_bp_stop_message: unrecognized enum value"));
4739 /* A helper function that prints a shared library stopped event. */
4742 print_solib_event (int is_catchpoint)
4745 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4747 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4751 if (any_added || any_deleted)
4752 ui_out_text (current_uiout,
4753 _("Stopped due to shared library event:\n"));
4755 ui_out_text (current_uiout,
4756 _("Stopped due to shared library event (no "
4757 "libraries added or removed)\n"));
4760 if (ui_out_is_mi_like_p (current_uiout))
4761 ui_out_field_string (current_uiout, "reason",
4762 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4766 struct cleanup *cleanup;
4770 ui_out_text (current_uiout, _(" Inferior unloaded "));
4771 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4774 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4779 ui_out_text (current_uiout, " ");
4780 ui_out_field_string (current_uiout, "library", name);
4781 ui_out_text (current_uiout, "\n");
4784 do_cleanups (cleanup);
4789 struct so_list *iter;
4791 struct cleanup *cleanup;
4793 ui_out_text (current_uiout, _(" Inferior loaded "));
4794 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4797 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4802 ui_out_text (current_uiout, " ");
4803 ui_out_field_string (current_uiout, "library", iter->so_name);
4804 ui_out_text (current_uiout, "\n");
4807 do_cleanups (cleanup);
4811 /* Print a message indicating what happened. This is called from
4812 normal_stop(). The input to this routine is the head of the bpstat
4813 list - a list of the eventpoints that caused this stop. KIND is
4814 the target_waitkind for the stopping event. This
4815 routine calls the generic print routine for printing a message
4816 about reasons for stopping. This will print (for example) the
4817 "Breakpoint n," part of the output. The return value of this
4820 PRINT_UNKNOWN: Means we printed nothing.
4821 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4822 code to print the location. An example is
4823 "Breakpoint 1, " which should be followed by
4825 PRINT_SRC_ONLY: Means we printed something, but there is no need
4826 to also print the location part of the message.
4827 An example is the catch/throw messages, which
4828 don't require a location appended to the end.
4829 PRINT_NOTHING: We have done some printing and we don't need any
4830 further info to be printed. */
4832 enum print_stop_action
4833 bpstat_print (bpstat bs, int kind)
4837 /* Maybe another breakpoint in the chain caused us to stop.
4838 (Currently all watchpoints go on the bpstat whether hit or not.
4839 That probably could (should) be changed, provided care is taken
4840 with respect to bpstat_explains_signal). */
4841 for (; bs; bs = bs->next)
4843 val = print_bp_stop_message (bs);
4844 if (val == PRINT_SRC_ONLY
4845 || val == PRINT_SRC_AND_LOC
4846 || val == PRINT_NOTHING)
4850 /* If we had hit a shared library event breakpoint,
4851 print_bp_stop_message would print out this message. If we hit an
4852 OS-level shared library event, do the same thing. */
4853 if (kind == TARGET_WAITKIND_LOADED)
4855 print_solib_event (0);
4856 return PRINT_NOTHING;
4859 /* We reached the end of the chain, or we got a null BS to start
4860 with and nothing was printed. */
4861 return PRINT_UNKNOWN;
4864 /* Evaluate the expression EXP and return 1 if value is zero.
4865 This returns the inverse of the condition because it is called
4866 from catch_errors which returns 0 if an exception happened, and if an
4867 exception happens we want execution to stop.
4868 The argument is a "struct expression *" that has been cast to a
4869 "void *" to make it pass through catch_errors. */
4872 breakpoint_cond_eval (void *exp)
4874 struct value *mark = value_mark ();
4875 int i = !value_true (evaluate_expression ((struct expression *) exp));
4877 value_free_to_mark (mark);
4881 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4884 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4888 bs = (bpstat) xmalloc (sizeof (*bs));
4890 **bs_link_pointer = bs;
4891 *bs_link_pointer = &bs->next;
4892 bs->breakpoint_at = bl->owner;
4893 bs->bp_location_at = bl;
4894 incref_bp_location (bl);
4895 /* If the condition is false, etc., don't do the commands. */
4896 bs->commands = NULL;
4898 bs->print_it = print_it_normal;
4902 /* The target has stopped with waitstatus WS. Check if any hardware
4903 watchpoints have triggered, according to the target. */
4906 watchpoints_triggered (struct target_waitstatus *ws)
4908 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4910 struct breakpoint *b;
4912 if (!stopped_by_watchpoint)
4914 /* We were not stopped by a watchpoint. Mark all watchpoints
4915 as not triggered. */
4917 if (is_hardware_watchpoint (b))
4919 struct watchpoint *w = (struct watchpoint *) b;
4921 w->watchpoint_triggered = watch_triggered_no;
4927 if (!target_stopped_data_address (¤t_target, &addr))
4929 /* We were stopped by a watchpoint, but we don't know where.
4930 Mark all watchpoints as unknown. */
4932 if (is_hardware_watchpoint (b))
4934 struct watchpoint *w = (struct watchpoint *) b;
4936 w->watchpoint_triggered = watch_triggered_unknown;
4942 /* The target could report the data address. Mark watchpoints
4943 affected by this data address as triggered, and all others as not
4947 if (is_hardware_watchpoint (b))
4949 struct watchpoint *w = (struct watchpoint *) b;
4950 struct bp_location *loc;
4952 w->watchpoint_triggered = watch_triggered_no;
4953 for (loc = b->loc; loc; loc = loc->next)
4955 if (is_masked_watchpoint (b))
4957 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4958 CORE_ADDR start = loc->address & w->hw_wp_mask;
4960 if (newaddr == start)
4962 w->watchpoint_triggered = watch_triggered_yes;
4966 /* Exact match not required. Within range is sufficient. */
4967 else if (target_watchpoint_addr_within_range (¤t_target,
4971 w->watchpoint_triggered = watch_triggered_yes;
4980 /* Possible return values for watchpoint_check (this can't be an enum
4981 because of check_errors). */
4982 /* The watchpoint has been deleted. */
4983 #define WP_DELETED 1
4984 /* The value has changed. */
4985 #define WP_VALUE_CHANGED 2
4986 /* The value has not changed. */
4987 #define WP_VALUE_NOT_CHANGED 3
4988 /* Ignore this watchpoint, no matter if the value changed or not. */
4991 #define BP_TEMPFLAG 1
4992 #define BP_HARDWAREFLAG 2
4994 /* Evaluate watchpoint condition expression and check if its value
4997 P should be a pointer to struct bpstat, but is defined as a void *
4998 in order for this function to be usable with catch_errors. */
5001 watchpoint_check (void *p)
5003 bpstat bs = (bpstat) p;
5004 struct watchpoint *b;
5005 struct frame_info *fr;
5006 int within_current_scope;
5008 /* BS is built from an existing struct breakpoint. */
5009 gdb_assert (bs->breakpoint_at != NULL);
5010 b = (struct watchpoint *) bs->breakpoint_at;
5012 /* If this is a local watchpoint, we only want to check if the
5013 watchpoint frame is in scope if the current thread is the thread
5014 that was used to create the watchpoint. */
5015 if (!watchpoint_in_thread_scope (b))
5018 if (b->exp_valid_block == NULL)
5019 within_current_scope = 1;
5022 struct frame_info *frame = get_current_frame ();
5023 struct gdbarch *frame_arch = get_frame_arch (frame);
5024 CORE_ADDR frame_pc = get_frame_pc (frame);
5026 /* in_function_epilogue_p() returns a non-zero value if we're
5027 still in the function but the stack frame has already been
5028 invalidated. Since we can't rely on the values of local
5029 variables after the stack has been destroyed, we are treating
5030 the watchpoint in that state as `not changed' without further
5031 checking. Don't mark watchpoints as changed if the current
5032 frame is in an epilogue - even if they are in some other
5033 frame, our view of the stack is likely to be wrong and
5034 frame_find_by_id could error out. */
5035 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
5038 fr = frame_find_by_id (b->watchpoint_frame);
5039 within_current_scope = (fr != NULL);
5041 /* If we've gotten confused in the unwinder, we might have
5042 returned a frame that can't describe this variable. */
5043 if (within_current_scope)
5045 struct symbol *function;
5047 function = get_frame_function (fr);
5048 if (function == NULL
5049 || !contained_in (b->exp_valid_block,
5050 SYMBOL_BLOCK_VALUE (function)))
5051 within_current_scope = 0;
5054 if (within_current_scope)
5055 /* If we end up stopping, the current frame will get selected
5056 in normal_stop. So this call to select_frame won't affect
5061 if (within_current_scope)
5063 /* We use value_{,free_to_}mark because it could be a *long*
5064 time before we return to the command level and call
5065 free_all_values. We can't call free_all_values because we
5066 might be in the middle of evaluating a function call. */
5070 struct value *new_val;
5072 if (is_masked_watchpoint (&b->base))
5073 /* Since we don't know the exact trigger address (from
5074 stopped_data_address), just tell the user we've triggered
5075 a mask watchpoint. */
5076 return WP_VALUE_CHANGED;
5078 mark = value_mark ();
5079 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5081 if (b->val_bitsize != 0)
5082 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5084 /* We use value_equal_contents instead of value_equal because
5085 the latter coerces an array to a pointer, thus comparing just
5086 the address of the array instead of its contents. This is
5087 not what we want. */
5088 if ((b->val != NULL) != (new_val != NULL)
5089 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5091 if (new_val != NULL)
5093 release_value (new_val);
5094 value_free_to_mark (mark);
5096 bs->old_val = b->val;
5099 return WP_VALUE_CHANGED;
5103 /* Nothing changed. */
5104 value_free_to_mark (mark);
5105 return WP_VALUE_NOT_CHANGED;
5110 struct ui_out *uiout = current_uiout;
5112 /* This seems like the only logical thing to do because
5113 if we temporarily ignored the watchpoint, then when
5114 we reenter the block in which it is valid it contains
5115 garbage (in the case of a function, it may have two
5116 garbage values, one before and one after the prologue).
5117 So we can't even detect the first assignment to it and
5118 watch after that (since the garbage may or may not equal
5119 the first value assigned). */
5120 /* We print all the stop information in
5121 breakpoint_ops->print_it, but in this case, by the time we
5122 call breakpoint_ops->print_it this bp will be deleted
5123 already. So we have no choice but print the information
5125 if (ui_out_is_mi_like_p (uiout))
5127 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5128 ui_out_text (uiout, "\nWatchpoint ");
5129 ui_out_field_int (uiout, "wpnum", b->base.number);
5131 " deleted because the program has left the block in\n\
5132 which its expression is valid.\n");
5134 /* Make sure the watchpoint's commands aren't executed. */
5135 decref_counted_command_line (&b->base.commands);
5136 watchpoint_del_at_next_stop (b);
5142 /* Return true if it looks like target has stopped due to hitting
5143 breakpoint location BL. This function does not check if we should
5144 stop, only if BL explains the stop. */
5147 bpstat_check_location (const struct bp_location *bl,
5148 struct address_space *aspace, CORE_ADDR bp_addr,
5149 const struct target_waitstatus *ws)
5151 struct breakpoint *b = bl->owner;
5153 /* BL is from an existing breakpoint. */
5154 gdb_assert (b != NULL);
5156 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5159 /* Determine if the watched values have actually changed, and we
5160 should stop. If not, set BS->stop to 0. */
5163 bpstat_check_watchpoint (bpstat bs)
5165 const struct bp_location *bl;
5166 struct watchpoint *b;
5168 /* BS is built for existing struct breakpoint. */
5169 bl = bs->bp_location_at;
5170 gdb_assert (bl != NULL);
5171 b = (struct watchpoint *) bs->breakpoint_at;
5172 gdb_assert (b != NULL);
5175 int must_check_value = 0;
5177 if (b->base.type == bp_watchpoint)
5178 /* For a software watchpoint, we must always check the
5180 must_check_value = 1;
5181 else if (b->watchpoint_triggered == watch_triggered_yes)
5182 /* We have a hardware watchpoint (read, write, or access)
5183 and the target earlier reported an address watched by
5185 must_check_value = 1;
5186 else if (b->watchpoint_triggered == watch_triggered_unknown
5187 && b->base.type == bp_hardware_watchpoint)
5188 /* We were stopped by a hardware watchpoint, but the target could
5189 not report the data address. We must check the watchpoint's
5190 value. Access and read watchpoints are out of luck; without
5191 a data address, we can't figure it out. */
5192 must_check_value = 1;
5194 if (must_check_value)
5197 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5199 struct cleanup *cleanups = make_cleanup (xfree, message);
5200 int e = catch_errors (watchpoint_check, bs, message,
5202 do_cleanups (cleanups);
5206 /* We've already printed what needs to be printed. */
5207 bs->print_it = print_it_done;
5211 bs->print_it = print_it_noop;
5214 case WP_VALUE_CHANGED:
5215 if (b->base.type == bp_read_watchpoint)
5217 /* There are two cases to consider here:
5219 1. We're watching the triggered memory for reads.
5220 In that case, trust the target, and always report
5221 the watchpoint hit to the user. Even though
5222 reads don't cause value changes, the value may
5223 have changed since the last time it was read, and
5224 since we're not trapping writes, we will not see
5225 those, and as such we should ignore our notion of
5228 2. We're watching the triggered memory for both
5229 reads and writes. There are two ways this may
5232 2.1. This is a target that can't break on data
5233 reads only, but can break on accesses (reads or
5234 writes), such as e.g., x86. We detect this case
5235 at the time we try to insert read watchpoints.
5237 2.2. Otherwise, the target supports read
5238 watchpoints, but, the user set an access or write
5239 watchpoint watching the same memory as this read
5242 If we're watching memory writes as well as reads,
5243 ignore watchpoint hits when we find that the
5244 value hasn't changed, as reads don't cause
5245 changes. This still gives false positives when
5246 the program writes the same value to memory as
5247 what there was already in memory (we will confuse
5248 it for a read), but it's much better than
5251 int other_write_watchpoint = 0;
5253 if (bl->watchpoint_type == hw_read)
5255 struct breakpoint *other_b;
5257 ALL_BREAKPOINTS (other_b)
5258 if (other_b->type == bp_hardware_watchpoint
5259 || other_b->type == bp_access_watchpoint)
5261 struct watchpoint *other_w =
5262 (struct watchpoint *) other_b;
5264 if (other_w->watchpoint_triggered
5265 == watch_triggered_yes)
5267 other_write_watchpoint = 1;
5273 if (other_write_watchpoint
5274 || bl->watchpoint_type == hw_access)
5276 /* We're watching the same memory for writes,
5277 and the value changed since the last time we
5278 updated it, so this trap must be for a write.
5280 bs->print_it = print_it_noop;
5285 case WP_VALUE_NOT_CHANGED:
5286 if (b->base.type == bp_hardware_watchpoint
5287 || b->base.type == bp_watchpoint)
5289 /* Don't stop: write watchpoints shouldn't fire if
5290 the value hasn't changed. */
5291 bs->print_it = print_it_noop;
5299 /* Error from catch_errors. */
5300 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5301 watchpoint_del_at_next_stop (b);
5302 /* We've already printed what needs to be printed. */
5303 bs->print_it = print_it_done;
5307 else /* must_check_value == 0 */
5309 /* This is a case where some watchpoint(s) triggered, but
5310 not at the address of this watchpoint, or else no
5311 watchpoint triggered after all. So don't print
5312 anything for this watchpoint. */
5313 bs->print_it = print_it_noop;
5319 /* For breakpoints that are currently marked as telling gdb to stop,
5320 check conditions (condition proper, frame, thread and ignore count)
5321 of breakpoint referred to by BS. If we should not stop for this
5322 breakpoint, set BS->stop to 0. */
5325 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5327 const struct bp_location *bl;
5328 struct breakpoint *b;
5329 int value_is_zero = 0;
5330 struct expression *cond;
5332 gdb_assert (bs->stop);
5334 /* BS is built for existing struct breakpoint. */
5335 bl = bs->bp_location_at;
5336 gdb_assert (bl != NULL);
5337 b = bs->breakpoint_at;
5338 gdb_assert (b != NULL);
5340 /* Even if the target evaluated the condition on its end and notified GDB, we
5341 need to do so again since GDB does not know if we stopped due to a
5342 breakpoint or a single step breakpoint. */
5344 if (frame_id_p (b->frame_id)
5345 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5351 /* If this is a thread/task-specific breakpoint, don't waste cpu
5352 evaluating the condition if this isn't the specified
5354 if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid))
5355 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5362 /* Evaluate extension language breakpoints that have a "stop" method
5364 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5366 if (is_watchpoint (b))
5368 struct watchpoint *w = (struct watchpoint *) b;
5375 if (cond && b->disposition != disp_del_at_next_stop)
5377 int within_current_scope = 1;
5378 struct watchpoint * w;
5380 /* We use value_mark and value_free_to_mark because it could
5381 be a long time before we return to the command level and
5382 call free_all_values. We can't call free_all_values
5383 because we might be in the middle of evaluating a
5385 struct value *mark = value_mark ();
5387 if (is_watchpoint (b))
5388 w = (struct watchpoint *) b;
5392 /* Need to select the frame, with all that implies so that
5393 the conditions will have the right context. Because we
5394 use the frame, we will not see an inlined function's
5395 variables when we arrive at a breakpoint at the start
5396 of the inlined function; the current frame will be the
5398 if (w == NULL || w->cond_exp_valid_block == NULL)
5399 select_frame (get_current_frame ());
5402 struct frame_info *frame;
5404 /* For local watchpoint expressions, which particular
5405 instance of a local is being watched matters, so we
5406 keep track of the frame to evaluate the expression
5407 in. To evaluate the condition however, it doesn't
5408 really matter which instantiation of the function
5409 where the condition makes sense triggers the
5410 watchpoint. This allows an expression like "watch
5411 global if q > 10" set in `func', catch writes to
5412 global on all threads that call `func', or catch
5413 writes on all recursive calls of `func' by a single
5414 thread. We simply always evaluate the condition in
5415 the innermost frame that's executing where it makes
5416 sense to evaluate the condition. It seems
5418 frame = block_innermost_frame (w->cond_exp_valid_block);
5420 select_frame (frame);
5422 within_current_scope = 0;
5424 if (within_current_scope)
5426 = catch_errors (breakpoint_cond_eval, cond,
5427 "Error in testing breakpoint condition:\n",
5431 warning (_("Watchpoint condition cannot be tested "
5432 "in the current scope"));
5433 /* If we failed to set the right context for this
5434 watchpoint, unconditionally report it. */
5437 /* FIXME-someday, should give breakpoint #. */
5438 value_free_to_mark (mark);
5441 if (cond && value_is_zero)
5445 else if (b->ignore_count > 0)
5449 /* Increase the hit count even though we don't stop. */
5451 observer_notify_breakpoint_modified (b);
5455 /* Returns true if we need to track moribund locations of LOC's type
5456 on the current target. */
5459 need_moribund_for_location_type (struct bp_location *loc)
5461 return ((loc->loc_type == bp_loc_software_breakpoint
5462 && !target_supports_stopped_by_sw_breakpoint ())
5463 || (loc->loc_type == bp_loc_hardware_breakpoint
5464 && !target_supports_stopped_by_hw_breakpoint ()));
5468 /* Get a bpstat associated with having just stopped at address
5469 BP_ADDR in thread PTID.
5471 Determine whether we stopped at a breakpoint, etc, or whether we
5472 don't understand this stop. Result is a chain of bpstat's such
5475 if we don't understand the stop, the result is a null pointer.
5477 if we understand why we stopped, the result is not null.
5479 Each element of the chain refers to a particular breakpoint or
5480 watchpoint at which we have stopped. (We may have stopped for
5481 several reasons concurrently.)
5483 Each element of the chain has valid next, breakpoint_at,
5484 commands, FIXME??? fields. */
5487 bpstat_stop_status (struct address_space *aspace,
5488 CORE_ADDR bp_addr, ptid_t ptid,
5489 const struct target_waitstatus *ws)
5491 struct breakpoint *b = NULL;
5492 struct bp_location *bl;
5493 struct bp_location *loc;
5494 /* First item of allocated bpstat's. */
5495 bpstat bs_head = NULL, *bs_link = &bs_head;
5496 /* Pointer to the last thing in the chain currently. */
5499 int need_remove_insert;
5502 /* First, build the bpstat chain with locations that explain a
5503 target stop, while being careful to not set the target running,
5504 as that may invalidate locations (in particular watchpoint
5505 locations are recreated). Resuming will happen here with
5506 breakpoint conditions or watchpoint expressions that include
5507 inferior function calls. */
5511 if (!breakpoint_enabled (b))
5514 for (bl = b->loc; bl != NULL; bl = bl->next)
5516 /* For hardware watchpoints, we look only at the first
5517 location. The watchpoint_check function will work on the
5518 entire expression, not the individual locations. For
5519 read watchpoints, the watchpoints_triggered function has
5520 checked all locations already. */
5521 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5524 if (!bl->enabled || bl->shlib_disabled)
5527 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5530 /* Come here if it's a watchpoint, or if the break address
5533 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5536 /* Assume we stop. Should we find a watchpoint that is not
5537 actually triggered, or if the condition of the breakpoint
5538 evaluates as false, we'll reset 'stop' to 0. */
5542 /* If this is a scope breakpoint, mark the associated
5543 watchpoint as triggered so that we will handle the
5544 out-of-scope event. We'll get to the watchpoint next
5546 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5548 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5550 w->watchpoint_triggered = watch_triggered_yes;
5555 /* Check if a moribund breakpoint explains the stop. */
5556 if (!target_supports_stopped_by_sw_breakpoint ()
5557 || !target_supports_stopped_by_hw_breakpoint ())
5559 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5561 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5562 && need_moribund_for_location_type (loc))
5564 bs = bpstat_alloc (loc, &bs_link);
5565 /* For hits of moribund locations, we should just proceed. */
5568 bs->print_it = print_it_noop;
5573 /* A bit of special processing for shlib breakpoints. We need to
5574 process solib loading here, so that the lists of loaded and
5575 unloaded libraries are correct before we handle "catch load" and
5577 for (bs = bs_head; bs != NULL; bs = bs->next)
5579 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5581 handle_solib_event ();
5586 /* Now go through the locations that caused the target to stop, and
5587 check whether we're interested in reporting this stop to higher
5588 layers, or whether we should resume the target transparently. */
5592 for (bs = bs_head; bs != NULL; bs = bs->next)
5597 b = bs->breakpoint_at;
5598 b->ops->check_status (bs);
5601 bpstat_check_breakpoint_conditions (bs, ptid);
5606 observer_notify_breakpoint_modified (b);
5608 /* We will stop here. */
5609 if (b->disposition == disp_disable)
5611 --(b->enable_count);
5612 if (b->enable_count <= 0)
5613 b->enable_state = bp_disabled;
5618 bs->commands = b->commands;
5619 incref_counted_command_line (bs->commands);
5620 if (command_line_is_silent (bs->commands
5621 ? bs->commands->commands : NULL))
5624 b->ops->after_condition_true (bs);
5629 /* Print nothing for this entry if we don't stop or don't
5631 if (!bs->stop || !bs->print)
5632 bs->print_it = print_it_noop;
5635 /* If we aren't stopping, the value of some hardware watchpoint may
5636 not have changed, but the intermediate memory locations we are
5637 watching may have. Don't bother if we're stopping; this will get
5639 need_remove_insert = 0;
5640 if (! bpstat_causes_stop (bs_head))
5641 for (bs = bs_head; bs != NULL; bs = bs->next)
5643 && bs->breakpoint_at
5644 && is_hardware_watchpoint (bs->breakpoint_at))
5646 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5648 update_watchpoint (w, 0 /* don't reparse. */);
5649 need_remove_insert = 1;
5652 if (need_remove_insert)
5653 update_global_location_list (UGLL_MAY_INSERT);
5654 else if (removed_any)
5655 update_global_location_list (UGLL_DONT_INSERT);
5661 handle_jit_event (void)
5663 struct frame_info *frame;
5664 struct gdbarch *gdbarch;
5666 /* Switch terminal for any messages produced by
5667 breakpoint_re_set. */
5668 target_terminal_ours_for_output ();
5670 frame = get_current_frame ();
5671 gdbarch = get_frame_arch (frame);
5673 jit_event_handler (gdbarch);
5675 target_terminal_inferior ();
5678 /* Prepare WHAT final decision for infrun. */
5680 /* Decide what infrun needs to do with this bpstat. */
5683 bpstat_what (bpstat bs_head)
5685 struct bpstat_what retval;
5689 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5690 retval.call_dummy = STOP_NONE;
5691 retval.is_longjmp = 0;
5693 for (bs = bs_head; bs != NULL; bs = bs->next)
5695 /* Extract this BS's action. After processing each BS, we check
5696 if its action overrides all we've seem so far. */
5697 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5700 if (bs->breakpoint_at == NULL)
5702 /* I suspect this can happen if it was a momentary
5703 breakpoint which has since been deleted. */
5707 bptype = bs->breakpoint_at->type;
5714 case bp_hardware_breakpoint:
5715 case bp_single_step:
5718 case bp_shlib_event:
5722 this_action = BPSTAT_WHAT_STOP_NOISY;
5724 this_action = BPSTAT_WHAT_STOP_SILENT;
5727 this_action = BPSTAT_WHAT_SINGLE;
5730 case bp_hardware_watchpoint:
5731 case bp_read_watchpoint:
5732 case bp_access_watchpoint:
5736 this_action = BPSTAT_WHAT_STOP_NOISY;
5738 this_action = BPSTAT_WHAT_STOP_SILENT;
5742 /* There was a watchpoint, but we're not stopping.
5743 This requires no further action. */
5747 case bp_longjmp_call_dummy:
5749 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5750 retval.is_longjmp = bptype != bp_exception;
5752 case bp_longjmp_resume:
5753 case bp_exception_resume:
5754 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5755 retval.is_longjmp = bptype == bp_longjmp_resume;
5757 case bp_step_resume:
5759 this_action = BPSTAT_WHAT_STEP_RESUME;
5762 /* It is for the wrong frame. */
5763 this_action = BPSTAT_WHAT_SINGLE;
5766 case bp_hp_step_resume:
5768 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5771 /* It is for the wrong frame. */
5772 this_action = BPSTAT_WHAT_SINGLE;
5775 case bp_watchpoint_scope:
5776 case bp_thread_event:
5777 case bp_overlay_event:
5778 case bp_longjmp_master:
5779 case bp_std_terminate_master:
5780 case bp_exception_master:
5781 this_action = BPSTAT_WHAT_SINGLE;
5787 this_action = BPSTAT_WHAT_STOP_NOISY;
5789 this_action = BPSTAT_WHAT_STOP_SILENT;
5793 /* There was a catchpoint, but we're not stopping.
5794 This requires no further action. */
5799 this_action = BPSTAT_WHAT_SINGLE;
5802 /* Make sure the action is stop (silent or noisy),
5803 so infrun.c pops the dummy frame. */
5804 retval.call_dummy = STOP_STACK_DUMMY;
5805 this_action = BPSTAT_WHAT_STOP_SILENT;
5807 case bp_std_terminate:
5808 /* Make sure the action is stop (silent or noisy),
5809 so infrun.c pops the dummy frame. */
5810 retval.call_dummy = STOP_STD_TERMINATE;
5811 this_action = BPSTAT_WHAT_STOP_SILENT;
5814 case bp_fast_tracepoint:
5815 case bp_static_tracepoint:
5816 /* Tracepoint hits should not be reported back to GDB, and
5817 if one got through somehow, it should have been filtered
5819 internal_error (__FILE__, __LINE__,
5820 _("bpstat_what: tracepoint encountered"));
5822 case bp_gnu_ifunc_resolver:
5823 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5824 this_action = BPSTAT_WHAT_SINGLE;
5826 case bp_gnu_ifunc_resolver_return:
5827 /* The breakpoint will be removed, execution will restart from the
5828 PC of the former breakpoint. */
5829 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5834 this_action = BPSTAT_WHAT_STOP_SILENT;
5836 this_action = BPSTAT_WHAT_SINGLE;
5840 internal_error (__FILE__, __LINE__,
5841 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5844 retval.main_action = max (retval.main_action, this_action);
5847 /* These operations may affect the bs->breakpoint_at state so they are
5848 delayed after MAIN_ACTION is decided above. */
5853 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5855 handle_jit_event ();
5858 for (bs = bs_head; bs != NULL; bs = bs->next)
5860 struct breakpoint *b = bs->breakpoint_at;
5866 case bp_gnu_ifunc_resolver:
5867 gnu_ifunc_resolver_stop (b);
5869 case bp_gnu_ifunc_resolver_return:
5870 gnu_ifunc_resolver_return_stop (b);
5878 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5879 without hardware support). This isn't related to a specific bpstat,
5880 just to things like whether watchpoints are set. */
5883 bpstat_should_step (void)
5885 struct breakpoint *b;
5888 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5894 bpstat_causes_stop (bpstat bs)
5896 for (; bs != NULL; bs = bs->next)
5905 /* Compute a string of spaces suitable to indent the next line
5906 so it starts at the position corresponding to the table column
5907 named COL_NAME in the currently active table of UIOUT. */
5910 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5912 static char wrap_indent[80];
5913 int i, total_width, width, align;
5917 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5919 if (strcmp (text, col_name) == 0)
5921 gdb_assert (total_width < sizeof wrap_indent);
5922 memset (wrap_indent, ' ', total_width);
5923 wrap_indent[total_width] = 0;
5928 total_width += width + 1;
5934 /* Determine if the locations of this breakpoint will have their conditions
5935 evaluated by the target, host or a mix of both. Returns the following:
5937 "host": Host evals condition.
5938 "host or target": Host or Target evals condition.
5939 "target": Target evals condition.
5943 bp_condition_evaluator (struct breakpoint *b)
5945 struct bp_location *bl;
5946 char host_evals = 0;
5947 char target_evals = 0;
5952 if (!is_breakpoint (b))
5955 if (gdb_evaluates_breakpoint_condition_p ()
5956 || !target_supports_evaluation_of_breakpoint_conditions ())
5957 return condition_evaluation_host;
5959 for (bl = b->loc; bl; bl = bl->next)
5961 if (bl->cond_bytecode)
5967 if (host_evals && target_evals)
5968 return condition_evaluation_both;
5969 else if (target_evals)
5970 return condition_evaluation_target;
5972 return condition_evaluation_host;
5975 /* Determine the breakpoint location's condition evaluator. This is
5976 similar to bp_condition_evaluator, but for locations. */
5979 bp_location_condition_evaluator (struct bp_location *bl)
5981 if (bl && !is_breakpoint (bl->owner))
5984 if (gdb_evaluates_breakpoint_condition_p ()
5985 || !target_supports_evaluation_of_breakpoint_conditions ())
5986 return condition_evaluation_host;
5988 if (bl && bl->cond_bytecode)
5989 return condition_evaluation_target;
5991 return condition_evaluation_host;
5994 /* Print the LOC location out of the list of B->LOC locations. */
5997 print_breakpoint_location (struct breakpoint *b,
5998 struct bp_location *loc)
6000 struct ui_out *uiout = current_uiout;
6001 struct cleanup *old_chain = save_current_program_space ();
6003 if (loc != NULL && loc->shlib_disabled)
6007 set_current_program_space (loc->pspace);
6009 if (b->display_canonical)
6010 ui_out_field_string (uiout, "what", b->addr_string);
6011 else if (loc && loc->symtab)
6014 = find_pc_sect_function (loc->address, loc->section);
6017 ui_out_text (uiout, "in ");
6018 ui_out_field_string (uiout, "func",
6019 SYMBOL_PRINT_NAME (sym));
6020 ui_out_text (uiout, " ");
6021 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6022 ui_out_text (uiout, "at ");
6024 ui_out_field_string (uiout, "file",
6025 symtab_to_filename_for_display (loc->symtab));
6026 ui_out_text (uiout, ":");
6028 if (ui_out_is_mi_like_p (uiout))
6029 ui_out_field_string (uiout, "fullname",
6030 symtab_to_fullname (loc->symtab));
6032 ui_out_field_int (uiout, "line", loc->line_number);
6036 struct ui_file *stb = mem_fileopen ();
6037 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6039 print_address_symbolic (loc->gdbarch, loc->address, stb,
6041 ui_out_field_stream (uiout, "at", stb);
6043 do_cleanups (stb_chain);
6046 ui_out_field_string (uiout, "pending", b->addr_string);
6048 if (loc && is_breakpoint (b)
6049 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6050 && bp_condition_evaluator (b) == condition_evaluation_both)
6052 ui_out_text (uiout, " (");
6053 ui_out_field_string (uiout, "evaluated-by",
6054 bp_location_condition_evaluator (loc));
6055 ui_out_text (uiout, ")");
6058 do_cleanups (old_chain);
6062 bptype_string (enum bptype type)
6064 struct ep_type_description
6069 static struct ep_type_description bptypes[] =
6071 {bp_none, "?deleted?"},
6072 {bp_breakpoint, "breakpoint"},
6073 {bp_hardware_breakpoint, "hw breakpoint"},
6074 {bp_single_step, "sw single-step"},
6075 {bp_until, "until"},
6076 {bp_finish, "finish"},
6077 {bp_watchpoint, "watchpoint"},
6078 {bp_hardware_watchpoint, "hw watchpoint"},
6079 {bp_read_watchpoint, "read watchpoint"},
6080 {bp_access_watchpoint, "acc watchpoint"},
6081 {bp_longjmp, "longjmp"},
6082 {bp_longjmp_resume, "longjmp resume"},
6083 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6084 {bp_exception, "exception"},
6085 {bp_exception_resume, "exception resume"},
6086 {bp_step_resume, "step resume"},
6087 {bp_hp_step_resume, "high-priority step resume"},
6088 {bp_watchpoint_scope, "watchpoint scope"},
6089 {bp_call_dummy, "call dummy"},
6090 {bp_std_terminate, "std::terminate"},
6091 {bp_shlib_event, "shlib events"},
6092 {bp_thread_event, "thread events"},
6093 {bp_overlay_event, "overlay events"},
6094 {bp_longjmp_master, "longjmp master"},
6095 {bp_std_terminate_master, "std::terminate master"},
6096 {bp_exception_master, "exception master"},
6097 {bp_catchpoint, "catchpoint"},
6098 {bp_tracepoint, "tracepoint"},
6099 {bp_fast_tracepoint, "fast tracepoint"},
6100 {bp_static_tracepoint, "static tracepoint"},
6101 {bp_dprintf, "dprintf"},
6102 {bp_jit_event, "jit events"},
6103 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6104 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6107 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6108 || ((int) type != bptypes[(int) type].type))
6109 internal_error (__FILE__, __LINE__,
6110 _("bptypes table does not describe type #%d."),
6113 return bptypes[(int) type].description;
6116 /* For MI, output a field named 'thread-groups' with a list as the value.
6117 For CLI, prefix the list with the string 'inf'. */
6120 output_thread_groups (struct ui_out *uiout,
6121 const char *field_name,
6125 struct cleanup *back_to;
6126 int is_mi = ui_out_is_mi_like_p (uiout);
6130 /* For backward compatibility, don't display inferiors in CLI unless
6131 there are several. Always display them for MI. */
6132 if (!is_mi && mi_only)
6135 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6137 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6143 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6144 ui_out_field_string (uiout, NULL, mi_group);
6149 ui_out_text (uiout, " inf ");
6151 ui_out_text (uiout, ", ");
6153 ui_out_text (uiout, plongest (inf));
6157 do_cleanups (back_to);
6160 /* Print B to gdb_stdout. */
6163 print_one_breakpoint_location (struct breakpoint *b,
6164 struct bp_location *loc,
6166 struct bp_location **last_loc,
6169 struct command_line *l;
6170 static char bpenables[] = "nynny";
6172 struct ui_out *uiout = current_uiout;
6173 int header_of_multiple = 0;
6174 int part_of_multiple = (loc != NULL);
6175 struct value_print_options opts;
6177 get_user_print_options (&opts);
6179 gdb_assert (!loc || loc_number != 0);
6180 /* See comment in print_one_breakpoint concerning treatment of
6181 breakpoints with single disabled location. */
6184 && (b->loc->next != NULL || !b->loc->enabled)))
6185 header_of_multiple = 1;
6193 if (part_of_multiple)
6196 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6197 ui_out_field_string (uiout, "number", formatted);
6202 ui_out_field_int (uiout, "number", b->number);
6207 if (part_of_multiple)
6208 ui_out_field_skip (uiout, "type");
6210 ui_out_field_string (uiout, "type", bptype_string (b->type));
6214 if (part_of_multiple)
6215 ui_out_field_skip (uiout, "disp");
6217 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6222 if (part_of_multiple)
6223 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6225 ui_out_field_fmt (uiout, "enabled", "%c",
6226 bpenables[(int) b->enable_state]);
6227 ui_out_spaces (uiout, 2);
6231 if (b->ops != NULL && b->ops->print_one != NULL)
6233 /* Although the print_one can possibly print all locations,
6234 calling it here is not likely to get any nice result. So,
6235 make sure there's just one location. */
6236 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6237 b->ops->print_one (b, last_loc);
6243 internal_error (__FILE__, __LINE__,
6244 _("print_one_breakpoint: bp_none encountered\n"));
6248 case bp_hardware_watchpoint:
6249 case bp_read_watchpoint:
6250 case bp_access_watchpoint:
6252 struct watchpoint *w = (struct watchpoint *) b;
6254 /* Field 4, the address, is omitted (which makes the columns
6255 not line up too nicely with the headers, but the effect
6256 is relatively readable). */
6257 if (opts.addressprint)
6258 ui_out_field_skip (uiout, "addr");
6260 ui_out_field_string (uiout, "what", w->exp_string);
6265 case bp_hardware_breakpoint:
6266 case bp_single_step:
6270 case bp_longjmp_resume:
6271 case bp_longjmp_call_dummy:
6273 case bp_exception_resume:
6274 case bp_step_resume:
6275 case bp_hp_step_resume:
6276 case bp_watchpoint_scope:
6278 case bp_std_terminate:
6279 case bp_shlib_event:
6280 case bp_thread_event:
6281 case bp_overlay_event:
6282 case bp_longjmp_master:
6283 case bp_std_terminate_master:
6284 case bp_exception_master:
6286 case bp_fast_tracepoint:
6287 case bp_static_tracepoint:
6290 case bp_gnu_ifunc_resolver:
6291 case bp_gnu_ifunc_resolver_return:
6292 if (opts.addressprint)
6295 if (header_of_multiple)
6296 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6297 else if (b->loc == NULL || loc->shlib_disabled)
6298 ui_out_field_string (uiout, "addr", "<PENDING>");
6300 ui_out_field_core_addr (uiout, "addr",
6301 loc->gdbarch, loc->address);
6304 if (!header_of_multiple)
6305 print_breakpoint_location (b, loc);
6312 if (loc != NULL && !header_of_multiple)
6314 struct inferior *inf;
6315 VEC(int) *inf_num = NULL;
6320 if (inf->pspace == loc->pspace)
6321 VEC_safe_push (int, inf_num, inf->num);
6324 /* For backward compatibility, don't display inferiors in CLI unless
6325 there are several. Always display for MI. */
6327 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6328 && (number_of_program_spaces () > 1
6329 || number_of_inferiors () > 1)
6330 /* LOC is for existing B, it cannot be in
6331 moribund_locations and thus having NULL OWNER. */
6332 && loc->owner->type != bp_catchpoint))
6334 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6335 VEC_free (int, inf_num);
6338 if (!part_of_multiple)
6340 if (b->thread != -1)
6342 /* FIXME: This seems to be redundant and lost here; see the
6343 "stop only in" line a little further down. */
6344 ui_out_text (uiout, " thread ");
6345 ui_out_field_int (uiout, "thread", b->thread);
6347 else if (b->task != 0)
6349 ui_out_text (uiout, " task ");
6350 ui_out_field_int (uiout, "task", b->task);
6354 ui_out_text (uiout, "\n");
6356 if (!part_of_multiple)
6357 b->ops->print_one_detail (b, uiout);
6359 if (part_of_multiple && frame_id_p (b->frame_id))
6362 ui_out_text (uiout, "\tstop only in stack frame at ");
6363 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6365 ui_out_field_core_addr (uiout, "frame",
6366 b->gdbarch, b->frame_id.stack_addr);
6367 ui_out_text (uiout, "\n");
6370 if (!part_of_multiple && b->cond_string)
6373 if (is_tracepoint (b))
6374 ui_out_text (uiout, "\ttrace only if ");
6376 ui_out_text (uiout, "\tstop only if ");
6377 ui_out_field_string (uiout, "cond", b->cond_string);
6379 /* Print whether the target is doing the breakpoint's condition
6380 evaluation. If GDB is doing the evaluation, don't print anything. */
6381 if (is_breakpoint (b)
6382 && breakpoint_condition_evaluation_mode ()
6383 == condition_evaluation_target)
6385 ui_out_text (uiout, " (");
6386 ui_out_field_string (uiout, "evaluated-by",
6387 bp_condition_evaluator (b));
6388 ui_out_text (uiout, " evals)");
6390 ui_out_text (uiout, "\n");
6393 if (!part_of_multiple && b->thread != -1)
6395 /* FIXME should make an annotation for this. */
6396 ui_out_text (uiout, "\tstop only in thread ");
6397 ui_out_field_int (uiout, "thread", b->thread);
6398 ui_out_text (uiout, "\n");
6401 if (!part_of_multiple)
6405 /* FIXME should make an annotation for this. */
6406 if (is_catchpoint (b))
6407 ui_out_text (uiout, "\tcatchpoint");
6408 else if (is_tracepoint (b))
6409 ui_out_text (uiout, "\ttracepoint");
6411 ui_out_text (uiout, "\tbreakpoint");
6412 ui_out_text (uiout, " already hit ");
6413 ui_out_field_int (uiout, "times", b->hit_count);
6414 if (b->hit_count == 1)
6415 ui_out_text (uiout, " time\n");
6417 ui_out_text (uiout, " times\n");
6421 /* Output the count also if it is zero, but only if this is mi. */
6422 if (ui_out_is_mi_like_p (uiout))
6423 ui_out_field_int (uiout, "times", b->hit_count);
6427 if (!part_of_multiple && b->ignore_count)
6430 ui_out_text (uiout, "\tignore next ");
6431 ui_out_field_int (uiout, "ignore", b->ignore_count);
6432 ui_out_text (uiout, " hits\n");
6435 /* Note that an enable count of 1 corresponds to "enable once"
6436 behavior, which is reported by the combination of enablement and
6437 disposition, so we don't need to mention it here. */
6438 if (!part_of_multiple && b->enable_count > 1)
6441 ui_out_text (uiout, "\tdisable after ");
6442 /* Tweak the wording to clarify that ignore and enable counts
6443 are distinct, and have additive effect. */
6444 if (b->ignore_count)
6445 ui_out_text (uiout, "additional ");
6447 ui_out_text (uiout, "next ");
6448 ui_out_field_int (uiout, "enable", b->enable_count);
6449 ui_out_text (uiout, " hits\n");
6452 if (!part_of_multiple && is_tracepoint (b))
6454 struct tracepoint *tp = (struct tracepoint *) b;
6456 if (tp->traceframe_usage)
6458 ui_out_text (uiout, "\ttrace buffer usage ");
6459 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6460 ui_out_text (uiout, " bytes\n");
6464 l = b->commands ? b->commands->commands : NULL;
6465 if (!part_of_multiple && l)
6467 struct cleanup *script_chain;
6470 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6471 print_command_lines (uiout, l, 4);
6472 do_cleanups (script_chain);
6475 if (is_tracepoint (b))
6477 struct tracepoint *t = (struct tracepoint *) b;
6479 if (!part_of_multiple && t->pass_count)
6481 annotate_field (10);
6482 ui_out_text (uiout, "\tpass count ");
6483 ui_out_field_int (uiout, "pass", t->pass_count);
6484 ui_out_text (uiout, " \n");
6487 /* Don't display it when tracepoint or tracepoint location is
6489 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6491 annotate_field (11);
6493 if (ui_out_is_mi_like_p (uiout))
6494 ui_out_field_string (uiout, "installed",
6495 loc->inserted ? "y" : "n");
6499 ui_out_text (uiout, "\t");
6501 ui_out_text (uiout, "\tnot ");
6502 ui_out_text (uiout, "installed on target\n");
6507 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6509 if (is_watchpoint (b))
6511 struct watchpoint *w = (struct watchpoint *) b;
6513 ui_out_field_string (uiout, "original-location", w->exp_string);
6515 else if (b->addr_string)
6516 ui_out_field_string (uiout, "original-location", b->addr_string);
6521 print_one_breakpoint (struct breakpoint *b,
6522 struct bp_location **last_loc,
6525 struct cleanup *bkpt_chain;
6526 struct ui_out *uiout = current_uiout;
6528 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6530 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6531 do_cleanups (bkpt_chain);
6533 /* If this breakpoint has custom print function,
6534 it's already printed. Otherwise, print individual
6535 locations, if any. */
6536 if (b->ops == NULL || b->ops->print_one == NULL)
6538 /* If breakpoint has a single location that is disabled, we
6539 print it as if it had several locations, since otherwise it's
6540 hard to represent "breakpoint enabled, location disabled"
6543 Note that while hardware watchpoints have several locations
6544 internally, that's not a property exposed to user. */
6546 && !is_hardware_watchpoint (b)
6547 && (b->loc->next || !b->loc->enabled))
6549 struct bp_location *loc;
6552 for (loc = b->loc; loc; loc = loc->next, ++n)
6554 struct cleanup *inner2 =
6555 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6556 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6557 do_cleanups (inner2);
6564 breakpoint_address_bits (struct breakpoint *b)
6566 int print_address_bits = 0;
6567 struct bp_location *loc;
6569 for (loc = b->loc; loc; loc = loc->next)
6573 /* Software watchpoints that aren't watching memory don't have
6574 an address to print. */
6575 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6578 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6579 if (addr_bit > print_address_bits)
6580 print_address_bits = addr_bit;
6583 return print_address_bits;
6586 struct captured_breakpoint_query_args
6592 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6594 struct captured_breakpoint_query_args *args = data;
6595 struct breakpoint *b;
6596 struct bp_location *dummy_loc = NULL;
6600 if (args->bnum == b->number)
6602 print_one_breakpoint (b, &dummy_loc, 0);
6610 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6611 char **error_message)
6613 struct captured_breakpoint_query_args args;
6616 /* For the moment we don't trust print_one_breakpoint() to not throw
6618 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6619 error_message, RETURN_MASK_ALL) < 0)
6625 /* Return true if this breakpoint was set by the user, false if it is
6626 internal or momentary. */
6629 user_breakpoint_p (struct breakpoint *b)
6631 return b->number > 0;
6634 /* Print information on user settable breakpoint (watchpoint, etc)
6635 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6636 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6637 FILTER is non-NULL, call it on each breakpoint and only include the
6638 ones for which it returns non-zero. Return the total number of
6639 breakpoints listed. */
6642 breakpoint_1 (char *args, int allflag,
6643 int (*filter) (const struct breakpoint *))
6645 struct breakpoint *b;
6646 struct bp_location *last_loc = NULL;
6647 int nr_printable_breakpoints;
6648 struct cleanup *bkpttbl_chain;
6649 struct value_print_options opts;
6650 int print_address_bits = 0;
6651 int print_type_col_width = 14;
6652 struct ui_out *uiout = current_uiout;
6654 get_user_print_options (&opts);
6656 /* Compute the number of rows in the table, as well as the size
6657 required for address fields. */
6658 nr_printable_breakpoints = 0;
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. */
6667 if (args != NULL && *args != '\0')
6669 if (allflag && parse_and_eval_long (args) != b->number)
6671 if (!allflag && !number_is_in_list (args, b->number))
6675 if (allflag || user_breakpoint_p (b))
6677 int addr_bit, type_len;
6679 addr_bit = breakpoint_address_bits (b);
6680 if (addr_bit > print_address_bits)
6681 print_address_bits = addr_bit;
6683 type_len = strlen (bptype_string (b->type));
6684 if (type_len > print_type_col_width)
6685 print_type_col_width = type_len;
6687 nr_printable_breakpoints++;
6691 if (opts.addressprint)
6693 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6694 nr_printable_breakpoints,
6698 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6699 nr_printable_breakpoints,
6702 if (nr_printable_breakpoints > 0)
6703 annotate_breakpoints_headers ();
6704 if (nr_printable_breakpoints > 0)
6706 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6707 if (nr_printable_breakpoints > 0)
6709 ui_out_table_header (uiout, print_type_col_width, ui_left,
6710 "type", "Type"); /* 2 */
6711 if (nr_printable_breakpoints > 0)
6713 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6714 if (nr_printable_breakpoints > 0)
6716 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6717 if (opts.addressprint)
6719 if (nr_printable_breakpoints > 0)
6721 if (print_address_bits <= 32)
6722 ui_out_table_header (uiout, 10, ui_left,
6723 "addr", "Address"); /* 5 */
6725 ui_out_table_header (uiout, 18, ui_left,
6726 "addr", "Address"); /* 5 */
6728 if (nr_printable_breakpoints > 0)
6730 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6731 ui_out_table_body (uiout);
6732 if (nr_printable_breakpoints > 0)
6733 annotate_breakpoints_table ();
6738 /* If we have a filter, only list the breakpoints it accepts. */
6739 if (filter && !filter (b))
6742 /* If we have an "args" string, it is a list of breakpoints to
6743 accept. Skip the others. */
6745 if (args != NULL && *args != '\0')
6747 if (allflag) /* maintenance info breakpoint */
6749 if (parse_and_eval_long (args) != b->number)
6752 else /* all others */
6754 if (!number_is_in_list (args, b->number))
6758 /* We only print out user settable breakpoints unless the
6760 if (allflag || user_breakpoint_p (b))
6761 print_one_breakpoint (b, &last_loc, allflag);
6764 do_cleanups (bkpttbl_chain);
6766 if (nr_printable_breakpoints == 0)
6768 /* If there's a filter, let the caller decide how to report
6772 if (args == NULL || *args == '\0')
6773 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6775 ui_out_message (uiout, 0,
6776 "No breakpoint or watchpoint matching '%s'.\n",
6782 if (last_loc && !server_command)
6783 set_next_address (last_loc->gdbarch, last_loc->address);
6786 /* FIXME? Should this be moved up so that it is only called when
6787 there have been breakpoints? */
6788 annotate_breakpoints_table_end ();
6790 return nr_printable_breakpoints;
6793 /* Display the value of default-collect in a way that is generally
6794 compatible with the breakpoint list. */
6797 default_collect_info (void)
6799 struct ui_out *uiout = current_uiout;
6801 /* If it has no value (which is frequently the case), say nothing; a
6802 message like "No default-collect." gets in user's face when it's
6804 if (!*default_collect)
6807 /* The following phrase lines up nicely with per-tracepoint collect
6809 ui_out_text (uiout, "default collect ");
6810 ui_out_field_string (uiout, "default-collect", default_collect);
6811 ui_out_text (uiout, " \n");
6815 breakpoints_info (char *args, int from_tty)
6817 breakpoint_1 (args, 0, NULL);
6819 default_collect_info ();
6823 watchpoints_info (char *args, int from_tty)
6825 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6826 struct ui_out *uiout = current_uiout;
6828 if (num_printed == 0)
6830 if (args == NULL || *args == '\0')
6831 ui_out_message (uiout, 0, "No watchpoints.\n");
6833 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6838 maintenance_info_breakpoints (char *args, int from_tty)
6840 breakpoint_1 (args, 1, NULL);
6842 default_collect_info ();
6846 breakpoint_has_pc (struct breakpoint *b,
6847 struct program_space *pspace,
6848 CORE_ADDR pc, struct obj_section *section)
6850 struct bp_location *bl = b->loc;
6852 for (; bl; bl = bl->next)
6854 if (bl->pspace == pspace
6855 && bl->address == pc
6856 && (!overlay_debugging || bl->section == section))
6862 /* Print a message describing any user-breakpoints set at PC. This
6863 concerns with logical breakpoints, so we match program spaces, not
6867 describe_other_breakpoints (struct gdbarch *gdbarch,
6868 struct program_space *pspace, CORE_ADDR pc,
6869 struct obj_section *section, int thread)
6872 struct breakpoint *b;
6875 others += (user_breakpoint_p (b)
6876 && breakpoint_has_pc (b, pspace, pc, section));
6880 printf_filtered (_("Note: breakpoint "));
6881 else /* if (others == ???) */
6882 printf_filtered (_("Note: breakpoints "));
6884 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6887 printf_filtered ("%d", b->number);
6888 if (b->thread == -1 && thread != -1)
6889 printf_filtered (" (all threads)");
6890 else if (b->thread != -1)
6891 printf_filtered (" (thread %d)", b->thread);
6892 printf_filtered ("%s%s ",
6893 ((b->enable_state == bp_disabled
6894 || b->enable_state == bp_call_disabled)
6898 : ((others == 1) ? " and" : ""));
6900 printf_filtered (_("also set at pc "));
6901 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6902 printf_filtered (".\n");
6907 /* Return true iff it is meaningful to use the address member of
6908 BPT. For some breakpoint types, the address member is irrelevant
6909 and it makes no sense to attempt to compare it to other addresses
6910 (or use it for any other purpose either).
6912 More specifically, each of the following breakpoint types will
6913 always have a zero valued address and we don't want to mark
6914 breakpoints of any of these types to be a duplicate of an actual
6915 breakpoint at address zero:
6923 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6925 enum bptype type = bpt->type;
6927 return (type != bp_watchpoint && type != bp_catchpoint);
6930 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6931 true if LOC1 and LOC2 represent the same watchpoint location. */
6934 watchpoint_locations_match (struct bp_location *loc1,
6935 struct bp_location *loc2)
6937 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6938 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6940 /* Both of them must exist. */
6941 gdb_assert (w1 != NULL);
6942 gdb_assert (w2 != NULL);
6944 /* If the target can evaluate the condition expression in hardware,
6945 then we we need to insert both watchpoints even if they are at
6946 the same place. Otherwise the watchpoint will only trigger when
6947 the condition of whichever watchpoint was inserted evaluates to
6948 true, not giving a chance for GDB to check the condition of the
6949 other watchpoint. */
6951 && target_can_accel_watchpoint_condition (loc1->address,
6953 loc1->watchpoint_type,
6956 && target_can_accel_watchpoint_condition (loc2->address,
6958 loc2->watchpoint_type,
6962 /* Note that this checks the owner's type, not the location's. In
6963 case the target does not support read watchpoints, but does
6964 support access watchpoints, we'll have bp_read_watchpoint
6965 watchpoints with hw_access locations. Those should be considered
6966 duplicates of hw_read locations. The hw_read locations will
6967 become hw_access locations later. */
6968 return (loc1->owner->type == loc2->owner->type
6969 && loc1->pspace->aspace == loc2->pspace->aspace
6970 && loc1->address == loc2->address
6971 && loc1->length == loc2->length);
6974 /* See breakpoint.h. */
6977 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6978 struct address_space *aspace2, CORE_ADDR addr2)
6980 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6981 || aspace1 == aspace2)
6985 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6986 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6987 matches ASPACE2. On targets that have global breakpoints, the address
6988 space doesn't really matter. */
6991 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6992 int len1, struct address_space *aspace2,
6995 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6996 || aspace1 == aspace2)
6997 && addr2 >= addr1 && addr2 < addr1 + len1);
7000 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7001 a ranged breakpoint. In most targets, a match happens only if ASPACE
7002 matches the breakpoint's address space. On targets that have global
7003 breakpoints, the address space doesn't really matter. */
7006 breakpoint_location_address_match (struct bp_location *bl,
7007 struct address_space *aspace,
7010 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7013 && breakpoint_address_match_range (bl->pspace->aspace,
7014 bl->address, bl->length,
7018 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7019 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7020 true, otherwise returns false. */
7023 tracepoint_locations_match (struct bp_location *loc1,
7024 struct bp_location *loc2)
7026 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7027 /* Since tracepoint locations are never duplicated with others', tracepoint
7028 locations at the same address of different tracepoints are regarded as
7029 different locations. */
7030 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7035 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7036 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7037 represent the same location. */
7040 breakpoint_locations_match (struct bp_location *loc1,
7041 struct bp_location *loc2)
7043 int hw_point1, hw_point2;
7045 /* Both of them must not be in moribund_locations. */
7046 gdb_assert (loc1->owner != NULL);
7047 gdb_assert (loc2->owner != NULL);
7049 hw_point1 = is_hardware_watchpoint (loc1->owner);
7050 hw_point2 = is_hardware_watchpoint (loc2->owner);
7052 if (hw_point1 != hw_point2)
7055 return watchpoint_locations_match (loc1, loc2);
7056 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7057 return tracepoint_locations_match (loc1, loc2);
7059 /* We compare bp_location.length in order to cover ranged breakpoints. */
7060 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7061 loc2->pspace->aspace, loc2->address)
7062 && loc1->length == loc2->length);
7066 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7067 int bnum, int have_bnum)
7069 /* The longest string possibly returned by hex_string_custom
7070 is 50 chars. These must be at least that big for safety. */
7074 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7075 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7077 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7078 bnum, astr1, astr2);
7080 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7083 /* Adjust a breakpoint's address to account for architectural
7084 constraints on breakpoint placement. Return the adjusted address.
7085 Note: Very few targets require this kind of adjustment. For most
7086 targets, this function is simply the identity function. */
7089 adjust_breakpoint_address (struct gdbarch *gdbarch,
7090 CORE_ADDR bpaddr, enum bptype bptype)
7092 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7094 /* Very few targets need any kind of breakpoint adjustment. */
7097 else if (bptype == bp_watchpoint
7098 || bptype == bp_hardware_watchpoint
7099 || bptype == bp_read_watchpoint
7100 || bptype == bp_access_watchpoint
7101 || bptype == bp_catchpoint)
7103 /* Watchpoints and the various bp_catch_* eventpoints should not
7104 have their addresses modified. */
7107 else if (bptype == bp_single_step)
7109 /* Single-step breakpoints should not have their addresses
7110 modified. If there's any architectural constrain that
7111 applies to this address, then it should have already been
7112 taken into account when the breakpoint was created in the
7113 first place. If we didn't do this, stepping through e.g.,
7114 Thumb-2 IT blocks would break. */
7119 CORE_ADDR adjusted_bpaddr;
7121 /* Some targets have architectural constraints on the placement
7122 of breakpoint instructions. Obtain the adjusted address. */
7123 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7125 /* An adjusted breakpoint address can significantly alter
7126 a user's expectations. Print a warning if an adjustment
7128 if (adjusted_bpaddr != bpaddr)
7129 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7131 return adjusted_bpaddr;
7136 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7137 struct breakpoint *owner)
7139 memset (loc, 0, sizeof (*loc));
7141 gdb_assert (ops != NULL);
7146 loc->cond_bytecode = NULL;
7147 loc->shlib_disabled = 0;
7150 switch (owner->type)
7153 case bp_single_step:
7157 case bp_longjmp_resume:
7158 case bp_longjmp_call_dummy:
7160 case bp_exception_resume:
7161 case bp_step_resume:
7162 case bp_hp_step_resume:
7163 case bp_watchpoint_scope:
7165 case bp_std_terminate:
7166 case bp_shlib_event:
7167 case bp_thread_event:
7168 case bp_overlay_event:
7170 case bp_longjmp_master:
7171 case bp_std_terminate_master:
7172 case bp_exception_master:
7173 case bp_gnu_ifunc_resolver:
7174 case bp_gnu_ifunc_resolver_return:
7176 loc->loc_type = bp_loc_software_breakpoint;
7177 mark_breakpoint_location_modified (loc);
7179 case bp_hardware_breakpoint:
7180 loc->loc_type = bp_loc_hardware_breakpoint;
7181 mark_breakpoint_location_modified (loc);
7183 case bp_hardware_watchpoint:
7184 case bp_read_watchpoint:
7185 case bp_access_watchpoint:
7186 loc->loc_type = bp_loc_hardware_watchpoint;
7191 case bp_fast_tracepoint:
7192 case bp_static_tracepoint:
7193 loc->loc_type = bp_loc_other;
7196 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7202 /* Allocate a struct bp_location. */
7204 static struct bp_location *
7205 allocate_bp_location (struct breakpoint *bpt)
7207 return bpt->ops->allocate_location (bpt);
7211 free_bp_location (struct bp_location *loc)
7213 loc->ops->dtor (loc);
7217 /* Increment reference count. */
7220 incref_bp_location (struct bp_location *bl)
7225 /* Decrement reference count. If the reference count reaches 0,
7226 destroy the bp_location. Sets *BLP to NULL. */
7229 decref_bp_location (struct bp_location **blp)
7231 gdb_assert ((*blp)->refc > 0);
7233 if (--(*blp)->refc == 0)
7234 free_bp_location (*blp);
7238 /* Add breakpoint B at the end of the global breakpoint chain. */
7241 add_to_breakpoint_chain (struct breakpoint *b)
7243 struct breakpoint *b1;
7245 /* Add this breakpoint to the end of the chain so that a list of
7246 breakpoints will come out in order of increasing numbers. */
7248 b1 = breakpoint_chain;
7250 breakpoint_chain = b;
7259 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7262 init_raw_breakpoint_without_location (struct breakpoint *b,
7263 struct gdbarch *gdbarch,
7265 const struct breakpoint_ops *ops)
7267 memset (b, 0, sizeof (*b));
7269 gdb_assert (ops != NULL);
7273 b->gdbarch = gdbarch;
7274 b->language = current_language->la_language;
7275 b->input_radix = input_radix;
7277 b->enable_state = bp_enabled;
7280 b->ignore_count = 0;
7282 b->frame_id = null_frame_id;
7283 b->condition_not_parsed = 0;
7284 b->py_bp_object = NULL;
7285 b->related_breakpoint = b;
7288 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7289 that has type BPTYPE and has no locations as yet. */
7291 static struct breakpoint *
7292 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7294 const struct breakpoint_ops *ops)
7296 struct breakpoint *b = XNEW (struct breakpoint);
7298 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7299 add_to_breakpoint_chain (b);
7303 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7304 resolutions should be made as the user specified the location explicitly
7308 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7310 gdb_assert (loc->owner != NULL);
7312 if (loc->owner->type == bp_breakpoint
7313 || loc->owner->type == bp_hardware_breakpoint
7314 || is_tracepoint (loc->owner))
7317 const char *function_name;
7318 CORE_ADDR func_addr;
7320 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7321 &func_addr, NULL, &is_gnu_ifunc);
7323 if (is_gnu_ifunc && !explicit_loc)
7325 struct breakpoint *b = loc->owner;
7327 gdb_assert (loc->pspace == current_program_space);
7328 if (gnu_ifunc_resolve_name (function_name,
7329 &loc->requested_address))
7331 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7332 loc->address = adjust_breakpoint_address (loc->gdbarch,
7333 loc->requested_address,
7336 else if (b->type == bp_breakpoint && b->loc == loc
7337 && loc->next == NULL && b->related_breakpoint == b)
7339 /* Create only the whole new breakpoint of this type but do not
7340 mess more complicated breakpoints with multiple locations. */
7341 b->type = bp_gnu_ifunc_resolver;
7342 /* Remember the resolver's address for use by the return
7344 loc->related_address = func_addr;
7349 loc->function_name = xstrdup (function_name);
7353 /* Attempt to determine architecture of location identified by SAL. */
7355 get_sal_arch (struct symtab_and_line sal)
7358 return get_objfile_arch (sal.section->objfile);
7360 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7365 /* Low level routine for partially initializing a breakpoint of type
7366 BPTYPE. The newly created breakpoint's address, section, source
7367 file name, and line number are provided by SAL.
7369 It is expected that the caller will complete the initialization of
7370 the newly created breakpoint struct as well as output any status
7371 information regarding the creation of a new breakpoint. */
7374 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7375 struct symtab_and_line sal, enum bptype bptype,
7376 const struct breakpoint_ops *ops)
7378 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7380 add_location_to_breakpoint (b, &sal);
7382 if (bptype != bp_catchpoint)
7383 gdb_assert (sal.pspace != NULL);
7385 /* Store the program space that was used to set the breakpoint,
7386 except for ordinary breakpoints, which are independent of the
7388 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7389 b->pspace = sal.pspace;
7392 /* set_raw_breakpoint is a low level routine for allocating and
7393 partially initializing a breakpoint of type BPTYPE. The newly
7394 created breakpoint's address, section, source file name, and line
7395 number are provided by SAL. The newly created and partially
7396 initialized breakpoint is added to the breakpoint chain and
7397 is also returned as the value of this function.
7399 It is expected that the caller will complete the initialization of
7400 the newly created breakpoint struct as well as output any status
7401 information regarding the creation of a new breakpoint. In
7402 particular, set_raw_breakpoint does NOT set the breakpoint
7403 number! Care should be taken to not allow an error to occur
7404 prior to completing the initialization of the breakpoint. If this
7405 should happen, a bogus breakpoint will be left on the chain. */
7408 set_raw_breakpoint (struct gdbarch *gdbarch,
7409 struct symtab_and_line sal, enum bptype bptype,
7410 const struct breakpoint_ops *ops)
7412 struct breakpoint *b = XNEW (struct breakpoint);
7414 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7415 add_to_breakpoint_chain (b);
7420 /* Note that the breakpoint object B describes a permanent breakpoint
7421 instruction, hard-wired into the inferior's code. */
7423 make_breakpoint_permanent (struct breakpoint *b)
7425 struct bp_location *bl;
7427 /* By definition, permanent breakpoints are already present in the
7428 code. Mark all locations as inserted. For now,
7429 make_breakpoint_permanent is called in just one place, so it's
7430 hard to say if it's reasonable to have permanent breakpoint with
7431 multiple locations or not, but it's easy to implement. */
7432 for (bl = b->loc; bl; bl = bl->next)
7439 /* Call this routine when stepping and nexting to enable a breakpoint
7440 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7441 initiated the operation. */
7444 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7446 struct breakpoint *b, *b_tmp;
7447 int thread = tp->num;
7449 /* To avoid having to rescan all objfile symbols at every step,
7450 we maintain a list of continually-inserted but always disabled
7451 longjmp "master" breakpoints. Here, we simply create momentary
7452 clones of those and enable them for the requested thread. */
7453 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7454 if (b->pspace == current_program_space
7455 && (b->type == bp_longjmp_master
7456 || b->type == bp_exception_master))
7458 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7459 struct breakpoint *clone;
7461 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7462 after their removal. */
7463 clone = momentary_breakpoint_from_master (b, type,
7464 &longjmp_breakpoint_ops, 1);
7465 clone->thread = thread;
7468 tp->initiating_frame = frame;
7471 /* Delete all longjmp breakpoints from THREAD. */
7473 delete_longjmp_breakpoint (int thread)
7475 struct breakpoint *b, *b_tmp;
7477 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7478 if (b->type == bp_longjmp || b->type == bp_exception)
7480 if (b->thread == thread)
7481 delete_breakpoint (b);
7486 delete_longjmp_breakpoint_at_next_stop (int thread)
7488 struct breakpoint *b, *b_tmp;
7490 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7491 if (b->type == bp_longjmp || b->type == bp_exception)
7493 if (b->thread == thread)
7494 b->disposition = disp_del_at_next_stop;
7498 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7499 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7500 pointer to any of them. Return NULL if this system cannot place longjmp
7504 set_longjmp_breakpoint_for_call_dummy (void)
7506 struct breakpoint *b, *retval = NULL;
7509 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7511 struct breakpoint *new_b;
7513 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7514 &momentary_breakpoint_ops,
7516 new_b->thread = pid_to_thread_id (inferior_ptid);
7518 /* Link NEW_B into the chain of RETVAL breakpoints. */
7520 gdb_assert (new_b->related_breakpoint == new_b);
7523 new_b->related_breakpoint = retval;
7524 while (retval->related_breakpoint != new_b->related_breakpoint)
7525 retval = retval->related_breakpoint;
7526 retval->related_breakpoint = new_b;
7532 /* Verify all existing dummy frames and their associated breakpoints for
7533 TP. Remove those which can no longer be found in the current frame
7536 You should call this function only at places where it is safe to currently
7537 unwind the whole stack. Failed stack unwind would discard live dummy
7541 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7543 struct breakpoint *b, *b_tmp;
7545 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7546 if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
7548 struct breakpoint *dummy_b = b->related_breakpoint;
7550 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7551 dummy_b = dummy_b->related_breakpoint;
7552 if (dummy_b->type != bp_call_dummy
7553 || frame_find_by_id (dummy_b->frame_id) != NULL)
7556 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7558 while (b->related_breakpoint != b)
7560 if (b_tmp == b->related_breakpoint)
7561 b_tmp = b->related_breakpoint->next;
7562 delete_breakpoint (b->related_breakpoint);
7564 delete_breakpoint (b);
7569 enable_overlay_breakpoints (void)
7571 struct breakpoint *b;
7574 if (b->type == bp_overlay_event)
7576 b->enable_state = bp_enabled;
7577 update_global_location_list (UGLL_MAY_INSERT);
7578 overlay_events_enabled = 1;
7583 disable_overlay_breakpoints (void)
7585 struct breakpoint *b;
7588 if (b->type == bp_overlay_event)
7590 b->enable_state = bp_disabled;
7591 update_global_location_list (UGLL_DONT_INSERT);
7592 overlay_events_enabled = 0;
7596 /* Set an active std::terminate breakpoint for each std::terminate
7597 master breakpoint. */
7599 set_std_terminate_breakpoint (void)
7601 struct breakpoint *b, *b_tmp;
7603 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7604 if (b->pspace == current_program_space
7605 && b->type == bp_std_terminate_master)
7607 momentary_breakpoint_from_master (b, bp_std_terminate,
7608 &momentary_breakpoint_ops, 1);
7612 /* Delete all the std::terminate breakpoints. */
7614 delete_std_terminate_breakpoint (void)
7616 struct breakpoint *b, *b_tmp;
7618 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7619 if (b->type == bp_std_terminate)
7620 delete_breakpoint (b);
7624 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7626 struct breakpoint *b;
7628 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7629 &internal_breakpoint_ops);
7631 b->enable_state = bp_enabled;
7632 /* addr_string has to be used or breakpoint_re_set will delete me. */
7634 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7636 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7642 remove_thread_event_breakpoints (void)
7644 struct breakpoint *b, *b_tmp;
7646 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7647 if (b->type == bp_thread_event
7648 && b->loc->pspace == current_program_space)
7649 delete_breakpoint (b);
7652 struct lang_and_radix
7658 /* Create a breakpoint for JIT code registration and unregistration. */
7661 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7663 struct breakpoint *b;
7665 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7666 &internal_breakpoint_ops);
7667 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7671 /* Remove JIT code registration and unregistration breakpoint(s). */
7674 remove_jit_event_breakpoints (void)
7676 struct breakpoint *b, *b_tmp;
7678 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7679 if (b->type == bp_jit_event
7680 && b->loc->pspace == current_program_space)
7681 delete_breakpoint (b);
7685 remove_solib_event_breakpoints (void)
7687 struct breakpoint *b, *b_tmp;
7689 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7690 if (b->type == bp_shlib_event
7691 && b->loc->pspace == current_program_space)
7692 delete_breakpoint (b);
7695 /* See breakpoint.h. */
7698 remove_solib_event_breakpoints_at_next_stop (void)
7700 struct breakpoint *b, *b_tmp;
7702 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7703 if (b->type == bp_shlib_event
7704 && b->loc->pspace == current_program_space)
7705 b->disposition = disp_del_at_next_stop;
7708 /* Helper for create_solib_event_breakpoint /
7709 create_and_insert_solib_event_breakpoint. Allows specifying which
7710 INSERT_MODE to pass through to update_global_location_list. */
7712 static struct breakpoint *
7713 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7714 enum ugll_insert_mode insert_mode)
7716 struct breakpoint *b;
7718 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7719 &internal_breakpoint_ops);
7720 update_global_location_list_nothrow (insert_mode);
7725 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7727 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7730 /* See breakpoint.h. */
7733 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7735 struct breakpoint *b;
7737 /* Explicitly tell update_global_location_list to insert
7739 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7740 if (!b->loc->inserted)
7742 delete_breakpoint (b);
7748 /* Disable any breakpoints that are on code in shared libraries. Only
7749 apply to enabled breakpoints, disabled ones can just stay disabled. */
7752 disable_breakpoints_in_shlibs (void)
7754 struct bp_location *loc, **locp_tmp;
7756 ALL_BP_LOCATIONS (loc, locp_tmp)
7758 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7759 struct breakpoint *b = loc->owner;
7761 /* We apply the check to all breakpoints, including disabled for
7762 those with loc->duplicate set. This is so that when breakpoint
7763 becomes enabled, or the duplicate is removed, gdb will try to
7764 insert all breakpoints. If we don't set shlib_disabled here,
7765 we'll try to insert those breakpoints and fail. */
7766 if (((b->type == bp_breakpoint)
7767 || (b->type == bp_jit_event)
7768 || (b->type == bp_hardware_breakpoint)
7769 || (is_tracepoint (b)))
7770 && loc->pspace == current_program_space
7771 && !loc->shlib_disabled
7772 && solib_name_from_address (loc->pspace, loc->address)
7775 loc->shlib_disabled = 1;
7780 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7781 notification of unloaded_shlib. Only apply to enabled breakpoints,
7782 disabled ones can just stay disabled. */
7785 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7787 struct bp_location *loc, **locp_tmp;
7788 int disabled_shlib_breaks = 0;
7790 /* SunOS a.out shared libraries are always mapped, so do not
7791 disable breakpoints; they will only be reported as unloaded
7792 through clear_solib when GDB discards its shared library
7793 list. See clear_solib for more information. */
7794 if (exec_bfd != NULL
7795 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7798 ALL_BP_LOCATIONS (loc, locp_tmp)
7800 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7801 struct breakpoint *b = loc->owner;
7803 if (solib->pspace == loc->pspace
7804 && !loc->shlib_disabled
7805 && (((b->type == bp_breakpoint
7806 || b->type == bp_jit_event
7807 || b->type == bp_hardware_breakpoint)
7808 && (loc->loc_type == bp_loc_hardware_breakpoint
7809 || loc->loc_type == bp_loc_software_breakpoint))
7810 || is_tracepoint (b))
7811 && solib_contains_address_p (solib, loc->address))
7813 loc->shlib_disabled = 1;
7814 /* At this point, we cannot rely on remove_breakpoint
7815 succeeding so we must mark the breakpoint as not inserted
7816 to prevent future errors occurring in remove_breakpoints. */
7819 /* This may cause duplicate notifications for the same breakpoint. */
7820 observer_notify_breakpoint_modified (b);
7822 if (!disabled_shlib_breaks)
7824 target_terminal_ours_for_output ();
7825 warning (_("Temporarily disabling breakpoints "
7826 "for unloaded shared library \"%s\""),
7829 disabled_shlib_breaks = 1;
7834 /* Disable any breakpoints and tracepoints in OBJFILE upon
7835 notification of free_objfile. Only apply to enabled breakpoints,
7836 disabled ones can just stay disabled. */
7839 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7841 struct breakpoint *b;
7843 if (objfile == NULL)
7846 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7847 managed by the user with add-symbol-file/remove-symbol-file.
7848 Similarly to how breakpoints in shared libraries are handled in
7849 response to "nosharedlibrary", mark breakpoints in such modules
7850 shlib_disabled so they end up uninserted on the next global
7851 location list update. Shared libraries not loaded by the user
7852 aren't handled here -- they're already handled in
7853 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7854 solib_unloaded observer. We skip objfiles that are not
7855 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7857 if ((objfile->flags & OBJF_SHARED) == 0
7858 || (objfile->flags & OBJF_USERLOADED) == 0)
7863 struct bp_location *loc;
7864 int bp_modified = 0;
7866 if (!is_breakpoint (b) && !is_tracepoint (b))
7869 for (loc = b->loc; loc != NULL; loc = loc->next)
7871 CORE_ADDR loc_addr = loc->address;
7873 if (loc->loc_type != bp_loc_hardware_breakpoint
7874 && loc->loc_type != bp_loc_software_breakpoint)
7877 if (loc->shlib_disabled != 0)
7880 if (objfile->pspace != loc->pspace)
7883 if (loc->loc_type != bp_loc_hardware_breakpoint
7884 && loc->loc_type != bp_loc_software_breakpoint)
7887 if (is_addr_in_objfile (loc_addr, objfile))
7889 loc->shlib_disabled = 1;
7890 /* At this point, we don't know whether the object was
7891 unmapped from the inferior or not, so leave the
7892 inserted flag alone. We'll handle failure to
7893 uninsert quietly, in case the object was indeed
7896 mark_breakpoint_location_modified (loc);
7903 observer_notify_breakpoint_modified (b);
7907 /* FORK & VFORK catchpoints. */
7909 /* An instance of this type is used to represent a fork or vfork
7910 catchpoint. It includes a "struct breakpoint" as a kind of base
7911 class; users downcast to "struct breakpoint *" when needed. A
7912 breakpoint is really of this type iff its ops pointer points to
7913 CATCH_FORK_BREAKPOINT_OPS. */
7915 struct fork_catchpoint
7917 /* The base class. */
7918 struct breakpoint base;
7920 /* Process id of a child process whose forking triggered this
7921 catchpoint. This field is only valid immediately after this
7922 catchpoint has triggered. */
7923 ptid_t forked_inferior_pid;
7926 /* Implement the "insert" breakpoint_ops method for fork
7930 insert_catch_fork (struct bp_location *bl)
7932 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7935 /* Implement the "remove" breakpoint_ops method for fork
7939 remove_catch_fork (struct bp_location *bl)
7941 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7944 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7948 breakpoint_hit_catch_fork (const struct bp_location *bl,
7949 struct address_space *aspace, CORE_ADDR bp_addr,
7950 const struct target_waitstatus *ws)
7952 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7954 if (ws->kind != TARGET_WAITKIND_FORKED)
7957 c->forked_inferior_pid = ws->value.related_pid;
7961 /* Implement the "print_it" breakpoint_ops method for fork
7964 static enum print_stop_action
7965 print_it_catch_fork (bpstat bs)
7967 struct ui_out *uiout = current_uiout;
7968 struct breakpoint *b = bs->breakpoint_at;
7969 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7971 annotate_catchpoint (b->number);
7972 if (b->disposition == disp_del)
7973 ui_out_text (uiout, "\nTemporary catchpoint ");
7975 ui_out_text (uiout, "\nCatchpoint ");
7976 if (ui_out_is_mi_like_p (uiout))
7978 ui_out_field_string (uiout, "reason",
7979 async_reason_lookup (EXEC_ASYNC_FORK));
7980 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7982 ui_out_field_int (uiout, "bkptno", b->number);
7983 ui_out_text (uiout, " (forked process ");
7984 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7985 ui_out_text (uiout, "), ");
7986 return PRINT_SRC_AND_LOC;
7989 /* Implement the "print_one" breakpoint_ops method for fork
7993 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7995 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7996 struct value_print_options opts;
7997 struct ui_out *uiout = current_uiout;
7999 get_user_print_options (&opts);
8001 /* Field 4, the address, is omitted (which makes the columns not
8002 line up too nicely with the headers, but the effect is relatively
8004 if (opts.addressprint)
8005 ui_out_field_skip (uiout, "addr");
8007 ui_out_text (uiout, "fork");
8008 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8010 ui_out_text (uiout, ", process ");
8011 ui_out_field_int (uiout, "what",
8012 ptid_get_pid (c->forked_inferior_pid));
8013 ui_out_spaces (uiout, 1);
8016 if (ui_out_is_mi_like_p (uiout))
8017 ui_out_field_string (uiout, "catch-type", "fork");
8020 /* Implement the "print_mention" breakpoint_ops method for fork
8024 print_mention_catch_fork (struct breakpoint *b)
8026 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8029 /* Implement the "print_recreate" breakpoint_ops method for fork
8033 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8035 fprintf_unfiltered (fp, "catch fork");
8036 print_recreate_thread (b, fp);
8039 /* The breakpoint_ops structure to be used in fork catchpoints. */
8041 static struct breakpoint_ops catch_fork_breakpoint_ops;
8043 /* Implement the "insert" breakpoint_ops method for vfork
8047 insert_catch_vfork (struct bp_location *bl)
8049 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8052 /* Implement the "remove" breakpoint_ops method for vfork
8056 remove_catch_vfork (struct bp_location *bl)
8058 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8061 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8065 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8066 struct address_space *aspace, CORE_ADDR bp_addr,
8067 const struct target_waitstatus *ws)
8069 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8071 if (ws->kind != TARGET_WAITKIND_VFORKED)
8074 c->forked_inferior_pid = ws->value.related_pid;
8078 /* Implement the "print_it" breakpoint_ops method for vfork
8081 static enum print_stop_action
8082 print_it_catch_vfork (bpstat bs)
8084 struct ui_out *uiout = current_uiout;
8085 struct breakpoint *b = bs->breakpoint_at;
8086 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8088 annotate_catchpoint (b->number);
8089 if (b->disposition == disp_del)
8090 ui_out_text (uiout, "\nTemporary catchpoint ");
8092 ui_out_text (uiout, "\nCatchpoint ");
8093 if (ui_out_is_mi_like_p (uiout))
8095 ui_out_field_string (uiout, "reason",
8096 async_reason_lookup (EXEC_ASYNC_VFORK));
8097 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8099 ui_out_field_int (uiout, "bkptno", b->number);
8100 ui_out_text (uiout, " (vforked process ");
8101 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8102 ui_out_text (uiout, "), ");
8103 return PRINT_SRC_AND_LOC;
8106 /* Implement the "print_one" breakpoint_ops method for vfork
8110 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8112 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8113 struct value_print_options opts;
8114 struct ui_out *uiout = current_uiout;
8116 get_user_print_options (&opts);
8117 /* Field 4, the address, is omitted (which makes the columns not
8118 line up too nicely with the headers, but the effect is relatively
8120 if (opts.addressprint)
8121 ui_out_field_skip (uiout, "addr");
8123 ui_out_text (uiout, "vfork");
8124 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8126 ui_out_text (uiout, ", process ");
8127 ui_out_field_int (uiout, "what",
8128 ptid_get_pid (c->forked_inferior_pid));
8129 ui_out_spaces (uiout, 1);
8132 if (ui_out_is_mi_like_p (uiout))
8133 ui_out_field_string (uiout, "catch-type", "vfork");
8136 /* Implement the "print_mention" breakpoint_ops method for vfork
8140 print_mention_catch_vfork (struct breakpoint *b)
8142 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8145 /* Implement the "print_recreate" breakpoint_ops method for vfork
8149 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8151 fprintf_unfiltered (fp, "catch vfork");
8152 print_recreate_thread (b, fp);
8155 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8157 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8159 /* An instance of this type is used to represent an solib catchpoint.
8160 It includes a "struct breakpoint" as a kind of base class; users
8161 downcast to "struct breakpoint *" when needed. A breakpoint is
8162 really of this type iff its ops pointer points to
8163 CATCH_SOLIB_BREAKPOINT_OPS. */
8165 struct solib_catchpoint
8167 /* The base class. */
8168 struct breakpoint base;
8170 /* True for "catch load", false for "catch unload". */
8171 unsigned char is_load;
8173 /* Regular expression to match, if any. COMPILED is only valid when
8174 REGEX is non-NULL. */
8180 dtor_catch_solib (struct breakpoint *b)
8182 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8185 regfree (&self->compiled);
8186 xfree (self->regex);
8188 base_breakpoint_ops.dtor (b);
8192 insert_catch_solib (struct bp_location *ignore)
8198 remove_catch_solib (struct bp_location *ignore)
8204 breakpoint_hit_catch_solib (const struct bp_location *bl,
8205 struct address_space *aspace,
8207 const struct target_waitstatus *ws)
8209 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8210 struct breakpoint *other;
8212 if (ws->kind == TARGET_WAITKIND_LOADED)
8215 ALL_BREAKPOINTS (other)
8217 struct bp_location *other_bl;
8219 if (other == bl->owner)
8222 if (other->type != bp_shlib_event)
8225 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8228 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8230 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8239 check_status_catch_solib (struct bpstats *bs)
8241 struct solib_catchpoint *self
8242 = (struct solib_catchpoint *) bs->breakpoint_at;
8247 struct so_list *iter;
8250 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8255 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8264 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8269 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8275 bs->print_it = print_it_noop;
8278 static enum print_stop_action
8279 print_it_catch_solib (bpstat bs)
8281 struct breakpoint *b = bs->breakpoint_at;
8282 struct ui_out *uiout = current_uiout;
8284 annotate_catchpoint (b->number);
8285 if (b->disposition == disp_del)
8286 ui_out_text (uiout, "\nTemporary catchpoint ");
8288 ui_out_text (uiout, "\nCatchpoint ");
8289 ui_out_field_int (uiout, "bkptno", b->number);
8290 ui_out_text (uiout, "\n");
8291 if (ui_out_is_mi_like_p (uiout))
8292 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8293 print_solib_event (1);
8294 return PRINT_SRC_AND_LOC;
8298 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8300 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8301 struct value_print_options opts;
8302 struct ui_out *uiout = current_uiout;
8305 get_user_print_options (&opts);
8306 /* Field 4, the address, is omitted (which makes the columns not
8307 line up too nicely with the headers, but the effect is relatively
8309 if (opts.addressprint)
8312 ui_out_field_skip (uiout, "addr");
8319 msg = xstrprintf (_("load of library matching %s"), self->regex);
8321 msg = xstrdup (_("load of library"));
8326 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8328 msg = xstrdup (_("unload of library"));
8330 ui_out_field_string (uiout, "what", msg);
8333 if (ui_out_is_mi_like_p (uiout))
8334 ui_out_field_string (uiout, "catch-type",
8335 self->is_load ? "load" : "unload");
8339 print_mention_catch_solib (struct breakpoint *b)
8341 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8343 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8344 self->is_load ? "load" : "unload");
8348 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8350 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8352 fprintf_unfiltered (fp, "%s %s",
8353 b->disposition == disp_del ? "tcatch" : "catch",
8354 self->is_load ? "load" : "unload");
8356 fprintf_unfiltered (fp, " %s", self->regex);
8357 fprintf_unfiltered (fp, "\n");
8360 static struct breakpoint_ops catch_solib_breakpoint_ops;
8362 /* Shared helper function (MI and CLI) for creating and installing
8363 a shared object event catchpoint. If IS_LOAD is non-zero then
8364 the events to be caught are load events, otherwise they are
8365 unload events. If IS_TEMP is non-zero the catchpoint is a
8366 temporary one. If ENABLED is non-zero the catchpoint is
8367 created in an enabled state. */
8370 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8372 struct solib_catchpoint *c;
8373 struct gdbarch *gdbarch = get_current_arch ();
8374 struct cleanup *cleanup;
8378 arg = skip_spaces (arg);
8380 c = XCNEW (struct solib_catchpoint);
8381 cleanup = make_cleanup (xfree, c);
8387 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8390 char *err = get_regcomp_error (errcode, &c->compiled);
8392 make_cleanup (xfree, err);
8393 error (_("Invalid regexp (%s): %s"), err, arg);
8395 c->regex = xstrdup (arg);
8398 c->is_load = is_load;
8399 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8400 &catch_solib_breakpoint_ops);
8402 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8404 discard_cleanups (cleanup);
8405 install_breakpoint (0, &c->base, 1);
8408 /* A helper function that does all the work for "catch load" and
8412 catch_load_or_unload (char *arg, int from_tty, int is_load,
8413 struct cmd_list_element *command)
8416 const int enabled = 1;
8418 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8420 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8424 catch_load_command_1 (char *arg, int from_tty,
8425 struct cmd_list_element *command)
8427 catch_load_or_unload (arg, from_tty, 1, command);
8431 catch_unload_command_1 (char *arg, int from_tty,
8432 struct cmd_list_element *command)
8434 catch_load_or_unload (arg, from_tty, 0, command);
8437 /* An instance of this type is used to represent a syscall catchpoint.
8438 It includes a "struct breakpoint" as a kind of base class; users
8439 downcast to "struct breakpoint *" when needed. A breakpoint is
8440 really of this type iff its ops pointer points to
8441 CATCH_SYSCALL_BREAKPOINT_OPS. */
8443 struct syscall_catchpoint
8445 /* The base class. */
8446 struct breakpoint base;
8448 /* Syscall numbers used for the 'catch syscall' feature. If no
8449 syscall has been specified for filtering, its value is NULL.
8450 Otherwise, it holds a list of all syscalls to be caught. The
8451 list elements are allocated with xmalloc. */
8452 VEC(int) *syscalls_to_be_caught;
8455 /* Implement the "dtor" breakpoint_ops method for syscall
8459 dtor_catch_syscall (struct breakpoint *b)
8461 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8463 VEC_free (int, c->syscalls_to_be_caught);
8465 base_breakpoint_ops.dtor (b);
8468 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8470 struct catch_syscall_inferior_data
8472 /* We keep a count of the number of times the user has requested a
8473 particular syscall to be tracked, and pass this information to the
8474 target. This lets capable targets implement filtering directly. */
8476 /* Number of times that "any" syscall is requested. */
8477 int any_syscall_count;
8479 /* Count of each system call. */
8480 VEC(int) *syscalls_counts;
8482 /* This counts all syscall catch requests, so we can readily determine
8483 if any catching is necessary. */
8484 int total_syscalls_count;
8487 static struct catch_syscall_inferior_data*
8488 get_catch_syscall_inferior_data (struct inferior *inf)
8490 struct catch_syscall_inferior_data *inf_data;
8492 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8493 if (inf_data == NULL)
8495 inf_data = XCNEW (struct catch_syscall_inferior_data);
8496 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8503 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8509 /* Implement the "insert" breakpoint_ops method for syscall
8513 insert_catch_syscall (struct bp_location *bl)
8515 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8516 struct inferior *inf = current_inferior ();
8517 struct catch_syscall_inferior_data *inf_data
8518 = get_catch_syscall_inferior_data (inf);
8520 ++inf_data->total_syscalls_count;
8521 if (!c->syscalls_to_be_caught)
8522 ++inf_data->any_syscall_count;
8528 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8533 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8535 int old_size = VEC_length (int, inf_data->syscalls_counts);
8536 uintptr_t vec_addr_offset
8537 = old_size * ((uintptr_t) sizeof (int));
8539 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8540 vec_addr = ((uintptr_t) VEC_address (int,
8541 inf_data->syscalls_counts)
8543 memset ((void *) vec_addr, 0,
8544 (iter + 1 - old_size) * sizeof (int));
8546 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8547 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8551 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8552 inf_data->total_syscalls_count != 0,
8553 inf_data->any_syscall_count,
8555 inf_data->syscalls_counts),
8557 inf_data->syscalls_counts));
8560 /* Implement the "remove" breakpoint_ops method for syscall
8564 remove_catch_syscall (struct bp_location *bl)
8566 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8567 struct inferior *inf = current_inferior ();
8568 struct catch_syscall_inferior_data *inf_data
8569 = get_catch_syscall_inferior_data (inf);
8571 --inf_data->total_syscalls_count;
8572 if (!c->syscalls_to_be_caught)
8573 --inf_data->any_syscall_count;
8579 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8583 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8584 /* Shouldn't happen. */
8586 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8587 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8591 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8592 inf_data->total_syscalls_count != 0,
8593 inf_data->any_syscall_count,
8595 inf_data->syscalls_counts),
8597 inf_data->syscalls_counts));
8600 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8604 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8605 struct address_space *aspace, CORE_ADDR bp_addr,
8606 const struct target_waitstatus *ws)
8608 /* We must check if we are catching specific syscalls in this
8609 breakpoint. If we are, then we must guarantee that the called
8610 syscall is the same syscall we are catching. */
8611 int syscall_number = 0;
8612 const struct syscall_catchpoint *c
8613 = (const struct syscall_catchpoint *) bl->owner;
8615 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8616 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8619 syscall_number = ws->value.syscall_number;
8621 /* Now, checking if the syscall is the same. */
8622 if (c->syscalls_to_be_caught)
8627 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8629 if (syscall_number == iter)
8638 /* Implement the "print_it" breakpoint_ops method for syscall
8641 static enum print_stop_action
8642 print_it_catch_syscall (bpstat bs)
8644 struct ui_out *uiout = current_uiout;
8645 struct breakpoint *b = bs->breakpoint_at;
8646 /* These are needed because we want to know in which state a
8647 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8648 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8649 must print "called syscall" or "returned from syscall". */
8651 struct target_waitstatus last;
8653 struct gdbarch *gdbarch = bs->bp_location_at->gdbarch;
8655 get_last_target_status (&ptid, &last);
8657 get_syscall_by_number (gdbarch, last.value.syscall_number, &s);
8659 annotate_catchpoint (b->number);
8661 if (b->disposition == disp_del)
8662 ui_out_text (uiout, "\nTemporary catchpoint ");
8664 ui_out_text (uiout, "\nCatchpoint ");
8665 if (ui_out_is_mi_like_p (uiout))
8667 ui_out_field_string (uiout, "reason",
8668 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8669 ? EXEC_ASYNC_SYSCALL_ENTRY
8670 : EXEC_ASYNC_SYSCALL_RETURN));
8671 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8673 ui_out_field_int (uiout, "bkptno", b->number);
8675 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8676 ui_out_text (uiout, " (call to syscall ");
8678 ui_out_text (uiout, " (returned from syscall ");
8680 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8681 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8683 ui_out_field_string (uiout, "syscall-name", s.name);
8685 ui_out_text (uiout, "), ");
8687 return PRINT_SRC_AND_LOC;
8690 /* Implement the "print_one" breakpoint_ops method for syscall
8694 print_one_catch_syscall (struct breakpoint *b,
8695 struct bp_location **last_loc)
8697 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8698 struct value_print_options opts;
8699 struct ui_out *uiout = current_uiout;
8700 struct gdbarch *gdbarch = b->loc->gdbarch;
8702 get_user_print_options (&opts);
8703 /* Field 4, the address, is omitted (which makes the columns not
8704 line up too nicely with the headers, but the effect is relatively
8706 if (opts.addressprint)
8707 ui_out_field_skip (uiout, "addr");
8710 if (c->syscalls_to_be_caught
8711 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8712 ui_out_text (uiout, "syscalls \"");
8714 ui_out_text (uiout, "syscall \"");
8716 if (c->syscalls_to_be_caught)
8719 char *text = xstrprintf ("%s", "");
8722 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8727 get_syscall_by_number (gdbarch, iter, &s);
8730 text = xstrprintf ("%s%s, ", text, s.name);
8732 text = xstrprintf ("%s%d, ", text, iter);
8734 /* We have to xfree the last 'text' (now stored at 'x')
8735 because xstrprintf dynamically allocates new space for it
8739 /* Remove the last comma. */
8740 text[strlen (text) - 2] = '\0';
8741 ui_out_field_string (uiout, "what", text);
8744 ui_out_field_string (uiout, "what", "<any syscall>");
8745 ui_out_text (uiout, "\" ");
8747 if (ui_out_is_mi_like_p (uiout))
8748 ui_out_field_string (uiout, "catch-type", "syscall");
8751 /* Implement the "print_mention" breakpoint_ops method for syscall
8755 print_mention_catch_syscall (struct breakpoint *b)
8757 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8758 struct gdbarch *gdbarch = b->loc->gdbarch;
8760 if (c->syscalls_to_be_caught)
8764 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8765 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8767 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8770 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8774 get_syscall_by_number (gdbarch, iter, &s);
8777 printf_filtered (" '%s' [%d]", s.name, s.number);
8779 printf_filtered (" %d", s.number);
8781 printf_filtered (")");
8784 printf_filtered (_("Catchpoint %d (any syscall)"),
8788 /* Implement the "print_recreate" breakpoint_ops method for syscall
8792 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8794 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8795 struct gdbarch *gdbarch = b->loc->gdbarch;
8797 fprintf_unfiltered (fp, "catch syscall");
8799 if (c->syscalls_to_be_caught)
8804 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8809 get_syscall_by_number (gdbarch, iter, &s);
8811 fprintf_unfiltered (fp, " %s", s.name);
8813 fprintf_unfiltered (fp, " %d", s.number);
8816 print_recreate_thread (b, fp);
8819 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8821 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8823 /* Returns non-zero if 'b' is a syscall catchpoint. */
8826 syscall_catchpoint_p (struct breakpoint *b)
8828 return (b->ops == &catch_syscall_breakpoint_ops);
8831 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8832 is non-zero, then make the breakpoint temporary. If COND_STRING is
8833 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8834 the breakpoint_ops structure associated to the catchpoint. */
8837 init_catchpoint (struct breakpoint *b,
8838 struct gdbarch *gdbarch, int tempflag,
8840 const struct breakpoint_ops *ops)
8842 struct symtab_and_line sal;
8845 sal.pspace = current_program_space;
8847 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8849 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8850 b->disposition = tempflag ? disp_del : disp_donttouch;
8854 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8856 add_to_breakpoint_chain (b);
8857 set_breakpoint_number (internal, b);
8858 if (is_tracepoint (b))
8859 set_tracepoint_count (breakpoint_count);
8862 observer_notify_breakpoint_created (b);
8865 update_global_location_list (UGLL_MAY_INSERT);
8869 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8870 int tempflag, char *cond_string,
8871 const struct breakpoint_ops *ops)
8873 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8875 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8877 c->forked_inferior_pid = null_ptid;
8879 install_breakpoint (0, &c->base, 1);
8882 /* Exec catchpoints. */
8884 /* An instance of this type is used to represent an exec catchpoint.
8885 It includes a "struct breakpoint" as a kind of base class; users
8886 downcast to "struct breakpoint *" when needed. A breakpoint is
8887 really of this type iff its ops pointer points to
8888 CATCH_EXEC_BREAKPOINT_OPS. */
8890 struct exec_catchpoint
8892 /* The base class. */
8893 struct breakpoint base;
8895 /* Filename of a program whose exec triggered this catchpoint.
8896 This field is only valid immediately after this catchpoint has
8898 char *exec_pathname;
8901 /* Implement the "dtor" breakpoint_ops method for exec
8905 dtor_catch_exec (struct breakpoint *b)
8907 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8909 xfree (c->exec_pathname);
8911 base_breakpoint_ops.dtor (b);
8915 insert_catch_exec (struct bp_location *bl)
8917 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8921 remove_catch_exec (struct bp_location *bl)
8923 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8927 breakpoint_hit_catch_exec (const struct bp_location *bl,
8928 struct address_space *aspace, CORE_ADDR bp_addr,
8929 const struct target_waitstatus *ws)
8931 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8933 if (ws->kind != TARGET_WAITKIND_EXECD)
8936 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8940 static enum print_stop_action
8941 print_it_catch_exec (bpstat bs)
8943 struct ui_out *uiout = current_uiout;
8944 struct breakpoint *b = bs->breakpoint_at;
8945 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8947 annotate_catchpoint (b->number);
8948 if (b->disposition == disp_del)
8949 ui_out_text (uiout, "\nTemporary catchpoint ");
8951 ui_out_text (uiout, "\nCatchpoint ");
8952 if (ui_out_is_mi_like_p (uiout))
8954 ui_out_field_string (uiout, "reason",
8955 async_reason_lookup (EXEC_ASYNC_EXEC));
8956 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8958 ui_out_field_int (uiout, "bkptno", b->number);
8959 ui_out_text (uiout, " (exec'd ");
8960 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8961 ui_out_text (uiout, "), ");
8963 return PRINT_SRC_AND_LOC;
8967 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8969 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8970 struct value_print_options opts;
8971 struct ui_out *uiout = current_uiout;
8973 get_user_print_options (&opts);
8975 /* Field 4, the address, is omitted (which makes the columns
8976 not line up too nicely with the headers, but the effect
8977 is relatively readable). */
8978 if (opts.addressprint)
8979 ui_out_field_skip (uiout, "addr");
8981 ui_out_text (uiout, "exec");
8982 if (c->exec_pathname != NULL)
8984 ui_out_text (uiout, ", program \"");
8985 ui_out_field_string (uiout, "what", c->exec_pathname);
8986 ui_out_text (uiout, "\" ");
8989 if (ui_out_is_mi_like_p (uiout))
8990 ui_out_field_string (uiout, "catch-type", "exec");
8994 print_mention_catch_exec (struct breakpoint *b)
8996 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8999 /* Implement the "print_recreate" breakpoint_ops method for exec
9003 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
9005 fprintf_unfiltered (fp, "catch exec");
9006 print_recreate_thread (b, fp);
9009 static struct breakpoint_ops catch_exec_breakpoint_ops;
9012 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
9013 const struct breakpoint_ops *ops)
9015 struct syscall_catchpoint *c;
9016 struct gdbarch *gdbarch = get_current_arch ();
9018 c = XNEW (struct syscall_catchpoint);
9019 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
9020 c->syscalls_to_be_caught = filter;
9022 install_breakpoint (0, &c->base, 1);
9026 hw_breakpoint_used_count (void)
9029 struct breakpoint *b;
9030 struct bp_location *bl;
9034 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
9035 for (bl = b->loc; bl; bl = bl->next)
9037 /* Special types of hardware breakpoints may use more than
9039 i += b->ops->resources_needed (bl);
9046 /* Returns the resources B would use if it were a hardware
9050 hw_watchpoint_use_count (struct breakpoint *b)
9053 struct bp_location *bl;
9055 if (!breakpoint_enabled (b))
9058 for (bl = b->loc; bl; bl = bl->next)
9060 /* Special types of hardware watchpoints may use more than
9062 i += b->ops->resources_needed (bl);
9068 /* Returns the sum the used resources of all hardware watchpoints of
9069 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9070 the sum of the used resources of all hardware watchpoints of other
9071 types _not_ TYPE. */
9074 hw_watchpoint_used_count_others (struct breakpoint *except,
9075 enum bptype type, int *other_type_used)
9078 struct breakpoint *b;
9080 *other_type_used = 0;
9085 if (!breakpoint_enabled (b))
9088 if (b->type == type)
9089 i += hw_watchpoint_use_count (b);
9090 else if (is_hardware_watchpoint (b))
9091 *other_type_used = 1;
9098 disable_watchpoints_before_interactive_call_start (void)
9100 struct breakpoint *b;
9104 if (is_watchpoint (b) && breakpoint_enabled (b))
9106 b->enable_state = bp_call_disabled;
9107 update_global_location_list (UGLL_DONT_INSERT);
9113 enable_watchpoints_after_interactive_call_stop (void)
9115 struct breakpoint *b;
9119 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
9121 b->enable_state = bp_enabled;
9122 update_global_location_list (UGLL_MAY_INSERT);
9128 disable_breakpoints_before_startup (void)
9130 current_program_space->executing_startup = 1;
9131 update_global_location_list (UGLL_DONT_INSERT);
9135 enable_breakpoints_after_startup (void)
9137 current_program_space->executing_startup = 0;
9138 breakpoint_re_set ();
9141 /* Create a new single-step breakpoint for thread THREAD, with no
9144 static struct breakpoint *
9145 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
9147 struct breakpoint *b = XNEW (struct breakpoint);
9149 init_raw_breakpoint_without_location (b, gdbarch, bp_single_step,
9150 &momentary_breakpoint_ops);
9152 b->disposition = disp_donttouch;
9153 b->frame_id = null_frame_id;
9156 gdb_assert (b->thread != 0);
9158 add_to_breakpoint_chain (b);
9163 /* Set a momentary breakpoint of type TYPE at address specified by
9164 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
9168 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
9169 struct frame_id frame_id, enum bptype type)
9171 struct breakpoint *b;
9173 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9175 gdb_assert (!frame_id_artificial_p (frame_id));
9177 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
9178 b->enable_state = bp_enabled;
9179 b->disposition = disp_donttouch;
9180 b->frame_id = frame_id;
9182 /* If we're debugging a multi-threaded program, then we want
9183 momentary breakpoints to be active in only a single thread of
9185 if (in_thread_list (inferior_ptid))
9186 b->thread = pid_to_thread_id (inferior_ptid);
9188 update_global_location_list_nothrow (UGLL_MAY_INSERT);
9193 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9194 The new breakpoint will have type TYPE, use OPS as its
9195 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9197 static struct breakpoint *
9198 momentary_breakpoint_from_master (struct breakpoint *orig,
9200 const struct breakpoint_ops *ops,
9203 struct breakpoint *copy;
9205 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
9206 copy->loc = allocate_bp_location (copy);
9207 set_breakpoint_location_function (copy->loc, 1);
9209 copy->loc->gdbarch = orig->loc->gdbarch;
9210 copy->loc->requested_address = orig->loc->requested_address;
9211 copy->loc->address = orig->loc->address;
9212 copy->loc->section = orig->loc->section;
9213 copy->loc->pspace = orig->loc->pspace;
9214 copy->loc->probe = orig->loc->probe;
9215 copy->loc->line_number = orig->loc->line_number;
9216 copy->loc->symtab = orig->loc->symtab;
9217 copy->loc->enabled = loc_enabled;
9218 copy->frame_id = orig->frame_id;
9219 copy->thread = orig->thread;
9220 copy->pspace = orig->pspace;
9222 copy->enable_state = bp_enabled;
9223 copy->disposition = disp_donttouch;
9224 copy->number = internal_breakpoint_number--;
9226 update_global_location_list_nothrow (UGLL_DONT_INSERT);
9230 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9234 clone_momentary_breakpoint (struct breakpoint *orig)
9236 /* If there's nothing to clone, then return nothing. */
9240 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
9244 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
9247 struct symtab_and_line sal;
9249 sal = find_pc_line (pc, 0);
9251 sal.section = find_pc_overlay (pc);
9252 sal.explicit_pc = 1;
9254 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
9258 /* Tell the user we have just set a breakpoint B. */
9261 mention (struct breakpoint *b)
9263 b->ops->print_mention (b);
9264 if (ui_out_is_mi_like_p (current_uiout))
9266 printf_filtered ("\n");
9270 static int bp_loc_is_permanent (struct bp_location *loc);
9272 static struct bp_location *
9273 add_location_to_breakpoint (struct breakpoint *b,
9274 const struct symtab_and_line *sal)
9276 struct bp_location *loc, **tmp;
9277 CORE_ADDR adjusted_address;
9278 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9280 if (loc_gdbarch == NULL)
9281 loc_gdbarch = b->gdbarch;
9283 /* Adjust the breakpoint's address prior to allocating a location.
9284 Once we call allocate_bp_location(), that mostly uninitialized
9285 location will be placed on the location chain. Adjustment of the
9286 breakpoint may cause target_read_memory() to be called and we do
9287 not want its scan of the location chain to find a breakpoint and
9288 location that's only been partially initialized. */
9289 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9292 /* Sort the locations by their ADDRESS. */
9293 loc = allocate_bp_location (b);
9294 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9295 tmp = &((*tmp)->next))
9300 loc->requested_address = sal->pc;
9301 loc->address = adjusted_address;
9302 loc->pspace = sal->pspace;
9303 loc->probe.probe = sal->probe;
9304 loc->probe.objfile = sal->objfile;
9305 gdb_assert (loc->pspace != NULL);
9306 loc->section = sal->section;
9307 loc->gdbarch = loc_gdbarch;
9308 loc->line_number = sal->line;
9309 loc->symtab = sal->symtab;
9311 set_breakpoint_location_function (loc,
9312 sal->explicit_pc || sal->explicit_line);
9314 if (bp_loc_is_permanent (loc))
9324 /* See breakpoint.h. */
9327 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
9331 const gdb_byte *bpoint;
9332 gdb_byte *target_mem;
9333 struct cleanup *cleanup;
9337 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
9339 /* Software breakpoints unsupported? */
9343 target_mem = alloca (len);
9345 /* Enable the automatic memory restoration from breakpoints while
9346 we read the memory. Otherwise we could say about our temporary
9347 breakpoints they are permanent. */
9348 cleanup = make_show_memory_breakpoints_cleanup (0);
9350 if (target_read_memory (address, target_mem, len) == 0
9351 && memcmp (target_mem, bpoint, len) == 0)
9354 do_cleanups (cleanup);
9359 /* Return 1 if LOC is pointing to a permanent breakpoint,
9360 return 0 otherwise. */
9363 bp_loc_is_permanent (struct bp_location *loc)
9365 struct cleanup *cleanup;
9368 gdb_assert (loc != NULL);
9370 /* bp_call_dummy breakpoint locations are usually memory locations
9371 where GDB just wrote a breakpoint instruction, making it look
9372 as if there is a permanent breakpoint at that location. Considering
9373 it permanent makes GDB rely on that breakpoint instruction to stop
9374 the program, thus removing the need to insert its own breakpoint
9375 there. This is normally expected to work, except that some versions
9376 of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap
9377 0x02 while interrupts disabled, Error state) instead of reporting
9378 a SIGTRAP. QEMU should probably be fixed, but in the interest of
9379 compatibility with versions that behave this way, we always consider
9380 bp_call_dummy breakpoint locations as non-permanent. */
9381 if (loc->owner->type == bp_call_dummy)
9384 cleanup = save_current_space_and_thread ();
9385 switch_to_program_space_and_thread (loc->pspace);
9387 retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
9389 do_cleanups (cleanup);
9394 /* Build a command list for the dprintf corresponding to the current
9395 settings of the dprintf style options. */
9398 update_dprintf_command_list (struct breakpoint *b)
9400 char *dprintf_args = b->extra_string;
9401 char *printf_line = NULL;
9406 dprintf_args = skip_spaces (dprintf_args);
9408 /* Allow a comma, as it may have terminated a location, but don't
9410 if (*dprintf_args == ',')
9412 dprintf_args = skip_spaces (dprintf_args);
9414 if (*dprintf_args != '"')
9415 error (_("Bad format string, missing '\"'."));
9417 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9418 printf_line = xstrprintf ("printf %s", dprintf_args);
9419 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9421 if (!dprintf_function)
9422 error (_("No function supplied for dprintf call"));
9424 if (dprintf_channel && strlen (dprintf_channel) > 0)
9425 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9430 printf_line = xstrprintf ("call (void) %s (%s)",
9434 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9436 if (target_can_run_breakpoint_commands ())
9437 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9440 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9441 printf_line = xstrprintf ("printf %s", dprintf_args);
9445 internal_error (__FILE__, __LINE__,
9446 _("Invalid dprintf style."));
9448 gdb_assert (printf_line != NULL);
9449 /* Manufacture a printf sequence. */
9451 struct command_line *printf_cmd_line
9452 = xmalloc (sizeof (struct command_line));
9454 printf_cmd_line = xmalloc (sizeof (struct command_line));
9455 printf_cmd_line->control_type = simple_control;
9456 printf_cmd_line->body_count = 0;
9457 printf_cmd_line->body_list = NULL;
9458 printf_cmd_line->next = NULL;
9459 printf_cmd_line->line = printf_line;
9461 breakpoint_set_commands (b, printf_cmd_line);
9465 /* Update all dprintf commands, making their command lists reflect
9466 current style settings. */
9469 update_dprintf_commands (char *args, int from_tty,
9470 struct cmd_list_element *c)
9472 struct breakpoint *b;
9476 if (b->type == bp_dprintf)
9477 update_dprintf_command_list (b);
9481 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9482 as textual description of the location, and COND_STRING
9483 as condition expression. */
9486 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9487 struct symtabs_and_lines sals, char *addr_string,
9488 char *filter, char *cond_string,
9490 enum bptype type, enum bpdisp disposition,
9491 int thread, int task, int ignore_count,
9492 const struct breakpoint_ops *ops, int from_tty,
9493 int enabled, int internal, unsigned flags,
9494 int display_canonical)
9498 if (type == bp_hardware_breakpoint)
9500 int target_resources_ok;
9502 i = hw_breakpoint_used_count ();
9503 target_resources_ok =
9504 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9506 if (target_resources_ok == 0)
9507 error (_("No hardware breakpoint support in the target."));
9508 else if (target_resources_ok < 0)
9509 error (_("Hardware breakpoints used exceeds limit."));
9512 gdb_assert (sals.nelts > 0);
9514 for (i = 0; i < sals.nelts; ++i)
9516 struct symtab_and_line sal = sals.sals[i];
9517 struct bp_location *loc;
9521 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9523 loc_gdbarch = gdbarch;
9525 describe_other_breakpoints (loc_gdbarch,
9526 sal.pspace, sal.pc, sal.section, thread);
9531 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9535 b->cond_string = cond_string;
9536 b->extra_string = extra_string;
9537 b->ignore_count = ignore_count;
9538 b->enable_state = enabled ? bp_enabled : bp_disabled;
9539 b->disposition = disposition;
9541 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9542 b->loc->inserted = 1;
9544 if (type == bp_static_tracepoint)
9546 struct tracepoint *t = (struct tracepoint *) b;
9547 struct static_tracepoint_marker marker;
9549 if (strace_marker_p (b))
9551 /* We already know the marker exists, otherwise, we
9552 wouldn't see a sal for it. */
9553 char *p = &addr_string[3];
9557 p = skip_spaces (p);
9559 endp = skip_to_space (p);
9561 marker_str = savestring (p, endp - p);
9562 t->static_trace_marker_id = marker_str;
9564 printf_filtered (_("Probed static tracepoint "
9566 t->static_trace_marker_id);
9568 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9570 t->static_trace_marker_id = xstrdup (marker.str_id);
9571 release_static_tracepoint_marker (&marker);
9573 printf_filtered (_("Probed static tracepoint "
9575 t->static_trace_marker_id);
9578 warning (_("Couldn't determine the static "
9579 "tracepoint marker to probe"));
9586 loc = add_location_to_breakpoint (b, &sal);
9587 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9593 const char *arg = b->cond_string;
9595 loc->cond = parse_exp_1 (&arg, loc->address,
9596 block_for_pc (loc->address), 0);
9598 error (_("Garbage '%s' follows condition"), arg);
9601 /* Dynamic printf requires and uses additional arguments on the
9602 command line, otherwise it's an error. */
9603 if (type == bp_dprintf)
9605 if (b->extra_string)
9606 update_dprintf_command_list (b);
9608 error (_("Format string required"));
9610 else if (b->extra_string)
9611 error (_("Garbage '%s' at end of command"), b->extra_string);
9614 b->display_canonical = display_canonical;
9616 b->addr_string = addr_string;
9618 /* addr_string has to be used or breakpoint_re_set will delete
9621 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9626 create_breakpoint_sal (struct gdbarch *gdbarch,
9627 struct symtabs_and_lines sals, char *addr_string,
9628 char *filter, char *cond_string,
9630 enum bptype type, enum bpdisp disposition,
9631 int thread, int task, int ignore_count,
9632 const struct breakpoint_ops *ops, int from_tty,
9633 int enabled, int internal, unsigned flags,
9634 int display_canonical)
9636 struct breakpoint *b;
9637 struct cleanup *old_chain;
9639 if (is_tracepoint_type (type))
9641 struct tracepoint *t;
9643 t = XCNEW (struct tracepoint);
9647 b = XNEW (struct breakpoint);
9649 old_chain = make_cleanup (xfree, b);
9651 init_breakpoint_sal (b, gdbarch,
9653 filter, cond_string, extra_string,
9655 thread, task, ignore_count,
9657 enabled, internal, flags,
9659 discard_cleanups (old_chain);
9661 install_breakpoint (internal, b, 0);
9664 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9665 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9666 value. COND_STRING, if not NULL, specified the condition to be
9667 used for all breakpoints. Essentially the only case where
9668 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9669 function. In that case, it's still not possible to specify
9670 separate conditions for different overloaded functions, so
9671 we take just a single condition string.
9673 NOTE: If the function succeeds, the caller is expected to cleanup
9674 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9675 array contents). If the function fails (error() is called), the
9676 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9677 COND and SALS arrays and each of those arrays contents. */
9680 create_breakpoints_sal (struct gdbarch *gdbarch,
9681 struct linespec_result *canonical,
9682 char *cond_string, char *extra_string,
9683 enum bptype type, enum bpdisp disposition,
9684 int thread, int task, int ignore_count,
9685 const struct breakpoint_ops *ops, int from_tty,
9686 int enabled, int internal, unsigned flags)
9689 struct linespec_sals *lsal;
9691 if (canonical->pre_expanded)
9692 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9694 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9696 /* Note that 'addr_string' can be NULL in the case of a plain
9697 'break', without arguments. */
9698 char *addr_string = (canonical->addr_string
9699 ? xstrdup (canonical->addr_string)
9701 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9702 struct cleanup *inner = make_cleanup (xfree, addr_string);
9704 make_cleanup (xfree, filter_string);
9705 create_breakpoint_sal (gdbarch, lsal->sals,
9708 cond_string, extra_string,
9710 thread, task, ignore_count, ops,
9711 from_tty, enabled, internal, flags,
9712 canonical->special_display);
9713 discard_cleanups (inner);
9717 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9718 followed by conditionals. On return, SALS contains an array of SAL
9719 addresses found. ADDR_STRING contains a vector of (canonical)
9720 address strings. ADDRESS points to the end of the SAL.
9722 The array and the line spec strings are allocated on the heap, it is
9723 the caller's responsibility to free them. */
9726 parse_breakpoint_sals (char **address,
9727 struct linespec_result *canonical)
9729 /* If no arg given, or if first arg is 'if ', use the default
9731 if ((*address) == NULL
9732 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9734 /* The last displayed codepoint, if it's valid, is our default breakpoint
9736 if (last_displayed_sal_is_valid ())
9738 struct linespec_sals lsal;
9739 struct symtab_and_line sal;
9742 init_sal (&sal); /* Initialize to zeroes. */
9743 lsal.sals.sals = (struct symtab_and_line *)
9744 xmalloc (sizeof (struct symtab_and_line));
9746 /* Set sal's pspace, pc, symtab, and line to the values
9747 corresponding to the last call to print_frame_info.
9748 Be sure to reinitialize LINE with NOTCURRENT == 0
9749 as the breakpoint line number is inappropriate otherwise.
9750 find_pc_line would adjust PC, re-set it back. */
9751 get_last_displayed_sal (&sal);
9753 sal = find_pc_line (pc, 0);
9755 /* "break" without arguments is equivalent to "break *PC"
9756 where PC is the last displayed codepoint's address. So
9757 make sure to set sal.explicit_pc to prevent GDB from
9758 trying to expand the list of sals to include all other
9759 instances with the same symtab and line. */
9761 sal.explicit_pc = 1;
9763 lsal.sals.sals[0] = sal;
9764 lsal.sals.nelts = 1;
9765 lsal.canonical = NULL;
9767 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9770 error (_("No default breakpoint address now."));
9774 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9776 /* Force almost all breakpoints to be in terms of the
9777 current_source_symtab (which is decode_line_1's default).
9778 This should produce the results we want almost all of the
9779 time while leaving default_breakpoint_* alone.
9781 ObjC: However, don't match an Objective-C method name which
9782 may have a '+' or '-' succeeded by a '['. */
9783 if (last_displayed_sal_is_valid ()
9785 || ((strchr ("+-", (*address)[0]) != NULL)
9786 && ((*address)[1] != '['))))
9787 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9788 get_last_displayed_symtab (),
9789 get_last_displayed_line (),
9790 canonical, NULL, NULL);
9792 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9793 cursal.symtab, cursal.line, canonical, NULL, NULL);
9798 /* Convert each SAL into a real PC. Verify that the PC can be
9799 inserted as a breakpoint. If it can't throw an error. */
9802 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9806 for (i = 0; i < sals->nelts; i++)
9807 resolve_sal_pc (&sals->sals[i]);
9810 /* Fast tracepoints may have restrictions on valid locations. For
9811 instance, a fast tracepoint using a jump instead of a trap will
9812 likely have to overwrite more bytes than a trap would, and so can
9813 only be placed where the instruction is longer than the jump, or a
9814 multi-instruction sequence does not have a jump into the middle of
9818 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9819 struct symtabs_and_lines *sals)
9822 struct symtab_and_line *sal;
9824 struct cleanup *old_chain;
9826 for (i = 0; i < sals->nelts; i++)
9828 struct gdbarch *sarch;
9830 sal = &sals->sals[i];
9832 sarch = get_sal_arch (*sal);
9833 /* We fall back to GDBARCH if there is no architecture
9834 associated with SAL. */
9837 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9839 old_chain = make_cleanup (xfree, msg);
9842 error (_("May not have a fast tracepoint at 0x%s%s"),
9843 paddress (sarch, sal->pc), (msg ? msg : ""));
9845 do_cleanups (old_chain);
9849 /* Issue an invalid thread ID error. */
9851 static void ATTRIBUTE_NORETURN
9852 invalid_thread_id_error (int id)
9854 error (_("Unknown thread %d."), id);
9857 /* Given TOK, a string specification of condition and thread, as
9858 accepted by the 'break' command, extract the condition
9859 string and thread number and set *COND_STRING and *THREAD.
9860 PC identifies the context at which the condition should be parsed.
9861 If no condition is found, *COND_STRING is set to NULL.
9862 If no thread is found, *THREAD is set to -1. */
9865 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9866 char **cond_string, int *thread, int *task,
9869 *cond_string = NULL;
9876 const char *end_tok;
9878 const char *cond_start = NULL;
9879 const char *cond_end = NULL;
9881 tok = skip_spaces_const (tok);
9883 if ((*tok == '"' || *tok == ',') && rest)
9885 *rest = savestring (tok, strlen (tok));
9889 end_tok = skip_to_space_const (tok);
9891 toklen = end_tok - tok;
9893 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9895 struct expression *expr;
9897 tok = cond_start = end_tok + 1;
9898 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9901 *cond_string = savestring (cond_start, cond_end - cond_start);
9903 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9908 *thread = strtol (tok, &tmptok, 0);
9910 error (_("Junk after thread keyword."));
9911 if (!valid_thread_id (*thread))
9912 invalid_thread_id_error (*thread);
9915 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9920 *task = strtol (tok, &tmptok, 0);
9922 error (_("Junk after task keyword."));
9923 if (!valid_task_id (*task))
9924 error (_("Unknown task %d."), *task);
9929 *rest = savestring (tok, strlen (tok));
9933 error (_("Junk at end of arguments."));
9937 /* Decode a static tracepoint marker spec. */
9939 static struct symtabs_and_lines
9940 decode_static_tracepoint_spec (char **arg_p)
9942 VEC(static_tracepoint_marker_p) *markers = NULL;
9943 struct symtabs_and_lines sals;
9944 struct cleanup *old_chain;
9945 char *p = &(*arg_p)[3];
9950 p = skip_spaces (p);
9952 endp = skip_to_space (p);
9954 marker_str = savestring (p, endp - p);
9955 old_chain = make_cleanup (xfree, marker_str);
9957 markers = target_static_tracepoint_markers_by_strid (marker_str);
9958 if (VEC_empty(static_tracepoint_marker_p, markers))
9959 error (_("No known static tracepoint marker named %s"), marker_str);
9961 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9962 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9964 for (i = 0; i < sals.nelts; i++)
9966 struct static_tracepoint_marker *marker;
9968 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9970 init_sal (&sals.sals[i]);
9972 sals.sals[i] = find_pc_line (marker->address, 0);
9973 sals.sals[i].pc = marker->address;
9975 release_static_tracepoint_marker (marker);
9978 do_cleanups (old_chain);
9984 /* Set a breakpoint. This function is shared between CLI and MI
9985 functions for setting a breakpoint. This function has two major
9986 modes of operations, selected by the PARSE_ARG parameter. If
9987 non-zero, the function will parse ARG, extracting location,
9988 condition, thread and extra string. Otherwise, ARG is just the
9989 breakpoint's location, with condition, thread, and extra string
9990 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9991 If INTERNAL is non-zero, the breakpoint number will be allocated
9992 from the internal breakpoint count. Returns true if any breakpoint
9993 was created; false otherwise. */
9996 create_breakpoint (struct gdbarch *gdbarch,
9997 char *arg, char *cond_string,
9998 int thread, char *extra_string,
10000 int tempflag, enum bptype type_wanted,
10002 enum auto_boolean pending_break_support,
10003 const struct breakpoint_ops *ops,
10004 int from_tty, int enabled, int internal,
10007 volatile struct gdb_exception e;
10008 char *copy_arg = NULL;
10009 char *addr_start = arg;
10010 struct linespec_result canonical;
10011 struct cleanup *old_chain;
10012 struct cleanup *bkpt_chain = NULL;
10015 int prev_bkpt_count = breakpoint_count;
10017 gdb_assert (ops != NULL);
10019 init_linespec_result (&canonical);
10021 TRY_CATCH (e, RETURN_MASK_ALL)
10023 ops->create_sals_from_address (&arg, &canonical, type_wanted,
10024 addr_start, ©_arg);
10027 /* If caller is interested in rc value from parse, set value. */
10031 if (VEC_empty (linespec_sals, canonical.sals))
10037 case NOT_FOUND_ERROR:
10039 /* If pending breakpoint support is turned off, throw
10042 if (pending_break_support == AUTO_BOOLEAN_FALSE)
10043 throw_exception (e);
10045 exception_print (gdb_stderr, e);
10047 /* If pending breakpoint support is auto query and the user
10048 selects no, then simply return the error code. */
10049 if (pending_break_support == AUTO_BOOLEAN_AUTO
10050 && !nquery (_("Make %s pending on future shared library load? "),
10051 bptype_string (type_wanted)))
10054 /* At this point, either the user was queried about setting
10055 a pending breakpoint and selected yes, or pending
10056 breakpoint behavior is on and thus a pending breakpoint
10057 is defaulted on behalf of the user. */
10059 struct linespec_sals lsal;
10061 copy_arg = xstrdup (addr_start);
10062 lsal.canonical = xstrdup (copy_arg);
10063 lsal.sals.nelts = 1;
10064 lsal.sals.sals = XNEW (struct symtab_and_line);
10065 init_sal (&lsal.sals.sals[0]);
10067 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
10071 throw_exception (e);
10075 throw_exception (e);
10078 /* Create a chain of things that always need to be cleaned up. */
10079 old_chain = make_cleanup_destroy_linespec_result (&canonical);
10081 /* ----------------------------- SNIP -----------------------------
10082 Anything added to the cleanup chain beyond this point is assumed
10083 to be part of a breakpoint. If the breakpoint create succeeds
10084 then the memory is not reclaimed. */
10085 bkpt_chain = make_cleanup (null_cleanup, 0);
10087 /* Resolve all line numbers to PC's and verify that the addresses
10088 are ok for the target. */
10092 struct linespec_sals *iter;
10094 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10095 breakpoint_sals_to_pc (&iter->sals);
10098 /* Fast tracepoints may have additional restrictions on location. */
10099 if (!pending && type_wanted == bp_fast_tracepoint)
10102 struct linespec_sals *iter;
10104 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10105 check_fast_tracepoint_sals (gdbarch, &iter->sals);
10108 /* Verify that condition can be parsed, before setting any
10109 breakpoints. Allocate a separate condition expression for each
10116 struct linespec_sals *lsal;
10118 lsal = VEC_index (linespec_sals, canonical.sals, 0);
10120 /* Here we only parse 'arg' to separate condition
10121 from thread number, so parsing in context of first
10122 sal is OK. When setting the breakpoint we'll
10123 re-parse it in context of each sal. */
10125 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
10126 &thread, &task, &rest);
10128 make_cleanup (xfree, cond_string);
10130 make_cleanup (xfree, rest);
10132 extra_string = rest;
10137 error (_("Garbage '%s' at end of location"), arg);
10139 /* Create a private copy of condition string. */
10142 cond_string = xstrdup (cond_string);
10143 make_cleanup (xfree, cond_string);
10145 /* Create a private copy of any extra string. */
10148 extra_string = xstrdup (extra_string);
10149 make_cleanup (xfree, extra_string);
10153 ops->create_breakpoints_sal (gdbarch, &canonical,
10154 cond_string, extra_string, type_wanted,
10155 tempflag ? disp_del : disp_donttouch,
10156 thread, task, ignore_count, ops,
10157 from_tty, enabled, internal, flags);
10161 struct breakpoint *b;
10163 make_cleanup (xfree, copy_arg);
10165 if (is_tracepoint_type (type_wanted))
10167 struct tracepoint *t;
10169 t = XCNEW (struct tracepoint);
10173 b = XNEW (struct breakpoint);
10175 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
10177 b->addr_string = copy_arg;
10179 b->cond_string = NULL;
10182 /* Create a private copy of condition string. */
10185 cond_string = xstrdup (cond_string);
10186 make_cleanup (xfree, cond_string);
10188 b->cond_string = cond_string;
10190 b->extra_string = NULL;
10191 b->ignore_count = ignore_count;
10192 b->disposition = tempflag ? disp_del : disp_donttouch;
10193 b->condition_not_parsed = 1;
10194 b->enable_state = enabled ? bp_enabled : bp_disabled;
10195 if ((type_wanted != bp_breakpoint
10196 && type_wanted != bp_hardware_breakpoint) || thread != -1)
10197 b->pspace = current_program_space;
10199 install_breakpoint (internal, b, 0);
10202 if (VEC_length (linespec_sals, canonical.sals) > 1)
10204 warning (_("Multiple breakpoints were set.\nUse the "
10205 "\"delete\" command to delete unwanted breakpoints."));
10206 prev_breakpoint_count = prev_bkpt_count;
10209 /* That's it. Discard the cleanups for data inserted into the
10211 discard_cleanups (bkpt_chain);
10212 /* But cleanup everything else. */
10213 do_cleanups (old_chain);
10215 /* error call may happen here - have BKPT_CHAIN already discarded. */
10216 update_global_location_list (UGLL_MAY_INSERT);
10221 /* Set a breakpoint.
10222 ARG is a string describing breakpoint address,
10223 condition, and thread.
10224 FLAG specifies if a breakpoint is hardware on,
10225 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10226 and BP_TEMPFLAG. */
10229 break_command_1 (char *arg, int flag, int from_tty)
10231 int tempflag = flag & BP_TEMPFLAG;
10232 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
10233 ? bp_hardware_breakpoint
10235 struct breakpoint_ops *ops;
10236 const char *arg_cp = arg;
10238 /* Matching breakpoints on probes. */
10239 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
10240 ops = &bkpt_probe_breakpoint_ops;
10242 ops = &bkpt_breakpoint_ops;
10244 create_breakpoint (get_current_arch (),
10246 NULL, 0, NULL, 1 /* parse arg */,
10247 tempflag, type_wanted,
10248 0 /* Ignore count */,
10249 pending_break_support,
10257 /* Helper function for break_command_1 and disassemble_command. */
10260 resolve_sal_pc (struct symtab_and_line *sal)
10264 if (sal->pc == 0 && sal->symtab != NULL)
10266 if (!find_line_pc (sal->symtab, sal->line, &pc))
10267 error (_("No line %d in file \"%s\"."),
10268 sal->line, symtab_to_filename_for_display (sal->symtab));
10271 /* If this SAL corresponds to a breakpoint inserted using a line
10272 number, then skip the function prologue if necessary. */
10273 if (sal->explicit_line)
10274 skip_prologue_sal (sal);
10277 if (sal->section == 0 && sal->symtab != NULL)
10279 const struct blockvector *bv;
10280 const struct block *b;
10281 struct symbol *sym;
10283 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
10284 SYMTAB_COMPUNIT (sal->symtab));
10287 sym = block_linkage_function (b);
10290 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
10291 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
10296 /* It really is worthwhile to have the section, so we'll
10297 just have to look harder. This case can be executed
10298 if we have line numbers but no functions (as can
10299 happen in assembly source). */
10301 struct bound_minimal_symbol msym;
10302 struct cleanup *old_chain = save_current_space_and_thread ();
10304 switch_to_program_space_and_thread (sal->pspace);
10306 msym = lookup_minimal_symbol_by_pc (sal->pc);
10308 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10310 do_cleanups (old_chain);
10317 break_command (char *arg, int from_tty)
10319 break_command_1 (arg, 0, from_tty);
10323 tbreak_command (char *arg, int from_tty)
10325 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10329 hbreak_command (char *arg, int from_tty)
10331 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10335 thbreak_command (char *arg, int from_tty)
10337 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10341 stop_command (char *arg, int from_tty)
10343 printf_filtered (_("Specify the type of breakpoint to set.\n\
10344 Usage: stop in <function | address>\n\
10345 stop at <line>\n"));
10349 stopin_command (char *arg, int from_tty)
10353 if (arg == (char *) NULL)
10355 else if (*arg != '*')
10357 char *argptr = arg;
10360 /* Look for a ':'. If this is a line number specification, then
10361 say it is bad, otherwise, it should be an address or
10362 function/method name. */
10363 while (*argptr && !hasColon)
10365 hasColon = (*argptr == ':');
10370 badInput = (*argptr != ':'); /* Not a class::method */
10372 badInput = isdigit (*arg); /* a simple line number */
10376 printf_filtered (_("Usage: stop in <function | address>\n"));
10378 break_command_1 (arg, 0, from_tty);
10382 stopat_command (char *arg, int from_tty)
10386 if (arg == (char *) NULL || *arg == '*') /* no line number */
10390 char *argptr = arg;
10393 /* Look for a ':'. If there is a '::' then get out, otherwise
10394 it is probably a line number. */
10395 while (*argptr && !hasColon)
10397 hasColon = (*argptr == ':');
10402 badInput = (*argptr == ':'); /* we have class::method */
10404 badInput = !isdigit (*arg); /* not a line number */
10408 printf_filtered (_("Usage: stop at <line>\n"));
10410 break_command_1 (arg, 0, from_tty);
10413 /* The dynamic printf command is mostly like a regular breakpoint, but
10414 with a prewired command list consisting of a single output command,
10415 built from extra arguments supplied on the dprintf command
10419 dprintf_command (char *arg, int from_tty)
10421 create_breakpoint (get_current_arch (),
10423 NULL, 0, NULL, 1 /* parse arg */,
10425 0 /* Ignore count */,
10426 pending_break_support,
10427 &dprintf_breakpoint_ops,
10435 agent_printf_command (char *arg, int from_tty)
10437 error (_("May only run agent-printf on the target"));
10440 /* Implement the "breakpoint_hit" breakpoint_ops method for
10441 ranged breakpoints. */
10444 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10445 struct address_space *aspace,
10447 const struct target_waitstatus *ws)
10449 if (ws->kind != TARGET_WAITKIND_STOPPED
10450 || ws->value.sig != GDB_SIGNAL_TRAP)
10453 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10454 bl->length, aspace, bp_addr);
10457 /* Implement the "resources_needed" breakpoint_ops method for
10458 ranged breakpoints. */
10461 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10463 return target_ranged_break_num_registers ();
10466 /* Implement the "print_it" breakpoint_ops method for
10467 ranged breakpoints. */
10469 static enum print_stop_action
10470 print_it_ranged_breakpoint (bpstat bs)
10472 struct breakpoint *b = bs->breakpoint_at;
10473 struct bp_location *bl = b->loc;
10474 struct ui_out *uiout = current_uiout;
10476 gdb_assert (b->type == bp_hardware_breakpoint);
10478 /* Ranged breakpoints have only one location. */
10479 gdb_assert (bl && bl->next == NULL);
10481 annotate_breakpoint (b->number);
10482 if (b->disposition == disp_del)
10483 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10485 ui_out_text (uiout, "\nRanged breakpoint ");
10486 if (ui_out_is_mi_like_p (uiout))
10488 ui_out_field_string (uiout, "reason",
10489 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10490 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10492 ui_out_field_int (uiout, "bkptno", b->number);
10493 ui_out_text (uiout, ", ");
10495 return PRINT_SRC_AND_LOC;
10498 /* Implement the "print_one" breakpoint_ops method for
10499 ranged breakpoints. */
10502 print_one_ranged_breakpoint (struct breakpoint *b,
10503 struct bp_location **last_loc)
10505 struct bp_location *bl = b->loc;
10506 struct value_print_options opts;
10507 struct ui_out *uiout = current_uiout;
10509 /* Ranged breakpoints have only one location. */
10510 gdb_assert (bl && bl->next == NULL);
10512 get_user_print_options (&opts);
10514 if (opts.addressprint)
10515 /* We don't print the address range here, it will be printed later
10516 by print_one_detail_ranged_breakpoint. */
10517 ui_out_field_skip (uiout, "addr");
10518 annotate_field (5);
10519 print_breakpoint_location (b, bl);
10523 /* Implement the "print_one_detail" breakpoint_ops method for
10524 ranged breakpoints. */
10527 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10528 struct ui_out *uiout)
10530 CORE_ADDR address_start, address_end;
10531 struct bp_location *bl = b->loc;
10532 struct ui_file *stb = mem_fileopen ();
10533 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10537 address_start = bl->address;
10538 address_end = address_start + bl->length - 1;
10540 ui_out_text (uiout, "\taddress range: ");
10541 fprintf_unfiltered (stb, "[%s, %s]",
10542 print_core_address (bl->gdbarch, address_start),
10543 print_core_address (bl->gdbarch, address_end));
10544 ui_out_field_stream (uiout, "addr", stb);
10545 ui_out_text (uiout, "\n");
10547 do_cleanups (cleanup);
10550 /* Implement the "print_mention" breakpoint_ops method for
10551 ranged breakpoints. */
10554 print_mention_ranged_breakpoint (struct breakpoint *b)
10556 struct bp_location *bl = b->loc;
10557 struct ui_out *uiout = current_uiout;
10560 gdb_assert (b->type == bp_hardware_breakpoint);
10562 if (ui_out_is_mi_like_p (uiout))
10565 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10566 b->number, paddress (bl->gdbarch, bl->address),
10567 paddress (bl->gdbarch, bl->address + bl->length - 1));
10570 /* Implement the "print_recreate" breakpoint_ops method for
10571 ranged breakpoints. */
10574 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10576 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10577 b->addr_string_range_end);
10578 print_recreate_thread (b, fp);
10581 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10583 static struct breakpoint_ops ranged_breakpoint_ops;
10585 /* Find the address where the end of the breakpoint range should be
10586 placed, given the SAL of the end of the range. This is so that if
10587 the user provides a line number, the end of the range is set to the
10588 last instruction of the given line. */
10591 find_breakpoint_range_end (struct symtab_and_line sal)
10595 /* If the user provided a PC value, use it. Otherwise,
10596 find the address of the end of the given location. */
10597 if (sal.explicit_pc)
10604 ret = find_line_pc_range (sal, &start, &end);
10606 error (_("Could not find location of the end of the range."));
10608 /* find_line_pc_range returns the start of the next line. */
10615 /* Implement the "break-range" CLI command. */
10618 break_range_command (char *arg, int from_tty)
10620 char *arg_start, *addr_string_start, *addr_string_end;
10621 struct linespec_result canonical_start, canonical_end;
10622 int bp_count, can_use_bp, length;
10624 struct breakpoint *b;
10625 struct symtab_and_line sal_start, sal_end;
10626 struct cleanup *cleanup_bkpt;
10627 struct linespec_sals *lsal_start, *lsal_end;
10629 /* We don't support software ranged breakpoints. */
10630 if (target_ranged_break_num_registers () < 0)
10631 error (_("This target does not support hardware ranged breakpoints."));
10633 bp_count = hw_breakpoint_used_count ();
10634 bp_count += target_ranged_break_num_registers ();
10635 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10637 if (can_use_bp < 0)
10638 error (_("Hardware breakpoints used exceeds limit."));
10640 arg = skip_spaces (arg);
10641 if (arg == NULL || arg[0] == '\0')
10642 error(_("No address range specified."));
10644 init_linespec_result (&canonical_start);
10647 parse_breakpoint_sals (&arg, &canonical_start);
10649 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10652 error (_("Too few arguments."));
10653 else if (VEC_empty (linespec_sals, canonical_start.sals))
10654 error (_("Could not find location of the beginning of the range."));
10656 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10658 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10659 || lsal_start->sals.nelts != 1)
10660 error (_("Cannot create a ranged breakpoint with multiple locations."));
10662 sal_start = lsal_start->sals.sals[0];
10663 addr_string_start = savestring (arg_start, arg - arg_start);
10664 make_cleanup (xfree, addr_string_start);
10666 arg++; /* Skip the comma. */
10667 arg = skip_spaces (arg);
10669 /* Parse the end location. */
10671 init_linespec_result (&canonical_end);
10674 /* We call decode_line_full directly here instead of using
10675 parse_breakpoint_sals because we need to specify the start location's
10676 symtab and line as the default symtab and line for the end of the
10677 range. This makes it possible to have ranges like "foo.c:27, +14",
10678 where +14 means 14 lines from the start location. */
10679 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10680 sal_start.symtab, sal_start.line,
10681 &canonical_end, NULL, NULL);
10683 make_cleanup_destroy_linespec_result (&canonical_end);
10685 if (VEC_empty (linespec_sals, canonical_end.sals))
10686 error (_("Could not find location of the end of the range."));
10688 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10689 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10690 || lsal_end->sals.nelts != 1)
10691 error (_("Cannot create a ranged breakpoint with multiple locations."));
10693 sal_end = lsal_end->sals.sals[0];
10694 addr_string_end = savestring (arg_start, arg - arg_start);
10695 make_cleanup (xfree, addr_string_end);
10697 end = find_breakpoint_range_end (sal_end);
10698 if (sal_start.pc > end)
10699 error (_("Invalid address range, end precedes start."));
10701 length = end - sal_start.pc + 1;
10703 /* Length overflowed. */
10704 error (_("Address range too large."));
10705 else if (length == 1)
10707 /* This range is simple enough to be handled by
10708 the `hbreak' command. */
10709 hbreak_command (addr_string_start, 1);
10711 do_cleanups (cleanup_bkpt);
10716 /* Now set up the breakpoint. */
10717 b = set_raw_breakpoint (get_current_arch (), sal_start,
10718 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10719 set_breakpoint_count (breakpoint_count + 1);
10720 b->number = breakpoint_count;
10721 b->disposition = disp_donttouch;
10722 b->addr_string = xstrdup (addr_string_start);
10723 b->addr_string_range_end = xstrdup (addr_string_end);
10724 b->loc->length = length;
10726 do_cleanups (cleanup_bkpt);
10729 observer_notify_breakpoint_created (b);
10730 update_global_location_list (UGLL_MAY_INSERT);
10733 /* Return non-zero if EXP is verified as constant. Returned zero
10734 means EXP is variable. Also the constant detection may fail for
10735 some constant expressions and in such case still falsely return
10739 watchpoint_exp_is_const (const struct expression *exp)
10741 int i = exp->nelts;
10747 /* We are only interested in the descriptor of each element. */
10748 operator_length (exp, i, &oplenp, &argsp);
10751 switch (exp->elts[i].opcode)
10761 case BINOP_LOGICAL_AND:
10762 case BINOP_LOGICAL_OR:
10763 case BINOP_BITWISE_AND:
10764 case BINOP_BITWISE_IOR:
10765 case BINOP_BITWISE_XOR:
10767 case BINOP_NOTEQUAL:
10794 case OP_OBJC_NSSTRING:
10797 case UNOP_LOGICAL_NOT:
10798 case UNOP_COMPLEMENT:
10803 case UNOP_CAST_TYPE:
10804 case UNOP_REINTERPRET_CAST:
10805 case UNOP_DYNAMIC_CAST:
10806 /* Unary, binary and ternary operators: We have to check
10807 their operands. If they are constant, then so is the
10808 result of that operation. For instance, if A and B are
10809 determined to be constants, then so is "A + B".
10811 UNOP_IND is one exception to the rule above, because the
10812 value of *ADDR is not necessarily a constant, even when
10817 /* Check whether the associated symbol is a constant.
10819 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10820 possible that a buggy compiler could mark a variable as
10821 constant even when it is not, and TYPE_CONST would return
10822 true in this case, while SYMBOL_CLASS wouldn't.
10824 We also have to check for function symbols because they
10825 are always constant. */
10827 struct symbol *s = exp->elts[i + 2].symbol;
10829 if (SYMBOL_CLASS (s) != LOC_BLOCK
10830 && SYMBOL_CLASS (s) != LOC_CONST
10831 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10836 /* The default action is to return 0 because we are using
10837 the optimistic approach here: If we don't know something,
10838 then it is not a constant. */
10847 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10850 dtor_watchpoint (struct breakpoint *self)
10852 struct watchpoint *w = (struct watchpoint *) self;
10854 xfree (w->cond_exp);
10856 xfree (w->exp_string);
10857 xfree (w->exp_string_reparse);
10858 value_free (w->val);
10860 base_breakpoint_ops.dtor (self);
10863 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10866 re_set_watchpoint (struct breakpoint *b)
10868 struct watchpoint *w = (struct watchpoint *) b;
10870 /* Watchpoint can be either on expression using entirely global
10871 variables, or it can be on local variables.
10873 Watchpoints of the first kind are never auto-deleted, and even
10874 persist across program restarts. Since they can use variables
10875 from shared libraries, we need to reparse expression as libraries
10876 are loaded and unloaded.
10878 Watchpoints on local variables can also change meaning as result
10879 of solib event. For example, if a watchpoint uses both a local
10880 and a global variables in expression, it's a local watchpoint,
10881 but unloading of a shared library will make the expression
10882 invalid. This is not a very common use case, but we still
10883 re-evaluate expression, to avoid surprises to the user.
10885 Note that for local watchpoints, we re-evaluate it only if
10886 watchpoints frame id is still valid. If it's not, it means the
10887 watchpoint is out of scope and will be deleted soon. In fact,
10888 I'm not sure we'll ever be called in this case.
10890 If a local watchpoint's frame id is still valid, then
10891 w->exp_valid_block is likewise valid, and we can safely use it.
10893 Don't do anything about disabled watchpoints, since they will be
10894 reevaluated again when enabled. */
10895 update_watchpoint (w, 1 /* reparse */);
10898 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10901 insert_watchpoint (struct bp_location *bl)
10903 struct watchpoint *w = (struct watchpoint *) bl->owner;
10904 int length = w->exact ? 1 : bl->length;
10906 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10910 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10913 remove_watchpoint (struct bp_location *bl)
10915 struct watchpoint *w = (struct watchpoint *) bl->owner;
10916 int length = w->exact ? 1 : bl->length;
10918 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10923 breakpoint_hit_watchpoint (const struct bp_location *bl,
10924 struct address_space *aspace, CORE_ADDR bp_addr,
10925 const struct target_waitstatus *ws)
10927 struct breakpoint *b = bl->owner;
10928 struct watchpoint *w = (struct watchpoint *) b;
10930 /* Continuable hardware watchpoints are treated as non-existent if the
10931 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10932 some data address). Otherwise gdb won't stop on a break instruction
10933 in the code (not from a breakpoint) when a hardware watchpoint has
10934 been defined. Also skip watchpoints which we know did not trigger
10935 (did not match the data address). */
10936 if (is_hardware_watchpoint (b)
10937 && w->watchpoint_triggered == watch_triggered_no)
10944 check_status_watchpoint (bpstat bs)
10946 gdb_assert (is_watchpoint (bs->breakpoint_at));
10948 bpstat_check_watchpoint (bs);
10951 /* Implement the "resources_needed" breakpoint_ops method for
10952 hardware watchpoints. */
10955 resources_needed_watchpoint (const struct bp_location *bl)
10957 struct watchpoint *w = (struct watchpoint *) bl->owner;
10958 int length = w->exact? 1 : bl->length;
10960 return target_region_ok_for_hw_watchpoint (bl->address, length);
10963 /* Implement the "works_in_software_mode" breakpoint_ops method for
10964 hardware watchpoints. */
10967 works_in_software_mode_watchpoint (const struct breakpoint *b)
10969 /* Read and access watchpoints only work with hardware support. */
10970 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10973 static enum print_stop_action
10974 print_it_watchpoint (bpstat bs)
10976 struct cleanup *old_chain;
10977 struct breakpoint *b;
10978 struct ui_file *stb;
10979 enum print_stop_action result;
10980 struct watchpoint *w;
10981 struct ui_out *uiout = current_uiout;
10983 gdb_assert (bs->bp_location_at != NULL);
10985 b = bs->breakpoint_at;
10986 w = (struct watchpoint *) b;
10988 stb = mem_fileopen ();
10989 old_chain = make_cleanup_ui_file_delete (stb);
10993 case bp_watchpoint:
10994 case bp_hardware_watchpoint:
10995 annotate_watchpoint (b->number);
10996 if (ui_out_is_mi_like_p (uiout))
10997 ui_out_field_string
10999 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11001 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11002 ui_out_text (uiout, "\nOld value = ");
11003 watchpoint_value_print (bs->old_val, stb);
11004 ui_out_field_stream (uiout, "old", stb);
11005 ui_out_text (uiout, "\nNew value = ");
11006 watchpoint_value_print (w->val, stb);
11007 ui_out_field_stream (uiout, "new", stb);
11008 ui_out_text (uiout, "\n");
11009 /* More than one watchpoint may have been triggered. */
11010 result = PRINT_UNKNOWN;
11013 case bp_read_watchpoint:
11014 if (ui_out_is_mi_like_p (uiout))
11015 ui_out_field_string
11017 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11019 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11020 ui_out_text (uiout, "\nValue = ");
11021 watchpoint_value_print (w->val, stb);
11022 ui_out_field_stream (uiout, "value", stb);
11023 ui_out_text (uiout, "\n");
11024 result = PRINT_UNKNOWN;
11027 case bp_access_watchpoint:
11028 if (bs->old_val != NULL)
11030 annotate_watchpoint (b->number);
11031 if (ui_out_is_mi_like_p (uiout))
11032 ui_out_field_string
11034 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11036 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11037 ui_out_text (uiout, "\nOld value = ");
11038 watchpoint_value_print (bs->old_val, stb);
11039 ui_out_field_stream (uiout, "old", stb);
11040 ui_out_text (uiout, "\nNew value = ");
11045 if (ui_out_is_mi_like_p (uiout))
11046 ui_out_field_string
11048 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11049 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11050 ui_out_text (uiout, "\nValue = ");
11052 watchpoint_value_print (w->val, stb);
11053 ui_out_field_stream (uiout, "new", stb);
11054 ui_out_text (uiout, "\n");
11055 result = PRINT_UNKNOWN;
11058 result = PRINT_UNKNOWN;
11061 do_cleanups (old_chain);
11065 /* Implement the "print_mention" breakpoint_ops method for hardware
11069 print_mention_watchpoint (struct breakpoint *b)
11071 struct cleanup *ui_out_chain;
11072 struct watchpoint *w = (struct watchpoint *) b;
11073 struct ui_out *uiout = current_uiout;
11077 case bp_watchpoint:
11078 ui_out_text (uiout, "Watchpoint ");
11079 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11081 case bp_hardware_watchpoint:
11082 ui_out_text (uiout, "Hardware watchpoint ");
11083 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11085 case bp_read_watchpoint:
11086 ui_out_text (uiout, "Hardware read watchpoint ");
11087 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11089 case bp_access_watchpoint:
11090 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
11091 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11094 internal_error (__FILE__, __LINE__,
11095 _("Invalid hardware watchpoint type."));
11098 ui_out_field_int (uiout, "number", b->number);
11099 ui_out_text (uiout, ": ");
11100 ui_out_field_string (uiout, "exp", w->exp_string);
11101 do_cleanups (ui_out_chain);
11104 /* Implement the "print_recreate" breakpoint_ops method for
11108 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
11110 struct watchpoint *w = (struct watchpoint *) b;
11114 case bp_watchpoint:
11115 case bp_hardware_watchpoint:
11116 fprintf_unfiltered (fp, "watch");
11118 case bp_read_watchpoint:
11119 fprintf_unfiltered (fp, "rwatch");
11121 case bp_access_watchpoint:
11122 fprintf_unfiltered (fp, "awatch");
11125 internal_error (__FILE__, __LINE__,
11126 _("Invalid watchpoint type."));
11129 fprintf_unfiltered (fp, " %s", w->exp_string);
11130 print_recreate_thread (b, fp);
11133 /* Implement the "explains_signal" breakpoint_ops method for
11137 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
11139 /* A software watchpoint cannot cause a signal other than
11140 GDB_SIGNAL_TRAP. */
11141 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
11147 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11149 static struct breakpoint_ops watchpoint_breakpoint_ops;
11151 /* Implement the "insert" breakpoint_ops method for
11152 masked hardware watchpoints. */
11155 insert_masked_watchpoint (struct bp_location *bl)
11157 struct watchpoint *w = (struct watchpoint *) bl->owner;
11159 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
11160 bl->watchpoint_type);
11163 /* Implement the "remove" breakpoint_ops method for
11164 masked hardware watchpoints. */
11167 remove_masked_watchpoint (struct bp_location *bl)
11169 struct watchpoint *w = (struct watchpoint *) bl->owner;
11171 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
11172 bl->watchpoint_type);
11175 /* Implement the "resources_needed" breakpoint_ops method for
11176 masked hardware watchpoints. */
11179 resources_needed_masked_watchpoint (const struct bp_location *bl)
11181 struct watchpoint *w = (struct watchpoint *) bl->owner;
11183 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
11186 /* Implement the "works_in_software_mode" breakpoint_ops method for
11187 masked hardware watchpoints. */
11190 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
11195 /* Implement the "print_it" breakpoint_ops method for
11196 masked hardware watchpoints. */
11198 static enum print_stop_action
11199 print_it_masked_watchpoint (bpstat bs)
11201 struct breakpoint *b = bs->breakpoint_at;
11202 struct ui_out *uiout = current_uiout;
11204 /* Masked watchpoints have only one location. */
11205 gdb_assert (b->loc && b->loc->next == NULL);
11209 case bp_hardware_watchpoint:
11210 annotate_watchpoint (b->number);
11211 if (ui_out_is_mi_like_p (uiout))
11212 ui_out_field_string
11214 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11217 case bp_read_watchpoint:
11218 if (ui_out_is_mi_like_p (uiout))
11219 ui_out_field_string
11221 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11224 case bp_access_watchpoint:
11225 if (ui_out_is_mi_like_p (uiout))
11226 ui_out_field_string
11228 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11231 internal_error (__FILE__, __LINE__,
11232 _("Invalid hardware watchpoint type."));
11236 ui_out_text (uiout, _("\n\
11237 Check the underlying instruction at PC for the memory\n\
11238 address and value which triggered this watchpoint.\n"));
11239 ui_out_text (uiout, "\n");
11241 /* More than one watchpoint may have been triggered. */
11242 return PRINT_UNKNOWN;
11245 /* Implement the "print_one_detail" breakpoint_ops method for
11246 masked hardware watchpoints. */
11249 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11250 struct ui_out *uiout)
11252 struct watchpoint *w = (struct watchpoint *) b;
11254 /* Masked watchpoints have only one location. */
11255 gdb_assert (b->loc && b->loc->next == NULL);
11257 ui_out_text (uiout, "\tmask ");
11258 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11259 ui_out_text (uiout, "\n");
11262 /* Implement the "print_mention" breakpoint_ops method for
11263 masked hardware watchpoints. */
11266 print_mention_masked_watchpoint (struct breakpoint *b)
11268 struct watchpoint *w = (struct watchpoint *) b;
11269 struct ui_out *uiout = current_uiout;
11270 struct cleanup *ui_out_chain;
11274 case bp_hardware_watchpoint:
11275 ui_out_text (uiout, "Masked hardware watchpoint ");
11276 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11278 case bp_read_watchpoint:
11279 ui_out_text (uiout, "Masked hardware read watchpoint ");
11280 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11282 case bp_access_watchpoint:
11283 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11284 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11287 internal_error (__FILE__, __LINE__,
11288 _("Invalid hardware watchpoint type."));
11291 ui_out_field_int (uiout, "number", b->number);
11292 ui_out_text (uiout, ": ");
11293 ui_out_field_string (uiout, "exp", w->exp_string);
11294 do_cleanups (ui_out_chain);
11297 /* Implement the "print_recreate" breakpoint_ops method for
11298 masked hardware watchpoints. */
11301 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11303 struct watchpoint *w = (struct watchpoint *) b;
11308 case bp_hardware_watchpoint:
11309 fprintf_unfiltered (fp, "watch");
11311 case bp_read_watchpoint:
11312 fprintf_unfiltered (fp, "rwatch");
11314 case bp_access_watchpoint:
11315 fprintf_unfiltered (fp, "awatch");
11318 internal_error (__FILE__, __LINE__,
11319 _("Invalid hardware watchpoint type."));
11322 sprintf_vma (tmp, w->hw_wp_mask);
11323 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11324 print_recreate_thread (b, fp);
11327 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11329 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11331 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11334 is_masked_watchpoint (const struct breakpoint *b)
11336 return b->ops == &masked_watchpoint_breakpoint_ops;
11339 /* accessflag: hw_write: watch write,
11340 hw_read: watch read,
11341 hw_access: watch access (read or write) */
11343 watch_command_1 (const char *arg, int accessflag, int from_tty,
11344 int just_location, int internal)
11346 volatile struct gdb_exception e;
11347 struct breakpoint *b, *scope_breakpoint = NULL;
11348 struct expression *exp;
11349 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11350 struct value *val, *mark, *result;
11351 int saved_bitpos = 0, saved_bitsize = 0;
11352 struct frame_info *frame;
11353 const char *exp_start = NULL;
11354 const char *exp_end = NULL;
11355 const char *tok, *end_tok;
11357 const char *cond_start = NULL;
11358 const char *cond_end = NULL;
11359 enum bptype bp_type;
11362 /* Flag to indicate whether we are going to use masks for
11363 the hardware watchpoint. */
11365 CORE_ADDR mask = 0;
11366 struct watchpoint *w;
11368 struct cleanup *back_to;
11370 /* Make sure that we actually have parameters to parse. */
11371 if (arg != NULL && arg[0] != '\0')
11373 const char *value_start;
11375 exp_end = arg + strlen (arg);
11377 /* Look for "parameter value" pairs at the end
11378 of the arguments string. */
11379 for (tok = exp_end - 1; tok > arg; tok--)
11381 /* Skip whitespace at the end of the argument list. */
11382 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11385 /* Find the beginning of the last token.
11386 This is the value of the parameter. */
11387 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11389 value_start = tok + 1;
11391 /* Skip whitespace. */
11392 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11397 /* Find the beginning of the second to last token.
11398 This is the parameter itself. */
11399 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11402 toklen = end_tok - tok + 1;
11404 if (toklen == 6 && !strncmp (tok, "thread", 6))
11406 /* At this point we've found a "thread" token, which means
11407 the user is trying to set a watchpoint that triggers
11408 only in a specific thread. */
11412 error(_("You can specify only one thread."));
11414 /* Extract the thread ID from the next token. */
11415 thread = strtol (value_start, &endp, 0);
11417 /* Check if the user provided a valid numeric value for the
11419 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11420 error (_("Invalid thread ID specification %s."), value_start);
11422 /* Check if the thread actually exists. */
11423 if (!valid_thread_id (thread))
11424 invalid_thread_id_error (thread);
11426 else if (toklen == 4 && !strncmp (tok, "mask", 4))
11428 /* We've found a "mask" token, which means the user wants to
11429 create a hardware watchpoint that is going to have the mask
11431 struct value *mask_value, *mark;
11434 error(_("You can specify only one mask."));
11436 use_mask = just_location = 1;
11438 mark = value_mark ();
11439 mask_value = parse_to_comma_and_eval (&value_start);
11440 mask = value_as_address (mask_value);
11441 value_free_to_mark (mark);
11444 /* We didn't recognize what we found. We should stop here. */
11447 /* Truncate the string and get rid of the "parameter value" pair before
11448 the arguments string is parsed by the parse_exp_1 function. */
11455 /* Parse the rest of the arguments. From here on out, everything
11456 is in terms of a newly allocated string instead of the original
11458 innermost_block = NULL;
11459 expression = savestring (arg, exp_end - arg);
11460 back_to = make_cleanup (xfree, expression);
11461 exp_start = arg = expression;
11462 exp = parse_exp_1 (&arg, 0, 0, 0);
11464 /* Remove trailing whitespace from the expression before saving it.
11465 This makes the eventual display of the expression string a bit
11467 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11470 /* Checking if the expression is not constant. */
11471 if (watchpoint_exp_is_const (exp))
11475 len = exp_end - exp_start;
11476 while (len > 0 && isspace (exp_start[len - 1]))
11478 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11481 exp_valid_block = innermost_block;
11482 mark = value_mark ();
11483 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11485 if (val != NULL && just_location)
11487 saved_bitpos = value_bitpos (val);
11488 saved_bitsize = value_bitsize (val);
11495 exp_valid_block = NULL;
11496 val = value_addr (result);
11497 release_value (val);
11498 value_free_to_mark (mark);
11502 ret = target_masked_watch_num_registers (value_as_address (val),
11505 error (_("This target does not support masked watchpoints."));
11506 else if (ret == -2)
11507 error (_("Invalid mask or memory region."));
11510 else if (val != NULL)
11511 release_value (val);
11513 tok = skip_spaces_const (arg);
11514 end_tok = skip_to_space_const (tok);
11516 toklen = end_tok - tok;
11517 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11519 struct expression *cond;
11521 innermost_block = NULL;
11522 tok = cond_start = end_tok + 1;
11523 cond = parse_exp_1 (&tok, 0, 0, 0);
11525 /* The watchpoint expression may not be local, but the condition
11526 may still be. E.g.: `watch global if local > 0'. */
11527 cond_exp_valid_block = innermost_block;
11533 error (_("Junk at end of command."));
11535 frame = block_innermost_frame (exp_valid_block);
11537 /* If the expression is "local", then set up a "watchpoint scope"
11538 breakpoint at the point where we've left the scope of the watchpoint
11539 expression. Create the scope breakpoint before the watchpoint, so
11540 that we will encounter it first in bpstat_stop_status. */
11541 if (exp_valid_block && frame)
11543 if (frame_id_p (frame_unwind_caller_id (frame)))
11546 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11547 frame_unwind_caller_pc (frame),
11548 bp_watchpoint_scope,
11549 &momentary_breakpoint_ops);
11551 scope_breakpoint->enable_state = bp_enabled;
11553 /* Automatically delete the breakpoint when it hits. */
11554 scope_breakpoint->disposition = disp_del;
11556 /* Only break in the proper frame (help with recursion). */
11557 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11559 /* Set the address at which we will stop. */
11560 scope_breakpoint->loc->gdbarch
11561 = frame_unwind_caller_arch (frame);
11562 scope_breakpoint->loc->requested_address
11563 = frame_unwind_caller_pc (frame);
11564 scope_breakpoint->loc->address
11565 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11566 scope_breakpoint->loc->requested_address,
11567 scope_breakpoint->type);
11571 /* Now set up the breakpoint. We create all watchpoints as hardware
11572 watchpoints here even if hardware watchpoints are turned off, a call
11573 to update_watchpoint later in this function will cause the type to
11574 drop back to bp_watchpoint (software watchpoint) if required. */
11576 if (accessflag == hw_read)
11577 bp_type = bp_read_watchpoint;
11578 else if (accessflag == hw_access)
11579 bp_type = bp_access_watchpoint;
11581 bp_type = bp_hardware_watchpoint;
11583 w = XCNEW (struct watchpoint);
11586 init_raw_breakpoint_without_location (b, NULL, bp_type,
11587 &masked_watchpoint_breakpoint_ops);
11589 init_raw_breakpoint_without_location (b, NULL, bp_type,
11590 &watchpoint_breakpoint_ops);
11591 b->thread = thread;
11592 b->disposition = disp_donttouch;
11593 b->pspace = current_program_space;
11595 w->exp_valid_block = exp_valid_block;
11596 w->cond_exp_valid_block = cond_exp_valid_block;
11599 struct type *t = value_type (val);
11600 CORE_ADDR addr = value_as_address (val);
11603 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11604 name = type_to_string (t);
11606 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11607 core_addr_to_string (addr));
11610 w->exp_string = xstrprintf ("-location %.*s",
11611 (int) (exp_end - exp_start), exp_start);
11613 /* The above expression is in C. */
11614 b->language = language_c;
11617 w->exp_string = savestring (exp_start, exp_end - exp_start);
11621 w->hw_wp_mask = mask;
11626 w->val_bitpos = saved_bitpos;
11627 w->val_bitsize = saved_bitsize;
11632 b->cond_string = savestring (cond_start, cond_end - cond_start);
11634 b->cond_string = 0;
11638 w->watchpoint_frame = get_frame_id (frame);
11639 w->watchpoint_thread = inferior_ptid;
11643 w->watchpoint_frame = null_frame_id;
11644 w->watchpoint_thread = null_ptid;
11647 if (scope_breakpoint != NULL)
11649 /* The scope breakpoint is related to the watchpoint. We will
11650 need to act on them together. */
11651 b->related_breakpoint = scope_breakpoint;
11652 scope_breakpoint->related_breakpoint = b;
11655 if (!just_location)
11656 value_free_to_mark (mark);
11658 TRY_CATCH (e, RETURN_MASK_ALL)
11660 /* Finally update the new watchpoint. This creates the locations
11661 that should be inserted. */
11662 update_watchpoint (w, 1);
11666 delete_breakpoint (b);
11667 throw_exception (e);
11670 install_breakpoint (internal, b, 1);
11671 do_cleanups (back_to);
11674 /* Return count of debug registers needed to watch the given expression.
11675 If the watchpoint cannot be handled in hardware return zero. */
11678 can_use_hardware_watchpoint (struct value *v)
11680 int found_memory_cnt = 0;
11681 struct value *head = v;
11683 /* Did the user specifically forbid us to use hardware watchpoints? */
11684 if (!can_use_hw_watchpoints)
11687 /* Make sure that the value of the expression depends only upon
11688 memory contents, and values computed from them within GDB. If we
11689 find any register references or function calls, we can't use a
11690 hardware watchpoint.
11692 The idea here is that evaluating an expression generates a series
11693 of values, one holding the value of every subexpression. (The
11694 expression a*b+c has five subexpressions: a, b, a*b, c, and
11695 a*b+c.) GDB's values hold almost enough information to establish
11696 the criteria given above --- they identify memory lvalues,
11697 register lvalues, computed values, etcetera. So we can evaluate
11698 the expression, and then scan the chain of values that leaves
11699 behind to decide whether we can detect any possible change to the
11700 expression's final value using only hardware watchpoints.
11702 However, I don't think that the values returned by inferior
11703 function calls are special in any way. So this function may not
11704 notice that an expression involving an inferior function call
11705 can't be watched with hardware watchpoints. FIXME. */
11706 for (; v; v = value_next (v))
11708 if (VALUE_LVAL (v) == lval_memory)
11710 if (v != head && value_lazy (v))
11711 /* A lazy memory lvalue in the chain is one that GDB never
11712 needed to fetch; we either just used its address (e.g.,
11713 `a' in `a.b') or we never needed it at all (e.g., `a'
11714 in `a,b'). This doesn't apply to HEAD; if that is
11715 lazy then it was not readable, but watch it anyway. */
11719 /* Ahh, memory we actually used! Check if we can cover
11720 it with hardware watchpoints. */
11721 struct type *vtype = check_typedef (value_type (v));
11723 /* We only watch structs and arrays if user asked for it
11724 explicitly, never if they just happen to appear in a
11725 middle of some value chain. */
11727 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11728 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11730 CORE_ADDR vaddr = value_address (v);
11734 len = (target_exact_watchpoints
11735 && is_scalar_type_recursive (vtype))?
11736 1 : TYPE_LENGTH (value_type (v));
11738 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11742 found_memory_cnt += num_regs;
11746 else if (VALUE_LVAL (v) != not_lval
11747 && deprecated_value_modifiable (v) == 0)
11748 return 0; /* These are values from the history (e.g., $1). */
11749 else if (VALUE_LVAL (v) == lval_register)
11750 return 0; /* Cannot watch a register with a HW watchpoint. */
11753 /* The expression itself looks suitable for using a hardware
11754 watchpoint, but give the target machine a chance to reject it. */
11755 return found_memory_cnt;
11759 watch_command_wrapper (char *arg, int from_tty, int internal)
11761 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11764 /* A helper function that looks for the "-location" argument and then
11765 calls watch_command_1. */
11768 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11770 int just_location = 0;
11773 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11774 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11776 arg = skip_spaces (arg);
11780 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11784 watch_command (char *arg, int from_tty)
11786 watch_maybe_just_location (arg, hw_write, from_tty);
11790 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11792 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11796 rwatch_command (char *arg, int from_tty)
11798 watch_maybe_just_location (arg, hw_read, from_tty);
11802 awatch_command_wrapper (char *arg, int from_tty, int internal)
11804 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11808 awatch_command (char *arg, int from_tty)
11810 watch_maybe_just_location (arg, hw_access, from_tty);
11814 /* Helper routines for the until_command routine in infcmd.c. Here
11815 because it uses the mechanisms of breakpoints. */
11817 struct until_break_command_continuation_args
11819 struct breakpoint *breakpoint;
11820 struct breakpoint *breakpoint2;
11824 /* This function is called by fetch_inferior_event via the
11825 cmd_continuation pointer, to complete the until command. It takes
11826 care of cleaning up the temporary breakpoints set up by the until
11829 until_break_command_continuation (void *arg, int err)
11831 struct until_break_command_continuation_args *a = arg;
11833 delete_breakpoint (a->breakpoint);
11834 if (a->breakpoint2)
11835 delete_breakpoint (a->breakpoint2);
11836 delete_longjmp_breakpoint (a->thread_num);
11840 until_break_command (char *arg, int from_tty, int anywhere)
11842 struct symtabs_and_lines sals;
11843 struct symtab_and_line sal;
11844 struct frame_info *frame;
11845 struct gdbarch *frame_gdbarch;
11846 struct frame_id stack_frame_id;
11847 struct frame_id caller_frame_id;
11848 struct breakpoint *breakpoint;
11849 struct breakpoint *breakpoint2 = NULL;
11850 struct cleanup *old_chain;
11852 struct thread_info *tp;
11854 clear_proceed_status (0);
11856 /* Set a breakpoint where the user wants it and at return from
11859 if (last_displayed_sal_is_valid ())
11860 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11861 get_last_displayed_symtab (),
11862 get_last_displayed_line ());
11864 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11865 (struct symtab *) NULL, 0);
11867 if (sals.nelts != 1)
11868 error (_("Couldn't get information on specified line."));
11870 sal = sals.sals[0];
11871 xfree (sals.sals); /* malloc'd, so freed. */
11874 error (_("Junk at end of arguments."));
11876 resolve_sal_pc (&sal);
11878 tp = inferior_thread ();
11881 old_chain = make_cleanup (null_cleanup, NULL);
11883 /* Note linespec handling above invalidates the frame chain.
11884 Installing a breakpoint also invalidates the frame chain (as it
11885 may need to switch threads), so do any frame handling before
11888 frame = get_selected_frame (NULL);
11889 frame_gdbarch = get_frame_arch (frame);
11890 stack_frame_id = get_stack_frame_id (frame);
11891 caller_frame_id = frame_unwind_caller_id (frame);
11893 /* Keep within the current frame, or in frames called by the current
11896 if (frame_id_p (caller_frame_id))
11898 struct symtab_and_line sal2;
11900 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11901 sal2.pc = frame_unwind_caller_pc (frame);
11902 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11906 make_cleanup_delete_breakpoint (breakpoint2);
11908 set_longjmp_breakpoint (tp, caller_frame_id);
11909 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11912 /* set_momentary_breakpoint could invalidate FRAME. */
11916 /* If the user told us to continue until a specified location,
11917 we don't specify a frame at which we need to stop. */
11918 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11919 null_frame_id, bp_until);
11921 /* Otherwise, specify the selected frame, because we want to stop
11922 only at the very same frame. */
11923 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11924 stack_frame_id, bp_until);
11925 make_cleanup_delete_breakpoint (breakpoint);
11927 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11929 /* If we are running asynchronously, and proceed call above has
11930 actually managed to start the target, arrange for breakpoints to
11931 be deleted when the target stops. Otherwise, we're already
11932 stopped and delete breakpoints via cleanup chain. */
11934 if (target_can_async_p () && is_running (inferior_ptid))
11936 struct until_break_command_continuation_args *args;
11937 args = xmalloc (sizeof (*args));
11939 args->breakpoint = breakpoint;
11940 args->breakpoint2 = breakpoint2;
11941 args->thread_num = thread;
11943 discard_cleanups (old_chain);
11944 add_continuation (inferior_thread (),
11945 until_break_command_continuation, args,
11949 do_cleanups (old_chain);
11952 /* This function attempts to parse an optional "if <cond>" clause
11953 from the arg string. If one is not found, it returns NULL.
11955 Else, it returns a pointer to the condition string. (It does not
11956 attempt to evaluate the string against a particular block.) And,
11957 it updates arg to point to the first character following the parsed
11958 if clause in the arg string. */
11961 ep_parse_optional_if_clause (char **arg)
11965 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11968 /* Skip the "if" keyword. */
11971 /* Skip any extra leading whitespace, and record the start of the
11972 condition string. */
11973 *arg = skip_spaces (*arg);
11974 cond_string = *arg;
11976 /* Assume that the condition occupies the remainder of the arg
11978 (*arg) += strlen (cond_string);
11980 return cond_string;
11983 /* Commands to deal with catching events, such as signals, exceptions,
11984 process start/exit, etc. */
11988 catch_fork_temporary, catch_vfork_temporary,
11989 catch_fork_permanent, catch_vfork_permanent
11994 catch_fork_command_1 (char *arg, int from_tty,
11995 struct cmd_list_element *command)
11997 struct gdbarch *gdbarch = get_current_arch ();
11998 char *cond_string = NULL;
11999 catch_fork_kind fork_kind;
12002 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
12003 tempflag = (fork_kind == catch_fork_temporary
12004 || fork_kind == catch_vfork_temporary);
12008 arg = skip_spaces (arg);
12010 /* The allowed syntax is:
12012 catch [v]fork if <cond>
12014 First, check if there's an if clause. */
12015 cond_string = ep_parse_optional_if_clause (&arg);
12017 if ((*arg != '\0') && !isspace (*arg))
12018 error (_("Junk at end of arguments."));
12020 /* If this target supports it, create a fork or vfork catchpoint
12021 and enable reporting of such events. */
12024 case catch_fork_temporary:
12025 case catch_fork_permanent:
12026 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
12027 &catch_fork_breakpoint_ops);
12029 case catch_vfork_temporary:
12030 case catch_vfork_permanent:
12031 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
12032 &catch_vfork_breakpoint_ops);
12035 error (_("unsupported or unknown fork kind; cannot catch it"));
12041 catch_exec_command_1 (char *arg, int from_tty,
12042 struct cmd_list_element *command)
12044 struct exec_catchpoint *c;
12045 struct gdbarch *gdbarch = get_current_arch ();
12047 char *cond_string = NULL;
12049 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12053 arg = skip_spaces (arg);
12055 /* The allowed syntax is:
12057 catch exec if <cond>
12059 First, check if there's an if clause. */
12060 cond_string = ep_parse_optional_if_clause (&arg);
12062 if ((*arg != '\0') && !isspace (*arg))
12063 error (_("Junk at end of arguments."));
12065 c = XNEW (struct exec_catchpoint);
12066 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
12067 &catch_exec_breakpoint_ops);
12068 c->exec_pathname = NULL;
12070 install_breakpoint (0, &c->base, 1);
12074 init_ada_exception_breakpoint (struct breakpoint *b,
12075 struct gdbarch *gdbarch,
12076 struct symtab_and_line sal,
12078 const struct breakpoint_ops *ops,
12085 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
12087 loc_gdbarch = gdbarch;
12089 describe_other_breakpoints (loc_gdbarch,
12090 sal.pspace, sal.pc, sal.section, -1);
12091 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12092 version for exception catchpoints, because two catchpoints
12093 used for different exception names will use the same address.
12094 In this case, a "breakpoint ... also set at..." warning is
12095 unproductive. Besides, the warning phrasing is also a bit
12096 inappropriate, we should use the word catchpoint, and tell
12097 the user what type of catchpoint it is. The above is good
12098 enough for now, though. */
12101 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
12103 b->enable_state = enabled ? bp_enabled : bp_disabled;
12104 b->disposition = tempflag ? disp_del : disp_donttouch;
12105 b->addr_string = addr_string;
12106 b->language = language_ada;
12109 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12110 filter list, or NULL if no filtering is required. */
12112 catch_syscall_split_args (char *arg)
12114 VEC(int) *result = NULL;
12115 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
12116 struct gdbarch *gdbarch = target_gdbarch ();
12118 while (*arg != '\0')
12120 int i, syscall_number;
12122 char cur_name[128];
12125 /* Skip whitespace. */
12126 arg = skip_spaces (arg);
12128 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
12129 cur_name[i] = arg[i];
12130 cur_name[i] = '\0';
12133 /* Check if the user provided a syscall name or a number. */
12134 syscall_number = (int) strtol (cur_name, &endptr, 0);
12135 if (*endptr == '\0')
12136 get_syscall_by_number (gdbarch, syscall_number, &s);
12139 /* We have a name. Let's check if it's valid and convert it
12141 get_syscall_by_name (gdbarch, cur_name, &s);
12143 if (s.number == UNKNOWN_SYSCALL)
12144 /* Here we have to issue an error instead of a warning,
12145 because GDB cannot do anything useful if there's no
12146 syscall number to be caught. */
12147 error (_("Unknown syscall name '%s'."), cur_name);
12150 /* Ok, it's valid. */
12151 VEC_safe_push (int, result, s.number);
12154 discard_cleanups (cleanup);
12158 /* Implement the "catch syscall" command. */
12161 catch_syscall_command_1 (char *arg, int from_tty,
12162 struct cmd_list_element *command)
12167 struct gdbarch *gdbarch = get_current_arch ();
12169 /* Checking if the feature if supported. */
12170 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
12171 error (_("The feature 'catch syscall' is not supported on \
12172 this architecture yet."));
12174 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12176 arg = skip_spaces (arg);
12178 /* We need to do this first "dummy" translation in order
12179 to get the syscall XML file loaded or, most important,
12180 to display a warning to the user if there's no XML file
12181 for his/her architecture. */
12182 get_syscall_by_number (gdbarch, 0, &s);
12184 /* The allowed syntax is:
12186 catch syscall <name | number> [<name | number> ... <name | number>]
12188 Let's check if there's a syscall name. */
12191 filter = catch_syscall_split_args (arg);
12195 create_syscall_event_catchpoint (tempflag, filter,
12196 &catch_syscall_breakpoint_ops);
12200 catch_command (char *arg, int from_tty)
12202 error (_("Catch requires an event name."));
12207 tcatch_command (char *arg, int from_tty)
12209 error (_("Catch requires an event name."));
12212 /* A qsort comparison function that sorts breakpoints in order. */
12215 compare_breakpoints (const void *a, const void *b)
12217 const breakpoint_p *ba = a;
12218 uintptr_t ua = (uintptr_t) *ba;
12219 const breakpoint_p *bb = b;
12220 uintptr_t ub = (uintptr_t) *bb;
12222 if ((*ba)->number < (*bb)->number)
12224 else if ((*ba)->number > (*bb)->number)
12227 /* Now sort by address, in case we see, e..g, two breakpoints with
12231 return ua > ub ? 1 : 0;
12234 /* Delete breakpoints by address or line. */
12237 clear_command (char *arg, int from_tty)
12239 struct breakpoint *b, *prev;
12240 VEC(breakpoint_p) *found = 0;
12243 struct symtabs_and_lines sals;
12244 struct symtab_and_line sal;
12246 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12250 sals = decode_line_with_current_source (arg,
12251 (DECODE_LINE_FUNFIRSTLINE
12252 | DECODE_LINE_LIST_MODE));
12253 make_cleanup (xfree, sals.sals);
12258 sals.sals = (struct symtab_and_line *)
12259 xmalloc (sizeof (struct symtab_and_line));
12260 make_cleanup (xfree, sals.sals);
12261 init_sal (&sal); /* Initialize to zeroes. */
12263 /* Set sal's line, symtab, pc, and pspace to the values
12264 corresponding to the last call to print_frame_info. If the
12265 codepoint is not valid, this will set all the fields to 0. */
12266 get_last_displayed_sal (&sal);
12267 if (sal.symtab == 0)
12268 error (_("No source file specified."));
12270 sals.sals[0] = sal;
12276 /* We don't call resolve_sal_pc here. That's not as bad as it
12277 seems, because all existing breakpoints typically have both
12278 file/line and pc set. So, if clear is given file/line, we can
12279 match this to existing breakpoint without obtaining pc at all.
12281 We only support clearing given the address explicitly
12282 present in breakpoint table. Say, we've set breakpoint
12283 at file:line. There were several PC values for that file:line,
12284 due to optimization, all in one block.
12286 We've picked one PC value. If "clear" is issued with another
12287 PC corresponding to the same file:line, the breakpoint won't
12288 be cleared. We probably can still clear the breakpoint, but
12289 since the other PC value is never presented to user, user
12290 can only find it by guessing, and it does not seem important
12291 to support that. */
12293 /* For each line spec given, delete bps which correspond to it. Do
12294 it in two passes, solely to preserve the current behavior that
12295 from_tty is forced true if we delete more than one
12299 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12300 for (i = 0; i < sals.nelts; i++)
12302 const char *sal_fullname;
12304 /* If exact pc given, clear bpts at that pc.
12305 If line given (pc == 0), clear all bpts on specified line.
12306 If defaulting, clear all bpts on default line
12309 defaulting sal.pc != 0 tests to do
12314 1 0 <can't happen> */
12316 sal = sals.sals[i];
12317 sal_fullname = (sal.symtab == NULL
12318 ? NULL : symtab_to_fullname (sal.symtab));
12320 /* Find all matching breakpoints and add them to 'found'. */
12321 ALL_BREAKPOINTS (b)
12324 /* Are we going to delete b? */
12325 if (b->type != bp_none && !is_watchpoint (b))
12327 struct bp_location *loc = b->loc;
12328 for (; loc; loc = loc->next)
12330 /* If the user specified file:line, don't allow a PC
12331 match. This matches historical gdb behavior. */
12332 int pc_match = (!sal.explicit_line
12334 && (loc->pspace == sal.pspace)
12335 && (loc->address == sal.pc)
12336 && (!section_is_overlay (loc->section)
12337 || loc->section == sal.section));
12338 int line_match = 0;
12340 if ((default_match || sal.explicit_line)
12341 && loc->symtab != NULL
12342 && sal_fullname != NULL
12343 && sal.pspace == loc->pspace
12344 && loc->line_number == sal.line
12345 && filename_cmp (symtab_to_fullname (loc->symtab),
12346 sal_fullname) == 0)
12349 if (pc_match || line_match)
12358 VEC_safe_push(breakpoint_p, found, b);
12362 /* Now go thru the 'found' chain and delete them. */
12363 if (VEC_empty(breakpoint_p, found))
12366 error (_("No breakpoint at %s."), arg);
12368 error (_("No breakpoint at this line."));
12371 /* Remove duplicates from the vec. */
12372 qsort (VEC_address (breakpoint_p, found),
12373 VEC_length (breakpoint_p, found),
12374 sizeof (breakpoint_p),
12375 compare_breakpoints);
12376 prev = VEC_index (breakpoint_p, found, 0);
12377 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12381 VEC_ordered_remove (breakpoint_p, found, ix);
12386 if (VEC_length(breakpoint_p, found) > 1)
12387 from_tty = 1; /* Always report if deleted more than one. */
12390 if (VEC_length(breakpoint_p, found) == 1)
12391 printf_unfiltered (_("Deleted breakpoint "));
12393 printf_unfiltered (_("Deleted breakpoints "));
12396 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12399 printf_unfiltered ("%d ", b->number);
12400 delete_breakpoint (b);
12403 putchar_unfiltered ('\n');
12405 do_cleanups (cleanups);
12408 /* Delete breakpoint in BS if they are `delete' breakpoints and
12409 all breakpoints that are marked for deletion, whether hit or not.
12410 This is called after any breakpoint is hit, or after errors. */
12413 breakpoint_auto_delete (bpstat bs)
12415 struct breakpoint *b, *b_tmp;
12417 for (; bs; bs = bs->next)
12418 if (bs->breakpoint_at
12419 && bs->breakpoint_at->disposition == disp_del
12421 delete_breakpoint (bs->breakpoint_at);
12423 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12425 if (b->disposition == disp_del_at_next_stop)
12426 delete_breakpoint (b);
12430 /* A comparison function for bp_location AP and BP being interfaced to
12431 qsort. Sort elements primarily by their ADDRESS (no matter what
12432 does breakpoint_address_is_meaningful say for its OWNER),
12433 secondarily by ordering first permanent elements and
12434 terciarily just ensuring the array is sorted stable way despite
12435 qsort being an unstable algorithm. */
12438 bp_location_compare (const void *ap, const void *bp)
12440 struct bp_location *a = *(void **) ap;
12441 struct bp_location *b = *(void **) bp;
12443 if (a->address != b->address)
12444 return (a->address > b->address) - (a->address < b->address);
12446 /* Sort locations at the same address by their pspace number, keeping
12447 locations of the same inferior (in a multi-inferior environment)
12450 if (a->pspace->num != b->pspace->num)
12451 return ((a->pspace->num > b->pspace->num)
12452 - (a->pspace->num < b->pspace->num));
12454 /* Sort permanent breakpoints first. */
12455 if (a->permanent != b->permanent)
12456 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
12458 /* Make the internal GDB representation stable across GDB runs
12459 where A and B memory inside GDB can differ. Breakpoint locations of
12460 the same type at the same address can be sorted in arbitrary order. */
12462 if (a->owner->number != b->owner->number)
12463 return ((a->owner->number > b->owner->number)
12464 - (a->owner->number < b->owner->number));
12466 return (a > b) - (a < b);
12469 /* Set bp_location_placed_address_before_address_max and
12470 bp_location_shadow_len_after_address_max according to the current
12471 content of the bp_location array. */
12474 bp_location_target_extensions_update (void)
12476 struct bp_location *bl, **blp_tmp;
12478 bp_location_placed_address_before_address_max = 0;
12479 bp_location_shadow_len_after_address_max = 0;
12481 ALL_BP_LOCATIONS (bl, blp_tmp)
12483 CORE_ADDR start, end, addr;
12485 if (!bp_location_has_shadow (bl))
12488 start = bl->target_info.placed_address;
12489 end = start + bl->target_info.shadow_len;
12491 gdb_assert (bl->address >= start);
12492 addr = bl->address - start;
12493 if (addr > bp_location_placed_address_before_address_max)
12494 bp_location_placed_address_before_address_max = addr;
12496 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12498 gdb_assert (bl->address < end);
12499 addr = end - bl->address;
12500 if (addr > bp_location_shadow_len_after_address_max)
12501 bp_location_shadow_len_after_address_max = addr;
12505 /* Download tracepoint locations if they haven't been. */
12508 download_tracepoint_locations (void)
12510 struct breakpoint *b;
12511 struct cleanup *old_chain;
12513 if (!target_can_download_tracepoint ())
12516 old_chain = save_current_space_and_thread ();
12518 ALL_TRACEPOINTS (b)
12520 struct bp_location *bl;
12521 struct tracepoint *t;
12522 int bp_location_downloaded = 0;
12524 if ((b->type == bp_fast_tracepoint
12525 ? !may_insert_fast_tracepoints
12526 : !may_insert_tracepoints))
12529 for (bl = b->loc; bl; bl = bl->next)
12531 /* In tracepoint, locations are _never_ duplicated, so
12532 should_be_inserted is equivalent to
12533 unduplicated_should_be_inserted. */
12534 if (!should_be_inserted (bl) || bl->inserted)
12537 switch_to_program_space_and_thread (bl->pspace);
12539 target_download_tracepoint (bl);
12542 bp_location_downloaded = 1;
12544 t = (struct tracepoint *) b;
12545 t->number_on_target = b->number;
12546 if (bp_location_downloaded)
12547 observer_notify_breakpoint_modified (b);
12550 do_cleanups (old_chain);
12553 /* Swap the insertion/duplication state between two locations. */
12556 swap_insertion (struct bp_location *left, struct bp_location *right)
12558 const int left_inserted = left->inserted;
12559 const int left_duplicate = left->duplicate;
12560 const int left_needs_update = left->needs_update;
12561 const struct bp_target_info left_target_info = left->target_info;
12563 /* Locations of tracepoints can never be duplicated. */
12564 if (is_tracepoint (left->owner))
12565 gdb_assert (!left->duplicate);
12566 if (is_tracepoint (right->owner))
12567 gdb_assert (!right->duplicate);
12569 left->inserted = right->inserted;
12570 left->duplicate = right->duplicate;
12571 left->needs_update = right->needs_update;
12572 left->target_info = right->target_info;
12573 right->inserted = left_inserted;
12574 right->duplicate = left_duplicate;
12575 right->needs_update = left_needs_update;
12576 right->target_info = left_target_info;
12579 /* Force the re-insertion of the locations at ADDRESS. This is called
12580 once a new/deleted/modified duplicate location is found and we are evaluating
12581 conditions on the target's side. Such conditions need to be updated on
12585 force_breakpoint_reinsertion (struct bp_location *bl)
12587 struct bp_location **locp = NULL, **loc2p;
12588 struct bp_location *loc;
12589 CORE_ADDR address = 0;
12592 address = bl->address;
12593 pspace_num = bl->pspace->num;
12595 /* This is only meaningful if the target is
12596 evaluating conditions and if the user has
12597 opted for condition evaluation on the target's
12599 if (gdb_evaluates_breakpoint_condition_p ()
12600 || !target_supports_evaluation_of_breakpoint_conditions ())
12603 /* Flag all breakpoint locations with this address and
12604 the same program space as the location
12605 as "its condition has changed". We need to
12606 update the conditions on the target's side. */
12607 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12611 if (!is_breakpoint (loc->owner)
12612 || pspace_num != loc->pspace->num)
12615 /* Flag the location appropriately. We use a different state to
12616 let everyone know that we already updated the set of locations
12617 with addr bl->address and program space bl->pspace. This is so
12618 we don't have to keep calling these functions just to mark locations
12619 that have already been marked. */
12620 loc->condition_changed = condition_updated;
12622 /* Free the agent expression bytecode as well. We will compute
12624 if (loc->cond_bytecode)
12626 free_agent_expr (loc->cond_bytecode);
12627 loc->cond_bytecode = NULL;
12631 /* Called whether new breakpoints are created, or existing breakpoints
12632 deleted, to update the global location list and recompute which
12633 locations are duplicate of which.
12635 The INSERT_MODE flag determines whether locations may not, may, or
12636 shall be inserted now. See 'enum ugll_insert_mode' for more
12640 update_global_location_list (enum ugll_insert_mode insert_mode)
12642 struct breakpoint *b;
12643 struct bp_location **locp, *loc;
12644 struct cleanup *cleanups;
12645 /* Last breakpoint location address that was marked for update. */
12646 CORE_ADDR last_addr = 0;
12647 /* Last breakpoint location program space that was marked for update. */
12648 int last_pspace_num = -1;
12650 /* Used in the duplicates detection below. When iterating over all
12651 bp_locations, points to the first bp_location of a given address.
12652 Breakpoints and watchpoints of different types are never
12653 duplicates of each other. Keep one pointer for each type of
12654 breakpoint/watchpoint, so we only need to loop over all locations
12656 struct bp_location *bp_loc_first; /* breakpoint */
12657 struct bp_location *wp_loc_first; /* hardware watchpoint */
12658 struct bp_location *awp_loc_first; /* access watchpoint */
12659 struct bp_location *rwp_loc_first; /* read watchpoint */
12661 /* Saved former bp_location array which we compare against the newly
12662 built bp_location from the current state of ALL_BREAKPOINTS. */
12663 struct bp_location **old_location, **old_locp;
12664 unsigned old_location_count;
12666 old_location = bp_location;
12667 old_location_count = bp_location_count;
12668 bp_location = NULL;
12669 bp_location_count = 0;
12670 cleanups = make_cleanup (xfree, old_location);
12672 ALL_BREAKPOINTS (b)
12673 for (loc = b->loc; loc; loc = loc->next)
12674 bp_location_count++;
12676 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12677 locp = bp_location;
12678 ALL_BREAKPOINTS (b)
12679 for (loc = b->loc; loc; loc = loc->next)
12681 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12682 bp_location_compare);
12684 bp_location_target_extensions_update ();
12686 /* Identify bp_location instances that are no longer present in the
12687 new list, and therefore should be freed. Note that it's not
12688 necessary that those locations should be removed from inferior --
12689 if there's another location at the same address (previously
12690 marked as duplicate), we don't need to remove/insert the
12693 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12694 and former bp_location array state respectively. */
12696 locp = bp_location;
12697 for (old_locp = old_location; old_locp < old_location + old_location_count;
12700 struct bp_location *old_loc = *old_locp;
12701 struct bp_location **loc2p;
12703 /* Tells if 'old_loc' is found among the new locations. If
12704 not, we have to free it. */
12705 int found_object = 0;
12706 /* Tells if the location should remain inserted in the target. */
12707 int keep_in_target = 0;
12710 /* Skip LOCP entries which will definitely never be needed.
12711 Stop either at or being the one matching OLD_LOC. */
12712 while (locp < bp_location + bp_location_count
12713 && (*locp)->address < old_loc->address)
12717 (loc2p < bp_location + bp_location_count
12718 && (*loc2p)->address == old_loc->address);
12721 /* Check if this is a new/duplicated location or a duplicated
12722 location that had its condition modified. If so, we want to send
12723 its condition to the target if evaluation of conditions is taking
12725 if ((*loc2p)->condition_changed == condition_modified
12726 && (last_addr != old_loc->address
12727 || last_pspace_num != old_loc->pspace->num))
12729 force_breakpoint_reinsertion (*loc2p);
12730 last_pspace_num = old_loc->pspace->num;
12733 if (*loc2p == old_loc)
12737 /* We have already handled this address, update it so that we don't
12738 have to go through updates again. */
12739 last_addr = old_loc->address;
12741 /* Target-side condition evaluation: Handle deleted locations. */
12743 force_breakpoint_reinsertion (old_loc);
12745 /* If this location is no longer present, and inserted, look if
12746 there's maybe a new location at the same address. If so,
12747 mark that one inserted, and don't remove this one. This is
12748 needed so that we don't have a time window where a breakpoint
12749 at certain location is not inserted. */
12751 if (old_loc->inserted)
12753 /* If the location is inserted now, we might have to remove
12756 if (found_object && should_be_inserted (old_loc))
12758 /* The location is still present in the location list,
12759 and still should be inserted. Don't do anything. */
12760 keep_in_target = 1;
12764 /* This location still exists, but it won't be kept in the
12765 target since it may have been disabled. We proceed to
12766 remove its target-side condition. */
12768 /* The location is either no longer present, or got
12769 disabled. See if there's another location at the
12770 same address, in which case we don't need to remove
12771 this one from the target. */
12773 /* OLD_LOC comes from existing struct breakpoint. */
12774 if (breakpoint_address_is_meaningful (old_loc->owner))
12777 (loc2p < bp_location + bp_location_count
12778 && (*loc2p)->address == old_loc->address);
12781 struct bp_location *loc2 = *loc2p;
12783 if (breakpoint_locations_match (loc2, old_loc))
12785 /* Read watchpoint locations are switched to
12786 access watchpoints, if the former are not
12787 supported, but the latter are. */
12788 if (is_hardware_watchpoint (old_loc->owner))
12790 gdb_assert (is_hardware_watchpoint (loc2->owner));
12791 loc2->watchpoint_type = old_loc->watchpoint_type;
12794 /* loc2 is a duplicated location. We need to check
12795 if it should be inserted in case it will be
12797 if (loc2 != old_loc
12798 && unduplicated_should_be_inserted (loc2))
12800 swap_insertion (old_loc, loc2);
12801 keep_in_target = 1;
12809 if (!keep_in_target)
12811 if (remove_breakpoint (old_loc, mark_uninserted))
12813 /* This is just about all we can do. We could keep
12814 this location on the global list, and try to
12815 remove it next time, but there's no particular
12816 reason why we will succeed next time.
12818 Note that at this point, old_loc->owner is still
12819 valid, as delete_breakpoint frees the breakpoint
12820 only after calling us. */
12821 printf_filtered (_("warning: Error removing "
12822 "breakpoint %d\n"),
12823 old_loc->owner->number);
12831 if (removed && non_stop
12832 && need_moribund_for_location_type (old_loc))
12834 /* This location was removed from the target. In
12835 non-stop mode, a race condition is possible where
12836 we've removed a breakpoint, but stop events for that
12837 breakpoint are already queued and will arrive later.
12838 We apply an heuristic to be able to distinguish such
12839 SIGTRAPs from other random SIGTRAPs: we keep this
12840 breakpoint location for a bit, and will retire it
12841 after we see some number of events. The theory here
12842 is that reporting of events should, "on the average",
12843 be fair, so after a while we'll see events from all
12844 threads that have anything of interest, and no longer
12845 need to keep this breakpoint location around. We
12846 don't hold locations forever so to reduce chances of
12847 mistaking a non-breakpoint SIGTRAP for a breakpoint
12850 The heuristic failing can be disastrous on
12851 decr_pc_after_break targets.
12853 On decr_pc_after_break targets, like e.g., x86-linux,
12854 if we fail to recognize a late breakpoint SIGTRAP,
12855 because events_till_retirement has reached 0 too
12856 soon, we'll fail to do the PC adjustment, and report
12857 a random SIGTRAP to the user. When the user resumes
12858 the inferior, it will most likely immediately crash
12859 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12860 corrupted, because of being resumed e.g., in the
12861 middle of a multi-byte instruction, or skipped a
12862 one-byte instruction. This was actually seen happen
12863 on native x86-linux, and should be less rare on
12864 targets that do not support new thread events, like
12865 remote, due to the heuristic depending on
12868 Mistaking a random SIGTRAP for a breakpoint trap
12869 causes similar symptoms (PC adjustment applied when
12870 it shouldn't), but then again, playing with SIGTRAPs
12871 behind the debugger's back is asking for trouble.
12873 Since hardware watchpoint traps are always
12874 distinguishable from other traps, so we don't need to
12875 apply keep hardware watchpoint moribund locations
12876 around. We simply always ignore hardware watchpoint
12877 traps we can no longer explain. */
12879 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12880 old_loc->owner = NULL;
12882 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12886 old_loc->owner = NULL;
12887 decref_bp_location (&old_loc);
12892 /* Rescan breakpoints at the same address and section, marking the
12893 first one as "first" and any others as "duplicates". This is so
12894 that the bpt instruction is only inserted once. If we have a
12895 permanent breakpoint at the same place as BPT, make that one the
12896 official one, and the rest as duplicates. Permanent breakpoints
12897 are sorted first for the same address.
12899 Do the same for hardware watchpoints, but also considering the
12900 watchpoint's type (regular/access/read) and length. */
12902 bp_loc_first = NULL;
12903 wp_loc_first = NULL;
12904 awp_loc_first = NULL;
12905 rwp_loc_first = NULL;
12906 ALL_BP_LOCATIONS (loc, locp)
12908 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12910 struct bp_location **loc_first_p;
12913 if (!unduplicated_should_be_inserted (loc)
12914 || !breakpoint_address_is_meaningful (b)
12915 /* Don't detect duplicate for tracepoint locations because they are
12916 never duplicated. See the comments in field `duplicate' of
12917 `struct bp_location'. */
12918 || is_tracepoint (b))
12920 /* Clear the condition modification flag. */
12921 loc->condition_changed = condition_unchanged;
12925 /* Permanent breakpoint should always be inserted. */
12926 if (loc->permanent && ! loc->inserted)
12927 internal_error (__FILE__, __LINE__,
12928 _("allegedly permanent breakpoint is not "
12929 "actually inserted"));
12931 if (b->type == bp_hardware_watchpoint)
12932 loc_first_p = &wp_loc_first;
12933 else if (b->type == bp_read_watchpoint)
12934 loc_first_p = &rwp_loc_first;
12935 else if (b->type == bp_access_watchpoint)
12936 loc_first_p = &awp_loc_first;
12938 loc_first_p = &bp_loc_first;
12940 if (*loc_first_p == NULL
12941 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12942 || !breakpoint_locations_match (loc, *loc_first_p))
12944 *loc_first_p = loc;
12945 loc->duplicate = 0;
12947 if (is_breakpoint (loc->owner) && loc->condition_changed)
12949 loc->needs_update = 1;
12950 /* Clear the condition modification flag. */
12951 loc->condition_changed = condition_unchanged;
12957 /* This and the above ensure the invariant that the first location
12958 is not duplicated, and is the inserted one.
12959 All following are marked as duplicated, and are not inserted. */
12961 swap_insertion (loc, *loc_first_p);
12962 loc->duplicate = 1;
12964 /* Clear the condition modification flag. */
12965 loc->condition_changed = condition_unchanged;
12967 if (loc->inserted && !loc->permanent
12968 && (*loc_first_p)->permanent)
12969 internal_error (__FILE__, __LINE__,
12970 _("another breakpoint was inserted on top of "
12971 "a permanent breakpoint"));
12974 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12976 if (insert_mode != UGLL_DONT_INSERT)
12977 insert_breakpoint_locations ();
12980 /* Even though the caller told us to not insert new
12981 locations, we may still need to update conditions on the
12982 target's side of breakpoints that were already inserted
12983 if the target is evaluating breakpoint conditions. We
12984 only update conditions for locations that are marked
12986 update_inserted_breakpoint_locations ();
12990 if (insert_mode != UGLL_DONT_INSERT)
12991 download_tracepoint_locations ();
12993 do_cleanups (cleanups);
12997 breakpoint_retire_moribund (void)
12999 struct bp_location *loc;
13002 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
13003 if (--(loc->events_till_retirement) == 0)
13005 decref_bp_location (&loc);
13006 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
13012 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
13014 volatile struct gdb_exception e;
13016 TRY_CATCH (e, RETURN_MASK_ERROR)
13017 update_global_location_list (insert_mode);
13020 /* Clear BKP from a BPS. */
13023 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
13027 for (bs = bps; bs; bs = bs->next)
13028 if (bs->breakpoint_at == bpt)
13030 bs->breakpoint_at = NULL;
13031 bs->old_val = NULL;
13032 /* bs->commands will be freed later. */
13036 /* Callback for iterate_over_threads. */
13038 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
13040 struct breakpoint *bpt = data;
13042 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
13046 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
13050 say_where (struct breakpoint *b)
13052 struct value_print_options opts;
13054 get_user_print_options (&opts);
13056 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13058 if (b->loc == NULL)
13060 printf_filtered (_(" (%s) pending."), b->addr_string);
13064 if (opts.addressprint || b->loc->symtab == NULL)
13066 printf_filtered (" at ");
13067 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
13070 if (b->loc->symtab != NULL)
13072 /* If there is a single location, we can print the location
13074 if (b->loc->next == NULL)
13075 printf_filtered (": file %s, line %d.",
13076 symtab_to_filename_for_display (b->loc->symtab),
13077 b->loc->line_number);
13079 /* This is not ideal, but each location may have a
13080 different file name, and this at least reflects the
13081 real situation somewhat. */
13082 printf_filtered (": %s.", b->addr_string);
13087 struct bp_location *loc = b->loc;
13089 for (; loc; loc = loc->next)
13091 printf_filtered (" (%d locations)", n);
13096 /* Default bp_location_ops methods. */
13099 bp_location_dtor (struct bp_location *self)
13101 xfree (self->cond);
13102 if (self->cond_bytecode)
13103 free_agent_expr (self->cond_bytecode);
13104 xfree (self->function_name);
13106 VEC_free (agent_expr_p, self->target_info.conditions);
13107 VEC_free (agent_expr_p, self->target_info.tcommands);
13110 static const struct bp_location_ops bp_location_ops =
13115 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13119 base_breakpoint_dtor (struct breakpoint *self)
13121 decref_counted_command_line (&self->commands);
13122 xfree (self->cond_string);
13123 xfree (self->extra_string);
13124 xfree (self->addr_string);
13125 xfree (self->filter);
13126 xfree (self->addr_string_range_end);
13129 static struct bp_location *
13130 base_breakpoint_allocate_location (struct breakpoint *self)
13132 struct bp_location *loc;
13134 loc = XNEW (struct bp_location);
13135 init_bp_location (loc, &bp_location_ops, self);
13140 base_breakpoint_re_set (struct breakpoint *b)
13142 /* Nothing to re-set. */
13145 #define internal_error_pure_virtual_called() \
13146 gdb_assert_not_reached ("pure virtual function called")
13149 base_breakpoint_insert_location (struct bp_location *bl)
13151 internal_error_pure_virtual_called ();
13155 base_breakpoint_remove_location (struct bp_location *bl)
13157 internal_error_pure_virtual_called ();
13161 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
13162 struct address_space *aspace,
13164 const struct target_waitstatus *ws)
13166 internal_error_pure_virtual_called ();
13170 base_breakpoint_check_status (bpstat bs)
13175 /* A "works_in_software_mode" breakpoint_ops method that just internal
13179 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
13181 internal_error_pure_virtual_called ();
13184 /* A "resources_needed" breakpoint_ops method that just internal
13188 base_breakpoint_resources_needed (const struct bp_location *bl)
13190 internal_error_pure_virtual_called ();
13193 static enum print_stop_action
13194 base_breakpoint_print_it (bpstat bs)
13196 internal_error_pure_virtual_called ();
13200 base_breakpoint_print_one_detail (const struct breakpoint *self,
13201 struct ui_out *uiout)
13207 base_breakpoint_print_mention (struct breakpoint *b)
13209 internal_error_pure_virtual_called ();
13213 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
13215 internal_error_pure_virtual_called ();
13219 base_breakpoint_create_sals_from_address (char **arg,
13220 struct linespec_result *canonical,
13221 enum bptype type_wanted,
13225 internal_error_pure_virtual_called ();
13229 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13230 struct linespec_result *c,
13232 char *extra_string,
13233 enum bptype type_wanted,
13234 enum bpdisp disposition,
13236 int task, int ignore_count,
13237 const struct breakpoint_ops *o,
13238 int from_tty, int enabled,
13239 int internal, unsigned flags)
13241 internal_error_pure_virtual_called ();
13245 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
13246 struct symtabs_and_lines *sals)
13248 internal_error_pure_virtual_called ();
13251 /* The default 'explains_signal' method. */
13254 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13259 /* The default "after_condition_true" method. */
13262 base_breakpoint_after_condition_true (struct bpstats *bs)
13264 /* Nothing to do. */
13267 struct breakpoint_ops base_breakpoint_ops =
13269 base_breakpoint_dtor,
13270 base_breakpoint_allocate_location,
13271 base_breakpoint_re_set,
13272 base_breakpoint_insert_location,
13273 base_breakpoint_remove_location,
13274 base_breakpoint_breakpoint_hit,
13275 base_breakpoint_check_status,
13276 base_breakpoint_resources_needed,
13277 base_breakpoint_works_in_software_mode,
13278 base_breakpoint_print_it,
13280 base_breakpoint_print_one_detail,
13281 base_breakpoint_print_mention,
13282 base_breakpoint_print_recreate,
13283 base_breakpoint_create_sals_from_address,
13284 base_breakpoint_create_breakpoints_sal,
13285 base_breakpoint_decode_linespec,
13286 base_breakpoint_explains_signal,
13287 base_breakpoint_after_condition_true,
13290 /* Default breakpoint_ops methods. */
13293 bkpt_re_set (struct breakpoint *b)
13295 /* FIXME: is this still reachable? */
13296 if (b->addr_string == NULL)
13298 /* Anything without a string can't be re-set. */
13299 delete_breakpoint (b);
13303 breakpoint_re_set_default (b);
13307 bkpt_insert_location (struct bp_location *bl)
13309 if (bl->loc_type == bp_loc_hardware_breakpoint)
13310 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
13312 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
13316 bkpt_remove_location (struct bp_location *bl)
13318 if (bl->loc_type == bp_loc_hardware_breakpoint)
13319 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13321 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13325 bkpt_breakpoint_hit (const struct bp_location *bl,
13326 struct address_space *aspace, CORE_ADDR bp_addr,
13327 const struct target_waitstatus *ws)
13329 if (ws->kind != TARGET_WAITKIND_STOPPED
13330 || ws->value.sig != GDB_SIGNAL_TRAP)
13333 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13337 if (overlay_debugging /* unmapped overlay section */
13338 && section_is_overlay (bl->section)
13339 && !section_is_mapped (bl->section))
13346 dprintf_breakpoint_hit (const struct bp_location *bl,
13347 struct address_space *aspace, CORE_ADDR bp_addr,
13348 const struct target_waitstatus *ws)
13350 if (dprintf_style == dprintf_style_agent
13351 && target_can_run_breakpoint_commands ())
13353 /* An agent-style dprintf never causes a stop. If we see a trap
13354 for this address it must be for a breakpoint that happens to
13355 be set at the same address. */
13359 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13363 bkpt_resources_needed (const struct bp_location *bl)
13365 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13370 static enum print_stop_action
13371 bkpt_print_it (bpstat bs)
13373 struct breakpoint *b;
13374 const struct bp_location *bl;
13376 struct ui_out *uiout = current_uiout;
13378 gdb_assert (bs->bp_location_at != NULL);
13380 bl = bs->bp_location_at;
13381 b = bs->breakpoint_at;
13383 bp_temp = b->disposition == disp_del;
13384 if (bl->address != bl->requested_address)
13385 breakpoint_adjustment_warning (bl->requested_address,
13388 annotate_breakpoint (b->number);
13390 ui_out_text (uiout, "\nTemporary breakpoint ");
13392 ui_out_text (uiout, "\nBreakpoint ");
13393 if (ui_out_is_mi_like_p (uiout))
13395 ui_out_field_string (uiout, "reason",
13396 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13397 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13399 ui_out_field_int (uiout, "bkptno", b->number);
13400 ui_out_text (uiout, ", ");
13402 return PRINT_SRC_AND_LOC;
13406 bkpt_print_mention (struct breakpoint *b)
13408 if (ui_out_is_mi_like_p (current_uiout))
13413 case bp_breakpoint:
13414 case bp_gnu_ifunc_resolver:
13415 if (b->disposition == disp_del)
13416 printf_filtered (_("Temporary breakpoint"));
13418 printf_filtered (_("Breakpoint"));
13419 printf_filtered (_(" %d"), b->number);
13420 if (b->type == bp_gnu_ifunc_resolver)
13421 printf_filtered (_(" at gnu-indirect-function resolver"));
13423 case bp_hardware_breakpoint:
13424 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13427 printf_filtered (_("Dprintf %d"), b->number);
13435 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13437 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13438 fprintf_unfiltered (fp, "tbreak");
13439 else if (tp->type == bp_breakpoint)
13440 fprintf_unfiltered (fp, "break");
13441 else if (tp->type == bp_hardware_breakpoint
13442 && tp->disposition == disp_del)
13443 fprintf_unfiltered (fp, "thbreak");
13444 else if (tp->type == bp_hardware_breakpoint)
13445 fprintf_unfiltered (fp, "hbreak");
13447 internal_error (__FILE__, __LINE__,
13448 _("unhandled breakpoint type %d"), (int) tp->type);
13450 fprintf_unfiltered (fp, " %s", tp->addr_string);
13451 print_recreate_thread (tp, fp);
13455 bkpt_create_sals_from_address (char **arg,
13456 struct linespec_result *canonical,
13457 enum bptype type_wanted,
13458 char *addr_start, char **copy_arg)
13460 create_sals_from_address_default (arg, canonical, type_wanted,
13461 addr_start, copy_arg);
13465 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13466 struct linespec_result *canonical,
13468 char *extra_string,
13469 enum bptype type_wanted,
13470 enum bpdisp disposition,
13472 int task, int ignore_count,
13473 const struct breakpoint_ops *ops,
13474 int from_tty, int enabled,
13475 int internal, unsigned flags)
13477 create_breakpoints_sal_default (gdbarch, canonical,
13478 cond_string, extra_string,
13480 disposition, thread, task,
13481 ignore_count, ops, from_tty,
13482 enabled, internal, flags);
13486 bkpt_decode_linespec (struct breakpoint *b, char **s,
13487 struct symtabs_and_lines *sals)
13489 decode_linespec_default (b, s, sals);
13492 /* Virtual table for internal breakpoints. */
13495 internal_bkpt_re_set (struct breakpoint *b)
13499 /* Delete overlay event and longjmp master breakpoints; they
13500 will be reset later by breakpoint_re_set. */
13501 case bp_overlay_event:
13502 case bp_longjmp_master:
13503 case bp_std_terminate_master:
13504 case bp_exception_master:
13505 delete_breakpoint (b);
13508 /* This breakpoint is special, it's set up when the inferior
13509 starts and we really don't want to touch it. */
13510 case bp_shlib_event:
13512 /* Like bp_shlib_event, this breakpoint type is special. Once
13513 it is set up, we do not want to touch it. */
13514 case bp_thread_event:
13520 internal_bkpt_check_status (bpstat bs)
13522 if (bs->breakpoint_at->type == bp_shlib_event)
13524 /* If requested, stop when the dynamic linker notifies GDB of
13525 events. This allows the user to get control and place
13526 breakpoints in initializer routines for dynamically loaded
13527 objects (among other things). */
13528 bs->stop = stop_on_solib_events;
13529 bs->print = stop_on_solib_events;
13535 static enum print_stop_action
13536 internal_bkpt_print_it (bpstat bs)
13538 struct breakpoint *b;
13540 b = bs->breakpoint_at;
13544 case bp_shlib_event:
13545 /* Did we stop because the user set the stop_on_solib_events
13546 variable? (If so, we report this as a generic, "Stopped due
13547 to shlib event" message.) */
13548 print_solib_event (0);
13551 case bp_thread_event:
13552 /* Not sure how we will get here.
13553 GDB should not stop for these breakpoints. */
13554 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13557 case bp_overlay_event:
13558 /* By analogy with the thread event, GDB should not stop for these. */
13559 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13562 case bp_longjmp_master:
13563 /* These should never be enabled. */
13564 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13567 case bp_std_terminate_master:
13568 /* These should never be enabled. */
13569 printf_filtered (_("std::terminate Master Breakpoint: "
13570 "gdb should not stop!\n"));
13573 case bp_exception_master:
13574 /* These should never be enabled. */
13575 printf_filtered (_("Exception Master Breakpoint: "
13576 "gdb should not stop!\n"));
13580 return PRINT_NOTHING;
13584 internal_bkpt_print_mention (struct breakpoint *b)
13586 /* Nothing to mention. These breakpoints are internal. */
13589 /* Virtual table for momentary breakpoints */
13592 momentary_bkpt_re_set (struct breakpoint *b)
13594 /* Keep temporary breakpoints, which can be encountered when we step
13595 over a dlopen call and solib_add is resetting the breakpoints.
13596 Otherwise these should have been blown away via the cleanup chain
13597 or by breakpoint_init_inferior when we rerun the executable. */
13601 momentary_bkpt_check_status (bpstat bs)
13603 /* Nothing. The point of these breakpoints is causing a stop. */
13606 static enum print_stop_action
13607 momentary_bkpt_print_it (bpstat bs)
13609 struct ui_out *uiout = current_uiout;
13611 if (ui_out_is_mi_like_p (uiout))
13613 struct breakpoint *b = bs->breakpoint_at;
13618 ui_out_field_string
13620 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13624 ui_out_field_string
13626 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13631 return PRINT_UNKNOWN;
13635 momentary_bkpt_print_mention (struct breakpoint *b)
13637 /* Nothing to mention. These breakpoints are internal. */
13640 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13642 It gets cleared already on the removal of the first one of such placed
13643 breakpoints. This is OK as they get all removed altogether. */
13646 longjmp_bkpt_dtor (struct breakpoint *self)
13648 struct thread_info *tp = find_thread_id (self->thread);
13651 tp->initiating_frame = null_frame_id;
13653 momentary_breakpoint_ops.dtor (self);
13656 /* Specific methods for probe breakpoints. */
13659 bkpt_probe_insert_location (struct bp_location *bl)
13661 int v = bkpt_insert_location (bl);
13665 /* The insertion was successful, now let's set the probe's semaphore
13667 if (bl->probe.probe->pops->set_semaphore != NULL)
13668 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13677 bkpt_probe_remove_location (struct bp_location *bl)
13679 /* Let's clear the semaphore before removing the location. */
13680 if (bl->probe.probe->pops->clear_semaphore != NULL)
13681 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13685 return bkpt_remove_location (bl);
13689 bkpt_probe_create_sals_from_address (char **arg,
13690 struct linespec_result *canonical,
13691 enum bptype type_wanted,
13692 char *addr_start, char **copy_arg)
13694 struct linespec_sals lsal;
13696 lsal.sals = parse_probes (arg, canonical);
13698 *copy_arg = xstrdup (canonical->addr_string);
13699 lsal.canonical = xstrdup (*copy_arg);
13701 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13705 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13706 struct symtabs_and_lines *sals)
13708 *sals = parse_probes (s, NULL);
13710 error (_("probe not found"));
13713 /* The breakpoint_ops structure to be used in tracepoints. */
13716 tracepoint_re_set (struct breakpoint *b)
13718 breakpoint_re_set_default (b);
13722 tracepoint_breakpoint_hit (const struct bp_location *bl,
13723 struct address_space *aspace, CORE_ADDR bp_addr,
13724 const struct target_waitstatus *ws)
13726 /* By definition, the inferior does not report stops at
13732 tracepoint_print_one_detail (const struct breakpoint *self,
13733 struct ui_out *uiout)
13735 struct tracepoint *tp = (struct tracepoint *) self;
13736 if (tp->static_trace_marker_id)
13738 gdb_assert (self->type == bp_static_tracepoint);
13740 ui_out_text (uiout, "\tmarker id is ");
13741 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13742 tp->static_trace_marker_id);
13743 ui_out_text (uiout, "\n");
13748 tracepoint_print_mention (struct breakpoint *b)
13750 if (ui_out_is_mi_like_p (current_uiout))
13755 case bp_tracepoint:
13756 printf_filtered (_("Tracepoint"));
13757 printf_filtered (_(" %d"), b->number);
13759 case bp_fast_tracepoint:
13760 printf_filtered (_("Fast tracepoint"));
13761 printf_filtered (_(" %d"), b->number);
13763 case bp_static_tracepoint:
13764 printf_filtered (_("Static tracepoint"));
13765 printf_filtered (_(" %d"), b->number);
13768 internal_error (__FILE__, __LINE__,
13769 _("unhandled tracepoint type %d"), (int) b->type);
13776 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13778 struct tracepoint *tp = (struct tracepoint *) self;
13780 if (self->type == bp_fast_tracepoint)
13781 fprintf_unfiltered (fp, "ftrace");
13782 if (self->type == bp_static_tracepoint)
13783 fprintf_unfiltered (fp, "strace");
13784 else if (self->type == bp_tracepoint)
13785 fprintf_unfiltered (fp, "trace");
13787 internal_error (__FILE__, __LINE__,
13788 _("unhandled tracepoint type %d"), (int) self->type);
13790 fprintf_unfiltered (fp, " %s", self->addr_string);
13791 print_recreate_thread (self, fp);
13793 if (tp->pass_count)
13794 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13798 tracepoint_create_sals_from_address (char **arg,
13799 struct linespec_result *canonical,
13800 enum bptype type_wanted,
13801 char *addr_start, char **copy_arg)
13803 create_sals_from_address_default (arg, canonical, type_wanted,
13804 addr_start, copy_arg);
13808 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13809 struct linespec_result *canonical,
13811 char *extra_string,
13812 enum bptype type_wanted,
13813 enum bpdisp disposition,
13815 int task, int ignore_count,
13816 const struct breakpoint_ops *ops,
13817 int from_tty, int enabled,
13818 int internal, unsigned flags)
13820 create_breakpoints_sal_default (gdbarch, canonical,
13821 cond_string, extra_string,
13823 disposition, thread, task,
13824 ignore_count, ops, from_tty,
13825 enabled, internal, flags);
13829 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13830 struct symtabs_and_lines *sals)
13832 decode_linespec_default (b, s, sals);
13835 struct breakpoint_ops tracepoint_breakpoint_ops;
13837 /* The breakpoint_ops structure to be use on tracepoints placed in a
13841 tracepoint_probe_create_sals_from_address (char **arg,
13842 struct linespec_result *canonical,
13843 enum bptype type_wanted,
13844 char *addr_start, char **copy_arg)
13846 /* We use the same method for breakpoint on probes. */
13847 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13848 addr_start, copy_arg);
13852 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13853 struct symtabs_and_lines *sals)
13855 /* We use the same method for breakpoint on probes. */
13856 bkpt_probe_decode_linespec (b, s, sals);
13859 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13861 /* Dprintf breakpoint_ops methods. */
13864 dprintf_re_set (struct breakpoint *b)
13866 breakpoint_re_set_default (b);
13868 /* This breakpoint could have been pending, and be resolved now, and
13869 if so, we should now have the extra string. If we don't, the
13870 dprintf was malformed when created, but we couldn't tell because
13871 we can't extract the extra string until the location is
13873 if (b->loc != NULL && b->extra_string == NULL)
13874 error (_("Format string required"));
13876 /* 1 - connect to target 1, that can run breakpoint commands.
13877 2 - create a dprintf, which resolves fine.
13878 3 - disconnect from target 1
13879 4 - connect to target 2, that can NOT run breakpoint commands.
13881 After steps #3/#4, you'll want the dprintf command list to
13882 be updated, because target 1 and 2 may well return different
13883 answers for target_can_run_breakpoint_commands().
13884 Given absence of finer grained resetting, we get to do
13885 it all the time. */
13886 if (b->extra_string != NULL)
13887 update_dprintf_command_list (b);
13890 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13893 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13895 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13897 print_recreate_thread (tp, fp);
13900 /* Implement the "after_condition_true" breakpoint_ops method for
13903 dprintf's are implemented with regular commands in their command
13904 list, but we run the commands here instead of before presenting the
13905 stop to the user, as dprintf's don't actually cause a stop. This
13906 also makes it so that the commands of multiple dprintfs at the same
13907 address are all handled. */
13910 dprintf_after_condition_true (struct bpstats *bs)
13912 struct cleanup *old_chain;
13913 struct bpstats tmp_bs = { NULL };
13914 struct bpstats *tmp_bs_p = &tmp_bs;
13916 /* dprintf's never cause a stop. This wasn't set in the
13917 check_status hook instead because that would make the dprintf's
13918 condition not be evaluated. */
13921 /* Run the command list here. Take ownership of it instead of
13922 copying. We never want these commands to run later in
13923 bpstat_do_actions, if a breakpoint that causes a stop happens to
13924 be set at same address as this dprintf, or even if running the
13925 commands here throws. */
13926 tmp_bs.commands = bs->commands;
13927 bs->commands = NULL;
13928 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13930 bpstat_do_actions_1 (&tmp_bs_p);
13932 /* 'tmp_bs.commands' will usually be NULL by now, but
13933 bpstat_do_actions_1 may return early without processing the whole
13935 do_cleanups (old_chain);
13938 /* The breakpoint_ops structure to be used on static tracepoints with
13942 strace_marker_create_sals_from_address (char **arg,
13943 struct linespec_result *canonical,
13944 enum bptype type_wanted,
13945 char *addr_start, char **copy_arg)
13947 struct linespec_sals lsal;
13949 lsal.sals = decode_static_tracepoint_spec (arg);
13951 *copy_arg = savestring (addr_start, *arg - addr_start);
13953 canonical->addr_string = xstrdup (*copy_arg);
13954 lsal.canonical = xstrdup (*copy_arg);
13955 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13959 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13960 struct linespec_result *canonical,
13962 char *extra_string,
13963 enum bptype type_wanted,
13964 enum bpdisp disposition,
13966 int task, int ignore_count,
13967 const struct breakpoint_ops *ops,
13968 int from_tty, int enabled,
13969 int internal, unsigned flags)
13972 struct linespec_sals *lsal = VEC_index (linespec_sals,
13973 canonical->sals, 0);
13975 /* If the user is creating a static tracepoint by marker id
13976 (strace -m MARKER_ID), then store the sals index, so that
13977 breakpoint_re_set can try to match up which of the newly
13978 found markers corresponds to this one, and, don't try to
13979 expand multiple locations for each sal, given than SALS
13980 already should contain all sals for MARKER_ID. */
13982 for (i = 0; i < lsal->sals.nelts; ++i)
13984 struct symtabs_and_lines expanded;
13985 struct tracepoint *tp;
13986 struct cleanup *old_chain;
13989 expanded.nelts = 1;
13990 expanded.sals = &lsal->sals.sals[i];
13992 addr_string = xstrdup (canonical->addr_string);
13993 old_chain = make_cleanup (xfree, addr_string);
13995 tp = XCNEW (struct tracepoint);
13996 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13998 cond_string, extra_string,
13999 type_wanted, disposition,
14000 thread, task, ignore_count, ops,
14001 from_tty, enabled, internal, flags,
14002 canonical->special_display);
14003 /* Given that its possible to have multiple markers with
14004 the same string id, if the user is creating a static
14005 tracepoint by marker id ("strace -m MARKER_ID"), then
14006 store the sals index, so that breakpoint_re_set can
14007 try to match up which of the newly found markers
14008 corresponds to this one */
14009 tp->static_trace_marker_id_idx = i;
14011 install_breakpoint (internal, &tp->base, 0);
14013 discard_cleanups (old_chain);
14018 strace_marker_decode_linespec (struct breakpoint *b, char **s,
14019 struct symtabs_and_lines *sals)
14021 struct tracepoint *tp = (struct tracepoint *) b;
14023 *sals = decode_static_tracepoint_spec (s);
14024 if (sals->nelts > tp->static_trace_marker_id_idx)
14026 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
14030 error (_("marker %s not found"), tp->static_trace_marker_id);
14033 static struct breakpoint_ops strace_marker_breakpoint_ops;
14036 strace_marker_p (struct breakpoint *b)
14038 return b->ops == &strace_marker_breakpoint_ops;
14041 /* Delete a breakpoint and clean up all traces of it in the data
14045 delete_breakpoint (struct breakpoint *bpt)
14047 struct breakpoint *b;
14049 gdb_assert (bpt != NULL);
14051 /* Has this bp already been deleted? This can happen because
14052 multiple lists can hold pointers to bp's. bpstat lists are
14055 One example of this happening is a watchpoint's scope bp. When
14056 the scope bp triggers, we notice that the watchpoint is out of
14057 scope, and delete it. We also delete its scope bp. But the
14058 scope bp is marked "auto-deleting", and is already on a bpstat.
14059 That bpstat is then checked for auto-deleting bp's, which are
14062 A real solution to this problem might involve reference counts in
14063 bp's, and/or giving them pointers back to their referencing
14064 bpstat's, and teaching delete_breakpoint to only free a bp's
14065 storage when no more references were extent. A cheaper bandaid
14067 if (bpt->type == bp_none)
14070 /* At least avoid this stale reference until the reference counting
14071 of breakpoints gets resolved. */
14072 if (bpt->related_breakpoint != bpt)
14074 struct breakpoint *related;
14075 struct watchpoint *w;
14077 if (bpt->type == bp_watchpoint_scope)
14078 w = (struct watchpoint *) bpt->related_breakpoint;
14079 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
14080 w = (struct watchpoint *) bpt;
14084 watchpoint_del_at_next_stop (w);
14086 /* Unlink bpt from the bpt->related_breakpoint ring. */
14087 for (related = bpt; related->related_breakpoint != bpt;
14088 related = related->related_breakpoint);
14089 related->related_breakpoint = bpt->related_breakpoint;
14090 bpt->related_breakpoint = bpt;
14093 /* watch_command_1 creates a watchpoint but only sets its number if
14094 update_watchpoint succeeds in creating its bp_locations. If there's
14095 a problem in that process, we'll be asked to delete the half-created
14096 watchpoint. In that case, don't announce the deletion. */
14098 observer_notify_breakpoint_deleted (bpt);
14100 if (breakpoint_chain == bpt)
14101 breakpoint_chain = bpt->next;
14103 ALL_BREAKPOINTS (b)
14104 if (b->next == bpt)
14106 b->next = bpt->next;
14110 /* Be sure no bpstat's are pointing at the breakpoint after it's
14112 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14113 in all threads for now. Note that we cannot just remove bpstats
14114 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14115 commands are associated with the bpstat; if we remove it here,
14116 then the later call to bpstat_do_actions (&stop_bpstat); in
14117 event-top.c won't do anything, and temporary breakpoints with
14118 commands won't work. */
14120 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
14122 /* Now that breakpoint is removed from breakpoint list, update the
14123 global location list. This will remove locations that used to
14124 belong to this breakpoint. Do this before freeing the breakpoint
14125 itself, since remove_breakpoint looks at location's owner. It
14126 might be better design to have location completely
14127 self-contained, but it's not the case now. */
14128 update_global_location_list (UGLL_DONT_INSERT);
14130 bpt->ops->dtor (bpt);
14131 /* On the chance that someone will soon try again to delete this
14132 same bp, we mark it as deleted before freeing its storage. */
14133 bpt->type = bp_none;
14138 do_delete_breakpoint_cleanup (void *b)
14140 delete_breakpoint (b);
14144 make_cleanup_delete_breakpoint (struct breakpoint *b)
14146 return make_cleanup (do_delete_breakpoint_cleanup, b);
14149 /* Iterator function to call a user-provided callback function once
14150 for each of B and its related breakpoints. */
14153 iterate_over_related_breakpoints (struct breakpoint *b,
14154 void (*function) (struct breakpoint *,
14158 struct breakpoint *related;
14163 struct breakpoint *next;
14165 /* FUNCTION may delete RELATED. */
14166 next = related->related_breakpoint;
14168 if (next == related)
14170 /* RELATED is the last ring entry. */
14171 function (related, data);
14173 /* FUNCTION may have deleted it, so we'd never reach back to
14174 B. There's nothing left to do anyway, so just break
14179 function (related, data);
14183 while (related != b);
14187 do_delete_breakpoint (struct breakpoint *b, void *ignore)
14189 delete_breakpoint (b);
14192 /* A callback for map_breakpoint_numbers that calls
14193 delete_breakpoint. */
14196 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
14198 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
14202 delete_command (char *arg, int from_tty)
14204 struct breakpoint *b, *b_tmp;
14210 int breaks_to_delete = 0;
14212 /* Delete all breakpoints if no argument. Do not delete
14213 internal breakpoints, these have to be deleted with an
14214 explicit breakpoint number argument. */
14215 ALL_BREAKPOINTS (b)
14216 if (user_breakpoint_p (b))
14218 breaks_to_delete = 1;
14222 /* Ask user only if there are some breakpoints to delete. */
14224 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
14226 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14227 if (user_breakpoint_p (b))
14228 delete_breakpoint (b);
14232 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14236 all_locations_are_pending (struct bp_location *loc)
14238 for (; loc; loc = loc->next)
14239 if (!loc->shlib_disabled
14240 && !loc->pspace->executing_startup)
14245 /* Subroutine of update_breakpoint_locations to simplify it.
14246 Return non-zero if multiple fns in list LOC have the same name.
14247 Null names are ignored. */
14250 ambiguous_names_p (struct bp_location *loc)
14252 struct bp_location *l;
14253 htab_t htab = htab_create_alloc (13, htab_hash_string,
14254 (int (*) (const void *,
14255 const void *)) streq,
14256 NULL, xcalloc, xfree);
14258 for (l = loc; l != NULL; l = l->next)
14261 const char *name = l->function_name;
14263 /* Allow for some names to be NULL, ignore them. */
14267 slot = (const char **) htab_find_slot (htab, (const void *) name,
14269 /* NOTE: We can assume slot != NULL here because xcalloc never
14273 htab_delete (htab);
14279 htab_delete (htab);
14283 /* When symbols change, it probably means the sources changed as well,
14284 and it might mean the static tracepoint markers are no longer at
14285 the same address or line numbers they used to be at last we
14286 checked. Losing your static tracepoints whenever you rebuild is
14287 undesirable. This function tries to resync/rematch gdb static
14288 tracepoints with the markers on the target, for static tracepoints
14289 that have not been set by marker id. Static tracepoint that have
14290 been set by marker id are reset by marker id in breakpoint_re_set.
14293 1) For a tracepoint set at a specific address, look for a marker at
14294 the old PC. If one is found there, assume to be the same marker.
14295 If the name / string id of the marker found is different from the
14296 previous known name, assume that means the user renamed the marker
14297 in the sources, and output a warning.
14299 2) For a tracepoint set at a given line number, look for a marker
14300 at the new address of the old line number. If one is found there,
14301 assume to be the same marker. If the name / string id of the
14302 marker found is different from the previous known name, assume that
14303 means the user renamed the marker in the sources, and output a
14306 3) If a marker is no longer found at the same address or line, it
14307 may mean the marker no longer exists. But it may also just mean
14308 the code changed a bit. Maybe the user added a few lines of code
14309 that made the marker move up or down (in line number terms). Ask
14310 the target for info about the marker with the string id as we knew
14311 it. If found, update line number and address in the matching
14312 static tracepoint. This will get confused if there's more than one
14313 marker with the same ID (possible in UST, although unadvised
14314 precisely because it confuses tools). */
14316 static struct symtab_and_line
14317 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14319 struct tracepoint *tp = (struct tracepoint *) b;
14320 struct static_tracepoint_marker marker;
14325 find_line_pc (sal.symtab, sal.line, &pc);
14327 if (target_static_tracepoint_marker_at (pc, &marker))
14329 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14330 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14332 tp->static_trace_marker_id, marker.str_id);
14334 xfree (tp->static_trace_marker_id);
14335 tp->static_trace_marker_id = xstrdup (marker.str_id);
14336 release_static_tracepoint_marker (&marker);
14341 /* Old marker wasn't found on target at lineno. Try looking it up
14343 if (!sal.explicit_pc
14345 && sal.symtab != NULL
14346 && tp->static_trace_marker_id != NULL)
14348 VEC(static_tracepoint_marker_p) *markers;
14351 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14353 if (!VEC_empty(static_tracepoint_marker_p, markers))
14355 struct symtab_and_line sal2;
14356 struct symbol *sym;
14357 struct static_tracepoint_marker *tpmarker;
14358 struct ui_out *uiout = current_uiout;
14360 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14362 xfree (tp->static_trace_marker_id);
14363 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14365 warning (_("marker for static tracepoint %d (%s) not "
14366 "found at previous line number"),
14367 b->number, tp->static_trace_marker_id);
14371 sal2.pc = tpmarker->address;
14373 sal2 = find_pc_line (tpmarker->address, 0);
14374 sym = find_pc_sect_function (tpmarker->address, NULL);
14375 ui_out_text (uiout, "Now in ");
14378 ui_out_field_string (uiout, "func",
14379 SYMBOL_PRINT_NAME (sym));
14380 ui_out_text (uiout, " at ");
14382 ui_out_field_string (uiout, "file",
14383 symtab_to_filename_for_display (sal2.symtab));
14384 ui_out_text (uiout, ":");
14386 if (ui_out_is_mi_like_p (uiout))
14388 const char *fullname = symtab_to_fullname (sal2.symtab);
14390 ui_out_field_string (uiout, "fullname", fullname);
14393 ui_out_field_int (uiout, "line", sal2.line);
14394 ui_out_text (uiout, "\n");
14396 b->loc->line_number = sal2.line;
14397 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14399 xfree (b->addr_string);
14400 b->addr_string = xstrprintf ("%s:%d",
14401 symtab_to_filename_for_display (sal2.symtab),
14402 b->loc->line_number);
14404 /* Might be nice to check if function changed, and warn if
14407 release_static_tracepoint_marker (tpmarker);
14413 /* Returns 1 iff locations A and B are sufficiently same that
14414 we don't need to report breakpoint as changed. */
14417 locations_are_equal (struct bp_location *a, struct bp_location *b)
14421 if (a->address != b->address)
14424 if (a->shlib_disabled != b->shlib_disabled)
14427 if (a->enabled != b->enabled)
14434 if ((a == NULL) != (b == NULL))
14440 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14441 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14442 a ranged breakpoint. */
14445 update_breakpoint_locations (struct breakpoint *b,
14446 struct symtabs_and_lines sals,
14447 struct symtabs_and_lines sals_end)
14450 struct bp_location *existing_locations = b->loc;
14452 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14454 /* Ranged breakpoints have only one start location and one end
14456 b->enable_state = bp_disabled;
14457 update_global_location_list (UGLL_MAY_INSERT);
14458 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14459 "multiple locations found\n"),
14464 /* If there's no new locations, and all existing locations are
14465 pending, don't do anything. This optimizes the common case where
14466 all locations are in the same shared library, that was unloaded.
14467 We'd like to retain the location, so that when the library is
14468 loaded again, we don't loose the enabled/disabled status of the
14469 individual locations. */
14470 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14475 for (i = 0; i < sals.nelts; ++i)
14477 struct bp_location *new_loc;
14479 switch_to_program_space_and_thread (sals.sals[i].pspace);
14481 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14483 /* Reparse conditions, they might contain references to the
14485 if (b->cond_string != NULL)
14488 volatile struct gdb_exception e;
14490 s = b->cond_string;
14491 TRY_CATCH (e, RETURN_MASK_ERROR)
14493 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14494 block_for_pc (sals.sals[i].pc),
14499 warning (_("failed to reevaluate condition "
14500 "for breakpoint %d: %s"),
14501 b->number, e.message);
14502 new_loc->enabled = 0;
14506 if (sals_end.nelts)
14508 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14510 new_loc->length = end - sals.sals[0].pc + 1;
14514 /* If possible, carry over 'disable' status from existing
14517 struct bp_location *e = existing_locations;
14518 /* If there are multiple breakpoints with the same function name,
14519 e.g. for inline functions, comparing function names won't work.
14520 Instead compare pc addresses; this is just a heuristic as things
14521 may have moved, but in practice it gives the correct answer
14522 often enough until a better solution is found. */
14523 int have_ambiguous_names = ambiguous_names_p (b->loc);
14525 for (; e; e = e->next)
14527 if (!e->enabled && e->function_name)
14529 struct bp_location *l = b->loc;
14530 if (have_ambiguous_names)
14532 for (; l; l = l->next)
14533 if (breakpoint_locations_match (e, l))
14541 for (; l; l = l->next)
14542 if (l->function_name
14543 && strcmp (e->function_name, l->function_name) == 0)
14553 if (!locations_are_equal (existing_locations, b->loc))
14554 observer_notify_breakpoint_modified (b);
14556 update_global_location_list (UGLL_MAY_INSERT);
14559 /* Find the SaL locations corresponding to the given ADDR_STRING.
14560 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14562 static struct symtabs_and_lines
14563 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14566 struct symtabs_and_lines sals = {0};
14567 volatile struct gdb_exception e;
14569 gdb_assert (b->ops != NULL);
14572 TRY_CATCH (e, RETURN_MASK_ERROR)
14574 b->ops->decode_linespec (b, &s, &sals);
14578 int not_found_and_ok = 0;
14579 /* For pending breakpoints, it's expected that parsing will
14580 fail until the right shared library is loaded. User has
14581 already told to create pending breakpoints and don't need
14582 extra messages. If breakpoint is in bp_shlib_disabled
14583 state, then user already saw the message about that
14584 breakpoint being disabled, and don't want to see more
14586 if (e.error == NOT_FOUND_ERROR
14587 && (b->condition_not_parsed
14588 || (b->loc && b->loc->shlib_disabled)
14589 || (b->loc && b->loc->pspace->executing_startup)
14590 || b->enable_state == bp_disabled))
14591 not_found_and_ok = 1;
14593 if (!not_found_and_ok)
14595 /* We surely don't want to warn about the same breakpoint
14596 10 times. One solution, implemented here, is disable
14597 the breakpoint on error. Another solution would be to
14598 have separate 'warning emitted' flag. Since this
14599 happens only when a binary has changed, I don't know
14600 which approach is better. */
14601 b->enable_state = bp_disabled;
14602 throw_exception (e);
14606 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14610 for (i = 0; i < sals.nelts; ++i)
14611 resolve_sal_pc (&sals.sals[i]);
14612 if (b->condition_not_parsed && s && s[0])
14614 char *cond_string, *extra_string;
14617 find_condition_and_thread (s, sals.sals[0].pc,
14618 &cond_string, &thread, &task,
14621 b->cond_string = cond_string;
14622 b->thread = thread;
14625 b->extra_string = extra_string;
14626 b->condition_not_parsed = 0;
14629 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14630 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14640 /* The default re_set method, for typical hardware or software
14641 breakpoints. Reevaluate the breakpoint and recreate its
14645 breakpoint_re_set_default (struct breakpoint *b)
14648 struct symtabs_and_lines sals, sals_end;
14649 struct symtabs_and_lines expanded = {0};
14650 struct symtabs_and_lines expanded_end = {0};
14652 sals = addr_string_to_sals (b, b->addr_string, &found);
14655 make_cleanup (xfree, sals.sals);
14659 if (b->addr_string_range_end)
14661 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14664 make_cleanup (xfree, sals_end.sals);
14665 expanded_end = sals_end;
14669 update_breakpoint_locations (b, expanded, expanded_end);
14672 /* Default method for creating SALs from an address string. It basically
14673 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14676 create_sals_from_address_default (char **arg,
14677 struct linespec_result *canonical,
14678 enum bptype type_wanted,
14679 char *addr_start, char **copy_arg)
14681 parse_breakpoint_sals (arg, canonical);
14684 /* Call create_breakpoints_sal for the given arguments. This is the default
14685 function for the `create_breakpoints_sal' method of
14689 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14690 struct linespec_result *canonical,
14692 char *extra_string,
14693 enum bptype type_wanted,
14694 enum bpdisp disposition,
14696 int task, int ignore_count,
14697 const struct breakpoint_ops *ops,
14698 int from_tty, int enabled,
14699 int internal, unsigned flags)
14701 create_breakpoints_sal (gdbarch, canonical, cond_string,
14703 type_wanted, disposition,
14704 thread, task, ignore_count, ops, from_tty,
14705 enabled, internal, flags);
14708 /* Decode the line represented by S by calling decode_line_full. This is the
14709 default function for the `decode_linespec' method of breakpoint_ops. */
14712 decode_linespec_default (struct breakpoint *b, char **s,
14713 struct symtabs_and_lines *sals)
14715 struct linespec_result canonical;
14717 init_linespec_result (&canonical);
14718 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14719 (struct symtab *) NULL, 0,
14720 &canonical, multiple_symbols_all,
14723 /* We should get 0 or 1 resulting SALs. */
14724 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14726 if (VEC_length (linespec_sals, canonical.sals) > 0)
14728 struct linespec_sals *lsal;
14730 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14731 *sals = lsal->sals;
14732 /* Arrange it so the destructor does not free the
14734 lsal->sals.sals = NULL;
14737 destroy_linespec_result (&canonical);
14740 /* Prepare the global context for a re-set of breakpoint B. */
14742 static struct cleanup *
14743 prepare_re_set_context (struct breakpoint *b)
14745 struct cleanup *cleanups;
14747 input_radix = b->input_radix;
14748 cleanups = save_current_space_and_thread ();
14749 if (b->pspace != NULL)
14750 switch_to_program_space_and_thread (b->pspace);
14751 set_language (b->language);
14756 /* Reset a breakpoint given it's struct breakpoint * BINT.
14757 The value we return ends up being the return value from catch_errors.
14758 Unused in this case. */
14761 breakpoint_re_set_one (void *bint)
14763 /* Get past catch_errs. */
14764 struct breakpoint *b = (struct breakpoint *) bint;
14765 struct cleanup *cleanups;
14767 cleanups = prepare_re_set_context (b);
14768 b->ops->re_set (b);
14769 do_cleanups (cleanups);
14773 /* Re-set all breakpoints after symbols have been re-loaded. */
14775 breakpoint_re_set (void)
14777 struct breakpoint *b, *b_tmp;
14778 enum language save_language;
14779 int save_input_radix;
14780 struct cleanup *old_chain;
14782 save_language = current_language->la_language;
14783 save_input_radix = input_radix;
14784 old_chain = save_current_program_space ();
14786 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14788 /* Format possible error msg. */
14789 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14791 struct cleanup *cleanups = make_cleanup (xfree, message);
14792 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14793 do_cleanups (cleanups);
14795 set_language (save_language);
14796 input_radix = save_input_radix;
14798 jit_breakpoint_re_set ();
14800 do_cleanups (old_chain);
14802 create_overlay_event_breakpoint ();
14803 create_longjmp_master_breakpoint ();
14804 create_std_terminate_master_breakpoint ();
14805 create_exception_master_breakpoint ();
14808 /* Reset the thread number of this breakpoint:
14810 - If the breakpoint is for all threads, leave it as-is.
14811 - Else, reset it to the current thread for inferior_ptid. */
14813 breakpoint_re_set_thread (struct breakpoint *b)
14815 if (b->thread != -1)
14817 if (in_thread_list (inferior_ptid))
14818 b->thread = pid_to_thread_id (inferior_ptid);
14820 /* We're being called after following a fork. The new fork is
14821 selected as current, and unless this was a vfork will have a
14822 different program space from the original thread. Reset that
14824 b->loc->pspace = current_program_space;
14828 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14829 If from_tty is nonzero, it prints a message to that effect,
14830 which ends with a period (no newline). */
14833 set_ignore_count (int bptnum, int count, int from_tty)
14835 struct breakpoint *b;
14840 ALL_BREAKPOINTS (b)
14841 if (b->number == bptnum)
14843 if (is_tracepoint (b))
14845 if (from_tty && count != 0)
14846 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14851 b->ignore_count = count;
14855 printf_filtered (_("Will stop next time "
14856 "breakpoint %d is reached."),
14858 else if (count == 1)
14859 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14862 printf_filtered (_("Will ignore next %d "
14863 "crossings of breakpoint %d."),
14866 observer_notify_breakpoint_modified (b);
14870 error (_("No breakpoint number %d."), bptnum);
14873 /* Command to set ignore-count of breakpoint N to COUNT. */
14876 ignore_command (char *args, int from_tty)
14882 error_no_arg (_("a breakpoint number"));
14884 num = get_number (&p);
14886 error (_("bad breakpoint number: '%s'"), args);
14888 error (_("Second argument (specified ignore-count) is missing."));
14890 set_ignore_count (num,
14891 longest_to_int (value_as_long (parse_and_eval (p))),
14894 printf_filtered ("\n");
14897 /* Call FUNCTION on each of the breakpoints
14898 whose numbers are given in ARGS. */
14901 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14906 struct breakpoint *b, *tmp;
14908 struct get_number_or_range_state state;
14910 if (args == 0 || *args == '\0')
14911 error_no_arg (_("one or more breakpoint numbers"));
14913 init_number_or_range (&state, args);
14915 while (!state.finished)
14917 const char *p = state.string;
14921 num = get_number_or_range (&state);
14924 warning (_("bad breakpoint number at or near '%s'"), p);
14928 ALL_BREAKPOINTS_SAFE (b, tmp)
14929 if (b->number == num)
14932 function (b, data);
14936 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14941 static struct bp_location *
14942 find_location_by_number (char *number)
14944 char *dot = strchr (number, '.');
14948 struct breakpoint *b;
14949 struct bp_location *loc;
14954 bp_num = get_number (&p1);
14956 error (_("Bad breakpoint number '%s'"), number);
14958 ALL_BREAKPOINTS (b)
14959 if (b->number == bp_num)
14964 if (!b || b->number != bp_num)
14965 error (_("Bad breakpoint number '%s'"), number);
14968 loc_num = get_number (&p1);
14970 error (_("Bad breakpoint location number '%s'"), number);
14974 for (;loc_num && loc; --loc_num, loc = loc->next)
14977 error (_("Bad breakpoint location number '%s'"), dot+1);
14983 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14984 If from_tty is nonzero, it prints a message to that effect,
14985 which ends with a period (no newline). */
14988 disable_breakpoint (struct breakpoint *bpt)
14990 /* Never disable a watchpoint scope breakpoint; we want to
14991 hit them when we leave scope so we can delete both the
14992 watchpoint and its scope breakpoint at that time. */
14993 if (bpt->type == bp_watchpoint_scope)
14996 bpt->enable_state = bp_disabled;
14998 /* Mark breakpoint locations modified. */
14999 mark_breakpoint_modified (bpt);
15001 if (target_supports_enable_disable_tracepoint ()
15002 && current_trace_status ()->running && is_tracepoint (bpt))
15004 struct bp_location *location;
15006 for (location = bpt->loc; location; location = location->next)
15007 target_disable_tracepoint (location);
15010 update_global_location_list (UGLL_DONT_INSERT);
15012 observer_notify_breakpoint_modified (bpt);
15015 /* A callback for iterate_over_related_breakpoints. */
15018 do_disable_breakpoint (struct breakpoint *b, void *ignore)
15020 disable_breakpoint (b);
15023 /* A callback for map_breakpoint_numbers that calls
15024 disable_breakpoint. */
15027 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
15029 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
15033 disable_command (char *args, int from_tty)
15037 struct breakpoint *bpt;
15039 ALL_BREAKPOINTS (bpt)
15040 if (user_breakpoint_p (bpt))
15041 disable_breakpoint (bpt);
15045 char *num = extract_arg (&args);
15049 if (strchr (num, '.'))
15051 struct bp_location *loc = find_location_by_number (num);
15058 mark_breakpoint_location_modified (loc);
15060 if (target_supports_enable_disable_tracepoint ()
15061 && current_trace_status ()->running && loc->owner
15062 && is_tracepoint (loc->owner))
15063 target_disable_tracepoint (loc);
15065 update_global_location_list (UGLL_DONT_INSERT);
15068 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
15069 num = extract_arg (&args);
15075 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
15078 int target_resources_ok;
15080 if (bpt->type == bp_hardware_breakpoint)
15083 i = hw_breakpoint_used_count ();
15084 target_resources_ok =
15085 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
15087 if (target_resources_ok == 0)
15088 error (_("No hardware breakpoint support in the target."));
15089 else if (target_resources_ok < 0)
15090 error (_("Hardware breakpoints used exceeds limit."));
15093 if (is_watchpoint (bpt))
15095 /* Initialize it just to avoid a GCC false warning. */
15096 enum enable_state orig_enable_state = 0;
15097 volatile struct gdb_exception e;
15099 TRY_CATCH (e, RETURN_MASK_ALL)
15101 struct watchpoint *w = (struct watchpoint *) bpt;
15103 orig_enable_state = bpt->enable_state;
15104 bpt->enable_state = bp_enabled;
15105 update_watchpoint (w, 1 /* reparse */);
15109 bpt->enable_state = orig_enable_state;
15110 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
15116 bpt->enable_state = bp_enabled;
15118 /* Mark breakpoint locations modified. */
15119 mark_breakpoint_modified (bpt);
15121 if (target_supports_enable_disable_tracepoint ()
15122 && current_trace_status ()->running && is_tracepoint (bpt))
15124 struct bp_location *location;
15126 for (location = bpt->loc; location; location = location->next)
15127 target_enable_tracepoint (location);
15130 bpt->disposition = disposition;
15131 bpt->enable_count = count;
15132 update_global_location_list (UGLL_MAY_INSERT);
15134 observer_notify_breakpoint_modified (bpt);
15139 enable_breakpoint (struct breakpoint *bpt)
15141 enable_breakpoint_disp (bpt, bpt->disposition, 0);
15145 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
15147 enable_breakpoint (bpt);
15150 /* A callback for map_breakpoint_numbers that calls
15151 enable_breakpoint. */
15154 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
15156 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
15159 /* The enable command enables the specified breakpoints (or all defined
15160 breakpoints) so they once again become (or continue to be) effective
15161 in stopping the inferior. */
15164 enable_command (char *args, int from_tty)
15168 struct breakpoint *bpt;
15170 ALL_BREAKPOINTS (bpt)
15171 if (user_breakpoint_p (bpt))
15172 enable_breakpoint (bpt);
15176 char *num = extract_arg (&args);
15180 if (strchr (num, '.'))
15182 struct bp_location *loc = find_location_by_number (num);
15189 mark_breakpoint_location_modified (loc);
15191 if (target_supports_enable_disable_tracepoint ()
15192 && current_trace_status ()->running && loc->owner
15193 && is_tracepoint (loc->owner))
15194 target_enable_tracepoint (loc);
15196 update_global_location_list (UGLL_MAY_INSERT);
15199 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15200 num = extract_arg (&args);
15205 /* This struct packages up disposition data for application to multiple
15215 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15217 struct disp_data disp_data = *(struct disp_data *) arg;
15219 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15223 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15225 struct disp_data disp = { disp_disable, 1 };
15227 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15231 enable_once_command (char *args, int from_tty)
15233 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15237 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15239 struct disp_data disp = { disp_disable, *(int *) countptr };
15241 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15245 enable_count_command (char *args, int from_tty)
15250 error_no_arg (_("hit count"));
15252 count = get_number (&args);
15254 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15258 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15260 struct disp_data disp = { disp_del, 1 };
15262 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15266 enable_delete_command (char *args, int from_tty)
15268 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15272 set_breakpoint_cmd (char *args, int from_tty)
15277 show_breakpoint_cmd (char *args, int from_tty)
15281 /* Invalidate last known value of any hardware watchpoint if
15282 the memory which that value represents has been written to by
15286 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15287 CORE_ADDR addr, ssize_t len,
15288 const bfd_byte *data)
15290 struct breakpoint *bp;
15292 ALL_BREAKPOINTS (bp)
15293 if (bp->enable_state == bp_enabled
15294 && bp->type == bp_hardware_watchpoint)
15296 struct watchpoint *wp = (struct watchpoint *) bp;
15298 if (wp->val_valid && wp->val)
15300 struct bp_location *loc;
15302 for (loc = bp->loc; loc != NULL; loc = loc->next)
15303 if (loc->loc_type == bp_loc_hardware_watchpoint
15304 && loc->address + loc->length > addr
15305 && addr + len > loc->address)
15307 value_free (wp->val);
15315 /* Create and insert a breakpoint for software single step. */
15318 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15319 struct address_space *aspace,
15322 struct thread_info *tp = inferior_thread ();
15323 struct symtab_and_line sal;
15324 CORE_ADDR pc = next_pc;
15326 if (tp->control.single_step_breakpoints == NULL)
15328 tp->control.single_step_breakpoints
15329 = new_single_step_breakpoint (tp->num, gdbarch);
15332 sal = find_pc_line (pc, 0);
15334 sal.section = find_pc_overlay (pc);
15335 sal.explicit_pc = 1;
15336 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
15338 update_global_location_list (UGLL_INSERT);
15341 /* See breakpoint.h. */
15344 breakpoint_has_location_inserted_here (struct breakpoint *bp,
15345 struct address_space *aspace,
15348 struct bp_location *loc;
15350 for (loc = bp->loc; loc != NULL; loc = loc->next)
15352 && breakpoint_location_address_match (loc, aspace, pc))
15358 /* Check whether a software single-step breakpoint is inserted at
15362 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15365 struct breakpoint *bpt;
15367 ALL_BREAKPOINTS (bpt)
15369 if (bpt->type == bp_single_step
15370 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
15376 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15377 non-zero otherwise. */
15379 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15381 if (syscall_catchpoint_p (bp)
15382 && bp->enable_state != bp_disabled
15383 && bp->enable_state != bp_call_disabled)
15390 catch_syscall_enabled (void)
15392 struct catch_syscall_inferior_data *inf_data
15393 = get_catch_syscall_inferior_data (current_inferior ());
15395 return inf_data->total_syscalls_count != 0;
15399 catching_syscall_number (int syscall_number)
15401 struct breakpoint *bp;
15403 ALL_BREAKPOINTS (bp)
15404 if (is_syscall_catchpoint_enabled (bp))
15406 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15408 if (c->syscalls_to_be_caught)
15412 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15414 if (syscall_number == iter)
15424 /* Complete syscall names. Used by "catch syscall". */
15425 static VEC (char_ptr) *
15426 catch_syscall_completer (struct cmd_list_element *cmd,
15427 const char *text, const char *word)
15429 const char **list = get_syscall_names (get_current_arch ());
15430 VEC (char_ptr) *retlist
15431 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15437 /* Tracepoint-specific operations. */
15439 /* Set tracepoint count to NUM. */
15441 set_tracepoint_count (int num)
15443 tracepoint_count = num;
15444 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15448 trace_command (char *arg, int from_tty)
15450 struct breakpoint_ops *ops;
15451 const char *arg_cp = arg;
15453 if (arg && probe_linespec_to_ops (&arg_cp))
15454 ops = &tracepoint_probe_breakpoint_ops;
15456 ops = &tracepoint_breakpoint_ops;
15458 create_breakpoint (get_current_arch (),
15460 NULL, 0, NULL, 1 /* parse arg */,
15462 bp_tracepoint /* type_wanted */,
15463 0 /* Ignore count */,
15464 pending_break_support,
15468 0 /* internal */, 0);
15472 ftrace_command (char *arg, int from_tty)
15474 create_breakpoint (get_current_arch (),
15476 NULL, 0, NULL, 1 /* parse arg */,
15478 bp_fast_tracepoint /* type_wanted */,
15479 0 /* Ignore count */,
15480 pending_break_support,
15481 &tracepoint_breakpoint_ops,
15484 0 /* internal */, 0);
15487 /* strace command implementation. Creates a static tracepoint. */
15490 strace_command (char *arg, int from_tty)
15492 struct breakpoint_ops *ops;
15494 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15495 or with a normal static tracepoint. */
15496 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15497 ops = &strace_marker_breakpoint_ops;
15499 ops = &tracepoint_breakpoint_ops;
15501 create_breakpoint (get_current_arch (),
15503 NULL, 0, NULL, 1 /* parse arg */,
15505 bp_static_tracepoint /* type_wanted */,
15506 0 /* Ignore count */,
15507 pending_break_support,
15511 0 /* internal */, 0);
15514 /* Set up a fake reader function that gets command lines from a linked
15515 list that was acquired during tracepoint uploading. */
15517 static struct uploaded_tp *this_utp;
15518 static int next_cmd;
15521 read_uploaded_action (void)
15525 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15532 /* Given information about a tracepoint as recorded on a target (which
15533 can be either a live system or a trace file), attempt to create an
15534 equivalent GDB tracepoint. This is not a reliable process, since
15535 the target does not necessarily have all the information used when
15536 the tracepoint was originally defined. */
15538 struct tracepoint *
15539 create_tracepoint_from_upload (struct uploaded_tp *utp)
15541 char *addr_str, small_buf[100];
15542 struct tracepoint *tp;
15544 if (utp->at_string)
15545 addr_str = utp->at_string;
15548 /* In the absence of a source location, fall back to raw
15549 address. Since there is no way to confirm that the address
15550 means the same thing as when the trace was started, warn the
15552 warning (_("Uploaded tracepoint %d has no "
15553 "source location, using raw address"),
15555 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15556 addr_str = small_buf;
15559 /* There's not much we can do with a sequence of bytecodes. */
15560 if (utp->cond && !utp->cond_string)
15561 warning (_("Uploaded tracepoint %d condition "
15562 "has no source form, ignoring it"),
15565 if (!create_breakpoint (get_current_arch (),
15567 utp->cond_string, -1, NULL,
15568 0 /* parse cond/thread */,
15570 utp->type /* type_wanted */,
15571 0 /* Ignore count */,
15572 pending_break_support,
15573 &tracepoint_breakpoint_ops,
15575 utp->enabled /* enabled */,
15577 CREATE_BREAKPOINT_FLAGS_INSERTED))
15580 /* Get the tracepoint we just created. */
15581 tp = get_tracepoint (tracepoint_count);
15582 gdb_assert (tp != NULL);
15586 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15589 trace_pass_command (small_buf, 0);
15592 /* If we have uploaded versions of the original commands, set up a
15593 special-purpose "reader" function and call the usual command line
15594 reader, then pass the result to the breakpoint command-setting
15596 if (!VEC_empty (char_ptr, utp->cmd_strings))
15598 struct command_line *cmd_list;
15603 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15605 breakpoint_set_commands (&tp->base, cmd_list);
15607 else if (!VEC_empty (char_ptr, utp->actions)
15608 || !VEC_empty (char_ptr, utp->step_actions))
15609 warning (_("Uploaded tracepoint %d actions "
15610 "have no source form, ignoring them"),
15613 /* Copy any status information that might be available. */
15614 tp->base.hit_count = utp->hit_count;
15615 tp->traceframe_usage = utp->traceframe_usage;
15620 /* Print information on tracepoint number TPNUM_EXP, or all if
15624 tracepoints_info (char *args, int from_tty)
15626 struct ui_out *uiout = current_uiout;
15629 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15631 if (num_printed == 0)
15633 if (args == NULL || *args == '\0')
15634 ui_out_message (uiout, 0, "No tracepoints.\n");
15636 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15639 default_collect_info ();
15642 /* The 'enable trace' command enables tracepoints.
15643 Not supported by all targets. */
15645 enable_trace_command (char *args, int from_tty)
15647 enable_command (args, from_tty);
15650 /* The 'disable trace' command disables tracepoints.
15651 Not supported by all targets. */
15653 disable_trace_command (char *args, int from_tty)
15655 disable_command (args, from_tty);
15658 /* Remove a tracepoint (or all if no argument). */
15660 delete_trace_command (char *arg, int from_tty)
15662 struct breakpoint *b, *b_tmp;
15668 int breaks_to_delete = 0;
15670 /* Delete all breakpoints if no argument.
15671 Do not delete internal or call-dummy breakpoints, these
15672 have to be deleted with an explicit breakpoint number
15674 ALL_TRACEPOINTS (b)
15675 if (is_tracepoint (b) && user_breakpoint_p (b))
15677 breaks_to_delete = 1;
15681 /* Ask user only if there are some breakpoints to delete. */
15683 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15685 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15686 if (is_tracepoint (b) && user_breakpoint_p (b))
15687 delete_breakpoint (b);
15691 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15694 /* Helper function for trace_pass_command. */
15697 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15699 tp->pass_count = count;
15700 observer_notify_breakpoint_modified (&tp->base);
15702 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15703 tp->base.number, count);
15706 /* Set passcount for tracepoint.
15708 First command argument is passcount, second is tracepoint number.
15709 If tracepoint number omitted, apply to most recently defined.
15710 Also accepts special argument "all". */
15713 trace_pass_command (char *args, int from_tty)
15715 struct tracepoint *t1;
15716 unsigned int count;
15718 if (args == 0 || *args == 0)
15719 error (_("passcount command requires an "
15720 "argument (count + optional TP num)"));
15722 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15724 args = skip_spaces (args);
15725 if (*args && strncasecmp (args, "all", 3) == 0)
15727 struct breakpoint *b;
15729 args += 3; /* Skip special argument "all". */
15731 error (_("Junk at end of arguments."));
15733 ALL_TRACEPOINTS (b)
15735 t1 = (struct tracepoint *) b;
15736 trace_pass_set_count (t1, count, from_tty);
15739 else if (*args == '\0')
15741 t1 = get_tracepoint_by_number (&args, NULL);
15743 trace_pass_set_count (t1, count, from_tty);
15747 struct get_number_or_range_state state;
15749 init_number_or_range (&state, args);
15750 while (!state.finished)
15752 t1 = get_tracepoint_by_number (&args, &state);
15754 trace_pass_set_count (t1, count, from_tty);
15759 struct tracepoint *
15760 get_tracepoint (int num)
15762 struct breakpoint *t;
15764 ALL_TRACEPOINTS (t)
15765 if (t->number == num)
15766 return (struct tracepoint *) t;
15771 /* Find the tracepoint with the given target-side number (which may be
15772 different from the tracepoint number after disconnecting and
15775 struct tracepoint *
15776 get_tracepoint_by_number_on_target (int num)
15778 struct breakpoint *b;
15780 ALL_TRACEPOINTS (b)
15782 struct tracepoint *t = (struct tracepoint *) b;
15784 if (t->number_on_target == num)
15791 /* Utility: parse a tracepoint number and look it up in the list.
15792 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15793 If the argument is missing, the most recent tracepoint
15794 (tracepoint_count) is returned. */
15796 struct tracepoint *
15797 get_tracepoint_by_number (char **arg,
15798 struct get_number_or_range_state *state)
15800 struct breakpoint *t;
15802 char *instring = arg == NULL ? NULL : *arg;
15806 gdb_assert (!state->finished);
15807 tpnum = get_number_or_range (state);
15809 else if (arg == NULL || *arg == NULL || ! **arg)
15810 tpnum = tracepoint_count;
15812 tpnum = get_number (arg);
15816 if (instring && *instring)
15817 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15820 printf_filtered (_("No previous tracepoint\n"));
15824 ALL_TRACEPOINTS (t)
15825 if (t->number == tpnum)
15827 return (struct tracepoint *) t;
15830 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15835 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15837 if (b->thread != -1)
15838 fprintf_unfiltered (fp, " thread %d", b->thread);
15841 fprintf_unfiltered (fp, " task %d", b->task);
15843 fprintf_unfiltered (fp, "\n");
15846 /* Save information on user settable breakpoints (watchpoints, etc) to
15847 a new script file named FILENAME. If FILTER is non-NULL, call it
15848 on each breakpoint and only include the ones for which it returns
15852 save_breakpoints (char *filename, int from_tty,
15853 int (*filter) (const struct breakpoint *))
15855 struct breakpoint *tp;
15857 struct cleanup *cleanup;
15858 struct ui_file *fp;
15859 int extra_trace_bits = 0;
15861 if (filename == 0 || *filename == 0)
15862 error (_("Argument required (file name in which to save)"));
15864 /* See if we have anything to save. */
15865 ALL_BREAKPOINTS (tp)
15867 /* Skip internal and momentary breakpoints. */
15868 if (!user_breakpoint_p (tp))
15871 /* If we have a filter, only save the breakpoints it accepts. */
15872 if (filter && !filter (tp))
15877 if (is_tracepoint (tp))
15879 extra_trace_bits = 1;
15881 /* We can stop searching. */
15888 warning (_("Nothing to save."));
15892 filename = tilde_expand (filename);
15893 cleanup = make_cleanup (xfree, filename);
15894 fp = gdb_fopen (filename, "w");
15896 error (_("Unable to open file '%s' for saving (%s)"),
15897 filename, safe_strerror (errno));
15898 make_cleanup_ui_file_delete (fp);
15900 if (extra_trace_bits)
15901 save_trace_state_variables (fp);
15903 ALL_BREAKPOINTS (tp)
15905 /* Skip internal and momentary breakpoints. */
15906 if (!user_breakpoint_p (tp))
15909 /* If we have a filter, only save the breakpoints it accepts. */
15910 if (filter && !filter (tp))
15913 tp->ops->print_recreate (tp, fp);
15915 /* Note, we can't rely on tp->number for anything, as we can't
15916 assume the recreated breakpoint numbers will match. Use $bpnum
15919 if (tp->cond_string)
15920 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15922 if (tp->ignore_count)
15923 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15925 if (tp->type != bp_dprintf && tp->commands)
15927 volatile struct gdb_exception ex;
15929 fprintf_unfiltered (fp, " commands\n");
15931 ui_out_redirect (current_uiout, fp);
15932 TRY_CATCH (ex, RETURN_MASK_ALL)
15934 print_command_lines (current_uiout, tp->commands->commands, 2);
15936 ui_out_redirect (current_uiout, NULL);
15939 throw_exception (ex);
15941 fprintf_unfiltered (fp, " end\n");
15944 if (tp->enable_state == bp_disabled)
15945 fprintf_unfiltered (fp, "disable $bpnum\n");
15947 /* If this is a multi-location breakpoint, check if the locations
15948 should be individually disabled. Watchpoint locations are
15949 special, and not user visible. */
15950 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15952 struct bp_location *loc;
15955 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15957 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15961 if (extra_trace_bits && *default_collect)
15962 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15965 printf_filtered (_("Saved to file '%s'.\n"), filename);
15966 do_cleanups (cleanup);
15969 /* The `save breakpoints' command. */
15972 save_breakpoints_command (char *args, int from_tty)
15974 save_breakpoints (args, from_tty, NULL);
15977 /* The `save tracepoints' command. */
15980 save_tracepoints_command (char *args, int from_tty)
15982 save_breakpoints (args, from_tty, is_tracepoint);
15985 /* Create a vector of all tracepoints. */
15987 VEC(breakpoint_p) *
15988 all_tracepoints (void)
15990 VEC(breakpoint_p) *tp_vec = 0;
15991 struct breakpoint *tp;
15993 ALL_TRACEPOINTS (tp)
15995 VEC_safe_push (breakpoint_p, tp_vec, tp);
16002 /* This help string is used for the break, hbreak, tbreak and thbreak
16003 commands. It is defined as a macro to prevent duplication.
16004 COMMAND should be a string constant containing the name of the
16006 #define BREAK_ARGS_HELP(command) \
16007 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16008 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16009 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16010 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
16011 `-probe-dtrace' (for a DTrace probe).\n\
16012 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16013 If a line number is specified, break at start of code for that line.\n\
16014 If a function is specified, break at start of code for that function.\n\
16015 If an address is specified, break at that exact address.\n\
16016 With no LOCATION, uses current execution address of the selected\n\
16017 stack frame. This is useful for breaking on return to a stack frame.\n\
16019 THREADNUM is the number from \"info threads\".\n\
16020 CONDITION is a boolean expression.\n\
16022 Multiple breakpoints at one place are permitted, and useful if their\n\
16023 conditions are different.\n\
16025 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16027 /* List of subcommands for "catch". */
16028 static struct cmd_list_element *catch_cmdlist;
16030 /* List of subcommands for "tcatch". */
16031 static struct cmd_list_element *tcatch_cmdlist;
16034 add_catch_command (char *name, char *docstring,
16035 cmd_sfunc_ftype *sfunc,
16036 completer_ftype *completer,
16037 void *user_data_catch,
16038 void *user_data_tcatch)
16040 struct cmd_list_element *command;
16042 command = add_cmd (name, class_breakpoint, NULL, docstring,
16044 set_cmd_sfunc (command, sfunc);
16045 set_cmd_context (command, user_data_catch);
16046 set_cmd_completer (command, completer);
16048 command = add_cmd (name, class_breakpoint, NULL, docstring,
16050 set_cmd_sfunc (command, sfunc);
16051 set_cmd_context (command, user_data_tcatch);
16052 set_cmd_completer (command, completer);
16056 clear_syscall_counts (struct inferior *inf)
16058 struct catch_syscall_inferior_data *inf_data
16059 = get_catch_syscall_inferior_data (inf);
16061 inf_data->total_syscalls_count = 0;
16062 inf_data->any_syscall_count = 0;
16063 VEC_free (int, inf_data->syscalls_counts);
16067 save_command (char *arg, int from_tty)
16069 printf_unfiltered (_("\"save\" must be followed by "
16070 "the name of a save subcommand.\n"));
16071 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
16074 struct breakpoint *
16075 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
16078 struct breakpoint *b, *b_tmp;
16080 ALL_BREAKPOINTS_SAFE (b, b_tmp)
16082 if ((*callback) (b, data))
16089 /* Zero if any of the breakpoint's locations could be a location where
16090 functions have been inlined, nonzero otherwise. */
16093 is_non_inline_function (struct breakpoint *b)
16095 /* The shared library event breakpoint is set on the address of a
16096 non-inline function. */
16097 if (b->type == bp_shlib_event)
16103 /* Nonzero if the specified PC cannot be a location where functions
16104 have been inlined. */
16107 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
16108 const struct target_waitstatus *ws)
16110 struct breakpoint *b;
16111 struct bp_location *bl;
16113 ALL_BREAKPOINTS (b)
16115 if (!is_non_inline_function (b))
16118 for (bl = b->loc; bl != NULL; bl = bl->next)
16120 if (!bl->shlib_disabled
16121 && bpstat_check_location (bl, aspace, pc, ws))
16129 /* Remove any references to OBJFILE which is going to be freed. */
16132 breakpoint_free_objfile (struct objfile *objfile)
16134 struct bp_location **locp, *loc;
16136 ALL_BP_LOCATIONS (loc, locp)
16137 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
16138 loc->symtab = NULL;
16142 initialize_breakpoint_ops (void)
16144 static int initialized = 0;
16146 struct breakpoint_ops *ops;
16152 /* The breakpoint_ops structure to be inherit by all kinds of
16153 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16154 internal and momentary breakpoints, etc.). */
16155 ops = &bkpt_base_breakpoint_ops;
16156 *ops = base_breakpoint_ops;
16157 ops->re_set = bkpt_re_set;
16158 ops->insert_location = bkpt_insert_location;
16159 ops->remove_location = bkpt_remove_location;
16160 ops->breakpoint_hit = bkpt_breakpoint_hit;
16161 ops->create_sals_from_address = bkpt_create_sals_from_address;
16162 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
16163 ops->decode_linespec = bkpt_decode_linespec;
16165 /* The breakpoint_ops structure to be used in regular breakpoints. */
16166 ops = &bkpt_breakpoint_ops;
16167 *ops = bkpt_base_breakpoint_ops;
16168 ops->re_set = bkpt_re_set;
16169 ops->resources_needed = bkpt_resources_needed;
16170 ops->print_it = bkpt_print_it;
16171 ops->print_mention = bkpt_print_mention;
16172 ops->print_recreate = bkpt_print_recreate;
16174 /* Ranged breakpoints. */
16175 ops = &ranged_breakpoint_ops;
16176 *ops = bkpt_breakpoint_ops;
16177 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16178 ops->resources_needed = resources_needed_ranged_breakpoint;
16179 ops->print_it = print_it_ranged_breakpoint;
16180 ops->print_one = print_one_ranged_breakpoint;
16181 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16182 ops->print_mention = print_mention_ranged_breakpoint;
16183 ops->print_recreate = print_recreate_ranged_breakpoint;
16185 /* Internal breakpoints. */
16186 ops = &internal_breakpoint_ops;
16187 *ops = bkpt_base_breakpoint_ops;
16188 ops->re_set = internal_bkpt_re_set;
16189 ops->check_status = internal_bkpt_check_status;
16190 ops->print_it = internal_bkpt_print_it;
16191 ops->print_mention = internal_bkpt_print_mention;
16193 /* Momentary breakpoints. */
16194 ops = &momentary_breakpoint_ops;
16195 *ops = bkpt_base_breakpoint_ops;
16196 ops->re_set = momentary_bkpt_re_set;
16197 ops->check_status = momentary_bkpt_check_status;
16198 ops->print_it = momentary_bkpt_print_it;
16199 ops->print_mention = momentary_bkpt_print_mention;
16201 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16202 ops = &longjmp_breakpoint_ops;
16203 *ops = momentary_breakpoint_ops;
16204 ops->dtor = longjmp_bkpt_dtor;
16206 /* Probe breakpoints. */
16207 ops = &bkpt_probe_breakpoint_ops;
16208 *ops = bkpt_breakpoint_ops;
16209 ops->insert_location = bkpt_probe_insert_location;
16210 ops->remove_location = bkpt_probe_remove_location;
16211 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
16212 ops->decode_linespec = bkpt_probe_decode_linespec;
16215 ops = &watchpoint_breakpoint_ops;
16216 *ops = base_breakpoint_ops;
16217 ops->dtor = dtor_watchpoint;
16218 ops->re_set = re_set_watchpoint;
16219 ops->insert_location = insert_watchpoint;
16220 ops->remove_location = remove_watchpoint;
16221 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16222 ops->check_status = check_status_watchpoint;
16223 ops->resources_needed = resources_needed_watchpoint;
16224 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16225 ops->print_it = print_it_watchpoint;
16226 ops->print_mention = print_mention_watchpoint;
16227 ops->print_recreate = print_recreate_watchpoint;
16228 ops->explains_signal = explains_signal_watchpoint;
16230 /* Masked watchpoints. */
16231 ops = &masked_watchpoint_breakpoint_ops;
16232 *ops = watchpoint_breakpoint_ops;
16233 ops->insert_location = insert_masked_watchpoint;
16234 ops->remove_location = remove_masked_watchpoint;
16235 ops->resources_needed = resources_needed_masked_watchpoint;
16236 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16237 ops->print_it = print_it_masked_watchpoint;
16238 ops->print_one_detail = print_one_detail_masked_watchpoint;
16239 ops->print_mention = print_mention_masked_watchpoint;
16240 ops->print_recreate = print_recreate_masked_watchpoint;
16243 ops = &tracepoint_breakpoint_ops;
16244 *ops = base_breakpoint_ops;
16245 ops->re_set = tracepoint_re_set;
16246 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16247 ops->print_one_detail = tracepoint_print_one_detail;
16248 ops->print_mention = tracepoint_print_mention;
16249 ops->print_recreate = tracepoint_print_recreate;
16250 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16251 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16252 ops->decode_linespec = tracepoint_decode_linespec;
16254 /* Probe tracepoints. */
16255 ops = &tracepoint_probe_breakpoint_ops;
16256 *ops = tracepoint_breakpoint_ops;
16257 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16258 ops->decode_linespec = tracepoint_probe_decode_linespec;
16260 /* Static tracepoints with marker (`-m'). */
16261 ops = &strace_marker_breakpoint_ops;
16262 *ops = tracepoint_breakpoint_ops;
16263 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16264 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16265 ops->decode_linespec = strace_marker_decode_linespec;
16267 /* Fork catchpoints. */
16268 ops = &catch_fork_breakpoint_ops;
16269 *ops = base_breakpoint_ops;
16270 ops->insert_location = insert_catch_fork;
16271 ops->remove_location = remove_catch_fork;
16272 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16273 ops->print_it = print_it_catch_fork;
16274 ops->print_one = print_one_catch_fork;
16275 ops->print_mention = print_mention_catch_fork;
16276 ops->print_recreate = print_recreate_catch_fork;
16278 /* Vfork catchpoints. */
16279 ops = &catch_vfork_breakpoint_ops;
16280 *ops = base_breakpoint_ops;
16281 ops->insert_location = insert_catch_vfork;
16282 ops->remove_location = remove_catch_vfork;
16283 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16284 ops->print_it = print_it_catch_vfork;
16285 ops->print_one = print_one_catch_vfork;
16286 ops->print_mention = print_mention_catch_vfork;
16287 ops->print_recreate = print_recreate_catch_vfork;
16289 /* Exec catchpoints. */
16290 ops = &catch_exec_breakpoint_ops;
16291 *ops = base_breakpoint_ops;
16292 ops->dtor = dtor_catch_exec;
16293 ops->insert_location = insert_catch_exec;
16294 ops->remove_location = remove_catch_exec;
16295 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16296 ops->print_it = print_it_catch_exec;
16297 ops->print_one = print_one_catch_exec;
16298 ops->print_mention = print_mention_catch_exec;
16299 ops->print_recreate = print_recreate_catch_exec;
16301 /* Syscall catchpoints. */
16302 ops = &catch_syscall_breakpoint_ops;
16303 *ops = base_breakpoint_ops;
16304 ops->dtor = dtor_catch_syscall;
16305 ops->insert_location = insert_catch_syscall;
16306 ops->remove_location = remove_catch_syscall;
16307 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16308 ops->print_it = print_it_catch_syscall;
16309 ops->print_one = print_one_catch_syscall;
16310 ops->print_mention = print_mention_catch_syscall;
16311 ops->print_recreate = print_recreate_catch_syscall;
16313 /* Solib-related catchpoints. */
16314 ops = &catch_solib_breakpoint_ops;
16315 *ops = base_breakpoint_ops;
16316 ops->dtor = dtor_catch_solib;
16317 ops->insert_location = insert_catch_solib;
16318 ops->remove_location = remove_catch_solib;
16319 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16320 ops->check_status = check_status_catch_solib;
16321 ops->print_it = print_it_catch_solib;
16322 ops->print_one = print_one_catch_solib;
16323 ops->print_mention = print_mention_catch_solib;
16324 ops->print_recreate = print_recreate_catch_solib;
16326 ops = &dprintf_breakpoint_ops;
16327 *ops = bkpt_base_breakpoint_ops;
16328 ops->re_set = dprintf_re_set;
16329 ops->resources_needed = bkpt_resources_needed;
16330 ops->print_it = bkpt_print_it;
16331 ops->print_mention = bkpt_print_mention;
16332 ops->print_recreate = dprintf_print_recreate;
16333 ops->after_condition_true = dprintf_after_condition_true;
16334 ops->breakpoint_hit = dprintf_breakpoint_hit;
16337 /* Chain containing all defined "enable breakpoint" subcommands. */
16339 static struct cmd_list_element *enablebreaklist = NULL;
16342 _initialize_breakpoint (void)
16344 struct cmd_list_element *c;
16346 initialize_breakpoint_ops ();
16348 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16349 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16350 observer_attach_inferior_exit (clear_syscall_counts);
16351 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16353 breakpoint_objfile_key
16354 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16356 catch_syscall_inferior_data
16357 = register_inferior_data_with_cleanup (NULL,
16358 catch_syscall_inferior_data_cleanup);
16360 breakpoint_chain = 0;
16361 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16362 before a breakpoint is set. */
16363 breakpoint_count = 0;
16365 tracepoint_count = 0;
16367 add_com ("ignore", class_breakpoint, ignore_command, _("\
16368 Set ignore-count of breakpoint number N to COUNT.\n\
16369 Usage is `ignore N COUNT'."));
16371 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16373 add_com ("commands", class_breakpoint, commands_command, _("\
16374 Set commands to be executed when a breakpoint is hit.\n\
16375 Give breakpoint number as argument after \"commands\".\n\
16376 With no argument, the targeted breakpoint is the last one set.\n\
16377 The commands themselves follow starting on the next line.\n\
16378 Type a line containing \"end\" to indicate the end of them.\n\
16379 Give \"silent\" as the first line to make the breakpoint silent;\n\
16380 then no output is printed when it is hit, except what the commands print."));
16382 c = add_com ("condition", class_breakpoint, condition_command, _("\
16383 Specify breakpoint number N to break only if COND is true.\n\
16384 Usage is `condition N COND', where N is an integer and COND is an\n\
16385 expression to be evaluated whenever breakpoint N is reached."));
16386 set_cmd_completer (c, condition_completer);
16388 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16389 Set a temporary breakpoint.\n\
16390 Like \"break\" except the breakpoint is only temporary,\n\
16391 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16392 by using \"enable delete\" on the breakpoint number.\n\
16394 BREAK_ARGS_HELP ("tbreak")));
16395 set_cmd_completer (c, location_completer);
16397 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16398 Set a hardware assisted breakpoint.\n\
16399 Like \"break\" except the breakpoint requires hardware support,\n\
16400 some target hardware may not have this support.\n\
16402 BREAK_ARGS_HELP ("hbreak")));
16403 set_cmd_completer (c, location_completer);
16405 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16406 Set a temporary hardware assisted breakpoint.\n\
16407 Like \"hbreak\" except the breakpoint is only temporary,\n\
16408 so it will be deleted when hit.\n\
16410 BREAK_ARGS_HELP ("thbreak")));
16411 set_cmd_completer (c, location_completer);
16413 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16414 Enable some breakpoints.\n\
16415 Give breakpoint numbers (separated by spaces) as arguments.\n\
16416 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16417 This is used to cancel the effect of the \"disable\" command.\n\
16418 With a subcommand you can enable temporarily."),
16419 &enablelist, "enable ", 1, &cmdlist);
16421 add_com ("ab", class_breakpoint, enable_command, _("\
16422 Enable some breakpoints.\n\
16423 Give breakpoint numbers (separated by spaces) as arguments.\n\
16424 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16425 This is used to cancel the effect of the \"disable\" command.\n\
16426 With a subcommand you can enable temporarily."));
16428 add_com_alias ("en", "enable", class_breakpoint, 1);
16430 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16431 Enable some breakpoints.\n\
16432 Give breakpoint numbers (separated by spaces) as arguments.\n\
16433 This is used to cancel the effect of the \"disable\" command.\n\
16434 May be abbreviated to simply \"enable\".\n"),
16435 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16437 add_cmd ("once", no_class, enable_once_command, _("\
16438 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16439 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16442 add_cmd ("delete", no_class, enable_delete_command, _("\
16443 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16444 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16447 add_cmd ("count", no_class, enable_count_command, _("\
16448 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16449 If a breakpoint is hit while enabled in this fashion,\n\
16450 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16453 add_cmd ("delete", no_class, enable_delete_command, _("\
16454 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16455 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16458 add_cmd ("once", no_class, enable_once_command, _("\
16459 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16460 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16463 add_cmd ("count", no_class, enable_count_command, _("\
16464 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16465 If a breakpoint is hit while enabled in this fashion,\n\
16466 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16469 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16470 Disable some breakpoints.\n\
16471 Arguments are breakpoint numbers with spaces in between.\n\
16472 To disable all breakpoints, give no argument.\n\
16473 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16474 &disablelist, "disable ", 1, &cmdlist);
16475 add_com_alias ("dis", "disable", class_breakpoint, 1);
16476 add_com_alias ("disa", "disable", class_breakpoint, 1);
16478 add_com ("sb", class_breakpoint, disable_command, _("\
16479 Disable some breakpoints.\n\
16480 Arguments are breakpoint numbers with spaces in between.\n\
16481 To disable all breakpoints, give no argument.\n\
16482 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16484 add_cmd ("breakpoints", class_alias, disable_command, _("\
16485 Disable some breakpoints.\n\
16486 Arguments are breakpoint numbers with spaces in between.\n\
16487 To disable all breakpoints, give no argument.\n\
16488 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16489 This command may be abbreviated \"disable\"."),
16492 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16493 Delete some breakpoints or auto-display expressions.\n\
16494 Arguments are breakpoint numbers with spaces in between.\n\
16495 To delete all breakpoints, give no argument.\n\
16497 Also a prefix command for deletion of other GDB objects.\n\
16498 The \"unset\" command is also an alias for \"delete\"."),
16499 &deletelist, "delete ", 1, &cmdlist);
16500 add_com_alias ("d", "delete", class_breakpoint, 1);
16501 add_com_alias ("del", "delete", class_breakpoint, 1);
16503 add_com ("db", class_breakpoint, delete_command, _("\
16504 Delete some breakpoints.\n\
16505 Arguments are breakpoint numbers with spaces in between.\n\
16506 To delete all breakpoints, give no argument.\n"));
16508 add_cmd ("breakpoints", class_alias, delete_command, _("\
16509 Delete some breakpoints or auto-display expressions.\n\
16510 Arguments are breakpoint numbers with spaces in between.\n\
16511 To delete all breakpoints, give no argument.\n\
16512 This command may be abbreviated \"delete\"."),
16515 add_com ("clear", class_breakpoint, clear_command, _("\
16516 Clear breakpoint at specified line or function.\n\
16517 Argument may be line number, function name, or \"*\" and an address.\n\
16518 If line number is specified, all breakpoints in that line are cleared.\n\
16519 If function is specified, breakpoints at beginning of function are cleared.\n\
16520 If an address is specified, breakpoints at that address are cleared.\n\
16522 With no argument, clears all breakpoints in the line that the selected frame\n\
16523 is executing in.\n\
16525 See also the \"delete\" command which clears breakpoints by number."));
16526 add_com_alias ("cl", "clear", class_breakpoint, 1);
16528 c = add_com ("break", class_breakpoint, break_command, _("\
16529 Set breakpoint at specified line or function.\n"
16530 BREAK_ARGS_HELP ("break")));
16531 set_cmd_completer (c, location_completer);
16533 add_com_alias ("b", "break", class_run, 1);
16534 add_com_alias ("br", "break", class_run, 1);
16535 add_com_alias ("bre", "break", class_run, 1);
16536 add_com_alias ("brea", "break", class_run, 1);
16539 add_com_alias ("ba", "break", class_breakpoint, 1);
16543 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16544 Break in function/address or break at a line in the current file."),
16545 &stoplist, "stop ", 1, &cmdlist);
16546 add_cmd ("in", class_breakpoint, stopin_command,
16547 _("Break in function or address."), &stoplist);
16548 add_cmd ("at", class_breakpoint, stopat_command,
16549 _("Break at a line in the current file."), &stoplist);
16550 add_com ("status", class_info, breakpoints_info, _("\
16551 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16552 The \"Type\" column indicates one of:\n\
16553 \tbreakpoint - normal breakpoint\n\
16554 \twatchpoint - watchpoint\n\
16555 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16556 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16557 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16558 address and file/line number respectively.\n\
16560 Convenience variable \"$_\" and default examine address for \"x\"\n\
16561 are set to the address of the last breakpoint listed unless the command\n\
16562 is prefixed with \"server \".\n\n\
16563 Convenience variable \"$bpnum\" contains the number of the last\n\
16564 breakpoint set."));
16567 add_info ("breakpoints", breakpoints_info, _("\
16568 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16569 The \"Type\" column indicates one of:\n\
16570 \tbreakpoint - normal breakpoint\n\
16571 \twatchpoint - watchpoint\n\
16572 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16573 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16574 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16575 address and file/line number respectively.\n\
16577 Convenience variable \"$_\" and default examine address for \"x\"\n\
16578 are set to the address of the last breakpoint listed unless the command\n\
16579 is prefixed with \"server \".\n\n\
16580 Convenience variable \"$bpnum\" contains the number of the last\n\
16581 breakpoint set."));
16583 add_info_alias ("b", "breakpoints", 1);
16586 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16587 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16588 The \"Type\" column indicates one of:\n\
16589 \tbreakpoint - normal breakpoint\n\
16590 \twatchpoint - watchpoint\n\
16591 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16592 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16593 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16594 address and file/line number respectively.\n\
16596 Convenience variable \"$_\" and default examine address for \"x\"\n\
16597 are set to the address of the last breakpoint listed unless the command\n\
16598 is prefixed with \"server \".\n\n\
16599 Convenience variable \"$bpnum\" contains the number of the last\n\
16600 breakpoint set."));
16602 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16603 Status of all breakpoints, or breakpoint number NUMBER.\n\
16604 The \"Type\" column indicates one of:\n\
16605 \tbreakpoint - normal breakpoint\n\
16606 \twatchpoint - watchpoint\n\
16607 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16608 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16609 \tuntil - internal breakpoint used by the \"until\" command\n\
16610 \tfinish - internal breakpoint used by the \"finish\" command\n\
16611 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16612 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16613 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16614 address and file/line number respectively.\n\
16616 Convenience variable \"$_\" and default examine address for \"x\"\n\
16617 are set to the address of the last breakpoint listed unless the command\n\
16618 is prefixed with \"server \".\n\n\
16619 Convenience variable \"$bpnum\" contains the number of the last\n\
16621 &maintenanceinfolist);
16623 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16624 Set catchpoints to catch events."),
16625 &catch_cmdlist, "catch ",
16626 0/*allow-unknown*/, &cmdlist);
16628 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16629 Set temporary catchpoints to catch events."),
16630 &tcatch_cmdlist, "tcatch ",
16631 0/*allow-unknown*/, &cmdlist);
16633 add_catch_command ("fork", _("Catch calls to fork."),
16634 catch_fork_command_1,
16636 (void *) (uintptr_t) catch_fork_permanent,
16637 (void *) (uintptr_t) catch_fork_temporary);
16638 add_catch_command ("vfork", _("Catch calls to vfork."),
16639 catch_fork_command_1,
16641 (void *) (uintptr_t) catch_vfork_permanent,
16642 (void *) (uintptr_t) catch_vfork_temporary);
16643 add_catch_command ("exec", _("Catch calls to exec."),
16644 catch_exec_command_1,
16648 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16649 Usage: catch load [REGEX]\n\
16650 If REGEX is given, only stop for libraries matching the regular expression."),
16651 catch_load_command_1,
16655 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16656 Usage: catch unload [REGEX]\n\
16657 If REGEX is given, only stop for libraries matching the regular expression."),
16658 catch_unload_command_1,
16662 add_catch_command ("syscall", _("\
16663 Catch system calls by their names and/or numbers.\n\
16664 Arguments say which system calls to catch. If no arguments\n\
16665 are given, every system call will be caught.\n\
16666 Arguments, if given, should be one or more system call names\n\
16667 (if your system supports that), or system call numbers."),
16668 catch_syscall_command_1,
16669 catch_syscall_completer,
16673 c = add_com ("watch", class_breakpoint, watch_command, _("\
16674 Set a watchpoint for an expression.\n\
16675 Usage: watch [-l|-location] EXPRESSION\n\
16676 A watchpoint stops execution of your program whenever the value of\n\
16677 an expression changes.\n\
16678 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16679 the memory to which it refers."));
16680 set_cmd_completer (c, expression_completer);
16682 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16683 Set a read watchpoint for an expression.\n\
16684 Usage: rwatch [-l|-location] EXPRESSION\n\
16685 A watchpoint stops execution of your program whenever the value of\n\
16686 an expression is read.\n\
16687 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16688 the memory to which it refers."));
16689 set_cmd_completer (c, expression_completer);
16691 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16692 Set a watchpoint for an expression.\n\
16693 Usage: awatch [-l|-location] EXPRESSION\n\
16694 A watchpoint stops execution of your program whenever the value of\n\
16695 an expression is either read or written.\n\
16696 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16697 the memory to which it refers."));
16698 set_cmd_completer (c, expression_completer);
16700 add_info ("watchpoints", watchpoints_info, _("\
16701 Status of specified watchpoints (all watchpoints if no argument)."));
16703 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16704 respond to changes - contrary to the description. */
16705 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16706 &can_use_hw_watchpoints, _("\
16707 Set debugger's willingness to use watchpoint hardware."), _("\
16708 Show debugger's willingness to use watchpoint hardware."), _("\
16709 If zero, gdb will not use hardware for new watchpoints, even if\n\
16710 such is available. (However, any hardware watchpoints that were\n\
16711 created before setting this to nonzero, will continue to use watchpoint\n\
16714 show_can_use_hw_watchpoints,
16715 &setlist, &showlist);
16717 can_use_hw_watchpoints = 1;
16719 /* Tracepoint manipulation commands. */
16721 c = add_com ("trace", class_breakpoint, trace_command, _("\
16722 Set a tracepoint at specified line or function.\n\
16724 BREAK_ARGS_HELP ("trace") "\n\
16725 Do \"help tracepoints\" for info on other tracepoint commands."));
16726 set_cmd_completer (c, location_completer);
16728 add_com_alias ("tp", "trace", class_alias, 0);
16729 add_com_alias ("tr", "trace", class_alias, 1);
16730 add_com_alias ("tra", "trace", class_alias, 1);
16731 add_com_alias ("trac", "trace", class_alias, 1);
16733 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16734 Set a fast tracepoint at specified line or function.\n\
16736 BREAK_ARGS_HELP ("ftrace") "\n\
16737 Do \"help tracepoints\" for info on other tracepoint commands."));
16738 set_cmd_completer (c, location_completer);
16740 c = add_com ("strace", class_breakpoint, strace_command, _("\
16741 Set a static tracepoint at specified line, function or marker.\n\
16743 strace [LOCATION] [if CONDITION]\n\
16744 LOCATION may be a line number, function name, \"*\" and an address,\n\
16745 or -m MARKER_ID.\n\
16746 If a line number is specified, probe the marker at start of code\n\
16747 for that line. If a function is specified, probe the marker at start\n\
16748 of code for that function. If an address is specified, probe the marker\n\
16749 at that exact address. If a marker id is specified, probe the marker\n\
16750 with that name. With no LOCATION, uses current execution address of\n\
16751 the selected stack frame.\n\
16752 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16753 This collects arbitrary user data passed in the probe point call to the\n\
16754 tracing library. You can inspect it when analyzing the trace buffer,\n\
16755 by printing the $_sdata variable like any other convenience variable.\n\
16757 CONDITION is a boolean expression.\n\
16759 Multiple tracepoints at one place are permitted, and useful if their\n\
16760 conditions are different.\n\
16762 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16763 Do \"help tracepoints\" for info on other tracepoint commands."));
16764 set_cmd_completer (c, location_completer);
16766 add_info ("tracepoints", tracepoints_info, _("\
16767 Status of specified tracepoints (all tracepoints if no argument).\n\
16768 Convenience variable \"$tpnum\" contains the number of the\n\
16769 last tracepoint set."));
16771 add_info_alias ("tp", "tracepoints", 1);
16773 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16774 Delete specified tracepoints.\n\
16775 Arguments are tracepoint numbers, separated by spaces.\n\
16776 No argument means delete all tracepoints."),
16778 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16780 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16781 Disable specified tracepoints.\n\
16782 Arguments are tracepoint numbers, separated by spaces.\n\
16783 No argument means disable all tracepoints."),
16785 deprecate_cmd (c, "disable");
16787 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16788 Enable specified tracepoints.\n\
16789 Arguments are tracepoint numbers, separated by spaces.\n\
16790 No argument means enable all tracepoints."),
16792 deprecate_cmd (c, "enable");
16794 add_com ("passcount", class_trace, trace_pass_command, _("\
16795 Set the passcount for a tracepoint.\n\
16796 The trace will end when the tracepoint has been passed 'count' times.\n\
16797 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16798 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16800 add_prefix_cmd ("save", class_breakpoint, save_command,
16801 _("Save breakpoint definitions as a script."),
16802 &save_cmdlist, "save ",
16803 0/*allow-unknown*/, &cmdlist);
16805 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16806 Save current breakpoint definitions as a script.\n\
16807 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16808 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16809 session to restore them."),
16811 set_cmd_completer (c, filename_completer);
16813 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16814 Save current tracepoint definitions as a script.\n\
16815 Use the 'source' command in another debug session to restore them."),
16817 set_cmd_completer (c, filename_completer);
16819 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16820 deprecate_cmd (c, "save tracepoints");
16822 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16823 Breakpoint specific settings\n\
16824 Configure various breakpoint-specific variables such as\n\
16825 pending breakpoint behavior"),
16826 &breakpoint_set_cmdlist, "set breakpoint ",
16827 0/*allow-unknown*/, &setlist);
16828 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16829 Breakpoint specific settings\n\
16830 Configure various breakpoint-specific variables such as\n\
16831 pending breakpoint behavior"),
16832 &breakpoint_show_cmdlist, "show breakpoint ",
16833 0/*allow-unknown*/, &showlist);
16835 add_setshow_auto_boolean_cmd ("pending", no_class,
16836 &pending_break_support, _("\
16837 Set debugger's behavior regarding pending breakpoints."), _("\
16838 Show debugger's behavior regarding pending breakpoints."), _("\
16839 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16840 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16841 an error. If auto, an unrecognized breakpoint location results in a\n\
16842 user-query to see if a pending breakpoint should be created."),
16844 show_pending_break_support,
16845 &breakpoint_set_cmdlist,
16846 &breakpoint_show_cmdlist);
16848 pending_break_support = AUTO_BOOLEAN_AUTO;
16850 add_setshow_boolean_cmd ("auto-hw", no_class,
16851 &automatic_hardware_breakpoints, _("\
16852 Set automatic usage of hardware breakpoints."), _("\
16853 Show automatic usage of hardware breakpoints."), _("\
16854 If set, the debugger will automatically use hardware breakpoints for\n\
16855 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16856 a warning will be emitted for such breakpoints."),
16858 show_automatic_hardware_breakpoints,
16859 &breakpoint_set_cmdlist,
16860 &breakpoint_show_cmdlist);
16862 add_setshow_boolean_cmd ("always-inserted", class_support,
16863 &always_inserted_mode, _("\
16864 Set mode for inserting breakpoints."), _("\
16865 Show mode for inserting breakpoints."), _("\
16866 When this mode is on, breakpoints are inserted immediately as soon as\n\
16867 they're created, kept inserted even when execution stops, and removed\n\
16868 only when the user deletes them. When this mode is off (the default),\n\
16869 breakpoints are inserted only when execution continues, and removed\n\
16870 when execution stops."),
16872 &show_always_inserted_mode,
16873 &breakpoint_set_cmdlist,
16874 &breakpoint_show_cmdlist);
16876 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16877 condition_evaluation_enums,
16878 &condition_evaluation_mode_1, _("\
16879 Set mode of breakpoint condition evaluation."), _("\
16880 Show mode of breakpoint condition evaluation."), _("\
16881 When this is set to \"host\", breakpoint conditions will be\n\
16882 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16883 breakpoint conditions will be downloaded to the target (if the target\n\
16884 supports such feature) and conditions will be evaluated on the target's side.\n\
16885 If this is set to \"auto\" (default), this will be automatically set to\n\
16886 \"target\" if it supports condition evaluation, otherwise it will\n\
16887 be set to \"gdb\""),
16888 &set_condition_evaluation_mode,
16889 &show_condition_evaluation_mode,
16890 &breakpoint_set_cmdlist,
16891 &breakpoint_show_cmdlist);
16893 add_com ("break-range", class_breakpoint, break_range_command, _("\
16894 Set a breakpoint for an address range.\n\
16895 break-range START-LOCATION, END-LOCATION\n\
16896 where START-LOCATION and END-LOCATION can be one of the following:\n\
16897 LINENUM, for that line in the current file,\n\
16898 FILE:LINENUM, for that line in that file,\n\
16899 +OFFSET, for that number of lines after the current line\n\
16900 or the start of the range\n\
16901 FUNCTION, for the first line in that function,\n\
16902 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16903 *ADDRESS, for the instruction at that address.\n\
16905 The breakpoint will stop execution of the inferior whenever it executes\n\
16906 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16907 range (including START-LOCATION and END-LOCATION)."));
16909 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16910 Set a dynamic printf at specified line or function.\n\
16911 dprintf location,format string,arg1,arg2,...\n\
16912 location may be a line number, function name, or \"*\" and an address.\n\
16913 If a line number is specified, break at start of code for that line.\n\
16914 If a function is specified, break at start of code for that function."));
16915 set_cmd_completer (c, location_completer);
16917 add_setshow_enum_cmd ("dprintf-style", class_support,
16918 dprintf_style_enums, &dprintf_style, _("\
16919 Set the style of usage for dynamic printf."), _("\
16920 Show the style of usage for dynamic printf."), _("\
16921 This setting chooses how GDB will do a dynamic printf.\n\
16922 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16923 console, as with the \"printf\" command.\n\
16924 If the value is \"call\", the print is done by calling a function in your\n\
16925 program; by default printf(), but you can choose a different function or\n\
16926 output stream by setting dprintf-function and dprintf-channel."),
16927 update_dprintf_commands, NULL,
16928 &setlist, &showlist);
16930 dprintf_function = xstrdup ("printf");
16931 add_setshow_string_cmd ("dprintf-function", class_support,
16932 &dprintf_function, _("\
16933 Set the function to use for dynamic printf"), _("\
16934 Show the function to use for dynamic printf"), NULL,
16935 update_dprintf_commands, NULL,
16936 &setlist, &showlist);
16938 dprintf_channel = xstrdup ("");
16939 add_setshow_string_cmd ("dprintf-channel", class_support,
16940 &dprintf_channel, _("\
16941 Set the channel to use for dynamic printf"), _("\
16942 Show the channel to use for dynamic printf"), NULL,
16943 update_dprintf_commands, NULL,
16944 &setlist, &showlist);
16946 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16947 &disconnected_dprintf, _("\
16948 Set whether dprintf continues after GDB disconnects."), _("\
16949 Show whether dprintf continues after GDB disconnects."), _("\
16950 Use this to let dprintf commands continue to hit and produce output\n\
16951 even if GDB disconnects or detaches from the target."),
16954 &setlist, &showlist);
16956 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16957 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16958 (target agent only) This is useful for formatted output in user-defined commands."));
16960 automatic_hardware_breakpoints = 1;
16962 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16963 observer_attach_thread_exit (remove_threaded_breakpoints);