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"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (const char *,
106 void (*) (struct breakpoint *,
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint *);
117 create_sals_from_location_default (const struct event_location *location,
118 struct linespec_result *canonical,
119 enum bptype type_wanted);
121 static void create_breakpoints_sal_default (struct gdbarch *,
122 struct linespec_result *,
123 char *, char *, enum bptype,
124 enum bpdisp, int, int,
126 const struct breakpoint_ops *,
127 int, int, int, unsigned);
129 static void decode_location_default (struct breakpoint *b,
130 const struct event_location *location,
131 struct program_space *search_pspace,
132 struct symtabs_and_lines *sals);
134 static void clear_command (char *, int);
136 static void catch_command (char *, int);
138 static int can_use_hardware_watchpoint (struct value *);
140 static void break_command_1 (char *, int, int);
142 static void mention (struct breakpoint *);
144 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
146 const struct breakpoint_ops *);
147 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
148 const struct symtab_and_line *);
150 /* This function is used in gdbtk sources and thus can not be made
152 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
153 struct symtab_and_line,
155 const struct breakpoint_ops *);
157 static struct breakpoint *
158 momentary_breakpoint_from_master (struct breakpoint *orig,
160 const struct breakpoint_ops *ops,
163 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
165 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
169 static void describe_other_breakpoints (struct gdbarch *,
170 struct program_space *, CORE_ADDR,
171 struct obj_section *, int);
173 static int watchpoint_locations_match (struct bp_location *loc1,
174 struct bp_location *loc2);
176 static int breakpoint_location_address_match (struct bp_location *bl,
177 struct address_space *aspace,
180 static int breakpoint_location_address_range_overlap (struct bp_location *,
181 struct address_space *,
184 static void breakpoints_info (char *, int);
186 static void watchpoints_info (char *, int);
188 static int breakpoint_1 (char *, int,
189 int (*) (const struct breakpoint *));
191 static int breakpoint_cond_eval (void *);
193 static void cleanup_executing_breakpoints (void *);
195 static void commands_command (char *, int);
197 static void condition_command (char *, int);
199 static int remove_breakpoint (struct bp_location *);
200 static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
202 static enum print_stop_action print_bp_stop_message (bpstat bs);
204 static int watchpoint_check (void *);
206 static void maintenance_info_breakpoints (char *, int);
208 static int hw_breakpoint_used_count (void);
210 static int hw_watchpoint_use_count (struct breakpoint *);
212 static int hw_watchpoint_used_count_others (struct breakpoint *except,
214 int *other_type_used);
216 static void hbreak_command (char *, int);
218 static void thbreak_command (char *, int);
220 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
223 static void stop_command (char *arg, int from_tty);
225 static void stopin_command (char *arg, int from_tty);
227 static void stopat_command (char *arg, int from_tty);
229 static void tcatch_command (char *arg, int from_tty);
231 static void free_bp_location (struct bp_location *loc);
232 static void incref_bp_location (struct bp_location *loc);
233 static void decref_bp_location (struct bp_location **loc);
235 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
237 /* update_global_location_list's modes of operation wrt to whether to
238 insert locations now. */
239 enum ugll_insert_mode
241 /* Don't insert any breakpoint locations into the inferior, only
242 remove already-inserted locations that no longer should be
243 inserted. Functions that delete a breakpoint or breakpoints
244 should specify this mode, so that deleting a breakpoint doesn't
245 have the side effect of inserting the locations of other
246 breakpoints that are marked not-inserted, but should_be_inserted
247 returns true on them.
249 This behavior is useful is situations close to tear-down -- e.g.,
250 after an exec, while the target still has execution, but
251 breakpoint shadows of the previous executable image should *NOT*
252 be restored to the new image; or before detaching, where the
253 target still has execution and wants to delete breakpoints from
254 GDB's lists, and all breakpoints had already been removed from
258 /* May insert breakpoints iff breakpoints_should_be_inserted_now
259 claims breakpoints should be inserted now. */
262 /* Insert locations now, irrespective of
263 breakpoints_should_be_inserted_now. E.g., say all threads are
264 stopped right now, and the user did "continue". We need to
265 insert breakpoints _before_ resuming the target, but
266 UGLL_MAY_INSERT wouldn't insert them, because
267 breakpoints_should_be_inserted_now returns false at that point,
268 as no thread is running yet. */
272 static void update_global_location_list (enum ugll_insert_mode);
274 static void update_global_location_list_nothrow (enum ugll_insert_mode);
276 static int is_hardware_watchpoint (const struct breakpoint *bpt);
278 static void insert_breakpoint_locations (void);
280 static void tracepoints_info (char *, int);
282 static void delete_trace_command (char *, int);
284 static void enable_trace_command (char *, int);
286 static void disable_trace_command (char *, int);
288 static void trace_pass_command (char *, int);
290 static void set_tracepoint_count (int num);
292 static int is_masked_watchpoint (const struct breakpoint *b);
294 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
296 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
299 static int strace_marker_p (struct breakpoint *b);
301 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
302 that are implemented on top of software or hardware breakpoints
303 (user breakpoints, internal and momentary breakpoints, etc.). */
304 static struct breakpoint_ops bkpt_base_breakpoint_ops;
306 /* Internal breakpoints class type. */
307 static struct breakpoint_ops internal_breakpoint_ops;
309 /* Momentary breakpoints class type. */
310 static struct breakpoint_ops momentary_breakpoint_ops;
312 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
313 static struct breakpoint_ops longjmp_breakpoint_ops;
315 /* The breakpoint_ops structure to be used in regular user created
317 struct breakpoint_ops bkpt_breakpoint_ops;
319 /* Breakpoints set on probes. */
320 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
322 /* Dynamic printf class type. */
323 struct breakpoint_ops dprintf_breakpoint_ops;
325 /* The style in which to perform a dynamic printf. This is a user
326 option because different output options have different tradeoffs;
327 if GDB does the printing, there is better error handling if there
328 is a problem with any of the arguments, but using an inferior
329 function lets you have special-purpose printers and sending of
330 output to the same place as compiled-in print functions. */
332 static const char dprintf_style_gdb[] = "gdb";
333 static const char dprintf_style_call[] = "call";
334 static const char dprintf_style_agent[] = "agent";
335 static const char *const dprintf_style_enums[] = {
341 static const char *dprintf_style = dprintf_style_gdb;
343 /* The function to use for dynamic printf if the preferred style is to
344 call into the inferior. The value is simply a string that is
345 copied into the command, so it can be anything that GDB can
346 evaluate to a callable address, not necessarily a function name. */
348 static char *dprintf_function = "";
350 /* The channel to use for dynamic printf if the preferred style is to
351 call into the inferior; if a nonempty string, it will be passed to
352 the call as the first argument, with the format string as the
353 second. As with the dprintf function, this can be anything that
354 GDB knows how to evaluate, so in addition to common choices like
355 "stderr", this could be an app-specific expression like
356 "mystreams[curlogger]". */
358 static char *dprintf_channel = "";
360 /* True if dprintf commands should continue to operate even if GDB
362 static int disconnected_dprintf = 1;
364 /* A reference-counted struct command_line. This lets multiple
365 breakpoints share a single command list. */
366 struct counted_command_line
368 /* The reference count. */
371 /* The command list. */
372 struct command_line *commands;
375 struct command_line *
376 breakpoint_commands (struct breakpoint *b)
378 return b->commands ? b->commands->commands : NULL;
381 /* Flag indicating that a command has proceeded the inferior past the
382 current breakpoint. */
384 static int breakpoint_proceeded;
387 bpdisp_text (enum bpdisp disp)
389 /* NOTE: the following values are a part of MI protocol and
390 represent values of 'disp' field returned when inferior stops at
392 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
394 return bpdisps[(int) disp];
397 /* Prototypes for exported functions. */
398 /* If FALSE, gdb will not use hardware support for watchpoints, even
399 if such is available. */
400 static int can_use_hw_watchpoints;
403 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
404 struct cmd_list_element *c,
407 fprintf_filtered (file,
408 _("Debugger's willingness to use "
409 "watchpoint hardware is %s.\n"),
413 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
414 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
415 for unrecognized breakpoint locations.
416 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
417 static enum auto_boolean pending_break_support;
419 show_pending_break_support (struct ui_file *file, int from_tty,
420 struct cmd_list_element *c,
423 fprintf_filtered (file,
424 _("Debugger's behavior regarding "
425 "pending breakpoints is %s.\n"),
429 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
430 set with "break" but falling in read-only memory.
431 If 0, gdb will warn about such breakpoints, but won't automatically
432 use hardware breakpoints. */
433 static int automatic_hardware_breakpoints;
435 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
436 struct cmd_list_element *c,
439 fprintf_filtered (file,
440 _("Automatic usage of hardware breakpoints is %s.\n"),
444 /* If on, GDB keeps breakpoints inserted even if the inferior is
445 stopped, and immediately inserts any new breakpoints as soon as
446 they're created. If off (default), GDB keeps breakpoints off of
447 the target as long as possible. That is, it delays inserting
448 breakpoints until the next resume, and removes them again when the
449 target fully stops. This is a bit safer in case GDB crashes while
450 processing user input. */
451 static int always_inserted_mode = 0;
454 show_always_inserted_mode (struct ui_file *file, int from_tty,
455 struct cmd_list_element *c, const char *value)
457 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
461 /* See breakpoint.h. */
464 breakpoints_should_be_inserted_now (void)
466 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
468 /* If breakpoints are global, they should be inserted even if no
469 thread under gdb's control is running, or even if there are
470 no threads under GDB's control yet. */
473 else if (target_has_execution)
475 struct thread_info *tp;
477 if (always_inserted_mode)
479 /* The user wants breakpoints inserted even if all threads
484 if (threads_are_executing ())
487 /* Don't remove breakpoints yet if, even though all threads are
488 stopped, we still have events to process. */
489 ALL_NON_EXITED_THREADS (tp)
491 && tp->suspend.waitstatus_pending_p)
497 static const char condition_evaluation_both[] = "host or target";
499 /* Modes for breakpoint condition evaluation. */
500 static const char condition_evaluation_auto[] = "auto";
501 static const char condition_evaluation_host[] = "host";
502 static const char condition_evaluation_target[] = "target";
503 static const char *const condition_evaluation_enums[] = {
504 condition_evaluation_auto,
505 condition_evaluation_host,
506 condition_evaluation_target,
510 /* Global that holds the current mode for breakpoint condition evaluation. */
511 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
513 /* Global that we use to display information to the user (gets its value from
514 condition_evaluation_mode_1. */
515 static const char *condition_evaluation_mode = condition_evaluation_auto;
517 /* Translate a condition evaluation mode MODE into either "host"
518 or "target". This is used mostly to translate from "auto" to the
519 real setting that is being used. It returns the translated
523 translate_condition_evaluation_mode (const char *mode)
525 if (mode == condition_evaluation_auto)
527 if (target_supports_evaluation_of_breakpoint_conditions ())
528 return condition_evaluation_target;
530 return condition_evaluation_host;
536 /* Discovers what condition_evaluation_auto translates to. */
539 breakpoint_condition_evaluation_mode (void)
541 return translate_condition_evaluation_mode (condition_evaluation_mode);
544 /* Return true if GDB should evaluate breakpoint conditions or false
548 gdb_evaluates_breakpoint_condition_p (void)
550 const char *mode = breakpoint_condition_evaluation_mode ();
552 return (mode == condition_evaluation_host);
555 void _initialize_breakpoint (void);
557 /* Are we executing breakpoint commands? */
558 static int executing_breakpoint_commands;
560 /* Are overlay event breakpoints enabled? */
561 static int overlay_events_enabled;
563 /* See description in breakpoint.h. */
564 int target_exact_watchpoints = 0;
566 /* Walk the following statement or block through all breakpoints.
567 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
568 current breakpoint. */
570 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
572 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
573 for (B = breakpoint_chain; \
574 B ? (TMP=B->next, 1): 0; \
577 /* Similar iterator for the low-level breakpoints. SAFE variant is
578 not provided so update_global_location_list must not be called
579 while executing the block of ALL_BP_LOCATIONS. */
581 #define ALL_BP_LOCATIONS(B,BP_TMP) \
582 for (BP_TMP = bp_location; \
583 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
586 /* Iterates through locations with address ADDRESS for the currently selected
587 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
588 to where the loop should start from.
589 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
590 appropriate location to start with. */
592 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
593 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
594 BP_LOCP_TMP = BP_LOCP_START; \
596 && (BP_LOCP_TMP < bp_location + bp_location_count \
597 && (*BP_LOCP_TMP)->address == ADDRESS); \
600 /* Iterator for tracepoints only. */
602 #define ALL_TRACEPOINTS(B) \
603 for (B = breakpoint_chain; B; B = B->next) \
604 if (is_tracepoint (B))
606 /* Chains of all breakpoints defined. */
608 struct breakpoint *breakpoint_chain;
610 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
612 static struct bp_location **bp_location;
614 /* Number of elements of BP_LOCATION. */
616 static unsigned bp_location_count;
618 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
619 ADDRESS for the current elements of BP_LOCATION which get a valid
620 result from bp_location_has_shadow. You can use it for roughly
621 limiting the subrange of BP_LOCATION to scan for shadow bytes for
622 an address you need to read. */
624 static CORE_ADDR bp_location_placed_address_before_address_max;
626 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
627 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
628 BP_LOCATION which get a valid result from bp_location_has_shadow.
629 You can use it for roughly limiting the subrange of BP_LOCATION to
630 scan for shadow bytes for an address you need to read. */
632 static CORE_ADDR bp_location_shadow_len_after_address_max;
634 /* The locations that no longer correspond to any breakpoint, unlinked
635 from bp_location array, but for which a hit may still be reported
637 VEC(bp_location_p) *moribund_locations = NULL;
639 /* Number of last breakpoint made. */
641 static int breakpoint_count;
643 /* The value of `breakpoint_count' before the last command that
644 created breakpoints. If the last (break-like) command created more
645 than one breakpoint, then the difference between BREAKPOINT_COUNT
646 and PREV_BREAKPOINT_COUNT is more than one. */
647 static int prev_breakpoint_count;
649 /* Number of last tracepoint made. */
651 static int tracepoint_count;
653 static struct cmd_list_element *breakpoint_set_cmdlist;
654 static struct cmd_list_element *breakpoint_show_cmdlist;
655 struct cmd_list_element *save_cmdlist;
657 /* See declaration at breakpoint.h. */
660 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
663 struct breakpoint *b = NULL;
667 if (func (b, user_data) != 0)
674 /* Return whether a breakpoint is an active enabled breakpoint. */
676 breakpoint_enabled (struct breakpoint *b)
678 return (b->enable_state == bp_enabled);
681 /* Set breakpoint count to NUM. */
684 set_breakpoint_count (int num)
686 prev_breakpoint_count = breakpoint_count;
687 breakpoint_count = num;
688 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
691 /* Used by `start_rbreak_breakpoints' below, to record the current
692 breakpoint count before "rbreak" creates any breakpoint. */
693 static int rbreak_start_breakpoint_count;
695 /* Called at the start an "rbreak" command to record the first
699 start_rbreak_breakpoints (void)
701 rbreak_start_breakpoint_count = breakpoint_count;
704 /* Called at the end of an "rbreak" command to record the last
708 end_rbreak_breakpoints (void)
710 prev_breakpoint_count = rbreak_start_breakpoint_count;
713 /* Used in run_command to zero the hit count when a new run starts. */
716 clear_breakpoint_hit_counts (void)
718 struct breakpoint *b;
724 /* Allocate a new counted_command_line with reference count of 1.
725 The new structure owns COMMANDS. */
727 static struct counted_command_line *
728 alloc_counted_command_line (struct command_line *commands)
730 struct counted_command_line *result = XNEW (struct counted_command_line);
733 result->commands = commands;
738 /* Increment reference count. This does nothing if CMD is NULL. */
741 incref_counted_command_line (struct counted_command_line *cmd)
747 /* Decrement reference count. If the reference count reaches 0,
748 destroy the counted_command_line. Sets *CMDP to NULL. This does
749 nothing if *CMDP is NULL. */
752 decref_counted_command_line (struct counted_command_line **cmdp)
756 if (--(*cmdp)->refc == 0)
758 free_command_lines (&(*cmdp)->commands);
765 /* A cleanup function that calls decref_counted_command_line. */
768 do_cleanup_counted_command_line (void *arg)
770 decref_counted_command_line ((struct counted_command_line **) arg);
773 /* Create a cleanup that calls decref_counted_command_line on the
776 static struct cleanup *
777 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
779 return make_cleanup (do_cleanup_counted_command_line, cmdp);
783 /* Return the breakpoint with the specified number, or NULL
784 if the number does not refer to an existing breakpoint. */
787 get_breakpoint (int num)
789 struct breakpoint *b;
792 if (b->number == num)
800 /* Mark locations as "conditions have changed" in case the target supports
801 evaluating conditions on its side. */
804 mark_breakpoint_modified (struct breakpoint *b)
806 struct bp_location *loc;
808 /* This is only meaningful if the target is
809 evaluating conditions and if the user has
810 opted for condition evaluation on the target's
812 if (gdb_evaluates_breakpoint_condition_p ()
813 || !target_supports_evaluation_of_breakpoint_conditions ())
816 if (!is_breakpoint (b))
819 for (loc = b->loc; loc; loc = loc->next)
820 loc->condition_changed = condition_modified;
823 /* Mark location as "conditions have changed" in case the target supports
824 evaluating conditions on its side. */
827 mark_breakpoint_location_modified (struct bp_location *loc)
829 /* This is only meaningful if the target is
830 evaluating conditions and if the user has
831 opted for condition evaluation on the target's
833 if (gdb_evaluates_breakpoint_condition_p ()
834 || !target_supports_evaluation_of_breakpoint_conditions ())
838 if (!is_breakpoint (loc->owner))
841 loc->condition_changed = condition_modified;
844 /* Sets the condition-evaluation mode using the static global
845 condition_evaluation_mode. */
848 set_condition_evaluation_mode (char *args, int from_tty,
849 struct cmd_list_element *c)
851 const char *old_mode, *new_mode;
853 if ((condition_evaluation_mode_1 == condition_evaluation_target)
854 && !target_supports_evaluation_of_breakpoint_conditions ())
856 condition_evaluation_mode_1 = condition_evaluation_mode;
857 warning (_("Target does not support breakpoint condition evaluation.\n"
858 "Using host evaluation mode instead."));
862 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
863 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
865 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
866 settings was "auto". */
867 condition_evaluation_mode = condition_evaluation_mode_1;
869 /* Only update the mode if the user picked a different one. */
870 if (new_mode != old_mode)
872 struct bp_location *loc, **loc_tmp;
873 /* If the user switched to a different evaluation mode, we
874 need to synch the changes with the target as follows:
876 "host" -> "target": Send all (valid) conditions to the target.
877 "target" -> "host": Remove all the conditions from the target.
880 if (new_mode == condition_evaluation_target)
882 /* Mark everything modified and synch conditions with the
884 ALL_BP_LOCATIONS (loc, loc_tmp)
885 mark_breakpoint_location_modified (loc);
889 /* Manually mark non-duplicate locations to synch conditions
890 with the target. We do this to remove all the conditions the
891 target knows about. */
892 ALL_BP_LOCATIONS (loc, loc_tmp)
893 if (is_breakpoint (loc->owner) && loc->inserted)
894 loc->needs_update = 1;
898 update_global_location_list (UGLL_MAY_INSERT);
904 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
905 what "auto" is translating to. */
908 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
909 struct cmd_list_element *c, const char *value)
911 if (condition_evaluation_mode == condition_evaluation_auto)
912 fprintf_filtered (file,
913 _("Breakpoint condition evaluation "
914 "mode is %s (currently %s).\n"),
916 breakpoint_condition_evaluation_mode ());
918 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
922 /* A comparison function for bp_location AP and BP that is used by
923 bsearch. This comparison function only cares about addresses, unlike
924 the more general bp_location_compare function. */
927 bp_location_compare_addrs (const void *ap, const void *bp)
929 const struct bp_location *a = *(const struct bp_location **) ap;
930 const struct bp_location *b = *(const struct bp_location **) bp;
932 if (a->address == b->address)
935 return ((a->address > b->address) - (a->address < b->address));
938 /* Helper function to skip all bp_locations with addresses
939 less than ADDRESS. It returns the first bp_location that
940 is greater than or equal to ADDRESS. If none is found, just
943 static struct bp_location **
944 get_first_locp_gte_addr (CORE_ADDR address)
946 struct bp_location dummy_loc;
947 struct bp_location *dummy_locp = &dummy_loc;
948 struct bp_location **locp_found = NULL;
950 /* Initialize the dummy location's address field. */
951 memset (&dummy_loc, 0, sizeof (struct bp_location));
952 dummy_loc.address = address;
954 /* Find a close match to the first location at ADDRESS. */
955 locp_found = ((struct bp_location **)
956 bsearch (&dummy_locp, bp_location, bp_location_count,
957 sizeof (struct bp_location **),
958 bp_location_compare_addrs));
960 /* Nothing was found, nothing left to do. */
961 if (locp_found == NULL)
964 /* We may have found a location that is at ADDRESS but is not the first in the
965 location's list. Go backwards (if possible) and locate the first one. */
966 while ((locp_found - 1) >= bp_location
967 && (*(locp_found - 1))->address == address)
974 set_breakpoint_condition (struct breakpoint *b, const char *exp,
977 xfree (b->cond_string);
978 b->cond_string = NULL;
980 if (is_watchpoint (b))
982 struct watchpoint *w = (struct watchpoint *) b;
989 struct bp_location *loc;
991 for (loc = b->loc; loc; loc = loc->next)
996 /* No need to free the condition agent expression
997 bytecode (if we have one). We will handle this
998 when we go through update_global_location_list. */
1005 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
1009 const char *arg = exp;
1011 /* I don't know if it matters whether this is the string the user
1012 typed in or the decompiled expression. */
1013 b->cond_string = xstrdup (arg);
1014 b->condition_not_parsed = 0;
1016 if (is_watchpoint (b))
1018 struct watchpoint *w = (struct watchpoint *) b;
1020 innermost_block = NULL;
1022 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1024 error (_("Junk at end of expression"));
1025 w->cond_exp_valid_block = innermost_block;
1029 struct bp_location *loc;
1031 for (loc = b->loc; loc; loc = loc->next)
1035 parse_exp_1 (&arg, loc->address,
1036 block_for_pc (loc->address), 0);
1038 error (_("Junk at end of expression"));
1042 mark_breakpoint_modified (b);
1044 observer_notify_breakpoint_modified (b);
1047 /* Completion for the "condition" command. */
1049 static VEC (char_ptr) *
1050 condition_completer (struct cmd_list_element *cmd,
1051 const char *text, const char *word)
1055 text = skip_spaces_const (text);
1056 space = skip_to_space_const (text);
1060 struct breakpoint *b;
1061 VEC (char_ptr) *result = NULL;
1065 /* We don't support completion of history indices. */
1066 if (isdigit (text[1]))
1068 return complete_internalvar (&text[1]);
1071 /* We're completing the breakpoint number. */
1072 len = strlen (text);
1078 xsnprintf (number, sizeof (number), "%d", b->number);
1080 if (strncmp (number, text, len) == 0)
1081 VEC_safe_push (char_ptr, result, xstrdup (number));
1087 /* We're completing the expression part. */
1088 text = skip_spaces_const (space);
1089 return expression_completer (cmd, text, word);
1092 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1095 condition_command (char *arg, int from_tty)
1097 struct breakpoint *b;
1102 error_no_arg (_("breakpoint number"));
1105 bnum = get_number (&p);
1107 error (_("Bad breakpoint argument: '%s'"), arg);
1110 if (b->number == bnum)
1112 /* Check if this breakpoint has a "stop" method implemented in an
1113 extension language. This method and conditions entered into GDB
1114 from the CLI are mutually exclusive. */
1115 const struct extension_language_defn *extlang
1116 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1118 if (extlang != NULL)
1120 error (_("Only one stop condition allowed. There is currently"
1121 " a %s stop condition defined for this breakpoint."),
1122 ext_lang_capitalized_name (extlang));
1124 set_breakpoint_condition (b, p, from_tty);
1126 if (is_breakpoint (b))
1127 update_global_location_list (UGLL_MAY_INSERT);
1132 error (_("No breakpoint number %d."), bnum);
1135 /* Check that COMMAND do not contain commands that are suitable
1136 only for tracepoints and not suitable for ordinary breakpoints.
1137 Throw if any such commands is found. */
1140 check_no_tracepoint_commands (struct command_line *commands)
1142 struct command_line *c;
1144 for (c = commands; c; c = c->next)
1148 if (c->control_type == while_stepping_control)
1149 error (_("The 'while-stepping' command can "
1150 "only be used for tracepoints"));
1152 for (i = 0; i < c->body_count; ++i)
1153 check_no_tracepoint_commands ((c->body_list)[i]);
1155 /* Not that command parsing removes leading whitespace and comment
1156 lines and also empty lines. So, we only need to check for
1157 command directly. */
1158 if (strstr (c->line, "collect ") == c->line)
1159 error (_("The 'collect' command can only be used for tracepoints"));
1161 if (strstr (c->line, "teval ") == c->line)
1162 error (_("The 'teval' command can only be used for tracepoints"));
1166 /* Encapsulate tests for different types of tracepoints. */
1169 is_tracepoint_type (enum bptype type)
1171 return (type == bp_tracepoint
1172 || type == bp_fast_tracepoint
1173 || type == bp_static_tracepoint);
1177 is_tracepoint (const struct breakpoint *b)
1179 return is_tracepoint_type (b->type);
1182 /* A helper function that validates that COMMANDS are valid for a
1183 breakpoint. This function will throw an exception if a problem is
1187 validate_commands_for_breakpoint (struct breakpoint *b,
1188 struct command_line *commands)
1190 if (is_tracepoint (b))
1192 struct tracepoint *t = (struct tracepoint *) b;
1193 struct command_line *c;
1194 struct command_line *while_stepping = 0;
1196 /* Reset the while-stepping step count. The previous commands
1197 might have included a while-stepping action, while the new
1201 /* We need to verify that each top-level element of commands is
1202 valid for tracepoints, that there's at most one
1203 while-stepping element, and that the while-stepping's body
1204 has valid tracing commands excluding nested while-stepping.
1205 We also need to validate the tracepoint action line in the
1206 context of the tracepoint --- validate_actionline actually
1207 has side effects, like setting the tracepoint's
1208 while-stepping STEP_COUNT, in addition to checking if the
1209 collect/teval actions parse and make sense in the
1210 tracepoint's context. */
1211 for (c = commands; c; c = c->next)
1213 if (c->control_type == while_stepping_control)
1215 if (b->type == bp_fast_tracepoint)
1216 error (_("The 'while-stepping' command "
1217 "cannot be used for fast tracepoint"));
1218 else if (b->type == bp_static_tracepoint)
1219 error (_("The 'while-stepping' command "
1220 "cannot be used for static tracepoint"));
1223 error (_("The 'while-stepping' command "
1224 "can be used only once"));
1229 validate_actionline (c->line, b);
1233 struct command_line *c2;
1235 gdb_assert (while_stepping->body_count == 1);
1236 c2 = while_stepping->body_list[0];
1237 for (; c2; c2 = c2->next)
1239 if (c2->control_type == while_stepping_control)
1240 error (_("The 'while-stepping' command cannot be nested"));
1246 check_no_tracepoint_commands (commands);
1250 /* Return a vector of all the static tracepoints set at ADDR. The
1251 caller is responsible for releasing the vector. */
1254 static_tracepoints_here (CORE_ADDR addr)
1256 struct breakpoint *b;
1257 VEC(breakpoint_p) *found = 0;
1258 struct bp_location *loc;
1261 if (b->type == bp_static_tracepoint)
1263 for (loc = b->loc; loc; loc = loc->next)
1264 if (loc->address == addr)
1265 VEC_safe_push(breakpoint_p, found, b);
1271 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1272 validate that only allowed commands are included. */
1275 breakpoint_set_commands (struct breakpoint *b,
1276 struct command_line *commands)
1278 validate_commands_for_breakpoint (b, commands);
1280 decref_counted_command_line (&b->commands);
1281 b->commands = alloc_counted_command_line (commands);
1282 observer_notify_breakpoint_modified (b);
1285 /* Set the internal `silent' flag on the breakpoint. Note that this
1286 is not the same as the "silent" that may appear in the breakpoint's
1290 breakpoint_set_silent (struct breakpoint *b, int silent)
1292 int old_silent = b->silent;
1295 if (old_silent != silent)
1296 observer_notify_breakpoint_modified (b);
1299 /* Set the thread for this breakpoint. If THREAD is -1, make the
1300 breakpoint work for any thread. */
1303 breakpoint_set_thread (struct breakpoint *b, int thread)
1305 int old_thread = b->thread;
1308 if (old_thread != thread)
1309 observer_notify_breakpoint_modified (b);
1312 /* Set the task for this breakpoint. If TASK is 0, make the
1313 breakpoint work for any task. */
1316 breakpoint_set_task (struct breakpoint *b, int task)
1318 int old_task = b->task;
1321 if (old_task != task)
1322 observer_notify_breakpoint_modified (b);
1326 check_tracepoint_command (char *line, void *closure)
1328 struct breakpoint *b = (struct breakpoint *) closure;
1330 validate_actionline (line, b);
1333 /* A structure used to pass information through
1334 map_breakpoint_numbers. */
1336 struct commands_info
1338 /* True if the command was typed at a tty. */
1341 /* The breakpoint range spec. */
1344 /* Non-NULL if the body of the commands are being read from this
1345 already-parsed command. */
1346 struct command_line *control;
1348 /* The command lines read from the user, or NULL if they have not
1350 struct counted_command_line *cmd;
1353 /* A callback for map_breakpoint_numbers that sets the commands for
1354 commands_command. */
1357 do_map_commands_command (struct breakpoint *b, void *data)
1359 struct commands_info *info = (struct commands_info *) data;
1361 if (info->cmd == NULL)
1363 struct command_line *l;
1365 if (info->control != NULL)
1366 l = copy_command_lines (info->control->body_list[0]);
1369 struct cleanup *old_chain;
1372 str = xstrprintf (_("Type commands for breakpoint(s) "
1373 "%s, one per line."),
1376 old_chain = make_cleanup (xfree, str);
1378 l = read_command_lines (str,
1381 ? check_tracepoint_command : 0),
1384 do_cleanups (old_chain);
1387 info->cmd = alloc_counted_command_line (l);
1390 /* If a breakpoint was on the list more than once, we don't need to
1392 if (b->commands != info->cmd)
1394 validate_commands_for_breakpoint (b, info->cmd->commands);
1395 incref_counted_command_line (info->cmd);
1396 decref_counted_command_line (&b->commands);
1397 b->commands = info->cmd;
1398 observer_notify_breakpoint_modified (b);
1403 commands_command_1 (const char *arg, int from_tty,
1404 struct command_line *control)
1406 struct cleanup *cleanups;
1407 struct commands_info info;
1409 info.from_tty = from_tty;
1410 info.control = control;
1412 /* If we read command lines from the user, then `info' will hold an
1413 extra reference to the commands that we must clean up. */
1414 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1416 std::string new_arg;
1418 if (arg == NULL || !*arg)
1420 if (breakpoint_count - prev_breakpoint_count > 1)
1421 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1423 else if (breakpoint_count > 0)
1424 new_arg = string_printf ("%d", breakpoint_count);
1429 info.arg = new_arg.c_str ();
1431 map_breakpoint_numbers (info.arg, do_map_commands_command, &info);
1433 if (info.cmd == NULL)
1434 error (_("No breakpoints specified."));
1436 do_cleanups (cleanups);
1440 commands_command (char *arg, int from_tty)
1442 commands_command_1 (arg, from_tty, NULL);
1445 /* Like commands_command, but instead of reading the commands from
1446 input stream, takes them from an already parsed command structure.
1448 This is used by cli-script.c to DTRT with breakpoint commands
1449 that are part of if and while bodies. */
1450 enum command_control_type
1451 commands_from_control_command (const char *arg, struct command_line *cmd)
1453 commands_command_1 (arg, 0, cmd);
1454 return simple_control;
1457 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1460 bp_location_has_shadow (struct bp_location *bl)
1462 if (bl->loc_type != bp_loc_software_breakpoint)
1466 if (bl->target_info.shadow_len == 0)
1467 /* BL isn't valid, or doesn't shadow memory. */
1472 /* Update BUF, which is LEN bytes read from the target address
1473 MEMADDR, by replacing a memory breakpoint with its shadowed
1476 If READBUF is not NULL, this buffer must not overlap with the of
1477 the breakpoint location's shadow_contents buffer. Otherwise, a
1478 failed assertion internal error will be raised. */
1481 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1482 const gdb_byte *writebuf_org,
1483 ULONGEST memaddr, LONGEST len,
1484 struct bp_target_info *target_info,
1485 struct gdbarch *gdbarch)
1487 /* Now do full processing of the found relevant range of elements. */
1488 CORE_ADDR bp_addr = 0;
1492 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1493 current_program_space->aspace, 0))
1495 /* The breakpoint is inserted in a different address space. */
1499 /* Addresses and length of the part of the breakpoint that
1501 bp_addr = target_info->placed_address;
1502 bp_size = target_info->shadow_len;
1504 if (bp_addr + bp_size <= memaddr)
1506 /* The breakpoint is entirely before the chunk of memory we are
1511 if (bp_addr >= memaddr + len)
1513 /* The breakpoint is entirely after the chunk of memory we are
1518 /* Offset within shadow_contents. */
1519 if (bp_addr < memaddr)
1521 /* Only copy the second part of the breakpoint. */
1522 bp_size -= memaddr - bp_addr;
1523 bptoffset = memaddr - bp_addr;
1527 if (bp_addr + bp_size > memaddr + len)
1529 /* Only copy the first part of the breakpoint. */
1530 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1533 if (readbuf != NULL)
1535 /* Verify that the readbuf buffer does not overlap with the
1536 shadow_contents buffer. */
1537 gdb_assert (target_info->shadow_contents >= readbuf + len
1538 || readbuf >= (target_info->shadow_contents
1539 + target_info->shadow_len));
1541 /* Update the read buffer with this inserted breakpoint's
1543 memcpy (readbuf + bp_addr - memaddr,
1544 target_info->shadow_contents + bptoffset, bp_size);
1548 const unsigned char *bp;
1549 CORE_ADDR addr = target_info->reqstd_address;
1552 /* Update the shadow with what we want to write to memory. */
1553 memcpy (target_info->shadow_contents + bptoffset,
1554 writebuf_org + bp_addr - memaddr, bp_size);
1556 /* Determine appropriate breakpoint contents and size for this
1558 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1560 /* Update the final write buffer with this inserted
1561 breakpoint's INSN. */
1562 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1566 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1567 by replacing any memory breakpoints with their shadowed contents.
1569 If READBUF is not NULL, this buffer must not overlap with any of
1570 the breakpoint location's shadow_contents buffers. Otherwise,
1571 a failed assertion internal error will be raised.
1573 The range of shadowed area by each bp_location is:
1574 bl->address - bp_location_placed_address_before_address_max
1575 up to bl->address + bp_location_shadow_len_after_address_max
1576 The range we were requested to resolve shadows for is:
1577 memaddr ... memaddr + len
1578 Thus the safe cutoff boundaries for performance optimization are
1579 memaddr + len <= (bl->address
1580 - bp_location_placed_address_before_address_max)
1582 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1585 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1586 const gdb_byte *writebuf_org,
1587 ULONGEST memaddr, LONGEST len)
1589 /* Left boundary, right boundary and median element of our binary
1591 unsigned bc_l, bc_r, bc;
1593 /* Find BC_L which is a leftmost element which may affect BUF
1594 content. It is safe to report lower value but a failure to
1595 report higher one. */
1598 bc_r = bp_location_count;
1599 while (bc_l + 1 < bc_r)
1601 struct bp_location *bl;
1603 bc = (bc_l + bc_r) / 2;
1604 bl = bp_location[bc];
1606 /* Check first BL->ADDRESS will not overflow due to the added
1607 constant. Then advance the left boundary only if we are sure
1608 the BC element can in no way affect the BUF content (MEMADDR
1609 to MEMADDR + LEN range).
1611 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1612 offset so that we cannot miss a breakpoint with its shadow
1613 range tail still reaching MEMADDR. */
1615 if ((bl->address + bp_location_shadow_len_after_address_max
1617 && (bl->address + bp_location_shadow_len_after_address_max
1624 /* Due to the binary search above, we need to make sure we pick the
1625 first location that's at BC_L's address. E.g., if there are
1626 multiple locations at the same address, BC_L may end up pointing
1627 at a duplicate location, and miss the "master"/"inserted"
1628 location. Say, given locations L1, L2 and L3 at addresses A and
1631 L1@A, L2@A, L3@B, ...
1633 BC_L could end up pointing at location L2, while the "master"
1634 location could be L1. Since the `loc->inserted' flag is only set
1635 on "master" locations, we'd forget to restore the shadow of L1
1638 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1641 /* Now do full processing of the found relevant range of elements. */
1643 for (bc = bc_l; bc < bp_location_count; bc++)
1645 struct bp_location *bl = bp_location[bc];
1647 /* bp_location array has BL->OWNER always non-NULL. */
1648 if (bl->owner->type == bp_none)
1649 warning (_("reading through apparently deleted breakpoint #%d?"),
1652 /* Performance optimization: any further element can no longer affect BUF
1655 if (bl->address >= bp_location_placed_address_before_address_max
1656 && memaddr + len <= (bl->address
1657 - bp_location_placed_address_before_address_max))
1660 if (!bp_location_has_shadow (bl))
1663 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1664 memaddr, len, &bl->target_info, bl->gdbarch);
1670 /* Return true if BPT is either a software breakpoint or a hardware
1674 is_breakpoint (const struct breakpoint *bpt)
1676 return (bpt->type == bp_breakpoint
1677 || bpt->type == bp_hardware_breakpoint
1678 || bpt->type == bp_dprintf);
1681 /* Return true if BPT is of any hardware watchpoint kind. */
1684 is_hardware_watchpoint (const struct breakpoint *bpt)
1686 return (bpt->type == bp_hardware_watchpoint
1687 || bpt->type == bp_read_watchpoint
1688 || bpt->type == bp_access_watchpoint);
1691 /* Return true if BPT is of any watchpoint kind, hardware or
1695 is_watchpoint (const struct breakpoint *bpt)
1697 return (is_hardware_watchpoint (bpt)
1698 || bpt->type == bp_watchpoint);
1701 /* Returns true if the current thread and its running state are safe
1702 to evaluate or update watchpoint B. Watchpoints on local
1703 expressions need to be evaluated in the context of the thread that
1704 was current when the watchpoint was created, and, that thread needs
1705 to be stopped to be able to select the correct frame context.
1706 Watchpoints on global expressions can be evaluated on any thread,
1707 and in any state. It is presently left to the target allowing
1708 memory accesses when threads are running. */
1711 watchpoint_in_thread_scope (struct watchpoint *b)
1713 return (b->base.pspace == current_program_space
1714 && (ptid_equal (b->watchpoint_thread, null_ptid)
1715 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1716 && !is_executing (inferior_ptid))));
1719 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1720 associated bp_watchpoint_scope breakpoint. */
1723 watchpoint_del_at_next_stop (struct watchpoint *w)
1725 struct breakpoint *b = &w->base;
1727 if (b->related_breakpoint != b)
1729 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1730 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1731 b->related_breakpoint->disposition = disp_del_at_next_stop;
1732 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1733 b->related_breakpoint = b;
1735 b->disposition = disp_del_at_next_stop;
1738 /* Extract a bitfield value from value VAL using the bit parameters contained in
1741 static struct value *
1742 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1744 struct value *bit_val;
1749 bit_val = allocate_value (value_type (val));
1751 unpack_value_bitfield (bit_val,
1754 value_contents_for_printing (val),
1761 /* Allocate a dummy location and add it to B, which must be a software
1762 watchpoint. This is required because even if a software watchpoint
1763 is not watching any memory, bpstat_stop_status requires a location
1764 to be able to report stops. */
1767 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1768 struct program_space *pspace)
1770 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1772 b->loc = allocate_bp_location (b);
1773 b->loc->pspace = pspace;
1774 b->loc->address = -1;
1775 b->loc->length = -1;
1778 /* Returns true if B is a software watchpoint that is not watching any
1779 memory (e.g., "watch $pc"). */
1782 is_no_memory_software_watchpoint (struct breakpoint *b)
1784 return (b->type == bp_watchpoint
1786 && b->loc->next == NULL
1787 && b->loc->address == -1
1788 && b->loc->length == -1);
1791 /* Assuming that B is a watchpoint:
1792 - Reparse watchpoint expression, if REPARSE is non-zero
1793 - Evaluate expression and store the result in B->val
1794 - Evaluate the condition if there is one, and store the result
1796 - Update the list of values that must be watched in B->loc.
1798 If the watchpoint disposition is disp_del_at_next_stop, then do
1799 nothing. If this is local watchpoint that is out of scope, delete
1802 Even with `set breakpoint always-inserted on' the watchpoints are
1803 removed + inserted on each stop here. Normal breakpoints must
1804 never be removed because they might be missed by a running thread
1805 when debugging in non-stop mode. On the other hand, hardware
1806 watchpoints (is_hardware_watchpoint; processed here) are specific
1807 to each LWP since they are stored in each LWP's hardware debug
1808 registers. Therefore, such LWP must be stopped first in order to
1809 be able to modify its hardware watchpoints.
1811 Hardware watchpoints must be reset exactly once after being
1812 presented to the user. It cannot be done sooner, because it would
1813 reset the data used to present the watchpoint hit to the user. And
1814 it must not be done later because it could display the same single
1815 watchpoint hit during multiple GDB stops. Note that the latter is
1816 relevant only to the hardware watchpoint types bp_read_watchpoint
1817 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1818 not user-visible - its hit is suppressed if the memory content has
1821 The following constraints influence the location where we can reset
1822 hardware watchpoints:
1824 * target_stopped_by_watchpoint and target_stopped_data_address are
1825 called several times when GDB stops.
1828 * Multiple hardware watchpoints can be hit at the same time,
1829 causing GDB to stop. GDB only presents one hardware watchpoint
1830 hit at a time as the reason for stopping, and all the other hits
1831 are presented later, one after the other, each time the user
1832 requests the execution to be resumed. Execution is not resumed
1833 for the threads still having pending hit event stored in
1834 LWP_INFO->STATUS. While the watchpoint is already removed from
1835 the inferior on the first stop the thread hit event is kept being
1836 reported from its cached value by linux_nat_stopped_data_address
1837 until the real thread resume happens after the watchpoint gets
1838 presented and thus its LWP_INFO->STATUS gets reset.
1840 Therefore the hardware watchpoint hit can get safely reset on the
1841 watchpoint removal from inferior. */
1844 update_watchpoint (struct watchpoint *b, int reparse)
1846 int within_current_scope;
1847 struct frame_id saved_frame_id;
1850 /* If this is a local watchpoint, we only want to check if the
1851 watchpoint frame is in scope if the current thread is the thread
1852 that was used to create the watchpoint. */
1853 if (!watchpoint_in_thread_scope (b))
1856 if (b->base.disposition == disp_del_at_next_stop)
1861 /* Determine if the watchpoint is within scope. */
1862 if (b->exp_valid_block == NULL)
1863 within_current_scope = 1;
1866 struct frame_info *fi = get_current_frame ();
1867 struct gdbarch *frame_arch = get_frame_arch (fi);
1868 CORE_ADDR frame_pc = get_frame_pc (fi);
1870 /* If we're at a point where the stack has been destroyed
1871 (e.g. in a function epilogue), unwinding may not work
1872 properly. Do not attempt to recreate locations at this
1873 point. See similar comments in watchpoint_check. */
1874 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1877 /* Save the current frame's ID so we can restore it after
1878 evaluating the watchpoint expression on its own frame. */
1879 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1880 took a frame parameter, so that we didn't have to change the
1883 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1885 fi = frame_find_by_id (b->watchpoint_frame);
1886 within_current_scope = (fi != NULL);
1887 if (within_current_scope)
1891 /* We don't free locations. They are stored in the bp_location array
1892 and update_global_location_list will eventually delete them and
1893 remove breakpoints if needed. */
1896 if (within_current_scope && reparse)
1905 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1906 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1907 /* If the meaning of expression itself changed, the old value is
1908 no longer relevant. We don't want to report a watchpoint hit
1909 to the user when the old value and the new value may actually
1910 be completely different objects. */
1911 value_free (b->val);
1915 /* Note that unlike with breakpoints, the watchpoint's condition
1916 expression is stored in the breakpoint object, not in the
1917 locations (re)created below. */
1918 if (b->base.cond_string != NULL)
1920 if (b->cond_exp != NULL)
1922 xfree (b->cond_exp);
1926 s = b->base.cond_string;
1927 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1931 /* If we failed to parse the expression, for example because
1932 it refers to a global variable in a not-yet-loaded shared library,
1933 don't try to insert watchpoint. We don't automatically delete
1934 such watchpoint, though, since failure to parse expression
1935 is different from out-of-scope watchpoint. */
1936 if (!target_has_execution)
1938 /* Without execution, memory can't change. No use to try and
1939 set watchpoint locations. The watchpoint will be reset when
1940 the target gains execution, through breakpoint_re_set. */
1941 if (!can_use_hw_watchpoints)
1943 if (b->base.ops->works_in_software_mode (&b->base))
1944 b->base.type = bp_watchpoint;
1946 error (_("Can't set read/access watchpoint when "
1947 "hardware watchpoints are disabled."));
1950 else if (within_current_scope && b->exp)
1953 struct value *val_chain, *v, *result, *next;
1954 struct program_space *frame_pspace;
1956 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1958 /* Avoid setting b->val if it's already set. The meaning of
1959 b->val is 'the last value' user saw, and we should update
1960 it only if we reported that last value to user. As it
1961 happens, the code that reports it updates b->val directly.
1962 We don't keep track of the memory value for masked
1964 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1966 if (b->val_bitsize != 0)
1968 v = extract_bitfield_from_watchpoint_value (b, v);
1976 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1978 /* Look at each value on the value chain. */
1979 for (v = val_chain; v; v = value_next (v))
1981 /* If it's a memory location, and GDB actually needed
1982 its contents to evaluate the expression, then we
1983 must watch it. If the first value returned is
1984 still lazy, that means an error occurred reading it;
1985 watch it anyway in case it becomes readable. */
1986 if (VALUE_LVAL (v) == lval_memory
1987 && (v == val_chain || ! value_lazy (v)))
1989 struct type *vtype = check_typedef (value_type (v));
1991 /* We only watch structs and arrays if user asked
1992 for it explicitly, never if they just happen to
1993 appear in the middle of some value chain. */
1995 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1996 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1999 enum target_hw_bp_type type;
2000 struct bp_location *loc, **tmp;
2001 int bitpos = 0, bitsize = 0;
2003 if (value_bitsize (v) != 0)
2005 /* Extract the bit parameters out from the bitfield
2007 bitpos = value_bitpos (v);
2008 bitsize = value_bitsize (v);
2010 else if (v == result && b->val_bitsize != 0)
2012 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2013 lvalue whose bit parameters are saved in the fields
2014 VAL_BITPOS and VAL_BITSIZE. */
2015 bitpos = b->val_bitpos;
2016 bitsize = b->val_bitsize;
2019 addr = value_address (v);
2022 /* Skip the bytes that don't contain the bitfield. */
2027 if (b->base.type == bp_read_watchpoint)
2029 else if (b->base.type == bp_access_watchpoint)
2032 loc = allocate_bp_location (&b->base);
2033 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
2036 loc->gdbarch = get_type_arch (value_type (v));
2038 loc->pspace = frame_pspace;
2039 loc->address = addr;
2043 /* Just cover the bytes that make up the bitfield. */
2044 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2047 loc->length = TYPE_LENGTH (value_type (v));
2049 loc->watchpoint_type = type;
2054 /* Change the type of breakpoint between hardware assisted or
2055 an ordinary watchpoint depending on the hardware support
2056 and free hardware slots. REPARSE is set when the inferior
2061 enum bp_loc_type loc_type;
2062 struct bp_location *bl;
2064 reg_cnt = can_use_hardware_watchpoint (val_chain);
2068 int i, target_resources_ok, other_type_used;
2071 /* Use an exact watchpoint when there's only one memory region to be
2072 watched, and only one debug register is needed to watch it. */
2073 b->exact = target_exact_watchpoints && reg_cnt == 1;
2075 /* We need to determine how many resources are already
2076 used for all other hardware watchpoints plus this one
2077 to see if we still have enough resources to also fit
2078 this watchpoint in as well. */
2080 /* If this is a software watchpoint, we try to turn it
2081 to a hardware one -- count resources as if B was of
2082 hardware watchpoint type. */
2083 type = b->base.type;
2084 if (type == bp_watchpoint)
2085 type = bp_hardware_watchpoint;
2087 /* This watchpoint may or may not have been placed on
2088 the list yet at this point (it won't be in the list
2089 if we're trying to create it for the first time,
2090 through watch_command), so always account for it
2093 /* Count resources used by all watchpoints except B. */
2094 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2096 /* Add in the resources needed for B. */
2097 i += hw_watchpoint_use_count (&b->base);
2100 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2101 if (target_resources_ok <= 0)
2103 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2105 if (target_resources_ok == 0 && !sw_mode)
2106 error (_("Target does not support this type of "
2107 "hardware watchpoint."));
2108 else if (target_resources_ok < 0 && !sw_mode)
2109 error (_("There are not enough available hardware "
2110 "resources for this watchpoint."));
2112 /* Downgrade to software watchpoint. */
2113 b->base.type = bp_watchpoint;
2117 /* If this was a software watchpoint, we've just
2118 found we have enough resources to turn it to a
2119 hardware watchpoint. Otherwise, this is a
2121 b->base.type = type;
2124 else if (!b->base.ops->works_in_software_mode (&b->base))
2126 if (!can_use_hw_watchpoints)
2127 error (_("Can't set read/access watchpoint when "
2128 "hardware watchpoints are disabled."));
2130 error (_("Expression cannot be implemented with "
2131 "read/access watchpoint."));
2134 b->base.type = bp_watchpoint;
2136 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2137 : bp_loc_hardware_watchpoint);
2138 for (bl = b->base.loc; bl; bl = bl->next)
2139 bl->loc_type = loc_type;
2142 for (v = val_chain; v; v = next)
2144 next = value_next (v);
2149 /* If a software watchpoint is not watching any memory, then the
2150 above left it without any location set up. But,
2151 bpstat_stop_status requires a location to be able to report
2152 stops, so make sure there's at least a dummy one. */
2153 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2154 software_watchpoint_add_no_memory_location (&b->base, frame_pspace);
2156 else if (!within_current_scope)
2158 printf_filtered (_("\
2159 Watchpoint %d deleted because the program has left the block\n\
2160 in which its expression is valid.\n"),
2162 watchpoint_del_at_next_stop (b);
2165 /* Restore the selected frame. */
2167 select_frame (frame_find_by_id (saved_frame_id));
2171 /* Returns 1 iff breakpoint location should be
2172 inserted in the inferior. We don't differentiate the type of BL's owner
2173 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2174 breakpoint_ops is not defined, because in insert_bp_location,
2175 tracepoint's insert_location will not be called. */
2177 should_be_inserted (struct bp_location *bl)
2179 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2182 if (bl->owner->disposition == disp_del_at_next_stop)
2185 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2188 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2191 /* This is set for example, when we're attached to the parent of a
2192 vfork, and have detached from the child. The child is running
2193 free, and we expect it to do an exec or exit, at which point the
2194 OS makes the parent schedulable again (and the target reports
2195 that the vfork is done). Until the child is done with the shared
2196 memory region, do not insert breakpoints in the parent, otherwise
2197 the child could still trip on the parent's breakpoints. Since
2198 the parent is blocked anyway, it won't miss any breakpoint. */
2199 if (bl->pspace->breakpoints_not_allowed)
2202 /* Don't insert a breakpoint if we're trying to step past its
2203 location, except if the breakpoint is a single-step breakpoint,
2204 and the breakpoint's thread is the thread which is stepping past
2206 if ((bl->loc_type == bp_loc_software_breakpoint
2207 || bl->loc_type == bp_loc_hardware_breakpoint)
2208 && stepping_past_instruction_at (bl->pspace->aspace,
2210 /* The single-step breakpoint may be inserted at the location
2211 we're trying to step if the instruction branches to itself.
2212 However, the instruction won't be executed at all and it may
2213 break the semantics of the instruction, for example, the
2214 instruction is a conditional branch or updates some flags.
2215 We can't fix it unless GDB is able to emulate the instruction
2216 or switch to displaced stepping. */
2217 && !(bl->owner->type == bp_single_step
2218 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2222 fprintf_unfiltered (gdb_stdlog,
2223 "infrun: skipping breakpoint: "
2224 "stepping past insn at: %s\n",
2225 paddress (bl->gdbarch, bl->address));
2230 /* Don't insert watchpoints if we're trying to step past the
2231 instruction that triggered one. */
2232 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2233 && stepping_past_nonsteppable_watchpoint ())
2237 fprintf_unfiltered (gdb_stdlog,
2238 "infrun: stepping past non-steppable watchpoint. "
2239 "skipping watchpoint at %s:%d\n",
2240 paddress (bl->gdbarch, bl->address),
2249 /* Same as should_be_inserted but does the check assuming
2250 that the location is not duplicated. */
2253 unduplicated_should_be_inserted (struct bp_location *bl)
2256 const int save_duplicate = bl->duplicate;
2259 result = should_be_inserted (bl);
2260 bl->duplicate = save_duplicate;
2264 /* Parses a conditional described by an expression COND into an
2265 agent expression bytecode suitable for evaluation
2266 by the bytecode interpreter. Return NULL if there was
2267 any error during parsing. */
2269 static struct agent_expr *
2270 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2272 struct agent_expr *aexpr = NULL;
2277 /* We don't want to stop processing, so catch any errors
2278 that may show up. */
2281 aexpr = gen_eval_for_expr (scope, cond);
2284 CATCH (ex, RETURN_MASK_ERROR)
2286 /* If we got here, it means the condition could not be parsed to a valid
2287 bytecode expression and thus can't be evaluated on the target's side.
2288 It's no use iterating through the conditions. */
2293 /* We have a valid agent expression. */
2297 /* Based on location BL, create a list of breakpoint conditions to be
2298 passed on to the target. If we have duplicated locations with different
2299 conditions, we will add such conditions to the list. The idea is that the
2300 target will evaluate the list of conditions and will only notify GDB when
2301 one of them is true. */
2304 build_target_condition_list (struct bp_location *bl)
2306 struct bp_location **locp = NULL, **loc2p;
2307 int null_condition_or_parse_error = 0;
2308 int modified = bl->needs_update;
2309 struct bp_location *loc;
2311 /* Release conditions left over from a previous insert. */
2312 VEC_free (agent_expr_p, bl->target_info.conditions);
2314 /* This is only meaningful if the target is
2315 evaluating conditions and if the user has
2316 opted for condition evaluation on the target's
2318 if (gdb_evaluates_breakpoint_condition_p ()
2319 || !target_supports_evaluation_of_breakpoint_conditions ())
2322 /* Do a first pass to check for locations with no assigned
2323 conditions or conditions that fail to parse to a valid agent expression
2324 bytecode. If any of these happen, then it's no use to send conditions
2325 to the target since this location will always trigger and generate a
2326 response back to GDB. */
2327 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2330 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2334 struct agent_expr *aexpr;
2336 /* Re-parse the conditions since something changed. In that
2337 case we already freed the condition bytecodes (see
2338 force_breakpoint_reinsertion). We just
2339 need to parse the condition to bytecodes again. */
2340 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2341 loc->cond_bytecode = aexpr;
2344 /* If we have a NULL bytecode expression, it means something
2345 went wrong or we have a null condition expression. */
2346 if (!loc->cond_bytecode)
2348 null_condition_or_parse_error = 1;
2354 /* If any of these happened, it means we will have to evaluate the conditions
2355 for the location's address on gdb's side. It is no use keeping bytecodes
2356 for all the other duplicate locations, thus we free all of them here.
2358 This is so we have a finer control over which locations' conditions are
2359 being evaluated by GDB or the remote stub. */
2360 if (null_condition_or_parse_error)
2362 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2365 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2367 /* Only go as far as the first NULL bytecode is
2369 if (!loc->cond_bytecode)
2372 free_agent_expr (loc->cond_bytecode);
2373 loc->cond_bytecode = NULL;
2378 /* No NULL conditions or failed bytecode generation. Build a condition list
2379 for this location's address. */
2380 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2384 && is_breakpoint (loc->owner)
2385 && loc->pspace->num == bl->pspace->num
2386 && loc->owner->enable_state == bp_enabled
2388 /* Add the condition to the vector. This will be used later to send the
2389 conditions to the target. */
2390 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2391 loc->cond_bytecode);
2397 /* Parses a command described by string CMD into an agent expression
2398 bytecode suitable for evaluation by the bytecode interpreter.
2399 Return NULL if there was any error during parsing. */
2401 static struct agent_expr *
2402 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2404 struct cleanup *old_cleanups = 0;
2405 struct expression *expr, **argvec;
2406 struct agent_expr *aexpr = NULL;
2407 const char *cmdrest;
2408 const char *format_start, *format_end;
2409 struct format_piece *fpieces;
2411 struct gdbarch *gdbarch = get_current_arch ();
2418 if (*cmdrest == ',')
2420 cmdrest = skip_spaces_const (cmdrest);
2422 if (*cmdrest++ != '"')
2423 error (_("No format string following the location"));
2425 format_start = cmdrest;
2427 fpieces = parse_format_string (&cmdrest);
2429 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2431 format_end = cmdrest;
2433 if (*cmdrest++ != '"')
2434 error (_("Bad format string, non-terminated '\"'."));
2436 cmdrest = skip_spaces_const (cmdrest);
2438 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2439 error (_("Invalid argument syntax"));
2441 if (*cmdrest == ',')
2443 cmdrest = skip_spaces_const (cmdrest);
2445 /* For each argument, make an expression. */
2447 argvec = (struct expression **) alloca (strlen (cmd)
2448 * sizeof (struct expression *));
2451 while (*cmdrest != '\0')
2456 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2457 argvec[nargs++] = expr;
2459 if (*cmdrest == ',')
2463 /* We don't want to stop processing, so catch any errors
2464 that may show up. */
2467 aexpr = gen_printf (scope, gdbarch, 0, 0,
2468 format_start, format_end - format_start,
2469 fpieces, nargs, argvec);
2471 CATCH (ex, RETURN_MASK_ERROR)
2473 /* If we got here, it means the command could not be parsed to a valid
2474 bytecode expression and thus can't be evaluated on the target's side.
2475 It's no use iterating through the other commands. */
2480 do_cleanups (old_cleanups);
2482 /* We have a valid agent expression, return it. */
2486 /* Based on location BL, create a list of breakpoint commands to be
2487 passed on to the target. If we have duplicated locations with
2488 different commands, we will add any such to the list. */
2491 build_target_command_list (struct bp_location *bl)
2493 struct bp_location **locp = NULL, **loc2p;
2494 int null_command_or_parse_error = 0;
2495 int modified = bl->needs_update;
2496 struct bp_location *loc;
2498 /* Release commands left over from a previous insert. */
2499 VEC_free (agent_expr_p, bl->target_info.tcommands);
2501 if (!target_can_run_breakpoint_commands ())
2504 /* For now, limit to agent-style dprintf breakpoints. */
2505 if (dprintf_style != dprintf_style_agent)
2508 /* For now, if we have any duplicate location that isn't a dprintf,
2509 don't install the target-side commands, as that would make the
2510 breakpoint not be reported to the core, and we'd lose
2512 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2515 if (is_breakpoint (loc->owner)
2516 && loc->pspace->num == bl->pspace->num
2517 && loc->owner->type != bp_dprintf)
2521 /* Do a first pass to check for locations with no assigned
2522 conditions or conditions that fail to parse to a valid agent expression
2523 bytecode. If any of these happen, then it's no use to send conditions
2524 to the target since this location will always trigger and generate a
2525 response back to GDB. */
2526 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2529 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2533 struct agent_expr *aexpr;
2535 /* Re-parse the commands since something changed. In that
2536 case we already freed the command bytecodes (see
2537 force_breakpoint_reinsertion). We just
2538 need to parse the command to bytecodes again. */
2539 aexpr = parse_cmd_to_aexpr (bl->address,
2540 loc->owner->extra_string);
2541 loc->cmd_bytecode = aexpr;
2544 /* If we have a NULL bytecode expression, it means something
2545 went wrong or we have a null command expression. */
2546 if (!loc->cmd_bytecode)
2548 null_command_or_parse_error = 1;
2554 /* If anything failed, then we're not doing target-side commands,
2556 if (null_command_or_parse_error)
2558 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2561 if (is_breakpoint (loc->owner)
2562 && loc->pspace->num == bl->pspace->num)
2564 /* Only go as far as the first NULL bytecode is
2566 if (loc->cmd_bytecode == NULL)
2569 free_agent_expr (loc->cmd_bytecode);
2570 loc->cmd_bytecode = NULL;
2575 /* No NULL commands or failed bytecode generation. Build a command list
2576 for this location's address. */
2577 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2580 if (loc->owner->extra_string
2581 && is_breakpoint (loc->owner)
2582 && loc->pspace->num == bl->pspace->num
2583 && loc->owner->enable_state == bp_enabled
2585 /* Add the command to the vector. This will be used later
2586 to send the commands to the target. */
2587 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2591 bl->target_info.persist = 0;
2592 /* Maybe flag this location as persistent. */
2593 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2594 bl->target_info.persist = 1;
2597 /* Return the kind of breakpoint on address *ADDR. Get the kind
2598 of breakpoint according to ADDR except single-step breakpoint.
2599 Get the kind of single-step breakpoint according to the current
2603 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2605 if (bl->owner->type == bp_single_step)
2607 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2608 struct regcache *regcache;
2610 regcache = get_thread_regcache (thr->ptid);
2612 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2616 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2619 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2620 location. Any error messages are printed to TMP_ERROR_STREAM; and
2621 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2622 Returns 0 for success, 1 if the bp_location type is not supported or
2625 NOTE drow/2003-09-09: This routine could be broken down to an
2626 object-style method for each breakpoint or catchpoint type. */
2628 insert_bp_location (struct bp_location *bl,
2629 struct ui_file *tmp_error_stream,
2630 int *disabled_breaks,
2631 int *hw_breakpoint_error,
2632 int *hw_bp_error_explained_already)
2634 enum errors bp_err = GDB_NO_ERROR;
2635 const char *bp_err_message = NULL;
2637 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2640 /* Note we don't initialize bl->target_info, as that wipes out
2641 the breakpoint location's shadow_contents if the breakpoint
2642 is still inserted at that location. This in turn breaks
2643 target_read_memory which depends on these buffers when
2644 a memory read is requested at the breakpoint location:
2645 Once the target_info has been wiped, we fail to see that
2646 we have a breakpoint inserted at that address and thus
2647 read the breakpoint instead of returning the data saved in
2648 the breakpoint location's shadow contents. */
2649 bl->target_info.reqstd_address = bl->address;
2650 bl->target_info.placed_address_space = bl->pspace->aspace;
2651 bl->target_info.length = bl->length;
2653 /* When working with target-side conditions, we must pass all the conditions
2654 for the same breakpoint address down to the target since GDB will not
2655 insert those locations. With a list of breakpoint conditions, the target
2656 can decide when to stop and notify GDB. */
2658 if (is_breakpoint (bl->owner))
2660 build_target_condition_list (bl);
2661 build_target_command_list (bl);
2662 /* Reset the modification marker. */
2663 bl->needs_update = 0;
2666 if (bl->loc_type == bp_loc_software_breakpoint
2667 || bl->loc_type == bp_loc_hardware_breakpoint)
2669 if (bl->owner->type != bp_hardware_breakpoint)
2671 /* If the explicitly specified breakpoint type
2672 is not hardware breakpoint, check the memory map to see
2673 if the breakpoint address is in read only memory or not.
2675 Two important cases are:
2676 - location type is not hardware breakpoint, memory
2677 is readonly. We change the type of the location to
2678 hardware breakpoint.
2679 - location type is hardware breakpoint, memory is
2680 read-write. This means we've previously made the
2681 location hardware one, but then the memory map changed,
2684 When breakpoints are removed, remove_breakpoints will use
2685 location types we've just set here, the only possible
2686 problem is that memory map has changed during running
2687 program, but it's not going to work anyway with current
2689 struct mem_region *mr
2690 = lookup_mem_region (bl->target_info.reqstd_address);
2694 if (automatic_hardware_breakpoints)
2696 enum bp_loc_type new_type;
2698 if (mr->attrib.mode != MEM_RW)
2699 new_type = bp_loc_hardware_breakpoint;
2701 new_type = bp_loc_software_breakpoint;
2703 if (new_type != bl->loc_type)
2705 static int said = 0;
2707 bl->loc_type = new_type;
2710 fprintf_filtered (gdb_stdout,
2711 _("Note: automatically using "
2712 "hardware breakpoints for "
2713 "read-only addresses.\n"));
2718 else if (bl->loc_type == bp_loc_software_breakpoint
2719 && mr->attrib.mode != MEM_RW)
2721 fprintf_unfiltered (tmp_error_stream,
2722 _("Cannot insert breakpoint %d.\n"
2723 "Cannot set software breakpoint "
2724 "at read-only address %s\n"),
2726 paddress (bl->gdbarch, bl->address));
2732 /* First check to see if we have to handle an overlay. */
2733 if (overlay_debugging == ovly_off
2734 || bl->section == NULL
2735 || !(section_is_overlay (bl->section)))
2737 /* No overlay handling: just set the breakpoint. */
2742 val = bl->owner->ops->insert_location (bl);
2744 bp_err = GENERIC_ERROR;
2746 CATCH (e, RETURN_MASK_ALL)
2749 bp_err_message = e.message;
2755 /* This breakpoint is in an overlay section.
2756 Shall we set a breakpoint at the LMA? */
2757 if (!overlay_events_enabled)
2759 /* Yes -- overlay event support is not active,
2760 so we must try to set a breakpoint at the LMA.
2761 This will not work for a hardware breakpoint. */
2762 if (bl->loc_type == bp_loc_hardware_breakpoint)
2763 warning (_("hardware breakpoint %d not supported in overlay!"),
2767 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2769 /* Set a software (trap) breakpoint at the LMA. */
2770 bl->overlay_target_info = bl->target_info;
2771 bl->overlay_target_info.reqstd_address = addr;
2773 /* No overlay handling: just set the breakpoint. */
2778 bl->overlay_target_info.kind
2779 = breakpoint_kind (bl, &addr);
2780 bl->overlay_target_info.placed_address = addr;
2781 val = target_insert_breakpoint (bl->gdbarch,
2782 &bl->overlay_target_info);
2784 bp_err = GENERIC_ERROR;
2786 CATCH (e, RETURN_MASK_ALL)
2789 bp_err_message = e.message;
2793 if (bp_err != GDB_NO_ERROR)
2794 fprintf_unfiltered (tmp_error_stream,
2795 "Overlay breakpoint %d "
2796 "failed: in ROM?\n",
2800 /* Shall we set a breakpoint at the VMA? */
2801 if (section_is_mapped (bl->section))
2803 /* Yes. This overlay section is mapped into memory. */
2808 val = bl->owner->ops->insert_location (bl);
2810 bp_err = GENERIC_ERROR;
2812 CATCH (e, RETURN_MASK_ALL)
2815 bp_err_message = e.message;
2821 /* No. This breakpoint will not be inserted.
2822 No error, but do not mark the bp as 'inserted'. */
2827 if (bp_err != GDB_NO_ERROR)
2829 /* Can't set the breakpoint. */
2831 /* In some cases, we might not be able to insert a
2832 breakpoint in a shared library that has already been
2833 removed, but we have not yet processed the shlib unload
2834 event. Unfortunately, some targets that implement
2835 breakpoint insertion themselves can't tell why the
2836 breakpoint insertion failed (e.g., the remote target
2837 doesn't define error codes), so we must treat generic
2838 errors as memory errors. */
2839 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2840 && bl->loc_type == bp_loc_software_breakpoint
2841 && (solib_name_from_address (bl->pspace, bl->address)
2842 || shared_objfile_contains_address_p (bl->pspace,
2845 /* See also: disable_breakpoints_in_shlibs. */
2846 bl->shlib_disabled = 1;
2847 observer_notify_breakpoint_modified (bl->owner);
2848 if (!*disabled_breaks)
2850 fprintf_unfiltered (tmp_error_stream,
2851 "Cannot insert breakpoint %d.\n",
2853 fprintf_unfiltered (tmp_error_stream,
2854 "Temporarily disabling shared "
2855 "library breakpoints:\n");
2857 *disabled_breaks = 1;
2858 fprintf_unfiltered (tmp_error_stream,
2859 "breakpoint #%d\n", bl->owner->number);
2864 if (bl->loc_type == bp_loc_hardware_breakpoint)
2866 *hw_breakpoint_error = 1;
2867 *hw_bp_error_explained_already = bp_err_message != NULL;
2868 fprintf_unfiltered (tmp_error_stream,
2869 "Cannot insert hardware breakpoint %d%s",
2870 bl->owner->number, bp_err_message ? ":" : ".\n");
2871 if (bp_err_message != NULL)
2872 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2876 if (bp_err_message == NULL)
2879 = memory_error_message (TARGET_XFER_E_IO,
2880 bl->gdbarch, bl->address);
2881 struct cleanup *old_chain = make_cleanup (xfree, message);
2883 fprintf_unfiltered (tmp_error_stream,
2884 "Cannot insert breakpoint %d.\n"
2886 bl->owner->number, message);
2887 do_cleanups (old_chain);
2891 fprintf_unfiltered (tmp_error_stream,
2892 "Cannot insert breakpoint %d: %s\n",
2907 else if (bl->loc_type == bp_loc_hardware_watchpoint
2908 /* NOTE drow/2003-09-08: This state only exists for removing
2909 watchpoints. It's not clear that it's necessary... */
2910 && bl->owner->disposition != disp_del_at_next_stop)
2914 gdb_assert (bl->owner->ops != NULL
2915 && bl->owner->ops->insert_location != NULL);
2917 val = bl->owner->ops->insert_location (bl);
2919 /* If trying to set a read-watchpoint, and it turns out it's not
2920 supported, try emulating one with an access watchpoint. */
2921 if (val == 1 && bl->watchpoint_type == hw_read)
2923 struct bp_location *loc, **loc_temp;
2925 /* But don't try to insert it, if there's already another
2926 hw_access location that would be considered a duplicate
2928 ALL_BP_LOCATIONS (loc, loc_temp)
2930 && loc->watchpoint_type == hw_access
2931 && watchpoint_locations_match (bl, loc))
2935 bl->target_info = loc->target_info;
2936 bl->watchpoint_type = hw_access;
2943 bl->watchpoint_type = hw_access;
2944 val = bl->owner->ops->insert_location (bl);
2947 /* Back to the original value. */
2948 bl->watchpoint_type = hw_read;
2952 bl->inserted = (val == 0);
2955 else if (bl->owner->type == bp_catchpoint)
2959 gdb_assert (bl->owner->ops != NULL
2960 && bl->owner->ops->insert_location != NULL);
2962 val = bl->owner->ops->insert_location (bl);
2965 bl->owner->enable_state = bp_disabled;
2969 Error inserting catchpoint %d: Your system does not support this type\n\
2970 of catchpoint."), bl->owner->number);
2972 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2975 bl->inserted = (val == 0);
2977 /* We've already printed an error message if there was a problem
2978 inserting this catchpoint, and we've disabled the catchpoint,
2979 so just return success. */
2986 /* This function is called when program space PSPACE is about to be
2987 deleted. It takes care of updating breakpoints to not reference
2991 breakpoint_program_space_exit (struct program_space *pspace)
2993 struct breakpoint *b, *b_temp;
2994 struct bp_location *loc, **loc_temp;
2996 /* Remove any breakpoint that was set through this program space. */
2997 ALL_BREAKPOINTS_SAFE (b, b_temp)
2999 if (b->pspace == pspace)
3000 delete_breakpoint (b);
3003 /* Breakpoints set through other program spaces could have locations
3004 bound to PSPACE as well. Remove those. */
3005 ALL_BP_LOCATIONS (loc, loc_temp)
3007 struct bp_location *tmp;
3009 if (loc->pspace == pspace)
3011 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3012 if (loc->owner->loc == loc)
3013 loc->owner->loc = loc->next;
3015 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
3016 if (tmp->next == loc)
3018 tmp->next = loc->next;
3024 /* Now update the global location list to permanently delete the
3025 removed locations above. */
3026 update_global_location_list (UGLL_DONT_INSERT);
3029 /* Make sure all breakpoints are inserted in inferior.
3030 Throws exception on any error.
3031 A breakpoint that is already inserted won't be inserted
3032 again, so calling this function twice is safe. */
3034 insert_breakpoints (void)
3036 struct breakpoint *bpt;
3038 ALL_BREAKPOINTS (bpt)
3039 if (is_hardware_watchpoint (bpt))
3041 struct watchpoint *w = (struct watchpoint *) bpt;
3043 update_watchpoint (w, 0 /* don't reparse. */);
3046 /* Updating watchpoints creates new locations, so update the global
3047 location list. Explicitly tell ugll to insert locations and
3048 ignore breakpoints_always_inserted_mode. */
3049 update_global_location_list (UGLL_INSERT);
3052 /* Invoke CALLBACK for each of bp_location. */
3055 iterate_over_bp_locations (walk_bp_location_callback callback)
3057 struct bp_location *loc, **loc_tmp;
3059 ALL_BP_LOCATIONS (loc, loc_tmp)
3061 callback (loc, NULL);
3065 /* This is used when we need to synch breakpoint conditions between GDB and the
3066 target. It is the case with deleting and disabling of breakpoints when using
3067 always-inserted mode. */
3070 update_inserted_breakpoint_locations (void)
3072 struct bp_location *bl, **blp_tmp;
3075 int disabled_breaks = 0;
3076 int hw_breakpoint_error = 0;
3077 int hw_bp_details_reported = 0;
3079 struct ui_file *tmp_error_stream = mem_fileopen ();
3080 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3082 /* Explicitly mark the warning -- this will only be printed if
3083 there was an error. */
3084 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3086 save_current_space_and_thread ();
3088 ALL_BP_LOCATIONS (bl, blp_tmp)
3090 /* We only want to update software breakpoints and hardware
3092 if (!is_breakpoint (bl->owner))
3095 /* We only want to update locations that are already inserted
3096 and need updating. This is to avoid unwanted insertion during
3097 deletion of breakpoints. */
3098 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3101 switch_to_program_space_and_thread (bl->pspace);
3103 /* For targets that support global breakpoints, there's no need
3104 to select an inferior to insert breakpoint to. In fact, even
3105 if we aren't attached to any process yet, we should still
3106 insert breakpoints. */
3107 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3108 && ptid_equal (inferior_ptid, null_ptid))
3111 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3112 &hw_breakpoint_error, &hw_bp_details_reported);
3119 target_terminal_ours_for_output ();
3120 error_stream (tmp_error_stream);
3123 do_cleanups (cleanups);
3126 /* Used when starting or continuing the program. */
3129 insert_breakpoint_locations (void)
3131 struct breakpoint *bpt;
3132 struct bp_location *bl, **blp_tmp;
3135 int disabled_breaks = 0;
3136 int hw_breakpoint_error = 0;
3137 int hw_bp_error_explained_already = 0;
3139 struct ui_file *tmp_error_stream = mem_fileopen ();
3140 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3142 /* Explicitly mark the warning -- this will only be printed if
3143 there was an error. */
3144 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3146 save_current_space_and_thread ();
3148 ALL_BP_LOCATIONS (bl, blp_tmp)
3150 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3153 /* There is no point inserting thread-specific breakpoints if
3154 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3155 has BL->OWNER always non-NULL. */
3156 if (bl->owner->thread != -1
3157 && !valid_global_thread_id (bl->owner->thread))
3160 switch_to_program_space_and_thread (bl->pspace);
3162 /* For targets that support global breakpoints, there's no need
3163 to select an inferior to insert breakpoint to. In fact, even
3164 if we aren't attached to any process yet, we should still
3165 insert breakpoints. */
3166 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3167 && ptid_equal (inferior_ptid, null_ptid))
3170 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3171 &hw_breakpoint_error, &hw_bp_error_explained_already);
3176 /* If we failed to insert all locations of a watchpoint, remove
3177 them, as half-inserted watchpoint is of limited use. */
3178 ALL_BREAKPOINTS (bpt)
3180 int some_failed = 0;
3181 struct bp_location *loc;
3183 if (!is_hardware_watchpoint (bpt))
3186 if (!breakpoint_enabled (bpt))
3189 if (bpt->disposition == disp_del_at_next_stop)
3192 for (loc = bpt->loc; loc; loc = loc->next)
3193 if (!loc->inserted && should_be_inserted (loc))
3200 for (loc = bpt->loc; loc; loc = loc->next)
3202 remove_breakpoint (loc);
3204 hw_breakpoint_error = 1;
3205 fprintf_unfiltered (tmp_error_stream,
3206 "Could not insert hardware watchpoint %d.\n",
3214 /* If a hardware breakpoint or watchpoint was inserted, add a
3215 message about possibly exhausted resources. */
3216 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3218 fprintf_unfiltered (tmp_error_stream,
3219 "Could not insert hardware breakpoints:\n\
3220 You may have requested too many hardware breakpoints/watchpoints.\n");
3222 target_terminal_ours_for_output ();
3223 error_stream (tmp_error_stream);
3226 do_cleanups (cleanups);
3229 /* Used when the program stops.
3230 Returns zero if successful, or non-zero if there was a problem
3231 removing a breakpoint location. */
3234 remove_breakpoints (void)
3236 struct bp_location *bl, **blp_tmp;
3239 ALL_BP_LOCATIONS (bl, blp_tmp)
3241 if (bl->inserted && !is_tracepoint (bl->owner))
3242 val |= remove_breakpoint (bl);
3247 /* When a thread exits, remove breakpoints that are related to
3251 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3253 struct breakpoint *b, *b_tmp;
3255 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3257 if (b->thread == tp->global_num && user_breakpoint_p (b))
3259 b->disposition = disp_del_at_next_stop;
3261 printf_filtered (_("\
3262 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3263 b->number, print_thread_id (tp));
3265 /* Hide it from the user. */
3271 /* Remove breakpoints of process PID. */
3274 remove_breakpoints_pid (int pid)
3276 struct bp_location *bl, **blp_tmp;
3278 struct inferior *inf = find_inferior_pid (pid);
3280 ALL_BP_LOCATIONS (bl, blp_tmp)
3282 if (bl->pspace != inf->pspace)
3285 if (bl->inserted && !bl->target_info.persist)
3287 val = remove_breakpoint (bl);
3296 reattach_breakpoints (int pid)
3298 struct cleanup *old_chain;
3299 struct bp_location *bl, **blp_tmp;
3301 struct ui_file *tmp_error_stream;
3302 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3303 struct inferior *inf;
3304 struct thread_info *tp;
3306 tp = any_live_thread_of_process (pid);
3310 inf = find_inferior_pid (pid);
3311 old_chain = save_inferior_ptid ();
3313 inferior_ptid = tp->ptid;
3315 tmp_error_stream = mem_fileopen ();
3316 make_cleanup_ui_file_delete (tmp_error_stream);
3318 ALL_BP_LOCATIONS (bl, blp_tmp)
3320 if (bl->pspace != inf->pspace)
3326 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3329 do_cleanups (old_chain);
3334 do_cleanups (old_chain);
3338 static int internal_breakpoint_number = -1;
3340 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3341 If INTERNAL is non-zero, the breakpoint number will be populated
3342 from internal_breakpoint_number and that variable decremented.
3343 Otherwise the breakpoint number will be populated from
3344 breakpoint_count and that value incremented. Internal breakpoints
3345 do not set the internal var bpnum. */
3347 set_breakpoint_number (int internal, struct breakpoint *b)
3350 b->number = internal_breakpoint_number--;
3353 set_breakpoint_count (breakpoint_count + 1);
3354 b->number = breakpoint_count;
3358 static struct breakpoint *
3359 create_internal_breakpoint (struct gdbarch *gdbarch,
3360 CORE_ADDR address, enum bptype type,
3361 const struct breakpoint_ops *ops)
3363 struct symtab_and_line sal;
3364 struct breakpoint *b;
3366 init_sal (&sal); /* Initialize to zeroes. */
3369 sal.section = find_pc_overlay (sal.pc);
3370 sal.pspace = current_program_space;
3372 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3373 b->number = internal_breakpoint_number--;
3374 b->disposition = disp_donttouch;
3379 static const char *const longjmp_names[] =
3381 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3383 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3385 /* Per-objfile data private to breakpoint.c. */
3386 struct breakpoint_objfile_data
3388 /* Minimal symbol for "_ovly_debug_event" (if any). */
3389 struct bound_minimal_symbol overlay_msym;
3391 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3392 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3394 /* True if we have looked for longjmp probes. */
3395 int longjmp_searched;
3397 /* SystemTap probe points for longjmp (if any). */
3398 VEC (probe_p) *longjmp_probes;
3400 /* Minimal symbol for "std::terminate()" (if any). */
3401 struct bound_minimal_symbol terminate_msym;
3403 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3404 struct bound_minimal_symbol exception_msym;
3406 /* True if we have looked for exception probes. */
3407 int exception_searched;
3409 /* SystemTap probe points for unwinding (if any). */
3410 VEC (probe_p) *exception_probes;
3413 static const struct objfile_data *breakpoint_objfile_key;
3415 /* Minimal symbol not found sentinel. */
3416 static struct minimal_symbol msym_not_found;
3418 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3421 msym_not_found_p (const struct minimal_symbol *msym)
3423 return msym == &msym_not_found;
3426 /* Return per-objfile data needed by breakpoint.c.
3427 Allocate the data if necessary. */
3429 static struct breakpoint_objfile_data *
3430 get_breakpoint_objfile_data (struct objfile *objfile)
3432 struct breakpoint_objfile_data *bp_objfile_data;
3434 bp_objfile_data = ((struct breakpoint_objfile_data *)
3435 objfile_data (objfile, breakpoint_objfile_key));
3436 if (bp_objfile_data == NULL)
3439 XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
3441 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3442 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3444 return bp_objfile_data;
3448 free_breakpoint_probes (struct objfile *obj, void *data)
3450 struct breakpoint_objfile_data *bp_objfile_data
3451 = (struct breakpoint_objfile_data *) data;
3453 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3454 VEC_free (probe_p, bp_objfile_data->exception_probes);
3458 create_overlay_event_breakpoint (void)
3460 struct objfile *objfile;
3461 const char *const func_name = "_ovly_debug_event";
3463 ALL_OBJFILES (objfile)
3465 struct breakpoint *b;
3466 struct breakpoint_objfile_data *bp_objfile_data;
3468 struct explicit_location explicit_loc;
3470 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3472 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3475 if (bp_objfile_data->overlay_msym.minsym == NULL)
3477 struct bound_minimal_symbol m;
3479 m = lookup_minimal_symbol_text (func_name, objfile);
3480 if (m.minsym == NULL)
3482 /* Avoid future lookups in this objfile. */
3483 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3486 bp_objfile_data->overlay_msym = m;
3489 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3490 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3492 &internal_breakpoint_ops);
3493 initialize_explicit_location (&explicit_loc);
3494 explicit_loc.function_name = ASTRDUP (func_name);
3495 b->location = new_explicit_location (&explicit_loc);
3497 if (overlay_debugging == ovly_auto)
3499 b->enable_state = bp_enabled;
3500 overlay_events_enabled = 1;
3504 b->enable_state = bp_disabled;
3505 overlay_events_enabled = 0;
3511 create_longjmp_master_breakpoint (void)
3513 struct program_space *pspace;
3514 struct cleanup *old_chain;
3516 old_chain = save_current_program_space ();
3518 ALL_PSPACES (pspace)
3520 struct objfile *objfile;
3522 set_current_program_space (pspace);
3524 ALL_OBJFILES (objfile)
3527 struct gdbarch *gdbarch;
3528 struct breakpoint_objfile_data *bp_objfile_data;
3530 gdbarch = get_objfile_arch (objfile);
3532 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3534 if (!bp_objfile_data->longjmp_searched)
3538 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3541 /* We are only interested in checking one element. */
3542 struct probe *p = VEC_index (probe_p, ret, 0);
3544 if (!can_evaluate_probe_arguments (p))
3546 /* We cannot use the probe interface here, because it does
3547 not know how to evaluate arguments. */
3548 VEC_free (probe_p, ret);
3552 bp_objfile_data->longjmp_probes = ret;
3553 bp_objfile_data->longjmp_searched = 1;
3556 if (bp_objfile_data->longjmp_probes != NULL)
3559 struct probe *probe;
3560 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3563 VEC_iterate (probe_p,
3564 bp_objfile_data->longjmp_probes,
3568 struct breakpoint *b;
3570 b = create_internal_breakpoint (gdbarch,
3571 get_probe_address (probe,
3574 &internal_breakpoint_ops);
3576 = new_probe_location ("-probe-stap libc:longjmp");
3577 b->enable_state = bp_disabled;
3583 if (!gdbarch_get_longjmp_target_p (gdbarch))
3586 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3588 struct breakpoint *b;
3589 const char *func_name;
3591 struct explicit_location explicit_loc;
3593 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3596 func_name = longjmp_names[i];
3597 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3599 struct bound_minimal_symbol m;
3601 m = lookup_minimal_symbol_text (func_name, objfile);
3602 if (m.minsym == NULL)
3604 /* Prevent future lookups in this objfile. */
3605 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3608 bp_objfile_data->longjmp_msym[i] = m;
3611 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3612 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3613 &internal_breakpoint_ops);
3614 initialize_explicit_location (&explicit_loc);
3615 explicit_loc.function_name = ASTRDUP (func_name);
3616 b->location = new_explicit_location (&explicit_loc);
3617 b->enable_state = bp_disabled;
3622 do_cleanups (old_chain);
3625 /* Create a master std::terminate breakpoint. */
3627 create_std_terminate_master_breakpoint (void)
3629 struct program_space *pspace;
3630 struct cleanup *old_chain;
3631 const char *const func_name = "std::terminate()";
3633 old_chain = save_current_program_space ();
3635 ALL_PSPACES (pspace)
3637 struct objfile *objfile;
3640 set_current_program_space (pspace);
3642 ALL_OBJFILES (objfile)
3644 struct breakpoint *b;
3645 struct breakpoint_objfile_data *bp_objfile_data;
3646 struct explicit_location explicit_loc;
3648 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3650 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3653 if (bp_objfile_data->terminate_msym.minsym == NULL)
3655 struct bound_minimal_symbol m;
3657 m = lookup_minimal_symbol (func_name, NULL, objfile);
3658 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3659 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3661 /* Prevent future lookups in this objfile. */
3662 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3665 bp_objfile_data->terminate_msym = m;
3668 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3669 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3670 bp_std_terminate_master,
3671 &internal_breakpoint_ops);
3672 initialize_explicit_location (&explicit_loc);
3673 explicit_loc.function_name = ASTRDUP (func_name);
3674 b->location = new_explicit_location (&explicit_loc);
3675 b->enable_state = bp_disabled;
3679 do_cleanups (old_chain);
3682 /* Install a master breakpoint on the unwinder's debug hook. */
3685 create_exception_master_breakpoint (void)
3687 struct objfile *objfile;
3688 const char *const func_name = "_Unwind_DebugHook";
3690 ALL_OBJFILES (objfile)
3692 struct breakpoint *b;
3693 struct gdbarch *gdbarch;
3694 struct breakpoint_objfile_data *bp_objfile_data;
3696 struct explicit_location explicit_loc;
3698 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3700 /* We prefer the SystemTap probe point if it exists. */
3701 if (!bp_objfile_data->exception_searched)
3705 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3709 /* We are only interested in checking one element. */
3710 struct probe *p = VEC_index (probe_p, ret, 0);
3712 if (!can_evaluate_probe_arguments (p))
3714 /* We cannot use the probe interface here, because it does
3715 not know how to evaluate arguments. */
3716 VEC_free (probe_p, ret);
3720 bp_objfile_data->exception_probes = ret;
3721 bp_objfile_data->exception_searched = 1;
3724 if (bp_objfile_data->exception_probes != NULL)
3726 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3728 struct probe *probe;
3731 VEC_iterate (probe_p,
3732 bp_objfile_data->exception_probes,
3736 struct breakpoint *b;
3738 b = create_internal_breakpoint (gdbarch,
3739 get_probe_address (probe,
3741 bp_exception_master,
3742 &internal_breakpoint_ops);
3744 = new_probe_location ("-probe-stap libgcc:unwind");
3745 b->enable_state = bp_disabled;
3751 /* Otherwise, try the hook function. */
3753 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3756 gdbarch = get_objfile_arch (objfile);
3758 if (bp_objfile_data->exception_msym.minsym == NULL)
3760 struct bound_minimal_symbol debug_hook;
3762 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3763 if (debug_hook.minsym == NULL)
3765 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3769 bp_objfile_data->exception_msym = debug_hook;
3772 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3773 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3775 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3776 &internal_breakpoint_ops);
3777 initialize_explicit_location (&explicit_loc);
3778 explicit_loc.function_name = ASTRDUP (func_name);
3779 b->location = new_explicit_location (&explicit_loc);
3780 b->enable_state = bp_disabled;
3784 /* Does B have a location spec? */
3787 breakpoint_event_location_empty_p (const struct breakpoint *b)
3789 return b->location != NULL && event_location_empty_p (b->location);
3793 update_breakpoints_after_exec (void)
3795 struct breakpoint *b, *b_tmp;
3796 struct bp_location *bploc, **bplocp_tmp;
3798 /* We're about to delete breakpoints from GDB's lists. If the
3799 INSERTED flag is true, GDB will try to lift the breakpoints by
3800 writing the breakpoints' "shadow contents" back into memory. The
3801 "shadow contents" are NOT valid after an exec, so GDB should not
3802 do that. Instead, the target is responsible from marking
3803 breakpoints out as soon as it detects an exec. We don't do that
3804 here instead, because there may be other attempts to delete
3805 breakpoints after detecting an exec and before reaching here. */
3806 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3807 if (bploc->pspace == current_program_space)
3808 gdb_assert (!bploc->inserted);
3810 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3812 if (b->pspace != current_program_space)
3815 /* Solib breakpoints must be explicitly reset after an exec(). */
3816 if (b->type == bp_shlib_event)
3818 delete_breakpoint (b);
3822 /* JIT breakpoints must be explicitly reset after an exec(). */
3823 if (b->type == bp_jit_event)
3825 delete_breakpoint (b);
3829 /* Thread event breakpoints must be set anew after an exec(),
3830 as must overlay event and longjmp master breakpoints. */
3831 if (b->type == bp_thread_event || b->type == bp_overlay_event
3832 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3833 || b->type == bp_exception_master)
3835 delete_breakpoint (b);
3839 /* Step-resume breakpoints are meaningless after an exec(). */
3840 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3842 delete_breakpoint (b);
3846 /* Just like single-step breakpoints. */
3847 if (b->type == bp_single_step)
3849 delete_breakpoint (b);
3853 /* Longjmp and longjmp-resume breakpoints are also meaningless
3855 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3856 || b->type == bp_longjmp_call_dummy
3857 || b->type == bp_exception || b->type == bp_exception_resume)
3859 delete_breakpoint (b);
3863 if (b->type == bp_catchpoint)
3865 /* For now, none of the bp_catchpoint breakpoints need to
3866 do anything at this point. In the future, if some of
3867 the catchpoints need to something, we will need to add
3868 a new method, and call this method from here. */
3872 /* bp_finish is a special case. The only way we ought to be able
3873 to see one of these when an exec() has happened, is if the user
3874 caught a vfork, and then said "finish". Ordinarily a finish just
3875 carries them to the call-site of the current callee, by setting
3876 a temporary bp there and resuming. But in this case, the finish
3877 will carry them entirely through the vfork & exec.
3879 We don't want to allow a bp_finish to remain inserted now. But
3880 we can't safely delete it, 'cause finish_command has a handle to
3881 the bp on a bpstat, and will later want to delete it. There's a
3882 chance (and I've seen it happen) that if we delete the bp_finish
3883 here, that its storage will get reused by the time finish_command
3884 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3885 We really must allow finish_command to delete a bp_finish.
3887 In the absence of a general solution for the "how do we know
3888 it's safe to delete something others may have handles to?"
3889 problem, what we'll do here is just uninsert the bp_finish, and
3890 let finish_command delete it.
3892 (We know the bp_finish is "doomed" in the sense that it's
3893 momentary, and will be deleted as soon as finish_command sees
3894 the inferior stopped. So it doesn't matter that the bp's
3895 address is probably bogus in the new a.out, unlike e.g., the
3896 solib breakpoints.) */
3898 if (b->type == bp_finish)
3903 /* Without a symbolic address, we have little hope of the
3904 pre-exec() address meaning the same thing in the post-exec()
3906 if (breakpoint_event_location_empty_p (b))
3908 delete_breakpoint (b);
3915 detach_breakpoints (ptid_t ptid)
3917 struct bp_location *bl, **blp_tmp;
3919 struct cleanup *old_chain = save_inferior_ptid ();
3920 struct inferior *inf = current_inferior ();
3922 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3923 error (_("Cannot detach breakpoints of inferior_ptid"));
3925 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3926 inferior_ptid = ptid;
3927 ALL_BP_LOCATIONS (bl, blp_tmp)
3929 if (bl->pspace != inf->pspace)
3932 /* This function must physically remove breakpoints locations
3933 from the specified ptid, without modifying the breakpoint
3934 package's state. Locations of type bp_loc_other are only
3935 maintained at GDB side. So, there is no need to remove
3936 these bp_loc_other locations. Moreover, removing these
3937 would modify the breakpoint package's state. */
3938 if (bl->loc_type == bp_loc_other)
3942 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3945 do_cleanups (old_chain);
3949 /* Remove the breakpoint location BL from the current address space.
3950 Note that this is used to detach breakpoints from a child fork.
3951 When we get here, the child isn't in the inferior list, and neither
3952 do we have objects to represent its address space --- we should
3953 *not* look at bl->pspace->aspace here. */
3956 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3960 /* BL is never in moribund_locations by our callers. */
3961 gdb_assert (bl->owner != NULL);
3963 /* The type of none suggests that owner is actually deleted.
3964 This should not ever happen. */
3965 gdb_assert (bl->owner->type != bp_none);
3967 if (bl->loc_type == bp_loc_software_breakpoint
3968 || bl->loc_type == bp_loc_hardware_breakpoint)
3970 /* "Normal" instruction breakpoint: either the standard
3971 trap-instruction bp (bp_breakpoint), or a
3972 bp_hardware_breakpoint. */
3974 /* First check to see if we have to handle an overlay. */
3975 if (overlay_debugging == ovly_off
3976 || bl->section == NULL
3977 || !(section_is_overlay (bl->section)))
3979 /* No overlay handling: just remove the breakpoint. */
3981 /* If we're trying to uninsert a memory breakpoint that we
3982 know is set in a dynamic object that is marked
3983 shlib_disabled, then either the dynamic object was
3984 removed with "remove-symbol-file" or with
3985 "nosharedlibrary". In the former case, we don't know
3986 whether another dynamic object might have loaded over the
3987 breakpoint's address -- the user might well let us know
3988 about it next with add-symbol-file (the whole point of
3989 add-symbol-file is letting the user manually maintain a
3990 list of dynamically loaded objects). If we have the
3991 breakpoint's shadow memory, that is, this is a software
3992 breakpoint managed by GDB, check whether the breakpoint
3993 is still inserted in memory, to avoid overwriting wrong
3994 code with stale saved shadow contents. Note that HW
3995 breakpoints don't have shadow memory, as they're
3996 implemented using a mechanism that is not dependent on
3997 being able to modify the target's memory, and as such
3998 they should always be removed. */
3999 if (bl->shlib_disabled
4000 && bl->target_info.shadow_len != 0
4001 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
4004 val = bl->owner->ops->remove_location (bl, reason);
4008 /* This breakpoint is in an overlay section.
4009 Did we set a breakpoint at the LMA? */
4010 if (!overlay_events_enabled)
4012 /* Yes -- overlay event support is not active, so we
4013 should have set a breakpoint at the LMA. Remove it.
4015 /* Ignore any failures: if the LMA is in ROM, we will
4016 have already warned when we failed to insert it. */
4017 if (bl->loc_type == bp_loc_hardware_breakpoint)
4018 target_remove_hw_breakpoint (bl->gdbarch,
4019 &bl->overlay_target_info);
4021 target_remove_breakpoint (bl->gdbarch,
4022 &bl->overlay_target_info,
4025 /* Did we set a breakpoint at the VMA?
4026 If so, we will have marked the breakpoint 'inserted'. */
4029 /* Yes -- remove it. Previously we did not bother to
4030 remove the breakpoint if the section had been
4031 unmapped, but let's not rely on that being safe. We
4032 don't know what the overlay manager might do. */
4034 /* However, we should remove *software* breakpoints only
4035 if the section is still mapped, or else we overwrite
4036 wrong code with the saved shadow contents. */
4037 if (bl->loc_type == bp_loc_hardware_breakpoint
4038 || section_is_mapped (bl->section))
4039 val = bl->owner->ops->remove_location (bl, reason);
4045 /* No -- not inserted, so no need to remove. No error. */
4050 /* In some cases, we might not be able to remove a breakpoint in
4051 a shared library that has already been removed, but we have
4052 not yet processed the shlib unload event. Similarly for an
4053 unloaded add-symbol-file object - the user might not yet have
4054 had the chance to remove-symbol-file it. shlib_disabled will
4055 be set if the library/object has already been removed, but
4056 the breakpoint hasn't been uninserted yet, e.g., after
4057 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4058 always-inserted mode. */
4060 && (bl->loc_type == bp_loc_software_breakpoint
4061 && (bl->shlib_disabled
4062 || solib_name_from_address (bl->pspace, bl->address)
4063 || shared_objfile_contains_address_p (bl->pspace,
4069 bl->inserted = (reason == DETACH_BREAKPOINT);
4071 else if (bl->loc_type == bp_loc_hardware_watchpoint)
4073 gdb_assert (bl->owner->ops != NULL
4074 && bl->owner->ops->remove_location != NULL);
4076 bl->inserted = (reason == DETACH_BREAKPOINT);
4077 bl->owner->ops->remove_location (bl, reason);
4079 /* Failure to remove any of the hardware watchpoints comes here. */
4080 if (reason == REMOVE_BREAKPOINT && bl->inserted)
4081 warning (_("Could not remove hardware watchpoint %d."),
4084 else if (bl->owner->type == bp_catchpoint
4085 && breakpoint_enabled (bl->owner)
4088 gdb_assert (bl->owner->ops != NULL
4089 && bl->owner->ops->remove_location != NULL);
4091 val = bl->owner->ops->remove_location (bl, reason);
4095 bl->inserted = (reason == DETACH_BREAKPOINT);
4102 remove_breakpoint (struct bp_location *bl)
4105 struct cleanup *old_chain;
4107 /* BL is never in moribund_locations by our callers. */
4108 gdb_assert (bl->owner != NULL);
4110 /* The type of none suggests that owner is actually deleted.
4111 This should not ever happen. */
4112 gdb_assert (bl->owner->type != bp_none);
4114 old_chain = save_current_space_and_thread ();
4116 switch_to_program_space_and_thread (bl->pspace);
4118 ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
4120 do_cleanups (old_chain);
4124 /* Clear the "inserted" flag in all breakpoints. */
4127 mark_breakpoints_out (void)
4129 struct bp_location *bl, **blp_tmp;
4131 ALL_BP_LOCATIONS (bl, blp_tmp)
4132 if (bl->pspace == current_program_space)
4136 /* Clear the "inserted" flag in all breakpoints and delete any
4137 breakpoints which should go away between runs of the program.
4139 Plus other such housekeeping that has to be done for breakpoints
4142 Note: this function gets called at the end of a run (by
4143 generic_mourn_inferior) and when a run begins (by
4144 init_wait_for_inferior). */
4149 breakpoint_init_inferior (enum inf_context context)
4151 struct breakpoint *b, *b_tmp;
4152 struct bp_location *bl;
4154 struct program_space *pspace = current_program_space;
4156 /* If breakpoint locations are shared across processes, then there's
4158 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4161 mark_breakpoints_out ();
4163 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4165 if (b->loc && b->loc->pspace != pspace)
4171 case bp_longjmp_call_dummy:
4173 /* If the call dummy breakpoint is at the entry point it will
4174 cause problems when the inferior is rerun, so we better get
4177 case bp_watchpoint_scope:
4179 /* Also get rid of scope breakpoints. */
4181 case bp_shlib_event:
4183 /* Also remove solib event breakpoints. Their addresses may
4184 have changed since the last time we ran the program.
4185 Actually we may now be debugging against different target;
4186 and so the solib backend that installed this breakpoint may
4187 not be used in by the target. E.g.,
4189 (gdb) file prog-linux
4190 (gdb) run # native linux target
4193 (gdb) file prog-win.exe
4194 (gdb) tar rem :9999 # remote Windows gdbserver.
4197 case bp_step_resume:
4199 /* Also remove step-resume breakpoints. */
4201 case bp_single_step:
4203 /* Also remove single-step breakpoints. */
4205 delete_breakpoint (b);
4209 case bp_hardware_watchpoint:
4210 case bp_read_watchpoint:
4211 case bp_access_watchpoint:
4213 struct watchpoint *w = (struct watchpoint *) b;
4215 /* Likewise for watchpoints on local expressions. */
4216 if (w->exp_valid_block != NULL)
4217 delete_breakpoint (b);
4220 /* Get rid of existing locations, which are no longer
4221 valid. New ones will be created in
4222 update_watchpoint, when the inferior is restarted.
4223 The next update_global_location_list call will
4224 garbage collect them. */
4227 if (context == inf_starting)
4229 /* Reset val field to force reread of starting value in
4230 insert_breakpoints. */
4232 value_free (w->val);
4244 /* Get rid of the moribund locations. */
4245 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4246 decref_bp_location (&bl);
4247 VEC_free (bp_location_p, moribund_locations);
4250 /* These functions concern about actual breakpoints inserted in the
4251 target --- to e.g. check if we need to do decr_pc adjustment or if
4252 we need to hop over the bkpt --- so we check for address space
4253 match, not program space. */
4255 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4256 exists at PC. It returns ordinary_breakpoint_here if it's an
4257 ordinary breakpoint, or permanent_breakpoint_here if it's a
4258 permanent breakpoint.
4259 - When continuing from a location with an ordinary breakpoint, we
4260 actually single step once before calling insert_breakpoints.
4261 - When continuing from a location with a permanent breakpoint, we
4262 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4263 the target, to advance the PC past the breakpoint. */
4265 enum breakpoint_here
4266 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4268 struct bp_location *bl, **blp_tmp;
4269 int any_breakpoint_here = 0;
4271 ALL_BP_LOCATIONS (bl, blp_tmp)
4273 if (bl->loc_type != bp_loc_software_breakpoint
4274 && bl->loc_type != bp_loc_hardware_breakpoint)
4277 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4278 if ((breakpoint_enabled (bl->owner)
4280 && breakpoint_location_address_match (bl, aspace, pc))
4282 if (overlay_debugging
4283 && section_is_overlay (bl->section)
4284 && !section_is_mapped (bl->section))
4285 continue; /* unmapped overlay -- can't be a match */
4286 else if (bl->permanent)
4287 return permanent_breakpoint_here;
4289 any_breakpoint_here = 1;
4293 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4296 /* See breakpoint.h. */
4299 breakpoint_in_range_p (struct address_space *aspace,
4300 CORE_ADDR addr, ULONGEST len)
4302 struct bp_location *bl, **blp_tmp;
4304 ALL_BP_LOCATIONS (bl, blp_tmp)
4306 if (bl->loc_type != bp_loc_software_breakpoint
4307 && bl->loc_type != bp_loc_hardware_breakpoint)
4310 if ((breakpoint_enabled (bl->owner)
4312 && breakpoint_location_address_range_overlap (bl, aspace,
4315 if (overlay_debugging
4316 && section_is_overlay (bl->section)
4317 && !section_is_mapped (bl->section))
4319 /* Unmapped overlay -- can't be a match. */
4330 /* Return true if there's a moribund breakpoint at PC. */
4333 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4335 struct bp_location *loc;
4338 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4339 if (breakpoint_location_address_match (loc, aspace, pc))
4345 /* Returns non-zero iff BL is inserted at PC, in address space
4349 bp_location_inserted_here_p (struct bp_location *bl,
4350 struct address_space *aspace, CORE_ADDR pc)
4353 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4356 if (overlay_debugging
4357 && section_is_overlay (bl->section)
4358 && !section_is_mapped (bl->section))
4359 return 0; /* unmapped overlay -- can't be a match */
4366 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4369 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4371 struct bp_location **blp, **blp_tmp = NULL;
4373 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4375 struct bp_location *bl = *blp;
4377 if (bl->loc_type != bp_loc_software_breakpoint
4378 && bl->loc_type != bp_loc_hardware_breakpoint)
4381 if (bp_location_inserted_here_p (bl, aspace, pc))
4387 /* This function returns non-zero iff there is a software breakpoint
4391 software_breakpoint_inserted_here_p (struct address_space *aspace,
4394 struct bp_location **blp, **blp_tmp = NULL;
4396 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4398 struct bp_location *bl = *blp;
4400 if (bl->loc_type != bp_loc_software_breakpoint)
4403 if (bp_location_inserted_here_p (bl, aspace, pc))
4410 /* See breakpoint.h. */
4413 hardware_breakpoint_inserted_here_p (struct address_space *aspace,
4416 struct bp_location **blp, **blp_tmp = NULL;
4418 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4420 struct bp_location *bl = *blp;
4422 if (bl->loc_type != bp_loc_hardware_breakpoint)
4425 if (bp_location_inserted_here_p (bl, aspace, pc))
4433 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4434 CORE_ADDR addr, ULONGEST len)
4436 struct breakpoint *bpt;
4438 ALL_BREAKPOINTS (bpt)
4440 struct bp_location *loc;
4442 if (bpt->type != bp_hardware_watchpoint
4443 && bpt->type != bp_access_watchpoint)
4446 if (!breakpoint_enabled (bpt))
4449 for (loc = bpt->loc; loc; loc = loc->next)
4450 if (loc->pspace->aspace == aspace && loc->inserted)
4454 /* Check for intersection. */
4455 l = std::max<CORE_ADDR> (loc->address, addr);
4456 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4465 /* bpstat stuff. External routines' interfaces are documented
4469 is_catchpoint (struct breakpoint *ep)
4471 return (ep->type == bp_catchpoint);
4474 /* Frees any storage that is part of a bpstat. Does not walk the
4478 bpstat_free (bpstat bs)
4480 if (bs->old_val != NULL)
4481 value_free (bs->old_val);
4482 decref_counted_command_line (&bs->commands);
4483 decref_bp_location (&bs->bp_location_at);
4487 /* Clear a bpstat so that it says we are not at any breakpoint.
4488 Also free any storage that is part of a bpstat. */
4491 bpstat_clear (bpstat *bsp)
4508 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4509 is part of the bpstat is copied as well. */
4512 bpstat_copy (bpstat bs)
4516 bpstat retval = NULL;
4521 for (; bs != NULL; bs = bs->next)
4523 tmp = (bpstat) xmalloc (sizeof (*tmp));
4524 memcpy (tmp, bs, sizeof (*tmp));
4525 incref_counted_command_line (tmp->commands);
4526 incref_bp_location (tmp->bp_location_at);
4527 if (bs->old_val != NULL)
4529 tmp->old_val = value_copy (bs->old_val);
4530 release_value (tmp->old_val);
4534 /* This is the first thing in the chain. */
4544 /* Find the bpstat associated with this breakpoint. */
4547 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4552 for (; bsp != NULL; bsp = bsp->next)
4554 if (bsp->breakpoint_at == breakpoint)
4560 /* See breakpoint.h. */
4563 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4565 for (; bsp != NULL; bsp = bsp->next)
4567 if (bsp->breakpoint_at == NULL)
4569 /* A moribund location can never explain a signal other than
4571 if (sig == GDB_SIGNAL_TRAP)
4576 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4585 /* Put in *NUM the breakpoint number of the first breakpoint we are
4586 stopped at. *BSP upon return is a bpstat which points to the
4587 remaining breakpoints stopped at (but which is not guaranteed to be
4588 good for anything but further calls to bpstat_num).
4590 Return 0 if passed a bpstat which does not indicate any breakpoints.
4591 Return -1 if stopped at a breakpoint that has been deleted since
4593 Return 1 otherwise. */
4596 bpstat_num (bpstat *bsp, int *num)
4598 struct breakpoint *b;
4601 return 0; /* No more breakpoint values */
4603 /* We assume we'll never have several bpstats that correspond to a
4604 single breakpoint -- otherwise, this function might return the
4605 same number more than once and this will look ugly. */
4606 b = (*bsp)->breakpoint_at;
4607 *bsp = (*bsp)->next;
4609 return -1; /* breakpoint that's been deleted since */
4611 *num = b->number; /* We have its number */
4615 /* See breakpoint.h. */
4618 bpstat_clear_actions (void)
4620 struct thread_info *tp;
4623 if (ptid_equal (inferior_ptid, null_ptid))
4626 tp = find_thread_ptid (inferior_ptid);
4630 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4632 decref_counted_command_line (&bs->commands);
4634 if (bs->old_val != NULL)
4636 value_free (bs->old_val);
4642 /* Called when a command is about to proceed the inferior. */
4645 breakpoint_about_to_proceed (void)
4647 if (!ptid_equal (inferior_ptid, null_ptid))
4649 struct thread_info *tp = inferior_thread ();
4651 /* Allow inferior function calls in breakpoint commands to not
4652 interrupt the command list. When the call finishes
4653 successfully, the inferior will be standing at the same
4654 breakpoint as if nothing happened. */
4655 if (tp->control.in_infcall)
4659 breakpoint_proceeded = 1;
4662 /* Stub for cleaning up our state if we error-out of a breakpoint
4665 cleanup_executing_breakpoints (void *ignore)
4667 executing_breakpoint_commands = 0;
4670 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4671 or its equivalent. */
4674 command_line_is_silent (struct command_line *cmd)
4676 return cmd && (strcmp ("silent", cmd->line) == 0);
4679 /* Execute all the commands associated with all the breakpoints at
4680 this location. Any of these commands could cause the process to
4681 proceed beyond this point, etc. We look out for such changes by
4682 checking the global "breakpoint_proceeded" after each command.
4684 Returns true if a breakpoint command resumed the inferior. In that
4685 case, it is the caller's responsibility to recall it again with the
4686 bpstat of the current thread. */
4689 bpstat_do_actions_1 (bpstat *bsp)
4692 struct cleanup *old_chain;
4695 /* Avoid endless recursion if a `source' command is contained
4697 if (executing_breakpoint_commands)
4700 executing_breakpoint_commands = 1;
4701 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4703 prevent_dont_repeat ();
4705 /* This pointer will iterate over the list of bpstat's. */
4708 breakpoint_proceeded = 0;
4709 for (; bs != NULL; bs = bs->next)
4711 struct counted_command_line *ccmd;
4712 struct command_line *cmd;
4713 struct cleanup *this_cmd_tree_chain;
4715 /* Take ownership of the BSP's command tree, if it has one.
4717 The command tree could legitimately contain commands like
4718 'step' and 'next', which call clear_proceed_status, which
4719 frees stop_bpstat's command tree. To make sure this doesn't
4720 free the tree we're executing out from under us, we need to
4721 take ownership of the tree ourselves. Since a given bpstat's
4722 commands are only executed once, we don't need to copy it; we
4723 can clear the pointer in the bpstat, and make sure we free
4724 the tree when we're done. */
4725 ccmd = bs->commands;
4726 bs->commands = NULL;
4727 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4728 cmd = ccmd ? ccmd->commands : NULL;
4729 if (command_line_is_silent (cmd))
4731 /* The action has been already done by bpstat_stop_status. */
4737 execute_control_command (cmd);
4739 if (breakpoint_proceeded)
4745 /* We can free this command tree now. */
4746 do_cleanups (this_cmd_tree_chain);
4748 if (breakpoint_proceeded)
4750 if (current_ui->async)
4751 /* If we are in async mode, then the target might be still
4752 running, not stopped at any breakpoint, so nothing for
4753 us to do here -- just return to the event loop. */
4756 /* In sync mode, when execute_control_command returns
4757 we're already standing on the next breakpoint.
4758 Breakpoint commands for that stop were not run, since
4759 execute_command does not run breakpoint commands --
4760 only command_line_handler does, but that one is not
4761 involved in execution of breakpoint commands. So, we
4762 can now execute breakpoint commands. It should be
4763 noted that making execute_command do bpstat actions is
4764 not an option -- in this case we'll have recursive
4765 invocation of bpstat for each breakpoint with a
4766 command, and can easily blow up GDB stack. Instead, we
4767 return true, which will trigger the caller to recall us
4768 with the new stop_bpstat. */
4773 do_cleanups (old_chain);
4778 bpstat_do_actions (void)
4780 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4782 /* Do any commands attached to breakpoint we are stopped at. */
4783 while (!ptid_equal (inferior_ptid, null_ptid)
4784 && target_has_execution
4785 && !is_exited (inferior_ptid)
4786 && !is_executing (inferior_ptid))
4787 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4788 and only return when it is stopped at the next breakpoint, we
4789 keep doing breakpoint actions until it returns false to
4790 indicate the inferior was not resumed. */
4791 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4794 discard_cleanups (cleanup_if_error);
4797 /* Print out the (old or new) value associated with a watchpoint. */
4800 watchpoint_value_print (struct value *val, struct ui_file *stream)
4803 fprintf_unfiltered (stream, _("<unreadable>"));
4806 struct value_print_options opts;
4807 get_user_print_options (&opts);
4808 value_print (val, stream, &opts);
4812 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4813 debugging multiple threads. */
4816 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4818 if (ui_out_is_mi_like_p (uiout))
4821 ui_out_text (uiout, "\n");
4823 if (show_thread_that_caused_stop ())
4826 struct thread_info *thr = inferior_thread ();
4828 ui_out_text (uiout, "Thread ");
4829 ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr));
4831 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4834 ui_out_text (uiout, " \"");
4835 ui_out_field_fmt (uiout, "name", "%s", name);
4836 ui_out_text (uiout, "\"");
4839 ui_out_text (uiout, " hit ");
4843 /* Generic routine for printing messages indicating why we
4844 stopped. The behavior of this function depends on the value
4845 'print_it' in the bpstat structure. Under some circumstances we
4846 may decide not to print anything here and delegate the task to
4849 static enum print_stop_action
4850 print_bp_stop_message (bpstat bs)
4852 switch (bs->print_it)
4855 /* Nothing should be printed for this bpstat entry. */
4856 return PRINT_UNKNOWN;
4860 /* We still want to print the frame, but we already printed the
4861 relevant messages. */
4862 return PRINT_SRC_AND_LOC;
4865 case print_it_normal:
4867 struct breakpoint *b = bs->breakpoint_at;
4869 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4870 which has since been deleted. */
4872 return PRINT_UNKNOWN;
4874 /* Normal case. Call the breakpoint's print_it method. */
4875 return b->ops->print_it (bs);
4880 internal_error (__FILE__, __LINE__,
4881 _("print_bp_stop_message: unrecognized enum value"));
4886 /* A helper function that prints a shared library stopped event. */
4889 print_solib_event (int is_catchpoint)
4892 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4894 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4898 if (any_added || any_deleted)
4899 ui_out_text (current_uiout,
4900 _("Stopped due to shared library event:\n"));
4902 ui_out_text (current_uiout,
4903 _("Stopped due to shared library event (no "
4904 "libraries added or removed)\n"));
4907 if (ui_out_is_mi_like_p (current_uiout))
4908 ui_out_field_string (current_uiout, "reason",
4909 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4913 struct cleanup *cleanup;
4917 ui_out_text (current_uiout, _(" Inferior unloaded "));
4918 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4921 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4926 ui_out_text (current_uiout, " ");
4927 ui_out_field_string (current_uiout, "library", name);
4928 ui_out_text (current_uiout, "\n");
4931 do_cleanups (cleanup);
4936 struct so_list *iter;
4938 struct cleanup *cleanup;
4940 ui_out_text (current_uiout, _(" Inferior loaded "));
4941 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4944 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4949 ui_out_text (current_uiout, " ");
4950 ui_out_field_string (current_uiout, "library", iter->so_name);
4951 ui_out_text (current_uiout, "\n");
4954 do_cleanups (cleanup);
4958 /* Print a message indicating what happened. This is called from
4959 normal_stop(). The input to this routine is the head of the bpstat
4960 list - a list of the eventpoints that caused this stop. KIND is
4961 the target_waitkind for the stopping event. This
4962 routine calls the generic print routine for printing a message
4963 about reasons for stopping. This will print (for example) the
4964 "Breakpoint n," part of the output. The return value of this
4967 PRINT_UNKNOWN: Means we printed nothing.
4968 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4969 code to print the location. An example is
4970 "Breakpoint 1, " which should be followed by
4972 PRINT_SRC_ONLY: Means we printed something, but there is no need
4973 to also print the location part of the message.
4974 An example is the catch/throw messages, which
4975 don't require a location appended to the end.
4976 PRINT_NOTHING: We have done some printing and we don't need any
4977 further info to be printed. */
4979 enum print_stop_action
4980 bpstat_print (bpstat bs, int kind)
4982 enum print_stop_action val;
4984 /* Maybe another breakpoint in the chain caused us to stop.
4985 (Currently all watchpoints go on the bpstat whether hit or not.
4986 That probably could (should) be changed, provided care is taken
4987 with respect to bpstat_explains_signal). */
4988 for (; bs; bs = bs->next)
4990 val = print_bp_stop_message (bs);
4991 if (val == PRINT_SRC_ONLY
4992 || val == PRINT_SRC_AND_LOC
4993 || val == PRINT_NOTHING)
4997 /* If we had hit a shared library event breakpoint,
4998 print_bp_stop_message would print out this message. If we hit an
4999 OS-level shared library event, do the same thing. */
5000 if (kind == TARGET_WAITKIND_LOADED)
5002 print_solib_event (0);
5003 return PRINT_NOTHING;
5006 /* We reached the end of the chain, or we got a null BS to start
5007 with and nothing was printed. */
5008 return PRINT_UNKNOWN;
5011 /* Evaluate the expression EXP and return 1 if value is zero.
5012 This returns the inverse of the condition because it is called
5013 from catch_errors which returns 0 if an exception happened, and if an
5014 exception happens we want execution to stop.
5015 The argument is a "struct expression *" that has been cast to a
5016 "void *" to make it pass through catch_errors. */
5019 breakpoint_cond_eval (void *exp)
5021 struct value *mark = value_mark ();
5022 int i = !value_true (evaluate_expression ((struct expression *) exp));
5024 value_free_to_mark (mark);
5028 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5031 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
5035 bs = (bpstat) xmalloc (sizeof (*bs));
5037 **bs_link_pointer = bs;
5038 *bs_link_pointer = &bs->next;
5039 bs->breakpoint_at = bl->owner;
5040 bs->bp_location_at = bl;
5041 incref_bp_location (bl);
5042 /* If the condition is false, etc., don't do the commands. */
5043 bs->commands = NULL;
5045 bs->print_it = print_it_normal;
5049 /* The target has stopped with waitstatus WS. Check if any hardware
5050 watchpoints have triggered, according to the target. */
5053 watchpoints_triggered (struct target_waitstatus *ws)
5055 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
5057 struct breakpoint *b;
5059 if (!stopped_by_watchpoint)
5061 /* We were not stopped by a watchpoint. Mark all watchpoints
5062 as not triggered. */
5064 if (is_hardware_watchpoint (b))
5066 struct watchpoint *w = (struct watchpoint *) b;
5068 w->watchpoint_triggered = watch_triggered_no;
5074 if (!target_stopped_data_address (¤t_target, &addr))
5076 /* We were stopped by a watchpoint, but we don't know where.
5077 Mark all watchpoints as unknown. */
5079 if (is_hardware_watchpoint (b))
5081 struct watchpoint *w = (struct watchpoint *) b;
5083 w->watchpoint_triggered = watch_triggered_unknown;
5089 /* The target could report the data address. Mark watchpoints
5090 affected by this data address as triggered, and all others as not
5094 if (is_hardware_watchpoint (b))
5096 struct watchpoint *w = (struct watchpoint *) b;
5097 struct bp_location *loc;
5099 w->watchpoint_triggered = watch_triggered_no;
5100 for (loc = b->loc; loc; loc = loc->next)
5102 if (is_masked_watchpoint (b))
5104 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5105 CORE_ADDR start = loc->address & w->hw_wp_mask;
5107 if (newaddr == start)
5109 w->watchpoint_triggered = watch_triggered_yes;
5113 /* Exact match not required. Within range is sufficient. */
5114 else if (target_watchpoint_addr_within_range (¤t_target,
5118 w->watchpoint_triggered = watch_triggered_yes;
5127 /* Possible return values for watchpoint_check (this can't be an enum
5128 because of check_errors). */
5129 /* The watchpoint has been deleted. */
5130 #define WP_DELETED 1
5131 /* The value has changed. */
5132 #define WP_VALUE_CHANGED 2
5133 /* The value has not changed. */
5134 #define WP_VALUE_NOT_CHANGED 3
5135 /* Ignore this watchpoint, no matter if the value changed or not. */
5138 #define BP_TEMPFLAG 1
5139 #define BP_HARDWAREFLAG 2
5141 /* Evaluate watchpoint condition expression and check if its value
5144 P should be a pointer to struct bpstat, but is defined as a void *
5145 in order for this function to be usable with catch_errors. */
5148 watchpoint_check (void *p)
5150 bpstat bs = (bpstat) p;
5151 struct watchpoint *b;
5152 struct frame_info *fr;
5153 int within_current_scope;
5155 /* BS is built from an existing struct breakpoint. */
5156 gdb_assert (bs->breakpoint_at != NULL);
5157 b = (struct watchpoint *) bs->breakpoint_at;
5159 /* If this is a local watchpoint, we only want to check if the
5160 watchpoint frame is in scope if the current thread is the thread
5161 that was used to create the watchpoint. */
5162 if (!watchpoint_in_thread_scope (b))
5165 if (b->exp_valid_block == NULL)
5166 within_current_scope = 1;
5169 struct frame_info *frame = get_current_frame ();
5170 struct gdbarch *frame_arch = get_frame_arch (frame);
5171 CORE_ADDR frame_pc = get_frame_pc (frame);
5173 /* stack_frame_destroyed_p() returns a non-zero value if we're
5174 still in the function but the stack frame has already been
5175 invalidated. Since we can't rely on the values of local
5176 variables after the stack has been destroyed, we are treating
5177 the watchpoint in that state as `not changed' without further
5178 checking. Don't mark watchpoints as changed if the current
5179 frame is in an epilogue - even if they are in some other
5180 frame, our view of the stack is likely to be wrong and
5181 frame_find_by_id could error out. */
5182 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5185 fr = frame_find_by_id (b->watchpoint_frame);
5186 within_current_scope = (fr != NULL);
5188 /* If we've gotten confused in the unwinder, we might have
5189 returned a frame that can't describe this variable. */
5190 if (within_current_scope)
5192 struct symbol *function;
5194 function = get_frame_function (fr);
5195 if (function == NULL
5196 || !contained_in (b->exp_valid_block,
5197 SYMBOL_BLOCK_VALUE (function)))
5198 within_current_scope = 0;
5201 if (within_current_scope)
5202 /* If we end up stopping, the current frame will get selected
5203 in normal_stop. So this call to select_frame won't affect
5208 if (within_current_scope)
5210 /* We use value_{,free_to_}mark because it could be a *long*
5211 time before we return to the command level and call
5212 free_all_values. We can't call free_all_values because we
5213 might be in the middle of evaluating a function call. */
5217 struct value *new_val;
5219 if (is_masked_watchpoint (&b->base))
5220 /* Since we don't know the exact trigger address (from
5221 stopped_data_address), just tell the user we've triggered
5222 a mask watchpoint. */
5223 return WP_VALUE_CHANGED;
5225 mark = value_mark ();
5226 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5228 if (b->val_bitsize != 0)
5229 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5231 /* We use value_equal_contents instead of value_equal because
5232 the latter coerces an array to a pointer, thus comparing just
5233 the address of the array instead of its contents. This is
5234 not what we want. */
5235 if ((b->val != NULL) != (new_val != NULL)
5236 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5238 if (new_val != NULL)
5240 release_value (new_val);
5241 value_free_to_mark (mark);
5243 bs->old_val = b->val;
5246 return WP_VALUE_CHANGED;
5250 /* Nothing changed. */
5251 value_free_to_mark (mark);
5252 return WP_VALUE_NOT_CHANGED;
5257 /* This seems like the only logical thing to do because
5258 if we temporarily ignored the watchpoint, then when
5259 we reenter the block in which it is valid it contains
5260 garbage (in the case of a function, it may have two
5261 garbage values, one before and one after the prologue).
5262 So we can't even detect the first assignment to it and
5263 watch after that (since the garbage may or may not equal
5264 the first value assigned). */
5265 /* We print all the stop information in
5266 breakpoint_ops->print_it, but in this case, by the time we
5267 call breakpoint_ops->print_it this bp will be deleted
5268 already. So we have no choice but print the information
5271 SWITCH_THRU_ALL_UIS ()
5273 struct ui_out *uiout = current_uiout;
5275 if (ui_out_is_mi_like_p (uiout))
5277 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5278 ui_out_text (uiout, "\nWatchpoint ");
5279 ui_out_field_int (uiout, "wpnum", b->base.number);
5281 " deleted because the program has left the block in\n"
5282 "which its expression is valid.\n");
5285 /* Make sure the watchpoint's commands aren't executed. */
5286 decref_counted_command_line (&b->base.commands);
5287 watchpoint_del_at_next_stop (b);
5293 /* Return true if it looks like target has stopped due to hitting
5294 breakpoint location BL. This function does not check if we should
5295 stop, only if BL explains the stop. */
5298 bpstat_check_location (const struct bp_location *bl,
5299 struct address_space *aspace, CORE_ADDR bp_addr,
5300 const struct target_waitstatus *ws)
5302 struct breakpoint *b = bl->owner;
5304 /* BL is from an existing breakpoint. */
5305 gdb_assert (b != NULL);
5307 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5310 /* Determine if the watched values have actually changed, and we
5311 should stop. If not, set BS->stop to 0. */
5314 bpstat_check_watchpoint (bpstat bs)
5316 const struct bp_location *bl;
5317 struct watchpoint *b;
5319 /* BS is built for existing struct breakpoint. */
5320 bl = bs->bp_location_at;
5321 gdb_assert (bl != NULL);
5322 b = (struct watchpoint *) bs->breakpoint_at;
5323 gdb_assert (b != NULL);
5326 int must_check_value = 0;
5328 if (b->base.type == bp_watchpoint)
5329 /* For a software watchpoint, we must always check the
5331 must_check_value = 1;
5332 else if (b->watchpoint_triggered == watch_triggered_yes)
5333 /* We have a hardware watchpoint (read, write, or access)
5334 and the target earlier reported an address watched by
5336 must_check_value = 1;
5337 else if (b->watchpoint_triggered == watch_triggered_unknown
5338 && b->base.type == bp_hardware_watchpoint)
5339 /* We were stopped by a hardware watchpoint, but the target could
5340 not report the data address. We must check the watchpoint's
5341 value. Access and read watchpoints are out of luck; without
5342 a data address, we can't figure it out. */
5343 must_check_value = 1;
5345 if (must_check_value)
5348 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5350 struct cleanup *cleanups = make_cleanup (xfree, message);
5351 int e = catch_errors (watchpoint_check, bs, message,
5353 do_cleanups (cleanups);
5357 /* We've already printed what needs to be printed. */
5358 bs->print_it = print_it_done;
5362 bs->print_it = print_it_noop;
5365 case WP_VALUE_CHANGED:
5366 if (b->base.type == bp_read_watchpoint)
5368 /* There are two cases to consider here:
5370 1. We're watching the triggered memory for reads.
5371 In that case, trust the target, and always report
5372 the watchpoint hit to the user. Even though
5373 reads don't cause value changes, the value may
5374 have changed since the last time it was read, and
5375 since we're not trapping writes, we will not see
5376 those, and as such we should ignore our notion of
5379 2. We're watching the triggered memory for both
5380 reads and writes. There are two ways this may
5383 2.1. This is a target that can't break on data
5384 reads only, but can break on accesses (reads or
5385 writes), such as e.g., x86. We detect this case
5386 at the time we try to insert read watchpoints.
5388 2.2. Otherwise, the target supports read
5389 watchpoints, but, the user set an access or write
5390 watchpoint watching the same memory as this read
5393 If we're watching memory writes as well as reads,
5394 ignore watchpoint hits when we find that the
5395 value hasn't changed, as reads don't cause
5396 changes. This still gives false positives when
5397 the program writes the same value to memory as
5398 what there was already in memory (we will confuse
5399 it for a read), but it's much better than
5402 int other_write_watchpoint = 0;
5404 if (bl->watchpoint_type == hw_read)
5406 struct breakpoint *other_b;
5408 ALL_BREAKPOINTS (other_b)
5409 if (other_b->type == bp_hardware_watchpoint
5410 || other_b->type == bp_access_watchpoint)
5412 struct watchpoint *other_w =
5413 (struct watchpoint *) other_b;
5415 if (other_w->watchpoint_triggered
5416 == watch_triggered_yes)
5418 other_write_watchpoint = 1;
5424 if (other_write_watchpoint
5425 || bl->watchpoint_type == hw_access)
5427 /* We're watching the same memory for writes,
5428 and the value changed since the last time we
5429 updated it, so this trap must be for a write.
5431 bs->print_it = print_it_noop;
5436 case WP_VALUE_NOT_CHANGED:
5437 if (b->base.type == bp_hardware_watchpoint
5438 || b->base.type == bp_watchpoint)
5440 /* Don't stop: write watchpoints shouldn't fire if
5441 the value hasn't changed. */
5442 bs->print_it = print_it_noop;
5450 /* Error from catch_errors. */
5452 SWITCH_THRU_ALL_UIS ()
5454 printf_filtered (_("Watchpoint %d deleted.\n"),
5457 watchpoint_del_at_next_stop (b);
5458 /* We've already printed what needs to be printed. */
5459 bs->print_it = print_it_done;
5464 else /* must_check_value == 0 */
5466 /* This is a case where some watchpoint(s) triggered, but
5467 not at the address of this watchpoint, or else no
5468 watchpoint triggered after all. So don't print
5469 anything for this watchpoint. */
5470 bs->print_it = print_it_noop;
5476 /* For breakpoints that are currently marked as telling gdb to stop,
5477 check conditions (condition proper, frame, thread and ignore count)
5478 of breakpoint referred to by BS. If we should not stop for this
5479 breakpoint, set BS->stop to 0. */
5482 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5484 const struct bp_location *bl;
5485 struct breakpoint *b;
5486 int value_is_zero = 0;
5487 struct expression *cond;
5489 gdb_assert (bs->stop);
5491 /* BS is built for existing struct breakpoint. */
5492 bl = bs->bp_location_at;
5493 gdb_assert (bl != NULL);
5494 b = bs->breakpoint_at;
5495 gdb_assert (b != NULL);
5497 /* Even if the target evaluated the condition on its end and notified GDB, we
5498 need to do so again since GDB does not know if we stopped due to a
5499 breakpoint or a single step breakpoint. */
5501 if (frame_id_p (b->frame_id)
5502 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5508 /* If this is a thread/task-specific breakpoint, don't waste cpu
5509 evaluating the condition if this isn't the specified
5511 if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
5512 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5519 /* Evaluate extension language breakpoints that have a "stop" method
5521 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5523 if (is_watchpoint (b))
5525 struct watchpoint *w = (struct watchpoint *) b;
5532 if (cond && b->disposition != disp_del_at_next_stop)
5534 int within_current_scope = 1;
5535 struct watchpoint * w;
5537 /* We use value_mark and value_free_to_mark because it could
5538 be a long time before we return to the command level and
5539 call free_all_values. We can't call free_all_values
5540 because we might be in the middle of evaluating a
5542 struct value *mark = value_mark ();
5544 if (is_watchpoint (b))
5545 w = (struct watchpoint *) b;
5549 /* Need to select the frame, with all that implies so that
5550 the conditions will have the right context. Because we
5551 use the frame, we will not see an inlined function's
5552 variables when we arrive at a breakpoint at the start
5553 of the inlined function; the current frame will be the
5555 if (w == NULL || w->cond_exp_valid_block == NULL)
5556 select_frame (get_current_frame ());
5559 struct frame_info *frame;
5561 /* For local watchpoint expressions, which particular
5562 instance of a local is being watched matters, so we
5563 keep track of the frame to evaluate the expression
5564 in. To evaluate the condition however, it doesn't
5565 really matter which instantiation of the function
5566 where the condition makes sense triggers the
5567 watchpoint. This allows an expression like "watch
5568 global if q > 10" set in `func', catch writes to
5569 global on all threads that call `func', or catch
5570 writes on all recursive calls of `func' by a single
5571 thread. We simply always evaluate the condition in
5572 the innermost frame that's executing where it makes
5573 sense to evaluate the condition. It seems
5575 frame = block_innermost_frame (w->cond_exp_valid_block);
5577 select_frame (frame);
5579 within_current_scope = 0;
5581 if (within_current_scope)
5583 = catch_errors (breakpoint_cond_eval, cond,
5584 "Error in testing breakpoint condition:\n",
5588 warning (_("Watchpoint condition cannot be tested "
5589 "in the current scope"));
5590 /* If we failed to set the right context for this
5591 watchpoint, unconditionally report it. */
5594 /* FIXME-someday, should give breakpoint #. */
5595 value_free_to_mark (mark);
5598 if (cond && value_is_zero)
5602 else if (b->ignore_count > 0)
5606 /* Increase the hit count even though we don't stop. */
5608 observer_notify_breakpoint_modified (b);
5612 /* Returns true if we need to track moribund locations of LOC's type
5613 on the current target. */
5616 need_moribund_for_location_type (struct bp_location *loc)
5618 return ((loc->loc_type == bp_loc_software_breakpoint
5619 && !target_supports_stopped_by_sw_breakpoint ())
5620 || (loc->loc_type == bp_loc_hardware_breakpoint
5621 && !target_supports_stopped_by_hw_breakpoint ()));
5625 /* Get a bpstat associated with having just stopped at address
5626 BP_ADDR in thread PTID.
5628 Determine whether we stopped at a breakpoint, etc, or whether we
5629 don't understand this stop. Result is a chain of bpstat's such
5632 if we don't understand the stop, the result is a null pointer.
5634 if we understand why we stopped, the result is not null.
5636 Each element of the chain refers to a particular breakpoint or
5637 watchpoint at which we have stopped. (We may have stopped for
5638 several reasons concurrently.)
5640 Each element of the chain has valid next, breakpoint_at,
5641 commands, FIXME??? fields. */
5644 bpstat_stop_status (struct address_space *aspace,
5645 CORE_ADDR bp_addr, ptid_t ptid,
5646 const struct target_waitstatus *ws)
5648 struct breakpoint *b = NULL;
5649 struct bp_location *bl;
5650 struct bp_location *loc;
5651 /* First item of allocated bpstat's. */
5652 bpstat bs_head = NULL, *bs_link = &bs_head;
5653 /* Pointer to the last thing in the chain currently. */
5656 int need_remove_insert;
5659 /* First, build the bpstat chain with locations that explain a
5660 target stop, while being careful to not set the target running,
5661 as that may invalidate locations (in particular watchpoint
5662 locations are recreated). Resuming will happen here with
5663 breakpoint conditions or watchpoint expressions that include
5664 inferior function calls. */
5668 if (!breakpoint_enabled (b))
5671 for (bl = b->loc; bl != NULL; bl = bl->next)
5673 /* For hardware watchpoints, we look only at the first
5674 location. The watchpoint_check function will work on the
5675 entire expression, not the individual locations. For
5676 read watchpoints, the watchpoints_triggered function has
5677 checked all locations already. */
5678 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5681 if (!bl->enabled || bl->shlib_disabled)
5684 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5687 /* Come here if it's a watchpoint, or if the break address
5690 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5693 /* Assume we stop. Should we find a watchpoint that is not
5694 actually triggered, or if the condition of the breakpoint
5695 evaluates as false, we'll reset 'stop' to 0. */
5699 /* If this is a scope breakpoint, mark the associated
5700 watchpoint as triggered so that we will handle the
5701 out-of-scope event. We'll get to the watchpoint next
5703 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5705 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5707 w->watchpoint_triggered = watch_triggered_yes;
5712 /* Check if a moribund breakpoint explains the stop. */
5713 if (!target_supports_stopped_by_sw_breakpoint ()
5714 || !target_supports_stopped_by_hw_breakpoint ())
5716 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5718 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5719 && need_moribund_for_location_type (loc))
5721 bs = bpstat_alloc (loc, &bs_link);
5722 /* For hits of moribund locations, we should just proceed. */
5725 bs->print_it = print_it_noop;
5730 /* A bit of special processing for shlib breakpoints. We need to
5731 process solib loading here, so that the lists of loaded and
5732 unloaded libraries are correct before we handle "catch load" and
5734 for (bs = bs_head; bs != NULL; bs = bs->next)
5736 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5738 handle_solib_event ();
5743 /* Now go through the locations that caused the target to stop, and
5744 check whether we're interested in reporting this stop to higher
5745 layers, or whether we should resume the target transparently. */
5749 for (bs = bs_head; bs != NULL; bs = bs->next)
5754 b = bs->breakpoint_at;
5755 b->ops->check_status (bs);
5758 bpstat_check_breakpoint_conditions (bs, ptid);
5763 observer_notify_breakpoint_modified (b);
5765 /* We will stop here. */
5766 if (b->disposition == disp_disable)
5768 --(b->enable_count);
5769 if (b->enable_count <= 0)
5770 b->enable_state = bp_disabled;
5775 bs->commands = b->commands;
5776 incref_counted_command_line (bs->commands);
5777 if (command_line_is_silent (bs->commands
5778 ? bs->commands->commands : NULL))
5781 b->ops->after_condition_true (bs);
5786 /* Print nothing for this entry if we don't stop or don't
5788 if (!bs->stop || !bs->print)
5789 bs->print_it = print_it_noop;
5792 /* If we aren't stopping, the value of some hardware watchpoint may
5793 not have changed, but the intermediate memory locations we are
5794 watching may have. Don't bother if we're stopping; this will get
5796 need_remove_insert = 0;
5797 if (! bpstat_causes_stop (bs_head))
5798 for (bs = bs_head; bs != NULL; bs = bs->next)
5800 && bs->breakpoint_at
5801 && is_hardware_watchpoint (bs->breakpoint_at))
5803 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5805 update_watchpoint (w, 0 /* don't reparse. */);
5806 need_remove_insert = 1;
5809 if (need_remove_insert)
5810 update_global_location_list (UGLL_MAY_INSERT);
5811 else if (removed_any)
5812 update_global_location_list (UGLL_DONT_INSERT);
5818 handle_jit_event (void)
5820 struct frame_info *frame;
5821 struct gdbarch *gdbarch;
5824 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5826 /* Switch terminal for any messages produced by
5827 breakpoint_re_set. */
5828 target_terminal_ours_for_output ();
5830 frame = get_current_frame ();
5831 gdbarch = get_frame_arch (frame);
5833 jit_event_handler (gdbarch);
5835 target_terminal_inferior ();
5838 /* Prepare WHAT final decision for infrun. */
5840 /* Decide what infrun needs to do with this bpstat. */
5843 bpstat_what (bpstat bs_head)
5845 struct bpstat_what retval;
5848 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5849 retval.call_dummy = STOP_NONE;
5850 retval.is_longjmp = 0;
5852 for (bs = bs_head; bs != NULL; bs = bs->next)
5854 /* Extract this BS's action. After processing each BS, we check
5855 if its action overrides all we've seem so far. */
5856 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5859 if (bs->breakpoint_at == NULL)
5861 /* I suspect this can happen if it was a momentary
5862 breakpoint which has since been deleted. */
5866 bptype = bs->breakpoint_at->type;
5873 case bp_hardware_breakpoint:
5874 case bp_single_step:
5877 case bp_shlib_event:
5881 this_action = BPSTAT_WHAT_STOP_NOISY;
5883 this_action = BPSTAT_WHAT_STOP_SILENT;
5886 this_action = BPSTAT_WHAT_SINGLE;
5889 case bp_hardware_watchpoint:
5890 case bp_read_watchpoint:
5891 case bp_access_watchpoint:
5895 this_action = BPSTAT_WHAT_STOP_NOISY;
5897 this_action = BPSTAT_WHAT_STOP_SILENT;
5901 /* There was a watchpoint, but we're not stopping.
5902 This requires no further action. */
5906 case bp_longjmp_call_dummy:
5910 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5911 retval.is_longjmp = bptype != bp_exception;
5914 this_action = BPSTAT_WHAT_SINGLE;
5916 case bp_longjmp_resume:
5917 case bp_exception_resume:
5920 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5921 retval.is_longjmp = bptype == bp_longjmp_resume;
5924 this_action = BPSTAT_WHAT_SINGLE;
5926 case bp_step_resume:
5928 this_action = BPSTAT_WHAT_STEP_RESUME;
5931 /* It is for the wrong frame. */
5932 this_action = BPSTAT_WHAT_SINGLE;
5935 case bp_hp_step_resume:
5937 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5940 /* It is for the wrong frame. */
5941 this_action = BPSTAT_WHAT_SINGLE;
5944 case bp_watchpoint_scope:
5945 case bp_thread_event:
5946 case bp_overlay_event:
5947 case bp_longjmp_master:
5948 case bp_std_terminate_master:
5949 case bp_exception_master:
5950 this_action = BPSTAT_WHAT_SINGLE;
5956 this_action = BPSTAT_WHAT_STOP_NOISY;
5958 this_action = BPSTAT_WHAT_STOP_SILENT;
5962 /* There was a catchpoint, but we're not stopping.
5963 This requires no further action. */
5967 this_action = BPSTAT_WHAT_SINGLE;
5970 /* Make sure the action is stop (silent or noisy),
5971 so infrun.c pops the dummy frame. */
5972 retval.call_dummy = STOP_STACK_DUMMY;
5973 this_action = BPSTAT_WHAT_STOP_SILENT;
5975 case bp_std_terminate:
5976 /* Make sure the action is stop (silent or noisy),
5977 so infrun.c pops the dummy frame. */
5978 retval.call_dummy = STOP_STD_TERMINATE;
5979 this_action = BPSTAT_WHAT_STOP_SILENT;
5982 case bp_fast_tracepoint:
5983 case bp_static_tracepoint:
5984 /* Tracepoint hits should not be reported back to GDB, and
5985 if one got through somehow, it should have been filtered
5987 internal_error (__FILE__, __LINE__,
5988 _("bpstat_what: tracepoint encountered"));
5990 case bp_gnu_ifunc_resolver:
5991 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5992 this_action = BPSTAT_WHAT_SINGLE;
5994 case bp_gnu_ifunc_resolver_return:
5995 /* The breakpoint will be removed, execution will restart from the
5996 PC of the former breakpoint. */
5997 this_action = BPSTAT_WHAT_KEEP_CHECKING;
6002 this_action = BPSTAT_WHAT_STOP_SILENT;
6004 this_action = BPSTAT_WHAT_SINGLE;
6008 internal_error (__FILE__, __LINE__,
6009 _("bpstat_what: unhandled bptype %d"), (int) bptype);
6012 retval.main_action = std::max (retval.main_action, this_action);
6019 bpstat_run_callbacks (bpstat bs_head)
6023 for (bs = bs_head; bs != NULL; bs = bs->next)
6025 struct breakpoint *b = bs->breakpoint_at;
6032 handle_jit_event ();
6034 case bp_gnu_ifunc_resolver:
6035 gnu_ifunc_resolver_stop (b);
6037 case bp_gnu_ifunc_resolver_return:
6038 gnu_ifunc_resolver_return_stop (b);
6044 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6045 without hardware support). This isn't related to a specific bpstat,
6046 just to things like whether watchpoints are set. */
6049 bpstat_should_step (void)
6051 struct breakpoint *b;
6054 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
6060 bpstat_causes_stop (bpstat bs)
6062 for (; bs != NULL; bs = bs->next)
6071 /* Compute a string of spaces suitable to indent the next line
6072 so it starts at the position corresponding to the table column
6073 named COL_NAME in the currently active table of UIOUT. */
6076 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
6078 static char wrap_indent[80];
6079 int i, total_width, width, align;
6083 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
6085 if (strcmp (text, col_name) == 0)
6087 gdb_assert (total_width < sizeof wrap_indent);
6088 memset (wrap_indent, ' ', total_width);
6089 wrap_indent[total_width] = 0;
6094 total_width += width + 1;
6100 /* Determine if the locations of this breakpoint will have their conditions
6101 evaluated by the target, host or a mix of both. Returns the following:
6103 "host": Host evals condition.
6104 "host or target": Host or Target evals condition.
6105 "target": Target evals condition.
6109 bp_condition_evaluator (struct breakpoint *b)
6111 struct bp_location *bl;
6112 char host_evals = 0;
6113 char target_evals = 0;
6118 if (!is_breakpoint (b))
6121 if (gdb_evaluates_breakpoint_condition_p ()
6122 || !target_supports_evaluation_of_breakpoint_conditions ())
6123 return condition_evaluation_host;
6125 for (bl = b->loc; bl; bl = bl->next)
6127 if (bl->cond_bytecode)
6133 if (host_evals && target_evals)
6134 return condition_evaluation_both;
6135 else if (target_evals)
6136 return condition_evaluation_target;
6138 return condition_evaluation_host;
6141 /* Determine the breakpoint location's condition evaluator. This is
6142 similar to bp_condition_evaluator, but for locations. */
6145 bp_location_condition_evaluator (struct bp_location *bl)
6147 if (bl && !is_breakpoint (bl->owner))
6150 if (gdb_evaluates_breakpoint_condition_p ()
6151 || !target_supports_evaluation_of_breakpoint_conditions ())
6152 return condition_evaluation_host;
6154 if (bl && bl->cond_bytecode)
6155 return condition_evaluation_target;
6157 return condition_evaluation_host;
6160 /* Print the LOC location out of the list of B->LOC locations. */
6163 print_breakpoint_location (struct breakpoint *b,
6164 struct bp_location *loc)
6166 struct ui_out *uiout = current_uiout;
6167 struct cleanup *old_chain = save_current_program_space ();
6169 if (loc != NULL && loc->shlib_disabled)
6173 set_current_program_space (loc->pspace);
6175 if (b->display_canonical)
6176 ui_out_field_string (uiout, "what",
6177 event_location_to_string (b->location));
6178 else if (loc && loc->symtab)
6181 = find_pc_sect_function (loc->address, loc->section);
6184 ui_out_text (uiout, "in ");
6185 ui_out_field_string (uiout, "func",
6186 SYMBOL_PRINT_NAME (sym));
6187 ui_out_text (uiout, " ");
6188 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6189 ui_out_text (uiout, "at ");
6191 ui_out_field_string (uiout, "file",
6192 symtab_to_filename_for_display (loc->symtab));
6193 ui_out_text (uiout, ":");
6195 if (ui_out_is_mi_like_p (uiout))
6196 ui_out_field_string (uiout, "fullname",
6197 symtab_to_fullname (loc->symtab));
6199 ui_out_field_int (uiout, "line", loc->line_number);
6203 struct ui_file *stb = mem_fileopen ();
6204 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6206 print_address_symbolic (loc->gdbarch, loc->address, stb,
6208 ui_out_field_stream (uiout, "at", stb);
6210 do_cleanups (stb_chain);
6214 ui_out_field_string (uiout, "pending",
6215 event_location_to_string (b->location));
6216 /* If extra_string is available, it could be holding a condition
6217 or dprintf arguments. In either case, make sure it is printed,
6218 too, but only for non-MI streams. */
6219 if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL)
6221 if (b->type == bp_dprintf)
6222 ui_out_text (uiout, ",");
6224 ui_out_text (uiout, " ");
6225 ui_out_text (uiout, b->extra_string);
6229 if (loc && is_breakpoint (b)
6230 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6231 && bp_condition_evaluator (b) == condition_evaluation_both)
6233 ui_out_text (uiout, " (");
6234 ui_out_field_string (uiout, "evaluated-by",
6235 bp_location_condition_evaluator (loc));
6236 ui_out_text (uiout, ")");
6239 do_cleanups (old_chain);
6243 bptype_string (enum bptype type)
6245 struct ep_type_description
6250 static struct ep_type_description bptypes[] =
6252 {bp_none, "?deleted?"},
6253 {bp_breakpoint, "breakpoint"},
6254 {bp_hardware_breakpoint, "hw breakpoint"},
6255 {bp_single_step, "sw single-step"},
6256 {bp_until, "until"},
6257 {bp_finish, "finish"},
6258 {bp_watchpoint, "watchpoint"},
6259 {bp_hardware_watchpoint, "hw watchpoint"},
6260 {bp_read_watchpoint, "read watchpoint"},
6261 {bp_access_watchpoint, "acc watchpoint"},
6262 {bp_longjmp, "longjmp"},
6263 {bp_longjmp_resume, "longjmp resume"},
6264 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6265 {bp_exception, "exception"},
6266 {bp_exception_resume, "exception resume"},
6267 {bp_step_resume, "step resume"},
6268 {bp_hp_step_resume, "high-priority step resume"},
6269 {bp_watchpoint_scope, "watchpoint scope"},
6270 {bp_call_dummy, "call dummy"},
6271 {bp_std_terminate, "std::terminate"},
6272 {bp_shlib_event, "shlib events"},
6273 {bp_thread_event, "thread events"},
6274 {bp_overlay_event, "overlay events"},
6275 {bp_longjmp_master, "longjmp master"},
6276 {bp_std_terminate_master, "std::terminate master"},
6277 {bp_exception_master, "exception master"},
6278 {bp_catchpoint, "catchpoint"},
6279 {bp_tracepoint, "tracepoint"},
6280 {bp_fast_tracepoint, "fast tracepoint"},
6281 {bp_static_tracepoint, "static tracepoint"},
6282 {bp_dprintf, "dprintf"},
6283 {bp_jit_event, "jit events"},
6284 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6285 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6288 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6289 || ((int) type != bptypes[(int) type].type))
6290 internal_error (__FILE__, __LINE__,
6291 _("bptypes table does not describe type #%d."),
6294 return bptypes[(int) type].description;
6297 /* For MI, output a field named 'thread-groups' with a list as the value.
6298 For CLI, prefix the list with the string 'inf'. */
6301 output_thread_groups (struct ui_out *uiout,
6302 const char *field_name,
6306 struct cleanup *back_to;
6307 int is_mi = ui_out_is_mi_like_p (uiout);
6311 /* For backward compatibility, don't display inferiors in CLI unless
6312 there are several. Always display them for MI. */
6313 if (!is_mi && mi_only)
6316 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6318 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6324 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6325 ui_out_field_string (uiout, NULL, mi_group);
6330 ui_out_text (uiout, " inf ");
6332 ui_out_text (uiout, ", ");
6334 ui_out_text (uiout, plongest (inf));
6338 do_cleanups (back_to);
6341 /* Print B to gdb_stdout. */
6344 print_one_breakpoint_location (struct breakpoint *b,
6345 struct bp_location *loc,
6347 struct bp_location **last_loc,
6350 struct command_line *l;
6351 static char bpenables[] = "nynny";
6353 struct ui_out *uiout = current_uiout;
6354 int header_of_multiple = 0;
6355 int part_of_multiple = (loc != NULL);
6356 struct value_print_options opts;
6358 get_user_print_options (&opts);
6360 gdb_assert (!loc || loc_number != 0);
6361 /* See comment in print_one_breakpoint concerning treatment of
6362 breakpoints with single disabled location. */
6365 && (b->loc->next != NULL || !b->loc->enabled)))
6366 header_of_multiple = 1;
6374 if (part_of_multiple)
6377 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6378 ui_out_field_string (uiout, "number", formatted);
6383 ui_out_field_int (uiout, "number", b->number);
6388 if (part_of_multiple)
6389 ui_out_field_skip (uiout, "type");
6391 ui_out_field_string (uiout, "type", bptype_string (b->type));
6395 if (part_of_multiple)
6396 ui_out_field_skip (uiout, "disp");
6398 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6403 if (part_of_multiple)
6404 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6406 ui_out_field_fmt (uiout, "enabled", "%c",
6407 bpenables[(int) b->enable_state]);
6408 ui_out_spaces (uiout, 2);
6412 if (b->ops != NULL && b->ops->print_one != NULL)
6414 /* Although the print_one can possibly print all locations,
6415 calling it here is not likely to get any nice result. So,
6416 make sure there's just one location. */
6417 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6418 b->ops->print_one (b, last_loc);
6424 internal_error (__FILE__, __LINE__,
6425 _("print_one_breakpoint: bp_none encountered\n"));
6429 case bp_hardware_watchpoint:
6430 case bp_read_watchpoint:
6431 case bp_access_watchpoint:
6433 struct watchpoint *w = (struct watchpoint *) b;
6435 /* Field 4, the address, is omitted (which makes the columns
6436 not line up too nicely with the headers, but the effect
6437 is relatively readable). */
6438 if (opts.addressprint)
6439 ui_out_field_skip (uiout, "addr");
6441 ui_out_field_string (uiout, "what", w->exp_string);
6446 case bp_hardware_breakpoint:
6447 case bp_single_step:
6451 case bp_longjmp_resume:
6452 case bp_longjmp_call_dummy:
6454 case bp_exception_resume:
6455 case bp_step_resume:
6456 case bp_hp_step_resume:
6457 case bp_watchpoint_scope:
6459 case bp_std_terminate:
6460 case bp_shlib_event:
6461 case bp_thread_event:
6462 case bp_overlay_event:
6463 case bp_longjmp_master:
6464 case bp_std_terminate_master:
6465 case bp_exception_master:
6467 case bp_fast_tracepoint:
6468 case bp_static_tracepoint:
6471 case bp_gnu_ifunc_resolver:
6472 case bp_gnu_ifunc_resolver_return:
6473 if (opts.addressprint)
6476 if (header_of_multiple)
6477 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6478 else if (b->loc == NULL || loc->shlib_disabled)
6479 ui_out_field_string (uiout, "addr", "<PENDING>");
6481 ui_out_field_core_addr (uiout, "addr",
6482 loc->gdbarch, loc->address);
6485 if (!header_of_multiple)
6486 print_breakpoint_location (b, loc);
6493 if (loc != NULL && !header_of_multiple)
6495 struct inferior *inf;
6496 VEC(int) *inf_num = NULL;
6501 if (inf->pspace == loc->pspace)
6502 VEC_safe_push (int, inf_num, inf->num);
6505 /* For backward compatibility, don't display inferiors in CLI unless
6506 there are several. Always display for MI. */
6508 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6509 && (number_of_program_spaces () > 1
6510 || number_of_inferiors () > 1)
6511 /* LOC is for existing B, it cannot be in
6512 moribund_locations and thus having NULL OWNER. */
6513 && loc->owner->type != bp_catchpoint))
6515 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6516 VEC_free (int, inf_num);
6519 if (!part_of_multiple)
6521 if (b->thread != -1)
6523 /* FIXME: This seems to be redundant and lost here; see the
6524 "stop only in" line a little further down. */
6525 ui_out_text (uiout, " thread ");
6526 ui_out_field_int (uiout, "thread", b->thread);
6528 else if (b->task != 0)
6530 ui_out_text (uiout, " task ");
6531 ui_out_field_int (uiout, "task", b->task);
6535 ui_out_text (uiout, "\n");
6537 if (!part_of_multiple)
6538 b->ops->print_one_detail (b, uiout);
6540 if (part_of_multiple && frame_id_p (b->frame_id))
6543 ui_out_text (uiout, "\tstop only in stack frame at ");
6544 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6546 ui_out_field_core_addr (uiout, "frame",
6547 b->gdbarch, b->frame_id.stack_addr);
6548 ui_out_text (uiout, "\n");
6551 if (!part_of_multiple && b->cond_string)
6554 if (is_tracepoint (b))
6555 ui_out_text (uiout, "\ttrace only if ");
6557 ui_out_text (uiout, "\tstop only if ");
6558 ui_out_field_string (uiout, "cond", b->cond_string);
6560 /* Print whether the target is doing the breakpoint's condition
6561 evaluation. If GDB is doing the evaluation, don't print anything. */
6562 if (is_breakpoint (b)
6563 && breakpoint_condition_evaluation_mode ()
6564 == condition_evaluation_target)
6566 ui_out_text (uiout, " (");
6567 ui_out_field_string (uiout, "evaluated-by",
6568 bp_condition_evaluator (b));
6569 ui_out_text (uiout, " evals)");
6571 ui_out_text (uiout, "\n");
6574 if (!part_of_multiple && b->thread != -1)
6576 /* FIXME should make an annotation for this. */
6577 ui_out_text (uiout, "\tstop only in thread ");
6578 if (ui_out_is_mi_like_p (uiout))
6579 ui_out_field_int (uiout, "thread", b->thread);
6582 struct thread_info *thr = find_thread_global_id (b->thread);
6584 ui_out_field_string (uiout, "thread", print_thread_id (thr));
6586 ui_out_text (uiout, "\n");
6589 if (!part_of_multiple)
6593 /* FIXME should make an annotation for this. */
6594 if (is_catchpoint (b))
6595 ui_out_text (uiout, "\tcatchpoint");
6596 else if (is_tracepoint (b))
6597 ui_out_text (uiout, "\ttracepoint");
6599 ui_out_text (uiout, "\tbreakpoint");
6600 ui_out_text (uiout, " already hit ");
6601 ui_out_field_int (uiout, "times", b->hit_count);
6602 if (b->hit_count == 1)
6603 ui_out_text (uiout, " time\n");
6605 ui_out_text (uiout, " times\n");
6609 /* Output the count also if it is zero, but only if this is mi. */
6610 if (ui_out_is_mi_like_p (uiout))
6611 ui_out_field_int (uiout, "times", b->hit_count);
6615 if (!part_of_multiple && b->ignore_count)
6618 ui_out_text (uiout, "\tignore next ");
6619 ui_out_field_int (uiout, "ignore", b->ignore_count);
6620 ui_out_text (uiout, " hits\n");
6623 /* Note that an enable count of 1 corresponds to "enable once"
6624 behavior, which is reported by the combination of enablement and
6625 disposition, so we don't need to mention it here. */
6626 if (!part_of_multiple && b->enable_count > 1)
6629 ui_out_text (uiout, "\tdisable after ");
6630 /* Tweak the wording to clarify that ignore and enable counts
6631 are distinct, and have additive effect. */
6632 if (b->ignore_count)
6633 ui_out_text (uiout, "additional ");
6635 ui_out_text (uiout, "next ");
6636 ui_out_field_int (uiout, "enable", b->enable_count);
6637 ui_out_text (uiout, " hits\n");
6640 if (!part_of_multiple && is_tracepoint (b))
6642 struct tracepoint *tp = (struct tracepoint *) b;
6644 if (tp->traceframe_usage)
6646 ui_out_text (uiout, "\ttrace buffer usage ");
6647 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6648 ui_out_text (uiout, " bytes\n");
6652 l = b->commands ? b->commands->commands : NULL;
6653 if (!part_of_multiple && l)
6655 struct cleanup *script_chain;
6658 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6659 print_command_lines (uiout, l, 4);
6660 do_cleanups (script_chain);
6663 if (is_tracepoint (b))
6665 struct tracepoint *t = (struct tracepoint *) b;
6667 if (!part_of_multiple && t->pass_count)
6669 annotate_field (10);
6670 ui_out_text (uiout, "\tpass count ");
6671 ui_out_field_int (uiout, "pass", t->pass_count);
6672 ui_out_text (uiout, " \n");
6675 /* Don't display it when tracepoint or tracepoint location is
6677 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6679 annotate_field (11);
6681 if (ui_out_is_mi_like_p (uiout))
6682 ui_out_field_string (uiout, "installed",
6683 loc->inserted ? "y" : "n");
6687 ui_out_text (uiout, "\t");
6689 ui_out_text (uiout, "\tnot ");
6690 ui_out_text (uiout, "installed on target\n");
6695 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6697 if (is_watchpoint (b))
6699 struct watchpoint *w = (struct watchpoint *) b;
6701 ui_out_field_string (uiout, "original-location", w->exp_string);
6703 else if (b->location != NULL
6704 && event_location_to_string (b->location) != NULL)
6705 ui_out_field_string (uiout, "original-location",
6706 event_location_to_string (b->location));
6711 print_one_breakpoint (struct breakpoint *b,
6712 struct bp_location **last_loc,
6715 struct cleanup *bkpt_chain;
6716 struct ui_out *uiout = current_uiout;
6718 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6720 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6721 do_cleanups (bkpt_chain);
6723 /* If this breakpoint has custom print function,
6724 it's already printed. Otherwise, print individual
6725 locations, if any. */
6726 if (b->ops == NULL || b->ops->print_one == NULL)
6728 /* If breakpoint has a single location that is disabled, we
6729 print it as if it had several locations, since otherwise it's
6730 hard to represent "breakpoint enabled, location disabled"
6733 Note that while hardware watchpoints have several locations
6734 internally, that's not a property exposed to user. */
6736 && !is_hardware_watchpoint (b)
6737 && (b->loc->next || !b->loc->enabled))
6739 struct bp_location *loc;
6742 for (loc = b->loc; loc; loc = loc->next, ++n)
6744 struct cleanup *inner2 =
6745 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6746 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6747 do_cleanups (inner2);
6754 breakpoint_address_bits (struct breakpoint *b)
6756 int print_address_bits = 0;
6757 struct bp_location *loc;
6759 /* Software watchpoints that aren't watching memory don't have an
6760 address to print. */
6761 if (is_no_memory_software_watchpoint (b))
6764 for (loc = b->loc; loc; loc = loc->next)
6768 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6769 if (addr_bit > print_address_bits)
6770 print_address_bits = addr_bit;
6773 return print_address_bits;
6776 struct captured_breakpoint_query_args
6782 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6784 struct captured_breakpoint_query_args *args
6785 = (struct captured_breakpoint_query_args *) data;
6786 struct breakpoint *b;
6787 struct bp_location *dummy_loc = NULL;
6791 if (args->bnum == b->number)
6793 print_one_breakpoint (b, &dummy_loc, 0);
6801 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6802 char **error_message)
6804 struct captured_breakpoint_query_args args;
6807 /* For the moment we don't trust print_one_breakpoint() to not throw
6809 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6810 error_message, RETURN_MASK_ALL) < 0)
6816 /* Return true if this breakpoint was set by the user, false if it is
6817 internal or momentary. */
6820 user_breakpoint_p (struct breakpoint *b)
6822 return b->number > 0;
6825 /* See breakpoint.h. */
6828 pending_breakpoint_p (struct breakpoint *b)
6830 return b->loc == NULL;
6833 /* Print information on user settable breakpoint (watchpoint, etc)
6834 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6835 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6836 FILTER is non-NULL, call it on each breakpoint and only include the
6837 ones for which it returns non-zero. Return the total number of
6838 breakpoints listed. */
6841 breakpoint_1 (char *args, int allflag,
6842 int (*filter) (const struct breakpoint *))
6844 struct breakpoint *b;
6845 struct bp_location *last_loc = NULL;
6846 int nr_printable_breakpoints;
6847 struct cleanup *bkpttbl_chain;
6848 struct value_print_options opts;
6849 int print_address_bits = 0;
6850 int print_type_col_width = 14;
6851 struct ui_out *uiout = current_uiout;
6853 get_user_print_options (&opts);
6855 /* Compute the number of rows in the table, as well as the size
6856 required for address fields. */
6857 nr_printable_breakpoints = 0;
6860 /* If we have a filter, only list the breakpoints it accepts. */
6861 if (filter && !filter (b))
6864 /* If we have an "args" string, it is a list of breakpoints to
6865 accept. Skip the others. */
6866 if (args != NULL && *args != '\0')
6868 if (allflag && parse_and_eval_long (args) != b->number)
6870 if (!allflag && !number_is_in_list (args, b->number))
6874 if (allflag || user_breakpoint_p (b))
6876 int addr_bit, type_len;
6878 addr_bit = breakpoint_address_bits (b);
6879 if (addr_bit > print_address_bits)
6880 print_address_bits = addr_bit;
6882 type_len = strlen (bptype_string (b->type));
6883 if (type_len > print_type_col_width)
6884 print_type_col_width = type_len;
6886 nr_printable_breakpoints++;
6890 if (opts.addressprint)
6892 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6893 nr_printable_breakpoints,
6897 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6898 nr_printable_breakpoints,
6901 if (nr_printable_breakpoints > 0)
6902 annotate_breakpoints_headers ();
6903 if (nr_printable_breakpoints > 0)
6905 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6906 if (nr_printable_breakpoints > 0)
6908 ui_out_table_header (uiout, print_type_col_width, ui_left,
6909 "type", "Type"); /* 2 */
6910 if (nr_printable_breakpoints > 0)
6912 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6913 if (nr_printable_breakpoints > 0)
6915 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6916 if (opts.addressprint)
6918 if (nr_printable_breakpoints > 0)
6920 if (print_address_bits <= 32)
6921 ui_out_table_header (uiout, 10, ui_left,
6922 "addr", "Address"); /* 5 */
6924 ui_out_table_header (uiout, 18, ui_left,
6925 "addr", "Address"); /* 5 */
6927 if (nr_printable_breakpoints > 0)
6929 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6930 ui_out_table_body (uiout);
6931 if (nr_printable_breakpoints > 0)
6932 annotate_breakpoints_table ();
6937 /* If we have a filter, only list the breakpoints it accepts. */
6938 if (filter && !filter (b))
6941 /* If we have an "args" string, it is a list of breakpoints to
6942 accept. Skip the others. */
6944 if (args != NULL && *args != '\0')
6946 if (allflag) /* maintenance info breakpoint */
6948 if (parse_and_eval_long (args) != b->number)
6951 else /* all others */
6953 if (!number_is_in_list (args, b->number))
6957 /* We only print out user settable breakpoints unless the
6959 if (allflag || user_breakpoint_p (b))
6960 print_one_breakpoint (b, &last_loc, allflag);
6963 do_cleanups (bkpttbl_chain);
6965 if (nr_printable_breakpoints == 0)
6967 /* If there's a filter, let the caller decide how to report
6971 if (args == NULL || *args == '\0')
6972 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6974 ui_out_message (uiout, 0,
6975 "No breakpoint or watchpoint matching '%s'.\n",
6981 if (last_loc && !server_command)
6982 set_next_address (last_loc->gdbarch, last_loc->address);
6985 /* FIXME? Should this be moved up so that it is only called when
6986 there have been breakpoints? */
6987 annotate_breakpoints_table_end ();
6989 return nr_printable_breakpoints;
6992 /* Display the value of default-collect in a way that is generally
6993 compatible with the breakpoint list. */
6996 default_collect_info (void)
6998 struct ui_out *uiout = current_uiout;
7000 /* If it has no value (which is frequently the case), say nothing; a
7001 message like "No default-collect." gets in user's face when it's
7003 if (!*default_collect)
7006 /* The following phrase lines up nicely with per-tracepoint collect
7008 ui_out_text (uiout, "default collect ");
7009 ui_out_field_string (uiout, "default-collect", default_collect);
7010 ui_out_text (uiout, " \n");
7014 breakpoints_info (char *args, int from_tty)
7016 breakpoint_1 (args, 0, NULL);
7018 default_collect_info ();
7022 watchpoints_info (char *args, int from_tty)
7024 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
7025 struct ui_out *uiout = current_uiout;
7027 if (num_printed == 0)
7029 if (args == NULL || *args == '\0')
7030 ui_out_message (uiout, 0, "No watchpoints.\n");
7032 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
7037 maintenance_info_breakpoints (char *args, int from_tty)
7039 breakpoint_1 (args, 1, NULL);
7041 default_collect_info ();
7045 breakpoint_has_pc (struct breakpoint *b,
7046 struct program_space *pspace,
7047 CORE_ADDR pc, struct obj_section *section)
7049 struct bp_location *bl = b->loc;
7051 for (; bl; bl = bl->next)
7053 if (bl->pspace == pspace
7054 && bl->address == pc
7055 && (!overlay_debugging || bl->section == section))
7061 /* Print a message describing any user-breakpoints set at PC. This
7062 concerns with logical breakpoints, so we match program spaces, not
7066 describe_other_breakpoints (struct gdbarch *gdbarch,
7067 struct program_space *pspace, CORE_ADDR pc,
7068 struct obj_section *section, int thread)
7071 struct breakpoint *b;
7074 others += (user_breakpoint_p (b)
7075 && breakpoint_has_pc (b, pspace, pc, section));
7079 printf_filtered (_("Note: breakpoint "));
7080 else /* if (others == ???) */
7081 printf_filtered (_("Note: breakpoints "));
7083 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
7086 printf_filtered ("%d", b->number);
7087 if (b->thread == -1 && thread != -1)
7088 printf_filtered (" (all threads)");
7089 else if (b->thread != -1)
7090 printf_filtered (" (thread %d)", b->thread);
7091 printf_filtered ("%s%s ",
7092 ((b->enable_state == bp_disabled
7093 || b->enable_state == bp_call_disabled)
7097 : ((others == 1) ? " and" : ""));
7099 printf_filtered (_("also set at pc "));
7100 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
7101 printf_filtered (".\n");
7106 /* Return true iff it is meaningful to use the address member of
7107 BPT locations. For some breakpoint types, the locations' address members
7108 are irrelevant and it makes no sense to attempt to compare them to other
7109 addresses (or use them for any other purpose either).
7111 More specifically, each of the following breakpoint types will
7112 always have a zero valued location address and we don't want to mark
7113 breakpoints of any of these types to be a duplicate of an actual
7114 breakpoint location at address zero:
7122 breakpoint_address_is_meaningful (struct breakpoint *bpt)
7124 enum bptype type = bpt->type;
7126 return (type != bp_watchpoint && type != bp_catchpoint);
7129 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7130 true if LOC1 and LOC2 represent the same watchpoint location. */
7133 watchpoint_locations_match (struct bp_location *loc1,
7134 struct bp_location *loc2)
7136 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
7137 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
7139 /* Both of them must exist. */
7140 gdb_assert (w1 != NULL);
7141 gdb_assert (w2 != NULL);
7143 /* If the target can evaluate the condition expression in hardware,
7144 then we we need to insert both watchpoints even if they are at
7145 the same place. Otherwise the watchpoint will only trigger when
7146 the condition of whichever watchpoint was inserted evaluates to
7147 true, not giving a chance for GDB to check the condition of the
7148 other watchpoint. */
7150 && target_can_accel_watchpoint_condition (loc1->address,
7152 loc1->watchpoint_type,
7155 && target_can_accel_watchpoint_condition (loc2->address,
7157 loc2->watchpoint_type,
7161 /* Note that this checks the owner's type, not the location's. In
7162 case the target does not support read watchpoints, but does
7163 support access watchpoints, we'll have bp_read_watchpoint
7164 watchpoints with hw_access locations. Those should be considered
7165 duplicates of hw_read locations. The hw_read locations will
7166 become hw_access locations later. */
7167 return (loc1->owner->type == loc2->owner->type
7168 && loc1->pspace->aspace == loc2->pspace->aspace
7169 && loc1->address == loc2->address
7170 && loc1->length == loc2->length);
7173 /* See breakpoint.h. */
7176 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7177 struct address_space *aspace2, CORE_ADDR addr2)
7179 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7180 || aspace1 == aspace2)
7184 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7185 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7186 matches ASPACE2. On targets that have global breakpoints, the address
7187 space doesn't really matter. */
7190 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7191 int len1, struct address_space *aspace2,
7194 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7195 || aspace1 == aspace2)
7196 && addr2 >= addr1 && addr2 < addr1 + len1);
7199 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7200 a ranged breakpoint. In most targets, a match happens only if ASPACE
7201 matches the breakpoint's address space. On targets that have global
7202 breakpoints, the address space doesn't really matter. */
7205 breakpoint_location_address_match (struct bp_location *bl,
7206 struct address_space *aspace,
7209 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7212 && breakpoint_address_match_range (bl->pspace->aspace,
7213 bl->address, bl->length,
7217 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7218 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7219 match happens only if ASPACE matches the breakpoint's address
7220 space. On targets that have global breakpoints, the address space
7221 doesn't really matter. */
7224 breakpoint_location_address_range_overlap (struct bp_location *bl,
7225 struct address_space *aspace,
7226 CORE_ADDR addr, int len)
7228 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7229 || bl->pspace->aspace == aspace)
7231 int bl_len = bl->length != 0 ? bl->length : 1;
7233 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
7239 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7240 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7241 true, otherwise returns false. */
7244 tracepoint_locations_match (struct bp_location *loc1,
7245 struct bp_location *loc2)
7247 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7248 /* Since tracepoint locations are never duplicated with others', tracepoint
7249 locations at the same address of different tracepoints are regarded as
7250 different locations. */
7251 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7256 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7257 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7258 represent the same location. */
7261 breakpoint_locations_match (struct bp_location *loc1,
7262 struct bp_location *loc2)
7264 int hw_point1, hw_point2;
7266 /* Both of them must not be in moribund_locations. */
7267 gdb_assert (loc1->owner != NULL);
7268 gdb_assert (loc2->owner != NULL);
7270 hw_point1 = is_hardware_watchpoint (loc1->owner);
7271 hw_point2 = is_hardware_watchpoint (loc2->owner);
7273 if (hw_point1 != hw_point2)
7276 return watchpoint_locations_match (loc1, loc2);
7277 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7278 return tracepoint_locations_match (loc1, loc2);
7280 /* We compare bp_location.length in order to cover ranged breakpoints. */
7281 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7282 loc2->pspace->aspace, loc2->address)
7283 && loc1->length == loc2->length);
7287 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7288 int bnum, int have_bnum)
7290 /* The longest string possibly returned by hex_string_custom
7291 is 50 chars. These must be at least that big for safety. */
7295 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7296 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7298 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7299 bnum, astr1, astr2);
7301 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7304 /* Adjust a breakpoint's address to account for architectural
7305 constraints on breakpoint placement. Return the adjusted address.
7306 Note: Very few targets require this kind of adjustment. For most
7307 targets, this function is simply the identity function. */
7310 adjust_breakpoint_address (struct gdbarch *gdbarch,
7311 CORE_ADDR bpaddr, enum bptype bptype)
7313 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7315 /* Very few targets need any kind of breakpoint adjustment. */
7318 else if (bptype == bp_watchpoint
7319 || bptype == bp_hardware_watchpoint
7320 || bptype == bp_read_watchpoint
7321 || bptype == bp_access_watchpoint
7322 || bptype == bp_catchpoint)
7324 /* Watchpoints and the various bp_catch_* eventpoints should not
7325 have their addresses modified. */
7328 else if (bptype == bp_single_step)
7330 /* Single-step breakpoints should not have their addresses
7331 modified. If there's any architectural constrain that
7332 applies to this address, then it should have already been
7333 taken into account when the breakpoint was created in the
7334 first place. If we didn't do this, stepping through e.g.,
7335 Thumb-2 IT blocks would break. */
7340 CORE_ADDR adjusted_bpaddr;
7342 /* Some targets have architectural constraints on the placement
7343 of breakpoint instructions. Obtain the adjusted address. */
7344 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7346 /* An adjusted breakpoint address can significantly alter
7347 a user's expectations. Print a warning if an adjustment
7349 if (adjusted_bpaddr != bpaddr)
7350 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7352 return adjusted_bpaddr;
7357 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7358 struct breakpoint *owner)
7360 memset (loc, 0, sizeof (*loc));
7362 gdb_assert (ops != NULL);
7367 loc->cond_bytecode = NULL;
7368 loc->shlib_disabled = 0;
7371 switch (owner->type)
7374 case bp_single_step:
7378 case bp_longjmp_resume:
7379 case bp_longjmp_call_dummy:
7381 case bp_exception_resume:
7382 case bp_step_resume:
7383 case bp_hp_step_resume:
7384 case bp_watchpoint_scope:
7386 case bp_std_terminate:
7387 case bp_shlib_event:
7388 case bp_thread_event:
7389 case bp_overlay_event:
7391 case bp_longjmp_master:
7392 case bp_std_terminate_master:
7393 case bp_exception_master:
7394 case bp_gnu_ifunc_resolver:
7395 case bp_gnu_ifunc_resolver_return:
7397 loc->loc_type = bp_loc_software_breakpoint;
7398 mark_breakpoint_location_modified (loc);
7400 case bp_hardware_breakpoint:
7401 loc->loc_type = bp_loc_hardware_breakpoint;
7402 mark_breakpoint_location_modified (loc);
7404 case bp_hardware_watchpoint:
7405 case bp_read_watchpoint:
7406 case bp_access_watchpoint:
7407 loc->loc_type = bp_loc_hardware_watchpoint;
7412 case bp_fast_tracepoint:
7413 case bp_static_tracepoint:
7414 loc->loc_type = bp_loc_other;
7417 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7423 /* Allocate a struct bp_location. */
7425 static struct bp_location *
7426 allocate_bp_location (struct breakpoint *bpt)
7428 return bpt->ops->allocate_location (bpt);
7432 free_bp_location (struct bp_location *loc)
7434 loc->ops->dtor (loc);
7438 /* Increment reference count. */
7441 incref_bp_location (struct bp_location *bl)
7446 /* Decrement reference count. If the reference count reaches 0,
7447 destroy the bp_location. Sets *BLP to NULL. */
7450 decref_bp_location (struct bp_location **blp)
7452 gdb_assert ((*blp)->refc > 0);
7454 if (--(*blp)->refc == 0)
7455 free_bp_location (*blp);
7459 /* Add breakpoint B at the end of the global breakpoint chain. */
7462 add_to_breakpoint_chain (struct breakpoint *b)
7464 struct breakpoint *b1;
7466 /* Add this breakpoint to the end of the chain so that a list of
7467 breakpoints will come out in order of increasing numbers. */
7469 b1 = breakpoint_chain;
7471 breakpoint_chain = b;
7480 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7483 init_raw_breakpoint_without_location (struct breakpoint *b,
7484 struct gdbarch *gdbarch,
7486 const struct breakpoint_ops *ops)
7488 memset (b, 0, sizeof (*b));
7490 gdb_assert (ops != NULL);
7494 b->gdbarch = gdbarch;
7495 b->language = current_language->la_language;
7496 b->input_radix = input_radix;
7498 b->enable_state = bp_enabled;
7501 b->ignore_count = 0;
7503 b->frame_id = null_frame_id;
7504 b->condition_not_parsed = 0;
7505 b->py_bp_object = NULL;
7506 b->related_breakpoint = b;
7510 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7511 that has type BPTYPE and has no locations as yet. */
7513 static struct breakpoint *
7514 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7516 const struct breakpoint_ops *ops)
7518 struct breakpoint *b = XNEW (struct breakpoint);
7520 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7521 add_to_breakpoint_chain (b);
7525 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7526 resolutions should be made as the user specified the location explicitly
7530 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7532 gdb_assert (loc->owner != NULL);
7534 if (loc->owner->type == bp_breakpoint
7535 || loc->owner->type == bp_hardware_breakpoint
7536 || is_tracepoint (loc->owner))
7539 const char *function_name;
7540 CORE_ADDR func_addr;
7542 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7543 &func_addr, NULL, &is_gnu_ifunc);
7545 if (is_gnu_ifunc && !explicit_loc)
7547 struct breakpoint *b = loc->owner;
7549 gdb_assert (loc->pspace == current_program_space);
7550 if (gnu_ifunc_resolve_name (function_name,
7551 &loc->requested_address))
7553 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7554 loc->address = adjust_breakpoint_address (loc->gdbarch,
7555 loc->requested_address,
7558 else if (b->type == bp_breakpoint && b->loc == loc
7559 && loc->next == NULL && b->related_breakpoint == b)
7561 /* Create only the whole new breakpoint of this type but do not
7562 mess more complicated breakpoints with multiple locations. */
7563 b->type = bp_gnu_ifunc_resolver;
7564 /* Remember the resolver's address for use by the return
7566 loc->related_address = func_addr;
7571 loc->function_name = xstrdup (function_name);
7575 /* Attempt to determine architecture of location identified by SAL. */
7577 get_sal_arch (struct symtab_and_line sal)
7580 return get_objfile_arch (sal.section->objfile);
7582 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7587 /* Low level routine for partially initializing a breakpoint of type
7588 BPTYPE. The newly created breakpoint's address, section, source
7589 file name, and line number are provided by SAL.
7591 It is expected that the caller will complete the initialization of
7592 the newly created breakpoint struct as well as output any status
7593 information regarding the creation of a new breakpoint. */
7596 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7597 struct symtab_and_line sal, enum bptype bptype,
7598 const struct breakpoint_ops *ops)
7600 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7602 add_location_to_breakpoint (b, &sal);
7604 if (bptype != bp_catchpoint)
7605 gdb_assert (sal.pspace != NULL);
7607 /* Store the program space that was used to set the breakpoint,
7608 except for ordinary breakpoints, which are independent of the
7610 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7611 b->pspace = sal.pspace;
7614 /* set_raw_breakpoint is a low level routine for allocating and
7615 partially initializing a breakpoint of type BPTYPE. The newly
7616 created breakpoint's address, section, source file name, and line
7617 number are provided by SAL. The newly created and partially
7618 initialized breakpoint is added to the breakpoint chain and
7619 is also returned as the value of this function.
7621 It is expected that the caller will complete the initialization of
7622 the newly created breakpoint struct as well as output any status
7623 information regarding the creation of a new breakpoint. In
7624 particular, set_raw_breakpoint does NOT set the breakpoint
7625 number! Care should be taken to not allow an error to occur
7626 prior to completing the initialization of the breakpoint. If this
7627 should happen, a bogus breakpoint will be left on the chain. */
7630 set_raw_breakpoint (struct gdbarch *gdbarch,
7631 struct symtab_and_line sal, enum bptype bptype,
7632 const struct breakpoint_ops *ops)
7634 struct breakpoint *b = XNEW (struct breakpoint);
7636 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7637 add_to_breakpoint_chain (b);
7641 /* Call this routine when stepping and nexting to enable a breakpoint
7642 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7643 initiated the operation. */
7646 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7648 struct breakpoint *b, *b_tmp;
7649 int thread = tp->global_num;
7651 /* To avoid having to rescan all objfile symbols at every step,
7652 we maintain a list of continually-inserted but always disabled
7653 longjmp "master" breakpoints. Here, we simply create momentary
7654 clones of those and enable them for the requested thread. */
7655 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7656 if (b->pspace == current_program_space
7657 && (b->type == bp_longjmp_master
7658 || b->type == bp_exception_master))
7660 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7661 struct breakpoint *clone;
7663 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7664 after their removal. */
7665 clone = momentary_breakpoint_from_master (b, type,
7666 &longjmp_breakpoint_ops, 1);
7667 clone->thread = thread;
7670 tp->initiating_frame = frame;
7673 /* Delete all longjmp breakpoints from THREAD. */
7675 delete_longjmp_breakpoint (int thread)
7677 struct breakpoint *b, *b_tmp;
7679 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7680 if (b->type == bp_longjmp || b->type == bp_exception)
7682 if (b->thread == thread)
7683 delete_breakpoint (b);
7688 delete_longjmp_breakpoint_at_next_stop (int thread)
7690 struct breakpoint *b, *b_tmp;
7692 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7693 if (b->type == bp_longjmp || b->type == bp_exception)
7695 if (b->thread == thread)
7696 b->disposition = disp_del_at_next_stop;
7700 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7701 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7702 pointer to any of them. Return NULL if this system cannot place longjmp
7706 set_longjmp_breakpoint_for_call_dummy (void)
7708 struct breakpoint *b, *retval = NULL;
7711 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7713 struct breakpoint *new_b;
7715 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7716 &momentary_breakpoint_ops,
7718 new_b->thread = ptid_to_global_thread_id (inferior_ptid);
7720 /* Link NEW_B into the chain of RETVAL breakpoints. */
7722 gdb_assert (new_b->related_breakpoint == new_b);
7725 new_b->related_breakpoint = retval;
7726 while (retval->related_breakpoint != new_b->related_breakpoint)
7727 retval = retval->related_breakpoint;
7728 retval->related_breakpoint = new_b;
7734 /* Verify all existing dummy frames and their associated breakpoints for
7735 TP. Remove those which can no longer be found in the current frame
7738 You should call this function only at places where it is safe to currently
7739 unwind the whole stack. Failed stack unwind would discard live dummy
7743 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7745 struct breakpoint *b, *b_tmp;
7747 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7748 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7750 struct breakpoint *dummy_b = b->related_breakpoint;
7752 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7753 dummy_b = dummy_b->related_breakpoint;
7754 if (dummy_b->type != bp_call_dummy
7755 || frame_find_by_id (dummy_b->frame_id) != NULL)
7758 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7760 while (b->related_breakpoint != b)
7762 if (b_tmp == b->related_breakpoint)
7763 b_tmp = b->related_breakpoint->next;
7764 delete_breakpoint (b->related_breakpoint);
7766 delete_breakpoint (b);
7771 enable_overlay_breakpoints (void)
7773 struct breakpoint *b;
7776 if (b->type == bp_overlay_event)
7778 b->enable_state = bp_enabled;
7779 update_global_location_list (UGLL_MAY_INSERT);
7780 overlay_events_enabled = 1;
7785 disable_overlay_breakpoints (void)
7787 struct breakpoint *b;
7790 if (b->type == bp_overlay_event)
7792 b->enable_state = bp_disabled;
7793 update_global_location_list (UGLL_DONT_INSERT);
7794 overlay_events_enabled = 0;
7798 /* Set an active std::terminate breakpoint for each std::terminate
7799 master breakpoint. */
7801 set_std_terminate_breakpoint (void)
7803 struct breakpoint *b, *b_tmp;
7805 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7806 if (b->pspace == current_program_space
7807 && b->type == bp_std_terminate_master)
7809 momentary_breakpoint_from_master (b, bp_std_terminate,
7810 &momentary_breakpoint_ops, 1);
7814 /* Delete all the std::terminate breakpoints. */
7816 delete_std_terminate_breakpoint (void)
7818 struct breakpoint *b, *b_tmp;
7820 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7821 if (b->type == bp_std_terminate)
7822 delete_breakpoint (b);
7826 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7828 struct breakpoint *b;
7830 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7831 &internal_breakpoint_ops);
7833 b->enable_state = bp_enabled;
7834 /* location has to be used or breakpoint_re_set will delete me. */
7835 b->location = new_address_location (b->loc->address, NULL, 0);
7837 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7842 struct lang_and_radix
7848 /* Create a breakpoint for JIT code registration and unregistration. */
7851 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7853 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7854 &internal_breakpoint_ops);
7857 /* Remove JIT code registration and unregistration breakpoint(s). */
7860 remove_jit_event_breakpoints (void)
7862 struct breakpoint *b, *b_tmp;
7864 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7865 if (b->type == bp_jit_event
7866 && b->loc->pspace == current_program_space)
7867 delete_breakpoint (b);
7871 remove_solib_event_breakpoints (void)
7873 struct breakpoint *b, *b_tmp;
7875 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7876 if (b->type == bp_shlib_event
7877 && b->loc->pspace == current_program_space)
7878 delete_breakpoint (b);
7881 /* See breakpoint.h. */
7884 remove_solib_event_breakpoints_at_next_stop (void)
7886 struct breakpoint *b, *b_tmp;
7888 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7889 if (b->type == bp_shlib_event
7890 && b->loc->pspace == current_program_space)
7891 b->disposition = disp_del_at_next_stop;
7894 /* Helper for create_solib_event_breakpoint /
7895 create_and_insert_solib_event_breakpoint. Allows specifying which
7896 INSERT_MODE to pass through to update_global_location_list. */
7898 static struct breakpoint *
7899 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7900 enum ugll_insert_mode insert_mode)
7902 struct breakpoint *b;
7904 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7905 &internal_breakpoint_ops);
7906 update_global_location_list_nothrow (insert_mode);
7911 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7913 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7916 /* See breakpoint.h. */
7919 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7921 struct breakpoint *b;
7923 /* Explicitly tell update_global_location_list to insert
7925 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7926 if (!b->loc->inserted)
7928 delete_breakpoint (b);
7934 /* Disable any breakpoints that are on code in shared libraries. Only
7935 apply to enabled breakpoints, disabled ones can just stay disabled. */
7938 disable_breakpoints_in_shlibs (void)
7940 struct bp_location *loc, **locp_tmp;
7942 ALL_BP_LOCATIONS (loc, locp_tmp)
7944 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7945 struct breakpoint *b = loc->owner;
7947 /* We apply the check to all breakpoints, including disabled for
7948 those with loc->duplicate set. This is so that when breakpoint
7949 becomes enabled, or the duplicate is removed, gdb will try to
7950 insert all breakpoints. If we don't set shlib_disabled here,
7951 we'll try to insert those breakpoints and fail. */
7952 if (((b->type == bp_breakpoint)
7953 || (b->type == bp_jit_event)
7954 || (b->type == bp_hardware_breakpoint)
7955 || (is_tracepoint (b)))
7956 && loc->pspace == current_program_space
7957 && !loc->shlib_disabled
7958 && solib_name_from_address (loc->pspace, loc->address)
7961 loc->shlib_disabled = 1;
7966 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7967 notification of unloaded_shlib. Only apply to enabled breakpoints,
7968 disabled ones can just stay disabled. */
7971 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7973 struct bp_location *loc, **locp_tmp;
7974 int disabled_shlib_breaks = 0;
7976 /* SunOS a.out shared libraries are always mapped, so do not
7977 disable breakpoints; they will only be reported as unloaded
7978 through clear_solib when GDB discards its shared library
7979 list. See clear_solib for more information. */
7980 if (exec_bfd != NULL
7981 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7984 ALL_BP_LOCATIONS (loc, locp_tmp)
7986 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7987 struct breakpoint *b = loc->owner;
7989 if (solib->pspace == loc->pspace
7990 && !loc->shlib_disabled
7991 && (((b->type == bp_breakpoint
7992 || b->type == bp_jit_event
7993 || b->type == bp_hardware_breakpoint)
7994 && (loc->loc_type == bp_loc_hardware_breakpoint
7995 || loc->loc_type == bp_loc_software_breakpoint))
7996 || is_tracepoint (b))
7997 && solib_contains_address_p (solib, loc->address))
7999 loc->shlib_disabled = 1;
8000 /* At this point, we cannot rely on remove_breakpoint
8001 succeeding so we must mark the breakpoint as not inserted
8002 to prevent future errors occurring in remove_breakpoints. */
8005 /* This may cause duplicate notifications for the same breakpoint. */
8006 observer_notify_breakpoint_modified (b);
8008 if (!disabled_shlib_breaks)
8010 target_terminal_ours_for_output ();
8011 warning (_("Temporarily disabling breakpoints "
8012 "for unloaded shared library \"%s\""),
8015 disabled_shlib_breaks = 1;
8020 /* Disable any breakpoints and tracepoints in OBJFILE upon
8021 notification of free_objfile. Only apply to enabled breakpoints,
8022 disabled ones can just stay disabled. */
8025 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
8027 struct breakpoint *b;
8029 if (objfile == NULL)
8032 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8033 managed by the user with add-symbol-file/remove-symbol-file.
8034 Similarly to how breakpoints in shared libraries are handled in
8035 response to "nosharedlibrary", mark breakpoints in such modules
8036 shlib_disabled so they end up uninserted on the next global
8037 location list update. Shared libraries not loaded by the user
8038 aren't handled here -- they're already handled in
8039 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8040 solib_unloaded observer. We skip objfiles that are not
8041 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8043 if ((objfile->flags & OBJF_SHARED) == 0
8044 || (objfile->flags & OBJF_USERLOADED) == 0)
8049 struct bp_location *loc;
8050 int bp_modified = 0;
8052 if (!is_breakpoint (b) && !is_tracepoint (b))
8055 for (loc = b->loc; loc != NULL; loc = loc->next)
8057 CORE_ADDR loc_addr = loc->address;
8059 if (loc->loc_type != bp_loc_hardware_breakpoint
8060 && loc->loc_type != bp_loc_software_breakpoint)
8063 if (loc->shlib_disabled != 0)
8066 if (objfile->pspace != loc->pspace)
8069 if (loc->loc_type != bp_loc_hardware_breakpoint
8070 && loc->loc_type != bp_loc_software_breakpoint)
8073 if (is_addr_in_objfile (loc_addr, objfile))
8075 loc->shlib_disabled = 1;
8076 /* At this point, we don't know whether the object was
8077 unmapped from the inferior or not, so leave the
8078 inserted flag alone. We'll handle failure to
8079 uninsert quietly, in case the object was indeed
8082 mark_breakpoint_location_modified (loc);
8089 observer_notify_breakpoint_modified (b);
8093 /* FORK & VFORK catchpoints. */
8095 /* An instance of this type is used to represent a fork or vfork
8096 catchpoint. It includes a "struct breakpoint" as a kind of base
8097 class; users downcast to "struct breakpoint *" when needed. A
8098 breakpoint is really of this type iff its ops pointer points to
8099 CATCH_FORK_BREAKPOINT_OPS. */
8101 struct fork_catchpoint
8103 /* The base class. */
8104 struct breakpoint base;
8106 /* Process id of a child process whose forking triggered this
8107 catchpoint. This field is only valid immediately after this
8108 catchpoint has triggered. */
8109 ptid_t forked_inferior_pid;
8112 /* Implement the "insert" breakpoint_ops method for fork
8116 insert_catch_fork (struct bp_location *bl)
8118 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
8121 /* Implement the "remove" breakpoint_ops method for fork
8125 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
8127 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
8130 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8134 breakpoint_hit_catch_fork (const struct bp_location *bl,
8135 struct address_space *aspace, CORE_ADDR bp_addr,
8136 const struct target_waitstatus *ws)
8138 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8140 if (ws->kind != TARGET_WAITKIND_FORKED)
8143 c->forked_inferior_pid = ws->value.related_pid;
8147 /* Implement the "print_it" breakpoint_ops method for fork
8150 static enum print_stop_action
8151 print_it_catch_fork (bpstat bs)
8153 struct ui_out *uiout = current_uiout;
8154 struct breakpoint *b = bs->breakpoint_at;
8155 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
8157 annotate_catchpoint (b->number);
8158 maybe_print_thread_hit_breakpoint (uiout);
8159 if (b->disposition == disp_del)
8160 ui_out_text (uiout, "Temporary catchpoint ");
8162 ui_out_text (uiout, "Catchpoint ");
8163 if (ui_out_is_mi_like_p (uiout))
8165 ui_out_field_string (uiout, "reason",
8166 async_reason_lookup (EXEC_ASYNC_FORK));
8167 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8169 ui_out_field_int (uiout, "bkptno", b->number);
8170 ui_out_text (uiout, " (forked process ");
8171 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8172 ui_out_text (uiout, "), ");
8173 return PRINT_SRC_AND_LOC;
8176 /* Implement the "print_one" breakpoint_ops method for fork
8180 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8182 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8183 struct value_print_options opts;
8184 struct ui_out *uiout = current_uiout;
8186 get_user_print_options (&opts);
8188 /* Field 4, the address, is omitted (which makes the columns not
8189 line up too nicely with the headers, but the effect is relatively
8191 if (opts.addressprint)
8192 ui_out_field_skip (uiout, "addr");
8194 ui_out_text (uiout, "fork");
8195 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8197 ui_out_text (uiout, ", process ");
8198 ui_out_field_int (uiout, "what",
8199 ptid_get_pid (c->forked_inferior_pid));
8200 ui_out_spaces (uiout, 1);
8203 if (ui_out_is_mi_like_p (uiout))
8204 ui_out_field_string (uiout, "catch-type", "fork");
8207 /* Implement the "print_mention" breakpoint_ops method for fork
8211 print_mention_catch_fork (struct breakpoint *b)
8213 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8216 /* Implement the "print_recreate" breakpoint_ops method for fork
8220 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8222 fprintf_unfiltered (fp, "catch fork");
8223 print_recreate_thread (b, fp);
8226 /* The breakpoint_ops structure to be used in fork catchpoints. */
8228 static struct breakpoint_ops catch_fork_breakpoint_ops;
8230 /* Implement the "insert" breakpoint_ops method for vfork
8234 insert_catch_vfork (struct bp_location *bl)
8236 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8239 /* Implement the "remove" breakpoint_ops method for vfork
8243 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
8245 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8248 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8252 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8253 struct address_space *aspace, CORE_ADDR bp_addr,
8254 const struct target_waitstatus *ws)
8256 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8258 if (ws->kind != TARGET_WAITKIND_VFORKED)
8261 c->forked_inferior_pid = ws->value.related_pid;
8265 /* Implement the "print_it" breakpoint_ops method for vfork
8268 static enum print_stop_action
8269 print_it_catch_vfork (bpstat bs)
8271 struct ui_out *uiout = current_uiout;
8272 struct breakpoint *b = bs->breakpoint_at;
8273 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8275 annotate_catchpoint (b->number);
8276 maybe_print_thread_hit_breakpoint (uiout);
8277 if (b->disposition == disp_del)
8278 ui_out_text (uiout, "Temporary catchpoint ");
8280 ui_out_text (uiout, "Catchpoint ");
8281 if (ui_out_is_mi_like_p (uiout))
8283 ui_out_field_string (uiout, "reason",
8284 async_reason_lookup (EXEC_ASYNC_VFORK));
8285 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8287 ui_out_field_int (uiout, "bkptno", b->number);
8288 ui_out_text (uiout, " (vforked process ");
8289 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8290 ui_out_text (uiout, "), ");
8291 return PRINT_SRC_AND_LOC;
8294 /* Implement the "print_one" breakpoint_ops method for vfork
8298 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8300 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8301 struct value_print_options opts;
8302 struct ui_out *uiout = current_uiout;
8304 get_user_print_options (&opts);
8305 /* Field 4, the address, is omitted (which makes the columns not
8306 line up too nicely with the headers, but the effect is relatively
8308 if (opts.addressprint)
8309 ui_out_field_skip (uiout, "addr");
8311 ui_out_text (uiout, "vfork");
8312 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8314 ui_out_text (uiout, ", process ");
8315 ui_out_field_int (uiout, "what",
8316 ptid_get_pid (c->forked_inferior_pid));
8317 ui_out_spaces (uiout, 1);
8320 if (ui_out_is_mi_like_p (uiout))
8321 ui_out_field_string (uiout, "catch-type", "vfork");
8324 /* Implement the "print_mention" breakpoint_ops method for vfork
8328 print_mention_catch_vfork (struct breakpoint *b)
8330 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8333 /* Implement the "print_recreate" breakpoint_ops method for vfork
8337 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8339 fprintf_unfiltered (fp, "catch vfork");
8340 print_recreate_thread (b, fp);
8343 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8345 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8347 /* An instance of this type is used to represent an solib catchpoint.
8348 It includes a "struct breakpoint" as a kind of base class; users
8349 downcast to "struct breakpoint *" when needed. A breakpoint is
8350 really of this type iff its ops pointer points to
8351 CATCH_SOLIB_BREAKPOINT_OPS. */
8353 struct solib_catchpoint
8355 /* The base class. */
8356 struct breakpoint base;
8358 /* True for "catch load", false for "catch unload". */
8359 unsigned char is_load;
8361 /* Regular expression to match, if any. COMPILED is only valid when
8362 REGEX is non-NULL. */
8368 dtor_catch_solib (struct breakpoint *b)
8370 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8373 regfree (&self->compiled);
8374 xfree (self->regex);
8376 base_breakpoint_ops.dtor (b);
8380 insert_catch_solib (struct bp_location *ignore)
8386 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
8392 breakpoint_hit_catch_solib (const struct bp_location *bl,
8393 struct address_space *aspace,
8395 const struct target_waitstatus *ws)
8397 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8398 struct breakpoint *other;
8400 if (ws->kind == TARGET_WAITKIND_LOADED)
8403 ALL_BREAKPOINTS (other)
8405 struct bp_location *other_bl;
8407 if (other == bl->owner)
8410 if (other->type != bp_shlib_event)
8413 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8416 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8418 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8427 check_status_catch_solib (struct bpstats *bs)
8429 struct solib_catchpoint *self
8430 = (struct solib_catchpoint *) bs->breakpoint_at;
8435 struct so_list *iter;
8438 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8443 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8452 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8457 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8463 bs->print_it = print_it_noop;
8466 static enum print_stop_action
8467 print_it_catch_solib (bpstat bs)
8469 struct breakpoint *b = bs->breakpoint_at;
8470 struct ui_out *uiout = current_uiout;
8472 annotate_catchpoint (b->number);
8473 maybe_print_thread_hit_breakpoint (uiout);
8474 if (b->disposition == disp_del)
8475 ui_out_text (uiout, "Temporary catchpoint ");
8477 ui_out_text (uiout, "Catchpoint ");
8478 ui_out_field_int (uiout, "bkptno", b->number);
8479 ui_out_text (uiout, "\n");
8480 if (ui_out_is_mi_like_p (uiout))
8481 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8482 print_solib_event (1);
8483 return PRINT_SRC_AND_LOC;
8487 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8489 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8490 struct value_print_options opts;
8491 struct ui_out *uiout = current_uiout;
8494 get_user_print_options (&opts);
8495 /* Field 4, the address, is omitted (which makes the columns not
8496 line up too nicely with the headers, but the effect is relatively
8498 if (opts.addressprint)
8501 ui_out_field_skip (uiout, "addr");
8508 msg = xstrprintf (_("load of library matching %s"), self->regex);
8510 msg = xstrdup (_("load of library"));
8515 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8517 msg = xstrdup (_("unload of library"));
8519 ui_out_field_string (uiout, "what", msg);
8522 if (ui_out_is_mi_like_p (uiout))
8523 ui_out_field_string (uiout, "catch-type",
8524 self->is_load ? "load" : "unload");
8528 print_mention_catch_solib (struct breakpoint *b)
8530 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8532 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8533 self->is_load ? "load" : "unload");
8537 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8539 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8541 fprintf_unfiltered (fp, "%s %s",
8542 b->disposition == disp_del ? "tcatch" : "catch",
8543 self->is_load ? "load" : "unload");
8545 fprintf_unfiltered (fp, " %s", self->regex);
8546 fprintf_unfiltered (fp, "\n");
8549 static struct breakpoint_ops catch_solib_breakpoint_ops;
8551 /* Shared helper function (MI and CLI) for creating and installing
8552 a shared object event catchpoint. If IS_LOAD is non-zero then
8553 the events to be caught are load events, otherwise they are
8554 unload events. If IS_TEMP is non-zero the catchpoint is a
8555 temporary one. If ENABLED is non-zero the catchpoint is
8556 created in an enabled state. */
8559 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8561 struct solib_catchpoint *c;
8562 struct gdbarch *gdbarch = get_current_arch ();
8563 struct cleanup *cleanup;
8567 arg = skip_spaces (arg);
8569 c = XCNEW (struct solib_catchpoint);
8570 cleanup = make_cleanup (xfree, c);
8576 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8579 char *err = get_regcomp_error (errcode, &c->compiled);
8581 make_cleanup (xfree, err);
8582 error (_("Invalid regexp (%s): %s"), err, arg);
8584 c->regex = xstrdup (arg);
8587 c->is_load = is_load;
8588 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8589 &catch_solib_breakpoint_ops);
8591 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8593 discard_cleanups (cleanup);
8594 install_breakpoint (0, &c->base, 1);
8597 /* A helper function that does all the work for "catch load" and
8601 catch_load_or_unload (char *arg, int from_tty, int is_load,
8602 struct cmd_list_element *command)
8605 const int enabled = 1;
8607 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8609 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8613 catch_load_command_1 (char *arg, int from_tty,
8614 struct cmd_list_element *command)
8616 catch_load_or_unload (arg, from_tty, 1, command);
8620 catch_unload_command_1 (char *arg, int from_tty,
8621 struct cmd_list_element *command)
8623 catch_load_or_unload (arg, from_tty, 0, command);
8626 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8627 is non-zero, then make the breakpoint temporary. If COND_STRING is
8628 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8629 the breakpoint_ops structure associated to the catchpoint. */
8632 init_catchpoint (struct breakpoint *b,
8633 struct gdbarch *gdbarch, int tempflag,
8635 const struct breakpoint_ops *ops)
8637 struct symtab_and_line sal;
8640 sal.pspace = current_program_space;
8642 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8644 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8645 b->disposition = tempflag ? disp_del : disp_donttouch;
8649 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8651 add_to_breakpoint_chain (b);
8652 set_breakpoint_number (internal, b);
8653 if (is_tracepoint (b))
8654 set_tracepoint_count (breakpoint_count);
8657 observer_notify_breakpoint_created (b);
8660 update_global_location_list (UGLL_MAY_INSERT);
8664 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8665 int tempflag, char *cond_string,
8666 const struct breakpoint_ops *ops)
8668 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8670 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8672 c->forked_inferior_pid = null_ptid;
8674 install_breakpoint (0, &c->base, 1);
8677 /* Exec catchpoints. */
8679 /* An instance of this type is used to represent an exec catchpoint.
8680 It includes a "struct breakpoint" as a kind of base class; users
8681 downcast to "struct breakpoint *" when needed. A breakpoint is
8682 really of this type iff its ops pointer points to
8683 CATCH_EXEC_BREAKPOINT_OPS. */
8685 struct exec_catchpoint
8687 /* The base class. */
8688 struct breakpoint base;
8690 /* Filename of a program whose exec triggered this catchpoint.
8691 This field is only valid immediately after this catchpoint has
8693 char *exec_pathname;
8696 /* Implement the "dtor" breakpoint_ops method for exec
8700 dtor_catch_exec (struct breakpoint *b)
8702 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8704 xfree (c->exec_pathname);
8706 base_breakpoint_ops.dtor (b);
8710 insert_catch_exec (struct bp_location *bl)
8712 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8716 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8718 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8722 breakpoint_hit_catch_exec (const struct bp_location *bl,
8723 struct address_space *aspace, CORE_ADDR bp_addr,
8724 const struct target_waitstatus *ws)
8726 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8728 if (ws->kind != TARGET_WAITKIND_EXECD)
8731 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8735 static enum print_stop_action
8736 print_it_catch_exec (bpstat bs)
8738 struct ui_out *uiout = current_uiout;
8739 struct breakpoint *b = bs->breakpoint_at;
8740 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8742 annotate_catchpoint (b->number);
8743 maybe_print_thread_hit_breakpoint (uiout);
8744 if (b->disposition == disp_del)
8745 ui_out_text (uiout, "Temporary catchpoint ");
8747 ui_out_text (uiout, "Catchpoint ");
8748 if (ui_out_is_mi_like_p (uiout))
8750 ui_out_field_string (uiout, "reason",
8751 async_reason_lookup (EXEC_ASYNC_EXEC));
8752 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8754 ui_out_field_int (uiout, "bkptno", b->number);
8755 ui_out_text (uiout, " (exec'd ");
8756 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8757 ui_out_text (uiout, "), ");
8759 return PRINT_SRC_AND_LOC;
8763 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8765 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8766 struct value_print_options opts;
8767 struct ui_out *uiout = current_uiout;
8769 get_user_print_options (&opts);
8771 /* Field 4, the address, is omitted (which makes the columns
8772 not line up too nicely with the headers, but the effect
8773 is relatively readable). */
8774 if (opts.addressprint)
8775 ui_out_field_skip (uiout, "addr");
8777 ui_out_text (uiout, "exec");
8778 if (c->exec_pathname != NULL)
8780 ui_out_text (uiout, ", program \"");
8781 ui_out_field_string (uiout, "what", c->exec_pathname);
8782 ui_out_text (uiout, "\" ");
8785 if (ui_out_is_mi_like_p (uiout))
8786 ui_out_field_string (uiout, "catch-type", "exec");
8790 print_mention_catch_exec (struct breakpoint *b)
8792 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8795 /* Implement the "print_recreate" breakpoint_ops method for exec
8799 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8801 fprintf_unfiltered (fp, "catch exec");
8802 print_recreate_thread (b, fp);
8805 static struct breakpoint_ops catch_exec_breakpoint_ops;
8808 hw_breakpoint_used_count (void)
8811 struct breakpoint *b;
8812 struct bp_location *bl;
8816 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8817 for (bl = b->loc; bl; bl = bl->next)
8819 /* Special types of hardware breakpoints may use more than
8821 i += b->ops->resources_needed (bl);
8828 /* Returns the resources B would use if it were a hardware
8832 hw_watchpoint_use_count (struct breakpoint *b)
8835 struct bp_location *bl;
8837 if (!breakpoint_enabled (b))
8840 for (bl = b->loc; bl; bl = bl->next)
8842 /* Special types of hardware watchpoints may use more than
8844 i += b->ops->resources_needed (bl);
8850 /* Returns the sum the used resources of all hardware watchpoints of
8851 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8852 the sum of the used resources of all hardware watchpoints of other
8853 types _not_ TYPE. */
8856 hw_watchpoint_used_count_others (struct breakpoint *except,
8857 enum bptype type, int *other_type_used)
8860 struct breakpoint *b;
8862 *other_type_used = 0;
8867 if (!breakpoint_enabled (b))
8870 if (b->type == type)
8871 i += hw_watchpoint_use_count (b);
8872 else if (is_hardware_watchpoint (b))
8873 *other_type_used = 1;
8880 disable_watchpoints_before_interactive_call_start (void)
8882 struct breakpoint *b;
8886 if (is_watchpoint (b) && breakpoint_enabled (b))
8888 b->enable_state = bp_call_disabled;
8889 update_global_location_list (UGLL_DONT_INSERT);
8895 enable_watchpoints_after_interactive_call_stop (void)
8897 struct breakpoint *b;
8901 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8903 b->enable_state = bp_enabled;
8904 update_global_location_list (UGLL_MAY_INSERT);
8910 disable_breakpoints_before_startup (void)
8912 current_program_space->executing_startup = 1;
8913 update_global_location_list (UGLL_DONT_INSERT);
8917 enable_breakpoints_after_startup (void)
8919 current_program_space->executing_startup = 0;
8920 breakpoint_re_set ();
8923 /* Create a new single-step breakpoint for thread THREAD, with no
8926 static struct breakpoint *
8927 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8929 struct breakpoint *b = XNEW (struct breakpoint);
8931 init_raw_breakpoint_without_location (b, gdbarch, bp_single_step,
8932 &momentary_breakpoint_ops);
8934 b->disposition = disp_donttouch;
8935 b->frame_id = null_frame_id;
8938 gdb_assert (b->thread != 0);
8940 add_to_breakpoint_chain (b);
8945 /* Set a momentary breakpoint of type TYPE at address specified by
8946 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8950 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8951 struct frame_id frame_id, enum bptype type)
8953 struct breakpoint *b;
8955 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8957 gdb_assert (!frame_id_artificial_p (frame_id));
8959 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8960 b->enable_state = bp_enabled;
8961 b->disposition = disp_donttouch;
8962 b->frame_id = frame_id;
8964 /* If we're debugging a multi-threaded program, then we want
8965 momentary breakpoints to be active in only a single thread of
8967 if (in_thread_list (inferior_ptid))
8968 b->thread = ptid_to_global_thread_id (inferior_ptid);
8970 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8975 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8976 The new breakpoint will have type TYPE, use OPS as its
8977 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8979 static struct breakpoint *
8980 momentary_breakpoint_from_master (struct breakpoint *orig,
8982 const struct breakpoint_ops *ops,
8985 struct breakpoint *copy;
8987 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8988 copy->loc = allocate_bp_location (copy);
8989 set_breakpoint_location_function (copy->loc, 1);
8991 copy->loc->gdbarch = orig->loc->gdbarch;
8992 copy->loc->requested_address = orig->loc->requested_address;
8993 copy->loc->address = orig->loc->address;
8994 copy->loc->section = orig->loc->section;
8995 copy->loc->pspace = orig->loc->pspace;
8996 copy->loc->probe = orig->loc->probe;
8997 copy->loc->line_number = orig->loc->line_number;
8998 copy->loc->symtab = orig->loc->symtab;
8999 copy->loc->enabled = loc_enabled;
9000 copy->frame_id = orig->frame_id;
9001 copy->thread = orig->thread;
9002 copy->pspace = orig->pspace;
9004 copy->enable_state = bp_enabled;
9005 copy->disposition = disp_donttouch;
9006 copy->number = internal_breakpoint_number--;
9008 update_global_location_list_nothrow (UGLL_DONT_INSERT);
9012 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9016 clone_momentary_breakpoint (struct breakpoint *orig)
9018 /* If there's nothing to clone, then return nothing. */
9022 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
9026 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
9029 struct symtab_and_line sal;
9031 sal = find_pc_line (pc, 0);
9033 sal.section = find_pc_overlay (pc);
9034 sal.explicit_pc = 1;
9036 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
9040 /* Tell the user we have just set a breakpoint B. */
9043 mention (struct breakpoint *b)
9045 b->ops->print_mention (b);
9046 if (ui_out_is_mi_like_p (current_uiout))
9048 printf_filtered ("\n");
9052 static int bp_loc_is_permanent (struct bp_location *loc);
9054 static struct bp_location *
9055 add_location_to_breakpoint (struct breakpoint *b,
9056 const struct symtab_and_line *sal)
9058 struct bp_location *loc, **tmp;
9059 CORE_ADDR adjusted_address;
9060 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9062 if (loc_gdbarch == NULL)
9063 loc_gdbarch = b->gdbarch;
9065 /* Adjust the breakpoint's address prior to allocating a location.
9066 Once we call allocate_bp_location(), that mostly uninitialized
9067 location will be placed on the location chain. Adjustment of the
9068 breakpoint may cause target_read_memory() to be called and we do
9069 not want its scan of the location chain to find a breakpoint and
9070 location that's only been partially initialized. */
9071 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9074 /* Sort the locations by their ADDRESS. */
9075 loc = allocate_bp_location (b);
9076 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9077 tmp = &((*tmp)->next))
9082 loc->requested_address = sal->pc;
9083 loc->address = adjusted_address;
9084 loc->pspace = sal->pspace;
9085 loc->probe.probe = sal->probe;
9086 loc->probe.objfile = sal->objfile;
9087 gdb_assert (loc->pspace != NULL);
9088 loc->section = sal->section;
9089 loc->gdbarch = loc_gdbarch;
9090 loc->line_number = sal->line;
9091 loc->symtab = sal->symtab;
9093 set_breakpoint_location_function (loc,
9094 sal->explicit_pc || sal->explicit_line);
9096 /* While by definition, permanent breakpoints are already present in the
9097 code, we don't mark the location as inserted. Normally one would expect
9098 that GDB could rely on that breakpoint instruction to stop the program,
9099 thus removing the need to insert its own breakpoint, except that executing
9100 the breakpoint instruction can kill the target instead of reporting a
9101 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9102 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9103 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9104 breakpoint be inserted normally results in QEMU knowing about the GDB
9105 breakpoint, and thus trap before the breakpoint instruction is executed.
9106 (If GDB later needs to continue execution past the permanent breakpoint,
9107 it manually increments the PC, thus avoiding executing the breakpoint
9109 if (bp_loc_is_permanent (loc))
9116 /* See breakpoint.h. */
9119 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
9123 const gdb_byte *bpoint;
9124 gdb_byte *target_mem;
9125 struct cleanup *cleanup;
9129 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
9131 /* Software breakpoints unsupported? */
9135 target_mem = (gdb_byte *) alloca (len);
9137 /* Enable the automatic memory restoration from breakpoints while
9138 we read the memory. Otherwise we could say about our temporary
9139 breakpoints they are permanent. */
9140 cleanup = make_show_memory_breakpoints_cleanup (0);
9142 if (target_read_memory (address, target_mem, len) == 0
9143 && memcmp (target_mem, bpoint, len) == 0)
9146 do_cleanups (cleanup);
9151 /* Return 1 if LOC is pointing to a permanent breakpoint,
9152 return 0 otherwise. */
9155 bp_loc_is_permanent (struct bp_location *loc)
9157 struct cleanup *cleanup;
9160 gdb_assert (loc != NULL);
9162 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9163 attempt to read from the addresses the locations of these breakpoint types
9164 point to. program_breakpoint_here_p, below, will attempt to read
9166 if (!breakpoint_address_is_meaningful (loc->owner))
9169 cleanup = save_current_space_and_thread ();
9170 switch_to_program_space_and_thread (loc->pspace);
9172 retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
9174 do_cleanups (cleanup);
9179 /* Build a command list for the dprintf corresponding to the current
9180 settings of the dprintf style options. */
9183 update_dprintf_command_list (struct breakpoint *b)
9185 char *dprintf_args = b->extra_string;
9186 char *printf_line = NULL;
9191 dprintf_args = skip_spaces (dprintf_args);
9193 /* Allow a comma, as it may have terminated a location, but don't
9195 if (*dprintf_args == ',')
9197 dprintf_args = skip_spaces (dprintf_args);
9199 if (*dprintf_args != '"')
9200 error (_("Bad format string, missing '\"'."));
9202 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9203 printf_line = xstrprintf ("printf %s", dprintf_args);
9204 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9206 if (!dprintf_function)
9207 error (_("No function supplied for dprintf call"));
9209 if (dprintf_channel && strlen (dprintf_channel) > 0)
9210 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9215 printf_line = xstrprintf ("call (void) %s (%s)",
9219 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9221 if (target_can_run_breakpoint_commands ())
9222 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9225 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9226 printf_line = xstrprintf ("printf %s", dprintf_args);
9230 internal_error (__FILE__, __LINE__,
9231 _("Invalid dprintf style."));
9233 gdb_assert (printf_line != NULL);
9234 /* Manufacture a printf sequence. */
9236 struct command_line *printf_cmd_line = XNEW (struct command_line);
9238 printf_cmd_line->control_type = simple_control;
9239 printf_cmd_line->body_count = 0;
9240 printf_cmd_line->body_list = NULL;
9241 printf_cmd_line->next = NULL;
9242 printf_cmd_line->line = printf_line;
9244 breakpoint_set_commands (b, printf_cmd_line);
9248 /* Update all dprintf commands, making their command lists reflect
9249 current style settings. */
9252 update_dprintf_commands (char *args, int from_tty,
9253 struct cmd_list_element *c)
9255 struct breakpoint *b;
9259 if (b->type == bp_dprintf)
9260 update_dprintf_command_list (b);
9264 /* Create a breakpoint with SAL as location. Use LOCATION
9265 as a description of the location, and COND_STRING
9266 as condition expression. If LOCATION is NULL then create an
9267 "address location" from the address in the SAL. */
9270 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9271 struct symtabs_and_lines sals,
9272 struct event_location *location,
9273 char *filter, char *cond_string,
9275 enum bptype type, enum bpdisp disposition,
9276 int thread, int task, int ignore_count,
9277 const struct breakpoint_ops *ops, int from_tty,
9278 int enabled, int internal, unsigned flags,
9279 int display_canonical)
9283 if (type == bp_hardware_breakpoint)
9285 int target_resources_ok;
9287 i = hw_breakpoint_used_count ();
9288 target_resources_ok =
9289 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9291 if (target_resources_ok == 0)
9292 error (_("No hardware breakpoint support in the target."));
9293 else if (target_resources_ok < 0)
9294 error (_("Hardware breakpoints used exceeds limit."));
9297 gdb_assert (sals.nelts > 0);
9299 for (i = 0; i < sals.nelts; ++i)
9301 struct symtab_and_line sal = sals.sals[i];
9302 struct bp_location *loc;
9306 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9308 loc_gdbarch = gdbarch;
9310 describe_other_breakpoints (loc_gdbarch,
9311 sal.pspace, sal.pc, sal.section, thread);
9316 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9320 b->cond_string = cond_string;
9321 b->extra_string = extra_string;
9322 b->ignore_count = ignore_count;
9323 b->enable_state = enabled ? bp_enabled : bp_disabled;
9324 b->disposition = disposition;
9326 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9327 b->loc->inserted = 1;
9329 if (type == bp_static_tracepoint)
9331 struct tracepoint *t = (struct tracepoint *) b;
9332 struct static_tracepoint_marker marker;
9334 if (strace_marker_p (b))
9336 /* We already know the marker exists, otherwise, we
9337 wouldn't see a sal for it. */
9338 const char *p = &event_location_to_string (b->location)[3];
9342 p = skip_spaces_const (p);
9344 endp = skip_to_space_const (p);
9346 marker_str = savestring (p, endp - p);
9347 t->static_trace_marker_id = marker_str;
9349 printf_filtered (_("Probed static tracepoint "
9351 t->static_trace_marker_id);
9353 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9355 t->static_trace_marker_id = xstrdup (marker.str_id);
9356 release_static_tracepoint_marker (&marker);
9358 printf_filtered (_("Probed static tracepoint "
9360 t->static_trace_marker_id);
9363 warning (_("Couldn't determine the static "
9364 "tracepoint marker to probe"));
9371 loc = add_location_to_breakpoint (b, &sal);
9372 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9378 const char *arg = b->cond_string;
9380 loc->cond = parse_exp_1 (&arg, loc->address,
9381 block_for_pc (loc->address), 0);
9383 error (_("Garbage '%s' follows condition"), arg);
9386 /* Dynamic printf requires and uses additional arguments on the
9387 command line, otherwise it's an error. */
9388 if (type == bp_dprintf)
9390 if (b->extra_string)
9391 update_dprintf_command_list (b);
9393 error (_("Format string required"));
9395 else if (b->extra_string)
9396 error (_("Garbage '%s' at end of command"), b->extra_string);
9399 b->display_canonical = display_canonical;
9400 if (location != NULL)
9401 b->location = location;
9404 const char *addr_string = NULL;
9405 int addr_string_len = 0;
9407 if (location != NULL)
9408 addr_string = event_location_to_string (location);
9409 if (addr_string != NULL)
9410 addr_string_len = strlen (addr_string);
9412 b->location = new_address_location (b->loc->address,
9413 addr_string, addr_string_len);
9419 create_breakpoint_sal (struct gdbarch *gdbarch,
9420 struct symtabs_and_lines sals,
9421 struct event_location *location,
9422 char *filter, char *cond_string,
9424 enum bptype type, enum bpdisp disposition,
9425 int thread, int task, int ignore_count,
9426 const struct breakpoint_ops *ops, int from_tty,
9427 int enabled, int internal, unsigned flags,
9428 int display_canonical)
9430 struct breakpoint *b;
9431 struct cleanup *old_chain;
9433 if (is_tracepoint_type (type))
9435 struct tracepoint *t;
9437 t = XCNEW (struct tracepoint);
9441 b = XNEW (struct breakpoint);
9443 old_chain = make_cleanup (xfree, b);
9445 init_breakpoint_sal (b, gdbarch,
9447 filter, cond_string, extra_string,
9449 thread, task, ignore_count,
9451 enabled, internal, flags,
9453 discard_cleanups (old_chain);
9455 install_breakpoint (internal, b, 0);
9458 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9459 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9460 value. COND_STRING, if not NULL, specified the condition to be
9461 used for all breakpoints. Essentially the only case where
9462 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9463 function. In that case, it's still not possible to specify
9464 separate conditions for different overloaded functions, so
9465 we take just a single condition string.
9467 NOTE: If the function succeeds, the caller is expected to cleanup
9468 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9469 array contents). If the function fails (error() is called), the
9470 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9471 COND and SALS arrays and each of those arrays contents. */
9474 create_breakpoints_sal (struct gdbarch *gdbarch,
9475 struct linespec_result *canonical,
9476 char *cond_string, char *extra_string,
9477 enum bptype type, enum bpdisp disposition,
9478 int thread, int task, int ignore_count,
9479 const struct breakpoint_ops *ops, int from_tty,
9480 int enabled, int internal, unsigned flags)
9483 struct linespec_sals *lsal;
9485 if (canonical->pre_expanded)
9486 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9488 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9490 /* Note that 'location' can be NULL in the case of a plain
9491 'break', without arguments. */
9492 struct event_location *location
9493 = (canonical->location != NULL
9494 ? copy_event_location (canonical->location) : NULL);
9495 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9496 struct cleanup *inner = make_cleanup_delete_event_location (location);
9498 make_cleanup (xfree, filter_string);
9499 create_breakpoint_sal (gdbarch, lsal->sals,
9502 cond_string, extra_string,
9504 thread, task, ignore_count, ops,
9505 from_tty, enabled, internal, flags,
9506 canonical->special_display);
9507 discard_cleanups (inner);
9511 /* Parse LOCATION which is assumed to be a SAL specification possibly
9512 followed by conditionals. On return, SALS contains an array of SAL
9513 addresses found. LOCATION points to the end of the SAL (for
9514 linespec locations).
9516 The array and the line spec strings are allocated on the heap, it is
9517 the caller's responsibility to free them. */
9520 parse_breakpoint_sals (const struct event_location *location,
9521 struct linespec_result *canonical)
9523 struct symtab_and_line cursal;
9525 if (event_location_type (location) == LINESPEC_LOCATION)
9527 const char *address = get_linespec_location (location);
9529 if (address == NULL)
9531 /* The last displayed codepoint, if it's valid, is our default
9532 breakpoint address. */
9533 if (last_displayed_sal_is_valid ())
9535 struct linespec_sals lsal;
9536 struct symtab_and_line sal;
9539 init_sal (&sal); /* Initialize to zeroes. */
9540 lsal.sals.sals = XNEW (struct symtab_and_line);
9542 /* Set sal's pspace, pc, symtab, and line to the values
9543 corresponding to the last call to print_frame_info.
9544 Be sure to reinitialize LINE with NOTCURRENT == 0
9545 as the breakpoint line number is inappropriate otherwise.
9546 find_pc_line would adjust PC, re-set it back. */
9547 get_last_displayed_sal (&sal);
9549 sal = find_pc_line (pc, 0);
9551 /* "break" without arguments is equivalent to "break *PC"
9552 where PC is the last displayed codepoint's address. So
9553 make sure to set sal.explicit_pc to prevent GDB from
9554 trying to expand the list of sals to include all other
9555 instances with the same symtab and line. */
9557 sal.explicit_pc = 1;
9559 lsal.sals.sals[0] = sal;
9560 lsal.sals.nelts = 1;
9561 lsal.canonical = NULL;
9563 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9567 error (_("No default breakpoint address now."));
9571 /* Force almost all breakpoints to be in terms of the
9572 current_source_symtab (which is decode_line_1's default).
9573 This should produce the results we want almost all of the
9574 time while leaving default_breakpoint_* alone.
9576 ObjC: However, don't match an Objective-C method name which
9577 may have a '+' or '-' succeeded by a '['. */
9578 cursal = get_current_source_symtab_and_line ();
9579 if (last_displayed_sal_is_valid ())
9581 const char *address = NULL;
9583 if (event_location_type (location) == LINESPEC_LOCATION)
9584 address = get_linespec_location (location);
9588 && strchr ("+-", address[0]) != NULL
9589 && address[1] != '['))
9591 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9592 get_last_displayed_symtab (),
9593 get_last_displayed_line (),
9594 canonical, NULL, NULL);
9599 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9600 cursal.symtab, cursal.line, canonical, NULL, NULL);
9604 /* Convert each SAL into a real PC. Verify that the PC can be
9605 inserted as a breakpoint. If it can't throw an error. */
9608 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9612 for (i = 0; i < sals->nelts; i++)
9613 resolve_sal_pc (&sals->sals[i]);
9616 /* Fast tracepoints may have restrictions on valid locations. For
9617 instance, a fast tracepoint using a jump instead of a trap will
9618 likely have to overwrite more bytes than a trap would, and so can
9619 only be placed where the instruction is longer than the jump, or a
9620 multi-instruction sequence does not have a jump into the middle of
9624 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9625 struct symtabs_and_lines *sals)
9628 struct symtab_and_line *sal;
9630 struct cleanup *old_chain;
9632 for (i = 0; i < sals->nelts; i++)
9634 struct gdbarch *sarch;
9636 sal = &sals->sals[i];
9638 sarch = get_sal_arch (*sal);
9639 /* We fall back to GDBARCH if there is no architecture
9640 associated with SAL. */
9643 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg);
9644 old_chain = make_cleanup (xfree, msg);
9647 error (_("May not have a fast tracepoint at %s%s"),
9648 paddress (sarch, sal->pc), (msg ? msg : ""));
9650 do_cleanups (old_chain);
9654 /* Given TOK, a string specification of condition and thread, as
9655 accepted by the 'break' command, extract the condition
9656 string and thread number and set *COND_STRING and *THREAD.
9657 PC identifies the context at which the condition should be parsed.
9658 If no condition is found, *COND_STRING is set to NULL.
9659 If no thread is found, *THREAD is set to -1. */
9662 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9663 char **cond_string, int *thread, int *task,
9666 *cond_string = NULL;
9673 const char *end_tok;
9675 const char *cond_start = NULL;
9676 const char *cond_end = NULL;
9678 tok = skip_spaces_const (tok);
9680 if ((*tok == '"' || *tok == ',') && rest)
9682 *rest = savestring (tok, strlen (tok));
9686 end_tok = skip_to_space_const (tok);
9688 toklen = end_tok - tok;
9690 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9692 struct expression *expr;
9694 tok = cond_start = end_tok + 1;
9695 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9698 *cond_string = savestring (cond_start, cond_end - cond_start);
9700 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9703 struct thread_info *thr;
9706 thr = parse_thread_id (tok, &tmptok);
9708 error (_("Junk after thread keyword."));
9709 *thread = thr->global_num;
9712 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9717 *task = strtol (tok, &tmptok, 0);
9719 error (_("Junk after task keyword."));
9720 if (!valid_task_id (*task))
9721 error (_("Unknown task %d."), *task);
9726 *rest = savestring (tok, strlen (tok));
9730 error (_("Junk at end of arguments."));
9734 /* Decode a static tracepoint marker spec. */
9736 static struct symtabs_and_lines
9737 decode_static_tracepoint_spec (const char **arg_p)
9739 VEC(static_tracepoint_marker_p) *markers = NULL;
9740 struct symtabs_and_lines sals;
9741 struct cleanup *old_chain;
9742 const char *p = &(*arg_p)[3];
9747 p = skip_spaces_const (p);
9749 endp = skip_to_space_const (p);
9751 marker_str = savestring (p, endp - p);
9752 old_chain = make_cleanup (xfree, marker_str);
9754 markers = target_static_tracepoint_markers_by_strid (marker_str);
9755 if (VEC_empty(static_tracepoint_marker_p, markers))
9756 error (_("No known static tracepoint marker named %s"), marker_str);
9758 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9759 sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
9761 for (i = 0; i < sals.nelts; i++)
9763 struct static_tracepoint_marker *marker;
9765 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9767 init_sal (&sals.sals[i]);
9769 sals.sals[i] = find_pc_line (marker->address, 0);
9770 sals.sals[i].pc = marker->address;
9772 release_static_tracepoint_marker (marker);
9775 do_cleanups (old_chain);
9781 /* See breakpoint.h. */
9784 create_breakpoint (struct gdbarch *gdbarch,
9785 const struct event_location *location, char *cond_string,
9786 int thread, char *extra_string,
9788 int tempflag, enum bptype type_wanted,
9790 enum auto_boolean pending_break_support,
9791 const struct breakpoint_ops *ops,
9792 int from_tty, int enabled, int internal,
9795 struct linespec_result canonical;
9796 struct cleanup *old_chain;
9797 struct cleanup *bkpt_chain = NULL;
9800 int prev_bkpt_count = breakpoint_count;
9802 gdb_assert (ops != NULL);
9804 /* If extra_string isn't useful, set it to NULL. */
9805 if (extra_string != NULL && *extra_string == '\0')
9806 extra_string = NULL;
9808 init_linespec_result (&canonical);
9812 ops->create_sals_from_location (location, &canonical, type_wanted);
9814 CATCH (e, RETURN_MASK_ERROR)
9816 /* If caller is interested in rc value from parse, set
9818 if (e.error == NOT_FOUND_ERROR)
9820 /* If pending breakpoint support is turned off, throw
9823 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9824 throw_exception (e);
9826 exception_print (gdb_stderr, e);
9828 /* If pending breakpoint support is auto query and the user
9829 selects no, then simply return the error code. */
9830 if (pending_break_support == AUTO_BOOLEAN_AUTO
9831 && !nquery (_("Make %s pending on future shared library load? "),
9832 bptype_string (type_wanted)))
9835 /* At this point, either the user was queried about setting
9836 a pending breakpoint and selected yes, or pending
9837 breakpoint behavior is on and thus a pending breakpoint
9838 is defaulted on behalf of the user. */
9842 throw_exception (e);
9846 if (!pending && VEC_empty (linespec_sals, canonical.sals))
9849 /* Create a chain of things that always need to be cleaned up. */
9850 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9852 /* ----------------------------- SNIP -----------------------------
9853 Anything added to the cleanup chain beyond this point is assumed
9854 to be part of a breakpoint. If the breakpoint create succeeds
9855 then the memory is not reclaimed. */
9856 bkpt_chain = make_cleanup (null_cleanup, 0);
9858 /* Resolve all line numbers to PC's and verify that the addresses
9859 are ok for the target. */
9863 struct linespec_sals *iter;
9865 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9866 breakpoint_sals_to_pc (&iter->sals);
9869 /* Fast tracepoints may have additional restrictions on location. */
9870 if (!pending && type_wanted == bp_fast_tracepoint)
9873 struct linespec_sals *iter;
9875 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9876 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9879 /* Verify that condition can be parsed, before setting any
9880 breakpoints. Allocate a separate condition expression for each
9887 struct linespec_sals *lsal;
9889 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9891 /* Here we only parse 'arg' to separate condition
9892 from thread number, so parsing in context of first
9893 sal is OK. When setting the breakpoint we'll
9894 re-parse it in context of each sal. */
9896 find_condition_and_thread (extra_string, lsal->sals.sals[0].pc,
9897 &cond_string, &thread, &task, &rest);
9899 make_cleanup (xfree, cond_string);
9901 make_cleanup (xfree, rest);
9903 extra_string = rest;
9905 extra_string = NULL;
9909 if (type_wanted != bp_dprintf
9910 && extra_string != NULL && *extra_string != '\0')
9911 error (_("Garbage '%s' at end of location"), extra_string);
9913 /* Create a private copy of condition string. */
9916 cond_string = xstrdup (cond_string);
9917 make_cleanup (xfree, cond_string);
9919 /* Create a private copy of any extra string. */
9922 extra_string = xstrdup (extra_string);
9923 make_cleanup (xfree, extra_string);
9927 ops->create_breakpoints_sal (gdbarch, &canonical,
9928 cond_string, extra_string, type_wanted,
9929 tempflag ? disp_del : disp_donttouch,
9930 thread, task, ignore_count, ops,
9931 from_tty, enabled, internal, flags);
9935 struct breakpoint *b;
9937 if (is_tracepoint_type (type_wanted))
9939 struct tracepoint *t;
9941 t = XCNEW (struct tracepoint);
9945 b = XNEW (struct breakpoint);
9947 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9948 b->location = copy_event_location (location);
9951 b->cond_string = NULL;
9954 /* Create a private copy of condition string. */
9957 cond_string = xstrdup (cond_string);
9958 make_cleanup (xfree, cond_string);
9960 b->cond_string = cond_string;
9964 /* Create a private copy of any extra string. */
9965 if (extra_string != NULL)
9967 extra_string = xstrdup (extra_string);
9968 make_cleanup (xfree, extra_string);
9970 b->extra_string = extra_string;
9971 b->ignore_count = ignore_count;
9972 b->disposition = tempflag ? disp_del : disp_donttouch;
9973 b->condition_not_parsed = 1;
9974 b->enable_state = enabled ? bp_enabled : bp_disabled;
9975 if ((type_wanted != bp_breakpoint
9976 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9977 b->pspace = current_program_space;
9979 install_breakpoint (internal, b, 0);
9982 if (VEC_length (linespec_sals, canonical.sals) > 1)
9984 warning (_("Multiple breakpoints were set.\nUse the "
9985 "\"delete\" command to delete unwanted breakpoints."));
9986 prev_breakpoint_count = prev_bkpt_count;
9989 /* That's it. Discard the cleanups for data inserted into the
9991 discard_cleanups (bkpt_chain);
9992 /* But cleanup everything else. */
9993 do_cleanups (old_chain);
9995 /* error call may happen here - have BKPT_CHAIN already discarded. */
9996 update_global_location_list (UGLL_MAY_INSERT);
10001 /* Set a breakpoint.
10002 ARG is a string describing breakpoint address,
10003 condition, and thread.
10004 FLAG specifies if a breakpoint is hardware on,
10005 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10006 and BP_TEMPFLAG. */
10009 break_command_1 (char *arg, int flag, int from_tty)
10011 int tempflag = flag & BP_TEMPFLAG;
10012 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
10013 ? bp_hardware_breakpoint
10015 struct breakpoint_ops *ops;
10016 struct event_location *location;
10017 struct cleanup *cleanup;
10019 location = string_to_event_location (&arg, current_language);
10020 cleanup = make_cleanup_delete_event_location (location);
10022 /* Matching breakpoints on probes. */
10023 if (location != NULL
10024 && event_location_type (location) == PROBE_LOCATION)
10025 ops = &bkpt_probe_breakpoint_ops;
10027 ops = &bkpt_breakpoint_ops;
10029 create_breakpoint (get_current_arch (),
10031 NULL, 0, arg, 1 /* parse arg */,
10032 tempflag, type_wanted,
10033 0 /* Ignore count */,
10034 pending_break_support,
10040 do_cleanups (cleanup);
10043 /* Helper function for break_command_1 and disassemble_command. */
10046 resolve_sal_pc (struct symtab_and_line *sal)
10050 if (sal->pc == 0 && sal->symtab != NULL)
10052 if (!find_line_pc (sal->symtab, sal->line, &pc))
10053 error (_("No line %d in file \"%s\"."),
10054 sal->line, symtab_to_filename_for_display (sal->symtab));
10057 /* If this SAL corresponds to a breakpoint inserted using a line
10058 number, then skip the function prologue if necessary. */
10059 if (sal->explicit_line)
10060 skip_prologue_sal (sal);
10063 if (sal->section == 0 && sal->symtab != NULL)
10065 const struct blockvector *bv;
10066 const struct block *b;
10067 struct symbol *sym;
10069 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
10070 SYMTAB_COMPUNIT (sal->symtab));
10073 sym = block_linkage_function (b);
10076 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
10077 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
10082 /* It really is worthwhile to have the section, so we'll
10083 just have to look harder. This case can be executed
10084 if we have line numbers but no functions (as can
10085 happen in assembly source). */
10087 struct bound_minimal_symbol msym;
10088 struct cleanup *old_chain = save_current_space_and_thread ();
10090 switch_to_program_space_and_thread (sal->pspace);
10092 msym = lookup_minimal_symbol_by_pc (sal->pc);
10094 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10096 do_cleanups (old_chain);
10103 break_command (char *arg, int from_tty)
10105 break_command_1 (arg, 0, from_tty);
10109 tbreak_command (char *arg, int from_tty)
10111 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10115 hbreak_command (char *arg, int from_tty)
10117 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10121 thbreak_command (char *arg, int from_tty)
10123 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10127 stop_command (char *arg, int from_tty)
10129 printf_filtered (_("Specify the type of breakpoint to set.\n\
10130 Usage: stop in <function | address>\n\
10131 stop at <line>\n"));
10135 stopin_command (char *arg, int from_tty)
10139 if (arg == (char *) NULL)
10141 else if (*arg != '*')
10143 char *argptr = arg;
10146 /* Look for a ':'. If this is a line number specification, then
10147 say it is bad, otherwise, it should be an address or
10148 function/method name. */
10149 while (*argptr && !hasColon)
10151 hasColon = (*argptr == ':');
10156 badInput = (*argptr != ':'); /* Not a class::method */
10158 badInput = isdigit (*arg); /* a simple line number */
10162 printf_filtered (_("Usage: stop in <function | address>\n"));
10164 break_command_1 (arg, 0, from_tty);
10168 stopat_command (char *arg, int from_tty)
10172 if (arg == (char *) NULL || *arg == '*') /* no line number */
10176 char *argptr = arg;
10179 /* Look for a ':'. If there is a '::' then get out, otherwise
10180 it is probably a line number. */
10181 while (*argptr && !hasColon)
10183 hasColon = (*argptr == ':');
10188 badInput = (*argptr == ':'); /* we have class::method */
10190 badInput = !isdigit (*arg); /* not a line number */
10194 printf_filtered (_("Usage: stop at <line>\n"));
10196 break_command_1 (arg, 0, from_tty);
10199 /* The dynamic printf command is mostly like a regular breakpoint, but
10200 with a prewired command list consisting of a single output command,
10201 built from extra arguments supplied on the dprintf command
10205 dprintf_command (char *arg, int from_tty)
10207 struct event_location *location;
10208 struct cleanup *cleanup;
10210 location = string_to_event_location (&arg, current_language);
10211 cleanup = make_cleanup_delete_event_location (location);
10213 /* If non-NULL, ARG should have been advanced past the location;
10214 the next character must be ','. */
10217 if (arg[0] != ',' || arg[1] == '\0')
10218 error (_("Format string required"));
10221 /* Skip the comma. */
10226 create_breakpoint (get_current_arch (),
10228 NULL, 0, arg, 1 /* parse arg */,
10230 0 /* Ignore count */,
10231 pending_break_support,
10232 &dprintf_breakpoint_ops,
10237 do_cleanups (cleanup);
10241 agent_printf_command (char *arg, int from_tty)
10243 error (_("May only run agent-printf on the target"));
10246 /* Implement the "breakpoint_hit" breakpoint_ops method for
10247 ranged breakpoints. */
10250 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10251 struct address_space *aspace,
10253 const struct target_waitstatus *ws)
10255 if (ws->kind != TARGET_WAITKIND_STOPPED
10256 || ws->value.sig != GDB_SIGNAL_TRAP)
10259 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10260 bl->length, aspace, bp_addr);
10263 /* Implement the "resources_needed" breakpoint_ops method for
10264 ranged breakpoints. */
10267 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10269 return target_ranged_break_num_registers ();
10272 /* Implement the "print_it" breakpoint_ops method for
10273 ranged breakpoints. */
10275 static enum print_stop_action
10276 print_it_ranged_breakpoint (bpstat bs)
10278 struct breakpoint *b = bs->breakpoint_at;
10279 struct bp_location *bl = b->loc;
10280 struct ui_out *uiout = current_uiout;
10282 gdb_assert (b->type == bp_hardware_breakpoint);
10284 /* Ranged breakpoints have only one location. */
10285 gdb_assert (bl && bl->next == NULL);
10287 annotate_breakpoint (b->number);
10289 maybe_print_thread_hit_breakpoint (uiout);
10291 if (b->disposition == disp_del)
10292 ui_out_text (uiout, "Temporary ranged breakpoint ");
10294 ui_out_text (uiout, "Ranged breakpoint ");
10295 if (ui_out_is_mi_like_p (uiout))
10297 ui_out_field_string (uiout, "reason",
10298 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10299 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10301 ui_out_field_int (uiout, "bkptno", b->number);
10302 ui_out_text (uiout, ", ");
10304 return PRINT_SRC_AND_LOC;
10307 /* Implement the "print_one" breakpoint_ops method for
10308 ranged breakpoints. */
10311 print_one_ranged_breakpoint (struct breakpoint *b,
10312 struct bp_location **last_loc)
10314 struct bp_location *bl = b->loc;
10315 struct value_print_options opts;
10316 struct ui_out *uiout = current_uiout;
10318 /* Ranged breakpoints have only one location. */
10319 gdb_assert (bl && bl->next == NULL);
10321 get_user_print_options (&opts);
10323 if (opts.addressprint)
10324 /* We don't print the address range here, it will be printed later
10325 by print_one_detail_ranged_breakpoint. */
10326 ui_out_field_skip (uiout, "addr");
10327 annotate_field (5);
10328 print_breakpoint_location (b, bl);
10332 /* Implement the "print_one_detail" breakpoint_ops method for
10333 ranged breakpoints. */
10336 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10337 struct ui_out *uiout)
10339 CORE_ADDR address_start, address_end;
10340 struct bp_location *bl = b->loc;
10341 struct ui_file *stb = mem_fileopen ();
10342 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10346 address_start = bl->address;
10347 address_end = address_start + bl->length - 1;
10349 ui_out_text (uiout, "\taddress range: ");
10350 fprintf_unfiltered (stb, "[%s, %s]",
10351 print_core_address (bl->gdbarch, address_start),
10352 print_core_address (bl->gdbarch, address_end));
10353 ui_out_field_stream (uiout, "addr", stb);
10354 ui_out_text (uiout, "\n");
10356 do_cleanups (cleanup);
10359 /* Implement the "print_mention" breakpoint_ops method for
10360 ranged breakpoints. */
10363 print_mention_ranged_breakpoint (struct breakpoint *b)
10365 struct bp_location *bl = b->loc;
10366 struct ui_out *uiout = current_uiout;
10369 gdb_assert (b->type == bp_hardware_breakpoint);
10371 if (ui_out_is_mi_like_p (uiout))
10374 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10375 b->number, paddress (bl->gdbarch, bl->address),
10376 paddress (bl->gdbarch, bl->address + bl->length - 1));
10379 /* Implement the "print_recreate" breakpoint_ops method for
10380 ranged breakpoints. */
10383 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10385 fprintf_unfiltered (fp, "break-range %s, %s",
10386 event_location_to_string (b->location),
10387 event_location_to_string (b->location_range_end));
10388 print_recreate_thread (b, fp);
10391 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10393 static struct breakpoint_ops ranged_breakpoint_ops;
10395 /* Find the address where the end of the breakpoint range should be
10396 placed, given the SAL of the end of the range. This is so that if
10397 the user provides a line number, the end of the range is set to the
10398 last instruction of the given line. */
10401 find_breakpoint_range_end (struct symtab_and_line sal)
10405 /* If the user provided a PC value, use it. Otherwise,
10406 find the address of the end of the given location. */
10407 if (sal.explicit_pc)
10414 ret = find_line_pc_range (sal, &start, &end);
10416 error (_("Could not find location of the end of the range."));
10418 /* find_line_pc_range returns the start of the next line. */
10425 /* Implement the "break-range" CLI command. */
10428 break_range_command (char *arg, int from_tty)
10430 char *arg_start, *addr_string_start;
10431 struct linespec_result canonical_start, canonical_end;
10432 int bp_count, can_use_bp, length;
10434 struct breakpoint *b;
10435 struct symtab_and_line sal_start, sal_end;
10436 struct cleanup *cleanup_bkpt;
10437 struct linespec_sals *lsal_start, *lsal_end;
10438 struct event_location *start_location, *end_location;
10440 /* We don't support software ranged breakpoints. */
10441 if (target_ranged_break_num_registers () < 0)
10442 error (_("This target does not support hardware ranged breakpoints."));
10444 bp_count = hw_breakpoint_used_count ();
10445 bp_count += target_ranged_break_num_registers ();
10446 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10448 if (can_use_bp < 0)
10449 error (_("Hardware breakpoints used exceeds limit."));
10451 arg = skip_spaces (arg);
10452 if (arg == NULL || arg[0] == '\0')
10453 error(_("No address range specified."));
10455 init_linespec_result (&canonical_start);
10458 start_location = string_to_event_location (&arg, current_language);
10459 cleanup_bkpt = make_cleanup_delete_event_location (start_location);
10460 parse_breakpoint_sals (start_location, &canonical_start);
10461 make_cleanup_destroy_linespec_result (&canonical_start);
10464 error (_("Too few arguments."));
10465 else if (VEC_empty (linespec_sals, canonical_start.sals))
10466 error (_("Could not find location of the beginning of the range."));
10468 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10470 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10471 || lsal_start->sals.nelts != 1)
10472 error (_("Cannot create a ranged breakpoint with multiple locations."));
10474 sal_start = lsal_start->sals.sals[0];
10475 addr_string_start = savestring (arg_start, arg - arg_start);
10476 make_cleanup (xfree, addr_string_start);
10478 arg++; /* Skip the comma. */
10479 arg = skip_spaces (arg);
10481 /* Parse the end location. */
10483 init_linespec_result (&canonical_end);
10486 /* We call decode_line_full directly here instead of using
10487 parse_breakpoint_sals because we need to specify the start location's
10488 symtab and line as the default symtab and line for the end of the
10489 range. This makes it possible to have ranges like "foo.c:27, +14",
10490 where +14 means 14 lines from the start location. */
10491 end_location = string_to_event_location (&arg, current_language);
10492 make_cleanup_delete_event_location (end_location);
10493 decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL,
10494 sal_start.symtab, sal_start.line,
10495 &canonical_end, NULL, NULL);
10497 make_cleanup_destroy_linespec_result (&canonical_end);
10499 if (VEC_empty (linespec_sals, canonical_end.sals))
10500 error (_("Could not find location of the end of the range."));
10502 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10503 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10504 || lsal_end->sals.nelts != 1)
10505 error (_("Cannot create a ranged breakpoint with multiple locations."));
10507 sal_end = lsal_end->sals.sals[0];
10509 end = find_breakpoint_range_end (sal_end);
10510 if (sal_start.pc > end)
10511 error (_("Invalid address range, end precedes start."));
10513 length = end - sal_start.pc + 1;
10515 /* Length overflowed. */
10516 error (_("Address range too large."));
10517 else if (length == 1)
10519 /* This range is simple enough to be handled by
10520 the `hbreak' command. */
10521 hbreak_command (addr_string_start, 1);
10523 do_cleanups (cleanup_bkpt);
10528 /* Now set up the breakpoint. */
10529 b = set_raw_breakpoint (get_current_arch (), sal_start,
10530 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10531 set_breakpoint_count (breakpoint_count + 1);
10532 b->number = breakpoint_count;
10533 b->disposition = disp_donttouch;
10534 b->location = copy_event_location (start_location);
10535 b->location_range_end = copy_event_location (end_location);
10536 b->loc->length = length;
10538 do_cleanups (cleanup_bkpt);
10541 observer_notify_breakpoint_created (b);
10542 update_global_location_list (UGLL_MAY_INSERT);
10545 /* Return non-zero if EXP is verified as constant. Returned zero
10546 means EXP is variable. Also the constant detection may fail for
10547 some constant expressions and in such case still falsely return
10551 watchpoint_exp_is_const (const struct expression *exp)
10553 int i = exp->nelts;
10559 /* We are only interested in the descriptor of each element. */
10560 operator_length (exp, i, &oplenp, &argsp);
10563 switch (exp->elts[i].opcode)
10573 case BINOP_LOGICAL_AND:
10574 case BINOP_LOGICAL_OR:
10575 case BINOP_BITWISE_AND:
10576 case BINOP_BITWISE_IOR:
10577 case BINOP_BITWISE_XOR:
10579 case BINOP_NOTEQUAL:
10606 case OP_OBJC_NSSTRING:
10609 case UNOP_LOGICAL_NOT:
10610 case UNOP_COMPLEMENT:
10615 case UNOP_CAST_TYPE:
10616 case UNOP_REINTERPRET_CAST:
10617 case UNOP_DYNAMIC_CAST:
10618 /* Unary, binary and ternary operators: We have to check
10619 their operands. If they are constant, then so is the
10620 result of that operation. For instance, if A and B are
10621 determined to be constants, then so is "A + B".
10623 UNOP_IND is one exception to the rule above, because the
10624 value of *ADDR is not necessarily a constant, even when
10629 /* Check whether the associated symbol is a constant.
10631 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10632 possible that a buggy compiler could mark a variable as
10633 constant even when it is not, and TYPE_CONST would return
10634 true in this case, while SYMBOL_CLASS wouldn't.
10636 We also have to check for function symbols because they
10637 are always constant. */
10639 struct symbol *s = exp->elts[i + 2].symbol;
10641 if (SYMBOL_CLASS (s) != LOC_BLOCK
10642 && SYMBOL_CLASS (s) != LOC_CONST
10643 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10648 /* The default action is to return 0 because we are using
10649 the optimistic approach here: If we don't know something,
10650 then it is not a constant. */
10659 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10662 dtor_watchpoint (struct breakpoint *self)
10664 struct watchpoint *w = (struct watchpoint *) self;
10666 xfree (w->cond_exp);
10668 xfree (w->exp_string);
10669 xfree (w->exp_string_reparse);
10670 value_free (w->val);
10672 base_breakpoint_ops.dtor (self);
10675 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10678 re_set_watchpoint (struct breakpoint *b)
10680 struct watchpoint *w = (struct watchpoint *) b;
10682 /* Watchpoint can be either on expression using entirely global
10683 variables, or it can be on local variables.
10685 Watchpoints of the first kind are never auto-deleted, and even
10686 persist across program restarts. Since they can use variables
10687 from shared libraries, we need to reparse expression as libraries
10688 are loaded and unloaded.
10690 Watchpoints on local variables can also change meaning as result
10691 of solib event. For example, if a watchpoint uses both a local
10692 and a global variables in expression, it's a local watchpoint,
10693 but unloading of a shared library will make the expression
10694 invalid. This is not a very common use case, but we still
10695 re-evaluate expression, to avoid surprises to the user.
10697 Note that for local watchpoints, we re-evaluate it only if
10698 watchpoints frame id is still valid. If it's not, it means the
10699 watchpoint is out of scope and will be deleted soon. In fact,
10700 I'm not sure we'll ever be called in this case.
10702 If a local watchpoint's frame id is still valid, then
10703 w->exp_valid_block is likewise valid, and we can safely use it.
10705 Don't do anything about disabled watchpoints, since they will be
10706 reevaluated again when enabled. */
10707 update_watchpoint (w, 1 /* reparse */);
10710 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10713 insert_watchpoint (struct bp_location *bl)
10715 struct watchpoint *w = (struct watchpoint *) bl->owner;
10716 int length = w->exact ? 1 : bl->length;
10718 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10722 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10725 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10727 struct watchpoint *w = (struct watchpoint *) bl->owner;
10728 int length = w->exact ? 1 : bl->length;
10730 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10735 breakpoint_hit_watchpoint (const struct bp_location *bl,
10736 struct address_space *aspace, CORE_ADDR bp_addr,
10737 const struct target_waitstatus *ws)
10739 struct breakpoint *b = bl->owner;
10740 struct watchpoint *w = (struct watchpoint *) b;
10742 /* Continuable hardware watchpoints are treated as non-existent if the
10743 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10744 some data address). Otherwise gdb won't stop on a break instruction
10745 in the code (not from a breakpoint) when a hardware watchpoint has
10746 been defined. Also skip watchpoints which we know did not trigger
10747 (did not match the data address). */
10748 if (is_hardware_watchpoint (b)
10749 && w->watchpoint_triggered == watch_triggered_no)
10756 check_status_watchpoint (bpstat bs)
10758 gdb_assert (is_watchpoint (bs->breakpoint_at));
10760 bpstat_check_watchpoint (bs);
10763 /* Implement the "resources_needed" breakpoint_ops method for
10764 hardware watchpoints. */
10767 resources_needed_watchpoint (const struct bp_location *bl)
10769 struct watchpoint *w = (struct watchpoint *) bl->owner;
10770 int length = w->exact? 1 : bl->length;
10772 return target_region_ok_for_hw_watchpoint (bl->address, length);
10775 /* Implement the "works_in_software_mode" breakpoint_ops method for
10776 hardware watchpoints. */
10779 works_in_software_mode_watchpoint (const struct breakpoint *b)
10781 /* Read and access watchpoints only work with hardware support. */
10782 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10785 static enum print_stop_action
10786 print_it_watchpoint (bpstat bs)
10788 struct cleanup *old_chain;
10789 struct breakpoint *b;
10790 struct ui_file *stb;
10791 enum print_stop_action result;
10792 struct watchpoint *w;
10793 struct ui_out *uiout = current_uiout;
10795 gdb_assert (bs->bp_location_at != NULL);
10797 b = bs->breakpoint_at;
10798 w = (struct watchpoint *) b;
10800 stb = mem_fileopen ();
10801 old_chain = make_cleanup_ui_file_delete (stb);
10803 annotate_watchpoint (b->number);
10804 maybe_print_thread_hit_breakpoint (uiout);
10808 case bp_watchpoint:
10809 case bp_hardware_watchpoint:
10810 if (ui_out_is_mi_like_p (uiout))
10811 ui_out_field_string
10813 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10815 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10816 ui_out_text (uiout, "\nOld value = ");
10817 watchpoint_value_print (bs->old_val, stb);
10818 ui_out_field_stream (uiout, "old", stb);
10819 ui_out_text (uiout, "\nNew value = ");
10820 watchpoint_value_print (w->val, stb);
10821 ui_out_field_stream (uiout, "new", stb);
10822 ui_out_text (uiout, "\n");
10823 /* More than one watchpoint may have been triggered. */
10824 result = PRINT_UNKNOWN;
10827 case bp_read_watchpoint:
10828 if (ui_out_is_mi_like_p (uiout))
10829 ui_out_field_string
10831 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10833 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10834 ui_out_text (uiout, "\nValue = ");
10835 watchpoint_value_print (w->val, stb);
10836 ui_out_field_stream (uiout, "value", stb);
10837 ui_out_text (uiout, "\n");
10838 result = PRINT_UNKNOWN;
10841 case bp_access_watchpoint:
10842 if (bs->old_val != NULL)
10844 if (ui_out_is_mi_like_p (uiout))
10845 ui_out_field_string
10847 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10849 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10850 ui_out_text (uiout, "\nOld value = ");
10851 watchpoint_value_print (bs->old_val, stb);
10852 ui_out_field_stream (uiout, "old", stb);
10853 ui_out_text (uiout, "\nNew value = ");
10858 if (ui_out_is_mi_like_p (uiout))
10859 ui_out_field_string
10861 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10862 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10863 ui_out_text (uiout, "\nValue = ");
10865 watchpoint_value_print (w->val, stb);
10866 ui_out_field_stream (uiout, "new", stb);
10867 ui_out_text (uiout, "\n");
10868 result = PRINT_UNKNOWN;
10871 result = PRINT_UNKNOWN;
10874 do_cleanups (old_chain);
10878 /* Implement the "print_mention" breakpoint_ops method for hardware
10882 print_mention_watchpoint (struct breakpoint *b)
10884 struct cleanup *ui_out_chain;
10885 struct watchpoint *w = (struct watchpoint *) b;
10886 struct ui_out *uiout = current_uiout;
10890 case bp_watchpoint:
10891 ui_out_text (uiout, "Watchpoint ");
10892 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10894 case bp_hardware_watchpoint:
10895 ui_out_text (uiout, "Hardware watchpoint ");
10896 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10898 case bp_read_watchpoint:
10899 ui_out_text (uiout, "Hardware read watchpoint ");
10900 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10902 case bp_access_watchpoint:
10903 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10904 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10907 internal_error (__FILE__, __LINE__,
10908 _("Invalid hardware watchpoint type."));
10911 ui_out_field_int (uiout, "number", b->number);
10912 ui_out_text (uiout, ": ");
10913 ui_out_field_string (uiout, "exp", w->exp_string);
10914 do_cleanups (ui_out_chain);
10917 /* Implement the "print_recreate" breakpoint_ops method for
10921 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10923 struct watchpoint *w = (struct watchpoint *) b;
10927 case bp_watchpoint:
10928 case bp_hardware_watchpoint:
10929 fprintf_unfiltered (fp, "watch");
10931 case bp_read_watchpoint:
10932 fprintf_unfiltered (fp, "rwatch");
10934 case bp_access_watchpoint:
10935 fprintf_unfiltered (fp, "awatch");
10938 internal_error (__FILE__, __LINE__,
10939 _("Invalid watchpoint type."));
10942 fprintf_unfiltered (fp, " %s", w->exp_string);
10943 print_recreate_thread (b, fp);
10946 /* Implement the "explains_signal" breakpoint_ops method for
10950 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10952 /* A software watchpoint cannot cause a signal other than
10953 GDB_SIGNAL_TRAP. */
10954 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10960 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10962 static struct breakpoint_ops watchpoint_breakpoint_ops;
10964 /* Implement the "insert" breakpoint_ops method for
10965 masked hardware watchpoints. */
10968 insert_masked_watchpoint (struct bp_location *bl)
10970 struct watchpoint *w = (struct watchpoint *) bl->owner;
10972 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10973 bl->watchpoint_type);
10976 /* Implement the "remove" breakpoint_ops method for
10977 masked hardware watchpoints. */
10980 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10982 struct watchpoint *w = (struct watchpoint *) bl->owner;
10984 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10985 bl->watchpoint_type);
10988 /* Implement the "resources_needed" breakpoint_ops method for
10989 masked hardware watchpoints. */
10992 resources_needed_masked_watchpoint (const struct bp_location *bl)
10994 struct watchpoint *w = (struct watchpoint *) bl->owner;
10996 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10999 /* Implement the "works_in_software_mode" breakpoint_ops method for
11000 masked hardware watchpoints. */
11003 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
11008 /* Implement the "print_it" breakpoint_ops method for
11009 masked hardware watchpoints. */
11011 static enum print_stop_action
11012 print_it_masked_watchpoint (bpstat bs)
11014 struct breakpoint *b = bs->breakpoint_at;
11015 struct ui_out *uiout = current_uiout;
11017 /* Masked watchpoints have only one location. */
11018 gdb_assert (b->loc && b->loc->next == NULL);
11020 annotate_watchpoint (b->number);
11021 maybe_print_thread_hit_breakpoint (uiout);
11025 case bp_hardware_watchpoint:
11026 if (ui_out_is_mi_like_p (uiout))
11027 ui_out_field_string
11029 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11032 case bp_read_watchpoint:
11033 if (ui_out_is_mi_like_p (uiout))
11034 ui_out_field_string
11036 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11039 case bp_access_watchpoint:
11040 if (ui_out_is_mi_like_p (uiout))
11041 ui_out_field_string
11043 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11046 internal_error (__FILE__, __LINE__,
11047 _("Invalid hardware watchpoint type."));
11051 ui_out_text (uiout, _("\n\
11052 Check the underlying instruction at PC for the memory\n\
11053 address and value which triggered this watchpoint.\n"));
11054 ui_out_text (uiout, "\n");
11056 /* More than one watchpoint may have been triggered. */
11057 return PRINT_UNKNOWN;
11060 /* Implement the "print_one_detail" breakpoint_ops method for
11061 masked hardware watchpoints. */
11064 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11065 struct ui_out *uiout)
11067 struct watchpoint *w = (struct watchpoint *) b;
11069 /* Masked watchpoints have only one location. */
11070 gdb_assert (b->loc && b->loc->next == NULL);
11072 ui_out_text (uiout, "\tmask ");
11073 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11074 ui_out_text (uiout, "\n");
11077 /* Implement the "print_mention" breakpoint_ops method for
11078 masked hardware watchpoints. */
11081 print_mention_masked_watchpoint (struct breakpoint *b)
11083 struct watchpoint *w = (struct watchpoint *) b;
11084 struct ui_out *uiout = current_uiout;
11085 struct cleanup *ui_out_chain;
11089 case bp_hardware_watchpoint:
11090 ui_out_text (uiout, "Masked hardware watchpoint ");
11091 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11093 case bp_read_watchpoint:
11094 ui_out_text (uiout, "Masked hardware read watchpoint ");
11095 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11097 case bp_access_watchpoint:
11098 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11099 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11102 internal_error (__FILE__, __LINE__,
11103 _("Invalid hardware watchpoint type."));
11106 ui_out_field_int (uiout, "number", b->number);
11107 ui_out_text (uiout, ": ");
11108 ui_out_field_string (uiout, "exp", w->exp_string);
11109 do_cleanups (ui_out_chain);
11112 /* Implement the "print_recreate" breakpoint_ops method for
11113 masked hardware watchpoints. */
11116 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11118 struct watchpoint *w = (struct watchpoint *) b;
11123 case bp_hardware_watchpoint:
11124 fprintf_unfiltered (fp, "watch");
11126 case bp_read_watchpoint:
11127 fprintf_unfiltered (fp, "rwatch");
11129 case bp_access_watchpoint:
11130 fprintf_unfiltered (fp, "awatch");
11133 internal_error (__FILE__, __LINE__,
11134 _("Invalid hardware watchpoint type."));
11137 sprintf_vma (tmp, w->hw_wp_mask);
11138 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11139 print_recreate_thread (b, fp);
11142 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11144 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11146 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11149 is_masked_watchpoint (const struct breakpoint *b)
11151 return b->ops == &masked_watchpoint_breakpoint_ops;
11154 /* accessflag: hw_write: watch write,
11155 hw_read: watch read,
11156 hw_access: watch access (read or write) */
11158 watch_command_1 (const char *arg, int accessflag, int from_tty,
11159 int just_location, int internal)
11161 struct breakpoint *b, *scope_breakpoint = NULL;
11162 struct expression *exp;
11163 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11164 struct value *val, *mark, *result;
11165 int saved_bitpos = 0, saved_bitsize = 0;
11166 struct frame_info *frame;
11167 const char *exp_start = NULL;
11168 const char *exp_end = NULL;
11169 const char *tok, *end_tok;
11171 const char *cond_start = NULL;
11172 const char *cond_end = NULL;
11173 enum bptype bp_type;
11176 /* Flag to indicate whether we are going to use masks for
11177 the hardware watchpoint. */
11179 CORE_ADDR mask = 0;
11180 struct watchpoint *w;
11182 struct cleanup *back_to;
11184 /* Make sure that we actually have parameters to parse. */
11185 if (arg != NULL && arg[0] != '\0')
11187 const char *value_start;
11189 exp_end = arg + strlen (arg);
11191 /* Look for "parameter value" pairs at the end
11192 of the arguments string. */
11193 for (tok = exp_end - 1; tok > arg; tok--)
11195 /* Skip whitespace at the end of the argument list. */
11196 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11199 /* Find the beginning of the last token.
11200 This is the value of the parameter. */
11201 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11203 value_start = tok + 1;
11205 /* Skip whitespace. */
11206 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11211 /* Find the beginning of the second to last token.
11212 This is the parameter itself. */
11213 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11216 toklen = end_tok - tok + 1;
11218 if (toklen == 6 && startswith (tok, "thread"))
11220 struct thread_info *thr;
11221 /* At this point we've found a "thread" token, which means
11222 the user is trying to set a watchpoint that triggers
11223 only in a specific thread. */
11227 error(_("You can specify only one thread."));
11229 /* Extract the thread ID from the next token. */
11230 thr = parse_thread_id (value_start, &endp);
11232 /* Check if the user provided a valid thread ID. */
11233 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11234 invalid_thread_id_error (value_start);
11236 thread = thr->global_num;
11238 else if (toklen == 4 && startswith (tok, "mask"))
11240 /* We've found a "mask" token, which means the user wants to
11241 create a hardware watchpoint that is going to have the mask
11243 struct value *mask_value, *mark;
11246 error(_("You can specify only one mask."));
11248 use_mask = just_location = 1;
11250 mark = value_mark ();
11251 mask_value = parse_to_comma_and_eval (&value_start);
11252 mask = value_as_address (mask_value);
11253 value_free_to_mark (mark);
11256 /* We didn't recognize what we found. We should stop here. */
11259 /* Truncate the string and get rid of the "parameter value" pair before
11260 the arguments string is parsed by the parse_exp_1 function. */
11267 /* Parse the rest of the arguments. From here on out, everything
11268 is in terms of a newly allocated string instead of the original
11270 innermost_block = NULL;
11271 expression = savestring (arg, exp_end - arg);
11272 back_to = make_cleanup (xfree, expression);
11273 exp_start = arg = expression;
11274 exp = parse_exp_1 (&arg, 0, 0, 0);
11276 /* Remove trailing whitespace from the expression before saving it.
11277 This makes the eventual display of the expression string a bit
11279 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11282 /* Checking if the expression is not constant. */
11283 if (watchpoint_exp_is_const (exp))
11287 len = exp_end - exp_start;
11288 while (len > 0 && isspace (exp_start[len - 1]))
11290 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11293 exp_valid_block = innermost_block;
11294 mark = value_mark ();
11295 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11297 if (val != NULL && just_location)
11299 saved_bitpos = value_bitpos (val);
11300 saved_bitsize = value_bitsize (val);
11307 exp_valid_block = NULL;
11308 val = value_addr (result);
11309 release_value (val);
11310 value_free_to_mark (mark);
11314 ret = target_masked_watch_num_registers (value_as_address (val),
11317 error (_("This target does not support masked watchpoints."));
11318 else if (ret == -2)
11319 error (_("Invalid mask or memory region."));
11322 else if (val != NULL)
11323 release_value (val);
11325 tok = skip_spaces_const (arg);
11326 end_tok = skip_to_space_const (tok);
11328 toklen = end_tok - tok;
11329 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11331 struct expression *cond;
11333 innermost_block = NULL;
11334 tok = cond_start = end_tok + 1;
11335 cond = parse_exp_1 (&tok, 0, 0, 0);
11337 /* The watchpoint expression may not be local, but the condition
11338 may still be. E.g.: `watch global if local > 0'. */
11339 cond_exp_valid_block = innermost_block;
11345 error (_("Junk at end of command."));
11347 frame = block_innermost_frame (exp_valid_block);
11349 /* If the expression is "local", then set up a "watchpoint scope"
11350 breakpoint at the point where we've left the scope of the watchpoint
11351 expression. Create the scope breakpoint before the watchpoint, so
11352 that we will encounter it first in bpstat_stop_status. */
11353 if (exp_valid_block && frame)
11355 if (frame_id_p (frame_unwind_caller_id (frame)))
11358 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11359 frame_unwind_caller_pc (frame),
11360 bp_watchpoint_scope,
11361 &momentary_breakpoint_ops);
11363 scope_breakpoint->enable_state = bp_enabled;
11365 /* Automatically delete the breakpoint when it hits. */
11366 scope_breakpoint->disposition = disp_del;
11368 /* Only break in the proper frame (help with recursion). */
11369 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11371 /* Set the address at which we will stop. */
11372 scope_breakpoint->loc->gdbarch
11373 = frame_unwind_caller_arch (frame);
11374 scope_breakpoint->loc->requested_address
11375 = frame_unwind_caller_pc (frame);
11376 scope_breakpoint->loc->address
11377 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11378 scope_breakpoint->loc->requested_address,
11379 scope_breakpoint->type);
11383 /* Now set up the breakpoint. We create all watchpoints as hardware
11384 watchpoints here even if hardware watchpoints are turned off, a call
11385 to update_watchpoint later in this function will cause the type to
11386 drop back to bp_watchpoint (software watchpoint) if required. */
11388 if (accessflag == hw_read)
11389 bp_type = bp_read_watchpoint;
11390 else if (accessflag == hw_access)
11391 bp_type = bp_access_watchpoint;
11393 bp_type = bp_hardware_watchpoint;
11395 w = XCNEW (struct watchpoint);
11398 init_raw_breakpoint_without_location (b, NULL, bp_type,
11399 &masked_watchpoint_breakpoint_ops);
11401 init_raw_breakpoint_without_location (b, NULL, bp_type,
11402 &watchpoint_breakpoint_ops);
11403 b->thread = thread;
11404 b->disposition = disp_donttouch;
11405 b->pspace = current_program_space;
11407 w->exp_valid_block = exp_valid_block;
11408 w->cond_exp_valid_block = cond_exp_valid_block;
11411 struct type *t = value_type (val);
11412 CORE_ADDR addr = value_as_address (val);
11415 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11416 name = type_to_string (t);
11418 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11419 core_addr_to_string (addr));
11422 w->exp_string = xstrprintf ("-location %.*s",
11423 (int) (exp_end - exp_start), exp_start);
11425 /* The above expression is in C. */
11426 b->language = language_c;
11429 w->exp_string = savestring (exp_start, exp_end - exp_start);
11433 w->hw_wp_mask = mask;
11438 w->val_bitpos = saved_bitpos;
11439 w->val_bitsize = saved_bitsize;
11444 b->cond_string = savestring (cond_start, cond_end - cond_start);
11446 b->cond_string = 0;
11450 w->watchpoint_frame = get_frame_id (frame);
11451 w->watchpoint_thread = inferior_ptid;
11455 w->watchpoint_frame = null_frame_id;
11456 w->watchpoint_thread = null_ptid;
11459 if (scope_breakpoint != NULL)
11461 /* The scope breakpoint is related to the watchpoint. We will
11462 need to act on them together. */
11463 b->related_breakpoint = scope_breakpoint;
11464 scope_breakpoint->related_breakpoint = b;
11467 if (!just_location)
11468 value_free_to_mark (mark);
11472 /* Finally update the new watchpoint. This creates the locations
11473 that should be inserted. */
11474 update_watchpoint (w, 1);
11476 CATCH (e, RETURN_MASK_ALL)
11478 delete_breakpoint (b);
11479 throw_exception (e);
11483 install_breakpoint (internal, b, 1);
11484 do_cleanups (back_to);
11487 /* Return count of debug registers needed to watch the given expression.
11488 If the watchpoint cannot be handled in hardware return zero. */
11491 can_use_hardware_watchpoint (struct value *v)
11493 int found_memory_cnt = 0;
11494 struct value *head = v;
11496 /* Did the user specifically forbid us to use hardware watchpoints? */
11497 if (!can_use_hw_watchpoints)
11500 /* Make sure that the value of the expression depends only upon
11501 memory contents, and values computed from them within GDB. If we
11502 find any register references or function calls, we can't use a
11503 hardware watchpoint.
11505 The idea here is that evaluating an expression generates a series
11506 of values, one holding the value of every subexpression. (The
11507 expression a*b+c has five subexpressions: a, b, a*b, c, and
11508 a*b+c.) GDB's values hold almost enough information to establish
11509 the criteria given above --- they identify memory lvalues,
11510 register lvalues, computed values, etcetera. So we can evaluate
11511 the expression, and then scan the chain of values that leaves
11512 behind to decide whether we can detect any possible change to the
11513 expression's final value using only hardware watchpoints.
11515 However, I don't think that the values returned by inferior
11516 function calls are special in any way. So this function may not
11517 notice that an expression involving an inferior function call
11518 can't be watched with hardware watchpoints. FIXME. */
11519 for (; v; v = value_next (v))
11521 if (VALUE_LVAL (v) == lval_memory)
11523 if (v != head && value_lazy (v))
11524 /* A lazy memory lvalue in the chain is one that GDB never
11525 needed to fetch; we either just used its address (e.g.,
11526 `a' in `a.b') or we never needed it at all (e.g., `a'
11527 in `a,b'). This doesn't apply to HEAD; if that is
11528 lazy then it was not readable, but watch it anyway. */
11532 /* Ahh, memory we actually used! Check if we can cover
11533 it with hardware watchpoints. */
11534 struct type *vtype = check_typedef (value_type (v));
11536 /* We only watch structs and arrays if user asked for it
11537 explicitly, never if they just happen to appear in a
11538 middle of some value chain. */
11540 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11541 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11543 CORE_ADDR vaddr = value_address (v);
11547 len = (target_exact_watchpoints
11548 && is_scalar_type_recursive (vtype))?
11549 1 : TYPE_LENGTH (value_type (v));
11551 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11555 found_memory_cnt += num_regs;
11559 else if (VALUE_LVAL (v) != not_lval
11560 && deprecated_value_modifiable (v) == 0)
11561 return 0; /* These are values from the history (e.g., $1). */
11562 else if (VALUE_LVAL (v) == lval_register)
11563 return 0; /* Cannot watch a register with a HW watchpoint. */
11566 /* The expression itself looks suitable for using a hardware
11567 watchpoint, but give the target machine a chance to reject it. */
11568 return found_memory_cnt;
11572 watch_command_wrapper (char *arg, int from_tty, int internal)
11574 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11577 /* A helper function that looks for the "-location" argument and then
11578 calls watch_command_1. */
11581 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11583 int just_location = 0;
11586 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11587 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11589 arg = skip_spaces (arg);
11593 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11597 watch_command (char *arg, int from_tty)
11599 watch_maybe_just_location (arg, hw_write, from_tty);
11603 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11605 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11609 rwatch_command (char *arg, int from_tty)
11611 watch_maybe_just_location (arg, hw_read, from_tty);
11615 awatch_command_wrapper (char *arg, int from_tty, int internal)
11617 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11621 awatch_command (char *arg, int from_tty)
11623 watch_maybe_just_location (arg, hw_access, from_tty);
11627 /* Data for the FSM that manages the until(location)/advance commands
11628 in infcmd.c. Here because it uses the mechanisms of
11631 struct until_break_fsm
11633 /* The base class. */
11634 struct thread_fsm thread_fsm;
11636 /* The thread that as current when the command was executed. */
11639 /* The breakpoint set at the destination location. */
11640 struct breakpoint *location_breakpoint;
11642 /* Breakpoint set at the return address in the caller frame. May be
11644 struct breakpoint *caller_breakpoint;
11647 static void until_break_fsm_clean_up (struct thread_fsm *self,
11648 struct thread_info *thread);
11649 static int until_break_fsm_should_stop (struct thread_fsm *self,
11650 struct thread_info *thread);
11651 static enum async_reply_reason
11652 until_break_fsm_async_reply_reason (struct thread_fsm *self);
11654 /* until_break_fsm's vtable. */
11656 static struct thread_fsm_ops until_break_fsm_ops =
11659 until_break_fsm_clean_up,
11660 until_break_fsm_should_stop,
11661 NULL, /* return_value */
11662 until_break_fsm_async_reply_reason,
11665 /* Allocate a new until_break_command_fsm. */
11667 static struct until_break_fsm *
11668 new_until_break_fsm (struct interp *cmd_interp, int thread,
11669 struct breakpoint *location_breakpoint,
11670 struct breakpoint *caller_breakpoint)
11672 struct until_break_fsm *sm;
11674 sm = XCNEW (struct until_break_fsm);
11675 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
11677 sm->thread = thread;
11678 sm->location_breakpoint = location_breakpoint;
11679 sm->caller_breakpoint = caller_breakpoint;
11684 /* Implementation of the 'should_stop' FSM method for the
11685 until(location)/advance commands. */
11688 until_break_fsm_should_stop (struct thread_fsm *self,
11689 struct thread_info *tp)
11691 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11693 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11694 sm->location_breakpoint) != NULL
11695 || (sm->caller_breakpoint != NULL
11696 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11697 sm->caller_breakpoint) != NULL))
11698 thread_fsm_set_finished (self);
11703 /* Implementation of the 'clean_up' FSM method for the
11704 until(location)/advance commands. */
11707 until_break_fsm_clean_up (struct thread_fsm *self,
11708 struct thread_info *thread)
11710 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11712 /* Clean up our temporary breakpoints. */
11713 if (sm->location_breakpoint != NULL)
11715 delete_breakpoint (sm->location_breakpoint);
11716 sm->location_breakpoint = NULL;
11718 if (sm->caller_breakpoint != NULL)
11720 delete_breakpoint (sm->caller_breakpoint);
11721 sm->caller_breakpoint = NULL;
11723 delete_longjmp_breakpoint (sm->thread);
11726 /* Implementation of the 'async_reply_reason' FSM method for the
11727 until(location)/advance commands. */
11729 static enum async_reply_reason
11730 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11732 return EXEC_ASYNC_LOCATION_REACHED;
11736 until_break_command (char *arg, int from_tty, int anywhere)
11738 struct symtabs_and_lines sals;
11739 struct symtab_and_line sal;
11740 struct frame_info *frame;
11741 struct gdbarch *frame_gdbarch;
11742 struct frame_id stack_frame_id;
11743 struct frame_id caller_frame_id;
11744 struct breakpoint *location_breakpoint;
11745 struct breakpoint *caller_breakpoint = NULL;
11746 struct cleanup *old_chain, *cleanup;
11748 struct thread_info *tp;
11749 struct event_location *location;
11750 struct until_break_fsm *sm;
11752 clear_proceed_status (0);
11754 /* Set a breakpoint where the user wants it and at return from
11757 location = string_to_event_location (&arg, current_language);
11758 cleanup = make_cleanup_delete_event_location (location);
11760 if (last_displayed_sal_is_valid ())
11761 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL,
11762 get_last_displayed_symtab (),
11763 get_last_displayed_line ());
11765 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE,
11766 NULL, (struct symtab *) NULL, 0);
11768 if (sals.nelts != 1)
11769 error (_("Couldn't get information on specified line."));
11771 sal = sals.sals[0];
11772 xfree (sals.sals); /* malloc'd, so freed. */
11775 error (_("Junk at end of arguments."));
11777 resolve_sal_pc (&sal);
11779 tp = inferior_thread ();
11780 thread = tp->global_num;
11782 old_chain = make_cleanup (null_cleanup, NULL);
11784 /* Note linespec handling above invalidates the frame chain.
11785 Installing a breakpoint also invalidates the frame chain (as it
11786 may need to switch threads), so do any frame handling before
11789 frame = get_selected_frame (NULL);
11790 frame_gdbarch = get_frame_arch (frame);
11791 stack_frame_id = get_stack_frame_id (frame);
11792 caller_frame_id = frame_unwind_caller_id (frame);
11794 /* Keep within the current frame, or in frames called by the current
11797 if (frame_id_p (caller_frame_id))
11799 struct symtab_and_line sal2;
11800 struct gdbarch *caller_gdbarch;
11802 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11803 sal2.pc = frame_unwind_caller_pc (frame);
11804 caller_gdbarch = frame_unwind_caller_arch (frame);
11805 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11809 make_cleanup_delete_breakpoint (caller_breakpoint);
11811 set_longjmp_breakpoint (tp, caller_frame_id);
11812 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11815 /* set_momentary_breakpoint could invalidate FRAME. */
11819 /* If the user told us to continue until a specified location,
11820 we don't specify a frame at which we need to stop. */
11821 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11822 null_frame_id, bp_until);
11824 /* Otherwise, specify the selected frame, because we want to stop
11825 only at the very same frame. */
11826 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11827 stack_frame_id, bp_until);
11828 make_cleanup_delete_breakpoint (location_breakpoint);
11830 sm = new_until_break_fsm (command_interp (), tp->global_num,
11831 location_breakpoint, caller_breakpoint);
11832 tp->thread_fsm = &sm->thread_fsm;
11834 discard_cleanups (old_chain);
11836 proceed (-1, GDB_SIGNAL_DEFAULT);
11838 do_cleanups (cleanup);
11841 /* This function attempts to parse an optional "if <cond>" clause
11842 from the arg string. If one is not found, it returns NULL.
11844 Else, it returns a pointer to the condition string. (It does not
11845 attempt to evaluate the string against a particular block.) And,
11846 it updates arg to point to the first character following the parsed
11847 if clause in the arg string. */
11850 ep_parse_optional_if_clause (char **arg)
11854 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11857 /* Skip the "if" keyword. */
11860 /* Skip any extra leading whitespace, and record the start of the
11861 condition string. */
11862 *arg = skip_spaces (*arg);
11863 cond_string = *arg;
11865 /* Assume that the condition occupies the remainder of the arg
11867 (*arg) += strlen (cond_string);
11869 return cond_string;
11872 /* Commands to deal with catching events, such as signals, exceptions,
11873 process start/exit, etc. */
11877 catch_fork_temporary, catch_vfork_temporary,
11878 catch_fork_permanent, catch_vfork_permanent
11883 catch_fork_command_1 (char *arg, int from_tty,
11884 struct cmd_list_element *command)
11886 struct gdbarch *gdbarch = get_current_arch ();
11887 char *cond_string = NULL;
11888 catch_fork_kind fork_kind;
11891 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11892 tempflag = (fork_kind == catch_fork_temporary
11893 || fork_kind == catch_vfork_temporary);
11897 arg = skip_spaces (arg);
11899 /* The allowed syntax is:
11901 catch [v]fork if <cond>
11903 First, check if there's an if clause. */
11904 cond_string = ep_parse_optional_if_clause (&arg);
11906 if ((*arg != '\0') && !isspace (*arg))
11907 error (_("Junk at end of arguments."));
11909 /* If this target supports it, create a fork or vfork catchpoint
11910 and enable reporting of such events. */
11913 case catch_fork_temporary:
11914 case catch_fork_permanent:
11915 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11916 &catch_fork_breakpoint_ops);
11918 case catch_vfork_temporary:
11919 case catch_vfork_permanent:
11920 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11921 &catch_vfork_breakpoint_ops);
11924 error (_("unsupported or unknown fork kind; cannot catch it"));
11930 catch_exec_command_1 (char *arg, int from_tty,
11931 struct cmd_list_element *command)
11933 struct exec_catchpoint *c;
11934 struct gdbarch *gdbarch = get_current_arch ();
11936 char *cond_string = NULL;
11938 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11942 arg = skip_spaces (arg);
11944 /* The allowed syntax is:
11946 catch exec if <cond>
11948 First, check if there's an if clause. */
11949 cond_string = ep_parse_optional_if_clause (&arg);
11951 if ((*arg != '\0') && !isspace (*arg))
11952 error (_("Junk at end of arguments."));
11954 c = XNEW (struct exec_catchpoint);
11955 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11956 &catch_exec_breakpoint_ops);
11957 c->exec_pathname = NULL;
11959 install_breakpoint (0, &c->base, 1);
11963 init_ada_exception_breakpoint (struct breakpoint *b,
11964 struct gdbarch *gdbarch,
11965 struct symtab_and_line sal,
11967 const struct breakpoint_ops *ops,
11974 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11976 loc_gdbarch = gdbarch;
11978 describe_other_breakpoints (loc_gdbarch,
11979 sal.pspace, sal.pc, sal.section, -1);
11980 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11981 version for exception catchpoints, because two catchpoints
11982 used for different exception names will use the same address.
11983 In this case, a "breakpoint ... also set at..." warning is
11984 unproductive. Besides, the warning phrasing is also a bit
11985 inappropriate, we should use the word catchpoint, and tell
11986 the user what type of catchpoint it is. The above is good
11987 enough for now, though. */
11990 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11992 b->enable_state = enabled ? bp_enabled : bp_disabled;
11993 b->disposition = tempflag ? disp_del : disp_donttouch;
11994 b->location = string_to_event_location (&addr_string,
11995 language_def (language_ada));
11996 b->language = language_ada;
12000 catch_command (char *arg, int from_tty)
12002 error (_("Catch requires an event name."));
12007 tcatch_command (char *arg, int from_tty)
12009 error (_("Catch requires an event name."));
12012 /* A qsort comparison function that sorts breakpoints in order. */
12015 compare_breakpoints (const void *a, const void *b)
12017 const breakpoint_p *ba = (const breakpoint_p *) a;
12018 uintptr_t ua = (uintptr_t) *ba;
12019 const breakpoint_p *bb = (const breakpoint_p *) b;
12020 uintptr_t ub = (uintptr_t) *bb;
12022 if ((*ba)->number < (*bb)->number)
12024 else if ((*ba)->number > (*bb)->number)
12027 /* Now sort by address, in case we see, e..g, two breakpoints with
12031 return ua > ub ? 1 : 0;
12034 /* Delete breakpoints by address or line. */
12037 clear_command (char *arg, int from_tty)
12039 struct breakpoint *b, *prev;
12040 VEC(breakpoint_p) *found = 0;
12043 struct symtabs_and_lines sals;
12044 struct symtab_and_line sal;
12046 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12050 sals = decode_line_with_current_source (arg,
12051 (DECODE_LINE_FUNFIRSTLINE
12052 | DECODE_LINE_LIST_MODE));
12053 make_cleanup (xfree, sals.sals);
12058 sals.sals = XNEW (struct symtab_and_line);
12059 make_cleanup (xfree, sals.sals);
12060 init_sal (&sal); /* Initialize to zeroes. */
12062 /* Set sal's line, symtab, pc, and pspace to the values
12063 corresponding to the last call to print_frame_info. If the
12064 codepoint is not valid, this will set all the fields to 0. */
12065 get_last_displayed_sal (&sal);
12066 if (sal.symtab == 0)
12067 error (_("No source file specified."));
12069 sals.sals[0] = sal;
12075 /* We don't call resolve_sal_pc here. That's not as bad as it
12076 seems, because all existing breakpoints typically have both
12077 file/line and pc set. So, if clear is given file/line, we can
12078 match this to existing breakpoint without obtaining pc at all.
12080 We only support clearing given the address explicitly
12081 present in breakpoint table. Say, we've set breakpoint
12082 at file:line. There were several PC values for that file:line,
12083 due to optimization, all in one block.
12085 We've picked one PC value. If "clear" is issued with another
12086 PC corresponding to the same file:line, the breakpoint won't
12087 be cleared. We probably can still clear the breakpoint, but
12088 since the other PC value is never presented to user, user
12089 can only find it by guessing, and it does not seem important
12090 to support that. */
12092 /* For each line spec given, delete bps which correspond to it. Do
12093 it in two passes, solely to preserve the current behavior that
12094 from_tty is forced true if we delete more than one
12098 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12099 for (i = 0; i < sals.nelts; i++)
12101 const char *sal_fullname;
12103 /* If exact pc given, clear bpts at that pc.
12104 If line given (pc == 0), clear all bpts on specified line.
12105 If defaulting, clear all bpts on default line
12108 defaulting sal.pc != 0 tests to do
12113 1 0 <can't happen> */
12115 sal = sals.sals[i];
12116 sal_fullname = (sal.symtab == NULL
12117 ? NULL : symtab_to_fullname (sal.symtab));
12119 /* Find all matching breakpoints and add them to 'found'. */
12120 ALL_BREAKPOINTS (b)
12123 /* Are we going to delete b? */
12124 if (b->type != bp_none && !is_watchpoint (b))
12126 struct bp_location *loc = b->loc;
12127 for (; loc; loc = loc->next)
12129 /* If the user specified file:line, don't allow a PC
12130 match. This matches historical gdb behavior. */
12131 int pc_match = (!sal.explicit_line
12133 && (loc->pspace == sal.pspace)
12134 && (loc->address == sal.pc)
12135 && (!section_is_overlay (loc->section)
12136 || loc->section == sal.section));
12137 int line_match = 0;
12139 if ((default_match || sal.explicit_line)
12140 && loc->symtab != NULL
12141 && sal_fullname != NULL
12142 && sal.pspace == loc->pspace
12143 && loc->line_number == sal.line
12144 && filename_cmp (symtab_to_fullname (loc->symtab),
12145 sal_fullname) == 0)
12148 if (pc_match || line_match)
12157 VEC_safe_push(breakpoint_p, found, b);
12161 /* Now go thru the 'found' chain and delete them. */
12162 if (VEC_empty(breakpoint_p, found))
12165 error (_("No breakpoint at %s."), arg);
12167 error (_("No breakpoint at this line."));
12170 /* Remove duplicates from the vec. */
12171 qsort (VEC_address (breakpoint_p, found),
12172 VEC_length (breakpoint_p, found),
12173 sizeof (breakpoint_p),
12174 compare_breakpoints);
12175 prev = VEC_index (breakpoint_p, found, 0);
12176 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12180 VEC_ordered_remove (breakpoint_p, found, ix);
12185 if (VEC_length(breakpoint_p, found) > 1)
12186 from_tty = 1; /* Always report if deleted more than one. */
12189 if (VEC_length(breakpoint_p, found) == 1)
12190 printf_unfiltered (_("Deleted breakpoint "));
12192 printf_unfiltered (_("Deleted breakpoints "));
12195 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12198 printf_unfiltered ("%d ", b->number);
12199 delete_breakpoint (b);
12202 putchar_unfiltered ('\n');
12204 do_cleanups (cleanups);
12207 /* Delete breakpoint in BS if they are `delete' breakpoints and
12208 all breakpoints that are marked for deletion, whether hit or not.
12209 This is called after any breakpoint is hit, or after errors. */
12212 breakpoint_auto_delete (bpstat bs)
12214 struct breakpoint *b, *b_tmp;
12216 for (; bs; bs = bs->next)
12217 if (bs->breakpoint_at
12218 && bs->breakpoint_at->disposition == disp_del
12220 delete_breakpoint (bs->breakpoint_at);
12222 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12224 if (b->disposition == disp_del_at_next_stop)
12225 delete_breakpoint (b);
12229 /* A comparison function for bp_location AP and BP being interfaced to
12230 qsort. Sort elements primarily by their ADDRESS (no matter what
12231 does breakpoint_address_is_meaningful say for its OWNER),
12232 secondarily by ordering first permanent elements and
12233 terciarily just ensuring the array is sorted stable way despite
12234 qsort being an unstable algorithm. */
12237 bp_location_compare (const void *ap, const void *bp)
12239 const struct bp_location *a = *(const struct bp_location **) ap;
12240 const struct bp_location *b = *(const struct bp_location **) bp;
12242 if (a->address != b->address)
12243 return (a->address > b->address) - (a->address < b->address);
12245 /* Sort locations at the same address by their pspace number, keeping
12246 locations of the same inferior (in a multi-inferior environment)
12249 if (a->pspace->num != b->pspace->num)
12250 return ((a->pspace->num > b->pspace->num)
12251 - (a->pspace->num < b->pspace->num));
12253 /* Sort permanent breakpoints first. */
12254 if (a->permanent != b->permanent)
12255 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
12257 /* Make the internal GDB representation stable across GDB runs
12258 where A and B memory inside GDB can differ. Breakpoint locations of
12259 the same type at the same address can be sorted in arbitrary order. */
12261 if (a->owner->number != b->owner->number)
12262 return ((a->owner->number > b->owner->number)
12263 - (a->owner->number < b->owner->number));
12265 return (a > b) - (a < b);
12268 /* Set bp_location_placed_address_before_address_max and
12269 bp_location_shadow_len_after_address_max according to the current
12270 content of the bp_location array. */
12273 bp_location_target_extensions_update (void)
12275 struct bp_location *bl, **blp_tmp;
12277 bp_location_placed_address_before_address_max = 0;
12278 bp_location_shadow_len_after_address_max = 0;
12280 ALL_BP_LOCATIONS (bl, blp_tmp)
12282 CORE_ADDR start, end, addr;
12284 if (!bp_location_has_shadow (bl))
12287 start = bl->target_info.placed_address;
12288 end = start + bl->target_info.shadow_len;
12290 gdb_assert (bl->address >= start);
12291 addr = bl->address - start;
12292 if (addr > bp_location_placed_address_before_address_max)
12293 bp_location_placed_address_before_address_max = addr;
12295 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12297 gdb_assert (bl->address < end);
12298 addr = end - bl->address;
12299 if (addr > bp_location_shadow_len_after_address_max)
12300 bp_location_shadow_len_after_address_max = addr;
12304 /* Download tracepoint locations if they haven't been. */
12307 download_tracepoint_locations (void)
12309 struct breakpoint *b;
12310 struct cleanup *old_chain;
12311 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
12313 old_chain = save_current_space_and_thread ();
12315 ALL_TRACEPOINTS (b)
12317 struct bp_location *bl;
12318 struct tracepoint *t;
12319 int bp_location_downloaded = 0;
12321 if ((b->type == bp_fast_tracepoint
12322 ? !may_insert_fast_tracepoints
12323 : !may_insert_tracepoints))
12326 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
12328 if (target_can_download_tracepoint ())
12329 can_download_tracepoint = TRIBOOL_TRUE;
12331 can_download_tracepoint = TRIBOOL_FALSE;
12334 if (can_download_tracepoint == TRIBOOL_FALSE)
12337 for (bl = b->loc; bl; bl = bl->next)
12339 /* In tracepoint, locations are _never_ duplicated, so
12340 should_be_inserted is equivalent to
12341 unduplicated_should_be_inserted. */
12342 if (!should_be_inserted (bl) || bl->inserted)
12345 switch_to_program_space_and_thread (bl->pspace);
12347 target_download_tracepoint (bl);
12350 bp_location_downloaded = 1;
12352 t = (struct tracepoint *) b;
12353 t->number_on_target = b->number;
12354 if (bp_location_downloaded)
12355 observer_notify_breakpoint_modified (b);
12358 do_cleanups (old_chain);
12361 /* Swap the insertion/duplication state between two locations. */
12364 swap_insertion (struct bp_location *left, struct bp_location *right)
12366 const int left_inserted = left->inserted;
12367 const int left_duplicate = left->duplicate;
12368 const int left_needs_update = left->needs_update;
12369 const struct bp_target_info left_target_info = left->target_info;
12371 /* Locations of tracepoints can never be duplicated. */
12372 if (is_tracepoint (left->owner))
12373 gdb_assert (!left->duplicate);
12374 if (is_tracepoint (right->owner))
12375 gdb_assert (!right->duplicate);
12377 left->inserted = right->inserted;
12378 left->duplicate = right->duplicate;
12379 left->needs_update = right->needs_update;
12380 left->target_info = right->target_info;
12381 right->inserted = left_inserted;
12382 right->duplicate = left_duplicate;
12383 right->needs_update = left_needs_update;
12384 right->target_info = left_target_info;
12387 /* Force the re-insertion of the locations at ADDRESS. This is called
12388 once a new/deleted/modified duplicate location is found and we are evaluating
12389 conditions on the target's side. Such conditions need to be updated on
12393 force_breakpoint_reinsertion (struct bp_location *bl)
12395 struct bp_location **locp = NULL, **loc2p;
12396 struct bp_location *loc;
12397 CORE_ADDR address = 0;
12400 address = bl->address;
12401 pspace_num = bl->pspace->num;
12403 /* This is only meaningful if the target is
12404 evaluating conditions and if the user has
12405 opted for condition evaluation on the target's
12407 if (gdb_evaluates_breakpoint_condition_p ()
12408 || !target_supports_evaluation_of_breakpoint_conditions ())
12411 /* Flag all breakpoint locations with this address and
12412 the same program space as the location
12413 as "its condition has changed". We need to
12414 update the conditions on the target's side. */
12415 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12419 if (!is_breakpoint (loc->owner)
12420 || pspace_num != loc->pspace->num)
12423 /* Flag the location appropriately. We use a different state to
12424 let everyone know that we already updated the set of locations
12425 with addr bl->address and program space bl->pspace. This is so
12426 we don't have to keep calling these functions just to mark locations
12427 that have already been marked. */
12428 loc->condition_changed = condition_updated;
12430 /* Free the agent expression bytecode as well. We will compute
12432 if (loc->cond_bytecode)
12434 free_agent_expr (loc->cond_bytecode);
12435 loc->cond_bytecode = NULL;
12439 /* Called whether new breakpoints are created, or existing breakpoints
12440 deleted, to update the global location list and recompute which
12441 locations are duplicate of which.
12443 The INSERT_MODE flag determines whether locations may not, may, or
12444 shall be inserted now. See 'enum ugll_insert_mode' for more
12448 update_global_location_list (enum ugll_insert_mode insert_mode)
12450 struct breakpoint *b;
12451 struct bp_location **locp, *loc;
12452 struct cleanup *cleanups;
12453 /* Last breakpoint location address that was marked for update. */
12454 CORE_ADDR last_addr = 0;
12455 /* Last breakpoint location program space that was marked for update. */
12456 int last_pspace_num = -1;
12458 /* Used in the duplicates detection below. When iterating over all
12459 bp_locations, points to the first bp_location of a given address.
12460 Breakpoints and watchpoints of different types are never
12461 duplicates of each other. Keep one pointer for each type of
12462 breakpoint/watchpoint, so we only need to loop over all locations
12464 struct bp_location *bp_loc_first; /* breakpoint */
12465 struct bp_location *wp_loc_first; /* hardware watchpoint */
12466 struct bp_location *awp_loc_first; /* access watchpoint */
12467 struct bp_location *rwp_loc_first; /* read watchpoint */
12469 /* Saved former bp_location array which we compare against the newly
12470 built bp_location from the current state of ALL_BREAKPOINTS. */
12471 struct bp_location **old_location, **old_locp;
12472 unsigned old_location_count;
12474 old_location = bp_location;
12475 old_location_count = bp_location_count;
12476 bp_location = NULL;
12477 bp_location_count = 0;
12478 cleanups = make_cleanup (xfree, old_location);
12480 ALL_BREAKPOINTS (b)
12481 for (loc = b->loc; loc; loc = loc->next)
12482 bp_location_count++;
12484 bp_location = XNEWVEC (struct bp_location *, bp_location_count);
12485 locp = bp_location;
12486 ALL_BREAKPOINTS (b)
12487 for (loc = b->loc; loc; loc = loc->next)
12489 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12490 bp_location_compare);
12492 bp_location_target_extensions_update ();
12494 /* Identify bp_location instances that are no longer present in the
12495 new list, and therefore should be freed. Note that it's not
12496 necessary that those locations should be removed from inferior --
12497 if there's another location at the same address (previously
12498 marked as duplicate), we don't need to remove/insert the
12501 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12502 and former bp_location array state respectively. */
12504 locp = bp_location;
12505 for (old_locp = old_location; old_locp < old_location + old_location_count;
12508 struct bp_location *old_loc = *old_locp;
12509 struct bp_location **loc2p;
12511 /* Tells if 'old_loc' is found among the new locations. If
12512 not, we have to free it. */
12513 int found_object = 0;
12514 /* Tells if the location should remain inserted in the target. */
12515 int keep_in_target = 0;
12518 /* Skip LOCP entries which will definitely never be needed.
12519 Stop either at or being the one matching OLD_LOC. */
12520 while (locp < bp_location + bp_location_count
12521 && (*locp)->address < old_loc->address)
12525 (loc2p < bp_location + bp_location_count
12526 && (*loc2p)->address == old_loc->address);
12529 /* Check if this is a new/duplicated location or a duplicated
12530 location that had its condition modified. If so, we want to send
12531 its condition to the target if evaluation of conditions is taking
12533 if ((*loc2p)->condition_changed == condition_modified
12534 && (last_addr != old_loc->address
12535 || last_pspace_num != old_loc->pspace->num))
12537 force_breakpoint_reinsertion (*loc2p);
12538 last_pspace_num = old_loc->pspace->num;
12541 if (*loc2p == old_loc)
12545 /* We have already handled this address, update it so that we don't
12546 have to go through updates again. */
12547 last_addr = old_loc->address;
12549 /* Target-side condition evaluation: Handle deleted locations. */
12551 force_breakpoint_reinsertion (old_loc);
12553 /* If this location is no longer present, and inserted, look if
12554 there's maybe a new location at the same address. If so,
12555 mark that one inserted, and don't remove this one. This is
12556 needed so that we don't have a time window where a breakpoint
12557 at certain location is not inserted. */
12559 if (old_loc->inserted)
12561 /* If the location is inserted now, we might have to remove
12564 if (found_object && should_be_inserted (old_loc))
12566 /* The location is still present in the location list,
12567 and still should be inserted. Don't do anything. */
12568 keep_in_target = 1;
12572 /* This location still exists, but it won't be kept in the
12573 target since it may have been disabled. We proceed to
12574 remove its target-side condition. */
12576 /* The location is either no longer present, or got
12577 disabled. See if there's another location at the
12578 same address, in which case we don't need to remove
12579 this one from the target. */
12581 /* OLD_LOC comes from existing struct breakpoint. */
12582 if (breakpoint_address_is_meaningful (old_loc->owner))
12585 (loc2p < bp_location + bp_location_count
12586 && (*loc2p)->address == old_loc->address);
12589 struct bp_location *loc2 = *loc2p;
12591 if (breakpoint_locations_match (loc2, old_loc))
12593 /* Read watchpoint locations are switched to
12594 access watchpoints, if the former are not
12595 supported, but the latter are. */
12596 if (is_hardware_watchpoint (old_loc->owner))
12598 gdb_assert (is_hardware_watchpoint (loc2->owner));
12599 loc2->watchpoint_type = old_loc->watchpoint_type;
12602 /* loc2 is a duplicated location. We need to check
12603 if it should be inserted in case it will be
12605 if (loc2 != old_loc
12606 && unduplicated_should_be_inserted (loc2))
12608 swap_insertion (old_loc, loc2);
12609 keep_in_target = 1;
12617 if (!keep_in_target)
12619 if (remove_breakpoint (old_loc))
12621 /* This is just about all we can do. We could keep
12622 this location on the global list, and try to
12623 remove it next time, but there's no particular
12624 reason why we will succeed next time.
12626 Note that at this point, old_loc->owner is still
12627 valid, as delete_breakpoint frees the breakpoint
12628 only after calling us. */
12629 printf_filtered (_("warning: Error removing "
12630 "breakpoint %d\n"),
12631 old_loc->owner->number);
12639 if (removed && target_is_non_stop_p ()
12640 && need_moribund_for_location_type (old_loc))
12642 /* This location was removed from the target. In
12643 non-stop mode, a race condition is possible where
12644 we've removed a breakpoint, but stop events for that
12645 breakpoint are already queued and will arrive later.
12646 We apply an heuristic to be able to distinguish such
12647 SIGTRAPs from other random SIGTRAPs: we keep this
12648 breakpoint location for a bit, and will retire it
12649 after we see some number of events. The theory here
12650 is that reporting of events should, "on the average",
12651 be fair, so after a while we'll see events from all
12652 threads that have anything of interest, and no longer
12653 need to keep this breakpoint location around. We
12654 don't hold locations forever so to reduce chances of
12655 mistaking a non-breakpoint SIGTRAP for a breakpoint
12658 The heuristic failing can be disastrous on
12659 decr_pc_after_break targets.
12661 On decr_pc_after_break targets, like e.g., x86-linux,
12662 if we fail to recognize a late breakpoint SIGTRAP,
12663 because events_till_retirement has reached 0 too
12664 soon, we'll fail to do the PC adjustment, and report
12665 a random SIGTRAP to the user. When the user resumes
12666 the inferior, it will most likely immediately crash
12667 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12668 corrupted, because of being resumed e.g., in the
12669 middle of a multi-byte instruction, or skipped a
12670 one-byte instruction. This was actually seen happen
12671 on native x86-linux, and should be less rare on
12672 targets that do not support new thread events, like
12673 remote, due to the heuristic depending on
12676 Mistaking a random SIGTRAP for a breakpoint trap
12677 causes similar symptoms (PC adjustment applied when
12678 it shouldn't), but then again, playing with SIGTRAPs
12679 behind the debugger's back is asking for trouble.
12681 Since hardware watchpoint traps are always
12682 distinguishable from other traps, so we don't need to
12683 apply keep hardware watchpoint moribund locations
12684 around. We simply always ignore hardware watchpoint
12685 traps we can no longer explain. */
12687 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12688 old_loc->owner = NULL;
12690 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12694 old_loc->owner = NULL;
12695 decref_bp_location (&old_loc);
12700 /* Rescan breakpoints at the same address and section, marking the
12701 first one as "first" and any others as "duplicates". This is so
12702 that the bpt instruction is only inserted once. If we have a
12703 permanent breakpoint at the same place as BPT, make that one the
12704 official one, and the rest as duplicates. Permanent breakpoints
12705 are sorted first for the same address.
12707 Do the same for hardware watchpoints, but also considering the
12708 watchpoint's type (regular/access/read) and length. */
12710 bp_loc_first = NULL;
12711 wp_loc_first = NULL;
12712 awp_loc_first = NULL;
12713 rwp_loc_first = NULL;
12714 ALL_BP_LOCATIONS (loc, locp)
12716 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12718 struct bp_location **loc_first_p;
12721 if (!unduplicated_should_be_inserted (loc)
12722 || !breakpoint_address_is_meaningful (b)
12723 /* Don't detect duplicate for tracepoint locations because they are
12724 never duplicated. See the comments in field `duplicate' of
12725 `struct bp_location'. */
12726 || is_tracepoint (b))
12728 /* Clear the condition modification flag. */
12729 loc->condition_changed = condition_unchanged;
12733 if (b->type == bp_hardware_watchpoint)
12734 loc_first_p = &wp_loc_first;
12735 else if (b->type == bp_read_watchpoint)
12736 loc_first_p = &rwp_loc_first;
12737 else if (b->type == bp_access_watchpoint)
12738 loc_first_p = &awp_loc_first;
12740 loc_first_p = &bp_loc_first;
12742 if (*loc_first_p == NULL
12743 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12744 || !breakpoint_locations_match (loc, *loc_first_p))
12746 *loc_first_p = loc;
12747 loc->duplicate = 0;
12749 if (is_breakpoint (loc->owner) && loc->condition_changed)
12751 loc->needs_update = 1;
12752 /* Clear the condition modification flag. */
12753 loc->condition_changed = condition_unchanged;
12759 /* This and the above ensure the invariant that the first location
12760 is not duplicated, and is the inserted one.
12761 All following are marked as duplicated, and are not inserted. */
12763 swap_insertion (loc, *loc_first_p);
12764 loc->duplicate = 1;
12766 /* Clear the condition modification flag. */
12767 loc->condition_changed = condition_unchanged;
12770 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12772 if (insert_mode != UGLL_DONT_INSERT)
12773 insert_breakpoint_locations ();
12776 /* Even though the caller told us to not insert new
12777 locations, we may still need to update conditions on the
12778 target's side of breakpoints that were already inserted
12779 if the target is evaluating breakpoint conditions. We
12780 only update conditions for locations that are marked
12782 update_inserted_breakpoint_locations ();
12786 if (insert_mode != UGLL_DONT_INSERT)
12787 download_tracepoint_locations ();
12789 do_cleanups (cleanups);
12793 breakpoint_retire_moribund (void)
12795 struct bp_location *loc;
12798 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12799 if (--(loc->events_till_retirement) == 0)
12801 decref_bp_location (&loc);
12802 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12808 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12813 update_global_location_list (insert_mode);
12815 CATCH (e, RETURN_MASK_ERROR)
12821 /* Clear BKP from a BPS. */
12824 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12828 for (bs = bps; bs; bs = bs->next)
12829 if (bs->breakpoint_at == bpt)
12831 bs->breakpoint_at = NULL;
12832 bs->old_val = NULL;
12833 /* bs->commands will be freed later. */
12837 /* Callback for iterate_over_threads. */
12839 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12841 struct breakpoint *bpt = (struct breakpoint *) data;
12843 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12847 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12851 say_where (struct breakpoint *b)
12853 struct value_print_options opts;
12855 get_user_print_options (&opts);
12857 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12859 if (b->loc == NULL)
12861 /* For pending locations, the output differs slightly based
12862 on b->extra_string. If this is non-NULL, it contains either
12863 a condition or dprintf arguments. */
12864 if (b->extra_string == NULL)
12866 printf_filtered (_(" (%s) pending."),
12867 event_location_to_string (b->location));
12869 else if (b->type == bp_dprintf)
12871 printf_filtered (_(" (%s,%s) pending."),
12872 event_location_to_string (b->location),
12877 printf_filtered (_(" (%s %s) pending."),
12878 event_location_to_string (b->location),
12884 if (opts.addressprint || b->loc->symtab == NULL)
12886 printf_filtered (" at ");
12887 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12890 if (b->loc->symtab != NULL)
12892 /* If there is a single location, we can print the location
12894 if (b->loc->next == NULL)
12895 printf_filtered (": file %s, line %d.",
12896 symtab_to_filename_for_display (b->loc->symtab),
12897 b->loc->line_number);
12899 /* This is not ideal, but each location may have a
12900 different file name, and this at least reflects the
12901 real situation somewhat. */
12902 printf_filtered (": %s.",
12903 event_location_to_string (b->location));
12908 struct bp_location *loc = b->loc;
12910 for (; loc; loc = loc->next)
12912 printf_filtered (" (%d locations)", n);
12917 /* Default bp_location_ops methods. */
12920 bp_location_dtor (struct bp_location *self)
12922 xfree (self->cond);
12923 if (self->cond_bytecode)
12924 free_agent_expr (self->cond_bytecode);
12925 xfree (self->function_name);
12927 VEC_free (agent_expr_p, self->target_info.conditions);
12928 VEC_free (agent_expr_p, self->target_info.tcommands);
12931 static const struct bp_location_ops bp_location_ops =
12936 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12940 base_breakpoint_dtor (struct breakpoint *self)
12942 decref_counted_command_line (&self->commands);
12943 xfree (self->cond_string);
12944 xfree (self->extra_string);
12945 xfree (self->filter);
12946 delete_event_location (self->location);
12947 delete_event_location (self->location_range_end);
12950 static struct bp_location *
12951 base_breakpoint_allocate_location (struct breakpoint *self)
12953 struct bp_location *loc;
12955 loc = XNEW (struct bp_location);
12956 init_bp_location (loc, &bp_location_ops, self);
12961 base_breakpoint_re_set (struct breakpoint *b)
12963 /* Nothing to re-set. */
12966 #define internal_error_pure_virtual_called() \
12967 gdb_assert_not_reached ("pure virtual function called")
12970 base_breakpoint_insert_location (struct bp_location *bl)
12972 internal_error_pure_virtual_called ();
12976 base_breakpoint_remove_location (struct bp_location *bl,
12977 enum remove_bp_reason reason)
12979 internal_error_pure_virtual_called ();
12983 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12984 struct address_space *aspace,
12986 const struct target_waitstatus *ws)
12988 internal_error_pure_virtual_called ();
12992 base_breakpoint_check_status (bpstat bs)
12997 /* A "works_in_software_mode" breakpoint_ops method that just internal
13001 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
13003 internal_error_pure_virtual_called ();
13006 /* A "resources_needed" breakpoint_ops method that just internal
13010 base_breakpoint_resources_needed (const struct bp_location *bl)
13012 internal_error_pure_virtual_called ();
13015 static enum print_stop_action
13016 base_breakpoint_print_it (bpstat bs)
13018 internal_error_pure_virtual_called ();
13022 base_breakpoint_print_one_detail (const struct breakpoint *self,
13023 struct ui_out *uiout)
13029 base_breakpoint_print_mention (struct breakpoint *b)
13031 internal_error_pure_virtual_called ();
13035 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
13037 internal_error_pure_virtual_called ();
13041 base_breakpoint_create_sals_from_location
13042 (const struct event_location *location,
13043 struct linespec_result *canonical,
13044 enum bptype type_wanted)
13046 internal_error_pure_virtual_called ();
13050 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13051 struct linespec_result *c,
13053 char *extra_string,
13054 enum bptype type_wanted,
13055 enum bpdisp disposition,
13057 int task, int ignore_count,
13058 const struct breakpoint_ops *o,
13059 int from_tty, int enabled,
13060 int internal, unsigned flags)
13062 internal_error_pure_virtual_called ();
13066 base_breakpoint_decode_location (struct breakpoint *b,
13067 const struct event_location *location,
13068 struct program_space *search_pspace,
13069 struct symtabs_and_lines *sals)
13071 internal_error_pure_virtual_called ();
13074 /* The default 'explains_signal' method. */
13077 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13082 /* The default "after_condition_true" method. */
13085 base_breakpoint_after_condition_true (struct bpstats *bs)
13087 /* Nothing to do. */
13090 struct breakpoint_ops base_breakpoint_ops =
13092 base_breakpoint_dtor,
13093 base_breakpoint_allocate_location,
13094 base_breakpoint_re_set,
13095 base_breakpoint_insert_location,
13096 base_breakpoint_remove_location,
13097 base_breakpoint_breakpoint_hit,
13098 base_breakpoint_check_status,
13099 base_breakpoint_resources_needed,
13100 base_breakpoint_works_in_software_mode,
13101 base_breakpoint_print_it,
13103 base_breakpoint_print_one_detail,
13104 base_breakpoint_print_mention,
13105 base_breakpoint_print_recreate,
13106 base_breakpoint_create_sals_from_location,
13107 base_breakpoint_create_breakpoints_sal,
13108 base_breakpoint_decode_location,
13109 base_breakpoint_explains_signal,
13110 base_breakpoint_after_condition_true,
13113 /* Default breakpoint_ops methods. */
13116 bkpt_re_set (struct breakpoint *b)
13118 /* FIXME: is this still reachable? */
13119 if (breakpoint_event_location_empty_p (b))
13121 /* Anything without a location can't be re-set. */
13122 delete_breakpoint (b);
13126 breakpoint_re_set_default (b);
13130 bkpt_insert_location (struct bp_location *bl)
13132 CORE_ADDR addr = bl->target_info.reqstd_address;
13134 bl->target_info.kind = breakpoint_kind (bl, &addr);
13135 bl->target_info.placed_address = addr;
13137 if (bl->loc_type == bp_loc_hardware_breakpoint)
13138 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
13140 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
13144 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
13146 if (bl->loc_type == bp_loc_hardware_breakpoint)
13147 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13149 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
13153 bkpt_breakpoint_hit (const struct bp_location *bl,
13154 struct address_space *aspace, CORE_ADDR bp_addr,
13155 const struct target_waitstatus *ws)
13157 if (ws->kind != TARGET_WAITKIND_STOPPED
13158 || ws->value.sig != GDB_SIGNAL_TRAP)
13161 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13165 if (overlay_debugging /* unmapped overlay section */
13166 && section_is_overlay (bl->section)
13167 && !section_is_mapped (bl->section))
13174 dprintf_breakpoint_hit (const struct bp_location *bl,
13175 struct address_space *aspace, CORE_ADDR bp_addr,
13176 const struct target_waitstatus *ws)
13178 if (dprintf_style == dprintf_style_agent
13179 && target_can_run_breakpoint_commands ())
13181 /* An agent-style dprintf never causes a stop. If we see a trap
13182 for this address it must be for a breakpoint that happens to
13183 be set at the same address. */
13187 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13191 bkpt_resources_needed (const struct bp_location *bl)
13193 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13198 static enum print_stop_action
13199 bkpt_print_it (bpstat bs)
13201 struct breakpoint *b;
13202 const struct bp_location *bl;
13204 struct ui_out *uiout = current_uiout;
13206 gdb_assert (bs->bp_location_at != NULL);
13208 bl = bs->bp_location_at;
13209 b = bs->breakpoint_at;
13211 bp_temp = b->disposition == disp_del;
13212 if (bl->address != bl->requested_address)
13213 breakpoint_adjustment_warning (bl->requested_address,
13216 annotate_breakpoint (b->number);
13217 maybe_print_thread_hit_breakpoint (uiout);
13220 ui_out_text (uiout, "Temporary breakpoint ");
13222 ui_out_text (uiout, "Breakpoint ");
13223 if (ui_out_is_mi_like_p (uiout))
13225 ui_out_field_string (uiout, "reason",
13226 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13227 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13229 ui_out_field_int (uiout, "bkptno", b->number);
13230 ui_out_text (uiout, ", ");
13232 return PRINT_SRC_AND_LOC;
13236 bkpt_print_mention (struct breakpoint *b)
13238 if (ui_out_is_mi_like_p (current_uiout))
13243 case bp_breakpoint:
13244 case bp_gnu_ifunc_resolver:
13245 if (b->disposition == disp_del)
13246 printf_filtered (_("Temporary breakpoint"));
13248 printf_filtered (_("Breakpoint"));
13249 printf_filtered (_(" %d"), b->number);
13250 if (b->type == bp_gnu_ifunc_resolver)
13251 printf_filtered (_(" at gnu-indirect-function resolver"));
13253 case bp_hardware_breakpoint:
13254 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13257 printf_filtered (_("Dprintf %d"), b->number);
13265 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13267 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13268 fprintf_unfiltered (fp, "tbreak");
13269 else if (tp->type == bp_breakpoint)
13270 fprintf_unfiltered (fp, "break");
13271 else if (tp->type == bp_hardware_breakpoint
13272 && tp->disposition == disp_del)
13273 fprintf_unfiltered (fp, "thbreak");
13274 else if (tp->type == bp_hardware_breakpoint)
13275 fprintf_unfiltered (fp, "hbreak");
13277 internal_error (__FILE__, __LINE__,
13278 _("unhandled breakpoint type %d"), (int) tp->type);
13280 fprintf_unfiltered (fp, " %s",
13281 event_location_to_string (tp->location));
13283 /* Print out extra_string if this breakpoint is pending. It might
13284 contain, for example, conditions that were set by the user. */
13285 if (tp->loc == NULL && tp->extra_string != NULL)
13286 fprintf_unfiltered (fp, " %s", tp->extra_string);
13288 print_recreate_thread (tp, fp);
13292 bkpt_create_sals_from_location (const struct event_location *location,
13293 struct linespec_result *canonical,
13294 enum bptype type_wanted)
13296 create_sals_from_location_default (location, canonical, type_wanted);
13300 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13301 struct linespec_result *canonical,
13303 char *extra_string,
13304 enum bptype type_wanted,
13305 enum bpdisp disposition,
13307 int task, int ignore_count,
13308 const struct breakpoint_ops *ops,
13309 int from_tty, int enabled,
13310 int internal, unsigned flags)
13312 create_breakpoints_sal_default (gdbarch, canonical,
13313 cond_string, extra_string,
13315 disposition, thread, task,
13316 ignore_count, ops, from_tty,
13317 enabled, internal, flags);
13321 bkpt_decode_location (struct breakpoint *b,
13322 const struct event_location *location,
13323 struct program_space *search_pspace,
13324 struct symtabs_and_lines *sals)
13326 decode_location_default (b, location, search_pspace, sals);
13329 /* Virtual table for internal breakpoints. */
13332 internal_bkpt_re_set (struct breakpoint *b)
13336 /* Delete overlay event and longjmp master breakpoints; they
13337 will be reset later by breakpoint_re_set. */
13338 case bp_overlay_event:
13339 case bp_longjmp_master:
13340 case bp_std_terminate_master:
13341 case bp_exception_master:
13342 delete_breakpoint (b);
13345 /* This breakpoint is special, it's set up when the inferior
13346 starts and we really don't want to touch it. */
13347 case bp_shlib_event:
13349 /* Like bp_shlib_event, this breakpoint type is special. Once
13350 it is set up, we do not want to touch it. */
13351 case bp_thread_event:
13357 internal_bkpt_check_status (bpstat bs)
13359 if (bs->breakpoint_at->type == bp_shlib_event)
13361 /* If requested, stop when the dynamic linker notifies GDB of
13362 events. This allows the user to get control and place
13363 breakpoints in initializer routines for dynamically loaded
13364 objects (among other things). */
13365 bs->stop = stop_on_solib_events;
13366 bs->print = stop_on_solib_events;
13372 static enum print_stop_action
13373 internal_bkpt_print_it (bpstat bs)
13375 struct breakpoint *b;
13377 b = bs->breakpoint_at;
13381 case bp_shlib_event:
13382 /* Did we stop because the user set the stop_on_solib_events
13383 variable? (If so, we report this as a generic, "Stopped due
13384 to shlib event" message.) */
13385 print_solib_event (0);
13388 case bp_thread_event:
13389 /* Not sure how we will get here.
13390 GDB should not stop for these breakpoints. */
13391 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13394 case bp_overlay_event:
13395 /* By analogy with the thread event, GDB should not stop for these. */
13396 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13399 case bp_longjmp_master:
13400 /* These should never be enabled. */
13401 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13404 case bp_std_terminate_master:
13405 /* These should never be enabled. */
13406 printf_filtered (_("std::terminate Master Breakpoint: "
13407 "gdb should not stop!\n"));
13410 case bp_exception_master:
13411 /* These should never be enabled. */
13412 printf_filtered (_("Exception Master Breakpoint: "
13413 "gdb should not stop!\n"));
13417 return PRINT_NOTHING;
13421 internal_bkpt_print_mention (struct breakpoint *b)
13423 /* Nothing to mention. These breakpoints are internal. */
13426 /* Virtual table for momentary breakpoints */
13429 momentary_bkpt_re_set (struct breakpoint *b)
13431 /* Keep temporary breakpoints, which can be encountered when we step
13432 over a dlopen call and solib_add is resetting the breakpoints.
13433 Otherwise these should have been blown away via the cleanup chain
13434 or by breakpoint_init_inferior when we rerun the executable. */
13438 momentary_bkpt_check_status (bpstat bs)
13440 /* Nothing. The point of these breakpoints is causing a stop. */
13443 static enum print_stop_action
13444 momentary_bkpt_print_it (bpstat bs)
13446 return PRINT_UNKNOWN;
13450 momentary_bkpt_print_mention (struct breakpoint *b)
13452 /* Nothing to mention. These breakpoints are internal. */
13455 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13457 It gets cleared already on the removal of the first one of such placed
13458 breakpoints. This is OK as they get all removed altogether. */
13461 longjmp_bkpt_dtor (struct breakpoint *self)
13463 struct thread_info *tp = find_thread_global_id (self->thread);
13466 tp->initiating_frame = null_frame_id;
13468 momentary_breakpoint_ops.dtor (self);
13471 /* Specific methods for probe breakpoints. */
13474 bkpt_probe_insert_location (struct bp_location *bl)
13476 int v = bkpt_insert_location (bl);
13480 /* The insertion was successful, now let's set the probe's semaphore
13482 if (bl->probe.probe->pops->set_semaphore != NULL)
13483 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13492 bkpt_probe_remove_location (struct bp_location *bl,
13493 enum remove_bp_reason reason)
13495 /* Let's clear the semaphore before removing the location. */
13496 if (bl->probe.probe->pops->clear_semaphore != NULL)
13497 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13501 return bkpt_remove_location (bl, reason);
13505 bkpt_probe_create_sals_from_location (const struct event_location *location,
13506 struct linespec_result *canonical,
13507 enum bptype type_wanted)
13509 struct linespec_sals lsal;
13511 lsal.sals = parse_probes (location, NULL, canonical);
13512 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13513 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13517 bkpt_probe_decode_location (struct breakpoint *b,
13518 const struct event_location *location,
13519 struct program_space *search_pspace,
13520 struct symtabs_and_lines *sals)
13522 *sals = parse_probes (location, search_pspace, NULL);
13524 error (_("probe not found"));
13527 /* The breakpoint_ops structure to be used in tracepoints. */
13530 tracepoint_re_set (struct breakpoint *b)
13532 breakpoint_re_set_default (b);
13536 tracepoint_breakpoint_hit (const struct bp_location *bl,
13537 struct address_space *aspace, CORE_ADDR bp_addr,
13538 const struct target_waitstatus *ws)
13540 /* By definition, the inferior does not report stops at
13546 tracepoint_print_one_detail (const struct breakpoint *self,
13547 struct ui_out *uiout)
13549 struct tracepoint *tp = (struct tracepoint *) self;
13550 if (tp->static_trace_marker_id)
13552 gdb_assert (self->type == bp_static_tracepoint);
13554 ui_out_text (uiout, "\tmarker id is ");
13555 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13556 tp->static_trace_marker_id);
13557 ui_out_text (uiout, "\n");
13562 tracepoint_print_mention (struct breakpoint *b)
13564 if (ui_out_is_mi_like_p (current_uiout))
13569 case bp_tracepoint:
13570 printf_filtered (_("Tracepoint"));
13571 printf_filtered (_(" %d"), b->number);
13573 case bp_fast_tracepoint:
13574 printf_filtered (_("Fast tracepoint"));
13575 printf_filtered (_(" %d"), b->number);
13577 case bp_static_tracepoint:
13578 printf_filtered (_("Static tracepoint"));
13579 printf_filtered (_(" %d"), b->number);
13582 internal_error (__FILE__, __LINE__,
13583 _("unhandled tracepoint type %d"), (int) b->type);
13590 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13592 struct tracepoint *tp = (struct tracepoint *) self;
13594 if (self->type == bp_fast_tracepoint)
13595 fprintf_unfiltered (fp, "ftrace");
13596 else if (self->type == bp_static_tracepoint)
13597 fprintf_unfiltered (fp, "strace");
13598 else if (self->type == bp_tracepoint)
13599 fprintf_unfiltered (fp, "trace");
13601 internal_error (__FILE__, __LINE__,
13602 _("unhandled tracepoint type %d"), (int) self->type);
13604 fprintf_unfiltered (fp, " %s",
13605 event_location_to_string (self->location));
13606 print_recreate_thread (self, fp);
13608 if (tp->pass_count)
13609 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13613 tracepoint_create_sals_from_location (const struct event_location *location,
13614 struct linespec_result *canonical,
13615 enum bptype type_wanted)
13617 create_sals_from_location_default (location, canonical, type_wanted);
13621 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13622 struct linespec_result *canonical,
13624 char *extra_string,
13625 enum bptype type_wanted,
13626 enum bpdisp disposition,
13628 int task, int ignore_count,
13629 const struct breakpoint_ops *ops,
13630 int from_tty, int enabled,
13631 int internal, unsigned flags)
13633 create_breakpoints_sal_default (gdbarch, canonical,
13634 cond_string, extra_string,
13636 disposition, thread, task,
13637 ignore_count, ops, from_tty,
13638 enabled, internal, flags);
13642 tracepoint_decode_location (struct breakpoint *b,
13643 const struct event_location *location,
13644 struct program_space *search_pspace,
13645 struct symtabs_and_lines *sals)
13647 decode_location_default (b, location, search_pspace, sals);
13650 struct breakpoint_ops tracepoint_breakpoint_ops;
13652 /* The breakpoint_ops structure to be use on tracepoints placed in a
13656 tracepoint_probe_create_sals_from_location
13657 (const struct event_location *location,
13658 struct linespec_result *canonical,
13659 enum bptype type_wanted)
13661 /* We use the same method for breakpoint on probes. */
13662 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
13666 tracepoint_probe_decode_location (struct breakpoint *b,
13667 const struct event_location *location,
13668 struct program_space *search_pspace,
13669 struct symtabs_and_lines *sals)
13671 /* We use the same method for breakpoint on probes. */
13672 bkpt_probe_decode_location (b, location, search_pspace, sals);
13675 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13677 /* Dprintf breakpoint_ops methods. */
13680 dprintf_re_set (struct breakpoint *b)
13682 breakpoint_re_set_default (b);
13684 /* extra_string should never be non-NULL for dprintf. */
13685 gdb_assert (b->extra_string != NULL);
13687 /* 1 - connect to target 1, that can run breakpoint commands.
13688 2 - create a dprintf, which resolves fine.
13689 3 - disconnect from target 1
13690 4 - connect to target 2, that can NOT run breakpoint commands.
13692 After steps #3/#4, you'll want the dprintf command list to
13693 be updated, because target 1 and 2 may well return different
13694 answers for target_can_run_breakpoint_commands().
13695 Given absence of finer grained resetting, we get to do
13696 it all the time. */
13697 if (b->extra_string != NULL)
13698 update_dprintf_command_list (b);
13701 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13704 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13706 fprintf_unfiltered (fp, "dprintf %s,%s",
13707 event_location_to_string (tp->location),
13709 print_recreate_thread (tp, fp);
13712 /* Implement the "after_condition_true" breakpoint_ops method for
13715 dprintf's are implemented with regular commands in their command
13716 list, but we run the commands here instead of before presenting the
13717 stop to the user, as dprintf's don't actually cause a stop. This
13718 also makes it so that the commands of multiple dprintfs at the same
13719 address are all handled. */
13722 dprintf_after_condition_true (struct bpstats *bs)
13724 struct cleanup *old_chain;
13725 struct bpstats tmp_bs = { NULL };
13726 struct bpstats *tmp_bs_p = &tmp_bs;
13728 /* dprintf's never cause a stop. This wasn't set in the
13729 check_status hook instead because that would make the dprintf's
13730 condition not be evaluated. */
13733 /* Run the command list here. Take ownership of it instead of
13734 copying. We never want these commands to run later in
13735 bpstat_do_actions, if a breakpoint that causes a stop happens to
13736 be set at same address as this dprintf, or even if running the
13737 commands here throws. */
13738 tmp_bs.commands = bs->commands;
13739 bs->commands = NULL;
13740 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13742 bpstat_do_actions_1 (&tmp_bs_p);
13744 /* 'tmp_bs.commands' will usually be NULL by now, but
13745 bpstat_do_actions_1 may return early without processing the whole
13747 do_cleanups (old_chain);
13750 /* The breakpoint_ops structure to be used on static tracepoints with
13754 strace_marker_create_sals_from_location (const struct event_location *location,
13755 struct linespec_result *canonical,
13756 enum bptype type_wanted)
13758 struct linespec_sals lsal;
13759 const char *arg_start, *arg;
13761 struct cleanup *cleanup;
13763 arg = arg_start = get_linespec_location (location);
13764 lsal.sals = decode_static_tracepoint_spec (&arg);
13766 str = savestring (arg_start, arg - arg_start);
13767 cleanup = make_cleanup (xfree, str);
13768 canonical->location = new_linespec_location (&str);
13769 do_cleanups (cleanup);
13771 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13772 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13776 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13777 struct linespec_result *canonical,
13779 char *extra_string,
13780 enum bptype type_wanted,
13781 enum bpdisp disposition,
13783 int task, int ignore_count,
13784 const struct breakpoint_ops *ops,
13785 int from_tty, int enabled,
13786 int internal, unsigned flags)
13789 struct linespec_sals *lsal = VEC_index (linespec_sals,
13790 canonical->sals, 0);
13792 /* If the user is creating a static tracepoint by marker id
13793 (strace -m MARKER_ID), then store the sals index, so that
13794 breakpoint_re_set can try to match up which of the newly
13795 found markers corresponds to this one, and, don't try to
13796 expand multiple locations for each sal, given than SALS
13797 already should contain all sals for MARKER_ID. */
13799 for (i = 0; i < lsal->sals.nelts; ++i)
13801 struct symtabs_and_lines expanded;
13802 struct tracepoint *tp;
13803 struct cleanup *old_chain;
13804 struct event_location *location;
13806 expanded.nelts = 1;
13807 expanded.sals = &lsal->sals.sals[i];
13809 location = copy_event_location (canonical->location);
13810 old_chain = make_cleanup_delete_event_location (location);
13812 tp = XCNEW (struct tracepoint);
13813 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13815 cond_string, extra_string,
13816 type_wanted, disposition,
13817 thread, task, ignore_count, ops,
13818 from_tty, enabled, internal, flags,
13819 canonical->special_display);
13820 /* Given that its possible to have multiple markers with
13821 the same string id, if the user is creating a static
13822 tracepoint by marker id ("strace -m MARKER_ID"), then
13823 store the sals index, so that breakpoint_re_set can
13824 try to match up which of the newly found markers
13825 corresponds to this one */
13826 tp->static_trace_marker_id_idx = i;
13828 install_breakpoint (internal, &tp->base, 0);
13830 discard_cleanups (old_chain);
13835 strace_marker_decode_location (struct breakpoint *b,
13836 const struct event_location *location,
13837 struct program_space *search_pspace,
13838 struct symtabs_and_lines *sals)
13840 struct tracepoint *tp = (struct tracepoint *) b;
13841 const char *s = get_linespec_location (location);
13843 *sals = decode_static_tracepoint_spec (&s);
13844 if (sals->nelts > tp->static_trace_marker_id_idx)
13846 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13850 error (_("marker %s not found"), tp->static_trace_marker_id);
13853 static struct breakpoint_ops strace_marker_breakpoint_ops;
13856 strace_marker_p (struct breakpoint *b)
13858 return b->ops == &strace_marker_breakpoint_ops;
13861 /* Delete a breakpoint and clean up all traces of it in the data
13865 delete_breakpoint (struct breakpoint *bpt)
13867 struct breakpoint *b;
13869 gdb_assert (bpt != NULL);
13871 /* Has this bp already been deleted? This can happen because
13872 multiple lists can hold pointers to bp's. bpstat lists are
13875 One example of this happening is a watchpoint's scope bp. When
13876 the scope bp triggers, we notice that the watchpoint is out of
13877 scope, and delete it. We also delete its scope bp. But the
13878 scope bp is marked "auto-deleting", and is already on a bpstat.
13879 That bpstat is then checked for auto-deleting bp's, which are
13882 A real solution to this problem might involve reference counts in
13883 bp's, and/or giving them pointers back to their referencing
13884 bpstat's, and teaching delete_breakpoint to only free a bp's
13885 storage when no more references were extent. A cheaper bandaid
13887 if (bpt->type == bp_none)
13890 /* At least avoid this stale reference until the reference counting
13891 of breakpoints gets resolved. */
13892 if (bpt->related_breakpoint != bpt)
13894 struct breakpoint *related;
13895 struct watchpoint *w;
13897 if (bpt->type == bp_watchpoint_scope)
13898 w = (struct watchpoint *) bpt->related_breakpoint;
13899 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13900 w = (struct watchpoint *) bpt;
13904 watchpoint_del_at_next_stop (w);
13906 /* Unlink bpt from the bpt->related_breakpoint ring. */
13907 for (related = bpt; related->related_breakpoint != bpt;
13908 related = related->related_breakpoint);
13909 related->related_breakpoint = bpt->related_breakpoint;
13910 bpt->related_breakpoint = bpt;
13913 /* watch_command_1 creates a watchpoint but only sets its number if
13914 update_watchpoint succeeds in creating its bp_locations. If there's
13915 a problem in that process, we'll be asked to delete the half-created
13916 watchpoint. In that case, don't announce the deletion. */
13918 observer_notify_breakpoint_deleted (bpt);
13920 if (breakpoint_chain == bpt)
13921 breakpoint_chain = bpt->next;
13923 ALL_BREAKPOINTS (b)
13924 if (b->next == bpt)
13926 b->next = bpt->next;
13930 /* Be sure no bpstat's are pointing at the breakpoint after it's
13932 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13933 in all threads for now. Note that we cannot just remove bpstats
13934 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13935 commands are associated with the bpstat; if we remove it here,
13936 then the later call to bpstat_do_actions (&stop_bpstat); in
13937 event-top.c won't do anything, and temporary breakpoints with
13938 commands won't work. */
13940 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13942 /* Now that breakpoint is removed from breakpoint list, update the
13943 global location list. This will remove locations that used to
13944 belong to this breakpoint. Do this before freeing the breakpoint
13945 itself, since remove_breakpoint looks at location's owner. It
13946 might be better design to have location completely
13947 self-contained, but it's not the case now. */
13948 update_global_location_list (UGLL_DONT_INSERT);
13950 bpt->ops->dtor (bpt);
13951 /* On the chance that someone will soon try again to delete this
13952 same bp, we mark it as deleted before freeing its storage. */
13953 bpt->type = bp_none;
13958 do_delete_breakpoint_cleanup (void *b)
13960 delete_breakpoint ((struct breakpoint *) b);
13964 make_cleanup_delete_breakpoint (struct breakpoint *b)
13966 return make_cleanup (do_delete_breakpoint_cleanup, b);
13969 /* Iterator function to call a user-provided callback function once
13970 for each of B and its related breakpoints. */
13973 iterate_over_related_breakpoints (struct breakpoint *b,
13974 void (*function) (struct breakpoint *,
13978 struct breakpoint *related;
13983 struct breakpoint *next;
13985 /* FUNCTION may delete RELATED. */
13986 next = related->related_breakpoint;
13988 if (next == related)
13990 /* RELATED is the last ring entry. */
13991 function (related, data);
13993 /* FUNCTION may have deleted it, so we'd never reach back to
13994 B. There's nothing left to do anyway, so just break
13999 function (related, data);
14003 while (related != b);
14007 do_delete_breakpoint (struct breakpoint *b, void *ignore)
14009 delete_breakpoint (b);
14012 /* A callback for map_breakpoint_numbers that calls
14013 delete_breakpoint. */
14016 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
14018 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
14022 delete_command (char *arg, int from_tty)
14024 struct breakpoint *b, *b_tmp;
14030 int breaks_to_delete = 0;
14032 /* Delete all breakpoints if no argument. Do not delete
14033 internal breakpoints, these have to be deleted with an
14034 explicit breakpoint number argument. */
14035 ALL_BREAKPOINTS (b)
14036 if (user_breakpoint_p (b))
14038 breaks_to_delete = 1;
14042 /* Ask user only if there are some breakpoints to delete. */
14044 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
14046 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14047 if (user_breakpoint_p (b))
14048 delete_breakpoint (b);
14052 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14055 /* Return true if all locations of B bound to PSPACE are pending. If
14056 PSPACE is NULL, all locations of all program spaces are
14060 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
14062 struct bp_location *loc;
14064 for (loc = b->loc; loc != NULL; loc = loc->next)
14065 if ((pspace == NULL
14066 || loc->pspace == pspace)
14067 && !loc->shlib_disabled
14068 && !loc->pspace->executing_startup)
14073 /* Subroutine of update_breakpoint_locations to simplify it.
14074 Return non-zero if multiple fns in list LOC have the same name.
14075 Null names are ignored. */
14078 ambiguous_names_p (struct bp_location *loc)
14080 struct bp_location *l;
14081 htab_t htab = htab_create_alloc (13, htab_hash_string,
14082 (int (*) (const void *,
14083 const void *)) streq,
14084 NULL, xcalloc, xfree);
14086 for (l = loc; l != NULL; l = l->next)
14089 const char *name = l->function_name;
14091 /* Allow for some names to be NULL, ignore them. */
14095 slot = (const char **) htab_find_slot (htab, (const void *) name,
14097 /* NOTE: We can assume slot != NULL here because xcalloc never
14101 htab_delete (htab);
14107 htab_delete (htab);
14111 /* When symbols change, it probably means the sources changed as well,
14112 and it might mean the static tracepoint markers are no longer at
14113 the same address or line numbers they used to be at last we
14114 checked. Losing your static tracepoints whenever you rebuild is
14115 undesirable. This function tries to resync/rematch gdb static
14116 tracepoints with the markers on the target, for static tracepoints
14117 that have not been set by marker id. Static tracepoint that have
14118 been set by marker id are reset by marker id in breakpoint_re_set.
14121 1) For a tracepoint set at a specific address, look for a marker at
14122 the old PC. If one is found there, assume to be the same marker.
14123 If the name / string id of the marker found is different from the
14124 previous known name, assume that means the user renamed the marker
14125 in the sources, and output a warning.
14127 2) For a tracepoint set at a given line number, look for a marker
14128 at the new address of the old line number. If one is found there,
14129 assume to be the same marker. If the name / string id of the
14130 marker found is different from the previous known name, assume that
14131 means the user renamed the marker in the sources, and output a
14134 3) If a marker is no longer found at the same address or line, it
14135 may mean the marker no longer exists. But it may also just mean
14136 the code changed a bit. Maybe the user added a few lines of code
14137 that made the marker move up or down (in line number terms). Ask
14138 the target for info about the marker with the string id as we knew
14139 it. If found, update line number and address in the matching
14140 static tracepoint. This will get confused if there's more than one
14141 marker with the same ID (possible in UST, although unadvised
14142 precisely because it confuses tools). */
14144 static struct symtab_and_line
14145 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14147 struct tracepoint *tp = (struct tracepoint *) b;
14148 struct static_tracepoint_marker marker;
14153 find_line_pc (sal.symtab, sal.line, &pc);
14155 if (target_static_tracepoint_marker_at (pc, &marker))
14157 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14158 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14160 tp->static_trace_marker_id, marker.str_id);
14162 xfree (tp->static_trace_marker_id);
14163 tp->static_trace_marker_id = xstrdup (marker.str_id);
14164 release_static_tracepoint_marker (&marker);
14169 /* Old marker wasn't found on target at lineno. Try looking it up
14171 if (!sal.explicit_pc
14173 && sal.symtab != NULL
14174 && tp->static_trace_marker_id != NULL)
14176 VEC(static_tracepoint_marker_p) *markers;
14179 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14181 if (!VEC_empty(static_tracepoint_marker_p, markers))
14183 struct symtab_and_line sal2;
14184 struct symbol *sym;
14185 struct static_tracepoint_marker *tpmarker;
14186 struct ui_out *uiout = current_uiout;
14187 struct explicit_location explicit_loc;
14189 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14191 xfree (tp->static_trace_marker_id);
14192 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14194 warning (_("marker for static tracepoint %d (%s) not "
14195 "found at previous line number"),
14196 b->number, tp->static_trace_marker_id);
14200 sal2.pc = tpmarker->address;
14202 sal2 = find_pc_line (tpmarker->address, 0);
14203 sym = find_pc_sect_function (tpmarker->address, NULL);
14204 ui_out_text (uiout, "Now in ");
14207 ui_out_field_string (uiout, "func",
14208 SYMBOL_PRINT_NAME (sym));
14209 ui_out_text (uiout, " at ");
14211 ui_out_field_string (uiout, "file",
14212 symtab_to_filename_for_display (sal2.symtab));
14213 ui_out_text (uiout, ":");
14215 if (ui_out_is_mi_like_p (uiout))
14217 const char *fullname = symtab_to_fullname (sal2.symtab);
14219 ui_out_field_string (uiout, "fullname", fullname);
14222 ui_out_field_int (uiout, "line", sal2.line);
14223 ui_out_text (uiout, "\n");
14225 b->loc->line_number = sal2.line;
14226 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14228 delete_event_location (b->location);
14229 initialize_explicit_location (&explicit_loc);
14230 explicit_loc.source_filename
14231 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
14232 explicit_loc.line_offset.offset = b->loc->line_number;
14233 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
14234 b->location = new_explicit_location (&explicit_loc);
14236 /* Might be nice to check if function changed, and warn if
14239 release_static_tracepoint_marker (tpmarker);
14245 /* Returns 1 iff locations A and B are sufficiently same that
14246 we don't need to report breakpoint as changed. */
14249 locations_are_equal (struct bp_location *a, struct bp_location *b)
14253 if (a->address != b->address)
14256 if (a->shlib_disabled != b->shlib_disabled)
14259 if (a->enabled != b->enabled)
14266 if ((a == NULL) != (b == NULL))
14272 /* Split all locations of B that are bound to PSPACE out of B's
14273 location list to a separate list and return that list's head. If
14274 PSPACE is NULL, hoist out all locations of B. */
14276 static struct bp_location *
14277 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
14279 struct bp_location head;
14280 struct bp_location *i = b->loc;
14281 struct bp_location **i_link = &b->loc;
14282 struct bp_location *hoisted = &head;
14284 if (pspace == NULL)
14295 if (i->pspace == pspace)
14310 /* Create new breakpoint locations for B (a hardware or software
14311 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14312 zero, then B is a ranged breakpoint. Only recreates locations for
14313 FILTER_PSPACE. Locations of other program spaces are left
14317 update_breakpoint_locations (struct breakpoint *b,
14318 struct program_space *filter_pspace,
14319 struct symtabs_and_lines sals,
14320 struct symtabs_and_lines sals_end)
14323 struct bp_location *existing_locations;
14325 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14327 /* Ranged breakpoints have only one start location and one end
14329 b->enable_state = bp_disabled;
14330 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14331 "multiple locations found\n"),
14336 /* If there's no new locations, and all existing locations are
14337 pending, don't do anything. This optimizes the common case where
14338 all locations are in the same shared library, that was unloaded.
14339 We'd like to retain the location, so that when the library is
14340 loaded again, we don't loose the enabled/disabled status of the
14341 individual locations. */
14342 if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0)
14345 existing_locations = hoist_existing_locations (b, filter_pspace);
14347 for (i = 0; i < sals.nelts; ++i)
14349 struct bp_location *new_loc;
14351 switch_to_program_space_and_thread (sals.sals[i].pspace);
14353 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14355 /* Reparse conditions, they might contain references to the
14357 if (b->cond_string != NULL)
14361 s = b->cond_string;
14364 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14365 block_for_pc (sals.sals[i].pc),
14368 CATCH (e, RETURN_MASK_ERROR)
14370 warning (_("failed to reevaluate condition "
14371 "for breakpoint %d: %s"),
14372 b->number, e.message);
14373 new_loc->enabled = 0;
14378 if (sals_end.nelts)
14380 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14382 new_loc->length = end - sals.sals[0].pc + 1;
14386 /* If possible, carry over 'disable' status from existing
14389 struct bp_location *e = existing_locations;
14390 /* If there are multiple breakpoints with the same function name,
14391 e.g. for inline functions, comparing function names won't work.
14392 Instead compare pc addresses; this is just a heuristic as things
14393 may have moved, but in practice it gives the correct answer
14394 often enough until a better solution is found. */
14395 int have_ambiguous_names = ambiguous_names_p (b->loc);
14397 for (; e; e = e->next)
14399 if (!e->enabled && e->function_name)
14401 struct bp_location *l = b->loc;
14402 if (have_ambiguous_names)
14404 for (; l; l = l->next)
14405 if (breakpoint_locations_match (e, l))
14413 for (; l; l = l->next)
14414 if (l->function_name
14415 && strcmp (e->function_name, l->function_name) == 0)
14425 if (!locations_are_equal (existing_locations, b->loc))
14426 observer_notify_breakpoint_modified (b);
14429 /* Find the SaL locations corresponding to the given LOCATION.
14430 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14432 static struct symtabs_and_lines
14433 location_to_sals (struct breakpoint *b, struct event_location *location,
14434 struct program_space *search_pspace, int *found)
14436 struct symtabs_and_lines sals = {0};
14437 struct gdb_exception exception = exception_none;
14439 gdb_assert (b->ops != NULL);
14443 b->ops->decode_location (b, location, search_pspace, &sals);
14445 CATCH (e, RETURN_MASK_ERROR)
14447 int not_found_and_ok = 0;
14451 /* For pending breakpoints, it's expected that parsing will
14452 fail until the right shared library is loaded. User has
14453 already told to create pending breakpoints and don't need
14454 extra messages. If breakpoint is in bp_shlib_disabled
14455 state, then user already saw the message about that
14456 breakpoint being disabled, and don't want to see more
14458 if (e.error == NOT_FOUND_ERROR
14459 && (b->condition_not_parsed
14461 && search_pspace != NULL
14462 && b->loc->pspace != search_pspace)
14463 || (b->loc && b->loc->shlib_disabled)
14464 || (b->loc && b->loc->pspace->executing_startup)
14465 || b->enable_state == bp_disabled))
14466 not_found_and_ok = 1;
14468 if (!not_found_and_ok)
14470 /* We surely don't want to warn about the same breakpoint
14471 10 times. One solution, implemented here, is disable
14472 the breakpoint on error. Another solution would be to
14473 have separate 'warning emitted' flag. Since this
14474 happens only when a binary has changed, I don't know
14475 which approach is better. */
14476 b->enable_state = bp_disabled;
14477 throw_exception (e);
14482 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
14486 for (i = 0; i < sals.nelts; ++i)
14487 resolve_sal_pc (&sals.sals[i]);
14488 if (b->condition_not_parsed && b->extra_string != NULL)
14490 char *cond_string, *extra_string;
14493 find_condition_and_thread (b->extra_string, sals.sals[0].pc,
14494 &cond_string, &thread, &task,
14496 gdb_assert (b->cond_string == NULL);
14498 b->cond_string = cond_string;
14499 b->thread = thread;
14503 xfree (b->extra_string);
14504 b->extra_string = extra_string;
14506 b->condition_not_parsed = 0;
14509 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14510 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14520 /* The default re_set method, for typical hardware or software
14521 breakpoints. Reevaluate the breakpoint and recreate its
14525 breakpoint_re_set_default (struct breakpoint *b)
14528 struct symtabs_and_lines sals, sals_end;
14529 struct symtabs_and_lines expanded = {0};
14530 struct symtabs_and_lines expanded_end = {0};
14531 struct program_space *filter_pspace = current_program_space;
14533 sals = location_to_sals (b, b->location, filter_pspace, &found);
14536 make_cleanup (xfree, sals.sals);
14540 if (b->location_range_end != NULL)
14542 sals_end = location_to_sals (b, b->location_range_end,
14543 filter_pspace, &found);
14546 make_cleanup (xfree, sals_end.sals);
14547 expanded_end = sals_end;
14551 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
14554 /* Default method for creating SALs from an address string. It basically
14555 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14558 create_sals_from_location_default (const struct event_location *location,
14559 struct linespec_result *canonical,
14560 enum bptype type_wanted)
14562 parse_breakpoint_sals (location, canonical);
14565 /* Call create_breakpoints_sal for the given arguments. This is the default
14566 function for the `create_breakpoints_sal' method of
14570 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14571 struct linespec_result *canonical,
14573 char *extra_string,
14574 enum bptype type_wanted,
14575 enum bpdisp disposition,
14577 int task, int ignore_count,
14578 const struct breakpoint_ops *ops,
14579 int from_tty, int enabled,
14580 int internal, unsigned flags)
14582 create_breakpoints_sal (gdbarch, canonical, cond_string,
14584 type_wanted, disposition,
14585 thread, task, ignore_count, ops, from_tty,
14586 enabled, internal, flags);
14589 /* Decode the line represented by S by calling decode_line_full. This is the
14590 default function for the `decode_location' method of breakpoint_ops. */
14593 decode_location_default (struct breakpoint *b,
14594 const struct event_location *location,
14595 struct program_space *search_pspace,
14596 struct symtabs_and_lines *sals)
14598 struct linespec_result canonical;
14600 init_linespec_result (&canonical);
14601 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
14602 (struct symtab *) NULL, 0,
14603 &canonical, multiple_symbols_all,
14606 /* We should get 0 or 1 resulting SALs. */
14607 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14609 if (VEC_length (linespec_sals, canonical.sals) > 0)
14611 struct linespec_sals *lsal;
14613 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14614 *sals = lsal->sals;
14615 /* Arrange it so the destructor does not free the
14617 lsal->sals.sals = NULL;
14620 destroy_linespec_result (&canonical);
14623 /* Prepare the global context for a re-set of breakpoint B. */
14625 static struct cleanup *
14626 prepare_re_set_context (struct breakpoint *b)
14628 input_radix = b->input_radix;
14629 set_language (b->language);
14631 return make_cleanup (null_cleanup, NULL);
14634 /* Reset a breakpoint given it's struct breakpoint * BINT.
14635 The value we return ends up being the return value from catch_errors.
14636 Unused in this case. */
14639 breakpoint_re_set_one (void *bint)
14641 /* Get past catch_errs. */
14642 struct breakpoint *b = (struct breakpoint *) bint;
14643 struct cleanup *cleanups;
14645 cleanups = prepare_re_set_context (b);
14646 b->ops->re_set (b);
14647 do_cleanups (cleanups);
14651 /* Re-set breakpoint locations for the current program space.
14652 Locations bound to other program spaces are left untouched. */
14655 breakpoint_re_set (void)
14657 struct breakpoint *b, *b_tmp;
14658 enum language save_language;
14659 int save_input_radix;
14660 struct cleanup *old_chain;
14662 save_language = current_language->la_language;
14663 save_input_radix = input_radix;
14664 old_chain = save_current_space_and_thread ();
14666 /* Note: we must not try to insert locations until after all
14667 breakpoints have been re-set. Otherwise, e.g., when re-setting
14668 breakpoint 1, we'd insert the locations of breakpoint 2, which
14669 hadn't been re-set yet, and thus may have stale locations. */
14671 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14673 /* Format possible error msg. */
14674 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14676 struct cleanup *cleanups = make_cleanup (xfree, message);
14677 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14678 do_cleanups (cleanups);
14680 set_language (save_language);
14681 input_radix = save_input_radix;
14683 jit_breakpoint_re_set ();
14685 do_cleanups (old_chain);
14687 create_overlay_event_breakpoint ();
14688 create_longjmp_master_breakpoint ();
14689 create_std_terminate_master_breakpoint ();
14690 create_exception_master_breakpoint ();
14692 /* Now we can insert. */
14693 update_global_location_list (UGLL_MAY_INSERT);
14696 /* Reset the thread number of this breakpoint:
14698 - If the breakpoint is for all threads, leave it as-is.
14699 - Else, reset it to the current thread for inferior_ptid. */
14701 breakpoint_re_set_thread (struct breakpoint *b)
14703 if (b->thread != -1)
14705 if (in_thread_list (inferior_ptid))
14706 b->thread = ptid_to_global_thread_id (inferior_ptid);
14708 /* We're being called after following a fork. The new fork is
14709 selected as current, and unless this was a vfork will have a
14710 different program space from the original thread. Reset that
14712 b->loc->pspace = current_program_space;
14716 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14717 If from_tty is nonzero, it prints a message to that effect,
14718 which ends with a period (no newline). */
14721 set_ignore_count (int bptnum, int count, int from_tty)
14723 struct breakpoint *b;
14728 ALL_BREAKPOINTS (b)
14729 if (b->number == bptnum)
14731 if (is_tracepoint (b))
14733 if (from_tty && count != 0)
14734 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14739 b->ignore_count = count;
14743 printf_filtered (_("Will stop next time "
14744 "breakpoint %d is reached."),
14746 else if (count == 1)
14747 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14750 printf_filtered (_("Will ignore next %d "
14751 "crossings of breakpoint %d."),
14754 observer_notify_breakpoint_modified (b);
14758 error (_("No breakpoint number %d."), bptnum);
14761 /* Command to set ignore-count of breakpoint N to COUNT. */
14764 ignore_command (char *args, int from_tty)
14770 error_no_arg (_("a breakpoint number"));
14772 num = get_number (&p);
14774 error (_("bad breakpoint number: '%s'"), args);
14776 error (_("Second argument (specified ignore-count) is missing."));
14778 set_ignore_count (num,
14779 longest_to_int (value_as_long (parse_and_eval (p))),
14782 printf_filtered ("\n");
14785 /* Call FUNCTION on each of the breakpoints
14786 whose numbers are given in ARGS. */
14789 map_breakpoint_numbers (const char *args,
14790 void (*function) (struct breakpoint *,
14795 struct breakpoint *b, *tmp;
14797 if (args == 0 || *args == '\0')
14798 error_no_arg (_("one or more breakpoint numbers"));
14800 number_or_range_parser parser (args);
14802 while (!parser.finished ())
14804 const char *p = parser.cur_tok ();
14805 bool match = false;
14807 num = parser.get_number ();
14810 warning (_("bad breakpoint number at or near '%s'"), p);
14814 ALL_BREAKPOINTS_SAFE (b, tmp)
14815 if (b->number == num)
14818 function (b, data);
14822 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14827 static struct bp_location *
14828 find_location_by_number (char *number)
14830 char *dot = strchr (number, '.');
14834 struct breakpoint *b;
14835 struct bp_location *loc;
14840 bp_num = get_number (&p1);
14842 error (_("Bad breakpoint number '%s'"), number);
14844 ALL_BREAKPOINTS (b)
14845 if (b->number == bp_num)
14850 if (!b || b->number != bp_num)
14851 error (_("Bad breakpoint number '%s'"), number);
14854 loc_num = get_number (&p1);
14856 error (_("Bad breakpoint location number '%s'"), number);
14860 for (;loc_num && loc; --loc_num, loc = loc->next)
14863 error (_("Bad breakpoint location number '%s'"), dot+1);
14869 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14870 If from_tty is nonzero, it prints a message to that effect,
14871 which ends with a period (no newline). */
14874 disable_breakpoint (struct breakpoint *bpt)
14876 /* Never disable a watchpoint scope breakpoint; we want to
14877 hit them when we leave scope so we can delete both the
14878 watchpoint and its scope breakpoint at that time. */
14879 if (bpt->type == bp_watchpoint_scope)
14882 bpt->enable_state = bp_disabled;
14884 /* Mark breakpoint locations modified. */
14885 mark_breakpoint_modified (bpt);
14887 if (target_supports_enable_disable_tracepoint ()
14888 && current_trace_status ()->running && is_tracepoint (bpt))
14890 struct bp_location *location;
14892 for (location = bpt->loc; location; location = location->next)
14893 target_disable_tracepoint (location);
14896 update_global_location_list (UGLL_DONT_INSERT);
14898 observer_notify_breakpoint_modified (bpt);
14901 /* A callback for iterate_over_related_breakpoints. */
14904 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14906 disable_breakpoint (b);
14909 /* A callback for map_breakpoint_numbers that calls
14910 disable_breakpoint. */
14913 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14915 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14919 disable_command (char *args, int from_tty)
14923 struct breakpoint *bpt;
14925 ALL_BREAKPOINTS (bpt)
14926 if (user_breakpoint_p (bpt))
14927 disable_breakpoint (bpt);
14931 char *num = extract_arg (&args);
14935 if (strchr (num, '.'))
14937 struct bp_location *loc = find_location_by_number (num);
14944 mark_breakpoint_location_modified (loc);
14946 if (target_supports_enable_disable_tracepoint ()
14947 && current_trace_status ()->running && loc->owner
14948 && is_tracepoint (loc->owner))
14949 target_disable_tracepoint (loc);
14951 update_global_location_list (UGLL_DONT_INSERT);
14954 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14955 num = extract_arg (&args);
14961 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14964 int target_resources_ok;
14966 if (bpt->type == bp_hardware_breakpoint)
14969 i = hw_breakpoint_used_count ();
14970 target_resources_ok =
14971 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14973 if (target_resources_ok == 0)
14974 error (_("No hardware breakpoint support in the target."));
14975 else if (target_resources_ok < 0)
14976 error (_("Hardware breakpoints used exceeds limit."));
14979 if (is_watchpoint (bpt))
14981 /* Initialize it just to avoid a GCC false warning. */
14982 enum enable_state orig_enable_state = bp_disabled;
14986 struct watchpoint *w = (struct watchpoint *) bpt;
14988 orig_enable_state = bpt->enable_state;
14989 bpt->enable_state = bp_enabled;
14990 update_watchpoint (w, 1 /* reparse */);
14992 CATCH (e, RETURN_MASK_ALL)
14994 bpt->enable_state = orig_enable_state;
14995 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
15002 bpt->enable_state = bp_enabled;
15004 /* Mark breakpoint locations modified. */
15005 mark_breakpoint_modified (bpt);
15007 if (target_supports_enable_disable_tracepoint ()
15008 && current_trace_status ()->running && is_tracepoint (bpt))
15010 struct bp_location *location;
15012 for (location = bpt->loc; location; location = location->next)
15013 target_enable_tracepoint (location);
15016 bpt->disposition = disposition;
15017 bpt->enable_count = count;
15018 update_global_location_list (UGLL_MAY_INSERT);
15020 observer_notify_breakpoint_modified (bpt);
15025 enable_breakpoint (struct breakpoint *bpt)
15027 enable_breakpoint_disp (bpt, bpt->disposition, 0);
15031 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
15033 enable_breakpoint (bpt);
15036 /* A callback for map_breakpoint_numbers that calls
15037 enable_breakpoint. */
15040 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
15042 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
15045 /* The enable command enables the specified breakpoints (or all defined
15046 breakpoints) so they once again become (or continue to be) effective
15047 in stopping the inferior. */
15050 enable_command (char *args, int from_tty)
15054 struct breakpoint *bpt;
15056 ALL_BREAKPOINTS (bpt)
15057 if (user_breakpoint_p (bpt))
15058 enable_breakpoint (bpt);
15062 char *num = extract_arg (&args);
15066 if (strchr (num, '.'))
15068 struct bp_location *loc = find_location_by_number (num);
15075 mark_breakpoint_location_modified (loc);
15077 if (target_supports_enable_disable_tracepoint ()
15078 && current_trace_status ()->running && loc->owner
15079 && is_tracepoint (loc->owner))
15080 target_enable_tracepoint (loc);
15082 update_global_location_list (UGLL_MAY_INSERT);
15085 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15086 num = extract_arg (&args);
15091 /* This struct packages up disposition data for application to multiple
15101 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15103 struct disp_data disp_data = *(struct disp_data *) arg;
15105 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15109 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15111 struct disp_data disp = { disp_disable, 1 };
15113 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15117 enable_once_command (char *args, int from_tty)
15119 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15123 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15125 struct disp_data disp = { disp_disable, *(int *) countptr };
15127 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15131 enable_count_command (char *args, int from_tty)
15136 error_no_arg (_("hit count"));
15138 count = get_number (&args);
15140 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15144 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15146 struct disp_data disp = { disp_del, 1 };
15148 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15152 enable_delete_command (char *args, int from_tty)
15154 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15158 set_breakpoint_cmd (char *args, int from_tty)
15163 show_breakpoint_cmd (char *args, int from_tty)
15167 /* Invalidate last known value of any hardware watchpoint if
15168 the memory which that value represents has been written to by
15172 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15173 CORE_ADDR addr, ssize_t len,
15174 const bfd_byte *data)
15176 struct breakpoint *bp;
15178 ALL_BREAKPOINTS (bp)
15179 if (bp->enable_state == bp_enabled
15180 && bp->type == bp_hardware_watchpoint)
15182 struct watchpoint *wp = (struct watchpoint *) bp;
15184 if (wp->val_valid && wp->val)
15186 struct bp_location *loc;
15188 for (loc = bp->loc; loc != NULL; loc = loc->next)
15189 if (loc->loc_type == bp_loc_hardware_watchpoint
15190 && loc->address + loc->length > addr
15191 && addr + len > loc->address)
15193 value_free (wp->val);
15201 /* Create and insert a breakpoint for software single step. */
15204 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15205 struct address_space *aspace,
15208 struct thread_info *tp = inferior_thread ();
15209 struct symtab_and_line sal;
15210 CORE_ADDR pc = next_pc;
15212 if (tp->control.single_step_breakpoints == NULL)
15214 tp->control.single_step_breakpoints
15215 = new_single_step_breakpoint (tp->global_num, gdbarch);
15218 sal = find_pc_line (pc, 0);
15220 sal.section = find_pc_overlay (pc);
15221 sal.explicit_pc = 1;
15222 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
15224 update_global_location_list (UGLL_INSERT);
15227 /* Insert single step breakpoints according to the current state. */
15230 insert_single_step_breakpoints (struct gdbarch *gdbarch)
15232 struct frame_info *frame = get_current_frame ();
15233 VEC (CORE_ADDR) * next_pcs;
15235 next_pcs = gdbarch_software_single_step (gdbarch, frame);
15237 if (next_pcs != NULL)
15241 struct address_space *aspace = get_frame_address_space (frame);
15243 for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++)
15244 insert_single_step_breakpoint (gdbarch, aspace, pc);
15246 VEC_free (CORE_ADDR, next_pcs);
15254 /* See breakpoint.h. */
15257 breakpoint_has_location_inserted_here (struct breakpoint *bp,
15258 struct address_space *aspace,
15261 struct bp_location *loc;
15263 for (loc = bp->loc; loc != NULL; loc = loc->next)
15265 && breakpoint_location_address_match (loc, aspace, pc))
15271 /* Check whether a software single-step breakpoint is inserted at
15275 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15278 struct breakpoint *bpt;
15280 ALL_BREAKPOINTS (bpt)
15282 if (bpt->type == bp_single_step
15283 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
15289 /* Tracepoint-specific operations. */
15291 /* Set tracepoint count to NUM. */
15293 set_tracepoint_count (int num)
15295 tracepoint_count = num;
15296 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15300 trace_command (char *arg, int from_tty)
15302 struct breakpoint_ops *ops;
15303 struct event_location *location;
15304 struct cleanup *back_to;
15306 location = string_to_event_location (&arg, current_language);
15307 back_to = make_cleanup_delete_event_location (location);
15308 if (location != NULL
15309 && event_location_type (location) == PROBE_LOCATION)
15310 ops = &tracepoint_probe_breakpoint_ops;
15312 ops = &tracepoint_breakpoint_ops;
15314 create_breakpoint (get_current_arch (),
15316 NULL, 0, arg, 1 /* parse arg */,
15318 bp_tracepoint /* type_wanted */,
15319 0 /* Ignore count */,
15320 pending_break_support,
15324 0 /* internal */, 0);
15325 do_cleanups (back_to);
15329 ftrace_command (char *arg, int from_tty)
15331 struct event_location *location;
15332 struct cleanup *back_to;
15334 location = string_to_event_location (&arg, current_language);
15335 back_to = make_cleanup_delete_event_location (location);
15336 create_breakpoint (get_current_arch (),
15338 NULL, 0, arg, 1 /* parse arg */,
15340 bp_fast_tracepoint /* type_wanted */,
15341 0 /* Ignore count */,
15342 pending_break_support,
15343 &tracepoint_breakpoint_ops,
15346 0 /* internal */, 0);
15347 do_cleanups (back_to);
15350 /* strace command implementation. Creates a static tracepoint. */
15353 strace_command (char *arg, int from_tty)
15355 struct breakpoint_ops *ops;
15356 struct event_location *location;
15357 struct cleanup *back_to;
15359 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15360 or with a normal static tracepoint. */
15361 if (arg && startswith (arg, "-m") && isspace (arg[2]))
15363 ops = &strace_marker_breakpoint_ops;
15364 location = new_linespec_location (&arg);
15368 ops = &tracepoint_breakpoint_ops;
15369 location = string_to_event_location (&arg, current_language);
15372 back_to = make_cleanup_delete_event_location (location);
15373 create_breakpoint (get_current_arch (),
15375 NULL, 0, arg, 1 /* parse arg */,
15377 bp_static_tracepoint /* type_wanted */,
15378 0 /* Ignore count */,
15379 pending_break_support,
15383 0 /* internal */, 0);
15384 do_cleanups (back_to);
15387 /* Set up a fake reader function that gets command lines from a linked
15388 list that was acquired during tracepoint uploading. */
15390 static struct uploaded_tp *this_utp;
15391 static int next_cmd;
15394 read_uploaded_action (void)
15398 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15405 /* Given information about a tracepoint as recorded on a target (which
15406 can be either a live system or a trace file), attempt to create an
15407 equivalent GDB tracepoint. This is not a reliable process, since
15408 the target does not necessarily have all the information used when
15409 the tracepoint was originally defined. */
15411 struct tracepoint *
15412 create_tracepoint_from_upload (struct uploaded_tp *utp)
15414 char *addr_str, small_buf[100];
15415 struct tracepoint *tp;
15416 struct event_location *location;
15417 struct cleanup *cleanup;
15419 if (utp->at_string)
15420 addr_str = utp->at_string;
15423 /* In the absence of a source location, fall back to raw
15424 address. Since there is no way to confirm that the address
15425 means the same thing as when the trace was started, warn the
15427 warning (_("Uploaded tracepoint %d has no "
15428 "source location, using raw address"),
15430 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15431 addr_str = small_buf;
15434 /* There's not much we can do with a sequence of bytecodes. */
15435 if (utp->cond && !utp->cond_string)
15436 warning (_("Uploaded tracepoint %d condition "
15437 "has no source form, ignoring it"),
15440 location = string_to_event_location (&addr_str, current_language);
15441 cleanup = make_cleanup_delete_event_location (location);
15442 if (!create_breakpoint (get_current_arch (),
15444 utp->cond_string, -1, addr_str,
15445 0 /* parse cond/thread */,
15447 utp->type /* type_wanted */,
15448 0 /* Ignore count */,
15449 pending_break_support,
15450 &tracepoint_breakpoint_ops,
15452 utp->enabled /* enabled */,
15454 CREATE_BREAKPOINT_FLAGS_INSERTED))
15456 do_cleanups (cleanup);
15460 do_cleanups (cleanup);
15462 /* Get the tracepoint we just created. */
15463 tp = get_tracepoint (tracepoint_count);
15464 gdb_assert (tp != NULL);
15468 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15471 trace_pass_command (small_buf, 0);
15474 /* If we have uploaded versions of the original commands, set up a
15475 special-purpose "reader" function and call the usual command line
15476 reader, then pass the result to the breakpoint command-setting
15478 if (!VEC_empty (char_ptr, utp->cmd_strings))
15480 struct command_line *cmd_list;
15485 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15487 breakpoint_set_commands (&tp->base, cmd_list);
15489 else if (!VEC_empty (char_ptr, utp->actions)
15490 || !VEC_empty (char_ptr, utp->step_actions))
15491 warning (_("Uploaded tracepoint %d actions "
15492 "have no source form, ignoring them"),
15495 /* Copy any status information that might be available. */
15496 tp->base.hit_count = utp->hit_count;
15497 tp->traceframe_usage = utp->traceframe_usage;
15502 /* Print information on tracepoint number TPNUM_EXP, or all if
15506 tracepoints_info (char *args, int from_tty)
15508 struct ui_out *uiout = current_uiout;
15511 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15513 if (num_printed == 0)
15515 if (args == NULL || *args == '\0')
15516 ui_out_message (uiout, 0, "No tracepoints.\n");
15518 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15521 default_collect_info ();
15524 /* The 'enable trace' command enables tracepoints.
15525 Not supported by all targets. */
15527 enable_trace_command (char *args, int from_tty)
15529 enable_command (args, from_tty);
15532 /* The 'disable trace' command disables tracepoints.
15533 Not supported by all targets. */
15535 disable_trace_command (char *args, int from_tty)
15537 disable_command (args, from_tty);
15540 /* Remove a tracepoint (or all if no argument). */
15542 delete_trace_command (char *arg, int from_tty)
15544 struct breakpoint *b, *b_tmp;
15550 int breaks_to_delete = 0;
15552 /* Delete all breakpoints if no argument.
15553 Do not delete internal or call-dummy breakpoints, these
15554 have to be deleted with an explicit breakpoint number
15556 ALL_TRACEPOINTS (b)
15557 if (is_tracepoint (b) && user_breakpoint_p (b))
15559 breaks_to_delete = 1;
15563 /* Ask user only if there are some breakpoints to delete. */
15565 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15567 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15568 if (is_tracepoint (b) && user_breakpoint_p (b))
15569 delete_breakpoint (b);
15573 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15576 /* Helper function for trace_pass_command. */
15579 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15581 tp->pass_count = count;
15582 observer_notify_breakpoint_modified (&tp->base);
15584 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15585 tp->base.number, count);
15588 /* Set passcount for tracepoint.
15590 First command argument is passcount, second is tracepoint number.
15591 If tracepoint number omitted, apply to most recently defined.
15592 Also accepts special argument "all". */
15595 trace_pass_command (char *args, int from_tty)
15597 struct tracepoint *t1;
15598 unsigned int count;
15600 if (args == 0 || *args == 0)
15601 error (_("passcount command requires an "
15602 "argument (count + optional TP num)"));
15604 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15606 args = skip_spaces (args);
15607 if (*args && strncasecmp (args, "all", 3) == 0)
15609 struct breakpoint *b;
15611 args += 3; /* Skip special argument "all". */
15613 error (_("Junk at end of arguments."));
15615 ALL_TRACEPOINTS (b)
15617 t1 = (struct tracepoint *) b;
15618 trace_pass_set_count (t1, count, from_tty);
15621 else if (*args == '\0')
15623 t1 = get_tracepoint_by_number (&args, NULL);
15625 trace_pass_set_count (t1, count, from_tty);
15629 number_or_range_parser parser (args);
15630 while (!parser.finished ())
15632 t1 = get_tracepoint_by_number (&args, &parser);
15634 trace_pass_set_count (t1, count, from_tty);
15639 struct tracepoint *
15640 get_tracepoint (int num)
15642 struct breakpoint *t;
15644 ALL_TRACEPOINTS (t)
15645 if (t->number == num)
15646 return (struct tracepoint *) t;
15651 /* Find the tracepoint with the given target-side number (which may be
15652 different from the tracepoint number after disconnecting and
15655 struct tracepoint *
15656 get_tracepoint_by_number_on_target (int num)
15658 struct breakpoint *b;
15660 ALL_TRACEPOINTS (b)
15662 struct tracepoint *t = (struct tracepoint *) b;
15664 if (t->number_on_target == num)
15671 /* Utility: parse a tracepoint number and look it up in the list.
15672 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15673 If the argument is missing, the most recent tracepoint
15674 (tracepoint_count) is returned. */
15676 struct tracepoint *
15677 get_tracepoint_by_number (char **arg,
15678 number_or_range_parser *parser)
15680 struct breakpoint *t;
15682 char *instring = arg == NULL ? NULL : *arg;
15684 if (parser != NULL)
15686 gdb_assert (!parser->finished ());
15687 tpnum = parser->get_number ();
15689 else if (arg == NULL || *arg == NULL || ! **arg)
15690 tpnum = tracepoint_count;
15692 tpnum = get_number (arg);
15696 if (instring && *instring)
15697 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15700 printf_filtered (_("No previous tracepoint\n"));
15704 ALL_TRACEPOINTS (t)
15705 if (t->number == tpnum)
15707 return (struct tracepoint *) t;
15710 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15715 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15717 if (b->thread != -1)
15718 fprintf_unfiltered (fp, " thread %d", b->thread);
15721 fprintf_unfiltered (fp, " task %d", b->task);
15723 fprintf_unfiltered (fp, "\n");
15726 /* Save information on user settable breakpoints (watchpoints, etc) to
15727 a new script file named FILENAME. If FILTER is non-NULL, call it
15728 on each breakpoint and only include the ones for which it returns
15732 save_breakpoints (char *filename, int from_tty,
15733 int (*filter) (const struct breakpoint *))
15735 struct breakpoint *tp;
15737 struct cleanup *cleanup;
15738 struct ui_file *fp;
15739 int extra_trace_bits = 0;
15741 if (filename == 0 || *filename == 0)
15742 error (_("Argument required (file name in which to save)"));
15744 /* See if we have anything to save. */
15745 ALL_BREAKPOINTS (tp)
15747 /* Skip internal and momentary breakpoints. */
15748 if (!user_breakpoint_p (tp))
15751 /* If we have a filter, only save the breakpoints it accepts. */
15752 if (filter && !filter (tp))
15757 if (is_tracepoint (tp))
15759 extra_trace_bits = 1;
15761 /* We can stop searching. */
15768 warning (_("Nothing to save."));
15772 filename = tilde_expand (filename);
15773 cleanup = make_cleanup (xfree, filename);
15774 fp = gdb_fopen (filename, "w");
15776 error (_("Unable to open file '%s' for saving (%s)"),
15777 filename, safe_strerror (errno));
15778 make_cleanup_ui_file_delete (fp);
15780 if (extra_trace_bits)
15781 save_trace_state_variables (fp);
15783 ALL_BREAKPOINTS (tp)
15785 /* Skip internal and momentary breakpoints. */
15786 if (!user_breakpoint_p (tp))
15789 /* If we have a filter, only save the breakpoints it accepts. */
15790 if (filter && !filter (tp))
15793 tp->ops->print_recreate (tp, fp);
15795 /* Note, we can't rely on tp->number for anything, as we can't
15796 assume the recreated breakpoint numbers will match. Use $bpnum
15799 if (tp->cond_string)
15800 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15802 if (tp->ignore_count)
15803 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15805 if (tp->type != bp_dprintf && tp->commands)
15807 fprintf_unfiltered (fp, " commands\n");
15809 ui_out_redirect (current_uiout, fp);
15812 print_command_lines (current_uiout, tp->commands->commands, 2);
15814 CATCH (ex, RETURN_MASK_ALL)
15816 ui_out_redirect (current_uiout, NULL);
15817 throw_exception (ex);
15821 ui_out_redirect (current_uiout, NULL);
15822 fprintf_unfiltered (fp, " end\n");
15825 if (tp->enable_state == bp_disabled)
15826 fprintf_unfiltered (fp, "disable $bpnum\n");
15828 /* If this is a multi-location breakpoint, check if the locations
15829 should be individually disabled. Watchpoint locations are
15830 special, and not user visible. */
15831 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15833 struct bp_location *loc;
15836 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15838 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15842 if (extra_trace_bits && *default_collect)
15843 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15846 printf_filtered (_("Saved to file '%s'.\n"), filename);
15847 do_cleanups (cleanup);
15850 /* The `save breakpoints' command. */
15853 save_breakpoints_command (char *args, int from_tty)
15855 save_breakpoints (args, from_tty, NULL);
15858 /* The `save tracepoints' command. */
15861 save_tracepoints_command (char *args, int from_tty)
15863 save_breakpoints (args, from_tty, is_tracepoint);
15866 /* Create a vector of all tracepoints. */
15868 VEC(breakpoint_p) *
15869 all_tracepoints (void)
15871 VEC(breakpoint_p) *tp_vec = 0;
15872 struct breakpoint *tp;
15874 ALL_TRACEPOINTS (tp)
15876 VEC_safe_push (breakpoint_p, tp_vec, tp);
15883 /* This help string is used to consolidate all the help string for specifying
15884 locations used by several commands. */
15886 #define LOCATION_HELP_STRING \
15887 "Linespecs are colon-separated lists of location parameters, such as\n\
15888 source filename, function name, label name, and line number.\n\
15889 Example: To specify the start of a label named \"the_top\" in the\n\
15890 function \"fact\" in the file \"factorial.c\", use\n\
15891 \"factorial.c:fact:the_top\".\n\
15893 Address locations begin with \"*\" and specify an exact address in the\n\
15894 program. Example: To specify the fourth byte past the start function\n\
15895 \"main\", use \"*main + 4\".\n\
15897 Explicit locations are similar to linespecs but use an option/argument\n\
15898 syntax to specify location parameters.\n\
15899 Example: To specify the start of the label named \"the_top\" in the\n\
15900 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15901 -function fact -label the_top\".\n"
15903 /* This help string is used for the break, hbreak, tbreak and thbreak
15904 commands. It is defined as a macro to prevent duplication.
15905 COMMAND should be a string constant containing the name of the
15908 #define BREAK_ARGS_HELP(command) \
15909 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15910 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15911 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15912 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15913 `-probe-dtrace' (for a DTrace probe).\n\
15914 LOCATION may be a linespec, address, or explicit location as described\n\
15917 With no LOCATION, uses current execution address of the selected\n\
15918 stack frame. This is useful for breaking on return to a stack frame.\n\
15920 THREADNUM is the number from \"info threads\".\n\
15921 CONDITION is a boolean expression.\n\
15922 \n" LOCATION_HELP_STRING "\n\
15923 Multiple breakpoints at one place are permitted, and useful if their\n\
15924 conditions are different.\n\
15926 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15928 /* List of subcommands for "catch". */
15929 static struct cmd_list_element *catch_cmdlist;
15931 /* List of subcommands for "tcatch". */
15932 static struct cmd_list_element *tcatch_cmdlist;
15935 add_catch_command (char *name, char *docstring,
15936 cmd_sfunc_ftype *sfunc,
15937 completer_ftype *completer,
15938 void *user_data_catch,
15939 void *user_data_tcatch)
15941 struct cmd_list_element *command;
15943 command = add_cmd (name, class_breakpoint, NULL, docstring,
15945 set_cmd_sfunc (command, sfunc);
15946 set_cmd_context (command, user_data_catch);
15947 set_cmd_completer (command, completer);
15949 command = add_cmd (name, class_breakpoint, NULL, docstring,
15951 set_cmd_sfunc (command, sfunc);
15952 set_cmd_context (command, user_data_tcatch);
15953 set_cmd_completer (command, completer);
15957 save_command (char *arg, int from_tty)
15959 printf_unfiltered (_("\"save\" must be followed by "
15960 "the name of a save subcommand.\n"));
15961 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15964 struct breakpoint *
15965 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15968 struct breakpoint *b, *b_tmp;
15970 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15972 if ((*callback) (b, data))
15979 /* Zero if any of the breakpoint's locations could be a location where
15980 functions have been inlined, nonzero otherwise. */
15983 is_non_inline_function (struct breakpoint *b)
15985 /* The shared library event breakpoint is set on the address of a
15986 non-inline function. */
15987 if (b->type == bp_shlib_event)
15993 /* Nonzero if the specified PC cannot be a location where functions
15994 have been inlined. */
15997 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15998 const struct target_waitstatus *ws)
16000 struct breakpoint *b;
16001 struct bp_location *bl;
16003 ALL_BREAKPOINTS (b)
16005 if (!is_non_inline_function (b))
16008 for (bl = b->loc; bl != NULL; bl = bl->next)
16010 if (!bl->shlib_disabled
16011 && bpstat_check_location (bl, aspace, pc, ws))
16019 /* Remove any references to OBJFILE which is going to be freed. */
16022 breakpoint_free_objfile (struct objfile *objfile)
16024 struct bp_location **locp, *loc;
16026 ALL_BP_LOCATIONS (loc, locp)
16027 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
16028 loc->symtab = NULL;
16032 initialize_breakpoint_ops (void)
16034 static int initialized = 0;
16036 struct breakpoint_ops *ops;
16042 /* The breakpoint_ops structure to be inherit by all kinds of
16043 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16044 internal and momentary breakpoints, etc.). */
16045 ops = &bkpt_base_breakpoint_ops;
16046 *ops = base_breakpoint_ops;
16047 ops->re_set = bkpt_re_set;
16048 ops->insert_location = bkpt_insert_location;
16049 ops->remove_location = bkpt_remove_location;
16050 ops->breakpoint_hit = bkpt_breakpoint_hit;
16051 ops->create_sals_from_location = bkpt_create_sals_from_location;
16052 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
16053 ops->decode_location = bkpt_decode_location;
16055 /* The breakpoint_ops structure to be used in regular breakpoints. */
16056 ops = &bkpt_breakpoint_ops;
16057 *ops = bkpt_base_breakpoint_ops;
16058 ops->re_set = bkpt_re_set;
16059 ops->resources_needed = bkpt_resources_needed;
16060 ops->print_it = bkpt_print_it;
16061 ops->print_mention = bkpt_print_mention;
16062 ops->print_recreate = bkpt_print_recreate;
16064 /* Ranged breakpoints. */
16065 ops = &ranged_breakpoint_ops;
16066 *ops = bkpt_breakpoint_ops;
16067 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16068 ops->resources_needed = resources_needed_ranged_breakpoint;
16069 ops->print_it = print_it_ranged_breakpoint;
16070 ops->print_one = print_one_ranged_breakpoint;
16071 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16072 ops->print_mention = print_mention_ranged_breakpoint;
16073 ops->print_recreate = print_recreate_ranged_breakpoint;
16075 /* Internal breakpoints. */
16076 ops = &internal_breakpoint_ops;
16077 *ops = bkpt_base_breakpoint_ops;
16078 ops->re_set = internal_bkpt_re_set;
16079 ops->check_status = internal_bkpt_check_status;
16080 ops->print_it = internal_bkpt_print_it;
16081 ops->print_mention = internal_bkpt_print_mention;
16083 /* Momentary breakpoints. */
16084 ops = &momentary_breakpoint_ops;
16085 *ops = bkpt_base_breakpoint_ops;
16086 ops->re_set = momentary_bkpt_re_set;
16087 ops->check_status = momentary_bkpt_check_status;
16088 ops->print_it = momentary_bkpt_print_it;
16089 ops->print_mention = momentary_bkpt_print_mention;
16091 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16092 ops = &longjmp_breakpoint_ops;
16093 *ops = momentary_breakpoint_ops;
16094 ops->dtor = longjmp_bkpt_dtor;
16096 /* Probe breakpoints. */
16097 ops = &bkpt_probe_breakpoint_ops;
16098 *ops = bkpt_breakpoint_ops;
16099 ops->insert_location = bkpt_probe_insert_location;
16100 ops->remove_location = bkpt_probe_remove_location;
16101 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
16102 ops->decode_location = bkpt_probe_decode_location;
16105 ops = &watchpoint_breakpoint_ops;
16106 *ops = base_breakpoint_ops;
16107 ops->dtor = dtor_watchpoint;
16108 ops->re_set = re_set_watchpoint;
16109 ops->insert_location = insert_watchpoint;
16110 ops->remove_location = remove_watchpoint;
16111 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16112 ops->check_status = check_status_watchpoint;
16113 ops->resources_needed = resources_needed_watchpoint;
16114 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16115 ops->print_it = print_it_watchpoint;
16116 ops->print_mention = print_mention_watchpoint;
16117 ops->print_recreate = print_recreate_watchpoint;
16118 ops->explains_signal = explains_signal_watchpoint;
16120 /* Masked watchpoints. */
16121 ops = &masked_watchpoint_breakpoint_ops;
16122 *ops = watchpoint_breakpoint_ops;
16123 ops->insert_location = insert_masked_watchpoint;
16124 ops->remove_location = remove_masked_watchpoint;
16125 ops->resources_needed = resources_needed_masked_watchpoint;
16126 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16127 ops->print_it = print_it_masked_watchpoint;
16128 ops->print_one_detail = print_one_detail_masked_watchpoint;
16129 ops->print_mention = print_mention_masked_watchpoint;
16130 ops->print_recreate = print_recreate_masked_watchpoint;
16133 ops = &tracepoint_breakpoint_ops;
16134 *ops = base_breakpoint_ops;
16135 ops->re_set = tracepoint_re_set;
16136 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16137 ops->print_one_detail = tracepoint_print_one_detail;
16138 ops->print_mention = tracepoint_print_mention;
16139 ops->print_recreate = tracepoint_print_recreate;
16140 ops->create_sals_from_location = tracepoint_create_sals_from_location;
16141 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16142 ops->decode_location = tracepoint_decode_location;
16144 /* Probe tracepoints. */
16145 ops = &tracepoint_probe_breakpoint_ops;
16146 *ops = tracepoint_breakpoint_ops;
16147 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
16148 ops->decode_location = tracepoint_probe_decode_location;
16150 /* Static tracepoints with marker (`-m'). */
16151 ops = &strace_marker_breakpoint_ops;
16152 *ops = tracepoint_breakpoint_ops;
16153 ops->create_sals_from_location = strace_marker_create_sals_from_location;
16154 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16155 ops->decode_location = strace_marker_decode_location;
16157 /* Fork catchpoints. */
16158 ops = &catch_fork_breakpoint_ops;
16159 *ops = base_breakpoint_ops;
16160 ops->insert_location = insert_catch_fork;
16161 ops->remove_location = remove_catch_fork;
16162 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16163 ops->print_it = print_it_catch_fork;
16164 ops->print_one = print_one_catch_fork;
16165 ops->print_mention = print_mention_catch_fork;
16166 ops->print_recreate = print_recreate_catch_fork;
16168 /* Vfork catchpoints. */
16169 ops = &catch_vfork_breakpoint_ops;
16170 *ops = base_breakpoint_ops;
16171 ops->insert_location = insert_catch_vfork;
16172 ops->remove_location = remove_catch_vfork;
16173 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16174 ops->print_it = print_it_catch_vfork;
16175 ops->print_one = print_one_catch_vfork;
16176 ops->print_mention = print_mention_catch_vfork;
16177 ops->print_recreate = print_recreate_catch_vfork;
16179 /* Exec catchpoints. */
16180 ops = &catch_exec_breakpoint_ops;
16181 *ops = base_breakpoint_ops;
16182 ops->dtor = dtor_catch_exec;
16183 ops->insert_location = insert_catch_exec;
16184 ops->remove_location = remove_catch_exec;
16185 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16186 ops->print_it = print_it_catch_exec;
16187 ops->print_one = print_one_catch_exec;
16188 ops->print_mention = print_mention_catch_exec;
16189 ops->print_recreate = print_recreate_catch_exec;
16191 /* Solib-related catchpoints. */
16192 ops = &catch_solib_breakpoint_ops;
16193 *ops = base_breakpoint_ops;
16194 ops->dtor = dtor_catch_solib;
16195 ops->insert_location = insert_catch_solib;
16196 ops->remove_location = remove_catch_solib;
16197 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16198 ops->check_status = check_status_catch_solib;
16199 ops->print_it = print_it_catch_solib;
16200 ops->print_one = print_one_catch_solib;
16201 ops->print_mention = print_mention_catch_solib;
16202 ops->print_recreate = print_recreate_catch_solib;
16204 ops = &dprintf_breakpoint_ops;
16205 *ops = bkpt_base_breakpoint_ops;
16206 ops->re_set = dprintf_re_set;
16207 ops->resources_needed = bkpt_resources_needed;
16208 ops->print_it = bkpt_print_it;
16209 ops->print_mention = bkpt_print_mention;
16210 ops->print_recreate = dprintf_print_recreate;
16211 ops->after_condition_true = dprintf_after_condition_true;
16212 ops->breakpoint_hit = dprintf_breakpoint_hit;
16215 /* Chain containing all defined "enable breakpoint" subcommands. */
16217 static struct cmd_list_element *enablebreaklist = NULL;
16220 _initialize_breakpoint (void)
16222 struct cmd_list_element *c;
16224 initialize_breakpoint_ops ();
16226 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16227 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16228 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16230 breakpoint_objfile_key
16231 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16233 breakpoint_chain = 0;
16234 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16235 before a breakpoint is set. */
16236 breakpoint_count = 0;
16238 tracepoint_count = 0;
16240 add_com ("ignore", class_breakpoint, ignore_command, _("\
16241 Set ignore-count of breakpoint number N to COUNT.\n\
16242 Usage is `ignore N COUNT'."));
16244 add_com ("commands", class_breakpoint, commands_command, _("\
16245 Set commands to be executed when a breakpoint is hit.\n\
16246 Give breakpoint number as argument after \"commands\".\n\
16247 With no argument, the targeted breakpoint is the last one set.\n\
16248 The commands themselves follow starting on the next line.\n\
16249 Type a line containing \"end\" to indicate the end of them.\n\
16250 Give \"silent\" as the first line to make the breakpoint silent;\n\
16251 then no output is printed when it is hit, except what the commands print."));
16253 c = add_com ("condition", class_breakpoint, condition_command, _("\
16254 Specify breakpoint number N to break only if COND is true.\n\
16255 Usage is `condition N COND', where N is an integer and COND is an\n\
16256 expression to be evaluated whenever breakpoint N is reached."));
16257 set_cmd_completer (c, condition_completer);
16259 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16260 Set a temporary breakpoint.\n\
16261 Like \"break\" except the breakpoint is only temporary,\n\
16262 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16263 by using \"enable delete\" on the breakpoint number.\n\
16265 BREAK_ARGS_HELP ("tbreak")));
16266 set_cmd_completer (c, location_completer);
16268 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16269 Set a hardware assisted breakpoint.\n\
16270 Like \"break\" except the breakpoint requires hardware support,\n\
16271 some target hardware may not have this support.\n\
16273 BREAK_ARGS_HELP ("hbreak")));
16274 set_cmd_completer (c, location_completer);
16276 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16277 Set a temporary hardware assisted breakpoint.\n\
16278 Like \"hbreak\" except the breakpoint is only temporary,\n\
16279 so it will be deleted when hit.\n\
16281 BREAK_ARGS_HELP ("thbreak")));
16282 set_cmd_completer (c, location_completer);
16284 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16285 Enable some breakpoints.\n\
16286 Give breakpoint numbers (separated by spaces) as arguments.\n\
16287 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16288 This is used to cancel the effect of the \"disable\" command.\n\
16289 With a subcommand you can enable temporarily."),
16290 &enablelist, "enable ", 1, &cmdlist);
16292 add_com_alias ("en", "enable", class_breakpoint, 1);
16294 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16295 Enable some breakpoints.\n\
16296 Give breakpoint numbers (separated by spaces) as arguments.\n\
16297 This is used to cancel the effect of the \"disable\" command.\n\
16298 May be abbreviated to simply \"enable\".\n"),
16299 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16301 add_cmd ("once", no_class, enable_once_command, _("\
16302 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16303 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16306 add_cmd ("delete", no_class, enable_delete_command, _("\
16307 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16308 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16311 add_cmd ("count", no_class, enable_count_command, _("\
16312 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16313 If a breakpoint is hit while enabled in this fashion,\n\
16314 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16317 add_cmd ("delete", no_class, enable_delete_command, _("\
16318 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16319 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16322 add_cmd ("once", no_class, enable_once_command, _("\
16323 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16324 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16327 add_cmd ("count", no_class, enable_count_command, _("\
16328 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16329 If a breakpoint is hit while enabled in this fashion,\n\
16330 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16333 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16334 Disable some breakpoints.\n\
16335 Arguments are breakpoint numbers with spaces in between.\n\
16336 To disable all breakpoints, give no argument.\n\
16337 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16338 &disablelist, "disable ", 1, &cmdlist);
16339 add_com_alias ("dis", "disable", class_breakpoint, 1);
16340 add_com_alias ("disa", "disable", class_breakpoint, 1);
16342 add_cmd ("breakpoints", class_alias, disable_command, _("\
16343 Disable some breakpoints.\n\
16344 Arguments are breakpoint numbers with spaces in between.\n\
16345 To disable all breakpoints, give no argument.\n\
16346 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16347 This command may be abbreviated \"disable\"."),
16350 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16351 Delete some breakpoints or auto-display expressions.\n\
16352 Arguments are breakpoint numbers with spaces in between.\n\
16353 To delete all breakpoints, give no argument.\n\
16355 Also a prefix command for deletion of other GDB objects.\n\
16356 The \"unset\" command is also an alias for \"delete\"."),
16357 &deletelist, "delete ", 1, &cmdlist);
16358 add_com_alias ("d", "delete", class_breakpoint, 1);
16359 add_com_alias ("del", "delete", class_breakpoint, 1);
16361 add_cmd ("breakpoints", class_alias, delete_command, _("\
16362 Delete some breakpoints or auto-display expressions.\n\
16363 Arguments are breakpoint numbers with spaces in between.\n\
16364 To delete all breakpoints, give no argument.\n\
16365 This command may be abbreviated \"delete\"."),
16368 add_com ("clear", class_breakpoint, clear_command, _("\
16369 Clear breakpoint at specified location.\n\
16370 Argument may be a linespec, explicit, or address location as described below.\n\
16372 With no argument, clears all breakpoints in the line that the selected frame\n\
16373 is executing in.\n"
16374 "\n" LOCATION_HELP_STRING "\n\
16375 See also the \"delete\" command which clears breakpoints by number."));
16376 add_com_alias ("cl", "clear", class_breakpoint, 1);
16378 c = add_com ("break", class_breakpoint, break_command, _("\
16379 Set breakpoint at specified location.\n"
16380 BREAK_ARGS_HELP ("break")));
16381 set_cmd_completer (c, location_completer);
16383 add_com_alias ("b", "break", class_run, 1);
16384 add_com_alias ("br", "break", class_run, 1);
16385 add_com_alias ("bre", "break", class_run, 1);
16386 add_com_alias ("brea", "break", class_run, 1);
16390 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16391 Break in function/address or break at a line in the current file."),
16392 &stoplist, "stop ", 1, &cmdlist);
16393 add_cmd ("in", class_breakpoint, stopin_command,
16394 _("Break in function or address."), &stoplist);
16395 add_cmd ("at", class_breakpoint, stopat_command,
16396 _("Break at a line in the current file."), &stoplist);
16397 add_com ("status", class_info, breakpoints_info, _("\
16398 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16399 The \"Type\" column indicates one of:\n\
16400 \tbreakpoint - normal breakpoint\n\
16401 \twatchpoint - watchpoint\n\
16402 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16403 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16404 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16405 address and file/line number respectively.\n\
16407 Convenience variable \"$_\" and default examine address for \"x\"\n\
16408 are set to the address of the last breakpoint listed unless the command\n\
16409 is prefixed with \"server \".\n\n\
16410 Convenience variable \"$bpnum\" contains the number of the last\n\
16411 breakpoint set."));
16414 add_info ("breakpoints", breakpoints_info, _("\
16415 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16416 The \"Type\" column indicates one of:\n\
16417 \tbreakpoint - normal breakpoint\n\
16418 \twatchpoint - watchpoint\n\
16419 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16420 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16421 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16422 address and file/line number respectively.\n\
16424 Convenience variable \"$_\" and default examine address for \"x\"\n\
16425 are set to the address of the last breakpoint listed unless the command\n\
16426 is prefixed with \"server \".\n\n\
16427 Convenience variable \"$bpnum\" contains the number of the last\n\
16428 breakpoint set."));
16430 add_info_alias ("b", "breakpoints", 1);
16432 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16433 Status of all breakpoints, or breakpoint number NUMBER.\n\
16434 The \"Type\" column indicates one of:\n\
16435 \tbreakpoint - normal breakpoint\n\
16436 \twatchpoint - watchpoint\n\
16437 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16438 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16439 \tuntil - internal breakpoint used by the \"until\" command\n\
16440 \tfinish - internal breakpoint used by the \"finish\" command\n\
16441 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16442 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16443 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16444 address and file/line number respectively.\n\
16446 Convenience variable \"$_\" and default examine address for \"x\"\n\
16447 are set to the address of the last breakpoint listed unless the command\n\
16448 is prefixed with \"server \".\n\n\
16449 Convenience variable \"$bpnum\" contains the number of the last\n\
16451 &maintenanceinfolist);
16453 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16454 Set catchpoints to catch events."),
16455 &catch_cmdlist, "catch ",
16456 0/*allow-unknown*/, &cmdlist);
16458 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16459 Set temporary catchpoints to catch events."),
16460 &tcatch_cmdlist, "tcatch ",
16461 0/*allow-unknown*/, &cmdlist);
16463 add_catch_command ("fork", _("Catch calls to fork."),
16464 catch_fork_command_1,
16466 (void *) (uintptr_t) catch_fork_permanent,
16467 (void *) (uintptr_t) catch_fork_temporary);
16468 add_catch_command ("vfork", _("Catch calls to vfork."),
16469 catch_fork_command_1,
16471 (void *) (uintptr_t) catch_vfork_permanent,
16472 (void *) (uintptr_t) catch_vfork_temporary);
16473 add_catch_command ("exec", _("Catch calls to exec."),
16474 catch_exec_command_1,
16478 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16479 Usage: catch load [REGEX]\n\
16480 If REGEX is given, only stop for libraries matching the regular expression."),
16481 catch_load_command_1,
16485 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16486 Usage: catch unload [REGEX]\n\
16487 If REGEX is given, only stop for libraries matching the regular expression."),
16488 catch_unload_command_1,
16493 c = add_com ("watch", class_breakpoint, watch_command, _("\
16494 Set a watchpoint for an expression.\n\
16495 Usage: watch [-l|-location] EXPRESSION\n\
16496 A watchpoint stops execution of your program whenever the value of\n\
16497 an expression changes.\n\
16498 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16499 the memory to which it refers."));
16500 set_cmd_completer (c, expression_completer);
16502 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16503 Set a read watchpoint for an expression.\n\
16504 Usage: rwatch [-l|-location] EXPRESSION\n\
16505 A watchpoint stops execution of your program whenever the value of\n\
16506 an expression is read.\n\
16507 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16508 the memory to which it refers."));
16509 set_cmd_completer (c, expression_completer);
16511 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16512 Set a watchpoint for an expression.\n\
16513 Usage: awatch [-l|-location] EXPRESSION\n\
16514 A watchpoint stops execution of your program whenever the value of\n\
16515 an expression is either read or written.\n\
16516 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16517 the memory to which it refers."));
16518 set_cmd_completer (c, expression_completer);
16520 add_info ("watchpoints", watchpoints_info, _("\
16521 Status of specified watchpoints (all watchpoints if no argument)."));
16523 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16524 respond to changes - contrary to the description. */
16525 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16526 &can_use_hw_watchpoints, _("\
16527 Set debugger's willingness to use watchpoint hardware."), _("\
16528 Show debugger's willingness to use watchpoint hardware."), _("\
16529 If zero, gdb will not use hardware for new watchpoints, even if\n\
16530 such is available. (However, any hardware watchpoints that were\n\
16531 created before setting this to nonzero, will continue to use watchpoint\n\
16534 show_can_use_hw_watchpoints,
16535 &setlist, &showlist);
16537 can_use_hw_watchpoints = 1;
16539 /* Tracepoint manipulation commands. */
16541 c = add_com ("trace", class_breakpoint, trace_command, _("\
16542 Set a tracepoint at specified location.\n\
16544 BREAK_ARGS_HELP ("trace") "\n\
16545 Do \"help tracepoints\" for info on other tracepoint commands."));
16546 set_cmd_completer (c, location_completer);
16548 add_com_alias ("tp", "trace", class_alias, 0);
16549 add_com_alias ("tr", "trace", class_alias, 1);
16550 add_com_alias ("tra", "trace", class_alias, 1);
16551 add_com_alias ("trac", "trace", class_alias, 1);
16553 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16554 Set a fast tracepoint at specified location.\n\
16556 BREAK_ARGS_HELP ("ftrace") "\n\
16557 Do \"help tracepoints\" for info on other tracepoint commands."));
16558 set_cmd_completer (c, location_completer);
16560 c = add_com ("strace", class_breakpoint, strace_command, _("\
16561 Set a static tracepoint at location or marker.\n\
16563 strace [LOCATION] [if CONDITION]\n\
16564 LOCATION may be a linespec, explicit, or address location (described below) \n\
16565 or -m MARKER_ID.\n\n\
16566 If a marker id is specified, probe the marker with that name. With\n\
16567 no LOCATION, uses current execution address of the selected stack frame.\n\
16568 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16569 This collects arbitrary user data passed in the probe point call to the\n\
16570 tracing library. You can inspect it when analyzing the trace buffer,\n\
16571 by printing the $_sdata variable like any other convenience variable.\n\
16573 CONDITION is a boolean expression.\n\
16574 \n" LOCATION_HELP_STRING "\n\
16575 Multiple tracepoints at one place are permitted, and useful if their\n\
16576 conditions are different.\n\
16578 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16579 Do \"help tracepoints\" for info on other tracepoint commands."));
16580 set_cmd_completer (c, location_completer);
16582 add_info ("tracepoints", tracepoints_info, _("\
16583 Status of specified tracepoints (all tracepoints if no argument).\n\
16584 Convenience variable \"$tpnum\" contains the number of the\n\
16585 last tracepoint set."));
16587 add_info_alias ("tp", "tracepoints", 1);
16589 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16590 Delete specified tracepoints.\n\
16591 Arguments are tracepoint numbers, separated by spaces.\n\
16592 No argument means delete all tracepoints."),
16594 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16596 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16597 Disable specified tracepoints.\n\
16598 Arguments are tracepoint numbers, separated by spaces.\n\
16599 No argument means disable all tracepoints."),
16601 deprecate_cmd (c, "disable");
16603 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16604 Enable specified tracepoints.\n\
16605 Arguments are tracepoint numbers, separated by spaces.\n\
16606 No argument means enable all tracepoints."),
16608 deprecate_cmd (c, "enable");
16610 add_com ("passcount", class_trace, trace_pass_command, _("\
16611 Set the passcount for a tracepoint.\n\
16612 The trace will end when the tracepoint has been passed 'count' times.\n\
16613 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16614 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16616 add_prefix_cmd ("save", class_breakpoint, save_command,
16617 _("Save breakpoint definitions as a script."),
16618 &save_cmdlist, "save ",
16619 0/*allow-unknown*/, &cmdlist);
16621 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16622 Save current breakpoint definitions as a script.\n\
16623 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16624 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16625 session to restore them."),
16627 set_cmd_completer (c, filename_completer);
16629 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16630 Save current tracepoint definitions as a script.\n\
16631 Use the 'source' command in another debug session to restore them."),
16633 set_cmd_completer (c, filename_completer);
16635 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16636 deprecate_cmd (c, "save tracepoints");
16638 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16639 Breakpoint specific settings\n\
16640 Configure various breakpoint-specific variables such as\n\
16641 pending breakpoint behavior"),
16642 &breakpoint_set_cmdlist, "set breakpoint ",
16643 0/*allow-unknown*/, &setlist);
16644 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16645 Breakpoint specific settings\n\
16646 Configure various breakpoint-specific variables such as\n\
16647 pending breakpoint behavior"),
16648 &breakpoint_show_cmdlist, "show breakpoint ",
16649 0/*allow-unknown*/, &showlist);
16651 add_setshow_auto_boolean_cmd ("pending", no_class,
16652 &pending_break_support, _("\
16653 Set debugger's behavior regarding pending breakpoints."), _("\
16654 Show debugger's behavior regarding pending breakpoints."), _("\
16655 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16656 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16657 an error. If auto, an unrecognized breakpoint location results in a\n\
16658 user-query to see if a pending breakpoint should be created."),
16660 show_pending_break_support,
16661 &breakpoint_set_cmdlist,
16662 &breakpoint_show_cmdlist);
16664 pending_break_support = AUTO_BOOLEAN_AUTO;
16666 add_setshow_boolean_cmd ("auto-hw", no_class,
16667 &automatic_hardware_breakpoints, _("\
16668 Set automatic usage of hardware breakpoints."), _("\
16669 Show automatic usage of hardware breakpoints."), _("\
16670 If set, the debugger will automatically use hardware breakpoints for\n\
16671 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16672 a warning will be emitted for such breakpoints."),
16674 show_automatic_hardware_breakpoints,
16675 &breakpoint_set_cmdlist,
16676 &breakpoint_show_cmdlist);
16678 add_setshow_boolean_cmd ("always-inserted", class_support,
16679 &always_inserted_mode, _("\
16680 Set mode for inserting breakpoints."), _("\
16681 Show mode for inserting breakpoints."), _("\
16682 When this mode is on, breakpoints are inserted immediately as soon as\n\
16683 they're created, kept inserted even when execution stops, and removed\n\
16684 only when the user deletes them. When this mode is off (the default),\n\
16685 breakpoints are inserted only when execution continues, and removed\n\
16686 when execution stops."),
16688 &show_always_inserted_mode,
16689 &breakpoint_set_cmdlist,
16690 &breakpoint_show_cmdlist);
16692 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16693 condition_evaluation_enums,
16694 &condition_evaluation_mode_1, _("\
16695 Set mode of breakpoint condition evaluation."), _("\
16696 Show mode of breakpoint condition evaluation."), _("\
16697 When this is set to \"host\", breakpoint conditions will be\n\
16698 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16699 breakpoint conditions will be downloaded to the target (if the target\n\
16700 supports such feature) and conditions will be evaluated on the target's side.\n\
16701 If this is set to \"auto\" (default), this will be automatically set to\n\
16702 \"target\" if it supports condition evaluation, otherwise it will\n\
16703 be set to \"gdb\""),
16704 &set_condition_evaluation_mode,
16705 &show_condition_evaluation_mode,
16706 &breakpoint_set_cmdlist,
16707 &breakpoint_show_cmdlist);
16709 add_com ("break-range", class_breakpoint, break_range_command, _("\
16710 Set a breakpoint for an address range.\n\
16711 break-range START-LOCATION, END-LOCATION\n\
16712 where START-LOCATION and END-LOCATION can be one of the following:\n\
16713 LINENUM, for that line in the current file,\n\
16714 FILE:LINENUM, for that line in that file,\n\
16715 +OFFSET, for that number of lines after the current line\n\
16716 or the start of the range\n\
16717 FUNCTION, for the first line in that function,\n\
16718 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16719 *ADDRESS, for the instruction at that address.\n\
16721 The breakpoint will stop execution of the inferior whenever it executes\n\
16722 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16723 range (including START-LOCATION and END-LOCATION)."));
16725 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16726 Set a dynamic printf at specified location.\n\
16727 dprintf location,format string,arg1,arg2,...\n\
16728 location may be a linespec, explicit, or address location.\n"
16729 "\n" LOCATION_HELP_STRING));
16730 set_cmd_completer (c, location_completer);
16732 add_setshow_enum_cmd ("dprintf-style", class_support,
16733 dprintf_style_enums, &dprintf_style, _("\
16734 Set the style of usage for dynamic printf."), _("\
16735 Show the style of usage for dynamic printf."), _("\
16736 This setting chooses how GDB will do a dynamic printf.\n\
16737 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16738 console, as with the \"printf\" command.\n\
16739 If the value is \"call\", the print is done by calling a function in your\n\
16740 program; by default printf(), but you can choose a different function or\n\
16741 output stream by setting dprintf-function and dprintf-channel."),
16742 update_dprintf_commands, NULL,
16743 &setlist, &showlist);
16745 dprintf_function = xstrdup ("printf");
16746 add_setshow_string_cmd ("dprintf-function", class_support,
16747 &dprintf_function, _("\
16748 Set the function to use for dynamic printf"), _("\
16749 Show the function to use for dynamic printf"), NULL,
16750 update_dprintf_commands, NULL,
16751 &setlist, &showlist);
16753 dprintf_channel = xstrdup ("");
16754 add_setshow_string_cmd ("dprintf-channel", class_support,
16755 &dprintf_channel, _("\
16756 Set the channel to use for dynamic printf"), _("\
16757 Show the channel to use for dynamic printf"), NULL,
16758 update_dprintf_commands, NULL,
16759 &setlist, &showlist);
16761 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16762 &disconnected_dprintf, _("\
16763 Set whether dprintf continues after GDB disconnects."), _("\
16764 Show whether dprintf continues after GDB disconnects."), _("\
16765 Use this to let dprintf commands continue to hit and produce output\n\
16766 even if GDB disconnects or detaches from the target."),
16769 &setlist, &showlist);
16771 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16772 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16773 (target agent only) This is useful for formatted output in user-defined commands."));
16775 automatic_hardware_breakpoints = 1;
16777 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16778 observer_attach_thread_exit (remove_threaded_breakpoints);