1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
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;
984 w->cond_exp.reset ();
988 struct bp_location *loc;
990 for (loc = b->loc; loc; loc = loc->next)
994 /* No need to free the condition agent expression
995 bytecode (if we have one). We will handle this
996 when we go through update_global_location_list. */
1003 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
1007 const char *arg = exp;
1009 /* I don't know if it matters whether this is the string the user
1010 typed in or the decompiled expression. */
1011 b->cond_string = xstrdup (arg);
1012 b->condition_not_parsed = 0;
1014 if (is_watchpoint (b))
1016 struct watchpoint *w = (struct watchpoint *) b;
1018 innermost_block = NULL;
1020 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1022 error (_("Junk at end of expression"));
1023 w->cond_exp_valid_block = innermost_block;
1027 struct bp_location *loc;
1029 for (loc = b->loc; loc; loc = loc->next)
1033 parse_exp_1 (&arg, loc->address,
1034 block_for_pc (loc->address), 0);
1036 error (_("Junk at end of expression"));
1040 mark_breakpoint_modified (b);
1042 observer_notify_breakpoint_modified (b);
1045 /* Completion for the "condition" command. */
1047 static VEC (char_ptr) *
1048 condition_completer (struct cmd_list_element *cmd,
1049 const char *text, const char *word)
1053 text = skip_spaces_const (text);
1054 space = skip_to_space_const (text);
1058 struct breakpoint *b;
1059 VEC (char_ptr) *result = NULL;
1063 /* We don't support completion of history indices. */
1064 if (isdigit (text[1]))
1066 return complete_internalvar (&text[1]);
1069 /* We're completing the breakpoint number. */
1070 len = strlen (text);
1076 xsnprintf (number, sizeof (number), "%d", b->number);
1078 if (strncmp (number, text, len) == 0)
1079 VEC_safe_push (char_ptr, result, xstrdup (number));
1085 /* We're completing the expression part. */
1086 text = skip_spaces_const (space);
1087 return expression_completer (cmd, text, word);
1090 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1093 condition_command (char *arg, int from_tty)
1095 struct breakpoint *b;
1100 error_no_arg (_("breakpoint number"));
1103 bnum = get_number (&p);
1105 error (_("Bad breakpoint argument: '%s'"), arg);
1108 if (b->number == bnum)
1110 /* Check if this breakpoint has a "stop" method implemented in an
1111 extension language. This method and conditions entered into GDB
1112 from the CLI are mutually exclusive. */
1113 const struct extension_language_defn *extlang
1114 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1116 if (extlang != NULL)
1118 error (_("Only one stop condition allowed. There is currently"
1119 " a %s stop condition defined for this breakpoint."),
1120 ext_lang_capitalized_name (extlang));
1122 set_breakpoint_condition (b, p, from_tty);
1124 if (is_breakpoint (b))
1125 update_global_location_list (UGLL_MAY_INSERT);
1130 error (_("No breakpoint number %d."), bnum);
1133 /* Check that COMMAND do not contain commands that are suitable
1134 only for tracepoints and not suitable for ordinary breakpoints.
1135 Throw if any such commands is found. */
1138 check_no_tracepoint_commands (struct command_line *commands)
1140 struct command_line *c;
1142 for (c = commands; c; c = c->next)
1146 if (c->control_type == while_stepping_control)
1147 error (_("The 'while-stepping' command can "
1148 "only be used for tracepoints"));
1150 for (i = 0; i < c->body_count; ++i)
1151 check_no_tracepoint_commands ((c->body_list)[i]);
1153 /* Not that command parsing removes leading whitespace and comment
1154 lines and also empty lines. So, we only need to check for
1155 command directly. */
1156 if (strstr (c->line, "collect ") == c->line)
1157 error (_("The 'collect' command can only be used for tracepoints"));
1159 if (strstr (c->line, "teval ") == c->line)
1160 error (_("The 'teval' command can only be used for tracepoints"));
1164 /* Encapsulate tests for different types of tracepoints. */
1167 is_tracepoint_type (enum bptype type)
1169 return (type == bp_tracepoint
1170 || type == bp_fast_tracepoint
1171 || type == bp_static_tracepoint);
1175 is_tracepoint (const struct breakpoint *b)
1177 return is_tracepoint_type (b->type);
1180 /* A helper function that validates that COMMANDS are valid for a
1181 breakpoint. This function will throw an exception if a problem is
1185 validate_commands_for_breakpoint (struct breakpoint *b,
1186 struct command_line *commands)
1188 if (is_tracepoint (b))
1190 struct tracepoint *t = (struct tracepoint *) b;
1191 struct command_line *c;
1192 struct command_line *while_stepping = 0;
1194 /* Reset the while-stepping step count. The previous commands
1195 might have included a while-stepping action, while the new
1199 /* We need to verify that each top-level element of commands is
1200 valid for tracepoints, that there's at most one
1201 while-stepping element, and that the while-stepping's body
1202 has valid tracing commands excluding nested while-stepping.
1203 We also need to validate the tracepoint action line in the
1204 context of the tracepoint --- validate_actionline actually
1205 has side effects, like setting the tracepoint's
1206 while-stepping STEP_COUNT, in addition to checking if the
1207 collect/teval actions parse and make sense in the
1208 tracepoint's context. */
1209 for (c = commands; c; c = c->next)
1211 if (c->control_type == while_stepping_control)
1213 if (b->type == bp_fast_tracepoint)
1214 error (_("The 'while-stepping' command "
1215 "cannot be used for fast tracepoint"));
1216 else if (b->type == bp_static_tracepoint)
1217 error (_("The 'while-stepping' command "
1218 "cannot be used for static tracepoint"));
1221 error (_("The 'while-stepping' command "
1222 "can be used only once"));
1227 validate_actionline (c->line, b);
1231 struct command_line *c2;
1233 gdb_assert (while_stepping->body_count == 1);
1234 c2 = while_stepping->body_list[0];
1235 for (; c2; c2 = c2->next)
1237 if (c2->control_type == while_stepping_control)
1238 error (_("The 'while-stepping' command cannot be nested"));
1244 check_no_tracepoint_commands (commands);
1248 /* Return a vector of all the static tracepoints set at ADDR. The
1249 caller is responsible for releasing the vector. */
1252 static_tracepoints_here (CORE_ADDR addr)
1254 struct breakpoint *b;
1255 VEC(breakpoint_p) *found = 0;
1256 struct bp_location *loc;
1259 if (b->type == bp_static_tracepoint)
1261 for (loc = b->loc; loc; loc = loc->next)
1262 if (loc->address == addr)
1263 VEC_safe_push(breakpoint_p, found, b);
1269 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1270 validate that only allowed commands are included. */
1273 breakpoint_set_commands (struct breakpoint *b,
1274 struct command_line *commands)
1276 validate_commands_for_breakpoint (b, commands);
1278 decref_counted_command_line (&b->commands);
1279 b->commands = alloc_counted_command_line (commands);
1280 observer_notify_breakpoint_modified (b);
1283 /* Set the internal `silent' flag on the breakpoint. Note that this
1284 is not the same as the "silent" that may appear in the breakpoint's
1288 breakpoint_set_silent (struct breakpoint *b, int silent)
1290 int old_silent = b->silent;
1293 if (old_silent != silent)
1294 observer_notify_breakpoint_modified (b);
1297 /* Set the thread for this breakpoint. If THREAD is -1, make the
1298 breakpoint work for any thread. */
1301 breakpoint_set_thread (struct breakpoint *b, int thread)
1303 int old_thread = b->thread;
1306 if (old_thread != thread)
1307 observer_notify_breakpoint_modified (b);
1310 /* Set the task for this breakpoint. If TASK is 0, make the
1311 breakpoint work for any task. */
1314 breakpoint_set_task (struct breakpoint *b, int task)
1316 int old_task = b->task;
1319 if (old_task != task)
1320 observer_notify_breakpoint_modified (b);
1324 check_tracepoint_command (char *line, void *closure)
1326 struct breakpoint *b = (struct breakpoint *) closure;
1328 validate_actionline (line, b);
1331 /* A structure used to pass information through
1332 map_breakpoint_numbers. */
1334 struct commands_info
1336 /* True if the command was typed at a tty. */
1339 /* The breakpoint range spec. */
1342 /* Non-NULL if the body of the commands are being read from this
1343 already-parsed command. */
1344 struct command_line *control;
1346 /* The command lines read from the user, or NULL if they have not
1348 struct counted_command_line *cmd;
1351 /* A callback for map_breakpoint_numbers that sets the commands for
1352 commands_command. */
1355 do_map_commands_command (struct breakpoint *b, void *data)
1357 struct commands_info *info = (struct commands_info *) data;
1359 if (info->cmd == NULL)
1361 struct command_line *l;
1363 if (info->control != NULL)
1364 l = copy_command_lines (info->control->body_list[0]);
1367 struct cleanup *old_chain;
1370 str = xstrprintf (_("Type commands for breakpoint(s) "
1371 "%s, one per line."),
1374 old_chain = make_cleanup (xfree, str);
1376 l = read_command_lines (str,
1379 ? check_tracepoint_command : 0),
1382 do_cleanups (old_chain);
1385 info->cmd = alloc_counted_command_line (l);
1388 /* If a breakpoint was on the list more than once, we don't need to
1390 if (b->commands != info->cmd)
1392 validate_commands_for_breakpoint (b, info->cmd->commands);
1393 incref_counted_command_line (info->cmd);
1394 decref_counted_command_line (&b->commands);
1395 b->commands = info->cmd;
1396 observer_notify_breakpoint_modified (b);
1401 commands_command_1 (const char *arg, int from_tty,
1402 struct command_line *control)
1404 struct cleanup *cleanups;
1405 struct commands_info info;
1407 info.from_tty = from_tty;
1408 info.control = control;
1410 /* If we read command lines from the user, then `info' will hold an
1411 extra reference to the commands that we must clean up. */
1412 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1414 std::string new_arg;
1416 if (arg == NULL || !*arg)
1418 if (breakpoint_count - prev_breakpoint_count > 1)
1419 new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
1421 else if (breakpoint_count > 0)
1422 new_arg = string_printf ("%d", breakpoint_count);
1427 info.arg = new_arg.c_str ();
1429 map_breakpoint_numbers (info.arg, do_map_commands_command, &info);
1431 if (info.cmd == NULL)
1432 error (_("No breakpoints specified."));
1434 do_cleanups (cleanups);
1438 commands_command (char *arg, int from_tty)
1440 commands_command_1 (arg, from_tty, NULL);
1443 /* Like commands_command, but instead of reading the commands from
1444 input stream, takes them from an already parsed command structure.
1446 This is used by cli-script.c to DTRT with breakpoint commands
1447 that are part of if and while bodies. */
1448 enum command_control_type
1449 commands_from_control_command (const char *arg, struct command_line *cmd)
1451 commands_command_1 (arg, 0, cmd);
1452 return simple_control;
1455 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1458 bp_location_has_shadow (struct bp_location *bl)
1460 if (bl->loc_type != bp_loc_software_breakpoint)
1464 if (bl->target_info.shadow_len == 0)
1465 /* BL isn't valid, or doesn't shadow memory. */
1470 /* Update BUF, which is LEN bytes read from the target address
1471 MEMADDR, by replacing a memory breakpoint with its shadowed
1474 If READBUF is not NULL, this buffer must not overlap with the of
1475 the breakpoint location's shadow_contents buffer. Otherwise, a
1476 failed assertion internal error will be raised. */
1479 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1480 const gdb_byte *writebuf_org,
1481 ULONGEST memaddr, LONGEST len,
1482 struct bp_target_info *target_info,
1483 struct gdbarch *gdbarch)
1485 /* Now do full processing of the found relevant range of elements. */
1486 CORE_ADDR bp_addr = 0;
1490 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1491 current_program_space->aspace, 0))
1493 /* The breakpoint is inserted in a different address space. */
1497 /* Addresses and length of the part of the breakpoint that
1499 bp_addr = target_info->placed_address;
1500 bp_size = target_info->shadow_len;
1502 if (bp_addr + bp_size <= memaddr)
1504 /* The breakpoint is entirely before the chunk of memory we are
1509 if (bp_addr >= memaddr + len)
1511 /* The breakpoint is entirely after the chunk of memory we are
1516 /* Offset within shadow_contents. */
1517 if (bp_addr < memaddr)
1519 /* Only copy the second part of the breakpoint. */
1520 bp_size -= memaddr - bp_addr;
1521 bptoffset = memaddr - bp_addr;
1525 if (bp_addr + bp_size > memaddr + len)
1527 /* Only copy the first part of the breakpoint. */
1528 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1531 if (readbuf != NULL)
1533 /* Verify that the readbuf buffer does not overlap with the
1534 shadow_contents buffer. */
1535 gdb_assert (target_info->shadow_contents >= readbuf + len
1536 || readbuf >= (target_info->shadow_contents
1537 + target_info->shadow_len));
1539 /* Update the read buffer with this inserted breakpoint's
1541 memcpy (readbuf + bp_addr - memaddr,
1542 target_info->shadow_contents + bptoffset, bp_size);
1546 const unsigned char *bp;
1547 CORE_ADDR addr = target_info->reqstd_address;
1550 /* Update the shadow with what we want to write to memory. */
1551 memcpy (target_info->shadow_contents + bptoffset,
1552 writebuf_org + bp_addr - memaddr, bp_size);
1554 /* Determine appropriate breakpoint contents and size for this
1556 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1558 /* Update the final write buffer with this inserted
1559 breakpoint's INSN. */
1560 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1564 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1565 by replacing any memory breakpoints with their shadowed contents.
1567 If READBUF is not NULL, this buffer must not overlap with any of
1568 the breakpoint location's shadow_contents buffers. Otherwise,
1569 a failed assertion internal error will be raised.
1571 The range of shadowed area by each bp_location is:
1572 bl->address - bp_location_placed_address_before_address_max
1573 up to bl->address + bp_location_shadow_len_after_address_max
1574 The range we were requested to resolve shadows for is:
1575 memaddr ... memaddr + len
1576 Thus the safe cutoff boundaries for performance optimization are
1577 memaddr + len <= (bl->address
1578 - bp_location_placed_address_before_address_max)
1580 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1583 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1584 const gdb_byte *writebuf_org,
1585 ULONGEST memaddr, LONGEST len)
1587 /* Left boundary, right boundary and median element of our binary
1589 unsigned bc_l, bc_r, bc;
1591 /* Find BC_L which is a leftmost element which may affect BUF
1592 content. It is safe to report lower value but a failure to
1593 report higher one. */
1596 bc_r = bp_location_count;
1597 while (bc_l + 1 < bc_r)
1599 struct bp_location *bl;
1601 bc = (bc_l + bc_r) / 2;
1602 bl = bp_location[bc];
1604 /* Check first BL->ADDRESS will not overflow due to the added
1605 constant. Then advance the left boundary only if we are sure
1606 the BC element can in no way affect the BUF content (MEMADDR
1607 to MEMADDR + LEN range).
1609 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1610 offset so that we cannot miss a breakpoint with its shadow
1611 range tail still reaching MEMADDR. */
1613 if ((bl->address + bp_location_shadow_len_after_address_max
1615 && (bl->address + bp_location_shadow_len_after_address_max
1622 /* Due to the binary search above, we need to make sure we pick the
1623 first location that's at BC_L's address. E.g., if there are
1624 multiple locations at the same address, BC_L may end up pointing
1625 at a duplicate location, and miss the "master"/"inserted"
1626 location. Say, given locations L1, L2 and L3 at addresses A and
1629 L1@A, L2@A, L3@B, ...
1631 BC_L could end up pointing at location L2, while the "master"
1632 location could be L1. Since the `loc->inserted' flag is only set
1633 on "master" locations, we'd forget to restore the shadow of L1
1636 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1639 /* Now do full processing of the found relevant range of elements. */
1641 for (bc = bc_l; bc < bp_location_count; bc++)
1643 struct bp_location *bl = bp_location[bc];
1645 /* bp_location array has BL->OWNER always non-NULL. */
1646 if (bl->owner->type == bp_none)
1647 warning (_("reading through apparently deleted breakpoint #%d?"),
1650 /* Performance optimization: any further element can no longer affect BUF
1653 if (bl->address >= bp_location_placed_address_before_address_max
1654 && memaddr + len <= (bl->address
1655 - bp_location_placed_address_before_address_max))
1658 if (!bp_location_has_shadow (bl))
1661 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1662 memaddr, len, &bl->target_info, bl->gdbarch);
1668 /* Return true if BPT is either a software breakpoint or a hardware
1672 is_breakpoint (const struct breakpoint *bpt)
1674 return (bpt->type == bp_breakpoint
1675 || bpt->type == bp_hardware_breakpoint
1676 || bpt->type == bp_dprintf);
1679 /* Return true if BPT is of any hardware watchpoint kind. */
1682 is_hardware_watchpoint (const struct breakpoint *bpt)
1684 return (bpt->type == bp_hardware_watchpoint
1685 || bpt->type == bp_read_watchpoint
1686 || bpt->type == bp_access_watchpoint);
1689 /* Return true if BPT is of any watchpoint kind, hardware or
1693 is_watchpoint (const struct breakpoint *bpt)
1695 return (is_hardware_watchpoint (bpt)
1696 || bpt->type == bp_watchpoint);
1699 /* Returns true if the current thread and its running state are safe
1700 to evaluate or update watchpoint B. Watchpoints on local
1701 expressions need to be evaluated in the context of the thread that
1702 was current when the watchpoint was created, and, that thread needs
1703 to be stopped to be able to select the correct frame context.
1704 Watchpoints on global expressions can be evaluated on any thread,
1705 and in any state. It is presently left to the target allowing
1706 memory accesses when threads are running. */
1709 watchpoint_in_thread_scope (struct watchpoint *b)
1711 return (b->base.pspace == current_program_space
1712 && (ptid_equal (b->watchpoint_thread, null_ptid)
1713 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1714 && !is_executing (inferior_ptid))));
1717 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1718 associated bp_watchpoint_scope breakpoint. */
1721 watchpoint_del_at_next_stop (struct watchpoint *w)
1723 struct breakpoint *b = &w->base;
1725 if (b->related_breakpoint != b)
1727 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1728 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1729 b->related_breakpoint->disposition = disp_del_at_next_stop;
1730 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1731 b->related_breakpoint = b;
1733 b->disposition = disp_del_at_next_stop;
1736 /* Extract a bitfield value from value VAL using the bit parameters contained in
1739 static struct value *
1740 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1742 struct value *bit_val;
1747 bit_val = allocate_value (value_type (val));
1749 unpack_value_bitfield (bit_val,
1752 value_contents_for_printing (val),
1759 /* Allocate a dummy location and add it to B, which must be a software
1760 watchpoint. This is required because even if a software watchpoint
1761 is not watching any memory, bpstat_stop_status requires a location
1762 to be able to report stops. */
1765 software_watchpoint_add_no_memory_location (struct breakpoint *b,
1766 struct program_space *pspace)
1768 gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
1770 b->loc = allocate_bp_location (b);
1771 b->loc->pspace = pspace;
1772 b->loc->address = -1;
1773 b->loc->length = -1;
1776 /* Returns true if B is a software watchpoint that is not watching any
1777 memory (e.g., "watch $pc"). */
1780 is_no_memory_software_watchpoint (struct breakpoint *b)
1782 return (b->type == bp_watchpoint
1784 && b->loc->next == NULL
1785 && b->loc->address == -1
1786 && b->loc->length == -1);
1789 /* Assuming that B is a watchpoint:
1790 - Reparse watchpoint expression, if REPARSE is non-zero
1791 - Evaluate expression and store the result in B->val
1792 - Evaluate the condition if there is one, and store the result
1794 - Update the list of values that must be watched in B->loc.
1796 If the watchpoint disposition is disp_del_at_next_stop, then do
1797 nothing. If this is local watchpoint that is out of scope, delete
1800 Even with `set breakpoint always-inserted on' the watchpoints are
1801 removed + inserted on each stop here. Normal breakpoints must
1802 never be removed because they might be missed by a running thread
1803 when debugging in non-stop mode. On the other hand, hardware
1804 watchpoints (is_hardware_watchpoint; processed here) are specific
1805 to each LWP since they are stored in each LWP's hardware debug
1806 registers. Therefore, such LWP must be stopped first in order to
1807 be able to modify its hardware watchpoints.
1809 Hardware watchpoints must be reset exactly once after being
1810 presented to the user. It cannot be done sooner, because it would
1811 reset the data used to present the watchpoint hit to the user. And
1812 it must not be done later because it could display the same single
1813 watchpoint hit during multiple GDB stops. Note that the latter is
1814 relevant only to the hardware watchpoint types bp_read_watchpoint
1815 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1816 not user-visible - its hit is suppressed if the memory content has
1819 The following constraints influence the location where we can reset
1820 hardware watchpoints:
1822 * target_stopped_by_watchpoint and target_stopped_data_address are
1823 called several times when GDB stops.
1826 * Multiple hardware watchpoints can be hit at the same time,
1827 causing GDB to stop. GDB only presents one hardware watchpoint
1828 hit at a time as the reason for stopping, and all the other hits
1829 are presented later, one after the other, each time the user
1830 requests the execution to be resumed. Execution is not resumed
1831 for the threads still having pending hit event stored in
1832 LWP_INFO->STATUS. While the watchpoint is already removed from
1833 the inferior on the first stop the thread hit event is kept being
1834 reported from its cached value by linux_nat_stopped_data_address
1835 until the real thread resume happens after the watchpoint gets
1836 presented and thus its LWP_INFO->STATUS gets reset.
1838 Therefore the hardware watchpoint hit can get safely reset on the
1839 watchpoint removal from inferior. */
1842 update_watchpoint (struct watchpoint *b, int reparse)
1844 int within_current_scope;
1845 struct frame_id saved_frame_id;
1848 /* If this is a local watchpoint, we only want to check if the
1849 watchpoint frame is in scope if the current thread is the thread
1850 that was used to create the watchpoint. */
1851 if (!watchpoint_in_thread_scope (b))
1854 if (b->base.disposition == disp_del_at_next_stop)
1859 /* Determine if the watchpoint is within scope. */
1860 if (b->exp_valid_block == NULL)
1861 within_current_scope = 1;
1864 struct frame_info *fi = get_current_frame ();
1865 struct gdbarch *frame_arch = get_frame_arch (fi);
1866 CORE_ADDR frame_pc = get_frame_pc (fi);
1868 /* If we're at a point where the stack has been destroyed
1869 (e.g. in a function epilogue), unwinding may not work
1870 properly. Do not attempt to recreate locations at this
1871 point. See similar comments in watchpoint_check. */
1872 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1875 /* Save the current frame's ID so we can restore it after
1876 evaluating the watchpoint expression on its own frame. */
1877 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1878 took a frame parameter, so that we didn't have to change the
1881 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1883 fi = frame_find_by_id (b->watchpoint_frame);
1884 within_current_scope = (fi != NULL);
1885 if (within_current_scope)
1889 /* We don't free locations. They are stored in the bp_location array
1890 and update_global_location_list will eventually delete them and
1891 remove breakpoints if needed. */
1894 if (within_current_scope && reparse)
1899 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1900 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1901 /* If the meaning of expression itself changed, the old value is
1902 no longer relevant. We don't want to report a watchpoint hit
1903 to the user when the old value and the new value may actually
1904 be completely different objects. */
1905 value_free (b->val);
1909 /* Note that unlike with breakpoints, the watchpoint's condition
1910 expression is stored in the breakpoint object, not in the
1911 locations (re)created below. */
1912 if (b->base.cond_string != NULL)
1914 b->cond_exp.reset ();
1916 s = b->base.cond_string;
1917 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1921 /* If we failed to parse the expression, for example because
1922 it refers to a global variable in a not-yet-loaded shared library,
1923 don't try to insert watchpoint. We don't automatically delete
1924 such watchpoint, though, since failure to parse expression
1925 is different from out-of-scope watchpoint. */
1926 if (!target_has_execution)
1928 /* Without execution, memory can't change. No use to try and
1929 set watchpoint locations. The watchpoint will be reset when
1930 the target gains execution, through breakpoint_re_set. */
1931 if (!can_use_hw_watchpoints)
1933 if (b->base.ops->works_in_software_mode (&b->base))
1934 b->base.type = bp_watchpoint;
1936 error (_("Can't set read/access watchpoint when "
1937 "hardware watchpoints are disabled."));
1940 else if (within_current_scope && b->exp)
1943 struct value *val_chain, *v, *result, *next;
1944 struct program_space *frame_pspace;
1946 fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0);
1948 /* Avoid setting b->val if it's already set. The meaning of
1949 b->val is 'the last value' user saw, and we should update
1950 it only if we reported that last value to user. As it
1951 happens, the code that reports it updates b->val directly.
1952 We don't keep track of the memory value for masked
1954 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1956 if (b->val_bitsize != 0)
1958 v = extract_bitfield_from_watchpoint_value (b, v);
1966 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1968 /* Look at each value on the value chain. */
1969 for (v = val_chain; v; v = value_next (v))
1971 /* If it's a memory location, and GDB actually needed
1972 its contents to evaluate the expression, then we
1973 must watch it. If the first value returned is
1974 still lazy, that means an error occurred reading it;
1975 watch it anyway in case it becomes readable. */
1976 if (VALUE_LVAL (v) == lval_memory
1977 && (v == val_chain || ! value_lazy (v)))
1979 struct type *vtype = check_typedef (value_type (v));
1981 /* We only watch structs and arrays if user asked
1982 for it explicitly, never if they just happen to
1983 appear in the middle of some value chain. */
1985 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1986 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1989 enum target_hw_bp_type type;
1990 struct bp_location *loc, **tmp;
1991 int bitpos = 0, bitsize = 0;
1993 if (value_bitsize (v) != 0)
1995 /* Extract the bit parameters out from the bitfield
1997 bitpos = value_bitpos (v);
1998 bitsize = value_bitsize (v);
2000 else if (v == result && b->val_bitsize != 0)
2002 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2003 lvalue whose bit parameters are saved in the fields
2004 VAL_BITPOS and VAL_BITSIZE. */
2005 bitpos = b->val_bitpos;
2006 bitsize = b->val_bitsize;
2009 addr = value_address (v);
2012 /* Skip the bytes that don't contain the bitfield. */
2017 if (b->base.type == bp_read_watchpoint)
2019 else if (b->base.type == bp_access_watchpoint)
2022 loc = allocate_bp_location (&b->base);
2023 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
2026 loc->gdbarch = get_type_arch (value_type (v));
2028 loc->pspace = frame_pspace;
2029 loc->address = addr;
2033 /* Just cover the bytes that make up the bitfield. */
2034 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2037 loc->length = TYPE_LENGTH (value_type (v));
2039 loc->watchpoint_type = type;
2044 /* Change the type of breakpoint between hardware assisted or
2045 an ordinary watchpoint depending on the hardware support
2046 and free hardware slots. REPARSE is set when the inferior
2051 enum bp_loc_type loc_type;
2052 struct bp_location *bl;
2054 reg_cnt = can_use_hardware_watchpoint (val_chain);
2058 int i, target_resources_ok, other_type_used;
2061 /* Use an exact watchpoint when there's only one memory region to be
2062 watched, and only one debug register is needed to watch it. */
2063 b->exact = target_exact_watchpoints && reg_cnt == 1;
2065 /* We need to determine how many resources are already
2066 used for all other hardware watchpoints plus this one
2067 to see if we still have enough resources to also fit
2068 this watchpoint in as well. */
2070 /* If this is a software watchpoint, we try to turn it
2071 to a hardware one -- count resources as if B was of
2072 hardware watchpoint type. */
2073 type = b->base.type;
2074 if (type == bp_watchpoint)
2075 type = bp_hardware_watchpoint;
2077 /* This watchpoint may or may not have been placed on
2078 the list yet at this point (it won't be in the list
2079 if we're trying to create it for the first time,
2080 through watch_command), so always account for it
2083 /* Count resources used by all watchpoints except B. */
2084 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2086 /* Add in the resources needed for B. */
2087 i += hw_watchpoint_use_count (&b->base);
2090 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2091 if (target_resources_ok <= 0)
2093 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2095 if (target_resources_ok == 0 && !sw_mode)
2096 error (_("Target does not support this type of "
2097 "hardware watchpoint."));
2098 else if (target_resources_ok < 0 && !sw_mode)
2099 error (_("There are not enough available hardware "
2100 "resources for this watchpoint."));
2102 /* Downgrade to software watchpoint. */
2103 b->base.type = bp_watchpoint;
2107 /* If this was a software watchpoint, we've just
2108 found we have enough resources to turn it to a
2109 hardware watchpoint. Otherwise, this is a
2111 b->base.type = type;
2114 else if (!b->base.ops->works_in_software_mode (&b->base))
2116 if (!can_use_hw_watchpoints)
2117 error (_("Can't set read/access watchpoint when "
2118 "hardware watchpoints are disabled."));
2120 error (_("Expression cannot be implemented with "
2121 "read/access watchpoint."));
2124 b->base.type = bp_watchpoint;
2126 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2127 : bp_loc_hardware_watchpoint);
2128 for (bl = b->base.loc; bl; bl = bl->next)
2129 bl->loc_type = loc_type;
2132 for (v = val_chain; v; v = next)
2134 next = value_next (v);
2139 /* If a software watchpoint is not watching any memory, then the
2140 above left it without any location set up. But,
2141 bpstat_stop_status requires a location to be able to report
2142 stops, so make sure there's at least a dummy one. */
2143 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2144 software_watchpoint_add_no_memory_location (&b->base, frame_pspace);
2146 else if (!within_current_scope)
2148 printf_filtered (_("\
2149 Watchpoint %d deleted because the program has left the block\n\
2150 in which its expression is valid.\n"),
2152 watchpoint_del_at_next_stop (b);
2155 /* Restore the selected frame. */
2157 select_frame (frame_find_by_id (saved_frame_id));
2161 /* Returns 1 iff breakpoint location should be
2162 inserted in the inferior. We don't differentiate the type of BL's owner
2163 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2164 breakpoint_ops is not defined, because in insert_bp_location,
2165 tracepoint's insert_location will not be called. */
2167 should_be_inserted (struct bp_location *bl)
2169 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2172 if (bl->owner->disposition == disp_del_at_next_stop)
2175 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2178 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2181 /* This is set for example, when we're attached to the parent of a
2182 vfork, and have detached from the child. The child is running
2183 free, and we expect it to do an exec or exit, at which point the
2184 OS makes the parent schedulable again (and the target reports
2185 that the vfork is done). Until the child is done with the shared
2186 memory region, do not insert breakpoints in the parent, otherwise
2187 the child could still trip on the parent's breakpoints. Since
2188 the parent is blocked anyway, it won't miss any breakpoint. */
2189 if (bl->pspace->breakpoints_not_allowed)
2192 /* Don't insert a breakpoint if we're trying to step past its
2193 location, except if the breakpoint is a single-step breakpoint,
2194 and the breakpoint's thread is the thread which is stepping past
2196 if ((bl->loc_type == bp_loc_software_breakpoint
2197 || bl->loc_type == bp_loc_hardware_breakpoint)
2198 && stepping_past_instruction_at (bl->pspace->aspace,
2200 /* The single-step breakpoint may be inserted at the location
2201 we're trying to step if the instruction branches to itself.
2202 However, the instruction won't be executed at all and it may
2203 break the semantics of the instruction, for example, the
2204 instruction is a conditional branch or updates some flags.
2205 We can't fix it unless GDB is able to emulate the instruction
2206 or switch to displaced stepping. */
2207 && !(bl->owner->type == bp_single_step
2208 && thread_is_stepping_over_breakpoint (bl->owner->thread)))
2212 fprintf_unfiltered (gdb_stdlog,
2213 "infrun: skipping breakpoint: "
2214 "stepping past insn at: %s\n",
2215 paddress (bl->gdbarch, bl->address));
2220 /* Don't insert watchpoints if we're trying to step past the
2221 instruction that triggered one. */
2222 if ((bl->loc_type == bp_loc_hardware_watchpoint)
2223 && stepping_past_nonsteppable_watchpoint ())
2227 fprintf_unfiltered (gdb_stdlog,
2228 "infrun: stepping past non-steppable watchpoint. "
2229 "skipping watchpoint at %s:%d\n",
2230 paddress (bl->gdbarch, bl->address),
2239 /* Same as should_be_inserted but does the check assuming
2240 that the location is not duplicated. */
2243 unduplicated_should_be_inserted (struct bp_location *bl)
2246 const int save_duplicate = bl->duplicate;
2249 result = should_be_inserted (bl);
2250 bl->duplicate = save_duplicate;
2254 /* Parses a conditional described by an expression COND into an
2255 agent expression bytecode suitable for evaluation
2256 by the bytecode interpreter. Return NULL if there was
2257 any error during parsing. */
2259 static agent_expr_up
2260 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2265 agent_expr_up aexpr;
2267 /* We don't want to stop processing, so catch any errors
2268 that may show up. */
2271 aexpr = gen_eval_for_expr (scope, cond);
2274 CATCH (ex, RETURN_MASK_ERROR)
2276 /* If we got here, it means the condition could not be parsed to a valid
2277 bytecode expression and thus can't be evaluated on the target's side.
2278 It's no use iterating through the conditions. */
2282 /* We have a valid agent expression. */
2286 /* Based on location BL, create a list of breakpoint conditions to be
2287 passed on to the target. If we have duplicated locations with different
2288 conditions, we will add such conditions to the list. The idea is that the
2289 target will evaluate the list of conditions and will only notify GDB when
2290 one of them is true. */
2293 build_target_condition_list (struct bp_location *bl)
2295 struct bp_location **locp = NULL, **loc2p;
2296 int null_condition_or_parse_error = 0;
2297 int modified = bl->needs_update;
2298 struct bp_location *loc;
2300 /* Release conditions left over from a previous insert. */
2301 bl->target_info.conditions.clear ();
2303 /* This is only meaningful if the target is
2304 evaluating conditions and if the user has
2305 opted for condition evaluation on the target's
2307 if (gdb_evaluates_breakpoint_condition_p ()
2308 || !target_supports_evaluation_of_breakpoint_conditions ())
2311 /* Do a first pass to check for locations with no assigned
2312 conditions or conditions that fail to parse to a valid agent expression
2313 bytecode. If any of these happen, then it's no use to send conditions
2314 to the target since this location will always trigger and generate a
2315 response back to GDB. */
2316 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2319 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2323 /* Re-parse the conditions since something changed. In that
2324 case we already freed the condition bytecodes (see
2325 force_breakpoint_reinsertion). We just
2326 need to parse the condition to bytecodes again. */
2327 loc->cond_bytecode = parse_cond_to_aexpr (bl->address,
2331 /* If we have a NULL bytecode expression, it means something
2332 went wrong or we have a null condition expression. */
2333 if (!loc->cond_bytecode)
2335 null_condition_or_parse_error = 1;
2341 /* If any of these happened, it means we will have to evaluate the conditions
2342 for the location's address on gdb's side. It is no use keeping bytecodes
2343 for all the other duplicate locations, thus we free all of them here.
2345 This is so we have a finer control over which locations' conditions are
2346 being evaluated by GDB or the remote stub. */
2347 if (null_condition_or_parse_error)
2349 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2352 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2354 /* Only go as far as the first NULL bytecode is
2356 if (!loc->cond_bytecode)
2359 loc->cond_bytecode.reset ();
2364 /* No NULL conditions or failed bytecode generation. Build a condition list
2365 for this location's address. */
2366 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2370 && is_breakpoint (loc->owner)
2371 && loc->pspace->num == bl->pspace->num
2372 && loc->owner->enable_state == bp_enabled
2375 /* Add the condition to the vector. This will be used later
2376 to send the conditions to the target. */
2377 bl->target_info.conditions.push_back (loc->cond_bytecode.get ());
2384 /* Parses a command described by string CMD into an agent expression
2385 bytecode suitable for evaluation by the bytecode interpreter.
2386 Return NULL if there was any error during parsing. */
2388 static agent_expr_up
2389 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2391 struct cleanup *old_cleanups = 0;
2392 struct expression **argvec;
2393 const char *cmdrest;
2394 const char *format_start, *format_end;
2395 struct format_piece *fpieces;
2397 struct gdbarch *gdbarch = get_current_arch ();
2404 if (*cmdrest == ',')
2406 cmdrest = skip_spaces_const (cmdrest);
2408 if (*cmdrest++ != '"')
2409 error (_("No format string following the location"));
2411 format_start = cmdrest;
2413 fpieces = parse_format_string (&cmdrest);
2415 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2417 format_end = cmdrest;
2419 if (*cmdrest++ != '"')
2420 error (_("Bad format string, non-terminated '\"'."));
2422 cmdrest = skip_spaces_const (cmdrest);
2424 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2425 error (_("Invalid argument syntax"));
2427 if (*cmdrest == ',')
2429 cmdrest = skip_spaces_const (cmdrest);
2431 /* For each argument, make an expression. */
2433 argvec = (struct expression **) alloca (strlen (cmd)
2434 * sizeof (struct expression *));
2437 while (*cmdrest != '\0')
2442 expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2443 argvec[nargs++] = expr.release ();
2445 if (*cmdrest == ',')
2449 agent_expr_up aexpr;
2451 /* We don't want to stop processing, so catch any errors
2452 that may show up. */
2455 aexpr = gen_printf (scope, gdbarch, 0, 0,
2456 format_start, format_end - format_start,
2457 fpieces, nargs, argvec);
2459 CATCH (ex, RETURN_MASK_ERROR)
2461 /* If we got here, it means the command could not be parsed to a valid
2462 bytecode expression and thus can't be evaluated on the target's side.
2463 It's no use iterating through the other commands. */
2467 do_cleanups (old_cleanups);
2469 /* We have a valid agent expression, return it. */
2473 /* Based on location BL, create a list of breakpoint commands to be
2474 passed on to the target. If we have duplicated locations with
2475 different commands, we will add any such to the list. */
2478 build_target_command_list (struct bp_location *bl)
2480 struct bp_location **locp = NULL, **loc2p;
2481 int null_command_or_parse_error = 0;
2482 int modified = bl->needs_update;
2483 struct bp_location *loc;
2485 /* Clear commands left over from a previous insert. */
2486 bl->target_info.tcommands.clear ();
2488 if (!target_can_run_breakpoint_commands ())
2491 /* For now, limit to agent-style dprintf breakpoints. */
2492 if (dprintf_style != dprintf_style_agent)
2495 /* For now, if we have any duplicate location that isn't a dprintf,
2496 don't install the target-side commands, as that would make the
2497 breakpoint not be reported to the core, and we'd lose
2499 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2502 if (is_breakpoint (loc->owner)
2503 && loc->pspace->num == bl->pspace->num
2504 && loc->owner->type != bp_dprintf)
2508 /* Do a first pass to check for locations with no assigned
2509 conditions or conditions that fail to parse to a valid agent expression
2510 bytecode. If any of these happen, then it's no use to send conditions
2511 to the target since this location will always trigger and generate a
2512 response back to GDB. */
2513 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2516 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2520 /* Re-parse the commands since something changed. In that
2521 case we already freed the command bytecodes (see
2522 force_breakpoint_reinsertion). We just
2523 need to parse the command to bytecodes again. */
2525 = parse_cmd_to_aexpr (bl->address,
2526 loc->owner->extra_string);
2529 /* If we have a NULL bytecode expression, it means something
2530 went wrong or we have a null command expression. */
2531 if (!loc->cmd_bytecode)
2533 null_command_or_parse_error = 1;
2539 /* If anything failed, then we're not doing target-side commands,
2541 if (null_command_or_parse_error)
2543 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2546 if (is_breakpoint (loc->owner)
2547 && loc->pspace->num == bl->pspace->num)
2549 /* Only go as far as the first NULL bytecode is
2551 if (loc->cmd_bytecode == NULL)
2554 loc->cmd_bytecode.reset ();
2559 /* No NULL commands or failed bytecode generation. Build a command list
2560 for this location's address. */
2561 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2564 if (loc->owner->extra_string
2565 && is_breakpoint (loc->owner)
2566 && loc->pspace->num == bl->pspace->num
2567 && loc->owner->enable_state == bp_enabled
2570 /* Add the command to the vector. This will be used later
2571 to send the commands to the target. */
2572 bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ());
2576 bl->target_info.persist = 0;
2577 /* Maybe flag this location as persistent. */
2578 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2579 bl->target_info.persist = 1;
2582 /* Return the kind of breakpoint on address *ADDR. Get the kind
2583 of breakpoint according to ADDR except single-step breakpoint.
2584 Get the kind of single-step breakpoint according to the current
2588 breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
2590 if (bl->owner->type == bp_single_step)
2592 struct thread_info *thr = find_thread_global_id (bl->owner->thread);
2593 struct regcache *regcache;
2595 regcache = get_thread_regcache (thr->ptid);
2597 return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
2601 return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
2604 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2605 location. Any error messages are printed to TMP_ERROR_STREAM; and
2606 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2607 Returns 0 for success, 1 if the bp_location type is not supported or
2610 NOTE drow/2003-09-09: This routine could be broken down to an
2611 object-style method for each breakpoint or catchpoint type. */
2613 insert_bp_location (struct bp_location *bl,
2614 struct ui_file *tmp_error_stream,
2615 int *disabled_breaks,
2616 int *hw_breakpoint_error,
2617 int *hw_bp_error_explained_already)
2619 enum errors bp_err = GDB_NO_ERROR;
2620 const char *bp_err_message = NULL;
2622 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2625 /* Note we don't initialize bl->target_info, as that wipes out
2626 the breakpoint location's shadow_contents if the breakpoint
2627 is still inserted at that location. This in turn breaks
2628 target_read_memory which depends on these buffers when
2629 a memory read is requested at the breakpoint location:
2630 Once the target_info has been wiped, we fail to see that
2631 we have a breakpoint inserted at that address and thus
2632 read the breakpoint instead of returning the data saved in
2633 the breakpoint location's shadow contents. */
2634 bl->target_info.reqstd_address = bl->address;
2635 bl->target_info.placed_address_space = bl->pspace->aspace;
2636 bl->target_info.length = bl->length;
2638 /* When working with target-side conditions, we must pass all the conditions
2639 for the same breakpoint address down to the target since GDB will not
2640 insert those locations. With a list of breakpoint conditions, the target
2641 can decide when to stop and notify GDB. */
2643 if (is_breakpoint (bl->owner))
2645 build_target_condition_list (bl);
2646 build_target_command_list (bl);
2647 /* Reset the modification marker. */
2648 bl->needs_update = 0;
2651 if (bl->loc_type == bp_loc_software_breakpoint
2652 || bl->loc_type == bp_loc_hardware_breakpoint)
2654 if (bl->owner->type != bp_hardware_breakpoint)
2656 /* If the explicitly specified breakpoint type
2657 is not hardware breakpoint, check the memory map to see
2658 if the breakpoint address is in read only memory or not.
2660 Two important cases are:
2661 - location type is not hardware breakpoint, memory
2662 is readonly. We change the type of the location to
2663 hardware breakpoint.
2664 - location type is hardware breakpoint, memory is
2665 read-write. This means we've previously made the
2666 location hardware one, but then the memory map changed,
2669 When breakpoints are removed, remove_breakpoints will use
2670 location types we've just set here, the only possible
2671 problem is that memory map has changed during running
2672 program, but it's not going to work anyway with current
2674 struct mem_region *mr
2675 = lookup_mem_region (bl->target_info.reqstd_address);
2679 if (automatic_hardware_breakpoints)
2681 enum bp_loc_type new_type;
2683 if (mr->attrib.mode != MEM_RW)
2684 new_type = bp_loc_hardware_breakpoint;
2686 new_type = bp_loc_software_breakpoint;
2688 if (new_type != bl->loc_type)
2690 static int said = 0;
2692 bl->loc_type = new_type;
2695 fprintf_filtered (gdb_stdout,
2696 _("Note: automatically using "
2697 "hardware breakpoints for "
2698 "read-only addresses.\n"));
2703 else if (bl->loc_type == bp_loc_software_breakpoint
2704 && mr->attrib.mode != MEM_RW)
2706 fprintf_unfiltered (tmp_error_stream,
2707 _("Cannot insert breakpoint %d.\n"
2708 "Cannot set software breakpoint "
2709 "at read-only address %s\n"),
2711 paddress (bl->gdbarch, bl->address));
2717 /* First check to see if we have to handle an overlay. */
2718 if (overlay_debugging == ovly_off
2719 || bl->section == NULL
2720 || !(section_is_overlay (bl->section)))
2722 /* No overlay handling: just set the breakpoint. */
2727 val = bl->owner->ops->insert_location (bl);
2729 bp_err = GENERIC_ERROR;
2731 CATCH (e, RETURN_MASK_ALL)
2734 bp_err_message = e.message;
2740 /* This breakpoint is in an overlay section.
2741 Shall we set a breakpoint at the LMA? */
2742 if (!overlay_events_enabled)
2744 /* Yes -- overlay event support is not active,
2745 so we must try to set a breakpoint at the LMA.
2746 This will not work for a hardware breakpoint. */
2747 if (bl->loc_type == bp_loc_hardware_breakpoint)
2748 warning (_("hardware breakpoint %d not supported in overlay!"),
2752 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2754 /* Set a software (trap) breakpoint at the LMA. */
2755 bl->overlay_target_info = bl->target_info;
2756 bl->overlay_target_info.reqstd_address = addr;
2758 /* No overlay handling: just set the breakpoint. */
2763 bl->overlay_target_info.kind
2764 = breakpoint_kind (bl, &addr);
2765 bl->overlay_target_info.placed_address = addr;
2766 val = target_insert_breakpoint (bl->gdbarch,
2767 &bl->overlay_target_info);
2769 bp_err = GENERIC_ERROR;
2771 CATCH (e, RETURN_MASK_ALL)
2774 bp_err_message = e.message;
2778 if (bp_err != GDB_NO_ERROR)
2779 fprintf_unfiltered (tmp_error_stream,
2780 "Overlay breakpoint %d "
2781 "failed: in ROM?\n",
2785 /* Shall we set a breakpoint at the VMA? */
2786 if (section_is_mapped (bl->section))
2788 /* Yes. This overlay section is mapped into memory. */
2793 val = bl->owner->ops->insert_location (bl);
2795 bp_err = GENERIC_ERROR;
2797 CATCH (e, RETURN_MASK_ALL)
2800 bp_err_message = e.message;
2806 /* No. This breakpoint will not be inserted.
2807 No error, but do not mark the bp as 'inserted'. */
2812 if (bp_err != GDB_NO_ERROR)
2814 /* Can't set the breakpoint. */
2816 /* In some cases, we might not be able to insert a
2817 breakpoint in a shared library that has already been
2818 removed, but we have not yet processed the shlib unload
2819 event. Unfortunately, some targets that implement
2820 breakpoint insertion themselves can't tell why the
2821 breakpoint insertion failed (e.g., the remote target
2822 doesn't define error codes), so we must treat generic
2823 errors as memory errors. */
2824 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2825 && bl->loc_type == bp_loc_software_breakpoint
2826 && (solib_name_from_address (bl->pspace, bl->address)
2827 || shared_objfile_contains_address_p (bl->pspace,
2830 /* See also: disable_breakpoints_in_shlibs. */
2831 bl->shlib_disabled = 1;
2832 observer_notify_breakpoint_modified (bl->owner);
2833 if (!*disabled_breaks)
2835 fprintf_unfiltered (tmp_error_stream,
2836 "Cannot insert breakpoint %d.\n",
2838 fprintf_unfiltered (tmp_error_stream,
2839 "Temporarily disabling shared "
2840 "library breakpoints:\n");
2842 *disabled_breaks = 1;
2843 fprintf_unfiltered (tmp_error_stream,
2844 "breakpoint #%d\n", bl->owner->number);
2849 if (bl->loc_type == bp_loc_hardware_breakpoint)
2851 *hw_breakpoint_error = 1;
2852 *hw_bp_error_explained_already = bp_err_message != NULL;
2853 fprintf_unfiltered (tmp_error_stream,
2854 "Cannot insert hardware breakpoint %d%s",
2855 bl->owner->number, bp_err_message ? ":" : ".\n");
2856 if (bp_err_message != NULL)
2857 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2861 if (bp_err_message == NULL)
2864 = memory_error_message (TARGET_XFER_E_IO,
2865 bl->gdbarch, bl->address);
2866 struct cleanup *old_chain = make_cleanup (xfree, message);
2868 fprintf_unfiltered (tmp_error_stream,
2869 "Cannot insert breakpoint %d.\n"
2871 bl->owner->number, message);
2872 do_cleanups (old_chain);
2876 fprintf_unfiltered (tmp_error_stream,
2877 "Cannot insert breakpoint %d: %s\n",
2892 else if (bl->loc_type == bp_loc_hardware_watchpoint
2893 /* NOTE drow/2003-09-08: This state only exists for removing
2894 watchpoints. It's not clear that it's necessary... */
2895 && bl->owner->disposition != disp_del_at_next_stop)
2899 gdb_assert (bl->owner->ops != NULL
2900 && bl->owner->ops->insert_location != NULL);
2902 val = bl->owner->ops->insert_location (bl);
2904 /* If trying to set a read-watchpoint, and it turns out it's not
2905 supported, try emulating one with an access watchpoint. */
2906 if (val == 1 && bl->watchpoint_type == hw_read)
2908 struct bp_location *loc, **loc_temp;
2910 /* But don't try to insert it, if there's already another
2911 hw_access location that would be considered a duplicate
2913 ALL_BP_LOCATIONS (loc, loc_temp)
2915 && loc->watchpoint_type == hw_access
2916 && watchpoint_locations_match (bl, loc))
2920 bl->target_info = loc->target_info;
2921 bl->watchpoint_type = hw_access;
2928 bl->watchpoint_type = hw_access;
2929 val = bl->owner->ops->insert_location (bl);
2932 /* Back to the original value. */
2933 bl->watchpoint_type = hw_read;
2937 bl->inserted = (val == 0);
2940 else if (bl->owner->type == bp_catchpoint)
2944 gdb_assert (bl->owner->ops != NULL
2945 && bl->owner->ops->insert_location != NULL);
2947 val = bl->owner->ops->insert_location (bl);
2950 bl->owner->enable_state = bp_disabled;
2954 Error inserting catchpoint %d: Your system does not support this type\n\
2955 of catchpoint."), bl->owner->number);
2957 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2960 bl->inserted = (val == 0);
2962 /* We've already printed an error message if there was a problem
2963 inserting this catchpoint, and we've disabled the catchpoint,
2964 so just return success. */
2971 /* This function is called when program space PSPACE is about to be
2972 deleted. It takes care of updating breakpoints to not reference
2976 breakpoint_program_space_exit (struct program_space *pspace)
2978 struct breakpoint *b, *b_temp;
2979 struct bp_location *loc, **loc_temp;
2981 /* Remove any breakpoint that was set through this program space. */
2982 ALL_BREAKPOINTS_SAFE (b, b_temp)
2984 if (b->pspace == pspace)
2985 delete_breakpoint (b);
2988 /* Breakpoints set through other program spaces could have locations
2989 bound to PSPACE as well. Remove those. */
2990 ALL_BP_LOCATIONS (loc, loc_temp)
2992 struct bp_location *tmp;
2994 if (loc->pspace == pspace)
2996 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2997 if (loc->owner->loc == loc)
2998 loc->owner->loc = loc->next;
3000 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
3001 if (tmp->next == loc)
3003 tmp->next = loc->next;
3009 /* Now update the global location list to permanently delete the
3010 removed locations above. */
3011 update_global_location_list (UGLL_DONT_INSERT);
3014 /* Make sure all breakpoints are inserted in inferior.
3015 Throws exception on any error.
3016 A breakpoint that is already inserted won't be inserted
3017 again, so calling this function twice is safe. */
3019 insert_breakpoints (void)
3021 struct breakpoint *bpt;
3023 ALL_BREAKPOINTS (bpt)
3024 if (is_hardware_watchpoint (bpt))
3026 struct watchpoint *w = (struct watchpoint *) bpt;
3028 update_watchpoint (w, 0 /* don't reparse. */);
3031 /* Updating watchpoints creates new locations, so update the global
3032 location list. Explicitly tell ugll to insert locations and
3033 ignore breakpoints_always_inserted_mode. */
3034 update_global_location_list (UGLL_INSERT);
3037 /* Invoke CALLBACK for each of bp_location. */
3040 iterate_over_bp_locations (walk_bp_location_callback callback)
3042 struct bp_location *loc, **loc_tmp;
3044 ALL_BP_LOCATIONS (loc, loc_tmp)
3046 callback (loc, NULL);
3050 /* This is used when we need to synch breakpoint conditions between GDB and the
3051 target. It is the case with deleting and disabling of breakpoints when using
3052 always-inserted mode. */
3055 update_inserted_breakpoint_locations (void)
3057 struct bp_location *bl, **blp_tmp;
3060 int disabled_breaks = 0;
3061 int hw_breakpoint_error = 0;
3062 int hw_bp_details_reported = 0;
3064 struct ui_file *tmp_error_stream = mem_fileopen ();
3065 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3067 /* Explicitly mark the warning -- this will only be printed if
3068 there was an error. */
3069 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3071 save_current_space_and_thread ();
3073 ALL_BP_LOCATIONS (bl, blp_tmp)
3075 /* We only want to update software breakpoints and hardware
3077 if (!is_breakpoint (bl->owner))
3080 /* We only want to update locations that are already inserted
3081 and need updating. This is to avoid unwanted insertion during
3082 deletion of breakpoints. */
3083 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3086 switch_to_program_space_and_thread (bl->pspace);
3088 /* For targets that support global breakpoints, there's no need
3089 to select an inferior to insert breakpoint to. In fact, even
3090 if we aren't attached to any process yet, we should still
3091 insert breakpoints. */
3092 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3093 && ptid_equal (inferior_ptid, null_ptid))
3096 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3097 &hw_breakpoint_error, &hw_bp_details_reported);
3104 target_terminal_ours_for_output ();
3105 error_stream (tmp_error_stream);
3108 do_cleanups (cleanups);
3111 /* Used when starting or continuing the program. */
3114 insert_breakpoint_locations (void)
3116 struct breakpoint *bpt;
3117 struct bp_location *bl, **blp_tmp;
3120 int disabled_breaks = 0;
3121 int hw_breakpoint_error = 0;
3122 int hw_bp_error_explained_already = 0;
3124 struct ui_file *tmp_error_stream = mem_fileopen ();
3125 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3127 /* Explicitly mark the warning -- this will only be printed if
3128 there was an error. */
3129 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3131 save_current_space_and_thread ();
3133 ALL_BP_LOCATIONS (bl, blp_tmp)
3135 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3138 /* There is no point inserting thread-specific breakpoints if
3139 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3140 has BL->OWNER always non-NULL. */
3141 if (bl->owner->thread != -1
3142 && !valid_global_thread_id (bl->owner->thread))
3145 switch_to_program_space_and_thread (bl->pspace);
3147 /* For targets that support global breakpoints, there's no need
3148 to select an inferior to insert breakpoint to. In fact, even
3149 if we aren't attached to any process yet, we should still
3150 insert breakpoints. */
3151 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3152 && ptid_equal (inferior_ptid, null_ptid))
3155 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3156 &hw_breakpoint_error, &hw_bp_error_explained_already);
3161 /* If we failed to insert all locations of a watchpoint, remove
3162 them, as half-inserted watchpoint is of limited use. */
3163 ALL_BREAKPOINTS (bpt)
3165 int some_failed = 0;
3166 struct bp_location *loc;
3168 if (!is_hardware_watchpoint (bpt))
3171 if (!breakpoint_enabled (bpt))
3174 if (bpt->disposition == disp_del_at_next_stop)
3177 for (loc = bpt->loc; loc; loc = loc->next)
3178 if (!loc->inserted && should_be_inserted (loc))
3185 for (loc = bpt->loc; loc; loc = loc->next)
3187 remove_breakpoint (loc);
3189 hw_breakpoint_error = 1;
3190 fprintf_unfiltered (tmp_error_stream,
3191 "Could not insert hardware watchpoint %d.\n",
3199 /* If a hardware breakpoint or watchpoint was inserted, add a
3200 message about possibly exhausted resources. */
3201 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3203 fprintf_unfiltered (tmp_error_stream,
3204 "Could not insert hardware breakpoints:\n\
3205 You may have requested too many hardware breakpoints/watchpoints.\n");
3207 target_terminal_ours_for_output ();
3208 error_stream (tmp_error_stream);
3211 do_cleanups (cleanups);
3214 /* Used when the program stops.
3215 Returns zero if successful, or non-zero if there was a problem
3216 removing a breakpoint location. */
3219 remove_breakpoints (void)
3221 struct bp_location *bl, **blp_tmp;
3224 ALL_BP_LOCATIONS (bl, blp_tmp)
3226 if (bl->inserted && !is_tracepoint (bl->owner))
3227 val |= remove_breakpoint (bl);
3232 /* When a thread exits, remove breakpoints that are related to
3236 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3238 struct breakpoint *b, *b_tmp;
3240 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3242 if (b->thread == tp->global_num && user_breakpoint_p (b))
3244 b->disposition = disp_del_at_next_stop;
3246 printf_filtered (_("\
3247 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3248 b->number, print_thread_id (tp));
3250 /* Hide it from the user. */
3256 /* Remove breakpoints of process PID. */
3259 remove_breakpoints_pid (int pid)
3261 struct bp_location *bl, **blp_tmp;
3263 struct inferior *inf = find_inferior_pid (pid);
3265 ALL_BP_LOCATIONS (bl, blp_tmp)
3267 if (bl->pspace != inf->pspace)
3270 if (bl->inserted && !bl->target_info.persist)
3272 val = remove_breakpoint (bl);
3281 reattach_breakpoints (int pid)
3283 struct cleanup *old_chain;
3284 struct bp_location *bl, **blp_tmp;
3286 struct ui_file *tmp_error_stream;
3287 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3288 struct inferior *inf;
3289 struct thread_info *tp;
3291 tp = any_live_thread_of_process (pid);
3295 inf = find_inferior_pid (pid);
3296 old_chain = save_inferior_ptid ();
3298 inferior_ptid = tp->ptid;
3300 tmp_error_stream = mem_fileopen ();
3301 make_cleanup_ui_file_delete (tmp_error_stream);
3303 ALL_BP_LOCATIONS (bl, blp_tmp)
3305 if (bl->pspace != inf->pspace)
3311 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3314 do_cleanups (old_chain);
3319 do_cleanups (old_chain);
3323 static int internal_breakpoint_number = -1;
3325 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3326 If INTERNAL is non-zero, the breakpoint number will be populated
3327 from internal_breakpoint_number and that variable decremented.
3328 Otherwise the breakpoint number will be populated from
3329 breakpoint_count and that value incremented. Internal breakpoints
3330 do not set the internal var bpnum. */
3332 set_breakpoint_number (int internal, struct breakpoint *b)
3335 b->number = internal_breakpoint_number--;
3338 set_breakpoint_count (breakpoint_count + 1);
3339 b->number = breakpoint_count;
3343 static struct breakpoint *
3344 create_internal_breakpoint (struct gdbarch *gdbarch,
3345 CORE_ADDR address, enum bptype type,
3346 const struct breakpoint_ops *ops)
3348 struct symtab_and_line sal;
3349 struct breakpoint *b;
3351 init_sal (&sal); /* Initialize to zeroes. */
3354 sal.section = find_pc_overlay (sal.pc);
3355 sal.pspace = current_program_space;
3357 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3358 b->number = internal_breakpoint_number--;
3359 b->disposition = disp_donttouch;
3364 static const char *const longjmp_names[] =
3366 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3368 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3370 /* Per-objfile data private to breakpoint.c. */
3371 struct breakpoint_objfile_data
3373 /* Minimal symbol for "_ovly_debug_event" (if any). */
3374 struct bound_minimal_symbol overlay_msym;
3376 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3377 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3379 /* True if we have looked for longjmp probes. */
3380 int longjmp_searched;
3382 /* SystemTap probe points for longjmp (if any). */
3383 VEC (probe_p) *longjmp_probes;
3385 /* Minimal symbol for "std::terminate()" (if any). */
3386 struct bound_minimal_symbol terminate_msym;
3388 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3389 struct bound_minimal_symbol exception_msym;
3391 /* True if we have looked for exception probes. */
3392 int exception_searched;
3394 /* SystemTap probe points for unwinding (if any). */
3395 VEC (probe_p) *exception_probes;
3398 static const struct objfile_data *breakpoint_objfile_key;
3400 /* Minimal symbol not found sentinel. */
3401 static struct minimal_symbol msym_not_found;
3403 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3406 msym_not_found_p (const struct minimal_symbol *msym)
3408 return msym == &msym_not_found;
3411 /* Return per-objfile data needed by breakpoint.c.
3412 Allocate the data if necessary. */
3414 static struct breakpoint_objfile_data *
3415 get_breakpoint_objfile_data (struct objfile *objfile)
3417 struct breakpoint_objfile_data *bp_objfile_data;
3419 bp_objfile_data = ((struct breakpoint_objfile_data *)
3420 objfile_data (objfile, breakpoint_objfile_key));
3421 if (bp_objfile_data == NULL)
3424 XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
3426 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3427 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3429 return bp_objfile_data;
3433 free_breakpoint_probes (struct objfile *obj, void *data)
3435 struct breakpoint_objfile_data *bp_objfile_data
3436 = (struct breakpoint_objfile_data *) data;
3438 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3439 VEC_free (probe_p, bp_objfile_data->exception_probes);
3443 create_overlay_event_breakpoint (void)
3445 struct objfile *objfile;
3446 const char *const func_name = "_ovly_debug_event";
3448 ALL_OBJFILES (objfile)
3450 struct breakpoint *b;
3451 struct breakpoint_objfile_data *bp_objfile_data;
3453 struct explicit_location explicit_loc;
3455 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3457 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3460 if (bp_objfile_data->overlay_msym.minsym == NULL)
3462 struct bound_minimal_symbol m;
3464 m = lookup_minimal_symbol_text (func_name, objfile);
3465 if (m.minsym == NULL)
3467 /* Avoid future lookups in this objfile. */
3468 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3471 bp_objfile_data->overlay_msym = m;
3474 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3475 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3477 &internal_breakpoint_ops);
3478 initialize_explicit_location (&explicit_loc);
3479 explicit_loc.function_name = ASTRDUP (func_name);
3480 b->location = new_explicit_location (&explicit_loc);
3482 if (overlay_debugging == ovly_auto)
3484 b->enable_state = bp_enabled;
3485 overlay_events_enabled = 1;
3489 b->enable_state = bp_disabled;
3490 overlay_events_enabled = 0;
3496 create_longjmp_master_breakpoint (void)
3498 struct program_space *pspace;
3499 struct cleanup *old_chain;
3501 old_chain = save_current_program_space ();
3503 ALL_PSPACES (pspace)
3505 struct objfile *objfile;
3507 set_current_program_space (pspace);
3509 ALL_OBJFILES (objfile)
3512 struct gdbarch *gdbarch;
3513 struct breakpoint_objfile_data *bp_objfile_data;
3515 gdbarch = get_objfile_arch (objfile);
3517 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3519 if (!bp_objfile_data->longjmp_searched)
3523 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3526 /* We are only interested in checking one element. */
3527 struct probe *p = VEC_index (probe_p, ret, 0);
3529 if (!can_evaluate_probe_arguments (p))
3531 /* We cannot use the probe interface here, because it does
3532 not know how to evaluate arguments. */
3533 VEC_free (probe_p, ret);
3537 bp_objfile_data->longjmp_probes = ret;
3538 bp_objfile_data->longjmp_searched = 1;
3541 if (bp_objfile_data->longjmp_probes != NULL)
3544 struct probe *probe;
3545 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3548 VEC_iterate (probe_p,
3549 bp_objfile_data->longjmp_probes,
3553 struct breakpoint *b;
3555 b = create_internal_breakpoint (gdbarch,
3556 get_probe_address (probe,
3559 &internal_breakpoint_ops);
3561 = new_probe_location ("-probe-stap libc:longjmp");
3562 b->enable_state = bp_disabled;
3568 if (!gdbarch_get_longjmp_target_p (gdbarch))
3571 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3573 struct breakpoint *b;
3574 const char *func_name;
3576 struct explicit_location explicit_loc;
3578 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3581 func_name = longjmp_names[i];
3582 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3584 struct bound_minimal_symbol m;
3586 m = lookup_minimal_symbol_text (func_name, objfile);
3587 if (m.minsym == NULL)
3589 /* Prevent future lookups in this objfile. */
3590 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3593 bp_objfile_data->longjmp_msym[i] = m;
3596 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3597 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3598 &internal_breakpoint_ops);
3599 initialize_explicit_location (&explicit_loc);
3600 explicit_loc.function_name = ASTRDUP (func_name);
3601 b->location = new_explicit_location (&explicit_loc);
3602 b->enable_state = bp_disabled;
3607 do_cleanups (old_chain);
3610 /* Create a master std::terminate breakpoint. */
3612 create_std_terminate_master_breakpoint (void)
3614 struct program_space *pspace;
3615 struct cleanup *old_chain;
3616 const char *const func_name = "std::terminate()";
3618 old_chain = save_current_program_space ();
3620 ALL_PSPACES (pspace)
3622 struct objfile *objfile;
3625 set_current_program_space (pspace);
3627 ALL_OBJFILES (objfile)
3629 struct breakpoint *b;
3630 struct breakpoint_objfile_data *bp_objfile_data;
3631 struct explicit_location explicit_loc;
3633 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3635 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3638 if (bp_objfile_data->terminate_msym.minsym == NULL)
3640 struct bound_minimal_symbol m;
3642 m = lookup_minimal_symbol (func_name, NULL, objfile);
3643 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3644 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3646 /* Prevent future lookups in this objfile. */
3647 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3650 bp_objfile_data->terminate_msym = m;
3653 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3654 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3655 bp_std_terminate_master,
3656 &internal_breakpoint_ops);
3657 initialize_explicit_location (&explicit_loc);
3658 explicit_loc.function_name = ASTRDUP (func_name);
3659 b->location = new_explicit_location (&explicit_loc);
3660 b->enable_state = bp_disabled;
3664 do_cleanups (old_chain);
3667 /* Install a master breakpoint on the unwinder's debug hook. */
3670 create_exception_master_breakpoint (void)
3672 struct objfile *objfile;
3673 const char *const func_name = "_Unwind_DebugHook";
3675 ALL_OBJFILES (objfile)
3677 struct breakpoint *b;
3678 struct gdbarch *gdbarch;
3679 struct breakpoint_objfile_data *bp_objfile_data;
3681 struct explicit_location explicit_loc;
3683 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3685 /* We prefer the SystemTap probe point if it exists. */
3686 if (!bp_objfile_data->exception_searched)
3690 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3694 /* We are only interested in checking one element. */
3695 struct probe *p = VEC_index (probe_p, ret, 0);
3697 if (!can_evaluate_probe_arguments (p))
3699 /* We cannot use the probe interface here, because it does
3700 not know how to evaluate arguments. */
3701 VEC_free (probe_p, ret);
3705 bp_objfile_data->exception_probes = ret;
3706 bp_objfile_data->exception_searched = 1;
3709 if (bp_objfile_data->exception_probes != NULL)
3711 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3713 struct probe *probe;
3716 VEC_iterate (probe_p,
3717 bp_objfile_data->exception_probes,
3721 struct breakpoint *b;
3723 b = create_internal_breakpoint (gdbarch,
3724 get_probe_address (probe,
3726 bp_exception_master,
3727 &internal_breakpoint_ops);
3729 = new_probe_location ("-probe-stap libgcc:unwind");
3730 b->enable_state = bp_disabled;
3736 /* Otherwise, try the hook function. */
3738 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3741 gdbarch = get_objfile_arch (objfile);
3743 if (bp_objfile_data->exception_msym.minsym == NULL)
3745 struct bound_minimal_symbol debug_hook;
3747 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3748 if (debug_hook.minsym == NULL)
3750 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3754 bp_objfile_data->exception_msym = debug_hook;
3757 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3758 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3760 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3761 &internal_breakpoint_ops);
3762 initialize_explicit_location (&explicit_loc);
3763 explicit_loc.function_name = ASTRDUP (func_name);
3764 b->location = new_explicit_location (&explicit_loc);
3765 b->enable_state = bp_disabled;
3769 /* Does B have a location spec? */
3772 breakpoint_event_location_empty_p (const struct breakpoint *b)
3774 return b->location != NULL && event_location_empty_p (b->location);
3778 update_breakpoints_after_exec (void)
3780 struct breakpoint *b, *b_tmp;
3781 struct bp_location *bploc, **bplocp_tmp;
3783 /* We're about to delete breakpoints from GDB's lists. If the
3784 INSERTED flag is true, GDB will try to lift the breakpoints by
3785 writing the breakpoints' "shadow contents" back into memory. The
3786 "shadow contents" are NOT valid after an exec, so GDB should not
3787 do that. Instead, the target is responsible from marking
3788 breakpoints out as soon as it detects an exec. We don't do that
3789 here instead, because there may be other attempts to delete
3790 breakpoints after detecting an exec and before reaching here. */
3791 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3792 if (bploc->pspace == current_program_space)
3793 gdb_assert (!bploc->inserted);
3795 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3797 if (b->pspace != current_program_space)
3800 /* Solib breakpoints must be explicitly reset after an exec(). */
3801 if (b->type == bp_shlib_event)
3803 delete_breakpoint (b);
3807 /* JIT breakpoints must be explicitly reset after an exec(). */
3808 if (b->type == bp_jit_event)
3810 delete_breakpoint (b);
3814 /* Thread event breakpoints must be set anew after an exec(),
3815 as must overlay event and longjmp master breakpoints. */
3816 if (b->type == bp_thread_event || b->type == bp_overlay_event
3817 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3818 || b->type == bp_exception_master)
3820 delete_breakpoint (b);
3824 /* Step-resume breakpoints are meaningless after an exec(). */
3825 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3827 delete_breakpoint (b);
3831 /* Just like single-step breakpoints. */
3832 if (b->type == bp_single_step)
3834 delete_breakpoint (b);
3838 /* Longjmp and longjmp-resume breakpoints are also meaningless
3840 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3841 || b->type == bp_longjmp_call_dummy
3842 || b->type == bp_exception || b->type == bp_exception_resume)
3844 delete_breakpoint (b);
3848 if (b->type == bp_catchpoint)
3850 /* For now, none of the bp_catchpoint breakpoints need to
3851 do anything at this point. In the future, if some of
3852 the catchpoints need to something, we will need to add
3853 a new method, and call this method from here. */
3857 /* bp_finish is a special case. The only way we ought to be able
3858 to see one of these when an exec() has happened, is if the user
3859 caught a vfork, and then said "finish". Ordinarily a finish just
3860 carries them to the call-site of the current callee, by setting
3861 a temporary bp there and resuming. But in this case, the finish
3862 will carry them entirely through the vfork & exec.
3864 We don't want to allow a bp_finish to remain inserted now. But
3865 we can't safely delete it, 'cause finish_command has a handle to
3866 the bp on a bpstat, and will later want to delete it. There's a
3867 chance (and I've seen it happen) that if we delete the bp_finish
3868 here, that its storage will get reused by the time finish_command
3869 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3870 We really must allow finish_command to delete a bp_finish.
3872 In the absence of a general solution for the "how do we know
3873 it's safe to delete something others may have handles to?"
3874 problem, what we'll do here is just uninsert the bp_finish, and
3875 let finish_command delete it.
3877 (We know the bp_finish is "doomed" in the sense that it's
3878 momentary, and will be deleted as soon as finish_command sees
3879 the inferior stopped. So it doesn't matter that the bp's
3880 address is probably bogus in the new a.out, unlike e.g., the
3881 solib breakpoints.) */
3883 if (b->type == bp_finish)
3888 /* Without a symbolic address, we have little hope of the
3889 pre-exec() address meaning the same thing in the post-exec()
3891 if (breakpoint_event_location_empty_p (b))
3893 delete_breakpoint (b);
3900 detach_breakpoints (ptid_t ptid)
3902 struct bp_location *bl, **blp_tmp;
3904 struct cleanup *old_chain = save_inferior_ptid ();
3905 struct inferior *inf = current_inferior ();
3907 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3908 error (_("Cannot detach breakpoints of inferior_ptid"));
3910 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3911 inferior_ptid = ptid;
3912 ALL_BP_LOCATIONS (bl, blp_tmp)
3914 if (bl->pspace != inf->pspace)
3917 /* This function must physically remove breakpoints locations
3918 from the specified ptid, without modifying the breakpoint
3919 package's state. Locations of type bp_loc_other are only
3920 maintained at GDB side. So, there is no need to remove
3921 these bp_loc_other locations. Moreover, removing these
3922 would modify the breakpoint package's state. */
3923 if (bl->loc_type == bp_loc_other)
3927 val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT);
3930 do_cleanups (old_chain);
3934 /* Remove the breakpoint location BL from the current address space.
3935 Note that this is used to detach breakpoints from a child fork.
3936 When we get here, the child isn't in the inferior list, and neither
3937 do we have objects to represent its address space --- we should
3938 *not* look at bl->pspace->aspace here. */
3941 remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason)
3945 /* BL is never in moribund_locations by our callers. */
3946 gdb_assert (bl->owner != NULL);
3948 /* The type of none suggests that owner is actually deleted.
3949 This should not ever happen. */
3950 gdb_assert (bl->owner->type != bp_none);
3952 if (bl->loc_type == bp_loc_software_breakpoint
3953 || bl->loc_type == bp_loc_hardware_breakpoint)
3955 /* "Normal" instruction breakpoint: either the standard
3956 trap-instruction bp (bp_breakpoint), or a
3957 bp_hardware_breakpoint. */
3959 /* First check to see if we have to handle an overlay. */
3960 if (overlay_debugging == ovly_off
3961 || bl->section == NULL
3962 || !(section_is_overlay (bl->section)))
3964 /* No overlay handling: just remove the breakpoint. */
3966 /* If we're trying to uninsert a memory breakpoint that we
3967 know is set in a dynamic object that is marked
3968 shlib_disabled, then either the dynamic object was
3969 removed with "remove-symbol-file" or with
3970 "nosharedlibrary". In the former case, we don't know
3971 whether another dynamic object might have loaded over the
3972 breakpoint's address -- the user might well let us know
3973 about it next with add-symbol-file (the whole point of
3974 add-symbol-file is letting the user manually maintain a
3975 list of dynamically loaded objects). If we have the
3976 breakpoint's shadow memory, that is, this is a software
3977 breakpoint managed by GDB, check whether the breakpoint
3978 is still inserted in memory, to avoid overwriting wrong
3979 code with stale saved shadow contents. Note that HW
3980 breakpoints don't have shadow memory, as they're
3981 implemented using a mechanism that is not dependent on
3982 being able to modify the target's memory, and as such
3983 they should always be removed. */
3984 if (bl->shlib_disabled
3985 && bl->target_info.shadow_len != 0
3986 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3989 val = bl->owner->ops->remove_location (bl, reason);
3993 /* This breakpoint is in an overlay section.
3994 Did we set a breakpoint at the LMA? */
3995 if (!overlay_events_enabled)
3997 /* Yes -- overlay event support is not active, so we
3998 should have set a breakpoint at the LMA. Remove it.
4000 /* Ignore any failures: if the LMA is in ROM, we will
4001 have already warned when we failed to insert it. */
4002 if (bl->loc_type == bp_loc_hardware_breakpoint)
4003 target_remove_hw_breakpoint (bl->gdbarch,
4004 &bl->overlay_target_info);
4006 target_remove_breakpoint (bl->gdbarch,
4007 &bl->overlay_target_info,
4010 /* Did we set a breakpoint at the VMA?
4011 If so, we will have marked the breakpoint 'inserted'. */
4014 /* Yes -- remove it. Previously we did not bother to
4015 remove the breakpoint if the section had been
4016 unmapped, but let's not rely on that being safe. We
4017 don't know what the overlay manager might do. */
4019 /* However, we should remove *software* breakpoints only
4020 if the section is still mapped, or else we overwrite
4021 wrong code with the saved shadow contents. */
4022 if (bl->loc_type == bp_loc_hardware_breakpoint
4023 || section_is_mapped (bl->section))
4024 val = bl->owner->ops->remove_location (bl, reason);
4030 /* No -- not inserted, so no need to remove. No error. */
4035 /* In some cases, we might not be able to remove a breakpoint in
4036 a shared library that has already been removed, but we have
4037 not yet processed the shlib unload event. Similarly for an
4038 unloaded add-symbol-file object - the user might not yet have
4039 had the chance to remove-symbol-file it. shlib_disabled will
4040 be set if the library/object has already been removed, but
4041 the breakpoint hasn't been uninserted yet, e.g., after
4042 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4043 always-inserted mode. */
4045 && (bl->loc_type == bp_loc_software_breakpoint
4046 && (bl->shlib_disabled
4047 || solib_name_from_address (bl->pspace, bl->address)
4048 || shared_objfile_contains_address_p (bl->pspace,
4054 bl->inserted = (reason == DETACH_BREAKPOINT);
4056 else if (bl->loc_type == bp_loc_hardware_watchpoint)
4058 gdb_assert (bl->owner->ops != NULL
4059 && bl->owner->ops->remove_location != NULL);
4061 bl->inserted = (reason == DETACH_BREAKPOINT);
4062 bl->owner->ops->remove_location (bl, reason);
4064 /* Failure to remove any of the hardware watchpoints comes here. */
4065 if (reason == REMOVE_BREAKPOINT && bl->inserted)
4066 warning (_("Could not remove hardware watchpoint %d."),
4069 else if (bl->owner->type == bp_catchpoint
4070 && breakpoint_enabled (bl->owner)
4073 gdb_assert (bl->owner->ops != NULL
4074 && bl->owner->ops->remove_location != NULL);
4076 val = bl->owner->ops->remove_location (bl, reason);
4080 bl->inserted = (reason == DETACH_BREAKPOINT);
4087 remove_breakpoint (struct bp_location *bl)
4090 struct cleanup *old_chain;
4092 /* BL is never in moribund_locations by our callers. */
4093 gdb_assert (bl->owner != NULL);
4095 /* The type of none suggests that owner is actually deleted.
4096 This should not ever happen. */
4097 gdb_assert (bl->owner->type != bp_none);
4099 old_chain = save_current_space_and_thread ();
4101 switch_to_program_space_and_thread (bl->pspace);
4103 ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT);
4105 do_cleanups (old_chain);
4109 /* Clear the "inserted" flag in all breakpoints. */
4112 mark_breakpoints_out (void)
4114 struct bp_location *bl, **blp_tmp;
4116 ALL_BP_LOCATIONS (bl, blp_tmp)
4117 if (bl->pspace == current_program_space)
4121 /* Clear the "inserted" flag in all breakpoints and delete any
4122 breakpoints which should go away between runs of the program.
4124 Plus other such housekeeping that has to be done for breakpoints
4127 Note: this function gets called at the end of a run (by
4128 generic_mourn_inferior) and when a run begins (by
4129 init_wait_for_inferior). */
4134 breakpoint_init_inferior (enum inf_context context)
4136 struct breakpoint *b, *b_tmp;
4137 struct bp_location *bl;
4139 struct program_space *pspace = current_program_space;
4141 /* If breakpoint locations are shared across processes, then there's
4143 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4146 mark_breakpoints_out ();
4148 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4150 if (b->loc && b->loc->pspace != pspace)
4156 case bp_longjmp_call_dummy:
4158 /* If the call dummy breakpoint is at the entry point it will
4159 cause problems when the inferior is rerun, so we better get
4162 case bp_watchpoint_scope:
4164 /* Also get rid of scope breakpoints. */
4166 case bp_shlib_event:
4168 /* Also remove solib event breakpoints. Their addresses may
4169 have changed since the last time we ran the program.
4170 Actually we may now be debugging against different target;
4171 and so the solib backend that installed this breakpoint may
4172 not be used in by the target. E.g.,
4174 (gdb) file prog-linux
4175 (gdb) run # native linux target
4178 (gdb) file prog-win.exe
4179 (gdb) tar rem :9999 # remote Windows gdbserver.
4182 case bp_step_resume:
4184 /* Also remove step-resume breakpoints. */
4186 case bp_single_step:
4188 /* Also remove single-step breakpoints. */
4190 delete_breakpoint (b);
4194 case bp_hardware_watchpoint:
4195 case bp_read_watchpoint:
4196 case bp_access_watchpoint:
4198 struct watchpoint *w = (struct watchpoint *) b;
4200 /* Likewise for watchpoints on local expressions. */
4201 if (w->exp_valid_block != NULL)
4202 delete_breakpoint (b);
4205 /* Get rid of existing locations, which are no longer
4206 valid. New ones will be created in
4207 update_watchpoint, when the inferior is restarted.
4208 The next update_global_location_list call will
4209 garbage collect them. */
4212 if (context == inf_starting)
4214 /* Reset val field to force reread of starting value in
4215 insert_breakpoints. */
4217 value_free (w->val);
4229 /* Get rid of the moribund locations. */
4230 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4231 decref_bp_location (&bl);
4232 VEC_free (bp_location_p, moribund_locations);
4235 /* These functions concern about actual breakpoints inserted in the
4236 target --- to e.g. check if we need to do decr_pc adjustment or if
4237 we need to hop over the bkpt --- so we check for address space
4238 match, not program space. */
4240 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4241 exists at PC. It returns ordinary_breakpoint_here if it's an
4242 ordinary breakpoint, or permanent_breakpoint_here if it's a
4243 permanent breakpoint.
4244 - When continuing from a location with an ordinary breakpoint, we
4245 actually single step once before calling insert_breakpoints.
4246 - When continuing from a location with a permanent breakpoint, we
4247 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4248 the target, to advance the PC past the breakpoint. */
4250 enum breakpoint_here
4251 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4253 struct bp_location *bl, **blp_tmp;
4254 int any_breakpoint_here = 0;
4256 ALL_BP_LOCATIONS (bl, blp_tmp)
4258 if (bl->loc_type != bp_loc_software_breakpoint
4259 && bl->loc_type != bp_loc_hardware_breakpoint)
4262 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4263 if ((breakpoint_enabled (bl->owner)
4265 && breakpoint_location_address_match (bl, aspace, pc))
4267 if (overlay_debugging
4268 && section_is_overlay (bl->section)
4269 && !section_is_mapped (bl->section))
4270 continue; /* unmapped overlay -- can't be a match */
4271 else if (bl->permanent)
4272 return permanent_breakpoint_here;
4274 any_breakpoint_here = 1;
4278 return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here;
4281 /* See breakpoint.h. */
4284 breakpoint_in_range_p (struct address_space *aspace,
4285 CORE_ADDR addr, ULONGEST len)
4287 struct bp_location *bl, **blp_tmp;
4289 ALL_BP_LOCATIONS (bl, blp_tmp)
4291 if (bl->loc_type != bp_loc_software_breakpoint
4292 && bl->loc_type != bp_loc_hardware_breakpoint)
4295 if ((breakpoint_enabled (bl->owner)
4297 && breakpoint_location_address_range_overlap (bl, aspace,
4300 if (overlay_debugging
4301 && section_is_overlay (bl->section)
4302 && !section_is_mapped (bl->section))
4304 /* Unmapped overlay -- can't be a match. */
4315 /* Return true if there's a moribund breakpoint at PC. */
4318 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4320 struct bp_location *loc;
4323 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4324 if (breakpoint_location_address_match (loc, aspace, pc))
4330 /* Returns non-zero iff BL is inserted at PC, in address space
4334 bp_location_inserted_here_p (struct bp_location *bl,
4335 struct address_space *aspace, CORE_ADDR pc)
4338 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4341 if (overlay_debugging
4342 && section_is_overlay (bl->section)
4343 && !section_is_mapped (bl->section))
4344 return 0; /* unmapped overlay -- can't be a match */
4351 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4354 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4356 struct bp_location **blp, **blp_tmp = NULL;
4358 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4360 struct bp_location *bl = *blp;
4362 if (bl->loc_type != bp_loc_software_breakpoint
4363 && bl->loc_type != bp_loc_hardware_breakpoint)
4366 if (bp_location_inserted_here_p (bl, aspace, pc))
4372 /* This function returns non-zero iff there is a software breakpoint
4376 software_breakpoint_inserted_here_p (struct address_space *aspace,
4379 struct bp_location **blp, **blp_tmp = NULL;
4381 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4383 struct bp_location *bl = *blp;
4385 if (bl->loc_type != bp_loc_software_breakpoint)
4388 if (bp_location_inserted_here_p (bl, aspace, pc))
4395 /* See breakpoint.h. */
4398 hardware_breakpoint_inserted_here_p (struct address_space *aspace,
4401 struct bp_location **blp, **blp_tmp = NULL;
4403 ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4405 struct bp_location *bl = *blp;
4407 if (bl->loc_type != bp_loc_hardware_breakpoint)
4410 if (bp_location_inserted_here_p (bl, aspace, pc))
4418 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4419 CORE_ADDR addr, ULONGEST len)
4421 struct breakpoint *bpt;
4423 ALL_BREAKPOINTS (bpt)
4425 struct bp_location *loc;
4427 if (bpt->type != bp_hardware_watchpoint
4428 && bpt->type != bp_access_watchpoint)
4431 if (!breakpoint_enabled (bpt))
4434 for (loc = bpt->loc; loc; loc = loc->next)
4435 if (loc->pspace->aspace == aspace && loc->inserted)
4439 /* Check for intersection. */
4440 l = std::max<CORE_ADDR> (loc->address, addr);
4441 h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
4450 /* bpstat stuff. External routines' interfaces are documented
4454 is_catchpoint (struct breakpoint *ep)
4456 return (ep->type == bp_catchpoint);
4459 /* Frees any storage that is part of a bpstat. Does not walk the
4463 bpstat_free (bpstat bs)
4465 if (bs->old_val != NULL)
4466 value_free (bs->old_val);
4467 decref_counted_command_line (&bs->commands);
4468 decref_bp_location (&bs->bp_location_at);
4472 /* Clear a bpstat so that it says we are not at any breakpoint.
4473 Also free any storage that is part of a bpstat. */
4476 bpstat_clear (bpstat *bsp)
4493 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4494 is part of the bpstat is copied as well. */
4497 bpstat_copy (bpstat bs)
4501 bpstat retval = NULL;
4506 for (; bs != NULL; bs = bs->next)
4508 tmp = (bpstat) xmalloc (sizeof (*tmp));
4509 memcpy (tmp, bs, sizeof (*tmp));
4510 incref_counted_command_line (tmp->commands);
4511 incref_bp_location (tmp->bp_location_at);
4512 if (bs->old_val != NULL)
4514 tmp->old_val = value_copy (bs->old_val);
4515 release_value (tmp->old_val);
4519 /* This is the first thing in the chain. */
4529 /* Find the bpstat associated with this breakpoint. */
4532 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4537 for (; bsp != NULL; bsp = bsp->next)
4539 if (bsp->breakpoint_at == breakpoint)
4545 /* See breakpoint.h. */
4548 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4550 for (; bsp != NULL; bsp = bsp->next)
4552 if (bsp->breakpoint_at == NULL)
4554 /* A moribund location can never explain a signal other than
4556 if (sig == GDB_SIGNAL_TRAP)
4561 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4570 /* Put in *NUM the breakpoint number of the first breakpoint we are
4571 stopped at. *BSP upon return is a bpstat which points to the
4572 remaining breakpoints stopped at (but which is not guaranteed to be
4573 good for anything but further calls to bpstat_num).
4575 Return 0 if passed a bpstat which does not indicate any breakpoints.
4576 Return -1 if stopped at a breakpoint that has been deleted since
4578 Return 1 otherwise. */
4581 bpstat_num (bpstat *bsp, int *num)
4583 struct breakpoint *b;
4586 return 0; /* No more breakpoint values */
4588 /* We assume we'll never have several bpstats that correspond to a
4589 single breakpoint -- otherwise, this function might return the
4590 same number more than once and this will look ugly. */
4591 b = (*bsp)->breakpoint_at;
4592 *bsp = (*bsp)->next;
4594 return -1; /* breakpoint that's been deleted since */
4596 *num = b->number; /* We have its number */
4600 /* See breakpoint.h. */
4603 bpstat_clear_actions (void)
4605 struct thread_info *tp;
4608 if (ptid_equal (inferior_ptid, null_ptid))
4611 tp = find_thread_ptid (inferior_ptid);
4615 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4617 decref_counted_command_line (&bs->commands);
4619 if (bs->old_val != NULL)
4621 value_free (bs->old_val);
4627 /* Called when a command is about to proceed the inferior. */
4630 breakpoint_about_to_proceed (void)
4632 if (!ptid_equal (inferior_ptid, null_ptid))
4634 struct thread_info *tp = inferior_thread ();
4636 /* Allow inferior function calls in breakpoint commands to not
4637 interrupt the command list. When the call finishes
4638 successfully, the inferior will be standing at the same
4639 breakpoint as if nothing happened. */
4640 if (tp->control.in_infcall)
4644 breakpoint_proceeded = 1;
4647 /* Stub for cleaning up our state if we error-out of a breakpoint
4650 cleanup_executing_breakpoints (void *ignore)
4652 executing_breakpoint_commands = 0;
4655 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4656 or its equivalent. */
4659 command_line_is_silent (struct command_line *cmd)
4661 return cmd && (strcmp ("silent", cmd->line) == 0);
4664 /* Execute all the commands associated with all the breakpoints at
4665 this location. Any of these commands could cause the process to
4666 proceed beyond this point, etc. We look out for such changes by
4667 checking the global "breakpoint_proceeded" after each command.
4669 Returns true if a breakpoint command resumed the inferior. In that
4670 case, it is the caller's responsibility to recall it again with the
4671 bpstat of the current thread. */
4674 bpstat_do_actions_1 (bpstat *bsp)
4677 struct cleanup *old_chain;
4680 /* Avoid endless recursion if a `source' command is contained
4682 if (executing_breakpoint_commands)
4685 executing_breakpoint_commands = 1;
4686 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4688 scoped_restore preventer = prevent_dont_repeat ();
4690 /* This pointer will iterate over the list of bpstat's. */
4693 breakpoint_proceeded = 0;
4694 for (; bs != NULL; bs = bs->next)
4696 struct counted_command_line *ccmd;
4697 struct command_line *cmd;
4698 struct cleanup *this_cmd_tree_chain;
4700 /* Take ownership of the BSP's command tree, if it has one.
4702 The command tree could legitimately contain commands like
4703 'step' and 'next', which call clear_proceed_status, which
4704 frees stop_bpstat's command tree. To make sure this doesn't
4705 free the tree we're executing out from under us, we need to
4706 take ownership of the tree ourselves. Since a given bpstat's
4707 commands are only executed once, we don't need to copy it; we
4708 can clear the pointer in the bpstat, and make sure we free
4709 the tree when we're done. */
4710 ccmd = bs->commands;
4711 bs->commands = NULL;
4712 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4713 cmd = ccmd ? ccmd->commands : NULL;
4714 if (command_line_is_silent (cmd))
4716 /* The action has been already done by bpstat_stop_status. */
4722 execute_control_command (cmd);
4724 if (breakpoint_proceeded)
4730 /* We can free this command tree now. */
4731 do_cleanups (this_cmd_tree_chain);
4733 if (breakpoint_proceeded)
4735 if (current_ui->async)
4736 /* If we are in async mode, then the target might be still
4737 running, not stopped at any breakpoint, so nothing for
4738 us to do here -- just return to the event loop. */
4741 /* In sync mode, when execute_control_command returns
4742 we're already standing on the next breakpoint.
4743 Breakpoint commands for that stop were not run, since
4744 execute_command does not run breakpoint commands --
4745 only command_line_handler does, but that one is not
4746 involved in execution of breakpoint commands. So, we
4747 can now execute breakpoint commands. It should be
4748 noted that making execute_command do bpstat actions is
4749 not an option -- in this case we'll have recursive
4750 invocation of bpstat for each breakpoint with a
4751 command, and can easily blow up GDB stack. Instead, we
4752 return true, which will trigger the caller to recall us
4753 with the new stop_bpstat. */
4758 do_cleanups (old_chain);
4763 bpstat_do_actions (void)
4765 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4767 /* Do any commands attached to breakpoint we are stopped at. */
4768 while (!ptid_equal (inferior_ptid, null_ptid)
4769 && target_has_execution
4770 && !is_exited (inferior_ptid)
4771 && !is_executing (inferior_ptid))
4772 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4773 and only return when it is stopped at the next breakpoint, we
4774 keep doing breakpoint actions until it returns false to
4775 indicate the inferior was not resumed. */
4776 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4779 discard_cleanups (cleanup_if_error);
4782 /* Print out the (old or new) value associated with a watchpoint. */
4785 watchpoint_value_print (struct value *val, struct ui_file *stream)
4788 fprintf_unfiltered (stream, _("<unreadable>"));
4791 struct value_print_options opts;
4792 get_user_print_options (&opts);
4793 value_print (val, stream, &opts);
4797 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4798 debugging multiple threads. */
4801 maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
4803 if (uiout->is_mi_like_p ())
4808 if (show_thread_that_caused_stop ())
4811 struct thread_info *thr = inferior_thread ();
4813 uiout->text ("Thread ");
4814 uiout->field_fmt ("thread-id", "%s", print_thread_id (thr));
4816 name = thr->name != NULL ? thr->name : target_thread_name (thr);
4819 uiout->text (" \"");
4820 uiout->field_fmt ("name", "%s", name);
4824 uiout->text (" hit ");
4828 /* Generic routine for printing messages indicating why we
4829 stopped. The behavior of this function depends on the value
4830 'print_it' in the bpstat structure. Under some circumstances we
4831 may decide not to print anything here and delegate the task to
4834 static enum print_stop_action
4835 print_bp_stop_message (bpstat bs)
4837 switch (bs->print_it)
4840 /* Nothing should be printed for this bpstat entry. */
4841 return PRINT_UNKNOWN;
4845 /* We still want to print the frame, but we already printed the
4846 relevant messages. */
4847 return PRINT_SRC_AND_LOC;
4850 case print_it_normal:
4852 struct breakpoint *b = bs->breakpoint_at;
4854 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4855 which has since been deleted. */
4857 return PRINT_UNKNOWN;
4859 /* Normal case. Call the breakpoint's print_it method. */
4860 return b->ops->print_it (bs);
4865 internal_error (__FILE__, __LINE__,
4866 _("print_bp_stop_message: unrecognized enum value"));
4871 /* A helper function that prints a shared library stopped event. */
4874 print_solib_event (int is_catchpoint)
4877 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4879 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4883 if (any_added || any_deleted)
4884 current_uiout->text (_("Stopped due to shared library event:\n"));
4886 current_uiout->text (_("Stopped due to shared library event (no "
4887 "libraries added or removed)\n"));
4890 if (current_uiout->is_mi_like_p ())
4891 current_uiout->field_string ("reason",
4892 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4896 struct cleanup *cleanup;
4900 current_uiout->text (_(" Inferior unloaded "));
4901 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4904 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4909 current_uiout->text (" ");
4910 current_uiout->field_string ("library", name);
4911 current_uiout->text ("\n");
4914 do_cleanups (cleanup);
4919 struct so_list *iter;
4921 struct cleanup *cleanup;
4923 current_uiout->text (_(" Inferior loaded "));
4924 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4927 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4932 current_uiout->text (" ");
4933 current_uiout->field_string ("library", iter->so_name);
4934 current_uiout->text ("\n");
4937 do_cleanups (cleanup);
4941 /* Print a message indicating what happened. This is called from
4942 normal_stop(). The input to this routine is the head of the bpstat
4943 list - a list of the eventpoints that caused this stop. KIND is
4944 the target_waitkind for the stopping event. This
4945 routine calls the generic print routine for printing a message
4946 about reasons for stopping. This will print (for example) the
4947 "Breakpoint n," part of the output. The return value of this
4950 PRINT_UNKNOWN: Means we printed nothing.
4951 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4952 code to print the location. An example is
4953 "Breakpoint 1, " which should be followed by
4955 PRINT_SRC_ONLY: Means we printed something, but there is no need
4956 to also print the location part of the message.
4957 An example is the catch/throw messages, which
4958 don't require a location appended to the end.
4959 PRINT_NOTHING: We have done some printing and we don't need any
4960 further info to be printed. */
4962 enum print_stop_action
4963 bpstat_print (bpstat bs, int kind)
4965 enum print_stop_action val;
4967 /* Maybe another breakpoint in the chain caused us to stop.
4968 (Currently all watchpoints go on the bpstat whether hit or not.
4969 That probably could (should) be changed, provided care is taken
4970 with respect to bpstat_explains_signal). */
4971 for (; bs; bs = bs->next)
4973 val = print_bp_stop_message (bs);
4974 if (val == PRINT_SRC_ONLY
4975 || val == PRINT_SRC_AND_LOC
4976 || val == PRINT_NOTHING)
4980 /* If we had hit a shared library event breakpoint,
4981 print_bp_stop_message would print out this message. If we hit an
4982 OS-level shared library event, do the same thing. */
4983 if (kind == TARGET_WAITKIND_LOADED)
4985 print_solib_event (0);
4986 return PRINT_NOTHING;
4989 /* We reached the end of the chain, or we got a null BS to start
4990 with and nothing was printed. */
4991 return PRINT_UNKNOWN;
4994 /* Evaluate the expression EXP and return 1 if value is zero.
4995 This returns the inverse of the condition because it is called
4996 from catch_errors which returns 0 if an exception happened, and if an
4997 exception happens we want execution to stop.
4998 The argument is a "struct expression *" that has been cast to a
4999 "void *" to make it pass through catch_errors. */
5002 breakpoint_cond_eval (void *exp)
5004 struct value *mark = value_mark ();
5005 int i = !value_true (evaluate_expression ((struct expression *) exp));
5007 value_free_to_mark (mark);
5011 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5014 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
5018 bs = (bpstat) xmalloc (sizeof (*bs));
5020 **bs_link_pointer = bs;
5021 *bs_link_pointer = &bs->next;
5022 bs->breakpoint_at = bl->owner;
5023 bs->bp_location_at = bl;
5024 incref_bp_location (bl);
5025 /* If the condition is false, etc., don't do the commands. */
5026 bs->commands = NULL;
5028 bs->print_it = print_it_normal;
5032 /* The target has stopped with waitstatus WS. Check if any hardware
5033 watchpoints have triggered, according to the target. */
5036 watchpoints_triggered (struct target_waitstatus *ws)
5038 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
5040 struct breakpoint *b;
5042 if (!stopped_by_watchpoint)
5044 /* We were not stopped by a watchpoint. Mark all watchpoints
5045 as not triggered. */
5047 if (is_hardware_watchpoint (b))
5049 struct watchpoint *w = (struct watchpoint *) b;
5051 w->watchpoint_triggered = watch_triggered_no;
5057 if (!target_stopped_data_address (¤t_target, &addr))
5059 /* We were stopped by a watchpoint, but we don't know where.
5060 Mark all watchpoints as unknown. */
5062 if (is_hardware_watchpoint (b))
5064 struct watchpoint *w = (struct watchpoint *) b;
5066 w->watchpoint_triggered = watch_triggered_unknown;
5072 /* The target could report the data address. Mark watchpoints
5073 affected by this data address as triggered, and all others as not
5077 if (is_hardware_watchpoint (b))
5079 struct watchpoint *w = (struct watchpoint *) b;
5080 struct bp_location *loc;
5082 w->watchpoint_triggered = watch_triggered_no;
5083 for (loc = b->loc; loc; loc = loc->next)
5085 if (is_masked_watchpoint (b))
5087 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5088 CORE_ADDR start = loc->address & w->hw_wp_mask;
5090 if (newaddr == start)
5092 w->watchpoint_triggered = watch_triggered_yes;
5096 /* Exact match not required. Within range is sufficient. */
5097 else if (target_watchpoint_addr_within_range (¤t_target,
5101 w->watchpoint_triggered = watch_triggered_yes;
5110 /* Possible return values for watchpoint_check (this can't be an enum
5111 because of check_errors). */
5112 /* The watchpoint has been deleted. */
5113 #define WP_DELETED 1
5114 /* The value has changed. */
5115 #define WP_VALUE_CHANGED 2
5116 /* The value has not changed. */
5117 #define WP_VALUE_NOT_CHANGED 3
5118 /* Ignore this watchpoint, no matter if the value changed or not. */
5121 #define BP_TEMPFLAG 1
5122 #define BP_HARDWAREFLAG 2
5124 /* Evaluate watchpoint condition expression and check if its value
5127 P should be a pointer to struct bpstat, but is defined as a void *
5128 in order for this function to be usable with catch_errors. */
5131 watchpoint_check (void *p)
5133 bpstat bs = (bpstat) p;
5134 struct watchpoint *b;
5135 struct frame_info *fr;
5136 int within_current_scope;
5138 /* BS is built from an existing struct breakpoint. */
5139 gdb_assert (bs->breakpoint_at != NULL);
5140 b = (struct watchpoint *) bs->breakpoint_at;
5142 /* If this is a local watchpoint, we only want to check if the
5143 watchpoint frame is in scope if the current thread is the thread
5144 that was used to create the watchpoint. */
5145 if (!watchpoint_in_thread_scope (b))
5148 if (b->exp_valid_block == NULL)
5149 within_current_scope = 1;
5152 struct frame_info *frame = get_current_frame ();
5153 struct gdbarch *frame_arch = get_frame_arch (frame);
5154 CORE_ADDR frame_pc = get_frame_pc (frame);
5156 /* stack_frame_destroyed_p() returns a non-zero value if we're
5157 still in the function but the stack frame has already been
5158 invalidated. Since we can't rely on the values of local
5159 variables after the stack has been destroyed, we are treating
5160 the watchpoint in that state as `not changed' without further
5161 checking. Don't mark watchpoints as changed if the current
5162 frame is in an epilogue - even if they are in some other
5163 frame, our view of the stack is likely to be wrong and
5164 frame_find_by_id could error out. */
5165 if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5168 fr = frame_find_by_id (b->watchpoint_frame);
5169 within_current_scope = (fr != NULL);
5171 /* If we've gotten confused in the unwinder, we might have
5172 returned a frame that can't describe this variable. */
5173 if (within_current_scope)
5175 struct symbol *function;
5177 function = get_frame_function (fr);
5178 if (function == NULL
5179 || !contained_in (b->exp_valid_block,
5180 SYMBOL_BLOCK_VALUE (function)))
5181 within_current_scope = 0;
5184 if (within_current_scope)
5185 /* If we end up stopping, the current frame will get selected
5186 in normal_stop. So this call to select_frame won't affect
5191 if (within_current_scope)
5193 /* We use value_{,free_to_}mark because it could be a *long*
5194 time before we return to the command level and call
5195 free_all_values. We can't call free_all_values because we
5196 might be in the middle of evaluating a function call. */
5200 struct value *new_val;
5202 if (is_masked_watchpoint (&b->base))
5203 /* Since we don't know the exact trigger address (from
5204 stopped_data_address), just tell the user we've triggered
5205 a mask watchpoint. */
5206 return WP_VALUE_CHANGED;
5208 mark = value_mark ();
5209 fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0);
5211 if (b->val_bitsize != 0)
5212 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5214 /* We use value_equal_contents instead of value_equal because
5215 the latter coerces an array to a pointer, thus comparing just
5216 the address of the array instead of its contents. This is
5217 not what we want. */
5218 if ((b->val != NULL) != (new_val != NULL)
5219 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5221 if (new_val != NULL)
5223 release_value (new_val);
5224 value_free_to_mark (mark);
5226 bs->old_val = b->val;
5229 return WP_VALUE_CHANGED;
5233 /* Nothing changed. */
5234 value_free_to_mark (mark);
5235 return WP_VALUE_NOT_CHANGED;
5240 /* This seems like the only logical thing to do because
5241 if we temporarily ignored the watchpoint, then when
5242 we reenter the block in which it is valid it contains
5243 garbage (in the case of a function, it may have two
5244 garbage values, one before and one after the prologue).
5245 So we can't even detect the first assignment to it and
5246 watch after that (since the garbage may or may not equal
5247 the first value assigned). */
5248 /* We print all the stop information in
5249 breakpoint_ops->print_it, but in this case, by the time we
5250 call breakpoint_ops->print_it this bp will be deleted
5251 already. So we have no choice but print the information
5254 SWITCH_THRU_ALL_UIS ()
5256 struct ui_out *uiout = current_uiout;
5258 if (uiout->is_mi_like_p ())
5260 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5261 uiout->text ("\nWatchpoint ");
5262 uiout->field_int ("wpnum", b->base.number);
5263 uiout->text (" deleted because the program has left the block in\n"
5264 "which its expression is valid.\n");
5267 /* Make sure the watchpoint's commands aren't executed. */
5268 decref_counted_command_line (&b->base.commands);
5269 watchpoint_del_at_next_stop (b);
5275 /* Return true if it looks like target has stopped due to hitting
5276 breakpoint location BL. This function does not check if we should
5277 stop, only if BL explains the stop. */
5280 bpstat_check_location (const struct bp_location *bl,
5281 struct address_space *aspace, CORE_ADDR bp_addr,
5282 const struct target_waitstatus *ws)
5284 struct breakpoint *b = bl->owner;
5286 /* BL is from an existing breakpoint. */
5287 gdb_assert (b != NULL);
5289 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5292 /* Determine if the watched values have actually changed, and we
5293 should stop. If not, set BS->stop to 0. */
5296 bpstat_check_watchpoint (bpstat bs)
5298 const struct bp_location *bl;
5299 struct watchpoint *b;
5301 /* BS is built for existing struct breakpoint. */
5302 bl = bs->bp_location_at;
5303 gdb_assert (bl != NULL);
5304 b = (struct watchpoint *) bs->breakpoint_at;
5305 gdb_assert (b != NULL);
5308 int must_check_value = 0;
5310 if (b->base.type == bp_watchpoint)
5311 /* For a software watchpoint, we must always check the
5313 must_check_value = 1;
5314 else if (b->watchpoint_triggered == watch_triggered_yes)
5315 /* We have a hardware watchpoint (read, write, or access)
5316 and the target earlier reported an address watched by
5318 must_check_value = 1;
5319 else if (b->watchpoint_triggered == watch_triggered_unknown
5320 && b->base.type == bp_hardware_watchpoint)
5321 /* We were stopped by a hardware watchpoint, but the target could
5322 not report the data address. We must check the watchpoint's
5323 value. Access and read watchpoints are out of luck; without
5324 a data address, we can't figure it out. */
5325 must_check_value = 1;
5327 if (must_check_value)
5330 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5332 struct cleanup *cleanups = make_cleanup (xfree, message);
5333 int e = catch_errors (watchpoint_check, bs, message,
5335 do_cleanups (cleanups);
5339 /* We've already printed what needs to be printed. */
5340 bs->print_it = print_it_done;
5344 bs->print_it = print_it_noop;
5347 case WP_VALUE_CHANGED:
5348 if (b->base.type == bp_read_watchpoint)
5350 /* There are two cases to consider here:
5352 1. We're watching the triggered memory for reads.
5353 In that case, trust the target, and always report
5354 the watchpoint hit to the user. Even though
5355 reads don't cause value changes, the value may
5356 have changed since the last time it was read, and
5357 since we're not trapping writes, we will not see
5358 those, and as such we should ignore our notion of
5361 2. We're watching the triggered memory for both
5362 reads and writes. There are two ways this may
5365 2.1. This is a target that can't break on data
5366 reads only, but can break on accesses (reads or
5367 writes), such as e.g., x86. We detect this case
5368 at the time we try to insert read watchpoints.
5370 2.2. Otherwise, the target supports read
5371 watchpoints, but, the user set an access or write
5372 watchpoint watching the same memory as this read
5375 If we're watching memory writes as well as reads,
5376 ignore watchpoint hits when we find that the
5377 value hasn't changed, as reads don't cause
5378 changes. This still gives false positives when
5379 the program writes the same value to memory as
5380 what there was already in memory (we will confuse
5381 it for a read), but it's much better than
5384 int other_write_watchpoint = 0;
5386 if (bl->watchpoint_type == hw_read)
5388 struct breakpoint *other_b;
5390 ALL_BREAKPOINTS (other_b)
5391 if (other_b->type == bp_hardware_watchpoint
5392 || other_b->type == bp_access_watchpoint)
5394 struct watchpoint *other_w =
5395 (struct watchpoint *) other_b;
5397 if (other_w->watchpoint_triggered
5398 == watch_triggered_yes)
5400 other_write_watchpoint = 1;
5406 if (other_write_watchpoint
5407 || bl->watchpoint_type == hw_access)
5409 /* We're watching the same memory for writes,
5410 and the value changed since the last time we
5411 updated it, so this trap must be for a write.
5413 bs->print_it = print_it_noop;
5418 case WP_VALUE_NOT_CHANGED:
5419 if (b->base.type == bp_hardware_watchpoint
5420 || b->base.type == bp_watchpoint)
5422 /* Don't stop: write watchpoints shouldn't fire if
5423 the value hasn't changed. */
5424 bs->print_it = print_it_noop;
5432 /* Error from catch_errors. */
5434 SWITCH_THRU_ALL_UIS ()
5436 printf_filtered (_("Watchpoint %d deleted.\n"),
5439 watchpoint_del_at_next_stop (b);
5440 /* We've already printed what needs to be printed. */
5441 bs->print_it = print_it_done;
5446 else /* must_check_value == 0 */
5448 /* This is a case where some watchpoint(s) triggered, but
5449 not at the address of this watchpoint, or else no
5450 watchpoint triggered after all. So don't print
5451 anything for this watchpoint. */
5452 bs->print_it = print_it_noop;
5458 /* For breakpoints that are currently marked as telling gdb to stop,
5459 check conditions (condition proper, frame, thread and ignore count)
5460 of breakpoint referred to by BS. If we should not stop for this
5461 breakpoint, set BS->stop to 0. */
5464 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5466 const struct bp_location *bl;
5467 struct breakpoint *b;
5468 int value_is_zero = 0;
5469 struct expression *cond;
5471 gdb_assert (bs->stop);
5473 /* BS is built for existing struct breakpoint. */
5474 bl = bs->bp_location_at;
5475 gdb_assert (bl != NULL);
5476 b = bs->breakpoint_at;
5477 gdb_assert (b != NULL);
5479 /* Even if the target evaluated the condition on its end and notified GDB, we
5480 need to do so again since GDB does not know if we stopped due to a
5481 breakpoint or a single step breakpoint. */
5483 if (frame_id_p (b->frame_id)
5484 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5490 /* If this is a thread/task-specific breakpoint, don't waste cpu
5491 evaluating the condition if this isn't the specified
5493 if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
5494 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5501 /* Evaluate extension language breakpoints that have a "stop" method
5503 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5505 if (is_watchpoint (b))
5507 struct watchpoint *w = (struct watchpoint *) b;
5509 cond = w->cond_exp.get ();
5512 cond = bl->cond.get ();
5514 if (cond && b->disposition != disp_del_at_next_stop)
5516 int within_current_scope = 1;
5517 struct watchpoint * w;
5519 /* We use value_mark and value_free_to_mark because it could
5520 be a long time before we return to the command level and
5521 call free_all_values. We can't call free_all_values
5522 because we might be in the middle of evaluating a
5524 struct value *mark = value_mark ();
5526 if (is_watchpoint (b))
5527 w = (struct watchpoint *) b;
5531 /* Need to select the frame, with all that implies so that
5532 the conditions will have the right context. Because we
5533 use the frame, we will not see an inlined function's
5534 variables when we arrive at a breakpoint at the start
5535 of the inlined function; the current frame will be the
5537 if (w == NULL || w->cond_exp_valid_block == NULL)
5538 select_frame (get_current_frame ());
5541 struct frame_info *frame;
5543 /* For local watchpoint expressions, which particular
5544 instance of a local is being watched matters, so we
5545 keep track of the frame to evaluate the expression
5546 in. To evaluate the condition however, it doesn't
5547 really matter which instantiation of the function
5548 where the condition makes sense triggers the
5549 watchpoint. This allows an expression like "watch
5550 global if q > 10" set in `func', catch writes to
5551 global on all threads that call `func', or catch
5552 writes on all recursive calls of `func' by a single
5553 thread. We simply always evaluate the condition in
5554 the innermost frame that's executing where it makes
5555 sense to evaluate the condition. It seems
5557 frame = block_innermost_frame (w->cond_exp_valid_block);
5559 select_frame (frame);
5561 within_current_scope = 0;
5563 if (within_current_scope)
5565 = catch_errors (breakpoint_cond_eval, cond,
5566 "Error in testing breakpoint condition:\n",
5570 warning (_("Watchpoint condition cannot be tested "
5571 "in the current scope"));
5572 /* If we failed to set the right context for this
5573 watchpoint, unconditionally report it. */
5576 /* FIXME-someday, should give breakpoint #. */
5577 value_free_to_mark (mark);
5580 if (cond && value_is_zero)
5584 else if (b->ignore_count > 0)
5588 /* Increase the hit count even though we don't stop. */
5590 observer_notify_breakpoint_modified (b);
5594 /* Returns true if we need to track moribund locations of LOC's type
5595 on the current target. */
5598 need_moribund_for_location_type (struct bp_location *loc)
5600 return ((loc->loc_type == bp_loc_software_breakpoint
5601 && !target_supports_stopped_by_sw_breakpoint ())
5602 || (loc->loc_type == bp_loc_hardware_breakpoint
5603 && !target_supports_stopped_by_hw_breakpoint ()));
5607 /* Get a bpstat associated with having just stopped at address
5608 BP_ADDR in thread PTID.
5610 Determine whether we stopped at a breakpoint, etc, or whether we
5611 don't understand this stop. Result is a chain of bpstat's such
5614 if we don't understand the stop, the result is a null pointer.
5616 if we understand why we stopped, the result is not null.
5618 Each element of the chain refers to a particular breakpoint or
5619 watchpoint at which we have stopped. (We may have stopped for
5620 several reasons concurrently.)
5622 Each element of the chain has valid next, breakpoint_at,
5623 commands, FIXME??? fields. */
5626 bpstat_stop_status (struct address_space *aspace,
5627 CORE_ADDR bp_addr, ptid_t ptid,
5628 const struct target_waitstatus *ws)
5630 struct breakpoint *b = NULL;
5631 struct bp_location *bl;
5632 struct bp_location *loc;
5633 /* First item of allocated bpstat's. */
5634 bpstat bs_head = NULL, *bs_link = &bs_head;
5635 /* Pointer to the last thing in the chain currently. */
5638 int need_remove_insert;
5641 /* First, build the bpstat chain with locations that explain a
5642 target stop, while being careful to not set the target running,
5643 as that may invalidate locations (in particular watchpoint
5644 locations are recreated). Resuming will happen here with
5645 breakpoint conditions or watchpoint expressions that include
5646 inferior function calls. */
5650 if (!breakpoint_enabled (b))
5653 for (bl = b->loc; bl != NULL; bl = bl->next)
5655 /* For hardware watchpoints, we look only at the first
5656 location. The watchpoint_check function will work on the
5657 entire expression, not the individual locations. For
5658 read watchpoints, the watchpoints_triggered function has
5659 checked all locations already. */
5660 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5663 if (!bl->enabled || bl->shlib_disabled)
5666 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5669 /* Come here if it's a watchpoint, or if the break address
5672 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5675 /* Assume we stop. Should we find a watchpoint that is not
5676 actually triggered, or if the condition of the breakpoint
5677 evaluates as false, we'll reset 'stop' to 0. */
5681 /* If this is a scope breakpoint, mark the associated
5682 watchpoint as triggered so that we will handle the
5683 out-of-scope event. We'll get to the watchpoint next
5685 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5687 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5689 w->watchpoint_triggered = watch_triggered_yes;
5694 /* Check if a moribund breakpoint explains the stop. */
5695 if (!target_supports_stopped_by_sw_breakpoint ()
5696 || !target_supports_stopped_by_hw_breakpoint ())
5698 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5700 if (breakpoint_location_address_match (loc, aspace, bp_addr)
5701 && need_moribund_for_location_type (loc))
5703 bs = bpstat_alloc (loc, &bs_link);
5704 /* For hits of moribund locations, we should just proceed. */
5707 bs->print_it = print_it_noop;
5712 /* A bit of special processing for shlib breakpoints. We need to
5713 process solib loading here, so that the lists of loaded and
5714 unloaded libraries are correct before we handle "catch load" and
5716 for (bs = bs_head; bs != NULL; bs = bs->next)
5718 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5720 handle_solib_event ();
5725 /* Now go through the locations that caused the target to stop, and
5726 check whether we're interested in reporting this stop to higher
5727 layers, or whether we should resume the target transparently. */
5731 for (bs = bs_head; bs != NULL; bs = bs->next)
5736 b = bs->breakpoint_at;
5737 b->ops->check_status (bs);
5740 bpstat_check_breakpoint_conditions (bs, ptid);
5745 observer_notify_breakpoint_modified (b);
5747 /* We will stop here. */
5748 if (b->disposition == disp_disable)
5750 --(b->enable_count);
5751 if (b->enable_count <= 0)
5752 b->enable_state = bp_disabled;
5757 bs->commands = b->commands;
5758 incref_counted_command_line (bs->commands);
5759 if (command_line_is_silent (bs->commands
5760 ? bs->commands->commands : NULL))
5763 b->ops->after_condition_true (bs);
5768 /* Print nothing for this entry if we don't stop or don't
5770 if (!bs->stop || !bs->print)
5771 bs->print_it = print_it_noop;
5774 /* If we aren't stopping, the value of some hardware watchpoint may
5775 not have changed, but the intermediate memory locations we are
5776 watching may have. Don't bother if we're stopping; this will get
5778 need_remove_insert = 0;
5779 if (! bpstat_causes_stop (bs_head))
5780 for (bs = bs_head; bs != NULL; bs = bs->next)
5782 && bs->breakpoint_at
5783 && is_hardware_watchpoint (bs->breakpoint_at))
5785 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5787 update_watchpoint (w, 0 /* don't reparse. */);
5788 need_remove_insert = 1;
5791 if (need_remove_insert)
5792 update_global_location_list (UGLL_MAY_INSERT);
5793 else if (removed_any)
5794 update_global_location_list (UGLL_DONT_INSERT);
5800 handle_jit_event (void)
5802 struct frame_info *frame;
5803 struct gdbarch *gdbarch;
5806 fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n");
5808 /* Switch terminal for any messages produced by
5809 breakpoint_re_set. */
5810 target_terminal_ours_for_output ();
5812 frame = get_current_frame ();
5813 gdbarch = get_frame_arch (frame);
5815 jit_event_handler (gdbarch);
5817 target_terminal_inferior ();
5820 /* Prepare WHAT final decision for infrun. */
5822 /* Decide what infrun needs to do with this bpstat. */
5825 bpstat_what (bpstat bs_head)
5827 struct bpstat_what retval;
5830 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5831 retval.call_dummy = STOP_NONE;
5832 retval.is_longjmp = 0;
5834 for (bs = bs_head; bs != NULL; bs = bs->next)
5836 /* Extract this BS's action. After processing each BS, we check
5837 if its action overrides all we've seem so far. */
5838 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5841 if (bs->breakpoint_at == NULL)
5843 /* I suspect this can happen if it was a momentary
5844 breakpoint which has since been deleted. */
5848 bptype = bs->breakpoint_at->type;
5855 case bp_hardware_breakpoint:
5856 case bp_single_step:
5859 case bp_shlib_event:
5863 this_action = BPSTAT_WHAT_STOP_NOISY;
5865 this_action = BPSTAT_WHAT_STOP_SILENT;
5868 this_action = BPSTAT_WHAT_SINGLE;
5871 case bp_hardware_watchpoint:
5872 case bp_read_watchpoint:
5873 case bp_access_watchpoint:
5877 this_action = BPSTAT_WHAT_STOP_NOISY;
5879 this_action = BPSTAT_WHAT_STOP_SILENT;
5883 /* There was a watchpoint, but we're not stopping.
5884 This requires no further action. */
5888 case bp_longjmp_call_dummy:
5892 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5893 retval.is_longjmp = bptype != bp_exception;
5896 this_action = BPSTAT_WHAT_SINGLE;
5898 case bp_longjmp_resume:
5899 case bp_exception_resume:
5902 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5903 retval.is_longjmp = bptype == bp_longjmp_resume;
5906 this_action = BPSTAT_WHAT_SINGLE;
5908 case bp_step_resume:
5910 this_action = BPSTAT_WHAT_STEP_RESUME;
5913 /* It is for the wrong frame. */
5914 this_action = BPSTAT_WHAT_SINGLE;
5917 case bp_hp_step_resume:
5919 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5922 /* It is for the wrong frame. */
5923 this_action = BPSTAT_WHAT_SINGLE;
5926 case bp_watchpoint_scope:
5927 case bp_thread_event:
5928 case bp_overlay_event:
5929 case bp_longjmp_master:
5930 case bp_std_terminate_master:
5931 case bp_exception_master:
5932 this_action = BPSTAT_WHAT_SINGLE;
5938 this_action = BPSTAT_WHAT_STOP_NOISY;
5940 this_action = BPSTAT_WHAT_STOP_SILENT;
5944 /* There was a catchpoint, but we're not stopping.
5945 This requires no further action. */
5949 this_action = BPSTAT_WHAT_SINGLE;
5952 /* Make sure the action is stop (silent or noisy),
5953 so infrun.c pops the dummy frame. */
5954 retval.call_dummy = STOP_STACK_DUMMY;
5955 this_action = BPSTAT_WHAT_STOP_SILENT;
5957 case bp_std_terminate:
5958 /* Make sure the action is stop (silent or noisy),
5959 so infrun.c pops the dummy frame. */
5960 retval.call_dummy = STOP_STD_TERMINATE;
5961 this_action = BPSTAT_WHAT_STOP_SILENT;
5964 case bp_fast_tracepoint:
5965 case bp_static_tracepoint:
5966 /* Tracepoint hits should not be reported back to GDB, and
5967 if one got through somehow, it should have been filtered
5969 internal_error (__FILE__, __LINE__,
5970 _("bpstat_what: tracepoint encountered"));
5972 case bp_gnu_ifunc_resolver:
5973 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5974 this_action = BPSTAT_WHAT_SINGLE;
5976 case bp_gnu_ifunc_resolver_return:
5977 /* The breakpoint will be removed, execution will restart from the
5978 PC of the former breakpoint. */
5979 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5984 this_action = BPSTAT_WHAT_STOP_SILENT;
5986 this_action = BPSTAT_WHAT_SINGLE;
5990 internal_error (__FILE__, __LINE__,
5991 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5994 retval.main_action = std::max (retval.main_action, this_action);
6001 bpstat_run_callbacks (bpstat bs_head)
6005 for (bs = bs_head; bs != NULL; bs = bs->next)
6007 struct breakpoint *b = bs->breakpoint_at;
6014 handle_jit_event ();
6016 case bp_gnu_ifunc_resolver:
6017 gnu_ifunc_resolver_stop (b);
6019 case bp_gnu_ifunc_resolver_return:
6020 gnu_ifunc_resolver_return_stop (b);
6026 /* Nonzero if we should step constantly (e.g. watchpoints on machines
6027 without hardware support). This isn't related to a specific bpstat,
6028 just to things like whether watchpoints are set. */
6031 bpstat_should_step (void)
6033 struct breakpoint *b;
6036 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
6042 bpstat_causes_stop (bpstat bs)
6044 for (; bs != NULL; bs = bs->next)
6053 /* Compute a string of spaces suitable to indent the next line
6054 so it starts at the position corresponding to the table column
6055 named COL_NAME in the currently active table of UIOUT. */
6058 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
6060 static char wrap_indent[80];
6061 int i, total_width, width, align;
6065 for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++)
6067 if (strcmp (text, col_name) == 0)
6069 gdb_assert (total_width < sizeof wrap_indent);
6070 memset (wrap_indent, ' ', total_width);
6071 wrap_indent[total_width] = 0;
6076 total_width += width + 1;
6082 /* Determine if the locations of this breakpoint will have their conditions
6083 evaluated by the target, host or a mix of both. Returns the following:
6085 "host": Host evals condition.
6086 "host or target": Host or Target evals condition.
6087 "target": Target evals condition.
6091 bp_condition_evaluator (struct breakpoint *b)
6093 struct bp_location *bl;
6094 char host_evals = 0;
6095 char target_evals = 0;
6100 if (!is_breakpoint (b))
6103 if (gdb_evaluates_breakpoint_condition_p ()
6104 || !target_supports_evaluation_of_breakpoint_conditions ())
6105 return condition_evaluation_host;
6107 for (bl = b->loc; bl; bl = bl->next)
6109 if (bl->cond_bytecode)
6115 if (host_evals && target_evals)
6116 return condition_evaluation_both;
6117 else if (target_evals)
6118 return condition_evaluation_target;
6120 return condition_evaluation_host;
6123 /* Determine the breakpoint location's condition evaluator. This is
6124 similar to bp_condition_evaluator, but for locations. */
6127 bp_location_condition_evaluator (struct bp_location *bl)
6129 if (bl && !is_breakpoint (bl->owner))
6132 if (gdb_evaluates_breakpoint_condition_p ()
6133 || !target_supports_evaluation_of_breakpoint_conditions ())
6134 return condition_evaluation_host;
6136 if (bl && bl->cond_bytecode)
6137 return condition_evaluation_target;
6139 return condition_evaluation_host;
6142 /* Print the LOC location out of the list of B->LOC locations. */
6145 print_breakpoint_location (struct breakpoint *b,
6146 struct bp_location *loc)
6148 struct ui_out *uiout = current_uiout;
6149 struct cleanup *old_chain = save_current_program_space ();
6151 if (loc != NULL && loc->shlib_disabled)
6155 set_current_program_space (loc->pspace);
6157 if (b->display_canonical)
6158 uiout->field_string ("what", event_location_to_string (b->location));
6159 else if (loc && loc->symtab)
6162 = find_pc_sect_function (loc->address, loc->section);
6165 uiout->text ("in ");
6166 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
6168 uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
6169 uiout->text ("at ");
6171 uiout->field_string ("file",
6172 symtab_to_filename_for_display (loc->symtab));
6175 if (uiout->is_mi_like_p ())
6176 uiout->field_string ("fullname", symtab_to_fullname (loc->symtab));
6178 uiout->field_int ("line", loc->line_number);
6182 struct ui_file *stb = mem_fileopen ();
6183 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6185 print_address_symbolic (loc->gdbarch, loc->address, stb,
6187 uiout->field_stream ("at", stb);
6189 do_cleanups (stb_chain);
6193 uiout->field_string ("pending", event_location_to_string (b->location));
6194 /* If extra_string is available, it could be holding a condition
6195 or dprintf arguments. In either case, make sure it is printed,
6196 too, but only for non-MI streams. */
6197 if (!uiout->is_mi_like_p () && b->extra_string != NULL)
6199 if (b->type == bp_dprintf)
6203 uiout->text (b->extra_string);
6207 if (loc && is_breakpoint (b)
6208 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6209 && bp_condition_evaluator (b) == condition_evaluation_both)
6212 uiout->field_string ("evaluated-by",
6213 bp_location_condition_evaluator (loc));
6217 do_cleanups (old_chain);
6221 bptype_string (enum bptype type)
6223 struct ep_type_description
6228 static struct ep_type_description bptypes[] =
6230 {bp_none, "?deleted?"},
6231 {bp_breakpoint, "breakpoint"},
6232 {bp_hardware_breakpoint, "hw breakpoint"},
6233 {bp_single_step, "sw single-step"},
6234 {bp_until, "until"},
6235 {bp_finish, "finish"},
6236 {bp_watchpoint, "watchpoint"},
6237 {bp_hardware_watchpoint, "hw watchpoint"},
6238 {bp_read_watchpoint, "read watchpoint"},
6239 {bp_access_watchpoint, "acc watchpoint"},
6240 {bp_longjmp, "longjmp"},
6241 {bp_longjmp_resume, "longjmp resume"},
6242 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6243 {bp_exception, "exception"},
6244 {bp_exception_resume, "exception resume"},
6245 {bp_step_resume, "step resume"},
6246 {bp_hp_step_resume, "high-priority step resume"},
6247 {bp_watchpoint_scope, "watchpoint scope"},
6248 {bp_call_dummy, "call dummy"},
6249 {bp_std_terminate, "std::terminate"},
6250 {bp_shlib_event, "shlib events"},
6251 {bp_thread_event, "thread events"},
6252 {bp_overlay_event, "overlay events"},
6253 {bp_longjmp_master, "longjmp master"},
6254 {bp_std_terminate_master, "std::terminate master"},
6255 {bp_exception_master, "exception master"},
6256 {bp_catchpoint, "catchpoint"},
6257 {bp_tracepoint, "tracepoint"},
6258 {bp_fast_tracepoint, "fast tracepoint"},
6259 {bp_static_tracepoint, "static tracepoint"},
6260 {bp_dprintf, "dprintf"},
6261 {bp_jit_event, "jit events"},
6262 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6263 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6266 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6267 || ((int) type != bptypes[(int) type].type))
6268 internal_error (__FILE__, __LINE__,
6269 _("bptypes table does not describe type #%d."),
6272 return bptypes[(int) type].description;
6275 /* For MI, output a field named 'thread-groups' with a list as the value.
6276 For CLI, prefix the list with the string 'inf'. */
6279 output_thread_groups (struct ui_out *uiout,
6280 const char *field_name,
6284 struct cleanup *back_to;
6285 int is_mi = uiout->is_mi_like_p ();
6289 /* For backward compatibility, don't display inferiors in CLI unless
6290 there are several. Always display them for MI. */
6291 if (!is_mi && mi_only)
6294 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6296 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6302 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6303 uiout->field_string (NULL, mi_group);
6308 uiout->text (" inf ");
6312 uiout->text (plongest (inf));
6316 do_cleanups (back_to);
6319 /* Print B to gdb_stdout. */
6322 print_one_breakpoint_location (struct breakpoint *b,
6323 struct bp_location *loc,
6325 struct bp_location **last_loc,
6328 struct command_line *l;
6329 static char bpenables[] = "nynny";
6331 struct ui_out *uiout = current_uiout;
6332 int header_of_multiple = 0;
6333 int part_of_multiple = (loc != NULL);
6334 struct value_print_options opts;
6336 get_user_print_options (&opts);
6338 gdb_assert (!loc || loc_number != 0);
6339 /* See comment in print_one_breakpoint concerning treatment of
6340 breakpoints with single disabled location. */
6343 && (b->loc->next != NULL || !b->loc->enabled)))
6344 header_of_multiple = 1;
6352 if (part_of_multiple)
6355 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6356 uiout->field_string ("number", formatted);
6361 uiout->field_int ("number", b->number);
6366 if (part_of_multiple)
6367 uiout->field_skip ("type");
6369 uiout->field_string ("type", bptype_string (b->type));
6373 if (part_of_multiple)
6374 uiout->field_skip ("disp");
6376 uiout->field_string ("disp", bpdisp_text (b->disposition));
6381 if (part_of_multiple)
6382 uiout->field_string ("enabled", loc->enabled ? "y" : "n");
6384 uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]);
6389 if (b->ops != NULL && b->ops->print_one != NULL)
6391 /* Although the print_one can possibly print all locations,
6392 calling it here is not likely to get any nice result. So,
6393 make sure there's just one location. */
6394 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6395 b->ops->print_one (b, last_loc);
6401 internal_error (__FILE__, __LINE__,
6402 _("print_one_breakpoint: bp_none encountered\n"));
6406 case bp_hardware_watchpoint:
6407 case bp_read_watchpoint:
6408 case bp_access_watchpoint:
6410 struct watchpoint *w = (struct watchpoint *) b;
6412 /* Field 4, the address, is omitted (which makes the columns
6413 not line up too nicely with the headers, but the effect
6414 is relatively readable). */
6415 if (opts.addressprint)
6416 uiout->field_skip ("addr");
6418 uiout->field_string ("what", w->exp_string);
6423 case bp_hardware_breakpoint:
6424 case bp_single_step:
6428 case bp_longjmp_resume:
6429 case bp_longjmp_call_dummy:
6431 case bp_exception_resume:
6432 case bp_step_resume:
6433 case bp_hp_step_resume:
6434 case bp_watchpoint_scope:
6436 case bp_std_terminate:
6437 case bp_shlib_event:
6438 case bp_thread_event:
6439 case bp_overlay_event:
6440 case bp_longjmp_master:
6441 case bp_std_terminate_master:
6442 case bp_exception_master:
6444 case bp_fast_tracepoint:
6445 case bp_static_tracepoint:
6448 case bp_gnu_ifunc_resolver:
6449 case bp_gnu_ifunc_resolver_return:
6450 if (opts.addressprint)
6453 if (header_of_multiple)
6454 uiout->field_string ("addr", "<MULTIPLE>");
6455 else if (b->loc == NULL || loc->shlib_disabled)
6456 uiout->field_string ("addr", "<PENDING>");
6458 uiout->field_core_addr ("addr",
6459 loc->gdbarch, loc->address);
6462 if (!header_of_multiple)
6463 print_breakpoint_location (b, loc);
6470 if (loc != NULL && !header_of_multiple)
6472 struct inferior *inf;
6473 VEC(int) *inf_num = NULL;
6478 if (inf->pspace == loc->pspace)
6479 VEC_safe_push (int, inf_num, inf->num);
6482 /* For backward compatibility, don't display inferiors in CLI unless
6483 there are several. Always display for MI. */
6485 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6486 && (number_of_program_spaces () > 1
6487 || number_of_inferiors () > 1)
6488 /* LOC is for existing B, it cannot be in
6489 moribund_locations and thus having NULL OWNER. */
6490 && loc->owner->type != bp_catchpoint))
6492 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6493 VEC_free (int, inf_num);
6496 if (!part_of_multiple)
6498 if (b->thread != -1)
6500 /* FIXME: This seems to be redundant and lost here; see the
6501 "stop only in" line a little further down. */
6502 uiout->text (" thread ");
6503 uiout->field_int ("thread", b->thread);
6505 else if (b->task != 0)
6507 uiout->text (" task ");
6508 uiout->field_int ("task", b->task);
6514 if (!part_of_multiple)
6515 b->ops->print_one_detail (b, uiout);
6517 if (part_of_multiple && frame_id_p (b->frame_id))
6520 uiout->text ("\tstop only in stack frame at ");
6521 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6523 uiout->field_core_addr ("frame",
6524 b->gdbarch, b->frame_id.stack_addr);
6528 if (!part_of_multiple && b->cond_string)
6531 if (is_tracepoint (b))
6532 uiout->text ("\ttrace only if ");
6534 uiout->text ("\tstop only if ");
6535 uiout->field_string ("cond", b->cond_string);
6537 /* Print whether the target is doing the breakpoint's condition
6538 evaluation. If GDB is doing the evaluation, don't print anything. */
6539 if (is_breakpoint (b)
6540 && breakpoint_condition_evaluation_mode ()
6541 == condition_evaluation_target)
6544 uiout->field_string ("evaluated-by",
6545 bp_condition_evaluator (b));
6546 uiout->text (" evals)");
6551 if (!part_of_multiple && b->thread != -1)
6553 /* FIXME should make an annotation for this. */
6554 uiout->text ("\tstop only in thread ");
6555 if (uiout->is_mi_like_p ())
6556 uiout->field_int ("thread", b->thread);
6559 struct thread_info *thr = find_thread_global_id (b->thread);
6561 uiout->field_string ("thread", print_thread_id (thr));
6566 if (!part_of_multiple)
6570 /* FIXME should make an annotation for this. */
6571 if (is_catchpoint (b))
6572 uiout->text ("\tcatchpoint");
6573 else if (is_tracepoint (b))
6574 uiout->text ("\ttracepoint");
6576 uiout->text ("\tbreakpoint");
6577 uiout->text (" already hit ");
6578 uiout->field_int ("times", b->hit_count);
6579 if (b->hit_count == 1)
6580 uiout->text (" time\n");
6582 uiout->text (" times\n");
6586 /* Output the count also if it is zero, but only if this is mi. */
6587 if (uiout->is_mi_like_p ())
6588 uiout->field_int ("times", b->hit_count);
6592 if (!part_of_multiple && b->ignore_count)
6595 uiout->text ("\tignore next ");
6596 uiout->field_int ("ignore", b->ignore_count);
6597 uiout->text (" hits\n");
6600 /* Note that an enable count of 1 corresponds to "enable once"
6601 behavior, which is reported by the combination of enablement and
6602 disposition, so we don't need to mention it here. */
6603 if (!part_of_multiple && b->enable_count > 1)
6606 uiout->text ("\tdisable after ");
6607 /* Tweak the wording to clarify that ignore and enable counts
6608 are distinct, and have additive effect. */
6609 if (b->ignore_count)
6610 uiout->text ("additional ");
6612 uiout->text ("next ");
6613 uiout->field_int ("enable", b->enable_count);
6614 uiout->text (" hits\n");
6617 if (!part_of_multiple && is_tracepoint (b))
6619 struct tracepoint *tp = (struct tracepoint *) b;
6621 if (tp->traceframe_usage)
6623 uiout->text ("\ttrace buffer usage ");
6624 uiout->field_int ("traceframe-usage", tp->traceframe_usage);
6625 uiout->text (" bytes\n");
6629 l = b->commands ? b->commands->commands : NULL;
6630 if (!part_of_multiple && l)
6632 struct cleanup *script_chain;
6635 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6636 print_command_lines (uiout, l, 4);
6637 do_cleanups (script_chain);
6640 if (is_tracepoint (b))
6642 struct tracepoint *t = (struct tracepoint *) b;
6644 if (!part_of_multiple && t->pass_count)
6646 annotate_field (10);
6647 uiout->text ("\tpass count ");
6648 uiout->field_int ("pass", t->pass_count);
6649 uiout->text (" \n");
6652 /* Don't display it when tracepoint or tracepoint location is
6654 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6656 annotate_field (11);
6658 if (uiout->is_mi_like_p ())
6659 uiout->field_string ("installed",
6660 loc->inserted ? "y" : "n");
6666 uiout->text ("\tnot ");
6667 uiout->text ("installed on target\n");
6672 if (uiout->is_mi_like_p () && !part_of_multiple)
6674 if (is_watchpoint (b))
6676 struct watchpoint *w = (struct watchpoint *) b;
6678 uiout->field_string ("original-location", w->exp_string);
6680 else if (b->location != NULL
6681 && event_location_to_string (b->location) != NULL)
6682 uiout->field_string ("original-location",
6683 event_location_to_string (b->location));
6688 print_one_breakpoint (struct breakpoint *b,
6689 struct bp_location **last_loc,
6692 struct cleanup *bkpt_chain;
6693 struct ui_out *uiout = current_uiout;
6695 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6697 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6698 do_cleanups (bkpt_chain);
6700 /* If this breakpoint has custom print function,
6701 it's already printed. Otherwise, print individual
6702 locations, if any. */
6703 if (b->ops == NULL || b->ops->print_one == NULL)
6705 /* If breakpoint has a single location that is disabled, we
6706 print it as if it had several locations, since otherwise it's
6707 hard to represent "breakpoint enabled, location disabled"
6710 Note that while hardware watchpoints have several locations
6711 internally, that's not a property exposed to user. */
6713 && !is_hardware_watchpoint (b)
6714 && (b->loc->next || !b->loc->enabled))
6716 struct bp_location *loc;
6719 for (loc = b->loc; loc; loc = loc->next, ++n)
6721 struct cleanup *inner2 =
6722 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6723 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6724 do_cleanups (inner2);
6731 breakpoint_address_bits (struct breakpoint *b)
6733 int print_address_bits = 0;
6734 struct bp_location *loc;
6736 /* Software watchpoints that aren't watching memory don't have an
6737 address to print. */
6738 if (is_no_memory_software_watchpoint (b))
6741 for (loc = b->loc; loc; loc = loc->next)
6745 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6746 if (addr_bit > print_address_bits)
6747 print_address_bits = addr_bit;
6750 return print_address_bits;
6753 struct captured_breakpoint_query_args
6759 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6761 struct captured_breakpoint_query_args *args
6762 = (struct captured_breakpoint_query_args *) data;
6763 struct breakpoint *b;
6764 struct bp_location *dummy_loc = NULL;
6768 if (args->bnum == b->number)
6770 print_one_breakpoint (b, &dummy_loc, 0);
6778 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6779 char **error_message)
6781 struct captured_breakpoint_query_args args;
6784 /* For the moment we don't trust print_one_breakpoint() to not throw
6786 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6787 error_message, RETURN_MASK_ALL) < 0)
6793 /* Return true if this breakpoint was set by the user, false if it is
6794 internal or momentary. */
6797 user_breakpoint_p (struct breakpoint *b)
6799 return b->number > 0;
6802 /* See breakpoint.h. */
6805 pending_breakpoint_p (struct breakpoint *b)
6807 return b->loc == NULL;
6810 /* Print information on user settable breakpoint (watchpoint, etc)
6811 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6812 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6813 FILTER is non-NULL, call it on each breakpoint and only include the
6814 ones for which it returns non-zero. Return the total number of
6815 breakpoints listed. */
6818 breakpoint_1 (char *args, int allflag,
6819 int (*filter) (const struct breakpoint *))
6821 struct breakpoint *b;
6822 struct bp_location *last_loc = NULL;
6823 int nr_printable_breakpoints;
6824 struct cleanup *bkpttbl_chain;
6825 struct value_print_options opts;
6826 int print_address_bits = 0;
6827 int print_type_col_width = 14;
6828 struct ui_out *uiout = current_uiout;
6830 get_user_print_options (&opts);
6832 /* Compute the number of rows in the table, as well as the size
6833 required for address fields. */
6834 nr_printable_breakpoints = 0;
6837 /* If we have a filter, only list the breakpoints it accepts. */
6838 if (filter && !filter (b))
6841 /* If we have an "args" string, it is a list of breakpoints to
6842 accept. Skip the others. */
6843 if (args != NULL && *args != '\0')
6845 if (allflag && parse_and_eval_long (args) != b->number)
6847 if (!allflag && !number_is_in_list (args, b->number))
6851 if (allflag || user_breakpoint_p (b))
6853 int addr_bit, type_len;
6855 addr_bit = breakpoint_address_bits (b);
6856 if (addr_bit > print_address_bits)
6857 print_address_bits = addr_bit;
6859 type_len = strlen (bptype_string (b->type));
6860 if (type_len > print_type_col_width)
6861 print_type_col_width = type_len;
6863 nr_printable_breakpoints++;
6867 if (opts.addressprint)
6869 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6870 nr_printable_breakpoints,
6874 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6875 nr_printable_breakpoints,
6878 if (nr_printable_breakpoints > 0)
6879 annotate_breakpoints_headers ();
6880 if (nr_printable_breakpoints > 0)
6882 uiout->table_header (7, ui_left, "number", "Num"); /* 1 */
6883 if (nr_printable_breakpoints > 0)
6885 uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */
6886 if (nr_printable_breakpoints > 0)
6888 uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */
6889 if (nr_printable_breakpoints > 0)
6891 uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */
6892 if (opts.addressprint)
6894 if (nr_printable_breakpoints > 0)
6896 if (print_address_bits <= 32)
6897 uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */
6899 uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */
6901 if (nr_printable_breakpoints > 0)
6903 uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */
6904 uiout->table_body ();
6905 if (nr_printable_breakpoints > 0)
6906 annotate_breakpoints_table ();
6911 /* If we have a filter, only list the breakpoints it accepts. */
6912 if (filter && !filter (b))
6915 /* If we have an "args" string, it is a list of breakpoints to
6916 accept. Skip the others. */
6918 if (args != NULL && *args != '\0')
6920 if (allflag) /* maintenance info breakpoint */
6922 if (parse_and_eval_long (args) != b->number)
6925 else /* all others */
6927 if (!number_is_in_list (args, b->number))
6931 /* We only print out user settable breakpoints unless the
6933 if (allflag || user_breakpoint_p (b))
6934 print_one_breakpoint (b, &last_loc, allflag);
6937 do_cleanups (bkpttbl_chain);
6939 if (nr_printable_breakpoints == 0)
6941 /* If there's a filter, let the caller decide how to report
6945 if (args == NULL || *args == '\0')
6946 uiout->message ("No breakpoints or watchpoints.\n");
6948 uiout->message ("No breakpoint or watchpoint matching '%s'.\n",
6954 if (last_loc && !server_command)
6955 set_next_address (last_loc->gdbarch, last_loc->address);
6958 /* FIXME? Should this be moved up so that it is only called when
6959 there have been breakpoints? */
6960 annotate_breakpoints_table_end ();
6962 return nr_printable_breakpoints;
6965 /* Display the value of default-collect in a way that is generally
6966 compatible with the breakpoint list. */
6969 default_collect_info (void)
6971 struct ui_out *uiout = current_uiout;
6973 /* If it has no value (which is frequently the case), say nothing; a
6974 message like "No default-collect." gets in user's face when it's
6976 if (!*default_collect)
6979 /* The following phrase lines up nicely with per-tracepoint collect
6981 uiout->text ("default collect ");
6982 uiout->field_string ("default-collect", default_collect);
6983 uiout->text (" \n");
6987 breakpoints_info (char *args, int from_tty)
6989 breakpoint_1 (args, 0, NULL);
6991 default_collect_info ();
6995 watchpoints_info (char *args, int from_tty)
6997 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6998 struct ui_out *uiout = current_uiout;
7000 if (num_printed == 0)
7002 if (args == NULL || *args == '\0')
7003 uiout->message ("No watchpoints.\n");
7005 uiout->message ("No watchpoint matching '%s'.\n", args);
7010 maintenance_info_breakpoints (char *args, int from_tty)
7012 breakpoint_1 (args, 1, NULL);
7014 default_collect_info ();
7018 breakpoint_has_pc (struct breakpoint *b,
7019 struct program_space *pspace,
7020 CORE_ADDR pc, struct obj_section *section)
7022 struct bp_location *bl = b->loc;
7024 for (; bl; bl = bl->next)
7026 if (bl->pspace == pspace
7027 && bl->address == pc
7028 && (!overlay_debugging || bl->section == section))
7034 /* Print a message describing any user-breakpoints set at PC. This
7035 concerns with logical breakpoints, so we match program spaces, not
7039 describe_other_breakpoints (struct gdbarch *gdbarch,
7040 struct program_space *pspace, CORE_ADDR pc,
7041 struct obj_section *section, int thread)
7044 struct breakpoint *b;
7047 others += (user_breakpoint_p (b)
7048 && breakpoint_has_pc (b, pspace, pc, section));
7052 printf_filtered (_("Note: breakpoint "));
7053 else /* if (others == ???) */
7054 printf_filtered (_("Note: breakpoints "));
7056 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
7059 printf_filtered ("%d", b->number);
7060 if (b->thread == -1 && thread != -1)
7061 printf_filtered (" (all threads)");
7062 else if (b->thread != -1)
7063 printf_filtered (" (thread %d)", b->thread);
7064 printf_filtered ("%s%s ",
7065 ((b->enable_state == bp_disabled
7066 || b->enable_state == bp_call_disabled)
7070 : ((others == 1) ? " and" : ""));
7072 printf_filtered (_("also set at pc "));
7073 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
7074 printf_filtered (".\n");
7079 /* Return true iff it is meaningful to use the address member of
7080 BPT locations. For some breakpoint types, the locations' address members
7081 are irrelevant and it makes no sense to attempt to compare them to other
7082 addresses (or use them for any other purpose either).
7084 More specifically, each of the following breakpoint types will
7085 always have a zero valued location address and we don't want to mark
7086 breakpoints of any of these types to be a duplicate of an actual
7087 breakpoint location at address zero:
7095 breakpoint_address_is_meaningful (struct breakpoint *bpt)
7097 enum bptype type = bpt->type;
7099 return (type != bp_watchpoint && type != bp_catchpoint);
7102 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7103 true if LOC1 and LOC2 represent the same watchpoint location. */
7106 watchpoint_locations_match (struct bp_location *loc1,
7107 struct bp_location *loc2)
7109 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
7110 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
7112 /* Both of them must exist. */
7113 gdb_assert (w1 != NULL);
7114 gdb_assert (w2 != NULL);
7116 /* If the target can evaluate the condition expression in hardware,
7117 then we we need to insert both watchpoints even if they are at
7118 the same place. Otherwise the watchpoint will only trigger when
7119 the condition of whichever watchpoint was inserted evaluates to
7120 true, not giving a chance for GDB to check the condition of the
7121 other watchpoint. */
7123 && target_can_accel_watchpoint_condition (loc1->address,
7125 loc1->watchpoint_type,
7126 w1->cond_exp.get ()))
7128 && target_can_accel_watchpoint_condition (loc2->address,
7130 loc2->watchpoint_type,
7131 w2->cond_exp.get ())))
7134 /* Note that this checks the owner's type, not the location's. In
7135 case the target does not support read watchpoints, but does
7136 support access watchpoints, we'll have bp_read_watchpoint
7137 watchpoints with hw_access locations. Those should be considered
7138 duplicates of hw_read locations. The hw_read locations will
7139 become hw_access locations later. */
7140 return (loc1->owner->type == loc2->owner->type
7141 && loc1->pspace->aspace == loc2->pspace->aspace
7142 && loc1->address == loc2->address
7143 && loc1->length == loc2->length);
7146 /* See breakpoint.h. */
7149 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7150 struct address_space *aspace2, CORE_ADDR addr2)
7152 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7153 || aspace1 == aspace2)
7157 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7158 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7159 matches ASPACE2. On targets that have global breakpoints, the address
7160 space doesn't really matter. */
7163 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7164 int len1, struct address_space *aspace2,
7167 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7168 || aspace1 == aspace2)
7169 && addr2 >= addr1 && addr2 < addr1 + len1);
7172 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7173 a ranged breakpoint. In most targets, a match happens only if ASPACE
7174 matches the breakpoint's address space. On targets that have global
7175 breakpoints, the address space doesn't really matter. */
7178 breakpoint_location_address_match (struct bp_location *bl,
7179 struct address_space *aspace,
7182 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7185 && breakpoint_address_match_range (bl->pspace->aspace,
7186 bl->address, bl->length,
7190 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7191 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7192 match happens only if ASPACE matches the breakpoint's address
7193 space. On targets that have global breakpoints, the address space
7194 doesn't really matter. */
7197 breakpoint_location_address_range_overlap (struct bp_location *bl,
7198 struct address_space *aspace,
7199 CORE_ADDR addr, int len)
7201 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7202 || bl->pspace->aspace == aspace)
7204 int bl_len = bl->length != 0 ? bl->length : 1;
7206 if (mem_ranges_overlap (addr, len, bl->address, bl_len))
7212 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7213 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7214 true, otherwise returns false. */
7217 tracepoint_locations_match (struct bp_location *loc1,
7218 struct bp_location *loc2)
7220 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7221 /* Since tracepoint locations are never duplicated with others', tracepoint
7222 locations at the same address of different tracepoints are regarded as
7223 different locations. */
7224 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7229 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7230 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7231 represent the same location. */
7234 breakpoint_locations_match (struct bp_location *loc1,
7235 struct bp_location *loc2)
7237 int hw_point1, hw_point2;
7239 /* Both of them must not be in moribund_locations. */
7240 gdb_assert (loc1->owner != NULL);
7241 gdb_assert (loc2->owner != NULL);
7243 hw_point1 = is_hardware_watchpoint (loc1->owner);
7244 hw_point2 = is_hardware_watchpoint (loc2->owner);
7246 if (hw_point1 != hw_point2)
7249 return watchpoint_locations_match (loc1, loc2);
7250 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7251 return tracepoint_locations_match (loc1, loc2);
7253 /* We compare bp_location.length in order to cover ranged breakpoints. */
7254 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7255 loc2->pspace->aspace, loc2->address)
7256 && loc1->length == loc2->length);
7260 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7261 int bnum, int have_bnum)
7263 /* The longest string possibly returned by hex_string_custom
7264 is 50 chars. These must be at least that big for safety. */
7268 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7269 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7271 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7272 bnum, astr1, astr2);
7274 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7277 /* Adjust a breakpoint's address to account for architectural
7278 constraints on breakpoint placement. Return the adjusted address.
7279 Note: Very few targets require this kind of adjustment. For most
7280 targets, this function is simply the identity function. */
7283 adjust_breakpoint_address (struct gdbarch *gdbarch,
7284 CORE_ADDR bpaddr, enum bptype bptype)
7286 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7288 /* Very few targets need any kind of breakpoint adjustment. */
7291 else if (bptype == bp_watchpoint
7292 || bptype == bp_hardware_watchpoint
7293 || bptype == bp_read_watchpoint
7294 || bptype == bp_access_watchpoint
7295 || bptype == bp_catchpoint)
7297 /* Watchpoints and the various bp_catch_* eventpoints should not
7298 have their addresses modified. */
7301 else if (bptype == bp_single_step)
7303 /* Single-step breakpoints should not have their addresses
7304 modified. If there's any architectural constrain that
7305 applies to this address, then it should have already been
7306 taken into account when the breakpoint was created in the
7307 first place. If we didn't do this, stepping through e.g.,
7308 Thumb-2 IT blocks would break. */
7313 CORE_ADDR adjusted_bpaddr;
7315 /* Some targets have architectural constraints on the placement
7316 of breakpoint instructions. Obtain the adjusted address. */
7317 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7319 /* An adjusted breakpoint address can significantly alter
7320 a user's expectations. Print a warning if an adjustment
7322 if (adjusted_bpaddr != bpaddr)
7323 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7325 return adjusted_bpaddr;
7330 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7331 struct breakpoint *owner)
7333 memset (loc, 0, sizeof (*loc));
7335 gdb_assert (ops != NULL);
7339 loc->cond_bytecode = NULL;
7340 loc->shlib_disabled = 0;
7343 switch (owner->type)
7346 case bp_single_step:
7350 case bp_longjmp_resume:
7351 case bp_longjmp_call_dummy:
7353 case bp_exception_resume:
7354 case bp_step_resume:
7355 case bp_hp_step_resume:
7356 case bp_watchpoint_scope:
7358 case bp_std_terminate:
7359 case bp_shlib_event:
7360 case bp_thread_event:
7361 case bp_overlay_event:
7363 case bp_longjmp_master:
7364 case bp_std_terminate_master:
7365 case bp_exception_master:
7366 case bp_gnu_ifunc_resolver:
7367 case bp_gnu_ifunc_resolver_return:
7369 loc->loc_type = bp_loc_software_breakpoint;
7370 mark_breakpoint_location_modified (loc);
7372 case bp_hardware_breakpoint:
7373 loc->loc_type = bp_loc_hardware_breakpoint;
7374 mark_breakpoint_location_modified (loc);
7376 case bp_hardware_watchpoint:
7377 case bp_read_watchpoint:
7378 case bp_access_watchpoint:
7379 loc->loc_type = bp_loc_hardware_watchpoint;
7384 case bp_fast_tracepoint:
7385 case bp_static_tracepoint:
7386 loc->loc_type = bp_loc_other;
7389 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7395 /* Allocate a struct bp_location. */
7397 static struct bp_location *
7398 allocate_bp_location (struct breakpoint *bpt)
7400 return bpt->ops->allocate_location (bpt);
7404 free_bp_location (struct bp_location *loc)
7406 loc->ops->dtor (loc);
7410 /* Increment reference count. */
7413 incref_bp_location (struct bp_location *bl)
7418 /* Decrement reference count. If the reference count reaches 0,
7419 destroy the bp_location. Sets *BLP to NULL. */
7422 decref_bp_location (struct bp_location **blp)
7424 gdb_assert ((*blp)->refc > 0);
7426 if (--(*blp)->refc == 0)
7427 free_bp_location (*blp);
7431 /* Add breakpoint B at the end of the global breakpoint chain. */
7434 add_to_breakpoint_chain (struct breakpoint *b)
7436 struct breakpoint *b1;
7438 /* Add this breakpoint to the end of the chain so that a list of
7439 breakpoints will come out in order of increasing numbers. */
7441 b1 = breakpoint_chain;
7443 breakpoint_chain = b;
7452 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7455 init_raw_breakpoint_without_location (struct breakpoint *b,
7456 struct gdbarch *gdbarch,
7458 const struct breakpoint_ops *ops)
7460 memset (b, 0, sizeof (*b));
7462 gdb_assert (ops != NULL);
7466 b->gdbarch = gdbarch;
7467 b->language = current_language->la_language;
7468 b->input_radix = input_radix;
7470 b->enable_state = bp_enabled;
7473 b->ignore_count = 0;
7475 b->frame_id = null_frame_id;
7476 b->condition_not_parsed = 0;
7477 b->py_bp_object = NULL;
7478 b->related_breakpoint = b;
7482 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7483 that has type BPTYPE and has no locations as yet. */
7485 static struct breakpoint *
7486 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7488 const struct breakpoint_ops *ops)
7490 struct breakpoint *b = new breakpoint ();
7492 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7493 add_to_breakpoint_chain (b);
7497 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7498 resolutions should be made as the user specified the location explicitly
7502 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7504 gdb_assert (loc->owner != NULL);
7506 if (loc->owner->type == bp_breakpoint
7507 || loc->owner->type == bp_hardware_breakpoint
7508 || is_tracepoint (loc->owner))
7511 const char *function_name;
7512 CORE_ADDR func_addr;
7514 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7515 &func_addr, NULL, &is_gnu_ifunc);
7517 if (is_gnu_ifunc && !explicit_loc)
7519 struct breakpoint *b = loc->owner;
7521 gdb_assert (loc->pspace == current_program_space);
7522 if (gnu_ifunc_resolve_name (function_name,
7523 &loc->requested_address))
7525 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7526 loc->address = adjust_breakpoint_address (loc->gdbarch,
7527 loc->requested_address,
7530 else if (b->type == bp_breakpoint && b->loc == loc
7531 && loc->next == NULL && b->related_breakpoint == b)
7533 /* Create only the whole new breakpoint of this type but do not
7534 mess more complicated breakpoints with multiple locations. */
7535 b->type = bp_gnu_ifunc_resolver;
7536 /* Remember the resolver's address for use by the return
7538 loc->related_address = func_addr;
7543 loc->function_name = xstrdup (function_name);
7547 /* Attempt to determine architecture of location identified by SAL. */
7549 get_sal_arch (struct symtab_and_line sal)
7552 return get_objfile_arch (sal.section->objfile);
7554 return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7559 /* Low level routine for partially initializing a breakpoint of type
7560 BPTYPE. The newly created breakpoint's address, section, source
7561 file name, and line number are provided by SAL.
7563 It is expected that the caller will complete the initialization of
7564 the newly created breakpoint struct as well as output any status
7565 information regarding the creation of a new breakpoint. */
7568 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7569 struct symtab_and_line sal, enum bptype bptype,
7570 const struct breakpoint_ops *ops)
7572 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7574 add_location_to_breakpoint (b, &sal);
7576 if (bptype != bp_catchpoint)
7577 gdb_assert (sal.pspace != NULL);
7579 /* Store the program space that was used to set the breakpoint,
7580 except for ordinary breakpoints, which are independent of the
7582 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7583 b->pspace = sal.pspace;
7586 /* set_raw_breakpoint is a low level routine for allocating and
7587 partially initializing a breakpoint of type BPTYPE. The newly
7588 created breakpoint's address, section, source file name, and line
7589 number are provided by SAL. The newly created and partially
7590 initialized breakpoint is added to the breakpoint chain and
7591 is also returned as the value of this function.
7593 It is expected that the caller will complete the initialization of
7594 the newly created breakpoint struct as well as output any status
7595 information regarding the creation of a new breakpoint. In
7596 particular, set_raw_breakpoint does NOT set the breakpoint
7597 number! Care should be taken to not allow an error to occur
7598 prior to completing the initialization of the breakpoint. If this
7599 should happen, a bogus breakpoint will be left on the chain. */
7602 set_raw_breakpoint (struct gdbarch *gdbarch,
7603 struct symtab_and_line sal, enum bptype bptype,
7604 const struct breakpoint_ops *ops)
7606 struct breakpoint *b = new breakpoint ();
7608 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7609 add_to_breakpoint_chain (b);
7613 /* Call this routine when stepping and nexting to enable a breakpoint
7614 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7615 initiated the operation. */
7618 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7620 struct breakpoint *b, *b_tmp;
7621 int thread = tp->global_num;
7623 /* To avoid having to rescan all objfile symbols at every step,
7624 we maintain a list of continually-inserted but always disabled
7625 longjmp "master" breakpoints. Here, we simply create momentary
7626 clones of those and enable them for the requested thread. */
7627 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7628 if (b->pspace == current_program_space
7629 && (b->type == bp_longjmp_master
7630 || b->type == bp_exception_master))
7632 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7633 struct breakpoint *clone;
7635 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7636 after their removal. */
7637 clone = momentary_breakpoint_from_master (b, type,
7638 &longjmp_breakpoint_ops, 1);
7639 clone->thread = thread;
7642 tp->initiating_frame = frame;
7645 /* Delete all longjmp breakpoints from THREAD. */
7647 delete_longjmp_breakpoint (int thread)
7649 struct breakpoint *b, *b_tmp;
7651 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7652 if (b->type == bp_longjmp || b->type == bp_exception)
7654 if (b->thread == thread)
7655 delete_breakpoint (b);
7660 delete_longjmp_breakpoint_at_next_stop (int thread)
7662 struct breakpoint *b, *b_tmp;
7664 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7665 if (b->type == bp_longjmp || b->type == bp_exception)
7667 if (b->thread == thread)
7668 b->disposition = disp_del_at_next_stop;
7672 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7673 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7674 pointer to any of them. Return NULL if this system cannot place longjmp
7678 set_longjmp_breakpoint_for_call_dummy (void)
7680 struct breakpoint *b, *retval = NULL;
7683 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7685 struct breakpoint *new_b;
7687 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7688 &momentary_breakpoint_ops,
7690 new_b->thread = ptid_to_global_thread_id (inferior_ptid);
7692 /* Link NEW_B into the chain of RETVAL breakpoints. */
7694 gdb_assert (new_b->related_breakpoint == new_b);
7697 new_b->related_breakpoint = retval;
7698 while (retval->related_breakpoint != new_b->related_breakpoint)
7699 retval = retval->related_breakpoint;
7700 retval->related_breakpoint = new_b;
7706 /* Verify all existing dummy frames and their associated breakpoints for
7707 TP. Remove those which can no longer be found in the current frame
7710 You should call this function only at places where it is safe to currently
7711 unwind the whole stack. Failed stack unwind would discard live dummy
7715 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7717 struct breakpoint *b, *b_tmp;
7719 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7720 if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num)
7722 struct breakpoint *dummy_b = b->related_breakpoint;
7724 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7725 dummy_b = dummy_b->related_breakpoint;
7726 if (dummy_b->type != bp_call_dummy
7727 || frame_find_by_id (dummy_b->frame_id) != NULL)
7730 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7732 while (b->related_breakpoint != b)
7734 if (b_tmp == b->related_breakpoint)
7735 b_tmp = b->related_breakpoint->next;
7736 delete_breakpoint (b->related_breakpoint);
7738 delete_breakpoint (b);
7743 enable_overlay_breakpoints (void)
7745 struct breakpoint *b;
7748 if (b->type == bp_overlay_event)
7750 b->enable_state = bp_enabled;
7751 update_global_location_list (UGLL_MAY_INSERT);
7752 overlay_events_enabled = 1;
7757 disable_overlay_breakpoints (void)
7759 struct breakpoint *b;
7762 if (b->type == bp_overlay_event)
7764 b->enable_state = bp_disabled;
7765 update_global_location_list (UGLL_DONT_INSERT);
7766 overlay_events_enabled = 0;
7770 /* Set an active std::terminate breakpoint for each std::terminate
7771 master breakpoint. */
7773 set_std_terminate_breakpoint (void)
7775 struct breakpoint *b, *b_tmp;
7777 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7778 if (b->pspace == current_program_space
7779 && b->type == bp_std_terminate_master)
7781 momentary_breakpoint_from_master (b, bp_std_terminate,
7782 &momentary_breakpoint_ops, 1);
7786 /* Delete all the std::terminate breakpoints. */
7788 delete_std_terminate_breakpoint (void)
7790 struct breakpoint *b, *b_tmp;
7792 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7793 if (b->type == bp_std_terminate)
7794 delete_breakpoint (b);
7798 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7800 struct breakpoint *b;
7802 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7803 &internal_breakpoint_ops);
7805 b->enable_state = bp_enabled;
7806 /* location has to be used or breakpoint_re_set will delete me. */
7807 b->location = new_address_location (b->loc->address, NULL, 0);
7809 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7814 struct lang_and_radix
7820 /* Create a breakpoint for JIT code registration and unregistration. */
7823 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7825 return create_internal_breakpoint (gdbarch, address, bp_jit_event,
7826 &internal_breakpoint_ops);
7829 /* Remove JIT code registration and unregistration breakpoint(s). */
7832 remove_jit_event_breakpoints (void)
7834 struct breakpoint *b, *b_tmp;
7836 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7837 if (b->type == bp_jit_event
7838 && b->loc->pspace == current_program_space)
7839 delete_breakpoint (b);
7843 remove_solib_event_breakpoints (void)
7845 struct breakpoint *b, *b_tmp;
7847 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7848 if (b->type == bp_shlib_event
7849 && b->loc->pspace == current_program_space)
7850 delete_breakpoint (b);
7853 /* See breakpoint.h. */
7856 remove_solib_event_breakpoints_at_next_stop (void)
7858 struct breakpoint *b, *b_tmp;
7860 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7861 if (b->type == bp_shlib_event
7862 && b->loc->pspace == current_program_space)
7863 b->disposition = disp_del_at_next_stop;
7866 /* Helper for create_solib_event_breakpoint /
7867 create_and_insert_solib_event_breakpoint. Allows specifying which
7868 INSERT_MODE to pass through to update_global_location_list. */
7870 static struct breakpoint *
7871 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7872 enum ugll_insert_mode insert_mode)
7874 struct breakpoint *b;
7876 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7877 &internal_breakpoint_ops);
7878 update_global_location_list_nothrow (insert_mode);
7883 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7885 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7888 /* See breakpoint.h. */
7891 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7893 struct breakpoint *b;
7895 /* Explicitly tell update_global_location_list to insert
7897 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7898 if (!b->loc->inserted)
7900 delete_breakpoint (b);
7906 /* Disable any breakpoints that are on code in shared libraries. Only
7907 apply to enabled breakpoints, disabled ones can just stay disabled. */
7910 disable_breakpoints_in_shlibs (void)
7912 struct bp_location *loc, **locp_tmp;
7914 ALL_BP_LOCATIONS (loc, locp_tmp)
7916 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7917 struct breakpoint *b = loc->owner;
7919 /* We apply the check to all breakpoints, including disabled for
7920 those with loc->duplicate set. This is so that when breakpoint
7921 becomes enabled, or the duplicate is removed, gdb will try to
7922 insert all breakpoints. If we don't set shlib_disabled here,
7923 we'll try to insert those breakpoints and fail. */
7924 if (((b->type == bp_breakpoint)
7925 || (b->type == bp_jit_event)
7926 || (b->type == bp_hardware_breakpoint)
7927 || (is_tracepoint (b)))
7928 && loc->pspace == current_program_space
7929 && !loc->shlib_disabled
7930 && solib_name_from_address (loc->pspace, loc->address)
7933 loc->shlib_disabled = 1;
7938 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7939 notification of unloaded_shlib. Only apply to enabled breakpoints,
7940 disabled ones can just stay disabled. */
7943 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7945 struct bp_location *loc, **locp_tmp;
7946 int disabled_shlib_breaks = 0;
7948 ALL_BP_LOCATIONS (loc, locp_tmp)
7950 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7951 struct breakpoint *b = loc->owner;
7953 if (solib->pspace == loc->pspace
7954 && !loc->shlib_disabled
7955 && (((b->type == bp_breakpoint
7956 || b->type == bp_jit_event
7957 || b->type == bp_hardware_breakpoint)
7958 && (loc->loc_type == bp_loc_hardware_breakpoint
7959 || loc->loc_type == bp_loc_software_breakpoint))
7960 || is_tracepoint (b))
7961 && solib_contains_address_p (solib, loc->address))
7963 loc->shlib_disabled = 1;
7964 /* At this point, we cannot rely on remove_breakpoint
7965 succeeding so we must mark the breakpoint as not inserted
7966 to prevent future errors occurring in remove_breakpoints. */
7969 /* This may cause duplicate notifications for the same breakpoint. */
7970 observer_notify_breakpoint_modified (b);
7972 if (!disabled_shlib_breaks)
7974 target_terminal_ours_for_output ();
7975 warning (_("Temporarily disabling breakpoints "
7976 "for unloaded shared library \"%s\""),
7979 disabled_shlib_breaks = 1;
7984 /* Disable any breakpoints and tracepoints in OBJFILE upon
7985 notification of free_objfile. Only apply to enabled breakpoints,
7986 disabled ones can just stay disabled. */
7989 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7991 struct breakpoint *b;
7993 if (objfile == NULL)
7996 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7997 managed by the user with add-symbol-file/remove-symbol-file.
7998 Similarly to how breakpoints in shared libraries are handled in
7999 response to "nosharedlibrary", mark breakpoints in such modules
8000 shlib_disabled so they end up uninserted on the next global
8001 location list update. Shared libraries not loaded by the user
8002 aren't handled here -- they're already handled in
8003 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8004 solib_unloaded observer. We skip objfiles that are not
8005 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8007 if ((objfile->flags & OBJF_SHARED) == 0
8008 || (objfile->flags & OBJF_USERLOADED) == 0)
8013 struct bp_location *loc;
8014 int bp_modified = 0;
8016 if (!is_breakpoint (b) && !is_tracepoint (b))
8019 for (loc = b->loc; loc != NULL; loc = loc->next)
8021 CORE_ADDR loc_addr = loc->address;
8023 if (loc->loc_type != bp_loc_hardware_breakpoint
8024 && loc->loc_type != bp_loc_software_breakpoint)
8027 if (loc->shlib_disabled != 0)
8030 if (objfile->pspace != loc->pspace)
8033 if (loc->loc_type != bp_loc_hardware_breakpoint
8034 && loc->loc_type != bp_loc_software_breakpoint)
8037 if (is_addr_in_objfile (loc_addr, objfile))
8039 loc->shlib_disabled = 1;
8040 /* At this point, we don't know whether the object was
8041 unmapped from the inferior or not, so leave the
8042 inserted flag alone. We'll handle failure to
8043 uninsert quietly, in case the object was indeed
8046 mark_breakpoint_location_modified (loc);
8053 observer_notify_breakpoint_modified (b);
8057 /* FORK & VFORK catchpoints. */
8059 /* An instance of this type is used to represent a fork or vfork
8060 catchpoint. It includes a "struct breakpoint" as a kind of base
8061 class; users downcast to "struct breakpoint *" when needed. A
8062 breakpoint is really of this type iff its ops pointer points to
8063 CATCH_FORK_BREAKPOINT_OPS. */
8065 struct fork_catchpoint
8067 /* The base class. */
8068 struct breakpoint base;
8070 /* Process id of a child process whose forking triggered this
8071 catchpoint. This field is only valid immediately after this
8072 catchpoint has triggered. */
8073 ptid_t forked_inferior_pid;
8076 /* Implement the "insert" breakpoint_ops method for fork
8080 insert_catch_fork (struct bp_location *bl)
8082 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
8085 /* Implement the "remove" breakpoint_ops method for fork
8089 remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason)
8091 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
8094 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8098 breakpoint_hit_catch_fork (const struct bp_location *bl,
8099 struct address_space *aspace, CORE_ADDR bp_addr,
8100 const struct target_waitstatus *ws)
8102 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8104 if (ws->kind != TARGET_WAITKIND_FORKED)
8107 c->forked_inferior_pid = ws->value.related_pid;
8111 /* Implement the "print_it" breakpoint_ops method for fork
8114 static enum print_stop_action
8115 print_it_catch_fork (bpstat bs)
8117 struct ui_out *uiout = current_uiout;
8118 struct breakpoint *b = bs->breakpoint_at;
8119 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
8121 annotate_catchpoint (b->number);
8122 maybe_print_thread_hit_breakpoint (uiout);
8123 if (b->disposition == disp_del)
8124 uiout->text ("Temporary catchpoint ");
8126 uiout->text ("Catchpoint ");
8127 if (uiout->is_mi_like_p ())
8129 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK));
8130 uiout->field_string ("disp", bpdisp_text (b->disposition));
8132 uiout->field_int ("bkptno", b->number);
8133 uiout->text (" (forked process ");
8134 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
8135 uiout->text ("), ");
8136 return PRINT_SRC_AND_LOC;
8139 /* Implement the "print_one" breakpoint_ops method for fork
8143 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8145 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8146 struct value_print_options opts;
8147 struct ui_out *uiout = current_uiout;
8149 get_user_print_options (&opts);
8151 /* Field 4, the address, is omitted (which makes the columns not
8152 line up too nicely with the headers, but the effect is relatively
8154 if (opts.addressprint)
8155 uiout->field_skip ("addr");
8157 uiout->text ("fork");
8158 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8160 uiout->text (", process ");
8161 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
8165 if (uiout->is_mi_like_p ())
8166 uiout->field_string ("catch-type", "fork");
8169 /* Implement the "print_mention" breakpoint_ops method for fork
8173 print_mention_catch_fork (struct breakpoint *b)
8175 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8178 /* Implement the "print_recreate" breakpoint_ops method for fork
8182 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8184 fprintf_unfiltered (fp, "catch fork");
8185 print_recreate_thread (b, fp);
8188 /* The breakpoint_ops structure to be used in fork catchpoints. */
8190 static struct breakpoint_ops catch_fork_breakpoint_ops;
8192 /* Implement the "insert" breakpoint_ops method for vfork
8196 insert_catch_vfork (struct bp_location *bl)
8198 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8201 /* Implement the "remove" breakpoint_ops method for vfork
8205 remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason)
8207 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8210 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8214 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8215 struct address_space *aspace, CORE_ADDR bp_addr,
8216 const struct target_waitstatus *ws)
8218 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8220 if (ws->kind != TARGET_WAITKIND_VFORKED)
8223 c->forked_inferior_pid = ws->value.related_pid;
8227 /* Implement the "print_it" breakpoint_ops method for vfork
8230 static enum print_stop_action
8231 print_it_catch_vfork (bpstat bs)
8233 struct ui_out *uiout = current_uiout;
8234 struct breakpoint *b = bs->breakpoint_at;
8235 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8237 annotate_catchpoint (b->number);
8238 maybe_print_thread_hit_breakpoint (uiout);
8239 if (b->disposition == disp_del)
8240 uiout->text ("Temporary catchpoint ");
8242 uiout->text ("Catchpoint ");
8243 if (uiout->is_mi_like_p ())
8245 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK));
8246 uiout->field_string ("disp", bpdisp_text (b->disposition));
8248 uiout->field_int ("bkptno", b->number);
8249 uiout->text (" (vforked process ");
8250 uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid));
8251 uiout->text ("), ");
8252 return PRINT_SRC_AND_LOC;
8255 /* Implement the "print_one" breakpoint_ops method for vfork
8259 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8261 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8262 struct value_print_options opts;
8263 struct ui_out *uiout = current_uiout;
8265 get_user_print_options (&opts);
8266 /* Field 4, the address, is omitted (which makes the columns not
8267 line up too nicely with the headers, but the effect is relatively
8269 if (opts.addressprint)
8270 uiout->field_skip ("addr");
8272 uiout->text ("vfork");
8273 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8275 uiout->text (", process ");
8276 uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid));
8280 if (uiout->is_mi_like_p ())
8281 uiout->field_string ("catch-type", "vfork");
8284 /* Implement the "print_mention" breakpoint_ops method for vfork
8288 print_mention_catch_vfork (struct breakpoint *b)
8290 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8293 /* Implement the "print_recreate" breakpoint_ops method for vfork
8297 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8299 fprintf_unfiltered (fp, "catch vfork");
8300 print_recreate_thread (b, fp);
8303 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8305 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8307 /* An instance of this type is used to represent an solib catchpoint.
8308 It includes a "struct breakpoint" as a kind of base class; users
8309 downcast to "struct breakpoint *" when needed. A breakpoint is
8310 really of this type iff its ops pointer points to
8311 CATCH_SOLIB_BREAKPOINT_OPS. */
8313 struct solib_catchpoint
8315 /* The base class. */
8316 struct breakpoint base;
8318 /* True for "catch load", false for "catch unload". */
8319 unsigned char is_load;
8321 /* Regular expression to match, if any. COMPILED is only valid when
8322 REGEX is non-NULL. */
8328 dtor_catch_solib (struct breakpoint *b)
8330 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8333 regfree (&self->compiled);
8334 xfree (self->regex);
8336 base_breakpoint_ops.dtor (b);
8340 insert_catch_solib (struct bp_location *ignore)
8346 remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason)
8352 breakpoint_hit_catch_solib (const struct bp_location *bl,
8353 struct address_space *aspace,
8355 const struct target_waitstatus *ws)
8357 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8358 struct breakpoint *other;
8360 if (ws->kind == TARGET_WAITKIND_LOADED)
8363 ALL_BREAKPOINTS (other)
8365 struct bp_location *other_bl;
8367 if (other == bl->owner)
8370 if (other->type != bp_shlib_event)
8373 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8376 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8378 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8387 check_status_catch_solib (struct bpstats *bs)
8389 struct solib_catchpoint *self
8390 = (struct solib_catchpoint *) bs->breakpoint_at;
8395 struct so_list *iter;
8398 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8403 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8412 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8417 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8423 bs->print_it = print_it_noop;
8426 static enum print_stop_action
8427 print_it_catch_solib (bpstat bs)
8429 struct breakpoint *b = bs->breakpoint_at;
8430 struct ui_out *uiout = current_uiout;
8432 annotate_catchpoint (b->number);
8433 maybe_print_thread_hit_breakpoint (uiout);
8434 if (b->disposition == disp_del)
8435 uiout->text ("Temporary catchpoint ");
8437 uiout->text ("Catchpoint ");
8438 uiout->field_int ("bkptno", b->number);
8440 if (uiout->is_mi_like_p ())
8441 uiout->field_string ("disp", bpdisp_text (b->disposition));
8442 print_solib_event (1);
8443 return PRINT_SRC_AND_LOC;
8447 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8449 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8450 struct value_print_options opts;
8451 struct ui_out *uiout = current_uiout;
8454 get_user_print_options (&opts);
8455 /* Field 4, the address, is omitted (which makes the columns not
8456 line up too nicely with the headers, but the effect is relatively
8458 if (opts.addressprint)
8461 uiout->field_skip ("addr");
8468 msg = xstrprintf (_("load of library matching %s"), self->regex);
8470 msg = xstrdup (_("load of library"));
8475 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8477 msg = xstrdup (_("unload of library"));
8479 uiout->field_string ("what", msg);
8482 if (uiout->is_mi_like_p ())
8483 uiout->field_string ("catch-type", self->is_load ? "load" : "unload");
8487 print_mention_catch_solib (struct breakpoint *b)
8489 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8491 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8492 self->is_load ? "load" : "unload");
8496 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8498 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8500 fprintf_unfiltered (fp, "%s %s",
8501 b->disposition == disp_del ? "tcatch" : "catch",
8502 self->is_load ? "load" : "unload");
8504 fprintf_unfiltered (fp, " %s", self->regex);
8505 fprintf_unfiltered (fp, "\n");
8508 static struct breakpoint_ops catch_solib_breakpoint_ops;
8510 /* Shared helper function (MI and CLI) for creating and installing
8511 a shared object event catchpoint. If IS_LOAD is non-zero then
8512 the events to be caught are load events, otherwise they are
8513 unload events. If IS_TEMP is non-zero the catchpoint is a
8514 temporary one. If ENABLED is non-zero the catchpoint is
8515 created in an enabled state. */
8518 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8520 struct solib_catchpoint *c;
8521 struct gdbarch *gdbarch = get_current_arch ();
8522 struct cleanup *cleanup;
8526 arg = skip_spaces (arg);
8528 c = new solib_catchpoint ();
8529 cleanup = make_cleanup (xfree, c);
8535 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8538 char *err = get_regcomp_error (errcode, &c->compiled);
8540 make_cleanup (xfree, err);
8541 error (_("Invalid regexp (%s): %s"), err, arg);
8543 c->regex = xstrdup (arg);
8546 c->is_load = is_load;
8547 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8548 &catch_solib_breakpoint_ops);
8550 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8552 discard_cleanups (cleanup);
8553 install_breakpoint (0, &c->base, 1);
8556 /* A helper function that does all the work for "catch load" and
8560 catch_load_or_unload (char *arg, int from_tty, int is_load,
8561 struct cmd_list_element *command)
8564 const int enabled = 1;
8566 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8568 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8572 catch_load_command_1 (char *arg, int from_tty,
8573 struct cmd_list_element *command)
8575 catch_load_or_unload (arg, from_tty, 1, command);
8579 catch_unload_command_1 (char *arg, int from_tty,
8580 struct cmd_list_element *command)
8582 catch_load_or_unload (arg, from_tty, 0, command);
8585 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8586 is non-zero, then make the breakpoint temporary. If COND_STRING is
8587 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8588 the breakpoint_ops structure associated to the catchpoint. */
8591 init_catchpoint (struct breakpoint *b,
8592 struct gdbarch *gdbarch, int tempflag,
8594 const struct breakpoint_ops *ops)
8596 struct symtab_and_line sal;
8599 sal.pspace = current_program_space;
8601 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8603 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8604 b->disposition = tempflag ? disp_del : disp_donttouch;
8608 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8610 add_to_breakpoint_chain (b);
8611 set_breakpoint_number (internal, b);
8612 if (is_tracepoint (b))
8613 set_tracepoint_count (breakpoint_count);
8616 observer_notify_breakpoint_created (b);
8619 update_global_location_list (UGLL_MAY_INSERT);
8623 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8624 int tempflag, char *cond_string,
8625 const struct breakpoint_ops *ops)
8627 struct fork_catchpoint *c = new fork_catchpoint ();
8629 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8631 c->forked_inferior_pid = null_ptid;
8633 install_breakpoint (0, &c->base, 1);
8636 /* Exec catchpoints. */
8638 /* An instance of this type is used to represent an exec catchpoint.
8639 It includes a "struct breakpoint" as a kind of base class; users
8640 downcast to "struct breakpoint *" when needed. A breakpoint is
8641 really of this type iff its ops pointer points to
8642 CATCH_EXEC_BREAKPOINT_OPS. */
8644 struct exec_catchpoint
8646 /* The base class. */
8647 struct breakpoint base;
8649 /* Filename of a program whose exec triggered this catchpoint.
8650 This field is only valid immediately after this catchpoint has
8652 char *exec_pathname;
8655 /* Implement the "dtor" breakpoint_ops method for exec
8659 dtor_catch_exec (struct breakpoint *b)
8661 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8663 xfree (c->exec_pathname);
8665 base_breakpoint_ops.dtor (b);
8669 insert_catch_exec (struct bp_location *bl)
8671 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8675 remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason)
8677 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8681 breakpoint_hit_catch_exec (const struct bp_location *bl,
8682 struct address_space *aspace, CORE_ADDR bp_addr,
8683 const struct target_waitstatus *ws)
8685 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8687 if (ws->kind != TARGET_WAITKIND_EXECD)
8690 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8694 static enum print_stop_action
8695 print_it_catch_exec (bpstat bs)
8697 struct ui_out *uiout = current_uiout;
8698 struct breakpoint *b = bs->breakpoint_at;
8699 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8701 annotate_catchpoint (b->number);
8702 maybe_print_thread_hit_breakpoint (uiout);
8703 if (b->disposition == disp_del)
8704 uiout->text ("Temporary catchpoint ");
8706 uiout->text ("Catchpoint ");
8707 if (uiout->is_mi_like_p ())
8709 uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC));
8710 uiout->field_string ("disp", bpdisp_text (b->disposition));
8712 uiout->field_int ("bkptno", b->number);
8713 uiout->text (" (exec'd ");
8714 uiout->field_string ("new-exec", c->exec_pathname);
8715 uiout->text ("), ");
8717 return PRINT_SRC_AND_LOC;
8721 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8723 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8724 struct value_print_options opts;
8725 struct ui_out *uiout = current_uiout;
8727 get_user_print_options (&opts);
8729 /* Field 4, the address, is omitted (which makes the columns
8730 not line up too nicely with the headers, but the effect
8731 is relatively readable). */
8732 if (opts.addressprint)
8733 uiout->field_skip ("addr");
8735 uiout->text ("exec");
8736 if (c->exec_pathname != NULL)
8738 uiout->text (", program \"");
8739 uiout->field_string ("what", c->exec_pathname);
8740 uiout->text ("\" ");
8743 if (uiout->is_mi_like_p ())
8744 uiout->field_string ("catch-type", "exec");
8748 print_mention_catch_exec (struct breakpoint *b)
8750 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8753 /* Implement the "print_recreate" breakpoint_ops method for exec
8757 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8759 fprintf_unfiltered (fp, "catch exec");
8760 print_recreate_thread (b, fp);
8763 static struct breakpoint_ops catch_exec_breakpoint_ops;
8766 hw_breakpoint_used_count (void)
8769 struct breakpoint *b;
8770 struct bp_location *bl;
8774 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8775 for (bl = b->loc; bl; bl = bl->next)
8777 /* Special types of hardware breakpoints may use more than
8779 i += b->ops->resources_needed (bl);
8786 /* Returns the resources B would use if it were a hardware
8790 hw_watchpoint_use_count (struct breakpoint *b)
8793 struct bp_location *bl;
8795 if (!breakpoint_enabled (b))
8798 for (bl = b->loc; bl; bl = bl->next)
8800 /* Special types of hardware watchpoints may use more than
8802 i += b->ops->resources_needed (bl);
8808 /* Returns the sum the used resources of all hardware watchpoints of
8809 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8810 the sum of the used resources of all hardware watchpoints of other
8811 types _not_ TYPE. */
8814 hw_watchpoint_used_count_others (struct breakpoint *except,
8815 enum bptype type, int *other_type_used)
8818 struct breakpoint *b;
8820 *other_type_used = 0;
8825 if (!breakpoint_enabled (b))
8828 if (b->type == type)
8829 i += hw_watchpoint_use_count (b);
8830 else if (is_hardware_watchpoint (b))
8831 *other_type_used = 1;
8838 disable_watchpoints_before_interactive_call_start (void)
8840 struct breakpoint *b;
8844 if (is_watchpoint (b) && breakpoint_enabled (b))
8846 b->enable_state = bp_call_disabled;
8847 update_global_location_list (UGLL_DONT_INSERT);
8853 enable_watchpoints_after_interactive_call_stop (void)
8855 struct breakpoint *b;
8859 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8861 b->enable_state = bp_enabled;
8862 update_global_location_list (UGLL_MAY_INSERT);
8868 disable_breakpoints_before_startup (void)
8870 current_program_space->executing_startup = 1;
8871 update_global_location_list (UGLL_DONT_INSERT);
8875 enable_breakpoints_after_startup (void)
8877 current_program_space->executing_startup = 0;
8878 breakpoint_re_set ();
8881 /* Create a new single-step breakpoint for thread THREAD, with no
8884 static struct breakpoint *
8885 new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
8887 struct breakpoint *b = new breakpoint ();
8889 init_raw_breakpoint_without_location (b, gdbarch, bp_single_step,
8890 &momentary_breakpoint_ops);
8892 b->disposition = disp_donttouch;
8893 b->frame_id = null_frame_id;
8896 gdb_assert (b->thread != 0);
8898 add_to_breakpoint_chain (b);
8903 /* Set a momentary breakpoint of type TYPE at address specified by
8904 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8908 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8909 struct frame_id frame_id, enum bptype type)
8911 struct breakpoint *b;
8913 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8915 gdb_assert (!frame_id_artificial_p (frame_id));
8917 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8918 b->enable_state = bp_enabled;
8919 b->disposition = disp_donttouch;
8920 b->frame_id = frame_id;
8922 /* If we're debugging a multi-threaded program, then we want
8923 momentary breakpoints to be active in only a single thread of
8925 if (in_thread_list (inferior_ptid))
8926 b->thread = ptid_to_global_thread_id (inferior_ptid);
8928 update_global_location_list_nothrow (UGLL_MAY_INSERT);
8933 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8934 The new breakpoint will have type TYPE, use OPS as its
8935 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8937 static struct breakpoint *
8938 momentary_breakpoint_from_master (struct breakpoint *orig,
8940 const struct breakpoint_ops *ops,
8943 struct breakpoint *copy;
8945 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8946 copy->loc = allocate_bp_location (copy);
8947 set_breakpoint_location_function (copy->loc, 1);
8949 copy->loc->gdbarch = orig->loc->gdbarch;
8950 copy->loc->requested_address = orig->loc->requested_address;
8951 copy->loc->address = orig->loc->address;
8952 copy->loc->section = orig->loc->section;
8953 copy->loc->pspace = orig->loc->pspace;
8954 copy->loc->probe = orig->loc->probe;
8955 copy->loc->line_number = orig->loc->line_number;
8956 copy->loc->symtab = orig->loc->symtab;
8957 copy->loc->enabled = loc_enabled;
8958 copy->frame_id = orig->frame_id;
8959 copy->thread = orig->thread;
8960 copy->pspace = orig->pspace;
8962 copy->enable_state = bp_enabled;
8963 copy->disposition = disp_donttouch;
8964 copy->number = internal_breakpoint_number--;
8966 update_global_location_list_nothrow (UGLL_DONT_INSERT);
8970 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8974 clone_momentary_breakpoint (struct breakpoint *orig)
8976 /* If there's nothing to clone, then return nothing. */
8980 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8984 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8987 struct symtab_and_line sal;
8989 sal = find_pc_line (pc, 0);
8991 sal.section = find_pc_overlay (pc);
8992 sal.explicit_pc = 1;
8994 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8998 /* Tell the user we have just set a breakpoint B. */
9001 mention (struct breakpoint *b)
9003 b->ops->print_mention (b);
9004 if (current_uiout->is_mi_like_p ())
9006 printf_filtered ("\n");
9010 static int bp_loc_is_permanent (struct bp_location *loc);
9012 static struct bp_location *
9013 add_location_to_breakpoint (struct breakpoint *b,
9014 const struct symtab_and_line *sal)
9016 struct bp_location *loc, **tmp;
9017 CORE_ADDR adjusted_address;
9018 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9020 if (loc_gdbarch == NULL)
9021 loc_gdbarch = b->gdbarch;
9023 /* Adjust the breakpoint's address prior to allocating a location.
9024 Once we call allocate_bp_location(), that mostly uninitialized
9025 location will be placed on the location chain. Adjustment of the
9026 breakpoint may cause target_read_memory() to be called and we do
9027 not want its scan of the location chain to find a breakpoint and
9028 location that's only been partially initialized. */
9029 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9032 /* Sort the locations by their ADDRESS. */
9033 loc = allocate_bp_location (b);
9034 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9035 tmp = &((*tmp)->next))
9040 loc->requested_address = sal->pc;
9041 loc->address = adjusted_address;
9042 loc->pspace = sal->pspace;
9043 loc->probe.probe = sal->probe;
9044 loc->probe.objfile = sal->objfile;
9045 gdb_assert (loc->pspace != NULL);
9046 loc->section = sal->section;
9047 loc->gdbarch = loc_gdbarch;
9048 loc->line_number = sal->line;
9049 loc->symtab = sal->symtab;
9051 set_breakpoint_location_function (loc,
9052 sal->explicit_pc || sal->explicit_line);
9054 /* While by definition, permanent breakpoints are already present in the
9055 code, we don't mark the location as inserted. Normally one would expect
9056 that GDB could rely on that breakpoint instruction to stop the program,
9057 thus removing the need to insert its own breakpoint, except that executing
9058 the breakpoint instruction can kill the target instead of reporting a
9059 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9060 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9061 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9062 breakpoint be inserted normally results in QEMU knowing about the GDB
9063 breakpoint, and thus trap before the breakpoint instruction is executed.
9064 (If GDB later needs to continue execution past the permanent breakpoint,
9065 it manually increments the PC, thus avoiding executing the breakpoint
9067 if (bp_loc_is_permanent (loc))
9074 /* See breakpoint.h. */
9077 program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
9081 const gdb_byte *bpoint;
9082 gdb_byte *target_mem;
9083 struct cleanup *cleanup;
9087 bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
9089 /* Software breakpoints unsupported? */
9093 target_mem = (gdb_byte *) alloca (len);
9095 /* Enable the automatic memory restoration from breakpoints while
9096 we read the memory. Otherwise we could say about our temporary
9097 breakpoints they are permanent. */
9098 cleanup = make_show_memory_breakpoints_cleanup (0);
9100 if (target_read_memory (address, target_mem, len) == 0
9101 && memcmp (target_mem, bpoint, len) == 0)
9104 do_cleanups (cleanup);
9109 /* Return 1 if LOC is pointing to a permanent breakpoint,
9110 return 0 otherwise. */
9113 bp_loc_is_permanent (struct bp_location *loc)
9115 struct cleanup *cleanup;
9118 gdb_assert (loc != NULL);
9120 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9121 attempt to read from the addresses the locations of these breakpoint types
9122 point to. program_breakpoint_here_p, below, will attempt to read
9124 if (!breakpoint_address_is_meaningful (loc->owner))
9127 cleanup = save_current_space_and_thread ();
9128 switch_to_program_space_and_thread (loc->pspace);
9130 retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
9132 do_cleanups (cleanup);
9137 /* Build a command list for the dprintf corresponding to the current
9138 settings of the dprintf style options. */
9141 update_dprintf_command_list (struct breakpoint *b)
9143 char *dprintf_args = b->extra_string;
9144 char *printf_line = NULL;
9149 dprintf_args = skip_spaces (dprintf_args);
9151 /* Allow a comma, as it may have terminated a location, but don't
9153 if (*dprintf_args == ',')
9155 dprintf_args = skip_spaces (dprintf_args);
9157 if (*dprintf_args != '"')
9158 error (_("Bad format string, missing '\"'."));
9160 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9161 printf_line = xstrprintf ("printf %s", dprintf_args);
9162 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9164 if (!dprintf_function)
9165 error (_("No function supplied for dprintf call"));
9167 if (dprintf_channel && strlen (dprintf_channel) > 0)
9168 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9173 printf_line = xstrprintf ("call (void) %s (%s)",
9177 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9179 if (target_can_run_breakpoint_commands ())
9180 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9183 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9184 printf_line = xstrprintf ("printf %s", dprintf_args);
9188 internal_error (__FILE__, __LINE__,
9189 _("Invalid dprintf style."));
9191 gdb_assert (printf_line != NULL);
9192 /* Manufacture a printf sequence. */
9194 struct command_line *printf_cmd_line = XNEW (struct command_line);
9196 printf_cmd_line->control_type = simple_control;
9197 printf_cmd_line->body_count = 0;
9198 printf_cmd_line->body_list = NULL;
9199 printf_cmd_line->next = NULL;
9200 printf_cmd_line->line = printf_line;
9202 breakpoint_set_commands (b, printf_cmd_line);
9206 /* Update all dprintf commands, making their command lists reflect
9207 current style settings. */
9210 update_dprintf_commands (char *args, int from_tty,
9211 struct cmd_list_element *c)
9213 struct breakpoint *b;
9217 if (b->type == bp_dprintf)
9218 update_dprintf_command_list (b);
9222 /* Create a breakpoint with SAL as location. Use LOCATION
9223 as a description of the location, and COND_STRING
9224 as condition expression. If LOCATION is NULL then create an
9225 "address location" from the address in the SAL. */
9228 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9229 struct symtabs_and_lines sals,
9230 struct event_location *location,
9231 char *filter, char *cond_string,
9233 enum bptype type, enum bpdisp disposition,
9234 int thread, int task, int ignore_count,
9235 const struct breakpoint_ops *ops, int from_tty,
9236 int enabled, int internal, unsigned flags,
9237 int display_canonical)
9241 if (type == bp_hardware_breakpoint)
9243 int target_resources_ok;
9245 i = hw_breakpoint_used_count ();
9246 target_resources_ok =
9247 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9249 if (target_resources_ok == 0)
9250 error (_("No hardware breakpoint support in the target."));
9251 else if (target_resources_ok < 0)
9252 error (_("Hardware breakpoints used exceeds limit."));
9255 gdb_assert (sals.nelts > 0);
9257 for (i = 0; i < sals.nelts; ++i)
9259 struct symtab_and_line sal = sals.sals[i];
9260 struct bp_location *loc;
9264 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9266 loc_gdbarch = gdbarch;
9268 describe_other_breakpoints (loc_gdbarch,
9269 sal.pspace, sal.pc, sal.section, thread);
9274 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9278 b->cond_string = cond_string;
9279 b->extra_string = extra_string;
9280 b->ignore_count = ignore_count;
9281 b->enable_state = enabled ? bp_enabled : bp_disabled;
9282 b->disposition = disposition;
9284 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9285 b->loc->inserted = 1;
9287 if (type == bp_static_tracepoint)
9289 struct tracepoint *t = (struct tracepoint *) b;
9290 struct static_tracepoint_marker marker;
9292 if (strace_marker_p (b))
9294 /* We already know the marker exists, otherwise, we
9295 wouldn't see a sal for it. */
9296 const char *p = &event_location_to_string (b->location)[3];
9300 p = skip_spaces_const (p);
9302 endp = skip_to_space_const (p);
9304 marker_str = savestring (p, endp - p);
9305 t->static_trace_marker_id = marker_str;
9307 printf_filtered (_("Probed static tracepoint "
9309 t->static_trace_marker_id);
9311 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9313 t->static_trace_marker_id = xstrdup (marker.str_id);
9314 release_static_tracepoint_marker (&marker);
9316 printf_filtered (_("Probed static tracepoint "
9318 t->static_trace_marker_id);
9321 warning (_("Couldn't determine the static "
9322 "tracepoint marker to probe"));
9329 loc = add_location_to_breakpoint (b, &sal);
9330 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9336 const char *arg = b->cond_string;
9338 loc->cond = parse_exp_1 (&arg, loc->address,
9339 block_for_pc (loc->address), 0);
9341 error (_("Garbage '%s' follows condition"), arg);
9344 /* Dynamic printf requires and uses additional arguments on the
9345 command line, otherwise it's an error. */
9346 if (type == bp_dprintf)
9348 if (b->extra_string)
9349 update_dprintf_command_list (b);
9351 error (_("Format string required"));
9353 else if (b->extra_string)
9354 error (_("Garbage '%s' at end of command"), b->extra_string);
9357 b->display_canonical = display_canonical;
9358 if (location != NULL)
9359 b->location = location;
9362 const char *addr_string = NULL;
9363 int addr_string_len = 0;
9365 if (location != NULL)
9366 addr_string = event_location_to_string (location);
9367 if (addr_string != NULL)
9368 addr_string_len = strlen (addr_string);
9370 b->location = new_address_location (b->loc->address,
9371 addr_string, addr_string_len);
9377 create_breakpoint_sal (struct gdbarch *gdbarch,
9378 struct symtabs_and_lines sals,
9379 struct event_location *location,
9380 char *filter, char *cond_string,
9382 enum bptype type, enum bpdisp disposition,
9383 int thread, int task, int ignore_count,
9384 const struct breakpoint_ops *ops, int from_tty,
9385 int enabled, int internal, unsigned flags,
9386 int display_canonical)
9388 struct breakpoint *b;
9389 struct cleanup *old_chain;
9391 if (is_tracepoint_type (type))
9393 struct tracepoint *t;
9395 t = new tracepoint ();
9399 b = new breakpoint ();
9401 old_chain = make_cleanup (xfree, b);
9403 init_breakpoint_sal (b, gdbarch,
9405 filter, cond_string, extra_string,
9407 thread, task, ignore_count,
9409 enabled, internal, flags,
9411 discard_cleanups (old_chain);
9413 install_breakpoint (internal, b, 0);
9416 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9417 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9418 value. COND_STRING, if not NULL, specified the condition to be
9419 used for all breakpoints. Essentially the only case where
9420 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9421 function. In that case, it's still not possible to specify
9422 separate conditions for different overloaded functions, so
9423 we take just a single condition string.
9425 NOTE: If the function succeeds, the caller is expected to cleanup
9426 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9427 array contents). If the function fails (error() is called), the
9428 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9429 COND and SALS arrays and each of those arrays contents. */
9432 create_breakpoints_sal (struct gdbarch *gdbarch,
9433 struct linespec_result *canonical,
9434 char *cond_string, char *extra_string,
9435 enum bptype type, enum bpdisp disposition,
9436 int thread, int task, int ignore_count,
9437 const struct breakpoint_ops *ops, int from_tty,
9438 int enabled, int internal, unsigned flags)
9441 struct linespec_sals *lsal;
9443 if (canonical->pre_expanded)
9444 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9446 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9448 /* Note that 'location' can be NULL in the case of a plain
9449 'break', without arguments. */
9450 struct event_location *location
9451 = (canonical->location != NULL
9452 ? copy_event_location (canonical->location) : NULL);
9453 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9454 struct cleanup *inner = make_cleanup_delete_event_location (location);
9456 make_cleanup (xfree, filter_string);
9457 create_breakpoint_sal (gdbarch, lsal->sals,
9460 cond_string, extra_string,
9462 thread, task, ignore_count, ops,
9463 from_tty, enabled, internal, flags,
9464 canonical->special_display);
9465 discard_cleanups (inner);
9469 /* Parse LOCATION which is assumed to be a SAL specification possibly
9470 followed by conditionals. On return, SALS contains an array of SAL
9471 addresses found. LOCATION points to the end of the SAL (for
9472 linespec locations).
9474 The array and the line spec strings are allocated on the heap, it is
9475 the caller's responsibility to free them. */
9478 parse_breakpoint_sals (const struct event_location *location,
9479 struct linespec_result *canonical)
9481 struct symtab_and_line cursal;
9483 if (event_location_type (location) == LINESPEC_LOCATION)
9485 const char *address = get_linespec_location (location);
9487 if (address == NULL)
9489 /* The last displayed codepoint, if it's valid, is our default
9490 breakpoint address. */
9491 if (last_displayed_sal_is_valid ())
9493 struct linespec_sals lsal;
9494 struct symtab_and_line sal;
9497 init_sal (&sal); /* Initialize to zeroes. */
9498 lsal.sals.sals = XNEW (struct symtab_and_line);
9500 /* Set sal's pspace, pc, symtab, and line to the values
9501 corresponding to the last call to print_frame_info.
9502 Be sure to reinitialize LINE with NOTCURRENT == 0
9503 as the breakpoint line number is inappropriate otherwise.
9504 find_pc_line would adjust PC, re-set it back. */
9505 get_last_displayed_sal (&sal);
9507 sal = find_pc_line (pc, 0);
9509 /* "break" without arguments is equivalent to "break *PC"
9510 where PC is the last displayed codepoint's address. So
9511 make sure to set sal.explicit_pc to prevent GDB from
9512 trying to expand the list of sals to include all other
9513 instances with the same symtab and line. */
9515 sal.explicit_pc = 1;
9517 lsal.sals.sals[0] = sal;
9518 lsal.sals.nelts = 1;
9519 lsal.canonical = NULL;
9521 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9525 error (_("No default breakpoint address now."));
9529 /* Force almost all breakpoints to be in terms of the
9530 current_source_symtab (which is decode_line_1's default).
9531 This should produce the results we want almost all of the
9532 time while leaving default_breakpoint_* alone.
9534 ObjC: However, don't match an Objective-C method name which
9535 may have a '+' or '-' succeeded by a '['. */
9536 cursal = get_current_source_symtab_and_line ();
9537 if (last_displayed_sal_is_valid ())
9539 const char *address = NULL;
9541 if (event_location_type (location) == LINESPEC_LOCATION)
9542 address = get_linespec_location (location);
9546 && strchr ("+-", address[0]) != NULL
9547 && address[1] != '['))
9549 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9550 get_last_displayed_symtab (),
9551 get_last_displayed_line (),
9552 canonical, NULL, NULL);
9557 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
9558 cursal.symtab, cursal.line, canonical, NULL, NULL);
9562 /* Convert each SAL into a real PC. Verify that the PC can be
9563 inserted as a breakpoint. If it can't throw an error. */
9566 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9570 for (i = 0; i < sals->nelts; i++)
9571 resolve_sal_pc (&sals->sals[i]);
9574 /* Fast tracepoints may have restrictions on valid locations. For
9575 instance, a fast tracepoint using a jump instead of a trap will
9576 likely have to overwrite more bytes than a trap would, and so can
9577 only be placed where the instruction is longer than the jump, or a
9578 multi-instruction sequence does not have a jump into the middle of
9582 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9583 struct symtabs_and_lines *sals)
9586 struct symtab_and_line *sal;
9588 struct cleanup *old_chain;
9590 for (i = 0; i < sals->nelts; i++)
9592 struct gdbarch *sarch;
9594 sal = &sals->sals[i];
9596 sarch = get_sal_arch (*sal);
9597 /* We fall back to GDBARCH if there is no architecture
9598 associated with SAL. */
9601 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg);
9602 old_chain = make_cleanup (xfree, msg);
9605 error (_("May not have a fast tracepoint at %s%s"),
9606 paddress (sarch, sal->pc), (msg ? msg : ""));
9608 do_cleanups (old_chain);
9612 /* Given TOK, a string specification of condition and thread, as
9613 accepted by the 'break' command, extract the condition
9614 string and thread number and set *COND_STRING and *THREAD.
9615 PC identifies the context at which the condition should be parsed.
9616 If no condition is found, *COND_STRING is set to NULL.
9617 If no thread is found, *THREAD is set to -1. */
9620 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9621 char **cond_string, int *thread, int *task,
9624 *cond_string = NULL;
9631 const char *end_tok;
9633 const char *cond_start = NULL;
9634 const char *cond_end = NULL;
9636 tok = skip_spaces_const (tok);
9638 if ((*tok == '"' || *tok == ',') && rest)
9640 *rest = savestring (tok, strlen (tok));
9644 end_tok = skip_to_space_const (tok);
9646 toklen = end_tok - tok;
9648 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9650 tok = cond_start = end_tok + 1;
9651 parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9653 *cond_string = savestring (cond_start, cond_end - cond_start);
9655 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9658 struct thread_info *thr;
9661 thr = parse_thread_id (tok, &tmptok);
9663 error (_("Junk after thread keyword."));
9664 *thread = thr->global_num;
9667 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9672 *task = strtol (tok, &tmptok, 0);
9674 error (_("Junk after task keyword."));
9675 if (!valid_task_id (*task))
9676 error (_("Unknown task %d."), *task);
9681 *rest = savestring (tok, strlen (tok));
9685 error (_("Junk at end of arguments."));
9689 /* Decode a static tracepoint marker spec. */
9691 static struct symtabs_and_lines
9692 decode_static_tracepoint_spec (const char **arg_p)
9694 VEC(static_tracepoint_marker_p) *markers = NULL;
9695 struct symtabs_and_lines sals;
9696 struct cleanup *old_chain;
9697 const char *p = &(*arg_p)[3];
9702 p = skip_spaces_const (p);
9704 endp = skip_to_space_const (p);
9706 marker_str = savestring (p, endp - p);
9707 old_chain = make_cleanup (xfree, marker_str);
9709 markers = target_static_tracepoint_markers_by_strid (marker_str);
9710 if (VEC_empty(static_tracepoint_marker_p, markers))
9711 error (_("No known static tracepoint marker named %s"), marker_str);
9713 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9714 sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts);
9716 for (i = 0; i < sals.nelts; i++)
9718 struct static_tracepoint_marker *marker;
9720 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9722 init_sal (&sals.sals[i]);
9724 sals.sals[i] = find_pc_line (marker->address, 0);
9725 sals.sals[i].pc = marker->address;
9727 release_static_tracepoint_marker (marker);
9730 do_cleanups (old_chain);
9736 /* See breakpoint.h. */
9739 create_breakpoint (struct gdbarch *gdbarch,
9740 const struct event_location *location, char *cond_string,
9741 int thread, char *extra_string,
9743 int tempflag, enum bptype type_wanted,
9745 enum auto_boolean pending_break_support,
9746 const struct breakpoint_ops *ops,
9747 int from_tty, int enabled, int internal,
9750 struct linespec_result canonical;
9751 struct cleanup *old_chain;
9752 struct cleanup *bkpt_chain = NULL;
9755 int prev_bkpt_count = breakpoint_count;
9757 gdb_assert (ops != NULL);
9759 /* If extra_string isn't useful, set it to NULL. */
9760 if (extra_string != NULL && *extra_string == '\0')
9761 extra_string = NULL;
9763 init_linespec_result (&canonical);
9767 ops->create_sals_from_location (location, &canonical, type_wanted);
9769 CATCH (e, RETURN_MASK_ERROR)
9771 /* If caller is interested in rc value from parse, set
9773 if (e.error == NOT_FOUND_ERROR)
9775 /* If pending breakpoint support is turned off, throw
9778 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9779 throw_exception (e);
9781 exception_print (gdb_stderr, e);
9783 /* If pending breakpoint support is auto query and the user
9784 selects no, then simply return the error code. */
9785 if (pending_break_support == AUTO_BOOLEAN_AUTO
9786 && !nquery (_("Make %s pending on future shared library load? "),
9787 bptype_string (type_wanted)))
9790 /* At this point, either the user was queried about setting
9791 a pending breakpoint and selected yes, or pending
9792 breakpoint behavior is on and thus a pending breakpoint
9793 is defaulted on behalf of the user. */
9797 throw_exception (e);
9801 if (!pending && VEC_empty (linespec_sals, canonical.sals))
9804 /* Create a chain of things that always need to be cleaned up. */
9805 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9807 /* ----------------------------- SNIP -----------------------------
9808 Anything added to the cleanup chain beyond this point is assumed
9809 to be part of a breakpoint. If the breakpoint create succeeds
9810 then the memory is not reclaimed. */
9811 bkpt_chain = make_cleanup (null_cleanup, 0);
9813 /* Resolve all line numbers to PC's and verify that the addresses
9814 are ok for the target. */
9818 struct linespec_sals *iter;
9820 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9821 breakpoint_sals_to_pc (&iter->sals);
9824 /* Fast tracepoints may have additional restrictions on location. */
9825 if (!pending && type_wanted == bp_fast_tracepoint)
9828 struct linespec_sals *iter;
9830 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9831 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9834 /* Verify that condition can be parsed, before setting any
9835 breakpoints. Allocate a separate condition expression for each
9842 struct linespec_sals *lsal;
9844 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9846 /* Here we only parse 'arg' to separate condition
9847 from thread number, so parsing in context of first
9848 sal is OK. When setting the breakpoint we'll
9849 re-parse it in context of each sal. */
9851 find_condition_and_thread (extra_string, lsal->sals.sals[0].pc,
9852 &cond_string, &thread, &task, &rest);
9854 make_cleanup (xfree, cond_string);
9856 make_cleanup (xfree, rest);
9858 extra_string = rest;
9860 extra_string = NULL;
9864 if (type_wanted != bp_dprintf
9865 && extra_string != NULL && *extra_string != '\0')
9866 error (_("Garbage '%s' at end of location"), extra_string);
9868 /* Create a private copy of condition string. */
9871 cond_string = xstrdup (cond_string);
9872 make_cleanup (xfree, cond_string);
9874 /* Create a private copy of any extra string. */
9877 extra_string = xstrdup (extra_string);
9878 make_cleanup (xfree, extra_string);
9882 ops->create_breakpoints_sal (gdbarch, &canonical,
9883 cond_string, extra_string, type_wanted,
9884 tempflag ? disp_del : disp_donttouch,
9885 thread, task, ignore_count, ops,
9886 from_tty, enabled, internal, flags);
9890 struct breakpoint *b;
9892 if (is_tracepoint_type (type_wanted))
9894 struct tracepoint *t;
9896 t = new tracepoint ();
9900 b = new breakpoint ();
9902 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9903 b->location = copy_event_location (location);
9906 b->cond_string = NULL;
9909 /* Create a private copy of condition string. */
9912 cond_string = xstrdup (cond_string);
9913 make_cleanup (xfree, cond_string);
9915 b->cond_string = cond_string;
9919 /* Create a private copy of any extra string. */
9920 if (extra_string != NULL)
9922 extra_string = xstrdup (extra_string);
9923 make_cleanup (xfree, extra_string);
9925 b->extra_string = extra_string;
9926 b->ignore_count = ignore_count;
9927 b->disposition = tempflag ? disp_del : disp_donttouch;
9928 b->condition_not_parsed = 1;
9929 b->enable_state = enabled ? bp_enabled : bp_disabled;
9930 if ((type_wanted != bp_breakpoint
9931 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9932 b->pspace = current_program_space;
9934 install_breakpoint (internal, b, 0);
9937 if (VEC_length (linespec_sals, canonical.sals) > 1)
9939 warning (_("Multiple breakpoints were set.\nUse the "
9940 "\"delete\" command to delete unwanted breakpoints."));
9941 prev_breakpoint_count = prev_bkpt_count;
9944 /* That's it. Discard the cleanups for data inserted into the
9946 discard_cleanups (bkpt_chain);
9947 /* But cleanup everything else. */
9948 do_cleanups (old_chain);
9950 /* error call may happen here - have BKPT_CHAIN already discarded. */
9951 update_global_location_list (UGLL_MAY_INSERT);
9956 /* Set a breakpoint.
9957 ARG is a string describing breakpoint address,
9958 condition, and thread.
9959 FLAG specifies if a breakpoint is hardware on,
9960 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9964 break_command_1 (char *arg, int flag, int from_tty)
9966 int tempflag = flag & BP_TEMPFLAG;
9967 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9968 ? bp_hardware_breakpoint
9970 struct breakpoint_ops *ops;
9971 struct event_location *location;
9972 struct cleanup *cleanup;
9974 location = string_to_event_location (&arg, current_language);
9975 cleanup = make_cleanup_delete_event_location (location);
9977 /* Matching breakpoints on probes. */
9978 if (location != NULL
9979 && event_location_type (location) == PROBE_LOCATION)
9980 ops = &bkpt_probe_breakpoint_ops;
9982 ops = &bkpt_breakpoint_ops;
9984 create_breakpoint (get_current_arch (),
9986 NULL, 0, arg, 1 /* parse arg */,
9987 tempflag, type_wanted,
9988 0 /* Ignore count */,
9989 pending_break_support,
9995 do_cleanups (cleanup);
9998 /* Helper function for break_command_1 and disassemble_command. */
10001 resolve_sal_pc (struct symtab_and_line *sal)
10005 if (sal->pc == 0 && sal->symtab != NULL)
10007 if (!find_line_pc (sal->symtab, sal->line, &pc))
10008 error (_("No line %d in file \"%s\"."),
10009 sal->line, symtab_to_filename_for_display (sal->symtab));
10012 /* If this SAL corresponds to a breakpoint inserted using a line
10013 number, then skip the function prologue if necessary. */
10014 if (sal->explicit_line)
10015 skip_prologue_sal (sal);
10018 if (sal->section == 0 && sal->symtab != NULL)
10020 const struct blockvector *bv;
10021 const struct block *b;
10022 struct symbol *sym;
10024 bv = blockvector_for_pc_sect (sal->pc, 0, &b,
10025 SYMTAB_COMPUNIT (sal->symtab));
10028 sym = block_linkage_function (b);
10031 fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab));
10032 sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab),
10037 /* It really is worthwhile to have the section, so we'll
10038 just have to look harder. This case can be executed
10039 if we have line numbers but no functions (as can
10040 happen in assembly source). */
10042 struct bound_minimal_symbol msym;
10043 struct cleanup *old_chain = save_current_space_and_thread ();
10045 switch_to_program_space_and_thread (sal->pspace);
10047 msym = lookup_minimal_symbol_by_pc (sal->pc);
10049 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10051 do_cleanups (old_chain);
10058 break_command (char *arg, int from_tty)
10060 break_command_1 (arg, 0, from_tty);
10064 tbreak_command (char *arg, int from_tty)
10066 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10070 hbreak_command (char *arg, int from_tty)
10072 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10076 thbreak_command (char *arg, int from_tty)
10078 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10082 stop_command (char *arg, int from_tty)
10084 printf_filtered (_("Specify the type of breakpoint to set.\n\
10085 Usage: stop in <function | address>\n\
10086 stop at <line>\n"));
10090 stopin_command (char *arg, int from_tty)
10094 if (arg == (char *) NULL)
10096 else if (*arg != '*')
10098 char *argptr = arg;
10101 /* Look for a ':'. If this is a line number specification, then
10102 say it is bad, otherwise, it should be an address or
10103 function/method name. */
10104 while (*argptr && !hasColon)
10106 hasColon = (*argptr == ':');
10111 badInput = (*argptr != ':'); /* Not a class::method */
10113 badInput = isdigit (*arg); /* a simple line number */
10117 printf_filtered (_("Usage: stop in <function | address>\n"));
10119 break_command_1 (arg, 0, from_tty);
10123 stopat_command (char *arg, int from_tty)
10127 if (arg == (char *) NULL || *arg == '*') /* no line number */
10131 char *argptr = arg;
10134 /* Look for a ':'. If there is a '::' then get out, otherwise
10135 it is probably a line number. */
10136 while (*argptr && !hasColon)
10138 hasColon = (*argptr == ':');
10143 badInput = (*argptr == ':'); /* we have class::method */
10145 badInput = !isdigit (*arg); /* not a line number */
10149 printf_filtered (_("Usage: stop at <line>\n"));
10151 break_command_1 (arg, 0, from_tty);
10154 /* The dynamic printf command is mostly like a regular breakpoint, but
10155 with a prewired command list consisting of a single output command,
10156 built from extra arguments supplied on the dprintf command
10160 dprintf_command (char *arg, int from_tty)
10162 struct event_location *location;
10163 struct cleanup *cleanup;
10165 location = string_to_event_location (&arg, current_language);
10166 cleanup = make_cleanup_delete_event_location (location);
10168 /* If non-NULL, ARG should have been advanced past the location;
10169 the next character must be ','. */
10172 if (arg[0] != ',' || arg[1] == '\0')
10173 error (_("Format string required"));
10176 /* Skip the comma. */
10181 create_breakpoint (get_current_arch (),
10183 NULL, 0, arg, 1 /* parse arg */,
10185 0 /* Ignore count */,
10186 pending_break_support,
10187 &dprintf_breakpoint_ops,
10192 do_cleanups (cleanup);
10196 agent_printf_command (char *arg, int from_tty)
10198 error (_("May only run agent-printf on the target"));
10201 /* Implement the "breakpoint_hit" breakpoint_ops method for
10202 ranged breakpoints. */
10205 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10206 struct address_space *aspace,
10208 const struct target_waitstatus *ws)
10210 if (ws->kind != TARGET_WAITKIND_STOPPED
10211 || ws->value.sig != GDB_SIGNAL_TRAP)
10214 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10215 bl->length, aspace, bp_addr);
10218 /* Implement the "resources_needed" breakpoint_ops method for
10219 ranged breakpoints. */
10222 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10224 return target_ranged_break_num_registers ();
10227 /* Implement the "print_it" breakpoint_ops method for
10228 ranged breakpoints. */
10230 static enum print_stop_action
10231 print_it_ranged_breakpoint (bpstat bs)
10233 struct breakpoint *b = bs->breakpoint_at;
10234 struct bp_location *bl = b->loc;
10235 struct ui_out *uiout = current_uiout;
10237 gdb_assert (b->type == bp_hardware_breakpoint);
10239 /* Ranged breakpoints have only one location. */
10240 gdb_assert (bl && bl->next == NULL);
10242 annotate_breakpoint (b->number);
10244 maybe_print_thread_hit_breakpoint (uiout);
10246 if (b->disposition == disp_del)
10247 uiout->text ("Temporary ranged breakpoint ");
10249 uiout->text ("Ranged breakpoint ");
10250 if (uiout->is_mi_like_p ())
10252 uiout->field_string ("reason",
10253 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10254 uiout->field_string ("disp", bpdisp_text (b->disposition));
10256 uiout->field_int ("bkptno", b->number);
10257 uiout->text (", ");
10259 return PRINT_SRC_AND_LOC;
10262 /* Implement the "print_one" breakpoint_ops method for
10263 ranged breakpoints. */
10266 print_one_ranged_breakpoint (struct breakpoint *b,
10267 struct bp_location **last_loc)
10269 struct bp_location *bl = b->loc;
10270 struct value_print_options opts;
10271 struct ui_out *uiout = current_uiout;
10273 /* Ranged breakpoints have only one location. */
10274 gdb_assert (bl && bl->next == NULL);
10276 get_user_print_options (&opts);
10278 if (opts.addressprint)
10279 /* We don't print the address range here, it will be printed later
10280 by print_one_detail_ranged_breakpoint. */
10281 uiout->field_skip ("addr");
10282 annotate_field (5);
10283 print_breakpoint_location (b, bl);
10287 /* Implement the "print_one_detail" breakpoint_ops method for
10288 ranged breakpoints. */
10291 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10292 struct ui_out *uiout)
10294 CORE_ADDR address_start, address_end;
10295 struct bp_location *bl = b->loc;
10296 struct ui_file *stb = mem_fileopen ();
10297 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10301 address_start = bl->address;
10302 address_end = address_start + bl->length - 1;
10304 uiout->text ("\taddress range: ");
10305 fprintf_unfiltered (stb, "[%s, %s]",
10306 print_core_address (bl->gdbarch, address_start),
10307 print_core_address (bl->gdbarch, address_end));
10308 uiout->field_stream ("addr", stb);
10309 uiout->text ("\n");
10311 do_cleanups (cleanup);
10314 /* Implement the "print_mention" breakpoint_ops method for
10315 ranged breakpoints. */
10318 print_mention_ranged_breakpoint (struct breakpoint *b)
10320 struct bp_location *bl = b->loc;
10321 struct ui_out *uiout = current_uiout;
10324 gdb_assert (b->type == bp_hardware_breakpoint);
10326 if (uiout->is_mi_like_p ())
10329 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10330 b->number, paddress (bl->gdbarch, bl->address),
10331 paddress (bl->gdbarch, bl->address + bl->length - 1));
10334 /* Implement the "print_recreate" breakpoint_ops method for
10335 ranged breakpoints. */
10338 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10340 fprintf_unfiltered (fp, "break-range %s, %s",
10341 event_location_to_string (b->location),
10342 event_location_to_string (b->location_range_end));
10343 print_recreate_thread (b, fp);
10346 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10348 static struct breakpoint_ops ranged_breakpoint_ops;
10350 /* Find the address where the end of the breakpoint range should be
10351 placed, given the SAL of the end of the range. This is so that if
10352 the user provides a line number, the end of the range is set to the
10353 last instruction of the given line. */
10356 find_breakpoint_range_end (struct symtab_and_line sal)
10360 /* If the user provided a PC value, use it. Otherwise,
10361 find the address of the end of the given location. */
10362 if (sal.explicit_pc)
10369 ret = find_line_pc_range (sal, &start, &end);
10371 error (_("Could not find location of the end of the range."));
10373 /* find_line_pc_range returns the start of the next line. */
10380 /* Implement the "break-range" CLI command. */
10383 break_range_command (char *arg, int from_tty)
10385 char *arg_start, *addr_string_start;
10386 struct linespec_result canonical_start, canonical_end;
10387 int bp_count, can_use_bp, length;
10389 struct breakpoint *b;
10390 struct symtab_and_line sal_start, sal_end;
10391 struct cleanup *cleanup_bkpt;
10392 struct linespec_sals *lsal_start, *lsal_end;
10393 struct event_location *start_location, *end_location;
10395 /* We don't support software ranged breakpoints. */
10396 if (target_ranged_break_num_registers () < 0)
10397 error (_("This target does not support hardware ranged breakpoints."));
10399 bp_count = hw_breakpoint_used_count ();
10400 bp_count += target_ranged_break_num_registers ();
10401 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10403 if (can_use_bp < 0)
10404 error (_("Hardware breakpoints used exceeds limit."));
10406 arg = skip_spaces (arg);
10407 if (arg == NULL || arg[0] == '\0')
10408 error(_("No address range specified."));
10410 init_linespec_result (&canonical_start);
10413 start_location = string_to_event_location (&arg, current_language);
10414 cleanup_bkpt = make_cleanup_delete_event_location (start_location);
10415 parse_breakpoint_sals (start_location, &canonical_start);
10416 make_cleanup_destroy_linespec_result (&canonical_start);
10419 error (_("Too few arguments."));
10420 else if (VEC_empty (linespec_sals, canonical_start.sals))
10421 error (_("Could not find location of the beginning of the range."));
10423 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10425 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10426 || lsal_start->sals.nelts != 1)
10427 error (_("Cannot create a ranged breakpoint with multiple locations."));
10429 sal_start = lsal_start->sals.sals[0];
10430 addr_string_start = savestring (arg_start, arg - arg_start);
10431 make_cleanup (xfree, addr_string_start);
10433 arg++; /* Skip the comma. */
10434 arg = skip_spaces (arg);
10436 /* Parse the end location. */
10438 init_linespec_result (&canonical_end);
10441 /* We call decode_line_full directly here instead of using
10442 parse_breakpoint_sals because we need to specify the start location's
10443 symtab and line as the default symtab and line for the end of the
10444 range. This makes it possible to have ranges like "foo.c:27, +14",
10445 where +14 means 14 lines from the start location. */
10446 end_location = string_to_event_location (&arg, current_language);
10447 make_cleanup_delete_event_location (end_location);
10448 decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL,
10449 sal_start.symtab, sal_start.line,
10450 &canonical_end, NULL, NULL);
10452 make_cleanup_destroy_linespec_result (&canonical_end);
10454 if (VEC_empty (linespec_sals, canonical_end.sals))
10455 error (_("Could not find location of the end of the range."));
10457 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10458 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10459 || lsal_end->sals.nelts != 1)
10460 error (_("Cannot create a ranged breakpoint with multiple locations."));
10462 sal_end = lsal_end->sals.sals[0];
10464 end = find_breakpoint_range_end (sal_end);
10465 if (sal_start.pc > end)
10466 error (_("Invalid address range, end precedes start."));
10468 length = end - sal_start.pc + 1;
10470 /* Length overflowed. */
10471 error (_("Address range too large."));
10472 else if (length == 1)
10474 /* This range is simple enough to be handled by
10475 the `hbreak' command. */
10476 hbreak_command (addr_string_start, 1);
10478 do_cleanups (cleanup_bkpt);
10483 /* Now set up the breakpoint. */
10484 b = set_raw_breakpoint (get_current_arch (), sal_start,
10485 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10486 set_breakpoint_count (breakpoint_count + 1);
10487 b->number = breakpoint_count;
10488 b->disposition = disp_donttouch;
10489 b->location = copy_event_location (start_location);
10490 b->location_range_end = copy_event_location (end_location);
10491 b->loc->length = length;
10493 do_cleanups (cleanup_bkpt);
10496 observer_notify_breakpoint_created (b);
10497 update_global_location_list (UGLL_MAY_INSERT);
10500 /* Return non-zero if EXP is verified as constant. Returned zero
10501 means EXP is variable. Also the constant detection may fail for
10502 some constant expressions and in such case still falsely return
10506 watchpoint_exp_is_const (const struct expression *exp)
10508 int i = exp->nelts;
10514 /* We are only interested in the descriptor of each element. */
10515 operator_length (exp, i, &oplenp, &argsp);
10518 switch (exp->elts[i].opcode)
10528 case BINOP_LOGICAL_AND:
10529 case BINOP_LOGICAL_OR:
10530 case BINOP_BITWISE_AND:
10531 case BINOP_BITWISE_IOR:
10532 case BINOP_BITWISE_XOR:
10534 case BINOP_NOTEQUAL:
10561 case OP_OBJC_NSSTRING:
10564 case UNOP_LOGICAL_NOT:
10565 case UNOP_COMPLEMENT:
10570 case UNOP_CAST_TYPE:
10571 case UNOP_REINTERPRET_CAST:
10572 case UNOP_DYNAMIC_CAST:
10573 /* Unary, binary and ternary operators: We have to check
10574 their operands. If they are constant, then so is the
10575 result of that operation. For instance, if A and B are
10576 determined to be constants, then so is "A + B".
10578 UNOP_IND is one exception to the rule above, because the
10579 value of *ADDR is not necessarily a constant, even when
10584 /* Check whether the associated symbol is a constant.
10586 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10587 possible that a buggy compiler could mark a variable as
10588 constant even when it is not, and TYPE_CONST would return
10589 true in this case, while SYMBOL_CLASS wouldn't.
10591 We also have to check for function symbols because they
10592 are always constant. */
10594 struct symbol *s = exp->elts[i + 2].symbol;
10596 if (SYMBOL_CLASS (s) != LOC_BLOCK
10597 && SYMBOL_CLASS (s) != LOC_CONST
10598 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10603 /* The default action is to return 0 because we are using
10604 the optimistic approach here: If we don't know something,
10605 then it is not a constant. */
10614 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10617 dtor_watchpoint (struct breakpoint *self)
10619 struct watchpoint *w = (struct watchpoint *) self;
10621 xfree (w->exp_string);
10622 xfree (w->exp_string_reparse);
10623 value_free (w->val);
10625 base_breakpoint_ops.dtor (self);
10628 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10631 re_set_watchpoint (struct breakpoint *b)
10633 struct watchpoint *w = (struct watchpoint *) b;
10635 /* Watchpoint can be either on expression using entirely global
10636 variables, or it can be on local variables.
10638 Watchpoints of the first kind are never auto-deleted, and even
10639 persist across program restarts. Since they can use variables
10640 from shared libraries, we need to reparse expression as libraries
10641 are loaded and unloaded.
10643 Watchpoints on local variables can also change meaning as result
10644 of solib event. For example, if a watchpoint uses both a local
10645 and a global variables in expression, it's a local watchpoint,
10646 but unloading of a shared library will make the expression
10647 invalid. This is not a very common use case, but we still
10648 re-evaluate expression, to avoid surprises to the user.
10650 Note that for local watchpoints, we re-evaluate it only if
10651 watchpoints frame id is still valid. If it's not, it means the
10652 watchpoint is out of scope and will be deleted soon. In fact,
10653 I'm not sure we'll ever be called in this case.
10655 If a local watchpoint's frame id is still valid, then
10656 w->exp_valid_block is likewise valid, and we can safely use it.
10658 Don't do anything about disabled watchpoints, since they will be
10659 reevaluated again when enabled. */
10660 update_watchpoint (w, 1 /* reparse */);
10663 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10666 insert_watchpoint (struct bp_location *bl)
10668 struct watchpoint *w = (struct watchpoint *) bl->owner;
10669 int length = w->exact ? 1 : bl->length;
10671 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10672 w->cond_exp.get ());
10675 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10678 remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10680 struct watchpoint *w = (struct watchpoint *) bl->owner;
10681 int length = w->exact ? 1 : bl->length;
10683 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10684 w->cond_exp.get ());
10688 breakpoint_hit_watchpoint (const struct bp_location *bl,
10689 struct address_space *aspace, CORE_ADDR bp_addr,
10690 const struct target_waitstatus *ws)
10692 struct breakpoint *b = bl->owner;
10693 struct watchpoint *w = (struct watchpoint *) b;
10695 /* Continuable hardware watchpoints are treated as non-existent if the
10696 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10697 some data address). Otherwise gdb won't stop on a break instruction
10698 in the code (not from a breakpoint) when a hardware watchpoint has
10699 been defined. Also skip watchpoints which we know did not trigger
10700 (did not match the data address). */
10701 if (is_hardware_watchpoint (b)
10702 && w->watchpoint_triggered == watch_triggered_no)
10709 check_status_watchpoint (bpstat bs)
10711 gdb_assert (is_watchpoint (bs->breakpoint_at));
10713 bpstat_check_watchpoint (bs);
10716 /* Implement the "resources_needed" breakpoint_ops method for
10717 hardware watchpoints. */
10720 resources_needed_watchpoint (const struct bp_location *bl)
10722 struct watchpoint *w = (struct watchpoint *) bl->owner;
10723 int length = w->exact? 1 : bl->length;
10725 return target_region_ok_for_hw_watchpoint (bl->address, length);
10728 /* Implement the "works_in_software_mode" breakpoint_ops method for
10729 hardware watchpoints. */
10732 works_in_software_mode_watchpoint (const struct breakpoint *b)
10734 /* Read and access watchpoints only work with hardware support. */
10735 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10738 static enum print_stop_action
10739 print_it_watchpoint (bpstat bs)
10741 struct cleanup *old_chain;
10742 struct breakpoint *b;
10743 struct ui_file *stb;
10744 enum print_stop_action result;
10745 struct watchpoint *w;
10746 struct ui_out *uiout = current_uiout;
10748 gdb_assert (bs->bp_location_at != NULL);
10750 b = bs->breakpoint_at;
10751 w = (struct watchpoint *) b;
10753 stb = mem_fileopen ();
10754 old_chain = make_cleanup_ui_file_delete (stb);
10756 annotate_watchpoint (b->number);
10757 maybe_print_thread_hit_breakpoint (uiout);
10761 case bp_watchpoint:
10762 case bp_hardware_watchpoint:
10763 if (uiout->is_mi_like_p ())
10764 uiout->field_string
10765 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10767 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10768 uiout->text ("\nOld value = ");
10769 watchpoint_value_print (bs->old_val, stb);
10770 uiout->field_stream ("old", stb);
10771 uiout->text ("\nNew value = ");
10772 watchpoint_value_print (w->val, stb);
10773 uiout->field_stream ("new", stb);
10774 uiout->text ("\n");
10775 /* More than one watchpoint may have been triggered. */
10776 result = PRINT_UNKNOWN;
10779 case bp_read_watchpoint:
10780 if (uiout->is_mi_like_p ())
10781 uiout->field_string
10782 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10784 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10785 uiout->text ("\nValue = ");
10786 watchpoint_value_print (w->val, stb);
10787 uiout->field_stream ("value", stb);
10788 uiout->text ("\n");
10789 result = PRINT_UNKNOWN;
10792 case bp_access_watchpoint:
10793 if (bs->old_val != NULL)
10795 if (uiout->is_mi_like_p ())
10796 uiout->field_string
10798 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10800 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10801 uiout->text ("\nOld value = ");
10802 watchpoint_value_print (bs->old_val, stb);
10803 uiout->field_stream ("old", stb);
10804 uiout->text ("\nNew value = ");
10809 if (uiout->is_mi_like_p ())
10810 uiout->field_string
10812 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10813 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10814 uiout->text ("\nValue = ");
10816 watchpoint_value_print (w->val, stb);
10817 uiout->field_stream ("new", stb);
10818 uiout->text ("\n");
10819 result = PRINT_UNKNOWN;
10822 result = PRINT_UNKNOWN;
10825 do_cleanups (old_chain);
10829 /* Implement the "print_mention" breakpoint_ops method for hardware
10833 print_mention_watchpoint (struct breakpoint *b)
10835 struct cleanup *ui_out_chain;
10836 struct watchpoint *w = (struct watchpoint *) b;
10837 struct ui_out *uiout = current_uiout;
10841 case bp_watchpoint:
10842 uiout->text ("Watchpoint ");
10843 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10845 case bp_hardware_watchpoint:
10846 uiout->text ("Hardware watchpoint ");
10847 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10849 case bp_read_watchpoint:
10850 uiout->text ("Hardware read watchpoint ");
10851 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10853 case bp_access_watchpoint:
10854 uiout->text ("Hardware access (read/write) watchpoint ");
10855 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10858 internal_error (__FILE__, __LINE__,
10859 _("Invalid hardware watchpoint type."));
10862 uiout->field_int ("number", b->number);
10863 uiout->text (": ");
10864 uiout->field_string ("exp", w->exp_string);
10865 do_cleanups (ui_out_chain);
10868 /* Implement the "print_recreate" breakpoint_ops method for
10872 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10874 struct watchpoint *w = (struct watchpoint *) b;
10878 case bp_watchpoint:
10879 case bp_hardware_watchpoint:
10880 fprintf_unfiltered (fp, "watch");
10882 case bp_read_watchpoint:
10883 fprintf_unfiltered (fp, "rwatch");
10885 case bp_access_watchpoint:
10886 fprintf_unfiltered (fp, "awatch");
10889 internal_error (__FILE__, __LINE__,
10890 _("Invalid watchpoint type."));
10893 fprintf_unfiltered (fp, " %s", w->exp_string);
10894 print_recreate_thread (b, fp);
10897 /* Implement the "explains_signal" breakpoint_ops method for
10901 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10903 /* A software watchpoint cannot cause a signal other than
10904 GDB_SIGNAL_TRAP. */
10905 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10911 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10913 static struct breakpoint_ops watchpoint_breakpoint_ops;
10915 /* Implement the "insert" breakpoint_ops method for
10916 masked hardware watchpoints. */
10919 insert_masked_watchpoint (struct bp_location *bl)
10921 struct watchpoint *w = (struct watchpoint *) bl->owner;
10923 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10924 bl->watchpoint_type);
10927 /* Implement the "remove" breakpoint_ops method for
10928 masked hardware watchpoints. */
10931 remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason)
10933 struct watchpoint *w = (struct watchpoint *) bl->owner;
10935 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10936 bl->watchpoint_type);
10939 /* Implement the "resources_needed" breakpoint_ops method for
10940 masked hardware watchpoints. */
10943 resources_needed_masked_watchpoint (const struct bp_location *bl)
10945 struct watchpoint *w = (struct watchpoint *) bl->owner;
10947 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10950 /* Implement the "works_in_software_mode" breakpoint_ops method for
10951 masked hardware watchpoints. */
10954 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10959 /* Implement the "print_it" breakpoint_ops method for
10960 masked hardware watchpoints. */
10962 static enum print_stop_action
10963 print_it_masked_watchpoint (bpstat bs)
10965 struct breakpoint *b = bs->breakpoint_at;
10966 struct ui_out *uiout = current_uiout;
10968 /* Masked watchpoints have only one location. */
10969 gdb_assert (b->loc && b->loc->next == NULL);
10971 annotate_watchpoint (b->number);
10972 maybe_print_thread_hit_breakpoint (uiout);
10976 case bp_hardware_watchpoint:
10977 if (uiout->is_mi_like_p ())
10978 uiout->field_string
10979 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10982 case bp_read_watchpoint:
10983 if (uiout->is_mi_like_p ())
10984 uiout->field_string
10985 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10988 case bp_access_watchpoint:
10989 if (uiout->is_mi_like_p ())
10990 uiout->field_string
10992 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10995 internal_error (__FILE__, __LINE__,
10996 _("Invalid hardware watchpoint type."));
11000 uiout->text (_("\n\
11001 Check the underlying instruction at PC for the memory\n\
11002 address and value which triggered this watchpoint.\n"));
11003 uiout->text ("\n");
11005 /* More than one watchpoint may have been triggered. */
11006 return PRINT_UNKNOWN;
11009 /* Implement the "print_one_detail" breakpoint_ops method for
11010 masked hardware watchpoints. */
11013 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11014 struct ui_out *uiout)
11016 struct watchpoint *w = (struct watchpoint *) b;
11018 /* Masked watchpoints have only one location. */
11019 gdb_assert (b->loc && b->loc->next == NULL);
11021 uiout->text ("\tmask ");
11022 uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask);
11023 uiout->text ("\n");
11026 /* Implement the "print_mention" breakpoint_ops method for
11027 masked hardware watchpoints. */
11030 print_mention_masked_watchpoint (struct breakpoint *b)
11032 struct watchpoint *w = (struct watchpoint *) b;
11033 struct ui_out *uiout = current_uiout;
11034 struct cleanup *ui_out_chain;
11038 case bp_hardware_watchpoint:
11039 uiout->text ("Masked hardware watchpoint ");
11040 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11042 case bp_read_watchpoint:
11043 uiout->text ("Masked hardware read watchpoint ");
11044 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11046 case bp_access_watchpoint:
11047 uiout->text ("Masked hardware access (read/write) watchpoint ");
11048 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11051 internal_error (__FILE__, __LINE__,
11052 _("Invalid hardware watchpoint type."));
11055 uiout->field_int ("number", b->number);
11056 uiout->text (": ");
11057 uiout->field_string ("exp", w->exp_string);
11058 do_cleanups (ui_out_chain);
11061 /* Implement the "print_recreate" breakpoint_ops method for
11062 masked hardware watchpoints. */
11065 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11067 struct watchpoint *w = (struct watchpoint *) b;
11072 case bp_hardware_watchpoint:
11073 fprintf_unfiltered (fp, "watch");
11075 case bp_read_watchpoint:
11076 fprintf_unfiltered (fp, "rwatch");
11078 case bp_access_watchpoint:
11079 fprintf_unfiltered (fp, "awatch");
11082 internal_error (__FILE__, __LINE__,
11083 _("Invalid hardware watchpoint type."));
11086 sprintf_vma (tmp, w->hw_wp_mask);
11087 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11088 print_recreate_thread (b, fp);
11091 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11093 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11095 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11098 is_masked_watchpoint (const struct breakpoint *b)
11100 return b->ops == &masked_watchpoint_breakpoint_ops;
11103 /* accessflag: hw_write: watch write,
11104 hw_read: watch read,
11105 hw_access: watch access (read or write) */
11107 watch_command_1 (const char *arg, int accessflag, int from_tty,
11108 int just_location, int internal)
11110 struct breakpoint *b, *scope_breakpoint = NULL;
11111 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11112 struct value *val, *mark, *result;
11113 int saved_bitpos = 0, saved_bitsize = 0;
11114 struct frame_info *frame;
11115 const char *exp_start = NULL;
11116 const char *exp_end = NULL;
11117 const char *tok, *end_tok;
11119 const char *cond_start = NULL;
11120 const char *cond_end = NULL;
11121 enum bptype bp_type;
11124 /* Flag to indicate whether we are going to use masks for
11125 the hardware watchpoint. */
11127 CORE_ADDR mask = 0;
11128 struct watchpoint *w;
11130 struct cleanup *back_to;
11132 /* Make sure that we actually have parameters to parse. */
11133 if (arg != NULL && arg[0] != '\0')
11135 const char *value_start;
11137 exp_end = arg + strlen (arg);
11139 /* Look for "parameter value" pairs at the end
11140 of the arguments string. */
11141 for (tok = exp_end - 1; tok > arg; tok--)
11143 /* Skip whitespace at the end of the argument list. */
11144 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11147 /* Find the beginning of the last token.
11148 This is the value of the parameter. */
11149 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11151 value_start = tok + 1;
11153 /* Skip whitespace. */
11154 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11159 /* Find the beginning of the second to last token.
11160 This is the parameter itself. */
11161 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11164 toklen = end_tok - tok + 1;
11166 if (toklen == 6 && startswith (tok, "thread"))
11168 struct thread_info *thr;
11169 /* At this point we've found a "thread" token, which means
11170 the user is trying to set a watchpoint that triggers
11171 only in a specific thread. */
11175 error(_("You can specify only one thread."));
11177 /* Extract the thread ID from the next token. */
11178 thr = parse_thread_id (value_start, &endp);
11180 /* Check if the user provided a valid thread ID. */
11181 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11182 invalid_thread_id_error (value_start);
11184 thread = thr->global_num;
11186 else if (toklen == 4 && startswith (tok, "mask"))
11188 /* We've found a "mask" token, which means the user wants to
11189 create a hardware watchpoint that is going to have the mask
11191 struct value *mask_value, *mark;
11194 error(_("You can specify only one mask."));
11196 use_mask = just_location = 1;
11198 mark = value_mark ();
11199 mask_value = parse_to_comma_and_eval (&value_start);
11200 mask = value_as_address (mask_value);
11201 value_free_to_mark (mark);
11204 /* We didn't recognize what we found. We should stop here. */
11207 /* Truncate the string and get rid of the "parameter value" pair before
11208 the arguments string is parsed by the parse_exp_1 function. */
11215 /* Parse the rest of the arguments. From here on out, everything
11216 is in terms of a newly allocated string instead of the original
11218 innermost_block = NULL;
11219 expression = savestring (arg, exp_end - arg);
11220 back_to = make_cleanup (xfree, expression);
11221 exp_start = arg = expression;
11222 expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
11224 /* Remove trailing whitespace from the expression before saving it.
11225 This makes the eventual display of the expression string a bit
11227 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11230 /* Checking if the expression is not constant. */
11231 if (watchpoint_exp_is_const (exp.get ()))
11235 len = exp_end - exp_start;
11236 while (len > 0 && isspace (exp_start[len - 1]))
11238 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11241 exp_valid_block = innermost_block;
11242 mark = value_mark ();
11243 fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location);
11245 if (val != NULL && just_location)
11247 saved_bitpos = value_bitpos (val);
11248 saved_bitsize = value_bitsize (val);
11255 exp_valid_block = NULL;
11256 val = value_addr (result);
11257 release_value (val);
11258 value_free_to_mark (mark);
11262 ret = target_masked_watch_num_registers (value_as_address (val),
11265 error (_("This target does not support masked watchpoints."));
11266 else if (ret == -2)
11267 error (_("Invalid mask or memory region."));
11270 else if (val != NULL)
11271 release_value (val);
11273 tok = skip_spaces_const (arg);
11274 end_tok = skip_to_space_const (tok);
11276 toklen = end_tok - tok;
11277 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11279 innermost_block = NULL;
11280 tok = cond_start = end_tok + 1;
11281 parse_exp_1 (&tok, 0, 0, 0);
11283 /* The watchpoint expression may not be local, but the condition
11284 may still be. E.g.: `watch global if local > 0'. */
11285 cond_exp_valid_block = innermost_block;
11290 error (_("Junk at end of command."));
11292 frame = block_innermost_frame (exp_valid_block);
11294 /* If the expression is "local", then set up a "watchpoint scope"
11295 breakpoint at the point where we've left the scope of the watchpoint
11296 expression. Create the scope breakpoint before the watchpoint, so
11297 that we will encounter it first in bpstat_stop_status. */
11298 if (exp_valid_block && frame)
11300 if (frame_id_p (frame_unwind_caller_id (frame)))
11303 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11304 frame_unwind_caller_pc (frame),
11305 bp_watchpoint_scope,
11306 &momentary_breakpoint_ops);
11308 scope_breakpoint->enable_state = bp_enabled;
11310 /* Automatically delete the breakpoint when it hits. */
11311 scope_breakpoint->disposition = disp_del;
11313 /* Only break in the proper frame (help with recursion). */
11314 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11316 /* Set the address at which we will stop. */
11317 scope_breakpoint->loc->gdbarch
11318 = frame_unwind_caller_arch (frame);
11319 scope_breakpoint->loc->requested_address
11320 = frame_unwind_caller_pc (frame);
11321 scope_breakpoint->loc->address
11322 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11323 scope_breakpoint->loc->requested_address,
11324 scope_breakpoint->type);
11328 /* Now set up the breakpoint. We create all watchpoints as hardware
11329 watchpoints here even if hardware watchpoints are turned off, a call
11330 to update_watchpoint later in this function will cause the type to
11331 drop back to bp_watchpoint (software watchpoint) if required. */
11333 if (accessflag == hw_read)
11334 bp_type = bp_read_watchpoint;
11335 else if (accessflag == hw_access)
11336 bp_type = bp_access_watchpoint;
11338 bp_type = bp_hardware_watchpoint;
11340 w = new watchpoint ();
11343 init_raw_breakpoint_without_location (b, NULL, bp_type,
11344 &masked_watchpoint_breakpoint_ops);
11346 init_raw_breakpoint_without_location (b, NULL, bp_type,
11347 &watchpoint_breakpoint_ops);
11348 b->thread = thread;
11349 b->disposition = disp_donttouch;
11350 b->pspace = current_program_space;
11351 w->exp = std::move (exp);
11352 w->exp_valid_block = exp_valid_block;
11353 w->cond_exp_valid_block = cond_exp_valid_block;
11356 struct type *t = value_type (val);
11357 CORE_ADDR addr = value_as_address (val);
11359 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11361 std::string name = type_to_string (t);
11363 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name.c_str (),
11364 core_addr_to_string (addr));
11366 w->exp_string = xstrprintf ("-location %.*s",
11367 (int) (exp_end - exp_start), exp_start);
11369 /* The above expression is in C. */
11370 b->language = language_c;
11373 w->exp_string = savestring (exp_start, exp_end - exp_start);
11377 w->hw_wp_mask = mask;
11382 w->val_bitpos = saved_bitpos;
11383 w->val_bitsize = saved_bitsize;
11388 b->cond_string = savestring (cond_start, cond_end - cond_start);
11390 b->cond_string = 0;
11394 w->watchpoint_frame = get_frame_id (frame);
11395 w->watchpoint_thread = inferior_ptid;
11399 w->watchpoint_frame = null_frame_id;
11400 w->watchpoint_thread = null_ptid;
11403 if (scope_breakpoint != NULL)
11405 /* The scope breakpoint is related to the watchpoint. We will
11406 need to act on them together. */
11407 b->related_breakpoint = scope_breakpoint;
11408 scope_breakpoint->related_breakpoint = b;
11411 if (!just_location)
11412 value_free_to_mark (mark);
11416 /* Finally update the new watchpoint. This creates the locations
11417 that should be inserted. */
11418 update_watchpoint (w, 1);
11420 CATCH (e, RETURN_MASK_ALL)
11422 delete_breakpoint (b);
11423 throw_exception (e);
11427 install_breakpoint (internal, b, 1);
11428 do_cleanups (back_to);
11431 /* Return count of debug registers needed to watch the given expression.
11432 If the watchpoint cannot be handled in hardware return zero. */
11435 can_use_hardware_watchpoint (struct value *v)
11437 int found_memory_cnt = 0;
11438 struct value *head = v;
11440 /* Did the user specifically forbid us to use hardware watchpoints? */
11441 if (!can_use_hw_watchpoints)
11444 /* Make sure that the value of the expression depends only upon
11445 memory contents, and values computed from them within GDB. If we
11446 find any register references or function calls, we can't use a
11447 hardware watchpoint.
11449 The idea here is that evaluating an expression generates a series
11450 of values, one holding the value of every subexpression. (The
11451 expression a*b+c has five subexpressions: a, b, a*b, c, and
11452 a*b+c.) GDB's values hold almost enough information to establish
11453 the criteria given above --- they identify memory lvalues,
11454 register lvalues, computed values, etcetera. So we can evaluate
11455 the expression, and then scan the chain of values that leaves
11456 behind to decide whether we can detect any possible change to the
11457 expression's final value using only hardware watchpoints.
11459 However, I don't think that the values returned by inferior
11460 function calls are special in any way. So this function may not
11461 notice that an expression involving an inferior function call
11462 can't be watched with hardware watchpoints. FIXME. */
11463 for (; v; v = value_next (v))
11465 if (VALUE_LVAL (v) == lval_memory)
11467 if (v != head && value_lazy (v))
11468 /* A lazy memory lvalue in the chain is one that GDB never
11469 needed to fetch; we either just used its address (e.g.,
11470 `a' in `a.b') or we never needed it at all (e.g., `a'
11471 in `a,b'). This doesn't apply to HEAD; if that is
11472 lazy then it was not readable, but watch it anyway. */
11476 /* Ahh, memory we actually used! Check if we can cover
11477 it with hardware watchpoints. */
11478 struct type *vtype = check_typedef (value_type (v));
11480 /* We only watch structs and arrays if user asked for it
11481 explicitly, never if they just happen to appear in a
11482 middle of some value chain. */
11484 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11485 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11487 CORE_ADDR vaddr = value_address (v);
11491 len = (target_exact_watchpoints
11492 && is_scalar_type_recursive (vtype))?
11493 1 : TYPE_LENGTH (value_type (v));
11495 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11499 found_memory_cnt += num_regs;
11503 else if (VALUE_LVAL (v) != not_lval
11504 && deprecated_value_modifiable (v) == 0)
11505 return 0; /* These are values from the history (e.g., $1). */
11506 else if (VALUE_LVAL (v) == lval_register)
11507 return 0; /* Cannot watch a register with a HW watchpoint. */
11510 /* The expression itself looks suitable for using a hardware
11511 watchpoint, but give the target machine a chance to reject it. */
11512 return found_memory_cnt;
11516 watch_command_wrapper (char *arg, int from_tty, int internal)
11518 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11521 /* A helper function that looks for the "-location" argument and then
11522 calls watch_command_1. */
11525 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11527 int just_location = 0;
11530 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11531 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11533 arg = skip_spaces (arg);
11537 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11541 watch_command (char *arg, int from_tty)
11543 watch_maybe_just_location (arg, hw_write, from_tty);
11547 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11549 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11553 rwatch_command (char *arg, int from_tty)
11555 watch_maybe_just_location (arg, hw_read, from_tty);
11559 awatch_command_wrapper (char *arg, int from_tty, int internal)
11561 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11565 awatch_command (char *arg, int from_tty)
11567 watch_maybe_just_location (arg, hw_access, from_tty);
11571 /* Data for the FSM that manages the until(location)/advance commands
11572 in infcmd.c. Here because it uses the mechanisms of
11575 struct until_break_fsm
11577 /* The base class. */
11578 struct thread_fsm thread_fsm;
11580 /* The thread that as current when the command was executed. */
11583 /* The breakpoint set at the destination location. */
11584 struct breakpoint *location_breakpoint;
11586 /* Breakpoint set at the return address in the caller frame. May be
11588 struct breakpoint *caller_breakpoint;
11591 static void until_break_fsm_clean_up (struct thread_fsm *self,
11592 struct thread_info *thread);
11593 static int until_break_fsm_should_stop (struct thread_fsm *self,
11594 struct thread_info *thread);
11595 static enum async_reply_reason
11596 until_break_fsm_async_reply_reason (struct thread_fsm *self);
11598 /* until_break_fsm's vtable. */
11600 static struct thread_fsm_ops until_break_fsm_ops =
11603 until_break_fsm_clean_up,
11604 until_break_fsm_should_stop,
11605 NULL, /* return_value */
11606 until_break_fsm_async_reply_reason,
11609 /* Allocate a new until_break_command_fsm. */
11611 static struct until_break_fsm *
11612 new_until_break_fsm (struct interp *cmd_interp, int thread,
11613 struct breakpoint *location_breakpoint,
11614 struct breakpoint *caller_breakpoint)
11616 struct until_break_fsm *sm;
11618 sm = XCNEW (struct until_break_fsm);
11619 thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
11621 sm->thread = thread;
11622 sm->location_breakpoint = location_breakpoint;
11623 sm->caller_breakpoint = caller_breakpoint;
11628 /* Implementation of the 'should_stop' FSM method for the
11629 until(location)/advance commands. */
11632 until_break_fsm_should_stop (struct thread_fsm *self,
11633 struct thread_info *tp)
11635 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11637 if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11638 sm->location_breakpoint) != NULL
11639 || (sm->caller_breakpoint != NULL
11640 && bpstat_find_breakpoint (tp->control.stop_bpstat,
11641 sm->caller_breakpoint) != NULL))
11642 thread_fsm_set_finished (self);
11647 /* Implementation of the 'clean_up' FSM method for the
11648 until(location)/advance commands. */
11651 until_break_fsm_clean_up (struct thread_fsm *self,
11652 struct thread_info *thread)
11654 struct until_break_fsm *sm = (struct until_break_fsm *) self;
11656 /* Clean up our temporary breakpoints. */
11657 if (sm->location_breakpoint != NULL)
11659 delete_breakpoint (sm->location_breakpoint);
11660 sm->location_breakpoint = NULL;
11662 if (sm->caller_breakpoint != NULL)
11664 delete_breakpoint (sm->caller_breakpoint);
11665 sm->caller_breakpoint = NULL;
11667 delete_longjmp_breakpoint (sm->thread);
11670 /* Implementation of the 'async_reply_reason' FSM method for the
11671 until(location)/advance commands. */
11673 static enum async_reply_reason
11674 until_break_fsm_async_reply_reason (struct thread_fsm *self)
11676 return EXEC_ASYNC_LOCATION_REACHED;
11680 until_break_command (char *arg, int from_tty, int anywhere)
11682 struct symtabs_and_lines sals;
11683 struct symtab_and_line sal;
11684 struct frame_info *frame;
11685 struct gdbarch *frame_gdbarch;
11686 struct frame_id stack_frame_id;
11687 struct frame_id caller_frame_id;
11688 struct breakpoint *location_breakpoint;
11689 struct breakpoint *caller_breakpoint = NULL;
11690 struct cleanup *old_chain, *cleanup;
11692 struct thread_info *tp;
11693 struct event_location *location;
11694 struct until_break_fsm *sm;
11696 clear_proceed_status (0);
11698 /* Set a breakpoint where the user wants it and at return from
11701 location = string_to_event_location (&arg, current_language);
11702 cleanup = make_cleanup_delete_event_location (location);
11704 if (last_displayed_sal_is_valid ())
11705 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL,
11706 get_last_displayed_symtab (),
11707 get_last_displayed_line ());
11709 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE,
11710 NULL, (struct symtab *) NULL, 0);
11712 if (sals.nelts != 1)
11713 error (_("Couldn't get information on specified line."));
11715 sal = sals.sals[0];
11716 xfree (sals.sals); /* malloc'd, so freed. */
11719 error (_("Junk at end of arguments."));
11721 resolve_sal_pc (&sal);
11723 tp = inferior_thread ();
11724 thread = tp->global_num;
11726 old_chain = make_cleanup (null_cleanup, NULL);
11728 /* Note linespec handling above invalidates the frame chain.
11729 Installing a breakpoint also invalidates the frame chain (as it
11730 may need to switch threads), so do any frame handling before
11733 frame = get_selected_frame (NULL);
11734 frame_gdbarch = get_frame_arch (frame);
11735 stack_frame_id = get_stack_frame_id (frame);
11736 caller_frame_id = frame_unwind_caller_id (frame);
11738 /* Keep within the current frame, or in frames called by the current
11741 if (frame_id_p (caller_frame_id))
11743 struct symtab_and_line sal2;
11744 struct gdbarch *caller_gdbarch;
11746 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11747 sal2.pc = frame_unwind_caller_pc (frame);
11748 caller_gdbarch = frame_unwind_caller_arch (frame);
11749 caller_breakpoint = set_momentary_breakpoint (caller_gdbarch,
11753 make_cleanup_delete_breakpoint (caller_breakpoint);
11755 set_longjmp_breakpoint (tp, caller_frame_id);
11756 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11759 /* set_momentary_breakpoint could invalidate FRAME. */
11763 /* If the user told us to continue until a specified location,
11764 we don't specify a frame at which we need to stop. */
11765 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11766 null_frame_id, bp_until);
11768 /* Otherwise, specify the selected frame, because we want to stop
11769 only at the very same frame. */
11770 location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11771 stack_frame_id, bp_until);
11772 make_cleanup_delete_breakpoint (location_breakpoint);
11774 sm = new_until_break_fsm (command_interp (), tp->global_num,
11775 location_breakpoint, caller_breakpoint);
11776 tp->thread_fsm = &sm->thread_fsm;
11778 discard_cleanups (old_chain);
11780 proceed (-1, GDB_SIGNAL_DEFAULT);
11782 do_cleanups (cleanup);
11785 /* This function attempts to parse an optional "if <cond>" clause
11786 from the arg string. If one is not found, it returns NULL.
11788 Else, it returns a pointer to the condition string. (It does not
11789 attempt to evaluate the string against a particular block.) And,
11790 it updates arg to point to the first character following the parsed
11791 if clause in the arg string. */
11794 ep_parse_optional_if_clause (char **arg)
11798 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11801 /* Skip the "if" keyword. */
11804 /* Skip any extra leading whitespace, and record the start of the
11805 condition string. */
11806 *arg = skip_spaces (*arg);
11807 cond_string = *arg;
11809 /* Assume that the condition occupies the remainder of the arg
11811 (*arg) += strlen (cond_string);
11813 return cond_string;
11816 /* Commands to deal with catching events, such as signals, exceptions,
11817 process start/exit, etc. */
11821 catch_fork_temporary, catch_vfork_temporary,
11822 catch_fork_permanent, catch_vfork_permanent
11827 catch_fork_command_1 (char *arg, int from_tty,
11828 struct cmd_list_element *command)
11830 struct gdbarch *gdbarch = get_current_arch ();
11831 char *cond_string = NULL;
11832 catch_fork_kind fork_kind;
11835 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11836 tempflag = (fork_kind == catch_fork_temporary
11837 || fork_kind == catch_vfork_temporary);
11841 arg = skip_spaces (arg);
11843 /* The allowed syntax is:
11845 catch [v]fork if <cond>
11847 First, check if there's an if clause. */
11848 cond_string = ep_parse_optional_if_clause (&arg);
11850 if ((*arg != '\0') && !isspace (*arg))
11851 error (_("Junk at end of arguments."));
11853 /* If this target supports it, create a fork or vfork catchpoint
11854 and enable reporting of such events. */
11857 case catch_fork_temporary:
11858 case catch_fork_permanent:
11859 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11860 &catch_fork_breakpoint_ops);
11862 case catch_vfork_temporary:
11863 case catch_vfork_permanent:
11864 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11865 &catch_vfork_breakpoint_ops);
11868 error (_("unsupported or unknown fork kind; cannot catch it"));
11874 catch_exec_command_1 (char *arg, int from_tty,
11875 struct cmd_list_element *command)
11877 struct exec_catchpoint *c;
11878 struct gdbarch *gdbarch = get_current_arch ();
11880 char *cond_string = NULL;
11882 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11886 arg = skip_spaces (arg);
11888 /* The allowed syntax is:
11890 catch exec if <cond>
11892 First, check if there's an if clause. */
11893 cond_string = ep_parse_optional_if_clause (&arg);
11895 if ((*arg != '\0') && !isspace (*arg))
11896 error (_("Junk at end of arguments."));
11898 c = new exec_catchpoint ();
11899 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11900 &catch_exec_breakpoint_ops);
11901 c->exec_pathname = NULL;
11903 install_breakpoint (0, &c->base, 1);
11907 init_ada_exception_breakpoint (struct breakpoint *b,
11908 struct gdbarch *gdbarch,
11909 struct symtab_and_line sal,
11911 const struct breakpoint_ops *ops,
11918 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11920 loc_gdbarch = gdbarch;
11922 describe_other_breakpoints (loc_gdbarch,
11923 sal.pspace, sal.pc, sal.section, -1);
11924 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11925 version for exception catchpoints, because two catchpoints
11926 used for different exception names will use the same address.
11927 In this case, a "breakpoint ... also set at..." warning is
11928 unproductive. Besides, the warning phrasing is also a bit
11929 inappropriate, we should use the word catchpoint, and tell
11930 the user what type of catchpoint it is. The above is good
11931 enough for now, though. */
11934 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11936 b->enable_state = enabled ? bp_enabled : bp_disabled;
11937 b->disposition = tempflag ? disp_del : disp_donttouch;
11938 b->location = string_to_event_location (&addr_string,
11939 language_def (language_ada));
11940 b->language = language_ada;
11944 catch_command (char *arg, int from_tty)
11946 error (_("Catch requires an event name."));
11951 tcatch_command (char *arg, int from_tty)
11953 error (_("Catch requires an event name."));
11956 /* A qsort comparison function that sorts breakpoints in order. */
11959 compare_breakpoints (const void *a, const void *b)
11961 const breakpoint_p *ba = (const breakpoint_p *) a;
11962 uintptr_t ua = (uintptr_t) *ba;
11963 const breakpoint_p *bb = (const breakpoint_p *) b;
11964 uintptr_t ub = (uintptr_t) *bb;
11966 if ((*ba)->number < (*bb)->number)
11968 else if ((*ba)->number > (*bb)->number)
11971 /* Now sort by address, in case we see, e..g, two breakpoints with
11975 return ua > ub ? 1 : 0;
11978 /* Delete breakpoints by address or line. */
11981 clear_command (char *arg, int from_tty)
11983 struct breakpoint *b, *prev;
11984 VEC(breakpoint_p) *found = 0;
11987 struct symtabs_and_lines sals;
11988 struct symtab_and_line sal;
11990 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11994 sals = decode_line_with_current_source (arg,
11995 (DECODE_LINE_FUNFIRSTLINE
11996 | DECODE_LINE_LIST_MODE));
11997 make_cleanup (xfree, sals.sals);
12002 sals.sals = XNEW (struct symtab_and_line);
12003 make_cleanup (xfree, sals.sals);
12004 init_sal (&sal); /* Initialize to zeroes. */
12006 /* Set sal's line, symtab, pc, and pspace to the values
12007 corresponding to the last call to print_frame_info. If the
12008 codepoint is not valid, this will set all the fields to 0. */
12009 get_last_displayed_sal (&sal);
12010 if (sal.symtab == 0)
12011 error (_("No source file specified."));
12013 sals.sals[0] = sal;
12019 /* We don't call resolve_sal_pc here. That's not as bad as it
12020 seems, because all existing breakpoints typically have both
12021 file/line and pc set. So, if clear is given file/line, we can
12022 match this to existing breakpoint without obtaining pc at all.
12024 We only support clearing given the address explicitly
12025 present in breakpoint table. Say, we've set breakpoint
12026 at file:line. There were several PC values for that file:line,
12027 due to optimization, all in one block.
12029 We've picked one PC value. If "clear" is issued with another
12030 PC corresponding to the same file:line, the breakpoint won't
12031 be cleared. We probably can still clear the breakpoint, but
12032 since the other PC value is never presented to user, user
12033 can only find it by guessing, and it does not seem important
12034 to support that. */
12036 /* For each line spec given, delete bps which correspond to it. Do
12037 it in two passes, solely to preserve the current behavior that
12038 from_tty is forced true if we delete more than one
12042 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12043 for (i = 0; i < sals.nelts; i++)
12045 const char *sal_fullname;
12047 /* If exact pc given, clear bpts at that pc.
12048 If line given (pc == 0), clear all bpts on specified line.
12049 If defaulting, clear all bpts on default line
12052 defaulting sal.pc != 0 tests to do
12057 1 0 <can't happen> */
12059 sal = sals.sals[i];
12060 sal_fullname = (sal.symtab == NULL
12061 ? NULL : symtab_to_fullname (sal.symtab));
12063 /* Find all matching breakpoints and add them to 'found'. */
12064 ALL_BREAKPOINTS (b)
12067 /* Are we going to delete b? */
12068 if (b->type != bp_none && !is_watchpoint (b))
12070 struct bp_location *loc = b->loc;
12071 for (; loc; loc = loc->next)
12073 /* If the user specified file:line, don't allow a PC
12074 match. This matches historical gdb behavior. */
12075 int pc_match = (!sal.explicit_line
12077 && (loc->pspace == sal.pspace)
12078 && (loc->address == sal.pc)
12079 && (!section_is_overlay (loc->section)
12080 || loc->section == sal.section));
12081 int line_match = 0;
12083 if ((default_match || sal.explicit_line)
12084 && loc->symtab != NULL
12085 && sal_fullname != NULL
12086 && sal.pspace == loc->pspace
12087 && loc->line_number == sal.line
12088 && filename_cmp (symtab_to_fullname (loc->symtab),
12089 sal_fullname) == 0)
12092 if (pc_match || line_match)
12101 VEC_safe_push(breakpoint_p, found, b);
12105 /* Now go thru the 'found' chain and delete them. */
12106 if (VEC_empty(breakpoint_p, found))
12109 error (_("No breakpoint at %s."), arg);
12111 error (_("No breakpoint at this line."));
12114 /* Remove duplicates from the vec. */
12115 qsort (VEC_address (breakpoint_p, found),
12116 VEC_length (breakpoint_p, found),
12117 sizeof (breakpoint_p),
12118 compare_breakpoints);
12119 prev = VEC_index (breakpoint_p, found, 0);
12120 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12124 VEC_ordered_remove (breakpoint_p, found, ix);
12129 if (VEC_length(breakpoint_p, found) > 1)
12130 from_tty = 1; /* Always report if deleted more than one. */
12133 if (VEC_length(breakpoint_p, found) == 1)
12134 printf_unfiltered (_("Deleted breakpoint "));
12136 printf_unfiltered (_("Deleted breakpoints "));
12139 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12142 printf_unfiltered ("%d ", b->number);
12143 delete_breakpoint (b);
12146 putchar_unfiltered ('\n');
12148 do_cleanups (cleanups);
12151 /* Delete breakpoint in BS if they are `delete' breakpoints and
12152 all breakpoints that are marked for deletion, whether hit or not.
12153 This is called after any breakpoint is hit, or after errors. */
12156 breakpoint_auto_delete (bpstat bs)
12158 struct breakpoint *b, *b_tmp;
12160 for (; bs; bs = bs->next)
12161 if (bs->breakpoint_at
12162 && bs->breakpoint_at->disposition == disp_del
12164 delete_breakpoint (bs->breakpoint_at);
12166 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12168 if (b->disposition == disp_del_at_next_stop)
12169 delete_breakpoint (b);
12173 /* A comparison function for bp_location AP and BP being interfaced to
12174 qsort. Sort elements primarily by their ADDRESS (no matter what
12175 does breakpoint_address_is_meaningful say for its OWNER),
12176 secondarily by ordering first permanent elements and
12177 terciarily just ensuring the array is sorted stable way despite
12178 qsort being an unstable algorithm. */
12181 bp_location_compare (const void *ap, const void *bp)
12183 const struct bp_location *a = *(const struct bp_location **) ap;
12184 const struct bp_location *b = *(const struct bp_location **) bp;
12186 if (a->address != b->address)
12187 return (a->address > b->address) - (a->address < b->address);
12189 /* Sort locations at the same address by their pspace number, keeping
12190 locations of the same inferior (in a multi-inferior environment)
12193 if (a->pspace->num != b->pspace->num)
12194 return ((a->pspace->num > b->pspace->num)
12195 - (a->pspace->num < b->pspace->num));
12197 /* Sort permanent breakpoints first. */
12198 if (a->permanent != b->permanent)
12199 return (a->permanent < b->permanent) - (a->permanent > b->permanent);
12201 /* Make the internal GDB representation stable across GDB runs
12202 where A and B memory inside GDB can differ. Breakpoint locations of
12203 the same type at the same address can be sorted in arbitrary order. */
12205 if (a->owner->number != b->owner->number)
12206 return ((a->owner->number > b->owner->number)
12207 - (a->owner->number < b->owner->number));
12209 return (a > b) - (a < b);
12212 /* Set bp_location_placed_address_before_address_max and
12213 bp_location_shadow_len_after_address_max according to the current
12214 content of the bp_location array. */
12217 bp_location_target_extensions_update (void)
12219 struct bp_location *bl, **blp_tmp;
12221 bp_location_placed_address_before_address_max = 0;
12222 bp_location_shadow_len_after_address_max = 0;
12224 ALL_BP_LOCATIONS (bl, blp_tmp)
12226 CORE_ADDR start, end, addr;
12228 if (!bp_location_has_shadow (bl))
12231 start = bl->target_info.placed_address;
12232 end = start + bl->target_info.shadow_len;
12234 gdb_assert (bl->address >= start);
12235 addr = bl->address - start;
12236 if (addr > bp_location_placed_address_before_address_max)
12237 bp_location_placed_address_before_address_max = addr;
12239 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12241 gdb_assert (bl->address < end);
12242 addr = end - bl->address;
12243 if (addr > bp_location_shadow_len_after_address_max)
12244 bp_location_shadow_len_after_address_max = addr;
12248 /* Download tracepoint locations if they haven't been. */
12251 download_tracepoint_locations (void)
12253 struct breakpoint *b;
12254 struct cleanup *old_chain;
12255 enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN;
12257 old_chain = save_current_space_and_thread ();
12259 ALL_TRACEPOINTS (b)
12261 struct bp_location *bl;
12262 struct tracepoint *t;
12263 int bp_location_downloaded = 0;
12265 if ((b->type == bp_fast_tracepoint
12266 ? !may_insert_fast_tracepoints
12267 : !may_insert_tracepoints))
12270 if (can_download_tracepoint == TRIBOOL_UNKNOWN)
12272 if (target_can_download_tracepoint ())
12273 can_download_tracepoint = TRIBOOL_TRUE;
12275 can_download_tracepoint = TRIBOOL_FALSE;
12278 if (can_download_tracepoint == TRIBOOL_FALSE)
12281 for (bl = b->loc; bl; bl = bl->next)
12283 /* In tracepoint, locations are _never_ duplicated, so
12284 should_be_inserted is equivalent to
12285 unduplicated_should_be_inserted. */
12286 if (!should_be_inserted (bl) || bl->inserted)
12289 switch_to_program_space_and_thread (bl->pspace);
12291 target_download_tracepoint (bl);
12294 bp_location_downloaded = 1;
12296 t = (struct tracepoint *) b;
12297 t->number_on_target = b->number;
12298 if (bp_location_downloaded)
12299 observer_notify_breakpoint_modified (b);
12302 do_cleanups (old_chain);
12305 /* Swap the insertion/duplication state between two locations. */
12308 swap_insertion (struct bp_location *left, struct bp_location *right)
12310 const int left_inserted = left->inserted;
12311 const int left_duplicate = left->duplicate;
12312 const int left_needs_update = left->needs_update;
12313 const struct bp_target_info left_target_info = left->target_info;
12315 /* Locations of tracepoints can never be duplicated. */
12316 if (is_tracepoint (left->owner))
12317 gdb_assert (!left->duplicate);
12318 if (is_tracepoint (right->owner))
12319 gdb_assert (!right->duplicate);
12321 left->inserted = right->inserted;
12322 left->duplicate = right->duplicate;
12323 left->needs_update = right->needs_update;
12324 left->target_info = right->target_info;
12325 right->inserted = left_inserted;
12326 right->duplicate = left_duplicate;
12327 right->needs_update = left_needs_update;
12328 right->target_info = left_target_info;
12331 /* Force the re-insertion of the locations at ADDRESS. This is called
12332 once a new/deleted/modified duplicate location is found and we are evaluating
12333 conditions on the target's side. Such conditions need to be updated on
12337 force_breakpoint_reinsertion (struct bp_location *bl)
12339 struct bp_location **locp = NULL, **loc2p;
12340 struct bp_location *loc;
12341 CORE_ADDR address = 0;
12344 address = bl->address;
12345 pspace_num = bl->pspace->num;
12347 /* This is only meaningful if the target is
12348 evaluating conditions and if the user has
12349 opted for condition evaluation on the target's
12351 if (gdb_evaluates_breakpoint_condition_p ()
12352 || !target_supports_evaluation_of_breakpoint_conditions ())
12355 /* Flag all breakpoint locations with this address and
12356 the same program space as the location
12357 as "its condition has changed". We need to
12358 update the conditions on the target's side. */
12359 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12363 if (!is_breakpoint (loc->owner)
12364 || pspace_num != loc->pspace->num)
12367 /* Flag the location appropriately. We use a different state to
12368 let everyone know that we already updated the set of locations
12369 with addr bl->address and program space bl->pspace. This is so
12370 we don't have to keep calling these functions just to mark locations
12371 that have already been marked. */
12372 loc->condition_changed = condition_updated;
12374 /* Free the agent expression bytecode as well. We will compute
12376 loc->cond_bytecode.reset ();
12379 /* Called whether new breakpoints are created, or existing breakpoints
12380 deleted, to update the global location list and recompute which
12381 locations are duplicate of which.
12383 The INSERT_MODE flag determines whether locations may not, may, or
12384 shall be inserted now. See 'enum ugll_insert_mode' for more
12388 update_global_location_list (enum ugll_insert_mode insert_mode)
12390 struct breakpoint *b;
12391 struct bp_location **locp, *loc;
12392 struct cleanup *cleanups;
12393 /* Last breakpoint location address that was marked for update. */
12394 CORE_ADDR last_addr = 0;
12395 /* Last breakpoint location program space that was marked for update. */
12396 int last_pspace_num = -1;
12398 /* Used in the duplicates detection below. When iterating over all
12399 bp_locations, points to the first bp_location of a given address.
12400 Breakpoints and watchpoints of different types are never
12401 duplicates of each other. Keep one pointer for each type of
12402 breakpoint/watchpoint, so we only need to loop over all locations
12404 struct bp_location *bp_loc_first; /* breakpoint */
12405 struct bp_location *wp_loc_first; /* hardware watchpoint */
12406 struct bp_location *awp_loc_first; /* access watchpoint */
12407 struct bp_location *rwp_loc_first; /* read watchpoint */
12409 /* Saved former bp_location array which we compare against the newly
12410 built bp_location from the current state of ALL_BREAKPOINTS. */
12411 struct bp_location **old_location, **old_locp;
12412 unsigned old_location_count;
12414 old_location = bp_location;
12415 old_location_count = bp_location_count;
12416 bp_location = NULL;
12417 bp_location_count = 0;
12418 cleanups = make_cleanup (xfree, old_location);
12420 ALL_BREAKPOINTS (b)
12421 for (loc = b->loc; loc; loc = loc->next)
12422 bp_location_count++;
12424 bp_location = XNEWVEC (struct bp_location *, bp_location_count);
12425 locp = bp_location;
12426 ALL_BREAKPOINTS (b)
12427 for (loc = b->loc; loc; loc = loc->next)
12429 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12430 bp_location_compare);
12432 bp_location_target_extensions_update ();
12434 /* Identify bp_location instances that are no longer present in the
12435 new list, and therefore should be freed. Note that it's not
12436 necessary that those locations should be removed from inferior --
12437 if there's another location at the same address (previously
12438 marked as duplicate), we don't need to remove/insert the
12441 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12442 and former bp_location array state respectively. */
12444 locp = bp_location;
12445 for (old_locp = old_location; old_locp < old_location + old_location_count;
12448 struct bp_location *old_loc = *old_locp;
12449 struct bp_location **loc2p;
12451 /* Tells if 'old_loc' is found among the new locations. If
12452 not, we have to free it. */
12453 int found_object = 0;
12454 /* Tells if the location should remain inserted in the target. */
12455 int keep_in_target = 0;
12458 /* Skip LOCP entries which will definitely never be needed.
12459 Stop either at or being the one matching OLD_LOC. */
12460 while (locp < bp_location + bp_location_count
12461 && (*locp)->address < old_loc->address)
12465 (loc2p < bp_location + bp_location_count
12466 && (*loc2p)->address == old_loc->address);
12469 /* Check if this is a new/duplicated location or a duplicated
12470 location that had its condition modified. If so, we want to send
12471 its condition to the target if evaluation of conditions is taking
12473 if ((*loc2p)->condition_changed == condition_modified
12474 && (last_addr != old_loc->address
12475 || last_pspace_num != old_loc->pspace->num))
12477 force_breakpoint_reinsertion (*loc2p);
12478 last_pspace_num = old_loc->pspace->num;
12481 if (*loc2p == old_loc)
12485 /* We have already handled this address, update it so that we don't
12486 have to go through updates again. */
12487 last_addr = old_loc->address;
12489 /* Target-side condition evaluation: Handle deleted locations. */
12491 force_breakpoint_reinsertion (old_loc);
12493 /* If this location is no longer present, and inserted, look if
12494 there's maybe a new location at the same address. If so,
12495 mark that one inserted, and don't remove this one. This is
12496 needed so that we don't have a time window where a breakpoint
12497 at certain location is not inserted. */
12499 if (old_loc->inserted)
12501 /* If the location is inserted now, we might have to remove
12504 if (found_object && should_be_inserted (old_loc))
12506 /* The location is still present in the location list,
12507 and still should be inserted. Don't do anything. */
12508 keep_in_target = 1;
12512 /* This location still exists, but it won't be kept in the
12513 target since it may have been disabled. We proceed to
12514 remove its target-side condition. */
12516 /* The location is either no longer present, or got
12517 disabled. See if there's another location at the
12518 same address, in which case we don't need to remove
12519 this one from the target. */
12521 /* OLD_LOC comes from existing struct breakpoint. */
12522 if (breakpoint_address_is_meaningful (old_loc->owner))
12525 (loc2p < bp_location + bp_location_count
12526 && (*loc2p)->address == old_loc->address);
12529 struct bp_location *loc2 = *loc2p;
12531 if (breakpoint_locations_match (loc2, old_loc))
12533 /* Read watchpoint locations are switched to
12534 access watchpoints, if the former are not
12535 supported, but the latter are. */
12536 if (is_hardware_watchpoint (old_loc->owner))
12538 gdb_assert (is_hardware_watchpoint (loc2->owner));
12539 loc2->watchpoint_type = old_loc->watchpoint_type;
12542 /* loc2 is a duplicated location. We need to check
12543 if it should be inserted in case it will be
12545 if (loc2 != old_loc
12546 && unduplicated_should_be_inserted (loc2))
12548 swap_insertion (old_loc, loc2);
12549 keep_in_target = 1;
12557 if (!keep_in_target)
12559 if (remove_breakpoint (old_loc))
12561 /* This is just about all we can do. We could keep
12562 this location on the global list, and try to
12563 remove it next time, but there's no particular
12564 reason why we will succeed next time.
12566 Note that at this point, old_loc->owner is still
12567 valid, as delete_breakpoint frees the breakpoint
12568 only after calling us. */
12569 printf_filtered (_("warning: Error removing "
12570 "breakpoint %d\n"),
12571 old_loc->owner->number);
12579 if (removed && target_is_non_stop_p ()
12580 && need_moribund_for_location_type (old_loc))
12582 /* This location was removed from the target. In
12583 non-stop mode, a race condition is possible where
12584 we've removed a breakpoint, but stop events for that
12585 breakpoint are already queued and will arrive later.
12586 We apply an heuristic to be able to distinguish such
12587 SIGTRAPs from other random SIGTRAPs: we keep this
12588 breakpoint location for a bit, and will retire it
12589 after we see some number of events. The theory here
12590 is that reporting of events should, "on the average",
12591 be fair, so after a while we'll see events from all
12592 threads that have anything of interest, and no longer
12593 need to keep this breakpoint location around. We
12594 don't hold locations forever so to reduce chances of
12595 mistaking a non-breakpoint SIGTRAP for a breakpoint
12598 The heuristic failing can be disastrous on
12599 decr_pc_after_break targets.
12601 On decr_pc_after_break targets, like e.g., x86-linux,
12602 if we fail to recognize a late breakpoint SIGTRAP,
12603 because events_till_retirement has reached 0 too
12604 soon, we'll fail to do the PC adjustment, and report
12605 a random SIGTRAP to the user. When the user resumes
12606 the inferior, it will most likely immediately crash
12607 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12608 corrupted, because of being resumed e.g., in the
12609 middle of a multi-byte instruction, or skipped a
12610 one-byte instruction. This was actually seen happen
12611 on native x86-linux, and should be less rare on
12612 targets that do not support new thread events, like
12613 remote, due to the heuristic depending on
12616 Mistaking a random SIGTRAP for a breakpoint trap
12617 causes similar symptoms (PC adjustment applied when
12618 it shouldn't), but then again, playing with SIGTRAPs
12619 behind the debugger's back is asking for trouble.
12621 Since hardware watchpoint traps are always
12622 distinguishable from other traps, so we don't need to
12623 apply keep hardware watchpoint moribund locations
12624 around. We simply always ignore hardware watchpoint
12625 traps we can no longer explain. */
12627 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12628 old_loc->owner = NULL;
12630 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12634 old_loc->owner = NULL;
12635 decref_bp_location (&old_loc);
12640 /* Rescan breakpoints at the same address and section, marking the
12641 first one as "first" and any others as "duplicates". This is so
12642 that the bpt instruction is only inserted once. If we have a
12643 permanent breakpoint at the same place as BPT, make that one the
12644 official one, and the rest as duplicates. Permanent breakpoints
12645 are sorted first for the same address.
12647 Do the same for hardware watchpoints, but also considering the
12648 watchpoint's type (regular/access/read) and length. */
12650 bp_loc_first = NULL;
12651 wp_loc_first = NULL;
12652 awp_loc_first = NULL;
12653 rwp_loc_first = NULL;
12654 ALL_BP_LOCATIONS (loc, locp)
12656 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12658 struct bp_location **loc_first_p;
12661 if (!unduplicated_should_be_inserted (loc)
12662 || !breakpoint_address_is_meaningful (b)
12663 /* Don't detect duplicate for tracepoint locations because they are
12664 never duplicated. See the comments in field `duplicate' of
12665 `struct bp_location'. */
12666 || is_tracepoint (b))
12668 /* Clear the condition modification flag. */
12669 loc->condition_changed = condition_unchanged;
12673 if (b->type == bp_hardware_watchpoint)
12674 loc_first_p = &wp_loc_first;
12675 else if (b->type == bp_read_watchpoint)
12676 loc_first_p = &rwp_loc_first;
12677 else if (b->type == bp_access_watchpoint)
12678 loc_first_p = &awp_loc_first;
12680 loc_first_p = &bp_loc_first;
12682 if (*loc_first_p == NULL
12683 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12684 || !breakpoint_locations_match (loc, *loc_first_p))
12686 *loc_first_p = loc;
12687 loc->duplicate = 0;
12689 if (is_breakpoint (loc->owner) && loc->condition_changed)
12691 loc->needs_update = 1;
12692 /* Clear the condition modification flag. */
12693 loc->condition_changed = condition_unchanged;
12699 /* This and the above ensure the invariant that the first location
12700 is not duplicated, and is the inserted one.
12701 All following are marked as duplicated, and are not inserted. */
12703 swap_insertion (loc, *loc_first_p);
12704 loc->duplicate = 1;
12706 /* Clear the condition modification flag. */
12707 loc->condition_changed = condition_unchanged;
12710 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12712 if (insert_mode != UGLL_DONT_INSERT)
12713 insert_breakpoint_locations ();
12716 /* Even though the caller told us to not insert new
12717 locations, we may still need to update conditions on the
12718 target's side of breakpoints that were already inserted
12719 if the target is evaluating breakpoint conditions. We
12720 only update conditions for locations that are marked
12722 update_inserted_breakpoint_locations ();
12726 if (insert_mode != UGLL_DONT_INSERT)
12727 download_tracepoint_locations ();
12729 do_cleanups (cleanups);
12733 breakpoint_retire_moribund (void)
12735 struct bp_location *loc;
12738 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12739 if (--(loc->events_till_retirement) == 0)
12741 decref_bp_location (&loc);
12742 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12748 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12753 update_global_location_list (insert_mode);
12755 CATCH (e, RETURN_MASK_ERROR)
12761 /* Clear BKP from a BPS. */
12764 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12768 for (bs = bps; bs; bs = bs->next)
12769 if (bs->breakpoint_at == bpt)
12771 bs->breakpoint_at = NULL;
12772 bs->old_val = NULL;
12773 /* bs->commands will be freed later. */
12777 /* Callback for iterate_over_threads. */
12779 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12781 struct breakpoint *bpt = (struct breakpoint *) data;
12783 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12787 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12791 say_where (struct breakpoint *b)
12793 struct value_print_options opts;
12795 get_user_print_options (&opts);
12797 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12799 if (b->loc == NULL)
12801 /* For pending locations, the output differs slightly based
12802 on b->extra_string. If this is non-NULL, it contains either
12803 a condition or dprintf arguments. */
12804 if (b->extra_string == NULL)
12806 printf_filtered (_(" (%s) pending."),
12807 event_location_to_string (b->location));
12809 else if (b->type == bp_dprintf)
12811 printf_filtered (_(" (%s,%s) pending."),
12812 event_location_to_string (b->location),
12817 printf_filtered (_(" (%s %s) pending."),
12818 event_location_to_string (b->location),
12824 if (opts.addressprint || b->loc->symtab == NULL)
12826 printf_filtered (" at ");
12827 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12830 if (b->loc->symtab != NULL)
12832 /* If there is a single location, we can print the location
12834 if (b->loc->next == NULL)
12835 printf_filtered (": file %s, line %d.",
12836 symtab_to_filename_for_display (b->loc->symtab),
12837 b->loc->line_number);
12839 /* This is not ideal, but each location may have a
12840 different file name, and this at least reflects the
12841 real situation somewhat. */
12842 printf_filtered (": %s.",
12843 event_location_to_string (b->location));
12848 struct bp_location *loc = b->loc;
12850 for (; loc; loc = loc->next)
12852 printf_filtered (" (%d locations)", n);
12857 /* Default bp_location_ops methods. */
12860 bp_location_dtor (struct bp_location *self)
12862 xfree (self->function_name);
12865 static const struct bp_location_ops bp_location_ops =
12870 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12874 base_breakpoint_dtor (struct breakpoint *self)
12876 decref_counted_command_line (&self->commands);
12877 xfree (self->cond_string);
12878 xfree (self->extra_string);
12879 xfree (self->filter);
12880 delete_event_location (self->location);
12881 delete_event_location (self->location_range_end);
12884 static struct bp_location *
12885 base_breakpoint_allocate_location (struct breakpoint *self)
12887 struct bp_location *loc;
12889 loc = new struct bp_location ();
12890 init_bp_location (loc, &bp_location_ops, self);
12895 base_breakpoint_re_set (struct breakpoint *b)
12897 /* Nothing to re-set. */
12900 #define internal_error_pure_virtual_called() \
12901 gdb_assert_not_reached ("pure virtual function called")
12904 base_breakpoint_insert_location (struct bp_location *bl)
12906 internal_error_pure_virtual_called ();
12910 base_breakpoint_remove_location (struct bp_location *bl,
12911 enum remove_bp_reason reason)
12913 internal_error_pure_virtual_called ();
12917 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12918 struct address_space *aspace,
12920 const struct target_waitstatus *ws)
12922 internal_error_pure_virtual_called ();
12926 base_breakpoint_check_status (bpstat bs)
12931 /* A "works_in_software_mode" breakpoint_ops method that just internal
12935 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12937 internal_error_pure_virtual_called ();
12940 /* A "resources_needed" breakpoint_ops method that just internal
12944 base_breakpoint_resources_needed (const struct bp_location *bl)
12946 internal_error_pure_virtual_called ();
12949 static enum print_stop_action
12950 base_breakpoint_print_it (bpstat bs)
12952 internal_error_pure_virtual_called ();
12956 base_breakpoint_print_one_detail (const struct breakpoint *self,
12957 struct ui_out *uiout)
12963 base_breakpoint_print_mention (struct breakpoint *b)
12965 internal_error_pure_virtual_called ();
12969 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12971 internal_error_pure_virtual_called ();
12975 base_breakpoint_create_sals_from_location
12976 (const struct event_location *location,
12977 struct linespec_result *canonical,
12978 enum bptype type_wanted)
12980 internal_error_pure_virtual_called ();
12984 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12985 struct linespec_result *c,
12987 char *extra_string,
12988 enum bptype type_wanted,
12989 enum bpdisp disposition,
12991 int task, int ignore_count,
12992 const struct breakpoint_ops *o,
12993 int from_tty, int enabled,
12994 int internal, unsigned flags)
12996 internal_error_pure_virtual_called ();
13000 base_breakpoint_decode_location (struct breakpoint *b,
13001 const struct event_location *location,
13002 struct program_space *search_pspace,
13003 struct symtabs_and_lines *sals)
13005 internal_error_pure_virtual_called ();
13008 /* The default 'explains_signal' method. */
13011 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13016 /* The default "after_condition_true" method. */
13019 base_breakpoint_after_condition_true (struct bpstats *bs)
13021 /* Nothing to do. */
13024 struct breakpoint_ops base_breakpoint_ops =
13026 base_breakpoint_dtor,
13027 base_breakpoint_allocate_location,
13028 base_breakpoint_re_set,
13029 base_breakpoint_insert_location,
13030 base_breakpoint_remove_location,
13031 base_breakpoint_breakpoint_hit,
13032 base_breakpoint_check_status,
13033 base_breakpoint_resources_needed,
13034 base_breakpoint_works_in_software_mode,
13035 base_breakpoint_print_it,
13037 base_breakpoint_print_one_detail,
13038 base_breakpoint_print_mention,
13039 base_breakpoint_print_recreate,
13040 base_breakpoint_create_sals_from_location,
13041 base_breakpoint_create_breakpoints_sal,
13042 base_breakpoint_decode_location,
13043 base_breakpoint_explains_signal,
13044 base_breakpoint_after_condition_true,
13047 /* Default breakpoint_ops methods. */
13050 bkpt_re_set (struct breakpoint *b)
13052 /* FIXME: is this still reachable? */
13053 if (breakpoint_event_location_empty_p (b))
13055 /* Anything without a location can't be re-set. */
13056 delete_breakpoint (b);
13060 breakpoint_re_set_default (b);
13064 bkpt_insert_location (struct bp_location *bl)
13066 CORE_ADDR addr = bl->target_info.reqstd_address;
13068 bl->target_info.kind = breakpoint_kind (bl, &addr);
13069 bl->target_info.placed_address = addr;
13071 if (bl->loc_type == bp_loc_hardware_breakpoint)
13072 return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
13074 return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
13078 bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason)
13080 if (bl->loc_type == bp_loc_hardware_breakpoint)
13081 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13083 return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason);
13087 bkpt_breakpoint_hit (const struct bp_location *bl,
13088 struct address_space *aspace, CORE_ADDR bp_addr,
13089 const struct target_waitstatus *ws)
13091 if (ws->kind != TARGET_WAITKIND_STOPPED
13092 || ws->value.sig != GDB_SIGNAL_TRAP)
13095 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13099 if (overlay_debugging /* unmapped overlay section */
13100 && section_is_overlay (bl->section)
13101 && !section_is_mapped (bl->section))
13108 dprintf_breakpoint_hit (const struct bp_location *bl,
13109 struct address_space *aspace, CORE_ADDR bp_addr,
13110 const struct target_waitstatus *ws)
13112 if (dprintf_style == dprintf_style_agent
13113 && target_can_run_breakpoint_commands ())
13115 /* An agent-style dprintf never causes a stop. If we see a trap
13116 for this address it must be for a breakpoint that happens to
13117 be set at the same address. */
13121 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13125 bkpt_resources_needed (const struct bp_location *bl)
13127 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13132 static enum print_stop_action
13133 bkpt_print_it (bpstat bs)
13135 struct breakpoint *b;
13136 const struct bp_location *bl;
13138 struct ui_out *uiout = current_uiout;
13140 gdb_assert (bs->bp_location_at != NULL);
13142 bl = bs->bp_location_at;
13143 b = bs->breakpoint_at;
13145 bp_temp = b->disposition == disp_del;
13146 if (bl->address != bl->requested_address)
13147 breakpoint_adjustment_warning (bl->requested_address,
13150 annotate_breakpoint (b->number);
13151 maybe_print_thread_hit_breakpoint (uiout);
13154 uiout->text ("Temporary breakpoint ");
13156 uiout->text ("Breakpoint ");
13157 if (uiout->is_mi_like_p ())
13159 uiout->field_string ("reason",
13160 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13161 uiout->field_string ("disp", bpdisp_text (b->disposition));
13163 uiout->field_int ("bkptno", b->number);
13164 uiout->text (", ");
13166 return PRINT_SRC_AND_LOC;
13170 bkpt_print_mention (struct breakpoint *b)
13172 if (current_uiout->is_mi_like_p ())
13177 case bp_breakpoint:
13178 case bp_gnu_ifunc_resolver:
13179 if (b->disposition == disp_del)
13180 printf_filtered (_("Temporary breakpoint"));
13182 printf_filtered (_("Breakpoint"));
13183 printf_filtered (_(" %d"), b->number);
13184 if (b->type == bp_gnu_ifunc_resolver)
13185 printf_filtered (_(" at gnu-indirect-function resolver"));
13187 case bp_hardware_breakpoint:
13188 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13191 printf_filtered (_("Dprintf %d"), b->number);
13199 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13201 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13202 fprintf_unfiltered (fp, "tbreak");
13203 else if (tp->type == bp_breakpoint)
13204 fprintf_unfiltered (fp, "break");
13205 else if (tp->type == bp_hardware_breakpoint
13206 && tp->disposition == disp_del)
13207 fprintf_unfiltered (fp, "thbreak");
13208 else if (tp->type == bp_hardware_breakpoint)
13209 fprintf_unfiltered (fp, "hbreak");
13211 internal_error (__FILE__, __LINE__,
13212 _("unhandled breakpoint type %d"), (int) tp->type);
13214 fprintf_unfiltered (fp, " %s",
13215 event_location_to_string (tp->location));
13217 /* Print out extra_string if this breakpoint is pending. It might
13218 contain, for example, conditions that were set by the user. */
13219 if (tp->loc == NULL && tp->extra_string != NULL)
13220 fprintf_unfiltered (fp, " %s", tp->extra_string);
13222 print_recreate_thread (tp, fp);
13226 bkpt_create_sals_from_location (const struct event_location *location,
13227 struct linespec_result *canonical,
13228 enum bptype type_wanted)
13230 create_sals_from_location_default (location, canonical, type_wanted);
13234 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13235 struct linespec_result *canonical,
13237 char *extra_string,
13238 enum bptype type_wanted,
13239 enum bpdisp disposition,
13241 int task, int ignore_count,
13242 const struct breakpoint_ops *ops,
13243 int from_tty, int enabled,
13244 int internal, unsigned flags)
13246 create_breakpoints_sal_default (gdbarch, canonical,
13247 cond_string, extra_string,
13249 disposition, thread, task,
13250 ignore_count, ops, from_tty,
13251 enabled, internal, flags);
13255 bkpt_decode_location (struct breakpoint *b,
13256 const struct event_location *location,
13257 struct program_space *search_pspace,
13258 struct symtabs_and_lines *sals)
13260 decode_location_default (b, location, search_pspace, sals);
13263 /* Virtual table for internal breakpoints. */
13266 internal_bkpt_re_set (struct breakpoint *b)
13270 /* Delete overlay event and longjmp master breakpoints; they
13271 will be reset later by breakpoint_re_set. */
13272 case bp_overlay_event:
13273 case bp_longjmp_master:
13274 case bp_std_terminate_master:
13275 case bp_exception_master:
13276 delete_breakpoint (b);
13279 /* This breakpoint is special, it's set up when the inferior
13280 starts and we really don't want to touch it. */
13281 case bp_shlib_event:
13283 /* Like bp_shlib_event, this breakpoint type is special. Once
13284 it is set up, we do not want to touch it. */
13285 case bp_thread_event:
13291 internal_bkpt_check_status (bpstat bs)
13293 if (bs->breakpoint_at->type == bp_shlib_event)
13295 /* If requested, stop when the dynamic linker notifies GDB of
13296 events. This allows the user to get control and place
13297 breakpoints in initializer routines for dynamically loaded
13298 objects (among other things). */
13299 bs->stop = stop_on_solib_events;
13300 bs->print = stop_on_solib_events;
13306 static enum print_stop_action
13307 internal_bkpt_print_it (bpstat bs)
13309 struct breakpoint *b;
13311 b = bs->breakpoint_at;
13315 case bp_shlib_event:
13316 /* Did we stop because the user set the stop_on_solib_events
13317 variable? (If so, we report this as a generic, "Stopped due
13318 to shlib event" message.) */
13319 print_solib_event (0);
13322 case bp_thread_event:
13323 /* Not sure how we will get here.
13324 GDB should not stop for these breakpoints. */
13325 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13328 case bp_overlay_event:
13329 /* By analogy with the thread event, GDB should not stop for these. */
13330 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13333 case bp_longjmp_master:
13334 /* These should never be enabled. */
13335 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13338 case bp_std_terminate_master:
13339 /* These should never be enabled. */
13340 printf_filtered (_("std::terminate Master Breakpoint: "
13341 "gdb should not stop!\n"));
13344 case bp_exception_master:
13345 /* These should never be enabled. */
13346 printf_filtered (_("Exception Master Breakpoint: "
13347 "gdb should not stop!\n"));
13351 return PRINT_NOTHING;
13355 internal_bkpt_print_mention (struct breakpoint *b)
13357 /* Nothing to mention. These breakpoints are internal. */
13360 /* Virtual table for momentary breakpoints */
13363 momentary_bkpt_re_set (struct breakpoint *b)
13365 /* Keep temporary breakpoints, which can be encountered when we step
13366 over a dlopen call and solib_add is resetting the breakpoints.
13367 Otherwise these should have been blown away via the cleanup chain
13368 or by breakpoint_init_inferior when we rerun the executable. */
13372 momentary_bkpt_check_status (bpstat bs)
13374 /* Nothing. The point of these breakpoints is causing a stop. */
13377 static enum print_stop_action
13378 momentary_bkpt_print_it (bpstat bs)
13380 return PRINT_UNKNOWN;
13384 momentary_bkpt_print_mention (struct breakpoint *b)
13386 /* Nothing to mention. These breakpoints are internal. */
13389 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13391 It gets cleared already on the removal of the first one of such placed
13392 breakpoints. This is OK as they get all removed altogether. */
13395 longjmp_bkpt_dtor (struct breakpoint *self)
13397 struct thread_info *tp = find_thread_global_id (self->thread);
13400 tp->initiating_frame = null_frame_id;
13402 momentary_breakpoint_ops.dtor (self);
13405 /* Specific methods for probe breakpoints. */
13408 bkpt_probe_insert_location (struct bp_location *bl)
13410 int v = bkpt_insert_location (bl);
13414 /* The insertion was successful, now let's set the probe's semaphore
13416 if (bl->probe.probe->pops->set_semaphore != NULL)
13417 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13426 bkpt_probe_remove_location (struct bp_location *bl,
13427 enum remove_bp_reason reason)
13429 /* Let's clear the semaphore before removing the location. */
13430 if (bl->probe.probe->pops->clear_semaphore != NULL)
13431 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13435 return bkpt_remove_location (bl, reason);
13439 bkpt_probe_create_sals_from_location (const struct event_location *location,
13440 struct linespec_result *canonical,
13441 enum bptype type_wanted)
13443 struct linespec_sals lsal;
13445 lsal.sals = parse_probes (location, NULL, canonical);
13446 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13447 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13451 bkpt_probe_decode_location (struct breakpoint *b,
13452 const struct event_location *location,
13453 struct program_space *search_pspace,
13454 struct symtabs_and_lines *sals)
13456 *sals = parse_probes (location, search_pspace, NULL);
13458 error (_("probe not found"));
13461 /* The breakpoint_ops structure to be used in tracepoints. */
13464 tracepoint_re_set (struct breakpoint *b)
13466 breakpoint_re_set_default (b);
13470 tracepoint_breakpoint_hit (const struct bp_location *bl,
13471 struct address_space *aspace, CORE_ADDR bp_addr,
13472 const struct target_waitstatus *ws)
13474 /* By definition, the inferior does not report stops at
13480 tracepoint_print_one_detail (const struct breakpoint *self,
13481 struct ui_out *uiout)
13483 struct tracepoint *tp = (struct tracepoint *) self;
13484 if (tp->static_trace_marker_id)
13486 gdb_assert (self->type == bp_static_tracepoint);
13488 uiout->text ("\tmarker id is ");
13489 uiout->field_string ("static-tracepoint-marker-string-id",
13490 tp->static_trace_marker_id);
13491 uiout->text ("\n");
13496 tracepoint_print_mention (struct breakpoint *b)
13498 if (current_uiout->is_mi_like_p ())
13503 case bp_tracepoint:
13504 printf_filtered (_("Tracepoint"));
13505 printf_filtered (_(" %d"), b->number);
13507 case bp_fast_tracepoint:
13508 printf_filtered (_("Fast tracepoint"));
13509 printf_filtered (_(" %d"), b->number);
13511 case bp_static_tracepoint:
13512 printf_filtered (_("Static tracepoint"));
13513 printf_filtered (_(" %d"), b->number);
13516 internal_error (__FILE__, __LINE__,
13517 _("unhandled tracepoint type %d"), (int) b->type);
13524 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13526 struct tracepoint *tp = (struct tracepoint *) self;
13528 if (self->type == bp_fast_tracepoint)
13529 fprintf_unfiltered (fp, "ftrace");
13530 else if (self->type == bp_static_tracepoint)
13531 fprintf_unfiltered (fp, "strace");
13532 else if (self->type == bp_tracepoint)
13533 fprintf_unfiltered (fp, "trace");
13535 internal_error (__FILE__, __LINE__,
13536 _("unhandled tracepoint type %d"), (int) self->type);
13538 fprintf_unfiltered (fp, " %s",
13539 event_location_to_string (self->location));
13540 print_recreate_thread (self, fp);
13542 if (tp->pass_count)
13543 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13547 tracepoint_create_sals_from_location (const struct event_location *location,
13548 struct linespec_result *canonical,
13549 enum bptype type_wanted)
13551 create_sals_from_location_default (location, canonical, type_wanted);
13555 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13556 struct linespec_result *canonical,
13558 char *extra_string,
13559 enum bptype type_wanted,
13560 enum bpdisp disposition,
13562 int task, int ignore_count,
13563 const struct breakpoint_ops *ops,
13564 int from_tty, int enabled,
13565 int internal, unsigned flags)
13567 create_breakpoints_sal_default (gdbarch, canonical,
13568 cond_string, extra_string,
13570 disposition, thread, task,
13571 ignore_count, ops, from_tty,
13572 enabled, internal, flags);
13576 tracepoint_decode_location (struct breakpoint *b,
13577 const struct event_location *location,
13578 struct program_space *search_pspace,
13579 struct symtabs_and_lines *sals)
13581 decode_location_default (b, location, search_pspace, sals);
13584 struct breakpoint_ops tracepoint_breakpoint_ops;
13586 /* The breakpoint_ops structure to be use on tracepoints placed in a
13590 tracepoint_probe_create_sals_from_location
13591 (const struct event_location *location,
13592 struct linespec_result *canonical,
13593 enum bptype type_wanted)
13595 /* We use the same method for breakpoint on probes. */
13596 bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
13600 tracepoint_probe_decode_location (struct breakpoint *b,
13601 const struct event_location *location,
13602 struct program_space *search_pspace,
13603 struct symtabs_and_lines *sals)
13605 /* We use the same method for breakpoint on probes. */
13606 bkpt_probe_decode_location (b, location, search_pspace, sals);
13609 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13611 /* Dprintf breakpoint_ops methods. */
13614 dprintf_re_set (struct breakpoint *b)
13616 breakpoint_re_set_default (b);
13618 /* extra_string should never be non-NULL for dprintf. */
13619 gdb_assert (b->extra_string != NULL);
13621 /* 1 - connect to target 1, that can run breakpoint commands.
13622 2 - create a dprintf, which resolves fine.
13623 3 - disconnect from target 1
13624 4 - connect to target 2, that can NOT run breakpoint commands.
13626 After steps #3/#4, you'll want the dprintf command list to
13627 be updated, because target 1 and 2 may well return different
13628 answers for target_can_run_breakpoint_commands().
13629 Given absence of finer grained resetting, we get to do
13630 it all the time. */
13631 if (b->extra_string != NULL)
13632 update_dprintf_command_list (b);
13635 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13638 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13640 fprintf_unfiltered (fp, "dprintf %s,%s",
13641 event_location_to_string (tp->location),
13643 print_recreate_thread (tp, fp);
13646 /* Implement the "after_condition_true" breakpoint_ops method for
13649 dprintf's are implemented with regular commands in their command
13650 list, but we run the commands here instead of before presenting the
13651 stop to the user, as dprintf's don't actually cause a stop. This
13652 also makes it so that the commands of multiple dprintfs at the same
13653 address are all handled. */
13656 dprintf_after_condition_true (struct bpstats *bs)
13658 struct cleanup *old_chain;
13659 struct bpstats tmp_bs = { NULL };
13660 struct bpstats *tmp_bs_p = &tmp_bs;
13662 /* dprintf's never cause a stop. This wasn't set in the
13663 check_status hook instead because that would make the dprintf's
13664 condition not be evaluated. */
13667 /* Run the command list here. Take ownership of it instead of
13668 copying. We never want these commands to run later in
13669 bpstat_do_actions, if a breakpoint that causes a stop happens to
13670 be set at same address as this dprintf, or even if running the
13671 commands here throws. */
13672 tmp_bs.commands = bs->commands;
13673 bs->commands = NULL;
13674 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13676 bpstat_do_actions_1 (&tmp_bs_p);
13678 /* 'tmp_bs.commands' will usually be NULL by now, but
13679 bpstat_do_actions_1 may return early without processing the whole
13681 do_cleanups (old_chain);
13684 /* The breakpoint_ops structure to be used on static tracepoints with
13688 strace_marker_create_sals_from_location (const struct event_location *location,
13689 struct linespec_result *canonical,
13690 enum bptype type_wanted)
13692 struct linespec_sals lsal;
13693 const char *arg_start, *arg;
13695 struct cleanup *cleanup;
13697 arg = arg_start = get_linespec_location (location);
13698 lsal.sals = decode_static_tracepoint_spec (&arg);
13700 str = savestring (arg_start, arg - arg_start);
13701 cleanup = make_cleanup (xfree, str);
13702 canonical->location = new_linespec_location (&str);
13703 do_cleanups (cleanup);
13705 lsal.canonical = xstrdup (event_location_to_string (canonical->location));
13706 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13710 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13711 struct linespec_result *canonical,
13713 char *extra_string,
13714 enum bptype type_wanted,
13715 enum bpdisp disposition,
13717 int task, int ignore_count,
13718 const struct breakpoint_ops *ops,
13719 int from_tty, int enabled,
13720 int internal, unsigned flags)
13723 struct linespec_sals *lsal = VEC_index (linespec_sals,
13724 canonical->sals, 0);
13726 /* If the user is creating a static tracepoint by marker id
13727 (strace -m MARKER_ID), then store the sals index, so that
13728 breakpoint_re_set can try to match up which of the newly
13729 found markers corresponds to this one, and, don't try to
13730 expand multiple locations for each sal, given than SALS
13731 already should contain all sals for MARKER_ID. */
13733 for (i = 0; i < lsal->sals.nelts; ++i)
13735 struct symtabs_and_lines expanded;
13736 struct tracepoint *tp;
13737 struct cleanup *old_chain;
13738 struct event_location *location;
13740 expanded.nelts = 1;
13741 expanded.sals = &lsal->sals.sals[i];
13743 location = copy_event_location (canonical->location);
13744 old_chain = make_cleanup_delete_event_location (location);
13746 tp = new tracepoint ();
13747 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13749 cond_string, extra_string,
13750 type_wanted, disposition,
13751 thread, task, ignore_count, ops,
13752 from_tty, enabled, internal, flags,
13753 canonical->special_display);
13754 /* Given that its possible to have multiple markers with
13755 the same string id, if the user is creating a static
13756 tracepoint by marker id ("strace -m MARKER_ID"), then
13757 store the sals index, so that breakpoint_re_set can
13758 try to match up which of the newly found markers
13759 corresponds to this one */
13760 tp->static_trace_marker_id_idx = i;
13762 install_breakpoint (internal, &tp->base, 0);
13764 discard_cleanups (old_chain);
13769 strace_marker_decode_location (struct breakpoint *b,
13770 const struct event_location *location,
13771 struct program_space *search_pspace,
13772 struct symtabs_and_lines *sals)
13774 struct tracepoint *tp = (struct tracepoint *) b;
13775 const char *s = get_linespec_location (location);
13777 *sals = decode_static_tracepoint_spec (&s);
13778 if (sals->nelts > tp->static_trace_marker_id_idx)
13780 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13784 error (_("marker %s not found"), tp->static_trace_marker_id);
13787 static struct breakpoint_ops strace_marker_breakpoint_ops;
13790 strace_marker_p (struct breakpoint *b)
13792 return b->ops == &strace_marker_breakpoint_ops;
13795 /* Delete a breakpoint and clean up all traces of it in the data
13799 delete_breakpoint (struct breakpoint *bpt)
13801 struct breakpoint *b;
13803 gdb_assert (bpt != NULL);
13805 /* Has this bp already been deleted? This can happen because
13806 multiple lists can hold pointers to bp's. bpstat lists are
13809 One example of this happening is a watchpoint's scope bp. When
13810 the scope bp triggers, we notice that the watchpoint is out of
13811 scope, and delete it. We also delete its scope bp. But the
13812 scope bp is marked "auto-deleting", and is already on a bpstat.
13813 That bpstat is then checked for auto-deleting bp's, which are
13816 A real solution to this problem might involve reference counts in
13817 bp's, and/or giving them pointers back to their referencing
13818 bpstat's, and teaching delete_breakpoint to only free a bp's
13819 storage when no more references were extent. A cheaper bandaid
13821 if (bpt->type == bp_none)
13824 /* At least avoid this stale reference until the reference counting
13825 of breakpoints gets resolved. */
13826 if (bpt->related_breakpoint != bpt)
13828 struct breakpoint *related;
13829 struct watchpoint *w;
13831 if (bpt->type == bp_watchpoint_scope)
13832 w = (struct watchpoint *) bpt->related_breakpoint;
13833 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13834 w = (struct watchpoint *) bpt;
13838 watchpoint_del_at_next_stop (w);
13840 /* Unlink bpt from the bpt->related_breakpoint ring. */
13841 for (related = bpt; related->related_breakpoint != bpt;
13842 related = related->related_breakpoint);
13843 related->related_breakpoint = bpt->related_breakpoint;
13844 bpt->related_breakpoint = bpt;
13847 /* watch_command_1 creates a watchpoint but only sets its number if
13848 update_watchpoint succeeds in creating its bp_locations. If there's
13849 a problem in that process, we'll be asked to delete the half-created
13850 watchpoint. In that case, don't announce the deletion. */
13852 observer_notify_breakpoint_deleted (bpt);
13854 if (breakpoint_chain == bpt)
13855 breakpoint_chain = bpt->next;
13857 ALL_BREAKPOINTS (b)
13858 if (b->next == bpt)
13860 b->next = bpt->next;
13864 /* Be sure no bpstat's are pointing at the breakpoint after it's
13866 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13867 in all threads for now. Note that we cannot just remove bpstats
13868 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13869 commands are associated with the bpstat; if we remove it here,
13870 then the later call to bpstat_do_actions (&stop_bpstat); in
13871 event-top.c won't do anything, and temporary breakpoints with
13872 commands won't work. */
13874 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13876 /* Now that breakpoint is removed from breakpoint list, update the
13877 global location list. This will remove locations that used to
13878 belong to this breakpoint. Do this before freeing the breakpoint
13879 itself, since remove_breakpoint looks at location's owner. It
13880 might be better design to have location completely
13881 self-contained, but it's not the case now. */
13882 update_global_location_list (UGLL_DONT_INSERT);
13884 bpt->ops->dtor (bpt);
13885 /* On the chance that someone will soon try again to delete this
13886 same bp, we mark it as deleted before freeing its storage. */
13887 bpt->type = bp_none;
13892 do_delete_breakpoint_cleanup (void *b)
13894 delete_breakpoint ((struct breakpoint *) b);
13898 make_cleanup_delete_breakpoint (struct breakpoint *b)
13900 return make_cleanup (do_delete_breakpoint_cleanup, b);
13903 /* Iterator function to call a user-provided callback function once
13904 for each of B and its related breakpoints. */
13907 iterate_over_related_breakpoints (struct breakpoint *b,
13908 void (*function) (struct breakpoint *,
13912 struct breakpoint *related;
13917 struct breakpoint *next;
13919 /* FUNCTION may delete RELATED. */
13920 next = related->related_breakpoint;
13922 if (next == related)
13924 /* RELATED is the last ring entry. */
13925 function (related, data);
13927 /* FUNCTION may have deleted it, so we'd never reach back to
13928 B. There's nothing left to do anyway, so just break
13933 function (related, data);
13937 while (related != b);
13941 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13943 delete_breakpoint (b);
13946 /* A callback for map_breakpoint_numbers that calls
13947 delete_breakpoint. */
13950 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13952 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13956 delete_command (char *arg, int from_tty)
13958 struct breakpoint *b, *b_tmp;
13964 int breaks_to_delete = 0;
13966 /* Delete all breakpoints if no argument. Do not delete
13967 internal breakpoints, these have to be deleted with an
13968 explicit breakpoint number argument. */
13969 ALL_BREAKPOINTS (b)
13970 if (user_breakpoint_p (b))
13972 breaks_to_delete = 1;
13976 /* Ask user only if there are some breakpoints to delete. */
13978 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13980 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13981 if (user_breakpoint_p (b))
13982 delete_breakpoint (b);
13986 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13989 /* Return true if all locations of B bound to PSPACE are pending. If
13990 PSPACE is NULL, all locations of all program spaces are
13994 all_locations_are_pending (struct breakpoint *b, struct program_space *pspace)
13996 struct bp_location *loc;
13998 for (loc = b->loc; loc != NULL; loc = loc->next)
13999 if ((pspace == NULL
14000 || loc->pspace == pspace)
14001 && !loc->shlib_disabled
14002 && !loc->pspace->executing_startup)
14007 /* Subroutine of update_breakpoint_locations to simplify it.
14008 Return non-zero if multiple fns in list LOC have the same name.
14009 Null names are ignored. */
14012 ambiguous_names_p (struct bp_location *loc)
14014 struct bp_location *l;
14015 htab_t htab = htab_create_alloc (13, htab_hash_string,
14016 (int (*) (const void *,
14017 const void *)) streq,
14018 NULL, xcalloc, xfree);
14020 for (l = loc; l != NULL; l = l->next)
14023 const char *name = l->function_name;
14025 /* Allow for some names to be NULL, ignore them. */
14029 slot = (const char **) htab_find_slot (htab, (const void *) name,
14031 /* NOTE: We can assume slot != NULL here because xcalloc never
14035 htab_delete (htab);
14041 htab_delete (htab);
14045 /* When symbols change, it probably means the sources changed as well,
14046 and it might mean the static tracepoint markers are no longer at
14047 the same address or line numbers they used to be at last we
14048 checked. Losing your static tracepoints whenever you rebuild is
14049 undesirable. This function tries to resync/rematch gdb static
14050 tracepoints with the markers on the target, for static tracepoints
14051 that have not been set by marker id. Static tracepoint that have
14052 been set by marker id are reset by marker id in breakpoint_re_set.
14055 1) For a tracepoint set at a specific address, look for a marker at
14056 the old PC. If one is found there, assume to be the same marker.
14057 If the name / string id of the marker found is different from the
14058 previous known name, assume that means the user renamed the marker
14059 in the sources, and output a warning.
14061 2) For a tracepoint set at a given line number, look for a marker
14062 at the new address of the old line number. If one is found there,
14063 assume to be the same marker. If the name / string id of the
14064 marker found is different from the previous known name, assume that
14065 means the user renamed the marker in the sources, and output a
14068 3) If a marker is no longer found at the same address or line, it
14069 may mean the marker no longer exists. But it may also just mean
14070 the code changed a bit. Maybe the user added a few lines of code
14071 that made the marker move up or down (in line number terms). Ask
14072 the target for info about the marker with the string id as we knew
14073 it. If found, update line number and address in the matching
14074 static tracepoint. This will get confused if there's more than one
14075 marker with the same ID (possible in UST, although unadvised
14076 precisely because it confuses tools). */
14078 static struct symtab_and_line
14079 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14081 struct tracepoint *tp = (struct tracepoint *) b;
14082 struct static_tracepoint_marker marker;
14087 find_line_pc (sal.symtab, sal.line, &pc);
14089 if (target_static_tracepoint_marker_at (pc, &marker))
14091 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14092 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14094 tp->static_trace_marker_id, marker.str_id);
14096 xfree (tp->static_trace_marker_id);
14097 tp->static_trace_marker_id = xstrdup (marker.str_id);
14098 release_static_tracepoint_marker (&marker);
14103 /* Old marker wasn't found on target at lineno. Try looking it up
14105 if (!sal.explicit_pc
14107 && sal.symtab != NULL
14108 && tp->static_trace_marker_id != NULL)
14110 VEC(static_tracepoint_marker_p) *markers;
14113 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14115 if (!VEC_empty(static_tracepoint_marker_p, markers))
14117 struct symtab_and_line sal2;
14118 struct symbol *sym;
14119 struct static_tracepoint_marker *tpmarker;
14120 struct ui_out *uiout = current_uiout;
14121 struct explicit_location explicit_loc;
14123 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14125 xfree (tp->static_trace_marker_id);
14126 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14128 warning (_("marker for static tracepoint %d (%s) not "
14129 "found at previous line number"),
14130 b->number, tp->static_trace_marker_id);
14134 sal2.pc = tpmarker->address;
14136 sal2 = find_pc_line (tpmarker->address, 0);
14137 sym = find_pc_sect_function (tpmarker->address, NULL);
14138 uiout->text ("Now in ");
14141 uiout->field_string ("func", SYMBOL_PRINT_NAME (sym));
14142 uiout->text (" at ");
14144 uiout->field_string ("file",
14145 symtab_to_filename_for_display (sal2.symtab));
14148 if (uiout->is_mi_like_p ())
14150 const char *fullname = symtab_to_fullname (sal2.symtab);
14152 uiout->field_string ("fullname", fullname);
14155 uiout->field_int ("line", sal2.line);
14156 uiout->text ("\n");
14158 b->loc->line_number = sal2.line;
14159 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14161 delete_event_location (b->location);
14162 initialize_explicit_location (&explicit_loc);
14163 explicit_loc.source_filename
14164 = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
14165 explicit_loc.line_offset.offset = b->loc->line_number;
14166 explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
14167 b->location = new_explicit_location (&explicit_loc);
14169 /* Might be nice to check if function changed, and warn if
14172 release_static_tracepoint_marker (tpmarker);
14178 /* Returns 1 iff locations A and B are sufficiently same that
14179 we don't need to report breakpoint as changed. */
14182 locations_are_equal (struct bp_location *a, struct bp_location *b)
14186 if (a->address != b->address)
14189 if (a->shlib_disabled != b->shlib_disabled)
14192 if (a->enabled != b->enabled)
14199 if ((a == NULL) != (b == NULL))
14205 /* Split all locations of B that are bound to PSPACE out of B's
14206 location list to a separate list and return that list's head. If
14207 PSPACE is NULL, hoist out all locations of B. */
14209 static struct bp_location *
14210 hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
14212 struct bp_location head;
14213 struct bp_location *i = b->loc;
14214 struct bp_location **i_link = &b->loc;
14215 struct bp_location *hoisted = &head;
14217 if (pspace == NULL)
14228 if (i->pspace == pspace)
14243 /* Create new breakpoint locations for B (a hardware or software
14244 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
14245 zero, then B is a ranged breakpoint. Only recreates locations for
14246 FILTER_PSPACE. Locations of other program spaces are left
14250 update_breakpoint_locations (struct breakpoint *b,
14251 struct program_space *filter_pspace,
14252 struct symtabs_and_lines sals,
14253 struct symtabs_and_lines sals_end)
14256 struct bp_location *existing_locations;
14258 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14260 /* Ranged breakpoints have only one start location and one end
14262 b->enable_state = bp_disabled;
14263 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14264 "multiple locations found\n"),
14269 /* If there's no new locations, and all existing locations are
14270 pending, don't do anything. This optimizes the common case where
14271 all locations are in the same shared library, that was unloaded.
14272 We'd like to retain the location, so that when the library is
14273 loaded again, we don't loose the enabled/disabled status of the
14274 individual locations. */
14275 if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0)
14278 existing_locations = hoist_existing_locations (b, filter_pspace);
14280 for (i = 0; i < sals.nelts; ++i)
14282 struct bp_location *new_loc;
14284 switch_to_program_space_and_thread (sals.sals[i].pspace);
14286 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14288 /* Reparse conditions, they might contain references to the
14290 if (b->cond_string != NULL)
14294 s = b->cond_string;
14297 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14298 block_for_pc (sals.sals[i].pc),
14301 CATCH (e, RETURN_MASK_ERROR)
14303 warning (_("failed to reevaluate condition "
14304 "for breakpoint %d: %s"),
14305 b->number, e.message);
14306 new_loc->enabled = 0;
14311 if (sals_end.nelts)
14313 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14315 new_loc->length = end - sals.sals[0].pc + 1;
14319 /* If possible, carry over 'disable' status from existing
14322 struct bp_location *e = existing_locations;
14323 /* If there are multiple breakpoints with the same function name,
14324 e.g. for inline functions, comparing function names won't work.
14325 Instead compare pc addresses; this is just a heuristic as things
14326 may have moved, but in practice it gives the correct answer
14327 often enough until a better solution is found. */
14328 int have_ambiguous_names = ambiguous_names_p (b->loc);
14330 for (; e; e = e->next)
14332 if (!e->enabled && e->function_name)
14334 struct bp_location *l = b->loc;
14335 if (have_ambiguous_names)
14337 for (; l; l = l->next)
14338 if (breakpoint_locations_match (e, l))
14346 for (; l; l = l->next)
14347 if (l->function_name
14348 && strcmp (e->function_name, l->function_name) == 0)
14358 if (!locations_are_equal (existing_locations, b->loc))
14359 observer_notify_breakpoint_modified (b);
14362 /* Find the SaL locations corresponding to the given LOCATION.
14363 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14365 static struct symtabs_and_lines
14366 location_to_sals (struct breakpoint *b, struct event_location *location,
14367 struct program_space *search_pspace, int *found)
14369 struct symtabs_and_lines sals = {0};
14370 struct gdb_exception exception = exception_none;
14372 gdb_assert (b->ops != NULL);
14376 b->ops->decode_location (b, location, search_pspace, &sals);
14378 CATCH (e, RETURN_MASK_ERROR)
14380 int not_found_and_ok = 0;
14384 /* For pending breakpoints, it's expected that parsing will
14385 fail until the right shared library is loaded. User has
14386 already told to create pending breakpoints and don't need
14387 extra messages. If breakpoint is in bp_shlib_disabled
14388 state, then user already saw the message about that
14389 breakpoint being disabled, and don't want to see more
14391 if (e.error == NOT_FOUND_ERROR
14392 && (b->condition_not_parsed
14394 && search_pspace != NULL
14395 && b->loc->pspace != search_pspace)
14396 || (b->loc && b->loc->shlib_disabled)
14397 || (b->loc && b->loc->pspace->executing_startup)
14398 || b->enable_state == bp_disabled))
14399 not_found_and_ok = 1;
14401 if (!not_found_and_ok)
14403 /* We surely don't want to warn about the same breakpoint
14404 10 times. One solution, implemented here, is disable
14405 the breakpoint on error. Another solution would be to
14406 have separate 'warning emitted' flag. Since this
14407 happens only when a binary has changed, I don't know
14408 which approach is better. */
14409 b->enable_state = bp_disabled;
14410 throw_exception (e);
14415 if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
14419 for (i = 0; i < sals.nelts; ++i)
14420 resolve_sal_pc (&sals.sals[i]);
14421 if (b->condition_not_parsed && b->extra_string != NULL)
14423 char *cond_string, *extra_string;
14426 find_condition_and_thread (b->extra_string, sals.sals[0].pc,
14427 &cond_string, &thread, &task,
14429 gdb_assert (b->cond_string == NULL);
14431 b->cond_string = cond_string;
14432 b->thread = thread;
14436 xfree (b->extra_string);
14437 b->extra_string = extra_string;
14439 b->condition_not_parsed = 0;
14442 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14443 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14453 /* The default re_set method, for typical hardware or software
14454 breakpoints. Reevaluate the breakpoint and recreate its
14458 breakpoint_re_set_default (struct breakpoint *b)
14461 struct symtabs_and_lines sals, sals_end;
14462 struct symtabs_and_lines expanded = {0};
14463 struct symtabs_and_lines expanded_end = {0};
14464 struct program_space *filter_pspace = current_program_space;
14466 sals = location_to_sals (b, b->location, filter_pspace, &found);
14469 make_cleanup (xfree, sals.sals);
14473 if (b->location_range_end != NULL)
14475 sals_end = location_to_sals (b, b->location_range_end,
14476 filter_pspace, &found);
14479 make_cleanup (xfree, sals_end.sals);
14480 expanded_end = sals_end;
14484 update_breakpoint_locations (b, filter_pspace, expanded, expanded_end);
14487 /* Default method for creating SALs from an address string. It basically
14488 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14491 create_sals_from_location_default (const struct event_location *location,
14492 struct linespec_result *canonical,
14493 enum bptype type_wanted)
14495 parse_breakpoint_sals (location, canonical);
14498 /* Call create_breakpoints_sal for the given arguments. This is the default
14499 function for the `create_breakpoints_sal' method of
14503 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14504 struct linespec_result *canonical,
14506 char *extra_string,
14507 enum bptype type_wanted,
14508 enum bpdisp disposition,
14510 int task, int ignore_count,
14511 const struct breakpoint_ops *ops,
14512 int from_tty, int enabled,
14513 int internal, unsigned flags)
14515 create_breakpoints_sal (gdbarch, canonical, cond_string,
14517 type_wanted, disposition,
14518 thread, task, ignore_count, ops, from_tty,
14519 enabled, internal, flags);
14522 /* Decode the line represented by S by calling decode_line_full. This is the
14523 default function for the `decode_location' method of breakpoint_ops. */
14526 decode_location_default (struct breakpoint *b,
14527 const struct event_location *location,
14528 struct program_space *search_pspace,
14529 struct symtabs_and_lines *sals)
14531 struct linespec_result canonical;
14533 init_linespec_result (&canonical);
14534 decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
14535 (struct symtab *) NULL, 0,
14536 &canonical, multiple_symbols_all,
14539 /* We should get 0 or 1 resulting SALs. */
14540 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14542 if (VEC_length (linespec_sals, canonical.sals) > 0)
14544 struct linespec_sals *lsal;
14546 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14547 *sals = lsal->sals;
14548 /* Arrange it so the destructor does not free the
14550 lsal->sals.sals = NULL;
14553 destroy_linespec_result (&canonical);
14556 /* Prepare the global context for a re-set of breakpoint B. */
14558 static struct cleanup *
14559 prepare_re_set_context (struct breakpoint *b)
14561 input_radix = b->input_radix;
14562 set_language (b->language);
14564 return make_cleanup (null_cleanup, NULL);
14567 /* Reset a breakpoint given it's struct breakpoint * BINT.
14568 The value we return ends up being the return value from catch_errors.
14569 Unused in this case. */
14572 breakpoint_re_set_one (void *bint)
14574 /* Get past catch_errs. */
14575 struct breakpoint *b = (struct breakpoint *) bint;
14576 struct cleanup *cleanups;
14578 cleanups = prepare_re_set_context (b);
14579 b->ops->re_set (b);
14580 do_cleanups (cleanups);
14584 /* Re-set breakpoint locations for the current program space.
14585 Locations bound to other program spaces are left untouched. */
14588 breakpoint_re_set (void)
14590 struct breakpoint *b, *b_tmp;
14591 enum language save_language;
14592 int save_input_radix;
14593 struct cleanup *old_chain;
14595 save_language = current_language->la_language;
14596 save_input_radix = input_radix;
14597 old_chain = save_current_space_and_thread ();
14599 /* Note: we must not try to insert locations until after all
14600 breakpoints have been re-set. Otherwise, e.g., when re-setting
14601 breakpoint 1, we'd insert the locations of breakpoint 2, which
14602 hadn't been re-set yet, and thus may have stale locations. */
14604 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14606 /* Format possible error msg. */
14607 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14609 struct cleanup *cleanups = make_cleanup (xfree, message);
14610 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14611 do_cleanups (cleanups);
14613 set_language (save_language);
14614 input_radix = save_input_radix;
14616 jit_breakpoint_re_set ();
14618 do_cleanups (old_chain);
14620 create_overlay_event_breakpoint ();
14621 create_longjmp_master_breakpoint ();
14622 create_std_terminate_master_breakpoint ();
14623 create_exception_master_breakpoint ();
14625 /* Now we can insert. */
14626 update_global_location_list (UGLL_MAY_INSERT);
14629 /* Reset the thread number of this breakpoint:
14631 - If the breakpoint is for all threads, leave it as-is.
14632 - Else, reset it to the current thread for inferior_ptid. */
14634 breakpoint_re_set_thread (struct breakpoint *b)
14636 if (b->thread != -1)
14638 if (in_thread_list (inferior_ptid))
14639 b->thread = ptid_to_global_thread_id (inferior_ptid);
14641 /* We're being called after following a fork. The new fork is
14642 selected as current, and unless this was a vfork will have a
14643 different program space from the original thread. Reset that
14645 b->loc->pspace = current_program_space;
14649 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14650 If from_tty is nonzero, it prints a message to that effect,
14651 which ends with a period (no newline). */
14654 set_ignore_count (int bptnum, int count, int from_tty)
14656 struct breakpoint *b;
14661 ALL_BREAKPOINTS (b)
14662 if (b->number == bptnum)
14664 if (is_tracepoint (b))
14666 if (from_tty && count != 0)
14667 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14672 b->ignore_count = count;
14676 printf_filtered (_("Will stop next time "
14677 "breakpoint %d is reached."),
14679 else if (count == 1)
14680 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14683 printf_filtered (_("Will ignore next %d "
14684 "crossings of breakpoint %d."),
14687 observer_notify_breakpoint_modified (b);
14691 error (_("No breakpoint number %d."), bptnum);
14694 /* Command to set ignore-count of breakpoint N to COUNT. */
14697 ignore_command (char *args, int from_tty)
14703 error_no_arg (_("a breakpoint number"));
14705 num = get_number (&p);
14707 error (_("bad breakpoint number: '%s'"), args);
14709 error (_("Second argument (specified ignore-count) is missing."));
14711 set_ignore_count (num,
14712 longest_to_int (value_as_long (parse_and_eval (p))),
14715 printf_filtered ("\n");
14718 /* Call FUNCTION on each of the breakpoints
14719 whose numbers are given in ARGS. */
14722 map_breakpoint_numbers (const char *args,
14723 void (*function) (struct breakpoint *,
14728 struct breakpoint *b, *tmp;
14730 if (args == 0 || *args == '\0')
14731 error_no_arg (_("one or more breakpoint numbers"));
14733 number_or_range_parser parser (args);
14735 while (!parser.finished ())
14737 const char *p = parser.cur_tok ();
14738 bool match = false;
14740 num = parser.get_number ();
14743 warning (_("bad breakpoint number at or near '%s'"), p);
14747 ALL_BREAKPOINTS_SAFE (b, tmp)
14748 if (b->number == num)
14751 function (b, data);
14755 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14760 static struct bp_location *
14761 find_location_by_number (char *number)
14763 char *dot = strchr (number, '.');
14767 struct breakpoint *b;
14768 struct bp_location *loc;
14773 bp_num = get_number (&p1);
14775 error (_("Bad breakpoint number '%s'"), number);
14777 ALL_BREAKPOINTS (b)
14778 if (b->number == bp_num)
14783 if (!b || b->number != bp_num)
14784 error (_("Bad breakpoint number '%s'"), number);
14787 loc_num = get_number (&p1);
14789 error (_("Bad breakpoint location number '%s'"), number);
14793 for (;loc_num && loc; --loc_num, loc = loc->next)
14796 error (_("Bad breakpoint location number '%s'"), dot+1);
14802 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14803 If from_tty is nonzero, it prints a message to that effect,
14804 which ends with a period (no newline). */
14807 disable_breakpoint (struct breakpoint *bpt)
14809 /* Never disable a watchpoint scope breakpoint; we want to
14810 hit them when we leave scope so we can delete both the
14811 watchpoint and its scope breakpoint at that time. */
14812 if (bpt->type == bp_watchpoint_scope)
14815 bpt->enable_state = bp_disabled;
14817 /* Mark breakpoint locations modified. */
14818 mark_breakpoint_modified (bpt);
14820 if (target_supports_enable_disable_tracepoint ()
14821 && current_trace_status ()->running && is_tracepoint (bpt))
14823 struct bp_location *location;
14825 for (location = bpt->loc; location; location = location->next)
14826 target_disable_tracepoint (location);
14829 update_global_location_list (UGLL_DONT_INSERT);
14831 observer_notify_breakpoint_modified (bpt);
14834 /* A callback for iterate_over_related_breakpoints. */
14837 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14839 disable_breakpoint (b);
14842 /* A callback for map_breakpoint_numbers that calls
14843 disable_breakpoint. */
14846 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14848 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14852 disable_command (char *args, int from_tty)
14856 struct breakpoint *bpt;
14858 ALL_BREAKPOINTS (bpt)
14859 if (user_breakpoint_p (bpt))
14860 disable_breakpoint (bpt);
14864 char *num = extract_arg (&args);
14868 if (strchr (num, '.'))
14870 struct bp_location *loc = find_location_by_number (num);
14877 mark_breakpoint_location_modified (loc);
14879 if (target_supports_enable_disable_tracepoint ()
14880 && current_trace_status ()->running && loc->owner
14881 && is_tracepoint (loc->owner))
14882 target_disable_tracepoint (loc);
14884 update_global_location_list (UGLL_DONT_INSERT);
14887 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
14888 num = extract_arg (&args);
14894 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14897 int target_resources_ok;
14899 if (bpt->type == bp_hardware_breakpoint)
14902 i = hw_breakpoint_used_count ();
14903 target_resources_ok =
14904 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14906 if (target_resources_ok == 0)
14907 error (_("No hardware breakpoint support in the target."));
14908 else if (target_resources_ok < 0)
14909 error (_("Hardware breakpoints used exceeds limit."));
14912 if (is_watchpoint (bpt))
14914 /* Initialize it just to avoid a GCC false warning. */
14915 enum enable_state orig_enable_state = bp_disabled;
14919 struct watchpoint *w = (struct watchpoint *) bpt;
14921 orig_enable_state = bpt->enable_state;
14922 bpt->enable_state = bp_enabled;
14923 update_watchpoint (w, 1 /* reparse */);
14925 CATCH (e, RETURN_MASK_ALL)
14927 bpt->enable_state = orig_enable_state;
14928 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14935 bpt->enable_state = bp_enabled;
14937 /* Mark breakpoint locations modified. */
14938 mark_breakpoint_modified (bpt);
14940 if (target_supports_enable_disable_tracepoint ()
14941 && current_trace_status ()->running && is_tracepoint (bpt))
14943 struct bp_location *location;
14945 for (location = bpt->loc; location; location = location->next)
14946 target_enable_tracepoint (location);
14949 bpt->disposition = disposition;
14950 bpt->enable_count = count;
14951 update_global_location_list (UGLL_MAY_INSERT);
14953 observer_notify_breakpoint_modified (bpt);
14958 enable_breakpoint (struct breakpoint *bpt)
14960 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14964 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14966 enable_breakpoint (bpt);
14969 /* A callback for map_breakpoint_numbers that calls
14970 enable_breakpoint. */
14973 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14975 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14978 /* The enable command enables the specified breakpoints (or all defined
14979 breakpoints) so they once again become (or continue to be) effective
14980 in stopping the inferior. */
14983 enable_command (char *args, int from_tty)
14987 struct breakpoint *bpt;
14989 ALL_BREAKPOINTS (bpt)
14990 if (user_breakpoint_p (bpt))
14991 enable_breakpoint (bpt);
14995 char *num = extract_arg (&args);
14999 if (strchr (num, '.'))
15001 struct bp_location *loc = find_location_by_number (num);
15008 mark_breakpoint_location_modified (loc);
15010 if (target_supports_enable_disable_tracepoint ()
15011 && current_trace_status ()->running && loc->owner
15012 && is_tracepoint (loc->owner))
15013 target_enable_tracepoint (loc);
15015 update_global_location_list (UGLL_MAY_INSERT);
15018 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15019 num = extract_arg (&args);
15024 /* This struct packages up disposition data for application to multiple
15034 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15036 struct disp_data disp_data = *(struct disp_data *) arg;
15038 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15042 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15044 struct disp_data disp = { disp_disable, 1 };
15046 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15050 enable_once_command (char *args, int from_tty)
15052 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15056 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15058 struct disp_data disp = { disp_disable, *(int *) countptr };
15060 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15064 enable_count_command (char *args, int from_tty)
15069 error_no_arg (_("hit count"));
15071 count = get_number (&args);
15073 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15077 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15079 struct disp_data disp = { disp_del, 1 };
15081 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15085 enable_delete_command (char *args, int from_tty)
15087 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15091 set_breakpoint_cmd (char *args, int from_tty)
15096 show_breakpoint_cmd (char *args, int from_tty)
15100 /* Invalidate last known value of any hardware watchpoint if
15101 the memory which that value represents has been written to by
15105 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15106 CORE_ADDR addr, ssize_t len,
15107 const bfd_byte *data)
15109 struct breakpoint *bp;
15111 ALL_BREAKPOINTS (bp)
15112 if (bp->enable_state == bp_enabled
15113 && bp->type == bp_hardware_watchpoint)
15115 struct watchpoint *wp = (struct watchpoint *) bp;
15117 if (wp->val_valid && wp->val)
15119 struct bp_location *loc;
15121 for (loc = bp->loc; loc != NULL; loc = loc->next)
15122 if (loc->loc_type == bp_loc_hardware_watchpoint
15123 && loc->address + loc->length > addr
15124 && addr + len > loc->address)
15126 value_free (wp->val);
15134 /* Create and insert a breakpoint for software single step. */
15137 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15138 struct address_space *aspace,
15141 struct thread_info *tp = inferior_thread ();
15142 struct symtab_and_line sal;
15143 CORE_ADDR pc = next_pc;
15145 if (tp->control.single_step_breakpoints == NULL)
15147 tp->control.single_step_breakpoints
15148 = new_single_step_breakpoint (tp->global_num, gdbarch);
15151 sal = find_pc_line (pc, 0);
15153 sal.section = find_pc_overlay (pc);
15154 sal.explicit_pc = 1;
15155 add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal);
15157 update_global_location_list (UGLL_INSERT);
15160 /* Insert single step breakpoints according to the current state. */
15163 insert_single_step_breakpoints (struct gdbarch *gdbarch)
15165 struct regcache *regcache = get_current_regcache ();
15166 VEC (CORE_ADDR) * next_pcs;
15168 next_pcs = gdbarch_software_single_step (gdbarch, regcache);
15170 if (next_pcs != NULL)
15174 struct frame_info *frame = get_current_frame ();
15175 struct address_space *aspace = get_frame_address_space (frame);
15177 for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++)
15178 insert_single_step_breakpoint (gdbarch, aspace, pc);
15180 VEC_free (CORE_ADDR, next_pcs);
15188 /* See breakpoint.h. */
15191 breakpoint_has_location_inserted_here (struct breakpoint *bp,
15192 struct address_space *aspace,
15195 struct bp_location *loc;
15197 for (loc = bp->loc; loc != NULL; loc = loc->next)
15199 && breakpoint_location_address_match (loc, aspace, pc))
15205 /* Check whether a software single-step breakpoint is inserted at
15209 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15212 struct breakpoint *bpt;
15214 ALL_BREAKPOINTS (bpt)
15216 if (bpt->type == bp_single_step
15217 && breakpoint_has_location_inserted_here (bpt, aspace, pc))
15223 /* Tracepoint-specific operations. */
15225 /* Set tracepoint count to NUM. */
15227 set_tracepoint_count (int num)
15229 tracepoint_count = num;
15230 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15234 trace_command (char *arg, int from_tty)
15236 struct breakpoint_ops *ops;
15237 struct event_location *location;
15238 struct cleanup *back_to;
15240 location = string_to_event_location (&arg, current_language);
15241 back_to = make_cleanup_delete_event_location (location);
15242 if (location != NULL
15243 && event_location_type (location) == PROBE_LOCATION)
15244 ops = &tracepoint_probe_breakpoint_ops;
15246 ops = &tracepoint_breakpoint_ops;
15248 create_breakpoint (get_current_arch (),
15250 NULL, 0, arg, 1 /* parse arg */,
15252 bp_tracepoint /* type_wanted */,
15253 0 /* Ignore count */,
15254 pending_break_support,
15258 0 /* internal */, 0);
15259 do_cleanups (back_to);
15263 ftrace_command (char *arg, int from_tty)
15265 struct event_location *location;
15266 struct cleanup *back_to;
15268 location = string_to_event_location (&arg, current_language);
15269 back_to = make_cleanup_delete_event_location (location);
15270 create_breakpoint (get_current_arch (),
15272 NULL, 0, arg, 1 /* parse arg */,
15274 bp_fast_tracepoint /* type_wanted */,
15275 0 /* Ignore count */,
15276 pending_break_support,
15277 &tracepoint_breakpoint_ops,
15280 0 /* internal */, 0);
15281 do_cleanups (back_to);
15284 /* strace command implementation. Creates a static tracepoint. */
15287 strace_command (char *arg, int from_tty)
15289 struct breakpoint_ops *ops;
15290 struct event_location *location;
15291 struct cleanup *back_to;
15293 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15294 or with a normal static tracepoint. */
15295 if (arg && startswith (arg, "-m") && isspace (arg[2]))
15297 ops = &strace_marker_breakpoint_ops;
15298 location = new_linespec_location (&arg);
15302 ops = &tracepoint_breakpoint_ops;
15303 location = string_to_event_location (&arg, current_language);
15306 back_to = make_cleanup_delete_event_location (location);
15307 create_breakpoint (get_current_arch (),
15309 NULL, 0, arg, 1 /* parse arg */,
15311 bp_static_tracepoint /* type_wanted */,
15312 0 /* Ignore count */,
15313 pending_break_support,
15317 0 /* internal */, 0);
15318 do_cleanups (back_to);
15321 /* Set up a fake reader function that gets command lines from a linked
15322 list that was acquired during tracepoint uploading. */
15324 static struct uploaded_tp *this_utp;
15325 static int next_cmd;
15328 read_uploaded_action (void)
15332 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15339 /* Given information about a tracepoint as recorded on a target (which
15340 can be either a live system or a trace file), attempt to create an
15341 equivalent GDB tracepoint. This is not a reliable process, since
15342 the target does not necessarily have all the information used when
15343 the tracepoint was originally defined. */
15345 struct tracepoint *
15346 create_tracepoint_from_upload (struct uploaded_tp *utp)
15348 char *addr_str, small_buf[100];
15349 struct tracepoint *tp;
15350 struct event_location *location;
15351 struct cleanup *cleanup;
15353 if (utp->at_string)
15354 addr_str = utp->at_string;
15357 /* In the absence of a source location, fall back to raw
15358 address. Since there is no way to confirm that the address
15359 means the same thing as when the trace was started, warn the
15361 warning (_("Uploaded tracepoint %d has no "
15362 "source location, using raw address"),
15364 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15365 addr_str = small_buf;
15368 /* There's not much we can do with a sequence of bytecodes. */
15369 if (utp->cond && !utp->cond_string)
15370 warning (_("Uploaded tracepoint %d condition "
15371 "has no source form, ignoring it"),
15374 location = string_to_event_location (&addr_str, current_language);
15375 cleanup = make_cleanup_delete_event_location (location);
15376 if (!create_breakpoint (get_current_arch (),
15378 utp->cond_string, -1, addr_str,
15379 0 /* parse cond/thread */,
15381 utp->type /* type_wanted */,
15382 0 /* Ignore count */,
15383 pending_break_support,
15384 &tracepoint_breakpoint_ops,
15386 utp->enabled /* enabled */,
15388 CREATE_BREAKPOINT_FLAGS_INSERTED))
15390 do_cleanups (cleanup);
15394 do_cleanups (cleanup);
15396 /* Get the tracepoint we just created. */
15397 tp = get_tracepoint (tracepoint_count);
15398 gdb_assert (tp != NULL);
15402 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15405 trace_pass_command (small_buf, 0);
15408 /* If we have uploaded versions of the original commands, set up a
15409 special-purpose "reader" function and call the usual command line
15410 reader, then pass the result to the breakpoint command-setting
15412 if (!VEC_empty (char_ptr, utp->cmd_strings))
15414 struct command_line *cmd_list;
15419 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15421 breakpoint_set_commands (&tp->base, cmd_list);
15423 else if (!VEC_empty (char_ptr, utp->actions)
15424 || !VEC_empty (char_ptr, utp->step_actions))
15425 warning (_("Uploaded tracepoint %d actions "
15426 "have no source form, ignoring them"),
15429 /* Copy any status information that might be available. */
15430 tp->base.hit_count = utp->hit_count;
15431 tp->traceframe_usage = utp->traceframe_usage;
15436 /* Print information on tracepoint number TPNUM_EXP, or all if
15440 tracepoints_info (char *args, int from_tty)
15442 struct ui_out *uiout = current_uiout;
15445 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15447 if (num_printed == 0)
15449 if (args == NULL || *args == '\0')
15450 uiout->message ("No tracepoints.\n");
15452 uiout->message ("No tracepoint matching '%s'.\n", args);
15455 default_collect_info ();
15458 /* The 'enable trace' command enables tracepoints.
15459 Not supported by all targets. */
15461 enable_trace_command (char *args, int from_tty)
15463 enable_command (args, from_tty);
15466 /* The 'disable trace' command disables tracepoints.
15467 Not supported by all targets. */
15469 disable_trace_command (char *args, int from_tty)
15471 disable_command (args, from_tty);
15474 /* Remove a tracepoint (or all if no argument). */
15476 delete_trace_command (char *arg, int from_tty)
15478 struct breakpoint *b, *b_tmp;
15484 int breaks_to_delete = 0;
15486 /* Delete all breakpoints if no argument.
15487 Do not delete internal or call-dummy breakpoints, these
15488 have to be deleted with an explicit breakpoint number
15490 ALL_TRACEPOINTS (b)
15491 if (is_tracepoint (b) && user_breakpoint_p (b))
15493 breaks_to_delete = 1;
15497 /* Ask user only if there are some breakpoints to delete. */
15499 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15501 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15502 if (is_tracepoint (b) && user_breakpoint_p (b))
15503 delete_breakpoint (b);
15507 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15510 /* Helper function for trace_pass_command. */
15513 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15515 tp->pass_count = count;
15516 observer_notify_breakpoint_modified (&tp->base);
15518 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15519 tp->base.number, count);
15522 /* Set passcount for tracepoint.
15524 First command argument is passcount, second is tracepoint number.
15525 If tracepoint number omitted, apply to most recently defined.
15526 Also accepts special argument "all". */
15529 trace_pass_command (char *args, int from_tty)
15531 struct tracepoint *t1;
15532 unsigned int count;
15534 if (args == 0 || *args == 0)
15535 error (_("passcount command requires an "
15536 "argument (count + optional TP num)"));
15538 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15540 args = skip_spaces (args);
15541 if (*args && strncasecmp (args, "all", 3) == 0)
15543 struct breakpoint *b;
15545 args += 3; /* Skip special argument "all". */
15547 error (_("Junk at end of arguments."));
15549 ALL_TRACEPOINTS (b)
15551 t1 = (struct tracepoint *) b;
15552 trace_pass_set_count (t1, count, from_tty);
15555 else if (*args == '\0')
15557 t1 = get_tracepoint_by_number (&args, NULL);
15559 trace_pass_set_count (t1, count, from_tty);
15563 number_or_range_parser parser (args);
15564 while (!parser.finished ())
15566 t1 = get_tracepoint_by_number (&args, &parser);
15568 trace_pass_set_count (t1, count, from_tty);
15573 struct tracepoint *
15574 get_tracepoint (int num)
15576 struct breakpoint *t;
15578 ALL_TRACEPOINTS (t)
15579 if (t->number == num)
15580 return (struct tracepoint *) t;
15585 /* Find the tracepoint with the given target-side number (which may be
15586 different from the tracepoint number after disconnecting and
15589 struct tracepoint *
15590 get_tracepoint_by_number_on_target (int num)
15592 struct breakpoint *b;
15594 ALL_TRACEPOINTS (b)
15596 struct tracepoint *t = (struct tracepoint *) b;
15598 if (t->number_on_target == num)
15605 /* Utility: parse a tracepoint number and look it up in the list.
15606 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15607 If the argument is missing, the most recent tracepoint
15608 (tracepoint_count) is returned. */
15610 struct tracepoint *
15611 get_tracepoint_by_number (char **arg,
15612 number_or_range_parser *parser)
15614 struct breakpoint *t;
15616 char *instring = arg == NULL ? NULL : *arg;
15618 if (parser != NULL)
15620 gdb_assert (!parser->finished ());
15621 tpnum = parser->get_number ();
15623 else if (arg == NULL || *arg == NULL || ! **arg)
15624 tpnum = tracepoint_count;
15626 tpnum = get_number (arg);
15630 if (instring && *instring)
15631 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15634 printf_filtered (_("No previous tracepoint\n"));
15638 ALL_TRACEPOINTS (t)
15639 if (t->number == tpnum)
15641 return (struct tracepoint *) t;
15644 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15649 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15651 if (b->thread != -1)
15652 fprintf_unfiltered (fp, " thread %d", b->thread);
15655 fprintf_unfiltered (fp, " task %d", b->task);
15657 fprintf_unfiltered (fp, "\n");
15660 /* Save information on user settable breakpoints (watchpoints, etc) to
15661 a new script file named FILENAME. If FILTER is non-NULL, call it
15662 on each breakpoint and only include the ones for which it returns
15666 save_breakpoints (char *filename, int from_tty,
15667 int (*filter) (const struct breakpoint *))
15669 struct breakpoint *tp;
15671 struct cleanup *cleanup;
15672 struct ui_file *fp;
15673 int extra_trace_bits = 0;
15675 if (filename == 0 || *filename == 0)
15676 error (_("Argument required (file name in which to save)"));
15678 /* See if we have anything to save. */
15679 ALL_BREAKPOINTS (tp)
15681 /* Skip internal and momentary breakpoints. */
15682 if (!user_breakpoint_p (tp))
15685 /* If we have a filter, only save the breakpoints it accepts. */
15686 if (filter && !filter (tp))
15691 if (is_tracepoint (tp))
15693 extra_trace_bits = 1;
15695 /* We can stop searching. */
15702 warning (_("Nothing to save."));
15706 filename = tilde_expand (filename);
15707 cleanup = make_cleanup (xfree, filename);
15708 fp = gdb_fopen (filename, "w");
15710 error (_("Unable to open file '%s' for saving (%s)"),
15711 filename, safe_strerror (errno));
15712 make_cleanup_ui_file_delete (fp);
15714 if (extra_trace_bits)
15715 save_trace_state_variables (fp);
15717 ALL_BREAKPOINTS (tp)
15719 /* Skip internal and momentary breakpoints. */
15720 if (!user_breakpoint_p (tp))
15723 /* If we have a filter, only save the breakpoints it accepts. */
15724 if (filter && !filter (tp))
15727 tp->ops->print_recreate (tp, fp);
15729 /* Note, we can't rely on tp->number for anything, as we can't
15730 assume the recreated breakpoint numbers will match. Use $bpnum
15733 if (tp->cond_string)
15734 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15736 if (tp->ignore_count)
15737 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15739 if (tp->type != bp_dprintf && tp->commands)
15741 fprintf_unfiltered (fp, " commands\n");
15743 current_uiout->redirect (fp);
15746 print_command_lines (current_uiout, tp->commands->commands, 2);
15748 CATCH (ex, RETURN_MASK_ALL)
15750 current_uiout->redirect (NULL);
15751 throw_exception (ex);
15755 current_uiout->redirect (NULL);
15756 fprintf_unfiltered (fp, " end\n");
15759 if (tp->enable_state == bp_disabled)
15760 fprintf_unfiltered (fp, "disable $bpnum\n");
15762 /* If this is a multi-location breakpoint, check if the locations
15763 should be individually disabled. Watchpoint locations are
15764 special, and not user visible. */
15765 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15767 struct bp_location *loc;
15770 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15772 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15776 if (extra_trace_bits && *default_collect)
15777 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15780 printf_filtered (_("Saved to file '%s'.\n"), filename);
15781 do_cleanups (cleanup);
15784 /* The `save breakpoints' command. */
15787 save_breakpoints_command (char *args, int from_tty)
15789 save_breakpoints (args, from_tty, NULL);
15792 /* The `save tracepoints' command. */
15795 save_tracepoints_command (char *args, int from_tty)
15797 save_breakpoints (args, from_tty, is_tracepoint);
15800 /* Create a vector of all tracepoints. */
15802 VEC(breakpoint_p) *
15803 all_tracepoints (void)
15805 VEC(breakpoint_p) *tp_vec = 0;
15806 struct breakpoint *tp;
15808 ALL_TRACEPOINTS (tp)
15810 VEC_safe_push (breakpoint_p, tp_vec, tp);
15817 /* This help string is used to consolidate all the help string for specifying
15818 locations used by several commands. */
15820 #define LOCATION_HELP_STRING \
15821 "Linespecs are colon-separated lists of location parameters, such as\n\
15822 source filename, function name, label name, and line number.\n\
15823 Example: To specify the start of a label named \"the_top\" in the\n\
15824 function \"fact\" in the file \"factorial.c\", use\n\
15825 \"factorial.c:fact:the_top\".\n\
15827 Address locations begin with \"*\" and specify an exact address in the\n\
15828 program. Example: To specify the fourth byte past the start function\n\
15829 \"main\", use \"*main + 4\".\n\
15831 Explicit locations are similar to linespecs but use an option/argument\n\
15832 syntax to specify location parameters.\n\
15833 Example: To specify the start of the label named \"the_top\" in the\n\
15834 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15835 -function fact -label the_top\".\n"
15837 /* This help string is used for the break, hbreak, tbreak and thbreak
15838 commands. It is defined as a macro to prevent duplication.
15839 COMMAND should be a string constant containing the name of the
15842 #define BREAK_ARGS_HELP(command) \
15843 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15844 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15845 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15846 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15847 `-probe-dtrace' (for a DTrace probe).\n\
15848 LOCATION may be a linespec, address, or explicit location as described\n\
15851 With no LOCATION, uses current execution address of the selected\n\
15852 stack frame. This is useful for breaking on return to a stack frame.\n\
15854 THREADNUM is the number from \"info threads\".\n\
15855 CONDITION is a boolean expression.\n\
15856 \n" LOCATION_HELP_STRING "\n\
15857 Multiple breakpoints at one place are permitted, and useful if their\n\
15858 conditions are different.\n\
15860 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15862 /* List of subcommands for "catch". */
15863 static struct cmd_list_element *catch_cmdlist;
15865 /* List of subcommands for "tcatch". */
15866 static struct cmd_list_element *tcatch_cmdlist;
15869 add_catch_command (char *name, char *docstring,
15870 cmd_sfunc_ftype *sfunc,
15871 completer_ftype *completer,
15872 void *user_data_catch,
15873 void *user_data_tcatch)
15875 struct cmd_list_element *command;
15877 command = add_cmd (name, class_breakpoint, NULL, docstring,
15879 set_cmd_sfunc (command, sfunc);
15880 set_cmd_context (command, user_data_catch);
15881 set_cmd_completer (command, completer);
15883 command = add_cmd (name, class_breakpoint, NULL, docstring,
15885 set_cmd_sfunc (command, sfunc);
15886 set_cmd_context (command, user_data_tcatch);
15887 set_cmd_completer (command, completer);
15891 save_command (char *arg, int from_tty)
15893 printf_unfiltered (_("\"save\" must be followed by "
15894 "the name of a save subcommand.\n"));
15895 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15898 struct breakpoint *
15899 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15902 struct breakpoint *b, *b_tmp;
15904 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15906 if ((*callback) (b, data))
15913 /* Zero if any of the breakpoint's locations could be a location where
15914 functions have been inlined, nonzero otherwise. */
15917 is_non_inline_function (struct breakpoint *b)
15919 /* The shared library event breakpoint is set on the address of a
15920 non-inline function. */
15921 if (b->type == bp_shlib_event)
15927 /* Nonzero if the specified PC cannot be a location where functions
15928 have been inlined. */
15931 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15932 const struct target_waitstatus *ws)
15934 struct breakpoint *b;
15935 struct bp_location *bl;
15937 ALL_BREAKPOINTS (b)
15939 if (!is_non_inline_function (b))
15942 for (bl = b->loc; bl != NULL; bl = bl->next)
15944 if (!bl->shlib_disabled
15945 && bpstat_check_location (bl, aspace, pc, ws))
15953 /* Remove any references to OBJFILE which is going to be freed. */
15956 breakpoint_free_objfile (struct objfile *objfile)
15958 struct bp_location **locp, *loc;
15960 ALL_BP_LOCATIONS (loc, locp)
15961 if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15962 loc->symtab = NULL;
15966 initialize_breakpoint_ops (void)
15968 static int initialized = 0;
15970 struct breakpoint_ops *ops;
15976 /* The breakpoint_ops structure to be inherit by all kinds of
15977 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15978 internal and momentary breakpoints, etc.). */
15979 ops = &bkpt_base_breakpoint_ops;
15980 *ops = base_breakpoint_ops;
15981 ops->re_set = bkpt_re_set;
15982 ops->insert_location = bkpt_insert_location;
15983 ops->remove_location = bkpt_remove_location;
15984 ops->breakpoint_hit = bkpt_breakpoint_hit;
15985 ops->create_sals_from_location = bkpt_create_sals_from_location;
15986 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15987 ops->decode_location = bkpt_decode_location;
15989 /* The breakpoint_ops structure to be used in regular breakpoints. */
15990 ops = &bkpt_breakpoint_ops;
15991 *ops = bkpt_base_breakpoint_ops;
15992 ops->re_set = bkpt_re_set;
15993 ops->resources_needed = bkpt_resources_needed;
15994 ops->print_it = bkpt_print_it;
15995 ops->print_mention = bkpt_print_mention;
15996 ops->print_recreate = bkpt_print_recreate;
15998 /* Ranged breakpoints. */
15999 ops = &ranged_breakpoint_ops;
16000 *ops = bkpt_breakpoint_ops;
16001 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16002 ops->resources_needed = resources_needed_ranged_breakpoint;
16003 ops->print_it = print_it_ranged_breakpoint;
16004 ops->print_one = print_one_ranged_breakpoint;
16005 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16006 ops->print_mention = print_mention_ranged_breakpoint;
16007 ops->print_recreate = print_recreate_ranged_breakpoint;
16009 /* Internal breakpoints. */
16010 ops = &internal_breakpoint_ops;
16011 *ops = bkpt_base_breakpoint_ops;
16012 ops->re_set = internal_bkpt_re_set;
16013 ops->check_status = internal_bkpt_check_status;
16014 ops->print_it = internal_bkpt_print_it;
16015 ops->print_mention = internal_bkpt_print_mention;
16017 /* Momentary breakpoints. */
16018 ops = &momentary_breakpoint_ops;
16019 *ops = bkpt_base_breakpoint_ops;
16020 ops->re_set = momentary_bkpt_re_set;
16021 ops->check_status = momentary_bkpt_check_status;
16022 ops->print_it = momentary_bkpt_print_it;
16023 ops->print_mention = momentary_bkpt_print_mention;
16025 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16026 ops = &longjmp_breakpoint_ops;
16027 *ops = momentary_breakpoint_ops;
16028 ops->dtor = longjmp_bkpt_dtor;
16030 /* Probe breakpoints. */
16031 ops = &bkpt_probe_breakpoint_ops;
16032 *ops = bkpt_breakpoint_ops;
16033 ops->insert_location = bkpt_probe_insert_location;
16034 ops->remove_location = bkpt_probe_remove_location;
16035 ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
16036 ops->decode_location = bkpt_probe_decode_location;
16039 ops = &watchpoint_breakpoint_ops;
16040 *ops = base_breakpoint_ops;
16041 ops->dtor = dtor_watchpoint;
16042 ops->re_set = re_set_watchpoint;
16043 ops->insert_location = insert_watchpoint;
16044 ops->remove_location = remove_watchpoint;
16045 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16046 ops->check_status = check_status_watchpoint;
16047 ops->resources_needed = resources_needed_watchpoint;
16048 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16049 ops->print_it = print_it_watchpoint;
16050 ops->print_mention = print_mention_watchpoint;
16051 ops->print_recreate = print_recreate_watchpoint;
16052 ops->explains_signal = explains_signal_watchpoint;
16054 /* Masked watchpoints. */
16055 ops = &masked_watchpoint_breakpoint_ops;
16056 *ops = watchpoint_breakpoint_ops;
16057 ops->insert_location = insert_masked_watchpoint;
16058 ops->remove_location = remove_masked_watchpoint;
16059 ops->resources_needed = resources_needed_masked_watchpoint;
16060 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16061 ops->print_it = print_it_masked_watchpoint;
16062 ops->print_one_detail = print_one_detail_masked_watchpoint;
16063 ops->print_mention = print_mention_masked_watchpoint;
16064 ops->print_recreate = print_recreate_masked_watchpoint;
16067 ops = &tracepoint_breakpoint_ops;
16068 *ops = base_breakpoint_ops;
16069 ops->re_set = tracepoint_re_set;
16070 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16071 ops->print_one_detail = tracepoint_print_one_detail;
16072 ops->print_mention = tracepoint_print_mention;
16073 ops->print_recreate = tracepoint_print_recreate;
16074 ops->create_sals_from_location = tracepoint_create_sals_from_location;
16075 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16076 ops->decode_location = tracepoint_decode_location;
16078 /* Probe tracepoints. */
16079 ops = &tracepoint_probe_breakpoint_ops;
16080 *ops = tracepoint_breakpoint_ops;
16081 ops->create_sals_from_location = tracepoint_probe_create_sals_from_location;
16082 ops->decode_location = tracepoint_probe_decode_location;
16084 /* Static tracepoints with marker (`-m'). */
16085 ops = &strace_marker_breakpoint_ops;
16086 *ops = tracepoint_breakpoint_ops;
16087 ops->create_sals_from_location = strace_marker_create_sals_from_location;
16088 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16089 ops->decode_location = strace_marker_decode_location;
16091 /* Fork catchpoints. */
16092 ops = &catch_fork_breakpoint_ops;
16093 *ops = base_breakpoint_ops;
16094 ops->insert_location = insert_catch_fork;
16095 ops->remove_location = remove_catch_fork;
16096 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16097 ops->print_it = print_it_catch_fork;
16098 ops->print_one = print_one_catch_fork;
16099 ops->print_mention = print_mention_catch_fork;
16100 ops->print_recreate = print_recreate_catch_fork;
16102 /* Vfork catchpoints. */
16103 ops = &catch_vfork_breakpoint_ops;
16104 *ops = base_breakpoint_ops;
16105 ops->insert_location = insert_catch_vfork;
16106 ops->remove_location = remove_catch_vfork;
16107 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16108 ops->print_it = print_it_catch_vfork;
16109 ops->print_one = print_one_catch_vfork;
16110 ops->print_mention = print_mention_catch_vfork;
16111 ops->print_recreate = print_recreate_catch_vfork;
16113 /* Exec catchpoints. */
16114 ops = &catch_exec_breakpoint_ops;
16115 *ops = base_breakpoint_ops;
16116 ops->dtor = dtor_catch_exec;
16117 ops->insert_location = insert_catch_exec;
16118 ops->remove_location = remove_catch_exec;
16119 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16120 ops->print_it = print_it_catch_exec;
16121 ops->print_one = print_one_catch_exec;
16122 ops->print_mention = print_mention_catch_exec;
16123 ops->print_recreate = print_recreate_catch_exec;
16125 /* Solib-related catchpoints. */
16126 ops = &catch_solib_breakpoint_ops;
16127 *ops = base_breakpoint_ops;
16128 ops->dtor = dtor_catch_solib;
16129 ops->insert_location = insert_catch_solib;
16130 ops->remove_location = remove_catch_solib;
16131 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16132 ops->check_status = check_status_catch_solib;
16133 ops->print_it = print_it_catch_solib;
16134 ops->print_one = print_one_catch_solib;
16135 ops->print_mention = print_mention_catch_solib;
16136 ops->print_recreate = print_recreate_catch_solib;
16138 ops = &dprintf_breakpoint_ops;
16139 *ops = bkpt_base_breakpoint_ops;
16140 ops->re_set = dprintf_re_set;
16141 ops->resources_needed = bkpt_resources_needed;
16142 ops->print_it = bkpt_print_it;
16143 ops->print_mention = bkpt_print_mention;
16144 ops->print_recreate = dprintf_print_recreate;
16145 ops->after_condition_true = dprintf_after_condition_true;
16146 ops->breakpoint_hit = dprintf_breakpoint_hit;
16149 /* Chain containing all defined "enable breakpoint" subcommands. */
16151 static struct cmd_list_element *enablebreaklist = NULL;
16154 _initialize_breakpoint (void)
16156 struct cmd_list_element *c;
16158 initialize_breakpoint_ops ();
16160 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16161 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16162 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16164 breakpoint_objfile_key
16165 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16167 breakpoint_chain = 0;
16168 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16169 before a breakpoint is set. */
16170 breakpoint_count = 0;
16172 tracepoint_count = 0;
16174 add_com ("ignore", class_breakpoint, ignore_command, _("\
16175 Set ignore-count of breakpoint number N to COUNT.\n\
16176 Usage is `ignore N COUNT'."));
16178 add_com ("commands", class_breakpoint, commands_command, _("\
16179 Set commands to be executed when a breakpoint is hit.\n\
16180 Give breakpoint number as argument after \"commands\".\n\
16181 With no argument, the targeted breakpoint is the last one set.\n\
16182 The commands themselves follow starting on the next line.\n\
16183 Type a line containing \"end\" to indicate the end of them.\n\
16184 Give \"silent\" as the first line to make the breakpoint silent;\n\
16185 then no output is printed when it is hit, except what the commands print."));
16187 c = add_com ("condition", class_breakpoint, condition_command, _("\
16188 Specify breakpoint number N to break only if COND is true.\n\
16189 Usage is `condition N COND', where N is an integer and COND is an\n\
16190 expression to be evaluated whenever breakpoint N is reached."));
16191 set_cmd_completer (c, condition_completer);
16193 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16194 Set a temporary breakpoint.\n\
16195 Like \"break\" except the breakpoint is only temporary,\n\
16196 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16197 by using \"enable delete\" on the breakpoint number.\n\
16199 BREAK_ARGS_HELP ("tbreak")));
16200 set_cmd_completer (c, location_completer);
16202 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16203 Set a hardware assisted breakpoint.\n\
16204 Like \"break\" except the breakpoint requires hardware support,\n\
16205 some target hardware may not have this support.\n\
16207 BREAK_ARGS_HELP ("hbreak")));
16208 set_cmd_completer (c, location_completer);
16210 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16211 Set a temporary hardware assisted breakpoint.\n\
16212 Like \"hbreak\" except the breakpoint is only temporary,\n\
16213 so it will be deleted when hit.\n\
16215 BREAK_ARGS_HELP ("thbreak")));
16216 set_cmd_completer (c, location_completer);
16218 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16219 Enable some breakpoints.\n\
16220 Give breakpoint numbers (separated by spaces) as arguments.\n\
16221 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16222 This is used to cancel the effect of the \"disable\" command.\n\
16223 With a subcommand you can enable temporarily."),
16224 &enablelist, "enable ", 1, &cmdlist);
16226 add_com_alias ("en", "enable", class_breakpoint, 1);
16228 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16229 Enable some breakpoints.\n\
16230 Give breakpoint numbers (separated by spaces) as arguments.\n\
16231 This is used to cancel the effect of the \"disable\" command.\n\
16232 May be abbreviated to simply \"enable\".\n"),
16233 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16235 add_cmd ("once", no_class, enable_once_command, _("\
16236 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16237 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16240 add_cmd ("delete", no_class, enable_delete_command, _("\
16241 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16242 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16245 add_cmd ("count", no_class, enable_count_command, _("\
16246 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16247 If a breakpoint is hit while enabled in this fashion,\n\
16248 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16251 add_cmd ("delete", no_class, enable_delete_command, _("\
16252 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16253 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16256 add_cmd ("once", no_class, enable_once_command, _("\
16257 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16258 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16261 add_cmd ("count", no_class, enable_count_command, _("\
16262 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16263 If a breakpoint is hit while enabled in this fashion,\n\
16264 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16267 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16268 Disable some breakpoints.\n\
16269 Arguments are breakpoint numbers with spaces in between.\n\
16270 To disable all breakpoints, give no argument.\n\
16271 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16272 &disablelist, "disable ", 1, &cmdlist);
16273 add_com_alias ("dis", "disable", class_breakpoint, 1);
16274 add_com_alias ("disa", "disable", class_breakpoint, 1);
16276 add_cmd ("breakpoints", class_alias, disable_command, _("\
16277 Disable some breakpoints.\n\
16278 Arguments are breakpoint numbers with spaces in between.\n\
16279 To disable all breakpoints, give no argument.\n\
16280 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16281 This command may be abbreviated \"disable\"."),
16284 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16285 Delete some breakpoints or auto-display expressions.\n\
16286 Arguments are breakpoint numbers with spaces in between.\n\
16287 To delete all breakpoints, give no argument.\n\
16289 Also a prefix command for deletion of other GDB objects.\n\
16290 The \"unset\" command is also an alias for \"delete\"."),
16291 &deletelist, "delete ", 1, &cmdlist);
16292 add_com_alias ("d", "delete", class_breakpoint, 1);
16293 add_com_alias ("del", "delete", class_breakpoint, 1);
16295 add_cmd ("breakpoints", class_alias, delete_command, _("\
16296 Delete some breakpoints or auto-display expressions.\n\
16297 Arguments are breakpoint numbers with spaces in between.\n\
16298 To delete all breakpoints, give no argument.\n\
16299 This command may be abbreviated \"delete\"."),
16302 add_com ("clear", class_breakpoint, clear_command, _("\
16303 Clear breakpoint at specified location.\n\
16304 Argument may be a linespec, explicit, or address location as described below.\n\
16306 With no argument, clears all breakpoints in the line that the selected frame\n\
16307 is executing in.\n"
16308 "\n" LOCATION_HELP_STRING "\n\
16309 See also the \"delete\" command which clears breakpoints by number."));
16310 add_com_alias ("cl", "clear", class_breakpoint, 1);
16312 c = add_com ("break", class_breakpoint, break_command, _("\
16313 Set breakpoint at specified location.\n"
16314 BREAK_ARGS_HELP ("break")));
16315 set_cmd_completer (c, location_completer);
16317 add_com_alias ("b", "break", class_run, 1);
16318 add_com_alias ("br", "break", class_run, 1);
16319 add_com_alias ("bre", "break", class_run, 1);
16320 add_com_alias ("brea", "break", class_run, 1);
16324 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16325 Break in function/address or break at a line in the current file."),
16326 &stoplist, "stop ", 1, &cmdlist);
16327 add_cmd ("in", class_breakpoint, stopin_command,
16328 _("Break in function or address."), &stoplist);
16329 add_cmd ("at", class_breakpoint, stopat_command,
16330 _("Break at a line in the current file."), &stoplist);
16331 add_com ("status", class_info, breakpoints_info, _("\
16332 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16333 The \"Type\" column indicates one of:\n\
16334 \tbreakpoint - normal breakpoint\n\
16335 \twatchpoint - watchpoint\n\
16336 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16337 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16338 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16339 address and file/line number respectively.\n\
16341 Convenience variable \"$_\" and default examine address for \"x\"\n\
16342 are set to the address of the last breakpoint listed unless the command\n\
16343 is prefixed with \"server \".\n\n\
16344 Convenience variable \"$bpnum\" contains the number of the last\n\
16345 breakpoint set."));
16348 add_info ("breakpoints", breakpoints_info, _("\
16349 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16350 The \"Type\" column indicates one of:\n\
16351 \tbreakpoint - normal breakpoint\n\
16352 \twatchpoint - watchpoint\n\
16353 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16354 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16355 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16356 address and file/line number respectively.\n\
16358 Convenience variable \"$_\" and default examine address for \"x\"\n\
16359 are set to the address of the last breakpoint listed unless the command\n\
16360 is prefixed with \"server \".\n\n\
16361 Convenience variable \"$bpnum\" contains the number of the last\n\
16362 breakpoint set."));
16364 add_info_alias ("b", "breakpoints", 1);
16366 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16367 Status of all breakpoints, or breakpoint number NUMBER.\n\
16368 The \"Type\" column indicates one of:\n\
16369 \tbreakpoint - normal breakpoint\n\
16370 \twatchpoint - watchpoint\n\
16371 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16372 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16373 \tuntil - internal breakpoint used by the \"until\" command\n\
16374 \tfinish - internal breakpoint used by the \"finish\" command\n\
16375 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16376 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16377 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16378 address and file/line number respectively.\n\
16380 Convenience variable \"$_\" and default examine address for \"x\"\n\
16381 are set to the address of the last breakpoint listed unless the command\n\
16382 is prefixed with \"server \".\n\n\
16383 Convenience variable \"$bpnum\" contains the number of the last\n\
16385 &maintenanceinfolist);
16387 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16388 Set catchpoints to catch events."),
16389 &catch_cmdlist, "catch ",
16390 0/*allow-unknown*/, &cmdlist);
16392 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16393 Set temporary catchpoints to catch events."),
16394 &tcatch_cmdlist, "tcatch ",
16395 0/*allow-unknown*/, &cmdlist);
16397 add_catch_command ("fork", _("Catch calls to fork."),
16398 catch_fork_command_1,
16400 (void *) (uintptr_t) catch_fork_permanent,
16401 (void *) (uintptr_t) catch_fork_temporary);
16402 add_catch_command ("vfork", _("Catch calls to vfork."),
16403 catch_fork_command_1,
16405 (void *) (uintptr_t) catch_vfork_permanent,
16406 (void *) (uintptr_t) catch_vfork_temporary);
16407 add_catch_command ("exec", _("Catch calls to exec."),
16408 catch_exec_command_1,
16412 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16413 Usage: catch load [REGEX]\n\
16414 If REGEX is given, only stop for libraries matching the regular expression."),
16415 catch_load_command_1,
16419 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16420 Usage: catch unload [REGEX]\n\
16421 If REGEX is given, only stop for libraries matching the regular expression."),
16422 catch_unload_command_1,
16427 c = add_com ("watch", class_breakpoint, watch_command, _("\
16428 Set a watchpoint for an expression.\n\
16429 Usage: watch [-l|-location] EXPRESSION\n\
16430 A watchpoint stops execution of your program whenever the value of\n\
16431 an expression changes.\n\
16432 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16433 the memory to which it refers."));
16434 set_cmd_completer (c, expression_completer);
16436 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16437 Set a read watchpoint for an expression.\n\
16438 Usage: rwatch [-l|-location] EXPRESSION\n\
16439 A watchpoint stops execution of your program whenever the value of\n\
16440 an expression is read.\n\
16441 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16442 the memory to which it refers."));
16443 set_cmd_completer (c, expression_completer);
16445 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16446 Set a watchpoint for an expression.\n\
16447 Usage: awatch [-l|-location] EXPRESSION\n\
16448 A watchpoint stops execution of your program whenever the value of\n\
16449 an expression is either read or written.\n\
16450 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16451 the memory to which it refers."));
16452 set_cmd_completer (c, expression_completer);
16454 add_info ("watchpoints", watchpoints_info, _("\
16455 Status of specified watchpoints (all watchpoints if no argument)."));
16457 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16458 respond to changes - contrary to the description. */
16459 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16460 &can_use_hw_watchpoints, _("\
16461 Set debugger's willingness to use watchpoint hardware."), _("\
16462 Show debugger's willingness to use watchpoint hardware."), _("\
16463 If zero, gdb will not use hardware for new watchpoints, even if\n\
16464 such is available. (However, any hardware watchpoints that were\n\
16465 created before setting this to nonzero, will continue to use watchpoint\n\
16468 show_can_use_hw_watchpoints,
16469 &setlist, &showlist);
16471 can_use_hw_watchpoints = 1;
16473 /* Tracepoint manipulation commands. */
16475 c = add_com ("trace", class_breakpoint, trace_command, _("\
16476 Set a tracepoint at specified location.\n\
16478 BREAK_ARGS_HELP ("trace") "\n\
16479 Do \"help tracepoints\" for info on other tracepoint commands."));
16480 set_cmd_completer (c, location_completer);
16482 add_com_alias ("tp", "trace", class_alias, 0);
16483 add_com_alias ("tr", "trace", class_alias, 1);
16484 add_com_alias ("tra", "trace", class_alias, 1);
16485 add_com_alias ("trac", "trace", class_alias, 1);
16487 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16488 Set a fast tracepoint at specified location.\n\
16490 BREAK_ARGS_HELP ("ftrace") "\n\
16491 Do \"help tracepoints\" for info on other tracepoint commands."));
16492 set_cmd_completer (c, location_completer);
16494 c = add_com ("strace", class_breakpoint, strace_command, _("\
16495 Set a static tracepoint at location or marker.\n\
16497 strace [LOCATION] [if CONDITION]\n\
16498 LOCATION may be a linespec, explicit, or address location (described below) \n\
16499 or -m MARKER_ID.\n\n\
16500 If a marker id is specified, probe the marker with that name. With\n\
16501 no LOCATION, uses current execution address of the selected stack frame.\n\
16502 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16503 This collects arbitrary user data passed in the probe point call to the\n\
16504 tracing library. You can inspect it when analyzing the trace buffer,\n\
16505 by printing the $_sdata variable like any other convenience variable.\n\
16507 CONDITION is a boolean expression.\n\
16508 \n" LOCATION_HELP_STRING "\n\
16509 Multiple tracepoints at one place are permitted, and useful if their\n\
16510 conditions are different.\n\
16512 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16513 Do \"help tracepoints\" for info on other tracepoint commands."));
16514 set_cmd_completer (c, location_completer);
16516 add_info ("tracepoints", tracepoints_info, _("\
16517 Status of specified tracepoints (all tracepoints if no argument).\n\
16518 Convenience variable \"$tpnum\" contains the number of the\n\
16519 last tracepoint set."));
16521 add_info_alias ("tp", "tracepoints", 1);
16523 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16524 Delete specified tracepoints.\n\
16525 Arguments are tracepoint numbers, separated by spaces.\n\
16526 No argument means delete all tracepoints."),
16528 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16530 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16531 Disable specified tracepoints.\n\
16532 Arguments are tracepoint numbers, separated by spaces.\n\
16533 No argument means disable all tracepoints."),
16535 deprecate_cmd (c, "disable");
16537 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16538 Enable specified tracepoints.\n\
16539 Arguments are tracepoint numbers, separated by spaces.\n\
16540 No argument means enable all tracepoints."),
16542 deprecate_cmd (c, "enable");
16544 add_com ("passcount", class_trace, trace_pass_command, _("\
16545 Set the passcount for a tracepoint.\n\
16546 The trace will end when the tracepoint has been passed 'count' times.\n\
16547 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16548 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16550 add_prefix_cmd ("save", class_breakpoint, save_command,
16551 _("Save breakpoint definitions as a script."),
16552 &save_cmdlist, "save ",
16553 0/*allow-unknown*/, &cmdlist);
16555 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16556 Save current breakpoint definitions as a script.\n\
16557 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16558 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16559 session to restore them."),
16561 set_cmd_completer (c, filename_completer);
16563 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16564 Save current tracepoint definitions as a script.\n\
16565 Use the 'source' command in another debug session to restore them."),
16567 set_cmd_completer (c, filename_completer);
16569 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16570 deprecate_cmd (c, "save tracepoints");
16572 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16573 Breakpoint specific settings\n\
16574 Configure various breakpoint-specific variables such as\n\
16575 pending breakpoint behavior"),
16576 &breakpoint_set_cmdlist, "set breakpoint ",
16577 0/*allow-unknown*/, &setlist);
16578 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16579 Breakpoint specific settings\n\
16580 Configure various breakpoint-specific variables such as\n\
16581 pending breakpoint behavior"),
16582 &breakpoint_show_cmdlist, "show breakpoint ",
16583 0/*allow-unknown*/, &showlist);
16585 add_setshow_auto_boolean_cmd ("pending", no_class,
16586 &pending_break_support, _("\
16587 Set debugger's behavior regarding pending breakpoints."), _("\
16588 Show debugger's behavior regarding pending breakpoints."), _("\
16589 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16590 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16591 an error. If auto, an unrecognized breakpoint location results in a\n\
16592 user-query to see if a pending breakpoint should be created."),
16594 show_pending_break_support,
16595 &breakpoint_set_cmdlist,
16596 &breakpoint_show_cmdlist);
16598 pending_break_support = AUTO_BOOLEAN_AUTO;
16600 add_setshow_boolean_cmd ("auto-hw", no_class,
16601 &automatic_hardware_breakpoints, _("\
16602 Set automatic usage of hardware breakpoints."), _("\
16603 Show automatic usage of hardware breakpoints."), _("\
16604 If set, the debugger will automatically use hardware breakpoints for\n\
16605 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16606 a warning will be emitted for such breakpoints."),
16608 show_automatic_hardware_breakpoints,
16609 &breakpoint_set_cmdlist,
16610 &breakpoint_show_cmdlist);
16612 add_setshow_boolean_cmd ("always-inserted", class_support,
16613 &always_inserted_mode, _("\
16614 Set mode for inserting breakpoints."), _("\
16615 Show mode for inserting breakpoints."), _("\
16616 When this mode is on, breakpoints are inserted immediately as soon as\n\
16617 they're created, kept inserted even when execution stops, and removed\n\
16618 only when the user deletes them. When this mode is off (the default),\n\
16619 breakpoints are inserted only when execution continues, and removed\n\
16620 when execution stops."),
16622 &show_always_inserted_mode,
16623 &breakpoint_set_cmdlist,
16624 &breakpoint_show_cmdlist);
16626 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16627 condition_evaluation_enums,
16628 &condition_evaluation_mode_1, _("\
16629 Set mode of breakpoint condition evaluation."), _("\
16630 Show mode of breakpoint condition evaluation."), _("\
16631 When this is set to \"host\", breakpoint conditions will be\n\
16632 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16633 breakpoint conditions will be downloaded to the target (if the target\n\
16634 supports such feature) and conditions will be evaluated on the target's side.\n\
16635 If this is set to \"auto\" (default), this will be automatically set to\n\
16636 \"target\" if it supports condition evaluation, otherwise it will\n\
16637 be set to \"gdb\""),
16638 &set_condition_evaluation_mode,
16639 &show_condition_evaluation_mode,
16640 &breakpoint_set_cmdlist,
16641 &breakpoint_show_cmdlist);
16643 add_com ("break-range", class_breakpoint, break_range_command, _("\
16644 Set a breakpoint for an address range.\n\
16645 break-range START-LOCATION, END-LOCATION\n\
16646 where START-LOCATION and END-LOCATION can be one of the following:\n\
16647 LINENUM, for that line in the current file,\n\
16648 FILE:LINENUM, for that line in that file,\n\
16649 +OFFSET, for that number of lines after the current line\n\
16650 or the start of the range\n\
16651 FUNCTION, for the first line in that function,\n\
16652 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16653 *ADDRESS, for the instruction at that address.\n\
16655 The breakpoint will stop execution of the inferior whenever it executes\n\
16656 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16657 range (including START-LOCATION and END-LOCATION)."));
16659 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16660 Set a dynamic printf at specified location.\n\
16661 dprintf location,format string,arg1,arg2,...\n\
16662 location may be a linespec, explicit, or address location.\n"
16663 "\n" LOCATION_HELP_STRING));
16664 set_cmd_completer (c, location_completer);
16666 add_setshow_enum_cmd ("dprintf-style", class_support,
16667 dprintf_style_enums, &dprintf_style, _("\
16668 Set the style of usage for dynamic printf."), _("\
16669 Show the style of usage for dynamic printf."), _("\
16670 This setting chooses how GDB will do a dynamic printf.\n\
16671 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16672 console, as with the \"printf\" command.\n\
16673 If the value is \"call\", the print is done by calling a function in your\n\
16674 program; by default printf(), but you can choose a different function or\n\
16675 output stream by setting dprintf-function and dprintf-channel."),
16676 update_dprintf_commands, NULL,
16677 &setlist, &showlist);
16679 dprintf_function = xstrdup ("printf");
16680 add_setshow_string_cmd ("dprintf-function", class_support,
16681 &dprintf_function, _("\
16682 Set the function to use for dynamic printf"), _("\
16683 Show the function to use for dynamic printf"), NULL,
16684 update_dprintf_commands, NULL,
16685 &setlist, &showlist);
16687 dprintf_channel = xstrdup ("");
16688 add_setshow_string_cmd ("dprintf-channel", class_support,
16689 &dprintf_channel, _("\
16690 Set the channel to use for dynamic printf"), _("\
16691 Show the channel to use for dynamic printf"), NULL,
16692 update_dprintf_commands, NULL,
16693 &setlist, &showlist);
16695 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16696 &disconnected_dprintf, _("\
16697 Set whether dprintf continues after GDB disconnects."), _("\
16698 Show whether dprintf continues after GDB disconnects."), _("\
16699 Use this to let dprintf commands continue to hit and produce output\n\
16700 even if GDB disconnects or detaches from the target."),
16703 &setlist, &showlist);
16705 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16706 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16707 (target agent only) This is useful for formatted output in user-defined commands."));
16709 automatic_hardware_breakpoints = 1;
16711 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
16712 observer_attach_thread_exit (remove_threaded_breakpoints);