1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2016 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"
71 #include "thread-fsm.h"
72 #include "tid-parse.h"
74 /* readline include files */
75 #include "readline/readline.h"
76 #include "readline/history.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "extension.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
108 static void ignore_command (char *, int);
110 static int breakpoint_re_set_one (void *);
112 static void breakpoint_re_set_default (struct breakpoint *);
115 create_sals_from_location_default (const struct event_location *location,
116 struct linespec_result *canonical,
117 enum bptype type_wanted);
119 static void create_breakpoints_sal_default (struct gdbarch *,
120 struct linespec_result *,
121 char *, char *, enum bptype,
122 enum bpdisp, int, int,
124 const struct breakpoint_ops *,
125 int, int, int, unsigned);
127 static void decode_location_default (struct breakpoint *b,
128 const struct event_location *location,
129 struct program_space *search_pspace,
130 struct symtabs_and_lines *sals);
132 static void clear_command (char *, int);
134 static void catch_command (char *, int);
136 static int can_use_hardware_watchpoint (struct value *);
138 static void break_command_1 (char *, int, int);
140 static void mention (struct breakpoint *);
142 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
144 const struct breakpoint_ops *);
145 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
146 const struct symtab_and_line *);
148 /* This function is used in gdbtk sources and thus can not be made
150 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
151 struct symtab_and_line,
153 const struct breakpoint_ops *);
155 static struct breakpoint *
156 momentary_breakpoint_from_master (struct breakpoint *orig,
158 const struct breakpoint_ops *ops,
161 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
163 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
167 static void describe_other_breakpoints (struct gdbarch *,
168 struct program_space *, CORE_ADDR,
169 struct obj_section *, int);
171 static int watchpoint_locations_match (struct bp_location *loc1,
172 struct bp_location *loc2);
174 static int breakpoint_location_address_match (struct bp_location *bl,
175 struct address_space *aspace,
178 static int breakpoint_location_address_range_overlap (struct bp_location *,
179 struct address_space *,
182 static void breakpoints_info (char *, int);
184 static void watchpoints_info (char *, int);
186 static int breakpoint_1 (char *, int,
187 int (*) (const struct breakpoint *));
189 static int breakpoint_cond_eval (void *);
191 static void cleanup_executing_breakpoints (void *);
193 static void commands_command (char *, int);
195 static void condition_command (char *, int);
204 static int remove_breakpoint (struct bp_location *, insertion_state_t);
205 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
207 static enum print_stop_action print_bp_stop_message (bpstat bs);
209 static int watchpoint_check (void *);
211 static void maintenance_info_breakpoints (char *, int);
213 static int hw_breakpoint_used_count (void);
215 static int hw_watchpoint_use_count (struct breakpoint *);
217 static int hw_watchpoint_used_count_others (struct breakpoint *except,
219 int *other_type_used);
221 static void hbreak_command (char *, int);
223 static void thbreak_command (char *, int);
225 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
228 static void stop_command (char *arg, int from_tty);
230 static void stopin_command (char *arg, int from_tty);
232 static void stopat_command (char *arg, int from_tty);
234 static void tcatch_command (char *arg, int from_tty);
236 static void free_bp_location (struct bp_location *loc);
237 static void incref_bp_location (struct bp_location *loc);
238 static void decref_bp_location (struct bp_location **loc);
240 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
242 /* update_global_location_list's modes of operation wrt to whether to
243 insert locations now. */
244 enum ugll_insert_mode
246 /* Don't insert any breakpoint locations into the inferior, only
247 remove already-inserted locations that no longer should be
248 inserted. Functions that delete a breakpoint or breakpoints
249 should specify this mode, so that deleting a breakpoint doesn't
250 have the side effect of inserting the locations of other
251 breakpoints that are marked not-inserted, but should_be_inserted
252 returns true on them.
254 This behavior is useful is situations close to tear-down -- e.g.,
255 after an exec, while the target still has execution, but
256 breakpoint shadows of the previous executable image should *NOT*
257 be restored to the new image; or before detaching, where the
258 target still has execution and wants to delete breakpoints from
259 GDB's lists, and all breakpoints had already been removed from
263 /* May insert breakpoints iff breakpoints_should_be_inserted_now
264 claims breakpoints should be inserted now. */
267 /* Insert locations now, irrespective of
268 breakpoints_should_be_inserted_now. E.g., say all threads are
269 stopped right now, and the user did "continue". We need to
270 insert breakpoints _before_ resuming the target, but
271 UGLL_MAY_INSERT wouldn't insert them, because
272 breakpoints_should_be_inserted_now returns false at that point,
273 as no thread is running yet. */
277 static void update_global_location_list (enum ugll_insert_mode);
279 static void update_global_location_list_nothrow (enum ugll_insert_mode);
281 static int is_hardware_watchpoint (const struct breakpoint *bpt);
283 static void insert_breakpoint_locations (void);
285 static void tracepoints_info (char *, int);
287 static void delete_trace_command (char *, int);
289 static void enable_trace_command (char *, int);
291 static void disable_trace_command (char *, int);
293 static void trace_pass_command (char *, int);
295 static void set_tracepoint_count (int num);
297 static int is_masked_watchpoint (const struct breakpoint *b);
299 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
301 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
304 static int strace_marker_p (struct breakpoint *b);
306 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
307 that are implemented on top of software or hardware breakpoints
308 (user breakpoints, internal and momentary breakpoints, etc.). */
309 static struct breakpoint_ops bkpt_base_breakpoint_ops;
311 /* Internal breakpoints class type. */
312 static struct breakpoint_ops internal_breakpoint_ops;
314 /* Momentary breakpoints class type. */
315 static struct breakpoint_ops momentary_breakpoint_ops;
317 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
318 static struct breakpoint_ops longjmp_breakpoint_ops;
320 /* The breakpoint_ops structure to be used in regular user created
322 struct breakpoint_ops bkpt_breakpoint_ops;
324 /* Breakpoints set on probes. */
325 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
327 /* Dynamic printf class type. */
328 struct breakpoint_ops dprintf_breakpoint_ops;
330 /* The style in which to perform a dynamic printf. This is a user
331 option because different output options have different tradeoffs;
332 if GDB does the printing, there is better error handling if there
333 is a problem with any of the arguments, but using an inferior
334 function lets you have special-purpose printers and sending of
335 output to the same place as compiled-in print functions. */
337 static const char dprintf_style_gdb[] = "gdb";
338 static const char dprintf_style_call[] = "call";
339 static const char dprintf_style_agent[] = "agent";
340 static const char *const dprintf_style_enums[] = {
346 static const char *dprintf_style = dprintf_style_gdb;
348 /* The function to use for dynamic printf if the preferred style is to
349 call into the inferior. The value is simply a string that is
350 copied into the command, so it can be anything that GDB can
351 evaluate to a callable address, not necessarily a function name. */
353 static char *dprintf_function = "";
355 /* The channel to use for dynamic printf if the preferred style is to
356 call into the inferior; if a nonempty string, it will be passed to
357 the call as the first argument, with the format string as the
358 second. As with the dprintf function, this can be anything that
359 GDB knows how to evaluate, so in addition to common choices like
360 "stderr", this could be an app-specific expression like
361 "mystreams[curlogger]". */
363 static char *dprintf_channel = "";
365 /* True if dprintf commands should continue to operate even if GDB
367 static int disconnected_dprintf = 1;
369 /* A reference-counted struct command_line. This lets multiple
370 breakpoints share a single command list. */
371 struct counted_command_line
373 /* The reference count. */
376 /* The command list. */
377 struct command_line *commands;
380 struct command_line *
381 breakpoint_commands (struct breakpoint *b)
383 return b->commands ? b->commands->commands : NULL;
386 /* Flag indicating that a command has proceeded the inferior past the
387 current breakpoint. */
389 static int breakpoint_proceeded;
392 bpdisp_text (enum bpdisp disp)
394 /* NOTE: the following values are a part of MI protocol and
395 represent values of 'disp' field returned when inferior stops at
397 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
399 return bpdisps[(int) disp];
402 /* Prototypes for exported functions. */
403 /* If FALSE, gdb will not use hardware support for watchpoints, even
404 if such is available. */
405 static int can_use_hw_watchpoints;
408 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
409 struct cmd_list_element *c,
412 fprintf_filtered (file,
413 _("Debugger's willingness to use "
414 "watchpoint hardware is %s.\n"),
418 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
419 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
420 for unrecognized breakpoint locations.
421 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
422 static enum auto_boolean pending_break_support;
424 show_pending_break_support (struct ui_file *file, int from_tty,
425 struct cmd_list_element *c,
428 fprintf_filtered (file,
429 _("Debugger's behavior regarding "
430 "pending breakpoints is %s.\n"),
434 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
435 set with "break" but falling in read-only memory.
436 If 0, gdb will warn about such breakpoints, but won't automatically
437 use hardware breakpoints. */
438 static int automatic_hardware_breakpoints;
440 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
441 struct cmd_list_element *c,
444 fprintf_filtered (file,
445 _("Automatic usage of hardware breakpoints is %s.\n"),
449 /* If on, GDB keeps breakpoints inserted even if the inferior is
450 stopped, and immediately inserts any new breakpoints as soon as
451 they're created. If off (default), GDB keeps breakpoints off of
452 the target as long as possible. That is, it delays inserting
453 breakpoints until the next resume, and removes them again when the
454 target fully stops. This is a bit safer in case GDB crashes while
455 processing user input. */
456 static int always_inserted_mode = 0;
459 show_always_inserted_mode (struct ui_file *file, int from_tty,
460 struct cmd_list_element *c, const char *value)
462 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
466 /* See breakpoint.h. */
469 breakpoints_should_be_inserted_now (void)
471 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
473 /* If breakpoints are global, they should be inserted even if no
474 thread under gdb's control is running, or even if there are
475 no threads under GDB's control yet. */
478 else if (target_has_execution)
480 struct thread_info *tp;
482 if (always_inserted_mode)
484 /* The user wants breakpoints inserted even if all threads
489 if (threads_are_executing ())
492 /* Don't remove breakpoints yet if, even though all threads are
493 stopped, we still have events to process. */
494 ALL_NON_EXITED_THREADS (tp)
496 && tp->suspend.waitstatus_pending_p)
502 static const char condition_evaluation_both[] = "host or target";
504 /* Modes for breakpoint condition evaluation. */
505 static const char condition_evaluation_auto[] = "auto";
506 static const char condition_evaluation_host[] = "host";
507 static const char condition_evaluation_target[] = "target";
508 static const char *const condition_evaluation_enums[] = {
509 condition_evaluation_auto,
510 condition_evaluation_host,
511 condition_evaluation_target,
515 /* Global that holds the current mode for breakpoint condition evaluation. */
516 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
518 /* Global that we use to display information to the user (gets its value from
519 condition_evaluation_mode_1. */
520 static const char *condition_evaluation_mode = condition_evaluation_auto;
522 /* Translate a condition evaluation mode MODE into either "host"
523 or "target". This is used mostly to translate from "auto" to the
524 real setting that is being used. It returns the translated
528 translate_condition_evaluation_mode (const char *mode)
530 if (mode == condition_evaluation_auto)
532 if (target_supports_evaluation_of_breakpoint_conditions ())
533 return condition_evaluation_target;
535 return condition_evaluation_host;
541 /* Discovers what condition_evaluation_auto translates to. */
544 breakpoint_condition_evaluation_mode (void)
546 return translate_condition_evaluation_mode (condition_evaluation_mode);
549 /* Return true if GDB should evaluate breakpoint conditions or false
553 gdb_evaluates_breakpoint_condition_p (void)
555 const char *mode = breakpoint_condition_evaluation_mode ();
557 return (mode == condition_evaluation_host);
560 void _initialize_breakpoint (void);
562 /* Are we executing breakpoint commands? */
563 static int executing_breakpoint_commands;
565 /* Are overlay event breakpoints enabled? */
566 static int overlay_events_enabled;
568 /* See description in breakpoint.h. */
569 int target_exact_watchpoints = 0;
571 /* Walk the following statement or block through all breakpoints.
572 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
573 current breakpoint. */
575 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
577 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
578 for (B = breakpoint_chain; \
579 B ? (TMP=B->next, 1): 0; \
582 /* Similar iterator for the low-level breakpoints. SAFE variant is
583 not provided so update_global_location_list must not be called
584 while executing the block of ALL_BP_LOCATIONS. */
586 #define ALL_BP_LOCATIONS(B,BP_TMP) \
587 for (BP_TMP = bp_location; \
588 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
591 /* Iterates through locations with address ADDRESS for the currently selected
592 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
593 to where the loop should start from.
594 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
595 appropriate location to start with. */
597 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
598 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
599 BP_LOCP_TMP = BP_LOCP_START; \
601 && (BP_LOCP_TMP < bp_location + bp_location_count \
602 && (*BP_LOCP_TMP)->address == ADDRESS); \
605 /* Iterator for tracepoints only. */
607 #define ALL_TRACEPOINTS(B) \
608 for (B = breakpoint_chain; B; B = B->next) \
609 if (is_tracepoint (B))
611 /* Chains of all breakpoints defined. */
613 struct breakpoint *breakpoint_chain;
615 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
617 static struct bp_location **bp_location;
619 /* Number of elements of BP_LOCATION. */
621 static unsigned bp_location_count;
623 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
624 ADDRESS for the current elements of BP_LOCATION which get a valid
625 result from bp_location_has_shadow. You can use it for roughly
626 limiting the subrange of BP_LOCATION to scan for shadow bytes for
627 an address you need to read. */
629 static CORE_ADDR bp_location_placed_address_before_address_max;
631 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
632 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
633 BP_LOCATION which get a valid result from bp_location_has_shadow.
634 You can use it for roughly limiting the subrange of BP_LOCATION to
635 scan for shadow bytes for an address you need to read. */
637 static CORE_ADDR bp_location_shadow_len_after_address_max;
639 /* The locations that no longer correspond to any breakpoint, unlinked
640 from bp_location array, but for which a hit may still be reported
642 VEC(bp_location_p) *moribund_locations = NULL;
644 /* Number of last breakpoint made. */
646 static int breakpoint_count;
648 /* The value of `breakpoint_count' before the last command that
649 created breakpoints. If the last (break-like) command created more
650 than one breakpoint, then the difference between BREAKPOINT_COUNT
651 and PREV_BREAKPOINT_COUNT is more than one. */
652 static int prev_breakpoint_count;
654 /* Number of last tracepoint made. */
656 static int tracepoint_count;
658 static struct cmd_list_element *breakpoint_set_cmdlist;
659 static struct cmd_list_element *breakpoint_show_cmdlist;
660 struct cmd_list_element *save_cmdlist;
662 /* See declaration at breakpoint.h. */
665 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
668 struct breakpoint *b = NULL;
672 if (func (b, user_data) != 0)
679 /* Return whether a breakpoint is an active enabled breakpoint. */
681 breakpoint_enabled (struct breakpoint *b)
683 return (b->enable_state == bp_enabled);
686 /* Set breakpoint count to NUM. */
689 set_breakpoint_count (int num)
691 prev_breakpoint_count = breakpoint_count;
692 breakpoint_count = num;
693 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
696 /* Used by `start_rbreak_breakpoints' below, to record the current
697 breakpoint count before "rbreak" creates any breakpoint. */
698 static int rbreak_start_breakpoint_count;
700 /* Called at the start an "rbreak" command to record the first
704 start_rbreak_breakpoints (void)
706 rbreak_start_breakpoint_count = breakpoint_count;
709 /* Called at the end of an "rbreak" command to record the last
713 end_rbreak_breakpoints (void)
715 prev_breakpoint_count = rbreak_start_breakpoint_count;
718 /* Used in run_command to zero the hit count when a new run starts. */
721 clear_breakpoint_hit_counts (void)
723 struct breakpoint *b;
729 /* Allocate a new counted_command_line with reference count of 1.
730 The new structure owns COMMANDS. */
732 static struct counted_command_line *
733 alloc_counted_command_line (struct command_line *commands)
735 struct counted_command_line *result = XNEW (struct counted_command_line);
738 result->commands = commands;
743 /* Increment reference count. This does nothing if CMD is NULL. */
746 incref_counted_command_line (struct counted_command_line *cmd)
752 /* Decrement reference count. If the reference count reaches 0,
753 destroy the counted_command_line. Sets *CMDP to NULL. This does
754 nothing if *CMDP is NULL. */
757 decref_counted_command_line (struct counted_command_line **cmdp)
761 if (--(*cmdp)->refc == 0)
763 free_command_lines (&(*cmdp)->commands);
770 /* A cleanup function that calls decref_counted_command_line. */
773 do_cleanup_counted_command_line (void *arg)
775 decref_counted_command_line ((struct counted_command_line **) arg);
778 /* Create a cleanup that calls decref_counted_command_line on the
781 static struct cleanup *
782 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
784 return make_cleanup (do_cleanup_counted_command_line, cmdp);
788 /* Return the breakpoint with the specified number, or NULL
789 if the number does not refer to an existing breakpoint. */
792 get_breakpoint (int num)
794 struct breakpoint *b;
797 if (b->number == num)
805 /* Mark locations as "conditions have changed" in case the target supports
806 evaluating conditions on its side. */
809 mark_breakpoint_modified (struct breakpoint *b)
811 struct bp_location *loc;
813 /* This is only meaningful if the target is
814 evaluating conditions and if the user has
815 opted for condition evaluation on the target's
817 if (gdb_evaluates_breakpoint_condition_p ()
818 || !target_supports_evaluation_of_breakpoint_conditions ())
821 if (!is_breakpoint (b))
824 for (loc = b->loc; loc; loc = loc->next)
825 loc->condition_changed = condition_modified;
828 /* Mark location as "conditions have changed" in case the target supports
829 evaluating conditions on its side. */
832 mark_breakpoint_location_modified (struct bp_location *loc)
834 /* This is only meaningful if the target is
835 evaluating conditions and if the user has
836 opted for condition evaluation on the target's
838 if (gdb_evaluates_breakpoint_condition_p ()
839 || !target_supports_evaluation_of_breakpoint_conditions ())
843 if (!is_breakpoint (loc->owner))
846 loc->condition_changed = condition_modified;
849 /* Sets the condition-evaluation mode using the static global
850 condition_evaluation_mode. */
853 set_condition_evaluation_mode (char *args, int from_tty,
854 struct cmd_list_element *c)
856 const char *old_mode, *new_mode;
858 if ((condition_evaluation_mode_1 == condition_evaluation_target)
859 && !target_supports_evaluation_of_breakpoint_conditions ())
861 condition_evaluation_mode_1 = condition_evaluation_mode;
862 warning (_("Target does not support breakpoint condition evaluation.\n"
863 "Using host evaluation mode instead."));
867 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
868 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
870 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
871 settings was "auto". */
872 condition_evaluation_mode = condition_evaluation_mode_1;
874 /* Only update the mode if the user picked a different one. */
875 if (new_mode != old_mode)
877 struct bp_location *loc, **loc_tmp;
878 /* If the user switched to a different evaluation mode, we
879 need to synch the changes with the target as follows:
881 "host" -> "target": Send all (valid) conditions to the target.
882 "target" -> "host": Remove all the conditions from the target.
885 if (new_mode == condition_evaluation_target)
887 /* Mark everything modified and synch conditions with the
889 ALL_BP_LOCATIONS (loc, loc_tmp)
890 mark_breakpoint_location_modified (loc);
894 /* Manually mark non-duplicate locations to synch conditions
895 with the target. We do this to remove all the conditions the
896 target knows about. */
897 ALL_BP_LOCATIONS (loc, loc_tmp)
898 if (is_breakpoint (loc->owner) && loc->inserted)
899 loc->needs_update = 1;
903 update_global_location_list (UGLL_MAY_INSERT);
909 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
910 what "auto" is translating to. */
913 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
914 struct cmd_list_element *c, const char *value)
916 if (condition_evaluation_mode == condition_evaluation_auto)
917 fprintf_filtered (file,
918 _("Breakpoint condition evaluation "
919 "mode is %s (currently %s).\n"),
921 breakpoint_condition_evaluation_mode ());
923 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
927 /* A comparison function for bp_location AP and BP that is used by
928 bsearch. This comparison function only cares about addresses, unlike
929 the more general bp_location_compare function. */
932 bp_location_compare_addrs (const void *ap, const void *bp)
934 const struct bp_location *a = *(const struct bp_location **) ap;
935 const struct bp_location *b = *(const struct bp_location **) bp;
937 if (a->address == b->address)
940 return ((a->address > b->address) - (a->address < b->address));
943 /* Helper function to skip all bp_locations with addresses
944 less than ADDRESS. It returns the first bp_location that
945 is greater than or equal to ADDRESS. If none is found, just
948 static struct bp_location **
949 get_first_locp_gte_addr (CORE_ADDR address)
951 struct bp_location dummy_loc;
952 struct bp_location *dummy_locp = &dummy_loc;
953 struct bp_location **locp_found = NULL;
955 /* Initialize the dummy location's address field. */
956 memset (&dummy_loc, 0, sizeof (struct bp_location));
957 dummy_loc.address = address;
959 /* Find a close match to the first location at ADDRESS. */
960 locp_found = ((struct bp_location **)
961 bsearch (&dummy_locp, bp_location, bp_location_count,
962 sizeof (struct bp_location **),
963 bp_location_compare_addrs));
965 /* Nothing was found, nothing left to do. */
966 if (locp_found == NULL)
969 /* We may have found a location that is at ADDRESS but is not the first in the
970 location's list. Go backwards (if possible) and locate the first one. */
971 while ((locp_found - 1) >= bp_location
972 && (*(locp_found - 1))->address == address)
979 set_breakpoint_condition (struct breakpoint *b, const char *exp,
982 xfree (b->cond_string);
983 b->cond_string = NULL;
985 if (is_watchpoint (b))
987 struct watchpoint *w = (struct watchpoint *) b;
994 struct bp_location *loc;
996 for (loc = b->loc; loc; loc = loc->next)
1001 /* No need to free the condition agent expression
1002 bytecode (if we have one). We will handle this
1003 when we go through update_global_location_list. */
1010 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
1014 const char *arg = exp;
1016 /* I don't know if it matters whether this is the string the user
1017 typed in or the decompiled expression. */
1018 b->cond_string = xstrdup (arg);
1019 b->condition_not_parsed = 0;
1021 if (is_watchpoint (b))
1023 struct watchpoint *w = (struct watchpoint *) b;
1025 innermost_block = NULL;
1027 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1029 error (_("Junk at end of expression"));
1030 w->cond_exp_valid_block = innermost_block;
1034 struct bp_location *loc;
1036 for (loc = b->loc; loc; loc = loc->next)
1040 parse_exp_1 (&arg, loc->address,
1041 block_for_pc (loc->address), 0);
1043 error (_("Junk at end of expression"));
1047 mark_breakpoint_modified (b);
1049 observer_notify_breakpoint_modified (b);
1052 /* Completion for the "condition" command. */
1054 static VEC (char_ptr) *
1055 condition_completer (struct cmd_list_element *cmd,
1056 const char *text, const char *word)
1060 text = skip_spaces_const (text);
1061 space = skip_to_space_const (text);
1065 struct breakpoint *b;
1066 VEC (char_ptr) *result = NULL;
1070 /* We don't support completion of history indices. */
1071 if (isdigit (text[1]))
1073 return complete_internalvar (&text[1]);
1076 /* We're completing the breakpoint number. */
1077 len = strlen (text);
1083 xsnprintf (number, sizeof (number), "%d", b->number);
1085 if (strncmp (number, text, len) == 0)
1086 VEC_safe_push (char_ptr, result, xstrdup (number));
1092 /* We're completing the expression part. */
1093 text = skip_spaces_const (space);
1094 return expression_completer (cmd, text, word);
1097 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1100 condition_command (char *arg, int from_tty)
1102 struct breakpoint *b;
1107 error_no_arg (_("breakpoint number"));
1110 bnum = get_number (&p);
1112 error (_("Bad breakpoint argument: '%s'"), arg);
1115 if (b->number == bnum)
1117 /* Check if this breakpoint has a "stop" method implemented in an
1118 extension language. This method and conditions entered into GDB
1119 from the CLI are mutually exclusive. */
1120 const struct extension_language_defn *extlang
1121 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1123 if (extlang != NULL)
1125 error (_("Only one stop condition allowed. There is currently"
1126 " a %s stop condition defined for this breakpoint."),
1127 ext_lang_capitalized_name (extlang));
1129 set_breakpoint_condition (b, p, from_tty);
1131 if (is_breakpoint (b))
1132 update_global_location_list (UGLL_MAY_INSERT);
1137 error (_("No breakpoint number %d."), bnum);
1140 /* Check that COMMAND do not contain commands that are suitable
1141 only for tracepoints and not suitable for ordinary breakpoints.
1142 Throw if any such commands is found. */
1145 check_no_tracepoint_commands (struct command_line *commands)
1147 struct command_line *c;
1149 for (c = commands; c; c = c->next)
1153 if (c->control_type == while_stepping_control)
1154 error (_("The 'while-stepping' command can "
1155 "only be used for tracepoints"));
1157 for (i = 0; i < c->body_count; ++i)
1158 check_no_tracepoint_commands ((c->body_list)[i]);
1160 /* Not that command parsing removes leading whitespace and comment
1161 lines and also empty lines. So, we only need to check for
1162 command directly. */
1163 if (strstr (c->line, "collect ") == c->line)
1164 error (_("The 'collect' command can only be used for tracepoints"));
1166 if (strstr (c->line, "teval ") == c->line)
1167 error (_("The 'teval' command can only be used for tracepoints"));
1171 /* Encapsulate tests for different types of tracepoints. */
1174 is_tracepoint_type (enum bptype type)
1176 return (type == bp_tracepoint
1177 || type == bp_fast_tracepoint
1178 || type == bp_static_tracepoint);
1182 is_tracepoint (const struct breakpoint *b)
1184 return is_tracepoint_type (b->type);
1187 /* A helper function that validates that COMMANDS are valid for a
1188 breakpoint. This function will throw an exception if a problem is
1192 validate_commands_for_breakpoint (struct breakpoint *b,
1193 struct command_line *commands)
1195 if (is_tracepoint (b))
1197 struct tracepoint *t = (struct tracepoint *) b;
1198 struct command_line *c;
1199 struct command_line *while_stepping = 0;
1201 /* Reset the while-stepping step count. The previous commands
1202 might have included a while-stepping action, while the new
1206 /* We need to verify that each top-level element of commands is
1207 valid for tracepoints, that there's at most one
1208 while-stepping element, and that the while-stepping's body
1209 has valid tracing commands excluding nested while-stepping.
1210 We also need to validate the tracepoint action line in the
1211 context of the tracepoint --- validate_actionline actually
1212 has side effects, like setting the tracepoint's
1213 while-stepping STEP_COUNT, in addition to checking if the
1214 collect/teval actions parse and make sense in the
1215 tracepoint's context. */
1216 for (c = commands; c; c = c->next)
1218 if (c->control_type == while_stepping_control)
1220 if (b->type == bp_fast_tracepoint)
1221 error (_("The 'while-stepping' command "
1222 "cannot be used for fast tracepoint"));
1223 else if (b->type == bp_static_tracepoint)
1224 error (_("The 'while-stepping' command "
1225 "cannot be used for static tracepoint"));
1228 error (_("The 'while-stepping' command "
1229 "can be used only once"));
1234 validate_actionline (c->line, b);
1238 struct command_line *c2;
1240 gdb_assert (while_stepping->body_count == 1);
1241 c2 = while_stepping->body_list[0];
1242 for (; c2; c2 = c2->next)
1244 if (c2->control_type == while_stepping_control)
1245 error (_("The 'while-stepping' command cannot be nested"));
1251 check_no_tracepoint_commands (commands);
1255 /* Return a vector of all the static tracepoints set at ADDR. The
1256 caller is responsible for releasing the vector. */
1259 static_tracepoints_here (CORE_ADDR addr)
1261 struct breakpoint *b;
1262 VEC(breakpoint_p) *found = 0;
1263 struct bp_location *loc;
1266 if (b->type == bp_static_tracepoint)
1268 for (loc = b->loc; loc; loc = loc->next)
1269 if (loc->address == addr)
1270 VEC_safe_push(breakpoint_p, found, b);
1276 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1277 validate that only allowed commands are included. */
1280 breakpoint_set_commands (struct breakpoint *b,
1281 struct command_line *commands)
1283 validate_commands_for_breakpoint (b, commands);
1285 decref_counted_command_line (&b->commands);
1286 b->commands = alloc_counted_command_line (commands);
1287 observer_notify_breakpoint_modified (b);
1290 /* Set the internal `silent' flag on the breakpoint. Note that this
1291 is not the same as the "silent" that may appear in the breakpoint's
1295 breakpoint_set_silent (struct breakpoint *b, int silent)
1297 int old_silent = b->silent;
1300 if (old_silent != silent)
1301 observer_notify_breakpoint_modified (b);
1304 /* Set the thread for this breakpoint. If THREAD is -1, make the
1305 breakpoint work for any thread. */
1308 breakpoint_set_thread (struct breakpoint *b, int thread)
1310 int old_thread = b->thread;
1313 if (old_thread != thread)
1314 observer_notify_breakpoint_modified (b);
1317 /* Set the task for this breakpoint. If TASK is 0, make the
1318 breakpoint work for any task. */
1321 breakpoint_set_task (struct breakpoint *b, int task)
1323 int old_task = b->task;
1326 if (old_task != task)
1327 observer_notify_breakpoint_modified (b);
1331 check_tracepoint_command (char *line, void *closure)
1333 struct breakpoint *b = (struct breakpoint *) closure;
1335 validate_actionline (line, b);
1338 /* A structure used to pass information through
1339 map_breakpoint_numbers. */
1341 struct commands_info
1343 /* True if the command was typed at a tty. */
1346 /* The breakpoint range spec. */
1349 /* Non-NULL if the body of the commands are being read from this
1350 already-parsed command. */
1351 struct command_line *control;
1353 /* The command lines read from the user, or NULL if they have not
1355 struct counted_command_line *cmd;
1358 /* A callback for map_breakpoint_numbers that sets the commands for
1359 commands_command. */
1362 do_map_commands_command (struct breakpoint *b, void *data)
1364 struct commands_info *info = (struct commands_info *) data;
1366 if (info->cmd == NULL)
1368 struct command_line *l;
1370 if (info->control != NULL)
1371 l = copy_command_lines (info->control->body_list[0]);
1374 struct cleanup *old_chain;
1377 str = xstrprintf (_("Type commands for breakpoint(s) "
1378 "%s, one per line."),
1381 old_chain = make_cleanup (xfree, str);
1383 l = read_command_lines (str,
1386 ? check_tracepoint_command : 0),
1389 do_cleanups (old_chain);
1392 info->cmd = alloc_counted_command_line (l);
1395 /* If a breakpoint was on the list more than once, we don't need to
1397 if (b->commands != info->cmd)
1399 validate_commands_for_breakpoint (b, info->cmd->commands);
1400 incref_counted_command_line (info->cmd);
1401 decref_counted_command_line (&b->commands);
1402 b->commands = info->cmd;
1403 observer_notify_breakpoint_modified (b);
1408 commands_command_1 (char *arg, int from_tty,
1409 struct command_line *control)
1411 struct cleanup *cleanups;
1412 struct commands_info info;
1414 info.from_tty = from_tty;
1415 info.control = control;
1417 /* If we read command lines from the user, then `info' will hold an
1418 extra reference to the commands that we must clean up. */
1419 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1421 if (arg == NULL || !*arg)
1423 if (breakpoint_count - prev_breakpoint_count > 1)
1424 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1426 else if (breakpoint_count > 0)
1427 arg = xstrprintf ("%d", breakpoint_count);
1430 /* So that we don't try to free the incoming non-NULL
1431 argument in the cleanup below. Mapping breakpoint
1432 numbers will fail in this case. */
1437 /* The command loop has some static state, so we need to preserve
1439 arg = xstrdup (arg);
1442 make_cleanup (xfree, arg);
1446 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1448 if (info.cmd == NULL)
1449 error (_("No breakpoints specified."));
1451 do_cleanups (cleanups);
1455 commands_command (char *arg, int from_tty)
1457 commands_command_1 (arg, from_tty, NULL);
1460 /* Like commands_command, but instead of reading the commands from
1461 input stream, takes them from an already parsed command structure.
1463 This is used by cli-script.c to DTRT with breakpoint commands
1464 that are part of if and while bodies. */
1465 enum command_control_type
1466 commands_from_control_command (char *arg, struct command_line *cmd)
1468 commands_command_1 (arg, 0, cmd);
1469 return simple_control;
1472 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1475 bp_location_has_shadow (struct bp_location *bl)
1477 if (bl->loc_type != bp_loc_software_breakpoint)
1481 if (bl->target_info.shadow_len == 0)
1482 /* BL isn't valid, or doesn't shadow memory. */
1487 /* Update BUF, which is LEN bytes read from the target address
1488 MEMADDR, by replacing a memory breakpoint with its shadowed
1491 If READBUF is not NULL, this buffer must not overlap with the of
1492 the breakpoint location's shadow_contents buffer. Otherwise, a
1493 failed assertion internal error will be raised. */
1496 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1497 const gdb_byte *writebuf_org,
1498 ULONGEST memaddr, LONGEST len,
1499 struct bp_target_info *target_info,
1500 struct gdbarch *gdbarch)
1502 /* Now do full processing of the found relevant range of elements. */
1503 CORE_ADDR bp_addr = 0;
1507 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1508 current_program_space->aspace, 0))
1510 /* The breakpoint is inserted in a different address space. */
1514 /* Addresses and length of the part of the breakpoint that
1516 bp_addr = target_info->placed_address;
1517 bp_size = target_info->shadow_len;
1519 if (bp_addr + bp_size <= memaddr)
1521 /* The breakpoint is entirely before the chunk of memory we are
1526 if (bp_addr >= memaddr + len)
1528 /* The breakpoint is entirely after the chunk of memory we are
1533 /* Offset within shadow_contents. */
1534 if (bp_addr < memaddr)
1536 /* Only copy the second part of the breakpoint. */
1537 bp_size -= memaddr - bp_addr;
1538 bptoffset = memaddr - bp_addr;
1542 if (bp_addr + bp_size > memaddr + len)
1544 /* Only copy the first part of the breakpoint. */
1545 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1548 if (readbuf != NULL)
1550 /* Verify that the readbuf buffer does not overlap with the
1551 shadow_contents buffer. */
1552 gdb_assert (target_info->shadow_contents >= readbuf + len
1553 || readbuf >= (target_info->shadow_contents
1554 + target_info->shadow_len));
1556 /* Update the read buffer with this inserted breakpoint's
1558 memcpy (readbuf + bp_addr - memaddr,
1559 target_info->shadow_contents + bptoffset, bp_size);
1563 const unsigned char *bp;
1564 CORE_ADDR addr = target_info->reqstd_address;
1567 /* Update the shadow with what we want to write to memory. */
1568 memcpy (target_info->shadow_contents + bptoffset,
1569 writebuf_org + bp_addr - memaddr, bp_size);
1571 /* Determine appropriate breakpoint contents and size for this
1573 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1575 /* Update the final write buffer with this inserted
1576 breakpoint's INSN. */
1577 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1581 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1582 by replacing any memory breakpoints with their shadowed contents.
1584 If READBUF is not NULL, this buffer must not overlap with any of
1585 the breakpoint location's shadow_contents buffers. Otherwise,
1586 a failed assertion internal error will be raised.
1588 The range of shadowed area by each bp_location is:
1589 bl->address - bp_location_placed_address_before_address_max
1590 up to bl->address + bp_location_shadow_len_after_address_max
1591 The range we were requested to resolve shadows for is:
1592 memaddr ... memaddr + len
1593 Thus the safe cutoff boundaries for performance optimization are
1594 memaddr + len <= (bl->address
1595 - bp_location_placed_address_before_address_max)
1597 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1600 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1601 const gdb_byte *writebuf_org,
1602 ULONGEST memaddr, LONGEST len)
1604 /* Left boundary, right boundary and median element of our binary
1606 unsigned bc_l, bc_r, bc;
1609 /* Find BC_L which is a leftmost element which may affect BUF
1610 content. It is safe to report lower value but a failure to
1611 report higher one. */
1614 bc_r = bp_location_count;
1615 while (bc_l + 1 < bc_r)
1617 struct bp_location *bl;
1619 bc = (bc_l + bc_r) / 2;
1620 bl = bp_location[bc];
1622 /* Check first BL->ADDRESS will not overflow due to the added
1623 constant. Then advance the left boundary only if we are sure
1624 the BC element can in no way affect the BUF content (MEMADDR
1625 to MEMADDR + LEN range).
1627 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1628 offset so that we cannot miss a breakpoint with its shadow
1629 range tail still reaching MEMADDR. */
1631 if ((bl->address + bp_location_shadow_len_after_address_max
1633 && (bl->address + bp_location_shadow_len_after_address_max
1640 /* Due to the binary search above, we need to make sure we pick the
1641 first location that's at BC_L's address. E.g., if there are
1642 multiple locations at the same address, BC_L may end up pointing
1643 at a duplicate location, and miss the "master"/"inserted"
1644 location. Say, given locations L1, L2 and L3 at addresses A and
1647 L1@A, L2@A, L3@B, ...
1649 BC_L could end up pointing at location L2, while the "master"
1650 location could be L1. Since the `loc->inserted' flag is only set
1651 on "master" locations, we'd forget to restore the shadow of L1
1654 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1657 /* Now do full processing of the found relevant range of elements. */
1659 for (bc = bc_l; bc < bp_location_count; bc++)
1661 struct bp_location *bl = bp_location[bc];
1662 CORE_ADDR bp_addr = 0;
1666 /* bp_location array has BL->OWNER always non-NULL. */
1667 if (bl->owner->type == bp_none)
1668 warning (_("reading through apparently deleted breakpoint #%d?"),
1671 /* Performance optimization: any further element can no longer affect BUF
1674 if (bl->address >= bp_location_placed_address_before_address_max
1675 && memaddr + len <= (bl->address
1676 - bp_location_placed_address_before_address_max))
1679 if (!bp_location_has_shadow (bl))
1682 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1683 memaddr, len, &bl->target_info, bl->gdbarch);
1689 /* Return true if BPT is either a software breakpoint or a hardware
1693 is_breakpoint (const struct breakpoint *bpt)
1695 return (bpt->type == bp_breakpoint
1696 || bpt->type == bp_hardware_breakpoint
1697 || bpt->type == bp_dprintf);
1700 /* Return true if BPT is of any hardware watchpoint kind. */
1703 is_hardware_watchpoint (const struct breakpoint *bpt)
1705 return (bpt->type == bp_hardware_watchpoint
1706 || bpt->type == bp_read_watchpoint
1707 || bpt->type == bp_access_watchpoint);
1710 /* Return true if BPT is of any watchpoint kind, hardware or
1714 is_watchpoint (const struct breakpoint *bpt)
1716 return (is_hardware_watchpoint (bpt)
1717 || bpt->type == bp_watchpoint);
1720 /* Returns true if the current thread and its running state are safe
1721 to evaluate or update watchpoint B. Watchpoints on local
1722 expressions need to be evaluated in the context of the thread that
1723 was current when the watchpoint was created, and, that thread needs
1724 to be stopped to be able to select the correct frame context.
1725 Watchpoints on global expressions can be evaluated on any thread,
1726 and in any state. It is presently left to the target allowing
1727 memory accesses when threads are running. */
1730 watchpoint_in_thread_scope (struct watchpoint *b)
1732 return (b->base.pspace == current_program_space
1733 && (ptid_equal (b->watchpoint_thread, null_ptid)
1734 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1735 && !is_executing (inferior_ptid))));
1738 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1739 associated bp_watchpoint_scope breakpoint. */
1742 watchpoint_del_at_next_stop (struct watchpoint *w)
1744 struct breakpoint *b = &w->base;
1746 if (b->related_breakpoint != b)
1748 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1749 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1750 b->related_breakpoint->disposition = disp_del_at_next_stop;
1751 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1752 b->related_breakpoint = b;
1754 b->disposition = disp_del_at_next_stop;
1757 /* Extract a bitfield value from value VAL using the bit parameters contained in
1760 static struct value *
1761 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1763 struct value *bit_val;
1768 bit_val = allocate_value (value_type (val));
1770 unpack_value_bitfield (bit_val,
1773 value_contents_for_printing (val),
1780 /* Allocate a dummy location and add it to B, which must be a software
1781 watchpoint. This is required because even if a software watchpoint
1782 is not watching any memory, bpstat_stop_status requires a location
1783 to be able to report stops. */
1786 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1787 struct program_space *pspace)
1789 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1791 b->loc = allocate_bp_location (b);
1792 b->loc->pspace = pspace;
1793 b->loc->address = -1;
1794 b->loc->length = -1;
1797 /* Returns true if B is a software watchpoint that is not watching any
1798 memory (e.g., "watch $pc"). */
1801 is_no_memory_software_watchpoint (struct breakpoint *b)
1803 return (b->type == bp_watchpoint
1805 && b->loc->next == NULL
1806 && b->loc->address == -1
1807 && b->loc->length == -1);
1810 /* Assuming that B is a watchpoint:
1811 - Reparse watchpoint expression, if REPARSE is non-zero
1812 - Evaluate expression and store the result in B->val
1813 - Evaluate the condition if there is one, and store the result
1815 - Update the list of values that must be watched in B->loc.
1817 If the watchpoint disposition is disp_del_at_next_stop, then do
1818 nothing. If this is local watchpoint that is out of scope, delete
1821 Even with `set breakpoint always-inserted on' the watchpoints are
1822 removed + inserted on each stop here. Normal breakpoints must
1823 never be removed because they might be missed by a running thread
1824 when debugging in non-stop mode. On the other hand, hardware
1825 watchpoints (is_hardware_watchpoint; processed here) are specific
1826 to each LWP since they are stored in each LWP's hardware debug
1827 registers. Therefore, such LWP must be stopped first in order to
1828 be able to modify its hardware watchpoints.
1830 Hardware watchpoints must be reset exactly once after being
1831 presented to the user. It cannot be done sooner, because it would
1832 reset the data used to present the watchpoint hit to the user. And
1833 it must not be done later because it could display the same single
1834 watchpoint hit during multiple GDB stops. Note that the latter is
1835 relevant only to the hardware watchpoint types bp_read_watchpoint
1836 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1837 not user-visible - its hit is suppressed if the memory content has
1840 The following constraints influence the location where we can reset
1841 hardware watchpoints:
1843 * target_stopped_by_watchpoint and target_stopped_data_address are
1844 called several times when GDB stops.
1847 * Multiple hardware watchpoints can be hit at the same time,
1848 causing GDB to stop. GDB only presents one hardware watchpoint
1849 hit at a time as the reason for stopping, and all the other hits
1850 are presented later, one after the other, each time the user
1851 requests the execution to be resumed. Execution is not resumed
1852 for the threads still having pending hit event stored in
1853 LWP_INFO->STATUS. While the watchpoint is already removed from
1854 the inferior on the first stop the thread hit event is kept being
1855 reported from its cached value by linux_nat_stopped_data_address
1856 until the real thread resume happens after the watchpoint gets
1857 presented and thus its LWP_INFO->STATUS gets reset.
1859 Therefore the hardware watchpoint hit can get safely reset on the
1860 watchpoint removal from inferior. */
1863 update_watchpoint (struct watchpoint *b, int reparse)
1865 int within_current_scope;
1866 struct frame_id saved_frame_id;
1869 /* If this is a local watchpoint, we only want to check if the
1870 watchpoint frame is in scope if the current thread is the thread
1871 that was used to create the watchpoint. */
1872 if (!watchpoint_in_thread_scope (b))
1875 if (b->base.disposition == disp_del_at_next_stop)
1880 /* Determine if the watchpoint is within scope. */
1881 if (b->exp_valid_block == NULL)
1882 within_current_scope = 1;
1885 struct frame_info *fi = get_current_frame ();
1886 struct gdbarch *frame_arch = get_frame_arch (fi);
1887 CORE_ADDR frame_pc = get_frame_pc (fi);
1889 /* If we're at a point where the stack has been destroyed
1890 (e.g. in a function epilogue), unwinding may not work
1891 properly. Do not attempt to recreate locations at this
1892 point. See similar comments in watchpoint_check. */
1893 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1896 /* Save the current frame's ID so we can restore it after
1897 evaluating the watchpoint expression on its own frame. */
1898 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1899 took a frame parameter, so that we didn't have to change the
1902 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1904 fi = frame_find_by_id (b->watchpoint_frame);
1905 within_current_scope = (fi != NULL);
1906 if (within_current_scope)
1910 /* We don't free locations. They are stored in the bp_location array
1911 and update_global_location_list will eventually delete them and
1912 remove breakpoints if needed. */
1915 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->base.cond_string != NULL)
1939 if (b->cond_exp != NULL)
1941 xfree (b->cond_exp);
1945 s = b->base.cond_string;
1946 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1950 /* If we failed to parse the expression, for example because
1951 it refers to a global variable in a not-yet-loaded shared library,
1952 don't try to insert watchpoint. We don't automatically delete
1953 such watchpoint, though, since failure to parse expression
1954 is different from out-of-scope watchpoint. */
1955 if (!target_has_execution)
1957 /* Without execution, memory can't change. No use to try and
1958 set watchpoint locations. The watchpoint will be reset when
1959 the target gains execution, through breakpoint_re_set. */
1960 if (!can_use_hw_watchpoints)
1962 if (b->base.ops->works_in_software_mode (&b->base))
1963 b->base.type = bp_watchpoint;
1965 error (_("Can't set read/access watchpoint when "
1966 "hardware watchpoints are disabled."));
1969 else if (within_current_scope && b->exp)
1972 struct value *val_chain, *v, *result, *next;
1973 struct program_space *frame_pspace;
1975 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1977 /* Avoid setting b->val if it's already set. The meaning of
1978 b->val is 'the last value' user saw, and we should update
1979 it only if we reported that last value to user. As it
1980 happens, the code that reports it updates b->val directly.
1981 We don't keep track of the memory value for masked
1983 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1985 if (b->val_bitsize != 0)
1987 v = extract_bitfield_from_watchpoint_value (b, v);
1995 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1997 /* Look at each value on the value chain. */
1998 for (v = val_chain; v; v = value_next (v))
2000 /* If it's a memory location, and GDB actually needed
2001 its contents to evaluate the expression, then we
2002 must watch it. If the first value returned is
2003 still lazy, that means an error occurred reading it;
2004 watch it anyway in case it becomes readable. */
2005 if (VALUE_LVAL (v) == lval_memory
2006 && (v == val_chain || ! value_lazy (v)))
2008 struct type *vtype = check_typedef (value_type (v));
2010 /* We only watch structs and arrays if user asked
2011 for it explicitly, never if they just happen to
2012 appear in the middle of some value chain. */
2014 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2015 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2018 enum target_hw_bp_type type;
2019 struct bp_location *loc, **tmp;
2020 int bitpos = 0, bitsize = 0;
2022 if (value_bitsize (v) != 0)
2024 /* Extract the bit parameters out from the bitfield
2026 bitpos = value_bitpos (v);
2027 bitsize = value_bitsize (v);
2029 else if (v == result && b->val_bitsize != 0)
2031 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2032 lvalue whose bit parameters are saved in the fields
2033 VAL_BITPOS and VAL_BITSIZE. */
2034 bitpos = b->val_bitpos;
2035 bitsize = b->val_bitsize;
2038 addr = value_address (v);
2041 /* Skip the bytes that don't contain the bitfield. */
2046 if (b->base.type == bp_read_watchpoint)
2048 else if (b->base.type == bp_access_watchpoint)
2051 loc = allocate_bp_location (&b->base);
2052 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
2055 loc->gdbarch = get_type_arch (value_type (v));
2057 loc->pspace = frame_pspace;
2058 loc->address = addr;
2062 /* Just cover the bytes that make up the bitfield. */
2063 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2066 loc->length = TYPE_LENGTH (value_type (v));
2068 loc->watchpoint_type = type;
2073 /* Change the type of breakpoint between hardware assisted or
2074 an ordinary watchpoint depending on the hardware support
2075 and free hardware slots. REPARSE is set when the inferior
2080 enum bp_loc_type loc_type;
2081 struct bp_location *bl;
2083 reg_cnt = can_use_hardware_watchpoint (val_chain);
2087 int i, target_resources_ok, other_type_used;
2090 /* Use an exact watchpoint when there's only one memory region to be
2091 watched, and only one debug register is needed to watch it. */
2092 b->exact = target_exact_watchpoints && reg_cnt == 1;
2094 /* We need to determine how many resources are already
2095 used for all other hardware watchpoints plus this one
2096 to see if we still have enough resources to also fit
2097 this watchpoint in as well. */
2099 /* If this is a software watchpoint, we try to turn it
2100 to a hardware one -- count resources as if B was of
2101 hardware watchpoint type. */
2102 type = b->base.type;
2103 if (type == bp_watchpoint)
2104 type = bp_hardware_watchpoint;
2106 /* This watchpoint may or may not have been placed on
2107 the list yet at this point (it won't be in the list
2108 if we're trying to create it for the first time,
2109 through watch_command), so always account for it
2112 /* Count resources used by all watchpoints except B. */
2113 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2115 /* Add in the resources needed for B. */
2116 i += hw_watchpoint_use_count (&b->base);
2119 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2120 if (target_resources_ok <= 0)
2122 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2124 if (target_resources_ok == 0 && !sw_mode)
2125 error (_("Target does not support this type of "
2126 "hardware watchpoint."));
2127 else if (target_resources_ok < 0 && !sw_mode)
2128 error (_("There are not enough available hardware "
2129 "resources for this watchpoint."));
2131 /* Downgrade to software watchpoint. */
2132 b->base.type = bp_watchpoint;
2136 /* If this was a software watchpoint, we've just
2137 found we have enough resources to turn it to a
2138 hardware watchpoint. Otherwise, this is a
2140 b->base.type = type;
2143 else if (!b->base.ops->works_in_software_mode (&b->base))
2145 if (!can_use_hw_watchpoints)
2146 error (_("Can't set read/access watchpoint when "
2147 "hardware watchpoints are disabled."));
2149 error (_("Expression cannot be implemented with "
2150 "read/access watchpoint."));
2153 b->base.type = bp_watchpoint;
2155 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2156 : bp_loc_hardware_watchpoint);
2157 for (bl = b->base.loc; bl; bl = bl->next)
2158 bl->loc_type = loc_type;
2161 for (v = val_chain; v; v = next)
2163 next = value_next (v);
2168 /* If a software watchpoint is not watching any memory, then the
2169 above left it without any location set up. But,
2170 bpstat_stop_status requires a location to be able to report
2171 stops, so make sure there's at least a dummy one. */
2172 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2173 software_watchpoint_add_no_memory_location (&b->base, frame_pspace);
2175 else if (!within_current_scope)
2177 printf_filtered (_("\
2178 Watchpoint %d deleted because the program has left the block\n\
2179 in which its expression is valid.\n"),
2181 watchpoint_del_at_next_stop (b);
2184 /* Restore the selected frame. */
2186 select_frame (frame_find_by_id (saved_frame_id));
2190 /* Returns 1 iff breakpoint location should be
2191 inserted in the inferior. We don't differentiate the type of BL's owner
2192 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2193 breakpoint_ops is not defined, because in insert_bp_location,
2194 tracepoint's insert_location will not be called. */
2196 should_be_inserted (struct bp_location *bl)
2198 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2201 if (bl->owner->disposition == disp_del_at_next_stop)
2204 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2207 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2210 /* This is set for example, when we're attached to the parent of a
2211 vfork, and have detached from the child. The child is running
2212 free, and we expect it to do an exec or exit, at which point the
2213 OS makes the parent schedulable again (and the target reports
2214 that the vfork is done). Until the child is done with the shared
2215 memory region, do not insert breakpoints in the parent, otherwise
2216 the child could still trip on the parent's breakpoints. Since
2217 the parent is blocked anyway, it won't miss any breakpoint. */
2218 if (bl->pspace->breakpoints_not_allowed)
2221 /* Don't insert a breakpoint if we're trying to step past its
2223 if ((bl->loc_type == bp_loc_software_breakpoint
2224 || bl->loc_type == bp_loc_hardware_breakpoint)
2225 && stepping_past_instruction_at (bl->pspace->aspace,
2230 fprintf_unfiltered (gdb_stdlog,
2231 "infrun: skipping breakpoint: "
2232 "stepping past insn at: %s\n",
2233 paddress (bl->gdbarch, bl->address));
2238 /* Don't insert watchpoints if we're trying to step past the
2239 instruction that triggered one. */
2240 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2241 && stepping_past_nonsteppable_watchpoint ())
2245 fprintf_unfiltered (gdb_stdlog,
2246 "infrun: stepping past non-steppable watchpoint. "
2247 "skipping watchpoint at %s:%d\n",
2248 paddress (bl->gdbarch, bl->address),
2257 /* Same as should_be_inserted but does the check assuming
2258 that the location is not duplicated. */
2261 unduplicated_should_be_inserted (struct bp_location *bl)
2264 const int save_duplicate = bl->duplicate;
2267 result = should_be_inserted (bl);
2268 bl->duplicate = save_duplicate;
2272 /* Parses a conditional described by an expression COND into an
2273 agent expression bytecode suitable for evaluation
2274 by the bytecode interpreter. Return NULL if there was
2275 any error during parsing. */
2277 static struct agent_expr *
2278 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2280 struct agent_expr *aexpr = NULL;
2285 /* We don't want to stop processing, so catch any errors
2286 that may show up. */
2289 aexpr = gen_eval_for_expr (scope, cond);
2292 CATCH (ex, RETURN_MASK_ERROR)
2294 /* If we got here, it means the condition could not be parsed to a valid
2295 bytecode expression and thus can't be evaluated on the target's side.
2296 It's no use iterating through the conditions. */
2301 /* We have a valid agent expression. */
2305 /* Based on location BL, create a list of breakpoint conditions to be
2306 passed on to the target. If we have duplicated locations with different
2307 conditions, we will add such conditions to the list. The idea is that the
2308 target will evaluate the list of conditions and will only notify GDB when
2309 one of them is true. */
2312 build_target_condition_list (struct bp_location *bl)
2314 struct bp_location **locp = NULL, **loc2p;
2315 int null_condition_or_parse_error = 0;
2316 int modified = bl->needs_update;
2317 struct bp_location *loc;
2319 /* Release conditions left over from a previous insert. */
2320 VEC_free (agent_expr_p, bl->target_info.conditions);
2322 /* This is only meaningful if the target is
2323 evaluating conditions and if the user has
2324 opted for condition evaluation on the target's
2326 if (gdb_evaluates_breakpoint_condition_p ()
2327 || !target_supports_evaluation_of_breakpoint_conditions ())
2330 /* Do a first pass to check for locations with no assigned
2331 conditions or conditions that fail to parse to a valid agent expression
2332 bytecode. If any of these happen, then it's no use to send conditions
2333 to the target since this location will always trigger and generate a
2334 response back to GDB. */
2335 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2338 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2342 struct agent_expr *aexpr;
2344 /* Re-parse the conditions since something changed. In that
2345 case we already freed the condition bytecodes (see
2346 force_breakpoint_reinsertion). We just
2347 need to parse the condition to bytecodes again. */
2348 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2349 loc->cond_bytecode = aexpr;
2352 /* If we have a NULL bytecode expression, it means something
2353 went wrong or we have a null condition expression. */
2354 if (!loc->cond_bytecode)
2356 null_condition_or_parse_error = 1;
2362 /* If any of these happened, it means we will have to evaluate the conditions
2363 for the location's address on gdb's side. It is no use keeping bytecodes
2364 for all the other duplicate locations, thus we free all of them here.
2366 This is so we have a finer control over which locations' conditions are
2367 being evaluated by GDB or the remote stub. */
2368 if (null_condition_or_parse_error)
2370 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2373 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2375 /* Only go as far as the first NULL bytecode is
2377 if (!loc->cond_bytecode)
2380 free_agent_expr (loc->cond_bytecode);
2381 loc->cond_bytecode = NULL;
2386 /* No NULL conditions or failed bytecode generation. Build a condition list
2387 for this location's address. */
2388 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2392 && is_breakpoint (loc->owner)
2393 && loc->pspace->num == bl->pspace->num
2394 && loc->owner->enable_state == bp_enabled
2396 /* Add the condition to the vector. This will be used later to send the
2397 conditions to the target. */
2398 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2399 loc->cond_bytecode);
2405 /* Parses a command described by string CMD into an agent expression
2406 bytecode suitable for evaluation by the bytecode interpreter.
2407 Return NULL if there was any error during parsing. */
2409 static struct agent_expr *
2410 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2412 struct cleanup *old_cleanups = 0;
2413 struct expression *expr, **argvec;
2414 struct agent_expr *aexpr = NULL;
2415 const char *cmdrest;
2416 const char *format_start, *format_end;
2417 struct format_piece *fpieces;
2419 struct gdbarch *gdbarch = get_current_arch ();
2426 if (*cmdrest == ',')
2428 cmdrest = skip_spaces_const (cmdrest);
2430 if (*cmdrest++ != '"')
2431 error (_("No format string following the location"));
2433 format_start = cmdrest;
2435 fpieces = parse_format_string (&cmdrest);
2437 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2439 format_end = cmdrest;
2441 if (*cmdrest++ != '"')
2442 error (_("Bad format string, non-terminated '\"'."));
2444 cmdrest = skip_spaces_const (cmdrest);
2446 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2447 error (_("Invalid argument syntax"));
2449 if (*cmdrest == ',')
2451 cmdrest = skip_spaces_const (cmdrest);
2453 /* For each argument, make an expression. */
2455 argvec = (struct expression **) alloca (strlen (cmd)
2456 * sizeof (struct expression *));
2459 while (*cmdrest != '\0')
2464 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2465 argvec[nargs++] = expr;
2467 if (*cmdrest == ',')
2471 /* We don't want to stop processing, so catch any errors
2472 that may show up. */
2475 aexpr = gen_printf (scope, gdbarch, 0, 0,
2476 format_start, format_end - format_start,
2477 fpieces, nargs, argvec);
2479 CATCH (ex, RETURN_MASK_ERROR)
2481 /* If we got here, it means the command could not be parsed to a valid
2482 bytecode expression and thus can't be evaluated on the target's side.
2483 It's no use iterating through the other commands. */
2488 do_cleanups (old_cleanups);
2490 /* We have a valid agent expression, return it. */
2494 /* Based on location BL, create a list of breakpoint commands to be
2495 passed on to the target. If we have duplicated locations with
2496 different commands, we will add any such to the list. */
2499 build_target_command_list (struct bp_location *bl)
2501 struct bp_location **locp = NULL, **loc2p;
2502 int null_command_or_parse_error = 0;
2503 int modified = bl->needs_update;
2504 struct bp_location *loc;
2506 /* Release commands left over from a previous insert. */
2507 VEC_free (agent_expr_p, bl->target_info.tcommands);
2509 if (!target_can_run_breakpoint_commands ())
2512 /* For now, limit to agent-style dprintf breakpoints. */
2513 if (dprintf_style != dprintf_style_agent)
2516 /* For now, if we have any duplicate location that isn't a dprintf,
2517 don't install the target-side commands, as that would make the
2518 breakpoint not be reported to the core, and we'd lose
2520 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2523 if (is_breakpoint (loc->owner)
2524 && loc->pspace->num == bl->pspace->num
2525 && loc->owner->type != bp_dprintf)
2529 /* Do a first pass to check for locations with no assigned
2530 conditions or conditions that fail to parse to a valid agent expression
2531 bytecode. If any of these happen, then it's no use to send conditions
2532 to the target since this location will always trigger and generate a
2533 response back to GDB. */
2534 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2537 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2541 struct agent_expr *aexpr;
2543 /* Re-parse the commands since something changed. In that
2544 case we already freed the command bytecodes (see
2545 force_breakpoint_reinsertion). We just
2546 need to parse the command to bytecodes again. */
2547 aexpr = parse_cmd_to_aexpr (bl->address,
2548 loc->owner->extra_string);
2549 loc->cmd_bytecode = aexpr;
2552 /* If we have a NULL bytecode expression, it means something
2553 went wrong or we have a null command expression. */
2554 if (!loc->cmd_bytecode)
2556 null_command_or_parse_error = 1;
2562 /* If anything failed, then we're not doing target-side commands,
2564 if (null_command_or_parse_error)
2566 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2569 if (is_breakpoint (loc->owner)
2570 && loc->pspace->num == bl->pspace->num)
2572 /* Only go as far as the first NULL bytecode is
2574 if (loc->cmd_bytecode == NULL)
2577 free_agent_expr (loc->cmd_bytecode);
2578 loc->cmd_bytecode = NULL;
2583 /* No NULL commands or failed bytecode generation. Build a command list
2584 for this location's address. */
2585 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2588 if (loc->owner->extra_string
2589 && is_breakpoint (loc->owner)
2590 && loc->pspace->num == bl->pspace->num
2591 && loc->owner->enable_state == bp_enabled
2593 /* Add the command to the vector. This will be used later
2594 to send the commands to the target. */
2595 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2599 bl->target_info.persist = 0;
2600 /* Maybe flag this location as persistent. */
2601 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2602 bl->target_info.persist = 1;
2605 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2606 location. Any error messages are printed to TMP_ERROR_STREAM; and
2607 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2608 Returns 0 for success, 1 if the bp_location type is not supported or
2611 NOTE drow/2003-09-09: This routine could be broken down to an
2612 object-style method for each breakpoint or catchpoint type. */
2614 insert_bp_location (struct bp_location *bl,
2615 struct ui_file *tmp_error_stream,
2616 int *disabled_breaks,
2617 int *hw_breakpoint_error,
2618 int *hw_bp_error_explained_already)
2620 enum errors bp_err = GDB_NO_ERROR;
2621 const char *bp_err_message = NULL;
2623 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2626 /* Note we don't initialize bl->target_info, as that wipes out
2627 the breakpoint location's shadow_contents if the breakpoint
2628 is still inserted at that location. This in turn breaks
2629 target_read_memory which depends on these buffers when
2630 a memory read is requested at the breakpoint location:
2631 Once the target_info has been wiped, we fail to see that
2632 we have a breakpoint inserted at that address and thus
2633 read the breakpoint instead of returning the data saved in
2634 the breakpoint location's shadow contents. */
2635 bl->target_info.reqstd_address = bl->address;
2636 bl->target_info.placed_address_space = bl->pspace->aspace;
2637 bl->target_info.length = bl->length;
2639 /* When working with target-side conditions, we must pass all the conditions
2640 for the same breakpoint address down to the target since GDB will not
2641 insert those locations. With a list of breakpoint conditions, the target
2642 can decide when to stop and notify GDB. */
2644 if (is_breakpoint (bl->owner))
2646 build_target_condition_list (bl);
2647 build_target_command_list (bl);
2648 /* Reset the modification marker. */
2649 bl->needs_update = 0;
2652 if (bl->loc_type == bp_loc_software_breakpoint
2653 || bl->loc_type == bp_loc_hardware_breakpoint)
2655 if (bl->owner->type != bp_hardware_breakpoint)
2657 /* If the explicitly specified breakpoint type
2658 is not hardware breakpoint, check the memory map to see
2659 if the breakpoint address is in read only memory or not.
2661 Two important cases are:
2662 - location type is not hardware breakpoint, memory
2663 is readonly. We change the type of the location to
2664 hardware breakpoint.
2665 - location type is hardware breakpoint, memory is
2666 read-write. This means we've previously made the
2667 location hardware one, but then the memory map changed,
2670 When breakpoints are removed, remove_breakpoints will use
2671 location types we've just set here, the only possible
2672 problem is that memory map has changed during running
2673 program, but it's not going to work anyway with current
2675 struct mem_region *mr
2676 = lookup_mem_region (bl->target_info.reqstd_address);
2680 if (automatic_hardware_breakpoints)
2682 enum bp_loc_type new_type;
2684 if (mr->attrib.mode != MEM_RW)
2685 new_type = bp_loc_hardware_breakpoint;
2687 new_type = bp_loc_software_breakpoint;
2689 if (new_type != bl->loc_type)
2691 static int said = 0;
2693 bl->loc_type = new_type;
2696 fprintf_filtered (gdb_stdout,
2697 _("Note: automatically using "
2698 "hardware breakpoints for "
2699 "read-only addresses.\n"));
2704 else if (bl->loc_type == bp_loc_software_breakpoint
2705 && mr->attrib.mode != MEM_RW)
2707 fprintf_unfiltered (tmp_error_stream,
2708 _("Cannot insert breakpoint %d.\n"
2709 "Cannot set software breakpoint "
2710 "at read-only address %s\n"),
2712 paddress (bl->gdbarch, bl->address));
2718 /* First check to see if we have to handle an overlay. */
2719 if (overlay_debugging == ovly_off
2720 || bl->section == NULL
2721 || !(section_is_overlay (bl->section)))
2723 /* No overlay handling: just set the breakpoint. */
2728 val = bl->owner->ops->insert_location (bl);
2730 bp_err = GENERIC_ERROR;
2732 CATCH (e, RETURN_MASK_ALL)
2735 bp_err_message = e.message;
2741 /* This breakpoint is in an overlay section.
2742 Shall we set a breakpoint at the LMA? */
2743 if (!overlay_events_enabled)
2745 /* Yes -- overlay event support is not active,
2746 so we must try to set a breakpoint at the LMA.
2747 This will not work for a hardware breakpoint. */
2748 if (bl->loc_type == bp_loc_hardware_breakpoint)
2749 warning (_("hardware breakpoint %d not supported in overlay!"),
2753 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2755 /* Set a software (trap) breakpoint at the LMA. */
2756 bl->overlay_target_info = bl->target_info;
2757 bl->overlay_target_info.reqstd_address = addr;
2759 /* No overlay handling: just set the breakpoint. */
2764 val = target_insert_breakpoint (bl->gdbarch,
2765 &bl->overlay_target_info);
2767 bp_err = GENERIC_ERROR;
2769 CATCH (e, RETURN_MASK_ALL)
2772 bp_err_message = e.message;
2776 if (bp_err != GDB_NO_ERROR)
2777 fprintf_unfiltered (tmp_error_stream,
2778 "Overlay breakpoint %d "
2779 "failed: in ROM?\n",
2783 /* Shall we set a breakpoint at the VMA? */
2784 if (section_is_mapped (bl->section))
2786 /* Yes. This overlay section is mapped into memory. */
2791 val = bl->owner->ops->insert_location (bl);
2793 bp_err = GENERIC_ERROR;
2795 CATCH (e, RETURN_MASK_ALL)
2798 bp_err_message = e.message;
2804 /* No. This breakpoint will not be inserted.
2805 No error, but do not mark the bp as 'inserted'. */
2810 if (bp_err != GDB_NO_ERROR)
2812 /* Can't set the breakpoint. */
2814 /* In some cases, we might not be able to insert a
2815 breakpoint in a shared library that has already been
2816 removed, but we have not yet processed the shlib unload
2817 event. Unfortunately, some targets that implement
2818 breakpoint insertion themselves can't tell why the
2819 breakpoint insertion failed (e.g., the remote target
2820 doesn't define error codes), so we must treat generic
2821 errors as memory errors. */
2822 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2823 && bl->loc_type == bp_loc_software_breakpoint
2824 && (solib_name_from_address (bl->pspace, bl->address)
2825 || shared_objfile_contains_address_p (bl->pspace,
2828 /* See also: disable_breakpoints_in_shlibs. */
2829 bl->shlib_disabled = 1;
2830 observer_notify_breakpoint_modified (bl->owner);
2831 if (!*disabled_breaks)
2833 fprintf_unfiltered (tmp_error_stream,
2834 "Cannot insert breakpoint %d.\n",
2836 fprintf_unfiltered (tmp_error_stream,
2837 "Temporarily disabling shared "
2838 "library breakpoints:\n");
2840 *disabled_breaks = 1;
2841 fprintf_unfiltered (tmp_error_stream,
2842 "breakpoint #%d\n", bl->owner->number);
2847 if (bl->loc_type == bp_loc_hardware_breakpoint)
2849 *hw_breakpoint_error = 1;
2850 *hw_bp_error_explained_already = bp_err_message != NULL;
2851 fprintf_unfiltered (tmp_error_stream,
2852 "Cannot insert hardware breakpoint %d%s",
2853 bl->owner->number, bp_err_message ? ":" : ".\n");
2854 if (bp_err_message != NULL)
2855 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2859 if (bp_err_message == NULL)
2862 = memory_error_message (TARGET_XFER_E_IO,
2863 bl->gdbarch, bl->address);
2864 struct cleanup *old_chain = make_cleanup (xfree, message);
2866 fprintf_unfiltered (tmp_error_stream,
2867 "Cannot insert breakpoint %d.\n"
2869 bl->owner->number, message);
2870 do_cleanups (old_chain);
2874 fprintf_unfiltered (tmp_error_stream,
2875 "Cannot insert breakpoint %d: %s\n",
2890 else if (bl->loc_type == bp_loc_hardware_watchpoint
2891 /* NOTE drow/2003-09-08: This state only exists for removing
2892 watchpoints. It's not clear that it's necessary... */
2893 && bl->owner->disposition != disp_del_at_next_stop)
2897 gdb_assert (bl->owner->ops != NULL
2898 && bl->owner->ops->insert_location != NULL);
2900 val = bl->owner->ops->insert_location (bl);
2902 /* If trying to set a read-watchpoint, and it turns out it's not
2903 supported, try emulating one with an access watchpoint. */
2904 if (val == 1 && bl->watchpoint_type == hw_read)
2906 struct bp_location *loc, **loc_temp;
2908 /* But don't try to insert it, if there's already another
2909 hw_access location that would be considered a duplicate
2911 ALL_BP_LOCATIONS (loc, loc_temp)
2913 && loc->watchpoint_type == hw_access
2914 && watchpoint_locations_match (bl, loc))
2918 bl->target_info = loc->target_info;
2919 bl->watchpoint_type = hw_access;
2926 bl->watchpoint_type = hw_access;
2927 val = bl->owner->ops->insert_location (bl);
2930 /* Back to the original value. */
2931 bl->watchpoint_type = hw_read;
2935 bl->inserted = (val == 0);
2938 else if (bl->owner->type == bp_catchpoint)
2942 gdb_assert (bl->owner->ops != NULL
2943 && bl->owner->ops->insert_location != NULL);
2945 val = bl->owner->ops->insert_location (bl);
2948 bl->owner->enable_state = bp_disabled;
2952 Error inserting catchpoint %d: Your system does not support this type\n\
2953 of catchpoint."), bl->owner->number);
2955 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2958 bl->inserted = (val == 0);
2960 /* We've already printed an error message if there was a problem
2961 inserting this catchpoint, and we've disabled the catchpoint,
2962 so just return success. */
2969 /* This function is called when program space PSPACE is about to be
2970 deleted. It takes care of updating breakpoints to not reference
2974 breakpoint_program_space_exit (struct program_space *pspace)
2976 struct breakpoint *b, *b_temp;
2977 struct bp_location *loc, **loc_temp;
2979 /* Remove any breakpoint that was set through this program space. */
2980 ALL_BREAKPOINTS_SAFE (b, b_temp)
2982 if (b->pspace == pspace)
2983 delete_breakpoint (b);
2986 /* Breakpoints set through other program spaces could have locations
2987 bound to PSPACE as well. Remove those. */
2988 ALL_BP_LOCATIONS (loc, loc_temp)
2990 struct bp_location *tmp;
2992 if (loc->pspace == pspace)
2994 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2995 if (loc->owner->loc == loc)
2996 loc->owner->loc = loc->next;
2998 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2999 if (tmp->next == loc)
3001 tmp->next = loc->next;
3007 /* Now update the global location list to permanently delete the
3008 removed locations above. */
3009 update_global_location_list (UGLL_DONT_INSERT);
3012 /* Make sure all breakpoints are inserted in inferior.
3013 Throws exception on any error.
3014 A breakpoint that is already inserted won't be inserted
3015 again, so calling this function twice is safe. */
3017 insert_breakpoints (void)
3019 struct breakpoint *bpt;
3021 ALL_BREAKPOINTS (bpt)
3022 if (is_hardware_watchpoint (bpt))
3024 struct watchpoint *w = (struct watchpoint *) bpt;
3026 update_watchpoint (w, 0 /* don't reparse. */);
3029 /* Updating watchpoints creates new locations, so update the global
3030 location list. Explicitly tell ugll to insert locations and
3031 ignore breakpoints_always_inserted_mode. */
3032 update_global_location_list (UGLL_INSERT);
3035 /* Invoke CALLBACK for each of bp_location. */
3038 iterate_over_bp_locations (walk_bp_location_callback callback)
3040 struct bp_location *loc, **loc_tmp;
3042 ALL_BP_LOCATIONS (loc, loc_tmp)
3044 callback (loc, NULL);
3048 /* This is used when we need to synch breakpoint conditions between GDB and the
3049 target. It is the case with deleting and disabling of breakpoints when using
3050 always-inserted mode. */
3053 update_inserted_breakpoint_locations (void)
3055 struct bp_location *bl, **blp_tmp;
3058 int disabled_breaks = 0;
3059 int hw_breakpoint_error = 0;
3060 int hw_bp_details_reported = 0;
3062 struct ui_file *tmp_error_stream = mem_fileopen ();
3063 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3065 /* Explicitly mark the warning -- this will only be printed if
3066 there was an error. */
3067 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3069 save_current_space_and_thread ();
3071 ALL_BP_LOCATIONS (bl, blp_tmp)
3073 /* We only want to update software breakpoints and hardware
3075 if (!is_breakpoint (bl->owner))
3078 /* We only want to update locations that are already inserted
3079 and need updating. This is to avoid unwanted insertion during
3080 deletion of breakpoints. */
3081 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3084 switch_to_program_space_and_thread (bl->pspace);
3086 /* For targets that support global breakpoints, there's no need
3087 to select an inferior to insert breakpoint to. In fact, even
3088 if we aren't attached to any process yet, we should still
3089 insert breakpoints. */
3090 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3091 && ptid_equal (inferior_ptid, null_ptid))
3094 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3095 &hw_breakpoint_error, &hw_bp_details_reported);
3102 target_terminal_ours_for_output ();
3103 error_stream (tmp_error_stream);
3106 do_cleanups (cleanups);
3109 /* Used when starting or continuing the program. */
3112 insert_breakpoint_locations (void)
3114 struct breakpoint *bpt;
3115 struct bp_location *bl, **blp_tmp;
3118 int disabled_breaks = 0;
3119 int hw_breakpoint_error = 0;
3120 int hw_bp_error_explained_already = 0;
3122 struct ui_file *tmp_error_stream = mem_fileopen ();
3123 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3125 /* Explicitly mark the warning -- this will only be printed if
3126 there was an error. */
3127 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3129 save_current_space_and_thread ();
3131 ALL_BP_LOCATIONS (bl, blp_tmp)
3133 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3136 /* There is no point inserting thread-specific breakpoints if
3137 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3138 has BL->OWNER always non-NULL. */
3139 if (bl->owner->thread != -1
3140 && !valid_global_thread_id (bl->owner->thread))
3143 switch_to_program_space_and_thread (bl->pspace);
3145 /* For targets that support global breakpoints, there's no need
3146 to select an inferior to insert breakpoint to. In fact, even
3147 if we aren't attached to any process yet, we should still
3148 insert breakpoints. */
3149 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3150 && ptid_equal (inferior_ptid, null_ptid))
3153 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3154 &hw_breakpoint_error, &hw_bp_error_explained_already);
3159 /* If we failed to insert all locations of a watchpoint, remove
3160 them, as half-inserted watchpoint is of limited use. */
3161 ALL_BREAKPOINTS (bpt)
3163 int some_failed = 0;
3164 struct bp_location *loc;
3166 if (!is_hardware_watchpoint (bpt))
3169 if (!breakpoint_enabled (bpt))
3172 if (bpt->disposition == disp_del_at_next_stop)
3175 for (loc = bpt->loc; loc; loc = loc->next)
3176 if (!loc->inserted && should_be_inserted (loc))
3183 for (loc = bpt->loc; loc; loc = loc->next)
3185 remove_breakpoint (loc, mark_uninserted);
3187 hw_breakpoint_error = 1;
3188 fprintf_unfiltered (tmp_error_stream,
3189 "Could not insert hardware watchpoint %d.\n",
3197 /* If a hardware breakpoint or watchpoint was inserted, add a
3198 message about possibly exhausted resources. */
3199 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3201 fprintf_unfiltered (tmp_error_stream,
3202 "Could not insert hardware breakpoints:\n\
3203 You may have requested too many hardware breakpoints/watchpoints.\n");
3205 target_terminal_ours_for_output ();
3206 error_stream (tmp_error_stream);
3209 do_cleanups (cleanups);
3212 /* Used when the program stops.
3213 Returns zero if successful, or non-zero if there was a problem
3214 removing a breakpoint location. */
3217 remove_breakpoints (void)
3219 struct bp_location *bl, **blp_tmp;
3222 ALL_BP_LOCATIONS (bl, blp_tmp)
3224 if (bl->inserted && !is_tracepoint (bl->owner))
3225 val |= remove_breakpoint (bl, mark_uninserted);
3230 /* When a thread exits, remove breakpoints that are related to
3234 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3236 struct breakpoint *b, *b_tmp;
3238 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3240 if (b->thread == tp->global_num && user_breakpoint_p (b))
3242 b->disposition = disp_del_at_next_stop;
3244 printf_filtered (_("\
3245 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3246 b->number, print_thread_id (tp));
3248 /* Hide it from the user. */
3254 /* Remove breakpoints of process PID. */
3257 remove_breakpoints_pid (int pid)
3259 struct bp_location *bl, **blp_tmp;
3261 struct inferior *inf = find_inferior_pid (pid);
3263 ALL_BP_LOCATIONS (bl, blp_tmp)
3265 if (bl->pspace != inf->pspace)
3268 if (bl->inserted && !bl->target_info.persist)
3270 val = remove_breakpoint (bl, mark_uninserted);
3279 reattach_breakpoints (int pid)
3281 struct cleanup *old_chain;
3282 struct bp_location *bl, **blp_tmp;
3284 struct ui_file *tmp_error_stream;
3285 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3286 struct inferior *inf;
3287 struct thread_info *tp;
3289 tp = any_live_thread_of_process (pid);
3293 inf = find_inferior_pid (pid);
3294 old_chain = save_inferior_ptid ();
3296 inferior_ptid = tp->ptid;
3298 tmp_error_stream = mem_fileopen ();
3299 make_cleanup_ui_file_delete (tmp_error_stream);
3301 ALL_BP_LOCATIONS (bl, blp_tmp)
3303 if (bl->pspace != inf->pspace)
3309 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3312 do_cleanups (old_chain);
3317 do_cleanups (old_chain);
3321 static int internal_breakpoint_number = -1;
3323 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3324 If INTERNAL is non-zero, the breakpoint number will be populated
3325 from internal_breakpoint_number and that variable decremented.
3326 Otherwise the breakpoint number will be populated from
3327 breakpoint_count and that value incremented. Internal breakpoints
3328 do not set the internal var bpnum. */
3330 set_breakpoint_number (int internal, struct breakpoint *b)
3333 b->number = internal_breakpoint_number--;
3336 set_breakpoint_count (breakpoint_count + 1);
3337 b->number = breakpoint_count;
3341 static struct breakpoint *
3342 create_internal_breakpoint (struct gdbarch *gdbarch,
3343 CORE_ADDR address, enum bptype type,
3344 const struct breakpoint_ops *ops)
3346 struct symtab_and_line sal;
3347 struct breakpoint *b;
3349 init_sal (&sal); /* Initialize to zeroes. */
3352 sal.section = find_pc_overlay (sal.pc);
3353 sal.pspace = current_program_space;
3355 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3356 b->number = internal_breakpoint_number--;
3357 b->disposition = disp_donttouch;
3362 static const char *const longjmp_names[] =
3364 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3366 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3368 /* Per-objfile data private to breakpoint.c. */
3369 struct breakpoint_objfile_data
3371 /* Minimal symbol for "_ovly_debug_event" (if any). */
3372 struct bound_minimal_symbol overlay_msym;
3374 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3375 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3377 /* True if we have looked for longjmp probes. */
3378 int longjmp_searched;
3380 /* SystemTap probe points for longjmp (if any). */
3381 VEC (probe_p) *longjmp_probes;
3383 /* Minimal symbol for "std::terminate()" (if any). */
3384 struct bound_minimal_symbol terminate_msym;
3386 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3387 struct bound_minimal_symbol exception_msym;
3389 /* True if we have looked for exception probes. */
3390 int exception_searched;
3392 /* SystemTap probe points for unwinding (if any). */
3393 VEC (probe_p) *exception_probes;
3396 static const struct objfile_data *breakpoint_objfile_key;
3398 /* Minimal symbol not found sentinel. */
3399 static struct minimal_symbol msym_not_found;
3401 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3404 msym_not_found_p (const struct minimal_symbol *msym)
3406 return msym == &msym_not_found;
3409 /* Return per-objfile data needed by breakpoint.c.
3410 Allocate the data if necessary. */
3412 static struct breakpoint_objfile_data *
3413 get_breakpoint_objfile_data (struct objfile *objfile)
3415 struct breakpoint_objfile_data *bp_objfile_data;
3417 bp_objfile_data = ((struct breakpoint_objfile_data *)
3418 objfile_data (objfile, breakpoint_objfile_key));
3419 if (bp_objfile_data == NULL)
3422 XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
3424 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3425 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3427 return bp_objfile_data;
3431 free_breakpoint_probes (struct objfile *obj, void *data)
3433 struct breakpoint_objfile_data *bp_objfile_data
3434 = (struct breakpoint_objfile_data *) data;
3436 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3437 VEC_free (probe_p, bp_objfile_data->exception_probes);
3441 create_overlay_event_breakpoint (void)
3443 struct objfile *objfile;
3444 const char *const func_name = "_ovly_debug_event";
3446 ALL_OBJFILES (objfile)
3448 struct breakpoint *b;
3449 struct breakpoint_objfile_data *bp_objfile_data;
3451 struct explicit_location explicit_loc;
3453 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3455 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3458 if (bp_objfile_data->overlay_msym.minsym == NULL)
3460 struct bound_minimal_symbol m;
3462 m = lookup_minimal_symbol_text (func_name, objfile);
3463 if (m.minsym == NULL)
3465 /* Avoid future lookups in this objfile. */
3466 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3469 bp_objfile_data->overlay_msym = m;
3472 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3473 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3475 &internal_breakpoint_ops);
3476 initialize_explicit_location (&explicit_loc);
3477 explicit_loc.function_name = ASTRDUP (func_name);
3478 b->location = new_explicit_location (&explicit_loc);
3480 if (overlay_debugging == ovly_auto)
3482 b->enable_state = bp_enabled;
3483 overlay_events_enabled = 1;
3487 b->enable_state = bp_disabled;
3488 overlay_events_enabled = 0;
3494 create_longjmp_master_breakpoint (void)
3496 struct program_space *pspace;
3497 struct cleanup *old_chain;
3499 old_chain = save_current_program_space ();
3501 ALL_PSPACES (pspace)
3503 struct objfile *objfile;
3505 set_current_program_space (pspace);
3507 ALL_OBJFILES (objfile)
3510 struct gdbarch *gdbarch;
3511 struct breakpoint_objfile_data *bp_objfile_data;
3513 gdbarch = get_objfile_arch (objfile);
3515 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3517 if (!bp_objfile_data->longjmp_searched)
3521 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3524 /* We are only interested in checking one element. */
3525 struct probe *p = VEC_index (probe_p, ret, 0);
3527 if (!can_evaluate_probe_arguments (p))
3529 /* We cannot use the probe interface here, because it does
3530 not know how to evaluate arguments. */
3531 VEC_free (probe_p, ret);
3535 bp_objfile_data->longjmp_probes = ret;
3536 bp_objfile_data->longjmp_searched = 1;
3539 if (bp_objfile_data->longjmp_probes != NULL)
3542 struct probe *probe;
3543 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3546 VEC_iterate (probe_p,
3547 bp_objfile_data->longjmp_probes,
3551 struct breakpoint *b;
3553 b = create_internal_breakpoint (gdbarch,
3554 get_probe_address (probe,
3557 &internal_breakpoint_ops);
3559 = new_probe_location ("-probe-stap libc:longjmp");
3560 b->enable_state = bp_disabled;
3566 if (!gdbarch_get_longjmp_target_p (gdbarch))
3569 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3571 struct breakpoint *b;
3572 const char *func_name;
3574 struct explicit_location explicit_loc;
3576 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3579 func_name = longjmp_names[i];
3580 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3582 struct bound_minimal_symbol m;
3584 m = lookup_minimal_symbol_text (func_name, objfile);
3585 if (m.minsym == NULL)
3587 /* Prevent future lookups in this objfile. */
3588 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3591 bp_objfile_data->longjmp_msym[i] = m;
3594 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3595 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3596 &internal_breakpoint_ops);
3597 initialize_explicit_location (&explicit_loc);
3598 explicit_loc.function_name = ASTRDUP (func_name);
3599 b->location = new_explicit_location (&explicit_loc);
3600 b->enable_state = bp_disabled;
3605 do_cleanups (old_chain);
3608 /* Create a master std::terminate breakpoint. */
3610 create_std_terminate_master_breakpoint (void)
3612 struct program_space *pspace;
3613 struct cleanup *old_chain;
3614 const char *const func_name = "std::terminate()";
3616 old_chain = save_current_program_space ();
3618 ALL_PSPACES (pspace)
3620 struct objfile *objfile;
3623 set_current_program_space (pspace);
3625 ALL_OBJFILES (objfile)
3627 struct breakpoint *b;
3628 struct breakpoint_objfile_data *bp_objfile_data;
3629 struct explicit_location explicit_loc;
3631 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3633 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3636 if (bp_objfile_data->terminate_msym.minsym == NULL)
3638 struct bound_minimal_symbol m;
3640 m = lookup_minimal_symbol (func_name, NULL, objfile);
3641 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3642 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3644 /* Prevent future lookups in this objfile. */
3645 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3648 bp_objfile_data->terminate_msym = m;
3651 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3652 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3653 bp_std_terminate_master,
3654 &internal_breakpoint_ops);
3655 initialize_explicit_location (&explicit_loc);
3656 explicit_loc.function_name = ASTRDUP (func_name);
3657 b->location = new_explicit_location (&explicit_loc);
3658 b->enable_state = bp_disabled;
3662 do_cleanups (old_chain);
3665 /* Install a master breakpoint on the unwinder's debug hook. */
3668 create_exception_master_breakpoint (void)
3670 struct objfile *objfile;
3671 const char *const func_name = "_Unwind_DebugHook";
3673 ALL_OBJFILES (objfile)
3675 struct breakpoint *b;
3676 struct gdbarch *gdbarch;
3677 struct breakpoint_objfile_data *bp_objfile_data;
3679 struct explicit_location explicit_loc;
3681 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3683 /* We prefer the SystemTap probe point if it exists. */
3684 if (!bp_objfile_data->exception_searched)
3688 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3692 /* We are only interested in checking one element. */
3693 struct probe *p = VEC_index (probe_p, ret, 0);
3695 if (!can_evaluate_probe_arguments (p))
3697 /* We cannot use the probe interface here, because it does
3698 not know how to evaluate arguments. */
3699 VEC_free (probe_p, ret);
3703 bp_objfile_data->exception_probes = ret;
3704 bp_objfile_data->exception_searched = 1;
3707 if (bp_objfile_data->exception_probes != NULL)
3709 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3711 struct probe *probe;
3714 VEC_iterate (probe_p,
3715 bp_objfile_data->exception_probes,
3719 struct breakpoint *b;
3721 b = create_internal_breakpoint (gdbarch,
3722 get_probe_address (probe,
3724 bp_exception_master,
3725 &internal_breakpoint_ops);
3727 = new_probe_location ("-probe-stap libgcc:unwind");
3728 b->enable_state = bp_disabled;
3734 /* Otherwise, try the hook function. */
3736 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3739 gdbarch = get_objfile_arch (objfile);
3741 if (bp_objfile_data->exception_msym.minsym == NULL)
3743 struct bound_minimal_symbol debug_hook;
3745 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3746 if (debug_hook.minsym == NULL)
3748 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3752 bp_objfile_data->exception_msym = debug_hook;
3755 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3756 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3758 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3759 &internal_breakpoint_ops);
3760 initialize_explicit_location (&explicit_loc);
3761 explicit_loc.function_name = ASTRDUP (func_name);
3762 b->location = new_explicit_location (&explicit_loc);
3763 b->enable_state = bp_disabled;
3767 /* Does B have a location spec? */
3770 breakpoint_event_location_empty_p (const struct breakpoint *b)
3772 return b->location != NULL && event_location_empty_p (b->location);
3776 update_breakpoints_after_exec (void)
3778 struct breakpoint *b, *b_tmp;
3779 struct bp_location *bploc, **bplocp_tmp;
3781 /* We're about to delete breakpoints from GDB's lists. If the
3782 INSERTED flag is true, GDB will try to lift the breakpoints by
3783 writing the breakpoints' "shadow contents" back into memory. The
3784 "shadow contents" are NOT valid after an exec, so GDB should not
3785 do that. Instead, the target is responsible from marking
3786 breakpoints out as soon as it detects an exec. We don't do that
3787 here instead, because there may be other attempts to delete
3788 breakpoints after detecting an exec and before reaching here. */
3789 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3790 if (bploc->pspace == current_program_space)
3791 gdb_assert (!bploc->inserted);
3793 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3795 if (b->pspace != current_program_space)
3798 /* Solib breakpoints must be explicitly reset after an exec(). */
3799 if (b->type == bp_shlib_event)
3801 delete_breakpoint (b);
3805 /* JIT breakpoints must be explicitly reset after an exec(). */
3806 if (b->type == bp_jit_event)
3808 delete_breakpoint (b);
3812 /* Thread event breakpoints must be set anew after an exec(),
3813 as must overlay event and longjmp master breakpoints. */
3814 if (b->type == bp_thread_event || b->type == bp_overlay_event
3815 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3816 || b->type == bp_exception_master)
3818 delete_breakpoint (b);
3822 /* Step-resume breakpoints are meaningless after an exec(). */
3823 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3825 delete_breakpoint (b);
3829 /* Just like single-step breakpoints. */
3830 if (b->type == bp_single_step)
3832 delete_breakpoint (b);
3836 /* Longjmp and longjmp-resume breakpoints are also meaningless
3838 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3839 || b->type == bp_longjmp_call_dummy
3840 || b->type == bp_exception || b->type == bp_exception_resume)
3842 delete_breakpoint (b);
3846 if (b->type == bp_catchpoint)
3848 /* For now, none of the bp_catchpoint breakpoints need to
3849 do anything at this point. In the future, if some of
3850 the catchpoints need to something, we will need to add
3851 a new method, and call this method from here. */
3855 /* bp_finish is a special case. The only way we ought to be able
3856 to see one of these when an exec() has happened, is if the user
3857 caught a vfork, and then said "finish". Ordinarily a finish just
3858 carries them to the call-site of the current callee, by setting
3859 a temporary bp there and resuming. But in this case, the finish
3860 will carry them entirely through the vfork & exec.
3862 We don't want to allow a bp_finish to remain inserted now. But
3863 we can't safely delete it, 'cause finish_command has a handle to
3864 the bp on a bpstat, and will later want to delete it. There's a
3865 chance (and I've seen it happen) that if we delete the bp_finish
3866 here, that its storage will get reused by the time finish_command
3867 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3868 We really must allow finish_command to delete a bp_finish.
3870 In the absence of a general solution for the "how do we know
3871 it's safe to delete something others may have handles to?"
3872 problem, what we'll do here is just uninsert the bp_finish, and
3873 let finish_command delete it.
3875 (We know the bp_finish is "doomed" in the sense that it's
3876 momentary, and will be deleted as soon as finish_command sees
3877 the inferior stopped. So it doesn't matter that the bp's
3878 address is probably bogus in the new a.out, unlike e.g., the
3879 solib breakpoints.) */
3881 if (b->type == bp_finish)
3886 /* Without a symbolic address, we have little hope of the
3887 pre-exec() address meaning the same thing in the post-exec()
3889 if (breakpoint_event_location_empty_p (b))
3891 delete_breakpoint (b);
3898 detach_breakpoints (ptid_t ptid)
3900 struct bp_location *bl, **blp_tmp;
3902 struct cleanup *old_chain = save_inferior_ptid ();
3903 struct inferior *inf = current_inferior ();
3905 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3906 error (_("Cannot detach breakpoints of inferior_ptid"));
3908 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3909 inferior_ptid = ptid;
3910 ALL_BP_LOCATIONS (bl, blp_tmp)
3912 if (bl->pspace != inf->pspace)
3915 /* This function must physically remove breakpoints locations
3916 from the specified ptid, without modifying the breakpoint
3917 package's state. Locations of type bp_loc_other are only
3918 maintained at GDB side. So, there is no need to remove
3919 these bp_loc_other locations. Moreover, removing these
3920 would modify the breakpoint package's state. */
3921 if (bl->loc_type == bp_loc_other)
3925 val |= remove_breakpoint_1 (bl, mark_inserted);
3928 do_cleanups (old_chain);
3932 /* Remove the breakpoint location BL from the current address space.
3933 Note that this is used to detach breakpoints from a child fork.
3934 When we get here, the child isn't in the inferior list, and neither
3935 do we have objects to represent its address space --- we should
3936 *not* look at bl->pspace->aspace here. */
3939 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3943 /* BL is never in moribund_locations by our callers. */
3944 gdb_assert (bl->owner != NULL);
3946 /* The type of none suggests that owner is actually deleted.
3947 This should not ever happen. */
3948 gdb_assert (bl->owner->type != bp_none);
3950 if (bl->loc_type == bp_loc_software_breakpoint
3951 || bl->loc_type == bp_loc_hardware_breakpoint)
3953 /* "Normal" instruction breakpoint: either the standard
3954 trap-instruction bp (bp_breakpoint), or a
3955 bp_hardware_breakpoint. */
3957 /* First check to see if we have to handle an overlay. */
3958 if (overlay_debugging == ovly_off
3959 || bl->section == NULL
3960 || !(section_is_overlay (bl->section)))
3962 /* No overlay handling: just remove the breakpoint. */
3964 /* If we're trying to uninsert a memory breakpoint that we
3965 know is set in a dynamic object that is marked
3966 shlib_disabled, then either the dynamic object was
3967 removed with "remove-symbol-file" or with
3968 "nosharedlibrary". In the former case, we don't know
3969 whether another dynamic object might have loaded over the
3970 breakpoint's address -- the user might well let us know
3971 about it next with add-symbol-file (the whole point of
3972 add-symbol-file is letting the user manually maintain a
3973 list of dynamically loaded objects). If we have the
3974 breakpoint's shadow memory, that is, this is a software
3975 breakpoint managed by GDB, check whether the breakpoint
3976 is still inserted in memory, to avoid overwriting wrong
3977 code with stale saved shadow contents. Note that HW
3978 breakpoints don't have shadow memory, as they're
3979 implemented using a mechanism that is not dependent on
3980 being able to modify the target's memory, and as such
3981 they should always be removed. */
3982 if (bl->shlib_disabled
3983 && bl->target_info.shadow_len != 0
3984 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3987 val = bl->owner->ops->remove_location (bl);
3991 /* This breakpoint is in an overlay section.
3992 Did we set a breakpoint at the LMA? */
3993 if (!overlay_events_enabled)
3995 /* Yes -- overlay event support is not active, so we
3996 should have set a breakpoint at the LMA. Remove it.
3998 /* Ignore any failures: if the LMA is in ROM, we will
3999 have already warned when we failed to insert it. */
4000 if (bl->loc_type == bp_loc_hardware_breakpoint)
4001 target_remove_hw_breakpoint (bl->gdbarch,
4002 &bl->overlay_target_info);
4004 target_remove_breakpoint (bl->gdbarch,
4005 &bl->overlay_target_info);
4007 /* Did we set a breakpoint at the VMA?
4008 If so, we will have marked the breakpoint 'inserted'. */
4011 /* Yes -- remove it. Previously we did not bother to
4012 remove the breakpoint if the section had been
4013 unmapped, but let's not rely on that being safe. We
4014 don't know what the overlay manager might do. */
4016 /* However, we should remove *software* breakpoints only
4017 if the section is still mapped, or else we overwrite
4018 wrong code with the saved shadow contents. */
4019 if (bl->loc_type == bp_loc_hardware_breakpoint
4020 || section_is_mapped (bl->section))
4021 val = bl->owner->ops->remove_location (bl);
4027 /* No -- not inserted, so no need to remove. No error. */
4032 /* In some cases, we might not be able to remove a breakpoint in
4033 a shared library that has already been removed, but we have
4034 not yet processed the shlib unload event. Similarly for an
4035 unloaded add-symbol-file object - the user might not yet have
4036 had the chance to remove-symbol-file it. shlib_disabled will
4037 be set if the library/object has already been removed, but
4038 the breakpoint hasn't been uninserted yet, e.g., after
4039 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4040 always-inserted mode. */
4042 && (bl->loc_type == bp_loc_software_breakpoint
4043 && (bl->shlib_disabled
4044 || solib_name_from_address (bl->pspace, bl->address)
4045 || shared_objfile_contains_address_p (bl->pspace,
4051 bl->inserted = (is == mark_inserted);
4053 else if (bl->loc_type == bp_loc_hardware_watchpoint)
4055 gdb_assert (bl->owner->ops != NULL
4056 && bl->owner->ops->remove_location != NULL);
4058 bl->inserted = (is == mark_inserted);
4059 bl->owner->ops->remove_location (bl);
4061 /* Failure to remove any of the hardware watchpoints comes here. */
4062 if ((is == mark_uninserted) && (bl->inserted))
4063 warning (_("Could not remove hardware watchpoint %d."),
4066 else if (bl->owner->type == bp_catchpoint
4067 && breakpoint_enabled (bl->owner)
4070 gdb_assert (bl->owner->ops != NULL
4071 && bl->owner->ops->remove_location != NULL);
4073 val = bl->owner->ops->remove_location (bl);
4077 bl->inserted = (is == mark_inserted);
4084 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
4087 struct cleanup *old_chain;
4089 /* BL is never in moribund_locations by our callers. */
4090 gdb_assert (bl->owner != NULL);
4092 /* The type of none suggests that owner is actually deleted.
4093 This should not ever happen. */
4094 gdb_assert (bl->owner->type != bp_none);
4096 old_chain = save_current_space_and_thread ();
4098 switch_to_program_space_and_thread (bl->pspace);
4100 ret = remove_breakpoint_1 (bl, is);
4102 do_cleanups (old_chain);
4106 /* Clear the "inserted" flag in all breakpoints. */
4109 mark_breakpoints_out (void)
4111 struct bp_location *bl, **blp_tmp;
4113 ALL_BP_LOCATIONS (bl, blp_tmp)
4114 if (bl->pspace == current_program_space)
4118 /* Clear the "inserted" flag in all breakpoints and delete any
4119 breakpoints which should go away between runs of the program.
4121 Plus other such housekeeping that has to be done for breakpoints
4124 Note: this function gets called at the end of a run (by
4125 generic_mourn_inferior) and when a run begins (by
4126 init_wait_for_inferior). */
4131 breakpoint_init_inferior (enum inf_context context)
4133 struct breakpoint *b, *b_tmp;
4134 struct bp_location *bl, **blp_tmp;
4136 struct program_space *pspace = current_program_space;
4138 /* If breakpoint locations are shared across processes, then there's
4140 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4143 mark_breakpoints_out ();
4145 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4147 if (b->loc && b->loc->pspace != pspace)
4153 case bp_longjmp_call_dummy:
4155 /* If the call dummy breakpoint is at the entry point it will
4156 cause problems when the inferior is rerun, so we better get
4159 case bp_watchpoint_scope:
4161 /* Also get rid of scope breakpoints. */
4163 case bp_shlib_event:
4165 /* Also remove solib event breakpoints. Their addresses may
4166 have changed since the last time we ran the program.
4167 Actually we may now be debugging against different target;
4168 and so the solib backend that installed this breakpoint may
4169 not be used in by the target. E.g.,
4171 (gdb) file prog-linux
4172 (gdb) run # native linux target
4175 (gdb) file prog-win.exe
4176 (gdb) tar rem :9999 # remote Windows gdbserver.
4179 case bp_step_resume:
4181 /* Also remove step-resume breakpoints. */
4183 case bp_single_step:
4185 /* Also remove single-step breakpoints. */
4187 delete_breakpoint (b);
4191 case bp_hardware_watchpoint:
4192 case bp_read_watchpoint:
4193 case bp_access_watchpoint:
4195 struct watchpoint *w = (struct watchpoint *) b;
4197 /* Likewise for watchpoints on local expressions. */
4198 if (w->exp_valid_block != NULL)
4199 delete_breakpoint (b);
4200 else if (context == inf_starting)
4202 /* Reset val field to force reread of starting value in
4203 insert_breakpoints. */
4205 value_free (w->val);
4216 /* Get rid of the moribund locations. */
4217 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4218 decref_bp_location (&bl);
4219 VEC_free (bp_location_p, moribund_locations);
4222 /* These functions concern about actual breakpoints inserted in the
4223 target --- to e.g. check if we need to do decr_pc adjustment or if
4224 we need to hop over the bkpt --- so we check for address space
4225 match, not program space. */
4227 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4228 exists at PC. It returns ordinary_breakpoint_here if it's an
4229 ordinary breakpoint, or permanent_breakpoint_here if it's a
4230 permanent breakpoint.
4231 - When continuing from a location with an ordinary breakpoint, we
4232 actually single step once before calling insert_breakpoints.
4233 - When continuing from a location with a permanent breakpoint, we
4234 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4235 the target, to advance the PC past the breakpoint. */
4237 enum breakpoint_here
4238 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4240 struct bp_location *bl, **blp_tmp;
4241 int any_breakpoint_here = 0;
4243 ALL_BP_LOCATIONS (bl, blp_tmp)
4245 if (bl->loc_type != bp_loc_software_breakpoint
4246 && bl->loc_type != bp_loc_hardware_breakpoint)
4249 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4250 if ((breakpoint_enabled (bl->owner)
4252 && breakpoint_location_address_match (bl, aspace, pc))
4254 if (overlay_debugging
4255 && section_is_overlay (bl->section)
4256 && !section_is_mapped (bl->section))
4257 continue; /* unmapped overlay -- can't be a match */
4258 else if (bl->permanent)
4259 return permanent_breakpoint_here;
4261 any_breakpoint_here = 1;
4265 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4268 /* See breakpoint.h. */
4271 breakpoint_in_range_p (struct address_space *aspace,
4272 CORE_ADDR addr, ULONGEST len)
4274 struct bp_location *bl, **blp_tmp;
4276 ALL_BP_LOCATIONS (bl, blp_tmp)
4278 if (bl->loc_type != bp_loc_software_breakpoint
4279 && bl->loc_type != bp_loc_hardware_breakpoint)
4282 if ((breakpoint_enabled (bl->owner)
4284 && breakpoint_location_address_range_overlap (bl, aspace,
4287 if (overlay_debugging
4288 && section_is_overlay (bl->section)
4289 && !section_is_mapped (bl->section))
4291 /* Unmapped overlay -- can't be a match. */
4302 /* Return true if there's a moribund breakpoint at PC. */
4305 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4307 struct bp_location *loc;
4310 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4311 if (breakpoint_location_address_match (loc, aspace, pc))
4317 /* Returns non-zero iff BL is inserted at PC, in address space
4321 bp_location_inserted_here_p (struct bp_location *bl,
4322 struct address_space *aspace, CORE_ADDR pc)
4325 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4328 if (overlay_debugging
4329 && section_is_overlay (bl->section)
4330 && !section_is_mapped (bl->section))
4331 return 0; /* unmapped overlay -- can't be a match */
4338 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4341 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4343 struct bp_location **blp, **blp_tmp = NULL;
4344 struct bp_location *bl;
4346 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4348 struct bp_location *bl = *blp;
4350 if (bl->loc_type != bp_loc_software_breakpoint
4351 && bl->loc_type != bp_loc_hardware_breakpoint)
4354 if (bp_location_inserted_here_p (bl, aspace, pc))
4360 /* This function returns non-zero iff there is a software breakpoint
4364 software_breakpoint_inserted_here_p (struct address_space *aspace,
4367 struct bp_location **blp, **blp_tmp = NULL;
4368 struct bp_location *bl;
4370 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4372 struct bp_location *bl = *blp;
4374 if (bl->loc_type != bp_loc_software_breakpoint)
4377 if (bp_location_inserted_here_p (bl, aspace, pc))
4384 /* See breakpoint.h. */
4387 hardware_breakpoint_inserted_here_p (struct address_space *aspace,
4390 struct bp_location **blp, **blp_tmp = NULL;
4391 struct bp_location *bl;
4393 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4395 struct bp_location *bl = *blp;
4397 if (bl->loc_type != bp_loc_hardware_breakpoint)
4400 if (bp_location_inserted_here_p (bl, aspace, pc))
4408 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4409 CORE_ADDR addr, ULONGEST len)
4411 struct breakpoint *bpt;
4413 ALL_BREAKPOINTS (bpt)
4415 struct bp_location *loc;
4417 if (bpt->type != bp_hardware_watchpoint
4418 && bpt->type != bp_access_watchpoint)
4421 if (!breakpoint_enabled (bpt))
4424 for (loc = bpt->loc; loc; loc = loc->next)
4425 if (loc->pspace->aspace == aspace && loc->inserted)
4429 /* Check for intersection. */
4430 l = max (loc->address, addr);
4431 h = min (loc->address + loc->length, addr + len);
4440 /* bpstat stuff. External routines' interfaces are documented
4444 is_catchpoint (struct breakpoint *ep)
4446 return (ep->type == bp_catchpoint);
4449 /* Frees any storage that is part of a bpstat. Does not walk the
4453 bpstat_free (bpstat bs)
4455 if (bs->old_val != NULL)
4456 value_free (bs->old_val);
4457 decref_counted_command_line (&bs->commands);
4458 decref_bp_location (&bs->bp_location_at);
4462 /* Clear a bpstat so that it says we are not at any breakpoint.
4463 Also free any storage that is part of a bpstat. */
4466 bpstat_clear (bpstat *bsp)
4483 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4484 is part of the bpstat is copied as well. */
4487 bpstat_copy (bpstat bs)
4491 bpstat retval = NULL;
4496 for (; bs != NULL; bs = bs->next)
4498 tmp = (bpstat) xmalloc (sizeof (*tmp));
4499 memcpy (tmp, bs, sizeof (*tmp));
4500 incref_counted_command_line (tmp->commands);
4501 incref_bp_location (tmp->bp_location_at);
4502 if (bs->old_val != NULL)
4504 tmp->old_val = value_copy (bs->old_val);
4505 release_value (tmp->old_val);
4509 /* This is the first thing in the chain. */
4519 /* Find the bpstat associated with this breakpoint. */
4522 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4527 for (; bsp != NULL; bsp = bsp->next)
4529 if (bsp->breakpoint_at == breakpoint)
4535 /* See breakpoint.h. */
4538 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4540 for (; bsp != NULL; bsp = bsp->next)
4542 if (bsp->breakpoint_at == NULL)
4544 /* A moribund location can never explain a signal other than
4546 if (sig == GDB_SIGNAL_TRAP)
4551 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4560 /* Put in *NUM the breakpoint number of the first breakpoint we are
4561 stopped at. *BSP upon return is a bpstat which points to the
4562 remaining breakpoints stopped at (but which is not guaranteed to be
4563 good for anything but further calls to bpstat_num).
4565 Return 0 if passed a bpstat which does not indicate any breakpoints.
4566 Return -1 if stopped at a breakpoint that has been deleted since
4568 Return 1 otherwise. */
4571 bpstat_num (bpstat *bsp, int *num)
4573 struct breakpoint *b;
4576 return 0; /* No more breakpoint values */
4578 /* We assume we'll never have several bpstats that correspond to a
4579 single breakpoint -- otherwise, this function might return the
4580 same number more than once and this will look ugly. */
4581 b = (*bsp)->breakpoint_at;
4582 *bsp = (*bsp)->next;
4584 return -1; /* breakpoint that's been deleted since */
4586 *num = b->number; /* We have its number */
4590 /* See breakpoint.h. */
4593 bpstat_clear_actions (void)
4595 struct thread_info *tp;
4598 if (ptid_equal (inferior_ptid, null_ptid))
4601 tp = find_thread_ptid (inferior_ptid);
4605 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4607 decref_counted_command_line (&bs->commands);
4609 if (bs->old_val != NULL)
4611 value_free (bs->old_val);
4617 /* Called when a command is about to proceed the inferior. */
4620 breakpoint_about_to_proceed (void)
4622 if (!ptid_equal (inferior_ptid, null_ptid))
4624 struct thread_info *tp = inferior_thread ();
4626 /* Allow inferior function calls in breakpoint commands to not
4627 interrupt the command list. When the call finishes
4628 successfully, the inferior will be standing at the same
4629 breakpoint as if nothing happened. */
4630 if (tp->control.in_infcall)
4634 breakpoint_proceeded = 1;
4637 /* Stub for cleaning up our state if we error-out of a breakpoint
4640 cleanup_executing_breakpoints (void *ignore)
4642 executing_breakpoint_commands = 0;
4645 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4646 or its equivalent. */
4649 command_line_is_silent (struct command_line *cmd)
4651 return cmd && (strcmp ("silent", cmd->line) == 0);
4654 /* Execute all the commands associated with all the breakpoints at
4655 this location. Any of these commands could cause the process to
4656 proceed beyond this point, etc. We look out for such changes by
4657 checking the global "breakpoint_proceeded" after each command.
4659 Returns true if a breakpoint command resumed the inferior. In that
4660 case, it is the caller's responsibility to recall it again with the
4661 bpstat of the current thread. */
4664 bpstat_do_actions_1 (bpstat *bsp)
4667 struct cleanup *old_chain;
4670 /* Avoid endless recursion if a `source' command is contained
4672 if (executing_breakpoint_commands)
4675 executing_breakpoint_commands = 1;
4676 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4678 prevent_dont_repeat ();
4680 /* This pointer will iterate over the list of bpstat's. */
4683 breakpoint_proceeded = 0;
4684 for (; bs != NULL; bs = bs->next)
4686 struct counted_command_line *ccmd;
4687 struct command_line *cmd;
4688 struct cleanup *this_cmd_tree_chain;
4690 /* Take ownership of the BSP's command tree, if it has one.
4692 The command tree could legitimately contain commands like
4693 'step' and 'next', which call clear_proceed_status, which
4694 frees stop_bpstat's command tree. To make sure this doesn't
4695 free the tree we're executing out from under us, we need to
4696 take ownership of the tree ourselves. Since a given bpstat's
4697 commands are only executed once, we don't need to copy it; we
4698 can clear the pointer in the bpstat, and make sure we free
4699 the tree when we're done. */
4700 ccmd = bs->commands;
4701 bs->commands = NULL;
4702 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4703 cmd = ccmd ? ccmd->commands : NULL;
4704 if (command_line_is_silent (cmd))
4706 /* The action has been already done by bpstat_stop_status. */
4712 execute_control_command (cmd);
4714 if (breakpoint_proceeded)
4720 /* We can free this command tree now. */
4721 do_cleanups (this_cmd_tree_chain);
4723 if (breakpoint_proceeded)
4725 if (interpreter_async)
4726 /* If we are in async mode, then the target might be still
4727 running, not stopped at any breakpoint, so nothing for
4728 us to do here -- just return to the event loop. */
4731 /* In sync mode, when execute_control_command returns
4732 we're already standing on the next breakpoint.
4733 Breakpoint commands for that stop were not run, since
4734 execute_command does not run breakpoint commands --
4735 only command_line_handler does, but that one is not
4736 involved in execution of breakpoint commands. So, we
4737 can now execute breakpoint commands. It should be
4738 noted that making execute_command do bpstat actions is
4739 not an option -- in this case we'll have recursive
4740 invocation of bpstat for each breakpoint with a
4741 command, and can easily blow up GDB stack. Instead, we
4742 return true, which will trigger the caller to recall us
4743 with the new stop_bpstat. */
4748 do_cleanups (old_chain);
4753 bpstat_do_actions (void)
4755 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4757 /* Do any commands attached to breakpoint we are stopped at. */
4758 while (!ptid_equal (inferior_ptid, null_ptid)
4759 && target_has_execution
4760 && !is_exited (inferior_ptid)
4761 && !is_executing (inferior_ptid))
4762 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4763 and only return when it is stopped at the next breakpoint, we
4764 keep doing breakpoint actions until it returns false to
4765 indicate the inferior was not resumed. */
4766 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4769 discard_cleanups (cleanup_if_error);
4772 /* Print out the (old or new) value associated with a watchpoint. */
4775 watchpoint_value_print (struct value *val, struct ui_file *stream)
4778 fprintf_unfiltered (stream, _("<unreadable>"));
4781 struct value_print_options opts;
4782 get_user_print_options (&opts);
4783 value_print (val, stream, &opts);
4787 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4788 debugging multiple threads. */
4791 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4793 if (ui_out_is_mi_like_p (uiout))
4796 ui_out_text (uiout, "\n");
4798 if (show_thread_that_caused_stop ())
4801 struct thread_info *thr = inferior_thread ();
4803 ui_out_text (uiout, "Thread ");
4804 ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr));
4806 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4809 ui_out_text (uiout, " \"");
4810 ui_out_field_fmt (uiout, "name", "%s", name);
4811 ui_out_text (uiout, "\"");
4814 ui_out_text (uiout, " hit ");
4818 /* Generic routine for printing messages indicating why we
4819 stopped. The behavior of this function depends on the value
4820 'print_it' in the bpstat structure. Under some circumstances we
4821 may decide not to print anything here and delegate the task to
4824 static enum print_stop_action
4825 print_bp_stop_message (bpstat bs)
4827 switch (bs->print_it)
4830 /* Nothing should be printed for this bpstat entry. */
4831 return PRINT_UNKNOWN;
4835 /* We still want to print the frame, but we already printed the
4836 relevant messages. */
4837 return PRINT_SRC_AND_LOC;
4840 case print_it_normal:
4842 struct breakpoint *b = bs->breakpoint_at;
4844 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4845 which has since been deleted. */
4847 return PRINT_UNKNOWN;
4849 /* Normal case. Call the breakpoint's print_it method. */
4850 return b->ops->print_it (bs);
4855 internal_error (__FILE__, __LINE__,
4856 _("print_bp_stop_message: unrecognized enum value"));
4861 /* A helper function that prints a shared library stopped event. */
4864 print_solib_event (int is_catchpoint)
4867 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4869 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4873 if (any_added || any_deleted)
4874 ui_out_text (current_uiout,
4875 _("Stopped due to shared library event:\n"));
4877 ui_out_text (current_uiout,
4878 _("Stopped due to shared library event (no "
4879 "libraries added or removed)\n"));
4882 if (ui_out_is_mi_like_p (current_uiout))
4883 ui_out_field_string (current_uiout, "reason",
4884 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4888 struct cleanup *cleanup;
4892 ui_out_text (current_uiout, _(" Inferior unloaded "));
4893 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4896 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4901 ui_out_text (current_uiout, " ");
4902 ui_out_field_string (current_uiout, "library", name);
4903 ui_out_text (current_uiout, "\n");
4906 do_cleanups (cleanup);
4911 struct so_list *iter;
4913 struct cleanup *cleanup;
4915 ui_out_text (current_uiout, _(" Inferior loaded "));
4916 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4919 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4924 ui_out_text (current_uiout, " ");
4925 ui_out_field_string (current_uiout, "library", iter->so_name);
4926 ui_out_text (current_uiout, "\n");
4929 do_cleanups (cleanup);
4933 /* Print a message indicating what happened. This is called from
4934 normal_stop(). The input to this routine is the head of the bpstat
4935 list - a list of the eventpoints that caused this stop. KIND is
4936 the target_waitkind for the stopping event. This
4937 routine calls the generic print routine for printing a message
4938 about reasons for stopping. This will print (for example) the
4939 "Breakpoint n," part of the output. The return value of this
4942 PRINT_UNKNOWN: Means we printed nothing.
4943 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4944 code to print the location. An example is
4945 "Breakpoint 1, " which should be followed by
4947 PRINT_SRC_ONLY: Means we printed something, but there is no need
4948 to also print the location part of the message.
4949 An example is the catch/throw messages, which
4950 don't require a location appended to the end.
4951 PRINT_NOTHING: We have done some printing and we don't need any
4952 further info to be printed. */
4954 enum print_stop_action
4955 bpstat_print (bpstat bs, int kind)
4957 enum print_stop_action val;
4959 /* Maybe another breakpoint in the chain caused us to stop.
4960 (Currently all watchpoints go on the bpstat whether hit or not.
4961 That probably could (should) be changed, provided care is taken
4962 with respect to bpstat_explains_signal). */
4963 for (; bs; bs = bs->next)
4965 val = print_bp_stop_message (bs);
4966 if (val == PRINT_SRC_ONLY
4967 || val == PRINT_SRC_AND_LOC
4968 || val == PRINT_NOTHING)
4972 /* If we had hit a shared library event breakpoint,
4973 print_bp_stop_message would print out this message. If we hit an
4974 OS-level shared library event, do the same thing. */
4975 if (kind == TARGET_WAITKIND_LOADED)
4977 print_solib_event (0);
4978 return PRINT_NOTHING;
4981 /* We reached the end of the chain, or we got a null BS to start
4982 with and nothing was printed. */
4983 return PRINT_UNKNOWN;
4986 /* Evaluate the expression EXP and return 1 if value is zero.
4987 This returns the inverse of the condition because it is called
4988 from catch_errors which returns 0 if an exception happened, and if an
4989 exception happens we want execution to stop.
4990 The argument is a "struct expression *" that has been cast to a
4991 "void *" to make it pass through catch_errors. */
4994 breakpoint_cond_eval (void *exp)
4996 struct value *mark = value_mark ();
4997 int i = !value_true (evaluate_expression ((struct expression *) exp));
4999 value_free_to_mark (mark);
5003 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5006 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
5010 bs = (bpstat) xmalloc (sizeof (*bs));
5012 **bs_link_pointer = bs;
5013 *bs_link_pointer = &bs->next;
5014 bs->breakpoint_at = bl->owner;
5015 bs->bp_location_at = bl;
5016 incref_bp_location (bl);
5017 /* If the condition is false, etc., don't do the commands. */
5018 bs->commands = NULL;
5020 bs->print_it = print_it_normal;
5024 /* The target has stopped with waitstatus WS. Check if any hardware
5025 watchpoints have triggered, according to the target. */
5028 watchpoints_triggered (struct target_waitstatus *ws)
5030 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
5032 struct breakpoint *b;
5034 if (!stopped_by_watchpoint)
5036 /* We were not stopped by a watchpoint. Mark all watchpoints
5037 as not triggered. */
5039 if (is_hardware_watchpoint (b))
5041 struct watchpoint *w = (struct watchpoint *) b;
5043 w->watchpoint_triggered = watch_triggered_no;
5049 if (!target_stopped_data_address (¤t_target, &addr))
5051 /* We were stopped by a watchpoint, but we don't know where.
5052 Mark all watchpoints as unknown. */
5054 if (is_hardware_watchpoint (b))
5056 struct watchpoint *w = (struct watchpoint *) b;
5058 w->watchpoint_triggered = watch_triggered_unknown;
5064 /* The target could report the data address. Mark watchpoints
5065 affected by this data address as triggered, and all others as not
5069 if (is_hardware_watchpoint (b))
5071 struct watchpoint *w = (struct watchpoint *) b;
5072 struct bp_location *loc;
5074 w->watchpoint_triggered = watch_triggered_no;
5075 for (loc = b->loc; loc; loc = loc->next)
5077 if (is_masked_watchpoint (b))
5079 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5080 CORE_ADDR start = loc->address & w->hw_wp_mask;
5082 if (newaddr == start)
5084 w->watchpoint_triggered = watch_triggered_yes;
5088 /* Exact match not required. Within range is sufficient. */
5089 else if (target_watchpoint_addr_within_range (¤t_target,
5093 w->watchpoint_triggered = watch_triggered_yes;
5102 /* Possible return values for watchpoint_check (this can't be an enum
5103 because of check_errors). */
5104 /* The watchpoint has been deleted. */
5105 #define WP_DELETED 1
5106 /* The value has changed. */
5107 #define WP_VALUE_CHANGED 2
5108 /* The value has not changed. */
5109 #define WP_VALUE_NOT_CHANGED 3
5110 /* Ignore this watchpoint, no matter if the value changed or not. */
5113 #define BP_TEMPFLAG 1
5114 #define BP_HARDWAREFLAG 2
5116 /* Evaluate watchpoint condition expression and check if its value
5119 P should be a pointer to struct bpstat, but is defined as a void *
5120 in order for this function to be usable with catch_errors. */
5123 watchpoint_check (void *p)
5125 bpstat bs = (bpstat) p;
5126 struct watchpoint *b;
5127 struct frame_info *fr;
5128 int within_current_scope;
5130 /* BS is built from an existing struct breakpoint. */
5131 gdb_assert (bs->breakpoint_at != NULL);
5132 b = (struct watchpoint *) bs->breakpoint_at;
5134 /* If this is a local watchpoint, we only want to check if the
5135 watchpoint frame is in scope if the current thread is the thread
5136 that was used to create the watchpoint. */
5137 if (!watchpoint_in_thread_scope (b))
5140 if (b->exp_valid_block == NULL)
5141 within_current_scope = 1;
5144 struct frame_info *frame = get_current_frame ();
5145 struct gdbarch *frame_arch = get_frame_arch (frame);
5146 CORE_ADDR frame_pc = get_frame_pc (frame);
5148 /* stack_frame_destroyed_p() returns a non-zero value if we're
5149 still in the function but the stack frame has already been
5150 invalidated. Since we can't rely on the values of local
5151 variables after the stack has been destroyed, we are treating
5152 the watchpoint in that state as `not changed' without further
5153 checking. Don't mark watchpoints as changed if the current
5154 frame is in an epilogue - even if they are in some other
5155 frame, our view of the stack is likely to be wrong and
5156 frame_find_by_id could error out. */
5157 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5160 fr = frame_find_by_id (b->watchpoint_frame);
5161 within_current_scope = (fr != NULL);
5163 /* If we've gotten confused in the unwinder, we might have
5164 returned a frame that can't describe this variable. */
5165 if (within_current_scope)
5167 struct symbol *function;
5169 function = get_frame_function (fr);
5170 if (function == NULL
5171 || !contained_in (b->exp_valid_block,
5172 SYMBOL_BLOCK_VALUE (function)))
5173 within_current_scope = 0;
5176 if (within_current_scope)
5177 /* If we end up stopping, the current frame will get selected
5178 in normal_stop. So this call to select_frame won't affect
5183 if (within_current_scope)
5185 /* We use value_{,free_to_}mark because it could be a *long*
5186 time before we return to the command level and call
5187 free_all_values. We can't call free_all_values because we
5188 might be in the middle of evaluating a function call. */
5192 struct value *new_val;
5194 if (is_masked_watchpoint (&b->base))
5195 /* Since we don't know the exact trigger address (from
5196 stopped_data_address), just tell the user we've triggered
5197 a mask watchpoint. */
5198 return WP_VALUE_CHANGED;
5200 mark = value_mark ();
5201 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5203 if (b->val_bitsize != 0)
5204 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5206 /* We use value_equal_contents instead of value_equal because
5207 the latter coerces an array to a pointer, thus comparing just
5208 the address of the array instead of its contents. This is
5209 not what we want. */
5210 if ((b->val != NULL) != (new_val != NULL)
5211 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5213 if (new_val != NULL)
5215 release_value (new_val);
5216 value_free_to_mark (mark);
5218 bs->old_val = b->val;
5221 return WP_VALUE_CHANGED;
5225 /* Nothing changed. */
5226 value_free_to_mark (mark);
5227 return WP_VALUE_NOT_CHANGED;
5232 struct ui_out *uiout = current_uiout;
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
5247 if (ui_out_is_mi_like_p (uiout))
5249 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5250 ui_out_text (uiout, "\nWatchpoint ");
5251 ui_out_field_int (uiout, "wpnum", b->base.number);
5253 " deleted because the program has left the block in\n\
5254 which its expression is valid.\n");
5256 /* Make sure the watchpoint's commands aren't executed. */
5257 decref_counted_command_line (&b->base.commands);
5258 watchpoint_del_at_next_stop (b);
5264 /* Return true if it looks like target has stopped due to hitting
5265 breakpoint location BL. This function does not check if we should
5266 stop, only if BL explains the stop. */
5269 bpstat_check_location (const struct bp_location *bl,
5270 struct address_space *aspace, CORE_ADDR bp_addr,
5271 const struct target_waitstatus *ws)
5273 struct breakpoint *b = bl->owner;
5275 /* BL is from an existing breakpoint. */
5276 gdb_assert (b != NULL);
5278 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5281 /* Determine if the watched values have actually changed, and we
5282 should stop. If not, set BS->stop to 0. */
5285 bpstat_check_watchpoint (bpstat bs)
5287 const struct bp_location *bl;
5288 struct watchpoint *b;
5290 /* BS is built for existing struct breakpoint. */
5291 bl = bs->bp_location_at;
5292 gdb_assert (bl != NULL);
5293 b = (struct watchpoint *) bs->breakpoint_at;
5294 gdb_assert (b != NULL);
5297 int must_check_value = 0;
5299 if (b->base.type == bp_watchpoint)
5300 /* For a software watchpoint, we must always check the
5302 must_check_value = 1;
5303 else if (b->watchpoint_triggered == watch_triggered_yes)
5304 /* We have a hardware watchpoint (read, write, or access)
5305 and the target earlier reported an address watched by
5307 must_check_value = 1;
5308 else if (b->watchpoint_triggered == watch_triggered_unknown
5309 && b->base.type == bp_hardware_watchpoint)
5310 /* We were stopped by a hardware watchpoint, but the target could
5311 not report the data address. We must check the watchpoint's
5312 value. Access and read watchpoints are out of luck; without
5313 a data address, we can't figure it out. */
5314 must_check_value = 1;
5316 if (must_check_value)
5319 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5321 struct cleanup *cleanups = make_cleanup (xfree, message);
5322 int e = catch_errors (watchpoint_check, bs, message,
5324 do_cleanups (cleanups);
5328 /* We've already printed what needs to be printed. */
5329 bs->print_it = print_it_done;
5333 bs->print_it = print_it_noop;
5336 case WP_VALUE_CHANGED:
5337 if (b->base.type == bp_read_watchpoint)
5339 /* There are two cases to consider here:
5341 1. We're watching the triggered memory for reads.
5342 In that case, trust the target, and always report
5343 the watchpoint hit to the user. Even though
5344 reads don't cause value changes, the value may
5345 have changed since the last time it was read, and
5346 since we're not trapping writes, we will not see
5347 those, and as such we should ignore our notion of
5350 2. We're watching the triggered memory for both
5351 reads and writes. There are two ways this may
5354 2.1. This is a target that can't break on data
5355 reads only, but can break on accesses (reads or
5356 writes), such as e.g., x86. We detect this case
5357 at the time we try to insert read watchpoints.
5359 2.2. Otherwise, the target supports read
5360 watchpoints, but, the user set an access or write
5361 watchpoint watching the same memory as this read
5364 If we're watching memory writes as well as reads,
5365 ignore watchpoint hits when we find that the
5366 value hasn't changed, as reads don't cause
5367 changes. This still gives false positives when
5368 the program writes the same value to memory as
5369 what there was already in memory (we will confuse
5370 it for a read), but it's much better than
5373 int other_write_watchpoint = 0;
5375 if (bl->watchpoint_type == hw_read)
5377 struct breakpoint *other_b;
5379 ALL_BREAKPOINTS (other_b)
5380 if (other_b->type == bp_hardware_watchpoint
5381 || other_b->type == bp_access_watchpoint)
5383 struct watchpoint *other_w =
5384 (struct watchpoint *) other_b;
5386 if (other_w->watchpoint_triggered
5387 == watch_triggered_yes)
5389 other_write_watchpoint = 1;
5395 if (other_write_watchpoint
5396 || bl->watchpoint_type == hw_access)
5398 /* We're watching the same memory for writes,
5399 and the value changed since the last time we
5400 updated it, so this trap must be for a write.
5402 bs->print_it = print_it_noop;
5407 case WP_VALUE_NOT_CHANGED:
5408 if (b->base.type == bp_hardware_watchpoint
5409 || b->base.type == bp_watchpoint)
5411 /* Don't stop: write watchpoints shouldn't fire if
5412 the value hasn't changed. */
5413 bs->print_it = print_it_noop;
5421 /* Error from catch_errors. */
5422 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5423 watchpoint_del_at_next_stop (b);
5424 /* We've already printed what needs to be printed. */
5425 bs->print_it = print_it_done;
5429 else /* must_check_value == 0 */
5431 /* This is a case where some watchpoint(s) triggered, but
5432 not at the address of this watchpoint, or else no
5433 watchpoint triggered after all. So don't print
5434 anything for this watchpoint. */
5435 bs->print_it = print_it_noop;
5441 /* For breakpoints that are currently marked as telling gdb to stop,
5442 check conditions (condition proper, frame, thread and ignore count)
5443 of breakpoint referred to by BS. If we should not stop for this
5444 breakpoint, set BS->stop to 0. */
5447 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5449 const struct bp_location *bl;
5450 struct breakpoint *b;
5451 int value_is_zero = 0;
5452 struct expression *cond;
5454 gdb_assert (bs->stop);
5456 /* BS is built for existing struct breakpoint. */
5457 bl = bs->bp_location_at;
5458 gdb_assert (bl != NULL);
5459 b = bs->breakpoint_at;
5460 gdb_assert (b != NULL);
5462 /* Even if the target evaluated the condition on its end and notified GDB, we
5463 need to do so again since GDB does not know if we stopped due to a
5464 breakpoint or a single step breakpoint. */
5466 if (frame_id_p (b->frame_id)
5467 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5473 /* If this is a thread/task-specific breakpoint, don't waste cpu
5474 evaluating the condition if this isn't the specified
5476 if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
5477 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5484 /* Evaluate extension language breakpoints that have a "stop" method
5486 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5488 if (is_watchpoint (b))
5490 struct watchpoint *w = (struct watchpoint *) b;
5497 if (cond && b->disposition != disp_del_at_next_stop)
5499 int within_current_scope = 1;
5500 struct watchpoint * w;
5502 /* We use value_mark and value_free_to_mark because it could
5503 be a long time before we return to the command level and
5504 call free_all_values. We can't call free_all_values
5505 because we might be in the middle of evaluating a
5507 struct value *mark = value_mark ();
5509 if (is_watchpoint (b))
5510 w = (struct watchpoint *) b;
5514 /* Need to select the frame, with all that implies so that
5515 the conditions will have the right context. Because we
5516 use the frame, we will not see an inlined function's
5517 variables when we arrive at a breakpoint at the start
5518 of the inlined function; the current frame will be the
5520 if (w == NULL || w->cond_exp_valid_block == NULL)
5521 select_frame (get_current_frame ());
5524 struct frame_info *frame;
5526 /* For local watchpoint expressions, which particular
5527 instance of a local is being watched matters, so we
5528 keep track of the frame to evaluate the expression
5529 in. To evaluate the condition however, it doesn't
5530 really matter which instantiation of the function
5531 where the condition makes sense triggers the
5532 watchpoint. This allows an expression like "watch
5533 global if q > 10" set in `func', catch writes to
5534 global on all threads that call `func', or catch
5535 writes on all recursive calls of `func' by a single
5536 thread. We simply always evaluate the condition in
5537 the innermost frame that's executing where it makes
5538 sense to evaluate the condition. It seems
5540 frame = block_innermost_frame (w->cond_exp_valid_block);
5542 select_frame (frame);
5544 within_current_scope = 0;
5546 if (within_current_scope)
5548 = catch_errors (breakpoint_cond_eval, cond,
5549 "Error in testing breakpoint condition:\n",
5553 warning (_("Watchpoint condition cannot be tested "
5554 "in the current scope"));
5555 /* If we failed to set the right context for this
5556 watchpoint, unconditionally report it. */
5559 /* FIXME-someday, should give breakpoint #. */
5560 value_free_to_mark (mark);
5563 if (cond && value_is_zero)
5567 else if (b->ignore_count > 0)
5571 /* Increase the hit count even though we don't stop. */
5573 observer_notify_breakpoint_modified (b);
5577 /* Returns true if we need to track moribund locations of LOC's type
5578 on the current target. */
5581 need_moribund_for_location_type (struct bp_location *loc)
5583 return ((loc->loc_type == bp_loc_software_breakpoint
5584 && !target_supports_stopped_by_sw_breakpoint ())
5585 || (loc->loc_type == bp_loc_hardware_breakpoint
5586 && !target_supports_stopped_by_hw_breakpoint ()));
5590 /* Get a bpstat associated with having just stopped at address
5591 BP_ADDR in thread PTID.
5593 Determine whether we stopped at a breakpoint, etc, or whether we
5594 don't understand this stop. Result is a chain of bpstat's such
5597 if we don't understand the stop, the result is a null pointer.
5599 if we understand why we stopped, the result is not null.
5601 Each element of the chain refers to a particular breakpoint or
5602 watchpoint at which we have stopped. (We may have stopped for
5603 several reasons concurrently.)
5605 Each element of the chain has valid next, breakpoint_at,
5606 commands, FIXME??? fields. */
5609 bpstat_stop_status (struct address_space *aspace,
5610 CORE_ADDR bp_addr, ptid_t ptid,
5611 const struct target_waitstatus *ws)
5613 struct breakpoint *b = NULL;
5614 struct bp_location *bl;
5615 struct bp_location *loc;
5616 /* First item of allocated bpstat's. */
5617 bpstat bs_head = NULL, *bs_link = &bs_head;
5618 /* Pointer to the last thing in the chain currently. */
5621 int need_remove_insert;
5624 /* First, build the bpstat chain with locations that explain a
5625 target stop, while being careful to not set the target running,
5626 as that may invalidate locations (in particular watchpoint
5627 locations are recreated). Resuming will happen here with
5628 breakpoint conditions or watchpoint expressions that include
5629 inferior function calls. */
5633 if (!breakpoint_enabled (b))
5636 for (bl = b->loc; bl != NULL; bl = bl->next)
5638 /* For hardware watchpoints, we look only at the first
5639 location. The watchpoint_check function will work on the
5640 entire expression, not the individual locations. For
5641 read watchpoints, the watchpoints_triggered function has
5642 checked all locations already. */
5643 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5646 if (!bl->enabled || bl->shlib_disabled)
5649 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5652 /* Come here if it's a watchpoint, or if the break address
5655 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5658 /* Assume we stop. Should we find a watchpoint that is not
5659 actually triggered, or if the condition of the breakpoint
5660 evaluates as false, we'll reset 'stop' to 0. */
5664 /* If this is a scope breakpoint, mark the associated
5665 watchpoint as triggered so that we will handle the
5666 out-of-scope event. We'll get to the watchpoint next
5668 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5670 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5672 w->watchpoint_triggered = watch_triggered_yes;
5677 /* Check if a moribund breakpoint explains the stop. */
5678 if (!target_supports_stopped_by_sw_breakpoint ()
5679 || !target_supports_stopped_by_hw_breakpoint ())
5681 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5683 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5684 && need_moribund_for_location_type (loc))
5686 bs = bpstat_alloc (loc, &bs_link);
5687 /* For hits of moribund locations, we should just proceed. */
5690 bs->print_it = print_it_noop;
5695 /* A bit of special processing for shlib breakpoints. We need to
5696 process solib loading here, so that the lists of loaded and
5697 unloaded libraries are correct before we handle "catch load" and
5699 for (bs = bs_head; bs != NULL; bs = bs->next)
5701 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5703 handle_solib_event ();
5708 /* Now go through the locations that caused the target to stop, and
5709 check whether we're interested in reporting this stop to higher
5710 layers, or whether we should resume the target transparently. */
5714 for (bs = bs_head; bs != NULL; bs = bs->next)
5719 b = bs->breakpoint_at;
5720 b->ops->check_status (bs);
5723 bpstat_check_breakpoint_conditions (bs, ptid);
5728 observer_notify_breakpoint_modified (b);
5730 /* We will stop here. */
5731 if (b->disposition == disp_disable)
5733 --(b->enable_count);
5734 if (b->enable_count <= 0)
5735 b->enable_state = bp_disabled;
5740 bs->commands = b->commands;
5741 incref_counted_command_line (bs->commands);
5742 if (command_line_is_silent (bs->commands
5743 ? bs->commands->commands : NULL))
5746 b->ops->after_condition_true (bs);
5751 /* Print nothing for this entry if we don't stop or don't
5753 if (!bs->stop || !bs->print)
5754 bs->print_it = print_it_noop;
5757 /* If we aren't stopping, the value of some hardware watchpoint may
5758 not have changed, but the intermediate memory locations we are
5759 watching may have. Don't bother if we're stopping; this will get
5761 need_remove_insert = 0;
5762 if (! bpstat_causes_stop (bs_head))
5763 for (bs = bs_head; bs != NULL; bs = bs->next)
5765 && bs->breakpoint_at
5766 && is_hardware_watchpoint (bs->breakpoint_at))
5768 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5770 update_watchpoint (w, 0 /* don't reparse. */);
5771 need_remove_insert = 1;
5774 if (need_remove_insert)
5775 update_global_location_list (UGLL_MAY_INSERT);
5776 else if (removed_any)
5777 update_global_location_list (UGLL_DONT_INSERT);
5783 handle_jit_event (void)
5785 struct frame_info *frame;
5786 struct gdbarch *gdbarch;
5789 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5791 /* Switch terminal for any messages produced by
5792 breakpoint_re_set. */
5793 target_terminal_ours_for_output ();
5795 frame = get_current_frame ();
5796 gdbarch = get_frame_arch (frame);
5798 jit_event_handler (gdbarch);
5800 target_terminal_inferior ();
5803 /* Prepare WHAT final decision for infrun. */
5805 /* Decide what infrun needs to do with this bpstat. */
5808 bpstat_what (bpstat bs_head)
5810 struct bpstat_what retval;
5814 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5815 retval.call_dummy = STOP_NONE;
5816 retval.is_longjmp = 0;
5818 for (bs = bs_head; bs != NULL; bs = bs->next)
5820 /* Extract this BS's action. After processing each BS, we check
5821 if its action overrides all we've seem so far. */
5822 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5825 if (bs->breakpoint_at == NULL)
5827 /* I suspect this can happen if it was a momentary
5828 breakpoint which has since been deleted. */
5832 bptype = bs->breakpoint_at->type;
5839 case bp_hardware_breakpoint:
5840 case bp_single_step:
5843 case bp_shlib_event:
5847 this_action = BPSTAT_WHAT_STOP_NOISY;
5849 this_action = BPSTAT_WHAT_STOP_SILENT;
5852 this_action = BPSTAT_WHAT_SINGLE;
5855 case bp_hardware_watchpoint:
5856 case bp_read_watchpoint:
5857 case bp_access_watchpoint:
5861 this_action = BPSTAT_WHAT_STOP_NOISY;
5863 this_action = BPSTAT_WHAT_STOP_SILENT;
5867 /* There was a watchpoint, but we're not stopping.
5868 This requires no further action. */
5872 case bp_longjmp_call_dummy:
5876 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5877 retval.is_longjmp = bptype != bp_exception;
5880 this_action = BPSTAT_WHAT_SINGLE;
5882 case bp_longjmp_resume:
5883 case bp_exception_resume:
5886 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5887 retval.is_longjmp = bptype == bp_longjmp_resume;
5890 this_action = BPSTAT_WHAT_SINGLE;
5892 case bp_step_resume:
5894 this_action = BPSTAT_WHAT_STEP_RESUME;
5897 /* It is for the wrong frame. */
5898 this_action = BPSTAT_WHAT_SINGLE;
5901 case bp_hp_step_resume:
5903 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5906 /* It is for the wrong frame. */
5907 this_action = BPSTAT_WHAT_SINGLE;
5910 case bp_watchpoint_scope:
5911 case bp_thread_event:
5912 case bp_overlay_event:
5913 case bp_longjmp_master:
5914 case bp_std_terminate_master:
5915 case bp_exception_master:
5916 this_action = BPSTAT_WHAT_SINGLE;
5922 this_action = BPSTAT_WHAT_STOP_NOISY;
5924 this_action = BPSTAT_WHAT_STOP_SILENT;
5928 /* There was a catchpoint, but we're not stopping.
5929 This requires no further action. */
5934 this_action = BPSTAT_WHAT_SINGLE;
5937 /* Make sure the action is stop (silent or noisy),
5938 so infrun.c pops the dummy frame. */
5939 retval.call_dummy = STOP_STACK_DUMMY;
5940 this_action = BPSTAT_WHAT_STOP_SILENT;
5942 case bp_std_terminate:
5943 /* Make sure the action is stop (silent or noisy),
5944 so infrun.c pops the dummy frame. */
5945 retval.call_dummy = STOP_STD_TERMINATE;
5946 this_action = BPSTAT_WHAT_STOP_SILENT;
5949 case bp_fast_tracepoint:
5950 case bp_static_tracepoint:
5951 /* Tracepoint hits should not be reported back to GDB, and
5952 if one got through somehow, it should have been filtered
5954 internal_error (__FILE__, __LINE__,
5955 _("bpstat_what: tracepoint encountered"));
5957 case bp_gnu_ifunc_resolver:
5958 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5959 this_action = BPSTAT_WHAT_SINGLE;
5961 case bp_gnu_ifunc_resolver_return:
5962 /* The breakpoint will be removed, execution will restart from the
5963 PC of the former breakpoint. */
5964 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5969 this_action = BPSTAT_WHAT_STOP_SILENT;
5971 this_action = BPSTAT_WHAT_SINGLE;
5975 internal_error (__FILE__, __LINE__,
5976 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5979 retval.main_action = max (retval.main_action, this_action);
5986 bpstat_run_callbacks (bpstat bs_head)
5990 for (bs = bs_head; bs != NULL; bs = bs->next)
5992 struct breakpoint *b = bs->breakpoint_at;
5999 handle_jit_event ();
6001 case bp_gnu_ifunc_resolver:
6002 gnu_ifunc_resolver_stop (b);
6004 case bp_gnu_ifunc_resolver_return:
6005 gnu_ifunc_resolver_return_stop (b);
6011 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6012 without hardware support). This isn't related to a specific bpstat,
6013 just to things like whether watchpoints are set. */
6016 bpstat_should_step (void)
6018 struct breakpoint *b;
6021 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
6027 bpstat_causes_stop (bpstat bs)
6029 for (; bs != NULL; bs = bs->next)
6038 /* Compute a string of spaces suitable to indent the next line
6039 so it starts at the position corresponding to the table column
6040 named COL_NAME in the currently active table of UIOUT. */
6043 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
6045 static char wrap_indent[80];
6046 int i, total_width, width, align;
6050 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
6052 if (strcmp (text, col_name) == 0)
6054 gdb_assert (total_width < sizeof wrap_indent);
6055 memset (wrap_indent, ' ', total_width);
6056 wrap_indent[total_width] = 0;
6061 total_width += width + 1;
6067 /* Determine if the locations of this breakpoint will have their conditions
6068 evaluated by the target, host or a mix of both. Returns the following:
6070 "host": Host evals condition.
6071 "host or target": Host or Target evals condition.
6072 "target": Target evals condition.
6076 bp_condition_evaluator (struct breakpoint *b)
6078 struct bp_location *bl;
6079 char host_evals = 0;
6080 char target_evals = 0;
6085 if (!is_breakpoint (b))
6088 if (gdb_evaluates_breakpoint_condition_p ()
6089 || !target_supports_evaluation_of_breakpoint_conditions ())
6090 return condition_evaluation_host;
6092 for (bl = b->loc; bl; bl = bl->next)
6094 if (bl->cond_bytecode)
6100 if (host_evals && target_evals)
6101 return condition_evaluation_both;
6102 else if (target_evals)
6103 return condition_evaluation_target;
6105 return condition_evaluation_host;
6108 /* Determine the breakpoint location's condition evaluator. This is
6109 similar to bp_condition_evaluator, but for locations. */
6112 bp_location_condition_evaluator (struct bp_location *bl)
6114 if (bl && !is_breakpoint (bl->owner))
6117 if (gdb_evaluates_breakpoint_condition_p ()
6118 || !target_supports_evaluation_of_breakpoint_conditions ())
6119 return condition_evaluation_host;
6121 if (bl && bl->cond_bytecode)
6122 return condition_evaluation_target;
6124 return condition_evaluation_host;
6127 /* Print the LOC location out of the list of B->LOC locations. */
6130 print_breakpoint_location (struct breakpoint *b,
6131 struct bp_location *loc)
6133 struct ui_out *uiout = current_uiout;
6134 struct cleanup *old_chain = save_current_program_space ();
6136 if (loc != NULL && loc->shlib_disabled)
6140 set_current_program_space (loc->pspace);
6142 if (b->display_canonical)
6143 ui_out_field_string (uiout, "what",
6144 event_location_to_string (b->location));
6145 else if (loc && loc->symtab)
6148 = find_pc_sect_function (loc->address, loc->section);
6151 ui_out_text (uiout, "in ");
6152 ui_out_field_string (uiout, "func",
6153 SYMBOL_PRINT_NAME (sym));
6154 ui_out_text (uiout, " ");
6155 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6156 ui_out_text (uiout, "at ");
6158 ui_out_field_string (uiout, "file",
6159 symtab_to_filename_for_display (loc->symtab));
6160 ui_out_text (uiout, ":");
6162 if (ui_out_is_mi_like_p (uiout))
6163 ui_out_field_string (uiout, "fullname",
6164 symtab_to_fullname (loc->symtab));
6166 ui_out_field_int (uiout, "line", loc->line_number);
6170 struct ui_file *stb = mem_fileopen ();
6171 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6173 print_address_symbolic (loc->gdbarch, loc->address, stb,
6175 ui_out_field_stream (uiout, "at", stb);
6177 do_cleanups (stb_chain);
6181 ui_out_field_string (uiout, "pending",
6182 event_location_to_string (b->location));
6183 /* If extra_string is available, it could be holding a condition
6184 or dprintf arguments. In either case, make sure it is printed,
6185 too, but only for non-MI streams. */
6186 if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL)
6188 if (b->type == bp_dprintf)
6189 ui_out_text (uiout, ",");
6191 ui_out_text (uiout, " ");
6192 ui_out_text (uiout, b->extra_string);
6196 if (loc && is_breakpoint (b)
6197 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6198 && bp_condition_evaluator (b) == condition_evaluation_both)
6200 ui_out_text (uiout, " (");
6201 ui_out_field_string (uiout, "evaluated-by",
6202 bp_location_condition_evaluator (loc));
6203 ui_out_text (uiout, ")");
6206 do_cleanups (old_chain);
6210 bptype_string (enum bptype type)
6212 struct ep_type_description
6217 static struct ep_type_description bptypes[] =
6219 {bp_none, "?deleted?"},
6220 {bp_breakpoint, "breakpoint"},
6221 {bp_hardware_breakpoint, "hw breakpoint"},
6222 {bp_single_step, "sw single-step"},
6223 {bp_until, "until"},
6224 {bp_finish, "finish"},
6225 {bp_watchpoint, "watchpoint"},
6226 {bp_hardware_watchpoint, "hw watchpoint"},
6227 {bp_read_watchpoint, "read watchpoint"},
6228 {bp_access_watchpoint, "acc watchpoint"},
6229 {bp_longjmp, "longjmp"},
6230 {bp_longjmp_resume, "longjmp resume"},
6231 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6232 {bp_exception, "exception"},
6233 {bp_exception_resume, "exception resume"},
6234 {bp_step_resume, "step resume"},
6235 {bp_hp_step_resume, "high-priority step resume"},
6236 {bp_watchpoint_scope, "watchpoint scope"},
6237 {bp_call_dummy, "call dummy"},
6238 {bp_std_terminate, "std::terminate"},
6239 {bp_shlib_event, "shlib events"},
6240 {bp_thread_event, "thread events"},
6241 {bp_overlay_event, "overlay events"},
6242 {bp_longjmp_master, "longjmp master"},
6243 {bp_std_terminate_master, "std::terminate master"},
6244 {bp_exception_master, "exception master"},
6245 {bp_catchpoint, "catchpoint"},
6246 {bp_tracepoint, "tracepoint"},
6247 {bp_fast_tracepoint, "fast tracepoint"},
6248 {bp_static_tracepoint, "static tracepoint"},
6249 {bp_dprintf, "dprintf"},
6250 {bp_jit_event, "jit events"},
6251 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6252 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6255 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6256 || ((int) type != bptypes[(int) type].type))
6257 internal_error (__FILE__, __LINE__,
6258 _("bptypes table does not describe type #%d."),
6261 return bptypes[(int) type].description;
6264 /* For MI, output a field named 'thread-groups' with a list as the value.
6265 For CLI, prefix the list with the string 'inf'. */
6268 output_thread_groups (struct ui_out *uiout,
6269 const char *field_name,
6273 struct cleanup *back_to;
6274 int is_mi = ui_out_is_mi_like_p (uiout);
6278 /* For backward compatibility, don't display inferiors in CLI unless
6279 there are several. Always display them for MI. */
6280 if (!is_mi && mi_only)
6283 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6285 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6291 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6292 ui_out_field_string (uiout, NULL, mi_group);
6297 ui_out_text (uiout, " inf ");
6299 ui_out_text (uiout, ", ");
6301 ui_out_text (uiout, plongest (inf));
6305 do_cleanups (back_to);
6308 /* Print B to gdb_stdout. */
6311 print_one_breakpoint_location (struct breakpoint *b,
6312 struct bp_location *loc,
6314 struct bp_location **last_loc,
6317 struct command_line *l;
6318 static char bpenables[] = "nynny";
6320 struct ui_out *uiout = current_uiout;
6321 int header_of_multiple = 0;
6322 int part_of_multiple = (loc != NULL);
6323 struct value_print_options opts;
6325 get_user_print_options (&opts);
6327 gdb_assert (!loc || loc_number != 0);
6328 /* See comment in print_one_breakpoint concerning treatment of
6329 breakpoints with single disabled location. */
6332 && (b->loc->next != NULL || !b->loc->enabled)))
6333 header_of_multiple = 1;
6341 if (part_of_multiple)
6344 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6345 ui_out_field_string (uiout, "number", formatted);
6350 ui_out_field_int (uiout, "number", b->number);
6355 if (part_of_multiple)
6356 ui_out_field_skip (uiout, "type");
6358 ui_out_field_string (uiout, "type", bptype_string (b->type));
6362 if (part_of_multiple)
6363 ui_out_field_skip (uiout, "disp");
6365 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6370 if (part_of_multiple)
6371 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6373 ui_out_field_fmt (uiout, "enabled", "%c",
6374 bpenables[(int) b->enable_state]);
6375 ui_out_spaces (uiout, 2);
6379 if (b->ops != NULL && b->ops->print_one != NULL)
6381 /* Although the print_one can possibly print all locations,
6382 calling it here is not likely to get any nice result. So,
6383 make sure there's just one location. */
6384 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6385 b->ops->print_one (b, last_loc);
6391 internal_error (__FILE__, __LINE__,
6392 _("print_one_breakpoint: bp_none encountered\n"));
6396 case bp_hardware_watchpoint:
6397 case bp_read_watchpoint:
6398 case bp_access_watchpoint:
6400 struct watchpoint *w = (struct watchpoint *) b;
6402 /* Field 4, the address, is omitted (which makes the columns
6403 not line up too nicely with the headers, but the effect
6404 is relatively readable). */
6405 if (opts.addressprint)
6406 ui_out_field_skip (uiout, "addr");
6408 ui_out_field_string (uiout, "what", w->exp_string);
6413 case bp_hardware_breakpoint:
6414 case bp_single_step:
6418 case bp_longjmp_resume:
6419 case bp_longjmp_call_dummy:
6421 case bp_exception_resume:
6422 case bp_step_resume:
6423 case bp_hp_step_resume:
6424 case bp_watchpoint_scope:
6426 case bp_std_terminate:
6427 case bp_shlib_event:
6428 case bp_thread_event:
6429 case bp_overlay_event:
6430 case bp_longjmp_master:
6431 case bp_std_terminate_master:
6432 case bp_exception_master:
6434 case bp_fast_tracepoint:
6435 case bp_static_tracepoint:
6438 case bp_gnu_ifunc_resolver:
6439 case bp_gnu_ifunc_resolver_return:
6440 if (opts.addressprint)
6443 if (header_of_multiple)
6444 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6445 else if (b->loc == NULL || loc->shlib_disabled)
6446 ui_out_field_string (uiout, "addr", "<PENDING>");
6448 ui_out_field_core_addr (uiout, "addr",
6449 loc->gdbarch, loc->address);
6452 if (!header_of_multiple)
6453 print_breakpoint_location (b, loc);
6460 if (loc != NULL && !header_of_multiple)
6462 struct inferior *inf;
6463 VEC(int) *inf_num = NULL;
6468 if (inf->pspace == loc->pspace)
6469 VEC_safe_push (int, inf_num, inf->num);
6472 /* For backward compatibility, don't display inferiors in CLI unless
6473 there are several. Always display for MI. */
6475 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6476 && (number_of_program_spaces () > 1
6477 || number_of_inferiors () > 1)
6478 /* LOC is for existing B, it cannot be in
6479 moribund_locations and thus having NULL OWNER. */
6480 && loc->owner->type != bp_catchpoint))
6482 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6483 VEC_free (int, inf_num);
6486 if (!part_of_multiple)
6488 if (b->thread != -1)
6490 /* FIXME: This seems to be redundant and lost here; see the
6491 "stop only in" line a little further down. */
6492 ui_out_text (uiout, " thread ");
6493 ui_out_field_int (uiout, "thread", b->thread);
6495 else if (b->task != 0)
6497 ui_out_text (uiout, " task ");
6498 ui_out_field_int (uiout, "task", b->task);
6502 ui_out_text (uiout, "\n");
6504 if (!part_of_multiple)
6505 b->ops->print_one_detail (b, uiout);
6507 if (part_of_multiple && frame_id_p (b->frame_id))
6510 ui_out_text (uiout, "\tstop only in stack frame at ");
6511 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6513 ui_out_field_core_addr (uiout, "frame",
6514 b->gdbarch, b->frame_id.stack_addr);
6515 ui_out_text (uiout, "\n");
6518 if (!part_of_multiple && b->cond_string)
6521 if (is_tracepoint (b))
6522 ui_out_text (uiout, "\ttrace only if ");
6524 ui_out_text (uiout, "\tstop only if ");
6525 ui_out_field_string (uiout, "cond", b->cond_string);
6527 /* Print whether the target is doing the breakpoint's condition
6528 evaluation. If GDB is doing the evaluation, don't print anything. */
6529 if (is_breakpoint (b)
6530 && breakpoint_condition_evaluation_mode ()
6531 == condition_evaluation_target)
6533 ui_out_text (uiout, " (");
6534 ui_out_field_string (uiout, "evaluated-by",
6535 bp_condition_evaluator (b));
6536 ui_out_text (uiout, " evals)");
6538 ui_out_text (uiout, "\n");
6541 if (!part_of_multiple && b->thread != -1)
6543 /* FIXME should make an annotation for this. */
6544 ui_out_text (uiout, "\tstop only in thread ");
6545 if (ui_out_is_mi_like_p (uiout))
6546 ui_out_field_int (uiout, "thread", b->thread);
6549 struct thread_info *thr = find_thread_global_id (b->thread);
6551 ui_out_field_string (uiout, "thread", print_thread_id (thr));
6553 ui_out_text (uiout, "\n");
6556 if (!part_of_multiple)
6560 /* FIXME should make an annotation for this. */
6561 if (is_catchpoint (b))
6562 ui_out_text (uiout, "\tcatchpoint");
6563 else if (is_tracepoint (b))
6564 ui_out_text (uiout, "\ttracepoint");
6566 ui_out_text (uiout, "\tbreakpoint");
6567 ui_out_text (uiout, " already hit ");
6568 ui_out_field_int (uiout, "times", b->hit_count);
6569 if (b->hit_count == 1)
6570 ui_out_text (uiout, " time\n");
6572 ui_out_text (uiout, " times\n");
6576 /* Output the count also if it is zero, but only if this is mi. */
6577 if (ui_out_is_mi_like_p (uiout))
6578 ui_out_field_int (uiout, "times", b->hit_count);
6582 if (!part_of_multiple && b->ignore_count)
6585 ui_out_text (uiout, "\tignore next ");
6586 ui_out_field_int (uiout, "ignore", b->ignore_count);
6587 ui_out_text (uiout, " hits\n");
6590 /* Note that an enable count of 1 corresponds to "enable once"
6591 behavior, which is reported by the combination of enablement and
6592 disposition, so we don't need to mention it here. */
6593 if (!part_of_multiple && b->enable_count > 1)
6596 ui_out_text (uiout, "\tdisable after ");
6597 /* Tweak the wording to clarify that ignore and enable counts
6598 are distinct, and have additive effect. */
6599 if (b->ignore_count)
6600 ui_out_text (uiout, "additional ");
6602 ui_out_text (uiout, "next ");
6603 ui_out_field_int (uiout, "enable", b->enable_count);
6604 ui_out_text (uiout, " hits\n");
6607 if (!part_of_multiple && is_tracepoint (b))
6609 struct tracepoint *tp = (struct tracepoint *) b;
6611 if (tp->traceframe_usage)
6613 ui_out_text (uiout, "\ttrace buffer usage ");
6614 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6615 ui_out_text (uiout, " bytes\n");
6619 l = b->commands ? b->commands->commands : NULL;
6620 if (!part_of_multiple && l)
6622 struct cleanup *script_chain;
6625 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6626 print_command_lines (uiout, l, 4);
6627 do_cleanups (script_chain);
6630 if (is_tracepoint (b))
6632 struct tracepoint *t = (struct tracepoint *) b;
6634 if (!part_of_multiple && t->pass_count)
6636 annotate_field (10);
6637 ui_out_text (uiout, "\tpass count ");
6638 ui_out_field_int (uiout, "pass", t->pass_count);
6639 ui_out_text (uiout, " \n");
6642 /* Don't display it when tracepoint or tracepoint location is
6644 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6646 annotate_field (11);
6648 if (ui_out_is_mi_like_p (uiout))
6649 ui_out_field_string (uiout, "installed",
6650 loc->inserted ? "y" : "n");
6654 ui_out_text (uiout, "\t");
6656 ui_out_text (uiout, "\tnot ");
6657 ui_out_text (uiout, "installed on target\n");
6662 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6664 if (is_watchpoint (b))
6666 struct watchpoint *w = (struct watchpoint *) b;
6668 ui_out_field_string (uiout, "original-location", w->exp_string);
6670 else if (b->location != NULL
6671 && event_location_to_string (b->location) != NULL)
6672 ui_out_field_string (uiout, "original-location",
6673 event_location_to_string (b->location));
6678 print_one_breakpoint (struct breakpoint *b,
6679 struct bp_location **last_loc,
6682 struct cleanup *bkpt_chain;
6683 struct ui_out *uiout = current_uiout;
6685 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6687 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6688 do_cleanups (bkpt_chain);
6690 /* If this breakpoint has custom print function,
6691 it's already printed. Otherwise, print individual
6692 locations, if any. */
6693 if (b->ops == NULL || b->ops->print_one == NULL)
6695 /* If breakpoint has a single location that is disabled, we
6696 print it as if it had several locations, since otherwise it's
6697 hard to represent "breakpoint enabled, location disabled"
6700 Note that while hardware watchpoints have several locations
6701 internally, that's not a property exposed to user. */
6703 && !is_hardware_watchpoint (b)
6704 && (b->loc->next || !b->loc->enabled))
6706 struct bp_location *loc;
6709 for (loc = b->loc; loc; loc = loc->next, ++n)
6711 struct cleanup *inner2 =
6712 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6713 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6714 do_cleanups (inner2);
6721 breakpoint_address_bits (struct breakpoint *b)
6723 int print_address_bits = 0;
6724 struct bp_location *loc;
6726 /* Software watchpoints that aren't watching memory don't have an
6727 address to print. */
6728 if (is_no_memory_software_watchpoint (b))
6731 for (loc = b->loc; loc; loc = loc->next)
6735 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6736 if (addr_bit > print_address_bits)
6737 print_address_bits = addr_bit;
6740 return print_address_bits;
6743 struct captured_breakpoint_query_args
6749 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6751 struct captured_breakpoint_query_args *args
6752 = (struct captured_breakpoint_query_args *) data;
6753 struct breakpoint *b;
6754 struct bp_location *dummy_loc = NULL;
6758 if (args->bnum == b->number)
6760 print_one_breakpoint (b, &dummy_loc, 0);
6768 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6769 char **error_message)
6771 struct captured_breakpoint_query_args args;
6774 /* For the moment we don't trust print_one_breakpoint() to not throw
6776 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6777 error_message, RETURN_MASK_ALL) < 0)
6783 /* Return true if this breakpoint was set by the user, false if it is
6784 internal or momentary. */
6787 user_breakpoint_p (struct breakpoint *b)
6789 return b->number > 0;
6792 /* Print information on user settable breakpoint (watchpoint, etc)
6793 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6794 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6795 FILTER is non-NULL, call it on each breakpoint and only include the
6796 ones for which it returns non-zero. Return the total number of
6797 breakpoints listed. */
6800 breakpoint_1 (char *args, int allflag,
6801 int (*filter) (const struct breakpoint *))
6803 struct breakpoint *b;
6804 struct bp_location *last_loc = NULL;
6805 int nr_printable_breakpoints;
6806 struct cleanup *bkpttbl_chain;
6807 struct value_print_options opts;
6808 int print_address_bits = 0;
6809 int print_type_col_width = 14;
6810 struct ui_out *uiout = current_uiout;
6812 get_user_print_options (&opts);
6814 /* Compute the number of rows in the table, as well as the size
6815 required for address fields. */
6816 nr_printable_breakpoints = 0;
6819 /* If we have a filter, only list the breakpoints it accepts. */
6820 if (filter && !filter (b))
6823 /* If we have an "args" string, it is a list of breakpoints to
6824 accept. Skip the others. */
6825 if (args != NULL && *args != '\0')
6827 if (allflag && parse_and_eval_long (args) != b->number)
6829 if (!allflag && !number_is_in_list (args, b->number))
6833 if (allflag || user_breakpoint_p (b))
6835 int addr_bit, type_len;
6837 addr_bit = breakpoint_address_bits (b);
6838 if (addr_bit > print_address_bits)
6839 print_address_bits = addr_bit;
6841 type_len = strlen (bptype_string (b->type));
6842 if (type_len > print_type_col_width)
6843 print_type_col_width = type_len;
6845 nr_printable_breakpoints++;
6849 if (opts.addressprint)
6851 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6852 nr_printable_breakpoints,
6856 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6857 nr_printable_breakpoints,
6860 if (nr_printable_breakpoints > 0)
6861 annotate_breakpoints_headers ();
6862 if (nr_printable_breakpoints > 0)
6864 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6865 if (nr_printable_breakpoints > 0)
6867 ui_out_table_header (uiout, print_type_col_width, ui_left,
6868 "type", "Type"); /* 2 */
6869 if (nr_printable_breakpoints > 0)
6871 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6872 if (nr_printable_breakpoints > 0)
6874 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6875 if (opts.addressprint)
6877 if (nr_printable_breakpoints > 0)
6879 if (print_address_bits <= 32)
6880 ui_out_table_header (uiout, 10, ui_left,
6881 "addr", "Address"); /* 5 */
6883 ui_out_table_header (uiout, 18, ui_left,
6884 "addr", "Address"); /* 5 */
6886 if (nr_printable_breakpoints > 0)
6888 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6889 ui_out_table_body (uiout);
6890 if (nr_printable_breakpoints > 0)
6891 annotate_breakpoints_table ();
6896 /* If we have a filter, only list the breakpoints it accepts. */
6897 if (filter && !filter (b))
6900 /* If we have an "args" string, it is a list of breakpoints to
6901 accept. Skip the others. */
6903 if (args != NULL && *args != '\0')
6905 if (allflag) /* maintenance info breakpoint */
6907 if (parse_and_eval_long (args) != b->number)
6910 else /* all others */
6912 if (!number_is_in_list (args, b->number))
6916 /* We only print out user settable breakpoints unless the
6918 if (allflag || user_breakpoint_p (b))
6919 print_one_breakpoint (b, &last_loc, allflag);
6922 do_cleanups (bkpttbl_chain);
6924 if (nr_printable_breakpoints == 0)
6926 /* If there's a filter, let the caller decide how to report
6930 if (args == NULL || *args == '\0')
6931 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6933 ui_out_message (uiout, 0,
6934 "No breakpoint or watchpoint matching '%s'.\n",
6940 if (last_loc && !server_command)
6941 set_next_address (last_loc->gdbarch, last_loc->address);
6944 /* FIXME? Should this be moved up so that it is only called when
6945 there have been breakpoints? */
6946 annotate_breakpoints_table_end ();
6948 return nr_printable_breakpoints;
6951 /* Display the value of default-collect in a way that is generally
6952 compatible with the breakpoint list. */
6955 default_collect_info (void)
6957 struct ui_out *uiout = current_uiout;
6959 /* If it has no value (which is frequently the case), say nothing; a
6960 message like "No default-collect." gets in user's face when it's
6962 if (!*default_collect)
6965 /* The following phrase lines up nicely with per-tracepoint collect
6967 ui_out_text (uiout, "default collect ");
6968 ui_out_field_string (uiout, "default-collect", default_collect);
6969 ui_out_text (uiout, " \n");
6973 breakpoints_info (char *args, int from_tty)
6975 breakpoint_1 (args, 0, NULL);
6977 default_collect_info ();
6981 watchpoints_info (char *args, int from_tty)
6983 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6984 struct ui_out *uiout = current_uiout;
6986 if (num_printed == 0)
6988 if (args == NULL || *args == '\0')
6989 ui_out_message (uiout, 0, "No watchpoints.\n");
6991 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6996 maintenance_info_breakpoints (char *args, int from_tty)
6998 breakpoint_1 (args, 1, NULL);
7000 default_collect_info ();
7004 breakpoint_has_pc (struct breakpoint *b,
7005 struct program_space *pspace,
7006 CORE_ADDR pc, struct obj_section *section)
7008 struct bp_location *bl = b->loc;
7010 for (; bl; bl = bl->next)
7012 if (bl->pspace == pspace
7013 && bl->address == pc
7014 && (!overlay_debugging || bl->section == section))
7020 /* Print a message describing any user-breakpoints set at PC. This
7021 concerns with logical breakpoints, so we match program spaces, not
7025 describe_other_breakpoints (struct gdbarch *gdbarch,
7026 struct program_space *pspace, CORE_ADDR pc,
7027 struct obj_section *section, int thread)
7030 struct breakpoint *b;
7033 others += (user_breakpoint_p (b)
7034 && breakpoint_has_pc (b, pspace, pc, section));
7038 printf_filtered (_("Note: breakpoint "));
7039 else /* if (others == ???) */
7040 printf_filtered (_("Note: breakpoints "));
7042 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
7045 printf_filtered ("%d", b->number);
7046 if (b->thread == -1 && thread != -1)
7047 printf_filtered (" (all threads)");
7048 else if (b->thread != -1)
7049 printf_filtered (" (thread %d)", b->thread);
7050 printf_filtered ("%s%s ",
7051 ((b->enable_state == bp_disabled
7052 || b->enable_state == bp_call_disabled)
7056 : ((others == 1) ? " and" : ""));
7058 printf_filtered (_("also set at pc "));
7059 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
7060 printf_filtered (".\n");
7065 /* Return true iff it is meaningful to use the address member of
7066 BPT locations. For some breakpoint types, the locations' address members
7067 are irrelevant and it makes no sense to attempt to compare them to other
7068 addresses (or use them for any other purpose either).
7070 More specifically, each of the following breakpoint types will
7071 always have a zero valued location address and we don't want to mark
7072 breakpoints of any of these types to be a duplicate of an actual
7073 breakpoint location at address zero:
7081 breakpoint_address_is_meaningful (struct breakpoint *bpt)
7083 enum bptype type = bpt->type;
7085 return (type != bp_watchpoint && type != bp_catchpoint);
7088 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7089 true if LOC1 and LOC2 represent the same watchpoint location. */
7092 watchpoint_locations_match (struct bp_location *loc1,
7093 struct bp_location *loc2)
7095 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
7096 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
7098 /* Both of them must exist. */
7099 gdb_assert (w1 != NULL);
7100 gdb_assert (w2 != NULL);
7102 /* If the target can evaluate the condition expression in hardware,
7103 then we we need to insert both watchpoints even if they are at
7104 the same place. Otherwise the watchpoint will only trigger when
7105 the condition of whichever watchpoint was inserted evaluates to
7106 true, not giving a chance for GDB to check the condition of the
7107 other watchpoint. */
7109 && target_can_accel_watchpoint_condition (loc1->address,
7111 loc1->watchpoint_type,
7114 && target_can_accel_watchpoint_condition (loc2->address,
7116 loc2->watchpoint_type,
7120 /* Note that this checks the owner's type, not the location's. In
7121 case the target does not support read watchpoints, but does
7122 support access watchpoints, we'll have bp_read_watchpoint
7123 watchpoints with hw_access locations. Those should be considered
7124 duplicates of hw_read locations. The hw_read locations will
7125 become hw_access locations later. */
7126 return (loc1->owner->type == loc2->owner->type
7127 && loc1->pspace->aspace == loc2->pspace->aspace
7128 && loc1->address == loc2->address
7129 && loc1->length == loc2->length);
7132 /* See breakpoint.h. */
7135 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7136 struct address_space *aspace2, CORE_ADDR addr2)
7138 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7139 || aspace1 == aspace2)
7143 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7144 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7145 matches ASPACE2. On targets that have global breakpoints, the address
7146 space doesn't really matter. */
7149 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7150 int len1, struct address_space *aspace2,
7153 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7154 || aspace1 == aspace2)
7155 && addr2 >= addr1 && addr2 < addr1 + len1);
7158 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7159 a ranged breakpoint. In most targets, a match happens only if ASPACE
7160 matches the breakpoint's address space. On targets that have global
7161 breakpoints, the address space doesn't really matter. */
7164 breakpoint_location_address_match (struct bp_location *bl,
7165 struct address_space *aspace,
7168 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7171 && breakpoint_address_match_range (bl->pspace->aspace,
7172 bl->address, bl->length,
7176 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7177 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7178 match happens only if ASPACE matches the breakpoint's address
7179 space. On targets that have global breakpoints, the address space
7180 doesn't really matter. */
7183 breakpoint_location_address_range_overlap (struct bp_location *bl,
7184 struct address_space *aspace,
7185 CORE_ADDR addr, int len)
7187 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7188 || bl->pspace->aspace == aspace)
7190 int bl_len = bl->length != 0 ? bl->length : 1;
7192 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
7198 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7199 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7200 true, otherwise returns false. */
7203 tracepoint_locations_match (struct bp_location *loc1,
7204 struct bp_location *loc2)
7206 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7207 /* Since tracepoint locations are never duplicated with others', tracepoint
7208 locations at the same address of different tracepoints are regarded as
7209 different locations. */
7210 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7215 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7216 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7217 represent the same location. */
7220 breakpoint_locations_match (struct bp_location *loc1,
7221 struct bp_location *loc2)
7223 int hw_point1, hw_point2;
7225 /* Both of them must not be in moribund_locations. */
7226 gdb_assert (loc1->owner != NULL);
7227 gdb_assert (loc2->owner != NULL);
7229 hw_point1 = is_hardware_watchpoint (loc1->owner);
7230 hw_point2 = is_hardware_watchpoint (loc2->owner);
7232 if (hw_point1 != hw_point2)
7235 return watchpoint_locations_match (loc1, loc2);
7236 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7237 return tracepoint_locations_match (loc1, loc2);
7239 /* We compare bp_location.length in order to cover ranged breakpoints. */
7240 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7241 loc2->pspace->aspace, loc2->address)
7242 && loc1->length == loc2->length);
7246 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7247 int bnum, int have_bnum)
7249 /* The longest string possibly returned by hex_string_custom
7250 is 50 chars. These must be at least that big for safety. */
7254 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7255 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7257 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7258 bnum, astr1, astr2);
7260 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7263 /* Adjust a breakpoint's address to account for architectural
7264 constraints on breakpoint placement. Return the adjusted address.
7265 Note: Very few targets require this kind of adjustment. For most
7266 targets, this function is simply the identity function. */
7269 adjust_breakpoint_address (struct gdbarch *gdbarch,
7270 CORE_ADDR bpaddr, enum bptype bptype)
7272 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7274 /* Very few targets need any kind of breakpoint adjustment. */
7277 else if (bptype == bp_watchpoint
7278 || bptype == bp_hardware_watchpoint
7279 || bptype == bp_read_watchpoint
7280 || bptype == bp_access_watchpoint
7281 || bptype == bp_catchpoint)
7283 /* Watchpoints and the various bp_catch_* eventpoints should not
7284 have their addresses modified. */
7287 else if (bptype == bp_single_step)
7289 /* Single-step breakpoints should not have their addresses
7290 modified. If there's any architectural constrain that
7291 applies to this address, then it should have already been
7292 taken into account when the breakpoint was created in the
7293 first place. If we didn't do this, stepping through e.g.,
7294 Thumb-2 IT blocks would break. */
7299 CORE_ADDR adjusted_bpaddr;
7301 /* Some targets have architectural constraints on the placement
7302 of breakpoint instructions. Obtain the adjusted address. */
7303 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7305 /* An adjusted breakpoint address can significantly alter
7306 a user's expectations. Print a warning if an adjustment
7308 if (adjusted_bpaddr != bpaddr)
7309 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7311 return adjusted_bpaddr;
7316 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7317 struct breakpoint *owner)
7319 memset (loc, 0, sizeof (*loc));
7321 gdb_assert (ops != NULL);
7326 loc->cond_bytecode = NULL;
7327 loc->shlib_disabled = 0;
7330 switch (owner->type)
7333 case bp_single_step:
7337 case bp_longjmp_resume:
7338 case bp_longjmp_call_dummy:
7340 case bp_exception_resume:
7341 case bp_step_resume:
7342 case bp_hp_step_resume:
7343 case bp_watchpoint_scope:
7345 case bp_std_terminate:
7346 case bp_shlib_event:
7347 case bp_thread_event:
7348 case bp_overlay_event:
7350 case bp_longjmp_master:
7351 case bp_std_terminate_master:
7352 case bp_exception_master:
7353 case bp_gnu_ifunc_resolver:
7354 case bp_gnu_ifunc_resolver_return:
7356 loc->loc_type = bp_loc_software_breakpoint;
7357 mark_breakpoint_location_modified (loc);
7359 case bp_hardware_breakpoint:
7360 loc->loc_type = bp_loc_hardware_breakpoint;
7361 mark_breakpoint_location_modified (loc);
7363 case bp_hardware_watchpoint:
7364 case bp_read_watchpoint:
7365 case bp_access_watchpoint:
7366 loc->loc_type = bp_loc_hardware_watchpoint;
7371 case bp_fast_tracepoint:
7372 case bp_static_tracepoint:
7373 loc->loc_type = bp_loc_other;
7376 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7382 /* Allocate a struct bp_location. */
7384 static struct bp_location *
7385 allocate_bp_location (struct breakpoint *bpt)
7387 return bpt->ops->allocate_location (bpt);
7391 free_bp_location (struct bp_location *loc)
7393 loc->ops->dtor (loc);
7397 /* Increment reference count. */
7400 incref_bp_location (struct bp_location *bl)
7405 /* Decrement reference count. If the reference count reaches 0,
7406 destroy the bp_location. Sets *BLP to NULL. */
7409 decref_bp_location (struct bp_location **blp)
7411 gdb_assert ((*blp)->refc > 0);
7413 if (--(*blp)->refc == 0)
7414 free_bp_location (*blp);
7418 /* Add breakpoint B at the end of the global breakpoint chain. */
7421 add_to_breakpoint_chain (struct breakpoint *b)
7423 struct breakpoint *b1;
7425 /* Add this breakpoint to the end of the chain so that a list of
7426 breakpoints will come out in order of increasing numbers. */
7428 b1 = breakpoint_chain;
7430 breakpoint_chain = b;
7439 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7442 init_raw_breakpoint_without_location (struct breakpoint *b,
7443 struct gdbarch *gdbarch,
7445 const struct breakpoint_ops *ops)
7447 memset (b, 0, sizeof (*b));
7449 gdb_assert (ops != NULL);
7453 b->gdbarch = gdbarch;
7454 b->language = current_language->la_language;
7455 b->input_radix = input_radix;
7457 b->enable_state = bp_enabled;
7460 b->ignore_count = 0;
7462 b->frame_id = null_frame_id;
7463 b->condition_not_parsed = 0;
7464 b->py_bp_object = NULL;
7465 b->related_breakpoint = b;
7469 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7470 that has type BPTYPE and has no locations as yet. */
7472 static struct breakpoint *
7473 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7475 const struct breakpoint_ops *ops)
7477 struct breakpoint *b = XNEW (struct breakpoint);
7479 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7480 add_to_breakpoint_chain (b);
7484 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7485 resolutions should be made as the user specified the location explicitly
7489 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7491 gdb_assert (loc->owner != NULL);
7493 if (loc->owner->type == bp_breakpoint
7494 || loc->owner->type == bp_hardware_breakpoint
7495 || is_tracepoint (loc->owner))
7498 const char *function_name;
7499 CORE_ADDR func_addr;
7501 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7502 &func_addr, NULL, &is_gnu_ifunc);
7504 if (is_gnu_ifunc && !explicit_loc)
7506 struct breakpoint *b = loc->owner;
7508 gdb_assert (loc->pspace == current_program_space);
7509 if (gnu_ifunc_resolve_name (function_name,
7510 &loc->requested_address))
7512 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7513 loc->address = adjust_breakpoint_address (loc->gdbarch,
7514 loc->requested_address,
7517 else if (b->type == bp_breakpoint && b->loc == loc
7518 && loc->next == NULL && b->related_breakpoint == b)
7520 /* Create only the whole new breakpoint of this type but do not
7521 mess more complicated breakpoints with multiple locations. */
7522 b->type = bp_gnu_ifunc_resolver;
7523 /* Remember the resolver's address for use by the return
7525 loc->related_address = func_addr;
7530 loc->function_name = xstrdup (function_name);
7534 /* Attempt to determine architecture of location identified by SAL. */
7536 get_sal_arch (struct symtab_and_line sal)
7539 return get_objfile_arch (sal.section->objfile);
7541 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7546 /* Low level routine for partially initializing a breakpoint of type
7547 BPTYPE. The newly created breakpoint's address, section, source
7548 file name, and line number are provided by SAL.
7550 It is expected that the caller will complete the initialization of
7551 the newly created breakpoint struct as well as output any status
7552 information regarding the creation of a new breakpoint. */
7555 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7556 struct symtab_and_line sal, enum bptype bptype,
7557 const struct breakpoint_ops *ops)
7559 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7561 add_location_to_breakpoint (b, &sal);
7563 if (bptype != bp_catchpoint)
7564 gdb_assert (sal.pspace != NULL);
7566 /* Store the program space that was used to set the breakpoint,
7567 except for ordinary breakpoints, which are independent of the
7569 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7570 b->pspace = sal.pspace;
7573 /* set_raw_breakpoint is a low level routine for allocating and
7574 partially initializing a breakpoint of type BPTYPE. The newly
7575 created breakpoint's address, section, source file name, and line
7576 number are provided by SAL. The newly created and partially
7577 initialized breakpoint is added to the breakpoint chain and
7578 is also returned as the value of this function.
7580 It is expected that the caller will complete the initialization of
7581 the newly created breakpoint struct as well as output any status
7582 information regarding the creation of a new breakpoint. In
7583 particular, set_raw_breakpoint does NOT set the breakpoint
7584 number! Care should be taken to not allow an error to occur
7585 prior to completing the initialization of the breakpoint. If this
7586 should happen, a bogus breakpoint will be left on the chain. */
7589 set_raw_breakpoint (struct gdbarch *gdbarch,
7590 struct symtab_and_line sal, enum bptype bptype,
7591 const struct breakpoint_ops *ops)
7593 struct breakpoint *b = XNEW (struct breakpoint);
7595 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7596 add_to_breakpoint_chain (b);
7600 /* Call this routine when stepping and nexting to enable a breakpoint
7601 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7602 initiated the operation. */
7605 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7607 struct breakpoint *b, *b_tmp;
7608 int thread = tp->global_num;
7610 /* To avoid having to rescan all objfile symbols at every step,
7611 we maintain a list of continually-inserted but always disabled
7612 longjmp "master" breakpoints. Here, we simply create momentary
7613 clones of those and enable them for the requested thread. */
7614 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7615 if (b->pspace == current_program_space
7616 && (b->type == bp_longjmp_master
7617 || b->type == bp_exception_master))
7619 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7620 struct breakpoint *clone;
7622 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7623 after their removal. */
7624 clone = momentary_breakpoint_from_master (b, type,
7625 &longjmp_breakpoint_ops, 1);
7626 clone->thread = thread;
7629 tp->initiating_frame = frame;
7632 /* Delete all longjmp breakpoints from THREAD. */
7634 delete_longjmp_breakpoint (int thread)
7636 struct breakpoint *b, *b_tmp;
7638 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7639 if (b->type == bp_longjmp || b->type == bp_exception)
7641 if (b->thread == thread)
7642 delete_breakpoint (b);
7647 delete_longjmp_breakpoint_at_next_stop (int thread)
7649 struct breakpoint *b, *b_tmp;
7651 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7652 if (b->type == bp_longjmp || b->type == bp_exception)
7654 if (b->thread == thread)
7655 b->disposition = disp_del_at_next_stop;
7659 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7660 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7661 pointer to any of them. Return NULL if this system cannot place longjmp
7665 set_longjmp_breakpoint_for_call_dummy (void)
7667 struct breakpoint *b, *retval = NULL;
7670 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7672 struct breakpoint *new_b;
7674 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7675 &momentary_breakpoint_ops,
7677 new_b->thread = ptid_to_global_thread_id (inferior_ptid);
7679 /* Link NEW_B into the chain of RETVAL breakpoints. */
7681 gdb_assert (new_b->related_breakpoint == new_b);
7684 new_b->related_breakpoint = retval;
7685 while (retval->related_breakpoint != new_b->related_breakpoint)
7686 retval = retval->related_breakpoint;
7687 retval->related_breakpoint = new_b;
7693 /* Verify all existing dummy frames and their associated breakpoints for
7694 TP. Remove those which can no longer be found in the current frame
7697 You should call this function only at places where it is safe to currently
7698 unwind the whole stack. Failed stack unwind would discard live dummy
7702 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7704 struct breakpoint *b, *b_tmp;
7706 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7707 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7709 struct breakpoint *dummy_b = b->related_breakpoint;
7711 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7712 dummy_b = dummy_b->related_breakpoint;
7713 if (dummy_b->type != bp_call_dummy
7714 || frame_find_by_id (dummy_b->frame_id) != NULL)
7717 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7719 while (b->related_breakpoint != b)
7721 if (b_tmp == b->related_breakpoint)
7722 b_tmp = b->related_breakpoint->next;
7723 delete_breakpoint (b->related_breakpoint);
7725 delete_breakpoint (b);
7730 enable_overlay_breakpoints (void)
7732 struct breakpoint *b;
7735 if (b->type == bp_overlay_event)
7737 b->enable_state = bp_enabled;
7738 update_global_location_list (UGLL_MAY_INSERT);
7739 overlay_events_enabled = 1;
7744 disable_overlay_breakpoints (void)
7746 struct breakpoint *b;
7749 if (b->type == bp_overlay_event)
7751 b->enable_state = bp_disabled;
7752 update_global_location_list (UGLL_DONT_INSERT);
7753 overlay_events_enabled = 0;
7757 /* Set an active std::terminate breakpoint for each std::terminate
7758 master breakpoint. */
7760 set_std_terminate_breakpoint (void)
7762 struct breakpoint *b, *b_tmp;
7764 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7765 if (b->pspace == current_program_space
7766 && b->type == bp_std_terminate_master)
7768 momentary_breakpoint_from_master (b, bp_std_terminate,
7769 &momentary_breakpoint_ops, 1);
7773 /* Delete all the std::terminate breakpoints. */
7775 delete_std_terminate_breakpoint (void)
7777 struct breakpoint *b, *b_tmp;
7779 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7780 if (b->type == bp_std_terminate)
7781 delete_breakpoint (b);
7785 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7787 struct breakpoint *b;
7789 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7790 &internal_breakpoint_ops);
7792 b->enable_state = bp_enabled;
7793 /* location has to be used or breakpoint_re_set will delete me. */
7794 b->location = new_address_location (b->loc->address, NULL, 0);
7796 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7801 struct lang_and_radix
7807 /* Create a breakpoint for JIT code registration and unregistration. */
7810 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7812 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7813 &internal_breakpoint_ops);
7816 /* Remove JIT code registration and unregistration breakpoint(s). */
7819 remove_jit_event_breakpoints (void)
7821 struct breakpoint *b, *b_tmp;
7823 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7824 if (b->type == bp_jit_event
7825 && b->loc->pspace == current_program_space)
7826 delete_breakpoint (b);
7830 remove_solib_event_breakpoints (void)
7832 struct breakpoint *b, *b_tmp;
7834 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7835 if (b->type == bp_shlib_event
7836 && b->loc->pspace == current_program_space)
7837 delete_breakpoint (b);
7840 /* See breakpoint.h. */
7843 remove_solib_event_breakpoints_at_next_stop (void)
7845 struct breakpoint *b, *b_tmp;
7847 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7848 if (b->type == bp_shlib_event
7849 && b->loc->pspace == current_program_space)
7850 b->disposition = disp_del_at_next_stop;
7853 /* Helper for create_solib_event_breakpoint /
7854 create_and_insert_solib_event_breakpoint. Allows specifying which
7855 INSERT_MODE to pass through to update_global_location_list. */
7857 static struct breakpoint *
7858 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7859 enum ugll_insert_mode insert_mode)
7861 struct breakpoint *b;
7863 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7864 &internal_breakpoint_ops);
7865 update_global_location_list_nothrow (insert_mode);
7870 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7872 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7875 /* See breakpoint.h. */
7878 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7880 struct breakpoint *b;
7882 /* Explicitly tell update_global_location_list to insert
7884 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7885 if (!b->loc->inserted)
7887 delete_breakpoint (b);
7893 /* Disable any breakpoints that are on code in shared libraries. Only
7894 apply to enabled breakpoints, disabled ones can just stay disabled. */
7897 disable_breakpoints_in_shlibs (void)
7899 struct bp_location *loc, **locp_tmp;
7901 ALL_BP_LOCATIONS (loc, locp_tmp)
7903 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7904 struct breakpoint *b = loc->owner;
7906 /* We apply the check to all breakpoints, including disabled for
7907 those with loc->duplicate set. This is so that when breakpoint
7908 becomes enabled, or the duplicate is removed, gdb will try to
7909 insert all breakpoints. If we don't set shlib_disabled here,
7910 we'll try to insert those breakpoints and fail. */
7911 if (((b->type == bp_breakpoint)
7912 || (b->type == bp_jit_event)
7913 || (b->type == bp_hardware_breakpoint)
7914 || (is_tracepoint (b)))
7915 && loc->pspace == current_program_space
7916 && !loc->shlib_disabled
7917 && solib_name_from_address (loc->pspace, loc->address)
7920 loc->shlib_disabled = 1;
7925 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7926 notification of unloaded_shlib. Only apply to enabled breakpoints,
7927 disabled ones can just stay disabled. */
7930 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7932 struct bp_location *loc, **locp_tmp;
7933 int disabled_shlib_breaks = 0;
7935 /* SunOS a.out shared libraries are always mapped, so do not
7936 disable breakpoints; they will only be reported as unloaded
7937 through clear_solib when GDB discards its shared library
7938 list. See clear_solib for more information. */
7939 if (exec_bfd != NULL
7940 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7943 ALL_BP_LOCATIONS (loc, locp_tmp)
7945 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7946 struct breakpoint *b = loc->owner;
7948 if (solib->pspace == loc->pspace
7949 && !loc->shlib_disabled
7950 && (((b->type == bp_breakpoint
7951 || b->type == bp_jit_event
7952 || b->type == bp_hardware_breakpoint)
7953 && (loc->loc_type == bp_loc_hardware_breakpoint
7954 || loc->loc_type == bp_loc_software_breakpoint))
7955 || is_tracepoint (b))
7956 && solib_contains_address_p (solib, loc->address))
7958 loc->shlib_disabled = 1;
7959 /* At this point, we cannot rely on remove_breakpoint
7960 succeeding so we must mark the breakpoint as not inserted
7961 to prevent future errors occurring in remove_breakpoints. */
7964 /* This may cause duplicate notifications for the same breakpoint. */
7965 observer_notify_breakpoint_modified (b);
7967 if (!disabled_shlib_breaks)
7969 target_terminal_ours_for_output ();
7970 warning (_("Temporarily disabling breakpoints "
7971 "for unloaded shared library \"%s\""),
7974 disabled_shlib_breaks = 1;
7979 /* Disable any breakpoints and tracepoints in OBJFILE upon
7980 notification of free_objfile. Only apply to enabled breakpoints,
7981 disabled ones can just stay disabled. */
7984 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7986 struct breakpoint *b;
7988 if (objfile == NULL)
7991 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7992 managed by the user with add-symbol-file/remove-symbol-file.
7993 Similarly to how breakpoints in shared libraries are handled in
7994 response to "nosharedlibrary", mark breakpoints in such modules
7995 shlib_disabled so they end up uninserted on the next global
7996 location list update. Shared libraries not loaded by the user
7997 aren't handled here -- they're already handled in
7998 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7999 solib_unloaded observer. We skip objfiles that are not
8000 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8002 if ((objfile->flags & OBJF_SHARED) == 0
8003 || (objfile->flags & OBJF_USERLOADED) == 0)
8008 struct bp_location *loc;
8009 int bp_modified = 0;
8011 if (!is_breakpoint (b) && !is_tracepoint (b))
8014 for (loc = b->loc; loc != NULL; loc = loc->next)
8016 CORE_ADDR loc_addr = loc->address;
8018 if (loc->loc_type != bp_loc_hardware_breakpoint
8019 && loc->loc_type != bp_loc_software_breakpoint)
8022 if (loc->shlib_disabled != 0)
8025 if (objfile->pspace != loc->pspace)
8028 if (loc->loc_type != bp_loc_hardware_breakpoint
8029 && loc->loc_type != bp_loc_software_breakpoint)
8032 if (is_addr_in_objfile (loc_addr, objfile))
8034 loc->shlib_disabled = 1;
8035 /* At this point, we don't know whether the object was
8036 unmapped from the inferior or not, so leave the
8037 inserted flag alone. We'll handle failure to
8038 uninsert quietly, in case the object was indeed
8041 mark_breakpoint_location_modified (loc);
8048 observer_notify_breakpoint_modified (b);
8052 /* FORK & VFORK catchpoints. */
8054 /* An instance of this type is used to represent a fork or vfork
8055 catchpoint. It includes a "struct breakpoint" as a kind of base
8056 class; users downcast to "struct breakpoint *" when needed. A
8057 breakpoint is really of this type iff its ops pointer points to
8058 CATCH_FORK_BREAKPOINT_OPS. */
8060 struct fork_catchpoint
8062 /* The base class. */
8063 struct breakpoint base;
8065 /* Process id of a child process whose forking triggered this
8066 catchpoint. This field is only valid immediately after this
8067 catchpoint has triggered. */
8068 ptid_t forked_inferior_pid;
8071 /* Implement the "insert" breakpoint_ops method for fork
8075 insert_catch_fork (struct bp_location *bl)
8077 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
8080 /* Implement the "remove" breakpoint_ops method for fork
8084 remove_catch_fork (struct bp_location *bl)
8086 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
8089 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8093 breakpoint_hit_catch_fork (const struct bp_location *bl,
8094 struct address_space *aspace, CORE_ADDR bp_addr,
8095 const struct target_waitstatus *ws)
8097 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8099 if (ws->kind != TARGET_WAITKIND_FORKED)
8102 c->forked_inferior_pid = ws->value.related_pid;
8106 /* Implement the "print_it" breakpoint_ops method for fork
8109 static enum print_stop_action
8110 print_it_catch_fork (bpstat bs)
8112 struct ui_out *uiout = current_uiout;
8113 struct breakpoint *b = bs->breakpoint_at;
8114 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
8116 annotate_catchpoint (b->number);
8117 maybe_print_thread_hit_breakpoint (uiout);
8118 if (b->disposition == disp_del)
8119 ui_out_text (uiout, "Temporary catchpoint ");
8121 ui_out_text (uiout, "Catchpoint ");
8122 if (ui_out_is_mi_like_p (uiout))
8124 ui_out_field_string (uiout, "reason",
8125 async_reason_lookup (EXEC_ASYNC_FORK));
8126 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8128 ui_out_field_int (uiout, "bkptno", b->number);
8129 ui_out_text (uiout, " (forked process ");
8130 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8131 ui_out_text (uiout, "), ");
8132 return PRINT_SRC_AND_LOC;
8135 /* Implement the "print_one" breakpoint_ops method for fork
8139 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8141 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8142 struct value_print_options opts;
8143 struct ui_out *uiout = current_uiout;
8145 get_user_print_options (&opts);
8147 /* Field 4, the address, is omitted (which makes the columns not
8148 line up too nicely with the headers, but the effect is relatively
8150 if (opts.addressprint)
8151 ui_out_field_skip (uiout, "addr");
8153 ui_out_text (uiout, "fork");
8154 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8156 ui_out_text (uiout, ", process ");
8157 ui_out_field_int (uiout, "what",
8158 ptid_get_pid (c->forked_inferior_pid));
8159 ui_out_spaces (uiout, 1);
8162 if (ui_out_is_mi_like_p (uiout))
8163 ui_out_field_string (uiout, "catch-type", "fork");
8166 /* Implement the "print_mention" breakpoint_ops method for fork
8170 print_mention_catch_fork (struct breakpoint *b)
8172 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8175 /* Implement the "print_recreate" breakpoint_ops method for fork
8179 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8181 fprintf_unfiltered (fp, "catch fork");
8182 print_recreate_thread (b, fp);
8185 /* The breakpoint_ops structure to be used in fork catchpoints. */
8187 static struct breakpoint_ops catch_fork_breakpoint_ops;
8189 /* Implement the "insert" breakpoint_ops method for vfork
8193 insert_catch_vfork (struct bp_location *bl)
8195 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8198 /* Implement the "remove" breakpoint_ops method for vfork
8202 remove_catch_vfork (struct bp_location *bl)
8204 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8207 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8211 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8212 struct address_space *aspace, CORE_ADDR bp_addr,
8213 const struct target_waitstatus *ws)
8215 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8217 if (ws->kind != TARGET_WAITKIND_VFORKED)
8220 c->forked_inferior_pid = ws->value.related_pid;
8224 /* Implement the "print_it" breakpoint_ops method for vfork
8227 static enum print_stop_action
8228 print_it_catch_vfork (bpstat bs)
8230 struct ui_out *uiout = current_uiout;
8231 struct breakpoint *b = bs->breakpoint_at;
8232 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8234 annotate_catchpoint (b->number);
8235 maybe_print_thread_hit_breakpoint (uiout);
8236 if (b->disposition == disp_del)
8237 ui_out_text (uiout, "Temporary catchpoint ");
8239 ui_out_text (uiout, "Catchpoint ");
8240 if (ui_out_is_mi_like_p (uiout))
8242 ui_out_field_string (uiout, "reason",
8243 async_reason_lookup (EXEC_ASYNC_VFORK));
8244 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8246 ui_out_field_int (uiout, "bkptno", b->number);
8247 ui_out_text (uiout, " (vforked process ");
8248 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8249 ui_out_text (uiout, "), ");
8250 return PRINT_SRC_AND_LOC;
8253 /* Implement the "print_one" breakpoint_ops method for vfork
8257 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8259 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8260 struct value_print_options opts;
8261 struct ui_out *uiout = current_uiout;
8263 get_user_print_options (&opts);
8264 /* Field 4, the address, is omitted (which makes the columns not
8265 line up too nicely with the headers, but the effect is relatively
8267 if (opts.addressprint)
8268 ui_out_field_skip (uiout, "addr");
8270 ui_out_text (uiout, "vfork");
8271 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8273 ui_out_text (uiout, ", process ");
8274 ui_out_field_int (uiout, "what",
8275 ptid_get_pid (c->forked_inferior_pid));
8276 ui_out_spaces (uiout, 1);
8279 if (ui_out_is_mi_like_p (uiout))
8280 ui_out_field_string (uiout, "catch-type", "vfork");
8283 /* Implement the "print_mention" breakpoint_ops method for vfork
8287 print_mention_catch_vfork (struct breakpoint *b)
8289 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8292 /* Implement the "print_recreate" breakpoint_ops method for vfork
8296 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8298 fprintf_unfiltered (fp, "catch vfork");
8299 print_recreate_thread (b, fp);
8302 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8304 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8306 /* An instance of this type is used to represent an solib catchpoint.
8307 It includes a "struct breakpoint" as a kind of base class; users
8308 downcast to "struct breakpoint *" when needed. A breakpoint is
8309 really of this type iff its ops pointer points to
8310 CATCH_SOLIB_BREAKPOINT_OPS. */
8312 struct solib_catchpoint
8314 /* The base class. */
8315 struct breakpoint base;
8317 /* True for "catch load", false for "catch unload". */
8318 unsigned char is_load;
8320 /* Regular expression to match, if any. COMPILED is only valid when
8321 REGEX is non-NULL. */
8327 dtor_catch_solib (struct breakpoint *b)
8329 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8332 regfree (&self->compiled);
8333 xfree (self->regex);
8335 base_breakpoint_ops.dtor (b);
8339 insert_catch_solib (struct bp_location *ignore)
8345 remove_catch_solib (struct bp_location *ignore)
8351 breakpoint_hit_catch_solib (const struct bp_location *bl,
8352 struct address_space *aspace,
8354 const struct target_waitstatus *ws)
8356 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8357 struct breakpoint *other;
8359 if (ws->kind == TARGET_WAITKIND_LOADED)
8362 ALL_BREAKPOINTS (other)
8364 struct bp_location *other_bl;
8366 if (other == bl->owner)
8369 if (other->type != bp_shlib_event)
8372 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8375 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8377 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8386 check_status_catch_solib (struct bpstats *bs)
8388 struct solib_catchpoint *self
8389 = (struct solib_catchpoint *) bs->breakpoint_at;
8394 struct so_list *iter;
8397 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8402 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8411 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8416 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8422 bs->print_it = print_it_noop;
8425 static enum print_stop_action
8426 print_it_catch_solib (bpstat bs)
8428 struct breakpoint *b = bs->breakpoint_at;
8429 struct ui_out *uiout = current_uiout;
8431 annotate_catchpoint (b->number);
8432 maybe_print_thread_hit_breakpoint (uiout);
8433 if (b->disposition == disp_del)
8434 ui_out_text (uiout, "Temporary catchpoint ");
8436 ui_out_text (uiout, "Catchpoint ");
8437 ui_out_field_int (uiout, "bkptno", b->number);
8438 ui_out_text (uiout, "\n");
8439 if (ui_out_is_mi_like_p (uiout))
8440 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8441 print_solib_event (1);
8442 return PRINT_SRC_AND_LOC;
8446 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8448 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8449 struct value_print_options opts;
8450 struct ui_out *uiout = current_uiout;
8453 get_user_print_options (&opts);
8454 /* Field 4, the address, is omitted (which makes the columns not
8455 line up too nicely with the headers, but the effect is relatively
8457 if (opts.addressprint)
8460 ui_out_field_skip (uiout, "addr");
8467 msg = xstrprintf (_("load of library matching %s"), self->regex);
8469 msg = xstrdup (_("load of library"));
8474 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8476 msg = xstrdup (_("unload of library"));
8478 ui_out_field_string (uiout, "what", msg);
8481 if (ui_out_is_mi_like_p (uiout))
8482 ui_out_field_string (uiout, "catch-type",
8483 self->is_load ? "load" : "unload");
8487 print_mention_catch_solib (struct breakpoint *b)
8489 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8491 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8492 self->is_load ? "load" : "unload");
8496 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8498 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8500 fprintf_unfiltered (fp, "%s %s",
8501 b->disposition == disp_del ? "tcatch" : "catch",
8502 self->is_load ? "load" : "unload");
8504 fprintf_unfiltered (fp, " %s", self->regex);
8505 fprintf_unfiltered (fp, "\n");
8508 static struct breakpoint_ops catch_solib_breakpoint_ops;
8510 /* Shared helper function (MI and CLI) for creating and installing
8511 a shared object event catchpoint. If IS_LOAD is non-zero then
8512 the events to be caught are load events, otherwise they are
8513 unload events. If IS_TEMP is non-zero the catchpoint is a
8514 temporary one. If ENABLED is non-zero the catchpoint is
8515 created in an enabled state. */
8518 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8520 struct solib_catchpoint *c;
8521 struct gdbarch *gdbarch = get_current_arch ();
8522 struct cleanup *cleanup;
8526 arg = skip_spaces (arg);
8528 c = XCNEW (struct solib_catchpoint);
8529 cleanup = make_cleanup (xfree, c);
8535 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8538 char *err = get_regcomp_error (errcode, &c->compiled);
8540 make_cleanup (xfree, err);
8541 error (_("Invalid regexp (%s): %s"), err, arg);
8543 c->regex = xstrdup (arg);
8546 c->is_load = is_load;
8547 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8548 &catch_solib_breakpoint_ops);
8550 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8552 discard_cleanups (cleanup);
8553 install_breakpoint (0, &c->base, 1);
8556 /* A helper function that does all the work for "catch load" and
8560 catch_load_or_unload (char *arg, int from_tty, int is_load,
8561 struct cmd_list_element *command)
8564 const int enabled = 1;
8566 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8568 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8572 catch_load_command_1 (char *arg, int from_tty,
8573 struct cmd_list_element *command)
8575 catch_load_or_unload (arg, from_tty, 1, command);
8579 catch_unload_command_1 (char *arg, int from_tty,
8580 struct cmd_list_element *command)
8582 catch_load_or_unload (arg, from_tty, 0, command);
8585 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8586 is non-zero, then make the breakpoint temporary. If COND_STRING is
8587 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8588 the breakpoint_ops structure associated to the catchpoint. */
8591 init_catchpoint (struct breakpoint *b,
8592 struct gdbarch *gdbarch, int tempflag,
8594 const struct breakpoint_ops *ops)
8596 struct symtab_and_line sal;
8599 sal.pspace = current_program_space;
8601 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8603 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8604 b->disposition = tempflag ? disp_del : disp_donttouch;
8608 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8610 add_to_breakpoint_chain (b);
8611 set_breakpoint_number (internal, b);
8612 if (is_tracepoint (b))
8613 set_tracepoint_count (breakpoint_count);
8616 observer_notify_breakpoint_created (b);
8619 update_global_location_list (UGLL_MAY_INSERT);
8623 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8624 int tempflag, char *cond_string,
8625 const struct breakpoint_ops *ops)
8627 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8629 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8631 c->forked_inferior_pid = null_ptid;
8633 install_breakpoint (0, &c->base, 1);
8636 /* Exec catchpoints. */
8638 /* An instance of this type is used to represent an exec catchpoint.
8639 It includes a "struct breakpoint" as a kind of base class; users
8640 downcast to "struct breakpoint *" when needed. A breakpoint is
8641 really of this type iff its ops pointer points to
8642 CATCH_EXEC_BREAKPOINT_OPS. */
8644 struct exec_catchpoint
8646 /* The base class. */
8647 struct breakpoint base;
8649 /* Filename of a program whose exec triggered this catchpoint.
8650 This field is only valid immediately after this catchpoint has
8652 char *exec_pathname;
8655 /* Implement the "dtor" breakpoint_ops method for exec
8659 dtor_catch_exec (struct breakpoint *b)
8661 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8663 xfree (c->exec_pathname);
8665 base_breakpoint_ops.dtor (b);
8669 insert_catch_exec (struct bp_location *bl)
8671 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8675 remove_catch_exec (struct bp_location *bl)
8677 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8681 breakpoint_hit_catch_exec (const struct bp_location *bl,
8682 struct address_space *aspace, CORE_ADDR bp_addr,
8683 const struct target_waitstatus *ws)
8685 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8687 if (ws->kind != TARGET_WAITKIND_EXECD)
8690 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8694 static enum print_stop_action
8695 print_it_catch_exec (bpstat bs)
8697 struct ui_out *uiout = current_uiout;
8698 struct breakpoint *b = bs->breakpoint_at;
8699 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8701 annotate_catchpoint (b->number);
8702 maybe_print_thread_hit_breakpoint (uiout);
8703 if (b->disposition == disp_del)
8704 ui_out_text (uiout, "Temporary catchpoint ");
8706 ui_out_text (uiout, "Catchpoint ");
8707 if (ui_out_is_mi_like_p (uiout))
8709 ui_out_field_string (uiout, "reason",
8710 async_reason_lookup (EXEC_ASYNC_EXEC));
8711 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8713 ui_out_field_int (uiout, "bkptno", b->number);
8714 ui_out_text (uiout, " (exec'd ");
8715 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8716 ui_out_text (uiout, "), ");
8718 return PRINT_SRC_AND_LOC;
8722 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8724 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8725 struct value_print_options opts;
8726 struct ui_out *uiout = current_uiout;
8728 get_user_print_options (&opts);
8730 /* Field 4, the address, is omitted (which makes the columns
8731 not line up too nicely with the headers, but the effect
8732 is relatively readable). */
8733 if (opts.addressprint)
8734 ui_out_field_skip (uiout, "addr");
8736 ui_out_text (uiout, "exec");
8737 if (c->exec_pathname != NULL)
8739 ui_out_text (uiout, ", program \"");
8740 ui_out_field_string (uiout, "what", c->exec_pathname);
8741 ui_out_text (uiout, "\" ");
8744 if (ui_out_is_mi_like_p (uiout))
8745 ui_out_field_string (uiout, "catch-type", "exec");
8749 print_mention_catch_exec (struct breakpoint *b)
8751 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8754 /* Implement the "print_recreate" breakpoint_ops method for exec
8758 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8760 fprintf_unfiltered (fp, "catch exec");
8761 print_recreate_thread (b, fp);
8764 static struct breakpoint_ops catch_exec_breakpoint_ops;
8767 hw_breakpoint_used_count (void)
8770 struct breakpoint *b;
8771 struct bp_location *bl;
8775 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8776 for (bl = b->loc; bl; bl = bl->next)
8778 /* Special types of hardware breakpoints may use more than
8780 i += b->ops->resources_needed (bl);
8787 /* Returns the resources B would use if it were a hardware
8791 hw_watchpoint_use_count (struct breakpoint *b)
8794 struct bp_location *bl;
8796 if (!breakpoint_enabled (b))
8799 for (bl = b->loc; bl; bl = bl->next)
8801 /* Special types of hardware watchpoints may use more than
8803 i += b->ops->resources_needed (bl);
8809 /* Returns the sum the used resources of all hardware watchpoints of
8810 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8811 the sum of the used resources of all hardware watchpoints of other
8812 types _not_ TYPE. */
8815 hw_watchpoint_used_count_others (struct breakpoint *except,
8816 enum bptype type, int *other_type_used)
8819 struct breakpoint *b;
8821 *other_type_used = 0;
8826 if (!breakpoint_enabled (b))
8829 if (b->type == type)
8830 i += hw_watchpoint_use_count (b);
8831 else if (is_hardware_watchpoint (b))
8832 *other_type_used = 1;
8839 disable_watchpoints_before_interactive_call_start (void)
8841 struct breakpoint *b;
8845 if (is_watchpoint (b) && breakpoint_enabled (b))
8847 b->enable_state = bp_call_disabled;
8848 update_global_location_list (UGLL_DONT_INSERT);
8854 enable_watchpoints_after_interactive_call_stop (void)
8856 struct breakpoint *b;
8860 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8862 b->enable_state = bp_enabled;
8863 update_global_location_list (UGLL_MAY_INSERT);
8869 disable_breakpoints_before_startup (void)
8871 current_program_space->executing_startup = 1;
8872 update_global_location_list (UGLL_DONT_INSERT);
8876 enable_breakpoints_after_startup (void)
8878 current_program_space->executing_startup = 0;
8879 breakpoint_re_set ();
8882 /* Create a new single-step breakpoint for thread THREAD, with no
8885 static struct breakpoint *
8886 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8888 struct breakpoint *b = XNEW (struct breakpoint);
8890 init_raw_breakpoint_without_location (b, gdbarch, bp_single_step,
8891 &momentary_breakpoint_ops);
8893 b->disposition = disp_donttouch;
8894 b->frame_id = null_frame_id;
8897 gdb_assert (b->thread != 0);
8899 add_to_breakpoint_chain (b);
8904 /* Set a momentary breakpoint of type TYPE at address specified by
8905 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8909 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8910 struct frame_id frame_id, enum bptype type)
8912 struct breakpoint *b;
8914 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8916 gdb_assert (!frame_id_artificial_p (frame_id));
8918 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8919 b->enable_state = bp_enabled;
8920 b->disposition = disp_donttouch;
8921 b->frame_id = frame_id;
8923 /* If we're debugging a multi-threaded program, then we want
8924 momentary breakpoints to be active in only a single thread of
8926 if (in_thread_list (inferior_ptid))
8927 b->thread = ptid_to_global_thread_id (inferior_ptid);
8929 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8934 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8935 The new breakpoint will have type TYPE, use OPS as its
8936 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8938 static struct breakpoint *
8939 momentary_breakpoint_from_master (struct breakpoint *orig,
8941 const struct breakpoint_ops *ops,
8944 struct breakpoint *copy;
8946 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8947 copy->loc = allocate_bp_location (copy);
8948 set_breakpoint_location_function (copy->loc, 1);
8950 copy->loc->gdbarch = orig->loc->gdbarch;
8951 copy->loc->requested_address = orig->loc->requested_address;
8952 copy->loc->address = orig->loc->address;
8953 copy->loc->section = orig->loc->section;
8954 copy->loc->pspace = orig->loc->pspace;
8955 copy->loc->probe = orig->loc->probe;
8956 copy->loc->line_number = orig->loc->line_number;
8957 copy->loc->symtab = orig->loc->symtab;
8958 copy->loc->enabled = loc_enabled;
8959 copy->frame_id = orig->frame_id;
8960 copy->thread = orig->thread;
8961 copy->pspace = orig->pspace;
8963 copy->enable_state = bp_enabled;
8964 copy->disposition = disp_donttouch;
8965 copy->number = internal_breakpoint_number--;
8967 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8971 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8975 clone_momentary_breakpoint (struct breakpoint *orig)
8977 /* If there's nothing to clone, then return nothing. */
8981 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8985 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8988 struct symtab_and_line sal;
8990 sal = find_pc_line (pc, 0);
8992 sal.section = find_pc_overlay (pc);
8993 sal.explicit_pc = 1;
8995 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8999 /* Tell the user we have just set a breakpoint B. */
9002 mention (struct breakpoint *b)
9004 b->ops->print_mention (b);
9005 if (ui_out_is_mi_like_p (current_uiout))
9007 printf_filtered ("\n");
9011 static int bp_loc_is_permanent (struct bp_location *loc);
9013 static struct bp_location *
9014 add_location_to_breakpoint (struct breakpoint *b,
9015 const struct symtab_and_line *sal)
9017 struct bp_location *loc, **tmp;
9018 CORE_ADDR adjusted_address;
9019 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9021 if (loc_gdbarch == NULL)
9022 loc_gdbarch = b->gdbarch;
9024 /* Adjust the breakpoint's address prior to allocating a location.
9025 Once we call allocate_bp_location(), that mostly uninitialized
9026 location will be placed on the location chain. Adjustment of the
9027 breakpoint may cause target_read_memory() to be called and we do
9028 not want its scan of the location chain to find a breakpoint and
9029 location that's only been partially initialized. */
9030 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9033 /* Sort the locations by their ADDRESS. */
9034 loc = allocate_bp_location (b);
9035 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9036 tmp = &((*tmp)->next))
9041 loc->requested_address = sal->pc;
9042 loc->address = adjusted_address;
9043 loc->pspace = sal->pspace;
9044 loc->probe.probe = sal->probe;
9045 loc->probe.objfile = sal->objfile;
9046 gdb_assert (loc->pspace != NULL);
9047 loc->section = sal->section;
9048 loc->gdbarch = loc_gdbarch;
9049 loc->line_number = sal->line;
9050 loc->symtab = sal->symtab;
9052 set_breakpoint_location_function (loc,
9053 sal->explicit_pc || sal->explicit_line);
9055 /* While by definition, permanent breakpoints are already present in the
9056 code, we don't mark the location as inserted. Normally one would expect
9057 that GDB could rely on that breakpoint instruction to stop the program,
9058 thus removing the need to insert its own breakpoint, except that executing
9059 the breakpoint instruction can kill the target instead of reporting a
9060 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9061 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9062 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9063 breakpoint be inserted normally results in QEMU knowing about the GDB
9064 breakpoint, and thus trap before the breakpoint instruction is executed.
9065 (If GDB later needs to continue execution past the permanent breakpoint,
9066 it manually increments the PC, thus avoiding executing the breakpoint
9068 if (bp_loc_is_permanent (loc))
9075 /* See breakpoint.h. */
9078 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
9082 const gdb_byte *bpoint;
9083 gdb_byte *target_mem;
9084 struct cleanup *cleanup;
9088 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
9090 /* Software breakpoints unsupported? */
9094 target_mem = (gdb_byte *) alloca (len);
9096 /* Enable the automatic memory restoration from breakpoints while
9097 we read the memory. Otherwise we could say about our temporary
9098 breakpoints they are permanent. */
9099 cleanup = make_show_memory_breakpoints_cleanup (0);
9101 if (target_read_memory (address, target_mem, len) == 0
9102 && memcmp (target_mem, bpoint, len) == 0)
9105 do_cleanups (cleanup);
9110 /* Return 1 if LOC is pointing to a permanent breakpoint,
9111 return 0 otherwise. */
9114 bp_loc_is_permanent (struct bp_location *loc)
9116 struct cleanup *cleanup;
9119 gdb_assert (loc != NULL);
9121 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9122 attempt to read from the addresses the locations of these breakpoint types
9123 point to. program_breakpoint_here_p, below, will attempt to read
9125 if (!breakpoint_address_is_meaningful (loc->owner))
9128 cleanup = save_current_space_and_thread ();
9129 switch_to_program_space_and_thread (loc->pspace);
9131 retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
9133 do_cleanups (cleanup);
9138 /* Build a command list for the dprintf corresponding to the current
9139 settings of the dprintf style options. */
9142 update_dprintf_command_list (struct breakpoint *b)
9144 char *dprintf_args = b->extra_string;
9145 char *printf_line = NULL;
9150 dprintf_args = skip_spaces (dprintf_args);
9152 /* Allow a comma, as it may have terminated a location, but don't
9154 if (*dprintf_args == ',')
9156 dprintf_args = skip_spaces (dprintf_args);
9158 if (*dprintf_args != '"')
9159 error (_("Bad format string, missing '\"'."));
9161 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9162 printf_line = xstrprintf ("printf %s", dprintf_args);
9163 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9165 if (!dprintf_function)
9166 error (_("No function supplied for dprintf call"));
9168 if (dprintf_channel && strlen (dprintf_channel) > 0)
9169 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9174 printf_line = xstrprintf ("call (void) %s (%s)",
9178 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9180 if (target_can_run_breakpoint_commands ())
9181 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9184 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9185 printf_line = xstrprintf ("printf %s", dprintf_args);
9189 internal_error (__FILE__, __LINE__,
9190 _("Invalid dprintf style."));
9192 gdb_assert (printf_line != NULL);
9193 /* Manufacture a printf sequence. */
9195 struct command_line *printf_cmd_line = XNEW (struct command_line);
9197 printf_cmd_line->control_type = simple_control;
9198 printf_cmd_line->body_count = 0;
9199 printf_cmd_line->body_list = NULL;
9200 printf_cmd_line->next = NULL;
9201 printf_cmd_line->line = printf_line;
9203 breakpoint_set_commands (b, printf_cmd_line);
9207 /* Update all dprintf commands, making their command lists reflect
9208 current style settings. */
9211 update_dprintf_commands (char *args, int from_tty,
9212 struct cmd_list_element *c)
9214 struct breakpoint *b;
9218 if (b->type == bp_dprintf)
9219 update_dprintf_command_list (b);
9223 /* Create a breakpoint with SAL as location. Use LOCATION
9224 as a description of the location, and COND_STRING
9225 as condition expression. If LOCATION is NULL then create an
9226 "address location" from the address in the SAL. */
9229 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9230 struct symtabs_and_lines sals,
9231 struct event_location *location,
9232 char *filter, char *cond_string,
9234 enum bptype type, enum bpdisp disposition,
9235 int thread, int task, int ignore_count,
9236 const struct breakpoint_ops *ops, int from_tty,
9237 int enabled, int internal, unsigned flags,
9238 int display_canonical)
9242 if (type == bp_hardware_breakpoint)
9244 int target_resources_ok;
9246 i = hw_breakpoint_used_count ();
9247 target_resources_ok =
9248 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9250 if (target_resources_ok == 0)
9251 error (_("No hardware breakpoint support in the target."));
9252 else if (target_resources_ok < 0)
9253 error (_("Hardware breakpoints used exceeds limit."));
9256 gdb_assert (sals.nelts > 0);
9258 for (i = 0; i < sals.nelts; ++i)
9260 struct symtab_and_line sal = sals.sals[i];
9261 struct bp_location *loc;
9265 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9267 loc_gdbarch = gdbarch;
9269 describe_other_breakpoints (loc_gdbarch,
9270 sal.pspace, sal.pc, sal.section, thread);
9275 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9279 b->cond_string = cond_string;
9280 b->extra_string = extra_string;
9281 b->ignore_count = ignore_count;
9282 b->enable_state = enabled ? bp_enabled : bp_disabled;
9283 b->disposition = disposition;
9285 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9286 b->loc->inserted = 1;
9288 if (type == bp_static_tracepoint)
9290 struct tracepoint *t = (struct tracepoint *) b;
9291 struct static_tracepoint_marker marker;
9293 if (strace_marker_p (b))
9295 /* We already know the marker exists, otherwise, we
9296 wouldn't see a sal for it. */
9297 const char *p = &event_location_to_string (b->location)[3];
9301 p = skip_spaces_const (p);
9303 endp = skip_to_space_const (p);
9305 marker_str = savestring (p, endp - p);
9306 t->static_trace_marker_id = marker_str;
9308 printf_filtered (_("Probed static tracepoint "
9310 t->static_trace_marker_id);
9312 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9314 t->static_trace_marker_id = xstrdup (marker.str_id);
9315 release_static_tracepoint_marker (&marker);
9317 printf_filtered (_("Probed static tracepoint "
9319 t->static_trace_marker_id);
9322 warning (_("Couldn't determine the static "
9323 "tracepoint marker to probe"));
9330 loc = add_location_to_breakpoint (b, &sal);
9331 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9337 const char *arg = b->cond_string;
9339 loc->cond = parse_exp_1 (&arg, loc->address,
9340 block_for_pc (loc->address), 0);
9342 error (_("Garbage '%s' follows condition"), arg);
9345 /* Dynamic printf requires and uses additional arguments on the
9346 command line, otherwise it's an error. */
9347 if (type == bp_dprintf)
9349 if (b->extra_string)
9350 update_dprintf_command_list (b);
9352 error (_("Format string required"));
9354 else if (b->extra_string)
9355 error (_("Garbage '%s' at end of command"), b->extra_string);
9358 b->display_canonical = display_canonical;
9359 if (location != NULL)
9360 b->location = location;
9363 const char *addr_string = NULL;
9364 int addr_string_len = 0;
9366 if (location != NULL)
9367 addr_string = event_location_to_string (location);
9368 if (addr_string != NULL)
9369 addr_string_len = strlen (addr_string);
9371 b->location = new_address_location (b->loc->address,
9372 addr_string, addr_string_len);
9378 create_breakpoint_sal (struct gdbarch *gdbarch,
9379 struct symtabs_and_lines sals,
9380 struct event_location *location,
9381 char *filter, char *cond_string,
9383 enum bptype type, enum bpdisp disposition,
9384 int thread, int task, int ignore_count,
9385 const struct breakpoint_ops *ops, int from_tty,
9386 int enabled, int internal, unsigned flags,
9387 int display_canonical)
9389 struct breakpoint *b;
9390 struct cleanup *old_chain;
9392 if (is_tracepoint_type (type))
9394 struct tracepoint *t;
9396 t = XCNEW (struct tracepoint);
9400 b = XNEW (struct breakpoint);
9402 old_chain = make_cleanup (xfree, b);
9404 init_breakpoint_sal (b, gdbarch,
9406 filter, cond_string, extra_string,
9408 thread, task, ignore_count,
9410 enabled, internal, flags,
9412 discard_cleanups (old_chain);
9414 install_breakpoint (internal, b, 0);
9417 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9418 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9419 value. COND_STRING, if not NULL, specified the condition to be
9420 used for all breakpoints. Essentially the only case where
9421 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9422 function. In that case, it's still not possible to specify
9423 separate conditions for different overloaded functions, so
9424 we take just a single condition string.
9426 NOTE: If the function succeeds, the caller is expected to cleanup
9427 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9428 array contents). If the function fails (error() is called), the
9429 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9430 COND and SALS arrays and each of those arrays contents. */
9433 create_breakpoints_sal (struct gdbarch *gdbarch,
9434 struct linespec_result *canonical,
9435 char *cond_string, char *extra_string,
9436 enum bptype type, enum bpdisp disposition,
9437 int thread, int task, int ignore_count,
9438 const struct breakpoint_ops *ops, int from_tty,
9439 int enabled, int internal, unsigned flags)
9442 struct linespec_sals *lsal;
9444 if (canonical->pre_expanded)
9445 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9447 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9449 /* Note that 'location' can be NULL in the case of a plain
9450 'break', without arguments. */
9451 struct event_location *location
9452 = (canonical->location != NULL
9453 ? copy_event_location (canonical->location) : NULL);
9454 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9455 struct cleanup *inner = make_cleanup_delete_event_location (location);
9457 make_cleanup (xfree, filter_string);
9458 create_breakpoint_sal (gdbarch, lsal->sals,
9461 cond_string, extra_string,
9463 thread, task, ignore_count, ops,
9464 from_tty, enabled, internal, flags,
9465 canonical->special_display);
9466 discard_cleanups (inner);
9470 /* Parse LOCATION which is assumed to be a SAL specification possibly
9471 followed by conditionals. On return, SALS contains an array of SAL
9472 addresses found. LOCATION points to the end of the SAL (for
9473 linespec locations).
9475 The array and the line spec strings are allocated on the heap, it is
9476 the caller's responsibility to free them. */
9479 parse_breakpoint_sals (const struct event_location *location,
9480 struct linespec_result *canonical)
9482 struct symtab_and_line cursal;
9484 if (event_location_type (location) == LINESPEC_LOCATION)
9486 const char *address = get_linespec_location (location);
9488 if (address == NULL)
9490 /* The last displayed codepoint, if it's valid, is our default
9491 breakpoint address. */
9492 if (last_displayed_sal_is_valid ())
9494 struct linespec_sals lsal;
9495 struct symtab_and_line sal;
9498 init_sal (&sal); /* Initialize to zeroes. */
9499 lsal.sals.sals = XNEW (struct symtab_and_line);
9501 /* Set sal's pspace, pc, symtab, and line to the values
9502 corresponding to the last call to print_frame_info.
9503 Be sure to reinitialize LINE with NOTCURRENT == 0
9504 as the breakpoint line number is inappropriate otherwise.
9505 find_pc_line would adjust PC, re-set it back. */
9506 get_last_displayed_sal (&sal);
9508 sal = find_pc_line (pc, 0);
9510 /* "break" without arguments is equivalent to "break *PC"
9511 where PC is the last displayed codepoint's address. So
9512 make sure to set sal.explicit_pc to prevent GDB from
9513 trying to expand the list of sals to include all other
9514 instances with the same symtab and line. */
9516 sal.explicit_pc = 1;
9518 lsal.sals.sals[0] = sal;
9519 lsal.sals.nelts = 1;
9520 lsal.canonical = NULL;
9522 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9526 error (_("No default breakpoint address now."));
9530 /* Force almost all breakpoints to be in terms of the
9531 current_source_symtab (which is decode_line_1's default).
9532 This should produce the results we want almost all of the
9533 time while leaving default_breakpoint_* alone.
9535 ObjC: However, don't match an Objective-C method name which
9536 may have a '+' or '-' succeeded by a '['. */
9537 cursal = get_current_source_symtab_and_line ();
9538 if (last_displayed_sal_is_valid ())
9540 const char *address = NULL;
9542 if (event_location_type (location) == LINESPEC_LOCATION)
9543 address = get_linespec_location (location);
9547 && strchr ("+-", address[0]) != NULL
9548 && address[1] != '['))
9550 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9551 get_last_displayed_symtab (),
9552 get_last_displayed_line (),
9553 canonical, NULL, NULL);
9558 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9559 cursal.symtab, cursal.line, canonical, NULL, NULL);
9563 /* Convert each SAL into a real PC. Verify that the PC can be
9564 inserted as a breakpoint. If it can't throw an error. */
9567 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9571 for (i = 0; i < sals->nelts; i++)
9572 resolve_sal_pc (&sals->sals[i]);
9575 /* Fast tracepoints may have restrictions on valid locations. For
9576 instance, a fast tracepoint using a jump instead of a trap will
9577 likely have to overwrite more bytes than a trap would, and so can
9578 only be placed where the instruction is longer than the jump, or a
9579 multi-instruction sequence does not have a jump into the middle of
9583 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9584 struct symtabs_and_lines *sals)
9587 struct symtab_and_line *sal;
9589 struct cleanup *old_chain;
9591 for (i = 0; i < sals->nelts; i++)
9593 struct gdbarch *sarch;
9595 sal = &sals->sals[i];
9597 sarch = get_sal_arch (*sal);
9598 /* We fall back to GDBARCH if there is no architecture
9599 associated with SAL. */
9602 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg);
9603 old_chain = make_cleanup (xfree, msg);
9606 error (_("May not have a fast tracepoint at 0x%s%s"),
9607 paddress (sarch, sal->pc), (msg ? msg : ""));
9609 do_cleanups (old_chain);
9613 /* Given TOK, a string specification of condition and thread, as
9614 accepted by the 'break' command, extract the condition
9615 string and thread number and set *COND_STRING and *THREAD.
9616 PC identifies the context at which the condition should be parsed.
9617 If no condition is found, *COND_STRING is set to NULL.
9618 If no thread is found, *THREAD is set to -1. */
9621 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9622 char **cond_string, int *thread, int *task,
9625 *cond_string = NULL;
9632 const char *end_tok;
9634 const char *cond_start = NULL;
9635 const char *cond_end = NULL;
9637 tok = skip_spaces_const (tok);
9639 if ((*tok == '"' || *tok == ',') && rest)
9641 *rest = savestring (tok, strlen (tok));
9645 end_tok = skip_to_space_const (tok);
9647 toklen = end_tok - tok;
9649 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9651 struct expression *expr;
9653 tok = cond_start = end_tok + 1;
9654 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9657 *cond_string = savestring (cond_start, cond_end - cond_start);
9659 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9662 struct thread_info *thr;
9665 thr = parse_thread_id (tok, &tmptok);
9667 error (_("Junk after thread keyword."));
9668 *thread = thr->global_num;
9671 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9676 *task = strtol (tok, &tmptok, 0);
9678 error (_("Junk after task keyword."));
9679 if (!valid_task_id (*task))
9680 error (_("Unknown task %d."), *task);
9685 *rest = savestring (tok, strlen (tok));
9689 error (_("Junk at end of arguments."));
9693 /* Decode a static tracepoint marker spec. */
9695 static struct symtabs_and_lines
9696 decode_static_tracepoint_spec (const char **arg_p)
9698 VEC(static_tracepoint_marker_p) *markers = NULL;
9699 struct symtabs_and_lines sals;
9700 struct cleanup *old_chain;
9701 const char *p = &(*arg_p)[3];
9706 p = skip_spaces_const (p);
9708 endp = skip_to_space_const (p);
9710 marker_str = savestring (p, endp - p);
9711 old_chain = make_cleanup (xfree, marker_str);
9713 markers = target_static_tracepoint_markers_by_strid (marker_str);
9714 if (VEC_empty(static_tracepoint_marker_p, markers))
9715 error (_("No known static tracepoint marker named %s"), marker_str);
9717 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9718 sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
9720 for (i = 0; i < sals.nelts; i++)
9722 struct static_tracepoint_marker *marker;
9724 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9726 init_sal (&sals.sals[i]);
9728 sals.sals[i] = find_pc_line (marker->address, 0);
9729 sals.sals[i].pc = marker->address;
9731 release_static_tracepoint_marker (marker);
9734 do_cleanups (old_chain);
9740 /* See breakpoint.h. */
9743 create_breakpoint (struct gdbarch *gdbarch,
9744 const struct event_location *location, char *cond_string,
9745 int thread, char *extra_string,
9747 int tempflag, enum bptype type_wanted,
9749 enum auto_boolean pending_break_support,
9750 const struct breakpoint_ops *ops,
9751 int from_tty, int enabled, int internal,
9754 struct linespec_result canonical;
9755 struct cleanup *old_chain;
9756 struct cleanup *bkpt_chain = NULL;
9759 int prev_bkpt_count = breakpoint_count;
9761 gdb_assert (ops != NULL);
9763 /* If extra_string isn't useful, set it to NULL. */
9764 if (extra_string != NULL && *extra_string == '\0')
9765 extra_string = NULL;
9767 init_linespec_result (&canonical);
9771 ops->create_sals_from_location (location, &canonical, type_wanted);
9773 CATCH (e, RETURN_MASK_ERROR)
9775 /* If caller is interested in rc value from parse, set
9777 if (e.error == NOT_FOUND_ERROR)
9779 /* If pending breakpoint support is turned off, throw
9782 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9783 throw_exception (e);
9785 exception_print (gdb_stderr, e);
9787 /* If pending breakpoint support is auto query and the user
9788 selects no, then simply return the error code. */
9789 if (pending_break_support == AUTO_BOOLEAN_AUTO
9790 && !nquery (_("Make %s pending on future shared library load? "),
9791 bptype_string (type_wanted)))
9794 /* At this point, either the user was queried about setting
9795 a pending breakpoint and selected yes, or pending
9796 breakpoint behavior is on and thus a pending breakpoint
9797 is defaulted on behalf of the user. */
9801 throw_exception (e);
9805 if (!pending && VEC_empty (linespec_sals, canonical.sals))
9808 /* Create a chain of things that always need to be cleaned up. */
9809 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9811 /* ----------------------------- SNIP -----------------------------
9812 Anything added to the cleanup chain beyond this point is assumed
9813 to be part of a breakpoint. If the breakpoint create succeeds
9814 then the memory is not reclaimed. */
9815 bkpt_chain = make_cleanup (null_cleanup, 0);
9817 /* Resolve all line numbers to PC's and verify that the addresses
9818 are ok for the target. */
9822 struct linespec_sals *iter;
9824 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9825 breakpoint_sals_to_pc (&iter->sals);
9828 /* Fast tracepoints may have additional restrictions on location. */
9829 if (!pending && type_wanted == bp_fast_tracepoint)
9832 struct linespec_sals *iter;
9834 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9835 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9838 /* Verify that condition can be parsed, before setting any
9839 breakpoints. Allocate a separate condition expression for each
9846 struct linespec_sals *lsal;
9848 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9850 /* Here we only parse 'arg' to separate condition
9851 from thread number, so parsing in context of first
9852 sal is OK. When setting the breakpoint we'll
9853 re-parse it in context of each sal. */
9855 find_condition_and_thread (extra_string, lsal->sals.sals[0].pc,
9856 &cond_string, &thread, &task, &rest);
9858 make_cleanup (xfree, cond_string);
9860 make_cleanup (xfree, rest);
9862 extra_string = rest;
9864 extra_string = NULL;
9868 if (type_wanted != bp_dprintf
9869 && extra_string != NULL && *extra_string != '\0')
9870 error (_("Garbage '%s' at end of location"), extra_string);
9872 /* Create a private copy of condition string. */
9875 cond_string = xstrdup (cond_string);
9876 make_cleanup (xfree, cond_string);
9878 /* Create a private copy of any extra string. */
9881 extra_string = xstrdup (extra_string);
9882 make_cleanup (xfree, extra_string);
9886 ops->create_breakpoints_sal (gdbarch, &canonical,
9887 cond_string, extra_string, type_wanted,
9888 tempflag ? disp_del : disp_donttouch,
9889 thread, task, ignore_count, ops,
9890 from_tty, enabled, internal, flags);
9894 struct breakpoint *b;
9896 if (is_tracepoint_type (type_wanted))
9898 struct tracepoint *t;
9900 t = XCNEW (struct tracepoint);
9904 b = XNEW (struct breakpoint);
9906 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9907 b->location = copy_event_location (location);
9910 b->cond_string = NULL;
9913 /* Create a private copy of condition string. */
9916 cond_string = xstrdup (cond_string);
9917 make_cleanup (xfree, cond_string);
9919 b->cond_string = cond_string;
9923 /* Create a private copy of any extra string. */
9924 if (extra_string != NULL)
9926 extra_string = xstrdup (extra_string);
9927 make_cleanup (xfree, extra_string);
9929 b->extra_string = extra_string;
9930 b->ignore_count = ignore_count;
9931 b->disposition = tempflag ? disp_del : disp_donttouch;
9932 b->condition_not_parsed = 1;
9933 b->enable_state = enabled ? bp_enabled : bp_disabled;
9934 if ((type_wanted != bp_breakpoint
9935 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9936 b->pspace = current_program_space;
9938 install_breakpoint (internal, b, 0);
9941 if (VEC_length (linespec_sals, canonical.sals) > 1)
9943 warning (_("Multiple breakpoints were set.\nUse the "
9944 "\"delete\" command to delete unwanted breakpoints."));
9945 prev_breakpoint_count = prev_bkpt_count;
9948 /* That's it. Discard the cleanups for data inserted into the
9950 discard_cleanups (bkpt_chain);
9951 /* But cleanup everything else. */
9952 do_cleanups (old_chain);
9954 /* error call may happen here - have BKPT_CHAIN already discarded. */
9955 update_global_location_list (UGLL_MAY_INSERT);
9960 /* Set a breakpoint.
9961 ARG is a string describing breakpoint address,
9962 condition, and thread.
9963 FLAG specifies if a breakpoint is hardware on,
9964 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9968 break_command_1 (char *arg, int flag, int from_tty)
9970 int tempflag = flag & BP_TEMPFLAG;
9971 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9972 ? bp_hardware_breakpoint
9974 struct breakpoint_ops *ops;
9975 struct event_location *location;
9976 struct cleanup *cleanup;
9978 location = string_to_event_location (&arg, current_language);
9979 cleanup = make_cleanup_delete_event_location (location);
9981 /* Matching breakpoints on probes. */
9982 if (location != NULL
9983 && event_location_type (location) == PROBE_LOCATION)
9984 ops = &bkpt_probe_breakpoint_ops;
9986 ops = &bkpt_breakpoint_ops;
9988 create_breakpoint (get_current_arch (),
9990 NULL, 0, arg, 1 /* parse arg */,
9991 tempflag, type_wanted,
9992 0 /* Ignore count */,
9993 pending_break_support,
9999 do_cleanups (cleanup);
10002 /* Helper function for break_command_1 and disassemble_command. */
10005 resolve_sal_pc (struct symtab_and_line *sal)
10009 if (sal->pc == 0 && sal->symtab != NULL)
10011 if (!find_line_pc (sal->symtab, sal->line, &pc))
10012 error (_("No line %d in file \"%s\"."),
10013 sal->line, symtab_to_filename_for_display (sal->symtab));
10016 /* If this SAL corresponds to a breakpoint inserted using a line
10017 number, then skip the function prologue if necessary. */
10018 if (sal->explicit_line)
10019 skip_prologue_sal (sal);
10022 if (sal->section == 0 && sal->symtab != NULL)
10024 const struct blockvector *bv;
10025 const struct block *b;
10026 struct symbol *sym;
10028 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
10029 SYMTAB_COMPUNIT (sal->symtab));
10032 sym = block_linkage_function (b);
10035 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
10036 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
10041 /* It really is worthwhile to have the section, so we'll
10042 just have to look harder. This case can be executed
10043 if we have line numbers but no functions (as can
10044 happen in assembly source). */
10046 struct bound_minimal_symbol msym;
10047 struct cleanup *old_chain = save_current_space_and_thread ();
10049 switch_to_program_space_and_thread (sal->pspace);
10051 msym = lookup_minimal_symbol_by_pc (sal->pc);
10053 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10055 do_cleanups (old_chain);
10062 break_command (char *arg, int from_tty)
10064 break_command_1 (arg, 0, from_tty);
10068 tbreak_command (char *arg, int from_tty)
10070 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10074 hbreak_command (char *arg, int from_tty)
10076 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10080 thbreak_command (char *arg, int from_tty)
10082 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10086 stop_command (char *arg, int from_tty)
10088 printf_filtered (_("Specify the type of breakpoint to set.\n\
10089 Usage: stop in <function | address>\n\
10090 stop at <line>\n"));
10094 stopin_command (char *arg, int from_tty)
10098 if (arg == (char *) NULL)
10100 else if (*arg != '*')
10102 char *argptr = arg;
10105 /* Look for a ':'. If this is a line number specification, then
10106 say it is bad, otherwise, it should be an address or
10107 function/method name. */
10108 while (*argptr && !hasColon)
10110 hasColon = (*argptr == ':');
10115 badInput = (*argptr != ':'); /* Not a class::method */
10117 badInput = isdigit (*arg); /* a simple line number */
10121 printf_filtered (_("Usage: stop in <function | address>\n"));
10123 break_command_1 (arg, 0, from_tty);
10127 stopat_command (char *arg, int from_tty)
10131 if (arg == (char *) NULL || *arg == '*') /* no line number */
10135 char *argptr = arg;
10138 /* Look for a ':'. If there is a '::' then get out, otherwise
10139 it is probably a line number. */
10140 while (*argptr && !hasColon)
10142 hasColon = (*argptr == ':');
10147 badInput = (*argptr == ':'); /* we have class::method */
10149 badInput = !isdigit (*arg); /* not a line number */
10153 printf_filtered (_("Usage: stop at <line>\n"));
10155 break_command_1 (arg, 0, from_tty);
10158 /* The dynamic printf command is mostly like a regular breakpoint, but
10159 with a prewired command list consisting of a single output command,
10160 built from extra arguments supplied on the dprintf command
10164 dprintf_command (char *arg, int from_tty)
10166 struct event_location *location;
10167 struct cleanup *cleanup;
10169 location = string_to_event_location (&arg, current_language);
10170 cleanup = make_cleanup_delete_event_location (location);
10172 /* If non-NULL, ARG should have been advanced past the location;
10173 the next character must be ','. */
10176 if (arg[0] != ',' || arg[1] == '\0')
10177 error (_("Format string required"));
10180 /* Skip the comma. */
10185 create_breakpoint (get_current_arch (),
10187 NULL, 0, arg, 1 /* parse arg */,
10189 0 /* Ignore count */,
10190 pending_break_support,
10191 &dprintf_breakpoint_ops,
10196 do_cleanups (cleanup);
10200 agent_printf_command (char *arg, int from_tty)
10202 error (_("May only run agent-printf on the target"));
10205 /* Implement the "breakpoint_hit" breakpoint_ops method for
10206 ranged breakpoints. */
10209 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10210 struct address_space *aspace,
10212 const struct target_waitstatus *ws)
10214 if (ws->kind != TARGET_WAITKIND_STOPPED
10215 || ws->value.sig != GDB_SIGNAL_TRAP)
10218 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10219 bl->length, aspace, bp_addr);
10222 /* Implement the "resources_needed" breakpoint_ops method for
10223 ranged breakpoints. */
10226 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10228 return target_ranged_break_num_registers ();
10231 /* Implement the "print_it" breakpoint_ops method for
10232 ranged breakpoints. */
10234 static enum print_stop_action
10235 print_it_ranged_breakpoint (bpstat bs)
10237 struct breakpoint *b = bs->breakpoint_at;
10238 struct bp_location *bl = b->loc;
10239 struct ui_out *uiout = current_uiout;
10241 gdb_assert (b->type == bp_hardware_breakpoint);
10243 /* Ranged breakpoints have only one location. */
10244 gdb_assert (bl && bl->next == NULL);
10246 annotate_breakpoint (b->number);
10248 maybe_print_thread_hit_breakpoint (uiout);
10250 if (b->disposition == disp_del)
10251 ui_out_text (uiout, "Temporary ranged breakpoint ");
10253 ui_out_text (uiout, "Ranged breakpoint ");
10254 if (ui_out_is_mi_like_p (uiout))
10256 ui_out_field_string (uiout, "reason",
10257 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10258 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10260 ui_out_field_int (uiout, "bkptno", b->number);
10261 ui_out_text (uiout, ", ");
10263 return PRINT_SRC_AND_LOC;
10266 /* Implement the "print_one" breakpoint_ops method for
10267 ranged breakpoints. */
10270 print_one_ranged_breakpoint (struct breakpoint *b,
10271 struct bp_location **last_loc)
10273 struct bp_location *bl = b->loc;
10274 struct value_print_options opts;
10275 struct ui_out *uiout = current_uiout;
10277 /* Ranged breakpoints have only one location. */
10278 gdb_assert (bl && bl->next == NULL);
10280 get_user_print_options (&opts);
10282 if (opts.addressprint)
10283 /* We don't print the address range here, it will be printed later
10284 by print_one_detail_ranged_breakpoint. */
10285 ui_out_field_skip (uiout, "addr");
10286 annotate_field (5);
10287 print_breakpoint_location (b, bl);
10291 /* Implement the "print_one_detail" breakpoint_ops method for
10292 ranged breakpoints. */
10295 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10296 struct ui_out *uiout)
10298 CORE_ADDR address_start, address_end;
10299 struct bp_location *bl = b->loc;
10300 struct ui_file *stb = mem_fileopen ();
10301 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10305 address_start = bl->address;
10306 address_end = address_start + bl->length - 1;
10308 ui_out_text (uiout, "\taddress range: ");
10309 fprintf_unfiltered (stb, "[%s, %s]",
10310 print_core_address (bl->gdbarch, address_start),
10311 print_core_address (bl->gdbarch, address_end));
10312 ui_out_field_stream (uiout, "addr", stb);
10313 ui_out_text (uiout, "\n");
10315 do_cleanups (cleanup);
10318 /* Implement the "print_mention" breakpoint_ops method for
10319 ranged breakpoints. */
10322 print_mention_ranged_breakpoint (struct breakpoint *b)
10324 struct bp_location *bl = b->loc;
10325 struct ui_out *uiout = current_uiout;
10328 gdb_assert (b->type == bp_hardware_breakpoint);
10330 if (ui_out_is_mi_like_p (uiout))
10333 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10334 b->number, paddress (bl->gdbarch, bl->address),
10335 paddress (bl->gdbarch, bl->address + bl->length - 1));
10338 /* Implement the "print_recreate" breakpoint_ops method for
10339 ranged breakpoints. */
10342 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10344 fprintf_unfiltered (fp, "break-range %s, %s",
10345 event_location_to_string (b->location),
10346 event_location_to_string (b->location_range_end));
10347 print_recreate_thread (b, fp);
10350 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10352 static struct breakpoint_ops ranged_breakpoint_ops;
10354 /* Find the address where the end of the breakpoint range should be
10355 placed, given the SAL of the end of the range. This is so that if
10356 the user provides a line number, the end of the range is set to the
10357 last instruction of the given line. */
10360 find_breakpoint_range_end (struct symtab_and_line sal)
10364 /* If the user provided a PC value, use it. Otherwise,
10365 find the address of the end of the given location. */
10366 if (sal.explicit_pc)
10373 ret = find_line_pc_range (sal, &start, &end);
10375 error (_("Could not find location of the end of the range."));
10377 /* find_line_pc_range returns the start of the next line. */
10384 /* Implement the "break-range" CLI command. */
10387 break_range_command (char *arg, int from_tty)
10389 char *arg_start, *addr_string_start, *addr_string_end;
10390 struct linespec_result canonical_start, canonical_end;
10391 int bp_count, can_use_bp, length;
10393 struct breakpoint *b;
10394 struct symtab_and_line sal_start, sal_end;
10395 struct cleanup *cleanup_bkpt;
10396 struct linespec_sals *lsal_start, *lsal_end;
10397 struct event_location *start_location, *end_location;
10399 /* We don't support software ranged breakpoints. */
10400 if (target_ranged_break_num_registers () < 0)
10401 error (_("This target does not support hardware ranged breakpoints."));
10403 bp_count = hw_breakpoint_used_count ();
10404 bp_count += target_ranged_break_num_registers ();
10405 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10407 if (can_use_bp < 0)
10408 error (_("Hardware breakpoints used exceeds limit."));
10410 arg = skip_spaces (arg);
10411 if (arg == NULL || arg[0] == '\0')
10412 error(_("No address range specified."));
10414 init_linespec_result (&canonical_start);
10417 start_location = string_to_event_location (&arg, current_language);
10418 cleanup_bkpt = make_cleanup_delete_event_location (start_location);
10419 parse_breakpoint_sals (start_location, &canonical_start);
10420 make_cleanup_destroy_linespec_result (&canonical_start);
10423 error (_("Too few arguments."));
10424 else if (VEC_empty (linespec_sals, canonical_start.sals))
10425 error (_("Could not find location of the beginning of the range."));
10427 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10429 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10430 || lsal_start->sals.nelts != 1)
10431 error (_("Cannot create a ranged breakpoint with multiple locations."));
10433 sal_start = lsal_start->sals.sals[0];
10434 addr_string_start = savestring (arg_start, arg - arg_start);
10435 make_cleanup (xfree, addr_string_start);
10437 arg++; /* Skip the comma. */
10438 arg = skip_spaces (arg);
10440 /* Parse the end location. */
10442 init_linespec_result (&canonical_end);
10445 /* We call decode_line_full directly here instead of using
10446 parse_breakpoint_sals because we need to specify the start location's
10447 symtab and line as the default symtab and line for the end of the
10448 range. This makes it possible to have ranges like "foo.c:27, +14",
10449 where +14 means 14 lines from the start location. */
10450 end_location = string_to_event_location (&arg, current_language);
10451 make_cleanup_delete_event_location (end_location);
10452 decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL,
10453 sal_start.symtab, sal_start.line,
10454 &canonical_end, NULL, NULL);
10456 make_cleanup_destroy_linespec_result (&canonical_end);
10458 if (VEC_empty (linespec_sals, canonical_end.sals))
10459 error (_("Could not find location of the end of the range."));
10461 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10462 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10463 || lsal_end->sals.nelts != 1)
10464 error (_("Cannot create a ranged breakpoint with multiple locations."));
10466 sal_end = lsal_end->sals.sals[0];
10468 end = find_breakpoint_range_end (sal_end);
10469 if (sal_start.pc > end)
10470 error (_("Invalid address range, end precedes start."));
10472 length = end - sal_start.pc + 1;
10474 /* Length overflowed. */
10475 error (_("Address range too large."));
10476 else if (length == 1)
10478 /* This range is simple enough to be handled by
10479 the `hbreak' command. */
10480 hbreak_command (addr_string_start, 1);
10482 do_cleanups (cleanup_bkpt);
10487 /* Now set up the breakpoint. */
10488 b = set_raw_breakpoint (get_current_arch (), sal_start,
10489 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10490 set_breakpoint_count (breakpoint_count + 1);
10491 b->number = breakpoint_count;
10492 b->disposition = disp_donttouch;
10493 b->location = copy_event_location (start_location);
10494 b->location_range_end = copy_event_location (end_location);
10495 b->loc->length = length;
10497 do_cleanups (cleanup_bkpt);
10500 observer_notify_breakpoint_created (b);
10501 update_global_location_list (UGLL_MAY_INSERT);
10504 /* Return non-zero if EXP is verified as constant. Returned zero
10505 means EXP is variable. Also the constant detection may fail for
10506 some constant expressions and in such case still falsely return
10510 watchpoint_exp_is_const (const struct expression *exp)
10512 int i = exp->nelts;
10518 /* We are only interested in the descriptor of each element. */
10519 operator_length (exp, i, &oplenp, &argsp);
10522 switch (exp->elts[i].opcode)
10532 case BINOP_LOGICAL_AND:
10533 case BINOP_LOGICAL_OR:
10534 case BINOP_BITWISE_AND:
10535 case BINOP_BITWISE_IOR:
10536 case BINOP_BITWISE_XOR:
10538 case BINOP_NOTEQUAL:
10565 case OP_OBJC_NSSTRING:
10568 case UNOP_LOGICAL_NOT:
10569 case UNOP_COMPLEMENT:
10574 case UNOP_CAST_TYPE:
10575 case UNOP_REINTERPRET_CAST:
10576 case UNOP_DYNAMIC_CAST:
10577 /* Unary, binary and ternary operators: We have to check
10578 their operands. If they are constant, then so is the
10579 result of that operation. For instance, if A and B are
10580 determined to be constants, then so is "A + B".
10582 UNOP_IND is one exception to the rule above, because the
10583 value of *ADDR is not necessarily a constant, even when
10588 /* Check whether the associated symbol is a constant.
10590 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10591 possible that a buggy compiler could mark a variable as
10592 constant even when it is not, and TYPE_CONST would return
10593 true in this case, while SYMBOL_CLASS wouldn't.
10595 We also have to check for function symbols because they
10596 are always constant. */
10598 struct symbol *s = exp->elts[i + 2].symbol;
10600 if (SYMBOL_CLASS (s) != LOC_BLOCK
10601 && SYMBOL_CLASS (s) != LOC_CONST
10602 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10607 /* The default action is to return 0 because we are using
10608 the optimistic approach here: If we don't know something,
10609 then it is not a constant. */
10618 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10621 dtor_watchpoint (struct breakpoint *self)
10623 struct watchpoint *w = (struct watchpoint *) self;
10625 xfree (w->cond_exp);
10627 xfree (w->exp_string);
10628 xfree (w->exp_string_reparse);
10629 value_free (w->val);
10631 base_breakpoint_ops.dtor (self);
10634 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10637 re_set_watchpoint (struct breakpoint *b)
10639 struct watchpoint *w = (struct watchpoint *) b;
10641 /* Watchpoint can be either on expression using entirely global
10642 variables, or it can be on local variables.
10644 Watchpoints of the first kind are never auto-deleted, and even
10645 persist across program restarts. Since they can use variables
10646 from shared libraries, we need to reparse expression as libraries
10647 are loaded and unloaded.
10649 Watchpoints on local variables can also change meaning as result
10650 of solib event. For example, if a watchpoint uses both a local
10651 and a global variables in expression, it's a local watchpoint,
10652 but unloading of a shared library will make the expression
10653 invalid. This is not a very common use case, but we still
10654 re-evaluate expression, to avoid surprises to the user.
10656 Note that for local watchpoints, we re-evaluate it only if
10657 watchpoints frame id is still valid. If it's not, it means the
10658 watchpoint is out of scope and will be deleted soon. In fact,
10659 I'm not sure we'll ever be called in this case.
10661 If a local watchpoint's frame id is still valid, then
10662 w->exp_valid_block is likewise valid, and we can safely use it.
10664 Don't do anything about disabled watchpoints, since they will be
10665 reevaluated again when enabled. */
10666 update_watchpoint (w, 1 /* reparse */);
10669 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10672 insert_watchpoint (struct bp_location *bl)
10674 struct watchpoint *w = (struct watchpoint *) bl->owner;
10675 int length = w->exact ? 1 : bl->length;
10677 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10681 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10684 remove_watchpoint (struct bp_location *bl)
10686 struct watchpoint *w = (struct watchpoint *) bl->owner;
10687 int length = w->exact ? 1 : bl->length;
10689 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10694 breakpoint_hit_watchpoint (const struct bp_location *bl,
10695 struct address_space *aspace, CORE_ADDR bp_addr,
10696 const struct target_waitstatus *ws)
10698 struct breakpoint *b = bl->owner;
10699 struct watchpoint *w = (struct watchpoint *) b;
10701 /* Continuable hardware watchpoints are treated as non-existent if the
10702 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10703 some data address). Otherwise gdb won't stop on a break instruction
10704 in the code (not from a breakpoint) when a hardware watchpoint has
10705 been defined. Also skip watchpoints which we know did not trigger
10706 (did not match the data address). */
10707 if (is_hardware_watchpoint (b)
10708 && w->watchpoint_triggered == watch_triggered_no)
10715 check_status_watchpoint (bpstat bs)
10717 gdb_assert (is_watchpoint (bs->breakpoint_at));
10719 bpstat_check_watchpoint (bs);
10722 /* Implement the "resources_needed" breakpoint_ops method for
10723 hardware watchpoints. */
10726 resources_needed_watchpoint (const struct bp_location *bl)
10728 struct watchpoint *w = (struct watchpoint *) bl->owner;
10729 int length = w->exact? 1 : bl->length;
10731 return target_region_ok_for_hw_watchpoint (bl->address, length);
10734 /* Implement the "works_in_software_mode" breakpoint_ops method for
10735 hardware watchpoints. */
10738 works_in_software_mode_watchpoint (const struct breakpoint *b)
10740 /* Read and access watchpoints only work with hardware support. */
10741 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10744 static enum print_stop_action
10745 print_it_watchpoint (bpstat bs)
10747 struct cleanup *old_chain;
10748 struct breakpoint *b;
10749 struct ui_file *stb;
10750 enum print_stop_action result;
10751 struct watchpoint *w;
10752 struct ui_out *uiout = current_uiout;
10754 gdb_assert (bs->bp_location_at != NULL);
10756 b = bs->breakpoint_at;
10757 w = (struct watchpoint *) b;
10759 stb = mem_fileopen ();
10760 old_chain = make_cleanup_ui_file_delete (stb);
10762 annotate_watchpoint (b->number);
10763 maybe_print_thread_hit_breakpoint (uiout);
10767 case bp_watchpoint:
10768 case bp_hardware_watchpoint:
10769 if (ui_out_is_mi_like_p (uiout))
10770 ui_out_field_string
10772 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10774 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10775 ui_out_text (uiout, "\nOld value = ");
10776 watchpoint_value_print (bs->old_val, stb);
10777 ui_out_field_stream (uiout, "old", stb);
10778 ui_out_text (uiout, "\nNew value = ");
10779 watchpoint_value_print (w->val, stb);
10780 ui_out_field_stream (uiout, "new", stb);
10781 ui_out_text (uiout, "\n");
10782 /* More than one watchpoint may have been triggered. */
10783 result = PRINT_UNKNOWN;
10786 case bp_read_watchpoint:
10787 if (ui_out_is_mi_like_p (uiout))
10788 ui_out_field_string
10790 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10792 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10793 ui_out_text (uiout, "\nValue = ");
10794 watchpoint_value_print (w->val, stb);
10795 ui_out_field_stream (uiout, "value", stb);
10796 ui_out_text (uiout, "\n");
10797 result = PRINT_UNKNOWN;
10800 case bp_access_watchpoint:
10801 if (bs->old_val != NULL)
10803 if (ui_out_is_mi_like_p (uiout))
10804 ui_out_field_string
10806 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10808 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10809 ui_out_text (uiout, "\nOld value = ");
10810 watchpoint_value_print (bs->old_val, stb);
10811 ui_out_field_stream (uiout, "old", stb);
10812 ui_out_text (uiout, "\nNew value = ");
10817 if (ui_out_is_mi_like_p (uiout))
10818 ui_out_field_string
10820 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10821 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10822 ui_out_text (uiout, "\nValue = ");
10824 watchpoint_value_print (w->val, stb);
10825 ui_out_field_stream (uiout, "new", stb);
10826 ui_out_text (uiout, "\n");
10827 result = PRINT_UNKNOWN;
10830 result = PRINT_UNKNOWN;
10833 do_cleanups (old_chain);
10837 /* Implement the "print_mention" breakpoint_ops method for hardware
10841 print_mention_watchpoint (struct breakpoint *b)
10843 struct cleanup *ui_out_chain;
10844 struct watchpoint *w = (struct watchpoint *) b;
10845 struct ui_out *uiout = current_uiout;
10849 case bp_watchpoint:
10850 ui_out_text (uiout, "Watchpoint ");
10851 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10853 case bp_hardware_watchpoint:
10854 ui_out_text (uiout, "Hardware watchpoint ");
10855 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10857 case bp_read_watchpoint:
10858 ui_out_text (uiout, "Hardware read watchpoint ");
10859 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10861 case bp_access_watchpoint:
10862 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10863 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10866 internal_error (__FILE__, __LINE__,
10867 _("Invalid hardware watchpoint type."));
10870 ui_out_field_int (uiout, "number", b->number);
10871 ui_out_text (uiout, ": ");
10872 ui_out_field_string (uiout, "exp", w->exp_string);
10873 do_cleanups (ui_out_chain);
10876 /* Implement the "print_recreate" breakpoint_ops method for
10880 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10882 struct watchpoint *w = (struct watchpoint *) b;
10886 case bp_watchpoint:
10887 case bp_hardware_watchpoint:
10888 fprintf_unfiltered (fp, "watch");
10890 case bp_read_watchpoint:
10891 fprintf_unfiltered (fp, "rwatch");
10893 case bp_access_watchpoint:
10894 fprintf_unfiltered (fp, "awatch");
10897 internal_error (__FILE__, __LINE__,
10898 _("Invalid watchpoint type."));
10901 fprintf_unfiltered (fp, " %s", w->exp_string);
10902 print_recreate_thread (b, fp);
10905 /* Implement the "explains_signal" breakpoint_ops method for
10909 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10911 /* A software watchpoint cannot cause a signal other than
10912 GDB_SIGNAL_TRAP. */
10913 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10919 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10921 static struct breakpoint_ops watchpoint_breakpoint_ops;
10923 /* Implement the "insert" breakpoint_ops method for
10924 masked hardware watchpoints. */
10927 insert_masked_watchpoint (struct bp_location *bl)
10929 struct watchpoint *w = (struct watchpoint *) bl->owner;
10931 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10932 bl->watchpoint_type);
10935 /* Implement the "remove" breakpoint_ops method for
10936 masked hardware watchpoints. */
10939 remove_masked_watchpoint (struct bp_location *bl)
10941 struct watchpoint *w = (struct watchpoint *) bl->owner;
10943 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10944 bl->watchpoint_type);
10947 /* Implement the "resources_needed" breakpoint_ops method for
10948 masked hardware watchpoints. */
10951 resources_needed_masked_watchpoint (const struct bp_location *bl)
10953 struct watchpoint *w = (struct watchpoint *) bl->owner;
10955 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10958 /* Implement the "works_in_software_mode" breakpoint_ops method for
10959 masked hardware watchpoints. */
10962 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10967 /* Implement the "print_it" breakpoint_ops method for
10968 masked hardware watchpoints. */
10970 static enum print_stop_action
10971 print_it_masked_watchpoint (bpstat bs)
10973 struct breakpoint *b = bs->breakpoint_at;
10974 struct ui_out *uiout = current_uiout;
10976 /* Masked watchpoints have only one location. */
10977 gdb_assert (b->loc && b->loc->next == NULL);
10979 annotate_watchpoint (b->number);
10980 maybe_print_thread_hit_breakpoint (uiout);
10984 case bp_hardware_watchpoint:
10985 if (ui_out_is_mi_like_p (uiout))
10986 ui_out_field_string
10988 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10991 case bp_read_watchpoint:
10992 if (ui_out_is_mi_like_p (uiout))
10993 ui_out_field_string
10995 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10998 case bp_access_watchpoint:
10999 if (ui_out_is_mi_like_p (uiout))
11000 ui_out_field_string
11002 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11005 internal_error (__FILE__, __LINE__,
11006 _("Invalid hardware watchpoint type."));
11010 ui_out_text (uiout, _("\n\
11011 Check the underlying instruction at PC for the memory\n\
11012 address and value which triggered this watchpoint.\n"));
11013 ui_out_text (uiout, "\n");
11015 /* More than one watchpoint may have been triggered. */
11016 return PRINT_UNKNOWN;
11019 /* Implement the "print_one_detail" breakpoint_ops method for
11020 masked hardware watchpoints. */
11023 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11024 struct ui_out *uiout)
11026 struct watchpoint *w = (struct watchpoint *) b;
11028 /* Masked watchpoints have only one location. */
11029 gdb_assert (b->loc && b->loc->next == NULL);
11031 ui_out_text (uiout, "\tmask ");
11032 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11033 ui_out_text (uiout, "\n");
11036 /* Implement the "print_mention" breakpoint_ops method for
11037 masked hardware watchpoints. */
11040 print_mention_masked_watchpoint (struct breakpoint *b)
11042 struct watchpoint *w = (struct watchpoint *) b;
11043 struct ui_out *uiout = current_uiout;
11044 struct cleanup *ui_out_chain;
11048 case bp_hardware_watchpoint:
11049 ui_out_text (uiout, "Masked hardware watchpoint ");
11050 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11052 case bp_read_watchpoint:
11053 ui_out_text (uiout, "Masked hardware read watchpoint ");
11054 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11056 case bp_access_watchpoint:
11057 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11058 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11061 internal_error (__FILE__, __LINE__,
11062 _("Invalid hardware watchpoint type."));
11065 ui_out_field_int (uiout, "number", b->number);
11066 ui_out_text (uiout, ": ");
11067 ui_out_field_string (uiout, "exp", w->exp_string);
11068 do_cleanups (ui_out_chain);
11071 /* Implement the "print_recreate" breakpoint_ops method for
11072 masked hardware watchpoints. */
11075 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11077 struct watchpoint *w = (struct watchpoint *) b;
11082 case bp_hardware_watchpoint:
11083 fprintf_unfiltered (fp, "watch");
11085 case bp_read_watchpoint:
11086 fprintf_unfiltered (fp, "rwatch");
11088 case bp_access_watchpoint:
11089 fprintf_unfiltered (fp, "awatch");
11092 internal_error (__FILE__, __LINE__,
11093 _("Invalid hardware watchpoint type."));
11096 sprintf_vma (tmp, w->hw_wp_mask);
11097 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11098 print_recreate_thread (b, fp);
11101 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11103 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11105 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11108 is_masked_watchpoint (const struct breakpoint *b)
11110 return b->ops == &masked_watchpoint_breakpoint_ops;
11113 /* accessflag: hw_write: watch write,
11114 hw_read: watch read,
11115 hw_access: watch access (read or write) */
11117 watch_command_1 (const char *arg, int accessflag, int from_tty,
11118 int just_location, int internal)
11120 struct breakpoint *b, *scope_breakpoint = NULL;
11121 struct expression *exp;
11122 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11123 struct value *val, *mark, *result;
11124 int saved_bitpos = 0, saved_bitsize = 0;
11125 struct frame_info *frame;
11126 const char *exp_start = NULL;
11127 const char *exp_end = NULL;
11128 const char *tok, *end_tok;
11130 const char *cond_start = NULL;
11131 const char *cond_end = NULL;
11132 enum bptype bp_type;
11135 /* Flag to indicate whether we are going to use masks for
11136 the hardware watchpoint. */
11138 CORE_ADDR mask = 0;
11139 struct watchpoint *w;
11141 struct cleanup *back_to;
11143 /* Make sure that we actually have parameters to parse. */
11144 if (arg != NULL && arg[0] != '\0')
11146 const char *value_start;
11148 exp_end = arg + strlen (arg);
11150 /* Look for "parameter value" pairs at the end
11151 of the arguments string. */
11152 for (tok = exp_end - 1; tok > arg; tok--)
11154 /* Skip whitespace at the end of the argument list. */
11155 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11158 /* Find the beginning of the last token.
11159 This is the value of the parameter. */
11160 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11162 value_start = tok + 1;
11164 /* Skip whitespace. */
11165 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11170 /* Find the beginning of the second to last token.
11171 This is the parameter itself. */
11172 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11175 toklen = end_tok - tok + 1;
11177 if (toklen == 6 && startswith (tok, "thread"))
11179 struct thread_info *thr;
11180 /* At this point we've found a "thread" token, which means
11181 the user is trying to set a watchpoint that triggers
11182 only in a specific thread. */
11186 error(_("You can specify only one thread."));
11188 /* Extract the thread ID from the next token. */
11189 thr = parse_thread_id (value_start, &endp);
11191 /* Check if the user provided a valid thread ID. */
11192 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11193 invalid_thread_id_error (value_start);
11195 thread = thr->global_num;
11197 else if (toklen == 4 && startswith (tok, "mask"))
11199 /* We've found a "mask" token, which means the user wants to
11200 create a hardware watchpoint that is going to have the mask
11202 struct value *mask_value, *mark;
11205 error(_("You can specify only one mask."));
11207 use_mask = just_location = 1;
11209 mark = value_mark ();
11210 mask_value = parse_to_comma_and_eval (&value_start);
11211 mask = value_as_address (mask_value);
11212 value_free_to_mark (mark);
11215 /* We didn't recognize what we found. We should stop here. */
11218 /* Truncate the string and get rid of the "parameter value" pair before
11219 the arguments string is parsed by the parse_exp_1 function. */
11226 /* Parse the rest of the arguments. From here on out, everything
11227 is in terms of a newly allocated string instead of the original
11229 innermost_block = NULL;
11230 expression = savestring (arg, exp_end - arg);
11231 back_to = make_cleanup (xfree, expression);
11232 exp_start = arg = expression;
11233 exp = parse_exp_1 (&arg, 0, 0, 0);
11235 /* Remove trailing whitespace from the expression before saving it.
11236 This makes the eventual display of the expression string a bit
11238 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11241 /* Checking if the expression is not constant. */
11242 if (watchpoint_exp_is_const (exp))
11246 len = exp_end - exp_start;
11247 while (len > 0 && isspace (exp_start[len - 1]))
11249 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11252 exp_valid_block = innermost_block;
11253 mark = value_mark ();
11254 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11256 if (val != NULL && just_location)
11258 saved_bitpos = value_bitpos (val);
11259 saved_bitsize = value_bitsize (val);
11266 exp_valid_block = NULL;
11267 val = value_addr (result);
11268 release_value (val);
11269 value_free_to_mark (mark);
11273 ret = target_masked_watch_num_registers (value_as_address (val),
11276 error (_("This target does not support masked watchpoints."));
11277 else if (ret == -2)
11278 error (_("Invalid mask or memory region."));
11281 else if (val != NULL)
11282 release_value (val);
11284 tok = skip_spaces_const (arg);
11285 end_tok = skip_to_space_const (tok);
11287 toklen = end_tok - tok;
11288 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11290 struct expression *cond;
11292 innermost_block = NULL;
11293 tok = cond_start = end_tok + 1;
11294 cond = parse_exp_1 (&tok, 0, 0, 0);
11296 /* The watchpoint expression may not be local, but the condition
11297 may still be. E.g.: `watch global if local > 0'. */
11298 cond_exp_valid_block = innermost_block;
11304 error (_("Junk at end of command."));
11306 frame = block_innermost_frame (exp_valid_block);
11308 /* If the expression is "local", then set up a "watchpoint scope"
11309 breakpoint at the point where we've left the scope of the watchpoint
11310 expression. Create the scope breakpoint before the watchpoint, so
11311 that we will encounter it first in bpstat_stop_status. */
11312 if (exp_valid_block && frame)
11314 if (frame_id_p (frame_unwind_caller_id (frame)))
11317 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11318 frame_unwind_caller_pc (frame),
11319 bp_watchpoint_scope,
11320 &momentary_breakpoint_ops);
11322 scope_breakpoint->enable_state = bp_enabled;
11324 /* Automatically delete the breakpoint when it hits. */
11325 scope_breakpoint->disposition = disp_del;
11327 /* Only break in the proper frame (help with recursion). */
11328 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11330 /* Set the address at which we will stop. */
11331 scope_breakpoint->loc->gdbarch
11332 = frame_unwind_caller_arch (frame);
11333 scope_breakpoint->loc->requested_address
11334 = frame_unwind_caller_pc (frame);
11335 scope_breakpoint->loc->address
11336 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11337 scope_breakpoint->loc->requested_address,
11338 scope_breakpoint->type);
11342 /* Now set up the breakpoint. We create all watchpoints as hardware
11343 watchpoints here even if hardware watchpoints are turned off, a call
11344 to update_watchpoint later in this function will cause the type to
11345 drop back to bp_watchpoint (software watchpoint) if required. */
11347 if (accessflag == hw_read)
11348 bp_type = bp_read_watchpoint;
11349 else if (accessflag == hw_access)
11350 bp_type = bp_access_watchpoint;
11352 bp_type = bp_hardware_watchpoint;
11354 w = XCNEW (struct watchpoint);
11357 init_raw_breakpoint_without_location (b, NULL, bp_type,
11358 &masked_watchpoint_breakpoint_ops);
11360 init_raw_breakpoint_without_location (b, NULL, bp_type,
11361 &watchpoint_breakpoint_ops);
11362 b->thread = thread;
11363 b->disposition = disp_donttouch;
11364 b->pspace = current_program_space;
11366 w->exp_valid_block = exp_valid_block;
11367 w->cond_exp_valid_block = cond_exp_valid_block;
11370 struct type *t = value_type (val);
11371 CORE_ADDR addr = value_as_address (val);
11374 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11375 name = type_to_string (t);
11377 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11378 core_addr_to_string (addr));
11381 w->exp_string = xstrprintf ("-location %.*s",
11382 (int) (exp_end - exp_start), exp_start);
11384 /* The above expression is in C. */
11385 b->language = language_c;
11388 w->exp_string = savestring (exp_start, exp_end - exp_start);
11392 w->hw_wp_mask = mask;
11397 w->val_bitpos = saved_bitpos;
11398 w->val_bitsize = saved_bitsize;
11403 b->cond_string = savestring (cond_start, cond_end - cond_start);
11405 b->cond_string = 0;
11409 w->watchpoint_frame = get_frame_id (frame);
11410 w->watchpoint_thread = inferior_ptid;
11414 w->watchpoint_frame = null_frame_id;
11415 w->watchpoint_thread = null_ptid;
11418 if (scope_breakpoint != NULL)
11420 /* The scope breakpoint is related to the watchpoint. We will
11421 need to act on them together. */
11422 b->related_breakpoint = scope_breakpoint;
11423 scope_breakpoint->related_breakpoint = b;
11426 if (!just_location)
11427 value_free_to_mark (mark);
11431 /* Finally update the new watchpoint. This creates the locations
11432 that should be inserted. */
11433 update_watchpoint (w, 1);
11435 CATCH (e, RETURN_MASK_ALL)
11437 delete_breakpoint (b);
11438 throw_exception (e);
11442 install_breakpoint (internal, b, 1);
11443 do_cleanups (back_to);
11446 /* Return count of debug registers needed to watch the given expression.
11447 If the watchpoint cannot be handled in hardware return zero. */
11450 can_use_hardware_watchpoint (struct value *v)
11452 int found_memory_cnt = 0;
11453 struct value *head = v;
11455 /* Did the user specifically forbid us to use hardware watchpoints? */
11456 if (!can_use_hw_watchpoints)
11459 /* Make sure that the value of the expression depends only upon
11460 memory contents, and values computed from them within GDB. If we
11461 find any register references or function calls, we can't use a
11462 hardware watchpoint.
11464 The idea here is that evaluating an expression generates a series
11465 of values, one holding the value of every subexpression. (The
11466 expression a*b+c has five subexpressions: a, b, a*b, c, and
11467 a*b+c.) GDB's values hold almost enough information to establish
11468 the criteria given above --- they identify memory lvalues,
11469 register lvalues, computed values, etcetera. So we can evaluate
11470 the expression, and then scan the chain of values that leaves
11471 behind to decide whether we can detect any possible change to the
11472 expression's final value using only hardware watchpoints.
11474 However, I don't think that the values returned by inferior
11475 function calls are special in any way. So this function may not
11476 notice that an expression involving an inferior function call
11477 can't be watched with hardware watchpoints. FIXME. */
11478 for (; v; v = value_next (v))
11480 if (VALUE_LVAL (v) == lval_memory)
11482 if (v != head && value_lazy (v))
11483 /* A lazy memory lvalue in the chain is one that GDB never
11484 needed to fetch; we either just used its address (e.g.,
11485 `a' in `a.b') or we never needed it at all (e.g., `a'
11486 in `a,b'). This doesn't apply to HEAD; if that is
11487 lazy then it was not readable, but watch it anyway. */
11491 /* Ahh, memory we actually used! Check if we can cover
11492 it with hardware watchpoints. */
11493 struct type *vtype = check_typedef (value_type (v));
11495 /* We only watch structs and arrays if user asked for it
11496 explicitly, never if they just happen to appear in a
11497 middle of some value chain. */
11499 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11500 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11502 CORE_ADDR vaddr = value_address (v);
11506 len = (target_exact_watchpoints
11507 && is_scalar_type_recursive (vtype))?
11508 1 : TYPE_LENGTH (value_type (v));
11510 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11514 found_memory_cnt += num_regs;
11518 else if (VALUE_LVAL (v) != not_lval
11519 && deprecated_value_modifiable (v) == 0)
11520 return 0; /* These are values from the history (e.g., $1). */
11521 else if (VALUE_LVAL (v) == lval_register)
11522 return 0; /* Cannot watch a register with a HW watchpoint. */
11525 /* The expression itself looks suitable for using a hardware
11526 watchpoint, but give the target machine a chance to reject it. */
11527 return found_memory_cnt;
11531 watch_command_wrapper (char *arg, int from_tty, int internal)
11533 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11536 /* A helper function that looks for the "-location" argument and then
11537 calls watch_command_1. */
11540 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11542 int just_location = 0;
11545 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11546 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11548 arg = skip_spaces (arg);
11552 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11556 watch_command (char *arg, int from_tty)
11558 watch_maybe_just_location (arg, hw_write, from_tty);
11562 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11564 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11568 rwatch_command (char *arg, int from_tty)
11570 watch_maybe_just_location (arg, hw_read, from_tty);
11574 awatch_command_wrapper (char *arg, int from_tty, int internal)
11576 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11580 awatch_command (char *arg, int from_tty)
11582 watch_maybe_just_location (arg, hw_access, from_tty);
11586 /* Data for the FSM that manages the until(location)/advance commands
11587 in infcmd.c. Here because it uses the mechanisms of
11590 struct until_break_fsm
11592 /* The base class. */
11593 struct thread_fsm thread_fsm;
11595 /* The thread that as current when the command was executed. */
11598 /* The breakpoint set at the destination location. */
11599 struct breakpoint *location_breakpoint;
11601 /* Breakpoint set at the return address in the caller frame. May be
11603 struct breakpoint *caller_breakpoint;
11606 static void until_break_fsm_clean_up (struct thread_fsm *self);
11607 static int until_break_fsm_should_stop (struct thread_fsm *self);
11608 static enum async_reply_reason
11609 until_break_fsm_async_reply_reason (struct thread_fsm *self);
11611 /* until_break_fsm's vtable. */
11613 static struct thread_fsm_ops until_break_fsm_ops =
11616 until_break_fsm_clean_up,
11617 until_break_fsm_should_stop,
11618 NULL, /* return_value */
11619 until_break_fsm_async_reply_reason,
11622 /* Allocate a new until_break_command_fsm. */
11624 static struct until_break_fsm *
11625 new_until_break_fsm (int thread,
11626 struct breakpoint *location_breakpoint,
11627 struct breakpoint *caller_breakpoint)
11629 struct until_break_fsm *sm;
11631 sm = XCNEW (struct until_break_fsm);
11632 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops);
11634 sm->thread = thread;
11635 sm->location_breakpoint = location_breakpoint;
11636 sm->caller_breakpoint = caller_breakpoint;
11641 /* Implementation of the 'should_stop' FSM method for the
11642 until(location)/advance commands. */
11645 until_break_fsm_should_stop (struct thread_fsm *self)
11647 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11648 struct thread_info *tp = inferior_thread ();
11650 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11651 sm->location_breakpoint) != NULL
11652 || (sm->caller_breakpoint != NULL
11653 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11654 sm->caller_breakpoint) != NULL))
11655 thread_fsm_set_finished (self);
11660 /* Implementation of the 'clean_up' FSM method for the
11661 until(location)/advance commands. */
11664 until_break_fsm_clean_up (struct thread_fsm *self)
11666 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11668 /* Clean up our temporary breakpoints. */
11669 if (sm->location_breakpoint != NULL)
11671 delete_breakpoint (sm->location_breakpoint);
11672 sm->location_breakpoint = NULL;
11674 if (sm->caller_breakpoint != NULL)
11676 delete_breakpoint (sm->caller_breakpoint);
11677 sm->caller_breakpoint = NULL;
11679 delete_longjmp_breakpoint (sm->thread);
11682 /* Implementation of the 'async_reply_reason' FSM method for the
11683 until(location)/advance commands. */
11685 static enum async_reply_reason
11686 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11688 return EXEC_ASYNC_LOCATION_REACHED;
11692 until_break_command (char *arg, int from_tty, int anywhere)
11694 struct symtabs_and_lines sals;
11695 struct symtab_and_line sal;
11696 struct frame_info *frame;
11697 struct gdbarch *frame_gdbarch;
11698 struct frame_id stack_frame_id;
11699 struct frame_id caller_frame_id;
11700 struct breakpoint *location_breakpoint;
11701 struct breakpoint *caller_breakpoint = NULL;
11702 struct cleanup *old_chain, *cleanup;
11704 struct thread_info *tp;
11705 struct event_location *location;
11706 struct until_break_fsm *sm;
11708 clear_proceed_status (0);
11710 /* Set a breakpoint where the user wants it and at return from
11713 location = string_to_event_location (&arg, current_language);
11714 cleanup = make_cleanup_delete_event_location (location);
11716 if (last_displayed_sal_is_valid ())
11717 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL,
11718 get_last_displayed_symtab (),
11719 get_last_displayed_line ());
11721 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE,
11722 NULL, (struct symtab *) NULL, 0);
11724 if (sals.nelts != 1)
11725 error (_("Couldn't get information on specified line."));
11727 sal = sals.sals[0];
11728 xfree (sals.sals); /* malloc'd, so freed. */
11731 error (_("Junk at end of arguments."));
11733 resolve_sal_pc (&sal);
11735 tp = inferior_thread ();
11736 thread = tp->global_num;
11738 old_chain = make_cleanup (null_cleanup, NULL);
11740 /* Note linespec handling above invalidates the frame chain.
11741 Installing a breakpoint also invalidates the frame chain (as it
11742 may need to switch threads), so do any frame handling before
11745 frame = get_selected_frame (NULL);
11746 frame_gdbarch = get_frame_arch (frame);
11747 stack_frame_id = get_stack_frame_id (frame);
11748 caller_frame_id = frame_unwind_caller_id (frame);
11750 /* Keep within the current frame, or in frames called by the current
11753 if (frame_id_p (caller_frame_id))
11755 struct symtab_and_line sal2;
11756 struct gdbarch *caller_gdbarch;
11758 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11759 sal2.pc = frame_unwind_caller_pc (frame);
11760 caller_gdbarch = frame_unwind_caller_arch (frame);
11761 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11765 make_cleanup_delete_breakpoint (caller_breakpoint);
11767 set_longjmp_breakpoint (tp, caller_frame_id);
11768 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11771 /* set_momentary_breakpoint could invalidate FRAME. */
11775 /* If the user told us to continue until a specified location,
11776 we don't specify a frame at which we need to stop. */
11777 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11778 null_frame_id, bp_until);
11780 /* Otherwise, specify the selected frame, because we want to stop
11781 only at the very same frame. */
11782 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11783 stack_frame_id, bp_until);
11784 make_cleanup_delete_breakpoint (location_breakpoint);
11786 sm = new_until_break_fsm (tp->global_num,
11787 location_breakpoint, caller_breakpoint);
11788 tp->thread_fsm = &sm->thread_fsm;
11790 discard_cleanups (old_chain);
11792 proceed (-1, GDB_SIGNAL_DEFAULT);
11794 do_cleanups (cleanup);
11797 /* This function attempts to parse an optional "if <cond>" clause
11798 from the arg string. If one is not found, it returns NULL.
11800 Else, it returns a pointer to the condition string. (It does not
11801 attempt to evaluate the string against a particular block.) And,
11802 it updates arg to point to the first character following the parsed
11803 if clause in the arg string. */
11806 ep_parse_optional_if_clause (char **arg)
11810 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11813 /* Skip the "if" keyword. */
11816 /* Skip any extra leading whitespace, and record the start of the
11817 condition string. */
11818 *arg = skip_spaces (*arg);
11819 cond_string = *arg;
11821 /* Assume that the condition occupies the remainder of the arg
11823 (*arg) += strlen (cond_string);
11825 return cond_string;
11828 /* Commands to deal with catching events, such as signals, exceptions,
11829 process start/exit, etc. */
11833 catch_fork_temporary, catch_vfork_temporary,
11834 catch_fork_permanent, catch_vfork_permanent
11839 catch_fork_command_1 (char *arg, int from_tty,
11840 struct cmd_list_element *command)
11842 struct gdbarch *gdbarch = get_current_arch ();
11843 char *cond_string = NULL;
11844 catch_fork_kind fork_kind;
11847 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11848 tempflag = (fork_kind == catch_fork_temporary
11849 || fork_kind == catch_vfork_temporary);
11853 arg = skip_spaces (arg);
11855 /* The allowed syntax is:
11857 catch [v]fork if <cond>
11859 First, check if there's an if clause. */
11860 cond_string = ep_parse_optional_if_clause (&arg);
11862 if ((*arg != '\0') && !isspace (*arg))
11863 error (_("Junk at end of arguments."));
11865 /* If this target supports it, create a fork or vfork catchpoint
11866 and enable reporting of such events. */
11869 case catch_fork_temporary:
11870 case catch_fork_permanent:
11871 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11872 &catch_fork_breakpoint_ops);
11874 case catch_vfork_temporary:
11875 case catch_vfork_permanent:
11876 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11877 &catch_vfork_breakpoint_ops);
11880 error (_("unsupported or unknown fork kind; cannot catch it"));
11886 catch_exec_command_1 (char *arg, int from_tty,
11887 struct cmd_list_element *command)
11889 struct exec_catchpoint *c;
11890 struct gdbarch *gdbarch = get_current_arch ();
11892 char *cond_string = NULL;
11894 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11898 arg = skip_spaces (arg);
11900 /* The allowed syntax is:
11902 catch exec if <cond>
11904 First, check if there's an if clause. */
11905 cond_string = ep_parse_optional_if_clause (&arg);
11907 if ((*arg != '\0') && !isspace (*arg))
11908 error (_("Junk at end of arguments."));
11910 c = XNEW (struct exec_catchpoint);
11911 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11912 &catch_exec_breakpoint_ops);
11913 c->exec_pathname = NULL;
11915 install_breakpoint (0, &c->base, 1);
11919 init_ada_exception_breakpoint (struct breakpoint *b,
11920 struct gdbarch *gdbarch,
11921 struct symtab_and_line sal,
11923 const struct breakpoint_ops *ops,
11930 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11932 loc_gdbarch = gdbarch;
11934 describe_other_breakpoints (loc_gdbarch,
11935 sal.pspace, sal.pc, sal.section, -1);
11936 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11937 version for exception catchpoints, because two catchpoints
11938 used for different exception names will use the same address.
11939 In this case, a "breakpoint ... also set at..." warning is
11940 unproductive. Besides, the warning phrasing is also a bit
11941 inappropriate, we should use the word catchpoint, and tell
11942 the user what type of catchpoint it is. The above is good
11943 enough for now, though. */
11946 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11948 b->enable_state = enabled ? bp_enabled : bp_disabled;
11949 b->disposition = tempflag ? disp_del : disp_donttouch;
11950 b->location = string_to_event_location (&addr_string,
11951 language_def (language_ada));
11952 b->language = language_ada;
11956 catch_command (char *arg, int from_tty)
11958 error (_("Catch requires an event name."));
11963 tcatch_command (char *arg, int from_tty)
11965 error (_("Catch requires an event name."));
11968 /* A qsort comparison function that sorts breakpoints in order. */
11971 compare_breakpoints (const void *a, const void *b)
11973 const breakpoint_p *ba = (const breakpoint_p *) a;
11974 uintptr_t ua = (uintptr_t) *ba;
11975 const breakpoint_p *bb = (const breakpoint_p *) b;
11976 uintptr_t ub = (uintptr_t) *bb;
11978 if ((*ba)->number < (*bb)->number)
11980 else if ((*ba)->number > (*bb)->number)
11983 /* Now sort by address, in case we see, e..g, two breakpoints with
11987 return ua > ub ? 1 : 0;
11990 /* Delete breakpoints by address or line. */
11993 clear_command (char *arg, int from_tty)
11995 struct breakpoint *b, *prev;
11996 VEC(breakpoint_p) *found = 0;
11999 struct symtabs_and_lines sals;
12000 struct symtab_and_line sal;
12002 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12006 sals = decode_line_with_current_source (arg,
12007 (DECODE_LINE_FUNFIRSTLINE
12008 | DECODE_LINE_LIST_MODE));
12009 make_cleanup (xfree, sals.sals);
12014 sals.sals = XNEW (struct symtab_and_line);
12015 make_cleanup (xfree, sals.sals);
12016 init_sal (&sal); /* Initialize to zeroes. */
12018 /* Set sal's line, symtab, pc, and pspace to the values
12019 corresponding to the last call to print_frame_info. If the
12020 codepoint is not valid, this will set all the fields to 0. */
12021 get_last_displayed_sal (&sal);
12022 if (sal.symtab == 0)
12023 error (_("No source file specified."));
12025 sals.sals[0] = sal;
12031 /* We don't call resolve_sal_pc here. That's not as bad as it
12032 seems, because all existing breakpoints typically have both
12033 file/line and pc set. So, if clear is given file/line, we can
12034 match this to existing breakpoint without obtaining pc at all.
12036 We only support clearing given the address explicitly
12037 present in breakpoint table. Say, we've set breakpoint
12038 at file:line. There were several PC values for that file:line,
12039 due to optimization, all in one block.
12041 We've picked one PC value. If "clear" is issued with another
12042 PC corresponding to the same file:line, the breakpoint won't
12043 be cleared. We probably can still clear the breakpoint, but
12044 since the other PC value is never presented to user, user
12045 can only find it by guessing, and it does not seem important
12046 to support that. */
12048 /* For each line spec given, delete bps which correspond to it. Do
12049 it in two passes, solely to preserve the current behavior that
12050 from_tty is forced true if we delete more than one
12054 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12055 for (i = 0; i < sals.nelts; i++)
12057 const char *sal_fullname;
12059 /* If exact pc given, clear bpts at that pc.
12060 If line given (pc == 0), clear all bpts on specified line.
12061 If defaulting, clear all bpts on default line
12064 defaulting sal.pc != 0 tests to do
12069 1 0 <can't happen> */
12071 sal = sals.sals[i];
12072 sal_fullname = (sal.symtab == NULL
12073 ? NULL : symtab_to_fullname (sal.symtab));
12075 /* Find all matching breakpoints and add them to 'found'. */
12076 ALL_BREAKPOINTS (b)
12079 /* Are we going to delete b? */
12080 if (b->type != bp_none && !is_watchpoint (b))
12082 struct bp_location *loc = b->loc;
12083 for (; loc; loc = loc->next)
12085 /* If the user specified file:line, don't allow a PC
12086 match. This matches historical gdb behavior. */
12087 int pc_match = (!sal.explicit_line
12089 && (loc->pspace == sal.pspace)
12090 && (loc->address == sal.pc)
12091 && (!section_is_overlay (loc->section)
12092 || loc->section == sal.section));
12093 int line_match = 0;
12095 if ((default_match || sal.explicit_line)
12096 && loc->symtab != NULL
12097 && sal_fullname != NULL
12098 && sal.pspace == loc->pspace
12099 && loc->line_number == sal.line
12100 && filename_cmp (symtab_to_fullname (loc->symtab),
12101 sal_fullname) == 0)
12104 if (pc_match || line_match)
12113 VEC_safe_push(breakpoint_p, found, b);
12117 /* Now go thru the 'found' chain and delete them. */
12118 if (VEC_empty(breakpoint_p, found))
12121 error (_("No breakpoint at %s."), arg);
12123 error (_("No breakpoint at this line."));
12126 /* Remove duplicates from the vec. */
12127 qsort (VEC_address (breakpoint_p, found),
12128 VEC_length (breakpoint_p, found),
12129 sizeof (breakpoint_p),
12130 compare_breakpoints);
12131 prev = VEC_index (breakpoint_p, found, 0);
12132 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12136 VEC_ordered_remove (breakpoint_p, found, ix);
12141 if (VEC_length(breakpoint_p, found) > 1)
12142 from_tty = 1; /* Always report if deleted more than one. */
12145 if (VEC_length(breakpoint_p, found) == 1)
12146 printf_unfiltered (_("Deleted breakpoint "));
12148 printf_unfiltered (_("Deleted breakpoints "));
12151 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12154 printf_unfiltered ("%d ", b->number);
12155 delete_breakpoint (b);
12158 putchar_unfiltered ('\n');
12160 do_cleanups (cleanups);
12163 /* Delete breakpoint in BS if they are `delete' breakpoints and
12164 all breakpoints that are marked for deletion, whether hit or not.
12165 This is called after any breakpoint is hit, or after errors. */
12168 breakpoint_auto_delete (bpstat bs)
12170 struct breakpoint *b, *b_tmp;
12172 for (; bs; bs = bs->next)
12173 if (bs->breakpoint_at
12174 && bs->breakpoint_at->disposition == disp_del
12176 delete_breakpoint (bs->breakpoint_at);
12178 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12180 if (b->disposition == disp_del_at_next_stop)
12181 delete_breakpoint (b);
12185 /* A comparison function for bp_location AP and BP being interfaced to
12186 qsort. Sort elements primarily by their ADDRESS (no matter what
12187 does breakpoint_address_is_meaningful say for its OWNER),
12188 secondarily by ordering first permanent elements and
12189 terciarily just ensuring the array is sorted stable way despite
12190 qsort being an unstable algorithm. */
12193 bp_location_compare (const void *ap, const void *bp)
12195 const struct bp_location *a = *(const struct bp_location **) ap;
12196 const struct bp_location *b = *(const struct bp_location **) bp;
12198 if (a->address != b->address)
12199 return (a->address > b->address) - (a->address < b->address);
12201 /* Sort locations at the same address by their pspace number, keeping
12202 locations of the same inferior (in a multi-inferior environment)
12205 if (a->pspace->num != b->pspace->num)
12206 return ((a->pspace->num > b->pspace->num)
12207 - (a->pspace->num < b->pspace->num));
12209 /* Sort permanent breakpoints first. */
12210 if (a->permanent != b->permanent)
12211 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
12213 /* Make the internal GDB representation stable across GDB runs
12214 where A and B memory inside GDB can differ. Breakpoint locations of
12215 the same type at the same address can be sorted in arbitrary order. */
12217 if (a->owner->number != b->owner->number)
12218 return ((a->owner->number > b->owner->number)
12219 - (a->owner->number < b->owner->number));
12221 return (a > b) - (a < b);
12224 /* Set bp_location_placed_address_before_address_max and
12225 bp_location_shadow_len_after_address_max according to the current
12226 content of the bp_location array. */
12229 bp_location_target_extensions_update (void)
12231 struct bp_location *bl, **blp_tmp;
12233 bp_location_placed_address_before_address_max = 0;
12234 bp_location_shadow_len_after_address_max = 0;
12236 ALL_BP_LOCATIONS (bl, blp_tmp)
12238 CORE_ADDR start, end, addr;
12240 if (!bp_location_has_shadow (bl))
12243 start = bl->target_info.placed_address;
12244 end = start + bl->target_info.shadow_len;
12246 gdb_assert (bl->address >= start);
12247 addr = bl->address - start;
12248 if (addr > bp_location_placed_address_before_address_max)
12249 bp_location_placed_address_before_address_max = addr;
12251 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12253 gdb_assert (bl->address < end);
12254 addr = end - bl->address;
12255 if (addr > bp_location_shadow_len_after_address_max)
12256 bp_location_shadow_len_after_address_max = addr;
12260 /* Download tracepoint locations if they haven't been. */
12263 download_tracepoint_locations (void)
12265 struct breakpoint *b;
12266 struct cleanup *old_chain;
12267 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
12269 old_chain = save_current_space_and_thread ();
12271 ALL_TRACEPOINTS (b)
12273 struct bp_location *bl;
12274 struct tracepoint *t;
12275 int bp_location_downloaded = 0;
12277 if ((b->type == bp_fast_tracepoint
12278 ? !may_insert_fast_tracepoints
12279 : !may_insert_tracepoints))
12282 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
12284 if (target_can_download_tracepoint ())
12285 can_download_tracepoint = TRIBOOL_TRUE;
12287 can_download_tracepoint = TRIBOOL_FALSE;
12290 if (can_download_tracepoint == TRIBOOL_FALSE)
12293 for (bl = b->loc; bl; bl = bl->next)
12295 /* In tracepoint, locations are _never_ duplicated, so
12296 should_be_inserted is equivalent to
12297 unduplicated_should_be_inserted. */
12298 if (!should_be_inserted (bl) || bl->inserted)
12301 switch_to_program_space_and_thread (bl->pspace);
12303 target_download_tracepoint (bl);
12306 bp_location_downloaded = 1;
12308 t = (struct tracepoint *) b;
12309 t->number_on_target = b->number;
12310 if (bp_location_downloaded)
12311 observer_notify_breakpoint_modified (b);
12314 do_cleanups (old_chain);
12317 /* Swap the insertion/duplication state between two locations. */
12320 swap_insertion (struct bp_location *left, struct bp_location *right)
12322 const int left_inserted = left->inserted;
12323 const int left_duplicate = left->duplicate;
12324 const int left_needs_update = left->needs_update;
12325 const struct bp_target_info left_target_info = left->target_info;
12327 /* Locations of tracepoints can never be duplicated. */
12328 if (is_tracepoint (left->owner))
12329 gdb_assert (!left->duplicate);
12330 if (is_tracepoint (right->owner))
12331 gdb_assert (!right->duplicate);
12333 left->inserted = right->inserted;
12334 left->duplicate = right->duplicate;
12335 left->needs_update = right->needs_update;
12336 left->target_info = right->target_info;
12337 right->inserted = left_inserted;
12338 right->duplicate = left_duplicate;
12339 right->needs_update = left_needs_update;
12340 right->target_info = left_target_info;
12343 /* Force the re-insertion of the locations at ADDRESS. This is called
12344 once a new/deleted/modified duplicate location is found and we are evaluating
12345 conditions on the target's side. Such conditions need to be updated on
12349 force_breakpoint_reinsertion (struct bp_location *bl)
12351 struct bp_location **locp = NULL, **loc2p;
12352 struct bp_location *loc;
12353 CORE_ADDR address = 0;
12356 address = bl->address;
12357 pspace_num = bl->pspace->num;
12359 /* This is only meaningful if the target is
12360 evaluating conditions and if the user has
12361 opted for condition evaluation on the target's
12363 if (gdb_evaluates_breakpoint_condition_p ()
12364 || !target_supports_evaluation_of_breakpoint_conditions ())
12367 /* Flag all breakpoint locations with this address and
12368 the same program space as the location
12369 as "its condition has changed". We need to
12370 update the conditions on the target's side. */
12371 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12375 if (!is_breakpoint (loc->owner)
12376 || pspace_num != loc->pspace->num)
12379 /* Flag the location appropriately. We use a different state to
12380 let everyone know that we already updated the set of locations
12381 with addr bl->address and program space bl->pspace. This is so
12382 we don't have to keep calling these functions just to mark locations
12383 that have already been marked. */
12384 loc->condition_changed = condition_updated;
12386 /* Free the agent expression bytecode as well. We will compute
12388 if (loc->cond_bytecode)
12390 free_agent_expr (loc->cond_bytecode);
12391 loc->cond_bytecode = NULL;
12395 /* Called whether new breakpoints are created, or existing breakpoints
12396 deleted, to update the global location list and recompute which
12397 locations are duplicate of which.
12399 The INSERT_MODE flag determines whether locations may not, may, or
12400 shall be inserted now. See 'enum ugll_insert_mode' for more
12404 update_global_location_list (enum ugll_insert_mode insert_mode)
12406 struct breakpoint *b;
12407 struct bp_location **locp, *loc;
12408 struct cleanup *cleanups;
12409 /* Last breakpoint location address that was marked for update. */
12410 CORE_ADDR last_addr = 0;
12411 /* Last breakpoint location program space that was marked for update. */
12412 int last_pspace_num = -1;
12414 /* Used in the duplicates detection below. When iterating over all
12415 bp_locations, points to the first bp_location of a given address.
12416 Breakpoints and watchpoints of different types are never
12417 duplicates of each other. Keep one pointer for each type of
12418 breakpoint/watchpoint, so we only need to loop over all locations
12420 struct bp_location *bp_loc_first; /* breakpoint */
12421 struct bp_location *wp_loc_first; /* hardware watchpoint */
12422 struct bp_location *awp_loc_first; /* access watchpoint */
12423 struct bp_location *rwp_loc_first; /* read watchpoint */
12425 /* Saved former bp_location array which we compare against the newly
12426 built bp_location from the current state of ALL_BREAKPOINTS. */
12427 struct bp_location **old_location, **old_locp;
12428 unsigned old_location_count;
12430 old_location = bp_location;
12431 old_location_count = bp_location_count;
12432 bp_location = NULL;
12433 bp_location_count = 0;
12434 cleanups = make_cleanup (xfree, old_location);
12436 ALL_BREAKPOINTS (b)
12437 for (loc = b->loc; loc; loc = loc->next)
12438 bp_location_count++;
12440 bp_location = XNEWVEC (struct bp_location *, bp_location_count);
12441 locp = bp_location;
12442 ALL_BREAKPOINTS (b)
12443 for (loc = b->loc; loc; loc = loc->next)
12445 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12446 bp_location_compare);
12448 bp_location_target_extensions_update ();
12450 /* Identify bp_location instances that are no longer present in the
12451 new list, and therefore should be freed. Note that it's not
12452 necessary that those locations should be removed from inferior --
12453 if there's another location at the same address (previously
12454 marked as duplicate), we don't need to remove/insert the
12457 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12458 and former bp_location array state respectively. */
12460 locp = bp_location;
12461 for (old_locp = old_location; old_locp < old_location + old_location_count;
12464 struct bp_location *old_loc = *old_locp;
12465 struct bp_location **loc2p;
12467 /* Tells if 'old_loc' is found among the new locations. If
12468 not, we have to free it. */
12469 int found_object = 0;
12470 /* Tells if the location should remain inserted in the target. */
12471 int keep_in_target = 0;
12474 /* Skip LOCP entries which will definitely never be needed.
12475 Stop either at or being the one matching OLD_LOC. */
12476 while (locp < bp_location + bp_location_count
12477 && (*locp)->address < old_loc->address)
12481 (loc2p < bp_location + bp_location_count
12482 && (*loc2p)->address == old_loc->address);
12485 /* Check if this is a new/duplicated location or a duplicated
12486 location that had its condition modified. If so, we want to send
12487 its condition to the target if evaluation of conditions is taking
12489 if ((*loc2p)->condition_changed == condition_modified
12490 && (last_addr != old_loc->address
12491 || last_pspace_num != old_loc->pspace->num))
12493 force_breakpoint_reinsertion (*loc2p);
12494 last_pspace_num = old_loc->pspace->num;
12497 if (*loc2p == old_loc)
12501 /* We have already handled this address, update it so that we don't
12502 have to go through updates again. */
12503 last_addr = old_loc->address;
12505 /* Target-side condition evaluation: Handle deleted locations. */
12507 force_breakpoint_reinsertion (old_loc);
12509 /* If this location is no longer present, and inserted, look if
12510 there's maybe a new location at the same address. If so,
12511 mark that one inserted, and don't remove this one. This is
12512 needed so that we don't have a time window where a breakpoint
12513 at certain location is not inserted. */
12515 if (old_loc->inserted)
12517 /* If the location is inserted now, we might have to remove
12520 if (found_object && should_be_inserted (old_loc))
12522 /* The location is still present in the location list,
12523 and still should be inserted. Don't do anything. */
12524 keep_in_target = 1;
12528 /* This location still exists, but it won't be kept in the
12529 target since it may have been disabled. We proceed to
12530 remove its target-side condition. */
12532 /* The location is either no longer present, or got
12533 disabled. See if there's another location at the
12534 same address, in which case we don't need to remove
12535 this one from the target. */
12537 /* OLD_LOC comes from existing struct breakpoint. */
12538 if (breakpoint_address_is_meaningful (old_loc->owner))
12541 (loc2p < bp_location + bp_location_count
12542 && (*loc2p)->address == old_loc->address);
12545 struct bp_location *loc2 = *loc2p;
12547 if (breakpoint_locations_match (loc2, old_loc))
12549 /* Read watchpoint locations are switched to
12550 access watchpoints, if the former are not
12551 supported, but the latter are. */
12552 if (is_hardware_watchpoint (old_loc->owner))
12554 gdb_assert (is_hardware_watchpoint (loc2->owner));
12555 loc2->watchpoint_type = old_loc->watchpoint_type;
12558 /* loc2 is a duplicated location. We need to check
12559 if it should be inserted in case it will be
12561 if (loc2 != old_loc
12562 && unduplicated_should_be_inserted (loc2))
12564 swap_insertion (old_loc, loc2);
12565 keep_in_target = 1;
12573 if (!keep_in_target)
12575 if (remove_breakpoint (old_loc, mark_uninserted))
12577 /* This is just about all we can do. We could keep
12578 this location on the global list, and try to
12579 remove it next time, but there's no particular
12580 reason why we will succeed next time.
12582 Note that at this point, old_loc->owner is still
12583 valid, as delete_breakpoint frees the breakpoint
12584 only after calling us. */
12585 printf_filtered (_("warning: Error removing "
12586 "breakpoint %d\n"),
12587 old_loc->owner->number);
12595 if (removed && target_is_non_stop_p ()
12596 && need_moribund_for_location_type (old_loc))
12598 /* This location was removed from the target. In
12599 non-stop mode, a race condition is possible where
12600 we've removed a breakpoint, but stop events for that
12601 breakpoint are already queued and will arrive later.
12602 We apply an heuristic to be able to distinguish such
12603 SIGTRAPs from other random SIGTRAPs: we keep this
12604 breakpoint location for a bit, and will retire it
12605 after we see some number of events. The theory here
12606 is that reporting of events should, "on the average",
12607 be fair, so after a while we'll see events from all
12608 threads that have anything of interest, and no longer
12609 need to keep this breakpoint location around. We
12610 don't hold locations forever so to reduce chances of
12611 mistaking a non-breakpoint SIGTRAP for a breakpoint
12614 The heuristic failing can be disastrous on
12615 decr_pc_after_break targets.
12617 On decr_pc_after_break targets, like e.g., x86-linux,
12618 if we fail to recognize a late breakpoint SIGTRAP,
12619 because events_till_retirement has reached 0 too
12620 soon, we'll fail to do the PC adjustment, and report
12621 a random SIGTRAP to the user. When the user resumes
12622 the inferior, it will most likely immediately crash
12623 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12624 corrupted, because of being resumed e.g., in the
12625 middle of a multi-byte instruction, or skipped a
12626 one-byte instruction. This was actually seen happen
12627 on native x86-linux, and should be less rare on
12628 targets that do not support new thread events, like
12629 remote, due to the heuristic depending on
12632 Mistaking a random SIGTRAP for a breakpoint trap
12633 causes similar symptoms (PC adjustment applied when
12634 it shouldn't), but then again, playing with SIGTRAPs
12635 behind the debugger's back is asking for trouble.
12637 Since hardware watchpoint traps are always
12638 distinguishable from other traps, so we don't need to
12639 apply keep hardware watchpoint moribund locations
12640 around. We simply always ignore hardware watchpoint
12641 traps we can no longer explain. */
12643 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12644 old_loc->owner = NULL;
12646 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12650 old_loc->owner = NULL;
12651 decref_bp_location (&old_loc);
12656 /* Rescan breakpoints at the same address and section, marking the
12657 first one as "first" and any others as "duplicates". This is so
12658 that the bpt instruction is only inserted once. If we have a
12659 permanent breakpoint at the same place as BPT, make that one the
12660 official one, and the rest as duplicates. Permanent breakpoints
12661 are sorted first for the same address.
12663 Do the same for hardware watchpoints, but also considering the
12664 watchpoint's type (regular/access/read) and length. */
12666 bp_loc_first = NULL;
12667 wp_loc_first = NULL;
12668 awp_loc_first = NULL;
12669 rwp_loc_first = NULL;
12670 ALL_BP_LOCATIONS (loc, locp)
12672 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12674 struct bp_location **loc_first_p;
12677 if (!unduplicated_should_be_inserted (loc)
12678 || !breakpoint_address_is_meaningful (b)
12679 /* Don't detect duplicate for tracepoint locations because they are
12680 never duplicated. See the comments in field `duplicate' of
12681 `struct bp_location'. */
12682 || is_tracepoint (b))
12684 /* Clear the condition modification flag. */
12685 loc->condition_changed = condition_unchanged;
12689 if (b->type == bp_hardware_watchpoint)
12690 loc_first_p = &wp_loc_first;
12691 else if (b->type == bp_read_watchpoint)
12692 loc_first_p = &rwp_loc_first;
12693 else if (b->type == bp_access_watchpoint)
12694 loc_first_p = &awp_loc_first;
12696 loc_first_p = &bp_loc_first;
12698 if (*loc_first_p == NULL
12699 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12700 || !breakpoint_locations_match (loc, *loc_first_p))
12702 *loc_first_p = loc;
12703 loc->duplicate = 0;
12705 if (is_breakpoint (loc->owner) && loc->condition_changed)
12707 loc->needs_update = 1;
12708 /* Clear the condition modification flag. */
12709 loc->condition_changed = condition_unchanged;
12715 /* This and the above ensure the invariant that the first location
12716 is not duplicated, and is the inserted one.
12717 All following are marked as duplicated, and are not inserted. */
12719 swap_insertion (loc, *loc_first_p);
12720 loc->duplicate = 1;
12722 /* Clear the condition modification flag. */
12723 loc->condition_changed = condition_unchanged;
12726 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12728 if (insert_mode != UGLL_DONT_INSERT)
12729 insert_breakpoint_locations ();
12732 /* Even though the caller told us to not insert new
12733 locations, we may still need to update conditions on the
12734 target's side of breakpoints that were already inserted
12735 if the target is evaluating breakpoint conditions. We
12736 only update conditions for locations that are marked
12738 update_inserted_breakpoint_locations ();
12742 if (insert_mode != UGLL_DONT_INSERT)
12743 download_tracepoint_locations ();
12745 do_cleanups (cleanups);
12749 breakpoint_retire_moribund (void)
12751 struct bp_location *loc;
12754 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12755 if (--(loc->events_till_retirement) == 0)
12757 decref_bp_location (&loc);
12758 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12764 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12769 update_global_location_list (insert_mode);
12771 CATCH (e, RETURN_MASK_ERROR)
12777 /* Clear BKP from a BPS. */
12780 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12784 for (bs = bps; bs; bs = bs->next)
12785 if (bs->breakpoint_at == bpt)
12787 bs->breakpoint_at = NULL;
12788 bs->old_val = NULL;
12789 /* bs->commands will be freed later. */
12793 /* Callback for iterate_over_threads. */
12795 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12797 struct breakpoint *bpt = (struct breakpoint *) data;
12799 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12803 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12807 say_where (struct breakpoint *b)
12809 struct value_print_options opts;
12811 get_user_print_options (&opts);
12813 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12815 if (b->loc == NULL)
12817 /* For pending locations, the output differs slightly based
12818 on b->extra_string. If this is non-NULL, it contains either
12819 a condition or dprintf arguments. */
12820 if (b->extra_string == NULL)
12822 printf_filtered (_(" (%s) pending."),
12823 event_location_to_string (b->location));
12825 else if (b->type == bp_dprintf)
12827 printf_filtered (_(" (%s,%s) pending."),
12828 event_location_to_string (b->location),
12833 printf_filtered (_(" (%s %s) pending."),
12834 event_location_to_string (b->location),
12840 if (opts.addressprint || b->loc->symtab == NULL)
12842 printf_filtered (" at ");
12843 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12846 if (b->loc->symtab != NULL)
12848 /* If there is a single location, we can print the location
12850 if (b->loc->next == NULL)
12851 printf_filtered (": file %s, line %d.",
12852 symtab_to_filename_for_display (b->loc->symtab),
12853 b->loc->line_number);
12855 /* This is not ideal, but each location may have a
12856 different file name, and this at least reflects the
12857 real situation somewhat. */
12858 printf_filtered (": %s.",
12859 event_location_to_string (b->location));
12864 struct bp_location *loc = b->loc;
12866 for (; loc; loc = loc->next)
12868 printf_filtered (" (%d locations)", n);
12873 /* Default bp_location_ops methods. */
12876 bp_location_dtor (struct bp_location *self)
12878 xfree (self->cond);
12879 if (self->cond_bytecode)
12880 free_agent_expr (self->cond_bytecode);
12881 xfree (self->function_name);
12883 VEC_free (agent_expr_p, self->target_info.conditions);
12884 VEC_free (agent_expr_p, self->target_info.tcommands);
12887 static const struct bp_location_ops bp_location_ops =
12892 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12896 base_breakpoint_dtor (struct breakpoint *self)
12898 decref_counted_command_line (&self->commands);
12899 xfree (self->cond_string);
12900 xfree (self->extra_string);
12901 xfree (self->filter);
12902 delete_event_location (self->location);
12903 delete_event_location (self->location_range_end);
12906 static struct bp_location *
12907 base_breakpoint_allocate_location (struct breakpoint *self)
12909 struct bp_location *loc;
12911 loc = XNEW (struct bp_location);
12912 init_bp_location (loc, &bp_location_ops, self);
12917 base_breakpoint_re_set (struct breakpoint *b)
12919 /* Nothing to re-set. */
12922 #define internal_error_pure_virtual_called() \
12923 gdb_assert_not_reached ("pure virtual function called")
12926 base_breakpoint_insert_location (struct bp_location *bl)
12928 internal_error_pure_virtual_called ();
12932 base_breakpoint_remove_location (struct bp_location *bl)
12934 internal_error_pure_virtual_called ();
12938 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12939 struct address_space *aspace,
12941 const struct target_waitstatus *ws)
12943 internal_error_pure_virtual_called ();
12947 base_breakpoint_check_status (bpstat bs)
12952 /* A "works_in_software_mode" breakpoint_ops method that just internal
12956 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12958 internal_error_pure_virtual_called ();
12961 /* A "resources_needed" breakpoint_ops method that just internal
12965 base_breakpoint_resources_needed (const struct bp_location *bl)
12967 internal_error_pure_virtual_called ();
12970 static enum print_stop_action
12971 base_breakpoint_print_it (bpstat bs)
12973 internal_error_pure_virtual_called ();
12977 base_breakpoint_print_one_detail (const struct breakpoint *self,
12978 struct ui_out *uiout)
12984 base_breakpoint_print_mention (struct breakpoint *b)
12986 internal_error_pure_virtual_called ();
12990 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12992 internal_error_pure_virtual_called ();
12996 base_breakpoint_create_sals_from_location
12997 (const struct event_location *location,
12998 struct linespec_result *canonical,
12999 enum bptype type_wanted)
13001 internal_error_pure_virtual_called ();
13005 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13006 struct linespec_result *c,
13008 char *extra_string,
13009 enum bptype type_wanted,
13010 enum bpdisp disposition,
13012 int task, int ignore_count,
13013 const struct breakpoint_ops *o,
13014 int from_tty, int enabled,
13015 int internal, unsigned flags)
13017 internal_error_pure_virtual_called ();
13021 base_breakpoint_decode_location (struct breakpoint *b,
13022 const struct event_location *location,
13023 struct program_space *search_pspace,
13024 struct symtabs_and_lines *sals)
13026 internal_error_pure_virtual_called ();
13029 /* The default 'explains_signal' method. */
13032 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13037 /* The default "after_condition_true" method. */
13040 base_breakpoint_after_condition_true (struct bpstats *bs)
13042 /* Nothing to do. */
13045 struct breakpoint_ops base_breakpoint_ops =
13047 base_breakpoint_dtor,
13048 base_breakpoint_allocate_location,
13049 base_breakpoint_re_set,
13050 base_breakpoint_insert_location,
13051 base_breakpoint_remove_location,
13052 base_breakpoint_breakpoint_hit,
13053 base_breakpoint_check_status,
13054 base_breakpoint_resources_needed,
13055 base_breakpoint_works_in_software_mode,
13056 base_breakpoint_print_it,
13058 base_breakpoint_print_one_detail,
13059 base_breakpoint_print_mention,
13060 base_breakpoint_print_recreate,
13061 base_breakpoint_create_sals_from_location,
13062 base_breakpoint_create_breakpoints_sal,
13063 base_breakpoint_decode_location,
13064 base_breakpoint_explains_signal,
13065 base_breakpoint_after_condition_true,
13068 /* Default breakpoint_ops methods. */
13071 bkpt_re_set (struct breakpoint *b)
13073 /* FIXME: is this still reachable? */
13074 if (breakpoint_event_location_empty_p (b))
13076 /* Anything without a location can't be re-set. */
13077 delete_breakpoint (b);
13081 breakpoint_re_set_default (b);
13085 bkpt_insert_location (struct bp_location *bl)
13087 if (bl->loc_type == bp_loc_hardware_breakpoint)
13088 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
13090 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
13094 bkpt_remove_location (struct bp_location *bl)
13096 if (bl->loc_type == bp_loc_hardware_breakpoint)
13097 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13099 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13103 bkpt_breakpoint_hit (const struct bp_location *bl,
13104 struct address_space *aspace, CORE_ADDR bp_addr,
13105 const struct target_waitstatus *ws)
13107 if (ws->kind != TARGET_WAITKIND_STOPPED
13108 || ws->value.sig != GDB_SIGNAL_TRAP)
13111 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13115 if (overlay_debugging /* unmapped overlay section */
13116 && section_is_overlay (bl->section)
13117 && !section_is_mapped (bl->section))
13124 dprintf_breakpoint_hit (const struct bp_location *bl,
13125 struct address_space *aspace, CORE_ADDR bp_addr,
13126 const struct target_waitstatus *ws)
13128 if (dprintf_style == dprintf_style_agent
13129 && target_can_run_breakpoint_commands ())
13131 /* An agent-style dprintf never causes a stop. If we see a trap
13132 for this address it must be for a breakpoint that happens to
13133 be set at the same address. */
13137 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13141 bkpt_resources_needed (const struct bp_location *bl)
13143 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13148 static enum print_stop_action
13149 bkpt_print_it (bpstat bs)
13151 struct breakpoint *b;
13152 const struct bp_location *bl;
13154 struct ui_out *uiout = current_uiout;
13156 gdb_assert (bs->bp_location_at != NULL);
13158 bl = bs->bp_location_at;
13159 b = bs->breakpoint_at;
13161 bp_temp = b->disposition == disp_del;
13162 if (bl->address != bl->requested_address)
13163 breakpoint_adjustment_warning (bl->requested_address,
13166 annotate_breakpoint (b->number);
13167 maybe_print_thread_hit_breakpoint (uiout);
13170 ui_out_text (uiout, "Temporary breakpoint ");
13172 ui_out_text (uiout, "Breakpoint ");
13173 if (ui_out_is_mi_like_p (uiout))
13175 ui_out_field_string (uiout, "reason",
13176 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13177 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13179 ui_out_field_int (uiout, "bkptno", b->number);
13180 ui_out_text (uiout, ", ");
13182 return PRINT_SRC_AND_LOC;
13186 bkpt_print_mention (struct breakpoint *b)
13188 if (ui_out_is_mi_like_p (current_uiout))
13193 case bp_breakpoint:
13194 case bp_gnu_ifunc_resolver:
13195 if (b->disposition == disp_del)
13196 printf_filtered (_("Temporary breakpoint"));
13198 printf_filtered (_("Breakpoint"));
13199 printf_filtered (_(" %d"), b->number);
13200 if (b->type == bp_gnu_ifunc_resolver)
13201 printf_filtered (_(" at gnu-indirect-function resolver"));
13203 case bp_hardware_breakpoint:
13204 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13207 printf_filtered (_("Dprintf %d"), b->number);
13215 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13217 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13218 fprintf_unfiltered (fp, "tbreak");
13219 else if (tp->type == bp_breakpoint)
13220 fprintf_unfiltered (fp, "break");
13221 else if (tp->type == bp_hardware_breakpoint
13222 && tp->disposition == disp_del)
13223 fprintf_unfiltered (fp, "thbreak");
13224 else if (tp->type == bp_hardware_breakpoint)
13225 fprintf_unfiltered (fp, "hbreak");
13227 internal_error (__FILE__, __LINE__,
13228 _("unhandled breakpoint type %d"), (int) tp->type);
13230 fprintf_unfiltered (fp, " %s",
13231 event_location_to_string (tp->location));
13233 /* Print out extra_string if this breakpoint is pending. It might
13234 contain, for example, conditions that were set by the user. */
13235 if (tp->loc == NULL && tp->extra_string != NULL)
13236 fprintf_unfiltered (fp, " %s", tp->extra_string);
13238 print_recreate_thread (tp, fp);
13242 bkpt_create_sals_from_location (const struct event_location *location,
13243 struct linespec_result *canonical,
13244 enum bptype type_wanted)
13246 create_sals_from_location_default (location, canonical, type_wanted);
13250 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13251 struct linespec_result *canonical,
13253 char *extra_string,
13254 enum bptype type_wanted,
13255 enum bpdisp disposition,
13257 int task, int ignore_count,
13258 const struct breakpoint_ops *ops,
13259 int from_tty, int enabled,
13260 int internal, unsigned flags)
13262 create_breakpoints_sal_default (gdbarch, canonical,
13263 cond_string, extra_string,
13265 disposition, thread, task,
13266 ignore_count, ops, from_tty,
13267 enabled, internal, flags);
13271 bkpt_decode_location (struct breakpoint *b,
13272 const struct event_location *location,
13273 struct program_space *search_pspace,
13274 struct symtabs_and_lines *sals)
13276 decode_location_default (b, location, search_pspace, sals);
13279 /* Virtual table for internal breakpoints. */
13282 internal_bkpt_re_set (struct breakpoint *b)
13286 /* Delete overlay event and longjmp master breakpoints; they
13287 will be reset later by breakpoint_re_set. */
13288 case bp_overlay_event:
13289 case bp_longjmp_master:
13290 case bp_std_terminate_master:
13291 case bp_exception_master:
13292 delete_breakpoint (b);
13295 /* This breakpoint is special, it's set up when the inferior
13296 starts and we really don't want to touch it. */
13297 case bp_shlib_event:
13299 /* Like bp_shlib_event, this breakpoint type is special. Once
13300 it is set up, we do not want to touch it. */
13301 case bp_thread_event:
13307 internal_bkpt_check_status (bpstat bs)
13309 if (bs->breakpoint_at->type == bp_shlib_event)
13311 /* If requested, stop when the dynamic linker notifies GDB of
13312 events. This allows the user to get control and place
13313 breakpoints in initializer routines for dynamically loaded
13314 objects (among other things). */
13315 bs->stop = stop_on_solib_events;
13316 bs->print = stop_on_solib_events;
13322 static enum print_stop_action
13323 internal_bkpt_print_it (bpstat bs)
13325 struct breakpoint *b;
13327 b = bs->breakpoint_at;
13331 case bp_shlib_event:
13332 /* Did we stop because the user set the stop_on_solib_events
13333 variable? (If so, we report this as a generic, "Stopped due
13334 to shlib event" message.) */
13335 print_solib_event (0);
13338 case bp_thread_event:
13339 /* Not sure how we will get here.
13340 GDB should not stop for these breakpoints. */
13341 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13344 case bp_overlay_event:
13345 /* By analogy with the thread event, GDB should not stop for these. */
13346 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13349 case bp_longjmp_master:
13350 /* These should never be enabled. */
13351 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13354 case bp_std_terminate_master:
13355 /* These should never be enabled. */
13356 printf_filtered (_("std::terminate Master Breakpoint: "
13357 "gdb should not stop!\n"));
13360 case bp_exception_master:
13361 /* These should never be enabled. */
13362 printf_filtered (_("Exception Master Breakpoint: "
13363 "gdb should not stop!\n"));
13367 return PRINT_NOTHING;
13371 internal_bkpt_print_mention (struct breakpoint *b)
13373 /* Nothing to mention. These breakpoints are internal. */
13376 /* Virtual table for momentary breakpoints */
13379 momentary_bkpt_re_set (struct breakpoint *b)
13381 /* Keep temporary breakpoints, which can be encountered when we step
13382 over a dlopen call and solib_add is resetting the breakpoints.
13383 Otherwise these should have been blown away via the cleanup chain
13384 or by breakpoint_init_inferior when we rerun the executable. */
13388 momentary_bkpt_check_status (bpstat bs)
13390 /* Nothing. The point of these breakpoints is causing a stop. */
13393 static enum print_stop_action
13394 momentary_bkpt_print_it (bpstat bs)
13396 return PRINT_UNKNOWN;
13400 momentary_bkpt_print_mention (struct breakpoint *b)
13402 /* Nothing to mention. These breakpoints are internal. */
13405 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13407 It gets cleared already on the removal of the first one of such placed
13408 breakpoints. This is OK as they get all removed altogether. */
13411 longjmp_bkpt_dtor (struct breakpoint *self)
13413 struct thread_info *tp = find_thread_global_id (self->thread);
13416 tp->initiating_frame = null_frame_id;
13418 momentary_breakpoint_ops.dtor (self);
13421 /* Specific methods for probe breakpoints. */
13424 bkpt_probe_insert_location (struct bp_location *bl)
13426 int v = bkpt_insert_location (bl);
13430 /* The insertion was successful, now let's set the probe's semaphore
13432 if (bl->probe.probe->pops->set_semaphore != NULL)
13433 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13442 bkpt_probe_remove_location (struct bp_location *bl)
13444 /* Let's clear the semaphore before removing the location. */
13445 if (bl->probe.probe->pops->clear_semaphore != NULL)
13446 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13450 return bkpt_remove_location (bl);
13454 bkpt_probe_create_sals_from_location (const struct event_location *location,
13455 struct linespec_result *canonical,
13456 enum bptype type_wanted)
13458 struct linespec_sals lsal;
13460 lsal.sals = parse_probes (location, NULL, canonical);
13461 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13462 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13466 bkpt_probe_decode_location (struct breakpoint *b,
13467 const struct event_location *location,
13468 struct program_space *search_pspace,
13469 struct symtabs_and_lines *sals)
13471 *sals = parse_probes (location, search_pspace, NULL);
13473 error (_("probe not found"));
13476 /* The breakpoint_ops structure to be used in tracepoints. */
13479 tracepoint_re_set (struct breakpoint *b)
13481 breakpoint_re_set_default (b);
13485 tracepoint_breakpoint_hit (const struct bp_location *bl,
13486 struct address_space *aspace, CORE_ADDR bp_addr,
13487 const struct target_waitstatus *ws)
13489 /* By definition, the inferior does not report stops at
13495 tracepoint_print_one_detail (const struct breakpoint *self,
13496 struct ui_out *uiout)
13498 struct tracepoint *tp = (struct tracepoint *) self;
13499 if (tp->static_trace_marker_id)
13501 gdb_assert (self->type == bp_static_tracepoint);
13503 ui_out_text (uiout, "\tmarker id is ");
13504 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13505 tp->static_trace_marker_id);
13506 ui_out_text (uiout, "\n");
13511 tracepoint_print_mention (struct breakpoint *b)
13513 if (ui_out_is_mi_like_p (current_uiout))
13518 case bp_tracepoint:
13519 printf_filtered (_("Tracepoint"));
13520 printf_filtered (_(" %d"), b->number);
13522 case bp_fast_tracepoint:
13523 printf_filtered (_("Fast tracepoint"));
13524 printf_filtered (_(" %d"), b->number);
13526 case bp_static_tracepoint:
13527 printf_filtered (_("Static tracepoint"));
13528 printf_filtered (_(" %d"), b->number);
13531 internal_error (__FILE__, __LINE__,
13532 _("unhandled tracepoint type %d"), (int) b->type);
13539 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13541 struct tracepoint *tp = (struct tracepoint *) self;
13543 if (self->type == bp_fast_tracepoint)
13544 fprintf_unfiltered (fp, "ftrace");
13545 else if (self->type == bp_static_tracepoint)
13546 fprintf_unfiltered (fp, "strace");
13547 else if (self->type == bp_tracepoint)
13548 fprintf_unfiltered (fp, "trace");
13550 internal_error (__FILE__, __LINE__,
13551 _("unhandled tracepoint type %d"), (int) self->type);
13553 fprintf_unfiltered (fp, " %s",
13554 event_location_to_string (self->location));
13555 print_recreate_thread (self, fp);
13557 if (tp->pass_count)
13558 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13562 tracepoint_create_sals_from_location (const struct event_location *location,
13563 struct linespec_result *canonical,
13564 enum bptype type_wanted)
13566 create_sals_from_location_default (location, canonical, type_wanted);
13570 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13571 struct linespec_result *canonical,
13573 char *extra_string,
13574 enum bptype type_wanted,
13575 enum bpdisp disposition,
13577 int task, int ignore_count,
13578 const struct breakpoint_ops *ops,
13579 int from_tty, int enabled,
13580 int internal, unsigned flags)
13582 create_breakpoints_sal_default (gdbarch, canonical,
13583 cond_string, extra_string,
13585 disposition, thread, task,
13586 ignore_count, ops, from_tty,
13587 enabled, internal, flags);
13591 tracepoint_decode_location (struct breakpoint *b,
13592 const struct event_location *location,
13593 struct program_space *search_pspace,
13594 struct symtabs_and_lines *sals)
13596 decode_location_default (b, location, search_pspace, sals);
13599 struct breakpoint_ops tracepoint_breakpoint_ops;
13601 /* The breakpoint_ops structure to be use on tracepoints placed in a
13605 tracepoint_probe_create_sals_from_location
13606 (const struct event_location *location,
13607 struct linespec_result *canonical,
13608 enum bptype type_wanted)
13610 /* We use the same method for breakpoint on probes. */
13611 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
13615 tracepoint_probe_decode_location (struct breakpoint *b,
13616 const struct event_location *location,
13617 struct program_space *search_pspace,
13618 struct symtabs_and_lines *sals)
13620 /* We use the same method for breakpoint on probes. */
13621 bkpt_probe_decode_location (b, location, search_pspace, sals);
13624 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13626 /* Dprintf breakpoint_ops methods. */
13629 dprintf_re_set (struct breakpoint *b)
13631 breakpoint_re_set_default (b);
13633 /* extra_string should never be non-NULL for dprintf. */
13634 gdb_assert (b->extra_string != NULL);
13636 /* 1 - connect to target 1, that can run breakpoint commands.
13637 2 - create a dprintf, which resolves fine.
13638 3 - disconnect from target 1
13639 4 - connect to target 2, that can NOT run breakpoint commands.
13641 After steps #3/#4, you'll want the dprintf command list to
13642 be updated, because target 1 and 2 may well return different
13643 answers for target_can_run_breakpoint_commands().
13644 Given absence of finer grained resetting, we get to do
13645 it all the time. */
13646 if (b->extra_string != NULL)
13647 update_dprintf_command_list (b);
13650 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13653 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13655 fprintf_unfiltered (fp, "dprintf %s,%s",
13656 event_location_to_string (tp->location),
13658 print_recreate_thread (tp, fp);
13661 /* Implement the "after_condition_true" breakpoint_ops method for
13664 dprintf's are implemented with regular commands in their command
13665 list, but we run the commands here instead of before presenting the
13666 stop to the user, as dprintf's don't actually cause a stop. This
13667 also makes it so that the commands of multiple dprintfs at the same
13668 address are all handled. */
13671 dprintf_after_condition_true (struct bpstats *bs)
13673 struct cleanup *old_chain;
13674 struct bpstats tmp_bs = { NULL };
13675 struct bpstats *tmp_bs_p = &tmp_bs;
13677 /* dprintf's never cause a stop. This wasn't set in the
13678 check_status hook instead because that would make the dprintf's
13679 condition not be evaluated. */
13682 /* Run the command list here. Take ownership of it instead of
13683 copying. We never want these commands to run later in
13684 bpstat_do_actions, if a breakpoint that causes a stop happens to
13685 be set at same address as this dprintf, or even if running the
13686 commands here throws. */
13687 tmp_bs.commands = bs->commands;
13688 bs->commands = NULL;
13689 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13691 bpstat_do_actions_1 (&tmp_bs_p);
13693 /* 'tmp_bs.commands' will usually be NULL by now, but
13694 bpstat_do_actions_1 may return early without processing the whole
13696 do_cleanups (old_chain);
13699 /* The breakpoint_ops structure to be used on static tracepoints with
13703 strace_marker_create_sals_from_location (const struct event_location *location,
13704 struct linespec_result *canonical,
13705 enum bptype type_wanted)
13707 struct linespec_sals lsal;
13708 const char *arg_start, *arg;
13710 struct cleanup *cleanup;
13712 arg = arg_start = get_linespec_location (location);
13713 lsal.sals = decode_static_tracepoint_spec (&arg);
13715 str = savestring (arg_start, arg - arg_start);
13716 cleanup = make_cleanup (xfree, str);
13717 canonical->location = new_linespec_location (&str);
13718 do_cleanups (cleanup);
13720 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13721 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13725 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13726 struct linespec_result *canonical,
13728 char *extra_string,
13729 enum bptype type_wanted,
13730 enum bpdisp disposition,
13732 int task, int ignore_count,
13733 const struct breakpoint_ops *ops,
13734 int from_tty, int enabled,
13735 int internal, unsigned flags)
13738 struct linespec_sals *lsal = VEC_index (linespec_sals,
13739 canonical->sals, 0);
13741 /* If the user is creating a static tracepoint by marker id
13742 (strace -m MARKER_ID), then store the sals index, so that
13743 breakpoint_re_set can try to match up which of the newly
13744 found markers corresponds to this one, and, don't try to
13745 expand multiple locations for each sal, given than SALS
13746 already should contain all sals for MARKER_ID. */
13748 for (i = 0; i < lsal->sals.nelts; ++i)
13750 struct symtabs_and_lines expanded;
13751 struct tracepoint *tp;
13752 struct cleanup *old_chain;
13753 struct event_location *location;
13755 expanded.nelts = 1;
13756 expanded.sals = &lsal->sals.sals[i];
13758 location = copy_event_location (canonical->location);
13759 old_chain = make_cleanup_delete_event_location (location);
13761 tp = XCNEW (struct tracepoint);
13762 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13764 cond_string, extra_string,
13765 type_wanted, disposition,
13766 thread, task, ignore_count, ops,
13767 from_tty, enabled, internal, flags,
13768 canonical->special_display);
13769 /* Given that its possible to have multiple markers with
13770 the same string id, if the user is creating a static
13771 tracepoint by marker id ("strace -m MARKER_ID"), then
13772 store the sals index, so that breakpoint_re_set can
13773 try to match up which of the newly found markers
13774 corresponds to this one */
13775 tp->static_trace_marker_id_idx = i;
13777 install_breakpoint (internal, &tp->base, 0);
13779 discard_cleanups (old_chain);
13784 strace_marker_decode_location (struct breakpoint *b,
13785 const struct event_location *location,
13786 struct program_space *search_pspace,
13787 struct symtabs_and_lines *sals)
13789 struct tracepoint *tp = (struct tracepoint *) b;
13790 const char *s = get_linespec_location (location);
13792 *sals = decode_static_tracepoint_spec (&s);
13793 if (sals->nelts > tp->static_trace_marker_id_idx)
13795 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13799 error (_("marker %s not found"), tp->static_trace_marker_id);
13802 static struct breakpoint_ops strace_marker_breakpoint_ops;
13805 strace_marker_p (struct breakpoint *b)
13807 return b->ops == &strace_marker_breakpoint_ops;
13810 /* Delete a breakpoint and clean up all traces of it in the data
13814 delete_breakpoint (struct breakpoint *bpt)
13816 struct breakpoint *b;
13818 gdb_assert (bpt != NULL);
13820 /* Has this bp already been deleted? This can happen because
13821 multiple lists can hold pointers to bp's. bpstat lists are
13824 One example of this happening is a watchpoint's scope bp. When
13825 the scope bp triggers, we notice that the watchpoint is out of
13826 scope, and delete it. We also delete its scope bp. But the
13827 scope bp is marked "auto-deleting", and is already on a bpstat.
13828 That bpstat is then checked for auto-deleting bp's, which are
13831 A real solution to this problem might involve reference counts in
13832 bp's, and/or giving them pointers back to their referencing
13833 bpstat's, and teaching delete_breakpoint to only free a bp's
13834 storage when no more references were extent. A cheaper bandaid
13836 if (bpt->type == bp_none)
13839 /* At least avoid this stale reference until the reference counting
13840 of breakpoints gets resolved. */
13841 if (bpt->related_breakpoint != bpt)
13843 struct breakpoint *related;
13844 struct watchpoint *w;
13846 if (bpt->type == bp_watchpoint_scope)
13847 w = (struct watchpoint *) bpt->related_breakpoint;
13848 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13849 w = (struct watchpoint *) bpt;
13853 watchpoint_del_at_next_stop (w);
13855 /* Unlink bpt from the bpt->related_breakpoint ring. */
13856 for (related = bpt; related->related_breakpoint != bpt;
13857 related = related->related_breakpoint);
13858 related->related_breakpoint = bpt->related_breakpoint;
13859 bpt->related_breakpoint = bpt;
13862 /* watch_command_1 creates a watchpoint but only sets its number if
13863 update_watchpoint succeeds in creating its bp_locations. If there's
13864 a problem in that process, we'll be asked to delete the half-created
13865 watchpoint. In that case, don't announce the deletion. */
13867 observer_notify_breakpoint_deleted (bpt);
13869 if (breakpoint_chain == bpt)
13870 breakpoint_chain = bpt->next;
13872 ALL_BREAKPOINTS (b)
13873 if (b->next == bpt)
13875 b->next = bpt->next;
13879 /* Be sure no bpstat's are pointing at the breakpoint after it's
13881 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13882 in all threads for now. Note that we cannot just remove bpstats
13883 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13884 commands are associated with the bpstat; if we remove it here,
13885 then the later call to bpstat_do_actions (&stop_bpstat); in
13886 event-top.c won't do anything, and temporary breakpoints with
13887 commands won't work. */
13889 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13891 /* Now that breakpoint is removed from breakpoint list, update the
13892 global location list. This will remove locations that used to
13893 belong to this breakpoint. Do this before freeing the breakpoint
13894 itself, since remove_breakpoint looks at location's owner. It
13895 might be better design to have location completely
13896 self-contained, but it's not the case now. */
13897 update_global_location_list (UGLL_DONT_INSERT);
13899 bpt->ops->dtor (bpt);
13900 /* On the chance that someone will soon try again to delete this
13901 same bp, we mark it as deleted before freeing its storage. */
13902 bpt->type = bp_none;
13907 do_delete_breakpoint_cleanup (void *b)
13909 delete_breakpoint ((struct breakpoint *) b);
13913 make_cleanup_delete_breakpoint (struct breakpoint *b)
13915 return make_cleanup (do_delete_breakpoint_cleanup, b);
13918 /* Iterator function to call a user-provided callback function once
13919 for each of B and its related breakpoints. */
13922 iterate_over_related_breakpoints (struct breakpoint *b,
13923 void (*function) (struct breakpoint *,
13927 struct breakpoint *related;
13932 struct breakpoint *next;
13934 /* FUNCTION may delete RELATED. */
13935 next = related->related_breakpoint;
13937 if (next == related)
13939 /* RELATED is the last ring entry. */
13940 function (related, data);
13942 /* FUNCTION may have deleted it, so we'd never reach back to
13943 B. There's nothing left to do anyway, so just break
13948 function (related, data);
13952 while (related != b);
13956 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13958 delete_breakpoint (b);
13961 /* A callback for map_breakpoint_numbers that calls
13962 delete_breakpoint. */
13965 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13967 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13971 delete_command (char *arg, int from_tty)
13973 struct breakpoint *b, *b_tmp;
13979 int breaks_to_delete = 0;
13981 /* Delete all breakpoints if no argument. Do not delete
13982 internal breakpoints, these have to be deleted with an
13983 explicit breakpoint number argument. */
13984 ALL_BREAKPOINTS (b)
13985 if (user_breakpoint_p (b))
13987 breaks_to_delete = 1;
13991 /* Ask user only if there are some breakpoints to delete. */
13993 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13995 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13996 if (user_breakpoint_p (b))
13997 delete_breakpoint (b);
14001 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14004 /* Return true if all locations of B bound to PSPACE are pending. If
14005 PSPACE is NULL, all locations of all program spaces are
14009 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
14011 struct bp_location *loc;
14013 for (loc = b->loc; loc != NULL; loc = loc->next)
14014 if ((pspace == NULL
14015 || loc->pspace == pspace)
14016 && !loc->shlib_disabled
14017 && !loc->pspace->executing_startup)
14022 /* Subroutine of update_breakpoint_locations to simplify it.
14023 Return non-zero if multiple fns in list LOC have the same name.
14024 Null names are ignored. */
14027 ambiguous_names_p (struct bp_location *loc)
14029 struct bp_location *l;
14030 htab_t htab = htab_create_alloc (13, htab_hash_string,
14031 (int (*) (const void *,
14032 const void *)) streq,
14033 NULL, xcalloc, xfree);
14035 for (l = loc; l != NULL; l = l->next)
14038 const char *name = l->function_name;
14040 /* Allow for some names to be NULL, ignore them. */
14044 slot = (const char **) htab_find_slot (htab, (const void *) name,
14046 /* NOTE: We can assume slot != NULL here because xcalloc never
14050 htab_delete (htab);
14056 htab_delete (htab);
14060 /* When symbols change, it probably means the sources changed as well,
14061 and it might mean the static tracepoint markers are no longer at
14062 the same address or line numbers they used to be at last we
14063 checked. Losing your static tracepoints whenever you rebuild is
14064 undesirable. This function tries to resync/rematch gdb static
14065 tracepoints with the markers on the target, for static tracepoints
14066 that have not been set by marker id. Static tracepoint that have
14067 been set by marker id are reset by marker id in breakpoint_re_set.
14070 1) For a tracepoint set at a specific address, look for a marker at
14071 the old PC. If one is found there, assume to be the same marker.
14072 If the name / string id of the marker found is different from the
14073 previous known name, assume that means the user renamed the marker
14074 in the sources, and output a warning.
14076 2) For a tracepoint set at a given line number, look for a marker
14077 at the new address of the old line number. If one is found there,
14078 assume to be the same marker. If the name / string id of the
14079 marker found is different from the previous known name, assume that
14080 means the user renamed the marker in the sources, and output a
14083 3) If a marker is no longer found at the same address or line, it
14084 may mean the marker no longer exists. But it may also just mean
14085 the code changed a bit. Maybe the user added a few lines of code
14086 that made the marker move up or down (in line number terms). Ask
14087 the target for info about the marker with the string id as we knew
14088 it. If found, update line number and address in the matching
14089 static tracepoint. This will get confused if there's more than one
14090 marker with the same ID (possible in UST, although unadvised
14091 precisely because it confuses tools). */
14093 static struct symtab_and_line
14094 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14096 struct tracepoint *tp = (struct tracepoint *) b;
14097 struct static_tracepoint_marker marker;
14102 find_line_pc (sal.symtab, sal.line, &pc);
14104 if (target_static_tracepoint_marker_at (pc, &marker))
14106 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14107 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14109 tp->static_trace_marker_id, marker.str_id);
14111 xfree (tp->static_trace_marker_id);
14112 tp->static_trace_marker_id = xstrdup (marker.str_id);
14113 release_static_tracepoint_marker (&marker);
14118 /* Old marker wasn't found on target at lineno. Try looking it up
14120 if (!sal.explicit_pc
14122 && sal.symtab != NULL
14123 && tp->static_trace_marker_id != NULL)
14125 VEC(static_tracepoint_marker_p) *markers;
14128 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14130 if (!VEC_empty(static_tracepoint_marker_p, markers))
14132 struct symtab_and_line sal2;
14133 struct symbol *sym;
14134 struct static_tracepoint_marker *tpmarker;
14135 struct ui_out *uiout = current_uiout;
14136 struct explicit_location explicit_loc;
14138 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14140 xfree (tp->static_trace_marker_id);
14141 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14143 warning (_("marker for static tracepoint %d (%s) not "
14144 "found at previous line number"),
14145 b->number, tp->static_trace_marker_id);
14149 sal2.pc = tpmarker->address;
14151 sal2 = find_pc_line (tpmarker->address, 0);
14152 sym = find_pc_sect_function (tpmarker->address, NULL);
14153 ui_out_text (uiout, "Now in ");
14156 ui_out_field_string (uiout, "func",
14157 SYMBOL_PRINT_NAME (sym));
14158 ui_out_text (uiout, " at ");
14160 ui_out_field_string (uiout, "file",
14161 symtab_to_filename_for_display (sal2.symtab));
14162 ui_out_text (uiout, ":");
14164 if (ui_out_is_mi_like_p (uiout))
14166 const char *fullname = symtab_to_fullname (sal2.symtab);
14168 ui_out_field_string (uiout, "fullname", fullname);
14171 ui_out_field_int (uiout, "line", sal2.line);
14172 ui_out_text (uiout, "\n");
14174 b->loc->line_number = sal2.line;
14175 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14177 delete_event_location (b->location);
14178 initialize_explicit_location (&explicit_loc);
14179 explicit_loc.source_filename
14180 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
14181 explicit_loc.line_offset.offset = b->loc->line_number;
14182 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
14183 b->location = new_explicit_location (&explicit_loc);
14185 /* Might be nice to check if function changed, and warn if
14188 release_static_tracepoint_marker (tpmarker);
14194 /* Returns 1 iff locations A and B are sufficiently same that
14195 we don't need to report breakpoint as changed. */
14198 locations_are_equal (struct bp_location *a, struct bp_location *b)
14202 if (a->address != b->address)
14205 if (a->shlib_disabled != b->shlib_disabled)
14208 if (a->enabled != b->enabled)
14215 if ((a == NULL) != (b == NULL))
14221 /* Split all locations of B that are bound to PSPACE out of B's
14222 location list to a separate list and return that list's head. If
14223 PSPACE is NULL, hoist out all locations of B. */
14225 static struct bp_location *
14226 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
14228 struct bp_location head;
14229 struct bp_location *i = b->loc;
14230 struct bp_location **i_link = &b->loc;
14231 struct bp_location *hoisted = &head;
14233 if (pspace == NULL)
14244 if (i->pspace == pspace)
14259 /* Create new breakpoint locations for B (a hardware or software
14260 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14261 zero, then B is a ranged breakpoint. Only recreates locations for
14262 FILTER_PSPACE. Locations of other program spaces are left
14266 update_breakpoint_locations (struct breakpoint *b,
14267 struct program_space *filter_pspace,
14268 struct symtabs_and_lines sals,
14269 struct symtabs_and_lines sals_end)
14272 struct bp_location *existing_locations;
14274 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14276 /* Ranged breakpoints have only one start location and one end
14278 b->enable_state = bp_disabled;
14279 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14280 "multiple locations found\n"),
14285 /* If there's no new locations, and all existing locations are
14286 pending, don't do anything. This optimizes the common case where
14287 all locations are in the same shared library, that was unloaded.
14288 We'd like to retain the location, so that when the library is
14289 loaded again, we don't loose the enabled/disabled status of the
14290 individual locations. */
14291 if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0)
14294 existing_locations = hoist_existing_locations (b, filter_pspace);
14296 for (i = 0; i < sals.nelts; ++i)
14298 struct bp_location *new_loc;
14300 switch_to_program_space_and_thread (sals.sals[i].pspace);
14302 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14304 /* Reparse conditions, they might contain references to the
14306 if (b->cond_string != NULL)
14310 s = b->cond_string;
14313 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14314 block_for_pc (sals.sals[i].pc),
14317 CATCH (e, RETURN_MASK_ERROR)
14319 warning (_("failed to reevaluate condition "
14320 "for breakpoint %d: %s"),
14321 b->number, e.message);
14322 new_loc->enabled = 0;
14327 if (sals_end.nelts)
14329 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14331 new_loc->length = end - sals.sals[0].pc + 1;
14335 /* If possible, carry over 'disable' status from existing
14338 struct bp_location *e = existing_locations;
14339 /* If there are multiple breakpoints with the same function name,
14340 e.g. for inline functions, comparing function names won't work.
14341 Instead compare pc addresses; this is just a heuristic as things
14342 may have moved, but in practice it gives the correct answer
14343 often enough until a better solution is found. */
14344 int have_ambiguous_names = ambiguous_names_p (b->loc);
14346 for (; e; e = e->next)
14348 if (!e->enabled && e->function_name)
14350 struct bp_location *l = b->loc;
14351 if (have_ambiguous_names)
14353 for (; l; l = l->next)
14354 if (breakpoint_locations_match (e, l))
14362 for (; l; l = l->next)
14363 if (l->function_name
14364 && strcmp (e->function_name, l->function_name) == 0)
14374 if (!locations_are_equal (existing_locations, b->loc))
14375 observer_notify_breakpoint_modified (b);
14378 /* Find the SaL locations corresponding to the given LOCATION.
14379 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14381 static struct symtabs_and_lines
14382 location_to_sals (struct breakpoint *b, struct event_location *location,
14383 struct program_space *search_pspace, int *found)
14385 struct symtabs_and_lines sals = {0};
14386 struct gdb_exception exception = exception_none;
14388 gdb_assert (b->ops != NULL);
14392 b->ops->decode_location (b, location, search_pspace, &sals);
14394 CATCH (e, RETURN_MASK_ERROR)
14396 int not_found_and_ok = 0;
14400 /* For pending breakpoints, it's expected that parsing will
14401 fail until the right shared library is loaded. User has
14402 already told to create pending breakpoints and don't need
14403 extra messages. If breakpoint is in bp_shlib_disabled
14404 state, then user already saw the message about that
14405 breakpoint being disabled, and don't want to see more
14407 if (e.error == NOT_FOUND_ERROR
14408 && (b->condition_not_parsed
14410 && search_pspace != NULL
14411 && b->loc->pspace != search_pspace)
14412 || (b->loc && b->loc->shlib_disabled)
14413 || (b->loc && b->loc->pspace->executing_startup)
14414 || b->enable_state == bp_disabled))
14415 not_found_and_ok = 1;
14417 if (!not_found_and_ok)
14419 /* We surely don't want to warn about the same breakpoint
14420 10 times. One solution, implemented here, is disable
14421 the breakpoint on error. Another solution would be to
14422 have separate 'warning emitted' flag. Since this
14423 happens only when a binary has changed, I don't know
14424 which approach is better. */
14425 b->enable_state = bp_disabled;
14426 throw_exception (e);
14431 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
14435 for (i = 0; i < sals.nelts; ++i)
14436 resolve_sal_pc (&sals.sals[i]);
14437 if (b->condition_not_parsed && b->extra_string != NULL)
14439 char *cond_string, *extra_string;
14442 find_condition_and_thread (b->extra_string, sals.sals[0].pc,
14443 &cond_string, &thread, &task,
14445 gdb_assert (b->cond_string == NULL);
14447 b->cond_string = cond_string;
14448 b->thread = thread;
14452 xfree (b->extra_string);
14453 b->extra_string = extra_string;
14455 b->condition_not_parsed = 0;
14458 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14459 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14469 /* The default re_set method, for typical hardware or software
14470 breakpoints. Reevaluate the breakpoint and recreate its
14474 breakpoint_re_set_default (struct breakpoint *b)
14477 struct symtabs_and_lines sals, sals_end;
14478 struct symtabs_and_lines expanded = {0};
14479 struct symtabs_and_lines expanded_end = {0};
14480 struct program_space *filter_pspace = current_program_space;
14482 sals = location_to_sals (b, b->location, filter_pspace, &found);
14485 make_cleanup (xfree, sals.sals);
14489 if (b->location_range_end != NULL)
14491 sals_end = location_to_sals (b, b->location_range_end,
14492 filter_pspace, &found);
14495 make_cleanup (xfree, sals_end.sals);
14496 expanded_end = sals_end;
14500 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
14503 /* Default method for creating SALs from an address string. It basically
14504 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14507 create_sals_from_location_default (const struct event_location *location,
14508 struct linespec_result *canonical,
14509 enum bptype type_wanted)
14511 parse_breakpoint_sals (location, canonical);
14514 /* Call create_breakpoints_sal for the given arguments. This is the default
14515 function for the `create_breakpoints_sal' method of
14519 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14520 struct linespec_result *canonical,
14522 char *extra_string,
14523 enum bptype type_wanted,
14524 enum bpdisp disposition,
14526 int task, int ignore_count,
14527 const struct breakpoint_ops *ops,
14528 int from_tty, int enabled,
14529 int internal, unsigned flags)
14531 create_breakpoints_sal (gdbarch, canonical, cond_string,
14533 type_wanted, disposition,
14534 thread, task, ignore_count, ops, from_tty,
14535 enabled, internal, flags);
14538 /* Decode the line represented by S by calling decode_line_full. This is the
14539 default function for the `decode_location' method of breakpoint_ops. */
14542 decode_location_default (struct breakpoint *b,
14543 const struct event_location *location,
14544 struct program_space *search_pspace,
14545 struct symtabs_and_lines *sals)
14547 struct linespec_result canonical;
14549 init_linespec_result (&canonical);
14550 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
14551 (struct symtab *) NULL, 0,
14552 &canonical, multiple_symbols_all,
14555 /* We should get 0 or 1 resulting SALs. */
14556 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14558 if (VEC_length (linespec_sals, canonical.sals) > 0)
14560 struct linespec_sals *lsal;
14562 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14563 *sals = lsal->sals;
14564 /* Arrange it so the destructor does not free the
14566 lsal->sals.sals = NULL;
14569 destroy_linespec_result (&canonical);
14572 /* Prepare the global context for a re-set of breakpoint B. */
14574 static struct cleanup *
14575 prepare_re_set_context (struct breakpoint *b)
14577 input_radix = b->input_radix;
14578 set_language (b->language);
14580 return make_cleanup (null_cleanup, NULL);
14583 /* Reset a breakpoint given it's struct breakpoint * BINT.
14584 The value we return ends up being the return value from catch_errors.
14585 Unused in this case. */
14588 breakpoint_re_set_one (void *bint)
14590 /* Get past catch_errs. */
14591 struct breakpoint *b = (struct breakpoint *) bint;
14592 struct cleanup *cleanups;
14594 cleanups = prepare_re_set_context (b);
14595 b->ops->re_set (b);
14596 do_cleanups (cleanups);
14600 /* Re-set breakpoint locations for the current program space.
14601 Locations bound to other program spaces are left untouched. */
14604 breakpoint_re_set (void)
14606 struct breakpoint *b, *b_tmp;
14607 enum language save_language;
14608 int save_input_radix;
14609 struct cleanup *old_chain;
14611 save_language = current_language->la_language;
14612 save_input_radix = input_radix;
14613 old_chain = save_current_space_and_thread ();
14615 /* Note: we must not try to insert locations until after all
14616 breakpoints have been re-set. Otherwise, e.g., when re-setting
14617 breakpoint 1, we'd insert the locations of breakpoint 2, which
14618 hadn't been re-set yet, and thus may have stale locations. */
14620 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14622 /* Format possible error msg. */
14623 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14625 struct cleanup *cleanups = make_cleanup (xfree, message);
14626 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14627 do_cleanups (cleanups);
14629 set_language (save_language);
14630 input_radix = save_input_radix;
14632 jit_breakpoint_re_set ();
14634 do_cleanups (old_chain);
14636 create_overlay_event_breakpoint ();
14637 create_longjmp_master_breakpoint ();
14638 create_std_terminate_master_breakpoint ();
14639 create_exception_master_breakpoint ();
14641 /* Now we can insert. */
14642 update_global_location_list (UGLL_MAY_INSERT);
14645 /* Reset the thread number of this breakpoint:
14647 - If the breakpoint is for all threads, leave it as-is.
14648 - Else, reset it to the current thread for inferior_ptid. */
14650 breakpoint_re_set_thread (struct breakpoint *b)
14652 if (b->thread != -1)
14654 if (in_thread_list (inferior_ptid))
14655 b->thread = ptid_to_global_thread_id (inferior_ptid);
14657 /* We're being called after following a fork. The new fork is
14658 selected as current, and unless this was a vfork will have a
14659 different program space from the original thread. Reset that
14661 b->loc->pspace = current_program_space;
14665 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14666 If from_tty is nonzero, it prints a message to that effect,
14667 which ends with a period (no newline). */
14670 set_ignore_count (int bptnum, int count, int from_tty)
14672 struct breakpoint *b;
14677 ALL_BREAKPOINTS (b)
14678 if (b->number == bptnum)
14680 if (is_tracepoint (b))
14682 if (from_tty && count != 0)
14683 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14688 b->ignore_count = count;
14692 printf_filtered (_("Will stop next time "
14693 "breakpoint %d is reached."),
14695 else if (count == 1)
14696 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14699 printf_filtered (_("Will ignore next %d "
14700 "crossings of breakpoint %d."),
14703 observer_notify_breakpoint_modified (b);
14707 error (_("No breakpoint number %d."), bptnum);
14710 /* Command to set ignore-count of breakpoint N to COUNT. */
14713 ignore_command (char *args, int from_tty)
14719 error_no_arg (_("a breakpoint number"));
14721 num = get_number (&p);
14723 error (_("bad breakpoint number: '%s'"), args);
14725 error (_("Second argument (specified ignore-count) is missing."));
14727 set_ignore_count (num,
14728 longest_to_int (value_as_long (parse_and_eval (p))),
14731 printf_filtered ("\n");
14734 /* Call FUNCTION on each of the breakpoints
14735 whose numbers are given in ARGS. */
14738 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14743 struct breakpoint *b, *tmp;
14745 struct get_number_or_range_state state;
14747 if (args == 0 || *args == '\0')
14748 error_no_arg (_("one or more breakpoint numbers"));
14750 init_number_or_range (&state, args);
14752 while (!state.finished)
14754 const char *p = state.string;
14758 num = get_number_or_range (&state);
14761 warning (_("bad breakpoint number at or near '%s'"), p);
14765 ALL_BREAKPOINTS_SAFE (b, tmp)
14766 if (b->number == num)
14769 function (b, data);
14773 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14778 static struct bp_location *
14779 find_location_by_number (char *number)
14781 char *dot = strchr (number, '.');
14785 struct breakpoint *b;
14786 struct bp_location *loc;
14791 bp_num = get_number (&p1);
14793 error (_("Bad breakpoint number '%s'"), number);
14795 ALL_BREAKPOINTS (b)
14796 if (b->number == bp_num)
14801 if (!b || b->number != bp_num)
14802 error (_("Bad breakpoint number '%s'"), number);
14805 loc_num = get_number (&p1);
14807 error (_("Bad breakpoint location number '%s'"), number);
14811 for (;loc_num && loc; --loc_num, loc = loc->next)
14814 error (_("Bad breakpoint location number '%s'"), dot+1);
14820 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14821 If from_tty is nonzero, it prints a message to that effect,
14822 which ends with a period (no newline). */
14825 disable_breakpoint (struct breakpoint *bpt)
14827 /* Never disable a watchpoint scope breakpoint; we want to
14828 hit them when we leave scope so we can delete both the
14829 watchpoint and its scope breakpoint at that time. */
14830 if (bpt->type == bp_watchpoint_scope)
14833 bpt->enable_state = bp_disabled;
14835 /* Mark breakpoint locations modified. */
14836 mark_breakpoint_modified (bpt);
14838 if (target_supports_enable_disable_tracepoint ()
14839 && current_trace_status ()->running && is_tracepoint (bpt))
14841 struct bp_location *location;
14843 for (location = bpt->loc; location; location = location->next)
14844 target_disable_tracepoint (location);
14847 update_global_location_list (UGLL_DONT_INSERT);
14849 observer_notify_breakpoint_modified (bpt);
14852 /* A callback for iterate_over_related_breakpoints. */
14855 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14857 disable_breakpoint (b);
14860 /* A callback for map_breakpoint_numbers that calls
14861 disable_breakpoint. */
14864 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14866 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14870 disable_command (char *args, int from_tty)
14874 struct breakpoint *bpt;
14876 ALL_BREAKPOINTS (bpt)
14877 if (user_breakpoint_p (bpt))
14878 disable_breakpoint (bpt);
14882 char *num = extract_arg (&args);
14886 if (strchr (num, '.'))
14888 struct bp_location *loc = find_location_by_number (num);
14895 mark_breakpoint_location_modified (loc);
14897 if (target_supports_enable_disable_tracepoint ()
14898 && current_trace_status ()->running && loc->owner
14899 && is_tracepoint (loc->owner))
14900 target_disable_tracepoint (loc);
14902 update_global_location_list (UGLL_DONT_INSERT);
14905 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14906 num = extract_arg (&args);
14912 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14915 int target_resources_ok;
14917 if (bpt->type == bp_hardware_breakpoint)
14920 i = hw_breakpoint_used_count ();
14921 target_resources_ok =
14922 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14924 if (target_resources_ok == 0)
14925 error (_("No hardware breakpoint support in the target."));
14926 else if (target_resources_ok < 0)
14927 error (_("Hardware breakpoints used exceeds limit."));
14930 if (is_watchpoint (bpt))
14932 /* Initialize it just to avoid a GCC false warning. */
14933 enum enable_state orig_enable_state = bp_disabled;
14937 struct watchpoint *w = (struct watchpoint *) bpt;
14939 orig_enable_state = bpt->enable_state;
14940 bpt->enable_state = bp_enabled;
14941 update_watchpoint (w, 1 /* reparse */);
14943 CATCH (e, RETURN_MASK_ALL)
14945 bpt->enable_state = orig_enable_state;
14946 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14953 bpt->enable_state = bp_enabled;
14955 /* Mark breakpoint locations modified. */
14956 mark_breakpoint_modified (bpt);
14958 if (target_supports_enable_disable_tracepoint ()
14959 && current_trace_status ()->running && is_tracepoint (bpt))
14961 struct bp_location *location;
14963 for (location = bpt->loc; location; location = location->next)
14964 target_enable_tracepoint (location);
14967 bpt->disposition = disposition;
14968 bpt->enable_count = count;
14969 update_global_location_list (UGLL_MAY_INSERT);
14971 observer_notify_breakpoint_modified (bpt);
14976 enable_breakpoint (struct breakpoint *bpt)
14978 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14982 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14984 enable_breakpoint (bpt);
14987 /* A callback for map_breakpoint_numbers that calls
14988 enable_breakpoint. */
14991 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14993 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14996 /* The enable command enables the specified breakpoints (or all defined
14997 breakpoints) so they once again become (or continue to be) effective
14998 in stopping the inferior. */
15001 enable_command (char *args, int from_tty)
15005 struct breakpoint *bpt;
15007 ALL_BREAKPOINTS (bpt)
15008 if (user_breakpoint_p (bpt))
15009 enable_breakpoint (bpt);
15013 char *num = extract_arg (&args);
15017 if (strchr (num, '.'))
15019 struct bp_location *loc = find_location_by_number (num);
15026 mark_breakpoint_location_modified (loc);
15028 if (target_supports_enable_disable_tracepoint ()
15029 && current_trace_status ()->running && loc->owner
15030 && is_tracepoint (loc->owner))
15031 target_enable_tracepoint (loc);
15033 update_global_location_list (UGLL_MAY_INSERT);
15036 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15037 num = extract_arg (&args);
15042 /* This struct packages up disposition data for application to multiple
15052 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15054 struct disp_data disp_data = *(struct disp_data *) arg;
15056 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15060 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15062 struct disp_data disp = { disp_disable, 1 };
15064 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15068 enable_once_command (char *args, int from_tty)
15070 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15074 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15076 struct disp_data disp = { disp_disable, *(int *) countptr };
15078 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15082 enable_count_command (char *args, int from_tty)
15087 error_no_arg (_("hit count"));
15089 count = get_number (&args);
15091 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15095 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15097 struct disp_data disp = { disp_del, 1 };
15099 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15103 enable_delete_command (char *args, int from_tty)
15105 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15109 set_breakpoint_cmd (char *args, int from_tty)
15114 show_breakpoint_cmd (char *args, int from_tty)
15118 /* Invalidate last known value of any hardware watchpoint if
15119 the memory which that value represents has been written to by
15123 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15124 CORE_ADDR addr, ssize_t len,
15125 const bfd_byte *data)
15127 struct breakpoint *bp;
15129 ALL_BREAKPOINTS (bp)
15130 if (bp->enable_state == bp_enabled
15131 && bp->type == bp_hardware_watchpoint)
15133 struct watchpoint *wp = (struct watchpoint *) bp;
15135 if (wp->val_valid && wp->val)
15137 struct bp_location *loc;
15139 for (loc = bp->loc; loc != NULL; loc = loc->next)
15140 if (loc->loc_type == bp_loc_hardware_watchpoint
15141 && loc->address + loc->length > addr
15142 && addr + len > loc->address)
15144 value_free (wp->val);
15152 /* Create and insert a breakpoint for software single step. */
15155 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15156 struct address_space *aspace,
15159 struct thread_info *tp = inferior_thread ();
15160 struct symtab_and_line sal;
15161 CORE_ADDR pc = next_pc;
15163 if (tp->control.single_step_breakpoints == NULL)
15165 tp->control.single_step_breakpoints
15166 = new_single_step_breakpoint (tp->global_num, gdbarch);
15169 sal = find_pc_line (pc, 0);
15171 sal.section = find_pc_overlay (pc);
15172 sal.explicit_pc = 1;
15173 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
15175 update_global_location_list (UGLL_INSERT);
15178 /* See breakpoint.h. */
15181 breakpoint_has_location_inserted_here (struct breakpoint *bp,
15182 struct address_space *aspace,
15185 struct bp_location *loc;
15187 for (loc = bp->loc; loc != NULL; loc = loc->next)
15189 && breakpoint_location_address_match (loc, aspace, pc))
15195 /* Check whether a software single-step breakpoint is inserted at
15199 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15202 struct breakpoint *bpt;
15204 ALL_BREAKPOINTS (bpt)
15206 if (bpt->type == bp_single_step
15207 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
15213 /* Tracepoint-specific operations. */
15215 /* Set tracepoint count to NUM. */
15217 set_tracepoint_count (int num)
15219 tracepoint_count = num;
15220 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15224 trace_command (char *arg, int from_tty)
15226 struct breakpoint_ops *ops;
15227 struct event_location *location;
15228 struct cleanup *back_to;
15230 location = string_to_event_location (&arg, current_language);
15231 back_to = make_cleanup_delete_event_location (location);
15232 if (location != NULL
15233 && event_location_type (location) == PROBE_LOCATION)
15234 ops = &tracepoint_probe_breakpoint_ops;
15236 ops = &tracepoint_breakpoint_ops;
15238 create_breakpoint (get_current_arch (),
15240 NULL, 0, arg, 1 /* parse arg */,
15242 bp_tracepoint /* type_wanted */,
15243 0 /* Ignore count */,
15244 pending_break_support,
15248 0 /* internal */, 0);
15249 do_cleanups (back_to);
15253 ftrace_command (char *arg, int from_tty)
15255 struct event_location *location;
15256 struct cleanup *back_to;
15258 location = string_to_event_location (&arg, current_language);
15259 back_to = make_cleanup_delete_event_location (location);
15260 create_breakpoint (get_current_arch (),
15262 NULL, 0, arg, 1 /* parse arg */,
15264 bp_fast_tracepoint /* type_wanted */,
15265 0 /* Ignore count */,
15266 pending_break_support,
15267 &tracepoint_breakpoint_ops,
15270 0 /* internal */, 0);
15271 do_cleanups (back_to);
15274 /* strace command implementation. Creates a static tracepoint. */
15277 strace_command (char *arg, int from_tty)
15279 struct breakpoint_ops *ops;
15280 struct event_location *location;
15281 struct cleanup *back_to;
15283 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15284 or with a normal static tracepoint. */
15285 if (arg && startswith (arg, "-m") && isspace (arg[2]))
15287 ops = &strace_marker_breakpoint_ops;
15288 location = new_linespec_location (&arg);
15292 ops = &tracepoint_breakpoint_ops;
15293 location = string_to_event_location (&arg, current_language);
15296 back_to = make_cleanup_delete_event_location (location);
15297 create_breakpoint (get_current_arch (),
15299 NULL, 0, arg, 1 /* parse arg */,
15301 bp_static_tracepoint /* type_wanted */,
15302 0 /* Ignore count */,
15303 pending_break_support,
15307 0 /* internal */, 0);
15308 do_cleanups (back_to);
15311 /* Set up a fake reader function that gets command lines from a linked
15312 list that was acquired during tracepoint uploading. */
15314 static struct uploaded_tp *this_utp;
15315 static int next_cmd;
15318 read_uploaded_action (void)
15322 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15329 /* Given information about a tracepoint as recorded on a target (which
15330 can be either a live system or a trace file), attempt to create an
15331 equivalent GDB tracepoint. This is not a reliable process, since
15332 the target does not necessarily have all the information used when
15333 the tracepoint was originally defined. */
15335 struct tracepoint *
15336 create_tracepoint_from_upload (struct uploaded_tp *utp)
15338 char *addr_str, small_buf[100];
15339 struct tracepoint *tp;
15340 struct event_location *location;
15341 struct cleanup *cleanup;
15343 if (utp->at_string)
15344 addr_str = utp->at_string;
15347 /* In the absence of a source location, fall back to raw
15348 address. Since there is no way to confirm that the address
15349 means the same thing as when the trace was started, warn the
15351 warning (_("Uploaded tracepoint %d has no "
15352 "source location, using raw address"),
15354 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15355 addr_str = small_buf;
15358 /* There's not much we can do with a sequence of bytecodes. */
15359 if (utp->cond && !utp->cond_string)
15360 warning (_("Uploaded tracepoint %d condition "
15361 "has no source form, ignoring it"),
15364 location = string_to_event_location (&addr_str, current_language);
15365 cleanup = make_cleanup_delete_event_location (location);
15366 if (!create_breakpoint (get_current_arch (),
15368 utp->cond_string, -1, addr_str,
15369 0 /* parse cond/thread */,
15371 utp->type /* type_wanted */,
15372 0 /* Ignore count */,
15373 pending_break_support,
15374 &tracepoint_breakpoint_ops,
15376 utp->enabled /* enabled */,
15378 CREATE_BREAKPOINT_FLAGS_INSERTED))
15380 do_cleanups (cleanup);
15384 do_cleanups (cleanup);
15386 /* Get the tracepoint we just created. */
15387 tp = get_tracepoint (tracepoint_count);
15388 gdb_assert (tp != NULL);
15392 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15395 trace_pass_command (small_buf, 0);
15398 /* If we have uploaded versions of the original commands, set up a
15399 special-purpose "reader" function and call the usual command line
15400 reader, then pass the result to the breakpoint command-setting
15402 if (!VEC_empty (char_ptr, utp->cmd_strings))
15404 struct command_line *cmd_list;
15409 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15411 breakpoint_set_commands (&tp->base, cmd_list);
15413 else if (!VEC_empty (char_ptr, utp->actions)
15414 || !VEC_empty (char_ptr, utp->step_actions))
15415 warning (_("Uploaded tracepoint %d actions "
15416 "have no source form, ignoring them"),
15419 /* Copy any status information that might be available. */
15420 tp->base.hit_count = utp->hit_count;
15421 tp->traceframe_usage = utp->traceframe_usage;
15426 /* Print information on tracepoint number TPNUM_EXP, or all if
15430 tracepoints_info (char *args, int from_tty)
15432 struct ui_out *uiout = current_uiout;
15435 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15437 if (num_printed == 0)
15439 if (args == NULL || *args == '\0')
15440 ui_out_message (uiout, 0, "No tracepoints.\n");
15442 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15445 default_collect_info ();
15448 /* The 'enable trace' command enables tracepoints.
15449 Not supported by all targets. */
15451 enable_trace_command (char *args, int from_tty)
15453 enable_command (args, from_tty);
15456 /* The 'disable trace' command disables tracepoints.
15457 Not supported by all targets. */
15459 disable_trace_command (char *args, int from_tty)
15461 disable_command (args, from_tty);
15464 /* Remove a tracepoint (or all if no argument). */
15466 delete_trace_command (char *arg, int from_tty)
15468 struct breakpoint *b, *b_tmp;
15474 int breaks_to_delete = 0;
15476 /* Delete all breakpoints if no argument.
15477 Do not delete internal or call-dummy breakpoints, these
15478 have to be deleted with an explicit breakpoint number
15480 ALL_TRACEPOINTS (b)
15481 if (is_tracepoint (b) && user_breakpoint_p (b))
15483 breaks_to_delete = 1;
15487 /* Ask user only if there are some breakpoints to delete. */
15489 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15491 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15492 if (is_tracepoint (b) && user_breakpoint_p (b))
15493 delete_breakpoint (b);
15497 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15500 /* Helper function for trace_pass_command. */
15503 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15505 tp->pass_count = count;
15506 observer_notify_breakpoint_modified (&tp->base);
15508 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15509 tp->base.number, count);
15512 /* Set passcount for tracepoint.
15514 First command argument is passcount, second is tracepoint number.
15515 If tracepoint number omitted, apply to most recently defined.
15516 Also accepts special argument "all". */
15519 trace_pass_command (char *args, int from_tty)
15521 struct tracepoint *t1;
15522 unsigned int count;
15524 if (args == 0 || *args == 0)
15525 error (_("passcount command requires an "
15526 "argument (count + optional TP num)"));
15528 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15530 args = skip_spaces (args);
15531 if (*args && strncasecmp (args, "all", 3) == 0)
15533 struct breakpoint *b;
15535 args += 3; /* Skip special argument "all". */
15537 error (_("Junk at end of arguments."));
15539 ALL_TRACEPOINTS (b)
15541 t1 = (struct tracepoint *) b;
15542 trace_pass_set_count (t1, count, from_tty);
15545 else if (*args == '\0')
15547 t1 = get_tracepoint_by_number (&args, NULL);
15549 trace_pass_set_count (t1, count, from_tty);
15553 struct get_number_or_range_state state;
15555 init_number_or_range (&state, args);
15556 while (!state.finished)
15558 t1 = get_tracepoint_by_number (&args, &state);
15560 trace_pass_set_count (t1, count, from_tty);
15565 struct tracepoint *
15566 get_tracepoint (int num)
15568 struct breakpoint *t;
15570 ALL_TRACEPOINTS (t)
15571 if (t->number == num)
15572 return (struct tracepoint *) t;
15577 /* Find the tracepoint with the given target-side number (which may be
15578 different from the tracepoint number after disconnecting and
15581 struct tracepoint *
15582 get_tracepoint_by_number_on_target (int num)
15584 struct breakpoint *b;
15586 ALL_TRACEPOINTS (b)
15588 struct tracepoint *t = (struct tracepoint *) b;
15590 if (t->number_on_target == num)
15597 /* Utility: parse a tracepoint number and look it up in the list.
15598 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15599 If the argument is missing, the most recent tracepoint
15600 (tracepoint_count) is returned. */
15602 struct tracepoint *
15603 get_tracepoint_by_number (char **arg,
15604 struct get_number_or_range_state *state)
15606 struct breakpoint *t;
15608 char *instring = arg == NULL ? NULL : *arg;
15612 gdb_assert (!state->finished);
15613 tpnum = get_number_or_range (state);
15615 else if (arg == NULL || *arg == NULL || ! **arg)
15616 tpnum = tracepoint_count;
15618 tpnum = get_number (arg);
15622 if (instring && *instring)
15623 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15626 printf_filtered (_("No previous tracepoint\n"));
15630 ALL_TRACEPOINTS (t)
15631 if (t->number == tpnum)
15633 return (struct tracepoint *) t;
15636 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15641 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15643 if (b->thread != -1)
15644 fprintf_unfiltered (fp, " thread %d", b->thread);
15647 fprintf_unfiltered (fp, " task %d", b->task);
15649 fprintf_unfiltered (fp, "\n");
15652 /* Save information on user settable breakpoints (watchpoints, etc) to
15653 a new script file named FILENAME. If FILTER is non-NULL, call it
15654 on each breakpoint and only include the ones for which it returns
15658 save_breakpoints (char *filename, int from_tty,
15659 int (*filter) (const struct breakpoint *))
15661 struct breakpoint *tp;
15663 struct cleanup *cleanup;
15664 struct ui_file *fp;
15665 int extra_trace_bits = 0;
15667 if (filename == 0 || *filename == 0)
15668 error (_("Argument required (file name in which to save)"));
15670 /* See if we have anything to save. */
15671 ALL_BREAKPOINTS (tp)
15673 /* Skip internal and momentary breakpoints. */
15674 if (!user_breakpoint_p (tp))
15677 /* If we have a filter, only save the breakpoints it accepts. */
15678 if (filter && !filter (tp))
15683 if (is_tracepoint (tp))
15685 extra_trace_bits = 1;
15687 /* We can stop searching. */
15694 warning (_("Nothing to save."));
15698 filename = tilde_expand (filename);
15699 cleanup = make_cleanup (xfree, filename);
15700 fp = gdb_fopen (filename, "w");
15702 error (_("Unable to open file '%s' for saving (%s)"),
15703 filename, safe_strerror (errno));
15704 make_cleanup_ui_file_delete (fp);
15706 if (extra_trace_bits)
15707 save_trace_state_variables (fp);
15709 ALL_BREAKPOINTS (tp)
15711 /* Skip internal and momentary breakpoints. */
15712 if (!user_breakpoint_p (tp))
15715 /* If we have a filter, only save the breakpoints it accepts. */
15716 if (filter && !filter (tp))
15719 tp->ops->print_recreate (tp, fp);
15721 /* Note, we can't rely on tp->number for anything, as we can't
15722 assume the recreated breakpoint numbers will match. Use $bpnum
15725 if (tp->cond_string)
15726 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15728 if (tp->ignore_count)
15729 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15731 if (tp->type != bp_dprintf && tp->commands)
15733 struct gdb_exception exception;
15735 fprintf_unfiltered (fp, " commands\n");
15737 ui_out_redirect (current_uiout, fp);
15740 print_command_lines (current_uiout, tp->commands->commands, 2);
15742 CATCH (ex, RETURN_MASK_ALL)
15744 ui_out_redirect (current_uiout, NULL);
15745 throw_exception (ex);
15749 ui_out_redirect (current_uiout, NULL);
15750 fprintf_unfiltered (fp, " end\n");
15753 if (tp->enable_state == bp_disabled)
15754 fprintf_unfiltered (fp, "disable $bpnum\n");
15756 /* If this is a multi-location breakpoint, check if the locations
15757 should be individually disabled. Watchpoint locations are
15758 special, and not user visible. */
15759 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15761 struct bp_location *loc;
15764 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15766 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15770 if (extra_trace_bits && *default_collect)
15771 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15774 printf_filtered (_("Saved to file '%s'.\n"), filename);
15775 do_cleanups (cleanup);
15778 /* The `save breakpoints' command. */
15781 save_breakpoints_command (char *args, int from_tty)
15783 save_breakpoints (args, from_tty, NULL);
15786 /* The `save tracepoints' command. */
15789 save_tracepoints_command (char *args, int from_tty)
15791 save_breakpoints (args, from_tty, is_tracepoint);
15794 /* Create a vector of all tracepoints. */
15796 VEC(breakpoint_p) *
15797 all_tracepoints (void)
15799 VEC(breakpoint_p) *tp_vec = 0;
15800 struct breakpoint *tp;
15802 ALL_TRACEPOINTS (tp)
15804 VEC_safe_push (breakpoint_p, tp_vec, tp);
15811 /* This help string is used to consolidate all the help string for specifying
15812 locations used by several commands. */
15814 #define LOCATION_HELP_STRING \
15815 "Linespecs are colon-separated lists of location parameters, such as\n\
15816 source filename, function name, label name, and line number.\n\
15817 Example: To specify the start of a label named \"the_top\" in the\n\
15818 function \"fact\" in the file \"factorial.c\", use\n\
15819 \"factorial.c:fact:the_top\".\n\
15821 Address locations begin with \"*\" and specify an exact address in the\n\
15822 program. Example: To specify the fourth byte past the start function\n\
15823 \"main\", use \"*main + 4\".\n\
15825 Explicit locations are similar to linespecs but use an option/argument\n\
15826 syntax to specify location parameters.\n\
15827 Example: To specify the start of the label named \"the_top\" in the\n\
15828 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15829 -function fact -label the_top\".\n"
15831 /* This help string is used for the break, hbreak, tbreak and thbreak
15832 commands. It is defined as a macro to prevent duplication.
15833 COMMAND should be a string constant containing the name of the
15836 #define BREAK_ARGS_HELP(command) \
15837 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15838 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15839 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15840 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15841 `-probe-dtrace' (for a DTrace probe).\n\
15842 LOCATION may be a linespec, address, or explicit location as described\n\
15845 With no LOCATION, uses current execution address of the selected\n\
15846 stack frame. This is useful for breaking on return to a stack frame.\n\
15848 THREADNUM is the number from \"info threads\".\n\
15849 CONDITION is a boolean expression.\n\
15850 \n" LOCATION_HELP_STRING "\n\
15851 Multiple breakpoints at one place are permitted, and useful if their\n\
15852 conditions are different.\n\
15854 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15856 /* List of subcommands for "catch". */
15857 static struct cmd_list_element *catch_cmdlist;
15859 /* List of subcommands for "tcatch". */
15860 static struct cmd_list_element *tcatch_cmdlist;
15863 add_catch_command (char *name, char *docstring,
15864 cmd_sfunc_ftype *sfunc,
15865 completer_ftype *completer,
15866 void *user_data_catch,
15867 void *user_data_tcatch)
15869 struct cmd_list_element *command;
15871 command = add_cmd (name, class_breakpoint, NULL, docstring,
15873 set_cmd_sfunc (command, sfunc);
15874 set_cmd_context (command, user_data_catch);
15875 set_cmd_completer (command, completer);
15877 command = add_cmd (name, class_breakpoint, NULL, docstring,
15879 set_cmd_sfunc (command, sfunc);
15880 set_cmd_context (command, user_data_tcatch);
15881 set_cmd_completer (command, completer);
15885 save_command (char *arg, int from_tty)
15887 printf_unfiltered (_("\"save\" must be followed by "
15888 "the name of a save subcommand.\n"));
15889 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15892 struct breakpoint *
15893 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15896 struct breakpoint *b, *b_tmp;
15898 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15900 if ((*callback) (b, data))
15907 /* Zero if any of the breakpoint's locations could be a location where
15908 functions have been inlined, nonzero otherwise. */
15911 is_non_inline_function (struct breakpoint *b)
15913 /* The shared library event breakpoint is set on the address of a
15914 non-inline function. */
15915 if (b->type == bp_shlib_event)
15921 /* Nonzero if the specified PC cannot be a location where functions
15922 have been inlined. */
15925 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15926 const struct target_waitstatus *ws)
15928 struct breakpoint *b;
15929 struct bp_location *bl;
15931 ALL_BREAKPOINTS (b)
15933 if (!is_non_inline_function (b))
15936 for (bl = b->loc; bl != NULL; bl = bl->next)
15938 if (!bl->shlib_disabled
15939 && bpstat_check_location (bl, aspace, pc, ws))
15947 /* Remove any references to OBJFILE which is going to be freed. */
15950 breakpoint_free_objfile (struct objfile *objfile)
15952 struct bp_location **locp, *loc;
15954 ALL_BP_LOCATIONS (loc, locp)
15955 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15956 loc->symtab = NULL;
15960 initialize_breakpoint_ops (void)
15962 static int initialized = 0;
15964 struct breakpoint_ops *ops;
15970 /* The breakpoint_ops structure to be inherit by all kinds of
15971 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15972 internal and momentary breakpoints, etc.). */
15973 ops = &bkpt_base_breakpoint_ops;
15974 *ops = base_breakpoint_ops;
15975 ops->re_set = bkpt_re_set;
15976 ops->insert_location = bkpt_insert_location;
15977 ops->remove_location = bkpt_remove_location;
15978 ops->breakpoint_hit = bkpt_breakpoint_hit;
15979 ops->create_sals_from_location = bkpt_create_sals_from_location;
15980 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15981 ops->decode_location = bkpt_decode_location;
15983 /* The breakpoint_ops structure to be used in regular breakpoints. */
15984 ops = &bkpt_breakpoint_ops;
15985 *ops = bkpt_base_breakpoint_ops;
15986 ops->re_set = bkpt_re_set;
15987 ops->resources_needed = bkpt_resources_needed;
15988 ops->print_it = bkpt_print_it;
15989 ops->print_mention = bkpt_print_mention;
15990 ops->print_recreate = bkpt_print_recreate;
15992 /* Ranged breakpoints. */
15993 ops = &ranged_breakpoint_ops;
15994 *ops = bkpt_breakpoint_ops;
15995 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15996 ops->resources_needed = resources_needed_ranged_breakpoint;
15997 ops->print_it = print_it_ranged_breakpoint;
15998 ops->print_one = print_one_ranged_breakpoint;
15999 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16000 ops->print_mention = print_mention_ranged_breakpoint;
16001 ops->print_recreate = print_recreate_ranged_breakpoint;
16003 /* Internal breakpoints. */
16004 ops = &internal_breakpoint_ops;
16005 *ops = bkpt_base_breakpoint_ops;
16006 ops->re_set = internal_bkpt_re_set;
16007 ops->check_status = internal_bkpt_check_status;
16008 ops->print_it = internal_bkpt_print_it;
16009 ops->print_mention = internal_bkpt_print_mention;
16011 /* Momentary breakpoints. */
16012 ops = &momentary_breakpoint_ops;
16013 *ops = bkpt_base_breakpoint_ops;
16014 ops->re_set = momentary_bkpt_re_set;
16015 ops->check_status = momentary_bkpt_check_status;
16016 ops->print_it = momentary_bkpt_print_it;
16017 ops->print_mention = momentary_bkpt_print_mention;
16019 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16020 ops = &longjmp_breakpoint_ops;
16021 *ops = momentary_breakpoint_ops;
16022 ops->dtor = longjmp_bkpt_dtor;
16024 /* Probe breakpoints. */
16025 ops = &bkpt_probe_breakpoint_ops;
16026 *ops = bkpt_breakpoint_ops;
16027 ops->insert_location = bkpt_probe_insert_location;
16028 ops->remove_location = bkpt_probe_remove_location;
16029 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
16030 ops->decode_location = bkpt_probe_decode_location;
16033 ops = &watchpoint_breakpoint_ops;
16034 *ops = base_breakpoint_ops;
16035 ops->dtor = dtor_watchpoint;
16036 ops->re_set = re_set_watchpoint;
16037 ops->insert_location = insert_watchpoint;
16038 ops->remove_location = remove_watchpoint;
16039 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16040 ops->check_status = check_status_watchpoint;
16041 ops->resources_needed = resources_needed_watchpoint;
16042 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16043 ops->print_it = print_it_watchpoint;
16044 ops->print_mention = print_mention_watchpoint;
16045 ops->print_recreate = print_recreate_watchpoint;
16046 ops->explains_signal = explains_signal_watchpoint;
16048 /* Masked watchpoints. */
16049 ops = &masked_watchpoint_breakpoint_ops;
16050 *ops = watchpoint_breakpoint_ops;
16051 ops->insert_location = insert_masked_watchpoint;
16052 ops->remove_location = remove_masked_watchpoint;
16053 ops->resources_needed = resources_needed_masked_watchpoint;
16054 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16055 ops->print_it = print_it_masked_watchpoint;
16056 ops->print_one_detail = print_one_detail_masked_watchpoint;
16057 ops->print_mention = print_mention_masked_watchpoint;
16058 ops->print_recreate = print_recreate_masked_watchpoint;
16061 ops = &tracepoint_breakpoint_ops;
16062 *ops = base_breakpoint_ops;
16063 ops->re_set = tracepoint_re_set;
16064 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16065 ops->print_one_detail = tracepoint_print_one_detail;
16066 ops->print_mention = tracepoint_print_mention;
16067 ops->print_recreate = tracepoint_print_recreate;
16068 ops->create_sals_from_location = tracepoint_create_sals_from_location;
16069 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16070 ops->decode_location = tracepoint_decode_location;
16072 /* Probe tracepoints. */
16073 ops = &tracepoint_probe_breakpoint_ops;
16074 *ops = tracepoint_breakpoint_ops;
16075 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
16076 ops->decode_location = tracepoint_probe_decode_location;
16078 /* Static tracepoints with marker (`-m'). */
16079 ops = &strace_marker_breakpoint_ops;
16080 *ops = tracepoint_breakpoint_ops;
16081 ops->create_sals_from_location = strace_marker_create_sals_from_location;
16082 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16083 ops->decode_location = strace_marker_decode_location;
16085 /* Fork catchpoints. */
16086 ops = &catch_fork_breakpoint_ops;
16087 *ops = base_breakpoint_ops;
16088 ops->insert_location = insert_catch_fork;
16089 ops->remove_location = remove_catch_fork;
16090 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16091 ops->print_it = print_it_catch_fork;
16092 ops->print_one = print_one_catch_fork;
16093 ops->print_mention = print_mention_catch_fork;
16094 ops->print_recreate = print_recreate_catch_fork;
16096 /* Vfork catchpoints. */
16097 ops = &catch_vfork_breakpoint_ops;
16098 *ops = base_breakpoint_ops;
16099 ops->insert_location = insert_catch_vfork;
16100 ops->remove_location = remove_catch_vfork;
16101 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16102 ops->print_it = print_it_catch_vfork;
16103 ops->print_one = print_one_catch_vfork;
16104 ops->print_mention = print_mention_catch_vfork;
16105 ops->print_recreate = print_recreate_catch_vfork;
16107 /* Exec catchpoints. */
16108 ops = &catch_exec_breakpoint_ops;
16109 *ops = base_breakpoint_ops;
16110 ops->dtor = dtor_catch_exec;
16111 ops->insert_location = insert_catch_exec;
16112 ops->remove_location = remove_catch_exec;
16113 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16114 ops->print_it = print_it_catch_exec;
16115 ops->print_one = print_one_catch_exec;
16116 ops->print_mention = print_mention_catch_exec;
16117 ops->print_recreate = print_recreate_catch_exec;
16119 /* Solib-related catchpoints. */
16120 ops = &catch_solib_breakpoint_ops;
16121 *ops = base_breakpoint_ops;
16122 ops->dtor = dtor_catch_solib;
16123 ops->insert_location = insert_catch_solib;
16124 ops->remove_location = remove_catch_solib;
16125 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16126 ops->check_status = check_status_catch_solib;
16127 ops->print_it = print_it_catch_solib;
16128 ops->print_one = print_one_catch_solib;
16129 ops->print_mention = print_mention_catch_solib;
16130 ops->print_recreate = print_recreate_catch_solib;
16132 ops = &dprintf_breakpoint_ops;
16133 *ops = bkpt_base_breakpoint_ops;
16134 ops->re_set = dprintf_re_set;
16135 ops->resources_needed = bkpt_resources_needed;
16136 ops->print_it = bkpt_print_it;
16137 ops->print_mention = bkpt_print_mention;
16138 ops->print_recreate = dprintf_print_recreate;
16139 ops->after_condition_true = dprintf_after_condition_true;
16140 ops->breakpoint_hit = dprintf_breakpoint_hit;
16143 /* Chain containing all defined "enable breakpoint" subcommands. */
16145 static struct cmd_list_element *enablebreaklist = NULL;
16148 _initialize_breakpoint (void)
16150 struct cmd_list_element *c;
16152 initialize_breakpoint_ops ();
16154 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16155 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16156 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16158 breakpoint_objfile_key
16159 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16161 breakpoint_chain = 0;
16162 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16163 before a breakpoint is set. */
16164 breakpoint_count = 0;
16166 tracepoint_count = 0;
16168 add_com ("ignore", class_breakpoint, ignore_command, _("\
16169 Set ignore-count of breakpoint number N to COUNT.\n\
16170 Usage is `ignore N COUNT'."));
16172 add_com ("commands", class_breakpoint, commands_command, _("\
16173 Set commands to be executed when a breakpoint is hit.\n\
16174 Give breakpoint number as argument after \"commands\".\n\
16175 With no argument, the targeted breakpoint is the last one set.\n\
16176 The commands themselves follow starting on the next line.\n\
16177 Type a line containing \"end\" to indicate the end of them.\n\
16178 Give \"silent\" as the first line to make the breakpoint silent;\n\
16179 then no output is printed when it is hit, except what the commands print."));
16181 c = add_com ("condition", class_breakpoint, condition_command, _("\
16182 Specify breakpoint number N to break only if COND is true.\n\
16183 Usage is `condition N COND', where N is an integer and COND is an\n\
16184 expression to be evaluated whenever breakpoint N is reached."));
16185 set_cmd_completer (c, condition_completer);
16187 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16188 Set a temporary breakpoint.\n\
16189 Like \"break\" except the breakpoint is only temporary,\n\
16190 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16191 by using \"enable delete\" on the breakpoint number.\n\
16193 BREAK_ARGS_HELP ("tbreak")));
16194 set_cmd_completer (c, location_completer);
16196 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16197 Set a hardware assisted breakpoint.\n\
16198 Like \"break\" except the breakpoint requires hardware support,\n\
16199 some target hardware may not have this support.\n\
16201 BREAK_ARGS_HELP ("hbreak")));
16202 set_cmd_completer (c, location_completer);
16204 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16205 Set a temporary hardware assisted breakpoint.\n\
16206 Like \"hbreak\" except the breakpoint is only temporary,\n\
16207 so it will be deleted when hit.\n\
16209 BREAK_ARGS_HELP ("thbreak")));
16210 set_cmd_completer (c, location_completer);
16212 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16213 Enable some breakpoints.\n\
16214 Give breakpoint numbers (separated by spaces) as arguments.\n\
16215 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16216 This is used to cancel the effect of the \"disable\" command.\n\
16217 With a subcommand you can enable temporarily."),
16218 &enablelist, "enable ", 1, &cmdlist);
16220 add_com_alias ("en", "enable", class_breakpoint, 1);
16222 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16223 Enable some breakpoints.\n\
16224 Give breakpoint numbers (separated by spaces) as arguments.\n\
16225 This is used to cancel the effect of the \"disable\" command.\n\
16226 May be abbreviated to simply \"enable\".\n"),
16227 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16229 add_cmd ("once", no_class, enable_once_command, _("\
16230 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16231 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16234 add_cmd ("delete", no_class, enable_delete_command, _("\
16235 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16236 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16239 add_cmd ("count", no_class, enable_count_command, _("\
16240 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16241 If a breakpoint is hit while enabled in this fashion,\n\
16242 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16245 add_cmd ("delete", no_class, enable_delete_command, _("\
16246 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16247 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16250 add_cmd ("once", no_class, enable_once_command, _("\
16251 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16252 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16255 add_cmd ("count", no_class, enable_count_command, _("\
16256 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16257 If a breakpoint is hit while enabled in this fashion,\n\
16258 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16261 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16262 Disable some breakpoints.\n\
16263 Arguments are breakpoint numbers with spaces in between.\n\
16264 To disable all breakpoints, give no argument.\n\
16265 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16266 &disablelist, "disable ", 1, &cmdlist);
16267 add_com_alias ("dis", "disable", class_breakpoint, 1);
16268 add_com_alias ("disa", "disable", class_breakpoint, 1);
16270 add_cmd ("breakpoints", class_alias, disable_command, _("\
16271 Disable some breakpoints.\n\
16272 Arguments are breakpoint numbers with spaces in between.\n\
16273 To disable all breakpoints, give no argument.\n\
16274 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16275 This command may be abbreviated \"disable\"."),
16278 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16279 Delete some breakpoints or auto-display expressions.\n\
16280 Arguments are breakpoint numbers with spaces in between.\n\
16281 To delete all breakpoints, give no argument.\n\
16283 Also a prefix command for deletion of other GDB objects.\n\
16284 The \"unset\" command is also an alias for \"delete\"."),
16285 &deletelist, "delete ", 1, &cmdlist);
16286 add_com_alias ("d", "delete", class_breakpoint, 1);
16287 add_com_alias ("del", "delete", class_breakpoint, 1);
16289 add_cmd ("breakpoints", class_alias, delete_command, _("\
16290 Delete some breakpoints or auto-display expressions.\n\
16291 Arguments are breakpoint numbers with spaces in between.\n\
16292 To delete all breakpoints, give no argument.\n\
16293 This command may be abbreviated \"delete\"."),
16296 add_com ("clear", class_breakpoint, clear_command, _("\
16297 Clear breakpoint at specified location.\n\
16298 Argument may be a linespec, explicit, or address location as described below.\n\
16300 With no argument, clears all breakpoints in the line that the selected frame\n\
16301 is executing in.\n"
16302 "\n" LOCATION_HELP_STRING "\n\
16303 See also the \"delete\" command which clears breakpoints by number."));
16304 add_com_alias ("cl", "clear", class_breakpoint, 1);
16306 c = add_com ("break", class_breakpoint, break_command, _("\
16307 Set breakpoint at specified location.\n"
16308 BREAK_ARGS_HELP ("break")));
16309 set_cmd_completer (c, location_completer);
16311 add_com_alias ("b", "break", class_run, 1);
16312 add_com_alias ("br", "break", class_run, 1);
16313 add_com_alias ("bre", "break", class_run, 1);
16314 add_com_alias ("brea", "break", class_run, 1);
16318 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16319 Break in function/address or break at a line in the current file."),
16320 &stoplist, "stop ", 1, &cmdlist);
16321 add_cmd ("in", class_breakpoint, stopin_command,
16322 _("Break in function or address."), &stoplist);
16323 add_cmd ("at", class_breakpoint, stopat_command,
16324 _("Break at a line in the current file."), &stoplist);
16325 add_com ("status", class_info, breakpoints_info, _("\
16326 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16327 The \"Type\" column indicates one of:\n\
16328 \tbreakpoint - normal breakpoint\n\
16329 \twatchpoint - watchpoint\n\
16330 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16331 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16332 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16333 address and file/line number respectively.\n\
16335 Convenience variable \"$_\" and default examine address for \"x\"\n\
16336 are set to the address of the last breakpoint listed unless the command\n\
16337 is prefixed with \"server \".\n\n\
16338 Convenience variable \"$bpnum\" contains the number of the last\n\
16339 breakpoint set."));
16342 add_info ("breakpoints", breakpoints_info, _("\
16343 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16344 The \"Type\" column indicates one of:\n\
16345 \tbreakpoint - normal breakpoint\n\
16346 \twatchpoint - watchpoint\n\
16347 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16348 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16349 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16350 address and file/line number respectively.\n\
16352 Convenience variable \"$_\" and default examine address for \"x\"\n\
16353 are set to the address of the last breakpoint listed unless the command\n\
16354 is prefixed with \"server \".\n\n\
16355 Convenience variable \"$bpnum\" contains the number of the last\n\
16356 breakpoint set."));
16358 add_info_alias ("b", "breakpoints", 1);
16360 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16361 Status of all breakpoints, or breakpoint number NUMBER.\n\
16362 The \"Type\" column indicates one of:\n\
16363 \tbreakpoint - normal breakpoint\n\
16364 \twatchpoint - watchpoint\n\
16365 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16366 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16367 \tuntil - internal breakpoint used by the \"until\" command\n\
16368 \tfinish - internal breakpoint used by the \"finish\" command\n\
16369 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16370 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16371 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16372 address and file/line number respectively.\n\
16374 Convenience variable \"$_\" and default examine address for \"x\"\n\
16375 are set to the address of the last breakpoint listed unless the command\n\
16376 is prefixed with \"server \".\n\n\
16377 Convenience variable \"$bpnum\" contains the number of the last\n\
16379 &maintenanceinfolist);
16381 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16382 Set catchpoints to catch events."),
16383 &catch_cmdlist, "catch ",
16384 0/*allow-unknown*/, &cmdlist);
16386 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16387 Set temporary catchpoints to catch events."),
16388 &tcatch_cmdlist, "tcatch ",
16389 0/*allow-unknown*/, &cmdlist);
16391 add_catch_command ("fork", _("Catch calls to fork."),
16392 catch_fork_command_1,
16394 (void *) (uintptr_t) catch_fork_permanent,
16395 (void *) (uintptr_t) catch_fork_temporary);
16396 add_catch_command ("vfork", _("Catch calls to vfork."),
16397 catch_fork_command_1,
16399 (void *) (uintptr_t) catch_vfork_permanent,
16400 (void *) (uintptr_t) catch_vfork_temporary);
16401 add_catch_command ("exec", _("Catch calls to exec."),
16402 catch_exec_command_1,
16406 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16407 Usage: catch load [REGEX]\n\
16408 If REGEX is given, only stop for libraries matching the regular expression."),
16409 catch_load_command_1,
16413 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16414 Usage: catch unload [REGEX]\n\
16415 If REGEX is given, only stop for libraries matching the regular expression."),
16416 catch_unload_command_1,
16421 c = add_com ("watch", class_breakpoint, watch_command, _("\
16422 Set a watchpoint for an expression.\n\
16423 Usage: watch [-l|-location] EXPRESSION\n\
16424 A watchpoint stops execution of your program whenever the value of\n\
16425 an expression changes.\n\
16426 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16427 the memory to which it refers."));
16428 set_cmd_completer (c, expression_completer);
16430 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16431 Set a read watchpoint for an expression.\n\
16432 Usage: rwatch [-l|-location] EXPRESSION\n\
16433 A watchpoint stops execution of your program whenever the value of\n\
16434 an expression is read.\n\
16435 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16436 the memory to which it refers."));
16437 set_cmd_completer (c, expression_completer);
16439 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16440 Set a watchpoint for an expression.\n\
16441 Usage: awatch [-l|-location] EXPRESSION\n\
16442 A watchpoint stops execution of your program whenever the value of\n\
16443 an expression is either read or written.\n\
16444 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16445 the memory to which it refers."));
16446 set_cmd_completer (c, expression_completer);
16448 add_info ("watchpoints", watchpoints_info, _("\
16449 Status of specified watchpoints (all watchpoints if no argument)."));
16451 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16452 respond to changes - contrary to the description. */
16453 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16454 &can_use_hw_watchpoints, _("\
16455 Set debugger's willingness to use watchpoint hardware."), _("\
16456 Show debugger's willingness to use watchpoint hardware."), _("\
16457 If zero, gdb will not use hardware for new watchpoints, even if\n\
16458 such is available. (However, any hardware watchpoints that were\n\
16459 created before setting this to nonzero, will continue to use watchpoint\n\
16462 show_can_use_hw_watchpoints,
16463 &setlist, &showlist);
16465 can_use_hw_watchpoints = 1;
16467 /* Tracepoint manipulation commands. */
16469 c = add_com ("trace", class_breakpoint, trace_command, _("\
16470 Set a tracepoint at specified location.\n\
16472 BREAK_ARGS_HELP ("trace") "\n\
16473 Do \"help tracepoints\" for info on other tracepoint commands."));
16474 set_cmd_completer (c, location_completer);
16476 add_com_alias ("tp", "trace", class_alias, 0);
16477 add_com_alias ("tr", "trace", class_alias, 1);
16478 add_com_alias ("tra", "trace", class_alias, 1);
16479 add_com_alias ("trac", "trace", class_alias, 1);
16481 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16482 Set a fast tracepoint at specified location.\n\
16484 BREAK_ARGS_HELP ("ftrace") "\n\
16485 Do \"help tracepoints\" for info on other tracepoint commands."));
16486 set_cmd_completer (c, location_completer);
16488 c = add_com ("strace", class_breakpoint, strace_command, _("\
16489 Set a static tracepoint at location or marker.\n\
16491 strace [LOCATION] [if CONDITION]\n\
16492 LOCATION may be a linespec, explicit, or address location (described below) \n\
16493 or -m MARKER_ID.\n\n\
16494 If a marker id is specified, probe the marker with that name. With\n\
16495 no LOCATION, uses current execution address of the selected stack frame.\n\
16496 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16497 This collects arbitrary user data passed in the probe point call to the\n\
16498 tracing library. You can inspect it when analyzing the trace buffer,\n\
16499 by printing the $_sdata variable like any other convenience variable.\n\
16501 CONDITION is a boolean expression.\n\
16502 \n" LOCATION_HELP_STRING "\n\
16503 Multiple tracepoints at one place are permitted, and useful if their\n\
16504 conditions are different.\n\
16506 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16507 Do \"help tracepoints\" for info on other tracepoint commands."));
16508 set_cmd_completer (c, location_completer);
16510 add_info ("tracepoints", tracepoints_info, _("\
16511 Status of specified tracepoints (all tracepoints if no argument).\n\
16512 Convenience variable \"$tpnum\" contains the number of the\n\
16513 last tracepoint set."));
16515 add_info_alias ("tp", "tracepoints", 1);
16517 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16518 Delete specified tracepoints.\n\
16519 Arguments are tracepoint numbers, separated by spaces.\n\
16520 No argument means delete all tracepoints."),
16522 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16524 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16525 Disable specified tracepoints.\n\
16526 Arguments are tracepoint numbers, separated by spaces.\n\
16527 No argument means disable all tracepoints."),
16529 deprecate_cmd (c, "disable");
16531 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16532 Enable specified tracepoints.\n\
16533 Arguments are tracepoint numbers, separated by spaces.\n\
16534 No argument means enable all tracepoints."),
16536 deprecate_cmd (c, "enable");
16538 add_com ("passcount", class_trace, trace_pass_command, _("\
16539 Set the passcount for a tracepoint.\n\
16540 The trace will end when the tracepoint has been passed 'count' times.\n\
16541 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16542 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16544 add_prefix_cmd ("save", class_breakpoint, save_command,
16545 _("Save breakpoint definitions as a script."),
16546 &save_cmdlist, "save ",
16547 0/*allow-unknown*/, &cmdlist);
16549 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16550 Save current breakpoint definitions as a script.\n\
16551 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16552 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16553 session to restore them."),
16555 set_cmd_completer (c, filename_completer);
16557 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16558 Save current tracepoint definitions as a script.\n\
16559 Use the 'source' command in another debug session to restore them."),
16561 set_cmd_completer (c, filename_completer);
16563 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16564 deprecate_cmd (c, "save tracepoints");
16566 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16567 Breakpoint specific settings\n\
16568 Configure various breakpoint-specific variables such as\n\
16569 pending breakpoint behavior"),
16570 &breakpoint_set_cmdlist, "set breakpoint ",
16571 0/*allow-unknown*/, &setlist);
16572 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16573 Breakpoint specific settings\n\
16574 Configure various breakpoint-specific variables such as\n\
16575 pending breakpoint behavior"),
16576 &breakpoint_show_cmdlist, "show breakpoint ",
16577 0/*allow-unknown*/, &showlist);
16579 add_setshow_auto_boolean_cmd ("pending", no_class,
16580 &pending_break_support, _("\
16581 Set debugger's behavior regarding pending breakpoints."), _("\
16582 Show debugger's behavior regarding pending breakpoints."), _("\
16583 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16584 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16585 an error. If auto, an unrecognized breakpoint location results in a\n\
16586 user-query to see if a pending breakpoint should be created."),
16588 show_pending_break_support,
16589 &breakpoint_set_cmdlist,
16590 &breakpoint_show_cmdlist);
16592 pending_break_support = AUTO_BOOLEAN_AUTO;
16594 add_setshow_boolean_cmd ("auto-hw", no_class,
16595 &automatic_hardware_breakpoints, _("\
16596 Set automatic usage of hardware breakpoints."), _("\
16597 Show automatic usage of hardware breakpoints."), _("\
16598 If set, the debugger will automatically use hardware breakpoints for\n\
16599 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16600 a warning will be emitted for such breakpoints."),
16602 show_automatic_hardware_breakpoints,
16603 &breakpoint_set_cmdlist,
16604 &breakpoint_show_cmdlist);
16606 add_setshow_boolean_cmd ("always-inserted", class_support,
16607 &always_inserted_mode, _("\
16608 Set mode for inserting breakpoints."), _("\
16609 Show mode for inserting breakpoints."), _("\
16610 When this mode is on, breakpoints are inserted immediately as soon as\n\
16611 they're created, kept inserted even when execution stops, and removed\n\
16612 only when the user deletes them. When this mode is off (the default),\n\
16613 breakpoints are inserted only when execution continues, and removed\n\
16614 when execution stops."),
16616 &show_always_inserted_mode,
16617 &breakpoint_set_cmdlist,
16618 &breakpoint_show_cmdlist);
16620 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16621 condition_evaluation_enums,
16622 &condition_evaluation_mode_1, _("\
16623 Set mode of breakpoint condition evaluation."), _("\
16624 Show mode of breakpoint condition evaluation."), _("\
16625 When this is set to \"host\", breakpoint conditions will be\n\
16626 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16627 breakpoint conditions will be downloaded to the target (if the target\n\
16628 supports such feature) and conditions will be evaluated on the target's side.\n\
16629 If this is set to \"auto\" (default), this will be automatically set to\n\
16630 \"target\" if it supports condition evaluation, otherwise it will\n\
16631 be set to \"gdb\""),
16632 &set_condition_evaluation_mode,
16633 &show_condition_evaluation_mode,
16634 &breakpoint_set_cmdlist,
16635 &breakpoint_show_cmdlist);
16637 add_com ("break-range", class_breakpoint, break_range_command, _("\
16638 Set a breakpoint for an address range.\n\
16639 break-range START-LOCATION, END-LOCATION\n\
16640 where START-LOCATION and END-LOCATION can be one of the following:\n\
16641 LINENUM, for that line in the current file,\n\
16642 FILE:LINENUM, for that line in that file,\n\
16643 +OFFSET, for that number of lines after the current line\n\
16644 or the start of the range\n\
16645 FUNCTION, for the first line in that function,\n\
16646 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16647 *ADDRESS, for the instruction at that address.\n\
16649 The breakpoint will stop execution of the inferior whenever it executes\n\
16650 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16651 range (including START-LOCATION and END-LOCATION)."));
16653 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16654 Set a dynamic printf at specified location.\n\
16655 dprintf location,format string,arg1,arg2,...\n\
16656 location may be a linespec, explicit, or address location.\n"
16657 "\n" LOCATION_HELP_STRING));
16658 set_cmd_completer (c, location_completer);
16660 add_setshow_enum_cmd ("dprintf-style", class_support,
16661 dprintf_style_enums, &dprintf_style, _("\
16662 Set the style of usage for dynamic printf."), _("\
16663 Show the style of usage for dynamic printf."), _("\
16664 This setting chooses how GDB will do a dynamic printf.\n\
16665 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16666 console, as with the \"printf\" command.\n\
16667 If the value is \"call\", the print is done by calling a function in your\n\
16668 program; by default printf(), but you can choose a different function or\n\
16669 output stream by setting dprintf-function and dprintf-channel."),
16670 update_dprintf_commands, NULL,
16671 &setlist, &showlist);
16673 dprintf_function = xstrdup ("printf");
16674 add_setshow_string_cmd ("dprintf-function", class_support,
16675 &dprintf_function, _("\
16676 Set the function to use for dynamic printf"), _("\
16677 Show the function to use for dynamic printf"), NULL,
16678 update_dprintf_commands, NULL,
16679 &setlist, &showlist);
16681 dprintf_channel = xstrdup ("");
16682 add_setshow_string_cmd ("dprintf-channel", class_support,
16683 &dprintf_channel, _("\
16684 Set the channel to use for dynamic printf"), _("\
16685 Show the channel to use for dynamic printf"), NULL,
16686 update_dprintf_commands, NULL,
16687 &setlist, &showlist);
16689 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16690 &disconnected_dprintf, _("\
16691 Set whether dprintf continues after GDB disconnects."), _("\
16692 Show whether dprintf continues after GDB disconnects."), _("\
16693 Use this to let dprintf commands continue to hit and produce output\n\
16694 even if GDB disconnects or detaches from the target."),
16697 &setlist, &showlist);
16699 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16700 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16701 (target agent only) This is useful for formatted output in user-defined commands."));
16703 automatic_hardware_breakpoints = 1;
16705 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16706 observer_attach_thread_exit (remove_threaded_breakpoints);