1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 #include "progspace-and-thread.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (const char *,
106 void (*) (struct breakpoint *,
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint *);
117 create_sals_from_location_default (const struct event_location *location,
118 struct linespec_result *canonical,
119 enum bptype type_wanted);
121 static void create_breakpoints_sal_default (struct gdbarch *,
122 struct linespec_result *,
123 gdb::unique_xmalloc_ptr<char>,
124 gdb::unique_xmalloc_ptr<char>,
126 enum bpdisp, int, int,
128 const struct breakpoint_ops *,
129 int, int, int, unsigned);
131 static void decode_location_default (struct breakpoint *b,
132 const struct event_location *location,
133 struct program_space *search_pspace,
134 struct symtabs_and_lines *sals);
136 static void clear_command (char *, int);
138 static void catch_command (char *, int);
140 static int can_use_hardware_watchpoint (struct value *);
142 static void break_command_1 (char *, int, int);
144 static void mention (struct breakpoint *);
146 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
148 const struct breakpoint_ops *);
149 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
150 const struct symtab_and_line *);
152 /* This function is used in gdbtk sources and thus can not be made
154 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
155 struct symtab_and_line,
157 const struct breakpoint_ops *);
159 static struct breakpoint *
160 momentary_breakpoint_from_master (struct breakpoint *orig,
162 const struct breakpoint_ops *ops,
165 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
167 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
171 static void describe_other_breakpoints (struct gdbarch *,
172 struct program_space *, CORE_ADDR,
173 struct obj_section *, int);
175 static int watchpoint_locations_match (struct bp_location *loc1,
176 struct bp_location *loc2);
178 static int breakpoint_location_address_match (struct bp_location *bl,
179 struct address_space *aspace,
182 static int breakpoint_location_address_range_overlap (struct bp_location *,
183 struct address_space *,
186 static void breakpoints_info (char *, int);
188 static void watchpoints_info (char *, int);
190 static int breakpoint_1 (char *, int,
191 int (*) (const struct breakpoint *));
193 static int breakpoint_cond_eval (void *);
195 static void cleanup_executing_breakpoints (void *);
197 static void commands_command (char *, int);
199 static void condition_command (char *, int);
201 static int remove_breakpoint (struct bp_location *);
202 static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
204 static enum print_stop_action print_bp_stop_message (bpstat bs);
206 static int watchpoint_check (void *);
208 static void maintenance_info_breakpoints (char *, int);
210 static int hw_breakpoint_used_count (void);
212 static int hw_watchpoint_use_count (struct breakpoint *);
214 static int hw_watchpoint_used_count_others (struct breakpoint *except,
216 int *other_type_used);
218 static void hbreak_command (char *, int);
220 static void thbreak_command (char *, int);
222 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
225 static void stop_command (char *arg, int from_tty);
227 static void stopin_command (char *arg, int from_tty);
229 static void stopat_command (char *arg, int from_tty);
231 static void tcatch_command (char *arg, int from_tty);
233 static void free_bp_location (struct bp_location *loc);
234 static void incref_bp_location (struct bp_location *loc);
235 static void decref_bp_location (struct bp_location **loc);
237 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
239 /* update_global_location_list's modes of operation wrt to whether to
240 insert locations now. */
241 enum ugll_insert_mode
243 /* Don't insert any breakpoint locations into the inferior, only
244 remove already-inserted locations that no longer should be
245 inserted. Functions that delete a breakpoint or breakpoints
246 should specify this mode, so that deleting a breakpoint doesn't
247 have the side effect of inserting the locations of other
248 breakpoints that are marked not-inserted, but should_be_inserted
249 returns true on them.
251 This behavior is useful is situations close to tear-down -- e.g.,
252 after an exec, while the target still has execution, but
253 breakpoint shadows of the previous executable image should *NOT*
254 be restored to the new image; or before detaching, where the
255 target still has execution and wants to delete breakpoints from
256 GDB's lists, and all breakpoints had already been removed from
260 /* May insert breakpoints iff breakpoints_should_be_inserted_now
261 claims breakpoints should be inserted now. */
264 /* Insert locations now, irrespective of
265 breakpoints_should_be_inserted_now. E.g., say all threads are
266 stopped right now, and the user did "continue". We need to
267 insert breakpoints _before_ resuming the target, but
268 UGLL_MAY_INSERT wouldn't insert them, because
269 breakpoints_should_be_inserted_now returns false at that point,
270 as no thread is running yet. */
274 static void update_global_location_list (enum ugll_insert_mode);
276 static void update_global_location_list_nothrow (enum ugll_insert_mode);
278 static int is_hardware_watchpoint (const struct breakpoint *bpt);
280 static void insert_breakpoint_locations (void);
282 static void tracepoints_info (char *, int);
284 static void delete_trace_command (char *, int);
286 static void enable_trace_command (char *, int);
288 static void disable_trace_command (char *, int);
290 static void trace_pass_command (char *, int);
292 static void set_tracepoint_count (int num);
294 static int is_masked_watchpoint (const struct breakpoint *b);
296 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
298 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
301 static int strace_marker_p (struct breakpoint *b);
303 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
304 that are implemented on top of software or hardware breakpoints
305 (user breakpoints, internal and momentary breakpoints, etc.). */
306 static struct breakpoint_ops bkpt_base_breakpoint_ops;
308 /* Internal breakpoints class type. */
309 static struct breakpoint_ops internal_breakpoint_ops;
311 /* Momentary breakpoints class type. */
312 static struct breakpoint_ops momentary_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 struct thread_info *tp;
476 if (always_inserted_mode)
478 /* The user wants breakpoints inserted even if all threads
483 if (threads_are_executing ())
486 /* Don't remove breakpoints yet if, even though all threads are
487 stopped, we still have events to process. */
488 ALL_NON_EXITED_THREADS (tp)
490 && tp->suspend.waitstatus_pending_p)
496 static const char condition_evaluation_both[] = "host or target";
498 /* Modes for breakpoint condition evaluation. */
499 static const char condition_evaluation_auto[] = "auto";
500 static const char condition_evaluation_host[] = "host";
501 static const char condition_evaluation_target[] = "target";
502 static const char *const condition_evaluation_enums[] = {
503 condition_evaluation_auto,
504 condition_evaluation_host,
505 condition_evaluation_target,
509 /* Global that holds the current mode for breakpoint condition evaluation. */
510 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
512 /* Global that we use to display information to the user (gets its value from
513 condition_evaluation_mode_1. */
514 static const char *condition_evaluation_mode = condition_evaluation_auto;
516 /* Translate a condition evaluation mode MODE into either "host"
517 or "target". This is used mostly to translate from "auto" to the
518 real setting that is being used. It returns the translated
522 translate_condition_evaluation_mode (const char *mode)
524 if (mode == condition_evaluation_auto)
526 if (target_supports_evaluation_of_breakpoint_conditions ())
527 return condition_evaluation_target;
529 return condition_evaluation_host;
535 /* Discovers what condition_evaluation_auto translates to. */
538 breakpoint_condition_evaluation_mode (void)
540 return translate_condition_evaluation_mode (condition_evaluation_mode);
543 /* Return true if GDB should evaluate breakpoint conditions or false
547 gdb_evaluates_breakpoint_condition_p (void)
549 const char *mode = breakpoint_condition_evaluation_mode ();
551 return (mode == condition_evaluation_host);
554 void _initialize_breakpoint (void);
556 /* Are we executing breakpoint commands? */
557 static int executing_breakpoint_commands;
559 /* Are overlay event breakpoints enabled? */
560 static int overlay_events_enabled;
562 /* See description in breakpoint.h. */
563 int target_exact_watchpoints = 0;
565 /* Walk the following statement or block through all breakpoints.
566 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
567 current breakpoint. */
569 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
571 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
572 for (B = breakpoint_chain; \
573 B ? (TMP=B->next, 1): 0; \
576 /* Similar iterator for the low-level breakpoints. SAFE variant is
577 not provided so update_global_location_list must not be called
578 while executing the block of ALL_BP_LOCATIONS. */
580 #define ALL_BP_LOCATIONS(B,BP_TMP) \
581 for (BP_TMP = bp_locations; \
582 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
585 /* Iterates through locations with address ADDRESS for the currently selected
586 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
587 to where the loop should start from.
588 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
589 appropriate location to start with. */
591 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
592 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
593 BP_LOCP_TMP = BP_LOCP_START; \
595 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
596 && (*BP_LOCP_TMP)->address == ADDRESS); \
599 /* Iterator for tracepoints only. */
601 #define ALL_TRACEPOINTS(B) \
602 for (B = breakpoint_chain; B; B = B->next) \
603 if (is_tracepoint (B))
605 /* Chains of all breakpoints defined. */
607 struct breakpoint *breakpoint_chain;
609 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
611 static struct bp_location **bp_locations;
613 /* Number of elements of BP_LOCATIONS. */
615 static unsigned bp_locations_count;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATIONS which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_locations_placed_address_before_address_max;
625 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
626 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
627 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATIONS to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_locations_shadow_len_after_address_max;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from the bp_locations array, but for which a hit may still be
635 reported by a target. */
636 VEC(bp_location_p) *moribund_locations = NULL;
638 /* Number of last breakpoint made. */
640 static int breakpoint_count;
642 /* The value of `breakpoint_count' before the last command that
643 created breakpoints. If the last (break-like) command created more
644 than one breakpoint, then the difference between BREAKPOINT_COUNT
645 and PREV_BREAKPOINT_COUNT is more than one. */
646 static int prev_breakpoint_count;
648 /* Number of last tracepoint made. */
650 static int tracepoint_count;
652 static struct cmd_list_element *breakpoint_set_cmdlist;
653 static struct cmd_list_element *breakpoint_show_cmdlist;
654 struct cmd_list_element *save_cmdlist;
656 /* See declaration at breakpoint.h. */
659 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
662 struct breakpoint *b = NULL;
666 if (func (b, user_data) != 0)
673 /* Return whether a breakpoint is an active enabled breakpoint. */
675 breakpoint_enabled (struct breakpoint *b)
677 return (b->enable_state == bp_enabled);
680 /* Set breakpoint count to NUM. */
683 set_breakpoint_count (int num)
685 prev_breakpoint_count = breakpoint_count;
686 breakpoint_count = num;
687 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
690 /* Used by `start_rbreak_breakpoints' below, to record the current
691 breakpoint count before "rbreak" creates any breakpoint. */
692 static int rbreak_start_breakpoint_count;
694 /* Called at the start an "rbreak" command to record the first
698 start_rbreak_breakpoints (void)
700 rbreak_start_breakpoint_count = breakpoint_count;
703 /* Called at the end of an "rbreak" command to record the last
707 end_rbreak_breakpoints (void)
709 prev_breakpoint_count = rbreak_start_breakpoint_count;
712 /* Used in run_command to zero the hit count when a new run starts. */
715 clear_breakpoint_hit_counts (void)
717 struct breakpoint *b;
723 /* Allocate a new counted_command_line with reference count of 1.
724 The new structure owns COMMANDS. */
726 static struct counted_command_line *
727 alloc_counted_command_line (struct command_line *commands)
729 struct counted_command_line *result = XNEW (struct counted_command_line);
732 result->commands = commands;
737 /* Increment reference count. This does nothing if CMD is NULL. */
740 incref_counted_command_line (struct counted_command_line *cmd)
746 /* Decrement reference count. If the reference count reaches 0,
747 destroy the counted_command_line. Sets *CMDP to NULL. This does
748 nothing if *CMDP is NULL. */
751 decref_counted_command_line (struct counted_command_line **cmdp)
755 if (--(*cmdp)->refc == 0)
757 free_command_lines (&(*cmdp)->commands);
764 /* A cleanup function that calls decref_counted_command_line. */
767 do_cleanup_counted_command_line (void *arg)
769 decref_counted_command_line ((struct counted_command_line **) arg);
772 /* Create a cleanup that calls decref_counted_command_line on the
775 static struct cleanup *
776 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
778 return make_cleanup (do_cleanup_counted_command_line, cmdp);
782 /* Return the breakpoint with the specified number, or NULL
783 if the number does not refer to an existing breakpoint. */
786 get_breakpoint (int num)
788 struct breakpoint *b;
791 if (b->number == num)
799 /* Mark locations as "conditions have changed" in case the target supports
800 evaluating conditions on its side. */
803 mark_breakpoint_modified (struct breakpoint *b)
805 struct bp_location *loc;
807 /* This is only meaningful if the target is
808 evaluating conditions and if the user has
809 opted for condition evaluation on the target's
811 if (gdb_evaluates_breakpoint_condition_p ()
812 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (b))
818 for (loc = b->loc; loc; loc = loc->next)
819 loc->condition_changed = condition_modified;
822 /* Mark location as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_location_modified (struct bp_location *loc)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
837 if (!is_breakpoint (loc->owner))
840 loc->condition_changed = condition_modified;
843 /* Sets the condition-evaluation mode using the static global
844 condition_evaluation_mode. */
847 set_condition_evaluation_mode (char *args, int from_tty,
848 struct cmd_list_element *c)
850 const char *old_mode, *new_mode;
852 if ((condition_evaluation_mode_1 == condition_evaluation_target)
853 && !target_supports_evaluation_of_breakpoint_conditions ())
855 condition_evaluation_mode_1 = condition_evaluation_mode;
856 warning (_("Target does not support breakpoint condition evaluation.\n"
857 "Using host evaluation mode instead."));
861 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
862 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
864 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
865 settings was "auto". */
866 condition_evaluation_mode = condition_evaluation_mode_1;
868 /* Only update the mode if the user picked a different one. */
869 if (new_mode != old_mode)
871 struct bp_location *loc, **loc_tmp;
872 /* If the user switched to a different evaluation mode, we
873 need to synch the changes with the target as follows:
875 "host" -> "target": Send all (valid) conditions to the target.
876 "target" -> "host": Remove all the conditions from the target.
879 if (new_mode == condition_evaluation_target)
881 /* Mark everything modified and synch conditions with the
883 ALL_BP_LOCATIONS (loc, loc_tmp)
884 mark_breakpoint_location_modified (loc);
888 /* Manually mark non-duplicate locations to synch conditions
889 with the target. We do this to remove all the conditions the
890 target knows about. */
891 ALL_BP_LOCATIONS (loc, loc_tmp)
892 if (is_breakpoint (loc->owner) && loc->inserted)
893 loc->needs_update = 1;
897 update_global_location_list (UGLL_MAY_INSERT);
903 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
904 what "auto" is translating to. */
907 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
908 struct cmd_list_element *c, const char *value)
910 if (condition_evaluation_mode == condition_evaluation_auto)
911 fprintf_filtered (file,
912 _("Breakpoint condition evaluation "
913 "mode is %s (currently %s).\n"),
915 breakpoint_condition_evaluation_mode ());
917 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
921 /* A comparison function for bp_location AP and BP that is used by
922 bsearch. This comparison function only cares about addresses, unlike
923 the more general bp_locations_compare function. */
926 bp_locations_compare_addrs (const void *ap, const void *bp)
928 const struct bp_location *a = *(const struct bp_location **) ap;
929 const struct bp_location *b = *(const struct bp_location **) bp;
931 if (a->address == b->address)
934 return ((a->address > b->address) - (a->address < b->address));
937 /* Helper function to skip all bp_locations with addresses
938 less than ADDRESS. It returns the first bp_location that
939 is greater than or equal to ADDRESS. If none is found, just
942 static struct bp_location **
943 get_first_locp_gte_addr (CORE_ADDR address)
945 struct bp_location dummy_loc;
946 struct bp_location *dummy_locp = &dummy_loc;
947 struct bp_location **locp_found = NULL;
949 /* Initialize the dummy location's address field. */
950 dummy_loc.address = address;
952 /* Find a close match to the first location at ADDRESS. */
953 locp_found = ((struct bp_location **)
954 bsearch (&dummy_locp, bp_locations, bp_locations_count,
955 sizeof (struct bp_location **),
956 bp_locations_compare_addrs));
958 /* Nothing was found, nothing left to do. */
959 if (locp_found == NULL)
962 /* We may have found a location that is at ADDRESS but is not the first in the
963 location's list. Go backwards (if possible) and locate the first one. */
964 while ((locp_found - 1) >= bp_locations
965 && (*(locp_found - 1))->address == address)
972 set_breakpoint_condition (struct breakpoint *b, const char *exp,
975 xfree (b->cond_string);
976 b->cond_string = NULL;
978 if (is_watchpoint (b))
980 struct watchpoint *w = (struct watchpoint *) b;
982 w->cond_exp.reset ();
986 struct bp_location *loc;
988 for (loc = b->loc; loc; loc = loc->next)
992 /* No need to free the condition agent expression
993 bytecode (if we have one). We will handle this
994 when we go through update_global_location_list. */
1001 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
1005 const char *arg = exp;
1007 /* I don't know if it matters whether this is the string the user
1008 typed in or the decompiled expression. */
1009 b->cond_string = xstrdup (arg);
1010 b->condition_not_parsed = 0;
1012 if (is_watchpoint (b))
1014 struct watchpoint *w = (struct watchpoint *) b;
1016 innermost_block = NULL;
1018 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1020 error (_("Junk at end of expression"));
1021 w->cond_exp_valid_block = innermost_block;
1025 struct bp_location *loc;
1027 for (loc = b->loc; loc; loc = loc->next)
1031 parse_exp_1 (&arg, loc->address,
1032 block_for_pc (loc->address), 0);
1034 error (_("Junk at end of expression"));
1038 mark_breakpoint_modified (b);
1040 observer_notify_breakpoint_modified (b);
1043 /* Completion for the "condition" command. */
1045 static VEC (char_ptr) *
1046 condition_completer (struct cmd_list_element *cmd,
1047 const char *text, const char *word)
1051 text = skip_spaces_const (text);
1052 space = skip_to_space_const (text);
1056 struct breakpoint *b;
1057 VEC (char_ptr) *result = NULL;
1061 /* We don't support completion of history indices. */
1062 if (isdigit (text[1]))
1064 return complete_internalvar (&text[1]);
1067 /* We're completing the breakpoint number. */
1068 len = strlen (text);
1074 xsnprintf (number, sizeof (number), "%d", b->number);
1076 if (strncmp (number, text, len) == 0)
1077 VEC_safe_push (char_ptr, result, xstrdup (number));
1083 /* We're completing the expression part. */
1084 text = skip_spaces_const (space);
1085 return expression_completer (cmd, text, word);
1088 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1091 condition_command (char *arg, int from_tty)
1093 struct breakpoint *b;
1098 error_no_arg (_("breakpoint number"));
1101 bnum = get_number (&p);
1103 error (_("Bad breakpoint argument: '%s'"), arg);
1106 if (b->number == bnum)
1108 /* Check if this breakpoint has a "stop" method implemented in an
1109 extension language. This method and conditions entered into GDB
1110 from the CLI are mutually exclusive. */
1111 const struct extension_language_defn *extlang
1112 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1114 if (extlang != NULL)
1116 error (_("Only one stop condition allowed. There is currently"
1117 " a %s stop condition defined for this breakpoint."),
1118 ext_lang_capitalized_name (extlang));
1120 set_breakpoint_condition (b, p, from_tty);
1122 if (is_breakpoint (b))
1123 update_global_location_list (UGLL_MAY_INSERT);
1128 error (_("No breakpoint number %d."), bnum);
1131 /* Check that COMMAND do not contain commands that are suitable
1132 only for tracepoints and not suitable for ordinary breakpoints.
1133 Throw if any such commands is found. */
1136 check_no_tracepoint_commands (struct command_line *commands)
1138 struct command_line *c;
1140 for (c = commands; c; c = c->next)
1144 if (c->control_type == while_stepping_control)
1145 error (_("The 'while-stepping' command can "
1146 "only be used for tracepoints"));
1148 for (i = 0; i < c->body_count; ++i)
1149 check_no_tracepoint_commands ((c->body_list)[i]);
1151 /* Not that command parsing removes leading whitespace and comment
1152 lines and also empty lines. So, we only need to check for
1153 command directly. */
1154 if (strstr (c->line, "collect ") == c->line)
1155 error (_("The 'collect' command can only be used for tracepoints"));
1157 if (strstr (c->line, "teval ") == c->line)
1158 error (_("The 'teval' command can only be used for tracepoints"));
1162 struct longjmp_breakpoint : public breakpoint
1164 ~longjmp_breakpoint () override;
1167 /* Encapsulate tests for different types of tracepoints. */
1170 is_tracepoint_type (bptype type)
1172 return (type == bp_tracepoint
1173 || type == bp_fast_tracepoint
1174 || type == bp_static_tracepoint);
1178 is_longjmp_type (bptype type)
1180 return type == bp_longjmp || type == bp_exception;
1184 is_tracepoint (const struct breakpoint *b)
1186 return is_tracepoint_type (b->type);
1189 /* Factory function to create an appropriate instance of breakpoint given
1192 static std::unique_ptr<breakpoint>
1193 new_breakpoint_from_type (bptype type)
1197 if (is_tracepoint_type (type))
1198 b = new tracepoint ();
1199 else if (is_longjmp_type (type))
1200 b = new longjmp_breakpoint ();
1202 b = new breakpoint ();
1204 return std::unique_ptr<breakpoint> (b);
1207 /* A helper function that validates that COMMANDS are valid for a
1208 breakpoint. This function will throw an exception if a problem is
1212 validate_commands_for_breakpoint (struct breakpoint *b,
1213 struct command_line *commands)
1215 if (is_tracepoint (b))
1217 struct tracepoint *t = (struct tracepoint *) b;
1218 struct command_line *c;
1219 struct command_line *while_stepping = 0;
1221 /* Reset the while-stepping step count. The previous commands
1222 might have included a while-stepping action, while the new
1226 /* We need to verify that each top-level element of commands is
1227 valid for tracepoints, that there's at most one
1228 while-stepping element, and that the while-stepping's body
1229 has valid tracing commands excluding nested while-stepping.
1230 We also need to validate the tracepoint action line in the
1231 context of the tracepoint --- validate_actionline actually
1232 has side effects, like setting the tracepoint's
1233 while-stepping STEP_COUNT, in addition to checking if the
1234 collect/teval actions parse and make sense in the
1235 tracepoint's context. */
1236 for (c = commands; c; c = c->next)
1238 if (c->control_type == while_stepping_control)
1240 if (b->type == bp_fast_tracepoint)
1241 error (_("The 'while-stepping' command "
1242 "cannot be used for fast tracepoint"));
1243 else if (b->type == bp_static_tracepoint)
1244 error (_("The 'while-stepping' command "
1245 "cannot be used for static tracepoint"));
1248 error (_("The 'while-stepping' command "
1249 "can be used only once"));
1254 validate_actionline (c->line, b);
1258 struct command_line *c2;
1260 gdb_assert (while_stepping->body_count == 1);
1261 c2 = while_stepping->body_list[0];
1262 for (; c2; c2 = c2->next)
1264 if (c2->control_type == while_stepping_control)
1265 error (_("The 'while-stepping' command cannot be nested"));
1271 check_no_tracepoint_commands (commands);
1275 /* Return a vector of all the static tracepoints set at ADDR. The
1276 caller is responsible for releasing the vector. */
1279 static_tracepoints_here (CORE_ADDR addr)
1281 struct breakpoint *b;
1282 VEC(breakpoint_p) *found = 0;
1283 struct bp_location *loc;
1286 if (b->type == bp_static_tracepoint)
1288 for (loc = b->loc; loc; loc = loc->next)
1289 if (loc->address == addr)
1290 VEC_safe_push(breakpoint_p, found, b);
1296 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1297 validate that only allowed commands are included. */
1300 breakpoint_set_commands (struct breakpoint *b,
1301 command_line_up &&commands)
1303 validate_commands_for_breakpoint (b, commands.get ());
1305 decref_counted_command_line (&b->commands);
1306 b->commands = alloc_counted_command_line (commands.release ());
1307 observer_notify_breakpoint_modified (b);
1310 /* Set the internal `silent' flag on the breakpoint. Note that this
1311 is not the same as the "silent" that may appear in the breakpoint's
1315 breakpoint_set_silent (struct breakpoint *b, int silent)
1317 int old_silent = b->silent;
1320 if (old_silent != silent)
1321 observer_notify_breakpoint_modified (b);
1324 /* Set the thread for this breakpoint. If THREAD is -1, make the
1325 breakpoint work for any thread. */
1328 breakpoint_set_thread (struct breakpoint *b, int thread)
1330 int old_thread = b->thread;
1333 if (old_thread != thread)
1334 observer_notify_breakpoint_modified (b);
1337 /* Set the task for this breakpoint. If TASK is 0, make the
1338 breakpoint work for any task. */
1341 breakpoint_set_task (struct breakpoint *b, int task)
1343 int old_task = b->task;
1346 if (old_task != task)
1347 observer_notify_breakpoint_modified (b);
1351 check_tracepoint_command (char *line, void *closure)
1353 struct breakpoint *b = (struct breakpoint *) closure;
1355 validate_actionline (line, b);
1358 /* A structure used to pass information through
1359 map_breakpoint_numbers. */
1361 struct commands_info
1363 /* True if the command was typed at a tty. */
1366 /* The breakpoint range spec. */
1369 /* Non-NULL if the body of the commands are being read from this
1370 already-parsed command. */
1371 struct command_line *control;
1373 /* The command lines read from the user, or NULL if they have not
1375 struct counted_command_line *cmd;
1378 /* A callback for map_breakpoint_numbers that sets the commands for
1379 commands_command. */
1382 do_map_commands_command (struct breakpoint *b, void *data)
1384 struct commands_info *info = (struct commands_info *) data;
1386 if (info->cmd == NULL)
1390 if (info->control != NULL)
1391 l = copy_command_lines (info->control->body_list[0]);
1394 struct cleanup *old_chain;
1397 str = xstrprintf (_("Type commands for breakpoint(s) "
1398 "%s, one per line."),
1401 old_chain = make_cleanup (xfree, str);
1403 l = read_command_lines (str,
1406 ? check_tracepoint_command : 0),
1409 do_cleanups (old_chain);
1412 info->cmd = alloc_counted_command_line (l.release ());
1415 /* If a breakpoint was on the list more than once, we don't need to
1417 if (b->commands != info->cmd)
1419 validate_commands_for_breakpoint (b, info->cmd->commands);
1420 incref_counted_command_line (info->cmd);
1421 decref_counted_command_line (&b->commands);
1422 b->commands = info->cmd;
1423 observer_notify_breakpoint_modified (b);
1428 commands_command_1 (const char *arg, int from_tty,
1429 struct command_line *control)
1431 struct cleanup *cleanups;
1432 struct commands_info info;
1434 info.from_tty = from_tty;
1435 info.control = control;
1437 /* If we read command lines from the user, then `info' will hold an
1438 extra reference to the commands that we must clean up. */
1439 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1441 std::string new_arg;
1443 if (arg == NULL || !*arg)
1445 if (breakpoint_count - prev_breakpoint_count > 1)
1446 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1448 else if (breakpoint_count > 0)
1449 new_arg = string_printf ("%d", breakpoint_count);
1454 info.arg = new_arg.c_str ();
1456 map_breakpoint_numbers (info.arg, do_map_commands_command, &info);
1458 if (info.cmd == NULL)
1459 error (_("No breakpoints specified."));
1461 do_cleanups (cleanups);
1465 commands_command (char *arg, int from_tty)
1467 commands_command_1 (arg, from_tty, NULL);
1470 /* Like commands_command, but instead of reading the commands from
1471 input stream, takes them from an already parsed command structure.
1473 This is used by cli-script.c to DTRT with breakpoint commands
1474 that are part of if and while bodies. */
1475 enum command_control_type
1476 commands_from_control_command (const char *arg, struct command_line *cmd)
1478 commands_command_1 (arg, 0, cmd);
1479 return simple_control;
1482 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1485 bp_location_has_shadow (struct bp_location *bl)
1487 if (bl->loc_type != bp_loc_software_breakpoint)
1491 if (bl->target_info.shadow_len == 0)
1492 /* BL isn't valid, or doesn't shadow memory. */
1497 /* Update BUF, which is LEN bytes read from the target address
1498 MEMADDR, by replacing a memory breakpoint with its shadowed
1501 If READBUF is not NULL, this buffer must not overlap with the of
1502 the breakpoint location's shadow_contents buffer. Otherwise, a
1503 failed assertion internal error will be raised. */
1506 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1507 const gdb_byte *writebuf_org,
1508 ULONGEST memaddr, LONGEST len,
1509 struct bp_target_info *target_info,
1510 struct gdbarch *gdbarch)
1512 /* Now do full processing of the found relevant range of elements. */
1513 CORE_ADDR bp_addr = 0;
1517 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1518 current_program_space->aspace, 0))
1520 /* The breakpoint is inserted in a different address space. */
1524 /* Addresses and length of the part of the breakpoint that
1526 bp_addr = target_info->placed_address;
1527 bp_size = target_info->shadow_len;
1529 if (bp_addr + bp_size <= memaddr)
1531 /* The breakpoint is entirely before the chunk of memory we are
1536 if (bp_addr >= memaddr + len)
1538 /* The breakpoint is entirely after the chunk of memory we are
1543 /* Offset within shadow_contents. */
1544 if (bp_addr < memaddr)
1546 /* Only copy the second part of the breakpoint. */
1547 bp_size -= memaddr - bp_addr;
1548 bptoffset = memaddr - bp_addr;
1552 if (bp_addr + bp_size > memaddr + len)
1554 /* Only copy the first part of the breakpoint. */
1555 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1558 if (readbuf != NULL)
1560 /* Verify that the readbuf buffer does not overlap with the
1561 shadow_contents buffer. */
1562 gdb_assert (target_info->shadow_contents >= readbuf + len
1563 || readbuf >= (target_info->shadow_contents
1564 + target_info->shadow_len));
1566 /* Update the read buffer with this inserted breakpoint's
1568 memcpy (readbuf + bp_addr - memaddr,
1569 target_info->shadow_contents + bptoffset, bp_size);
1573 const unsigned char *bp;
1574 CORE_ADDR addr = target_info->reqstd_address;
1577 /* Update the shadow with what we want to write to memory. */
1578 memcpy (target_info->shadow_contents + bptoffset,
1579 writebuf_org + bp_addr - memaddr, bp_size);
1581 /* Determine appropriate breakpoint contents and size for this
1583 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1585 /* Update the final write buffer with this inserted
1586 breakpoint's INSN. */
1587 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1591 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1592 by replacing any memory breakpoints with their shadowed contents.
1594 If READBUF is not NULL, this buffer must not overlap with any of
1595 the breakpoint location's shadow_contents buffers. Otherwise,
1596 a failed assertion internal error will be raised.
1598 The range of shadowed area by each bp_location is:
1599 bl->address - bp_locations_placed_address_before_address_max
1600 up to bl->address + bp_locations_shadow_len_after_address_max
1601 The range we were requested to resolve shadows for is:
1602 memaddr ... memaddr + len
1603 Thus the safe cutoff boundaries for performance optimization are
1604 memaddr + len <= (bl->address
1605 - bp_locations_placed_address_before_address_max)
1607 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1610 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1611 const gdb_byte *writebuf_org,
1612 ULONGEST memaddr, LONGEST len)
1614 /* Left boundary, right boundary and median element of our binary
1616 unsigned bc_l, bc_r, bc;
1618 /* Find BC_L which is a leftmost element which may affect BUF
1619 content. It is safe to report lower value but a failure to
1620 report higher one. */
1623 bc_r = bp_locations_count;
1624 while (bc_l + 1 < bc_r)
1626 struct bp_location *bl;
1628 bc = (bc_l + bc_r) / 2;
1629 bl = bp_locations[bc];
1631 /* Check first BL->ADDRESS will not overflow due to the added
1632 constant. Then advance the left boundary only if we are sure
1633 the BC element can in no way affect the BUF content (MEMADDR
1634 to MEMADDR + LEN range).
1636 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1637 offset so that we cannot miss a breakpoint with its shadow
1638 range tail still reaching MEMADDR. */
1640 if ((bl->address + bp_locations_shadow_len_after_address_max
1642 && (bl->address + bp_locations_shadow_len_after_address_max
1649 /* Due to the binary search above, we need to make sure we pick the
1650 first location that's at BC_L's address. E.g., if there are
1651 multiple locations at the same address, BC_L may end up pointing
1652 at a duplicate location, and miss the "master"/"inserted"
1653 location. Say, given locations L1, L2 and L3 at addresses A and
1656 L1@A, L2@A, L3@B, ...
1658 BC_L could end up pointing at location L2, while the "master"
1659 location could be L1. Since the `loc->inserted' flag is only set
1660 on "master" locations, we'd forget to restore the shadow of L1
1663 && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address)
1666 /* Now do full processing of the found relevant range of elements. */
1668 for (bc = bc_l; bc < bp_locations_count; bc++)
1670 struct bp_location *bl = bp_locations[bc];
1672 /* bp_location array has BL->OWNER always non-NULL. */
1673 if (bl->owner->type == bp_none)
1674 warning (_("reading through apparently deleted breakpoint #%d?"),
1677 /* Performance optimization: any further element can no longer affect BUF
1680 if (bl->address >= bp_locations_placed_address_before_address_max
1681 && memaddr + len <= (bl->address
1682 - bp_locations_placed_address_before_address_max))
1685 if (!bp_location_has_shadow (bl))
1688 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1689 memaddr, len, &bl->target_info, bl->gdbarch);
1695 /* Return true if BPT is either a software breakpoint or a hardware
1699 is_breakpoint (const struct breakpoint *bpt)
1701 return (bpt->type == bp_breakpoint
1702 || bpt->type == bp_hardware_breakpoint
1703 || bpt->type == bp_dprintf);
1706 /* Return true if BPT is of any hardware watchpoint kind. */
1709 is_hardware_watchpoint (const struct breakpoint *bpt)
1711 return (bpt->type == bp_hardware_watchpoint
1712 || bpt->type == bp_read_watchpoint
1713 || bpt->type == bp_access_watchpoint);
1716 /* Return true if BPT is of any watchpoint kind, hardware or
1720 is_watchpoint (const struct breakpoint *bpt)
1722 return (is_hardware_watchpoint (bpt)
1723 || bpt->type == bp_watchpoint);
1726 /* Returns true if the current thread and its running state are safe
1727 to evaluate or update watchpoint B. Watchpoints on local
1728 expressions need to be evaluated in the context of the thread that
1729 was current when the watchpoint was created, and, that thread needs
1730 to be stopped to be able to select the correct frame context.
1731 Watchpoints on global expressions can be evaluated on any thread,
1732 and in any state. It is presently left to the target allowing
1733 memory accesses when threads are running. */
1736 watchpoint_in_thread_scope (struct watchpoint *b)
1738 return (b->pspace == current_program_space
1739 && (ptid_equal (b->watchpoint_thread, null_ptid)
1740 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1741 && !is_executing (inferior_ptid))));
1744 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1745 associated bp_watchpoint_scope breakpoint. */
1748 watchpoint_del_at_next_stop (struct watchpoint *w)
1750 if (w->related_breakpoint != w)
1752 gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope);
1753 gdb_assert (w->related_breakpoint->related_breakpoint == w);
1754 w->related_breakpoint->disposition = disp_del_at_next_stop;
1755 w->related_breakpoint->related_breakpoint = w->related_breakpoint;
1756 w->related_breakpoint = w;
1758 w->disposition = disp_del_at_next_stop;
1761 /* Extract a bitfield value from value VAL using the bit parameters contained in
1764 static struct value *
1765 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1767 struct value *bit_val;
1772 bit_val = allocate_value (value_type (val));
1774 unpack_value_bitfield (bit_val,
1777 value_contents_for_printing (val),
1784 /* Allocate a dummy location and add it to B, which must be a software
1785 watchpoint. This is required because even if a software watchpoint
1786 is not watching any memory, bpstat_stop_status requires a location
1787 to be able to report stops. */
1790 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1791 struct program_space *pspace)
1793 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1795 b->loc = allocate_bp_location (b);
1796 b->loc->pspace = pspace;
1797 b->loc->address = -1;
1798 b->loc->length = -1;
1801 /* Returns true if B is a software watchpoint that is not watching any
1802 memory (e.g., "watch $pc"). */
1805 is_no_memory_software_watchpoint (struct breakpoint *b)
1807 return (b->type == bp_watchpoint
1809 && b->loc->next == NULL
1810 && b->loc->address == -1
1811 && b->loc->length == -1);
1814 /* Assuming that B is a watchpoint:
1815 - Reparse watchpoint expression, if REPARSE is non-zero
1816 - Evaluate expression and store the result in B->val
1817 - Evaluate the condition if there is one, and store the result
1819 - Update the list of values that must be watched in B->loc.
1821 If the watchpoint disposition is disp_del_at_next_stop, then do
1822 nothing. If this is local watchpoint that is out of scope, delete
1825 Even with `set breakpoint always-inserted on' the watchpoints are
1826 removed + inserted on each stop here. Normal breakpoints must
1827 never be removed because they might be missed by a running thread
1828 when debugging in non-stop mode. On the other hand, hardware
1829 watchpoints (is_hardware_watchpoint; processed here) are specific
1830 to each LWP since they are stored in each LWP's hardware debug
1831 registers. Therefore, such LWP must be stopped first in order to
1832 be able to modify its hardware watchpoints.
1834 Hardware watchpoints must be reset exactly once after being
1835 presented to the user. It cannot be done sooner, because it would
1836 reset the data used to present the watchpoint hit to the user. And
1837 it must not be done later because it could display the same single
1838 watchpoint hit during multiple GDB stops. Note that the latter is
1839 relevant only to the hardware watchpoint types bp_read_watchpoint
1840 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1841 not user-visible - its hit is suppressed if the memory content has
1844 The following constraints influence the location where we can reset
1845 hardware watchpoints:
1847 * target_stopped_by_watchpoint and target_stopped_data_address are
1848 called several times when GDB stops.
1851 * Multiple hardware watchpoints can be hit at the same time,
1852 causing GDB to stop. GDB only presents one hardware watchpoint
1853 hit at a time as the reason for stopping, and all the other hits
1854 are presented later, one after the other, each time the user
1855 requests the execution to be resumed. Execution is not resumed
1856 for the threads still having pending hit event stored in
1857 LWP_INFO->STATUS. While the watchpoint is already removed from
1858 the inferior on the first stop the thread hit event is kept being
1859 reported from its cached value by linux_nat_stopped_data_address
1860 until the real thread resume happens after the watchpoint gets
1861 presented and thus its LWP_INFO->STATUS gets reset.
1863 Therefore the hardware watchpoint hit can get safely reset on the
1864 watchpoint removal from inferior. */
1867 update_watchpoint (struct watchpoint *b, int reparse)
1869 int within_current_scope;
1870 struct frame_id saved_frame_id;
1873 /* If this is a local watchpoint, we only want to check if the
1874 watchpoint frame is in scope if the current thread is the thread
1875 that was used to create the watchpoint. */
1876 if (!watchpoint_in_thread_scope (b))
1879 if (b->disposition == disp_del_at_next_stop)
1884 /* Determine if the watchpoint is within scope. */
1885 if (b->exp_valid_block == NULL)
1886 within_current_scope = 1;
1889 struct frame_info *fi = get_current_frame ();
1890 struct gdbarch *frame_arch = get_frame_arch (fi);
1891 CORE_ADDR frame_pc = get_frame_pc (fi);
1893 /* If we're at a point where the stack has been destroyed
1894 (e.g. in a function epilogue), unwinding may not work
1895 properly. Do not attempt to recreate locations at this
1896 point. See similar comments in watchpoint_check. */
1897 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1900 /* Save the current frame's ID so we can restore it after
1901 evaluating the watchpoint expression on its own frame. */
1902 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1903 took a frame parameter, so that we didn't have to change the
1906 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1908 fi = frame_find_by_id (b->watchpoint_frame);
1909 within_current_scope = (fi != NULL);
1910 if (within_current_scope)
1914 /* We don't free locations. They are stored in the bp_location array
1915 and update_global_location_list will eventually delete them and
1916 remove breakpoints if needed. */
1919 if (within_current_scope && reparse)
1924 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1925 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1926 /* If the meaning of expression itself changed, the old value is
1927 no longer relevant. We don't want to report a watchpoint hit
1928 to the user when the old value and the new value may actually
1929 be completely different objects. */
1930 value_free (b->val);
1934 /* Note that unlike with breakpoints, the watchpoint's condition
1935 expression is stored in the breakpoint object, not in the
1936 locations (re)created below. */
1937 if (b->cond_string != NULL)
1939 b->cond_exp.reset ();
1942 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1946 /* If we failed to parse the expression, for example because
1947 it refers to a global variable in a not-yet-loaded shared library,
1948 don't try to insert watchpoint. We don't automatically delete
1949 such watchpoint, though, since failure to parse expression
1950 is different from out-of-scope watchpoint. */
1951 if (!target_has_execution)
1953 /* Without execution, memory can't change. No use to try and
1954 set watchpoint locations. The watchpoint will be reset when
1955 the target gains execution, through breakpoint_re_set. */
1956 if (!can_use_hw_watchpoints)
1958 if (b->ops->works_in_software_mode (b))
1959 b->type = bp_watchpoint;
1961 error (_("Can't set read/access watchpoint when "
1962 "hardware watchpoints are disabled."));
1965 else if (within_current_scope && b->exp)
1968 struct value *val_chain, *v, *result, *next;
1969 struct program_space *frame_pspace;
1971 fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
1973 /* Avoid setting b->val if it's already set. The meaning of
1974 b->val is 'the last value' user saw, and we should update
1975 it only if we reported that last value to user. As it
1976 happens, the code that reports it updates b->val directly.
1977 We don't keep track of the memory value for masked
1979 if (!b->val_valid && !is_masked_watchpoint (b))
1981 if (b->val_bitsize != 0)
1983 v = extract_bitfield_from_watchpoint_value (b, v);
1991 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1993 /* Look at each value on the value chain. */
1994 for (v = val_chain; v; v = value_next (v))
1996 /* If it's a memory location, and GDB actually needed
1997 its contents to evaluate the expression, then we
1998 must watch it. If the first value returned is
1999 still lazy, that means an error occurred reading it;
2000 watch it anyway in case it becomes readable. */
2001 if (VALUE_LVAL (v) == lval_memory
2002 && (v == val_chain || ! value_lazy (v)))
2004 struct type *vtype = check_typedef (value_type (v));
2006 /* We only watch structs and arrays if user asked
2007 for it explicitly, never if they just happen to
2008 appear in the middle of some value chain. */
2010 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2011 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2014 enum target_hw_bp_type type;
2015 struct bp_location *loc, **tmp;
2016 int bitpos = 0, bitsize = 0;
2018 if (value_bitsize (v) != 0)
2020 /* Extract the bit parameters out from the bitfield
2022 bitpos = value_bitpos (v);
2023 bitsize = value_bitsize (v);
2025 else if (v == result && b->val_bitsize != 0)
2027 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2028 lvalue whose bit parameters are saved in the fields
2029 VAL_BITPOS and VAL_BITSIZE. */
2030 bitpos = b->val_bitpos;
2031 bitsize = b->val_bitsize;
2034 addr = value_address (v);
2037 /* Skip the bytes that don't contain the bitfield. */
2042 if (b->type == bp_read_watchpoint)
2044 else if (b->type == bp_access_watchpoint)
2047 loc = allocate_bp_location (b);
2048 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
2051 loc->gdbarch = get_type_arch (value_type (v));
2053 loc->pspace = frame_pspace;
2054 loc->address = addr;
2058 /* Just cover the bytes that make up the bitfield. */
2059 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2062 loc->length = TYPE_LENGTH (value_type (v));
2064 loc->watchpoint_type = type;
2069 /* Change the type of breakpoint between hardware assisted or
2070 an ordinary watchpoint depending on the hardware support
2071 and free hardware slots. REPARSE is set when the inferior
2076 enum bp_loc_type loc_type;
2077 struct bp_location *bl;
2079 reg_cnt = can_use_hardware_watchpoint (val_chain);
2083 int i, target_resources_ok, other_type_used;
2086 /* Use an exact watchpoint when there's only one memory region to be
2087 watched, and only one debug register is needed to watch it. */
2088 b->exact = target_exact_watchpoints && reg_cnt == 1;
2090 /* We need to determine how many resources are already
2091 used for all other hardware watchpoints plus this one
2092 to see if we still have enough resources to also fit
2093 this watchpoint in as well. */
2095 /* If this is a software watchpoint, we try to turn it
2096 to a hardware one -- count resources as if B was of
2097 hardware watchpoint type. */
2099 if (type == bp_watchpoint)
2100 type = bp_hardware_watchpoint;
2102 /* This watchpoint may or may not have been placed on
2103 the list yet at this point (it won't be in the list
2104 if we're trying to create it for the first time,
2105 through watch_command), so always account for it
2108 /* Count resources used by all watchpoints except B. */
2109 i = hw_watchpoint_used_count_others (b, type, &other_type_used);
2111 /* Add in the resources needed for B. */
2112 i += hw_watchpoint_use_count (b);
2115 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2116 if (target_resources_ok <= 0)
2118 int sw_mode = b->ops->works_in_software_mode (b);
2120 if (target_resources_ok == 0 && !sw_mode)
2121 error (_("Target does not support this type of "
2122 "hardware watchpoint."));
2123 else if (target_resources_ok < 0 && !sw_mode)
2124 error (_("There are not enough available hardware "
2125 "resources for this watchpoint."));
2127 /* Downgrade to software watchpoint. */
2128 b->type = bp_watchpoint;
2132 /* If this was a software watchpoint, we've just
2133 found we have enough resources to turn it to a
2134 hardware watchpoint. Otherwise, this is a
2139 else if (!b->ops->works_in_software_mode (b))
2141 if (!can_use_hw_watchpoints)
2142 error (_("Can't set read/access watchpoint when "
2143 "hardware watchpoints are disabled."));
2145 error (_("Expression cannot be implemented with "
2146 "read/access watchpoint."));
2149 b->type = bp_watchpoint;
2151 loc_type = (b->type == bp_watchpoint? bp_loc_other
2152 : bp_loc_hardware_watchpoint);
2153 for (bl = b->loc; bl; bl = bl->next)
2154 bl->loc_type = loc_type;
2157 for (v = val_chain; v; v = next)
2159 next = value_next (v);
2164 /* If a software watchpoint is not watching any memory, then the
2165 above left it without any location set up. But,
2166 bpstat_stop_status requires a location to be able to report
2167 stops, so make sure there's at least a dummy one. */
2168 if (b->type == bp_watchpoint && b->loc == NULL)
2169 software_watchpoint_add_no_memory_location (b, frame_pspace);
2171 else if (!within_current_scope)
2173 printf_filtered (_("\
2174 Watchpoint %d deleted because the program has left the block\n\
2175 in which its expression is valid.\n"),
2177 watchpoint_del_at_next_stop (b);
2180 /* Restore the selected frame. */
2182 select_frame (frame_find_by_id (saved_frame_id));
2186 /* Returns 1 iff breakpoint location should be
2187 inserted in the inferior. We don't differentiate the type of BL's owner
2188 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2189 breakpoint_ops is not defined, because in insert_bp_location,
2190 tracepoint's insert_location will not be called. */
2192 should_be_inserted (struct bp_location *bl)
2194 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2197 if (bl->owner->disposition == disp_del_at_next_stop)
2200 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2203 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2206 /* This is set for example, when we're attached to the parent of a
2207 vfork, and have detached from the child. The child is running
2208 free, and we expect it to do an exec or exit, at which point the
2209 OS makes the parent schedulable again (and the target reports
2210 that the vfork is done). Until the child is done with the shared
2211 memory region, do not insert breakpoints in the parent, otherwise
2212 the child could still trip on the parent's breakpoints. Since
2213 the parent is blocked anyway, it won't miss any breakpoint. */
2214 if (bl->pspace->breakpoints_not_allowed)
2217 /* Don't insert a breakpoint if we're trying to step past its
2218 location, except if the breakpoint is a single-step breakpoint,
2219 and the breakpoint's thread is the thread which is stepping past
2221 if ((bl->loc_type == bp_loc_software_breakpoint
2222 || bl->loc_type == bp_loc_hardware_breakpoint)
2223 && stepping_past_instruction_at (bl->pspace->aspace,
2225 /* The single-step breakpoint may be inserted at the location
2226 we're trying to step if the instruction branches to itself.
2227 However, the instruction won't be executed at all and it may
2228 break the semantics of the instruction, for example, the
2229 instruction is a conditional branch or updates some flags.
2230 We can't fix it unless GDB is able to emulate the instruction
2231 or switch to displaced stepping. */
2232 && !(bl->owner->type == bp_single_step
2233 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2237 fprintf_unfiltered (gdb_stdlog,
2238 "infrun: skipping breakpoint: "
2239 "stepping past insn at: %s\n",
2240 paddress (bl->gdbarch, bl->address));
2245 /* Don't insert watchpoints if we're trying to step past the
2246 instruction that triggered one. */
2247 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2248 && stepping_past_nonsteppable_watchpoint ())
2252 fprintf_unfiltered (gdb_stdlog,
2253 "infrun: stepping past non-steppable watchpoint. "
2254 "skipping watchpoint at %s:%d\n",
2255 paddress (bl->gdbarch, bl->address),
2264 /* Same as should_be_inserted but does the check assuming
2265 that the location is not duplicated. */
2268 unduplicated_should_be_inserted (struct bp_location *bl)
2271 const int save_duplicate = bl->duplicate;
2274 result = should_be_inserted (bl);
2275 bl->duplicate = save_duplicate;
2279 /* Parses a conditional described by an expression COND into an
2280 agent expression bytecode suitable for evaluation
2281 by the bytecode interpreter. Return NULL if there was
2282 any error during parsing. */
2284 static agent_expr_up
2285 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2290 agent_expr_up aexpr;
2292 /* We don't want to stop processing, so catch any errors
2293 that may show up. */
2296 aexpr = gen_eval_for_expr (scope, cond);
2299 CATCH (ex, RETURN_MASK_ERROR)
2301 /* If we got here, it means the condition could not be parsed to a valid
2302 bytecode expression and thus can't be evaluated on the target's side.
2303 It's no use iterating through the conditions. */
2307 /* We have a valid agent expression. */
2311 /* Based on location BL, create a list of breakpoint conditions to be
2312 passed on to the target. If we have duplicated locations with different
2313 conditions, we will add such conditions to the list. The idea is that the
2314 target will evaluate the list of conditions and will only notify GDB when
2315 one of them is true. */
2318 build_target_condition_list (struct bp_location *bl)
2320 struct bp_location **locp = NULL, **loc2p;
2321 int null_condition_or_parse_error = 0;
2322 int modified = bl->needs_update;
2323 struct bp_location *loc;
2325 /* Release conditions left over from a previous insert. */
2326 bl->target_info.conditions.clear ();
2328 /* This is only meaningful if the target is
2329 evaluating conditions and if the user has
2330 opted for condition evaluation on the target's
2332 if (gdb_evaluates_breakpoint_condition_p ()
2333 || !target_supports_evaluation_of_breakpoint_conditions ())
2336 /* Do a first pass to check for locations with no assigned
2337 conditions or conditions that fail to parse to a valid agent expression
2338 bytecode. If any of these happen, then it's no use to send conditions
2339 to the target since this location will always trigger and generate a
2340 response back to GDB. */
2341 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2344 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2348 /* Re-parse the conditions since something changed. In that
2349 case we already freed the condition bytecodes (see
2350 force_breakpoint_reinsertion). We just
2351 need to parse the condition to bytecodes again. */
2352 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2356 /* If we have a NULL bytecode expression, it means something
2357 went wrong or we have a null condition expression. */
2358 if (!loc->cond_bytecode)
2360 null_condition_or_parse_error = 1;
2366 /* If any of these happened, it means we will have to evaluate the conditions
2367 for the location's address on gdb's side. It is no use keeping bytecodes
2368 for all the other duplicate locations, thus we free all of them here.
2370 This is so we have a finer control over which locations' conditions are
2371 being evaluated by GDB or the remote stub. */
2372 if (null_condition_or_parse_error)
2374 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2377 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2379 /* Only go as far as the first NULL bytecode is
2381 if (!loc->cond_bytecode)
2384 loc->cond_bytecode.reset ();
2389 /* No NULL conditions or failed bytecode generation. Build a condition list
2390 for this location's address. */
2391 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2395 && is_breakpoint (loc->owner)
2396 && loc->pspace->num == bl->pspace->num
2397 && loc->owner->enable_state == bp_enabled
2400 /* Add the condition to the vector. This will be used later
2401 to send the conditions to the target. */
2402 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2409 /* Parses a command described by string CMD into an agent expression
2410 bytecode suitable for evaluation by the bytecode interpreter.
2411 Return NULL if there was any error during parsing. */
2413 static agent_expr_up
2414 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2416 struct cleanup *old_cleanups = 0;
2417 struct expression **argvec;
2418 const char *cmdrest;
2419 const char *format_start, *format_end;
2420 struct format_piece *fpieces;
2422 struct gdbarch *gdbarch = get_current_arch ();
2429 if (*cmdrest == ',')
2431 cmdrest = skip_spaces_const (cmdrest);
2433 if (*cmdrest++ != '"')
2434 error (_("No format string following the location"));
2436 format_start = cmdrest;
2438 fpieces = parse_format_string (&cmdrest);
2440 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2442 format_end = cmdrest;
2444 if (*cmdrest++ != '"')
2445 error (_("Bad format string, non-terminated '\"'."));
2447 cmdrest = skip_spaces_const (cmdrest);
2449 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2450 error (_("Invalid argument syntax"));
2452 if (*cmdrest == ',')
2454 cmdrest = skip_spaces_const (cmdrest);
2456 /* For each argument, make an expression. */
2458 argvec = (struct expression **) alloca (strlen (cmd)
2459 * sizeof (struct expression *));
2462 while (*cmdrest != '\0')
2467 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2468 argvec[nargs++] = expr.release ();
2470 if (*cmdrest == ',')
2474 agent_expr_up aexpr;
2476 /* We don't want to stop processing, so catch any errors
2477 that may show up. */
2480 aexpr = gen_printf (scope, gdbarch, 0, 0,
2481 format_start, format_end - format_start,
2482 fpieces, nargs, argvec);
2484 CATCH (ex, RETURN_MASK_ERROR)
2486 /* If we got here, it means the command could not be parsed to a valid
2487 bytecode expression and thus can't be evaluated on the target's side.
2488 It's no use iterating through the other commands. */
2492 do_cleanups (old_cleanups);
2494 /* We have a valid agent expression, return it. */
2498 /* Based on location BL, create a list of breakpoint commands to be
2499 passed on to the target. If we have duplicated locations with
2500 different commands, we will add any such to the list. */
2503 build_target_command_list (struct bp_location *bl)
2505 struct bp_location **locp = NULL, **loc2p;
2506 int null_command_or_parse_error = 0;
2507 int modified = bl->needs_update;
2508 struct bp_location *loc;
2510 /* Clear commands left over from a previous insert. */
2511 bl->target_info.tcommands.clear ();
2513 if (!target_can_run_breakpoint_commands ())
2516 /* For now, limit to agent-style dprintf breakpoints. */
2517 if (dprintf_style != dprintf_style_agent)
2520 /* For now, if we have any duplicate location that isn't a dprintf,
2521 don't install the target-side commands, as that would make the
2522 breakpoint not be reported to the core, and we'd lose
2524 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2527 if (is_breakpoint (loc->owner)
2528 && loc->pspace->num == bl->pspace->num
2529 && loc->owner->type != bp_dprintf)
2533 /* Do a first pass to check for locations with no assigned
2534 conditions or conditions that fail to parse to a valid agent expression
2535 bytecode. If any of these happen, then it's no use to send conditions
2536 to the target since this location will always trigger and generate a
2537 response back to GDB. */
2538 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2541 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2545 /* Re-parse the commands since something changed. In that
2546 case we already freed the command bytecodes (see
2547 force_breakpoint_reinsertion). We just
2548 need to parse the command to bytecodes again. */
2550 = parse_cmd_to_aexpr (bl->address,
2551 loc->owner->extra_string);
2554 /* If we have a NULL bytecode expression, it means something
2555 went wrong or we have a null command expression. */
2556 if (!loc->cmd_bytecode)
2558 null_command_or_parse_error = 1;
2564 /* If anything failed, then we're not doing target-side commands,
2566 if (null_command_or_parse_error)
2568 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2571 if (is_breakpoint (loc->owner)
2572 && loc->pspace->num == bl->pspace->num)
2574 /* Only go as far as the first NULL bytecode is
2576 if (loc->cmd_bytecode == NULL)
2579 loc->cmd_bytecode.reset ();
2584 /* No NULL commands or failed bytecode generation. Build a command list
2585 for this location's address. */
2586 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2589 if (loc->owner->extra_string
2590 && is_breakpoint (loc->owner)
2591 && loc->pspace->num == bl->pspace->num
2592 && loc->owner->enable_state == bp_enabled
2595 /* Add the command to the vector. This will be used later
2596 to send the commands to the target. */
2597 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2601 bl->target_info.persist = 0;
2602 /* Maybe flag this location as persistent. */
2603 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2604 bl->target_info.persist = 1;
2607 /* Return the kind of breakpoint on address *ADDR. Get the kind
2608 of breakpoint according to ADDR except single-step breakpoint.
2609 Get the kind of single-step breakpoint according to the current
2613 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2615 if (bl->owner->type == bp_single_step)
2617 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2618 struct regcache *regcache;
2620 regcache = get_thread_regcache (thr->ptid);
2622 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2626 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2629 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2630 location. Any error messages are printed to TMP_ERROR_STREAM; and
2631 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2632 Returns 0 for success, 1 if the bp_location type is not supported or
2635 NOTE drow/2003-09-09: This routine could be broken down to an
2636 object-style method for each breakpoint or catchpoint type. */
2638 insert_bp_location (struct bp_location *bl,
2639 struct ui_file *tmp_error_stream,
2640 int *disabled_breaks,
2641 int *hw_breakpoint_error,
2642 int *hw_bp_error_explained_already)
2644 enum errors bp_err = GDB_NO_ERROR;
2645 const char *bp_err_message = NULL;
2647 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2650 /* Note we don't initialize bl->target_info, as that wipes out
2651 the breakpoint location's shadow_contents if the breakpoint
2652 is still inserted at that location. This in turn breaks
2653 target_read_memory which depends on these buffers when
2654 a memory read is requested at the breakpoint location:
2655 Once the target_info has been wiped, we fail to see that
2656 we have a breakpoint inserted at that address and thus
2657 read the breakpoint instead of returning the data saved in
2658 the breakpoint location's shadow contents. */
2659 bl->target_info.reqstd_address = bl->address;
2660 bl->target_info.placed_address_space = bl->pspace->aspace;
2661 bl->target_info.length = bl->length;
2663 /* When working with target-side conditions, we must pass all the conditions
2664 for the same breakpoint address down to the target since GDB will not
2665 insert those locations. With a list of breakpoint conditions, the target
2666 can decide when to stop and notify GDB. */
2668 if (is_breakpoint (bl->owner))
2670 build_target_condition_list (bl);
2671 build_target_command_list (bl);
2672 /* Reset the modification marker. */
2673 bl->needs_update = 0;
2676 if (bl->loc_type == bp_loc_software_breakpoint
2677 || bl->loc_type == bp_loc_hardware_breakpoint)
2679 if (bl->owner->type != bp_hardware_breakpoint)
2681 /* If the explicitly specified breakpoint type
2682 is not hardware breakpoint, check the memory map to see
2683 if the breakpoint address is in read only memory or not.
2685 Two important cases are:
2686 - location type is not hardware breakpoint, memory
2687 is readonly. We change the type of the location to
2688 hardware breakpoint.
2689 - location type is hardware breakpoint, memory is
2690 read-write. This means we've previously made the
2691 location hardware one, but then the memory map changed,
2694 When breakpoints are removed, remove_breakpoints will use
2695 location types we've just set here, the only possible
2696 problem is that memory map has changed during running
2697 program, but it's not going to work anyway with current
2699 struct mem_region *mr
2700 = lookup_mem_region (bl->target_info.reqstd_address);
2704 if (automatic_hardware_breakpoints)
2706 enum bp_loc_type new_type;
2708 if (mr->attrib.mode != MEM_RW)
2709 new_type = bp_loc_hardware_breakpoint;
2711 new_type = bp_loc_software_breakpoint;
2713 if (new_type != bl->loc_type)
2715 static int said = 0;
2717 bl->loc_type = new_type;
2720 fprintf_filtered (gdb_stdout,
2721 _("Note: automatically using "
2722 "hardware breakpoints for "
2723 "read-only addresses.\n"));
2728 else if (bl->loc_type == bp_loc_software_breakpoint
2729 && mr->attrib.mode != MEM_RW)
2731 fprintf_unfiltered (tmp_error_stream,
2732 _("Cannot insert breakpoint %d.\n"
2733 "Cannot set software breakpoint "
2734 "at read-only address %s\n"),
2736 paddress (bl->gdbarch, bl->address));
2742 /* First check to see if we have to handle an overlay. */
2743 if (overlay_debugging == ovly_off
2744 || bl->section == NULL
2745 || !(section_is_overlay (bl->section)))
2747 /* No overlay handling: just set the breakpoint. */
2752 val = bl->owner->ops->insert_location (bl);
2754 bp_err = GENERIC_ERROR;
2756 CATCH (e, RETURN_MASK_ALL)
2759 bp_err_message = e.message;
2765 /* This breakpoint is in an overlay section.
2766 Shall we set a breakpoint at the LMA? */
2767 if (!overlay_events_enabled)
2769 /* Yes -- overlay event support is not active,
2770 so we must try to set a breakpoint at the LMA.
2771 This will not work for a hardware breakpoint. */
2772 if (bl->loc_type == bp_loc_hardware_breakpoint)
2773 warning (_("hardware breakpoint %d not supported in overlay!"),
2777 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2779 /* Set a software (trap) breakpoint at the LMA. */
2780 bl->overlay_target_info = bl->target_info;
2781 bl->overlay_target_info.reqstd_address = addr;
2783 /* No overlay handling: just set the breakpoint. */
2788 bl->overlay_target_info.kind
2789 = breakpoint_kind (bl, &addr);
2790 bl->overlay_target_info.placed_address = addr;
2791 val = target_insert_breakpoint (bl->gdbarch,
2792 &bl->overlay_target_info);
2794 bp_err = GENERIC_ERROR;
2796 CATCH (e, RETURN_MASK_ALL)
2799 bp_err_message = e.message;
2803 if (bp_err != GDB_NO_ERROR)
2804 fprintf_unfiltered (tmp_error_stream,
2805 "Overlay breakpoint %d "
2806 "failed: in ROM?\n",
2810 /* Shall we set a breakpoint at the VMA? */
2811 if (section_is_mapped (bl->section))
2813 /* Yes. This overlay section is mapped into memory. */
2818 val = bl->owner->ops->insert_location (bl);
2820 bp_err = GENERIC_ERROR;
2822 CATCH (e, RETURN_MASK_ALL)
2825 bp_err_message = e.message;
2831 /* No. This breakpoint will not be inserted.
2832 No error, but do not mark the bp as 'inserted'. */
2837 if (bp_err != GDB_NO_ERROR)
2839 /* Can't set the breakpoint. */
2841 /* In some cases, we might not be able to insert a
2842 breakpoint in a shared library that has already been
2843 removed, but we have not yet processed the shlib unload
2844 event. Unfortunately, some targets that implement
2845 breakpoint insertion themselves can't tell why the
2846 breakpoint insertion failed (e.g., the remote target
2847 doesn't define error codes), so we must treat generic
2848 errors as memory errors. */
2849 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2850 && bl->loc_type == bp_loc_software_breakpoint
2851 && (solib_name_from_address (bl->pspace, bl->address)
2852 || shared_objfile_contains_address_p (bl->pspace,
2855 /* See also: disable_breakpoints_in_shlibs. */
2856 bl->shlib_disabled = 1;
2857 observer_notify_breakpoint_modified (bl->owner);
2858 if (!*disabled_breaks)
2860 fprintf_unfiltered (tmp_error_stream,
2861 "Cannot insert breakpoint %d.\n",
2863 fprintf_unfiltered (tmp_error_stream,
2864 "Temporarily disabling shared "
2865 "library breakpoints:\n");
2867 *disabled_breaks = 1;
2868 fprintf_unfiltered (tmp_error_stream,
2869 "breakpoint #%d\n", bl->owner->number);
2874 if (bl->loc_type == bp_loc_hardware_breakpoint)
2876 *hw_breakpoint_error = 1;
2877 *hw_bp_error_explained_already = bp_err_message != NULL;
2878 fprintf_unfiltered (tmp_error_stream,
2879 "Cannot insert hardware breakpoint %d%s",
2880 bl->owner->number, bp_err_message ? ":" : ".\n");
2881 if (bp_err_message != NULL)
2882 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2886 if (bp_err_message == NULL)
2889 = memory_error_message (TARGET_XFER_E_IO,
2890 bl->gdbarch, bl->address);
2891 struct cleanup *old_chain = make_cleanup (xfree, message);
2893 fprintf_unfiltered (tmp_error_stream,
2894 "Cannot insert breakpoint %d.\n"
2896 bl->owner->number, message);
2897 do_cleanups (old_chain);
2901 fprintf_unfiltered (tmp_error_stream,
2902 "Cannot insert breakpoint %d: %s\n",
2917 else if (bl->loc_type == bp_loc_hardware_watchpoint
2918 /* NOTE drow/2003-09-08: This state only exists for removing
2919 watchpoints. It's not clear that it's necessary... */
2920 && bl->owner->disposition != disp_del_at_next_stop)
2924 gdb_assert (bl->owner->ops != NULL
2925 && bl->owner->ops->insert_location != NULL);
2927 val = bl->owner->ops->insert_location (bl);
2929 /* If trying to set a read-watchpoint, and it turns out it's not
2930 supported, try emulating one with an access watchpoint. */
2931 if (val == 1 && bl->watchpoint_type == hw_read)
2933 struct bp_location *loc, **loc_temp;
2935 /* But don't try to insert it, if there's already another
2936 hw_access location that would be considered a duplicate
2938 ALL_BP_LOCATIONS (loc, loc_temp)
2940 && loc->watchpoint_type == hw_access
2941 && watchpoint_locations_match (bl, loc))
2945 bl->target_info = loc->target_info;
2946 bl->watchpoint_type = hw_access;
2953 bl->watchpoint_type = hw_access;
2954 val = bl->owner->ops->insert_location (bl);
2957 /* Back to the original value. */
2958 bl->watchpoint_type = hw_read;
2962 bl->inserted = (val == 0);
2965 else if (bl->owner->type == bp_catchpoint)
2969 gdb_assert (bl->owner->ops != NULL
2970 && bl->owner->ops->insert_location != NULL);
2972 val = bl->owner->ops->insert_location (bl);
2975 bl->owner->enable_state = bp_disabled;
2979 Error inserting catchpoint %d: Your system does not support this type\n\
2980 of catchpoint."), bl->owner->number);
2982 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2985 bl->inserted = (val == 0);
2987 /* We've already printed an error message if there was a problem
2988 inserting this catchpoint, and we've disabled the catchpoint,
2989 so just return success. */
2996 /* This function is called when program space PSPACE is about to be
2997 deleted. It takes care of updating breakpoints to not reference
3001 breakpoint_program_space_exit (struct program_space *pspace)
3003 struct breakpoint *b, *b_temp;
3004 struct bp_location *loc, **loc_temp;
3006 /* Remove any breakpoint that was set through this program space. */
3007 ALL_BREAKPOINTS_SAFE (b, b_temp)
3009 if (b->pspace == pspace)
3010 delete_breakpoint (b);
3013 /* Breakpoints set through other program spaces could have locations
3014 bound to PSPACE as well. Remove those. */
3015 ALL_BP_LOCATIONS (loc, loc_temp)
3017 struct bp_location *tmp;
3019 if (loc->pspace == pspace)
3021 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3022 if (loc->owner->loc == loc)
3023 loc->owner->loc = loc->next;
3025 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
3026 if (tmp->next == loc)
3028 tmp->next = loc->next;
3034 /* Now update the global location list to permanently delete the
3035 removed locations above. */
3036 update_global_location_list (UGLL_DONT_INSERT);
3039 /* Make sure all breakpoints are inserted in inferior.
3040 Throws exception on any error.
3041 A breakpoint that is already inserted won't be inserted
3042 again, so calling this function twice is safe. */
3044 insert_breakpoints (void)
3046 struct breakpoint *bpt;
3048 ALL_BREAKPOINTS (bpt)
3049 if (is_hardware_watchpoint (bpt))
3051 struct watchpoint *w = (struct watchpoint *) bpt;
3053 update_watchpoint (w, 0 /* don't reparse. */);
3056 /* Updating watchpoints creates new locations, so update the global
3057 location list. Explicitly tell ugll to insert locations and
3058 ignore breakpoints_always_inserted_mode. */
3059 update_global_location_list (UGLL_INSERT);
3062 /* Invoke CALLBACK for each of bp_location. */
3065 iterate_over_bp_locations (walk_bp_location_callback callback)
3067 struct bp_location *loc, **loc_tmp;
3069 ALL_BP_LOCATIONS (loc, loc_tmp)
3071 callback (loc, NULL);
3075 /* This is used when we need to synch breakpoint conditions between GDB and the
3076 target. It is the case with deleting and disabling of breakpoints when using
3077 always-inserted mode. */
3080 update_inserted_breakpoint_locations (void)
3082 struct bp_location *bl, **blp_tmp;
3085 int disabled_breaks = 0;
3086 int hw_breakpoint_error = 0;
3087 int hw_bp_details_reported = 0;
3089 string_file tmp_error_stream;
3091 /* Explicitly mark the warning -- this will only be printed if
3092 there was an error. */
3093 tmp_error_stream.puts ("Warning:\n");
3095 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3097 ALL_BP_LOCATIONS (bl, blp_tmp)
3099 /* We only want to update software breakpoints and hardware
3101 if (!is_breakpoint (bl->owner))
3104 /* We only want to update locations that are already inserted
3105 and need updating. This is to avoid unwanted insertion during
3106 deletion of breakpoints. */
3107 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3110 switch_to_program_space_and_thread (bl->pspace);
3112 /* For targets that support global breakpoints, there's no need
3113 to select an inferior to insert breakpoint to. In fact, even
3114 if we aren't attached to any process yet, we should still
3115 insert breakpoints. */
3116 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3117 && ptid_equal (inferior_ptid, null_ptid))
3120 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
3121 &hw_breakpoint_error, &hw_bp_details_reported);
3128 target_terminal_ours_for_output ();
3129 error_stream (tmp_error_stream);
3133 /* Used when starting or continuing the program. */
3136 insert_breakpoint_locations (void)
3138 struct breakpoint *bpt;
3139 struct bp_location *bl, **blp_tmp;
3142 int disabled_breaks = 0;
3143 int hw_breakpoint_error = 0;
3144 int hw_bp_error_explained_already = 0;
3146 string_file tmp_error_stream;
3148 /* Explicitly mark the warning -- this will only be printed if
3149 there was an error. */
3150 tmp_error_stream.puts ("Warning:\n");
3152 scoped_restore_current_pspace_and_thread restore_pspace_thread;
3154 ALL_BP_LOCATIONS (bl, blp_tmp)
3156 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3159 /* There is no point inserting thread-specific breakpoints if
3160 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3161 has BL->OWNER always non-NULL. */
3162 if (bl->owner->thread != -1
3163 && !valid_global_thread_id (bl->owner->thread))
3166 switch_to_program_space_and_thread (bl->pspace);
3168 /* For targets that support global breakpoints, there's no need
3169 to select an inferior to insert breakpoint to. In fact, even
3170 if we aren't attached to any process yet, we should still
3171 insert breakpoints. */
3172 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3173 && ptid_equal (inferior_ptid, null_ptid))
3176 val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks,
3177 &hw_breakpoint_error, &hw_bp_error_explained_already);
3182 /* If we failed to insert all locations of a watchpoint, remove
3183 them, as half-inserted watchpoint is of limited use. */
3184 ALL_BREAKPOINTS (bpt)
3186 int some_failed = 0;
3187 struct bp_location *loc;
3189 if (!is_hardware_watchpoint (bpt))
3192 if (!breakpoint_enabled (bpt))
3195 if (bpt->disposition == disp_del_at_next_stop)
3198 for (loc = bpt->loc; loc; loc = loc->next)
3199 if (!loc->inserted && should_be_inserted (loc))
3206 for (loc = bpt->loc; loc; loc = loc->next)
3208 remove_breakpoint (loc);
3210 hw_breakpoint_error = 1;
3211 tmp_error_stream.printf ("Could not insert "
3212 "hardware watchpoint %d.\n",
3220 /* If a hardware breakpoint or watchpoint was inserted, add a
3221 message about possibly exhausted resources. */
3222 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3224 tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
3225 You may have requested too many hardware breakpoints/watchpoints.\n");
3227 target_terminal_ours_for_output ();
3228 error_stream (tmp_error_stream);
3232 /* Used when the program stops.
3233 Returns zero if successful, or non-zero if there was a problem
3234 removing a breakpoint location. */
3237 remove_breakpoints (void)
3239 struct bp_location *bl, **blp_tmp;
3242 ALL_BP_LOCATIONS (bl, blp_tmp)
3244 if (bl->inserted && !is_tracepoint (bl->owner))
3245 val |= remove_breakpoint (bl);
3250 /* When a thread exits, remove breakpoints that are related to
3254 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3256 struct breakpoint *b, *b_tmp;
3258 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3260 if (b->thread == tp->global_num && user_breakpoint_p (b))
3262 b->disposition = disp_del_at_next_stop;
3264 printf_filtered (_("\
3265 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3266 b->number, print_thread_id (tp));
3268 /* Hide it from the user. */
3274 /* Remove breakpoints of process PID. */
3277 remove_breakpoints_pid (int pid)
3279 struct bp_location *bl, **blp_tmp;
3281 struct inferior *inf = find_inferior_pid (pid);
3283 ALL_BP_LOCATIONS (bl, blp_tmp)
3285 if (bl->pspace != inf->pspace)
3288 if (bl->inserted && !bl->target_info.persist)
3290 val = remove_breakpoint (bl);
3299 reattach_breakpoints (int pid)
3301 struct cleanup *old_chain;
3302 struct bp_location *bl, **blp_tmp;
3304 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3305 struct inferior *inf;
3306 struct thread_info *tp;
3308 tp = any_live_thread_of_process (pid);
3312 inf = find_inferior_pid (pid);
3313 old_chain = save_inferior_ptid ();
3315 inferior_ptid = tp->ptid;
3317 string_file tmp_error_stream;
3319 ALL_BP_LOCATIONS (bl, blp_tmp)
3321 if (bl->pspace != inf->pspace)
3327 val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3);
3330 do_cleanups (old_chain);
3335 do_cleanups (old_chain);
3339 static int internal_breakpoint_number = -1;
3341 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3342 If INTERNAL is non-zero, the breakpoint number will be populated
3343 from internal_breakpoint_number and that variable decremented.
3344 Otherwise the breakpoint number will be populated from
3345 breakpoint_count and that value incremented. Internal breakpoints
3346 do not set the internal var bpnum. */
3348 set_breakpoint_number (int internal, struct breakpoint *b)
3351 b->number = internal_breakpoint_number--;
3354 set_breakpoint_count (breakpoint_count + 1);
3355 b->number = breakpoint_count;
3359 static struct breakpoint *
3360 create_internal_breakpoint (struct gdbarch *gdbarch,
3361 CORE_ADDR address, enum bptype type,
3362 const struct breakpoint_ops *ops)
3364 struct symtab_and_line sal;
3365 struct breakpoint *b;
3367 init_sal (&sal); /* Initialize to zeroes. */
3370 sal.section = find_pc_overlay (sal.pc);
3371 sal.pspace = current_program_space;
3373 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3374 b->number = internal_breakpoint_number--;
3375 b->disposition = disp_donttouch;
3380 static const char *const longjmp_names[] =
3382 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3384 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3386 /* Per-objfile data private to breakpoint.c. */
3387 struct breakpoint_objfile_data
3389 /* Minimal symbol for "_ovly_debug_event" (if any). */
3390 struct bound_minimal_symbol overlay_msym;
3392 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3393 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3395 /* True if we have looked for longjmp probes. */
3396 int longjmp_searched;
3398 /* SystemTap probe points for longjmp (if any). */
3399 VEC (probe_p) *longjmp_probes;
3401 /* Minimal symbol for "std::terminate()" (if any). */
3402 struct bound_minimal_symbol terminate_msym;
3404 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3405 struct bound_minimal_symbol exception_msym;
3407 /* True if we have looked for exception probes. */
3408 int exception_searched;
3410 /* SystemTap probe points for unwinding (if any). */
3411 VEC (probe_p) *exception_probes;
3414 static const struct objfile_data *breakpoint_objfile_key;
3416 /* Minimal symbol not found sentinel. */
3417 static struct minimal_symbol msym_not_found;
3419 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3422 msym_not_found_p (const struct minimal_symbol *msym)
3424 return msym == &msym_not_found;
3427 /* Return per-objfile data needed by breakpoint.c.
3428 Allocate the data if necessary. */
3430 static struct breakpoint_objfile_data *
3431 get_breakpoint_objfile_data (struct objfile *objfile)
3433 struct breakpoint_objfile_data *bp_objfile_data;
3435 bp_objfile_data = ((struct breakpoint_objfile_data *)
3436 objfile_data (objfile, breakpoint_objfile_key));
3437 if (bp_objfile_data == NULL)
3440 XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
3442 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3443 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3445 return bp_objfile_data;
3449 free_breakpoint_probes (struct objfile *obj, void *data)
3451 struct breakpoint_objfile_data *bp_objfile_data
3452 = (struct breakpoint_objfile_data *) data;
3454 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3455 VEC_free (probe_p, bp_objfile_data->exception_probes);
3459 create_overlay_event_breakpoint (void)
3461 struct objfile *objfile;
3462 const char *const func_name = "_ovly_debug_event";
3464 ALL_OBJFILES (objfile)
3466 struct breakpoint *b;
3467 struct breakpoint_objfile_data *bp_objfile_data;
3469 struct explicit_location explicit_loc;
3471 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3473 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3476 if (bp_objfile_data->overlay_msym.minsym == NULL)
3478 struct bound_minimal_symbol m;
3480 m = lookup_minimal_symbol_text (func_name, objfile);
3481 if (m.minsym == NULL)
3483 /* Avoid future lookups in this objfile. */
3484 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3487 bp_objfile_data->overlay_msym = m;
3490 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3491 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3493 &internal_breakpoint_ops);
3494 initialize_explicit_location (&explicit_loc);
3495 explicit_loc.function_name = ASTRDUP (func_name);
3496 b->location = new_explicit_location (&explicit_loc);
3498 if (overlay_debugging == ovly_auto)
3500 b->enable_state = bp_enabled;
3501 overlay_events_enabled = 1;
3505 b->enable_state = bp_disabled;
3506 overlay_events_enabled = 0;
3512 create_longjmp_master_breakpoint (void)
3514 struct program_space *pspace;
3516 scoped_restore_current_program_space restore_pspace;
3518 ALL_PSPACES (pspace)
3520 struct objfile *objfile;
3522 set_current_program_space (pspace);
3524 ALL_OBJFILES (objfile)
3527 struct gdbarch *gdbarch;
3528 struct breakpoint_objfile_data *bp_objfile_data;
3530 gdbarch = get_objfile_arch (objfile);
3532 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3534 if (!bp_objfile_data->longjmp_searched)
3538 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3541 /* We are only interested in checking one element. */
3542 struct probe *p = VEC_index (probe_p, ret, 0);
3544 if (!can_evaluate_probe_arguments (p))
3546 /* We cannot use the probe interface here, because it does
3547 not know how to evaluate arguments. */
3548 VEC_free (probe_p, ret);
3552 bp_objfile_data->longjmp_probes = ret;
3553 bp_objfile_data->longjmp_searched = 1;
3556 if (bp_objfile_data->longjmp_probes != NULL)
3559 struct probe *probe;
3560 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3563 VEC_iterate (probe_p,
3564 bp_objfile_data->longjmp_probes,
3568 struct breakpoint *b;
3570 b = create_internal_breakpoint (gdbarch,
3571 get_probe_address (probe,
3574 &internal_breakpoint_ops);
3575 b->location = new_probe_location ("-probe-stap libc:longjmp");
3576 b->enable_state = bp_disabled;
3582 if (!gdbarch_get_longjmp_target_p (gdbarch))
3585 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3587 struct breakpoint *b;
3588 const char *func_name;
3590 struct explicit_location explicit_loc;
3592 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3595 func_name = longjmp_names[i];
3596 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3598 struct bound_minimal_symbol m;
3600 m = lookup_minimal_symbol_text (func_name, objfile);
3601 if (m.minsym == NULL)
3603 /* Prevent future lookups in this objfile. */
3604 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3607 bp_objfile_data->longjmp_msym[i] = m;
3610 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3611 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3612 &internal_breakpoint_ops);
3613 initialize_explicit_location (&explicit_loc);
3614 explicit_loc.function_name = ASTRDUP (func_name);
3615 b->location = new_explicit_location (&explicit_loc);
3616 b->enable_state = bp_disabled;
3622 /* Create a master std::terminate breakpoint. */
3624 create_std_terminate_master_breakpoint (void)
3626 struct program_space *pspace;
3627 const char *const func_name = "std::terminate()";
3629 scoped_restore_current_program_space restore_pspace;
3631 ALL_PSPACES (pspace)
3633 struct objfile *objfile;
3636 set_current_program_space (pspace);
3638 ALL_OBJFILES (objfile)
3640 struct breakpoint *b;
3641 struct breakpoint_objfile_data *bp_objfile_data;
3642 struct explicit_location explicit_loc;
3644 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3646 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3649 if (bp_objfile_data->terminate_msym.minsym == NULL)
3651 struct bound_minimal_symbol m;
3653 m = lookup_minimal_symbol (func_name, NULL, objfile);
3654 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3655 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3657 /* Prevent future lookups in this objfile. */
3658 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3661 bp_objfile_data->terminate_msym = m;
3664 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3665 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3666 bp_std_terminate_master,
3667 &internal_breakpoint_ops);
3668 initialize_explicit_location (&explicit_loc);
3669 explicit_loc.function_name = ASTRDUP (func_name);
3670 b->location = new_explicit_location (&explicit_loc);
3671 b->enable_state = bp_disabled;
3676 /* Install a master breakpoint on the unwinder's debug hook. */
3679 create_exception_master_breakpoint (void)
3681 struct objfile *objfile;
3682 const char *const func_name = "_Unwind_DebugHook";
3684 ALL_OBJFILES (objfile)
3686 struct breakpoint *b;
3687 struct gdbarch *gdbarch;
3688 struct breakpoint_objfile_data *bp_objfile_data;
3690 struct explicit_location explicit_loc;
3692 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3694 /* We prefer the SystemTap probe point if it exists. */
3695 if (!bp_objfile_data->exception_searched)
3699 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3703 /* We are only interested in checking one element. */
3704 struct probe *p = VEC_index (probe_p, ret, 0);
3706 if (!can_evaluate_probe_arguments (p))
3708 /* We cannot use the probe interface here, because it does
3709 not know how to evaluate arguments. */
3710 VEC_free (probe_p, ret);
3714 bp_objfile_data->exception_probes = ret;
3715 bp_objfile_data->exception_searched = 1;
3718 if (bp_objfile_data->exception_probes != NULL)
3720 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3722 struct probe *probe;
3725 VEC_iterate (probe_p,
3726 bp_objfile_data->exception_probes,
3730 struct breakpoint *b;
3732 b = create_internal_breakpoint (gdbarch,
3733 get_probe_address (probe,
3735 bp_exception_master,
3736 &internal_breakpoint_ops);
3737 b->location = new_probe_location ("-probe-stap libgcc:unwind");
3738 b->enable_state = bp_disabled;
3744 /* Otherwise, try the hook function. */
3746 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3749 gdbarch = get_objfile_arch (objfile);
3751 if (bp_objfile_data->exception_msym.minsym == NULL)
3753 struct bound_minimal_symbol debug_hook;
3755 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3756 if (debug_hook.minsym == NULL)
3758 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3762 bp_objfile_data->exception_msym = debug_hook;
3765 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3766 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3768 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3769 &internal_breakpoint_ops);
3770 initialize_explicit_location (&explicit_loc);
3771 explicit_loc.function_name = ASTRDUP (func_name);
3772 b->location = new_explicit_location (&explicit_loc);
3773 b->enable_state = bp_disabled;
3777 /* Does B have a location spec? */
3780 breakpoint_event_location_empty_p (const struct breakpoint *b)
3782 return b->location != NULL && event_location_empty_p (b->location.get ());
3786 update_breakpoints_after_exec (void)
3788 struct breakpoint *b, *b_tmp;
3789 struct bp_location *bploc, **bplocp_tmp;
3791 /* We're about to delete breakpoints from GDB's lists. If the
3792 INSERTED flag is true, GDB will try to lift the breakpoints by
3793 writing the breakpoints' "shadow contents" back into memory. The
3794 "shadow contents" are NOT valid after an exec, so GDB should not
3795 do that. Instead, the target is responsible from marking
3796 breakpoints out as soon as it detects an exec. We don't do that
3797 here instead, because there may be other attempts to delete
3798 breakpoints after detecting an exec and before reaching here. */
3799 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3800 if (bploc->pspace == current_program_space)
3801 gdb_assert (!bploc->inserted);
3803 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3805 if (b->pspace != current_program_space)
3808 /* Solib breakpoints must be explicitly reset after an exec(). */
3809 if (b->type == bp_shlib_event)
3811 delete_breakpoint (b);
3815 /* JIT breakpoints must be explicitly reset after an exec(). */
3816 if (b->type == bp_jit_event)
3818 delete_breakpoint (b);
3822 /* Thread event breakpoints must be set anew after an exec(),
3823 as must overlay event and longjmp master breakpoints. */
3824 if (b->type == bp_thread_event || b->type == bp_overlay_event
3825 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3826 || b->type == bp_exception_master)
3828 delete_breakpoint (b);
3832 /* Step-resume breakpoints are meaningless after an exec(). */
3833 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3835 delete_breakpoint (b);
3839 /* Just like single-step breakpoints. */
3840 if (b->type == bp_single_step)
3842 delete_breakpoint (b);
3846 /* Longjmp and longjmp-resume breakpoints are also meaningless
3848 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3849 || b->type == bp_longjmp_call_dummy
3850 || b->type == bp_exception || b->type == bp_exception_resume)
3852 delete_breakpoint (b);
3856 if (b->type == bp_catchpoint)
3858 /* For now, none of the bp_catchpoint breakpoints need to
3859 do anything at this point. In the future, if some of
3860 the catchpoints need to something, we will need to add
3861 a new method, and call this method from here. */
3865 /* bp_finish is a special case. The only way we ought to be able
3866 to see one of these when an exec() has happened, is if the user
3867 caught a vfork, and then said "finish". Ordinarily a finish just
3868 carries them to the call-site of the current callee, by setting
3869 a temporary bp there and resuming. But in this case, the finish
3870 will carry them entirely through the vfork & exec.
3872 We don't want to allow a bp_finish to remain inserted now. But
3873 we can't safely delete it, 'cause finish_command has a handle to
3874 the bp on a bpstat, and will later want to delete it. There's a
3875 chance (and I've seen it happen) that if we delete the bp_finish
3876 here, that its storage will get reused by the time finish_command
3877 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3878 We really must allow finish_command to delete a bp_finish.
3880 In the absence of a general solution for the "how do we know
3881 it's safe to delete something others may have handles to?"
3882 problem, what we'll do here is just uninsert the bp_finish, and
3883 let finish_command delete it.
3885 (We know the bp_finish is "doomed" in the sense that it's
3886 momentary, and will be deleted as soon as finish_command sees
3887 the inferior stopped. So it doesn't matter that the bp's
3888 address is probably bogus in the new a.out, unlike e.g., the
3889 solib breakpoints.) */
3891 if (b->type == bp_finish)
3896 /* Without a symbolic address, we have little hope of the
3897 pre-exec() address meaning the same thing in the post-exec()
3899 if (breakpoint_event_location_empty_p (b))
3901 delete_breakpoint (b);
3908 detach_breakpoints (ptid_t ptid)
3910 struct bp_location *bl, **blp_tmp;
3912 struct cleanup *old_chain = save_inferior_ptid ();
3913 struct inferior *inf = current_inferior ();
3915 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3916 error (_("Cannot detach breakpoints of inferior_ptid"));
3918 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3919 inferior_ptid = ptid;
3920 ALL_BP_LOCATIONS (bl, blp_tmp)
3922 if (bl->pspace != inf->pspace)
3925 /* This function must physically remove breakpoints locations
3926 from the specified ptid, without modifying the breakpoint
3927 package's state. Locations of type bp_loc_other are only
3928 maintained at GDB side. So, there is no need to remove
3929 these bp_loc_other locations. Moreover, removing these
3930 would modify the breakpoint package's state. */
3931 if (bl->loc_type == bp_loc_other)
3935 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3938 do_cleanups (old_chain);
3942 /* Remove the breakpoint location BL from the current address space.
3943 Note that this is used to detach breakpoints from a child fork.
3944 When we get here, the child isn't in the inferior list, and neither
3945 do we have objects to represent its address space --- we should
3946 *not* look at bl->pspace->aspace here. */
3949 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3953 /* BL is never in moribund_locations by our callers. */
3954 gdb_assert (bl->owner != NULL);
3956 /* The type of none suggests that owner is actually deleted.
3957 This should not ever happen. */
3958 gdb_assert (bl->owner->type != bp_none);
3960 if (bl->loc_type == bp_loc_software_breakpoint
3961 || bl->loc_type == bp_loc_hardware_breakpoint)
3963 /* "Normal" instruction breakpoint: either the standard
3964 trap-instruction bp (bp_breakpoint), or a
3965 bp_hardware_breakpoint. */
3967 /* First check to see if we have to handle an overlay. */
3968 if (overlay_debugging == ovly_off
3969 || bl->section == NULL
3970 || !(section_is_overlay (bl->section)))
3972 /* No overlay handling: just remove the breakpoint. */
3974 /* If we're trying to uninsert a memory breakpoint that we
3975 know is set in a dynamic object that is marked
3976 shlib_disabled, then either the dynamic object was
3977 removed with "remove-symbol-file" or with
3978 "nosharedlibrary". In the former case, we don't know
3979 whether another dynamic object might have loaded over the
3980 breakpoint's address -- the user might well let us know
3981 about it next with add-symbol-file (the whole point of
3982 add-symbol-file is letting the user manually maintain a
3983 list of dynamically loaded objects). If we have the
3984 breakpoint's shadow memory, that is, this is a software
3985 breakpoint managed by GDB, check whether the breakpoint
3986 is still inserted in memory, to avoid overwriting wrong
3987 code with stale saved shadow contents. Note that HW
3988 breakpoints don't have shadow memory, as they're
3989 implemented using a mechanism that is not dependent on
3990 being able to modify the target's memory, and as such
3991 they should always be removed. */
3992 if (bl->shlib_disabled
3993 && bl->target_info.shadow_len != 0
3994 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3997 val = bl->owner->ops->remove_location (bl, reason);
4001 /* This breakpoint is in an overlay section.
4002 Did we set a breakpoint at the LMA? */
4003 if (!overlay_events_enabled)
4005 /* Yes -- overlay event support is not active, so we
4006 should have set a breakpoint at the LMA. Remove it.
4008 /* Ignore any failures: if the LMA is in ROM, we will
4009 have already warned when we failed to insert it. */
4010 if (bl->loc_type == bp_loc_hardware_breakpoint)
4011 target_remove_hw_breakpoint (bl->gdbarch,
4012 &bl->overlay_target_info);
4014 target_remove_breakpoint (bl->gdbarch,
4015 &bl->overlay_target_info,
4018 /* Did we set a breakpoint at the VMA?
4019 If so, we will have marked the breakpoint 'inserted'. */
4022 /* Yes -- remove it. Previously we did not bother to
4023 remove the breakpoint if the section had been
4024 unmapped, but let's not rely on that being safe. We
4025 don't know what the overlay manager might do. */
4027 /* However, we should remove *software* breakpoints only
4028 if the section is still mapped, or else we overwrite
4029 wrong code with the saved shadow contents. */
4030 if (bl->loc_type == bp_loc_hardware_breakpoint
4031 || section_is_mapped (bl->section))
4032 val = bl->owner->ops->remove_location (bl, reason);
4038 /* No -- not inserted, so no need to remove. No error. */
4043 /* In some cases, we might not be able to remove a breakpoint in
4044 a shared library that has already been removed, but we have
4045 not yet processed the shlib unload event. Similarly for an
4046 unloaded add-symbol-file object - the user might not yet have
4047 had the chance to remove-symbol-file it. shlib_disabled will
4048 be set if the library/object has already been removed, but
4049 the breakpoint hasn't been uninserted yet, e.g., after
4050 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4051 always-inserted mode. */
4053 && (bl->loc_type == bp_loc_software_breakpoint
4054 && (bl->shlib_disabled
4055 || solib_name_from_address (bl->pspace, bl->address)
4056 || shared_objfile_contains_address_p (bl->pspace,
4062 bl->inserted = (reason == DETACH_BREAKPOINT);
4064 else if (bl->loc_type == bp_loc_hardware_watchpoint)
4066 gdb_assert (bl->owner->ops != NULL
4067 && bl->owner->ops->remove_location != NULL);
4069 bl->inserted = (reason == DETACH_BREAKPOINT);
4070 bl->owner->ops->remove_location (bl, reason);
4072 /* Failure to remove any of the hardware watchpoints comes here. */
4073 if (reason == REMOVE_BREAKPOINT && bl->inserted)
4074 warning (_("Could not remove hardware watchpoint %d."),
4077 else if (bl->owner->type == bp_catchpoint
4078 && breakpoint_enabled (bl->owner)
4081 gdb_assert (bl->owner->ops != NULL
4082 && bl->owner->ops->remove_location != NULL);
4084 val = bl->owner->ops->remove_location (bl, reason);
4088 bl->inserted = (reason == DETACH_BREAKPOINT);
4095 remove_breakpoint (struct bp_location *bl)
4097 /* BL is never in moribund_locations by our callers. */
4098 gdb_assert (bl->owner != NULL);
4100 /* The type of none suggests that owner is actually deleted.
4101 This should not ever happen. */
4102 gdb_assert (bl->owner->type != bp_none);
4104 scoped_restore_current_pspace_and_thread restore_pspace_thread;
4106 switch_to_program_space_and_thread (bl->pspace);
4108 return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
4111 /* Clear the "inserted" flag in all breakpoints. */
4114 mark_breakpoints_out (void)
4116 struct bp_location *bl, **blp_tmp;
4118 ALL_BP_LOCATIONS (bl, blp_tmp)
4119 if (bl->pspace == current_program_space)
4123 /* Clear the "inserted" flag in all breakpoints and delete any
4124 breakpoints which should go away between runs of the program.
4126 Plus other such housekeeping that has to be done for breakpoints
4129 Note: this function gets called at the end of a run (by
4130 generic_mourn_inferior) and when a run begins (by
4131 init_wait_for_inferior). */
4136 breakpoint_init_inferior (enum inf_context context)
4138 struct breakpoint *b, *b_tmp;
4139 struct bp_location *bl;
4141 struct program_space *pspace = current_program_space;
4143 /* If breakpoint locations are shared across processes, then there's
4145 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4148 mark_breakpoints_out ();
4150 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4152 if (b->loc && b->loc->pspace != pspace)
4158 case bp_longjmp_call_dummy:
4160 /* If the call dummy breakpoint is at the entry point it will
4161 cause problems when the inferior is rerun, so we better get
4164 case bp_watchpoint_scope:
4166 /* Also get rid of scope breakpoints. */
4168 case bp_shlib_event:
4170 /* Also remove solib event breakpoints. Their addresses may
4171 have changed since the last time we ran the program.
4172 Actually we may now be debugging against different target;
4173 and so the solib backend that installed this breakpoint may
4174 not be used in by the target. E.g.,
4176 (gdb) file prog-linux
4177 (gdb) run # native linux target
4180 (gdb) file prog-win.exe
4181 (gdb) tar rem :9999 # remote Windows gdbserver.
4184 case bp_step_resume:
4186 /* Also remove step-resume breakpoints. */
4188 case bp_single_step:
4190 /* Also remove single-step breakpoints. */
4192 delete_breakpoint (b);
4196 case bp_hardware_watchpoint:
4197 case bp_read_watchpoint:
4198 case bp_access_watchpoint:
4200 struct watchpoint *w = (struct watchpoint *) b;
4202 /* Likewise for watchpoints on local expressions. */
4203 if (w->exp_valid_block != NULL)
4204 delete_breakpoint (b);
4207 /* Get rid of existing locations, which are no longer
4208 valid. New ones will be created in
4209 update_watchpoint, when the inferior is restarted.
4210 The next update_global_location_list call will
4211 garbage collect them. */
4214 if (context == inf_starting)
4216 /* Reset val field to force reread of starting value in
4217 insert_breakpoints. */
4219 value_free (w->val);
4231 /* Get rid of the moribund locations. */
4232 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4233 decref_bp_location (&bl);
4234 VEC_free (bp_location_p, moribund_locations);
4237 /* These functions concern about actual breakpoints inserted in the
4238 target --- to e.g. check if we need to do decr_pc adjustment or if
4239 we need to hop over the bkpt --- so we check for address space
4240 match, not program space. */
4242 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4243 exists at PC. It returns ordinary_breakpoint_here if it's an
4244 ordinary breakpoint, or permanent_breakpoint_here if it's a
4245 permanent breakpoint.
4246 - When continuing from a location with an ordinary breakpoint, we
4247 actually single step once before calling insert_breakpoints.
4248 - When continuing from a location with a permanent breakpoint, we
4249 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4250 the target, to advance the PC past the breakpoint. */
4252 enum breakpoint_here
4253 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4255 struct bp_location *bl, **blp_tmp;
4256 int any_breakpoint_here = 0;
4258 ALL_BP_LOCATIONS (bl, blp_tmp)
4260 if (bl->loc_type != bp_loc_software_breakpoint
4261 && bl->loc_type != bp_loc_hardware_breakpoint)
4264 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4265 if ((breakpoint_enabled (bl->owner)
4267 && breakpoint_location_address_match (bl, aspace, pc))
4269 if (overlay_debugging
4270 && section_is_overlay (bl->section)
4271 && !section_is_mapped (bl->section))
4272 continue; /* unmapped overlay -- can't be a match */
4273 else if (bl->permanent)
4274 return permanent_breakpoint_here;
4276 any_breakpoint_here = 1;
4280 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4283 /* See breakpoint.h. */
4286 breakpoint_in_range_p (struct address_space *aspace,
4287 CORE_ADDR addr, ULONGEST len)
4289 struct bp_location *bl, **blp_tmp;
4291 ALL_BP_LOCATIONS (bl, blp_tmp)
4293 if (bl->loc_type != bp_loc_software_breakpoint
4294 && bl->loc_type != bp_loc_hardware_breakpoint)
4297 if ((breakpoint_enabled (bl->owner)
4299 && breakpoint_location_address_range_overlap (bl, aspace,
4302 if (overlay_debugging
4303 && section_is_overlay (bl->section)
4304 && !section_is_mapped (bl->section))
4306 /* Unmapped overlay -- can't be a match. */
4317 /* Return true if there's a moribund breakpoint at PC. */
4320 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4322 struct bp_location *loc;
4325 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4326 if (breakpoint_location_address_match (loc, aspace, pc))
4332 /* Returns non-zero iff BL is inserted at PC, in address space
4336 bp_location_inserted_here_p (struct bp_location *bl,
4337 struct address_space *aspace, CORE_ADDR pc)
4340 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4343 if (overlay_debugging
4344 && section_is_overlay (bl->section)
4345 && !section_is_mapped (bl->section))
4346 return 0; /* unmapped overlay -- can't be a match */
4353 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4356 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4358 struct bp_location **blp, **blp_tmp = NULL;
4360 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4362 struct bp_location *bl = *blp;
4364 if (bl->loc_type != bp_loc_software_breakpoint
4365 && bl->loc_type != bp_loc_hardware_breakpoint)
4368 if (bp_location_inserted_here_p (bl, aspace, pc))
4374 /* This function returns non-zero iff there is a software breakpoint
4378 software_breakpoint_inserted_here_p (struct address_space *aspace,
4381 struct bp_location **blp, **blp_tmp = NULL;
4383 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4385 struct bp_location *bl = *blp;
4387 if (bl->loc_type != bp_loc_software_breakpoint)
4390 if (bp_location_inserted_here_p (bl, aspace, pc))
4397 /* See breakpoint.h. */
4400 hardware_breakpoint_inserted_here_p (struct address_space *aspace,
4403 struct bp_location **blp, **blp_tmp = NULL;
4405 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4407 struct bp_location *bl = *blp;
4409 if (bl->loc_type != bp_loc_hardware_breakpoint)
4412 if (bp_location_inserted_here_p (bl, aspace, pc))
4420 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4421 CORE_ADDR addr, ULONGEST len)
4423 struct breakpoint *bpt;
4425 ALL_BREAKPOINTS (bpt)
4427 struct bp_location *loc;
4429 if (bpt->type != bp_hardware_watchpoint
4430 && bpt->type != bp_access_watchpoint)
4433 if (!breakpoint_enabled (bpt))
4436 for (loc = bpt->loc; loc; loc = loc->next)
4437 if (loc->pspace->aspace == aspace && loc->inserted)
4441 /* Check for intersection. */
4442 l = std::max<CORE_ADDR> (loc->address, addr);
4443 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4452 /* bpstat stuff. External routines' interfaces are documented
4456 is_catchpoint (struct breakpoint *ep)
4458 return (ep->type == bp_catchpoint);
4461 /* Frees any storage that is part of a bpstat. Does not walk the
4465 bpstat_free (bpstat bs)
4467 if (bs->old_val != NULL)
4468 value_free (bs->old_val);
4469 decref_counted_command_line (&bs->commands);
4470 decref_bp_location (&bs->bp_location_at);
4474 /* Clear a bpstat so that it says we are not at any breakpoint.
4475 Also free any storage that is part of a bpstat. */
4478 bpstat_clear (bpstat *bsp)
4495 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4496 is part of the bpstat is copied as well. */
4499 bpstat_copy (bpstat bs)
4503 bpstat retval = NULL;
4508 for (; bs != NULL; bs = bs->next)
4510 tmp = (bpstat) xmalloc (sizeof (*tmp));
4511 memcpy (tmp, bs, sizeof (*tmp));
4512 incref_counted_command_line (tmp->commands);
4513 incref_bp_location (tmp->bp_location_at);
4514 if (bs->old_val != NULL)
4516 tmp->old_val = value_copy (bs->old_val);
4517 release_value (tmp->old_val);
4521 /* This is the first thing in the chain. */
4531 /* Find the bpstat associated with this breakpoint. */
4534 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4539 for (; bsp != NULL; bsp = bsp->next)
4541 if (bsp->breakpoint_at == breakpoint)
4547 /* See breakpoint.h. */
4550 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4552 for (; bsp != NULL; bsp = bsp->next)
4554 if (bsp->breakpoint_at == NULL)
4556 /* A moribund location can never explain a signal other than
4558 if (sig == GDB_SIGNAL_TRAP)
4563 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4572 /* Put in *NUM the breakpoint number of the first breakpoint we are
4573 stopped at. *BSP upon return is a bpstat which points to the
4574 remaining breakpoints stopped at (but which is not guaranteed to be
4575 good for anything but further calls to bpstat_num).
4577 Return 0 if passed a bpstat which does not indicate any breakpoints.
4578 Return -1 if stopped at a breakpoint that has been deleted since
4580 Return 1 otherwise. */
4583 bpstat_num (bpstat *bsp, int *num)
4585 struct breakpoint *b;
4588 return 0; /* No more breakpoint values */
4590 /* We assume we'll never have several bpstats that correspond to a
4591 single breakpoint -- otherwise, this function might return the
4592 same number more than once and this will look ugly. */
4593 b = (*bsp)->breakpoint_at;
4594 *bsp = (*bsp)->next;
4596 return -1; /* breakpoint that's been deleted since */
4598 *num = b->number; /* We have its number */
4602 /* See breakpoint.h. */
4605 bpstat_clear_actions (void)
4607 struct thread_info *tp;
4610 if (ptid_equal (inferior_ptid, null_ptid))
4613 tp = find_thread_ptid (inferior_ptid);
4617 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4619 decref_counted_command_line (&bs->commands);
4621 if (bs->old_val != NULL)
4623 value_free (bs->old_val);
4629 /* Called when a command is about to proceed the inferior. */
4632 breakpoint_about_to_proceed (void)
4634 if (!ptid_equal (inferior_ptid, null_ptid))
4636 struct thread_info *tp = inferior_thread ();
4638 /* Allow inferior function calls in breakpoint commands to not
4639 interrupt the command list. When the call finishes
4640 successfully, the inferior will be standing at the same
4641 breakpoint as if nothing happened. */
4642 if (tp->control.in_infcall)
4646 breakpoint_proceeded = 1;
4649 /* Stub for cleaning up our state if we error-out of a breakpoint
4652 cleanup_executing_breakpoints (void *ignore)
4654 executing_breakpoint_commands = 0;
4657 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4658 or its equivalent. */
4661 command_line_is_silent (struct command_line *cmd)
4663 return cmd && (strcmp ("silent", cmd->line) == 0);
4666 /* Execute all the commands associated with all the breakpoints at
4667 this location. Any of these commands could cause the process to
4668 proceed beyond this point, etc. We look out for such changes by
4669 checking the global "breakpoint_proceeded" after each command.
4671 Returns true if a breakpoint command resumed the inferior. In that
4672 case, it is the caller's responsibility to recall it again with the
4673 bpstat of the current thread. */
4676 bpstat_do_actions_1 (bpstat *bsp)
4679 struct cleanup *old_chain;
4682 /* Avoid endless recursion if a `source' command is contained
4684 if (executing_breakpoint_commands)
4687 executing_breakpoint_commands = 1;
4688 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4690 scoped_restore preventer = prevent_dont_repeat ();
4692 /* This pointer will iterate over the list of bpstat's. */
4695 breakpoint_proceeded = 0;
4696 for (; bs != NULL; bs = bs->next)
4698 struct counted_command_line *ccmd;
4699 struct command_line *cmd;
4700 struct cleanup *this_cmd_tree_chain;
4702 /* Take ownership of the BSP's command tree, if it has one.
4704 The command tree could legitimately contain commands like
4705 'step' and 'next', which call clear_proceed_status, which
4706 frees stop_bpstat's command tree. To make sure this doesn't
4707 free the tree we're executing out from under us, we need to
4708 take ownership of the tree ourselves. Since a given bpstat's
4709 commands are only executed once, we don't need to copy it; we
4710 can clear the pointer in the bpstat, and make sure we free
4711 the tree when we're done. */
4712 ccmd = bs->commands;
4713 bs->commands = NULL;
4714 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4715 cmd = ccmd ? ccmd->commands : NULL;
4716 if (command_line_is_silent (cmd))
4718 /* The action has been already done by bpstat_stop_status. */
4724 execute_control_command (cmd);
4726 if (breakpoint_proceeded)
4732 /* We can free this command tree now. */
4733 do_cleanups (this_cmd_tree_chain);
4735 if (breakpoint_proceeded)
4737 if (current_ui->async)
4738 /* If we are in async mode, then the target might be still
4739 running, not stopped at any breakpoint, so nothing for
4740 us to do here -- just return to the event loop. */
4743 /* In sync mode, when execute_control_command returns
4744 we're already standing on the next breakpoint.
4745 Breakpoint commands for that stop were not run, since
4746 execute_command does not run breakpoint commands --
4747 only command_line_handler does, but that one is not
4748 involved in execution of breakpoint commands. So, we
4749 can now execute breakpoint commands. It should be
4750 noted that making execute_command do bpstat actions is
4751 not an option -- in this case we'll have recursive
4752 invocation of bpstat for each breakpoint with a
4753 command, and can easily blow up GDB stack. Instead, we
4754 return true, which will trigger the caller to recall us
4755 with the new stop_bpstat. */
4760 do_cleanups (old_chain);
4765 bpstat_do_actions (void)
4767 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4769 /* Do any commands attached to breakpoint we are stopped at. */
4770 while (!ptid_equal (inferior_ptid, null_ptid)
4771 && target_has_execution
4772 && !is_exited (inferior_ptid)
4773 && !is_executing (inferior_ptid))
4774 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4775 and only return when it is stopped at the next breakpoint, we
4776 keep doing breakpoint actions until it returns false to
4777 indicate the inferior was not resumed. */
4778 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4781 discard_cleanups (cleanup_if_error);
4784 /* Print out the (old or new) value associated with a watchpoint. */
4787 watchpoint_value_print (struct value *val, struct ui_file *stream)
4790 fprintf_unfiltered (stream, _("<unreadable>"));
4793 struct value_print_options opts;
4794 get_user_print_options (&opts);
4795 value_print (val, stream, &opts);
4799 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4800 debugging multiple threads. */
4803 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4805 if (uiout->is_mi_like_p ())
4810 if (show_thread_that_caused_stop ())
4813 struct thread_info *thr = inferior_thread ();
4815 uiout->text ("Thread ");
4816 uiout->field_fmt ("thread-id", "%s", print_thread_id (thr));
4818 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4821 uiout->text (" \"");
4822 uiout->field_fmt ("name", "%s", name);
4826 uiout->text (" hit ");
4830 /* Generic routine for printing messages indicating why we
4831 stopped. The behavior of this function depends on the value
4832 'print_it' in the bpstat structure. Under some circumstances we
4833 may decide not to print anything here and delegate the task to
4836 static enum print_stop_action
4837 print_bp_stop_message (bpstat bs)
4839 switch (bs->print_it)
4842 /* Nothing should be printed for this bpstat entry. */
4843 return PRINT_UNKNOWN;
4847 /* We still want to print the frame, but we already printed the
4848 relevant messages. */
4849 return PRINT_SRC_AND_LOC;
4852 case print_it_normal:
4854 struct breakpoint *b = bs->breakpoint_at;
4856 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4857 which has since been deleted. */
4859 return PRINT_UNKNOWN;
4861 /* Normal case. Call the breakpoint's print_it method. */
4862 return b->ops->print_it (bs);
4867 internal_error (__FILE__, __LINE__,
4868 _("print_bp_stop_message: unrecognized enum value"));
4873 /* A helper function that prints a shared library stopped event. */
4876 print_solib_event (int is_catchpoint)
4879 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4881 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4885 if (any_added || any_deleted)
4886 current_uiout->text (_("Stopped due to shared library event:\n"));
4888 current_uiout->text (_("Stopped due to shared library event (no "
4889 "libraries added or removed)\n"));
4892 if (current_uiout->is_mi_like_p ())
4893 current_uiout->field_string ("reason",
4894 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4901 current_uiout->text (_(" Inferior unloaded "));
4902 ui_out_emit_list list_emitter (current_uiout, "removed");
4904 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4909 current_uiout->text (" ");
4910 current_uiout->field_string ("library", name);
4911 current_uiout->text ("\n");
4917 struct so_list *iter;
4920 current_uiout->text (_(" Inferior loaded "));
4921 ui_out_emit_list list_emitter (current_uiout, "added");
4923 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4928 current_uiout->text (" ");
4929 current_uiout->field_string ("library", iter->so_name);
4930 current_uiout->text ("\n");
4935 /* Print a message indicating what happened. This is called from
4936 normal_stop(). The input to this routine is the head of the bpstat
4937 list - a list of the eventpoints that caused this stop. KIND is
4938 the target_waitkind for the stopping event. This
4939 routine calls the generic print routine for printing a message
4940 about reasons for stopping. This will print (for example) the
4941 "Breakpoint n," part of the output. The return value of this
4944 PRINT_UNKNOWN: Means we printed nothing.
4945 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4946 code to print the location. An example is
4947 "Breakpoint 1, " which should be followed by
4949 PRINT_SRC_ONLY: Means we printed something, but there is no need
4950 to also print the location part of the message.
4951 An example is the catch/throw messages, which
4952 don't require a location appended to the end.
4953 PRINT_NOTHING: We have done some printing and we don't need any
4954 further info to be printed. */
4956 enum print_stop_action
4957 bpstat_print (bpstat bs, int kind)
4959 enum print_stop_action val;
4961 /* Maybe another breakpoint in the chain caused us to stop.
4962 (Currently all watchpoints go on the bpstat whether hit or not.
4963 That probably could (should) be changed, provided care is taken
4964 with respect to bpstat_explains_signal). */
4965 for (; bs; bs = bs->next)
4967 val = print_bp_stop_message (bs);
4968 if (val == PRINT_SRC_ONLY
4969 || val == PRINT_SRC_AND_LOC
4970 || val == PRINT_NOTHING)
4974 /* If we had hit a shared library event breakpoint,
4975 print_bp_stop_message would print out this message. If we hit an
4976 OS-level shared library event, do the same thing. */
4977 if (kind == TARGET_WAITKIND_LOADED)
4979 print_solib_event (0);
4980 return PRINT_NOTHING;
4983 /* We reached the end of the chain, or we got a null BS to start
4984 with and nothing was printed. */
4985 return PRINT_UNKNOWN;
4988 /* Evaluate the expression EXP and return 1 if value is zero.
4989 This returns the inverse of the condition because it is called
4990 from catch_errors which returns 0 if an exception happened, and if an
4991 exception happens we want execution to stop.
4992 The argument is a "struct expression *" that has been cast to a
4993 "void *" to make it pass through catch_errors. */
4996 breakpoint_cond_eval (void *exp)
4998 struct value *mark = value_mark ();
4999 int i = !value_true (evaluate_expression ((struct expression *) exp));
5001 value_free_to_mark (mark);
5005 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5008 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
5012 bs = (bpstat) xmalloc (sizeof (*bs));
5014 **bs_link_pointer = bs;
5015 *bs_link_pointer = &bs->next;
5016 bs->breakpoint_at = bl->owner;
5017 bs->bp_location_at = bl;
5018 incref_bp_location (bl);
5019 /* If the condition is false, etc., don't do the commands. */
5020 bs->commands = NULL;
5022 bs->print_it = print_it_normal;
5026 /* The target has stopped with waitstatus WS. Check if any hardware
5027 watchpoints have triggered, according to the target. */
5030 watchpoints_triggered (struct target_waitstatus *ws)
5032 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
5034 struct breakpoint *b;
5036 if (!stopped_by_watchpoint)
5038 /* We were not stopped by a watchpoint. Mark all watchpoints
5039 as not triggered. */
5041 if (is_hardware_watchpoint (b))
5043 struct watchpoint *w = (struct watchpoint *) b;
5045 w->watchpoint_triggered = watch_triggered_no;
5051 if (!target_stopped_data_address (¤t_target, &addr))
5053 /* We were stopped by a watchpoint, but we don't know where.
5054 Mark all watchpoints as unknown. */
5056 if (is_hardware_watchpoint (b))
5058 struct watchpoint *w = (struct watchpoint *) b;
5060 w->watchpoint_triggered = watch_triggered_unknown;
5066 /* The target could report the data address. Mark watchpoints
5067 affected by this data address as triggered, and all others as not
5071 if (is_hardware_watchpoint (b))
5073 struct watchpoint *w = (struct watchpoint *) b;
5074 struct bp_location *loc;
5076 w->watchpoint_triggered = watch_triggered_no;
5077 for (loc = b->loc; loc; loc = loc->next)
5079 if (is_masked_watchpoint (b))
5081 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5082 CORE_ADDR start = loc->address & w->hw_wp_mask;
5084 if (newaddr == start)
5086 w->watchpoint_triggered = watch_triggered_yes;
5090 /* Exact match not required. Within range is sufficient. */
5091 else if (target_watchpoint_addr_within_range (¤t_target,
5095 w->watchpoint_triggered = watch_triggered_yes;
5104 /* Possible return values for watchpoint_check (this can't be an enum
5105 because of check_errors). */
5106 /* The watchpoint has been deleted. */
5107 #define WP_DELETED 1
5108 /* The value has changed. */
5109 #define WP_VALUE_CHANGED 2
5110 /* The value has not changed. */
5111 #define WP_VALUE_NOT_CHANGED 3
5112 /* Ignore this watchpoint, no matter if the value changed or not. */
5115 #define BP_TEMPFLAG 1
5116 #define BP_HARDWAREFLAG 2
5118 /* Evaluate watchpoint condition expression and check if its value
5121 P should be a pointer to struct bpstat, but is defined as a void *
5122 in order for this function to be usable with catch_errors. */
5125 watchpoint_check (void *p)
5127 bpstat bs = (bpstat) p;
5128 struct watchpoint *b;
5129 struct frame_info *fr;
5130 int within_current_scope;
5132 /* BS is built from an existing struct breakpoint. */
5133 gdb_assert (bs->breakpoint_at != NULL);
5134 b = (struct watchpoint *) bs->breakpoint_at;
5136 /* If this is a local watchpoint, we only want to check if the
5137 watchpoint frame is in scope if the current thread is the thread
5138 that was used to create the watchpoint. */
5139 if (!watchpoint_in_thread_scope (b))
5142 if (b->exp_valid_block == NULL)
5143 within_current_scope = 1;
5146 struct frame_info *frame = get_current_frame ();
5147 struct gdbarch *frame_arch = get_frame_arch (frame);
5148 CORE_ADDR frame_pc = get_frame_pc (frame);
5150 /* stack_frame_destroyed_p() returns a non-zero value if we're
5151 still in the function but the stack frame has already been
5152 invalidated. Since we can't rely on the values of local
5153 variables after the stack has been destroyed, we are treating
5154 the watchpoint in that state as `not changed' without further
5155 checking. Don't mark watchpoints as changed if the current
5156 frame is in an epilogue - even if they are in some other
5157 frame, our view of the stack is likely to be wrong and
5158 frame_find_by_id could error out. */
5159 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5162 fr = frame_find_by_id (b->watchpoint_frame);
5163 within_current_scope = (fr != NULL);
5165 /* If we've gotten confused in the unwinder, we might have
5166 returned a frame that can't describe this variable. */
5167 if (within_current_scope)
5169 struct symbol *function;
5171 function = get_frame_function (fr);
5172 if (function == NULL
5173 || !contained_in (b->exp_valid_block,
5174 SYMBOL_BLOCK_VALUE (function)))
5175 within_current_scope = 0;
5178 if (within_current_scope)
5179 /* If we end up stopping, the current frame will get selected
5180 in normal_stop. So this call to select_frame won't affect
5185 if (within_current_scope)
5187 /* We use value_{,free_to_}mark because it could be a *long*
5188 time before we return to the command level and call
5189 free_all_values. We can't call free_all_values because we
5190 might be in the middle of evaluating a function call. */
5194 struct value *new_val;
5196 if (is_masked_watchpoint (b))
5197 /* Since we don't know the exact trigger address (from
5198 stopped_data_address), just tell the user we've triggered
5199 a mask watchpoint. */
5200 return WP_VALUE_CHANGED;
5202 mark = value_mark ();
5203 fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
5205 if (b->val_bitsize != 0)
5206 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5208 /* We use value_equal_contents instead of value_equal because
5209 the latter coerces an array to a pointer, thus comparing just
5210 the address of the array instead of its contents. This is
5211 not what we want. */
5212 if ((b->val != NULL) != (new_val != NULL)
5213 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5215 if (new_val != NULL)
5217 release_value (new_val);
5218 value_free_to_mark (mark);
5220 bs->old_val = b->val;
5223 return WP_VALUE_CHANGED;
5227 /* Nothing changed. */
5228 value_free_to_mark (mark);
5229 return WP_VALUE_NOT_CHANGED;
5234 /* This seems like the only logical thing to do because
5235 if we temporarily ignored the watchpoint, then when
5236 we reenter the block in which it is valid it contains
5237 garbage (in the case of a function, it may have two
5238 garbage values, one before and one after the prologue).
5239 So we can't even detect the first assignment to it and
5240 watch after that (since the garbage may or may not equal
5241 the first value assigned). */
5242 /* We print all the stop information in
5243 breakpoint_ops->print_it, but in this case, by the time we
5244 call breakpoint_ops->print_it this bp will be deleted
5245 already. So we have no choice but print the information
5248 SWITCH_THRU_ALL_UIS ()
5250 struct ui_out *uiout = current_uiout;
5252 if (uiout->is_mi_like_p ())
5254 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5255 uiout->text ("\nWatchpoint ");
5256 uiout->field_int ("wpnum", b->number);
5257 uiout->text (" deleted because the program has left the block in\n"
5258 "which its expression is valid.\n");
5261 /* Make sure the watchpoint's commands aren't executed. */
5262 decref_counted_command_line (&b->commands);
5263 watchpoint_del_at_next_stop (b);
5269 /* Return true if it looks like target has stopped due to hitting
5270 breakpoint location BL. This function does not check if we should
5271 stop, only if BL explains the stop. */
5274 bpstat_check_location (const struct bp_location *bl,
5275 struct address_space *aspace, CORE_ADDR bp_addr,
5276 const struct target_waitstatus *ws)
5278 struct breakpoint *b = bl->owner;
5280 /* BL is from an existing breakpoint. */
5281 gdb_assert (b != NULL);
5283 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5286 /* Determine if the watched values have actually changed, and we
5287 should stop. If not, set BS->stop to 0. */
5290 bpstat_check_watchpoint (bpstat bs)
5292 const struct bp_location *bl;
5293 struct watchpoint *b;
5295 /* BS is built for existing struct breakpoint. */
5296 bl = bs->bp_location_at;
5297 gdb_assert (bl != NULL);
5298 b = (struct watchpoint *) bs->breakpoint_at;
5299 gdb_assert (b != NULL);
5302 int must_check_value = 0;
5304 if (b->type == bp_watchpoint)
5305 /* For a software watchpoint, we must always check the
5307 must_check_value = 1;
5308 else if (b->watchpoint_triggered == watch_triggered_yes)
5309 /* We have a hardware watchpoint (read, write, or access)
5310 and the target earlier reported an address watched by
5312 must_check_value = 1;
5313 else if (b->watchpoint_triggered == watch_triggered_unknown
5314 && b->type == bp_hardware_watchpoint)
5315 /* We were stopped by a hardware watchpoint, but the target could
5316 not report the data address. We must check the watchpoint's
5317 value. Access and read watchpoints are out of luck; without
5318 a data address, we can't figure it out. */
5319 must_check_value = 1;
5321 if (must_check_value)
5324 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5326 struct cleanup *cleanups = make_cleanup (xfree, message);
5327 int e = catch_errors (watchpoint_check, bs, message,
5329 do_cleanups (cleanups);
5333 /* We've already printed what needs to be printed. */
5334 bs->print_it = print_it_done;
5338 bs->print_it = print_it_noop;
5341 case WP_VALUE_CHANGED:
5342 if (b->type == bp_read_watchpoint)
5344 /* There are two cases to consider here:
5346 1. We're watching the triggered memory for reads.
5347 In that case, trust the target, and always report
5348 the watchpoint hit to the user. Even though
5349 reads don't cause value changes, the value may
5350 have changed since the last time it was read, and
5351 since we're not trapping writes, we will not see
5352 those, and as such we should ignore our notion of
5355 2. We're watching the triggered memory for both
5356 reads and writes. There are two ways this may
5359 2.1. This is a target that can't break on data
5360 reads only, but can break on accesses (reads or
5361 writes), such as e.g., x86. We detect this case
5362 at the time we try to insert read watchpoints.
5364 2.2. Otherwise, the target supports read
5365 watchpoints, but, the user set an access or write
5366 watchpoint watching the same memory as this read
5369 If we're watching memory writes as well as reads,
5370 ignore watchpoint hits when we find that the
5371 value hasn't changed, as reads don't cause
5372 changes. This still gives false positives when
5373 the program writes the same value to memory as
5374 what there was already in memory (we will confuse
5375 it for a read), but it's much better than
5378 int other_write_watchpoint = 0;
5380 if (bl->watchpoint_type == hw_read)
5382 struct breakpoint *other_b;
5384 ALL_BREAKPOINTS (other_b)
5385 if (other_b->type == bp_hardware_watchpoint
5386 || other_b->type == bp_access_watchpoint)
5388 struct watchpoint *other_w =
5389 (struct watchpoint *) other_b;
5391 if (other_w->watchpoint_triggered
5392 == watch_triggered_yes)
5394 other_write_watchpoint = 1;
5400 if (other_write_watchpoint
5401 || bl->watchpoint_type == hw_access)
5403 /* We're watching the same memory for writes,
5404 and the value changed since the last time we
5405 updated it, so this trap must be for a write.
5407 bs->print_it = print_it_noop;
5412 case WP_VALUE_NOT_CHANGED:
5413 if (b->type == bp_hardware_watchpoint
5414 || b->type == bp_watchpoint)
5416 /* Don't stop: write watchpoints shouldn't fire if
5417 the value hasn't changed. */
5418 bs->print_it = print_it_noop;
5426 /* Error from catch_errors. */
5428 SWITCH_THRU_ALL_UIS ()
5430 printf_filtered (_("Watchpoint %d deleted.\n"),
5433 watchpoint_del_at_next_stop (b);
5434 /* We've already printed what needs to be printed. */
5435 bs->print_it = print_it_done;
5440 else /* must_check_value == 0 */
5442 /* This is a case where some watchpoint(s) triggered, but
5443 not at the address of this watchpoint, or else no
5444 watchpoint triggered after all. So don't print
5445 anything for this watchpoint. */
5446 bs->print_it = print_it_noop;
5452 /* For breakpoints that are currently marked as telling gdb to stop,
5453 check conditions (condition proper, frame, thread and ignore count)
5454 of breakpoint referred to by BS. If we should not stop for this
5455 breakpoint, set BS->stop to 0. */
5458 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5460 const struct bp_location *bl;
5461 struct breakpoint *b;
5462 int value_is_zero = 0;
5463 struct expression *cond;
5465 gdb_assert (bs->stop);
5467 /* BS is built for existing struct breakpoint. */
5468 bl = bs->bp_location_at;
5469 gdb_assert (bl != NULL);
5470 b = bs->breakpoint_at;
5471 gdb_assert (b != NULL);
5473 /* Even if the target evaluated the condition on its end and notified GDB, we
5474 need to do so again since GDB does not know if we stopped due to a
5475 breakpoint or a single step breakpoint. */
5477 if (frame_id_p (b->frame_id)
5478 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5484 /* If this is a thread/task-specific breakpoint, don't waste cpu
5485 evaluating the condition if this isn't the specified
5487 if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
5488 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5495 /* Evaluate extension language breakpoints that have a "stop" method
5497 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5499 if (is_watchpoint (b))
5501 struct watchpoint *w = (struct watchpoint *) b;
5503 cond = w->cond_exp.get ();
5506 cond = bl->cond.get ();
5508 if (cond && b->disposition != disp_del_at_next_stop)
5510 int within_current_scope = 1;
5511 struct watchpoint * w;
5513 /* We use value_mark and value_free_to_mark because it could
5514 be a long time before we return to the command level and
5515 call free_all_values. We can't call free_all_values
5516 because we might be in the middle of evaluating a
5518 struct value *mark = value_mark ();
5520 if (is_watchpoint (b))
5521 w = (struct watchpoint *) b;
5525 /* Need to select the frame, with all that implies so that
5526 the conditions will have the right context. Because we
5527 use the frame, we will not see an inlined function's
5528 variables when we arrive at a breakpoint at the start
5529 of the inlined function; the current frame will be the
5531 if (w == NULL || w->cond_exp_valid_block == NULL)
5532 select_frame (get_current_frame ());
5535 struct frame_info *frame;
5537 /* For local watchpoint expressions, which particular
5538 instance of a local is being watched matters, so we
5539 keep track of the frame to evaluate the expression
5540 in. To evaluate the condition however, it doesn't
5541 really matter which instantiation of the function
5542 where the condition makes sense triggers the
5543 watchpoint. This allows an expression like "watch
5544 global if q > 10" set in `func', catch writes to
5545 global on all threads that call `func', or catch
5546 writes on all recursive calls of `func' by a single
5547 thread. We simply always evaluate the condition in
5548 the innermost frame that's executing where it makes
5549 sense to evaluate the condition. It seems
5551 frame = block_innermost_frame (w->cond_exp_valid_block);
5553 select_frame (frame);
5555 within_current_scope = 0;
5557 if (within_current_scope)
5559 = catch_errors (breakpoint_cond_eval, cond,
5560 "Error in testing breakpoint condition:\n",
5564 warning (_("Watchpoint condition cannot be tested "
5565 "in the current scope"));
5566 /* If we failed to set the right context for this
5567 watchpoint, unconditionally report it. */
5570 /* FIXME-someday, should give breakpoint #. */
5571 value_free_to_mark (mark);
5574 if (cond && value_is_zero)
5578 else if (b->ignore_count > 0)
5582 /* Increase the hit count even though we don't stop. */
5584 observer_notify_breakpoint_modified (b);
5588 /* Returns true if we need to track moribund locations of LOC's type
5589 on the current target. */
5592 need_moribund_for_location_type (struct bp_location *loc)
5594 return ((loc->loc_type == bp_loc_software_breakpoint
5595 && !target_supports_stopped_by_sw_breakpoint ())
5596 || (loc->loc_type == bp_loc_hardware_breakpoint
5597 && !target_supports_stopped_by_hw_breakpoint ()));
5601 /* Get a bpstat associated with having just stopped at address
5602 BP_ADDR in thread PTID.
5604 Determine whether we stopped at a breakpoint, etc, or whether we
5605 don't understand this stop. Result is a chain of bpstat's such
5608 if we don't understand the stop, the result is a null pointer.
5610 if we understand why we stopped, the result is not null.
5612 Each element of the chain refers to a particular breakpoint or
5613 watchpoint at which we have stopped. (We may have stopped for
5614 several reasons concurrently.)
5616 Each element of the chain has valid next, breakpoint_at,
5617 commands, FIXME??? fields. */
5620 bpstat_stop_status (struct address_space *aspace,
5621 CORE_ADDR bp_addr, ptid_t ptid,
5622 const struct target_waitstatus *ws)
5624 struct breakpoint *b = NULL;
5625 struct bp_location *bl;
5626 struct bp_location *loc;
5627 /* First item of allocated bpstat's. */
5628 bpstat bs_head = NULL, *bs_link = &bs_head;
5629 /* Pointer to the last thing in the chain currently. */
5632 int need_remove_insert;
5635 /* First, build the bpstat chain with locations that explain a
5636 target stop, while being careful to not set the target running,
5637 as that may invalidate locations (in particular watchpoint
5638 locations are recreated). Resuming will happen here with
5639 breakpoint conditions or watchpoint expressions that include
5640 inferior function calls. */
5644 if (!breakpoint_enabled (b))
5647 for (bl = b->loc; bl != NULL; bl = bl->next)
5649 /* For hardware watchpoints, we look only at the first
5650 location. The watchpoint_check function will work on the
5651 entire expression, not the individual locations. For
5652 read watchpoints, the watchpoints_triggered function has
5653 checked all locations already. */
5654 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5657 if (!bl->enabled || bl->shlib_disabled)
5660 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5663 /* Come here if it's a watchpoint, or if the break address
5666 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5669 /* Assume we stop. Should we find a watchpoint that is not
5670 actually triggered, or if the condition of the breakpoint
5671 evaluates as false, we'll reset 'stop' to 0. */
5675 /* If this is a scope breakpoint, mark the associated
5676 watchpoint as triggered so that we will handle the
5677 out-of-scope event. We'll get to the watchpoint next
5679 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5681 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5683 w->watchpoint_triggered = watch_triggered_yes;
5688 /* Check if a moribund breakpoint explains the stop. */
5689 if (!target_supports_stopped_by_sw_breakpoint ()
5690 || !target_supports_stopped_by_hw_breakpoint ())
5692 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5694 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5695 && need_moribund_for_location_type (loc))
5697 bs = bpstat_alloc (loc, &bs_link);
5698 /* For hits of moribund locations, we should just proceed. */
5701 bs->print_it = print_it_noop;
5706 /* A bit of special processing for shlib breakpoints. We need to
5707 process solib loading here, so that the lists of loaded and
5708 unloaded libraries are correct before we handle "catch load" and
5710 for (bs = bs_head; bs != NULL; bs = bs->next)
5712 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5714 handle_solib_event ();
5719 /* Now go through the locations that caused the target to stop, and
5720 check whether we're interested in reporting this stop to higher
5721 layers, or whether we should resume the target transparently. */
5725 for (bs = bs_head; bs != NULL; bs = bs->next)
5730 b = bs->breakpoint_at;
5731 b->ops->check_status (bs);
5734 bpstat_check_breakpoint_conditions (bs, ptid);
5739 observer_notify_breakpoint_modified (b);
5741 /* We will stop here. */
5742 if (b->disposition == disp_disable)
5744 --(b->enable_count);
5745 if (b->enable_count <= 0)
5746 b->enable_state = bp_disabled;
5751 bs->commands = b->commands;
5752 incref_counted_command_line (bs->commands);
5753 if (command_line_is_silent (bs->commands
5754 ? bs->commands->commands : NULL))
5757 b->ops->after_condition_true (bs);
5762 /* Print nothing for this entry if we don't stop or don't
5764 if (!bs->stop || !bs->print)
5765 bs->print_it = print_it_noop;
5768 /* If we aren't stopping, the value of some hardware watchpoint may
5769 not have changed, but the intermediate memory locations we are
5770 watching may have. Don't bother if we're stopping; this will get
5772 need_remove_insert = 0;
5773 if (! bpstat_causes_stop (bs_head))
5774 for (bs = bs_head; bs != NULL; bs = bs->next)
5776 && bs->breakpoint_at
5777 && is_hardware_watchpoint (bs->breakpoint_at))
5779 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5781 update_watchpoint (w, 0 /* don't reparse. */);
5782 need_remove_insert = 1;
5785 if (need_remove_insert)
5786 update_global_location_list (UGLL_MAY_INSERT);
5787 else if (removed_any)
5788 update_global_location_list (UGLL_DONT_INSERT);
5794 handle_jit_event (void)
5796 struct frame_info *frame;
5797 struct gdbarch *gdbarch;
5800 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5802 /* Switch terminal for any messages produced by
5803 breakpoint_re_set. */
5804 target_terminal_ours_for_output ();
5806 frame = get_current_frame ();
5807 gdbarch = get_frame_arch (frame);
5809 jit_event_handler (gdbarch);
5811 target_terminal_inferior ();
5814 /* Prepare WHAT final decision for infrun. */
5816 /* Decide what infrun needs to do with this bpstat. */
5819 bpstat_what (bpstat bs_head)
5821 struct bpstat_what retval;
5824 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5825 retval.call_dummy = STOP_NONE;
5826 retval.is_longjmp = 0;
5828 for (bs = bs_head; bs != NULL; bs = bs->next)
5830 /* Extract this BS's action. After processing each BS, we check
5831 if its action overrides all we've seem so far. */
5832 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5835 if (bs->breakpoint_at == NULL)
5837 /* I suspect this can happen if it was a momentary
5838 breakpoint which has since been deleted. */
5842 bptype = bs->breakpoint_at->type;
5849 case bp_hardware_breakpoint:
5850 case bp_single_step:
5853 case bp_shlib_event:
5857 this_action = BPSTAT_WHAT_STOP_NOISY;
5859 this_action = BPSTAT_WHAT_STOP_SILENT;
5862 this_action = BPSTAT_WHAT_SINGLE;
5865 case bp_hardware_watchpoint:
5866 case bp_read_watchpoint:
5867 case bp_access_watchpoint:
5871 this_action = BPSTAT_WHAT_STOP_NOISY;
5873 this_action = BPSTAT_WHAT_STOP_SILENT;
5877 /* There was a watchpoint, but we're not stopping.
5878 This requires no further action. */
5882 case bp_longjmp_call_dummy:
5886 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5887 retval.is_longjmp = bptype != bp_exception;
5890 this_action = BPSTAT_WHAT_SINGLE;
5892 case bp_longjmp_resume:
5893 case bp_exception_resume:
5896 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5897 retval.is_longjmp = bptype == bp_longjmp_resume;
5900 this_action = BPSTAT_WHAT_SINGLE;
5902 case bp_step_resume:
5904 this_action = BPSTAT_WHAT_STEP_RESUME;
5907 /* It is for the wrong frame. */
5908 this_action = BPSTAT_WHAT_SINGLE;
5911 case bp_hp_step_resume:
5913 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5916 /* It is for the wrong frame. */
5917 this_action = BPSTAT_WHAT_SINGLE;
5920 case bp_watchpoint_scope:
5921 case bp_thread_event:
5922 case bp_overlay_event:
5923 case bp_longjmp_master:
5924 case bp_std_terminate_master:
5925 case bp_exception_master:
5926 this_action = BPSTAT_WHAT_SINGLE;
5932 this_action = BPSTAT_WHAT_STOP_NOISY;
5934 this_action = BPSTAT_WHAT_STOP_SILENT;
5938 /* There was a catchpoint, but we're not stopping.
5939 This requires no further action. */
5943 this_action = BPSTAT_WHAT_SINGLE;
5946 /* Make sure the action is stop (silent or noisy),
5947 so infrun.c pops the dummy frame. */
5948 retval.call_dummy = STOP_STACK_DUMMY;
5949 this_action = BPSTAT_WHAT_STOP_SILENT;
5951 case bp_std_terminate:
5952 /* Make sure the action is stop (silent or noisy),
5953 so infrun.c pops the dummy frame. */
5954 retval.call_dummy = STOP_STD_TERMINATE;
5955 this_action = BPSTAT_WHAT_STOP_SILENT;
5958 case bp_fast_tracepoint:
5959 case bp_static_tracepoint:
5960 /* Tracepoint hits should not be reported back to GDB, and
5961 if one got through somehow, it should have been filtered
5963 internal_error (__FILE__, __LINE__,
5964 _("bpstat_what: tracepoint encountered"));
5966 case bp_gnu_ifunc_resolver:
5967 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5968 this_action = BPSTAT_WHAT_SINGLE;
5970 case bp_gnu_ifunc_resolver_return:
5971 /* The breakpoint will be removed, execution will restart from the
5972 PC of the former breakpoint. */
5973 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5978 this_action = BPSTAT_WHAT_STOP_SILENT;
5980 this_action = BPSTAT_WHAT_SINGLE;
5984 internal_error (__FILE__, __LINE__,
5985 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5988 retval.main_action = std::max (retval.main_action, this_action);
5995 bpstat_run_callbacks (bpstat bs_head)
5999 for (bs = bs_head; bs != NULL; bs = bs->next)
6001 struct breakpoint *b = bs->breakpoint_at;
6008 handle_jit_event ();
6010 case bp_gnu_ifunc_resolver:
6011 gnu_ifunc_resolver_stop (b);
6013 case bp_gnu_ifunc_resolver_return:
6014 gnu_ifunc_resolver_return_stop (b);
6020 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6021 without hardware support). This isn't related to a specific bpstat,
6022 just to things like whether watchpoints are set. */
6025 bpstat_should_step (void)
6027 struct breakpoint *b;
6030 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
6036 bpstat_causes_stop (bpstat bs)
6038 for (; bs != NULL; bs = bs->next)
6047 /* Compute a string of spaces suitable to indent the next line
6048 so it starts at the position corresponding to the table column
6049 named COL_NAME in the currently active table of UIOUT. */
6052 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
6054 static char wrap_indent[80];
6055 int i, total_width, width, align;
6059 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
6061 if (strcmp (text, col_name) == 0)
6063 gdb_assert (total_width < sizeof wrap_indent);
6064 memset (wrap_indent, ' ', total_width);
6065 wrap_indent[total_width] = 0;
6070 total_width += width + 1;
6076 /* Determine if the locations of this breakpoint will have their conditions
6077 evaluated by the target, host or a mix of both. Returns the following:
6079 "host": Host evals condition.
6080 "host or target": Host or Target evals condition.
6081 "target": Target evals condition.
6085 bp_condition_evaluator (struct breakpoint *b)
6087 struct bp_location *bl;
6088 char host_evals = 0;
6089 char target_evals = 0;
6094 if (!is_breakpoint (b))
6097 if (gdb_evaluates_breakpoint_condition_p ()
6098 || !target_supports_evaluation_of_breakpoint_conditions ())
6099 return condition_evaluation_host;
6101 for (bl = b->loc; bl; bl = bl->next)
6103 if (bl->cond_bytecode)
6109 if (host_evals && target_evals)
6110 return condition_evaluation_both;
6111 else if (target_evals)
6112 return condition_evaluation_target;
6114 return condition_evaluation_host;
6117 /* Determine the breakpoint location's condition evaluator. This is
6118 similar to bp_condition_evaluator, but for locations. */
6121 bp_location_condition_evaluator (struct bp_location *bl)
6123 if (bl && !is_breakpoint (bl->owner))
6126 if (gdb_evaluates_breakpoint_condition_p ()
6127 || !target_supports_evaluation_of_breakpoint_conditions ())
6128 return condition_evaluation_host;
6130 if (bl && bl->cond_bytecode)
6131 return condition_evaluation_target;
6133 return condition_evaluation_host;
6136 /* Print the LOC location out of the list of B->LOC locations. */
6139 print_breakpoint_location (struct breakpoint *b,
6140 struct bp_location *loc)
6142 struct ui_out *uiout = current_uiout;
6144 scoped_restore_current_program_space restore_pspace;
6146 if (loc != NULL && loc->shlib_disabled)
6150 set_current_program_space (loc->pspace);
6152 if (b->display_canonical)
6153 uiout->field_string ("what", event_location_to_string (b->location.get ()));
6154 else if (loc && loc->symtab)
6157 = find_pc_sect_function (loc->address, loc->section);
6160 uiout->text ("in ");
6161 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
6163 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
6164 uiout->text ("at ");
6166 uiout->field_string ("file",
6167 symtab_to_filename_for_display (loc->symtab));
6170 if (uiout->is_mi_like_p ())
6171 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
6173 uiout->field_int ("line", loc->line_number);
6179 print_address_symbolic (loc->gdbarch, loc->address, &stb,
6181 uiout->field_stream ("at", stb);
6185 uiout->field_string ("pending",
6186 event_location_to_string (b->location.get ()));
6187 /* If extra_string is available, it could be holding a condition
6188 or dprintf arguments. In either case, make sure it is printed,
6189 too, but only for non-MI streams. */
6190 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
6192 if (b->type == bp_dprintf)
6196 uiout->text (b->extra_string);
6200 if (loc && is_breakpoint (b)
6201 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6202 && bp_condition_evaluator (b) == condition_evaluation_both)
6205 uiout->field_string ("evaluated-by",
6206 bp_location_condition_evaluator (loc));
6212 bptype_string (enum bptype type)
6214 struct ep_type_description
6217 const char *description;
6219 static struct ep_type_description bptypes[] =
6221 {bp_none, "?deleted?"},
6222 {bp_breakpoint, "breakpoint"},
6223 {bp_hardware_breakpoint, "hw breakpoint"},
6224 {bp_single_step, "sw single-step"},
6225 {bp_until, "until"},
6226 {bp_finish, "finish"},
6227 {bp_watchpoint, "watchpoint"},
6228 {bp_hardware_watchpoint, "hw watchpoint"},
6229 {bp_read_watchpoint, "read watchpoint"},
6230 {bp_access_watchpoint, "acc watchpoint"},
6231 {bp_longjmp, "longjmp"},
6232 {bp_longjmp_resume, "longjmp resume"},
6233 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6234 {bp_exception, "exception"},
6235 {bp_exception_resume, "exception resume"},
6236 {bp_step_resume, "step resume"},
6237 {bp_hp_step_resume, "high-priority step resume"},
6238 {bp_watchpoint_scope, "watchpoint scope"},
6239 {bp_call_dummy, "call dummy"},
6240 {bp_std_terminate, "std::terminate"},
6241 {bp_shlib_event, "shlib events"},
6242 {bp_thread_event, "thread events"},
6243 {bp_overlay_event, "overlay events"},
6244 {bp_longjmp_master, "longjmp master"},
6245 {bp_std_terminate_master, "std::terminate master"},
6246 {bp_exception_master, "exception master"},
6247 {bp_catchpoint, "catchpoint"},
6248 {bp_tracepoint, "tracepoint"},
6249 {bp_fast_tracepoint, "fast tracepoint"},
6250 {bp_static_tracepoint, "static tracepoint"},
6251 {bp_dprintf, "dprintf"},
6252 {bp_jit_event, "jit events"},
6253 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6254 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6257 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6258 || ((int) type != bptypes[(int) type].type))
6259 internal_error (__FILE__, __LINE__,
6260 _("bptypes table does not describe type #%d."),
6263 return bptypes[(int) type].description;
6266 /* For MI, output a field named 'thread-groups' with a list as the value.
6267 For CLI, prefix the list with the string 'inf'. */
6270 output_thread_groups (struct ui_out *uiout,
6271 const char *field_name,
6275 int is_mi = uiout->is_mi_like_p ();
6279 /* For backward compatibility, don't display inferiors in CLI unless
6280 there are several. Always display them for MI. */
6281 if (!is_mi && mi_only)
6284 ui_out_emit_list list_emitter (uiout, field_name);
6286 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6292 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6293 uiout->field_string (NULL, mi_group);
6298 uiout->text (" inf ");
6302 uiout->text (plongest (inf));
6307 /* Print B to gdb_stdout. */
6310 print_one_breakpoint_location (struct breakpoint *b,
6311 struct bp_location *loc,
6313 struct bp_location **last_loc,
6316 struct command_line *l;
6317 static char bpenables[] = "nynny";
6319 struct ui_out *uiout = current_uiout;
6320 int header_of_multiple = 0;
6321 int part_of_multiple = (loc != NULL);
6322 struct value_print_options opts;
6324 get_user_print_options (&opts);
6326 gdb_assert (!loc || loc_number != 0);
6327 /* See comment in print_one_breakpoint concerning treatment of
6328 breakpoints with single disabled location. */
6331 && (b->loc->next != NULL || !b->loc->enabled)))
6332 header_of_multiple = 1;
6340 if (part_of_multiple)
6343 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6344 uiout->field_string ("number", formatted);
6349 uiout->field_int ("number", b->number);
6354 if (part_of_multiple)
6355 uiout->field_skip ("type");
6357 uiout->field_string ("type", bptype_string (b->type));
6361 if (part_of_multiple)
6362 uiout->field_skip ("disp");
6364 uiout->field_string ("disp", bpdisp_text (b->disposition));
6369 if (part_of_multiple)
6370 uiout->field_string ("enabled", loc->enabled ? "y" : "n");
6372 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6377 if (b->ops != NULL && b->ops->print_one != NULL)
6379 /* Although the print_one can possibly print all locations,
6380 calling it here is not likely to get any nice result. So,
6381 make sure there's just one location. */
6382 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6383 b->ops->print_one (b, last_loc);
6389 internal_error (__FILE__, __LINE__,
6390 _("print_one_breakpoint: bp_none encountered\n"));
6394 case bp_hardware_watchpoint:
6395 case bp_read_watchpoint:
6396 case bp_access_watchpoint:
6398 struct watchpoint *w = (struct watchpoint *) b;
6400 /* Field 4, the address, is omitted (which makes the columns
6401 not line up too nicely with the headers, but the effect
6402 is relatively readable). */
6403 if (opts.addressprint)
6404 uiout->field_skip ("addr");
6406 uiout->field_string ("what", w->exp_string);
6411 case bp_hardware_breakpoint:
6412 case bp_single_step:
6416 case bp_longjmp_resume:
6417 case bp_longjmp_call_dummy:
6419 case bp_exception_resume:
6420 case bp_step_resume:
6421 case bp_hp_step_resume:
6422 case bp_watchpoint_scope:
6424 case bp_std_terminate:
6425 case bp_shlib_event:
6426 case bp_thread_event:
6427 case bp_overlay_event:
6428 case bp_longjmp_master:
6429 case bp_std_terminate_master:
6430 case bp_exception_master:
6432 case bp_fast_tracepoint:
6433 case bp_static_tracepoint:
6436 case bp_gnu_ifunc_resolver:
6437 case bp_gnu_ifunc_resolver_return:
6438 if (opts.addressprint)
6441 if (header_of_multiple)
6442 uiout->field_string ("addr", "<MULTIPLE>");
6443 else if (b->loc == NULL || loc->shlib_disabled)
6444 uiout->field_string ("addr", "<PENDING>");
6446 uiout->field_core_addr ("addr",
6447 loc->gdbarch, loc->address);
6450 if (!header_of_multiple)
6451 print_breakpoint_location (b, loc);
6458 if (loc != NULL && !header_of_multiple)
6460 struct inferior *inf;
6461 VEC(int) *inf_num = NULL;
6466 if (inf->pspace == loc->pspace)
6467 VEC_safe_push (int, inf_num, inf->num);
6470 /* For backward compatibility, don't display inferiors in CLI unless
6471 there are several. Always display for MI. */
6473 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6474 && (number_of_program_spaces () > 1
6475 || number_of_inferiors () > 1)
6476 /* LOC is for existing B, it cannot be in
6477 moribund_locations and thus having NULL OWNER. */
6478 && loc->owner->type != bp_catchpoint))
6480 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6481 VEC_free (int, inf_num);
6484 if (!part_of_multiple)
6486 if (b->thread != -1)
6488 /* FIXME: This seems to be redundant and lost here; see the
6489 "stop only in" line a little further down. */
6490 uiout->text (" thread ");
6491 uiout->field_int ("thread", b->thread);
6493 else if (b->task != 0)
6495 uiout->text (" task ");
6496 uiout->field_int ("task", b->task);
6502 if (!part_of_multiple)
6503 b->ops->print_one_detail (b, uiout);
6505 if (part_of_multiple && frame_id_p (b->frame_id))
6508 uiout->text ("\tstop only in stack frame at ");
6509 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6511 uiout->field_core_addr ("frame",
6512 b->gdbarch, b->frame_id.stack_addr);
6516 if (!part_of_multiple && b->cond_string)
6519 if (is_tracepoint (b))
6520 uiout->text ("\ttrace only if ");
6522 uiout->text ("\tstop only if ");
6523 uiout->field_string ("cond", b->cond_string);
6525 /* Print whether the target is doing the breakpoint's condition
6526 evaluation. If GDB is doing the evaluation, don't print anything. */
6527 if (is_breakpoint (b)
6528 && breakpoint_condition_evaluation_mode ()
6529 == condition_evaluation_target)
6532 uiout->field_string ("evaluated-by",
6533 bp_condition_evaluator (b));
6534 uiout->text (" evals)");
6539 if (!part_of_multiple && b->thread != -1)
6541 /* FIXME should make an annotation for this. */
6542 uiout->text ("\tstop only in thread ");
6543 if (uiout->is_mi_like_p ())
6544 uiout->field_int ("thread", b->thread);
6547 struct thread_info *thr = find_thread_global_id (b->thread);
6549 uiout->field_string ("thread", print_thread_id (thr));
6554 if (!part_of_multiple)
6558 /* FIXME should make an annotation for this. */
6559 if (is_catchpoint (b))
6560 uiout->text ("\tcatchpoint");
6561 else if (is_tracepoint (b))
6562 uiout->text ("\ttracepoint");
6564 uiout->text ("\tbreakpoint");
6565 uiout->text (" already hit ");
6566 uiout->field_int ("times", b->hit_count);
6567 if (b->hit_count == 1)
6568 uiout->text (" time\n");
6570 uiout->text (" times\n");
6574 /* Output the count also if it is zero, but only if this is mi. */
6575 if (uiout->is_mi_like_p ())
6576 uiout->field_int ("times", b->hit_count);
6580 if (!part_of_multiple && b->ignore_count)
6583 uiout->text ("\tignore next ");
6584 uiout->field_int ("ignore", b->ignore_count);
6585 uiout->text (" hits\n");
6588 /* Note that an enable count of 1 corresponds to "enable once"
6589 behavior, which is reported by the combination of enablement and
6590 disposition, so we don't need to mention it here. */
6591 if (!part_of_multiple && b->enable_count > 1)
6594 uiout->text ("\tdisable after ");
6595 /* Tweak the wording to clarify that ignore and enable counts
6596 are distinct, and have additive effect. */
6597 if (b->ignore_count)
6598 uiout->text ("additional ");
6600 uiout->text ("next ");
6601 uiout->field_int ("enable", b->enable_count);
6602 uiout->text (" hits\n");
6605 if (!part_of_multiple && is_tracepoint (b))
6607 struct tracepoint *tp = (struct tracepoint *) b;
6609 if (tp->traceframe_usage)
6611 uiout->text ("\ttrace buffer usage ");
6612 uiout->field_int ("traceframe-usage", tp->traceframe_usage);
6613 uiout->text (" bytes\n");
6617 l = b->commands ? b->commands->commands : NULL;
6618 if (!part_of_multiple && l)
6621 ui_out_emit_tuple tuple_emitter (uiout, "script");
6622 print_command_lines (uiout, l, 4);
6625 if (is_tracepoint (b))
6627 struct tracepoint *t = (struct tracepoint *) b;
6629 if (!part_of_multiple && t->pass_count)
6631 annotate_field (10);
6632 uiout->text ("\tpass count ");
6633 uiout->field_int ("pass", t->pass_count);
6634 uiout->text (" \n");
6637 /* Don't display it when tracepoint or tracepoint location is
6639 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6641 annotate_field (11);
6643 if (uiout->is_mi_like_p ())
6644 uiout->field_string ("installed",
6645 loc->inserted ? "y" : "n");
6651 uiout->text ("\tnot ");
6652 uiout->text ("installed on target\n");
6657 if (uiout->is_mi_like_p () && !part_of_multiple)
6659 if (is_watchpoint (b))
6661 struct watchpoint *w = (struct watchpoint *) b;
6663 uiout->field_string ("original-location", w->exp_string);
6665 else if (b->location != NULL
6666 && event_location_to_string (b->location.get ()) != NULL)
6667 uiout->field_string ("original-location",
6668 event_location_to_string (b->location.get ()));
6673 print_one_breakpoint (struct breakpoint *b,
6674 struct bp_location **last_loc,
6677 struct ui_out *uiout = current_uiout;
6680 ui_out_emit_tuple tuple_emitter (uiout, "bkpt");
6682 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6685 /* If this breakpoint has custom print function,
6686 it's already printed. Otherwise, print individual
6687 locations, if any. */
6688 if (b->ops == NULL || b->ops->print_one == NULL)
6690 /* If breakpoint has a single location that is disabled, we
6691 print it as if it had several locations, since otherwise it's
6692 hard to represent "breakpoint enabled, location disabled"
6695 Note that while hardware watchpoints have several locations
6696 internally, that's not a property exposed to user. */
6698 && !is_hardware_watchpoint (b)
6699 && (b->loc->next || !b->loc->enabled))
6701 struct bp_location *loc;
6704 for (loc = b->loc; loc; loc = loc->next, ++n)
6706 ui_out_emit_tuple tuple_emitter (uiout, NULL);
6707 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6714 breakpoint_address_bits (struct breakpoint *b)
6716 int print_address_bits = 0;
6717 struct bp_location *loc;
6719 /* Software watchpoints that aren't watching memory don't have an
6720 address to print. */
6721 if (is_no_memory_software_watchpoint (b))
6724 for (loc = b->loc; loc; loc = loc->next)
6728 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6729 if (addr_bit > print_address_bits)
6730 print_address_bits = addr_bit;
6733 return print_address_bits;
6736 struct captured_breakpoint_query_args
6742 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6744 struct captured_breakpoint_query_args *args
6745 = (struct captured_breakpoint_query_args *) data;
6746 struct breakpoint *b;
6747 struct bp_location *dummy_loc = NULL;
6751 if (args->bnum == b->number)
6753 print_one_breakpoint (b, &dummy_loc, 0);
6761 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6762 char **error_message)
6764 struct captured_breakpoint_query_args args;
6767 /* For the moment we don't trust print_one_breakpoint() to not throw
6769 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6770 error_message, RETURN_MASK_ALL) < 0)
6776 /* Return true if this breakpoint was set by the user, false if it is
6777 internal or momentary. */
6780 user_breakpoint_p (struct breakpoint *b)
6782 return b->number > 0;
6785 /* See breakpoint.h. */
6788 pending_breakpoint_p (struct breakpoint *b)
6790 return b->loc == NULL;
6793 /* Print information on user settable breakpoint (watchpoint, etc)
6794 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6795 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6796 FILTER is non-NULL, call it on each breakpoint and only include the
6797 ones for which it returns non-zero. Return the total number of
6798 breakpoints listed. */
6801 breakpoint_1 (char *args, int allflag,
6802 int (*filter) (const struct breakpoint *))
6804 struct breakpoint *b;
6805 struct bp_location *last_loc = NULL;
6806 int nr_printable_breakpoints;
6807 struct cleanup *bkpttbl_chain;
6808 struct value_print_options opts;
6809 int print_address_bits = 0;
6810 int print_type_col_width = 14;
6811 struct ui_out *uiout = current_uiout;
6813 get_user_print_options (&opts);
6815 /* Compute the number of rows in the table, as well as the size
6816 required for address fields. */
6817 nr_printable_breakpoints = 0;
6820 /* If we have a filter, only list the breakpoints it accepts. */
6821 if (filter && !filter (b))
6824 /* If we have an "args" string, it is a list of breakpoints to
6825 accept. Skip the others. */
6826 if (args != NULL && *args != '\0')
6828 if (allflag && parse_and_eval_long (args) != b->number)
6830 if (!allflag && !number_is_in_list (args, b->number))
6834 if (allflag || user_breakpoint_p (b))
6836 int addr_bit, type_len;
6838 addr_bit = breakpoint_address_bits (b);
6839 if (addr_bit > print_address_bits)
6840 print_address_bits = addr_bit;
6842 type_len = strlen (bptype_string (b->type));
6843 if (type_len > print_type_col_width)
6844 print_type_col_width = type_len;
6846 nr_printable_breakpoints++;
6850 if (opts.addressprint)
6852 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6853 nr_printable_breakpoints,
6857 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6858 nr_printable_breakpoints,
6861 if (nr_printable_breakpoints > 0)
6862 annotate_breakpoints_headers ();
6863 if (nr_printable_breakpoints > 0)
6865 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
6866 if (nr_printable_breakpoints > 0)
6868 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
6869 if (nr_printable_breakpoints > 0)
6871 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
6872 if (nr_printable_breakpoints > 0)
6874 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
6875 if (opts.addressprint)
6877 if (nr_printable_breakpoints > 0)
6879 if (print_address_bits <= 32)
6880 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
6882 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
6884 if (nr_printable_breakpoints > 0)
6886 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
6887 uiout->table_body ();
6888 if (nr_printable_breakpoints > 0)
6889 annotate_breakpoints_table ();
6894 /* If we have a filter, only list the breakpoints it accepts. */
6895 if (filter && !filter (b))
6898 /* If we have an "args" string, it is a list of breakpoints to
6899 accept. Skip the others. */
6901 if (args != NULL && *args != '\0')
6903 if (allflag) /* maintenance info breakpoint */
6905 if (parse_and_eval_long (args) != b->number)
6908 else /* all others */
6910 if (!number_is_in_list (args, b->number))
6914 /* We only print out user settable breakpoints unless the
6916 if (allflag || user_breakpoint_p (b))
6917 print_one_breakpoint (b, &last_loc, allflag);
6920 do_cleanups (bkpttbl_chain);
6922 if (nr_printable_breakpoints == 0)
6924 /* If there's a filter, let the caller decide how to report
6928 if (args == NULL || *args == '\0')
6929 uiout->message ("No breakpoints or watchpoints.\n");
6931 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
6937 if (last_loc && !server_command)
6938 set_next_address (last_loc->gdbarch, last_loc->address);
6941 /* FIXME? Should this be moved up so that it is only called when
6942 there have been breakpoints? */
6943 annotate_breakpoints_table_end ();
6945 return nr_printable_breakpoints;
6948 /* Display the value of default-collect in a way that is generally
6949 compatible with the breakpoint list. */
6952 default_collect_info (void)
6954 struct ui_out *uiout = current_uiout;
6956 /* If it has no value (which is frequently the case), say nothing; a
6957 message like "No default-collect." gets in user's face when it's
6959 if (!*default_collect)
6962 /* The following phrase lines up nicely with per-tracepoint collect
6964 uiout->text ("default collect ");
6965 uiout->field_string ("default-collect", default_collect);
6966 uiout->text (" \n");
6970 breakpoints_info (char *args, int from_tty)
6972 breakpoint_1 (args, 0, NULL);
6974 default_collect_info ();
6978 watchpoints_info (char *args, int from_tty)
6980 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6981 struct ui_out *uiout = current_uiout;
6983 if (num_printed == 0)
6985 if (args == NULL || *args == '\0')
6986 uiout->message ("No watchpoints.\n");
6988 uiout->message ("No watchpoint matching '%s'.\n", args);
6993 maintenance_info_breakpoints (char *args, int from_tty)
6995 breakpoint_1 (args, 1, NULL);
6997 default_collect_info ();
7001 breakpoint_has_pc (struct breakpoint *b,
7002 struct program_space *pspace,
7003 CORE_ADDR pc, struct obj_section *section)
7005 struct bp_location *bl = b->loc;
7007 for (; bl; bl = bl->next)
7009 if (bl->pspace == pspace
7010 && bl->address == pc
7011 && (!overlay_debugging || bl->section == section))
7017 /* Print a message describing any user-breakpoints set at PC. This
7018 concerns with logical breakpoints, so we match program spaces, not
7022 describe_other_breakpoints (struct gdbarch *gdbarch,
7023 struct program_space *pspace, CORE_ADDR pc,
7024 struct obj_section *section, int thread)
7027 struct breakpoint *b;
7030 others += (user_breakpoint_p (b)
7031 && breakpoint_has_pc (b, pspace, pc, section));
7035 printf_filtered (_("Note: breakpoint "));
7036 else /* if (others == ???) */
7037 printf_filtered (_("Note: breakpoints "));
7039 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
7042 printf_filtered ("%d", b->number);
7043 if (b->thread == -1 && thread != -1)
7044 printf_filtered (" (all threads)");
7045 else if (b->thread != -1)
7046 printf_filtered (" (thread %d)", b->thread);
7047 printf_filtered ("%s%s ",
7048 ((b->enable_state == bp_disabled
7049 || b->enable_state == bp_call_disabled)
7053 : ((others == 1) ? " and" : ""));
7055 printf_filtered (_("also set at pc "));
7056 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
7057 printf_filtered (".\n");
7062 /* Return true iff it is meaningful to use the address member of
7063 BPT locations. For some breakpoint types, the locations' address members
7064 are irrelevant and it makes no sense to attempt to compare them to other
7065 addresses (or use them for any other purpose either).
7067 More specifically, each of the following breakpoint types will
7068 always have a zero valued location address and we don't want to mark
7069 breakpoints of any of these types to be a duplicate of an actual
7070 breakpoint location at address zero:
7078 breakpoint_address_is_meaningful (struct breakpoint *bpt)
7080 enum bptype type = bpt->type;
7082 return (type != bp_watchpoint && type != bp_catchpoint);
7085 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7086 true if LOC1 and LOC2 represent the same watchpoint location. */
7089 watchpoint_locations_match (struct bp_location *loc1,
7090 struct bp_location *loc2)
7092 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
7093 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
7095 /* Both of them must exist. */
7096 gdb_assert (w1 != NULL);
7097 gdb_assert (w2 != NULL);
7099 /* If the target can evaluate the condition expression in hardware,
7100 then we we need to insert both watchpoints even if they are at
7101 the same place. Otherwise the watchpoint will only trigger when
7102 the condition of whichever watchpoint was inserted evaluates to
7103 true, not giving a chance for GDB to check the condition of the
7104 other watchpoint. */
7106 && target_can_accel_watchpoint_condition (loc1->address,
7108 loc1->watchpoint_type,
7109 w1->cond_exp.get ()))
7111 && target_can_accel_watchpoint_condition (loc2->address,
7113 loc2->watchpoint_type,
7114 w2->cond_exp.get ())))
7117 /* Note that this checks the owner's type, not the location's. In
7118 case the target does not support read watchpoints, but does
7119 support access watchpoints, we'll have bp_read_watchpoint
7120 watchpoints with hw_access locations. Those should be considered
7121 duplicates of hw_read locations. The hw_read locations will
7122 become hw_access locations later. */
7123 return (loc1->owner->type == loc2->owner->type
7124 && loc1->pspace->aspace == loc2->pspace->aspace
7125 && loc1->address == loc2->address
7126 && loc1->length == loc2->length);
7129 /* See breakpoint.h. */
7132 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7133 struct address_space *aspace2, CORE_ADDR addr2)
7135 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7136 || aspace1 == aspace2)
7140 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7141 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7142 matches ASPACE2. On targets that have global breakpoints, the address
7143 space doesn't really matter. */
7146 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7147 int len1, struct address_space *aspace2,
7150 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7151 || aspace1 == aspace2)
7152 && addr2 >= addr1 && addr2 < addr1 + len1);
7155 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7156 a ranged breakpoint. In most targets, a match happens only if ASPACE
7157 matches the breakpoint's address space. On targets that have global
7158 breakpoints, the address space doesn't really matter. */
7161 breakpoint_location_address_match (struct bp_location *bl,
7162 struct address_space *aspace,
7165 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7168 && breakpoint_address_match_range (bl->pspace->aspace,
7169 bl->address, bl->length,
7173 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7174 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7175 match happens only if ASPACE matches the breakpoint's address
7176 space. On targets that have global breakpoints, the address space
7177 doesn't really matter. */
7180 breakpoint_location_address_range_overlap (struct bp_location *bl,
7181 struct address_space *aspace,
7182 CORE_ADDR addr, int len)
7184 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7185 || bl->pspace->aspace == aspace)
7187 int bl_len = bl->length != 0 ? bl->length : 1;
7189 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
7195 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7196 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7197 true, otherwise returns false. */
7200 tracepoint_locations_match (struct bp_location *loc1,
7201 struct bp_location *loc2)
7203 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7204 /* Since tracepoint locations are never duplicated with others', tracepoint
7205 locations at the same address of different tracepoints are regarded as
7206 different locations. */
7207 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7212 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7213 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7214 represent the same location. */
7217 breakpoint_locations_match (struct bp_location *loc1,
7218 struct bp_location *loc2)
7220 int hw_point1, hw_point2;
7222 /* Both of them must not be in moribund_locations. */
7223 gdb_assert (loc1->owner != NULL);
7224 gdb_assert (loc2->owner != NULL);
7226 hw_point1 = is_hardware_watchpoint (loc1->owner);
7227 hw_point2 = is_hardware_watchpoint (loc2->owner);
7229 if (hw_point1 != hw_point2)
7232 return watchpoint_locations_match (loc1, loc2);
7233 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7234 return tracepoint_locations_match (loc1, loc2);
7236 /* We compare bp_location.length in order to cover ranged breakpoints. */
7237 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7238 loc2->pspace->aspace, loc2->address)
7239 && loc1->length == loc2->length);
7243 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7244 int bnum, int have_bnum)
7246 /* The longest string possibly returned by hex_string_custom
7247 is 50 chars. These must be at least that big for safety. */
7251 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7252 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7254 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7255 bnum, astr1, astr2);
7257 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7260 /* Adjust a breakpoint's address to account for architectural
7261 constraints on breakpoint placement. Return the adjusted address.
7262 Note: Very few targets require this kind of adjustment. For most
7263 targets, this function is simply the identity function. */
7266 adjust_breakpoint_address (struct gdbarch *gdbarch,
7267 CORE_ADDR bpaddr, enum bptype bptype)
7269 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7271 /* Very few targets need any kind of breakpoint adjustment. */
7274 else if (bptype == bp_watchpoint
7275 || bptype == bp_hardware_watchpoint
7276 || bptype == bp_read_watchpoint
7277 || bptype == bp_access_watchpoint
7278 || bptype == bp_catchpoint)
7280 /* Watchpoints and the various bp_catch_* eventpoints should not
7281 have their addresses modified. */
7284 else if (bptype == bp_single_step)
7286 /* Single-step breakpoints should not have their addresses
7287 modified. If there's any architectural constrain that
7288 applies to this address, then it should have already been
7289 taken into account when the breakpoint was created in the
7290 first place. If we didn't do this, stepping through e.g.,
7291 Thumb-2 IT blocks would break. */
7296 CORE_ADDR adjusted_bpaddr;
7298 /* Some targets have architectural constraints on the placement
7299 of breakpoint instructions. Obtain the adjusted address. */
7300 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7302 /* An adjusted breakpoint address can significantly alter
7303 a user's expectations. Print a warning if an adjustment
7305 if (adjusted_bpaddr != bpaddr)
7306 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7308 return adjusted_bpaddr;
7312 bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner)
7314 bp_location *loc = this;
7316 gdb_assert (ops != NULL);
7320 loc->cond_bytecode = NULL;
7321 loc->shlib_disabled = 0;
7324 switch (owner->type)
7327 case bp_single_step:
7331 case bp_longjmp_resume:
7332 case bp_longjmp_call_dummy:
7334 case bp_exception_resume:
7335 case bp_step_resume:
7336 case bp_hp_step_resume:
7337 case bp_watchpoint_scope:
7339 case bp_std_terminate:
7340 case bp_shlib_event:
7341 case bp_thread_event:
7342 case bp_overlay_event:
7344 case bp_longjmp_master:
7345 case bp_std_terminate_master:
7346 case bp_exception_master:
7347 case bp_gnu_ifunc_resolver:
7348 case bp_gnu_ifunc_resolver_return:
7350 loc->loc_type = bp_loc_software_breakpoint;
7351 mark_breakpoint_location_modified (loc);
7353 case bp_hardware_breakpoint:
7354 loc->loc_type = bp_loc_hardware_breakpoint;
7355 mark_breakpoint_location_modified (loc);
7357 case bp_hardware_watchpoint:
7358 case bp_read_watchpoint:
7359 case bp_access_watchpoint:
7360 loc->loc_type = bp_loc_hardware_watchpoint;
7365 case bp_fast_tracepoint:
7366 case bp_static_tracepoint:
7367 loc->loc_type = bp_loc_other;
7370 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7376 /* Allocate a struct bp_location. */
7378 static struct bp_location *
7379 allocate_bp_location (struct breakpoint *bpt)
7381 return bpt->ops->allocate_location (bpt);
7385 free_bp_location (struct bp_location *loc)
7387 loc->ops->dtor (loc);
7391 /* Increment reference count. */
7394 incref_bp_location (struct bp_location *bl)
7399 /* Decrement reference count. If the reference count reaches 0,
7400 destroy the bp_location. Sets *BLP to NULL. */
7403 decref_bp_location (struct bp_location **blp)
7405 gdb_assert ((*blp)->refc > 0);
7407 if (--(*blp)->refc == 0)
7408 free_bp_location (*blp);
7412 /* Add breakpoint B at the end of the global breakpoint chain. */
7415 add_to_breakpoint_chain (struct breakpoint *b)
7417 struct breakpoint *b1;
7419 /* Add this breakpoint to the end of the chain so that a list of
7420 breakpoints will come out in order of increasing numbers. */
7422 b1 = breakpoint_chain;
7424 breakpoint_chain = b;
7433 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7436 init_raw_breakpoint_without_location (struct breakpoint *b,
7437 struct gdbarch *gdbarch,
7439 const struct breakpoint_ops *ops)
7441 gdb_assert (ops != NULL);
7445 b->gdbarch = gdbarch;
7446 b->language = current_language->la_language;
7447 b->input_radix = input_radix;
7448 b->related_breakpoint = b;
7451 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7452 that has type BPTYPE and has no locations as yet. */
7454 static struct breakpoint *
7455 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7457 const struct breakpoint_ops *ops)
7459 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7461 init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops);
7462 add_to_breakpoint_chain (b.get ());
7464 return b.release ();
7467 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7468 resolutions should be made as the user specified the location explicitly
7472 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7474 gdb_assert (loc->owner != NULL);
7476 if (loc->owner->type == bp_breakpoint
7477 || loc->owner->type == bp_hardware_breakpoint
7478 || is_tracepoint (loc->owner))
7481 const char *function_name;
7482 CORE_ADDR func_addr;
7484 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7485 &func_addr, NULL, &is_gnu_ifunc);
7487 if (is_gnu_ifunc && !explicit_loc)
7489 struct breakpoint *b = loc->owner;
7491 gdb_assert (loc->pspace == current_program_space);
7492 if (gnu_ifunc_resolve_name (function_name,
7493 &loc->requested_address))
7495 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7496 loc->address = adjust_breakpoint_address (loc->gdbarch,
7497 loc->requested_address,
7500 else if (b->type == bp_breakpoint && b->loc == loc
7501 && loc->next == NULL && b->related_breakpoint == b)
7503 /* Create only the whole new breakpoint of this type but do not
7504 mess more complicated breakpoints with multiple locations. */
7505 b->type = bp_gnu_ifunc_resolver;
7506 /* Remember the resolver's address for use by the return
7508 loc->related_address = func_addr;
7513 loc->function_name = xstrdup (function_name);
7517 /* Attempt to determine architecture of location identified by SAL. */
7519 get_sal_arch (struct symtab_and_line sal)
7522 return get_objfile_arch (sal.section->objfile);
7524 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7529 /* Low level routine for partially initializing a breakpoint of type
7530 BPTYPE. The newly created breakpoint's address, section, source
7531 file name, and line number are provided by SAL.
7533 It is expected that the caller will complete the initialization of
7534 the newly created breakpoint struct as well as output any status
7535 information regarding the creation of a new breakpoint. */
7538 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7539 struct symtab_and_line sal, enum bptype bptype,
7540 const struct breakpoint_ops *ops)
7542 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7544 add_location_to_breakpoint (b, &sal);
7546 if (bptype != bp_catchpoint)
7547 gdb_assert (sal.pspace != NULL);
7549 /* Store the program space that was used to set the breakpoint,
7550 except for ordinary breakpoints, which are independent of the
7552 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7553 b->pspace = sal.pspace;
7556 /* set_raw_breakpoint is a low level routine for allocating and
7557 partially initializing a breakpoint of type BPTYPE. The newly
7558 created breakpoint's address, section, source file name, and line
7559 number are provided by SAL. The newly created and partially
7560 initialized breakpoint is added to the breakpoint chain and
7561 is also returned as the value of this function.
7563 It is expected that the caller will complete the initialization of
7564 the newly created breakpoint struct as well as output any status
7565 information regarding the creation of a new breakpoint. In
7566 particular, set_raw_breakpoint does NOT set the breakpoint
7567 number! Care should be taken to not allow an error to occur
7568 prior to completing the initialization of the breakpoint. If this
7569 should happen, a bogus breakpoint will be left on the chain. */
7572 set_raw_breakpoint (struct gdbarch *gdbarch,
7573 struct symtab_and_line sal, enum bptype bptype,
7574 const struct breakpoint_ops *ops)
7576 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype);
7578 init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops);
7579 add_to_breakpoint_chain (b.get ());
7581 return b.release ();
7584 /* Call this routine when stepping and nexting to enable a breakpoint
7585 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7586 initiated the operation. */
7589 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7591 struct breakpoint *b, *b_tmp;
7592 int thread = tp->global_num;
7594 /* To avoid having to rescan all objfile symbols at every step,
7595 we maintain a list of continually-inserted but always disabled
7596 longjmp "master" breakpoints. Here, we simply create momentary
7597 clones of those and enable them for the requested thread. */
7598 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7599 if (b->pspace == current_program_space
7600 && (b->type == bp_longjmp_master
7601 || b->type == bp_exception_master))
7603 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7604 struct breakpoint *clone;
7606 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7607 after their removal. */
7608 clone = momentary_breakpoint_from_master (b, type,
7609 &momentary_breakpoint_ops, 1);
7610 clone->thread = thread;
7613 tp->initiating_frame = frame;
7616 /* Delete all longjmp breakpoints from THREAD. */
7618 delete_longjmp_breakpoint (int thread)
7620 struct breakpoint *b, *b_tmp;
7622 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7623 if (b->type == bp_longjmp || b->type == bp_exception)
7625 if (b->thread == thread)
7626 delete_breakpoint (b);
7631 delete_longjmp_breakpoint_at_next_stop (int thread)
7633 struct breakpoint *b, *b_tmp;
7635 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7636 if (b->type == bp_longjmp || b->type == bp_exception)
7638 if (b->thread == thread)
7639 b->disposition = disp_del_at_next_stop;
7643 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7644 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7645 pointer to any of them. Return NULL if this system cannot place longjmp
7649 set_longjmp_breakpoint_for_call_dummy (void)
7651 struct breakpoint *b, *retval = NULL;
7654 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7656 struct breakpoint *new_b;
7658 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7659 &momentary_breakpoint_ops,
7661 new_b->thread = ptid_to_global_thread_id (inferior_ptid);
7663 /* Link NEW_B into the chain of RETVAL breakpoints. */
7665 gdb_assert (new_b->related_breakpoint == new_b);
7668 new_b->related_breakpoint = retval;
7669 while (retval->related_breakpoint != new_b->related_breakpoint)
7670 retval = retval->related_breakpoint;
7671 retval->related_breakpoint = new_b;
7677 /* Verify all existing dummy frames and their associated breakpoints for
7678 TP. Remove those which can no longer be found in the current frame
7681 You should call this function only at places where it is safe to currently
7682 unwind the whole stack. Failed stack unwind would discard live dummy
7686 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7688 struct breakpoint *b, *b_tmp;
7690 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7691 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7693 struct breakpoint *dummy_b = b->related_breakpoint;
7695 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7696 dummy_b = dummy_b->related_breakpoint;
7697 if (dummy_b->type != bp_call_dummy
7698 || frame_find_by_id (dummy_b->frame_id) != NULL)
7701 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7703 while (b->related_breakpoint != b)
7705 if (b_tmp == b->related_breakpoint)
7706 b_tmp = b->related_breakpoint->next;
7707 delete_breakpoint (b->related_breakpoint);
7709 delete_breakpoint (b);
7714 enable_overlay_breakpoints (void)
7716 struct breakpoint *b;
7719 if (b->type == bp_overlay_event)
7721 b->enable_state = bp_enabled;
7722 update_global_location_list (UGLL_MAY_INSERT);
7723 overlay_events_enabled = 1;
7728 disable_overlay_breakpoints (void)
7730 struct breakpoint *b;
7733 if (b->type == bp_overlay_event)
7735 b->enable_state = bp_disabled;
7736 update_global_location_list (UGLL_DONT_INSERT);
7737 overlay_events_enabled = 0;
7741 /* Set an active std::terminate breakpoint for each std::terminate
7742 master breakpoint. */
7744 set_std_terminate_breakpoint (void)
7746 struct breakpoint *b, *b_tmp;
7748 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7749 if (b->pspace == current_program_space
7750 && b->type == bp_std_terminate_master)
7752 momentary_breakpoint_from_master (b, bp_std_terminate,
7753 &momentary_breakpoint_ops, 1);
7757 /* Delete all the std::terminate breakpoints. */
7759 delete_std_terminate_breakpoint (void)
7761 struct breakpoint *b, *b_tmp;
7763 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7764 if (b->type == bp_std_terminate)
7765 delete_breakpoint (b);
7769 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7771 struct breakpoint *b;
7773 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7774 &internal_breakpoint_ops);
7776 b->enable_state = bp_enabled;
7777 /* location has to be used or breakpoint_re_set will delete me. */
7778 b->location = new_address_location (b->loc->address, NULL, 0);
7780 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7785 struct lang_and_radix
7791 /* Create a breakpoint for JIT code registration and unregistration. */
7794 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7796 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7797 &internal_breakpoint_ops);
7800 /* Remove JIT code registration and unregistration breakpoint(s). */
7803 remove_jit_event_breakpoints (void)
7805 struct breakpoint *b, *b_tmp;
7807 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7808 if (b->type == bp_jit_event
7809 && b->loc->pspace == current_program_space)
7810 delete_breakpoint (b);
7814 remove_solib_event_breakpoints (void)
7816 struct breakpoint *b, *b_tmp;
7818 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7819 if (b->type == bp_shlib_event
7820 && b->loc->pspace == current_program_space)
7821 delete_breakpoint (b);
7824 /* See breakpoint.h. */
7827 remove_solib_event_breakpoints_at_next_stop (void)
7829 struct breakpoint *b, *b_tmp;
7831 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7832 if (b->type == bp_shlib_event
7833 && b->loc->pspace == current_program_space)
7834 b->disposition = disp_del_at_next_stop;
7837 /* Helper for create_solib_event_breakpoint /
7838 create_and_insert_solib_event_breakpoint. Allows specifying which
7839 INSERT_MODE to pass through to update_global_location_list. */
7841 static struct breakpoint *
7842 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7843 enum ugll_insert_mode insert_mode)
7845 struct breakpoint *b;
7847 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7848 &internal_breakpoint_ops);
7849 update_global_location_list_nothrow (insert_mode);
7854 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7856 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7859 /* See breakpoint.h. */
7862 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7864 struct breakpoint *b;
7866 /* Explicitly tell update_global_location_list to insert
7868 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7869 if (!b->loc->inserted)
7871 delete_breakpoint (b);
7877 /* Disable any breakpoints that are on code in shared libraries. Only
7878 apply to enabled breakpoints, disabled ones can just stay disabled. */
7881 disable_breakpoints_in_shlibs (void)
7883 struct bp_location *loc, **locp_tmp;
7885 ALL_BP_LOCATIONS (loc, locp_tmp)
7887 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7888 struct breakpoint *b = loc->owner;
7890 /* We apply the check to all breakpoints, including disabled for
7891 those with loc->duplicate set. This is so that when breakpoint
7892 becomes enabled, or the duplicate is removed, gdb will try to
7893 insert all breakpoints. If we don't set shlib_disabled here,
7894 we'll try to insert those breakpoints and fail. */
7895 if (((b->type == bp_breakpoint)
7896 || (b->type == bp_jit_event)
7897 || (b->type == bp_hardware_breakpoint)
7898 || (is_tracepoint (b)))
7899 && loc->pspace == current_program_space
7900 && !loc->shlib_disabled
7901 && solib_name_from_address (loc->pspace, loc->address)
7904 loc->shlib_disabled = 1;
7909 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7910 notification of unloaded_shlib. Only apply to enabled breakpoints,
7911 disabled ones can just stay disabled. */
7914 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7916 struct bp_location *loc, **locp_tmp;
7917 int disabled_shlib_breaks = 0;
7919 ALL_BP_LOCATIONS (loc, locp_tmp)
7921 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7922 struct breakpoint *b = loc->owner;
7924 if (solib->pspace == loc->pspace
7925 && !loc->shlib_disabled
7926 && (((b->type == bp_breakpoint
7927 || b->type == bp_jit_event
7928 || b->type == bp_hardware_breakpoint)
7929 && (loc->loc_type == bp_loc_hardware_breakpoint
7930 || loc->loc_type == bp_loc_software_breakpoint))
7931 || is_tracepoint (b))
7932 && solib_contains_address_p (solib, loc->address))
7934 loc->shlib_disabled = 1;
7935 /* At this point, we cannot rely on remove_breakpoint
7936 succeeding so we must mark the breakpoint as not inserted
7937 to prevent future errors occurring in remove_breakpoints. */
7940 /* This may cause duplicate notifications for the same breakpoint. */
7941 observer_notify_breakpoint_modified (b);
7943 if (!disabled_shlib_breaks)
7945 target_terminal_ours_for_output ();
7946 warning (_("Temporarily disabling breakpoints "
7947 "for unloaded shared library \"%s\""),
7950 disabled_shlib_breaks = 1;
7955 /* Disable any breakpoints and tracepoints in OBJFILE upon
7956 notification of free_objfile. Only apply to enabled breakpoints,
7957 disabled ones can just stay disabled. */
7960 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7962 struct breakpoint *b;
7964 if (objfile == NULL)
7967 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7968 managed by the user with add-symbol-file/remove-symbol-file.
7969 Similarly to how breakpoints in shared libraries are handled in
7970 response to "nosharedlibrary", mark breakpoints in such modules
7971 shlib_disabled so they end up uninserted on the next global
7972 location list update. Shared libraries not loaded by the user
7973 aren't handled here -- they're already handled in
7974 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7975 solib_unloaded observer. We skip objfiles that are not
7976 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7978 if ((objfile->flags & OBJF_SHARED) == 0
7979 || (objfile->flags & OBJF_USERLOADED) == 0)
7984 struct bp_location *loc;
7985 int bp_modified = 0;
7987 if (!is_breakpoint (b) && !is_tracepoint (b))
7990 for (loc = b->loc; loc != NULL; loc = loc->next)
7992 CORE_ADDR loc_addr = loc->address;
7994 if (loc->loc_type != bp_loc_hardware_breakpoint
7995 && loc->loc_type != bp_loc_software_breakpoint)
7998 if (loc->shlib_disabled != 0)
8001 if (objfile->pspace != loc->pspace)
8004 if (loc->loc_type != bp_loc_hardware_breakpoint
8005 && loc->loc_type != bp_loc_software_breakpoint)
8008 if (is_addr_in_objfile (loc_addr, objfile))
8010 loc->shlib_disabled = 1;
8011 /* At this point, we don't know whether the object was
8012 unmapped from the inferior or not, so leave the
8013 inserted flag alone. We'll handle failure to
8014 uninsert quietly, in case the object was indeed
8017 mark_breakpoint_location_modified (loc);
8024 observer_notify_breakpoint_modified (b);
8028 /* FORK & VFORK catchpoints. */
8030 /* An instance of this type is used to represent a fork or vfork
8031 catchpoint. A breakpoint is really of this type iff its ops pointer points
8032 to CATCH_FORK_BREAKPOINT_OPS. */
8034 struct fork_catchpoint : public breakpoint
8036 /* Process id of a child process whose forking triggered this
8037 catchpoint. This field is only valid immediately after this
8038 catchpoint has triggered. */
8039 ptid_t forked_inferior_pid;
8042 /* Implement the "insert" breakpoint_ops method for fork
8046 insert_catch_fork (struct bp_location *bl)
8048 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
8051 /* Implement the "remove" breakpoint_ops method for fork
8055 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
8057 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
8060 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8064 breakpoint_hit_catch_fork (const struct bp_location *bl,
8065 struct address_space *aspace, CORE_ADDR bp_addr,
8066 const struct target_waitstatus *ws)
8068 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8070 if (ws->kind != TARGET_WAITKIND_FORKED)
8073 c->forked_inferior_pid = ws->value.related_pid;
8077 /* Implement the "print_it" breakpoint_ops method for fork
8080 static enum print_stop_action
8081 print_it_catch_fork (bpstat bs)
8083 struct ui_out *uiout = current_uiout;
8084 struct breakpoint *b = bs->breakpoint_at;
8085 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
8087 annotate_catchpoint (b->number);
8088 maybe_print_thread_hit_breakpoint (uiout);
8089 if (b->disposition == disp_del)
8090 uiout->text ("Temporary catchpoint ");
8092 uiout->text ("Catchpoint ");
8093 if (uiout->is_mi_like_p ())
8095 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK));
8096 uiout->field_string ("disp", bpdisp_text (b->disposition));
8098 uiout->field_int ("bkptno", b->number);
8099 uiout->text (" (forked process ");
8100 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
8101 uiout->text ("), ");
8102 return PRINT_SRC_AND_LOC;
8105 /* Implement the "print_one" breakpoint_ops method for fork
8109 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8111 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8112 struct value_print_options opts;
8113 struct ui_out *uiout = current_uiout;
8115 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 uiout->field_skip ("addr");
8123 uiout->text ("fork");
8124 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8126 uiout->text (", process ");
8127 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
8131 if (uiout->is_mi_like_p ())
8132 uiout->field_string ("catch-type", "fork");
8135 /* Implement the "print_mention" breakpoint_ops method for fork
8139 print_mention_catch_fork (struct breakpoint *b)
8141 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8144 /* Implement the "print_recreate" breakpoint_ops method for fork
8148 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8150 fprintf_unfiltered (fp, "catch fork");
8151 print_recreate_thread (b, fp);
8154 /* The breakpoint_ops structure to be used in fork catchpoints. */
8156 static struct breakpoint_ops catch_fork_breakpoint_ops;
8158 /* Implement the "insert" breakpoint_ops method for vfork
8162 insert_catch_vfork (struct bp_location *bl)
8164 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8167 /* Implement the "remove" breakpoint_ops method for vfork
8171 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
8173 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8176 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8180 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8181 struct address_space *aspace, CORE_ADDR bp_addr,
8182 const struct target_waitstatus *ws)
8184 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8186 if (ws->kind != TARGET_WAITKIND_VFORKED)
8189 c->forked_inferior_pid = ws->value.related_pid;
8193 /* Implement the "print_it" breakpoint_ops method for vfork
8196 static enum print_stop_action
8197 print_it_catch_vfork (bpstat bs)
8199 struct ui_out *uiout = current_uiout;
8200 struct breakpoint *b = bs->breakpoint_at;
8201 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8203 annotate_catchpoint (b->number);
8204 maybe_print_thread_hit_breakpoint (uiout);
8205 if (b->disposition == disp_del)
8206 uiout->text ("Temporary catchpoint ");
8208 uiout->text ("Catchpoint ");
8209 if (uiout->is_mi_like_p ())
8211 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK));
8212 uiout->field_string ("disp", bpdisp_text (b->disposition));
8214 uiout->field_int ("bkptno", b->number);
8215 uiout->text (" (vforked process ");
8216 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
8217 uiout->text ("), ");
8218 return PRINT_SRC_AND_LOC;
8221 /* Implement the "print_one" breakpoint_ops method for vfork
8225 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8227 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8228 struct value_print_options opts;
8229 struct ui_out *uiout = current_uiout;
8231 get_user_print_options (&opts);
8232 /* Field 4, the address, is omitted (which makes the columns not
8233 line up too nicely with the headers, but the effect is relatively
8235 if (opts.addressprint)
8236 uiout->field_skip ("addr");
8238 uiout->text ("vfork");
8239 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8241 uiout->text (", process ");
8242 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
8246 if (uiout->is_mi_like_p ())
8247 uiout->field_string ("catch-type", "vfork");
8250 /* Implement the "print_mention" breakpoint_ops method for vfork
8254 print_mention_catch_vfork (struct breakpoint *b)
8256 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8259 /* Implement the "print_recreate" breakpoint_ops method for vfork
8263 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8265 fprintf_unfiltered (fp, "catch vfork");
8266 print_recreate_thread (b, fp);
8269 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8271 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8273 /* An instance of this type is used to represent an solib catchpoint.
8274 A breakpoint is really of this type iff its ops pointer points to
8275 CATCH_SOLIB_BREAKPOINT_OPS. */
8277 struct solib_catchpoint : public breakpoint
8279 ~solib_catchpoint () override;
8281 /* True for "catch load", false for "catch unload". */
8282 unsigned char is_load;
8284 /* Regular expression to match, if any. COMPILED is only valid when
8285 REGEX is non-NULL. */
8287 std::unique_ptr<compiled_regex> compiled;
8290 solib_catchpoint::~solib_catchpoint ()
8292 xfree (this->regex);
8296 insert_catch_solib (struct bp_location *ignore)
8302 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
8308 breakpoint_hit_catch_solib (const struct bp_location *bl,
8309 struct address_space *aspace,
8311 const struct target_waitstatus *ws)
8313 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8314 struct breakpoint *other;
8316 if (ws->kind == TARGET_WAITKIND_LOADED)
8319 ALL_BREAKPOINTS (other)
8321 struct bp_location *other_bl;
8323 if (other == bl->owner)
8326 if (other->type != bp_shlib_event)
8329 if (self->pspace != NULL && other->pspace != self->pspace)
8332 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8334 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8343 check_status_catch_solib (struct bpstats *bs)
8345 struct solib_catchpoint *self
8346 = (struct solib_catchpoint *) bs->breakpoint_at;
8351 struct so_list *iter;
8354 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8359 || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0)
8368 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8373 || self->compiled->exec (iter, 0, NULL, 0) == 0)
8379 bs->print_it = print_it_noop;
8382 static enum print_stop_action
8383 print_it_catch_solib (bpstat bs)
8385 struct breakpoint *b = bs->breakpoint_at;
8386 struct ui_out *uiout = current_uiout;
8388 annotate_catchpoint (b->number);
8389 maybe_print_thread_hit_breakpoint (uiout);
8390 if (b->disposition == disp_del)
8391 uiout->text ("Temporary catchpoint ");
8393 uiout->text ("Catchpoint ");
8394 uiout->field_int ("bkptno", b->number);
8396 if (uiout->is_mi_like_p ())
8397 uiout->field_string ("disp", bpdisp_text (b->disposition));
8398 print_solib_event (1);
8399 return PRINT_SRC_AND_LOC;
8403 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8405 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8406 struct value_print_options opts;
8407 struct ui_out *uiout = current_uiout;
8410 get_user_print_options (&opts);
8411 /* Field 4, the address, is omitted (which makes the columns not
8412 line up too nicely with the headers, but the effect is relatively
8414 if (opts.addressprint)
8417 uiout->field_skip ("addr");
8424 msg = xstrprintf (_("load of library matching %s"), self->regex);
8426 msg = xstrdup (_("load of library"));
8431 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8433 msg = xstrdup (_("unload of library"));
8435 uiout->field_string ("what", msg);
8438 if (uiout->is_mi_like_p ())
8439 uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
8443 print_mention_catch_solib (struct breakpoint *b)
8445 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8447 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8448 self->is_load ? "load" : "unload");
8452 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8454 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8456 fprintf_unfiltered (fp, "%s %s",
8457 b->disposition == disp_del ? "tcatch" : "catch",
8458 self->is_load ? "load" : "unload");
8460 fprintf_unfiltered (fp, " %s", self->regex);
8461 fprintf_unfiltered (fp, "\n");
8464 static struct breakpoint_ops catch_solib_breakpoint_ops;
8466 /* Shared helper function (MI and CLI) for creating and installing
8467 a shared object event catchpoint. If IS_LOAD is non-zero then
8468 the events to be caught are load events, otherwise they are
8469 unload events. If IS_TEMP is non-zero the catchpoint is a
8470 temporary one. If ENABLED is non-zero the catchpoint is
8471 created in an enabled state. */
8474 add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
8476 struct solib_catchpoint *c;
8477 struct gdbarch *gdbarch = get_current_arch ();
8478 struct cleanup *cleanup;
8482 arg = skip_spaces_const (arg);
8484 c = new solib_catchpoint ();
8485 cleanup = make_cleanup (xfree, c);
8489 c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
8490 _("Invalid regexp")));
8491 c->regex = xstrdup (arg);
8494 c->is_load = is_load;
8495 init_catchpoint (c, gdbarch, is_temp, NULL,
8496 &catch_solib_breakpoint_ops);
8498 c->enable_state = enabled ? bp_enabled : bp_disabled;
8500 discard_cleanups (cleanup);
8501 install_breakpoint (0, c, 1);
8504 /* A helper function that does all the work for "catch load" and
8508 catch_load_or_unload (char *arg, int from_tty, int is_load,
8509 struct cmd_list_element *command)
8512 const int enabled = 1;
8514 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8516 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8520 catch_load_command_1 (char *arg, int from_tty,
8521 struct cmd_list_element *command)
8523 catch_load_or_unload (arg, from_tty, 1, command);
8527 catch_unload_command_1 (char *arg, int from_tty,
8528 struct cmd_list_element *command)
8530 catch_load_or_unload (arg, from_tty, 0, command);
8533 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8534 is non-zero, then make the breakpoint temporary. If COND_STRING is
8535 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8536 the breakpoint_ops structure associated to the catchpoint. */
8539 init_catchpoint (struct breakpoint *b,
8540 struct gdbarch *gdbarch, int tempflag,
8541 const char *cond_string,
8542 const struct breakpoint_ops *ops)
8544 struct symtab_and_line sal;
8547 sal.pspace = current_program_space;
8549 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8551 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8552 b->disposition = tempflag ? disp_del : disp_donttouch;
8556 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8558 add_to_breakpoint_chain (b);
8559 set_breakpoint_number (internal, b);
8560 if (is_tracepoint (b))
8561 set_tracepoint_count (breakpoint_count);
8564 observer_notify_breakpoint_created (b);
8567 update_global_location_list (UGLL_MAY_INSERT);
8571 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8572 int tempflag, const char *cond_string,
8573 const struct breakpoint_ops *ops)
8575 struct fork_catchpoint *c = new fork_catchpoint ();
8577 init_catchpoint (c, gdbarch, tempflag, cond_string, ops);
8579 c->forked_inferior_pid = null_ptid;
8581 install_breakpoint (0, c, 1);
8584 /* Exec catchpoints. */
8586 /* An instance of this type is used to represent an exec catchpoint.
8587 A breakpoint is really of this type iff its ops pointer points to
8588 CATCH_EXEC_BREAKPOINT_OPS. */
8590 struct exec_catchpoint : public breakpoint
8592 ~exec_catchpoint () override;
8594 /* Filename of a program whose exec triggered this catchpoint.
8595 This field is only valid immediately after this catchpoint has
8597 char *exec_pathname;
8600 /* Exec catchpoint destructor. */
8602 exec_catchpoint::~exec_catchpoint ()
8604 xfree (this->exec_pathname);
8608 insert_catch_exec (struct bp_location *bl)
8610 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8614 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8616 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8620 breakpoint_hit_catch_exec (const struct bp_location *bl,
8621 struct address_space *aspace, CORE_ADDR bp_addr,
8622 const struct target_waitstatus *ws)
8624 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8626 if (ws->kind != TARGET_WAITKIND_EXECD)
8629 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8633 static enum print_stop_action
8634 print_it_catch_exec (bpstat bs)
8636 struct ui_out *uiout = current_uiout;
8637 struct breakpoint *b = bs->breakpoint_at;
8638 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8640 annotate_catchpoint (b->number);
8641 maybe_print_thread_hit_breakpoint (uiout);
8642 if (b->disposition == disp_del)
8643 uiout->text ("Temporary catchpoint ");
8645 uiout->text ("Catchpoint ");
8646 if (uiout->is_mi_like_p ())
8648 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
8649 uiout->field_string ("disp", bpdisp_text (b->disposition));
8651 uiout->field_int ("bkptno", b->number);
8652 uiout->text (" (exec'd ");
8653 uiout->field_string ("new-exec", c->exec_pathname);
8654 uiout->text ("), ");
8656 return PRINT_SRC_AND_LOC;
8660 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8662 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8663 struct value_print_options opts;
8664 struct ui_out *uiout = current_uiout;
8666 get_user_print_options (&opts);
8668 /* Field 4, the address, is omitted (which makes the columns
8669 not line up too nicely with the headers, but the effect
8670 is relatively readable). */
8671 if (opts.addressprint)
8672 uiout->field_skip ("addr");
8674 uiout->text ("exec");
8675 if (c->exec_pathname != NULL)
8677 uiout->text (", program \"");
8678 uiout->field_string ("what", c->exec_pathname);
8679 uiout->text ("\" ");
8682 if (uiout->is_mi_like_p ())
8683 uiout->field_string ("catch-type", "exec");
8687 print_mention_catch_exec (struct breakpoint *b)
8689 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8692 /* Implement the "print_recreate" breakpoint_ops method for exec
8696 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8698 fprintf_unfiltered (fp, "catch exec");
8699 print_recreate_thread (b, fp);
8702 static struct breakpoint_ops catch_exec_breakpoint_ops;
8705 hw_breakpoint_used_count (void)
8708 struct breakpoint *b;
8709 struct bp_location *bl;
8713 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8714 for (bl = b->loc; bl; bl = bl->next)
8716 /* Special types of hardware breakpoints may use more than
8718 i += b->ops->resources_needed (bl);
8725 /* Returns the resources B would use if it were a hardware
8729 hw_watchpoint_use_count (struct breakpoint *b)
8732 struct bp_location *bl;
8734 if (!breakpoint_enabled (b))
8737 for (bl = b->loc; bl; bl = bl->next)
8739 /* Special types of hardware watchpoints may use more than
8741 i += b->ops->resources_needed (bl);
8747 /* Returns the sum the used resources of all hardware watchpoints of
8748 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8749 the sum of the used resources of all hardware watchpoints of other
8750 types _not_ TYPE. */
8753 hw_watchpoint_used_count_others (struct breakpoint *except,
8754 enum bptype type, int *other_type_used)
8757 struct breakpoint *b;
8759 *other_type_used = 0;
8764 if (!breakpoint_enabled (b))
8767 if (b->type == type)
8768 i += hw_watchpoint_use_count (b);
8769 else if (is_hardware_watchpoint (b))
8770 *other_type_used = 1;
8777 disable_watchpoints_before_interactive_call_start (void)
8779 struct breakpoint *b;
8783 if (is_watchpoint (b) && breakpoint_enabled (b))
8785 b->enable_state = bp_call_disabled;
8786 update_global_location_list (UGLL_DONT_INSERT);
8792 enable_watchpoints_after_interactive_call_stop (void)
8794 struct breakpoint *b;
8798 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8800 b->enable_state = bp_enabled;
8801 update_global_location_list (UGLL_MAY_INSERT);
8807 disable_breakpoints_before_startup (void)
8809 current_program_space->executing_startup = 1;
8810 update_global_location_list (UGLL_DONT_INSERT);
8814 enable_breakpoints_after_startup (void)
8816 current_program_space->executing_startup = 0;
8817 breakpoint_re_set ();
8820 /* Create a new single-step breakpoint for thread THREAD, with no
8823 static struct breakpoint *
8824 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8826 struct breakpoint *b = new breakpoint ();
8828 init_raw_breakpoint_without_location (b, gdbarch, bp_single_step,
8829 &momentary_breakpoint_ops);
8831 b->disposition = disp_donttouch;
8832 b->frame_id = null_frame_id;
8835 gdb_assert (b->thread != 0);
8837 add_to_breakpoint_chain (b);
8842 /* Set a momentary breakpoint of type TYPE at address specified by
8843 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8847 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8848 struct frame_id frame_id, enum bptype type)
8850 struct breakpoint *b;
8852 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8854 gdb_assert (!frame_id_artificial_p (frame_id));
8856 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8857 b->enable_state = bp_enabled;
8858 b->disposition = disp_donttouch;
8859 b->frame_id = frame_id;
8861 /* If we're debugging a multi-threaded program, then we want
8862 momentary breakpoints to be active in only a single thread of
8864 if (in_thread_list (inferior_ptid))
8865 b->thread = ptid_to_global_thread_id (inferior_ptid);
8867 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8872 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8873 The new breakpoint will have type TYPE, use OPS as its
8874 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8876 static struct breakpoint *
8877 momentary_breakpoint_from_master (struct breakpoint *orig,
8879 const struct breakpoint_ops *ops,
8882 struct breakpoint *copy;
8884 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8885 copy->loc = allocate_bp_location (copy);
8886 set_breakpoint_location_function (copy->loc, 1);
8888 copy->loc->gdbarch = orig->loc->gdbarch;
8889 copy->loc->requested_address = orig->loc->requested_address;
8890 copy->loc->address = orig->loc->address;
8891 copy->loc->section = orig->loc->section;
8892 copy->loc->pspace = orig->loc->pspace;
8893 copy->loc->probe = orig->loc->probe;
8894 copy->loc->line_number = orig->loc->line_number;
8895 copy->loc->symtab = orig->loc->symtab;
8896 copy->loc->enabled = loc_enabled;
8897 copy->frame_id = orig->frame_id;
8898 copy->thread = orig->thread;
8899 copy->pspace = orig->pspace;
8901 copy->enable_state = bp_enabled;
8902 copy->disposition = disp_donttouch;
8903 copy->number = internal_breakpoint_number--;
8905 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8909 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8913 clone_momentary_breakpoint (struct breakpoint *orig)
8915 /* If there's nothing to clone, then return nothing. */
8919 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8923 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8926 struct symtab_and_line sal;
8928 sal = find_pc_line (pc, 0);
8930 sal.section = find_pc_overlay (pc);
8931 sal.explicit_pc = 1;
8933 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8937 /* Tell the user we have just set a breakpoint B. */
8940 mention (struct breakpoint *b)
8942 b->ops->print_mention (b);
8943 if (current_uiout->is_mi_like_p ())
8945 printf_filtered ("\n");
8949 static int bp_loc_is_permanent (struct bp_location *loc);
8951 static struct bp_location *
8952 add_location_to_breakpoint (struct breakpoint *b,
8953 const struct symtab_and_line *sal)
8955 struct bp_location *loc, **tmp;
8956 CORE_ADDR adjusted_address;
8957 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8959 if (loc_gdbarch == NULL)
8960 loc_gdbarch = b->gdbarch;
8962 /* Adjust the breakpoint's address prior to allocating a location.
8963 Once we call allocate_bp_location(), that mostly uninitialized
8964 location will be placed on the location chain. Adjustment of the
8965 breakpoint may cause target_read_memory() to be called and we do
8966 not want its scan of the location chain to find a breakpoint and
8967 location that's only been partially initialized. */
8968 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8971 /* Sort the locations by their ADDRESS. */
8972 loc = allocate_bp_location (b);
8973 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8974 tmp = &((*tmp)->next))
8979 loc->requested_address = sal->pc;
8980 loc->address = adjusted_address;
8981 loc->pspace = sal->pspace;
8982 loc->probe.probe = sal->probe;
8983 loc->probe.objfile = sal->objfile;
8984 gdb_assert (loc->pspace != NULL);
8985 loc->section = sal->section;
8986 loc->gdbarch = loc_gdbarch;
8987 loc->line_number = sal->line;
8988 loc->symtab = sal->symtab;
8990 set_breakpoint_location_function (loc,
8991 sal->explicit_pc || sal->explicit_line);
8993 /* While by definition, permanent breakpoints are already present in the
8994 code, we don't mark the location as inserted. Normally one would expect
8995 that GDB could rely on that breakpoint instruction to stop the program,
8996 thus removing the need to insert its own breakpoint, except that executing
8997 the breakpoint instruction can kill the target instead of reporting a
8998 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8999 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9000 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9001 breakpoint be inserted normally results in QEMU knowing about the GDB
9002 breakpoint, and thus trap before the breakpoint instruction is executed.
9003 (If GDB later needs to continue execution past the permanent breakpoint,
9004 it manually increments the PC, thus avoiding executing the breakpoint
9006 if (bp_loc_is_permanent (loc))
9013 /* See breakpoint.h. */
9016 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
9020 const gdb_byte *bpoint;
9021 gdb_byte *target_mem;
9022 struct cleanup *cleanup;
9026 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
9028 /* Software breakpoints unsupported? */
9032 target_mem = (gdb_byte *) alloca (len);
9034 /* Enable the automatic memory restoration from breakpoints while
9035 we read the memory. Otherwise we could say about our temporary
9036 breakpoints they are permanent. */
9037 cleanup = make_show_memory_breakpoints_cleanup (0);
9039 if (target_read_memory (address, target_mem, len) == 0
9040 && memcmp (target_mem, bpoint, len) == 0)
9043 do_cleanups (cleanup);
9048 /* Return 1 if LOC is pointing to a permanent breakpoint,
9049 return 0 otherwise. */
9052 bp_loc_is_permanent (struct bp_location *loc)
9054 gdb_assert (loc != NULL);
9056 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9057 attempt to read from the addresses the locations of these breakpoint types
9058 point to. program_breakpoint_here_p, below, will attempt to read
9060 if (!breakpoint_address_is_meaningful (loc->owner))
9063 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9064 switch_to_program_space_and_thread (loc->pspace);
9065 return program_breakpoint_here_p (loc->gdbarch, loc->address);
9068 /* Build a command list for the dprintf corresponding to the current
9069 settings of the dprintf style options. */
9072 update_dprintf_command_list (struct breakpoint *b)
9074 char *dprintf_args = b->extra_string;
9075 char *printf_line = NULL;
9080 dprintf_args = skip_spaces (dprintf_args);
9082 /* Allow a comma, as it may have terminated a location, but don't
9084 if (*dprintf_args == ',')
9086 dprintf_args = skip_spaces (dprintf_args);
9088 if (*dprintf_args != '"')
9089 error (_("Bad format string, missing '\"'."));
9091 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9092 printf_line = xstrprintf ("printf %s", dprintf_args);
9093 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9095 if (!dprintf_function)
9096 error (_("No function supplied for dprintf call"));
9098 if (dprintf_channel && strlen (dprintf_channel) > 0)
9099 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9104 printf_line = xstrprintf ("call (void) %s (%s)",
9108 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9110 if (target_can_run_breakpoint_commands ())
9111 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9114 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9115 printf_line = xstrprintf ("printf %s", dprintf_args);
9119 internal_error (__FILE__, __LINE__,
9120 _("Invalid dprintf style."));
9122 gdb_assert (printf_line != NULL);
9123 /* Manufacture a printf sequence. */
9125 struct command_line *printf_cmd_line = XNEW (struct command_line);
9127 printf_cmd_line->control_type = simple_control;
9128 printf_cmd_line->body_count = 0;
9129 printf_cmd_line->body_list = NULL;
9130 printf_cmd_line->next = NULL;
9131 printf_cmd_line->line = printf_line;
9133 breakpoint_set_commands (b, command_line_up (printf_cmd_line));
9137 /* Update all dprintf commands, making their command lists reflect
9138 current style settings. */
9141 update_dprintf_commands (char *args, int from_tty,
9142 struct cmd_list_element *c)
9144 struct breakpoint *b;
9148 if (b->type == bp_dprintf)
9149 update_dprintf_command_list (b);
9153 /* Create a breakpoint with SAL as location. Use LOCATION
9154 as a description of the location, and COND_STRING
9155 as condition expression. If LOCATION is NULL then create an
9156 "address location" from the address in the SAL. */
9159 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9160 struct symtabs_and_lines sals,
9161 event_location_up &&location,
9162 gdb::unique_xmalloc_ptr<char> filter,
9163 gdb::unique_xmalloc_ptr<char> cond_string,
9164 gdb::unique_xmalloc_ptr<char> extra_string,
9165 enum bptype type, enum bpdisp disposition,
9166 int thread, int task, int ignore_count,
9167 const struct breakpoint_ops *ops, int from_tty,
9168 int enabled, int internal, unsigned flags,
9169 int display_canonical)
9173 if (type == bp_hardware_breakpoint)
9175 int target_resources_ok;
9177 i = hw_breakpoint_used_count ();
9178 target_resources_ok =
9179 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9181 if (target_resources_ok == 0)
9182 error (_("No hardware breakpoint support in the target."));
9183 else if (target_resources_ok < 0)
9184 error (_("Hardware breakpoints used exceeds limit."));
9187 gdb_assert (sals.nelts > 0);
9189 for (i = 0; i < sals.nelts; ++i)
9191 struct symtab_and_line sal = sals.sals[i];
9192 struct bp_location *loc;
9196 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9198 loc_gdbarch = gdbarch;
9200 describe_other_breakpoints (loc_gdbarch,
9201 sal.pspace, sal.pc, sal.section, thread);
9206 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9210 b->cond_string = cond_string.release ();
9211 b->extra_string = extra_string.release ();
9212 b->ignore_count = ignore_count;
9213 b->enable_state = enabled ? bp_enabled : bp_disabled;
9214 b->disposition = disposition;
9216 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9217 b->loc->inserted = 1;
9219 if (type == bp_static_tracepoint)
9221 struct tracepoint *t = (struct tracepoint *) b;
9222 struct static_tracepoint_marker marker;
9224 if (strace_marker_p (b))
9226 /* We already know the marker exists, otherwise, we
9227 wouldn't see a sal for it. */
9229 = &event_location_to_string (b->location.get ())[3];
9233 p = skip_spaces_const (p);
9235 endp = skip_to_space_const (p);
9237 marker_str = savestring (p, endp - p);
9238 t->static_trace_marker_id = marker_str;
9240 printf_filtered (_("Probed static tracepoint "
9242 t->static_trace_marker_id);
9244 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9246 t->static_trace_marker_id = xstrdup (marker.str_id);
9247 release_static_tracepoint_marker (&marker);
9249 printf_filtered (_("Probed static tracepoint "
9251 t->static_trace_marker_id);
9254 warning (_("Couldn't determine the static "
9255 "tracepoint marker to probe"));
9262 loc = add_location_to_breakpoint (b, &sal);
9263 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9269 const char *arg = b->cond_string;
9271 loc->cond = parse_exp_1 (&arg, loc->address,
9272 block_for_pc (loc->address), 0);
9274 error (_("Garbage '%s' follows condition"), arg);
9277 /* Dynamic printf requires and uses additional arguments on the
9278 command line, otherwise it's an error. */
9279 if (type == bp_dprintf)
9281 if (b->extra_string)
9282 update_dprintf_command_list (b);
9284 error (_("Format string required"));
9286 else if (b->extra_string)
9287 error (_("Garbage '%s' at end of command"), b->extra_string);
9290 b->display_canonical = display_canonical;
9291 if (location != NULL)
9292 b->location = std::move (location);
9294 b->location = new_address_location (b->loc->address, NULL, 0);
9295 b->filter = filter.release ();
9299 create_breakpoint_sal (struct gdbarch *gdbarch,
9300 struct symtabs_and_lines sals,
9301 event_location_up &&location,
9302 gdb::unique_xmalloc_ptr<char> filter,
9303 gdb::unique_xmalloc_ptr<char> cond_string,
9304 gdb::unique_xmalloc_ptr<char> extra_string,
9305 enum bptype type, enum bpdisp disposition,
9306 int thread, int task, int ignore_count,
9307 const struct breakpoint_ops *ops, int from_tty,
9308 int enabled, int internal, unsigned flags,
9309 int display_canonical)
9311 std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type);
9313 init_breakpoint_sal (b.get (), gdbarch,
9314 sals, std::move (location),
9316 std::move (cond_string),
9317 std::move (extra_string),
9319 thread, task, ignore_count,
9321 enabled, internal, flags,
9324 install_breakpoint (internal, b.release (), 0);
9327 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9328 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9329 value. COND_STRING, if not NULL, specified the condition to be
9330 used for all breakpoints. Essentially the only case where
9331 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9332 function. In that case, it's still not possible to specify
9333 separate conditions for different overloaded functions, so
9334 we take just a single condition string.
9336 NOTE: If the function succeeds, the caller is expected to cleanup
9337 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9338 array contents). If the function fails (error() is called), the
9339 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9340 COND and SALS arrays and each of those arrays contents. */
9343 create_breakpoints_sal (struct gdbarch *gdbarch,
9344 struct linespec_result *canonical,
9345 gdb::unique_xmalloc_ptr<char> cond_string,
9346 gdb::unique_xmalloc_ptr<char> extra_string,
9347 enum bptype type, enum bpdisp disposition,
9348 int thread, int task, int ignore_count,
9349 const struct breakpoint_ops *ops, int from_tty,
9350 int enabled, int internal, unsigned flags)
9353 struct linespec_sals *lsal;
9355 if (canonical->pre_expanded)
9356 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9358 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9360 /* Note that 'location' can be NULL in the case of a plain
9361 'break', without arguments. */
9362 event_location_up location
9363 = (canonical->location != NULL
9364 ? copy_event_location (canonical->location.get ()) : NULL);
9365 gdb::unique_xmalloc_ptr<char> filter_string
9366 (lsal->canonical != NULL ? xstrdup (lsal->canonical) : NULL);
9368 create_breakpoint_sal (gdbarch, lsal->sals,
9369 std::move (location),
9370 std::move (filter_string),
9371 std::move (cond_string),
9372 std::move (extra_string),
9374 thread, task, ignore_count, ops,
9375 from_tty, enabled, internal, flags,
9376 canonical->special_display);
9380 /* Parse LOCATION which is assumed to be a SAL specification possibly
9381 followed by conditionals. On return, SALS contains an array of SAL
9382 addresses found. LOCATION points to the end of the SAL (for
9383 linespec locations).
9385 The array and the line spec strings are allocated on the heap, it is
9386 the caller's responsibility to free them. */
9389 parse_breakpoint_sals (const struct event_location *location,
9390 struct linespec_result *canonical)
9392 struct symtab_and_line cursal;
9394 if (event_location_type (location) == LINESPEC_LOCATION)
9396 const char *address = get_linespec_location (location);
9398 if (address == NULL)
9400 /* The last displayed codepoint, if it's valid, is our default
9401 breakpoint address. */
9402 if (last_displayed_sal_is_valid ())
9404 struct linespec_sals lsal;
9405 struct symtab_and_line sal;
9408 init_sal (&sal); /* Initialize to zeroes. */
9409 lsal.sals.sals = XNEW (struct symtab_and_line);
9411 /* Set sal's pspace, pc, symtab, and line to the values
9412 corresponding to the last call to print_frame_info.
9413 Be sure to reinitialize LINE with NOTCURRENT == 0
9414 as the breakpoint line number is inappropriate otherwise.
9415 find_pc_line would adjust PC, re-set it back. */
9416 get_last_displayed_sal (&sal);
9418 sal = find_pc_line (pc, 0);
9420 /* "break" without arguments is equivalent to "break *PC"
9421 where PC is the last displayed codepoint's address. So
9422 make sure to set sal.explicit_pc to prevent GDB from
9423 trying to expand the list of sals to include all other
9424 instances with the same symtab and line. */
9426 sal.explicit_pc = 1;
9428 lsal.sals.sals[0] = sal;
9429 lsal.sals.nelts = 1;
9430 lsal.canonical = NULL;
9432 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9436 error (_("No default breakpoint address now."));
9440 /* Force almost all breakpoints to be in terms of the
9441 current_source_symtab (which is decode_line_1's default).
9442 This should produce the results we want almost all of the
9443 time while leaving default_breakpoint_* alone.
9445 ObjC: However, don't match an Objective-C method name which
9446 may have a '+' or '-' succeeded by a '['. */
9447 cursal = get_current_source_symtab_and_line ();
9448 if (last_displayed_sal_is_valid ())
9450 const char *address = NULL;
9452 if (event_location_type (location) == LINESPEC_LOCATION)
9453 address = get_linespec_location (location);
9457 && strchr ("+-", address[0]) != NULL
9458 && address[1] != '['))
9460 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9461 get_last_displayed_symtab (),
9462 get_last_displayed_line (),
9463 canonical, NULL, NULL);
9468 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9469 cursal.symtab, cursal.line, canonical, NULL, NULL);
9473 /* Convert each SAL into a real PC. Verify that the PC can be
9474 inserted as a breakpoint. If it can't throw an error. */
9477 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9481 for (i = 0; i < sals->nelts; i++)
9482 resolve_sal_pc (&sals->sals[i]);
9485 /* Fast tracepoints may have restrictions on valid locations. For
9486 instance, a fast tracepoint using a jump instead of a trap will
9487 likely have to overwrite more bytes than a trap would, and so can
9488 only be placed where the instruction is longer than the jump, or a
9489 multi-instruction sequence does not have a jump into the middle of
9493 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9494 struct symtabs_and_lines *sals)
9497 struct symtab_and_line *sal;
9499 struct cleanup *old_chain;
9501 for (i = 0; i < sals->nelts; i++)
9503 struct gdbarch *sarch;
9505 sal = &sals->sals[i];
9507 sarch = get_sal_arch (*sal);
9508 /* We fall back to GDBARCH if there is no architecture
9509 associated with SAL. */
9512 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg);
9513 old_chain = make_cleanup (xfree, msg);
9516 error (_("May not have a fast tracepoint at %s%s"),
9517 paddress (sarch, sal->pc), (msg ? msg : ""));
9519 do_cleanups (old_chain);
9523 /* Given TOK, a string specification of condition and thread, as
9524 accepted by the 'break' command, extract the condition
9525 string and thread number and set *COND_STRING and *THREAD.
9526 PC identifies the context at which the condition should be parsed.
9527 If no condition is found, *COND_STRING is set to NULL.
9528 If no thread is found, *THREAD is set to -1. */
9531 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9532 char **cond_string, int *thread, int *task,
9535 *cond_string = NULL;
9542 const char *end_tok;
9544 const char *cond_start = NULL;
9545 const char *cond_end = NULL;
9547 tok = skip_spaces_const (tok);
9549 if ((*tok == '"' || *tok == ',') && rest)
9551 *rest = savestring (tok, strlen (tok));
9555 end_tok = skip_to_space_const (tok);
9557 toklen = end_tok - tok;
9559 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9561 tok = cond_start = end_tok + 1;
9562 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9564 *cond_string = savestring (cond_start, cond_end - cond_start);
9566 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9569 struct thread_info *thr;
9572 thr = parse_thread_id (tok, &tmptok);
9574 error (_("Junk after thread keyword."));
9575 *thread = thr->global_num;
9578 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9583 *task = strtol (tok, &tmptok, 0);
9585 error (_("Junk after task keyword."));
9586 if (!valid_task_id (*task))
9587 error (_("Unknown task %d."), *task);
9592 *rest = savestring (tok, strlen (tok));
9596 error (_("Junk at end of arguments."));
9600 /* Decode a static tracepoint marker spec. */
9602 static struct symtabs_and_lines
9603 decode_static_tracepoint_spec (const char **arg_p)
9605 VEC(static_tracepoint_marker_p) *markers = NULL;
9606 struct symtabs_and_lines sals;
9607 struct cleanup *old_chain;
9608 const char *p = &(*arg_p)[3];
9613 p = skip_spaces_const (p);
9615 endp = skip_to_space_const (p);
9617 marker_str = savestring (p, endp - p);
9618 old_chain = make_cleanup (xfree, marker_str);
9620 markers = target_static_tracepoint_markers_by_strid (marker_str);
9621 if (VEC_empty(static_tracepoint_marker_p, markers))
9622 error (_("No known static tracepoint marker named %s"), marker_str);
9624 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9625 sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
9627 for (i = 0; i < sals.nelts; i++)
9629 struct static_tracepoint_marker *marker;
9631 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9633 init_sal (&sals.sals[i]);
9635 sals.sals[i] = find_pc_line (marker->address, 0);
9636 sals.sals[i].pc = marker->address;
9638 release_static_tracepoint_marker (marker);
9641 do_cleanups (old_chain);
9647 /* See breakpoint.h. */
9650 create_breakpoint (struct gdbarch *gdbarch,
9651 const struct event_location *location,
9652 const char *cond_string,
9653 int thread, const char *extra_string,
9655 int tempflag, enum bptype type_wanted,
9657 enum auto_boolean pending_break_support,
9658 const struct breakpoint_ops *ops,
9659 int from_tty, int enabled, int internal,
9662 struct linespec_result canonical;
9663 struct cleanup *bkpt_chain = NULL;
9666 int prev_bkpt_count = breakpoint_count;
9668 gdb_assert (ops != NULL);
9670 /* If extra_string isn't useful, set it to NULL. */
9671 if (extra_string != NULL && *extra_string == '\0')
9672 extra_string = NULL;
9676 ops->create_sals_from_location (location, &canonical, type_wanted);
9678 CATCH (e, RETURN_MASK_ERROR)
9680 /* If caller is interested in rc value from parse, set
9682 if (e.error == NOT_FOUND_ERROR)
9684 /* If pending breakpoint support is turned off, throw
9687 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9688 throw_exception (e);
9690 exception_print (gdb_stderr, e);
9692 /* If pending breakpoint support is auto query and the user
9693 selects no, then simply return the error code. */
9694 if (pending_break_support == AUTO_BOOLEAN_AUTO
9695 && !nquery (_("Make %s pending on future shared library load? "),
9696 bptype_string (type_wanted)))
9699 /* At this point, either the user was queried about setting
9700 a pending breakpoint and selected yes, or pending
9701 breakpoint behavior is on and thus a pending breakpoint
9702 is defaulted on behalf of the user. */
9706 throw_exception (e);
9710 if (!pending && VEC_empty (linespec_sals, canonical.sals))
9713 /* ----------------------------- SNIP -----------------------------
9714 Anything added to the cleanup chain beyond this point is assumed
9715 to be part of a breakpoint. If the breakpoint create succeeds
9716 then the memory is not reclaimed. */
9717 bkpt_chain = make_cleanup (null_cleanup, 0);
9719 /* Resolve all line numbers to PC's and verify that the addresses
9720 are ok for the target. */
9724 struct linespec_sals *iter;
9726 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9727 breakpoint_sals_to_pc (&iter->sals);
9730 /* Fast tracepoints may have additional restrictions on location. */
9731 if (!pending && type_wanted == bp_fast_tracepoint)
9734 struct linespec_sals *iter;
9736 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9737 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9740 /* Verify that condition can be parsed, before setting any
9741 breakpoints. Allocate a separate condition expression for each
9745 gdb::unique_xmalloc_ptr<char> cond_string_copy;
9746 gdb::unique_xmalloc_ptr<char> extra_string_copy;
9752 struct linespec_sals *lsal;
9754 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9756 /* Here we only parse 'arg' to separate condition
9757 from thread number, so parsing in context of first
9758 sal is OK. When setting the breakpoint we'll
9759 re-parse it in context of each sal. */
9761 find_condition_and_thread (extra_string, lsal->sals.sals[0].pc,
9762 &cond, &thread, &task, &rest);
9763 cond_string_copy.reset (cond);
9764 extra_string_copy.reset (rest);
9768 if (type_wanted != bp_dprintf
9769 && extra_string != NULL && *extra_string != '\0')
9770 error (_("Garbage '%s' at end of location"), extra_string);
9772 /* Create a private copy of condition string. */
9774 cond_string_copy.reset (xstrdup (cond_string));
9775 /* Create a private copy of any extra string. */
9777 extra_string_copy.reset (xstrdup (extra_string));
9780 ops->create_breakpoints_sal (gdbarch, &canonical,
9781 std::move (cond_string_copy),
9782 std::move (extra_string_copy),
9784 tempflag ? disp_del : disp_donttouch,
9785 thread, task, ignore_count, ops,
9786 from_tty, enabled, internal, flags);
9790 std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted);
9792 init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops);
9793 b->location = copy_event_location (location);
9796 b->cond_string = NULL;
9799 /* Create a private copy of condition string. */
9800 b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL;
9804 /* Create a private copy of any extra string. */
9805 b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL;
9806 b->ignore_count = ignore_count;
9807 b->disposition = tempflag ? disp_del : disp_donttouch;
9808 b->condition_not_parsed = 1;
9809 b->enable_state = enabled ? bp_enabled : bp_disabled;
9810 if ((type_wanted != bp_breakpoint
9811 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9812 b->pspace = current_program_space;
9814 install_breakpoint (internal, b.release (), 0);
9817 if (VEC_length (linespec_sals, canonical.sals) > 1)
9819 warning (_("Multiple breakpoints were set.\nUse the "
9820 "\"delete\" command to delete unwanted breakpoints."));
9821 prev_breakpoint_count = prev_bkpt_count;
9824 /* That's it. Discard the cleanups for data inserted into the
9826 discard_cleanups (bkpt_chain);
9828 /* error call may happen here - have BKPT_CHAIN already discarded. */
9829 update_global_location_list (UGLL_MAY_INSERT);
9834 /* Set a breakpoint.
9835 ARG is a string describing breakpoint address,
9836 condition, and thread.
9837 FLAG specifies if a breakpoint is hardware on,
9838 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9842 break_command_1 (char *arg, int flag, int from_tty)
9844 int tempflag = flag & BP_TEMPFLAG;
9845 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9846 ? bp_hardware_breakpoint
9848 struct breakpoint_ops *ops;
9850 event_location_up location = string_to_event_location (&arg, current_language);
9852 /* Matching breakpoints on probes. */
9853 if (location != NULL
9854 && event_location_type (location.get ()) == PROBE_LOCATION)
9855 ops = &bkpt_probe_breakpoint_ops;
9857 ops = &bkpt_breakpoint_ops;
9859 create_breakpoint (get_current_arch (),
9861 NULL, 0, arg, 1 /* parse arg */,
9862 tempflag, type_wanted,
9863 0 /* Ignore count */,
9864 pending_break_support,
9872 /* Helper function for break_command_1 and disassemble_command. */
9875 resolve_sal_pc (struct symtab_and_line *sal)
9879 if (sal->pc == 0 && sal->symtab != NULL)
9881 if (!find_line_pc (sal->symtab, sal->line, &pc))
9882 error (_("No line %d in file \"%s\"."),
9883 sal->line, symtab_to_filename_for_display (sal->symtab));
9886 /* If this SAL corresponds to a breakpoint inserted using a line
9887 number, then skip the function prologue if necessary. */
9888 if (sal->explicit_line)
9889 skip_prologue_sal (sal);
9892 if (sal->section == 0 && sal->symtab != NULL)
9894 const struct blockvector *bv;
9895 const struct block *b;
9898 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9899 SYMTAB_COMPUNIT (sal->symtab));
9902 sym = block_linkage_function (b);
9905 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
9906 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
9911 /* It really is worthwhile to have the section, so we'll
9912 just have to look harder. This case can be executed
9913 if we have line numbers but no functions (as can
9914 happen in assembly source). */
9916 scoped_restore_current_pspace_and_thread restore_pspace_thread;
9917 switch_to_program_space_and_thread (sal->pspace);
9919 bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc);
9921 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9928 break_command (char *arg, int from_tty)
9930 break_command_1 (arg, 0, from_tty);
9934 tbreak_command (char *arg, int from_tty)
9936 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9940 hbreak_command (char *arg, int from_tty)
9942 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9946 thbreak_command (char *arg, int from_tty)
9948 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9952 stop_command (char *arg, int from_tty)
9954 printf_filtered (_("Specify the type of breakpoint to set.\n\
9955 Usage: stop in <function | address>\n\
9956 stop at <line>\n"));
9960 stopin_command (char *arg, int from_tty)
9964 if (arg == (char *) NULL)
9966 else if (*arg != '*')
9971 /* Look for a ':'. If this is a line number specification, then
9972 say it is bad, otherwise, it should be an address or
9973 function/method name. */
9974 while (*argptr && !hasColon)
9976 hasColon = (*argptr == ':');
9981 badInput = (*argptr != ':'); /* Not a class::method */
9983 badInput = isdigit (*arg); /* a simple line number */
9987 printf_filtered (_("Usage: stop in <function | address>\n"));
9989 break_command_1 (arg, 0, from_tty);
9993 stopat_command (char *arg, int from_tty)
9997 if (arg == (char *) NULL || *arg == '*') /* no line number */
10001 char *argptr = arg;
10004 /* Look for a ':'. If there is a '::' then get out, otherwise
10005 it is probably a line number. */
10006 while (*argptr && !hasColon)
10008 hasColon = (*argptr == ':');
10013 badInput = (*argptr == ':'); /* we have class::method */
10015 badInput = !isdigit (*arg); /* not a line number */
10019 printf_filtered (_("Usage: stop at <line>\n"));
10021 break_command_1 (arg, 0, from_tty);
10024 /* The dynamic printf command is mostly like a regular breakpoint, but
10025 with a prewired command list consisting of a single output command,
10026 built from extra arguments supplied on the dprintf command
10030 dprintf_command (char *arg, int from_tty)
10032 event_location_up location = string_to_event_location (&arg, current_language);
10034 /* If non-NULL, ARG should have been advanced past the location;
10035 the next character must be ','. */
10038 if (arg[0] != ',' || arg[1] == '\0')
10039 error (_("Format string required"));
10042 /* Skip the comma. */
10047 create_breakpoint (get_current_arch (),
10049 NULL, 0, arg, 1 /* parse arg */,
10051 0 /* Ignore count */,
10052 pending_break_support,
10053 &dprintf_breakpoint_ops,
10061 agent_printf_command (char *arg, int from_tty)
10063 error (_("May only run agent-printf on the target"));
10066 /* Implement the "breakpoint_hit" breakpoint_ops method for
10067 ranged breakpoints. */
10070 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10071 struct address_space *aspace,
10073 const struct target_waitstatus *ws)
10075 if (ws->kind != TARGET_WAITKIND_STOPPED
10076 || ws->value.sig != GDB_SIGNAL_TRAP)
10079 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10080 bl->length, aspace, bp_addr);
10083 /* Implement the "resources_needed" breakpoint_ops method for
10084 ranged breakpoints. */
10087 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10089 return target_ranged_break_num_registers ();
10092 /* Implement the "print_it" breakpoint_ops method for
10093 ranged breakpoints. */
10095 static enum print_stop_action
10096 print_it_ranged_breakpoint (bpstat bs)
10098 struct breakpoint *b = bs->breakpoint_at;
10099 struct bp_location *bl = b->loc;
10100 struct ui_out *uiout = current_uiout;
10102 gdb_assert (b->type == bp_hardware_breakpoint);
10104 /* Ranged breakpoints have only one location. */
10105 gdb_assert (bl && bl->next == NULL);
10107 annotate_breakpoint (b->number);
10109 maybe_print_thread_hit_breakpoint (uiout);
10111 if (b->disposition == disp_del)
10112 uiout->text ("Temporary ranged breakpoint ");
10114 uiout->text ("Ranged breakpoint ");
10115 if (uiout->is_mi_like_p ())
10117 uiout->field_string ("reason",
10118 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10119 uiout->field_string ("disp", bpdisp_text (b->disposition));
10121 uiout->field_int ("bkptno", b->number);
10122 uiout->text (", ");
10124 return PRINT_SRC_AND_LOC;
10127 /* Implement the "print_one" breakpoint_ops method for
10128 ranged breakpoints. */
10131 print_one_ranged_breakpoint (struct breakpoint *b,
10132 struct bp_location **last_loc)
10134 struct bp_location *bl = b->loc;
10135 struct value_print_options opts;
10136 struct ui_out *uiout = current_uiout;
10138 /* Ranged breakpoints have only one location. */
10139 gdb_assert (bl && bl->next == NULL);
10141 get_user_print_options (&opts);
10143 if (opts.addressprint)
10144 /* We don't print the address range here, it will be printed later
10145 by print_one_detail_ranged_breakpoint. */
10146 uiout->field_skip ("addr");
10147 annotate_field (5);
10148 print_breakpoint_location (b, bl);
10152 /* Implement the "print_one_detail" breakpoint_ops method for
10153 ranged breakpoints. */
10156 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10157 struct ui_out *uiout)
10159 CORE_ADDR address_start, address_end;
10160 struct bp_location *bl = b->loc;
10165 address_start = bl->address;
10166 address_end = address_start + bl->length - 1;
10168 uiout->text ("\taddress range: ");
10169 stb.printf ("[%s, %s]",
10170 print_core_address (bl->gdbarch, address_start),
10171 print_core_address (bl->gdbarch, address_end));
10172 uiout->field_stream ("addr", stb);
10173 uiout->text ("\n");
10176 /* Implement the "print_mention" breakpoint_ops method for
10177 ranged breakpoints. */
10180 print_mention_ranged_breakpoint (struct breakpoint *b)
10182 struct bp_location *bl = b->loc;
10183 struct ui_out *uiout = current_uiout;
10186 gdb_assert (b->type == bp_hardware_breakpoint);
10188 if (uiout->is_mi_like_p ())
10191 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10192 b->number, paddress (bl->gdbarch, bl->address),
10193 paddress (bl->gdbarch, bl->address + bl->length - 1));
10196 /* Implement the "print_recreate" breakpoint_ops method for
10197 ranged breakpoints. */
10200 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10202 fprintf_unfiltered (fp, "break-range %s, %s",
10203 event_location_to_string (b->location.get ()),
10204 event_location_to_string (b->location_range_end.get ()));
10205 print_recreate_thread (b, fp);
10208 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10210 static struct breakpoint_ops ranged_breakpoint_ops;
10212 /* Find the address where the end of the breakpoint range should be
10213 placed, given the SAL of the end of the range. This is so that if
10214 the user provides a line number, the end of the range is set to the
10215 last instruction of the given line. */
10218 find_breakpoint_range_end (struct symtab_and_line sal)
10222 /* If the user provided a PC value, use it. Otherwise,
10223 find the address of the end of the given location. */
10224 if (sal.explicit_pc)
10231 ret = find_line_pc_range (sal, &start, &end);
10233 error (_("Could not find location of the end of the range."));
10235 /* find_line_pc_range returns the start of the next line. */
10242 /* Implement the "break-range" CLI command. */
10245 break_range_command (char *arg, int from_tty)
10247 char *arg_start, *addr_string_start;
10248 struct linespec_result canonical_start, canonical_end;
10249 int bp_count, can_use_bp, length;
10251 struct breakpoint *b;
10252 struct symtab_and_line sal_start, sal_end;
10253 struct cleanup *cleanup_bkpt;
10254 struct linespec_sals *lsal_start, *lsal_end;
10256 /* We don't support software ranged breakpoints. */
10257 if (target_ranged_break_num_registers () < 0)
10258 error (_("This target does not support hardware ranged breakpoints."));
10260 bp_count = hw_breakpoint_used_count ();
10261 bp_count += target_ranged_break_num_registers ();
10262 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10264 if (can_use_bp < 0)
10265 error (_("Hardware breakpoints used exceeds limit."));
10267 arg = skip_spaces (arg);
10268 if (arg == NULL || arg[0] == '\0')
10269 error(_("No address range specified."));
10272 event_location_up start_location = string_to_event_location (&arg,
10274 parse_breakpoint_sals (start_location.get (), &canonical_start);
10277 error (_("Too few arguments."));
10278 else if (VEC_empty (linespec_sals, canonical_start.sals))
10279 error (_("Could not find location of the beginning of the range."));
10281 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10283 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10284 || lsal_start->sals.nelts != 1)
10285 error (_("Cannot create a ranged breakpoint with multiple locations."));
10287 sal_start = lsal_start->sals.sals[0];
10288 addr_string_start = savestring (arg_start, arg - arg_start);
10289 cleanup_bkpt = make_cleanup (xfree, addr_string_start);
10291 arg++; /* Skip the comma. */
10292 arg = skip_spaces (arg);
10294 /* Parse the end location. */
10298 /* We call decode_line_full directly here instead of using
10299 parse_breakpoint_sals because we need to specify the start location's
10300 symtab and line as the default symtab and line for the end of the
10301 range. This makes it possible to have ranges like "foo.c:27, +14",
10302 where +14 means 14 lines from the start location. */
10303 event_location_up end_location = string_to_event_location (&arg,
10305 decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
10306 sal_start.symtab, sal_start.line,
10307 &canonical_end, NULL, NULL);
10309 if (VEC_empty (linespec_sals, canonical_end.sals))
10310 error (_("Could not find location of the end of the range."));
10312 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10313 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10314 || lsal_end->sals.nelts != 1)
10315 error (_("Cannot create a ranged breakpoint with multiple locations."));
10317 sal_end = lsal_end->sals.sals[0];
10319 end = find_breakpoint_range_end (sal_end);
10320 if (sal_start.pc > end)
10321 error (_("Invalid address range, end precedes start."));
10323 length = end - sal_start.pc + 1;
10325 /* Length overflowed. */
10326 error (_("Address range too large."));
10327 else if (length == 1)
10329 /* This range is simple enough to be handled by
10330 the `hbreak' command. */
10331 hbreak_command (addr_string_start, 1);
10333 do_cleanups (cleanup_bkpt);
10338 /* Now set up the breakpoint. */
10339 b = set_raw_breakpoint (get_current_arch (), sal_start,
10340 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10341 set_breakpoint_count (breakpoint_count + 1);
10342 b->number = breakpoint_count;
10343 b->disposition = disp_donttouch;
10344 b->location = std::move (start_location);
10345 b->location_range_end = std::move (end_location);
10346 b->loc->length = length;
10348 do_cleanups (cleanup_bkpt);
10351 observer_notify_breakpoint_created (b);
10352 update_global_location_list (UGLL_MAY_INSERT);
10355 /* Return non-zero if EXP is verified as constant. Returned zero
10356 means EXP is variable. Also the constant detection may fail for
10357 some constant expressions and in such case still falsely return
10361 watchpoint_exp_is_const (const struct expression *exp)
10363 int i = exp->nelts;
10369 /* We are only interested in the descriptor of each element. */
10370 operator_length (exp, i, &oplenp, &argsp);
10373 switch (exp->elts[i].opcode)
10383 case BINOP_LOGICAL_AND:
10384 case BINOP_LOGICAL_OR:
10385 case BINOP_BITWISE_AND:
10386 case BINOP_BITWISE_IOR:
10387 case BINOP_BITWISE_XOR:
10389 case BINOP_NOTEQUAL:
10416 case OP_OBJC_NSSTRING:
10419 case UNOP_LOGICAL_NOT:
10420 case UNOP_COMPLEMENT:
10425 case UNOP_CAST_TYPE:
10426 case UNOP_REINTERPRET_CAST:
10427 case UNOP_DYNAMIC_CAST:
10428 /* Unary, binary and ternary operators: We have to check
10429 their operands. If they are constant, then so is the
10430 result of that operation. For instance, if A and B are
10431 determined to be constants, then so is "A + B".
10433 UNOP_IND is one exception to the rule above, because the
10434 value of *ADDR is not necessarily a constant, even when
10439 /* Check whether the associated symbol is a constant.
10441 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10442 possible that a buggy compiler could mark a variable as
10443 constant even when it is not, and TYPE_CONST would return
10444 true in this case, while SYMBOL_CLASS wouldn't.
10446 We also have to check for function symbols because they
10447 are always constant. */
10449 struct symbol *s = exp->elts[i + 2].symbol;
10451 if (SYMBOL_CLASS (s) != LOC_BLOCK
10452 && SYMBOL_CLASS (s) != LOC_CONST
10453 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10458 /* The default action is to return 0 because we are using
10459 the optimistic approach here: If we don't know something,
10460 then it is not a constant. */
10469 /* Watchpoint destructor. */
10471 watchpoint::~watchpoint ()
10473 xfree (this->exp_string);
10474 xfree (this->exp_string_reparse);
10475 value_free (this->val);
10478 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10481 re_set_watchpoint (struct breakpoint *b)
10483 struct watchpoint *w = (struct watchpoint *) b;
10485 /* Watchpoint can be either on expression using entirely global
10486 variables, or it can be on local variables.
10488 Watchpoints of the first kind are never auto-deleted, and even
10489 persist across program restarts. Since they can use variables
10490 from shared libraries, we need to reparse expression as libraries
10491 are loaded and unloaded.
10493 Watchpoints on local variables can also change meaning as result
10494 of solib event. For example, if a watchpoint uses both a local
10495 and a global variables in expression, it's a local watchpoint,
10496 but unloading of a shared library will make the expression
10497 invalid. This is not a very common use case, but we still
10498 re-evaluate expression, to avoid surprises to the user.
10500 Note that for local watchpoints, we re-evaluate it only if
10501 watchpoints frame id is still valid. If it's not, it means the
10502 watchpoint is out of scope and will be deleted soon. In fact,
10503 I'm not sure we'll ever be called in this case.
10505 If a local watchpoint's frame id is still valid, then
10506 w->exp_valid_block is likewise valid, and we can safely use it.
10508 Don't do anything about disabled watchpoints, since they will be
10509 reevaluated again when enabled. */
10510 update_watchpoint (w, 1 /* reparse */);
10513 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10516 insert_watchpoint (struct bp_location *bl)
10518 struct watchpoint *w = (struct watchpoint *) bl->owner;
10519 int length = w->exact ? 1 : bl->length;
10521 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10522 w->cond_exp.get ());
10525 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10528 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10530 struct watchpoint *w = (struct watchpoint *) bl->owner;
10531 int length = w->exact ? 1 : bl->length;
10533 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10534 w->cond_exp.get ());
10538 breakpoint_hit_watchpoint (const struct bp_location *bl,
10539 struct address_space *aspace, CORE_ADDR bp_addr,
10540 const struct target_waitstatus *ws)
10542 struct breakpoint *b = bl->owner;
10543 struct watchpoint *w = (struct watchpoint *) b;
10545 /* Continuable hardware watchpoints are treated as non-existent if the
10546 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10547 some data address). Otherwise gdb won't stop on a break instruction
10548 in the code (not from a breakpoint) when a hardware watchpoint has
10549 been defined. Also skip watchpoints which we know did not trigger
10550 (did not match the data address). */
10551 if (is_hardware_watchpoint (b)
10552 && w->watchpoint_triggered == watch_triggered_no)
10559 check_status_watchpoint (bpstat bs)
10561 gdb_assert (is_watchpoint (bs->breakpoint_at));
10563 bpstat_check_watchpoint (bs);
10566 /* Implement the "resources_needed" breakpoint_ops method for
10567 hardware watchpoints. */
10570 resources_needed_watchpoint (const struct bp_location *bl)
10572 struct watchpoint *w = (struct watchpoint *) bl->owner;
10573 int length = w->exact? 1 : bl->length;
10575 return target_region_ok_for_hw_watchpoint (bl->address, length);
10578 /* Implement the "works_in_software_mode" breakpoint_ops method for
10579 hardware watchpoints. */
10582 works_in_software_mode_watchpoint (const struct breakpoint *b)
10584 /* Read and access watchpoints only work with hardware support. */
10585 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10588 static enum print_stop_action
10589 print_it_watchpoint (bpstat bs)
10591 struct cleanup *old_chain;
10592 struct breakpoint *b;
10593 enum print_stop_action result;
10594 struct watchpoint *w;
10595 struct ui_out *uiout = current_uiout;
10597 gdb_assert (bs->bp_location_at != NULL);
10599 b = bs->breakpoint_at;
10600 w = (struct watchpoint *) b;
10602 old_chain = make_cleanup (null_cleanup, NULL);
10604 annotate_watchpoint (b->number);
10605 maybe_print_thread_hit_breakpoint (uiout);
10611 case bp_watchpoint:
10612 case bp_hardware_watchpoint:
10613 if (uiout->is_mi_like_p ())
10614 uiout->field_string
10615 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10617 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10618 uiout->text ("\nOld value = ");
10619 watchpoint_value_print (bs->old_val, &stb);
10620 uiout->field_stream ("old", stb);
10621 uiout->text ("\nNew value = ");
10622 watchpoint_value_print (w->val, &stb);
10623 uiout->field_stream ("new", stb);
10624 uiout->text ("\n");
10625 /* More than one watchpoint may have been triggered. */
10626 result = PRINT_UNKNOWN;
10629 case bp_read_watchpoint:
10630 if (uiout->is_mi_like_p ())
10631 uiout->field_string
10632 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10634 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10635 uiout->text ("\nValue = ");
10636 watchpoint_value_print (w->val, &stb);
10637 uiout->field_stream ("value", stb);
10638 uiout->text ("\n");
10639 result = PRINT_UNKNOWN;
10642 case bp_access_watchpoint:
10643 if (bs->old_val != NULL)
10645 if (uiout->is_mi_like_p ())
10646 uiout->field_string
10648 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10650 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10651 uiout->text ("\nOld value = ");
10652 watchpoint_value_print (bs->old_val, &stb);
10653 uiout->field_stream ("old", stb);
10654 uiout->text ("\nNew value = ");
10659 if (uiout->is_mi_like_p ())
10660 uiout->field_string
10662 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10663 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10664 uiout->text ("\nValue = ");
10666 watchpoint_value_print (w->val, &stb);
10667 uiout->field_stream ("new", stb);
10668 uiout->text ("\n");
10669 result = PRINT_UNKNOWN;
10672 result = PRINT_UNKNOWN;
10675 do_cleanups (old_chain);
10679 /* Implement the "print_mention" breakpoint_ops method for hardware
10683 print_mention_watchpoint (struct breakpoint *b)
10685 struct watchpoint *w = (struct watchpoint *) b;
10686 struct ui_out *uiout = current_uiout;
10687 const char *tuple_name;
10691 case bp_watchpoint:
10692 uiout->text ("Watchpoint ");
10693 tuple_name = "wpt";
10695 case bp_hardware_watchpoint:
10696 uiout->text ("Hardware watchpoint ");
10697 tuple_name = "wpt";
10699 case bp_read_watchpoint:
10700 uiout->text ("Hardware read watchpoint ");
10701 tuple_name = "hw-rwpt";
10703 case bp_access_watchpoint:
10704 uiout->text ("Hardware access (read/write) watchpoint ");
10705 tuple_name = "hw-awpt";
10708 internal_error (__FILE__, __LINE__,
10709 _("Invalid hardware watchpoint type."));
10712 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10713 uiout->field_int ("number", b->number);
10714 uiout->text (": ");
10715 uiout->field_string ("exp", w->exp_string);
10718 /* Implement the "print_recreate" breakpoint_ops method for
10722 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10724 struct watchpoint *w = (struct watchpoint *) b;
10728 case bp_watchpoint:
10729 case bp_hardware_watchpoint:
10730 fprintf_unfiltered (fp, "watch");
10732 case bp_read_watchpoint:
10733 fprintf_unfiltered (fp, "rwatch");
10735 case bp_access_watchpoint:
10736 fprintf_unfiltered (fp, "awatch");
10739 internal_error (__FILE__, __LINE__,
10740 _("Invalid watchpoint type."));
10743 fprintf_unfiltered (fp, " %s", w->exp_string);
10744 print_recreate_thread (b, fp);
10747 /* Implement the "explains_signal" breakpoint_ops method for
10751 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10753 /* A software watchpoint cannot cause a signal other than
10754 GDB_SIGNAL_TRAP. */
10755 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10761 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10763 static struct breakpoint_ops watchpoint_breakpoint_ops;
10765 /* Implement the "insert" breakpoint_ops method for
10766 masked hardware watchpoints. */
10769 insert_masked_watchpoint (struct bp_location *bl)
10771 struct watchpoint *w = (struct watchpoint *) bl->owner;
10773 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10774 bl->watchpoint_type);
10777 /* Implement the "remove" breakpoint_ops method for
10778 masked hardware watchpoints. */
10781 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10783 struct watchpoint *w = (struct watchpoint *) bl->owner;
10785 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10786 bl->watchpoint_type);
10789 /* Implement the "resources_needed" breakpoint_ops method for
10790 masked hardware watchpoints. */
10793 resources_needed_masked_watchpoint (const struct bp_location *bl)
10795 struct watchpoint *w = (struct watchpoint *) bl->owner;
10797 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10800 /* Implement the "works_in_software_mode" breakpoint_ops method for
10801 masked hardware watchpoints. */
10804 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10809 /* Implement the "print_it" breakpoint_ops method for
10810 masked hardware watchpoints. */
10812 static enum print_stop_action
10813 print_it_masked_watchpoint (bpstat bs)
10815 struct breakpoint *b = bs->breakpoint_at;
10816 struct ui_out *uiout = current_uiout;
10818 /* Masked watchpoints have only one location. */
10819 gdb_assert (b->loc && b->loc->next == NULL);
10821 annotate_watchpoint (b->number);
10822 maybe_print_thread_hit_breakpoint (uiout);
10826 case bp_hardware_watchpoint:
10827 if (uiout->is_mi_like_p ())
10828 uiout->field_string
10829 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10832 case bp_read_watchpoint:
10833 if (uiout->is_mi_like_p ())
10834 uiout->field_string
10835 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10838 case bp_access_watchpoint:
10839 if (uiout->is_mi_like_p ())
10840 uiout->field_string
10842 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10845 internal_error (__FILE__, __LINE__,
10846 _("Invalid hardware watchpoint type."));
10850 uiout->text (_("\n\
10851 Check the underlying instruction at PC for the memory\n\
10852 address and value which triggered this watchpoint.\n"));
10853 uiout->text ("\n");
10855 /* More than one watchpoint may have been triggered. */
10856 return PRINT_UNKNOWN;
10859 /* Implement the "print_one_detail" breakpoint_ops method for
10860 masked hardware watchpoints. */
10863 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10864 struct ui_out *uiout)
10866 struct watchpoint *w = (struct watchpoint *) b;
10868 /* Masked watchpoints have only one location. */
10869 gdb_assert (b->loc && b->loc->next == NULL);
10871 uiout->text ("\tmask ");
10872 uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
10873 uiout->text ("\n");
10876 /* Implement the "print_mention" breakpoint_ops method for
10877 masked hardware watchpoints. */
10880 print_mention_masked_watchpoint (struct breakpoint *b)
10882 struct watchpoint *w = (struct watchpoint *) b;
10883 struct ui_out *uiout = current_uiout;
10884 const char *tuple_name;
10888 case bp_hardware_watchpoint:
10889 uiout->text ("Masked hardware watchpoint ");
10890 tuple_name = "wpt";
10892 case bp_read_watchpoint:
10893 uiout->text ("Masked hardware read watchpoint ");
10894 tuple_name = "hw-rwpt";
10896 case bp_access_watchpoint:
10897 uiout->text ("Masked hardware access (read/write) watchpoint ");
10898 tuple_name = "hw-awpt";
10901 internal_error (__FILE__, __LINE__,
10902 _("Invalid hardware watchpoint type."));
10905 ui_out_emit_tuple tuple_emitter (uiout, tuple_name);
10906 uiout->field_int ("number", b->number);
10907 uiout->text (": ");
10908 uiout->field_string ("exp", w->exp_string);
10911 /* Implement the "print_recreate" breakpoint_ops method for
10912 masked hardware watchpoints. */
10915 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10917 struct watchpoint *w = (struct watchpoint *) b;
10922 case bp_hardware_watchpoint:
10923 fprintf_unfiltered (fp, "watch");
10925 case bp_read_watchpoint:
10926 fprintf_unfiltered (fp, "rwatch");
10928 case bp_access_watchpoint:
10929 fprintf_unfiltered (fp, "awatch");
10932 internal_error (__FILE__, __LINE__,
10933 _("Invalid hardware watchpoint type."));
10936 sprintf_vma (tmp, w->hw_wp_mask);
10937 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10938 print_recreate_thread (b, fp);
10941 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10943 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10945 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10948 is_masked_watchpoint (const struct breakpoint *b)
10950 return b->ops == &masked_watchpoint_breakpoint_ops;
10953 /* accessflag: hw_write: watch write,
10954 hw_read: watch read,
10955 hw_access: watch access (read or write) */
10957 watch_command_1 (const char *arg, int accessflag, int from_tty,
10958 int just_location, int internal)
10960 struct breakpoint *scope_breakpoint = NULL;
10961 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10962 struct value *val, *mark, *result;
10963 int saved_bitpos = 0, saved_bitsize = 0;
10964 const char *exp_start = NULL;
10965 const char *exp_end = NULL;
10966 const char *tok, *end_tok;
10968 const char *cond_start = NULL;
10969 const char *cond_end = NULL;
10970 enum bptype bp_type;
10973 /* Flag to indicate whether we are going to use masks for
10974 the hardware watchpoint. */
10976 CORE_ADDR mask = 0;
10977 struct watchpoint *w;
10979 struct cleanup *back_to;
10981 /* Make sure that we actually have parameters to parse. */
10982 if (arg != NULL && arg[0] != '\0')
10984 const char *value_start;
10986 exp_end = arg + strlen (arg);
10988 /* Look for "parameter value" pairs at the end
10989 of the arguments string. */
10990 for (tok = exp_end - 1; tok > arg; tok--)
10992 /* Skip whitespace at the end of the argument list. */
10993 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10996 /* Find the beginning of the last token.
10997 This is the value of the parameter. */
10998 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11000 value_start = tok + 1;
11002 /* Skip whitespace. */
11003 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11008 /* Find the beginning of the second to last token.
11009 This is the parameter itself. */
11010 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11013 toklen = end_tok - tok + 1;
11015 if (toklen == 6 && startswith (tok, "thread"))
11017 struct thread_info *thr;
11018 /* At this point we've found a "thread" token, which means
11019 the user is trying to set a watchpoint that triggers
11020 only in a specific thread. */
11024 error(_("You can specify only one thread."));
11026 /* Extract the thread ID from the next token. */
11027 thr = parse_thread_id (value_start, &endp);
11029 /* Check if the user provided a valid thread ID. */
11030 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11031 invalid_thread_id_error (value_start);
11033 thread = thr->global_num;
11035 else if (toklen == 4 && startswith (tok, "mask"))
11037 /* We've found a "mask" token, which means the user wants to
11038 create a hardware watchpoint that is going to have the mask
11040 struct value *mask_value, *mark;
11043 error(_("You can specify only one mask."));
11045 use_mask = just_location = 1;
11047 mark = value_mark ();
11048 mask_value = parse_to_comma_and_eval (&value_start);
11049 mask = value_as_address (mask_value);
11050 value_free_to_mark (mark);
11053 /* We didn't recognize what we found. We should stop here. */
11056 /* Truncate the string and get rid of the "parameter value" pair before
11057 the arguments string is parsed by the parse_exp_1 function. */
11064 /* Parse the rest of the arguments. From here on out, everything
11065 is in terms of a newly allocated string instead of the original
11067 innermost_block = NULL;
11068 expression = savestring (arg, exp_end - arg);
11069 back_to = make_cleanup (xfree, expression);
11070 exp_start = arg = expression;
11071 expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
11073 /* Remove trailing whitespace from the expression before saving it.
11074 This makes the eventual display of the expression string a bit
11076 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11079 /* Checking if the expression is not constant. */
11080 if (watchpoint_exp_is_const (exp.get ()))
11084 len = exp_end - exp_start;
11085 while (len > 0 && isspace (exp_start[len - 1]))
11087 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11090 exp_valid_block = innermost_block;
11091 mark = value_mark ();
11092 fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location);
11094 if (val != NULL && just_location)
11096 saved_bitpos = value_bitpos (val);
11097 saved_bitsize = value_bitsize (val);
11104 exp_valid_block = NULL;
11105 val = value_addr (result);
11106 release_value (val);
11107 value_free_to_mark (mark);
11111 ret = target_masked_watch_num_registers (value_as_address (val),
11114 error (_("This target does not support masked watchpoints."));
11115 else if (ret == -2)
11116 error (_("Invalid mask or memory region."));
11119 else if (val != NULL)
11120 release_value (val);
11122 tok = skip_spaces_const (arg);
11123 end_tok = skip_to_space_const (tok);
11125 toklen = end_tok - tok;
11126 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11128 innermost_block = NULL;
11129 tok = cond_start = end_tok + 1;
11130 parse_exp_1 (&tok, 0, 0, 0);
11132 /* The watchpoint expression may not be local, but the condition
11133 may still be. E.g.: `watch global if local > 0'. */
11134 cond_exp_valid_block = innermost_block;
11139 error (_("Junk at end of command."));
11141 frame_info *wp_frame = block_innermost_frame (exp_valid_block);
11143 /* Save this because create_internal_breakpoint below invalidates
11145 frame_id watchpoint_frame = get_frame_id (wp_frame);
11147 /* If the expression is "local", then set up a "watchpoint scope"
11148 breakpoint at the point where we've left the scope of the watchpoint
11149 expression. Create the scope breakpoint before the watchpoint, so
11150 that we will encounter it first in bpstat_stop_status. */
11151 if (exp_valid_block != NULL && wp_frame != NULL)
11153 frame_id caller_frame_id = frame_unwind_caller_id (wp_frame);
11155 if (frame_id_p (caller_frame_id))
11157 gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame);
11158 CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame);
11161 = create_internal_breakpoint (caller_arch, caller_pc,
11162 bp_watchpoint_scope,
11163 &momentary_breakpoint_ops);
11165 /* create_internal_breakpoint could invalidate WP_FRAME. */
11168 scope_breakpoint->enable_state = bp_enabled;
11170 /* Automatically delete the breakpoint when it hits. */
11171 scope_breakpoint->disposition = disp_del;
11173 /* Only break in the proper frame (help with recursion). */
11174 scope_breakpoint->frame_id = caller_frame_id;
11176 /* Set the address at which we will stop. */
11177 scope_breakpoint->loc->gdbarch = caller_arch;
11178 scope_breakpoint->loc->requested_address = caller_pc;
11179 scope_breakpoint->loc->address
11180 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11181 scope_breakpoint->loc->requested_address,
11182 scope_breakpoint->type);
11186 /* Now set up the breakpoint. We create all watchpoints as hardware
11187 watchpoints here even if hardware watchpoints are turned off, a call
11188 to update_watchpoint later in this function will cause the type to
11189 drop back to bp_watchpoint (software watchpoint) if required. */
11191 if (accessflag == hw_read)
11192 bp_type = bp_read_watchpoint;
11193 else if (accessflag == hw_access)
11194 bp_type = bp_access_watchpoint;
11196 bp_type = bp_hardware_watchpoint;
11198 w = new watchpoint ();
11201 init_raw_breakpoint_without_location (w, NULL, bp_type,
11202 &masked_watchpoint_breakpoint_ops);
11204 init_raw_breakpoint_without_location (w, NULL, bp_type,
11205 &watchpoint_breakpoint_ops);
11206 w->thread = thread;
11207 w->disposition = disp_donttouch;
11208 w->pspace = current_program_space;
11209 w->exp = std::move (exp);
11210 w->exp_valid_block = exp_valid_block;
11211 w->cond_exp_valid_block = cond_exp_valid_block;
11214 struct type *t = value_type (val);
11215 CORE_ADDR addr = value_as_address (val);
11217 w->exp_string_reparse
11218 = current_language->la_watch_location_expression (t, addr).release ();
11220 w->exp_string = xstrprintf ("-location %.*s",
11221 (int) (exp_end - exp_start), exp_start);
11224 w->exp_string = savestring (exp_start, exp_end - exp_start);
11228 w->hw_wp_mask = mask;
11233 w->val_bitpos = saved_bitpos;
11234 w->val_bitsize = saved_bitsize;
11239 w->cond_string = savestring (cond_start, cond_end - cond_start);
11241 w->cond_string = 0;
11243 if (frame_id_p (watchpoint_frame))
11245 w->watchpoint_frame = watchpoint_frame;
11246 w->watchpoint_thread = inferior_ptid;
11250 w->watchpoint_frame = null_frame_id;
11251 w->watchpoint_thread = null_ptid;
11254 if (scope_breakpoint != NULL)
11256 /* The scope breakpoint is related to the watchpoint. We will
11257 need to act on them together. */
11258 w->related_breakpoint = scope_breakpoint;
11259 scope_breakpoint->related_breakpoint = w;
11262 if (!just_location)
11263 value_free_to_mark (mark);
11267 /* Finally update the new watchpoint. This creates the locations
11268 that should be inserted. */
11269 update_watchpoint (w, 1);
11271 CATCH (e, RETURN_MASK_ALL)
11273 delete_breakpoint (w);
11274 throw_exception (e);
11278 install_breakpoint (internal, w, 1);
11279 do_cleanups (back_to);
11282 /* Return count of debug registers needed to watch the given expression.
11283 If the watchpoint cannot be handled in hardware return zero. */
11286 can_use_hardware_watchpoint (struct value *v)
11288 int found_memory_cnt = 0;
11289 struct value *head = v;
11291 /* Did the user specifically forbid us to use hardware watchpoints? */
11292 if (!can_use_hw_watchpoints)
11295 /* Make sure that the value of the expression depends only upon
11296 memory contents, and values computed from them within GDB. If we
11297 find any register references or function calls, we can't use a
11298 hardware watchpoint.
11300 The idea here is that evaluating an expression generates a series
11301 of values, one holding the value of every subexpression. (The
11302 expression a*b+c has five subexpressions: a, b, a*b, c, and
11303 a*b+c.) GDB's values hold almost enough information to establish
11304 the criteria given above --- they identify memory lvalues,
11305 register lvalues, computed values, etcetera. So we can evaluate
11306 the expression, and then scan the chain of values that leaves
11307 behind to decide whether we can detect any possible change to the
11308 expression's final value using only hardware watchpoints.
11310 However, I don't think that the values returned by inferior
11311 function calls are special in any way. So this function may not
11312 notice that an expression involving an inferior function call
11313 can't be watched with hardware watchpoints. FIXME. */
11314 for (; v; v = value_next (v))
11316 if (VALUE_LVAL (v) == lval_memory)
11318 if (v != head && value_lazy (v))
11319 /* A lazy memory lvalue in the chain is one that GDB never
11320 needed to fetch; we either just used its address (e.g.,
11321 `a' in `a.b') or we never needed it at all (e.g., `a'
11322 in `a,b'). This doesn't apply to HEAD; if that is
11323 lazy then it was not readable, but watch it anyway. */
11327 /* Ahh, memory we actually used! Check if we can cover
11328 it with hardware watchpoints. */
11329 struct type *vtype = check_typedef (value_type (v));
11331 /* We only watch structs and arrays if user asked for it
11332 explicitly, never if they just happen to appear in a
11333 middle of some value chain. */
11335 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11336 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11338 CORE_ADDR vaddr = value_address (v);
11342 len = (target_exact_watchpoints
11343 && is_scalar_type_recursive (vtype))?
11344 1 : TYPE_LENGTH (value_type (v));
11346 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11350 found_memory_cnt += num_regs;
11354 else if (VALUE_LVAL (v) != not_lval
11355 && deprecated_value_modifiable (v) == 0)
11356 return 0; /* These are values from the history (e.g., $1). */
11357 else if (VALUE_LVAL (v) == lval_register)
11358 return 0; /* Cannot watch a register with a HW watchpoint. */
11361 /* The expression itself looks suitable for using a hardware
11362 watchpoint, but give the target machine a chance to reject it. */
11363 return found_memory_cnt;
11367 watch_command_wrapper (char *arg, int from_tty, int internal)
11369 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11372 /* A helper function that looks for the "-location" argument and then
11373 calls watch_command_1. */
11376 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11378 int just_location = 0;
11381 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11382 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11384 arg = skip_spaces (arg);
11388 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11392 watch_command (char *arg, int from_tty)
11394 watch_maybe_just_location (arg, hw_write, from_tty);
11398 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11400 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11404 rwatch_command (char *arg, int from_tty)
11406 watch_maybe_just_location (arg, hw_read, from_tty);
11410 awatch_command_wrapper (char *arg, int from_tty, int internal)
11412 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11416 awatch_command (char *arg, int from_tty)
11418 watch_maybe_just_location (arg, hw_access, from_tty);
11422 /* Data for the FSM that manages the until(location)/advance commands
11423 in infcmd.c. Here because it uses the mechanisms of
11426 struct until_break_fsm
11428 /* The base class. */
11429 struct thread_fsm thread_fsm;
11431 /* The thread that as current when the command was executed. */
11434 /* The breakpoint set at the destination location. */
11435 struct breakpoint *location_breakpoint;
11437 /* Breakpoint set at the return address in the caller frame. May be
11439 struct breakpoint *caller_breakpoint;
11442 static void until_break_fsm_clean_up (struct thread_fsm *self,
11443 struct thread_info *thread);
11444 static int until_break_fsm_should_stop (struct thread_fsm *self,
11445 struct thread_info *thread);
11446 static enum async_reply_reason
11447 until_break_fsm_async_reply_reason (struct thread_fsm *self);
11449 /* until_break_fsm's vtable. */
11451 static struct thread_fsm_ops until_break_fsm_ops =
11454 until_break_fsm_clean_up,
11455 until_break_fsm_should_stop,
11456 NULL, /* return_value */
11457 until_break_fsm_async_reply_reason,
11460 /* Allocate a new until_break_command_fsm. */
11462 static struct until_break_fsm *
11463 new_until_break_fsm (struct interp *cmd_interp, int thread,
11464 struct breakpoint *location_breakpoint,
11465 struct breakpoint *caller_breakpoint)
11467 struct until_break_fsm *sm;
11469 sm = XCNEW (struct until_break_fsm);
11470 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
11472 sm->thread = thread;
11473 sm->location_breakpoint = location_breakpoint;
11474 sm->caller_breakpoint = caller_breakpoint;
11479 /* Implementation of the 'should_stop' FSM method for the
11480 until(location)/advance commands. */
11483 until_break_fsm_should_stop (struct thread_fsm *self,
11484 struct thread_info *tp)
11486 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11488 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11489 sm->location_breakpoint) != NULL
11490 || (sm->caller_breakpoint != NULL
11491 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11492 sm->caller_breakpoint) != NULL))
11493 thread_fsm_set_finished (self);
11498 /* Implementation of the 'clean_up' FSM method for the
11499 until(location)/advance commands. */
11502 until_break_fsm_clean_up (struct thread_fsm *self,
11503 struct thread_info *thread)
11505 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11507 /* Clean up our temporary breakpoints. */
11508 if (sm->location_breakpoint != NULL)
11510 delete_breakpoint (sm->location_breakpoint);
11511 sm->location_breakpoint = NULL;
11513 if (sm->caller_breakpoint != NULL)
11515 delete_breakpoint (sm->caller_breakpoint);
11516 sm->caller_breakpoint = NULL;
11518 delete_longjmp_breakpoint (sm->thread);
11521 /* Implementation of the 'async_reply_reason' FSM method for the
11522 until(location)/advance commands. */
11524 static enum async_reply_reason
11525 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11527 return EXEC_ASYNC_LOCATION_REACHED;
11531 until_break_command (char *arg, int from_tty, int anywhere)
11533 struct symtabs_and_lines sals;
11534 struct symtab_and_line sal;
11535 struct frame_info *frame;
11536 struct gdbarch *frame_gdbarch;
11537 struct frame_id stack_frame_id;
11538 struct frame_id caller_frame_id;
11539 struct breakpoint *location_breakpoint;
11540 struct breakpoint *caller_breakpoint = NULL;
11541 struct cleanup *old_chain;
11543 struct thread_info *tp;
11544 struct until_break_fsm *sm;
11546 clear_proceed_status (0);
11548 /* Set a breakpoint where the user wants it and at return from
11551 event_location_up location = string_to_event_location (&arg, current_language);
11553 if (last_displayed_sal_is_valid ())
11554 sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
11555 get_last_displayed_symtab (),
11556 get_last_displayed_line ());
11558 sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
11559 NULL, (struct symtab *) NULL, 0);
11561 if (sals.nelts != 1)
11562 error (_("Couldn't get information on specified line."));
11564 sal = sals.sals[0];
11565 xfree (sals.sals); /* malloc'd, so freed. */
11568 error (_("Junk at end of arguments."));
11570 resolve_sal_pc (&sal);
11572 tp = inferior_thread ();
11573 thread = tp->global_num;
11575 old_chain = make_cleanup (null_cleanup, NULL);
11577 /* Note linespec handling above invalidates the frame chain.
11578 Installing a breakpoint also invalidates the frame chain (as it
11579 may need to switch threads), so do any frame handling before
11582 frame = get_selected_frame (NULL);
11583 frame_gdbarch = get_frame_arch (frame);
11584 stack_frame_id = get_stack_frame_id (frame);
11585 caller_frame_id = frame_unwind_caller_id (frame);
11587 /* Keep within the current frame, or in frames called by the current
11590 if (frame_id_p (caller_frame_id))
11592 struct symtab_and_line sal2;
11593 struct gdbarch *caller_gdbarch;
11595 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11596 sal2.pc = frame_unwind_caller_pc (frame);
11597 caller_gdbarch = frame_unwind_caller_arch (frame);
11598 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11602 make_cleanup_delete_breakpoint (caller_breakpoint);
11604 set_longjmp_breakpoint (tp, caller_frame_id);
11605 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11608 /* set_momentary_breakpoint could invalidate FRAME. */
11612 /* If the user told us to continue until a specified location,
11613 we don't specify a frame at which we need to stop. */
11614 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11615 null_frame_id, bp_until);
11617 /* Otherwise, specify the selected frame, because we want to stop
11618 only at the very same frame. */
11619 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11620 stack_frame_id, bp_until);
11621 make_cleanup_delete_breakpoint (location_breakpoint);
11623 sm = new_until_break_fsm (command_interp (), tp->global_num,
11624 location_breakpoint, caller_breakpoint);
11625 tp->thread_fsm = &sm->thread_fsm;
11627 discard_cleanups (old_chain);
11629 proceed (-1, GDB_SIGNAL_DEFAULT);
11632 /* This function attempts to parse an optional "if <cond>" clause
11633 from the arg string. If one is not found, it returns NULL.
11635 Else, it returns a pointer to the condition string. (It does not
11636 attempt to evaluate the string against a particular block.) And,
11637 it updates arg to point to the first character following the parsed
11638 if clause in the arg string. */
11641 ep_parse_optional_if_clause (const char **arg)
11643 const char *cond_string;
11645 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11648 /* Skip the "if" keyword. */
11651 /* Skip any extra leading whitespace, and record the start of the
11652 condition string. */
11653 *arg = skip_spaces_const (*arg);
11654 cond_string = *arg;
11656 /* Assume that the condition occupies the remainder of the arg
11658 (*arg) += strlen (cond_string);
11660 return cond_string;
11663 /* Commands to deal with catching events, such as signals, exceptions,
11664 process start/exit, etc. */
11668 catch_fork_temporary, catch_vfork_temporary,
11669 catch_fork_permanent, catch_vfork_permanent
11674 catch_fork_command_1 (char *arg_entry, int from_tty,
11675 struct cmd_list_element *command)
11677 const char *arg = arg_entry;
11678 struct gdbarch *gdbarch = get_current_arch ();
11679 const char *cond_string = NULL;
11680 catch_fork_kind fork_kind;
11683 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11684 tempflag = (fork_kind == catch_fork_temporary
11685 || fork_kind == catch_vfork_temporary);
11689 arg = skip_spaces_const (arg);
11691 /* The allowed syntax is:
11693 catch [v]fork if <cond>
11695 First, check if there's an if clause. */
11696 cond_string = ep_parse_optional_if_clause (&arg);
11698 if ((*arg != '\0') && !isspace (*arg))
11699 error (_("Junk at end of arguments."));
11701 /* If this target supports it, create a fork or vfork catchpoint
11702 and enable reporting of such events. */
11705 case catch_fork_temporary:
11706 case catch_fork_permanent:
11707 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11708 &catch_fork_breakpoint_ops);
11710 case catch_vfork_temporary:
11711 case catch_vfork_permanent:
11712 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11713 &catch_vfork_breakpoint_ops);
11716 error (_("unsupported or unknown fork kind; cannot catch it"));
11722 catch_exec_command_1 (char *arg_entry, int from_tty,
11723 struct cmd_list_element *command)
11725 const char *arg = arg_entry;
11726 struct exec_catchpoint *c;
11727 struct gdbarch *gdbarch = get_current_arch ();
11729 const char *cond_string = NULL;
11731 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11735 arg = skip_spaces_const (arg);
11737 /* The allowed syntax is:
11739 catch exec if <cond>
11741 First, check if there's an if clause. */
11742 cond_string = ep_parse_optional_if_clause (&arg);
11744 if ((*arg != '\0') && !isspace (*arg))
11745 error (_("Junk at end of arguments."));
11747 c = new exec_catchpoint ();
11748 init_catchpoint (c, gdbarch, tempflag, cond_string,
11749 &catch_exec_breakpoint_ops);
11750 c->exec_pathname = NULL;
11752 install_breakpoint (0, c, 1);
11756 init_ada_exception_breakpoint (struct breakpoint *b,
11757 struct gdbarch *gdbarch,
11758 struct symtab_and_line sal,
11760 const struct breakpoint_ops *ops,
11767 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11769 loc_gdbarch = gdbarch;
11771 describe_other_breakpoints (loc_gdbarch,
11772 sal.pspace, sal.pc, sal.section, -1);
11773 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11774 version for exception catchpoints, because two catchpoints
11775 used for different exception names will use the same address.
11776 In this case, a "breakpoint ... also set at..." warning is
11777 unproductive. Besides, the warning phrasing is also a bit
11778 inappropriate, we should use the word catchpoint, and tell
11779 the user what type of catchpoint it is. The above is good
11780 enough for now, though. */
11783 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11785 b->enable_state = enabled ? bp_enabled : bp_disabled;
11786 b->disposition = tempflag ? disp_del : disp_donttouch;
11787 b->location = string_to_event_location (&addr_string,
11788 language_def (language_ada));
11789 b->language = language_ada;
11793 catch_command (char *arg, int from_tty)
11795 error (_("Catch requires an event name."));
11800 tcatch_command (char *arg, int from_tty)
11802 error (_("Catch requires an event name."));
11805 /* A qsort comparison function that sorts breakpoints in order. */
11808 compare_breakpoints (const void *a, const void *b)
11810 const breakpoint_p *ba = (const breakpoint_p *) a;
11811 uintptr_t ua = (uintptr_t) *ba;
11812 const breakpoint_p *bb = (const breakpoint_p *) b;
11813 uintptr_t ub = (uintptr_t) *bb;
11815 if ((*ba)->number < (*bb)->number)
11817 else if ((*ba)->number > (*bb)->number)
11820 /* Now sort by address, in case we see, e..g, two breakpoints with
11824 return ua > ub ? 1 : 0;
11827 /* Delete breakpoints by address or line. */
11830 clear_command (char *arg, int from_tty)
11832 struct breakpoint *b, *prev;
11833 VEC(breakpoint_p) *found = 0;
11836 struct symtabs_and_lines sals;
11837 struct symtab_and_line sal;
11839 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11843 sals = decode_line_with_current_source (arg,
11844 (DECODE_LINE_FUNFIRSTLINE
11845 | DECODE_LINE_LIST_MODE));
11846 make_cleanup (xfree, sals.sals);
11851 sals.sals = XNEW (struct symtab_and_line);
11852 make_cleanup (xfree, sals.sals);
11853 init_sal (&sal); /* Initialize to zeroes. */
11855 /* Set sal's line, symtab, pc, and pspace to the values
11856 corresponding to the last call to print_frame_info. If the
11857 codepoint is not valid, this will set all the fields to 0. */
11858 get_last_displayed_sal (&sal);
11859 if (sal.symtab == 0)
11860 error (_("No source file specified."));
11862 sals.sals[0] = sal;
11868 /* We don't call resolve_sal_pc here. That's not as bad as it
11869 seems, because all existing breakpoints typically have both
11870 file/line and pc set. So, if clear is given file/line, we can
11871 match this to existing breakpoint without obtaining pc at all.
11873 We only support clearing given the address explicitly
11874 present in breakpoint table. Say, we've set breakpoint
11875 at file:line. There were several PC values for that file:line,
11876 due to optimization, all in one block.
11878 We've picked one PC value. If "clear" is issued with another
11879 PC corresponding to the same file:line, the breakpoint won't
11880 be cleared. We probably can still clear the breakpoint, but
11881 since the other PC value is never presented to user, user
11882 can only find it by guessing, and it does not seem important
11883 to support that. */
11885 /* For each line spec given, delete bps which correspond to it. Do
11886 it in two passes, solely to preserve the current behavior that
11887 from_tty is forced true if we delete more than one
11891 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11892 for (i = 0; i < sals.nelts; i++)
11894 const char *sal_fullname;
11896 /* If exact pc given, clear bpts at that pc.
11897 If line given (pc == 0), clear all bpts on specified line.
11898 If defaulting, clear all bpts on default line
11901 defaulting sal.pc != 0 tests to do
11906 1 0 <can't happen> */
11908 sal = sals.sals[i];
11909 sal_fullname = (sal.symtab == NULL
11910 ? NULL : symtab_to_fullname (sal.symtab));
11912 /* Find all matching breakpoints and add them to 'found'. */
11913 ALL_BREAKPOINTS (b)
11916 /* Are we going to delete b? */
11917 if (b->type != bp_none && !is_watchpoint (b))
11919 struct bp_location *loc = b->loc;
11920 for (; loc; loc = loc->next)
11922 /* If the user specified file:line, don't allow a PC
11923 match. This matches historical gdb behavior. */
11924 int pc_match = (!sal.explicit_line
11926 && (loc->pspace == sal.pspace)
11927 && (loc->address == sal.pc)
11928 && (!section_is_overlay (loc->section)
11929 || loc->section == sal.section));
11930 int line_match = 0;
11932 if ((default_match || sal.explicit_line)
11933 && loc->symtab != NULL
11934 && sal_fullname != NULL
11935 && sal.pspace == loc->pspace
11936 && loc->line_number == sal.line
11937 && filename_cmp (symtab_to_fullname (loc->symtab),
11938 sal_fullname) == 0)
11941 if (pc_match || line_match)
11950 VEC_safe_push(breakpoint_p, found, b);
11954 /* Now go thru the 'found' chain and delete them. */
11955 if (VEC_empty(breakpoint_p, found))
11958 error (_("No breakpoint at %s."), arg);
11960 error (_("No breakpoint at this line."));
11963 /* Remove duplicates from the vec. */
11964 qsort (VEC_address (breakpoint_p, found),
11965 VEC_length (breakpoint_p, found),
11966 sizeof (breakpoint_p),
11967 compare_breakpoints);
11968 prev = VEC_index (breakpoint_p, found, 0);
11969 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11973 VEC_ordered_remove (breakpoint_p, found, ix);
11978 if (VEC_length(breakpoint_p, found) > 1)
11979 from_tty = 1; /* Always report if deleted more than one. */
11982 if (VEC_length(breakpoint_p, found) == 1)
11983 printf_unfiltered (_("Deleted breakpoint "));
11985 printf_unfiltered (_("Deleted breakpoints "));
11988 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11991 printf_unfiltered ("%d ", b->number);
11992 delete_breakpoint (b);
11995 putchar_unfiltered ('\n');
11997 do_cleanups (cleanups);
12000 /* Delete breakpoint in BS if they are `delete' breakpoints and
12001 all breakpoints that are marked for deletion, whether hit or not.
12002 This is called after any breakpoint is hit, or after errors. */
12005 breakpoint_auto_delete (bpstat bs)
12007 struct breakpoint *b, *b_tmp;
12009 for (; bs; bs = bs->next)
12010 if (bs->breakpoint_at
12011 && bs->breakpoint_at->disposition == disp_del
12013 delete_breakpoint (bs->breakpoint_at);
12015 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12017 if (b->disposition == disp_del_at_next_stop)
12018 delete_breakpoint (b);
12022 /* A comparison function for bp_location AP and BP being interfaced to
12023 qsort. Sort elements primarily by their ADDRESS (no matter what
12024 does breakpoint_address_is_meaningful say for its OWNER),
12025 secondarily by ordering first permanent elements and
12026 terciarily just ensuring the array is sorted stable way despite
12027 qsort being an unstable algorithm. */
12030 bp_locations_compare (const void *ap, const void *bp)
12032 const struct bp_location *a = *(const struct bp_location **) ap;
12033 const struct bp_location *b = *(const struct bp_location **) bp;
12035 if (a->address != b->address)
12036 return (a->address > b->address) - (a->address < b->address);
12038 /* Sort locations at the same address by their pspace number, keeping
12039 locations of the same inferior (in a multi-inferior environment)
12042 if (a->pspace->num != b->pspace->num)
12043 return ((a->pspace->num > b->pspace->num)
12044 - (a->pspace->num < b->pspace->num));
12046 /* Sort permanent breakpoints first. */
12047 if (a->permanent != b->permanent)
12048 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
12050 /* Make the internal GDB representation stable across GDB runs
12051 where A and B memory inside GDB can differ. Breakpoint locations of
12052 the same type at the same address can be sorted in arbitrary order. */
12054 if (a->owner->number != b->owner->number)
12055 return ((a->owner->number > b->owner->number)
12056 - (a->owner->number < b->owner->number));
12058 return (a > b) - (a < b);
12061 /* Set bp_locations_placed_address_before_address_max and
12062 bp_locations_shadow_len_after_address_max according to the current
12063 content of the bp_locations array. */
12066 bp_locations_target_extensions_update (void)
12068 struct bp_location *bl, **blp_tmp;
12070 bp_locations_placed_address_before_address_max = 0;
12071 bp_locations_shadow_len_after_address_max = 0;
12073 ALL_BP_LOCATIONS (bl, blp_tmp)
12075 CORE_ADDR start, end, addr;
12077 if (!bp_location_has_shadow (bl))
12080 start = bl->target_info.placed_address;
12081 end = start + bl->target_info.shadow_len;
12083 gdb_assert (bl->address >= start);
12084 addr = bl->address - start;
12085 if (addr > bp_locations_placed_address_before_address_max)
12086 bp_locations_placed_address_before_address_max = addr;
12088 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12090 gdb_assert (bl->address < end);
12091 addr = end - bl->address;
12092 if (addr > bp_locations_shadow_len_after_address_max)
12093 bp_locations_shadow_len_after_address_max = addr;
12097 /* Download tracepoint locations if they haven't been. */
12100 download_tracepoint_locations (void)
12102 struct breakpoint *b;
12103 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
12105 scoped_restore_current_pspace_and_thread restore_pspace_thread;
12107 ALL_TRACEPOINTS (b)
12109 struct bp_location *bl;
12110 struct tracepoint *t;
12111 int bp_location_downloaded = 0;
12113 if ((b->type == bp_fast_tracepoint
12114 ? !may_insert_fast_tracepoints
12115 : !may_insert_tracepoints))
12118 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
12120 if (target_can_download_tracepoint ())
12121 can_download_tracepoint = TRIBOOL_TRUE;
12123 can_download_tracepoint = TRIBOOL_FALSE;
12126 if (can_download_tracepoint == TRIBOOL_FALSE)
12129 for (bl = b->loc; bl; bl = bl->next)
12131 /* In tracepoint, locations are _never_ duplicated, so
12132 should_be_inserted is equivalent to
12133 unduplicated_should_be_inserted. */
12134 if (!should_be_inserted (bl) || bl->inserted)
12137 switch_to_program_space_and_thread (bl->pspace);
12139 target_download_tracepoint (bl);
12142 bp_location_downloaded = 1;
12144 t = (struct tracepoint *) b;
12145 t->number_on_target = b->number;
12146 if (bp_location_downloaded)
12147 observer_notify_breakpoint_modified (b);
12151 /* Swap the insertion/duplication state between two locations. */
12154 swap_insertion (struct bp_location *left, struct bp_location *right)
12156 const int left_inserted = left->inserted;
12157 const int left_duplicate = left->duplicate;
12158 const int left_needs_update = left->needs_update;
12159 const struct bp_target_info left_target_info = left->target_info;
12161 /* Locations of tracepoints can never be duplicated. */
12162 if (is_tracepoint (left->owner))
12163 gdb_assert (!left->duplicate);
12164 if (is_tracepoint (right->owner))
12165 gdb_assert (!right->duplicate);
12167 left->inserted = right->inserted;
12168 left->duplicate = right->duplicate;
12169 left->needs_update = right->needs_update;
12170 left->target_info = right->target_info;
12171 right->inserted = left_inserted;
12172 right->duplicate = left_duplicate;
12173 right->needs_update = left_needs_update;
12174 right->target_info = left_target_info;
12177 /* Force the re-insertion of the locations at ADDRESS. This is called
12178 once a new/deleted/modified duplicate location is found and we are evaluating
12179 conditions on the target's side. Such conditions need to be updated on
12183 force_breakpoint_reinsertion (struct bp_location *bl)
12185 struct bp_location **locp = NULL, **loc2p;
12186 struct bp_location *loc;
12187 CORE_ADDR address = 0;
12190 address = bl->address;
12191 pspace_num = bl->pspace->num;
12193 /* This is only meaningful if the target is
12194 evaluating conditions and if the user has
12195 opted for condition evaluation on the target's
12197 if (gdb_evaluates_breakpoint_condition_p ()
12198 || !target_supports_evaluation_of_breakpoint_conditions ())
12201 /* Flag all breakpoint locations with this address and
12202 the same program space as the location
12203 as "its condition has changed". We need to
12204 update the conditions on the target's side. */
12205 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12209 if (!is_breakpoint (loc->owner)
12210 || pspace_num != loc->pspace->num)
12213 /* Flag the location appropriately. We use a different state to
12214 let everyone know that we already updated the set of locations
12215 with addr bl->address and program space bl->pspace. This is so
12216 we don't have to keep calling these functions just to mark locations
12217 that have already been marked. */
12218 loc->condition_changed = condition_updated;
12220 /* Free the agent expression bytecode as well. We will compute
12222 loc->cond_bytecode.reset ();
12225 /* Called whether new breakpoints are created, or existing breakpoints
12226 deleted, to update the global location list and recompute which
12227 locations are duplicate of which.
12229 The INSERT_MODE flag determines whether locations may not, may, or
12230 shall be inserted now. See 'enum ugll_insert_mode' for more
12234 update_global_location_list (enum ugll_insert_mode insert_mode)
12236 struct breakpoint *b;
12237 struct bp_location **locp, *loc;
12238 struct cleanup *cleanups;
12239 /* Last breakpoint location address that was marked for update. */
12240 CORE_ADDR last_addr = 0;
12241 /* Last breakpoint location program space that was marked for update. */
12242 int last_pspace_num = -1;
12244 /* Used in the duplicates detection below. When iterating over all
12245 bp_locations, points to the first bp_location of a given address.
12246 Breakpoints and watchpoints of different types are never
12247 duplicates of each other. Keep one pointer for each type of
12248 breakpoint/watchpoint, so we only need to loop over all locations
12250 struct bp_location *bp_loc_first; /* breakpoint */
12251 struct bp_location *wp_loc_first; /* hardware watchpoint */
12252 struct bp_location *awp_loc_first; /* access watchpoint */
12253 struct bp_location *rwp_loc_first; /* read watchpoint */
12255 /* Saved former bp_locations array which we compare against the newly
12256 built bp_locations from the current state of ALL_BREAKPOINTS. */
12257 struct bp_location **old_locations, **old_locp;
12258 unsigned old_locations_count;
12260 old_locations = bp_locations;
12261 old_locations_count = bp_locations_count;
12262 bp_locations = NULL;
12263 bp_locations_count = 0;
12264 cleanups = make_cleanup (xfree, old_locations);
12266 ALL_BREAKPOINTS (b)
12267 for (loc = b->loc; loc; loc = loc->next)
12268 bp_locations_count++;
12270 bp_locations = XNEWVEC (struct bp_location *, bp_locations_count);
12271 locp = bp_locations;
12272 ALL_BREAKPOINTS (b)
12273 for (loc = b->loc; loc; loc = loc->next)
12275 qsort (bp_locations, bp_locations_count, sizeof (*bp_locations),
12276 bp_locations_compare);
12278 bp_locations_target_extensions_update ();
12280 /* Identify bp_location instances that are no longer present in the
12281 new list, and therefore should be freed. Note that it's not
12282 necessary that those locations should be removed from inferior --
12283 if there's another location at the same address (previously
12284 marked as duplicate), we don't need to remove/insert the
12287 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12288 and former bp_location array state respectively. */
12290 locp = bp_locations;
12291 for (old_locp = old_locations;
12292 old_locp < old_locations + old_locations_count;
12295 struct bp_location *old_loc = *old_locp;
12296 struct bp_location **loc2p;
12298 /* Tells if 'old_loc' is found among the new locations. If
12299 not, we have to free it. */
12300 int found_object = 0;
12301 /* Tells if the location should remain inserted in the target. */
12302 int keep_in_target = 0;
12305 /* Skip LOCP entries which will definitely never be needed.
12306 Stop either at or being the one matching OLD_LOC. */
12307 while (locp < bp_locations + bp_locations_count
12308 && (*locp)->address < old_loc->address)
12312 (loc2p < bp_locations + bp_locations_count
12313 && (*loc2p)->address == old_loc->address);
12316 /* Check if this is a new/duplicated location or a duplicated
12317 location that had its condition modified. If so, we want to send
12318 its condition to the target if evaluation of conditions is taking
12320 if ((*loc2p)->condition_changed == condition_modified
12321 && (last_addr != old_loc->address
12322 || last_pspace_num != old_loc->pspace->num))
12324 force_breakpoint_reinsertion (*loc2p);
12325 last_pspace_num = old_loc->pspace->num;
12328 if (*loc2p == old_loc)
12332 /* We have already handled this address, update it so that we don't
12333 have to go through updates again. */
12334 last_addr = old_loc->address;
12336 /* Target-side condition evaluation: Handle deleted locations. */
12338 force_breakpoint_reinsertion (old_loc);
12340 /* If this location is no longer present, and inserted, look if
12341 there's maybe a new location at the same address. If so,
12342 mark that one inserted, and don't remove this one. This is
12343 needed so that we don't have a time window where a breakpoint
12344 at certain location is not inserted. */
12346 if (old_loc->inserted)
12348 /* If the location is inserted now, we might have to remove
12351 if (found_object && should_be_inserted (old_loc))
12353 /* The location is still present in the location list,
12354 and still should be inserted. Don't do anything. */
12355 keep_in_target = 1;
12359 /* This location still exists, but it won't be kept in the
12360 target since it may have been disabled. We proceed to
12361 remove its target-side condition. */
12363 /* The location is either no longer present, or got
12364 disabled. See if there's another location at the
12365 same address, in which case we don't need to remove
12366 this one from the target. */
12368 /* OLD_LOC comes from existing struct breakpoint. */
12369 if (breakpoint_address_is_meaningful (old_loc->owner))
12372 (loc2p < bp_locations + bp_locations_count
12373 && (*loc2p)->address == old_loc->address);
12376 struct bp_location *loc2 = *loc2p;
12378 if (breakpoint_locations_match (loc2, old_loc))
12380 /* Read watchpoint locations are switched to
12381 access watchpoints, if the former are not
12382 supported, but the latter are. */
12383 if (is_hardware_watchpoint (old_loc->owner))
12385 gdb_assert (is_hardware_watchpoint (loc2->owner));
12386 loc2->watchpoint_type = old_loc->watchpoint_type;
12389 /* loc2 is a duplicated location. We need to check
12390 if it should be inserted in case it will be
12392 if (loc2 != old_loc
12393 && unduplicated_should_be_inserted (loc2))
12395 swap_insertion (old_loc, loc2);
12396 keep_in_target = 1;
12404 if (!keep_in_target)
12406 if (remove_breakpoint (old_loc))
12408 /* This is just about all we can do. We could keep
12409 this location on the global list, and try to
12410 remove it next time, but there's no particular
12411 reason why we will succeed next time.
12413 Note that at this point, old_loc->owner is still
12414 valid, as delete_breakpoint frees the breakpoint
12415 only after calling us. */
12416 printf_filtered (_("warning: Error removing "
12417 "breakpoint %d\n"),
12418 old_loc->owner->number);
12426 if (removed && target_is_non_stop_p ()
12427 && need_moribund_for_location_type (old_loc))
12429 /* This location was removed from the target. In
12430 non-stop mode, a race condition is possible where
12431 we've removed a breakpoint, but stop events for that
12432 breakpoint are already queued and will arrive later.
12433 We apply an heuristic to be able to distinguish such
12434 SIGTRAPs from other random SIGTRAPs: we keep this
12435 breakpoint location for a bit, and will retire it
12436 after we see some number of events. The theory here
12437 is that reporting of events should, "on the average",
12438 be fair, so after a while we'll see events from all
12439 threads that have anything of interest, and no longer
12440 need to keep this breakpoint location around. We
12441 don't hold locations forever so to reduce chances of
12442 mistaking a non-breakpoint SIGTRAP for a breakpoint
12445 The heuristic failing can be disastrous on
12446 decr_pc_after_break targets.
12448 On decr_pc_after_break targets, like e.g., x86-linux,
12449 if we fail to recognize a late breakpoint SIGTRAP,
12450 because events_till_retirement has reached 0 too
12451 soon, we'll fail to do the PC adjustment, and report
12452 a random SIGTRAP to the user. When the user resumes
12453 the inferior, it will most likely immediately crash
12454 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12455 corrupted, because of being resumed e.g., in the
12456 middle of a multi-byte instruction, or skipped a
12457 one-byte instruction. This was actually seen happen
12458 on native x86-linux, and should be less rare on
12459 targets that do not support new thread events, like
12460 remote, due to the heuristic depending on
12463 Mistaking a random SIGTRAP for a breakpoint trap
12464 causes similar symptoms (PC adjustment applied when
12465 it shouldn't), but then again, playing with SIGTRAPs
12466 behind the debugger's back is asking for trouble.
12468 Since hardware watchpoint traps are always
12469 distinguishable from other traps, so we don't need to
12470 apply keep hardware watchpoint moribund locations
12471 around. We simply always ignore hardware watchpoint
12472 traps we can no longer explain. */
12474 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12475 old_loc->owner = NULL;
12477 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12481 old_loc->owner = NULL;
12482 decref_bp_location (&old_loc);
12487 /* Rescan breakpoints at the same address and section, marking the
12488 first one as "first" and any others as "duplicates". This is so
12489 that the bpt instruction is only inserted once. If we have a
12490 permanent breakpoint at the same place as BPT, make that one the
12491 official one, and the rest as duplicates. Permanent breakpoints
12492 are sorted first for the same address.
12494 Do the same for hardware watchpoints, but also considering the
12495 watchpoint's type (regular/access/read) and length. */
12497 bp_loc_first = NULL;
12498 wp_loc_first = NULL;
12499 awp_loc_first = NULL;
12500 rwp_loc_first = NULL;
12501 ALL_BP_LOCATIONS (loc, locp)
12503 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12505 struct bp_location **loc_first_p;
12508 if (!unduplicated_should_be_inserted (loc)
12509 || !breakpoint_address_is_meaningful (b)
12510 /* Don't detect duplicate for tracepoint locations because they are
12511 never duplicated. See the comments in field `duplicate' of
12512 `struct bp_location'. */
12513 || is_tracepoint (b))
12515 /* Clear the condition modification flag. */
12516 loc->condition_changed = condition_unchanged;
12520 if (b->type == bp_hardware_watchpoint)
12521 loc_first_p = &wp_loc_first;
12522 else if (b->type == bp_read_watchpoint)
12523 loc_first_p = &rwp_loc_first;
12524 else if (b->type == bp_access_watchpoint)
12525 loc_first_p = &awp_loc_first;
12527 loc_first_p = &bp_loc_first;
12529 if (*loc_first_p == NULL
12530 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12531 || !breakpoint_locations_match (loc, *loc_first_p))
12533 *loc_first_p = loc;
12534 loc->duplicate = 0;
12536 if (is_breakpoint (loc->owner) && loc->condition_changed)
12538 loc->needs_update = 1;
12539 /* Clear the condition modification flag. */
12540 loc->condition_changed = condition_unchanged;
12546 /* This and the above ensure the invariant that the first location
12547 is not duplicated, and is the inserted one.
12548 All following are marked as duplicated, and are not inserted. */
12550 swap_insertion (loc, *loc_first_p);
12551 loc->duplicate = 1;
12553 /* Clear the condition modification flag. */
12554 loc->condition_changed = condition_unchanged;
12557 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12559 if (insert_mode != UGLL_DONT_INSERT)
12560 insert_breakpoint_locations ();
12563 /* Even though the caller told us to not insert new
12564 locations, we may still need to update conditions on the
12565 target's side of breakpoints that were already inserted
12566 if the target is evaluating breakpoint conditions. We
12567 only update conditions for locations that are marked
12569 update_inserted_breakpoint_locations ();
12573 if (insert_mode != UGLL_DONT_INSERT)
12574 download_tracepoint_locations ();
12576 do_cleanups (cleanups);
12580 breakpoint_retire_moribund (void)
12582 struct bp_location *loc;
12585 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12586 if (--(loc->events_till_retirement) == 0)
12588 decref_bp_location (&loc);
12589 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12595 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12600 update_global_location_list (insert_mode);
12602 CATCH (e, RETURN_MASK_ERROR)
12608 /* Clear BKP from a BPS. */
12611 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12615 for (bs = bps; bs; bs = bs->next)
12616 if (bs->breakpoint_at == bpt)
12618 bs->breakpoint_at = NULL;
12619 bs->old_val = NULL;
12620 /* bs->commands will be freed later. */
12624 /* Callback for iterate_over_threads. */
12626 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12628 struct breakpoint *bpt = (struct breakpoint *) data;
12630 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12634 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12638 say_where (struct breakpoint *b)
12640 struct value_print_options opts;
12642 get_user_print_options (&opts);
12644 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12646 if (b->loc == NULL)
12648 /* For pending locations, the output differs slightly based
12649 on b->extra_string. If this is non-NULL, it contains either
12650 a condition or dprintf arguments. */
12651 if (b->extra_string == NULL)
12653 printf_filtered (_(" (%s) pending."),
12654 event_location_to_string (b->location.get ()));
12656 else if (b->type == bp_dprintf)
12658 printf_filtered (_(" (%s,%s) pending."),
12659 event_location_to_string (b->location.get ()),
12664 printf_filtered (_(" (%s %s) pending."),
12665 event_location_to_string (b->location.get ()),
12671 if (opts.addressprint || b->loc->symtab == NULL)
12673 printf_filtered (" at ");
12674 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12677 if (b->loc->symtab != NULL)
12679 /* If there is a single location, we can print the location
12681 if (b->loc->next == NULL)
12682 printf_filtered (": file %s, line %d.",
12683 symtab_to_filename_for_display (b->loc->symtab),
12684 b->loc->line_number);
12686 /* This is not ideal, but each location may have a
12687 different file name, and this at least reflects the
12688 real situation somewhat. */
12689 printf_filtered (": %s.",
12690 event_location_to_string (b->location.get ()));
12695 struct bp_location *loc = b->loc;
12697 for (; loc; loc = loc->next)
12699 printf_filtered (" (%d locations)", n);
12704 /* Default bp_location_ops methods. */
12707 bp_location_dtor (struct bp_location *self)
12709 xfree (self->function_name);
12712 static const struct bp_location_ops bp_location_ops =
12717 /* Destructor for the breakpoint base class. */
12719 breakpoint::~breakpoint ()
12721 decref_counted_command_line (&this->commands);
12722 xfree (this->cond_string);
12723 xfree (this->extra_string);
12724 xfree (this->filter);
12727 static struct bp_location *
12728 base_breakpoint_allocate_location (struct breakpoint *self)
12730 return new bp_location (&bp_location_ops, self);
12734 base_breakpoint_re_set (struct breakpoint *b)
12736 /* Nothing to re-set. */
12739 #define internal_error_pure_virtual_called() \
12740 gdb_assert_not_reached ("pure virtual function called")
12743 base_breakpoint_insert_location (struct bp_location *bl)
12745 internal_error_pure_virtual_called ();
12749 base_breakpoint_remove_location (struct bp_location *bl,
12750 enum remove_bp_reason reason)
12752 internal_error_pure_virtual_called ();
12756 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12757 struct address_space *aspace,
12759 const struct target_waitstatus *ws)
12761 internal_error_pure_virtual_called ();
12765 base_breakpoint_check_status (bpstat bs)
12770 /* A "works_in_software_mode" breakpoint_ops method that just internal
12774 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12776 internal_error_pure_virtual_called ();
12779 /* A "resources_needed" breakpoint_ops method that just internal
12783 base_breakpoint_resources_needed (const struct bp_location *bl)
12785 internal_error_pure_virtual_called ();
12788 static enum print_stop_action
12789 base_breakpoint_print_it (bpstat bs)
12791 internal_error_pure_virtual_called ();
12795 base_breakpoint_print_one_detail (const struct breakpoint *self,
12796 struct ui_out *uiout)
12802 base_breakpoint_print_mention (struct breakpoint *b)
12804 internal_error_pure_virtual_called ();
12808 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12810 internal_error_pure_virtual_called ();
12814 base_breakpoint_create_sals_from_location
12815 (const struct event_location *location,
12816 struct linespec_result *canonical,
12817 enum bptype type_wanted)
12819 internal_error_pure_virtual_called ();
12823 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12824 struct linespec_result *c,
12825 gdb::unique_xmalloc_ptr<char> cond_string,
12826 gdb::unique_xmalloc_ptr<char> extra_string,
12827 enum bptype type_wanted,
12828 enum bpdisp disposition,
12830 int task, int ignore_count,
12831 const struct breakpoint_ops *o,
12832 int from_tty, int enabled,
12833 int internal, unsigned flags)
12835 internal_error_pure_virtual_called ();
12839 base_breakpoint_decode_location (struct breakpoint *b,
12840 const struct event_location *location,
12841 struct program_space *search_pspace,
12842 struct symtabs_and_lines *sals)
12844 internal_error_pure_virtual_called ();
12847 /* The default 'explains_signal' method. */
12850 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12855 /* The default "after_condition_true" method. */
12858 base_breakpoint_after_condition_true (struct bpstats *bs)
12860 /* Nothing to do. */
12863 struct breakpoint_ops base_breakpoint_ops =
12865 base_breakpoint_allocate_location,
12866 base_breakpoint_re_set,
12867 base_breakpoint_insert_location,
12868 base_breakpoint_remove_location,
12869 base_breakpoint_breakpoint_hit,
12870 base_breakpoint_check_status,
12871 base_breakpoint_resources_needed,
12872 base_breakpoint_works_in_software_mode,
12873 base_breakpoint_print_it,
12875 base_breakpoint_print_one_detail,
12876 base_breakpoint_print_mention,
12877 base_breakpoint_print_recreate,
12878 base_breakpoint_create_sals_from_location,
12879 base_breakpoint_create_breakpoints_sal,
12880 base_breakpoint_decode_location,
12881 base_breakpoint_explains_signal,
12882 base_breakpoint_after_condition_true,
12885 /* Default breakpoint_ops methods. */
12888 bkpt_re_set (struct breakpoint *b)
12890 /* FIXME: is this still reachable? */
12891 if (breakpoint_event_location_empty_p (b))
12893 /* Anything without a location can't be re-set. */
12894 delete_breakpoint (b);
12898 breakpoint_re_set_default (b);
12902 bkpt_insert_location (struct bp_location *bl)
12904 CORE_ADDR addr = bl->target_info.reqstd_address;
12906 bl->target_info.kind = breakpoint_kind (bl, &addr);
12907 bl->target_info.placed_address = addr;
12909 if (bl->loc_type == bp_loc_hardware_breakpoint)
12910 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
12912 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
12916 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
12918 if (bl->loc_type == bp_loc_hardware_breakpoint)
12919 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12921 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
12925 bkpt_breakpoint_hit (const struct bp_location *bl,
12926 struct address_space *aspace, CORE_ADDR bp_addr,
12927 const struct target_waitstatus *ws)
12929 if (ws->kind != TARGET_WAITKIND_STOPPED
12930 || ws->value.sig != GDB_SIGNAL_TRAP)
12933 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12937 if (overlay_debugging /* unmapped overlay section */
12938 && section_is_overlay (bl->section)
12939 && !section_is_mapped (bl->section))
12946 dprintf_breakpoint_hit (const struct bp_location *bl,
12947 struct address_space *aspace, CORE_ADDR bp_addr,
12948 const struct target_waitstatus *ws)
12950 if (dprintf_style == dprintf_style_agent
12951 && target_can_run_breakpoint_commands ())
12953 /* An agent-style dprintf never causes a stop. If we see a trap
12954 for this address it must be for a breakpoint that happens to
12955 be set at the same address. */
12959 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
12963 bkpt_resources_needed (const struct bp_location *bl)
12965 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12970 static enum print_stop_action
12971 bkpt_print_it (bpstat bs)
12973 struct breakpoint *b;
12974 const struct bp_location *bl;
12976 struct ui_out *uiout = current_uiout;
12978 gdb_assert (bs->bp_location_at != NULL);
12980 bl = bs->bp_location_at;
12981 b = bs->breakpoint_at;
12983 bp_temp = b->disposition == disp_del;
12984 if (bl->address != bl->requested_address)
12985 breakpoint_adjustment_warning (bl->requested_address,
12988 annotate_breakpoint (b->number);
12989 maybe_print_thread_hit_breakpoint (uiout);
12992 uiout->text ("Temporary breakpoint ");
12994 uiout->text ("Breakpoint ");
12995 if (uiout->is_mi_like_p ())
12997 uiout->field_string ("reason",
12998 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12999 uiout->field_string ("disp", bpdisp_text (b->disposition));
13001 uiout->field_int ("bkptno", b->number);
13002 uiout->text (", ");
13004 return PRINT_SRC_AND_LOC;
13008 bkpt_print_mention (struct breakpoint *b)
13010 if (current_uiout->is_mi_like_p ())
13015 case bp_breakpoint:
13016 case bp_gnu_ifunc_resolver:
13017 if (b->disposition == disp_del)
13018 printf_filtered (_("Temporary breakpoint"));
13020 printf_filtered (_("Breakpoint"));
13021 printf_filtered (_(" %d"), b->number);
13022 if (b->type == bp_gnu_ifunc_resolver)
13023 printf_filtered (_(" at gnu-indirect-function resolver"));
13025 case bp_hardware_breakpoint:
13026 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13029 printf_filtered (_("Dprintf %d"), b->number);
13037 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13039 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13040 fprintf_unfiltered (fp, "tbreak");
13041 else if (tp->type == bp_breakpoint)
13042 fprintf_unfiltered (fp, "break");
13043 else if (tp->type == bp_hardware_breakpoint
13044 && tp->disposition == disp_del)
13045 fprintf_unfiltered (fp, "thbreak");
13046 else if (tp->type == bp_hardware_breakpoint)
13047 fprintf_unfiltered (fp, "hbreak");
13049 internal_error (__FILE__, __LINE__,
13050 _("unhandled breakpoint type %d"), (int) tp->type);
13052 fprintf_unfiltered (fp, " %s",
13053 event_location_to_string (tp->location.get ()));
13055 /* Print out extra_string if this breakpoint is pending. It might
13056 contain, for example, conditions that were set by the user. */
13057 if (tp->loc == NULL && tp->extra_string != NULL)
13058 fprintf_unfiltered (fp, " %s", tp->extra_string);
13060 print_recreate_thread (tp, fp);
13064 bkpt_create_sals_from_location (const struct event_location *location,
13065 struct linespec_result *canonical,
13066 enum bptype type_wanted)
13068 create_sals_from_location_default (location, canonical, type_wanted);
13072 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13073 struct linespec_result *canonical,
13074 gdb::unique_xmalloc_ptr<char> cond_string,
13075 gdb::unique_xmalloc_ptr<char> extra_string,
13076 enum bptype type_wanted,
13077 enum bpdisp disposition,
13079 int task, int ignore_count,
13080 const struct breakpoint_ops *ops,
13081 int from_tty, int enabled,
13082 int internal, unsigned flags)
13084 create_breakpoints_sal_default (gdbarch, canonical,
13085 std::move (cond_string),
13086 std::move (extra_string),
13088 disposition, thread, task,
13089 ignore_count, ops, from_tty,
13090 enabled, internal, flags);
13094 bkpt_decode_location (struct breakpoint *b,
13095 const struct event_location *location,
13096 struct program_space *search_pspace,
13097 struct symtabs_and_lines *sals)
13099 decode_location_default (b, location, search_pspace, sals);
13102 /* Virtual table for internal breakpoints. */
13105 internal_bkpt_re_set (struct breakpoint *b)
13109 /* Delete overlay event and longjmp master breakpoints; they
13110 will be reset later by breakpoint_re_set. */
13111 case bp_overlay_event:
13112 case bp_longjmp_master:
13113 case bp_std_terminate_master:
13114 case bp_exception_master:
13115 delete_breakpoint (b);
13118 /* This breakpoint is special, it's set up when the inferior
13119 starts and we really don't want to touch it. */
13120 case bp_shlib_event:
13122 /* Like bp_shlib_event, this breakpoint type is special. Once
13123 it is set up, we do not want to touch it. */
13124 case bp_thread_event:
13130 internal_bkpt_check_status (bpstat bs)
13132 if (bs->breakpoint_at->type == bp_shlib_event)
13134 /* If requested, stop when the dynamic linker notifies GDB of
13135 events. This allows the user to get control and place
13136 breakpoints in initializer routines for dynamically loaded
13137 objects (among other things). */
13138 bs->stop = stop_on_solib_events;
13139 bs->print = stop_on_solib_events;
13145 static enum print_stop_action
13146 internal_bkpt_print_it (bpstat bs)
13148 struct breakpoint *b;
13150 b = bs->breakpoint_at;
13154 case bp_shlib_event:
13155 /* Did we stop because the user set the stop_on_solib_events
13156 variable? (If so, we report this as a generic, "Stopped due
13157 to shlib event" message.) */
13158 print_solib_event (0);
13161 case bp_thread_event:
13162 /* Not sure how we will get here.
13163 GDB should not stop for these breakpoints. */
13164 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13167 case bp_overlay_event:
13168 /* By analogy with the thread event, GDB should not stop for these. */
13169 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13172 case bp_longjmp_master:
13173 /* These should never be enabled. */
13174 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13177 case bp_std_terminate_master:
13178 /* These should never be enabled. */
13179 printf_filtered (_("std::terminate Master Breakpoint: "
13180 "gdb should not stop!\n"));
13183 case bp_exception_master:
13184 /* These should never be enabled. */
13185 printf_filtered (_("Exception Master Breakpoint: "
13186 "gdb should not stop!\n"));
13190 return PRINT_NOTHING;
13194 internal_bkpt_print_mention (struct breakpoint *b)
13196 /* Nothing to mention. These breakpoints are internal. */
13199 /* Virtual table for momentary breakpoints */
13202 momentary_bkpt_re_set (struct breakpoint *b)
13204 /* Keep temporary breakpoints, which can be encountered when we step
13205 over a dlopen call and solib_add is resetting the breakpoints.
13206 Otherwise these should have been blown away via the cleanup chain
13207 or by breakpoint_init_inferior when we rerun the executable. */
13211 momentary_bkpt_check_status (bpstat bs)
13213 /* Nothing. The point of these breakpoints is causing a stop. */
13216 static enum print_stop_action
13217 momentary_bkpt_print_it (bpstat bs)
13219 return PRINT_UNKNOWN;
13223 momentary_bkpt_print_mention (struct breakpoint *b)
13225 /* Nothing to mention. These breakpoints are internal. */
13228 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13230 It gets cleared already on the removal of the first one of such placed
13231 breakpoints. This is OK as they get all removed altogether. */
13233 longjmp_breakpoint::~longjmp_breakpoint ()
13235 thread_info *tp = find_thread_global_id (this->thread);
13238 tp->initiating_frame = null_frame_id;
13241 /* Specific methods for probe breakpoints. */
13244 bkpt_probe_insert_location (struct bp_location *bl)
13246 int v = bkpt_insert_location (bl);
13250 /* The insertion was successful, now let's set the probe's semaphore
13252 if (bl->probe.probe->pops->set_semaphore != NULL)
13253 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13262 bkpt_probe_remove_location (struct bp_location *bl,
13263 enum remove_bp_reason reason)
13265 /* Let's clear the semaphore before removing the location. */
13266 if (bl->probe.probe->pops->clear_semaphore != NULL)
13267 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13271 return bkpt_remove_location (bl, reason);
13275 bkpt_probe_create_sals_from_location (const struct event_location *location,
13276 struct linespec_result *canonical,
13277 enum bptype type_wanted)
13279 struct linespec_sals lsal;
13281 lsal.sals = parse_probes (location, NULL, canonical);
13283 = xstrdup (event_location_to_string (canonical->location.get ()));
13284 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13288 bkpt_probe_decode_location (struct breakpoint *b,
13289 const struct event_location *location,
13290 struct program_space *search_pspace,
13291 struct symtabs_and_lines *sals)
13293 *sals = parse_probes (location, search_pspace, NULL);
13295 error (_("probe not found"));
13298 /* The breakpoint_ops structure to be used in tracepoints. */
13301 tracepoint_re_set (struct breakpoint *b)
13303 breakpoint_re_set_default (b);
13307 tracepoint_breakpoint_hit (const struct bp_location *bl,
13308 struct address_space *aspace, CORE_ADDR bp_addr,
13309 const struct target_waitstatus *ws)
13311 /* By definition, the inferior does not report stops at
13317 tracepoint_print_one_detail (const struct breakpoint *self,
13318 struct ui_out *uiout)
13320 struct tracepoint *tp = (struct tracepoint *) self;
13321 if (tp->static_trace_marker_id)
13323 gdb_assert (self->type == bp_static_tracepoint);
13325 uiout->text ("\tmarker id is ");
13326 uiout->field_string ("static-tracepoint-marker-string-id",
13327 tp->static_trace_marker_id);
13328 uiout->text ("\n");
13333 tracepoint_print_mention (struct breakpoint *b)
13335 if (current_uiout->is_mi_like_p ())
13340 case bp_tracepoint:
13341 printf_filtered (_("Tracepoint"));
13342 printf_filtered (_(" %d"), b->number);
13344 case bp_fast_tracepoint:
13345 printf_filtered (_("Fast tracepoint"));
13346 printf_filtered (_(" %d"), b->number);
13348 case bp_static_tracepoint:
13349 printf_filtered (_("Static tracepoint"));
13350 printf_filtered (_(" %d"), b->number);
13353 internal_error (__FILE__, __LINE__,
13354 _("unhandled tracepoint type %d"), (int) b->type);
13361 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13363 struct tracepoint *tp = (struct tracepoint *) self;
13365 if (self->type == bp_fast_tracepoint)
13366 fprintf_unfiltered (fp, "ftrace");
13367 else if (self->type == bp_static_tracepoint)
13368 fprintf_unfiltered (fp, "strace");
13369 else if (self->type == bp_tracepoint)
13370 fprintf_unfiltered (fp, "trace");
13372 internal_error (__FILE__, __LINE__,
13373 _("unhandled tracepoint type %d"), (int) self->type);
13375 fprintf_unfiltered (fp, " %s",
13376 event_location_to_string (self->location.get ()));
13377 print_recreate_thread (self, fp);
13379 if (tp->pass_count)
13380 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13384 tracepoint_create_sals_from_location (const struct event_location *location,
13385 struct linespec_result *canonical,
13386 enum bptype type_wanted)
13388 create_sals_from_location_default (location, canonical, type_wanted);
13392 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13393 struct linespec_result *canonical,
13394 gdb::unique_xmalloc_ptr<char> cond_string,
13395 gdb::unique_xmalloc_ptr<char> extra_string,
13396 enum bptype type_wanted,
13397 enum bpdisp disposition,
13399 int task, int ignore_count,
13400 const struct breakpoint_ops *ops,
13401 int from_tty, int enabled,
13402 int internal, unsigned flags)
13404 create_breakpoints_sal_default (gdbarch, canonical,
13405 std::move (cond_string),
13406 std::move (extra_string),
13408 disposition, thread, task,
13409 ignore_count, ops, from_tty,
13410 enabled, internal, flags);
13414 tracepoint_decode_location (struct breakpoint *b,
13415 const struct event_location *location,
13416 struct program_space *search_pspace,
13417 struct symtabs_and_lines *sals)
13419 decode_location_default (b, location, search_pspace, sals);
13422 struct breakpoint_ops tracepoint_breakpoint_ops;
13424 /* The breakpoint_ops structure to be use on tracepoints placed in a
13428 tracepoint_probe_create_sals_from_location
13429 (const struct event_location *location,
13430 struct linespec_result *canonical,
13431 enum bptype type_wanted)
13433 /* We use the same method for breakpoint on probes. */
13434 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
13438 tracepoint_probe_decode_location (struct breakpoint *b,
13439 const struct event_location *location,
13440 struct program_space *search_pspace,
13441 struct symtabs_and_lines *sals)
13443 /* We use the same method for breakpoint on probes. */
13444 bkpt_probe_decode_location (b, location, search_pspace, sals);
13447 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13449 /* Dprintf breakpoint_ops methods. */
13452 dprintf_re_set (struct breakpoint *b)
13454 breakpoint_re_set_default (b);
13456 /* extra_string should never be non-NULL for dprintf. */
13457 gdb_assert (b->extra_string != NULL);
13459 /* 1 - connect to target 1, that can run breakpoint commands.
13460 2 - create a dprintf, which resolves fine.
13461 3 - disconnect from target 1
13462 4 - connect to target 2, that can NOT run breakpoint commands.
13464 After steps #3/#4, you'll want the dprintf command list to
13465 be updated, because target 1 and 2 may well return different
13466 answers for target_can_run_breakpoint_commands().
13467 Given absence of finer grained resetting, we get to do
13468 it all the time. */
13469 if (b->extra_string != NULL)
13470 update_dprintf_command_list (b);
13473 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13476 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13478 fprintf_unfiltered (fp, "dprintf %s,%s",
13479 event_location_to_string (tp->location.get ()),
13481 print_recreate_thread (tp, fp);
13484 /* Implement the "after_condition_true" breakpoint_ops method for
13487 dprintf's are implemented with regular commands in their command
13488 list, but we run the commands here instead of before presenting the
13489 stop to the user, as dprintf's don't actually cause a stop. This
13490 also makes it so that the commands of multiple dprintfs at the same
13491 address are all handled. */
13494 dprintf_after_condition_true (struct bpstats *bs)
13496 struct cleanup *old_chain;
13497 struct bpstats tmp_bs = { NULL };
13498 struct bpstats *tmp_bs_p = &tmp_bs;
13500 /* dprintf's never cause a stop. This wasn't set in the
13501 check_status hook instead because that would make the dprintf's
13502 condition not be evaluated. */
13505 /* Run the command list here. Take ownership of it instead of
13506 copying. We never want these commands to run later in
13507 bpstat_do_actions, if a breakpoint that causes a stop happens to
13508 be set at same address as this dprintf, or even if running the
13509 commands here throws. */
13510 tmp_bs.commands = bs->commands;
13511 bs->commands = NULL;
13512 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13514 bpstat_do_actions_1 (&tmp_bs_p);
13516 /* 'tmp_bs.commands' will usually be NULL by now, but
13517 bpstat_do_actions_1 may return early without processing the whole
13519 do_cleanups (old_chain);
13522 /* The breakpoint_ops structure to be used on static tracepoints with
13526 strace_marker_create_sals_from_location (const struct event_location *location,
13527 struct linespec_result *canonical,
13528 enum bptype type_wanted)
13530 struct linespec_sals lsal;
13531 const char *arg_start, *arg;
13533 struct cleanup *cleanup;
13535 arg = arg_start = get_linespec_location (location);
13536 lsal.sals = decode_static_tracepoint_spec (&arg);
13538 str = savestring (arg_start, arg - arg_start);
13539 cleanup = make_cleanup (xfree, str);
13540 canonical->location = new_linespec_location (&str);
13541 do_cleanups (cleanup);
13544 = xstrdup (event_location_to_string (canonical->location.get ()));
13545 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13549 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13550 struct linespec_result *canonical,
13551 gdb::unique_xmalloc_ptr<char> cond_string,
13552 gdb::unique_xmalloc_ptr<char> extra_string,
13553 enum bptype type_wanted,
13554 enum bpdisp disposition,
13556 int task, int ignore_count,
13557 const struct breakpoint_ops *ops,
13558 int from_tty, int enabled,
13559 int internal, unsigned flags)
13562 struct linespec_sals *lsal = VEC_index (linespec_sals,
13563 canonical->sals, 0);
13565 /* If the user is creating a static tracepoint by marker id
13566 (strace -m MARKER_ID), then store the sals index, so that
13567 breakpoint_re_set can try to match up which of the newly
13568 found markers corresponds to this one, and, don't try to
13569 expand multiple locations for each sal, given than SALS
13570 already should contain all sals for MARKER_ID. */
13572 for (i = 0; i < lsal->sals.nelts; ++i)
13574 struct symtabs_and_lines expanded;
13575 struct tracepoint *tp;
13576 event_location_up location;
13578 expanded.nelts = 1;
13579 expanded.sals = &lsal->sals.sals[i];
13581 location = copy_event_location (canonical->location.get ());
13583 tp = new tracepoint ();
13584 init_breakpoint_sal (tp, gdbarch, expanded,
13585 std::move (location), NULL,
13586 std::move (cond_string),
13587 std::move (extra_string),
13588 type_wanted, disposition,
13589 thread, task, ignore_count, ops,
13590 from_tty, enabled, internal, flags,
13591 canonical->special_display);
13592 /* Given that its possible to have multiple markers with
13593 the same string id, if the user is creating a static
13594 tracepoint by marker id ("strace -m MARKER_ID"), then
13595 store the sals index, so that breakpoint_re_set can
13596 try to match up which of the newly found markers
13597 corresponds to this one */
13598 tp->static_trace_marker_id_idx = i;
13600 install_breakpoint (internal, tp, 0);
13605 strace_marker_decode_location (struct breakpoint *b,
13606 const struct event_location *location,
13607 struct program_space *search_pspace,
13608 struct symtabs_and_lines *sals)
13610 struct tracepoint *tp = (struct tracepoint *) b;
13611 const char *s = get_linespec_location (location);
13613 *sals = decode_static_tracepoint_spec (&s);
13614 if (sals->nelts > tp->static_trace_marker_id_idx)
13616 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13620 error (_("marker %s not found"), tp->static_trace_marker_id);
13623 static struct breakpoint_ops strace_marker_breakpoint_ops;
13626 strace_marker_p (struct breakpoint *b)
13628 return b->ops == &strace_marker_breakpoint_ops;
13631 /* Delete a breakpoint and clean up all traces of it in the data
13635 delete_breakpoint (struct breakpoint *bpt)
13637 struct breakpoint *b;
13639 gdb_assert (bpt != NULL);
13641 /* Has this bp already been deleted? This can happen because
13642 multiple lists can hold pointers to bp's. bpstat lists are
13645 One example of this happening is a watchpoint's scope bp. When
13646 the scope bp triggers, we notice that the watchpoint is out of
13647 scope, and delete it. We also delete its scope bp. But the
13648 scope bp is marked "auto-deleting", and is already on a bpstat.
13649 That bpstat is then checked for auto-deleting bp's, which are
13652 A real solution to this problem might involve reference counts in
13653 bp's, and/or giving them pointers back to their referencing
13654 bpstat's, and teaching delete_breakpoint to only free a bp's
13655 storage when no more references were extent. A cheaper bandaid
13657 if (bpt->type == bp_none)
13660 /* At least avoid this stale reference until the reference counting
13661 of breakpoints gets resolved. */
13662 if (bpt->related_breakpoint != bpt)
13664 struct breakpoint *related;
13665 struct watchpoint *w;
13667 if (bpt->type == bp_watchpoint_scope)
13668 w = (struct watchpoint *) bpt->related_breakpoint;
13669 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13670 w = (struct watchpoint *) bpt;
13674 watchpoint_del_at_next_stop (w);
13676 /* Unlink bpt from the bpt->related_breakpoint ring. */
13677 for (related = bpt; related->related_breakpoint != bpt;
13678 related = related->related_breakpoint);
13679 related->related_breakpoint = bpt->related_breakpoint;
13680 bpt->related_breakpoint = bpt;
13683 /* watch_command_1 creates a watchpoint but only sets its number if
13684 update_watchpoint succeeds in creating its bp_locations. If there's
13685 a problem in that process, we'll be asked to delete the half-created
13686 watchpoint. In that case, don't announce the deletion. */
13688 observer_notify_breakpoint_deleted (bpt);
13690 if (breakpoint_chain == bpt)
13691 breakpoint_chain = bpt->next;
13693 ALL_BREAKPOINTS (b)
13694 if (b->next == bpt)
13696 b->next = bpt->next;
13700 /* Be sure no bpstat's are pointing at the breakpoint after it's
13702 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13703 in all threads for now. Note that we cannot just remove bpstats
13704 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13705 commands are associated with the bpstat; if we remove it here,
13706 then the later call to bpstat_do_actions (&stop_bpstat); in
13707 event-top.c won't do anything, and temporary breakpoints with
13708 commands won't work. */
13710 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13712 /* Now that breakpoint is removed from breakpoint list, update the
13713 global location list. This will remove locations that used to
13714 belong to this breakpoint. Do this before freeing the breakpoint
13715 itself, since remove_breakpoint looks at location's owner. It
13716 might be better design to have location completely
13717 self-contained, but it's not the case now. */
13718 update_global_location_list (UGLL_DONT_INSERT);
13720 /* On the chance that someone will soon try again to delete this
13721 same bp, we mark it as deleted before freeing its storage. */
13722 bpt->type = bp_none;
13727 do_delete_breakpoint_cleanup (void *b)
13729 delete_breakpoint ((struct breakpoint *) b);
13733 make_cleanup_delete_breakpoint (struct breakpoint *b)
13735 return make_cleanup (do_delete_breakpoint_cleanup, b);
13738 /* Iterator function to call a user-provided callback function once
13739 for each of B and its related breakpoints. */
13742 iterate_over_related_breakpoints (struct breakpoint *b,
13743 void (*function) (struct breakpoint *,
13747 struct breakpoint *related;
13752 struct breakpoint *next;
13754 /* FUNCTION may delete RELATED. */
13755 next = related->related_breakpoint;
13757 if (next == related)
13759 /* RELATED is the last ring entry. */
13760 function (related, data);
13762 /* FUNCTION may have deleted it, so we'd never reach back to
13763 B. There's nothing left to do anyway, so just break
13768 function (related, data);
13772 while (related != b);
13776 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13778 delete_breakpoint (b);
13781 /* A callback for map_breakpoint_numbers that calls
13782 delete_breakpoint. */
13785 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13787 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13791 delete_command (char *arg, int from_tty)
13793 struct breakpoint *b, *b_tmp;
13799 int breaks_to_delete = 0;
13801 /* Delete all breakpoints if no argument. Do not delete
13802 internal breakpoints, these have to be deleted with an
13803 explicit breakpoint number argument. */
13804 ALL_BREAKPOINTS (b)
13805 if (user_breakpoint_p (b))
13807 breaks_to_delete = 1;
13811 /* Ask user only if there are some breakpoints to delete. */
13813 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13815 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13816 if (user_breakpoint_p (b))
13817 delete_breakpoint (b);
13821 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13824 /* Return true if all locations of B bound to PSPACE are pending. If
13825 PSPACE is NULL, all locations of all program spaces are
13829 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
13831 struct bp_location *loc;
13833 for (loc = b->loc; loc != NULL; loc = loc->next)
13834 if ((pspace == NULL
13835 || loc->pspace == pspace)
13836 && !loc->shlib_disabled
13837 && !loc->pspace->executing_startup)
13842 /* Subroutine of update_breakpoint_locations to simplify it.
13843 Return non-zero if multiple fns in list LOC have the same name.
13844 Null names are ignored. */
13847 ambiguous_names_p (struct bp_location *loc)
13849 struct bp_location *l;
13850 htab_t htab = htab_create_alloc (13, htab_hash_string,
13851 (int (*) (const void *,
13852 const void *)) streq,
13853 NULL, xcalloc, xfree);
13855 for (l = loc; l != NULL; l = l->next)
13858 const char *name = l->function_name;
13860 /* Allow for some names to be NULL, ignore them. */
13864 slot = (const char **) htab_find_slot (htab, (const void *) name,
13866 /* NOTE: We can assume slot != NULL here because xcalloc never
13870 htab_delete (htab);
13876 htab_delete (htab);
13880 /* When symbols change, it probably means the sources changed as well,
13881 and it might mean the static tracepoint markers are no longer at
13882 the same address or line numbers they used to be at last we
13883 checked. Losing your static tracepoints whenever you rebuild is
13884 undesirable. This function tries to resync/rematch gdb static
13885 tracepoints with the markers on the target, for static tracepoints
13886 that have not been set by marker id. Static tracepoint that have
13887 been set by marker id are reset by marker id in breakpoint_re_set.
13890 1) For a tracepoint set at a specific address, look for a marker at
13891 the old PC. If one is found there, assume to be the same marker.
13892 If the name / string id of the marker found is different from the
13893 previous known name, assume that means the user renamed the marker
13894 in the sources, and output a warning.
13896 2) For a tracepoint set at a given line number, look for a marker
13897 at the new address of the old line number. If one is found there,
13898 assume to be the same marker. If the name / string id of the
13899 marker found is different from the previous known name, assume that
13900 means the user renamed the marker in the sources, and output a
13903 3) If a marker is no longer found at the same address or line, it
13904 may mean the marker no longer exists. But it may also just mean
13905 the code changed a bit. Maybe the user added a few lines of code
13906 that made the marker move up or down (in line number terms). Ask
13907 the target for info about the marker with the string id as we knew
13908 it. If found, update line number and address in the matching
13909 static tracepoint. This will get confused if there's more than one
13910 marker with the same ID (possible in UST, although unadvised
13911 precisely because it confuses tools). */
13913 static struct symtab_and_line
13914 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13916 struct tracepoint *tp = (struct tracepoint *) b;
13917 struct static_tracepoint_marker marker;
13922 find_line_pc (sal.symtab, sal.line, &pc);
13924 if (target_static_tracepoint_marker_at (pc, &marker))
13926 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13927 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13929 tp->static_trace_marker_id, marker.str_id);
13931 xfree (tp->static_trace_marker_id);
13932 tp->static_trace_marker_id = xstrdup (marker.str_id);
13933 release_static_tracepoint_marker (&marker);
13938 /* Old marker wasn't found on target at lineno. Try looking it up
13940 if (!sal.explicit_pc
13942 && sal.symtab != NULL
13943 && tp->static_trace_marker_id != NULL)
13945 VEC(static_tracepoint_marker_p) *markers;
13948 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13950 if (!VEC_empty(static_tracepoint_marker_p, markers))
13952 struct symtab_and_line sal2;
13953 struct symbol *sym;
13954 struct static_tracepoint_marker *tpmarker;
13955 struct ui_out *uiout = current_uiout;
13956 struct explicit_location explicit_loc;
13958 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13960 xfree (tp->static_trace_marker_id);
13961 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13963 warning (_("marker for static tracepoint %d (%s) not "
13964 "found at previous line number"),
13965 b->number, tp->static_trace_marker_id);
13969 sal2.pc = tpmarker->address;
13971 sal2 = find_pc_line (tpmarker->address, 0);
13972 sym = find_pc_sect_function (tpmarker->address, NULL);
13973 uiout->text ("Now in ");
13976 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
13977 uiout->text (" at ");
13979 uiout->field_string ("file",
13980 symtab_to_filename_for_display (sal2.symtab));
13983 if (uiout->is_mi_like_p ())
13985 const char *fullname = symtab_to_fullname (sal2.symtab);
13987 uiout->field_string ("fullname", fullname);
13990 uiout->field_int ("line", sal2.line);
13991 uiout->text ("\n");
13993 b->loc->line_number = sal2.line;
13994 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13996 b->location.reset (NULL);
13997 initialize_explicit_location (&explicit_loc);
13998 explicit_loc.source_filename
13999 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
14000 explicit_loc.line_offset.offset = b->loc->line_number;
14001 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
14002 b->location = new_explicit_location (&explicit_loc);
14004 /* Might be nice to check if function changed, and warn if
14007 release_static_tracepoint_marker (tpmarker);
14013 /* Returns 1 iff locations A and B are sufficiently same that
14014 we don't need to report breakpoint as changed. */
14017 locations_are_equal (struct bp_location *a, struct bp_location *b)
14021 if (a->address != b->address)
14024 if (a->shlib_disabled != b->shlib_disabled)
14027 if (a->enabled != b->enabled)
14034 if ((a == NULL) != (b == NULL))
14040 /* Split all locations of B that are bound to PSPACE out of B's
14041 location list to a separate list and return that list's head. If
14042 PSPACE is NULL, hoist out all locations of B. */
14044 static struct bp_location *
14045 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
14047 struct bp_location head;
14048 struct bp_location *i = b->loc;
14049 struct bp_location **i_link = &b->loc;
14050 struct bp_location *hoisted = &head;
14052 if (pspace == NULL)
14063 if (i->pspace == pspace)
14078 /* Create new breakpoint locations for B (a hardware or software
14079 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14080 zero, then B is a ranged breakpoint. Only recreates locations for
14081 FILTER_PSPACE. Locations of other program spaces are left
14085 update_breakpoint_locations (struct breakpoint *b,
14086 struct program_space *filter_pspace,
14087 struct symtabs_and_lines sals,
14088 struct symtabs_and_lines sals_end)
14091 struct bp_location *existing_locations;
14093 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14095 /* Ranged breakpoints have only one start location and one end
14097 b->enable_state = bp_disabled;
14098 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14099 "multiple locations found\n"),
14104 /* If there's no new locations, and all existing locations are
14105 pending, don't do anything. This optimizes the common case where
14106 all locations are in the same shared library, that was unloaded.
14107 We'd like to retain the location, so that when the library is
14108 loaded again, we don't loose the enabled/disabled status of the
14109 individual locations. */
14110 if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0)
14113 existing_locations = hoist_existing_locations (b, filter_pspace);
14115 for (i = 0; i < sals.nelts; ++i)
14117 struct bp_location *new_loc;
14119 switch_to_program_space_and_thread (sals.sals[i].pspace);
14121 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14123 /* Reparse conditions, they might contain references to the
14125 if (b->cond_string != NULL)
14129 s = b->cond_string;
14132 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14133 block_for_pc (sals.sals[i].pc),
14136 CATCH (e, RETURN_MASK_ERROR)
14138 warning (_("failed to reevaluate condition "
14139 "for breakpoint %d: %s"),
14140 b->number, e.message);
14141 new_loc->enabled = 0;
14146 if (sals_end.nelts)
14148 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14150 new_loc->length = end - sals.sals[0].pc + 1;
14154 /* If possible, carry over 'disable' status from existing
14157 struct bp_location *e = existing_locations;
14158 /* If there are multiple breakpoints with the same function name,
14159 e.g. for inline functions, comparing function names won't work.
14160 Instead compare pc addresses; this is just a heuristic as things
14161 may have moved, but in practice it gives the correct answer
14162 often enough until a better solution is found. */
14163 int have_ambiguous_names = ambiguous_names_p (b->loc);
14165 for (; e; e = e->next)
14167 if (!e->enabled && e->function_name)
14169 struct bp_location *l = b->loc;
14170 if (have_ambiguous_names)
14172 for (; l; l = l->next)
14173 if (breakpoint_locations_match (e, l))
14181 for (; l; l = l->next)
14182 if (l->function_name
14183 && strcmp (e->function_name, l->function_name) == 0)
14193 if (!locations_are_equal (existing_locations, b->loc))
14194 observer_notify_breakpoint_modified (b);
14197 /* Find the SaL locations corresponding to the given LOCATION.
14198 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14200 static struct symtabs_and_lines
14201 location_to_sals (struct breakpoint *b, struct event_location *location,
14202 struct program_space *search_pspace, int *found)
14204 struct symtabs_and_lines sals = {0};
14205 struct gdb_exception exception = exception_none;
14207 gdb_assert (b->ops != NULL);
14211 b->ops->decode_location (b, location, search_pspace, &sals);
14213 CATCH (e, RETURN_MASK_ERROR)
14215 int not_found_and_ok = 0;
14219 /* For pending breakpoints, it's expected that parsing will
14220 fail until the right shared library is loaded. User has
14221 already told to create pending breakpoints and don't need
14222 extra messages. If breakpoint is in bp_shlib_disabled
14223 state, then user already saw the message about that
14224 breakpoint being disabled, and don't want to see more
14226 if (e.error == NOT_FOUND_ERROR
14227 && (b->condition_not_parsed
14229 && search_pspace != NULL
14230 && b->loc->pspace != search_pspace)
14231 || (b->loc && b->loc->shlib_disabled)
14232 || (b->loc && b->loc->pspace->executing_startup)
14233 || b->enable_state == bp_disabled))
14234 not_found_and_ok = 1;
14236 if (!not_found_and_ok)
14238 /* We surely don't want to warn about the same breakpoint
14239 10 times. One solution, implemented here, is disable
14240 the breakpoint on error. Another solution would be to
14241 have separate 'warning emitted' flag. Since this
14242 happens only when a binary has changed, I don't know
14243 which approach is better. */
14244 b->enable_state = bp_disabled;
14245 throw_exception (e);
14250 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
14254 for (i = 0; i < sals.nelts; ++i)
14255 resolve_sal_pc (&sals.sals[i]);
14256 if (b->condition_not_parsed && b->extra_string != NULL)
14258 char *cond_string, *extra_string;
14261 find_condition_and_thread (b->extra_string, sals.sals[0].pc,
14262 &cond_string, &thread, &task,
14264 gdb_assert (b->cond_string == NULL);
14266 b->cond_string = cond_string;
14267 b->thread = thread;
14271 xfree (b->extra_string);
14272 b->extra_string = extra_string;
14274 b->condition_not_parsed = 0;
14277 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14278 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14288 /* The default re_set method, for typical hardware or software
14289 breakpoints. Reevaluate the breakpoint and recreate its
14293 breakpoint_re_set_default (struct breakpoint *b)
14296 struct symtabs_and_lines sals, sals_end;
14297 struct symtabs_and_lines expanded = {0};
14298 struct symtabs_and_lines expanded_end = {0};
14299 struct program_space *filter_pspace = current_program_space;
14301 sals = location_to_sals (b, b->location.get (), filter_pspace, &found);
14304 make_cleanup (xfree, sals.sals);
14308 if (b->location_range_end != NULL)
14310 sals_end = location_to_sals (b, b->location_range_end.get (),
14311 filter_pspace, &found);
14314 make_cleanup (xfree, sals_end.sals);
14315 expanded_end = sals_end;
14319 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
14322 /* Default method for creating SALs from an address string. It basically
14323 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14326 create_sals_from_location_default (const struct event_location *location,
14327 struct linespec_result *canonical,
14328 enum bptype type_wanted)
14330 parse_breakpoint_sals (location, canonical);
14333 /* Call create_breakpoints_sal for the given arguments. This is the default
14334 function for the `create_breakpoints_sal' method of
14338 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14339 struct linespec_result *canonical,
14340 gdb::unique_xmalloc_ptr<char> cond_string,
14341 gdb::unique_xmalloc_ptr<char> extra_string,
14342 enum bptype type_wanted,
14343 enum bpdisp disposition,
14345 int task, int ignore_count,
14346 const struct breakpoint_ops *ops,
14347 int from_tty, int enabled,
14348 int internal, unsigned flags)
14350 create_breakpoints_sal (gdbarch, canonical,
14351 std::move (cond_string),
14352 std::move (extra_string),
14353 type_wanted, disposition,
14354 thread, task, ignore_count, ops, from_tty,
14355 enabled, internal, flags);
14358 /* Decode the line represented by S by calling decode_line_full. This is the
14359 default function for the `decode_location' method of breakpoint_ops. */
14362 decode_location_default (struct breakpoint *b,
14363 const struct event_location *location,
14364 struct program_space *search_pspace,
14365 struct symtabs_and_lines *sals)
14367 struct linespec_result canonical;
14369 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
14370 (struct symtab *) NULL, 0,
14371 &canonical, multiple_symbols_all,
14374 /* We should get 0 or 1 resulting SALs. */
14375 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14377 if (VEC_length (linespec_sals, canonical.sals) > 0)
14379 struct linespec_sals *lsal;
14381 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14382 *sals = lsal->sals;
14383 /* Arrange it so the destructor does not free the
14385 lsal->sals.sals = NULL;
14389 /* Prepare the global context for a re-set of breakpoint B. */
14391 static struct cleanup *
14392 prepare_re_set_context (struct breakpoint *b)
14394 input_radix = b->input_radix;
14395 set_language (b->language);
14397 return make_cleanup (null_cleanup, NULL);
14400 /* Reset a breakpoint given it's struct breakpoint * BINT.
14401 The value we return ends up being the return value from catch_errors.
14402 Unused in this case. */
14405 breakpoint_re_set_one (void *bint)
14407 /* Get past catch_errs. */
14408 struct breakpoint *b = (struct breakpoint *) bint;
14409 struct cleanup *cleanups;
14411 cleanups = prepare_re_set_context (b);
14412 b->ops->re_set (b);
14413 do_cleanups (cleanups);
14417 /* Re-set breakpoint locations for the current program space.
14418 Locations bound to other program spaces are left untouched. */
14421 breakpoint_re_set (void)
14423 struct breakpoint *b, *b_tmp;
14424 enum language save_language;
14425 int save_input_radix;
14427 save_language = current_language->la_language;
14428 save_input_radix = input_radix;
14431 scoped_restore_current_pspace_and_thread restore_pspace_thread;
14433 /* Note: we must not try to insert locations until after all
14434 breakpoints have been re-set. Otherwise, e.g., when re-setting
14435 breakpoint 1, we'd insert the locations of breakpoint 2, which
14436 hadn't been re-set yet, and thus may have stale locations. */
14438 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14440 /* Format possible error msg. */
14441 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14443 struct cleanup *cleanups = make_cleanup (xfree, message);
14444 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14445 do_cleanups (cleanups);
14447 set_language (save_language);
14448 input_radix = save_input_radix;
14450 jit_breakpoint_re_set ();
14453 create_overlay_event_breakpoint ();
14454 create_longjmp_master_breakpoint ();
14455 create_std_terminate_master_breakpoint ();
14456 create_exception_master_breakpoint ();
14458 /* Now we can insert. */
14459 update_global_location_list (UGLL_MAY_INSERT);
14462 /* Reset the thread number of this breakpoint:
14464 - If the breakpoint is for all threads, leave it as-is.
14465 - Else, reset it to the current thread for inferior_ptid. */
14467 breakpoint_re_set_thread (struct breakpoint *b)
14469 if (b->thread != -1)
14471 if (in_thread_list (inferior_ptid))
14472 b->thread = ptid_to_global_thread_id (inferior_ptid);
14474 /* We're being called after following a fork. The new fork is
14475 selected as current, and unless this was a vfork will have a
14476 different program space from the original thread. Reset that
14478 b->loc->pspace = current_program_space;
14482 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14483 If from_tty is nonzero, it prints a message to that effect,
14484 which ends with a period (no newline). */
14487 set_ignore_count (int bptnum, int count, int from_tty)
14489 struct breakpoint *b;
14494 ALL_BREAKPOINTS (b)
14495 if (b->number == bptnum)
14497 if (is_tracepoint (b))
14499 if (from_tty && count != 0)
14500 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14505 b->ignore_count = count;
14509 printf_filtered (_("Will stop next time "
14510 "breakpoint %d is reached."),
14512 else if (count == 1)
14513 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14516 printf_filtered (_("Will ignore next %d "
14517 "crossings of breakpoint %d."),
14520 observer_notify_breakpoint_modified (b);
14524 error (_("No breakpoint number %d."), bptnum);
14527 /* Command to set ignore-count of breakpoint N to COUNT. */
14530 ignore_command (char *args, int from_tty)
14536 error_no_arg (_("a breakpoint number"));
14538 num = get_number (&p);
14540 error (_("bad breakpoint number: '%s'"), args);
14542 error (_("Second argument (specified ignore-count) is missing."));
14544 set_ignore_count (num,
14545 longest_to_int (value_as_long (parse_and_eval (p))),
14548 printf_filtered ("\n");
14551 /* Call FUNCTION on each of the breakpoints
14552 whose numbers are given in ARGS. */
14555 map_breakpoint_numbers (const char *args,
14556 void (*function) (struct breakpoint *,
14561 struct breakpoint *b, *tmp;
14563 if (args == 0 || *args == '\0')
14564 error_no_arg (_("one or more breakpoint numbers"));
14566 number_or_range_parser parser (args);
14568 while (!parser.finished ())
14570 const char *p = parser.cur_tok ();
14571 bool match = false;
14573 num = parser.get_number ();
14576 warning (_("bad breakpoint number at or near '%s'"), p);
14580 ALL_BREAKPOINTS_SAFE (b, tmp)
14581 if (b->number == num)
14584 function (b, data);
14588 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14593 static struct bp_location *
14594 find_location_by_number (char *number)
14596 char *dot = strchr (number, '.');
14600 struct breakpoint *b;
14601 struct bp_location *loc;
14606 bp_num = get_number (&p1);
14608 error (_("Bad breakpoint number '%s'"), number);
14610 ALL_BREAKPOINTS (b)
14611 if (b->number == bp_num)
14616 if (!b || b->number != bp_num)
14617 error (_("Bad breakpoint number '%s'"), number);
14620 loc_num = get_number (&p1);
14622 error (_("Bad breakpoint location number '%s'"), number);
14626 for (;loc_num && loc; --loc_num, loc = loc->next)
14629 error (_("Bad breakpoint location number '%s'"), dot+1);
14635 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14636 If from_tty is nonzero, it prints a message to that effect,
14637 which ends with a period (no newline). */
14640 disable_breakpoint (struct breakpoint *bpt)
14642 /* Never disable a watchpoint scope breakpoint; we want to
14643 hit them when we leave scope so we can delete both the
14644 watchpoint and its scope breakpoint at that time. */
14645 if (bpt->type == bp_watchpoint_scope)
14648 bpt->enable_state = bp_disabled;
14650 /* Mark breakpoint locations modified. */
14651 mark_breakpoint_modified (bpt);
14653 if (target_supports_enable_disable_tracepoint ()
14654 && current_trace_status ()->running && is_tracepoint (bpt))
14656 struct bp_location *location;
14658 for (location = bpt->loc; location; location = location->next)
14659 target_disable_tracepoint (location);
14662 update_global_location_list (UGLL_DONT_INSERT);
14664 observer_notify_breakpoint_modified (bpt);
14667 /* A callback for iterate_over_related_breakpoints. */
14670 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14672 disable_breakpoint (b);
14675 /* A callback for map_breakpoint_numbers that calls
14676 disable_breakpoint. */
14679 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14681 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14685 disable_command (char *args, int from_tty)
14689 struct breakpoint *bpt;
14691 ALL_BREAKPOINTS (bpt)
14692 if (user_breakpoint_p (bpt))
14693 disable_breakpoint (bpt);
14697 char *num = extract_arg (&args);
14701 if (strchr (num, '.'))
14703 struct bp_location *loc = find_location_by_number (num);
14710 mark_breakpoint_location_modified (loc);
14712 if (target_supports_enable_disable_tracepoint ()
14713 && current_trace_status ()->running && loc->owner
14714 && is_tracepoint (loc->owner))
14715 target_disable_tracepoint (loc);
14717 update_global_location_list (UGLL_DONT_INSERT);
14720 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14721 num = extract_arg (&args);
14727 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14730 int target_resources_ok;
14732 if (bpt->type == bp_hardware_breakpoint)
14735 i = hw_breakpoint_used_count ();
14736 target_resources_ok =
14737 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14739 if (target_resources_ok == 0)
14740 error (_("No hardware breakpoint support in the target."));
14741 else if (target_resources_ok < 0)
14742 error (_("Hardware breakpoints used exceeds limit."));
14745 if (is_watchpoint (bpt))
14747 /* Initialize it just to avoid a GCC false warning. */
14748 enum enable_state orig_enable_state = bp_disabled;
14752 struct watchpoint *w = (struct watchpoint *) bpt;
14754 orig_enable_state = bpt->enable_state;
14755 bpt->enable_state = bp_enabled;
14756 update_watchpoint (w, 1 /* reparse */);
14758 CATCH (e, RETURN_MASK_ALL)
14760 bpt->enable_state = orig_enable_state;
14761 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14768 bpt->enable_state = bp_enabled;
14770 /* Mark breakpoint locations modified. */
14771 mark_breakpoint_modified (bpt);
14773 if (target_supports_enable_disable_tracepoint ()
14774 && current_trace_status ()->running && is_tracepoint (bpt))
14776 struct bp_location *location;
14778 for (location = bpt->loc; location; location = location->next)
14779 target_enable_tracepoint (location);
14782 bpt->disposition = disposition;
14783 bpt->enable_count = count;
14784 update_global_location_list (UGLL_MAY_INSERT);
14786 observer_notify_breakpoint_modified (bpt);
14791 enable_breakpoint (struct breakpoint *bpt)
14793 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14797 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14799 enable_breakpoint (bpt);
14802 /* A callback for map_breakpoint_numbers that calls
14803 enable_breakpoint. */
14806 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14808 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14811 /* The enable command enables the specified breakpoints (or all defined
14812 breakpoints) so they once again become (or continue to be) effective
14813 in stopping the inferior. */
14816 enable_command (char *args, int from_tty)
14820 struct breakpoint *bpt;
14822 ALL_BREAKPOINTS (bpt)
14823 if (user_breakpoint_p (bpt))
14824 enable_breakpoint (bpt);
14828 char *num = extract_arg (&args);
14832 if (strchr (num, '.'))
14834 struct bp_location *loc = find_location_by_number (num);
14841 mark_breakpoint_location_modified (loc);
14843 if (target_supports_enable_disable_tracepoint ()
14844 && current_trace_status ()->running && loc->owner
14845 && is_tracepoint (loc->owner))
14846 target_enable_tracepoint (loc);
14848 update_global_location_list (UGLL_MAY_INSERT);
14851 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
14852 num = extract_arg (&args);
14857 /* This struct packages up disposition data for application to multiple
14867 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14869 struct disp_data disp_data = *(struct disp_data *) arg;
14871 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14875 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14877 struct disp_data disp = { disp_disable, 1 };
14879 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14883 enable_once_command (char *args, int from_tty)
14885 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14889 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14891 struct disp_data disp = { disp_disable, *(int *) countptr };
14893 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14897 enable_count_command (char *args, int from_tty)
14902 error_no_arg (_("hit count"));
14904 count = get_number (&args);
14906 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14910 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14912 struct disp_data disp = { disp_del, 1 };
14914 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14918 enable_delete_command (char *args, int from_tty)
14920 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14924 set_breakpoint_cmd (char *args, int from_tty)
14929 show_breakpoint_cmd (char *args, int from_tty)
14933 /* Invalidate last known value of any hardware watchpoint if
14934 the memory which that value represents has been written to by
14938 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14939 CORE_ADDR addr, ssize_t len,
14940 const bfd_byte *data)
14942 struct breakpoint *bp;
14944 ALL_BREAKPOINTS (bp)
14945 if (bp->enable_state == bp_enabled
14946 && bp->type == bp_hardware_watchpoint)
14948 struct watchpoint *wp = (struct watchpoint *) bp;
14950 if (wp->val_valid && wp->val)
14952 struct bp_location *loc;
14954 for (loc = bp->loc; loc != NULL; loc = loc->next)
14955 if (loc->loc_type == bp_loc_hardware_watchpoint
14956 && loc->address + loc->length > addr
14957 && addr + len > loc->address)
14959 value_free (wp->val);
14967 /* Create and insert a breakpoint for software single step. */
14970 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14971 struct address_space *aspace,
14974 struct thread_info *tp = inferior_thread ();
14975 struct symtab_and_line sal;
14976 CORE_ADDR pc = next_pc;
14978 if (tp->control.single_step_breakpoints == NULL)
14980 tp->control.single_step_breakpoints
14981 = new_single_step_breakpoint (tp->global_num, gdbarch);
14984 sal = find_pc_line (pc, 0);
14986 sal.section = find_pc_overlay (pc);
14987 sal.explicit_pc = 1;
14988 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
14990 update_global_location_list (UGLL_INSERT);
14993 /* Insert single step breakpoints according to the current state. */
14996 insert_single_step_breakpoints (struct gdbarch *gdbarch)
14998 struct regcache *regcache = get_current_regcache ();
14999 std::vector<CORE_ADDR> next_pcs;
15001 next_pcs = gdbarch_software_single_step (gdbarch, regcache);
15003 if (!next_pcs.empty ())
15005 struct frame_info *frame = get_current_frame ();
15006 struct address_space *aspace = get_frame_address_space (frame);
15008 for (CORE_ADDR pc : next_pcs)
15009 insert_single_step_breakpoint (gdbarch, aspace, pc);
15017 /* See breakpoint.h. */
15020 breakpoint_has_location_inserted_here (struct breakpoint *bp,
15021 struct address_space *aspace,
15024 struct bp_location *loc;
15026 for (loc = bp->loc; loc != NULL; loc = loc->next)
15028 && breakpoint_location_address_match (loc, aspace, pc))
15034 /* Check whether a software single-step breakpoint is inserted at
15038 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15041 struct breakpoint *bpt;
15043 ALL_BREAKPOINTS (bpt)
15045 if (bpt->type == bp_single_step
15046 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
15052 /* Tracepoint-specific operations. */
15054 /* Set tracepoint count to NUM. */
15056 set_tracepoint_count (int num)
15058 tracepoint_count = num;
15059 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15063 trace_command (char *arg, int from_tty)
15065 struct breakpoint_ops *ops;
15067 event_location_up location = string_to_event_location (&arg,
15069 if (location != NULL
15070 && event_location_type (location.get ()) == PROBE_LOCATION)
15071 ops = &tracepoint_probe_breakpoint_ops;
15073 ops = &tracepoint_breakpoint_ops;
15075 create_breakpoint (get_current_arch (),
15077 NULL, 0, arg, 1 /* parse arg */,
15079 bp_tracepoint /* type_wanted */,
15080 0 /* Ignore count */,
15081 pending_break_support,
15085 0 /* internal */, 0);
15089 ftrace_command (char *arg, int from_tty)
15091 event_location_up location = string_to_event_location (&arg,
15093 create_breakpoint (get_current_arch (),
15095 NULL, 0, arg, 1 /* parse arg */,
15097 bp_fast_tracepoint /* type_wanted */,
15098 0 /* Ignore count */,
15099 pending_break_support,
15100 &tracepoint_breakpoint_ops,
15103 0 /* internal */, 0);
15106 /* strace command implementation. Creates a static tracepoint. */
15109 strace_command (char *arg, int from_tty)
15111 struct breakpoint_ops *ops;
15112 event_location_up location;
15113 struct cleanup *back_to;
15115 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15116 or with a normal static tracepoint. */
15117 if (arg && startswith (arg, "-m") && isspace (arg[2]))
15119 ops = &strace_marker_breakpoint_ops;
15120 location = new_linespec_location (&arg);
15124 ops = &tracepoint_breakpoint_ops;
15125 location = string_to_event_location (&arg, current_language);
15128 create_breakpoint (get_current_arch (),
15130 NULL, 0, arg, 1 /* parse arg */,
15132 bp_static_tracepoint /* type_wanted */,
15133 0 /* Ignore count */,
15134 pending_break_support,
15138 0 /* internal */, 0);
15141 /* Set up a fake reader function that gets command lines from a linked
15142 list that was acquired during tracepoint uploading. */
15144 static struct uploaded_tp *this_utp;
15145 static int next_cmd;
15148 read_uploaded_action (void)
15152 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15159 /* Given information about a tracepoint as recorded on a target (which
15160 can be either a live system or a trace file), attempt to create an
15161 equivalent GDB tracepoint. This is not a reliable process, since
15162 the target does not necessarily have all the information used when
15163 the tracepoint was originally defined. */
15165 struct tracepoint *
15166 create_tracepoint_from_upload (struct uploaded_tp *utp)
15168 char *addr_str, small_buf[100];
15169 struct tracepoint *tp;
15171 if (utp->at_string)
15172 addr_str = utp->at_string;
15175 /* In the absence of a source location, fall back to raw
15176 address. Since there is no way to confirm that the address
15177 means the same thing as when the trace was started, warn the
15179 warning (_("Uploaded tracepoint %d has no "
15180 "source location, using raw address"),
15182 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15183 addr_str = small_buf;
15186 /* There's not much we can do with a sequence of bytecodes. */
15187 if (utp->cond && !utp->cond_string)
15188 warning (_("Uploaded tracepoint %d condition "
15189 "has no source form, ignoring it"),
15192 event_location_up location = string_to_event_location (&addr_str,
15194 if (!create_breakpoint (get_current_arch (),
15196 utp->cond_string, -1, addr_str,
15197 0 /* parse cond/thread */,
15199 utp->type /* type_wanted */,
15200 0 /* Ignore count */,
15201 pending_break_support,
15202 &tracepoint_breakpoint_ops,
15204 utp->enabled /* enabled */,
15206 CREATE_BREAKPOINT_FLAGS_INSERTED))
15209 /* Get the tracepoint we just created. */
15210 tp = get_tracepoint (tracepoint_count);
15211 gdb_assert (tp != NULL);
15215 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15218 trace_pass_command (small_buf, 0);
15221 /* If we have uploaded versions of the original commands, set up a
15222 special-purpose "reader" function and call the usual command line
15223 reader, then pass the result to the breakpoint command-setting
15225 if (!VEC_empty (char_ptr, utp->cmd_strings))
15227 command_line_up cmd_list;
15232 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15234 breakpoint_set_commands (tp, std::move (cmd_list));
15236 else if (!VEC_empty (char_ptr, utp->actions)
15237 || !VEC_empty (char_ptr, utp->step_actions))
15238 warning (_("Uploaded tracepoint %d actions "
15239 "have no source form, ignoring them"),
15242 /* Copy any status information that might be available. */
15243 tp->hit_count = utp->hit_count;
15244 tp->traceframe_usage = utp->traceframe_usage;
15249 /* Print information on tracepoint number TPNUM_EXP, or all if
15253 tracepoints_info (char *args, int from_tty)
15255 struct ui_out *uiout = current_uiout;
15258 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15260 if (num_printed == 0)
15262 if (args == NULL || *args == '\0')
15263 uiout->message ("No tracepoints.\n");
15265 uiout->message ("No tracepoint matching '%s'.\n", args);
15268 default_collect_info ();
15271 /* The 'enable trace' command enables tracepoints.
15272 Not supported by all targets. */
15274 enable_trace_command (char *args, int from_tty)
15276 enable_command (args, from_tty);
15279 /* The 'disable trace' command disables tracepoints.
15280 Not supported by all targets. */
15282 disable_trace_command (char *args, int from_tty)
15284 disable_command (args, from_tty);
15287 /* Remove a tracepoint (or all if no argument). */
15289 delete_trace_command (char *arg, int from_tty)
15291 struct breakpoint *b, *b_tmp;
15297 int breaks_to_delete = 0;
15299 /* Delete all breakpoints if no argument.
15300 Do not delete internal or call-dummy breakpoints, these
15301 have to be deleted with an explicit breakpoint number
15303 ALL_TRACEPOINTS (b)
15304 if (is_tracepoint (b) && user_breakpoint_p (b))
15306 breaks_to_delete = 1;
15310 /* Ask user only if there are some breakpoints to delete. */
15312 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15314 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15315 if (is_tracepoint (b) && user_breakpoint_p (b))
15316 delete_breakpoint (b);
15320 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15323 /* Helper function for trace_pass_command. */
15326 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15328 tp->pass_count = count;
15329 observer_notify_breakpoint_modified (tp);
15331 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15332 tp->number, count);
15335 /* Set passcount for tracepoint.
15337 First command argument is passcount, second is tracepoint number.
15338 If tracepoint number omitted, apply to most recently defined.
15339 Also accepts special argument "all". */
15342 trace_pass_command (char *args, int from_tty)
15344 struct tracepoint *t1;
15345 unsigned int count;
15347 if (args == 0 || *args == 0)
15348 error (_("passcount command requires an "
15349 "argument (count + optional TP num)"));
15351 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15353 args = skip_spaces (args);
15354 if (*args && strncasecmp (args, "all", 3) == 0)
15356 struct breakpoint *b;
15358 args += 3; /* Skip special argument "all". */
15360 error (_("Junk at end of arguments."));
15362 ALL_TRACEPOINTS (b)
15364 t1 = (struct tracepoint *) b;
15365 trace_pass_set_count (t1, count, from_tty);
15368 else if (*args == '\0')
15370 t1 = get_tracepoint_by_number (&args, NULL);
15372 trace_pass_set_count (t1, count, from_tty);
15376 number_or_range_parser parser (args);
15377 while (!parser.finished ())
15379 t1 = get_tracepoint_by_number (&args, &parser);
15381 trace_pass_set_count (t1, count, from_tty);
15386 struct tracepoint *
15387 get_tracepoint (int num)
15389 struct breakpoint *t;
15391 ALL_TRACEPOINTS (t)
15392 if (t->number == num)
15393 return (struct tracepoint *) t;
15398 /* Find the tracepoint with the given target-side number (which may be
15399 different from the tracepoint number after disconnecting and
15402 struct tracepoint *
15403 get_tracepoint_by_number_on_target (int num)
15405 struct breakpoint *b;
15407 ALL_TRACEPOINTS (b)
15409 struct tracepoint *t = (struct tracepoint *) b;
15411 if (t->number_on_target == num)
15418 /* Utility: parse a tracepoint number and look it up in the list.
15419 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15420 If the argument is missing, the most recent tracepoint
15421 (tracepoint_count) is returned. */
15423 struct tracepoint *
15424 get_tracepoint_by_number (char **arg,
15425 number_or_range_parser *parser)
15427 struct breakpoint *t;
15429 char *instring = arg == NULL ? NULL : *arg;
15431 if (parser != NULL)
15433 gdb_assert (!parser->finished ());
15434 tpnum = parser->get_number ();
15436 else if (arg == NULL || *arg == NULL || ! **arg)
15437 tpnum = tracepoint_count;
15439 tpnum = get_number (arg);
15443 if (instring && *instring)
15444 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15447 printf_filtered (_("No previous tracepoint\n"));
15451 ALL_TRACEPOINTS (t)
15452 if (t->number == tpnum)
15454 return (struct tracepoint *) t;
15457 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15462 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15464 if (b->thread != -1)
15465 fprintf_unfiltered (fp, " thread %d", b->thread);
15468 fprintf_unfiltered (fp, " task %d", b->task);
15470 fprintf_unfiltered (fp, "\n");
15473 /* Save information on user settable breakpoints (watchpoints, etc) to
15474 a new script file named FILENAME. If FILTER is non-NULL, call it
15475 on each breakpoint and only include the ones for which it returns
15479 save_breakpoints (char *filename, int from_tty,
15480 int (*filter) (const struct breakpoint *))
15482 struct breakpoint *tp;
15484 struct cleanup *cleanup;
15485 int extra_trace_bits = 0;
15487 if (filename == 0 || *filename == 0)
15488 error (_("Argument required (file name in which to save)"));
15490 /* See if we have anything to save. */
15491 ALL_BREAKPOINTS (tp)
15493 /* Skip internal and momentary breakpoints. */
15494 if (!user_breakpoint_p (tp))
15497 /* If we have a filter, only save the breakpoints it accepts. */
15498 if (filter && !filter (tp))
15503 if (is_tracepoint (tp))
15505 extra_trace_bits = 1;
15507 /* We can stop searching. */
15514 warning (_("Nothing to save."));
15518 filename = tilde_expand (filename);
15519 cleanup = make_cleanup (xfree, filename);
15523 if (!fp.open (filename, "w"))
15524 error (_("Unable to open file '%s' for saving (%s)"),
15525 filename, safe_strerror (errno));
15527 if (extra_trace_bits)
15528 save_trace_state_variables (&fp);
15530 ALL_BREAKPOINTS (tp)
15532 /* Skip internal and momentary breakpoints. */
15533 if (!user_breakpoint_p (tp))
15536 /* If we have a filter, only save the breakpoints it accepts. */
15537 if (filter && !filter (tp))
15540 tp->ops->print_recreate (tp, &fp);
15542 /* Note, we can't rely on tp->number for anything, as we can't
15543 assume the recreated breakpoint numbers will match. Use $bpnum
15546 if (tp->cond_string)
15547 fp.printf (" condition $bpnum %s\n", tp->cond_string);
15549 if (tp->ignore_count)
15550 fp.printf (" ignore $bpnum %d\n", tp->ignore_count);
15552 if (tp->type != bp_dprintf && tp->commands)
15554 fp.puts (" commands\n");
15556 current_uiout->redirect (&fp);
15559 print_command_lines (current_uiout, tp->commands->commands, 2);
15561 CATCH (ex, RETURN_MASK_ALL)
15563 current_uiout->redirect (NULL);
15564 throw_exception (ex);
15568 current_uiout->redirect (NULL);
15569 fp.puts (" end\n");
15572 if (tp->enable_state == bp_disabled)
15573 fp.puts ("disable $bpnum\n");
15575 /* If this is a multi-location breakpoint, check if the locations
15576 should be individually disabled. Watchpoint locations are
15577 special, and not user visible. */
15578 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15580 struct bp_location *loc;
15583 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15585 fp.printf ("disable $bpnum.%d\n", n);
15589 if (extra_trace_bits && *default_collect)
15590 fp.printf ("set default-collect %s\n", default_collect);
15593 printf_filtered (_("Saved to file '%s'.\n"), filename);
15594 do_cleanups (cleanup);
15597 /* The `save breakpoints' command. */
15600 save_breakpoints_command (char *args, int from_tty)
15602 save_breakpoints (args, from_tty, NULL);
15605 /* The `save tracepoints' command. */
15608 save_tracepoints_command (char *args, int from_tty)
15610 save_breakpoints (args, from_tty, is_tracepoint);
15613 /* Create a vector of all tracepoints. */
15615 VEC(breakpoint_p) *
15616 all_tracepoints (void)
15618 VEC(breakpoint_p) *tp_vec = 0;
15619 struct breakpoint *tp;
15621 ALL_TRACEPOINTS (tp)
15623 VEC_safe_push (breakpoint_p, tp_vec, tp);
15630 /* This help string is used to consolidate all the help string for specifying
15631 locations used by several commands. */
15633 #define LOCATION_HELP_STRING \
15634 "Linespecs are colon-separated lists of location parameters, such as\n\
15635 source filename, function name, label name, and line number.\n\
15636 Example: To specify the start of a label named \"the_top\" in the\n\
15637 function \"fact\" in the file \"factorial.c\", use\n\
15638 \"factorial.c:fact:the_top\".\n\
15640 Address locations begin with \"*\" and specify an exact address in the\n\
15641 program. Example: To specify the fourth byte past the start function\n\
15642 \"main\", use \"*main + 4\".\n\
15644 Explicit locations are similar to linespecs but use an option/argument\n\
15645 syntax to specify location parameters.\n\
15646 Example: To specify the start of the label named \"the_top\" in the\n\
15647 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15648 -function fact -label the_top\".\n"
15650 /* This help string is used for the break, hbreak, tbreak and thbreak
15651 commands. It is defined as a macro to prevent duplication.
15652 COMMAND should be a string constant containing the name of the
15655 #define BREAK_ARGS_HELP(command) \
15656 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15657 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15658 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15659 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15660 `-probe-dtrace' (for a DTrace probe).\n\
15661 LOCATION may be a linespec, address, or explicit location as described\n\
15664 With no LOCATION, uses current execution address of the selected\n\
15665 stack frame. This is useful for breaking on return to a stack frame.\n\
15667 THREADNUM is the number from \"info threads\".\n\
15668 CONDITION is a boolean expression.\n\
15669 \n" LOCATION_HELP_STRING "\n\
15670 Multiple breakpoints at one place are permitted, and useful if their\n\
15671 conditions are different.\n\
15673 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15675 /* List of subcommands for "catch". */
15676 static struct cmd_list_element *catch_cmdlist;
15678 /* List of subcommands for "tcatch". */
15679 static struct cmd_list_element *tcatch_cmdlist;
15682 add_catch_command (const char *name, const char *docstring,
15683 cmd_sfunc_ftype *sfunc,
15684 completer_ftype *completer,
15685 void *user_data_catch,
15686 void *user_data_tcatch)
15688 struct cmd_list_element *command;
15690 command = add_cmd (name, class_breakpoint, NULL, docstring,
15692 set_cmd_sfunc (command, sfunc);
15693 set_cmd_context (command, user_data_catch);
15694 set_cmd_completer (command, completer);
15696 command = add_cmd (name, class_breakpoint, NULL, docstring,
15698 set_cmd_sfunc (command, sfunc);
15699 set_cmd_context (command, user_data_tcatch);
15700 set_cmd_completer (command, completer);
15704 save_command (char *arg, int from_tty)
15706 printf_unfiltered (_("\"save\" must be followed by "
15707 "the name of a save subcommand.\n"));
15708 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15711 struct breakpoint *
15712 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15715 struct breakpoint *b, *b_tmp;
15717 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15719 if ((*callback) (b, data))
15726 /* Zero if any of the breakpoint's locations could be a location where
15727 functions have been inlined, nonzero otherwise. */
15730 is_non_inline_function (struct breakpoint *b)
15732 /* The shared library event breakpoint is set on the address of a
15733 non-inline function. */
15734 if (b->type == bp_shlib_event)
15740 /* Nonzero if the specified PC cannot be a location where functions
15741 have been inlined. */
15744 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15745 const struct target_waitstatus *ws)
15747 struct breakpoint *b;
15748 struct bp_location *bl;
15750 ALL_BREAKPOINTS (b)
15752 if (!is_non_inline_function (b))
15755 for (bl = b->loc; bl != NULL; bl = bl->next)
15757 if (!bl->shlib_disabled
15758 && bpstat_check_location (bl, aspace, pc, ws))
15766 /* Remove any references to OBJFILE which is going to be freed. */
15769 breakpoint_free_objfile (struct objfile *objfile)
15771 struct bp_location **locp, *loc;
15773 ALL_BP_LOCATIONS (loc, locp)
15774 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15775 loc->symtab = NULL;
15779 initialize_breakpoint_ops (void)
15781 static int initialized = 0;
15783 struct breakpoint_ops *ops;
15789 /* The breakpoint_ops structure to be inherit by all kinds of
15790 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15791 internal and momentary breakpoints, etc.). */
15792 ops = &bkpt_base_breakpoint_ops;
15793 *ops = base_breakpoint_ops;
15794 ops->re_set = bkpt_re_set;
15795 ops->insert_location = bkpt_insert_location;
15796 ops->remove_location = bkpt_remove_location;
15797 ops->breakpoint_hit = bkpt_breakpoint_hit;
15798 ops->create_sals_from_location = bkpt_create_sals_from_location;
15799 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15800 ops->decode_location = bkpt_decode_location;
15802 /* The breakpoint_ops structure to be used in regular breakpoints. */
15803 ops = &bkpt_breakpoint_ops;
15804 *ops = bkpt_base_breakpoint_ops;
15805 ops->re_set = bkpt_re_set;
15806 ops->resources_needed = bkpt_resources_needed;
15807 ops->print_it = bkpt_print_it;
15808 ops->print_mention = bkpt_print_mention;
15809 ops->print_recreate = bkpt_print_recreate;
15811 /* Ranged breakpoints. */
15812 ops = &ranged_breakpoint_ops;
15813 *ops = bkpt_breakpoint_ops;
15814 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15815 ops->resources_needed = resources_needed_ranged_breakpoint;
15816 ops->print_it = print_it_ranged_breakpoint;
15817 ops->print_one = print_one_ranged_breakpoint;
15818 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15819 ops->print_mention = print_mention_ranged_breakpoint;
15820 ops->print_recreate = print_recreate_ranged_breakpoint;
15822 /* Internal breakpoints. */
15823 ops = &internal_breakpoint_ops;
15824 *ops = bkpt_base_breakpoint_ops;
15825 ops->re_set = internal_bkpt_re_set;
15826 ops->check_status = internal_bkpt_check_status;
15827 ops->print_it = internal_bkpt_print_it;
15828 ops->print_mention = internal_bkpt_print_mention;
15830 /* Momentary breakpoints. */
15831 ops = &momentary_breakpoint_ops;
15832 *ops = bkpt_base_breakpoint_ops;
15833 ops->re_set = momentary_bkpt_re_set;
15834 ops->check_status = momentary_bkpt_check_status;
15835 ops->print_it = momentary_bkpt_print_it;
15836 ops->print_mention = momentary_bkpt_print_mention;
15838 /* Probe breakpoints. */
15839 ops = &bkpt_probe_breakpoint_ops;
15840 *ops = bkpt_breakpoint_ops;
15841 ops->insert_location = bkpt_probe_insert_location;
15842 ops->remove_location = bkpt_probe_remove_location;
15843 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
15844 ops->decode_location = bkpt_probe_decode_location;
15847 ops = &watchpoint_breakpoint_ops;
15848 *ops = base_breakpoint_ops;
15849 ops->re_set = re_set_watchpoint;
15850 ops->insert_location = insert_watchpoint;
15851 ops->remove_location = remove_watchpoint;
15852 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15853 ops->check_status = check_status_watchpoint;
15854 ops->resources_needed = resources_needed_watchpoint;
15855 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15856 ops->print_it = print_it_watchpoint;
15857 ops->print_mention = print_mention_watchpoint;
15858 ops->print_recreate = print_recreate_watchpoint;
15859 ops->explains_signal = explains_signal_watchpoint;
15861 /* Masked watchpoints. */
15862 ops = &masked_watchpoint_breakpoint_ops;
15863 *ops = watchpoint_breakpoint_ops;
15864 ops->insert_location = insert_masked_watchpoint;
15865 ops->remove_location = remove_masked_watchpoint;
15866 ops->resources_needed = resources_needed_masked_watchpoint;
15867 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15868 ops->print_it = print_it_masked_watchpoint;
15869 ops->print_one_detail = print_one_detail_masked_watchpoint;
15870 ops->print_mention = print_mention_masked_watchpoint;
15871 ops->print_recreate = print_recreate_masked_watchpoint;
15874 ops = &tracepoint_breakpoint_ops;
15875 *ops = base_breakpoint_ops;
15876 ops->re_set = tracepoint_re_set;
15877 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15878 ops->print_one_detail = tracepoint_print_one_detail;
15879 ops->print_mention = tracepoint_print_mention;
15880 ops->print_recreate = tracepoint_print_recreate;
15881 ops->create_sals_from_location = tracepoint_create_sals_from_location;
15882 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15883 ops->decode_location = tracepoint_decode_location;
15885 /* Probe tracepoints. */
15886 ops = &tracepoint_probe_breakpoint_ops;
15887 *ops = tracepoint_breakpoint_ops;
15888 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
15889 ops->decode_location = tracepoint_probe_decode_location;
15891 /* Static tracepoints with marker (`-m'). */
15892 ops = &strace_marker_breakpoint_ops;
15893 *ops = tracepoint_breakpoint_ops;
15894 ops->create_sals_from_location = strace_marker_create_sals_from_location;
15895 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15896 ops->decode_location = strace_marker_decode_location;
15898 /* Fork catchpoints. */
15899 ops = &catch_fork_breakpoint_ops;
15900 *ops = base_breakpoint_ops;
15901 ops->insert_location = insert_catch_fork;
15902 ops->remove_location = remove_catch_fork;
15903 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15904 ops->print_it = print_it_catch_fork;
15905 ops->print_one = print_one_catch_fork;
15906 ops->print_mention = print_mention_catch_fork;
15907 ops->print_recreate = print_recreate_catch_fork;
15909 /* Vfork catchpoints. */
15910 ops = &catch_vfork_breakpoint_ops;
15911 *ops = base_breakpoint_ops;
15912 ops->insert_location = insert_catch_vfork;
15913 ops->remove_location = remove_catch_vfork;
15914 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15915 ops->print_it = print_it_catch_vfork;
15916 ops->print_one = print_one_catch_vfork;
15917 ops->print_mention = print_mention_catch_vfork;
15918 ops->print_recreate = print_recreate_catch_vfork;
15920 /* Exec catchpoints. */
15921 ops = &catch_exec_breakpoint_ops;
15922 *ops = base_breakpoint_ops;
15923 ops->insert_location = insert_catch_exec;
15924 ops->remove_location = remove_catch_exec;
15925 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15926 ops->print_it = print_it_catch_exec;
15927 ops->print_one = print_one_catch_exec;
15928 ops->print_mention = print_mention_catch_exec;
15929 ops->print_recreate = print_recreate_catch_exec;
15931 /* Solib-related catchpoints. */
15932 ops = &catch_solib_breakpoint_ops;
15933 *ops = base_breakpoint_ops;
15934 ops->insert_location = insert_catch_solib;
15935 ops->remove_location = remove_catch_solib;
15936 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15937 ops->check_status = check_status_catch_solib;
15938 ops->print_it = print_it_catch_solib;
15939 ops->print_one = print_one_catch_solib;
15940 ops->print_mention = print_mention_catch_solib;
15941 ops->print_recreate = print_recreate_catch_solib;
15943 ops = &dprintf_breakpoint_ops;
15944 *ops = bkpt_base_breakpoint_ops;
15945 ops->re_set = dprintf_re_set;
15946 ops->resources_needed = bkpt_resources_needed;
15947 ops->print_it = bkpt_print_it;
15948 ops->print_mention = bkpt_print_mention;
15949 ops->print_recreate = dprintf_print_recreate;
15950 ops->after_condition_true = dprintf_after_condition_true;
15951 ops->breakpoint_hit = dprintf_breakpoint_hit;
15954 /* Chain containing all defined "enable breakpoint" subcommands. */
15956 static struct cmd_list_element *enablebreaklist = NULL;
15959 _initialize_breakpoint (void)
15961 struct cmd_list_element *c;
15963 initialize_breakpoint_ops ();
15965 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15966 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
15967 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15969 breakpoint_objfile_key
15970 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15972 breakpoint_chain = 0;
15973 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15974 before a breakpoint is set. */
15975 breakpoint_count = 0;
15977 tracepoint_count = 0;
15979 add_com ("ignore", class_breakpoint, ignore_command, _("\
15980 Set ignore-count of breakpoint number N to COUNT.\n\
15981 Usage is `ignore N COUNT'."));
15983 add_com ("commands", class_breakpoint, commands_command, _("\
15984 Set commands to be executed when the given breakpoints are hit.\n\
15985 Give a space-separated breakpoint list as argument after \"commands\".\n\
15986 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15988 With no argument, the targeted breakpoint is the last one set.\n\
15989 The commands themselves follow starting on the next line.\n\
15990 Type a line containing \"end\" to indicate the end of them.\n\
15991 Give \"silent\" as the first line to make the breakpoint silent;\n\
15992 then no output is printed when it is hit, except what the commands print."));
15994 c = add_com ("condition", class_breakpoint, condition_command, _("\
15995 Specify breakpoint number N to break only if COND is true.\n\
15996 Usage is `condition N COND', where N is an integer and COND is an\n\
15997 expression to be evaluated whenever breakpoint N is reached."));
15998 set_cmd_completer (c, condition_completer);
16000 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16001 Set a temporary breakpoint.\n\
16002 Like \"break\" except the breakpoint is only temporary,\n\
16003 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16004 by using \"enable delete\" on the breakpoint number.\n\
16006 BREAK_ARGS_HELP ("tbreak")));
16007 set_cmd_completer (c, location_completer);
16009 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16010 Set a hardware assisted breakpoint.\n\
16011 Like \"break\" except the breakpoint requires hardware support,\n\
16012 some target hardware may not have this support.\n\
16014 BREAK_ARGS_HELP ("hbreak")));
16015 set_cmd_completer (c, location_completer);
16017 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16018 Set a temporary hardware assisted breakpoint.\n\
16019 Like \"hbreak\" except the breakpoint is only temporary,\n\
16020 so it will be deleted when hit.\n\
16022 BREAK_ARGS_HELP ("thbreak")));
16023 set_cmd_completer (c, location_completer);
16025 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16026 Enable some breakpoints.\n\
16027 Give breakpoint numbers (separated by spaces) as arguments.\n\
16028 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16029 This is used to cancel the effect of the \"disable\" command.\n\
16030 With a subcommand you can enable temporarily."),
16031 &enablelist, "enable ", 1, &cmdlist);
16033 add_com_alias ("en", "enable", class_breakpoint, 1);
16035 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16036 Enable some breakpoints.\n\
16037 Give breakpoint numbers (separated by spaces) as arguments.\n\
16038 This is used to cancel the effect of the \"disable\" command.\n\
16039 May be abbreviated to simply \"enable\".\n"),
16040 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16042 add_cmd ("once", no_class, enable_once_command, _("\
16043 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16044 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16047 add_cmd ("delete", no_class, enable_delete_command, _("\
16048 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16049 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16052 add_cmd ("count", no_class, enable_count_command, _("\
16053 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16054 If a breakpoint is hit while enabled in this fashion,\n\
16055 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16058 add_cmd ("delete", no_class, enable_delete_command, _("\
16059 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16060 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16063 add_cmd ("once", no_class, enable_once_command, _("\
16064 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16065 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16068 add_cmd ("count", no_class, enable_count_command, _("\
16069 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16070 If a breakpoint is hit while enabled in this fashion,\n\
16071 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16074 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16075 Disable some breakpoints.\n\
16076 Arguments are breakpoint numbers with spaces in between.\n\
16077 To disable all breakpoints, give no argument.\n\
16078 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16079 &disablelist, "disable ", 1, &cmdlist);
16080 add_com_alias ("dis", "disable", class_breakpoint, 1);
16081 add_com_alias ("disa", "disable", class_breakpoint, 1);
16083 add_cmd ("breakpoints", class_alias, disable_command, _("\
16084 Disable some breakpoints.\n\
16085 Arguments are breakpoint numbers with spaces in between.\n\
16086 To disable all breakpoints, give no argument.\n\
16087 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16088 This command may be abbreviated \"disable\"."),
16091 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16092 Delete some breakpoints or auto-display expressions.\n\
16093 Arguments are breakpoint numbers with spaces in between.\n\
16094 To delete all breakpoints, give no argument.\n\
16096 Also a prefix command for deletion of other GDB objects.\n\
16097 The \"unset\" command is also an alias for \"delete\"."),
16098 &deletelist, "delete ", 1, &cmdlist);
16099 add_com_alias ("d", "delete", class_breakpoint, 1);
16100 add_com_alias ("del", "delete", class_breakpoint, 1);
16102 add_cmd ("breakpoints", class_alias, delete_command, _("\
16103 Delete some breakpoints or auto-display expressions.\n\
16104 Arguments are breakpoint numbers with spaces in between.\n\
16105 To delete all breakpoints, give no argument.\n\
16106 This command may be abbreviated \"delete\"."),
16109 add_com ("clear", class_breakpoint, clear_command, _("\
16110 Clear breakpoint at specified location.\n\
16111 Argument may be a linespec, explicit, or address location as described below.\n\
16113 With no argument, clears all breakpoints in the line that the selected frame\n\
16114 is executing in.\n"
16115 "\n" LOCATION_HELP_STRING "\n\
16116 See also the \"delete\" command which clears breakpoints by number."));
16117 add_com_alias ("cl", "clear", class_breakpoint, 1);
16119 c = add_com ("break", class_breakpoint, break_command, _("\
16120 Set breakpoint at specified location.\n"
16121 BREAK_ARGS_HELP ("break")));
16122 set_cmd_completer (c, location_completer);
16124 add_com_alias ("b", "break", class_run, 1);
16125 add_com_alias ("br", "break", class_run, 1);
16126 add_com_alias ("bre", "break", class_run, 1);
16127 add_com_alias ("brea", "break", class_run, 1);
16131 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16132 Break in function/address or break at a line in the current file."),
16133 &stoplist, "stop ", 1, &cmdlist);
16134 add_cmd ("in", class_breakpoint, stopin_command,
16135 _("Break in function or address."), &stoplist);
16136 add_cmd ("at", class_breakpoint, stopat_command,
16137 _("Break at a line in the current file."), &stoplist);
16138 add_com ("status", class_info, breakpoints_info, _("\
16139 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16140 The \"Type\" column indicates one of:\n\
16141 \tbreakpoint - normal breakpoint\n\
16142 \twatchpoint - watchpoint\n\
16143 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16144 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16145 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16146 address and file/line number respectively.\n\
16148 Convenience variable \"$_\" and default examine address for \"x\"\n\
16149 are set to the address of the last breakpoint listed unless the command\n\
16150 is prefixed with \"server \".\n\n\
16151 Convenience variable \"$bpnum\" contains the number of the last\n\
16152 breakpoint set."));
16155 add_info ("breakpoints", breakpoints_info, _("\
16156 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16157 The \"Type\" column indicates one of:\n\
16158 \tbreakpoint - normal breakpoint\n\
16159 \twatchpoint - watchpoint\n\
16160 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16161 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16162 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16163 address and file/line number respectively.\n\
16165 Convenience variable \"$_\" and default examine address for \"x\"\n\
16166 are set to the address of the last breakpoint listed unless the command\n\
16167 is prefixed with \"server \".\n\n\
16168 Convenience variable \"$bpnum\" contains the number of the last\n\
16169 breakpoint set."));
16171 add_info_alias ("b", "breakpoints", 1);
16173 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16174 Status of all breakpoints, or breakpoint number NUMBER.\n\
16175 The \"Type\" column indicates one of:\n\
16176 \tbreakpoint - normal breakpoint\n\
16177 \twatchpoint - watchpoint\n\
16178 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16179 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16180 \tuntil - internal breakpoint used by the \"until\" command\n\
16181 \tfinish - internal breakpoint used by the \"finish\" command\n\
16182 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16183 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16184 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16185 address and file/line number respectively.\n\
16187 Convenience variable \"$_\" and default examine address for \"x\"\n\
16188 are set to the address of the last breakpoint listed unless the command\n\
16189 is prefixed with \"server \".\n\n\
16190 Convenience variable \"$bpnum\" contains the number of the last\n\
16192 &maintenanceinfolist);
16194 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16195 Set catchpoints to catch events."),
16196 &catch_cmdlist, "catch ",
16197 0/*allow-unknown*/, &cmdlist);
16199 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16200 Set temporary catchpoints to catch events."),
16201 &tcatch_cmdlist, "tcatch ",
16202 0/*allow-unknown*/, &cmdlist);
16204 add_catch_command ("fork", _("Catch calls to fork."),
16205 catch_fork_command_1,
16207 (void *) (uintptr_t) catch_fork_permanent,
16208 (void *) (uintptr_t) catch_fork_temporary);
16209 add_catch_command ("vfork", _("Catch calls to vfork."),
16210 catch_fork_command_1,
16212 (void *) (uintptr_t) catch_vfork_permanent,
16213 (void *) (uintptr_t) catch_vfork_temporary);
16214 add_catch_command ("exec", _("Catch calls to exec."),
16215 catch_exec_command_1,
16219 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16220 Usage: catch load [REGEX]\n\
16221 If REGEX is given, only stop for libraries matching the regular expression."),
16222 catch_load_command_1,
16226 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16227 Usage: catch unload [REGEX]\n\
16228 If REGEX is given, only stop for libraries matching the regular expression."),
16229 catch_unload_command_1,
16234 c = add_com ("watch", class_breakpoint, watch_command, _("\
16235 Set a watchpoint for an expression.\n\
16236 Usage: watch [-l|-location] EXPRESSION\n\
16237 A watchpoint stops execution of your program whenever the value of\n\
16238 an expression changes.\n\
16239 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16240 the memory to which it refers."));
16241 set_cmd_completer (c, expression_completer);
16243 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16244 Set a read watchpoint for an expression.\n\
16245 Usage: rwatch [-l|-location] EXPRESSION\n\
16246 A watchpoint stops execution of your program whenever the value of\n\
16247 an expression is read.\n\
16248 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16249 the memory to which it refers."));
16250 set_cmd_completer (c, expression_completer);
16252 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16253 Set a watchpoint for an expression.\n\
16254 Usage: awatch [-l|-location] EXPRESSION\n\
16255 A watchpoint stops execution of your program whenever the value of\n\
16256 an expression is either read or written.\n\
16257 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16258 the memory to which it refers."));
16259 set_cmd_completer (c, expression_completer);
16261 add_info ("watchpoints", watchpoints_info, _("\
16262 Status of specified watchpoints (all watchpoints if no argument)."));
16264 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16265 respond to changes - contrary to the description. */
16266 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16267 &can_use_hw_watchpoints, _("\
16268 Set debugger's willingness to use watchpoint hardware."), _("\
16269 Show debugger's willingness to use watchpoint hardware."), _("\
16270 If zero, gdb will not use hardware for new watchpoints, even if\n\
16271 such is available. (However, any hardware watchpoints that were\n\
16272 created before setting this to nonzero, will continue to use watchpoint\n\
16275 show_can_use_hw_watchpoints,
16276 &setlist, &showlist);
16278 can_use_hw_watchpoints = 1;
16280 /* Tracepoint manipulation commands. */
16282 c = add_com ("trace", class_breakpoint, trace_command, _("\
16283 Set a tracepoint at specified location.\n\
16285 BREAK_ARGS_HELP ("trace") "\n\
16286 Do \"help tracepoints\" for info on other tracepoint commands."));
16287 set_cmd_completer (c, location_completer);
16289 add_com_alias ("tp", "trace", class_alias, 0);
16290 add_com_alias ("tr", "trace", class_alias, 1);
16291 add_com_alias ("tra", "trace", class_alias, 1);
16292 add_com_alias ("trac", "trace", class_alias, 1);
16294 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16295 Set a fast tracepoint at specified location.\n\
16297 BREAK_ARGS_HELP ("ftrace") "\n\
16298 Do \"help tracepoints\" for info on other tracepoint commands."));
16299 set_cmd_completer (c, location_completer);
16301 c = add_com ("strace", class_breakpoint, strace_command, _("\
16302 Set a static tracepoint at location or marker.\n\
16304 strace [LOCATION] [if CONDITION]\n\
16305 LOCATION may be a linespec, explicit, or address location (described below) \n\
16306 or -m MARKER_ID.\n\n\
16307 If a marker id is specified, probe the marker with that name. With\n\
16308 no LOCATION, uses current execution address of the selected stack frame.\n\
16309 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16310 This collects arbitrary user data passed in the probe point call to the\n\
16311 tracing library. You can inspect it when analyzing the trace buffer,\n\
16312 by printing the $_sdata variable like any other convenience variable.\n\
16314 CONDITION is a boolean expression.\n\
16315 \n" LOCATION_HELP_STRING "\n\
16316 Multiple tracepoints at one place are permitted, and useful if their\n\
16317 conditions are different.\n\
16319 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16320 Do \"help tracepoints\" for info on other tracepoint commands."));
16321 set_cmd_completer (c, location_completer);
16323 add_info ("tracepoints", tracepoints_info, _("\
16324 Status of specified tracepoints (all tracepoints if no argument).\n\
16325 Convenience variable \"$tpnum\" contains the number of the\n\
16326 last tracepoint set."));
16328 add_info_alias ("tp", "tracepoints", 1);
16330 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16331 Delete specified tracepoints.\n\
16332 Arguments are tracepoint numbers, separated by spaces.\n\
16333 No argument means delete all tracepoints."),
16335 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16337 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16338 Disable specified tracepoints.\n\
16339 Arguments are tracepoint numbers, separated by spaces.\n\
16340 No argument means disable all tracepoints."),
16342 deprecate_cmd (c, "disable");
16344 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16345 Enable specified tracepoints.\n\
16346 Arguments are tracepoint numbers, separated by spaces.\n\
16347 No argument means enable all tracepoints."),
16349 deprecate_cmd (c, "enable");
16351 add_com ("passcount", class_trace, trace_pass_command, _("\
16352 Set the passcount for a tracepoint.\n\
16353 The trace will end when the tracepoint has been passed 'count' times.\n\
16354 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16355 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16357 add_prefix_cmd ("save", class_breakpoint, save_command,
16358 _("Save breakpoint definitions as a script."),
16359 &save_cmdlist, "save ",
16360 0/*allow-unknown*/, &cmdlist);
16362 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16363 Save current breakpoint definitions as a script.\n\
16364 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16365 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16366 session to restore them."),
16368 set_cmd_completer (c, filename_completer);
16370 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16371 Save current tracepoint definitions as a script.\n\
16372 Use the 'source' command in another debug session to restore them."),
16374 set_cmd_completer (c, filename_completer);
16376 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16377 deprecate_cmd (c, "save tracepoints");
16379 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16380 Breakpoint specific settings\n\
16381 Configure various breakpoint-specific variables such as\n\
16382 pending breakpoint behavior"),
16383 &breakpoint_set_cmdlist, "set breakpoint ",
16384 0/*allow-unknown*/, &setlist);
16385 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16386 Breakpoint specific settings\n\
16387 Configure various breakpoint-specific variables such as\n\
16388 pending breakpoint behavior"),
16389 &breakpoint_show_cmdlist, "show breakpoint ",
16390 0/*allow-unknown*/, &showlist);
16392 add_setshow_auto_boolean_cmd ("pending", no_class,
16393 &pending_break_support, _("\
16394 Set debugger's behavior regarding pending breakpoints."), _("\
16395 Show debugger's behavior regarding pending breakpoints."), _("\
16396 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16397 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16398 an error. If auto, an unrecognized breakpoint location results in a\n\
16399 user-query to see if a pending breakpoint should be created."),
16401 show_pending_break_support,
16402 &breakpoint_set_cmdlist,
16403 &breakpoint_show_cmdlist);
16405 pending_break_support = AUTO_BOOLEAN_AUTO;
16407 add_setshow_boolean_cmd ("auto-hw", no_class,
16408 &automatic_hardware_breakpoints, _("\
16409 Set automatic usage of hardware breakpoints."), _("\
16410 Show automatic usage of hardware breakpoints."), _("\
16411 If set, the debugger will automatically use hardware breakpoints for\n\
16412 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16413 a warning will be emitted for such breakpoints."),
16415 show_automatic_hardware_breakpoints,
16416 &breakpoint_set_cmdlist,
16417 &breakpoint_show_cmdlist);
16419 add_setshow_boolean_cmd ("always-inserted", class_support,
16420 &always_inserted_mode, _("\
16421 Set mode for inserting breakpoints."), _("\
16422 Show mode for inserting breakpoints."), _("\
16423 When this mode is on, breakpoints are inserted immediately as soon as\n\
16424 they're created, kept inserted even when execution stops, and removed\n\
16425 only when the user deletes them. When this mode is off (the default),\n\
16426 breakpoints are inserted only when execution continues, and removed\n\
16427 when execution stops."),
16429 &show_always_inserted_mode,
16430 &breakpoint_set_cmdlist,
16431 &breakpoint_show_cmdlist);
16433 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16434 condition_evaluation_enums,
16435 &condition_evaluation_mode_1, _("\
16436 Set mode of breakpoint condition evaluation."), _("\
16437 Show mode of breakpoint condition evaluation."), _("\
16438 When this is set to \"host\", breakpoint conditions will be\n\
16439 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16440 breakpoint conditions will be downloaded to the target (if the target\n\
16441 supports such feature) and conditions will be evaluated on the target's side.\n\
16442 If this is set to \"auto\" (default), this will be automatically set to\n\
16443 \"target\" if it supports condition evaluation, otherwise it will\n\
16444 be set to \"gdb\""),
16445 &set_condition_evaluation_mode,
16446 &show_condition_evaluation_mode,
16447 &breakpoint_set_cmdlist,
16448 &breakpoint_show_cmdlist);
16450 add_com ("break-range", class_breakpoint, break_range_command, _("\
16451 Set a breakpoint for an address range.\n\
16452 break-range START-LOCATION, END-LOCATION\n\
16453 where START-LOCATION and END-LOCATION can be one of the following:\n\
16454 LINENUM, for that line in the current file,\n\
16455 FILE:LINENUM, for that line in that file,\n\
16456 +OFFSET, for that number of lines after the current line\n\
16457 or the start of the range\n\
16458 FUNCTION, for the first line in that function,\n\
16459 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16460 *ADDRESS, for the instruction at that address.\n\
16462 The breakpoint will stop execution of the inferior whenever it executes\n\
16463 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16464 range (including START-LOCATION and END-LOCATION)."));
16466 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16467 Set a dynamic printf at specified location.\n\
16468 dprintf location,format string,arg1,arg2,...\n\
16469 location may be a linespec, explicit, or address location.\n"
16470 "\n" LOCATION_HELP_STRING));
16471 set_cmd_completer (c, location_completer);
16473 add_setshow_enum_cmd ("dprintf-style", class_support,
16474 dprintf_style_enums, &dprintf_style, _("\
16475 Set the style of usage for dynamic printf."), _("\
16476 Show the style of usage for dynamic printf."), _("\
16477 This setting chooses how GDB will do a dynamic printf.\n\
16478 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16479 console, as with the \"printf\" command.\n\
16480 If the value is \"call\", the print is done by calling a function in your\n\
16481 program; by default printf(), but you can choose a different function or\n\
16482 output stream by setting dprintf-function and dprintf-channel."),
16483 update_dprintf_commands, NULL,
16484 &setlist, &showlist);
16486 dprintf_function = xstrdup ("printf");
16487 add_setshow_string_cmd ("dprintf-function", class_support,
16488 &dprintf_function, _("\
16489 Set the function to use for dynamic printf"), _("\
16490 Show the function to use for dynamic printf"), NULL,
16491 update_dprintf_commands, NULL,
16492 &setlist, &showlist);
16494 dprintf_channel = xstrdup ("");
16495 add_setshow_string_cmd ("dprintf-channel", class_support,
16496 &dprintf_channel, _("\
16497 Set the channel to use for dynamic printf"), _("\
16498 Show the channel to use for dynamic printf"), NULL,
16499 update_dprintf_commands, NULL,
16500 &setlist, &showlist);
16502 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16503 &disconnected_dprintf, _("\
16504 Set whether dprintf continues after GDB disconnects."), _("\
16505 Show whether dprintf continues after GDB disconnects."), _("\
16506 Use this to let dprintf commands continue to hit and produce output\n\
16507 even if GDB disconnects or detaches from the target."),
16510 &setlist, &showlist);
16512 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16513 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16514 (target agent only) This is useful for formatted output in user-defined commands."));
16516 automatic_hardware_breakpoints = 1;
16518 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16519 observer_attach_thread_exit (remove_threaded_breakpoints);