1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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"
54 #include "exceptions.h"
60 #include "xml-syscall.h"
61 #include "parser-defs.h"
62 #include "gdb_regex.h"
64 #include "cli/cli-utils.h"
65 #include "continuations.h"
69 #include "dummy-frame.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 /* Enums for exception-handling support. */
84 enum exception_event_kind
91 /* Prototypes for local functions. */
93 static void enable_delete_command (char *, int);
95 static void enable_once_command (char *, int);
97 static void enable_count_command (char *, int);
99 static void disable_command (char *, int);
101 static void enable_command (char *, int);
103 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
107 static void ignore_command (char *, int);
109 static int breakpoint_re_set_one (void *);
111 static void breakpoint_re_set_default (struct breakpoint *);
113 static void create_sals_from_address_default (char **,
114 struct linespec_result *,
118 static void create_breakpoints_sal_default (struct gdbarch *,
119 struct linespec_result *,
120 char *, char *, enum bptype,
121 enum bpdisp, int, int,
123 const struct breakpoint_ops *,
124 int, int, int, unsigned);
126 static void decode_linespec_default (struct breakpoint *, char **,
127 struct symtabs_and_lines *);
129 static void clear_command (char *, int);
131 static void catch_command (char *, int);
133 static int can_use_hardware_watchpoint (struct value *);
135 static void break_command_1 (char *, int, int);
137 static void mention (struct breakpoint *);
139 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
141 const struct breakpoint_ops *);
142 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
143 const struct symtab_and_line *);
145 /* This function is used in gdbtk sources and thus can not be made
147 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
148 struct symtab_and_line,
150 const struct breakpoint_ops *);
152 static struct breakpoint *
153 momentary_breakpoint_from_master (struct breakpoint *orig,
155 const struct breakpoint_ops *ops,
158 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
160 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
164 static void describe_other_breakpoints (struct gdbarch *,
165 struct program_space *, CORE_ADDR,
166 struct obj_section *, int);
168 static int watchpoint_locations_match (struct bp_location *loc1,
169 struct bp_location *loc2);
171 static int breakpoint_location_address_match (struct bp_location *bl,
172 struct address_space *aspace,
175 static void breakpoints_info (char *, int);
177 static void watchpoints_info (char *, int);
179 static int breakpoint_1 (char *, int,
180 int (*) (const struct breakpoint *));
182 static int breakpoint_cond_eval (void *);
184 static void cleanup_executing_breakpoints (void *);
186 static void commands_command (char *, int);
188 static void condition_command (char *, int);
197 static int remove_breakpoint (struct bp_location *, insertion_state_t);
198 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
200 static enum print_stop_action print_bp_stop_message (bpstat bs);
202 static int watchpoint_check (void *);
204 static void maintenance_info_breakpoints (char *, int);
206 static int hw_breakpoint_used_count (void);
208 static int hw_watchpoint_use_count (struct breakpoint *);
210 static int hw_watchpoint_used_count_others (struct breakpoint *except,
212 int *other_type_used);
214 static void hbreak_command (char *, int);
216 static void thbreak_command (char *, int);
218 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
221 static void stop_command (char *arg, int from_tty);
223 static void stopin_command (char *arg, int from_tty);
225 static void stopat_command (char *arg, int from_tty);
227 static void tcatch_command (char *arg, int from_tty);
229 static void detach_single_step_breakpoints (void);
231 static int find_single_step_breakpoint (struct address_space *aspace,
234 static void free_bp_location (struct bp_location *loc);
235 static void incref_bp_location (struct bp_location *loc);
236 static void decref_bp_location (struct bp_location **loc);
238 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
240 /* update_global_location_list's modes of operation wrt to whether to
241 insert locations now. */
242 enum ugll_insert_mode
244 /* Don't insert any breakpoint locations into the inferior, only
245 remove already-inserted locations that no longer should be
246 inserted. Functions that delete a breakpoint or breakpoints
247 should specify this mode, so that deleting a breakpoint doesn't
248 have the side effect of inserting the locations of other
249 breakpoints that are marked not-inserted, but should_be_inserted
250 returns true on them.
252 This behavior is useful is situations close to tear-down -- e.g.,
253 after an exec, while the target still has execution, but
254 breakpoint shadows of the previous executable image should *NOT*
255 be restored to the new image; or before detaching, where the
256 target still has execution and wants to delete breakpoints from
257 GDB's lists, and all breakpoints had already been removed from
261 /* May insert breakpoints iff breakpoints_should_be_inserted_now
262 claims breakpoints should be inserted now. */
265 /* Insert locations now, irrespective of
266 breakpoints_should_be_inserted_now. E.g., say all threads are
267 stopped right now, and the user did "continue". We need to
268 insert breakpoints _before_ resuming the target, but
269 UGLL_MAY_INSERT wouldn't insert them, because
270 breakpoints_should_be_inserted_now returns false at that point,
271 as no thread is running yet. */
275 static void update_global_location_list (enum ugll_insert_mode);
277 static void update_global_location_list_nothrow (enum ugll_insert_mode);
279 static int is_hardware_watchpoint (const struct breakpoint *bpt);
281 static void insert_breakpoint_locations (void);
283 static int syscall_catchpoint_p (struct breakpoint *b);
285 static void tracepoints_info (char *, int);
287 static void delete_trace_command (char *, int);
289 static void enable_trace_command (char *, int);
291 static void disable_trace_command (char *, int);
293 static void trace_pass_command (char *, int);
295 static void set_tracepoint_count (int num);
297 static int is_masked_watchpoint (const struct breakpoint *b);
299 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
301 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
304 static int strace_marker_p (struct breakpoint *b);
306 /* The abstract base class all breakpoint_ops structures inherit
308 struct breakpoint_ops base_breakpoint_ops;
310 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
311 that are implemented on top of software or hardware breakpoints
312 (user breakpoints, internal and momentary breakpoints, etc.). */
313 static struct breakpoint_ops bkpt_base_breakpoint_ops;
315 /* Internal breakpoints class type. */
316 static struct breakpoint_ops internal_breakpoint_ops;
318 /* Momentary breakpoints class type. */
319 static struct breakpoint_ops momentary_breakpoint_ops;
321 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
322 static struct breakpoint_ops longjmp_breakpoint_ops;
324 /* The breakpoint_ops structure to be used in regular user created
326 struct breakpoint_ops bkpt_breakpoint_ops;
328 /* Breakpoints set on probes. */
329 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
331 /* Dynamic printf class type. */
332 struct breakpoint_ops dprintf_breakpoint_ops;
334 /* One (or perhaps two) breakpoints used for software single
337 static void *single_step_breakpoints[2];
338 static struct gdbarch *single_step_gdbarch[2];
340 /* The style in which to perform a dynamic printf. This is a user
341 option because different output options have different tradeoffs;
342 if GDB does the printing, there is better error handling if there
343 is a problem with any of the arguments, but using an inferior
344 function lets you have special-purpose printers and sending of
345 output to the same place as compiled-in print functions. */
347 static const char dprintf_style_gdb[] = "gdb";
348 static const char dprintf_style_call[] = "call";
349 static const char dprintf_style_agent[] = "agent";
350 static const char *const dprintf_style_enums[] = {
356 static const char *dprintf_style = dprintf_style_gdb;
358 /* The function to use for dynamic printf if the preferred style is to
359 call into the inferior. The value is simply a string that is
360 copied into the command, so it can be anything that GDB can
361 evaluate to a callable address, not necessarily a function name. */
363 static char *dprintf_function = "";
365 /* The channel to use for dynamic printf if the preferred style is to
366 call into the inferior; if a nonempty string, it will be passed to
367 the call as the first argument, with the format string as the
368 second. As with the dprintf function, this can be anything that
369 GDB knows how to evaluate, so in addition to common choices like
370 "stderr", this could be an app-specific expression like
371 "mystreams[curlogger]". */
373 static char *dprintf_channel = "";
375 /* True if dprintf commands should continue to operate even if GDB
377 static int disconnected_dprintf = 1;
379 /* A reference-counted struct command_line. This lets multiple
380 breakpoints share a single command list. */
381 struct counted_command_line
383 /* The reference count. */
386 /* The command list. */
387 struct command_line *commands;
390 struct command_line *
391 breakpoint_commands (struct breakpoint *b)
393 return b->commands ? b->commands->commands : NULL;
396 /* Flag indicating that a command has proceeded the inferior past the
397 current breakpoint. */
399 static int breakpoint_proceeded;
402 bpdisp_text (enum bpdisp disp)
404 /* NOTE: the following values are a part of MI protocol and
405 represent values of 'disp' field returned when inferior stops at
407 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
409 return bpdisps[(int) disp];
412 /* Prototypes for exported functions. */
413 /* If FALSE, gdb will not use hardware support for watchpoints, even
414 if such is available. */
415 static int can_use_hw_watchpoints;
418 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
419 struct cmd_list_element *c,
422 fprintf_filtered (file,
423 _("Debugger's willingness to use "
424 "watchpoint hardware is %s.\n"),
428 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
429 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
430 for unrecognized breakpoint locations.
431 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
432 static enum auto_boolean pending_break_support;
434 show_pending_break_support (struct ui_file *file, int from_tty,
435 struct cmd_list_element *c,
438 fprintf_filtered (file,
439 _("Debugger's behavior regarding "
440 "pending breakpoints is %s.\n"),
444 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
445 set with "break" but falling in read-only memory.
446 If 0, gdb will warn about such breakpoints, but won't automatically
447 use hardware breakpoints. */
448 static int automatic_hardware_breakpoints;
450 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
451 struct cmd_list_element *c,
454 fprintf_filtered (file,
455 _("Automatic usage of hardware breakpoints is %s.\n"),
459 /* If on, GDB keeps breakpoints inserted even if the inferior is
460 stopped, and immediately inserts any new breakpoints as soon as
461 they're created. If off (default), GDB keeps breakpoints off of
462 the target as long as possible. That is, it delays inserting
463 breakpoints until the next resume, and removes them again when the
464 target fully stops. This is a bit safer in case GDB crashes while
465 processing user input. */
466 static int always_inserted_mode = 0;
469 show_always_inserted_mode (struct ui_file *file, int from_tty,
470 struct cmd_list_element *c, const char *value)
472 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
477 breakpoints_should_be_inserted_now (void)
479 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
481 /* If breakpoints are global, they should be inserted even if no
482 thread under gdb's control is running, or even if there are
483 no threads under GDB's control yet. */
486 else if (target_has_execution)
488 struct thread_info *tp;
490 if (always_inserted_mode)
492 /* The user wants breakpoints inserted even if all threads
497 ALL_NON_EXITED_THREADS (tp)
506 static const char condition_evaluation_both[] = "host or target";
508 /* Modes for breakpoint condition evaluation. */
509 static const char condition_evaluation_auto[] = "auto";
510 static const char condition_evaluation_host[] = "host";
511 static const char condition_evaluation_target[] = "target";
512 static const char *const condition_evaluation_enums[] = {
513 condition_evaluation_auto,
514 condition_evaluation_host,
515 condition_evaluation_target,
519 /* Global that holds the current mode for breakpoint condition evaluation. */
520 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
522 /* Global that we use to display information to the user (gets its value from
523 condition_evaluation_mode_1. */
524 static const char *condition_evaluation_mode = condition_evaluation_auto;
526 /* Translate a condition evaluation mode MODE into either "host"
527 or "target". This is used mostly to translate from "auto" to the
528 real setting that is being used. It returns the translated
532 translate_condition_evaluation_mode (const char *mode)
534 if (mode == condition_evaluation_auto)
536 if (target_supports_evaluation_of_breakpoint_conditions ())
537 return condition_evaluation_target;
539 return condition_evaluation_host;
545 /* Discovers what condition_evaluation_auto translates to. */
548 breakpoint_condition_evaluation_mode (void)
550 return translate_condition_evaluation_mode (condition_evaluation_mode);
553 /* Return true if GDB should evaluate breakpoint conditions or false
557 gdb_evaluates_breakpoint_condition_p (void)
559 const char *mode = breakpoint_condition_evaluation_mode ();
561 return (mode == condition_evaluation_host);
564 void _initialize_breakpoint (void);
566 /* Are we executing breakpoint commands? */
567 static int executing_breakpoint_commands;
569 /* Are overlay event breakpoints enabled? */
570 static int overlay_events_enabled;
572 /* See description in breakpoint.h. */
573 int target_exact_watchpoints = 0;
575 /* Walk the following statement or block through all breakpoints.
576 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
577 current breakpoint. */
579 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
581 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
582 for (B = breakpoint_chain; \
583 B ? (TMP=B->next, 1): 0; \
586 /* Similar iterator for the low-level breakpoints. SAFE variant is
587 not provided so update_global_location_list must not be called
588 while executing the block of ALL_BP_LOCATIONS. */
590 #define ALL_BP_LOCATIONS(B,BP_TMP) \
591 for (BP_TMP = bp_location; \
592 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
595 /* Iterates through locations with address ADDRESS for the currently selected
596 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
597 to where the loop should start from.
598 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
599 appropriate location to start with. */
601 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
602 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
603 BP_LOCP_TMP = BP_LOCP_START; \
605 && (BP_LOCP_TMP < bp_location + bp_location_count \
606 && (*BP_LOCP_TMP)->address == ADDRESS); \
609 /* Iterator for tracepoints only. */
611 #define ALL_TRACEPOINTS(B) \
612 for (B = breakpoint_chain; B; B = B->next) \
613 if (is_tracepoint (B))
615 /* Chains of all breakpoints defined. */
617 struct breakpoint *breakpoint_chain;
619 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
621 static struct bp_location **bp_location;
623 /* Number of elements of BP_LOCATION. */
625 static unsigned bp_location_count;
627 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
628 ADDRESS for the current elements of BP_LOCATION which get a valid
629 result from bp_location_has_shadow. You can use it for roughly
630 limiting the subrange of BP_LOCATION to scan for shadow bytes for
631 an address you need to read. */
633 static CORE_ADDR bp_location_placed_address_before_address_max;
635 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
636 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
637 BP_LOCATION which get a valid result from bp_location_has_shadow.
638 You can use it for roughly limiting the subrange of BP_LOCATION to
639 scan for shadow bytes for an address you need to read. */
641 static CORE_ADDR bp_location_shadow_len_after_address_max;
643 /* The locations that no longer correspond to any breakpoint, unlinked
644 from bp_location array, but for which a hit may still be reported
646 VEC(bp_location_p) *moribund_locations = NULL;
648 /* Number of last breakpoint made. */
650 static int breakpoint_count;
652 /* The value of `breakpoint_count' before the last command that
653 created breakpoints. If the last (break-like) command created more
654 than one breakpoint, then the difference between BREAKPOINT_COUNT
655 and PREV_BREAKPOINT_COUNT is more than one. */
656 static int prev_breakpoint_count;
658 /* Number of last tracepoint made. */
660 static int tracepoint_count;
662 static struct cmd_list_element *breakpoint_set_cmdlist;
663 static struct cmd_list_element *breakpoint_show_cmdlist;
664 struct cmd_list_element *save_cmdlist;
666 /* Return whether a breakpoint is an active enabled breakpoint. */
668 breakpoint_enabled (struct breakpoint *b)
670 return (b->enable_state == bp_enabled);
673 /* Set breakpoint count to NUM. */
676 set_breakpoint_count (int num)
678 prev_breakpoint_count = breakpoint_count;
679 breakpoint_count = num;
680 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
683 /* Used by `start_rbreak_breakpoints' below, to record the current
684 breakpoint count before "rbreak" creates any breakpoint. */
685 static int rbreak_start_breakpoint_count;
687 /* Called at the start an "rbreak" command to record the first
691 start_rbreak_breakpoints (void)
693 rbreak_start_breakpoint_count = breakpoint_count;
696 /* Called at the end of an "rbreak" command to record the last
700 end_rbreak_breakpoints (void)
702 prev_breakpoint_count = rbreak_start_breakpoint_count;
705 /* Used in run_command to zero the hit count when a new run starts. */
708 clear_breakpoint_hit_counts (void)
710 struct breakpoint *b;
716 /* Allocate a new counted_command_line with reference count of 1.
717 The new structure owns COMMANDS. */
719 static struct counted_command_line *
720 alloc_counted_command_line (struct command_line *commands)
722 struct counted_command_line *result
723 = xmalloc (sizeof (struct counted_command_line));
726 result->commands = commands;
730 /* Increment reference count. This does nothing if CMD is NULL. */
733 incref_counted_command_line (struct counted_command_line *cmd)
739 /* Decrement reference count. If the reference count reaches 0,
740 destroy the counted_command_line. Sets *CMDP to NULL. This does
741 nothing if *CMDP is NULL. */
744 decref_counted_command_line (struct counted_command_line **cmdp)
748 if (--(*cmdp)->refc == 0)
750 free_command_lines (&(*cmdp)->commands);
757 /* A cleanup function that calls decref_counted_command_line. */
760 do_cleanup_counted_command_line (void *arg)
762 decref_counted_command_line (arg);
765 /* Create a cleanup that calls decref_counted_command_line on the
768 static struct cleanup *
769 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
771 return make_cleanup (do_cleanup_counted_command_line, cmdp);
775 /* Return the breakpoint with the specified number, or NULL
776 if the number does not refer to an existing breakpoint. */
779 get_breakpoint (int num)
781 struct breakpoint *b;
784 if (b->number == num)
792 /* Mark locations as "conditions have changed" in case the target supports
793 evaluating conditions on its side. */
796 mark_breakpoint_modified (struct breakpoint *b)
798 struct bp_location *loc;
800 /* This is only meaningful if the target is
801 evaluating conditions and if the user has
802 opted for condition evaluation on the target's
804 if (gdb_evaluates_breakpoint_condition_p ()
805 || !target_supports_evaluation_of_breakpoint_conditions ())
808 if (!is_breakpoint (b))
811 for (loc = b->loc; loc; loc = loc->next)
812 loc->condition_changed = condition_modified;
815 /* Mark location as "conditions have changed" in case the target supports
816 evaluating conditions on its side. */
819 mark_breakpoint_location_modified (struct bp_location *loc)
821 /* This is only meaningful if the target is
822 evaluating conditions and if the user has
823 opted for condition evaluation on the target's
825 if (gdb_evaluates_breakpoint_condition_p ()
826 || !target_supports_evaluation_of_breakpoint_conditions ())
830 if (!is_breakpoint (loc->owner))
833 loc->condition_changed = condition_modified;
836 /* Sets the condition-evaluation mode using the static global
837 condition_evaluation_mode. */
840 set_condition_evaluation_mode (char *args, int from_tty,
841 struct cmd_list_element *c)
843 const char *old_mode, *new_mode;
845 if ((condition_evaluation_mode_1 == condition_evaluation_target)
846 && !target_supports_evaluation_of_breakpoint_conditions ())
848 condition_evaluation_mode_1 = condition_evaluation_mode;
849 warning (_("Target does not support breakpoint condition evaluation.\n"
850 "Using host evaluation mode instead."));
854 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
855 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
857 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
858 settings was "auto". */
859 condition_evaluation_mode = condition_evaluation_mode_1;
861 /* Only update the mode if the user picked a different one. */
862 if (new_mode != old_mode)
864 struct bp_location *loc, **loc_tmp;
865 /* If the user switched to a different evaluation mode, we
866 need to synch the changes with the target as follows:
868 "host" -> "target": Send all (valid) conditions to the target.
869 "target" -> "host": Remove all the conditions from the target.
872 if (new_mode == condition_evaluation_target)
874 /* Mark everything modified and synch conditions with the
876 ALL_BP_LOCATIONS (loc, loc_tmp)
877 mark_breakpoint_location_modified (loc);
881 /* Manually mark non-duplicate locations to synch conditions
882 with the target. We do this to remove all the conditions the
883 target knows about. */
884 ALL_BP_LOCATIONS (loc, loc_tmp)
885 if (is_breakpoint (loc->owner) && loc->inserted)
886 loc->needs_update = 1;
890 update_global_location_list (UGLL_MAY_INSERT);
896 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
897 what "auto" is translating to. */
900 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
901 struct cmd_list_element *c, const char *value)
903 if (condition_evaluation_mode == condition_evaluation_auto)
904 fprintf_filtered (file,
905 _("Breakpoint condition evaluation "
906 "mode is %s (currently %s).\n"),
908 breakpoint_condition_evaluation_mode ());
910 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
914 /* A comparison function for bp_location AP and BP that is used by
915 bsearch. This comparison function only cares about addresses, unlike
916 the more general bp_location_compare function. */
919 bp_location_compare_addrs (const void *ap, const void *bp)
921 struct bp_location *a = *(void **) ap;
922 struct bp_location *b = *(void **) bp;
924 if (a->address == b->address)
927 return ((a->address > b->address) - (a->address < b->address));
930 /* Helper function to skip all bp_locations with addresses
931 less than ADDRESS. It returns the first bp_location that
932 is greater than or equal to ADDRESS. If none is found, just
935 static struct bp_location **
936 get_first_locp_gte_addr (CORE_ADDR address)
938 struct bp_location dummy_loc;
939 struct bp_location *dummy_locp = &dummy_loc;
940 struct bp_location **locp_found = NULL;
942 /* Initialize the dummy location's address field. */
943 memset (&dummy_loc, 0, sizeof (struct bp_location));
944 dummy_loc.address = address;
946 /* Find a close match to the first location at ADDRESS. */
947 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
948 sizeof (struct bp_location **),
949 bp_location_compare_addrs);
951 /* Nothing was found, nothing left to do. */
952 if (locp_found == NULL)
955 /* We may have found a location that is at ADDRESS but is not the first in the
956 location's list. Go backwards (if possible) and locate the first one. */
957 while ((locp_found - 1) >= bp_location
958 && (*(locp_found - 1))->address == address)
965 set_breakpoint_condition (struct breakpoint *b, char *exp,
968 xfree (b->cond_string);
969 b->cond_string = NULL;
971 if (is_watchpoint (b))
973 struct watchpoint *w = (struct watchpoint *) b;
980 struct bp_location *loc;
982 for (loc = b->loc; loc; loc = loc->next)
987 /* No need to free the condition agent expression
988 bytecode (if we have one). We will handle this
989 when we go through update_global_location_list. */
996 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
1000 const char *arg = exp;
1002 /* I don't know if it matters whether this is the string the user
1003 typed in or the decompiled expression. */
1004 b->cond_string = xstrdup (arg);
1005 b->condition_not_parsed = 0;
1007 if (is_watchpoint (b))
1009 struct watchpoint *w = (struct watchpoint *) b;
1011 innermost_block = NULL;
1013 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1015 error (_("Junk at end of expression"));
1016 w->cond_exp_valid_block = innermost_block;
1020 struct bp_location *loc;
1022 for (loc = b->loc; loc; loc = loc->next)
1026 parse_exp_1 (&arg, loc->address,
1027 block_for_pc (loc->address), 0);
1029 error (_("Junk at end of expression"));
1033 mark_breakpoint_modified (b);
1035 observer_notify_breakpoint_modified (b);
1038 /* Completion for the "condition" command. */
1040 static VEC (char_ptr) *
1041 condition_completer (struct cmd_list_element *cmd,
1042 const char *text, const char *word)
1046 text = skip_spaces_const (text);
1047 space = skip_to_space_const (text);
1051 struct breakpoint *b;
1052 VEC (char_ptr) *result = NULL;
1056 /* We don't support completion of history indices. */
1057 if (isdigit (text[1]))
1059 return complete_internalvar (&text[1]);
1062 /* We're completing the breakpoint number. */
1063 len = strlen (text);
1069 xsnprintf (number, sizeof (number), "%d", b->number);
1071 if (strncmp (number, text, len) == 0)
1072 VEC_safe_push (char_ptr, result, xstrdup (number));
1078 /* We're completing the expression part. */
1079 text = skip_spaces_const (space);
1080 return expression_completer (cmd, text, word);
1083 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1086 condition_command (char *arg, int from_tty)
1088 struct breakpoint *b;
1093 error_no_arg (_("breakpoint number"));
1096 bnum = get_number (&p);
1098 error (_("Bad breakpoint argument: '%s'"), arg);
1101 if (b->number == bnum)
1103 /* Check if this breakpoint has a "stop" method implemented in an
1104 extension language. This method and conditions entered into GDB
1105 from the CLI are mutually exclusive. */
1106 const struct extension_language_defn *extlang
1107 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1109 if (extlang != NULL)
1111 error (_("Only one stop condition allowed. There is currently"
1112 " a %s stop condition defined for this breakpoint."),
1113 ext_lang_capitalized_name (extlang));
1115 set_breakpoint_condition (b, p, from_tty);
1117 if (is_breakpoint (b))
1118 update_global_location_list (UGLL_MAY_INSERT);
1123 error (_("No breakpoint number %d."), bnum);
1126 /* Check that COMMAND do not contain commands that are suitable
1127 only for tracepoints and not suitable for ordinary breakpoints.
1128 Throw if any such commands is found. */
1131 check_no_tracepoint_commands (struct command_line *commands)
1133 struct command_line *c;
1135 for (c = commands; c; c = c->next)
1139 if (c->control_type == while_stepping_control)
1140 error (_("The 'while-stepping' command can "
1141 "only be used for tracepoints"));
1143 for (i = 0; i < c->body_count; ++i)
1144 check_no_tracepoint_commands ((c->body_list)[i]);
1146 /* Not that command parsing removes leading whitespace and comment
1147 lines and also empty lines. So, we only need to check for
1148 command directly. */
1149 if (strstr (c->line, "collect ") == c->line)
1150 error (_("The 'collect' command can only be used for tracepoints"));
1152 if (strstr (c->line, "teval ") == c->line)
1153 error (_("The 'teval' command can only be used for tracepoints"));
1157 /* Encapsulate tests for different types of tracepoints. */
1160 is_tracepoint_type (enum bptype type)
1162 return (type == bp_tracepoint
1163 || type == bp_fast_tracepoint
1164 || type == bp_static_tracepoint);
1168 is_tracepoint (const struct breakpoint *b)
1170 return is_tracepoint_type (b->type);
1173 /* A helper function that validates that COMMANDS are valid for a
1174 breakpoint. This function will throw an exception if a problem is
1178 validate_commands_for_breakpoint (struct breakpoint *b,
1179 struct command_line *commands)
1181 if (is_tracepoint (b))
1183 struct tracepoint *t = (struct tracepoint *) b;
1184 struct command_line *c;
1185 struct command_line *while_stepping = 0;
1187 /* Reset the while-stepping step count. The previous commands
1188 might have included a while-stepping action, while the new
1192 /* We need to verify that each top-level element of commands is
1193 valid for tracepoints, that there's at most one
1194 while-stepping element, and that the while-stepping's body
1195 has valid tracing commands excluding nested while-stepping.
1196 We also need to validate the tracepoint action line in the
1197 context of the tracepoint --- validate_actionline actually
1198 has side effects, like setting the tracepoint's
1199 while-stepping STEP_COUNT, in addition to checking if the
1200 collect/teval actions parse and make sense in the
1201 tracepoint's context. */
1202 for (c = commands; c; c = c->next)
1204 if (c->control_type == while_stepping_control)
1206 if (b->type == bp_fast_tracepoint)
1207 error (_("The 'while-stepping' command "
1208 "cannot be used for fast tracepoint"));
1209 else if (b->type == bp_static_tracepoint)
1210 error (_("The 'while-stepping' command "
1211 "cannot be used for static tracepoint"));
1214 error (_("The 'while-stepping' command "
1215 "can be used only once"));
1220 validate_actionline (c->line, b);
1224 struct command_line *c2;
1226 gdb_assert (while_stepping->body_count == 1);
1227 c2 = while_stepping->body_list[0];
1228 for (; c2; c2 = c2->next)
1230 if (c2->control_type == while_stepping_control)
1231 error (_("The 'while-stepping' command cannot be nested"));
1237 check_no_tracepoint_commands (commands);
1241 /* Return a vector of all the static tracepoints set at ADDR. The
1242 caller is responsible for releasing the vector. */
1245 static_tracepoints_here (CORE_ADDR addr)
1247 struct breakpoint *b;
1248 VEC(breakpoint_p) *found = 0;
1249 struct bp_location *loc;
1252 if (b->type == bp_static_tracepoint)
1254 for (loc = b->loc; loc; loc = loc->next)
1255 if (loc->address == addr)
1256 VEC_safe_push(breakpoint_p, found, b);
1262 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1263 validate that only allowed commands are included. */
1266 breakpoint_set_commands (struct breakpoint *b,
1267 struct command_line *commands)
1269 validate_commands_for_breakpoint (b, commands);
1271 decref_counted_command_line (&b->commands);
1272 b->commands = alloc_counted_command_line (commands);
1273 observer_notify_breakpoint_modified (b);
1276 /* Set the internal `silent' flag on the breakpoint. Note that this
1277 is not the same as the "silent" that may appear in the breakpoint's
1281 breakpoint_set_silent (struct breakpoint *b, int silent)
1283 int old_silent = b->silent;
1286 if (old_silent != silent)
1287 observer_notify_breakpoint_modified (b);
1290 /* Set the thread for this breakpoint. If THREAD is -1, make the
1291 breakpoint work for any thread. */
1294 breakpoint_set_thread (struct breakpoint *b, int thread)
1296 int old_thread = b->thread;
1299 if (old_thread != thread)
1300 observer_notify_breakpoint_modified (b);
1303 /* Set the task for this breakpoint. If TASK is 0, make the
1304 breakpoint work for any task. */
1307 breakpoint_set_task (struct breakpoint *b, int task)
1309 int old_task = b->task;
1312 if (old_task != task)
1313 observer_notify_breakpoint_modified (b);
1317 check_tracepoint_command (char *line, void *closure)
1319 struct breakpoint *b = closure;
1321 validate_actionline (line, b);
1324 /* A structure used to pass information through
1325 map_breakpoint_numbers. */
1327 struct commands_info
1329 /* True if the command was typed at a tty. */
1332 /* The breakpoint range spec. */
1335 /* Non-NULL if the body of the commands are being read from this
1336 already-parsed command. */
1337 struct command_line *control;
1339 /* The command lines read from the user, or NULL if they have not
1341 struct counted_command_line *cmd;
1344 /* A callback for map_breakpoint_numbers that sets the commands for
1345 commands_command. */
1348 do_map_commands_command (struct breakpoint *b, void *data)
1350 struct commands_info *info = data;
1352 if (info->cmd == NULL)
1354 struct command_line *l;
1356 if (info->control != NULL)
1357 l = copy_command_lines (info->control->body_list[0]);
1360 struct cleanup *old_chain;
1363 str = xstrprintf (_("Type commands for breakpoint(s) "
1364 "%s, one per line."),
1367 old_chain = make_cleanup (xfree, str);
1369 l = read_command_lines (str,
1372 ? check_tracepoint_command : 0),
1375 do_cleanups (old_chain);
1378 info->cmd = alloc_counted_command_line (l);
1381 /* If a breakpoint was on the list more than once, we don't need to
1383 if (b->commands != info->cmd)
1385 validate_commands_for_breakpoint (b, info->cmd->commands);
1386 incref_counted_command_line (info->cmd);
1387 decref_counted_command_line (&b->commands);
1388 b->commands = info->cmd;
1389 observer_notify_breakpoint_modified (b);
1394 commands_command_1 (char *arg, int from_tty,
1395 struct command_line *control)
1397 struct cleanup *cleanups;
1398 struct commands_info info;
1400 info.from_tty = from_tty;
1401 info.control = control;
1403 /* If we read command lines from the user, then `info' will hold an
1404 extra reference to the commands that we must clean up. */
1405 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1407 if (arg == NULL || !*arg)
1409 if (breakpoint_count - prev_breakpoint_count > 1)
1410 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1412 else if (breakpoint_count > 0)
1413 arg = xstrprintf ("%d", breakpoint_count);
1416 /* So that we don't try to free the incoming non-NULL
1417 argument in the cleanup below. Mapping breakpoint
1418 numbers will fail in this case. */
1423 /* The command loop has some static state, so we need to preserve
1425 arg = xstrdup (arg);
1428 make_cleanup (xfree, arg);
1432 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1434 if (info.cmd == NULL)
1435 error (_("No breakpoints specified."));
1437 do_cleanups (cleanups);
1441 commands_command (char *arg, int from_tty)
1443 commands_command_1 (arg, from_tty, NULL);
1446 /* Like commands_command, but instead of reading the commands from
1447 input stream, takes them from an already parsed command structure.
1449 This is used by cli-script.c to DTRT with breakpoint commands
1450 that are part of if and while bodies. */
1451 enum command_control_type
1452 commands_from_control_command (char *arg, struct command_line *cmd)
1454 commands_command_1 (arg, 0, cmd);
1455 return simple_control;
1458 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1461 bp_location_has_shadow (struct bp_location *bl)
1463 if (bl->loc_type != bp_loc_software_breakpoint)
1467 if (bl->target_info.shadow_len == 0)
1468 /* BL isn't valid, or doesn't shadow memory. */
1473 /* Update BUF, which is LEN bytes read from the target address
1474 MEMADDR, by replacing a memory breakpoint with its shadowed
1477 If READBUF is not NULL, this buffer must not overlap with the of
1478 the breakpoint location's shadow_contents buffer. Otherwise, a
1479 failed assertion internal error will be raised. */
1482 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1483 const gdb_byte *writebuf_org,
1484 ULONGEST memaddr, LONGEST len,
1485 struct bp_target_info *target_info,
1486 struct gdbarch *gdbarch)
1488 /* Now do full processing of the found relevant range of elements. */
1489 CORE_ADDR bp_addr = 0;
1493 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1494 current_program_space->aspace, 0))
1496 /* The breakpoint is inserted in a different address space. */
1500 /* Addresses and length of the part of the breakpoint that
1502 bp_addr = target_info->placed_address;
1503 bp_size = target_info->shadow_len;
1505 if (bp_addr + bp_size <= memaddr)
1507 /* The breakpoint is entirely before the chunk of memory we are
1512 if (bp_addr >= memaddr + len)
1514 /* The breakpoint is entirely after the chunk of memory we are
1519 /* Offset within shadow_contents. */
1520 if (bp_addr < memaddr)
1522 /* Only copy the second part of the breakpoint. */
1523 bp_size -= memaddr - bp_addr;
1524 bptoffset = memaddr - bp_addr;
1528 if (bp_addr + bp_size > memaddr + len)
1530 /* Only copy the first part of the breakpoint. */
1531 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1534 if (readbuf != NULL)
1536 /* Verify that the readbuf buffer does not overlap with the
1537 shadow_contents buffer. */
1538 gdb_assert (target_info->shadow_contents >= readbuf + len
1539 || readbuf >= (target_info->shadow_contents
1540 + target_info->shadow_len));
1542 /* Update the read buffer with this inserted breakpoint's
1544 memcpy (readbuf + bp_addr - memaddr,
1545 target_info->shadow_contents + bptoffset, bp_size);
1549 const unsigned char *bp;
1550 CORE_ADDR placed_address = target_info->placed_address;
1551 int placed_size = target_info->placed_size;
1553 /* Update the shadow with what we want to write to memory. */
1554 memcpy (target_info->shadow_contents + bptoffset,
1555 writebuf_org + bp_addr - memaddr, bp_size);
1557 /* Determine appropriate breakpoint contents and size for this
1559 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1561 /* Update the final write buffer with this inserted
1562 breakpoint's INSN. */
1563 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1567 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1568 by replacing any memory breakpoints with their shadowed contents.
1570 If READBUF is not NULL, this buffer must not overlap with any of
1571 the breakpoint location's shadow_contents buffers. Otherwise,
1572 a failed assertion internal error will be raised.
1574 The range of shadowed area by each bp_location is:
1575 bl->address - bp_location_placed_address_before_address_max
1576 up to bl->address + bp_location_shadow_len_after_address_max
1577 The range we were requested to resolve shadows for is:
1578 memaddr ... memaddr + len
1579 Thus the safe cutoff boundaries for performance optimization are
1580 memaddr + len <= (bl->address
1581 - bp_location_placed_address_before_address_max)
1583 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1586 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1587 const gdb_byte *writebuf_org,
1588 ULONGEST memaddr, LONGEST len)
1590 /* Left boundary, right boundary and median element of our binary
1592 unsigned bc_l, bc_r, bc;
1595 /* Find BC_L which is a leftmost element which may affect BUF
1596 content. It is safe to report lower value but a failure to
1597 report higher one. */
1600 bc_r = bp_location_count;
1601 while (bc_l + 1 < bc_r)
1603 struct bp_location *bl;
1605 bc = (bc_l + bc_r) / 2;
1606 bl = bp_location[bc];
1608 /* Check first BL->ADDRESS will not overflow due to the added
1609 constant. Then advance the left boundary only if we are sure
1610 the BC element can in no way affect the BUF content (MEMADDR
1611 to MEMADDR + LEN range).
1613 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1614 offset so that we cannot miss a breakpoint with its shadow
1615 range tail still reaching MEMADDR. */
1617 if ((bl->address + bp_location_shadow_len_after_address_max
1619 && (bl->address + bp_location_shadow_len_after_address_max
1626 /* Due to the binary search above, we need to make sure we pick the
1627 first location that's at BC_L's address. E.g., if there are
1628 multiple locations at the same address, BC_L may end up pointing
1629 at a duplicate location, and miss the "master"/"inserted"
1630 location. Say, given locations L1, L2 and L3 at addresses A and
1633 L1@A, L2@A, L3@B, ...
1635 BC_L could end up pointing at location L2, while the "master"
1636 location could be L1. Since the `loc->inserted' flag is only set
1637 on "master" locations, we'd forget to restore the shadow of L1
1640 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1643 /* Now do full processing of the found relevant range of elements. */
1645 for (bc = bc_l; bc < bp_location_count; bc++)
1647 struct bp_location *bl = bp_location[bc];
1648 CORE_ADDR bp_addr = 0;
1652 /* bp_location array has BL->OWNER always non-NULL. */
1653 if (bl->owner->type == bp_none)
1654 warning (_("reading through apparently deleted breakpoint #%d?"),
1657 /* Performance optimization: any further element can no longer affect BUF
1660 if (bl->address >= bp_location_placed_address_before_address_max
1661 && memaddr + len <= (bl->address
1662 - bp_location_placed_address_before_address_max))
1665 if (!bp_location_has_shadow (bl))
1668 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1669 memaddr, len, &bl->target_info, bl->gdbarch);
1672 /* Now process single-step breakpoints. These are not found in the
1673 bp_location array. */
1674 for (i = 0; i < 2; i++)
1676 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
1680 struct gdbarch *gdbarch = single_step_gdbarch[i];
1682 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1683 memaddr, len, bp_tgt, gdbarch);
1690 /* Return true if BPT is either a software breakpoint or a hardware
1694 is_breakpoint (const struct breakpoint *bpt)
1696 return (bpt->type == bp_breakpoint
1697 || bpt->type == bp_hardware_breakpoint
1698 || bpt->type == bp_dprintf);
1701 /* Return true if BPT is of any hardware watchpoint kind. */
1704 is_hardware_watchpoint (const struct breakpoint *bpt)
1706 return (bpt->type == bp_hardware_watchpoint
1707 || bpt->type == bp_read_watchpoint
1708 || bpt->type == bp_access_watchpoint);
1711 /* Return true if BPT is of any watchpoint kind, hardware or
1715 is_watchpoint (const struct breakpoint *bpt)
1717 return (is_hardware_watchpoint (bpt)
1718 || bpt->type == bp_watchpoint);
1721 /* Returns true if the current thread and its running state are safe
1722 to evaluate or update watchpoint B. Watchpoints on local
1723 expressions need to be evaluated in the context of the thread that
1724 was current when the watchpoint was created, and, that thread needs
1725 to be stopped to be able to select the correct frame context.
1726 Watchpoints on global expressions can be evaluated on any thread,
1727 and in any state. It is presently left to the target allowing
1728 memory accesses when threads are running. */
1731 watchpoint_in_thread_scope (struct watchpoint *b)
1733 return (b->base.pspace == current_program_space
1734 && (ptid_equal (b->watchpoint_thread, null_ptid)
1735 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1736 && !is_executing (inferior_ptid))));
1739 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1740 associated bp_watchpoint_scope breakpoint. */
1743 watchpoint_del_at_next_stop (struct watchpoint *w)
1745 struct breakpoint *b = &w->base;
1747 if (b->related_breakpoint != b)
1749 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1750 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1751 b->related_breakpoint->disposition = disp_del_at_next_stop;
1752 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1753 b->related_breakpoint = b;
1755 b->disposition = disp_del_at_next_stop;
1758 /* Extract a bitfield value from value VAL using the bit parameters contained in
1761 static struct value *
1762 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1764 struct value *bit_val;
1769 bit_val = allocate_value (value_type (val));
1771 unpack_value_bitfield (bit_val,
1774 value_contents_for_printing (val),
1781 /* Assuming that B is a watchpoint:
1782 - Reparse watchpoint expression, if REPARSE is non-zero
1783 - Evaluate expression and store the result in B->val
1784 - Evaluate the condition if there is one, and store the result
1786 - Update the list of values that must be watched in B->loc.
1788 If the watchpoint disposition is disp_del_at_next_stop, then do
1789 nothing. If this is local watchpoint that is out of scope, delete
1792 Even with `set breakpoint always-inserted on' the watchpoints are
1793 removed + inserted on each stop here. Normal breakpoints must
1794 never be removed because they might be missed by a running thread
1795 when debugging in non-stop mode. On the other hand, hardware
1796 watchpoints (is_hardware_watchpoint; processed here) are specific
1797 to each LWP since they are stored in each LWP's hardware debug
1798 registers. Therefore, such LWP must be stopped first in order to
1799 be able to modify its hardware watchpoints.
1801 Hardware watchpoints must be reset exactly once after being
1802 presented to the user. It cannot be done sooner, because it would
1803 reset the data used to present the watchpoint hit to the user. And
1804 it must not be done later because it could display the same single
1805 watchpoint hit during multiple GDB stops. Note that the latter is
1806 relevant only to the hardware watchpoint types bp_read_watchpoint
1807 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1808 not user-visible - its hit is suppressed if the memory content has
1811 The following constraints influence the location where we can reset
1812 hardware watchpoints:
1814 * target_stopped_by_watchpoint and target_stopped_data_address are
1815 called several times when GDB stops.
1818 * Multiple hardware watchpoints can be hit at the same time,
1819 causing GDB to stop. GDB only presents one hardware watchpoint
1820 hit at a time as the reason for stopping, and all the other hits
1821 are presented later, one after the other, each time the user
1822 requests the execution to be resumed. Execution is not resumed
1823 for the threads still having pending hit event stored in
1824 LWP_INFO->STATUS. While the watchpoint is already removed from
1825 the inferior on the first stop the thread hit event is kept being
1826 reported from its cached value by linux_nat_stopped_data_address
1827 until the real thread resume happens after the watchpoint gets
1828 presented and thus its LWP_INFO->STATUS gets reset.
1830 Therefore the hardware watchpoint hit can get safely reset on the
1831 watchpoint removal from inferior. */
1834 update_watchpoint (struct watchpoint *b, int reparse)
1836 int within_current_scope;
1837 struct frame_id saved_frame_id;
1840 /* If this is a local watchpoint, we only want to check if the
1841 watchpoint frame is in scope if the current thread is the thread
1842 that was used to create the watchpoint. */
1843 if (!watchpoint_in_thread_scope (b))
1846 if (b->base.disposition == disp_del_at_next_stop)
1851 /* Determine if the watchpoint is within scope. */
1852 if (b->exp_valid_block == NULL)
1853 within_current_scope = 1;
1856 struct frame_info *fi = get_current_frame ();
1857 struct gdbarch *frame_arch = get_frame_arch (fi);
1858 CORE_ADDR frame_pc = get_frame_pc (fi);
1860 /* If we're in a function epilogue, unwinding may not work
1861 properly, so do not attempt to recreate locations at this
1862 point. See similar comments in watchpoint_check. */
1863 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1866 /* Save the current frame's ID so we can restore it after
1867 evaluating the watchpoint expression on its own frame. */
1868 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1869 took a frame parameter, so that we didn't have to change the
1872 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1874 fi = frame_find_by_id (b->watchpoint_frame);
1875 within_current_scope = (fi != NULL);
1876 if (within_current_scope)
1880 /* We don't free locations. They are stored in the bp_location array
1881 and update_global_location_list will eventually delete them and
1882 remove breakpoints if needed. */
1885 if (within_current_scope && reparse)
1894 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1895 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1896 /* If the meaning of expression itself changed, the old value is
1897 no longer relevant. We don't want to report a watchpoint hit
1898 to the user when the old value and the new value may actually
1899 be completely different objects. */
1900 value_free (b->val);
1904 /* Note that unlike with breakpoints, the watchpoint's condition
1905 expression is stored in the breakpoint object, not in the
1906 locations (re)created below. */
1907 if (b->base.cond_string != NULL)
1909 if (b->cond_exp != NULL)
1911 xfree (b->cond_exp);
1915 s = b->base.cond_string;
1916 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1920 /* If we failed to parse the expression, for example because
1921 it refers to a global variable in a not-yet-loaded shared library,
1922 don't try to insert watchpoint. We don't automatically delete
1923 such watchpoint, though, since failure to parse expression
1924 is different from out-of-scope watchpoint. */
1925 if (!target_has_execution)
1927 /* Without execution, memory can't change. No use to try and
1928 set watchpoint locations. The watchpoint will be reset when
1929 the target gains execution, through breakpoint_re_set. */
1930 if (!can_use_hw_watchpoints)
1932 if (b->base.ops->works_in_software_mode (&b->base))
1933 b->base.type = bp_watchpoint;
1935 error (_("Can't set read/access watchpoint when "
1936 "hardware watchpoints are disabled."));
1939 else if (within_current_scope && b->exp)
1942 struct value *val_chain, *v, *result, *next;
1943 struct program_space *frame_pspace;
1945 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1947 /* Avoid setting b->val if it's already set. The meaning of
1948 b->val is 'the last value' user saw, and we should update
1949 it only if we reported that last value to user. As it
1950 happens, the code that reports it updates b->val directly.
1951 We don't keep track of the memory value for masked
1953 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1955 if (b->val_bitsize != 0)
1957 v = extract_bitfield_from_watchpoint_value (b, v);
1965 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1967 /* Look at each value on the value chain. */
1968 for (v = val_chain; v; v = value_next (v))
1970 /* If it's a memory location, and GDB actually needed
1971 its contents to evaluate the expression, then we
1972 must watch it. If the first value returned is
1973 still lazy, that means an error occurred reading it;
1974 watch it anyway in case it becomes readable. */
1975 if (VALUE_LVAL (v) == lval_memory
1976 && (v == val_chain || ! value_lazy (v)))
1978 struct type *vtype = check_typedef (value_type (v));
1980 /* We only watch structs and arrays if user asked
1981 for it explicitly, never if they just happen to
1982 appear in the middle of some value chain. */
1984 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1985 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1989 struct bp_location *loc, **tmp;
1990 int bitpos = 0, bitsize = 0;
1992 if (value_bitsize (v) != 0)
1994 /* Extract the bit parameters out from the bitfield
1996 bitpos = value_bitpos (v);
1997 bitsize = value_bitsize (v);
1999 else if (v == result && b->val_bitsize != 0)
2001 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2002 lvalue whose bit parameters are saved in the fields
2003 VAL_BITPOS and VAL_BITSIZE. */
2004 bitpos = b->val_bitpos;
2005 bitsize = b->val_bitsize;
2008 addr = value_address (v);
2011 /* Skip the bytes that don't contain the bitfield. */
2016 if (b->base.type == bp_read_watchpoint)
2018 else if (b->base.type == bp_access_watchpoint)
2021 loc = allocate_bp_location (&b->base);
2022 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
2025 loc->gdbarch = get_type_arch (value_type (v));
2027 loc->pspace = frame_pspace;
2028 loc->address = addr;
2032 /* Just cover the bytes that make up the bitfield. */
2033 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2036 loc->length = TYPE_LENGTH (value_type (v));
2038 loc->watchpoint_type = type;
2043 /* Change the type of breakpoint between hardware assisted or
2044 an ordinary watchpoint depending on the hardware support
2045 and free hardware slots. REPARSE is set when the inferior
2050 enum bp_loc_type loc_type;
2051 struct bp_location *bl;
2053 reg_cnt = can_use_hardware_watchpoint (val_chain);
2057 int i, target_resources_ok, other_type_used;
2060 /* Use an exact watchpoint when there's only one memory region to be
2061 watched, and only one debug register is needed to watch it. */
2062 b->exact = target_exact_watchpoints && reg_cnt == 1;
2064 /* We need to determine how many resources are already
2065 used for all other hardware watchpoints plus this one
2066 to see if we still have enough resources to also fit
2067 this watchpoint in as well. */
2069 /* If this is a software watchpoint, we try to turn it
2070 to a hardware one -- count resources as if B was of
2071 hardware watchpoint type. */
2072 type = b->base.type;
2073 if (type == bp_watchpoint)
2074 type = bp_hardware_watchpoint;
2076 /* This watchpoint may or may not have been placed on
2077 the list yet at this point (it won't be in the list
2078 if we're trying to create it for the first time,
2079 through watch_command), so always account for it
2082 /* Count resources used by all watchpoints except B. */
2083 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2085 /* Add in the resources needed for B. */
2086 i += hw_watchpoint_use_count (&b->base);
2089 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2090 if (target_resources_ok <= 0)
2092 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2094 if (target_resources_ok == 0 && !sw_mode)
2095 error (_("Target does not support this type of "
2096 "hardware watchpoint."));
2097 else if (target_resources_ok < 0 && !sw_mode)
2098 error (_("There are not enough available hardware "
2099 "resources for this watchpoint."));
2101 /* Downgrade to software watchpoint. */
2102 b->base.type = bp_watchpoint;
2106 /* If this was a software watchpoint, we've just
2107 found we have enough resources to turn it to a
2108 hardware watchpoint. Otherwise, this is a
2110 b->base.type = type;
2113 else if (!b->base.ops->works_in_software_mode (&b->base))
2115 if (!can_use_hw_watchpoints)
2116 error (_("Can't set read/access watchpoint when "
2117 "hardware watchpoints are disabled."));
2119 error (_("Expression cannot be implemented with "
2120 "read/access watchpoint."));
2123 b->base.type = bp_watchpoint;
2125 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2126 : bp_loc_hardware_watchpoint);
2127 for (bl = b->base.loc; bl; bl = bl->next)
2128 bl->loc_type = loc_type;
2131 for (v = val_chain; v; v = next)
2133 next = value_next (v);
2138 /* If a software watchpoint is not watching any memory, then the
2139 above left it without any location set up. But,
2140 bpstat_stop_status requires a location to be able to report
2141 stops, so make sure there's at least a dummy one. */
2142 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2144 struct breakpoint *base = &b->base;
2145 base->loc = allocate_bp_location (base);
2146 base->loc->pspace = frame_pspace;
2147 base->loc->address = -1;
2148 base->loc->length = -1;
2149 base->loc->watchpoint_type = -1;
2152 else if (!within_current_scope)
2154 printf_filtered (_("\
2155 Watchpoint %d deleted because the program has left the block\n\
2156 in which its expression is valid.\n"),
2158 watchpoint_del_at_next_stop (b);
2161 /* Restore the selected frame. */
2163 select_frame (frame_find_by_id (saved_frame_id));
2167 /* Returns 1 iff breakpoint location should be
2168 inserted in the inferior. We don't differentiate the type of BL's owner
2169 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2170 breakpoint_ops is not defined, because in insert_bp_location,
2171 tracepoint's insert_location will not be called. */
2173 should_be_inserted (struct bp_location *bl)
2175 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2178 if (bl->owner->disposition == disp_del_at_next_stop)
2181 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2184 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2187 /* This is set for example, when we're attached to the parent of a
2188 vfork, and have detached from the child. The child is running
2189 free, and we expect it to do an exec or exit, at which point the
2190 OS makes the parent schedulable again (and the target reports
2191 that the vfork is done). Until the child is done with the shared
2192 memory region, do not insert breakpoints in the parent, otherwise
2193 the child could still trip on the parent's breakpoints. Since
2194 the parent is blocked anyway, it won't miss any breakpoint. */
2195 if (bl->pspace->breakpoints_not_allowed)
2198 /* Don't insert a breakpoint if we're trying to step past its
2200 if ((bl->loc_type == bp_loc_software_breakpoint
2201 || bl->loc_type == bp_loc_hardware_breakpoint)
2202 && stepping_past_instruction_at (bl->pspace->aspace,
2209 /* Same as should_be_inserted but does the check assuming
2210 that the location is not duplicated. */
2213 unduplicated_should_be_inserted (struct bp_location *bl)
2216 const int save_duplicate = bl->duplicate;
2219 result = should_be_inserted (bl);
2220 bl->duplicate = save_duplicate;
2224 /* Parses a conditional described by an expression COND into an
2225 agent expression bytecode suitable for evaluation
2226 by the bytecode interpreter. Return NULL if there was
2227 any error during parsing. */
2229 static struct agent_expr *
2230 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2232 struct agent_expr *aexpr = NULL;
2233 volatile struct gdb_exception ex;
2238 /* We don't want to stop processing, so catch any errors
2239 that may show up. */
2240 TRY_CATCH (ex, RETURN_MASK_ERROR)
2242 aexpr = gen_eval_for_expr (scope, cond);
2247 /* If we got here, it means the condition could not be parsed to a valid
2248 bytecode expression and thus can't be evaluated on the target's side.
2249 It's no use iterating through the conditions. */
2253 /* We have a valid agent expression. */
2257 /* Based on location BL, create a list of breakpoint conditions to be
2258 passed on to the target. If we have duplicated locations with different
2259 conditions, we will add such conditions to the list. The idea is that the
2260 target will evaluate the list of conditions and will only notify GDB when
2261 one of them is true. */
2264 build_target_condition_list (struct bp_location *bl)
2266 struct bp_location **locp = NULL, **loc2p;
2267 int null_condition_or_parse_error = 0;
2268 int modified = bl->needs_update;
2269 struct bp_location *loc;
2271 /* Release conditions left over from a previous insert. */
2272 VEC_free (agent_expr_p, bl->target_info.conditions);
2274 /* This is only meaningful if the target is
2275 evaluating conditions and if the user has
2276 opted for condition evaluation on the target's
2278 if (gdb_evaluates_breakpoint_condition_p ()
2279 || !target_supports_evaluation_of_breakpoint_conditions ())
2282 /* Do a first pass to check for locations with no assigned
2283 conditions or conditions that fail to parse to a valid agent expression
2284 bytecode. If any of these happen, then it's no use to send conditions
2285 to the target since this location will always trigger and generate a
2286 response back to GDB. */
2287 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2290 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2294 struct agent_expr *aexpr;
2296 /* Re-parse the conditions since something changed. In that
2297 case we already freed the condition bytecodes (see
2298 force_breakpoint_reinsertion). We just
2299 need to parse the condition to bytecodes again. */
2300 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2301 loc->cond_bytecode = aexpr;
2303 /* Check if we managed to parse the conditional expression
2304 correctly. If not, we will not send this condition
2310 /* If we have a NULL bytecode expression, it means something
2311 went wrong or we have a null condition expression. */
2312 if (!loc->cond_bytecode)
2314 null_condition_or_parse_error = 1;
2320 /* If any of these happened, it means we will have to evaluate the conditions
2321 for the location's address on gdb's side. It is no use keeping bytecodes
2322 for all the other duplicate locations, thus we free all of them here.
2324 This is so we have a finer control over which locations' conditions are
2325 being evaluated by GDB or the remote stub. */
2326 if (null_condition_or_parse_error)
2328 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2331 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2333 /* Only go as far as the first NULL bytecode is
2335 if (!loc->cond_bytecode)
2338 free_agent_expr (loc->cond_bytecode);
2339 loc->cond_bytecode = NULL;
2344 /* No NULL conditions or failed bytecode generation. Build a condition list
2345 for this location's address. */
2346 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2350 && is_breakpoint (loc->owner)
2351 && loc->pspace->num == bl->pspace->num
2352 && loc->owner->enable_state == bp_enabled
2354 /* Add the condition to the vector. This will be used later to send the
2355 conditions to the target. */
2356 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2357 loc->cond_bytecode);
2363 /* Parses a command described by string CMD into an agent expression
2364 bytecode suitable for evaluation by the bytecode interpreter.
2365 Return NULL if there was any error during parsing. */
2367 static struct agent_expr *
2368 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2370 struct cleanup *old_cleanups = 0;
2371 struct expression *expr, **argvec;
2372 struct agent_expr *aexpr = NULL;
2373 volatile struct gdb_exception ex;
2374 const char *cmdrest;
2375 const char *format_start, *format_end;
2376 struct format_piece *fpieces;
2378 struct gdbarch *gdbarch = get_current_arch ();
2385 if (*cmdrest == ',')
2387 cmdrest = skip_spaces_const (cmdrest);
2389 if (*cmdrest++ != '"')
2390 error (_("No format string following the location"));
2392 format_start = cmdrest;
2394 fpieces = parse_format_string (&cmdrest);
2396 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2398 format_end = cmdrest;
2400 if (*cmdrest++ != '"')
2401 error (_("Bad format string, non-terminated '\"'."));
2403 cmdrest = skip_spaces_const (cmdrest);
2405 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2406 error (_("Invalid argument syntax"));
2408 if (*cmdrest == ',')
2410 cmdrest = skip_spaces_const (cmdrest);
2412 /* For each argument, make an expression. */
2414 argvec = (struct expression **) alloca (strlen (cmd)
2415 * sizeof (struct expression *));
2418 while (*cmdrest != '\0')
2423 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2424 argvec[nargs++] = expr;
2426 if (*cmdrest == ',')
2430 /* We don't want to stop processing, so catch any errors
2431 that may show up. */
2432 TRY_CATCH (ex, RETURN_MASK_ERROR)
2434 aexpr = gen_printf (scope, gdbarch, 0, 0,
2435 format_start, format_end - format_start,
2436 fpieces, nargs, argvec);
2439 do_cleanups (old_cleanups);
2443 /* If we got here, it means the command could not be parsed to a valid
2444 bytecode expression and thus can't be evaluated on the target's side.
2445 It's no use iterating through the other commands. */
2449 /* We have a valid agent expression, return it. */
2453 /* Based on location BL, create a list of breakpoint commands to be
2454 passed on to the target. If we have duplicated locations with
2455 different commands, we will add any such to the list. */
2458 build_target_command_list (struct bp_location *bl)
2460 struct bp_location **locp = NULL, **loc2p;
2461 int null_command_or_parse_error = 0;
2462 int modified = bl->needs_update;
2463 struct bp_location *loc;
2465 /* Release commands left over from a previous insert. */
2466 VEC_free (agent_expr_p, bl->target_info.tcommands);
2468 if (!target_can_run_breakpoint_commands ())
2471 /* For now, limit to agent-style dprintf breakpoints. */
2472 if (dprintf_style != dprintf_style_agent)
2475 /* For now, if we have any duplicate location that isn't a dprintf,
2476 don't install the target-side commands, as that would make the
2477 breakpoint not be reported to the core, and we'd lose
2479 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2482 if (is_breakpoint (loc->owner)
2483 && loc->pspace->num == bl->pspace->num
2484 && loc->owner->type != bp_dprintf)
2488 /* Do a first pass to check for locations with no assigned
2489 conditions or conditions that fail to parse to a valid agent expression
2490 bytecode. If any of these happen, then it's no use to send conditions
2491 to the target since this location will always trigger and generate a
2492 response back to GDB. */
2493 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2496 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2500 struct agent_expr *aexpr;
2502 /* Re-parse the commands since something changed. In that
2503 case we already freed the command bytecodes (see
2504 force_breakpoint_reinsertion). We just
2505 need to parse the command to bytecodes again. */
2506 aexpr = parse_cmd_to_aexpr (bl->address,
2507 loc->owner->extra_string);
2508 loc->cmd_bytecode = aexpr;
2514 /* If we have a NULL bytecode expression, it means something
2515 went wrong or we have a null command expression. */
2516 if (!loc->cmd_bytecode)
2518 null_command_or_parse_error = 1;
2524 /* If anything failed, then we're not doing target-side commands,
2526 if (null_command_or_parse_error)
2528 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2531 if (is_breakpoint (loc->owner)
2532 && loc->pspace->num == bl->pspace->num)
2534 /* Only go as far as the first NULL bytecode is
2536 if (loc->cmd_bytecode == NULL)
2539 free_agent_expr (loc->cmd_bytecode);
2540 loc->cmd_bytecode = NULL;
2545 /* No NULL commands or failed bytecode generation. Build a command list
2546 for this location's address. */
2547 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2550 if (loc->owner->extra_string
2551 && is_breakpoint (loc->owner)
2552 && loc->pspace->num == bl->pspace->num
2553 && loc->owner->enable_state == bp_enabled
2555 /* Add the command to the vector. This will be used later
2556 to send the commands to the target. */
2557 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2561 bl->target_info.persist = 0;
2562 /* Maybe flag this location as persistent. */
2563 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2564 bl->target_info.persist = 1;
2567 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2568 location. Any error messages are printed to TMP_ERROR_STREAM; and
2569 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2570 Returns 0 for success, 1 if the bp_location type is not supported or
2573 NOTE drow/2003-09-09: This routine could be broken down to an
2574 object-style method for each breakpoint or catchpoint type. */
2576 insert_bp_location (struct bp_location *bl,
2577 struct ui_file *tmp_error_stream,
2578 int *disabled_breaks,
2579 int *hw_breakpoint_error,
2580 int *hw_bp_error_explained_already)
2582 enum errors bp_err = GDB_NO_ERROR;
2583 const char *bp_err_message = NULL;
2584 volatile struct gdb_exception e;
2586 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2589 /* Note we don't initialize bl->target_info, as that wipes out
2590 the breakpoint location's shadow_contents if the breakpoint
2591 is still inserted at that location. This in turn breaks
2592 target_read_memory which depends on these buffers when
2593 a memory read is requested at the breakpoint location:
2594 Once the target_info has been wiped, we fail to see that
2595 we have a breakpoint inserted at that address and thus
2596 read the breakpoint instead of returning the data saved in
2597 the breakpoint location's shadow contents. */
2598 bl->target_info.placed_address = bl->address;
2599 bl->target_info.placed_address_space = bl->pspace->aspace;
2600 bl->target_info.length = bl->length;
2602 /* When working with target-side conditions, we must pass all the conditions
2603 for the same breakpoint address down to the target since GDB will not
2604 insert those locations. With a list of breakpoint conditions, the target
2605 can decide when to stop and notify GDB. */
2607 if (is_breakpoint (bl->owner))
2609 build_target_condition_list (bl);
2610 build_target_command_list (bl);
2611 /* Reset the modification marker. */
2612 bl->needs_update = 0;
2615 if (bl->loc_type == bp_loc_software_breakpoint
2616 || bl->loc_type == bp_loc_hardware_breakpoint)
2618 if (bl->owner->type != bp_hardware_breakpoint)
2620 /* If the explicitly specified breakpoint type
2621 is not hardware breakpoint, check the memory map to see
2622 if the breakpoint address is in read only memory or not.
2624 Two important cases are:
2625 - location type is not hardware breakpoint, memory
2626 is readonly. We change the type of the location to
2627 hardware breakpoint.
2628 - location type is hardware breakpoint, memory is
2629 read-write. This means we've previously made the
2630 location hardware one, but then the memory map changed,
2633 When breakpoints are removed, remove_breakpoints will use
2634 location types we've just set here, the only possible
2635 problem is that memory map has changed during running
2636 program, but it's not going to work anyway with current
2638 struct mem_region *mr
2639 = lookup_mem_region (bl->target_info.placed_address);
2643 if (automatic_hardware_breakpoints)
2645 enum bp_loc_type new_type;
2647 if (mr->attrib.mode != MEM_RW)
2648 new_type = bp_loc_hardware_breakpoint;
2650 new_type = bp_loc_software_breakpoint;
2652 if (new_type != bl->loc_type)
2654 static int said = 0;
2656 bl->loc_type = new_type;
2659 fprintf_filtered (gdb_stdout,
2660 _("Note: automatically using "
2661 "hardware breakpoints for "
2662 "read-only addresses.\n"));
2667 else if (bl->loc_type == bp_loc_software_breakpoint
2668 && mr->attrib.mode != MEM_RW)
2669 warning (_("cannot set software breakpoint "
2670 "at readonly address %s"),
2671 paddress (bl->gdbarch, bl->address));
2675 /* First check to see if we have to handle an overlay. */
2676 if (overlay_debugging == ovly_off
2677 || bl->section == NULL
2678 || !(section_is_overlay (bl->section)))
2680 /* No overlay handling: just set the breakpoint. */
2681 TRY_CATCH (e, RETURN_MASK_ALL)
2685 val = bl->owner->ops->insert_location (bl);
2687 bp_err = GENERIC_ERROR;
2692 bp_err_message = e.message;
2697 /* This breakpoint is in an overlay section.
2698 Shall we set a breakpoint at the LMA? */
2699 if (!overlay_events_enabled)
2701 /* Yes -- overlay event support is not active,
2702 so we must try to set a breakpoint at the LMA.
2703 This will not work for a hardware breakpoint. */
2704 if (bl->loc_type == bp_loc_hardware_breakpoint)
2705 warning (_("hardware breakpoint %d not supported in overlay!"),
2709 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2711 /* Set a software (trap) breakpoint at the LMA. */
2712 bl->overlay_target_info = bl->target_info;
2713 bl->overlay_target_info.placed_address = addr;
2715 /* No overlay handling: just set the breakpoint. */
2716 TRY_CATCH (e, RETURN_MASK_ALL)
2720 val = target_insert_breakpoint (bl->gdbarch,
2721 &bl->overlay_target_info);
2723 bp_err = GENERIC_ERROR;
2728 bp_err_message = e.message;
2731 if (bp_err != GDB_NO_ERROR)
2732 fprintf_unfiltered (tmp_error_stream,
2733 "Overlay breakpoint %d "
2734 "failed: in ROM?\n",
2738 /* Shall we set a breakpoint at the VMA? */
2739 if (section_is_mapped (bl->section))
2741 /* Yes. This overlay section is mapped into memory. */
2742 TRY_CATCH (e, RETURN_MASK_ALL)
2746 val = bl->owner->ops->insert_location (bl);
2748 bp_err = GENERIC_ERROR;
2753 bp_err_message = e.message;
2758 /* No. This breakpoint will not be inserted.
2759 No error, but do not mark the bp as 'inserted'. */
2764 if (bp_err != GDB_NO_ERROR)
2766 /* Can't set the breakpoint. */
2768 /* In some cases, we might not be able to insert a
2769 breakpoint in a shared library that has already been
2770 removed, but we have not yet processed the shlib unload
2771 event. Unfortunately, some targets that implement
2772 breakpoint insertion themselves can't tell why the
2773 breakpoint insertion failed (e.g., the remote target
2774 doesn't define error codes), so we must treat generic
2775 errors as memory errors. */
2776 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2777 && bl->loc_type == bp_loc_software_breakpoint
2778 && (solib_name_from_address (bl->pspace, bl->address)
2779 || shared_objfile_contains_address_p (bl->pspace,
2782 /* See also: disable_breakpoints_in_shlibs. */
2783 bl->shlib_disabled = 1;
2784 observer_notify_breakpoint_modified (bl->owner);
2785 if (!*disabled_breaks)
2787 fprintf_unfiltered (tmp_error_stream,
2788 "Cannot insert breakpoint %d.\n",
2790 fprintf_unfiltered (tmp_error_stream,
2791 "Temporarily disabling shared "
2792 "library breakpoints:\n");
2794 *disabled_breaks = 1;
2795 fprintf_unfiltered (tmp_error_stream,
2796 "breakpoint #%d\n", bl->owner->number);
2801 if (bl->loc_type == bp_loc_hardware_breakpoint)
2803 *hw_breakpoint_error = 1;
2804 *hw_bp_error_explained_already = bp_err_message != NULL;
2805 fprintf_unfiltered (tmp_error_stream,
2806 "Cannot insert hardware breakpoint %d%s",
2807 bl->owner->number, bp_err_message ? ":" : ".\n");
2808 if (bp_err_message != NULL)
2809 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2813 if (bp_err_message == NULL)
2816 = memory_error_message (TARGET_XFER_E_IO,
2817 bl->gdbarch, bl->address);
2818 struct cleanup *old_chain = make_cleanup (xfree, message);
2820 fprintf_unfiltered (tmp_error_stream,
2821 "Cannot insert breakpoint %d.\n"
2823 bl->owner->number, message);
2824 do_cleanups (old_chain);
2828 fprintf_unfiltered (tmp_error_stream,
2829 "Cannot insert breakpoint %d: %s\n",
2844 else if (bl->loc_type == bp_loc_hardware_watchpoint
2845 /* NOTE drow/2003-09-08: This state only exists for removing
2846 watchpoints. It's not clear that it's necessary... */
2847 && bl->owner->disposition != disp_del_at_next_stop)
2851 gdb_assert (bl->owner->ops != NULL
2852 && bl->owner->ops->insert_location != NULL);
2854 val = bl->owner->ops->insert_location (bl);
2856 /* If trying to set a read-watchpoint, and it turns out it's not
2857 supported, try emulating one with an access watchpoint. */
2858 if (val == 1 && bl->watchpoint_type == hw_read)
2860 struct bp_location *loc, **loc_temp;
2862 /* But don't try to insert it, if there's already another
2863 hw_access location that would be considered a duplicate
2865 ALL_BP_LOCATIONS (loc, loc_temp)
2867 && loc->watchpoint_type == hw_access
2868 && watchpoint_locations_match (bl, loc))
2872 bl->target_info = loc->target_info;
2873 bl->watchpoint_type = hw_access;
2880 bl->watchpoint_type = hw_access;
2881 val = bl->owner->ops->insert_location (bl);
2884 /* Back to the original value. */
2885 bl->watchpoint_type = hw_read;
2889 bl->inserted = (val == 0);
2892 else if (bl->owner->type == bp_catchpoint)
2896 gdb_assert (bl->owner->ops != NULL
2897 && bl->owner->ops->insert_location != NULL);
2899 val = bl->owner->ops->insert_location (bl);
2902 bl->owner->enable_state = bp_disabled;
2906 Error inserting catchpoint %d: Your system does not support this type\n\
2907 of catchpoint."), bl->owner->number);
2909 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2912 bl->inserted = (val == 0);
2914 /* We've already printed an error message if there was a problem
2915 inserting this catchpoint, and we've disabled the catchpoint,
2916 so just return success. */
2923 /* This function is called when program space PSPACE is about to be
2924 deleted. It takes care of updating breakpoints to not reference
2928 breakpoint_program_space_exit (struct program_space *pspace)
2930 struct breakpoint *b, *b_temp;
2931 struct bp_location *loc, **loc_temp;
2933 /* Remove any breakpoint that was set through this program space. */
2934 ALL_BREAKPOINTS_SAFE (b, b_temp)
2936 if (b->pspace == pspace)
2937 delete_breakpoint (b);
2940 /* Breakpoints set through other program spaces could have locations
2941 bound to PSPACE as well. Remove those. */
2942 ALL_BP_LOCATIONS (loc, loc_temp)
2944 struct bp_location *tmp;
2946 if (loc->pspace == pspace)
2948 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2949 if (loc->owner->loc == loc)
2950 loc->owner->loc = loc->next;
2952 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2953 if (tmp->next == loc)
2955 tmp->next = loc->next;
2961 /* Now update the global location list to permanently delete the
2962 removed locations above. */
2963 update_global_location_list (UGLL_DONT_INSERT);
2966 /* Make sure all breakpoints are inserted in inferior.
2967 Throws exception on any error.
2968 A breakpoint that is already inserted won't be inserted
2969 again, so calling this function twice is safe. */
2971 insert_breakpoints (void)
2973 struct breakpoint *bpt;
2975 ALL_BREAKPOINTS (bpt)
2976 if (is_hardware_watchpoint (bpt))
2978 struct watchpoint *w = (struct watchpoint *) bpt;
2980 update_watchpoint (w, 0 /* don't reparse. */);
2983 /* Updating watchpoints creates new locations, so update the global
2984 location list. Explicitly tell ugll to insert locations and
2985 ignore breakpoints_always_inserted_mode. */
2986 update_global_location_list (UGLL_INSERT);
2989 /* Invoke CALLBACK for each of bp_location. */
2992 iterate_over_bp_locations (walk_bp_location_callback callback)
2994 struct bp_location *loc, **loc_tmp;
2996 ALL_BP_LOCATIONS (loc, loc_tmp)
2998 callback (loc, NULL);
3002 /* This is used when we need to synch breakpoint conditions between GDB and the
3003 target. It is the case with deleting and disabling of breakpoints when using
3004 always-inserted mode. */
3007 update_inserted_breakpoint_locations (void)
3009 struct bp_location *bl, **blp_tmp;
3012 int disabled_breaks = 0;
3013 int hw_breakpoint_error = 0;
3014 int hw_bp_details_reported = 0;
3016 struct ui_file *tmp_error_stream = mem_fileopen ();
3017 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3019 /* Explicitly mark the warning -- this will only be printed if
3020 there was an error. */
3021 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3023 save_current_space_and_thread ();
3025 ALL_BP_LOCATIONS (bl, blp_tmp)
3027 /* We only want to update software breakpoints and hardware
3029 if (!is_breakpoint (bl->owner))
3032 /* We only want to update locations that are already inserted
3033 and need updating. This is to avoid unwanted insertion during
3034 deletion of breakpoints. */
3035 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3038 switch_to_program_space_and_thread (bl->pspace);
3040 /* For targets that support global breakpoints, there's no need
3041 to select an inferior to insert breakpoint to. In fact, even
3042 if we aren't attached to any process yet, we should still
3043 insert breakpoints. */
3044 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3045 && ptid_equal (inferior_ptid, null_ptid))
3048 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3049 &hw_breakpoint_error, &hw_bp_details_reported);
3056 target_terminal_ours_for_output ();
3057 error_stream (tmp_error_stream);
3060 do_cleanups (cleanups);
3063 /* Used when starting or continuing the program. */
3066 insert_breakpoint_locations (void)
3068 struct breakpoint *bpt;
3069 struct bp_location *bl, **blp_tmp;
3072 int disabled_breaks = 0;
3073 int hw_breakpoint_error = 0;
3074 int hw_bp_error_explained_already = 0;
3076 struct ui_file *tmp_error_stream = mem_fileopen ();
3077 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3079 /* Explicitly mark the warning -- this will only be printed if
3080 there was an error. */
3081 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3083 save_current_space_and_thread ();
3085 ALL_BP_LOCATIONS (bl, blp_tmp)
3087 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3090 /* There is no point inserting thread-specific breakpoints if
3091 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3092 has BL->OWNER always non-NULL. */
3093 if (bl->owner->thread != -1
3094 && !valid_thread_id (bl->owner->thread))
3097 switch_to_program_space_and_thread (bl->pspace);
3099 /* For targets that support global breakpoints, there's no need
3100 to select an inferior to insert breakpoint to. In fact, even
3101 if we aren't attached to any process yet, we should still
3102 insert breakpoints. */
3103 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3104 && ptid_equal (inferior_ptid, null_ptid))
3107 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3108 &hw_breakpoint_error, &hw_bp_error_explained_already);
3113 /* If we failed to insert all locations of a watchpoint, remove
3114 them, as half-inserted watchpoint is of limited use. */
3115 ALL_BREAKPOINTS (bpt)
3117 int some_failed = 0;
3118 struct bp_location *loc;
3120 if (!is_hardware_watchpoint (bpt))
3123 if (!breakpoint_enabled (bpt))
3126 if (bpt->disposition == disp_del_at_next_stop)
3129 for (loc = bpt->loc; loc; loc = loc->next)
3130 if (!loc->inserted && should_be_inserted (loc))
3137 for (loc = bpt->loc; loc; loc = loc->next)
3139 remove_breakpoint (loc, mark_uninserted);
3141 hw_breakpoint_error = 1;
3142 fprintf_unfiltered (tmp_error_stream,
3143 "Could not insert hardware watchpoint %d.\n",
3151 /* If a hardware breakpoint or watchpoint was inserted, add a
3152 message about possibly exhausted resources. */
3153 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3155 fprintf_unfiltered (tmp_error_stream,
3156 "Could not insert hardware breakpoints:\n\
3157 You may have requested too many hardware breakpoints/watchpoints.\n");
3159 target_terminal_ours_for_output ();
3160 error_stream (tmp_error_stream);
3163 do_cleanups (cleanups);
3166 /* Used when the program stops.
3167 Returns zero if successful, or non-zero if there was a problem
3168 removing a breakpoint location. */
3171 remove_breakpoints (void)
3173 struct bp_location *bl, **blp_tmp;
3176 ALL_BP_LOCATIONS (bl, blp_tmp)
3178 if (bl->inserted && !is_tracepoint (bl->owner))
3179 val |= remove_breakpoint (bl, mark_uninserted);
3184 /* When a thread exits, remove breakpoints that are related to
3188 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3190 struct breakpoint *b, *b_tmp;
3192 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3194 if (b->thread == tp->num && user_breakpoint_p (b))
3196 b->disposition = disp_del_at_next_stop;
3198 printf_filtered (_("\
3199 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3200 b->number, tp->num);
3202 /* Hide it from the user. */
3208 /* Remove breakpoints of process PID. */
3211 remove_breakpoints_pid (int pid)
3213 struct bp_location *bl, **blp_tmp;
3215 struct inferior *inf = find_inferior_pid (pid);
3217 ALL_BP_LOCATIONS (bl, blp_tmp)
3219 if (bl->pspace != inf->pspace)
3222 if (bl->owner->type == bp_dprintf)
3227 val = remove_breakpoint (bl, mark_uninserted);
3236 reattach_breakpoints (int pid)
3238 struct cleanup *old_chain;
3239 struct bp_location *bl, **blp_tmp;
3241 struct ui_file *tmp_error_stream;
3242 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3243 struct inferior *inf;
3244 struct thread_info *tp;
3246 tp = any_live_thread_of_process (pid);
3250 inf = find_inferior_pid (pid);
3251 old_chain = save_inferior_ptid ();
3253 inferior_ptid = tp->ptid;
3255 tmp_error_stream = mem_fileopen ();
3256 make_cleanup_ui_file_delete (tmp_error_stream);
3258 ALL_BP_LOCATIONS (bl, blp_tmp)
3260 if (bl->pspace != inf->pspace)
3266 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3269 do_cleanups (old_chain);
3274 do_cleanups (old_chain);
3278 static int internal_breakpoint_number = -1;
3280 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3281 If INTERNAL is non-zero, the breakpoint number will be populated
3282 from internal_breakpoint_number and that variable decremented.
3283 Otherwise the breakpoint number will be populated from
3284 breakpoint_count and that value incremented. Internal breakpoints
3285 do not set the internal var bpnum. */
3287 set_breakpoint_number (int internal, struct breakpoint *b)
3290 b->number = internal_breakpoint_number--;
3293 set_breakpoint_count (breakpoint_count + 1);
3294 b->number = breakpoint_count;
3298 static struct breakpoint *
3299 create_internal_breakpoint (struct gdbarch *gdbarch,
3300 CORE_ADDR address, enum bptype type,
3301 const struct breakpoint_ops *ops)
3303 struct symtab_and_line sal;
3304 struct breakpoint *b;
3306 init_sal (&sal); /* Initialize to zeroes. */
3309 sal.section = find_pc_overlay (sal.pc);
3310 sal.pspace = current_program_space;
3312 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3313 b->number = internal_breakpoint_number--;
3314 b->disposition = disp_donttouch;
3319 static const char *const longjmp_names[] =
3321 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3323 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3325 /* Per-objfile data private to breakpoint.c. */
3326 struct breakpoint_objfile_data
3328 /* Minimal symbol for "_ovly_debug_event" (if any). */
3329 struct bound_minimal_symbol overlay_msym;
3331 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3332 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3334 /* True if we have looked for longjmp probes. */
3335 int longjmp_searched;
3337 /* SystemTap probe points for longjmp (if any). */
3338 VEC (probe_p) *longjmp_probes;
3340 /* Minimal symbol for "std::terminate()" (if any). */
3341 struct bound_minimal_symbol terminate_msym;
3343 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3344 struct bound_minimal_symbol exception_msym;
3346 /* True if we have looked for exception probes. */
3347 int exception_searched;
3349 /* SystemTap probe points for unwinding (if any). */
3350 VEC (probe_p) *exception_probes;
3353 static const struct objfile_data *breakpoint_objfile_key;
3355 /* Minimal symbol not found sentinel. */
3356 static struct minimal_symbol msym_not_found;
3358 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3361 msym_not_found_p (const struct minimal_symbol *msym)
3363 return msym == &msym_not_found;
3366 /* Return per-objfile data needed by breakpoint.c.
3367 Allocate the data if necessary. */
3369 static struct breakpoint_objfile_data *
3370 get_breakpoint_objfile_data (struct objfile *objfile)
3372 struct breakpoint_objfile_data *bp_objfile_data;
3374 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3375 if (bp_objfile_data == NULL)
3377 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3378 sizeof (*bp_objfile_data));
3380 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3381 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3383 return bp_objfile_data;
3387 free_breakpoint_probes (struct objfile *obj, void *data)
3389 struct breakpoint_objfile_data *bp_objfile_data = data;
3391 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3392 VEC_free (probe_p, bp_objfile_data->exception_probes);
3396 create_overlay_event_breakpoint (void)
3398 struct objfile *objfile;
3399 const char *const func_name = "_ovly_debug_event";
3401 ALL_OBJFILES (objfile)
3403 struct breakpoint *b;
3404 struct breakpoint_objfile_data *bp_objfile_data;
3407 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3409 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3412 if (bp_objfile_data->overlay_msym.minsym == NULL)
3414 struct bound_minimal_symbol m;
3416 m = lookup_minimal_symbol_text (func_name, objfile);
3417 if (m.minsym == NULL)
3419 /* Avoid future lookups in this objfile. */
3420 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3423 bp_objfile_data->overlay_msym = m;
3426 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3427 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3429 &internal_breakpoint_ops);
3430 b->addr_string = xstrdup (func_name);
3432 if (overlay_debugging == ovly_auto)
3434 b->enable_state = bp_enabled;
3435 overlay_events_enabled = 1;
3439 b->enable_state = bp_disabled;
3440 overlay_events_enabled = 0;
3443 update_global_location_list (UGLL_MAY_INSERT);
3447 create_longjmp_master_breakpoint (void)
3449 struct program_space *pspace;
3450 struct cleanup *old_chain;
3452 old_chain = save_current_program_space ();
3454 ALL_PSPACES (pspace)
3456 struct objfile *objfile;
3458 set_current_program_space (pspace);
3460 ALL_OBJFILES (objfile)
3463 struct gdbarch *gdbarch;
3464 struct breakpoint_objfile_data *bp_objfile_data;
3466 gdbarch = get_objfile_arch (objfile);
3468 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3470 if (!bp_objfile_data->longjmp_searched)
3474 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3477 /* We are only interested in checking one element. */
3478 struct probe *p = VEC_index (probe_p, ret, 0);
3480 if (!can_evaluate_probe_arguments (p))
3482 /* We cannot use the probe interface here, because it does
3483 not know how to evaluate arguments. */
3484 VEC_free (probe_p, ret);
3488 bp_objfile_data->longjmp_probes = ret;
3489 bp_objfile_data->longjmp_searched = 1;
3492 if (bp_objfile_data->longjmp_probes != NULL)
3495 struct probe *probe;
3496 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3499 VEC_iterate (probe_p,
3500 bp_objfile_data->longjmp_probes,
3504 struct breakpoint *b;
3506 b = create_internal_breakpoint (gdbarch,
3507 get_probe_address (probe,
3510 &internal_breakpoint_ops);
3511 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3512 b->enable_state = bp_disabled;
3518 if (!gdbarch_get_longjmp_target_p (gdbarch))
3521 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3523 struct breakpoint *b;
3524 const char *func_name;
3527 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3530 func_name = longjmp_names[i];
3531 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3533 struct bound_minimal_symbol m;
3535 m = lookup_minimal_symbol_text (func_name, objfile);
3536 if (m.minsym == NULL)
3538 /* Prevent future lookups in this objfile. */
3539 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3542 bp_objfile_data->longjmp_msym[i] = m;
3545 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3546 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3547 &internal_breakpoint_ops);
3548 b->addr_string = xstrdup (func_name);
3549 b->enable_state = bp_disabled;
3553 update_global_location_list (UGLL_MAY_INSERT);
3555 do_cleanups (old_chain);
3558 /* Create a master std::terminate breakpoint. */
3560 create_std_terminate_master_breakpoint (void)
3562 struct program_space *pspace;
3563 struct cleanup *old_chain;
3564 const char *const func_name = "std::terminate()";
3566 old_chain = save_current_program_space ();
3568 ALL_PSPACES (pspace)
3570 struct objfile *objfile;
3573 set_current_program_space (pspace);
3575 ALL_OBJFILES (objfile)
3577 struct breakpoint *b;
3578 struct breakpoint_objfile_data *bp_objfile_data;
3580 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3582 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3585 if (bp_objfile_data->terminate_msym.minsym == NULL)
3587 struct bound_minimal_symbol m;
3589 m = lookup_minimal_symbol (func_name, NULL, objfile);
3590 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3591 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3593 /* Prevent future lookups in this objfile. */
3594 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3597 bp_objfile_data->terminate_msym = m;
3600 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3601 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3602 bp_std_terminate_master,
3603 &internal_breakpoint_ops);
3604 b->addr_string = xstrdup (func_name);
3605 b->enable_state = bp_disabled;
3609 update_global_location_list (UGLL_MAY_INSERT);
3611 do_cleanups (old_chain);
3614 /* Install a master breakpoint on the unwinder's debug hook. */
3617 create_exception_master_breakpoint (void)
3619 struct objfile *objfile;
3620 const char *const func_name = "_Unwind_DebugHook";
3622 ALL_OBJFILES (objfile)
3624 struct breakpoint *b;
3625 struct gdbarch *gdbarch;
3626 struct breakpoint_objfile_data *bp_objfile_data;
3629 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3631 /* We prefer the SystemTap probe point if it exists. */
3632 if (!bp_objfile_data->exception_searched)
3636 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3640 /* We are only interested in checking one element. */
3641 struct probe *p = VEC_index (probe_p, ret, 0);
3643 if (!can_evaluate_probe_arguments (p))
3645 /* We cannot use the probe interface here, because it does
3646 not know how to evaluate arguments. */
3647 VEC_free (probe_p, ret);
3651 bp_objfile_data->exception_probes = ret;
3652 bp_objfile_data->exception_searched = 1;
3655 if (bp_objfile_data->exception_probes != NULL)
3657 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3659 struct probe *probe;
3662 VEC_iterate (probe_p,
3663 bp_objfile_data->exception_probes,
3667 struct breakpoint *b;
3669 b = create_internal_breakpoint (gdbarch,
3670 get_probe_address (probe,
3672 bp_exception_master,
3673 &internal_breakpoint_ops);
3674 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3675 b->enable_state = bp_disabled;
3681 /* Otherwise, try the hook function. */
3683 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3686 gdbarch = get_objfile_arch (objfile);
3688 if (bp_objfile_data->exception_msym.minsym == NULL)
3690 struct bound_minimal_symbol debug_hook;
3692 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3693 if (debug_hook.minsym == NULL)
3695 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3699 bp_objfile_data->exception_msym = debug_hook;
3702 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3703 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3705 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3706 &internal_breakpoint_ops);
3707 b->addr_string = xstrdup (func_name);
3708 b->enable_state = bp_disabled;
3711 update_global_location_list (UGLL_MAY_INSERT);
3715 update_breakpoints_after_exec (void)
3717 struct breakpoint *b, *b_tmp;
3718 struct bp_location *bploc, **bplocp_tmp;
3720 /* We're about to delete breakpoints from GDB's lists. If the
3721 INSERTED flag is true, GDB will try to lift the breakpoints by
3722 writing the breakpoints' "shadow contents" back into memory. The
3723 "shadow contents" are NOT valid after an exec, so GDB should not
3724 do that. Instead, the target is responsible from marking
3725 breakpoints out as soon as it detects an exec. We don't do that
3726 here instead, because there may be other attempts to delete
3727 breakpoints after detecting an exec and before reaching here. */
3728 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3729 if (bploc->pspace == current_program_space)
3730 gdb_assert (!bploc->inserted);
3732 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3734 if (b->pspace != current_program_space)
3737 /* Solib breakpoints must be explicitly reset after an exec(). */
3738 if (b->type == bp_shlib_event)
3740 delete_breakpoint (b);
3744 /* JIT breakpoints must be explicitly reset after an exec(). */
3745 if (b->type == bp_jit_event)
3747 delete_breakpoint (b);
3751 /* Thread event breakpoints must be set anew after an exec(),
3752 as must overlay event and longjmp master breakpoints. */
3753 if (b->type == bp_thread_event || b->type == bp_overlay_event
3754 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3755 || b->type == bp_exception_master)
3757 delete_breakpoint (b);
3761 /* Step-resume breakpoints are meaningless after an exec(). */
3762 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3764 delete_breakpoint (b);
3768 /* Longjmp and longjmp-resume breakpoints are also meaningless
3770 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3771 || b->type == bp_longjmp_call_dummy
3772 || b->type == bp_exception || b->type == bp_exception_resume)
3774 delete_breakpoint (b);
3778 if (b->type == bp_catchpoint)
3780 /* For now, none of the bp_catchpoint breakpoints need to
3781 do anything at this point. In the future, if some of
3782 the catchpoints need to something, we will need to add
3783 a new method, and call this method from here. */
3787 /* bp_finish is a special case. The only way we ought to be able
3788 to see one of these when an exec() has happened, is if the user
3789 caught a vfork, and then said "finish". Ordinarily a finish just
3790 carries them to the call-site of the current callee, by setting
3791 a temporary bp there and resuming. But in this case, the finish
3792 will carry them entirely through the vfork & exec.
3794 We don't want to allow a bp_finish to remain inserted now. But
3795 we can't safely delete it, 'cause finish_command has a handle to
3796 the bp on a bpstat, and will later want to delete it. There's a
3797 chance (and I've seen it happen) that if we delete the bp_finish
3798 here, that its storage will get reused by the time finish_command
3799 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3800 We really must allow finish_command to delete a bp_finish.
3802 In the absence of a general solution for the "how do we know
3803 it's safe to delete something others may have handles to?"
3804 problem, what we'll do here is just uninsert the bp_finish, and
3805 let finish_command delete it.
3807 (We know the bp_finish is "doomed" in the sense that it's
3808 momentary, and will be deleted as soon as finish_command sees
3809 the inferior stopped. So it doesn't matter that the bp's
3810 address is probably bogus in the new a.out, unlike e.g., the
3811 solib breakpoints.) */
3813 if (b->type == bp_finish)
3818 /* Without a symbolic address, we have little hope of the
3819 pre-exec() address meaning the same thing in the post-exec()
3821 if (b->addr_string == NULL)
3823 delete_breakpoint (b);
3827 /* FIXME what about longjmp breakpoints? Re-create them here? */
3828 create_overlay_event_breakpoint ();
3829 create_longjmp_master_breakpoint ();
3830 create_std_terminate_master_breakpoint ();
3831 create_exception_master_breakpoint ();
3835 detach_breakpoints (ptid_t ptid)
3837 struct bp_location *bl, **blp_tmp;
3839 struct cleanup *old_chain = save_inferior_ptid ();
3840 struct inferior *inf = current_inferior ();
3842 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3843 error (_("Cannot detach breakpoints of inferior_ptid"));
3845 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3846 inferior_ptid = ptid;
3847 ALL_BP_LOCATIONS (bl, blp_tmp)
3849 if (bl->pspace != inf->pspace)
3852 /* This function must physically remove breakpoints locations
3853 from the specified ptid, without modifying the breakpoint
3854 package's state. Locations of type bp_loc_other are only
3855 maintained at GDB side. So, there is no need to remove
3856 these bp_loc_other locations. Moreover, removing these
3857 would modify the breakpoint package's state. */
3858 if (bl->loc_type == bp_loc_other)
3862 val |= remove_breakpoint_1 (bl, mark_inserted);
3865 /* Detach single-step breakpoints as well. */
3866 detach_single_step_breakpoints ();
3868 do_cleanups (old_chain);
3872 /* Remove the breakpoint location BL from the current address space.
3873 Note that this is used to detach breakpoints from a child fork.
3874 When we get here, the child isn't in the inferior list, and neither
3875 do we have objects to represent its address space --- we should
3876 *not* look at bl->pspace->aspace here. */
3879 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3883 /* BL is never in moribund_locations by our callers. */
3884 gdb_assert (bl->owner != NULL);
3886 if (bl->owner->enable_state == bp_permanent)
3887 /* Permanent breakpoints cannot be inserted or removed. */
3890 /* The type of none suggests that owner is actually deleted.
3891 This should not ever happen. */
3892 gdb_assert (bl->owner->type != bp_none);
3894 if (bl->loc_type == bp_loc_software_breakpoint
3895 || bl->loc_type == bp_loc_hardware_breakpoint)
3897 /* "Normal" instruction breakpoint: either the standard
3898 trap-instruction bp (bp_breakpoint), or a
3899 bp_hardware_breakpoint. */
3901 /* First check to see if we have to handle an overlay. */
3902 if (overlay_debugging == ovly_off
3903 || bl->section == NULL
3904 || !(section_is_overlay (bl->section)))
3906 /* No overlay handling: just remove the breakpoint. */
3908 /* If we're trying to uninsert a memory breakpoint that we
3909 know is set in a dynamic object that is marked
3910 shlib_disabled, then either the dynamic object was
3911 removed with "remove-symbol-file" or with
3912 "nosharedlibrary". In the former case, we don't know
3913 whether another dynamic object might have loaded over the
3914 breakpoint's address -- the user might well let us know
3915 about it next with add-symbol-file (the whole point of
3916 add-symbol-file is letting the user manually maintain a
3917 list of dynamically loaded objects). If we have the
3918 breakpoint's shadow memory, that is, this is a software
3919 breakpoint managed by GDB, check whether the breakpoint
3920 is still inserted in memory, to avoid overwriting wrong
3921 code with stale saved shadow contents. Note that HW
3922 breakpoints don't have shadow memory, as they're
3923 implemented using a mechanism that is not dependent on
3924 being able to modify the target's memory, and as such
3925 they should always be removed. */
3926 if (bl->shlib_disabled
3927 && bl->target_info.shadow_len != 0
3928 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3931 val = bl->owner->ops->remove_location (bl);
3935 /* This breakpoint is in an overlay section.
3936 Did we set a breakpoint at the LMA? */
3937 if (!overlay_events_enabled)
3939 /* Yes -- overlay event support is not active, so we
3940 should have set a breakpoint at the LMA. Remove it.
3942 /* Ignore any failures: if the LMA is in ROM, we will
3943 have already warned when we failed to insert it. */
3944 if (bl->loc_type == bp_loc_hardware_breakpoint)
3945 target_remove_hw_breakpoint (bl->gdbarch,
3946 &bl->overlay_target_info);
3948 target_remove_breakpoint (bl->gdbarch,
3949 &bl->overlay_target_info);
3951 /* Did we set a breakpoint at the VMA?
3952 If so, we will have marked the breakpoint 'inserted'. */
3955 /* Yes -- remove it. Previously we did not bother to
3956 remove the breakpoint if the section had been
3957 unmapped, but let's not rely on that being safe. We
3958 don't know what the overlay manager might do. */
3960 /* However, we should remove *software* breakpoints only
3961 if the section is still mapped, or else we overwrite
3962 wrong code with the saved shadow contents. */
3963 if (bl->loc_type == bp_loc_hardware_breakpoint
3964 || section_is_mapped (bl->section))
3965 val = bl->owner->ops->remove_location (bl);
3971 /* No -- not inserted, so no need to remove. No error. */
3976 /* In some cases, we might not be able to remove a breakpoint in
3977 a shared library that has already been removed, but we have
3978 not yet processed the shlib unload event. Similarly for an
3979 unloaded add-symbol-file object - the user might not yet have
3980 had the chance to remove-symbol-file it. shlib_disabled will
3981 be set if the library/object has already been removed, but
3982 the breakpoint hasn't been uninserted yet, e.g., after
3983 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3984 always-inserted mode. */
3986 && (bl->loc_type == bp_loc_software_breakpoint
3987 && (bl->shlib_disabled
3988 || solib_name_from_address (bl->pspace, bl->address)
3989 || shared_objfile_contains_address_p (bl->pspace,
3995 bl->inserted = (is == mark_inserted);
3997 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3999 gdb_assert (bl->owner->ops != NULL
4000 && bl->owner->ops->remove_location != NULL);
4002 bl->inserted = (is == mark_inserted);
4003 bl->owner->ops->remove_location (bl);
4005 /* Failure to remove any of the hardware watchpoints comes here. */
4006 if ((is == mark_uninserted) && (bl->inserted))
4007 warning (_("Could not remove hardware watchpoint %d."),
4010 else if (bl->owner->type == bp_catchpoint
4011 && breakpoint_enabled (bl->owner)
4014 gdb_assert (bl->owner->ops != NULL
4015 && bl->owner->ops->remove_location != NULL);
4017 val = bl->owner->ops->remove_location (bl);
4021 bl->inserted = (is == mark_inserted);
4028 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
4031 struct cleanup *old_chain;
4033 /* BL is never in moribund_locations by our callers. */
4034 gdb_assert (bl->owner != NULL);
4036 if (bl->owner->enable_state == bp_permanent)
4037 /* Permanent breakpoints cannot be inserted or removed. */
4040 /* The type of none suggests that owner is actually deleted.
4041 This should not ever happen. */
4042 gdb_assert (bl->owner->type != bp_none);
4044 old_chain = save_current_space_and_thread ();
4046 switch_to_program_space_and_thread (bl->pspace);
4048 ret = remove_breakpoint_1 (bl, is);
4050 do_cleanups (old_chain);
4054 /* Clear the "inserted" flag in all breakpoints. */
4057 mark_breakpoints_out (void)
4059 struct bp_location *bl, **blp_tmp;
4061 ALL_BP_LOCATIONS (bl, blp_tmp)
4062 if (bl->pspace == current_program_space)
4066 /* Clear the "inserted" flag in all breakpoints and delete any
4067 breakpoints which should go away between runs of the program.
4069 Plus other such housekeeping that has to be done for breakpoints
4072 Note: this function gets called at the end of a run (by
4073 generic_mourn_inferior) and when a run begins (by
4074 init_wait_for_inferior). */
4079 breakpoint_init_inferior (enum inf_context context)
4081 struct breakpoint *b, *b_tmp;
4082 struct bp_location *bl, **blp_tmp;
4084 struct program_space *pspace = current_program_space;
4086 /* If breakpoint locations are shared across processes, then there's
4088 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4091 ALL_BP_LOCATIONS (bl, blp_tmp)
4093 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4094 if (bl->pspace == pspace
4095 && bl->owner->enable_state != bp_permanent)
4099 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4101 if (b->loc && b->loc->pspace != pspace)
4107 case bp_longjmp_call_dummy:
4109 /* If the call dummy breakpoint is at the entry point it will
4110 cause problems when the inferior is rerun, so we better get
4113 case bp_watchpoint_scope:
4115 /* Also get rid of scope breakpoints. */
4117 case bp_shlib_event:
4119 /* Also remove solib event breakpoints. Their addresses may
4120 have changed since the last time we ran the program.
4121 Actually we may now be debugging against different target;
4122 and so the solib backend that installed this breakpoint may
4123 not be used in by the target. E.g.,
4125 (gdb) file prog-linux
4126 (gdb) run # native linux target
4129 (gdb) file prog-win.exe
4130 (gdb) tar rem :9999 # remote Windows gdbserver.
4133 case bp_step_resume:
4135 /* Also remove step-resume breakpoints. */
4137 delete_breakpoint (b);
4141 case bp_hardware_watchpoint:
4142 case bp_read_watchpoint:
4143 case bp_access_watchpoint:
4145 struct watchpoint *w = (struct watchpoint *) b;
4147 /* Likewise for watchpoints on local expressions. */
4148 if (w->exp_valid_block != NULL)
4149 delete_breakpoint (b);
4150 else if (context == inf_starting)
4152 /* Reset val field to force reread of starting value in
4153 insert_breakpoints. */
4155 value_free (w->val);
4166 /* Get rid of the moribund locations. */
4167 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4168 decref_bp_location (&bl);
4169 VEC_free (bp_location_p, moribund_locations);
4172 /* These functions concern about actual breakpoints inserted in the
4173 target --- to e.g. check if we need to do decr_pc adjustment or if
4174 we need to hop over the bkpt --- so we check for address space
4175 match, not program space. */
4177 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4178 exists at PC. It returns ordinary_breakpoint_here if it's an
4179 ordinary breakpoint, or permanent_breakpoint_here if it's a
4180 permanent breakpoint.
4181 - When continuing from a location with an ordinary breakpoint, we
4182 actually single step once before calling insert_breakpoints.
4183 - When continuing from a location with a permanent breakpoint, we
4184 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4185 the target, to advance the PC past the breakpoint. */
4187 enum breakpoint_here
4188 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4190 struct bp_location *bl, **blp_tmp;
4191 int any_breakpoint_here = 0;
4193 ALL_BP_LOCATIONS (bl, blp_tmp)
4195 if (bl->loc_type != bp_loc_software_breakpoint
4196 && bl->loc_type != bp_loc_hardware_breakpoint)
4199 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4200 if ((breakpoint_enabled (bl->owner)
4201 || bl->owner->enable_state == bp_permanent)
4202 && breakpoint_location_address_match (bl, aspace, pc))
4204 if (overlay_debugging
4205 && section_is_overlay (bl->section)
4206 && !section_is_mapped (bl->section))
4207 continue; /* unmapped overlay -- can't be a match */
4208 else if (bl->owner->enable_state == bp_permanent)
4209 return permanent_breakpoint_here;
4211 any_breakpoint_here = 1;
4215 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
4218 /* Return true if there's a moribund breakpoint at PC. */
4221 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4223 struct bp_location *loc;
4226 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4227 if (breakpoint_location_address_match (loc, aspace, pc))
4233 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4234 inserted using regular breakpoint_chain / bp_location array
4235 mechanism. This does not check for single-step breakpoints, which
4236 are inserted and removed using direct target manipulation. */
4239 regular_breakpoint_inserted_here_p (struct address_space *aspace,
4242 struct bp_location *bl, **blp_tmp;
4244 ALL_BP_LOCATIONS (bl, blp_tmp)
4246 if (bl->loc_type != bp_loc_software_breakpoint
4247 && bl->loc_type != bp_loc_hardware_breakpoint)
4251 && breakpoint_location_address_match (bl, aspace, pc))
4253 if (overlay_debugging
4254 && section_is_overlay (bl->section)
4255 && !section_is_mapped (bl->section))
4256 continue; /* unmapped overlay -- can't be a match */
4264 /* Returns non-zero iff there's either regular breakpoint
4265 or a single step breakpoint inserted at PC. */
4268 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4270 if (regular_breakpoint_inserted_here_p (aspace, pc))
4273 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4279 /* Ignoring deprecated raw breakpoints, return non-zero iff there is a
4280 software breakpoint inserted at PC. */
4282 static struct bp_location *
4283 find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace,
4286 struct bp_location *bl, **blp_tmp;
4288 ALL_BP_LOCATIONS (bl, blp_tmp)
4290 if (bl->loc_type != bp_loc_software_breakpoint)
4294 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4297 if (overlay_debugging
4298 && section_is_overlay (bl->section)
4299 && !section_is_mapped (bl->section))
4300 continue; /* unmapped overlay -- can't be a match */
4309 /* This function returns non-zero iff there is a software breakpoint
4313 software_breakpoint_inserted_here_p (struct address_space *aspace,
4316 if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL)
4319 /* Also check for software single-step breakpoints. */
4320 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4327 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4328 CORE_ADDR addr, ULONGEST len)
4330 struct breakpoint *bpt;
4332 ALL_BREAKPOINTS (bpt)
4334 struct bp_location *loc;
4336 if (bpt->type != bp_hardware_watchpoint
4337 && bpt->type != bp_access_watchpoint)
4340 if (!breakpoint_enabled (bpt))
4343 for (loc = bpt->loc; loc; loc = loc->next)
4344 if (loc->pspace->aspace == aspace && loc->inserted)
4348 /* Check for intersection. */
4349 l = max (loc->address, addr);
4350 h = min (loc->address + loc->length, addr + len);
4358 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4359 PC is valid for process/thread PTID. */
4362 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4365 struct bp_location *bl, **blp_tmp;
4366 /* The thread and task IDs associated to PTID, computed lazily. */
4370 ALL_BP_LOCATIONS (bl, blp_tmp)
4372 if (bl->loc_type != bp_loc_software_breakpoint
4373 && bl->loc_type != bp_loc_hardware_breakpoint)
4376 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4377 if (!breakpoint_enabled (bl->owner)
4378 && bl->owner->enable_state != bp_permanent)
4381 if (!breakpoint_location_address_match (bl, aspace, pc))
4384 if (bl->owner->thread != -1)
4386 /* This is a thread-specific breakpoint. Check that ptid
4387 matches that thread. If thread hasn't been computed yet,
4388 it is now time to do so. */
4390 thread = pid_to_thread_id (ptid);
4391 if (bl->owner->thread != thread)
4395 if (bl->owner->task != 0)
4397 /* This is a task-specific breakpoint. Check that ptid
4398 matches that task. If task hasn't been computed yet,
4399 it is now time to do so. */
4401 task = ada_get_task_number (ptid);
4402 if (bl->owner->task != task)
4406 if (overlay_debugging
4407 && section_is_overlay (bl->section)
4408 && !section_is_mapped (bl->section))
4409 continue; /* unmapped overlay -- can't be a match */
4418 /* bpstat stuff. External routines' interfaces are documented
4422 is_catchpoint (struct breakpoint *ep)
4424 return (ep->type == bp_catchpoint);
4427 /* Frees any storage that is part of a bpstat. Does not walk the
4431 bpstat_free (bpstat bs)
4433 if (bs->old_val != NULL)
4434 value_free (bs->old_val);
4435 decref_counted_command_line (&bs->commands);
4436 decref_bp_location (&bs->bp_location_at);
4440 /* Clear a bpstat so that it says we are not at any breakpoint.
4441 Also free any storage that is part of a bpstat. */
4444 bpstat_clear (bpstat *bsp)
4461 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4462 is part of the bpstat is copied as well. */
4465 bpstat_copy (bpstat bs)
4469 bpstat retval = NULL;
4474 for (; bs != NULL; bs = bs->next)
4476 tmp = (bpstat) xmalloc (sizeof (*tmp));
4477 memcpy (tmp, bs, sizeof (*tmp));
4478 incref_counted_command_line (tmp->commands);
4479 incref_bp_location (tmp->bp_location_at);
4480 if (bs->old_val != NULL)
4482 tmp->old_val = value_copy (bs->old_val);
4483 release_value (tmp->old_val);
4487 /* This is the first thing in the chain. */
4497 /* Find the bpstat associated with this breakpoint. */
4500 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4505 for (; bsp != NULL; bsp = bsp->next)
4507 if (bsp->breakpoint_at == breakpoint)
4513 /* See breakpoint.h. */
4516 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4518 for (; bsp != NULL; bsp = bsp->next)
4520 if (bsp->breakpoint_at == NULL)
4522 /* A moribund location can never explain a signal other than
4524 if (sig == GDB_SIGNAL_TRAP)
4529 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4538 /* Put in *NUM the breakpoint number of the first breakpoint we are
4539 stopped at. *BSP upon return is a bpstat which points to the
4540 remaining breakpoints stopped at (but which is not guaranteed to be
4541 good for anything but further calls to bpstat_num).
4543 Return 0 if passed a bpstat which does not indicate any breakpoints.
4544 Return -1 if stopped at a breakpoint that has been deleted since
4546 Return 1 otherwise. */
4549 bpstat_num (bpstat *bsp, int *num)
4551 struct breakpoint *b;
4554 return 0; /* No more breakpoint values */
4556 /* We assume we'll never have several bpstats that correspond to a
4557 single breakpoint -- otherwise, this function might return the
4558 same number more than once and this will look ugly. */
4559 b = (*bsp)->breakpoint_at;
4560 *bsp = (*bsp)->next;
4562 return -1; /* breakpoint that's been deleted since */
4564 *num = b->number; /* We have its number */
4568 /* See breakpoint.h. */
4571 bpstat_clear_actions (void)
4573 struct thread_info *tp;
4576 if (ptid_equal (inferior_ptid, null_ptid))
4579 tp = find_thread_ptid (inferior_ptid);
4583 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4585 decref_counted_command_line (&bs->commands);
4587 if (bs->old_val != NULL)
4589 value_free (bs->old_val);
4595 /* Called when a command is about to proceed the inferior. */
4598 breakpoint_about_to_proceed (void)
4600 if (!ptid_equal (inferior_ptid, null_ptid))
4602 struct thread_info *tp = inferior_thread ();
4604 /* Allow inferior function calls in breakpoint commands to not
4605 interrupt the command list. When the call finishes
4606 successfully, the inferior will be standing at the same
4607 breakpoint as if nothing happened. */
4608 if (tp->control.in_infcall)
4612 breakpoint_proceeded = 1;
4615 /* Stub for cleaning up our state if we error-out of a breakpoint
4618 cleanup_executing_breakpoints (void *ignore)
4620 executing_breakpoint_commands = 0;
4623 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4624 or its equivalent. */
4627 command_line_is_silent (struct command_line *cmd)
4629 return cmd && (strcmp ("silent", cmd->line) == 0
4630 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4633 /* Execute all the commands associated with all the breakpoints at
4634 this location. Any of these commands could cause the process to
4635 proceed beyond this point, etc. We look out for such changes by
4636 checking the global "breakpoint_proceeded" after each command.
4638 Returns true if a breakpoint command resumed the inferior. In that
4639 case, it is the caller's responsibility to recall it again with the
4640 bpstat of the current thread. */
4643 bpstat_do_actions_1 (bpstat *bsp)
4646 struct cleanup *old_chain;
4649 /* Avoid endless recursion if a `source' command is contained
4651 if (executing_breakpoint_commands)
4654 executing_breakpoint_commands = 1;
4655 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4657 prevent_dont_repeat ();
4659 /* This pointer will iterate over the list of bpstat's. */
4662 breakpoint_proceeded = 0;
4663 for (; bs != NULL; bs = bs->next)
4665 struct counted_command_line *ccmd;
4666 struct command_line *cmd;
4667 struct cleanup *this_cmd_tree_chain;
4669 /* Take ownership of the BSP's command tree, if it has one.
4671 The command tree could legitimately contain commands like
4672 'step' and 'next', which call clear_proceed_status, which
4673 frees stop_bpstat's command tree. To make sure this doesn't
4674 free the tree we're executing out from under us, we need to
4675 take ownership of the tree ourselves. Since a given bpstat's
4676 commands are only executed once, we don't need to copy it; we
4677 can clear the pointer in the bpstat, and make sure we free
4678 the tree when we're done. */
4679 ccmd = bs->commands;
4680 bs->commands = NULL;
4681 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4682 cmd = ccmd ? ccmd->commands : NULL;
4683 if (command_line_is_silent (cmd))
4685 /* The action has been already done by bpstat_stop_status. */
4691 execute_control_command (cmd);
4693 if (breakpoint_proceeded)
4699 /* We can free this command tree now. */
4700 do_cleanups (this_cmd_tree_chain);
4702 if (breakpoint_proceeded)
4704 if (target_can_async_p ())
4705 /* If we are in async mode, then the target might be still
4706 running, not stopped at any breakpoint, so nothing for
4707 us to do here -- just return to the event loop. */
4710 /* In sync mode, when execute_control_command returns
4711 we're already standing on the next breakpoint.
4712 Breakpoint commands for that stop were not run, since
4713 execute_command does not run breakpoint commands --
4714 only command_line_handler does, but that one is not
4715 involved in execution of breakpoint commands. So, we
4716 can now execute breakpoint commands. It should be
4717 noted that making execute_command do bpstat actions is
4718 not an option -- in this case we'll have recursive
4719 invocation of bpstat for each breakpoint with a
4720 command, and can easily blow up GDB stack. Instead, we
4721 return true, which will trigger the caller to recall us
4722 with the new stop_bpstat. */
4727 do_cleanups (old_chain);
4732 bpstat_do_actions (void)
4734 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4736 /* Do any commands attached to breakpoint we are stopped at. */
4737 while (!ptid_equal (inferior_ptid, null_ptid)
4738 && target_has_execution
4739 && !is_exited (inferior_ptid)
4740 && !is_executing (inferior_ptid))
4741 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4742 and only return when it is stopped at the next breakpoint, we
4743 keep doing breakpoint actions until it returns false to
4744 indicate the inferior was not resumed. */
4745 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4748 discard_cleanups (cleanup_if_error);
4751 /* Print out the (old or new) value associated with a watchpoint. */
4754 watchpoint_value_print (struct value *val, struct ui_file *stream)
4757 fprintf_unfiltered (stream, _("<unreadable>"));
4760 struct value_print_options opts;
4761 get_user_print_options (&opts);
4762 value_print (val, stream, &opts);
4766 /* Generic routine for printing messages indicating why we
4767 stopped. The behavior of this function depends on the value
4768 'print_it' in the bpstat structure. Under some circumstances we
4769 may decide not to print anything here and delegate the task to
4772 static enum print_stop_action
4773 print_bp_stop_message (bpstat bs)
4775 switch (bs->print_it)
4778 /* Nothing should be printed for this bpstat entry. */
4779 return PRINT_UNKNOWN;
4783 /* We still want to print the frame, but we already printed the
4784 relevant messages. */
4785 return PRINT_SRC_AND_LOC;
4788 case print_it_normal:
4790 struct breakpoint *b = bs->breakpoint_at;
4792 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4793 which has since been deleted. */
4795 return PRINT_UNKNOWN;
4797 /* Normal case. Call the breakpoint's print_it method. */
4798 return b->ops->print_it (bs);
4803 internal_error (__FILE__, __LINE__,
4804 _("print_bp_stop_message: unrecognized enum value"));
4809 /* A helper function that prints a shared library stopped event. */
4812 print_solib_event (int is_catchpoint)
4815 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4817 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4821 if (any_added || any_deleted)
4822 ui_out_text (current_uiout,
4823 _("Stopped due to shared library event:\n"));
4825 ui_out_text (current_uiout,
4826 _("Stopped due to shared library event (no "
4827 "libraries added or removed)\n"));
4830 if (ui_out_is_mi_like_p (current_uiout))
4831 ui_out_field_string (current_uiout, "reason",
4832 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4836 struct cleanup *cleanup;
4840 ui_out_text (current_uiout, _(" Inferior unloaded "));
4841 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4844 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4849 ui_out_text (current_uiout, " ");
4850 ui_out_field_string (current_uiout, "library", name);
4851 ui_out_text (current_uiout, "\n");
4854 do_cleanups (cleanup);
4859 struct so_list *iter;
4861 struct cleanup *cleanup;
4863 ui_out_text (current_uiout, _(" Inferior loaded "));
4864 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4867 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4872 ui_out_text (current_uiout, " ");
4873 ui_out_field_string (current_uiout, "library", iter->so_name);
4874 ui_out_text (current_uiout, "\n");
4877 do_cleanups (cleanup);
4881 /* Print a message indicating what happened. This is called from
4882 normal_stop(). The input to this routine is the head of the bpstat
4883 list - a list of the eventpoints that caused this stop. KIND is
4884 the target_waitkind for the stopping event. This
4885 routine calls the generic print routine for printing a message
4886 about reasons for stopping. This will print (for example) the
4887 "Breakpoint n," part of the output. The return value of this
4890 PRINT_UNKNOWN: Means we printed nothing.
4891 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4892 code to print the location. An example is
4893 "Breakpoint 1, " which should be followed by
4895 PRINT_SRC_ONLY: Means we printed something, but there is no need
4896 to also print the location part of the message.
4897 An example is the catch/throw messages, which
4898 don't require a location appended to the end.
4899 PRINT_NOTHING: We have done some printing and we don't need any
4900 further info to be printed. */
4902 enum print_stop_action
4903 bpstat_print (bpstat bs, int kind)
4907 /* Maybe another breakpoint in the chain caused us to stop.
4908 (Currently all watchpoints go on the bpstat whether hit or not.
4909 That probably could (should) be changed, provided care is taken
4910 with respect to bpstat_explains_signal). */
4911 for (; bs; bs = bs->next)
4913 val = print_bp_stop_message (bs);
4914 if (val == PRINT_SRC_ONLY
4915 || val == PRINT_SRC_AND_LOC
4916 || val == PRINT_NOTHING)
4920 /* If we had hit a shared library event breakpoint,
4921 print_bp_stop_message would print out this message. If we hit an
4922 OS-level shared library event, do the same thing. */
4923 if (kind == TARGET_WAITKIND_LOADED)
4925 print_solib_event (0);
4926 return PRINT_NOTHING;
4929 /* We reached the end of the chain, or we got a null BS to start
4930 with and nothing was printed. */
4931 return PRINT_UNKNOWN;
4934 /* Evaluate the expression EXP and return 1 if value is zero.
4935 This returns the inverse of the condition because it is called
4936 from catch_errors which returns 0 if an exception happened, and if an
4937 exception happens we want execution to stop.
4938 The argument is a "struct expression *" that has been cast to a
4939 "void *" to make it pass through catch_errors. */
4942 breakpoint_cond_eval (void *exp)
4944 struct value *mark = value_mark ();
4945 int i = !value_true (evaluate_expression ((struct expression *) exp));
4947 value_free_to_mark (mark);
4951 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4954 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4958 bs = (bpstat) xmalloc (sizeof (*bs));
4960 **bs_link_pointer = bs;
4961 *bs_link_pointer = &bs->next;
4962 bs->breakpoint_at = bl->owner;
4963 bs->bp_location_at = bl;
4964 incref_bp_location (bl);
4965 /* If the condition is false, etc., don't do the commands. */
4966 bs->commands = NULL;
4968 bs->print_it = print_it_normal;
4972 /* The target has stopped with waitstatus WS. Check if any hardware
4973 watchpoints have triggered, according to the target. */
4976 watchpoints_triggered (struct target_waitstatus *ws)
4978 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4980 struct breakpoint *b;
4982 if (!stopped_by_watchpoint)
4984 /* We were not stopped by a watchpoint. Mark all watchpoints
4985 as not triggered. */
4987 if (is_hardware_watchpoint (b))
4989 struct watchpoint *w = (struct watchpoint *) b;
4991 w->watchpoint_triggered = watch_triggered_no;
4997 if (!target_stopped_data_address (¤t_target, &addr))
4999 /* We were stopped by a watchpoint, but we don't know where.
5000 Mark all watchpoints as unknown. */
5002 if (is_hardware_watchpoint (b))
5004 struct watchpoint *w = (struct watchpoint *) b;
5006 w->watchpoint_triggered = watch_triggered_unknown;
5012 /* The target could report the data address. Mark watchpoints
5013 affected by this data address as triggered, and all others as not
5017 if (is_hardware_watchpoint (b))
5019 struct watchpoint *w = (struct watchpoint *) b;
5020 struct bp_location *loc;
5022 w->watchpoint_triggered = watch_triggered_no;
5023 for (loc = b->loc; loc; loc = loc->next)
5025 if (is_masked_watchpoint (b))
5027 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5028 CORE_ADDR start = loc->address & w->hw_wp_mask;
5030 if (newaddr == start)
5032 w->watchpoint_triggered = watch_triggered_yes;
5036 /* Exact match not required. Within range is sufficient. */
5037 else if (target_watchpoint_addr_within_range (¤t_target,
5041 w->watchpoint_triggered = watch_triggered_yes;
5050 /* Possible return values for watchpoint_check (this can't be an enum
5051 because of check_errors). */
5052 /* The watchpoint has been deleted. */
5053 #define WP_DELETED 1
5054 /* The value has changed. */
5055 #define WP_VALUE_CHANGED 2
5056 /* The value has not changed. */
5057 #define WP_VALUE_NOT_CHANGED 3
5058 /* Ignore this watchpoint, no matter if the value changed or not. */
5061 #define BP_TEMPFLAG 1
5062 #define BP_HARDWAREFLAG 2
5064 /* Evaluate watchpoint condition expression and check if its value
5067 P should be a pointer to struct bpstat, but is defined as a void *
5068 in order for this function to be usable with catch_errors. */
5071 watchpoint_check (void *p)
5073 bpstat bs = (bpstat) p;
5074 struct watchpoint *b;
5075 struct frame_info *fr;
5076 int within_current_scope;
5078 /* BS is built from an existing struct breakpoint. */
5079 gdb_assert (bs->breakpoint_at != NULL);
5080 b = (struct watchpoint *) bs->breakpoint_at;
5082 /* If this is a local watchpoint, we only want to check if the
5083 watchpoint frame is in scope if the current thread is the thread
5084 that was used to create the watchpoint. */
5085 if (!watchpoint_in_thread_scope (b))
5088 if (b->exp_valid_block == NULL)
5089 within_current_scope = 1;
5092 struct frame_info *frame = get_current_frame ();
5093 struct gdbarch *frame_arch = get_frame_arch (frame);
5094 CORE_ADDR frame_pc = get_frame_pc (frame);
5096 /* in_function_epilogue_p() returns a non-zero value if we're
5097 still in the function but the stack frame has already been
5098 invalidated. Since we can't rely on the values of local
5099 variables after the stack has been destroyed, we are treating
5100 the watchpoint in that state as `not changed' without further
5101 checking. Don't mark watchpoints as changed if the current
5102 frame is in an epilogue - even if they are in some other
5103 frame, our view of the stack is likely to be wrong and
5104 frame_find_by_id could error out. */
5105 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
5108 fr = frame_find_by_id (b->watchpoint_frame);
5109 within_current_scope = (fr != NULL);
5111 /* If we've gotten confused in the unwinder, we might have
5112 returned a frame that can't describe this variable. */
5113 if (within_current_scope)
5115 struct symbol *function;
5117 function = get_frame_function (fr);
5118 if (function == NULL
5119 || !contained_in (b->exp_valid_block,
5120 SYMBOL_BLOCK_VALUE (function)))
5121 within_current_scope = 0;
5124 if (within_current_scope)
5125 /* If we end up stopping, the current frame will get selected
5126 in normal_stop. So this call to select_frame won't affect
5131 if (within_current_scope)
5133 /* We use value_{,free_to_}mark because it could be a *long*
5134 time before we return to the command level and call
5135 free_all_values. We can't call free_all_values because we
5136 might be in the middle of evaluating a function call. */
5140 struct value *new_val;
5142 if (is_masked_watchpoint (&b->base))
5143 /* Since we don't know the exact trigger address (from
5144 stopped_data_address), just tell the user we've triggered
5145 a mask watchpoint. */
5146 return WP_VALUE_CHANGED;
5148 mark = value_mark ();
5149 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5151 if (b->val_bitsize != 0)
5152 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5154 /* We use value_equal_contents instead of value_equal because
5155 the latter coerces an array to a pointer, thus comparing just
5156 the address of the array instead of its contents. This is
5157 not what we want. */
5158 if ((b->val != NULL) != (new_val != NULL)
5159 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5161 if (new_val != NULL)
5163 release_value (new_val);
5164 value_free_to_mark (mark);
5166 bs->old_val = b->val;
5169 return WP_VALUE_CHANGED;
5173 /* Nothing changed. */
5174 value_free_to_mark (mark);
5175 return WP_VALUE_NOT_CHANGED;
5180 struct ui_out *uiout = current_uiout;
5182 /* This seems like the only logical thing to do because
5183 if we temporarily ignored the watchpoint, then when
5184 we reenter the block in which it is valid it contains
5185 garbage (in the case of a function, it may have two
5186 garbage values, one before and one after the prologue).
5187 So we can't even detect the first assignment to it and
5188 watch after that (since the garbage may or may not equal
5189 the first value assigned). */
5190 /* We print all the stop information in
5191 breakpoint_ops->print_it, but in this case, by the time we
5192 call breakpoint_ops->print_it this bp will be deleted
5193 already. So we have no choice but print the information
5195 if (ui_out_is_mi_like_p (uiout))
5197 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5198 ui_out_text (uiout, "\nWatchpoint ");
5199 ui_out_field_int (uiout, "wpnum", b->base.number);
5201 " deleted because the program has left the block in\n\
5202 which its expression is valid.\n");
5204 /* Make sure the watchpoint's commands aren't executed. */
5205 decref_counted_command_line (&b->base.commands);
5206 watchpoint_del_at_next_stop (b);
5212 /* Return true if it looks like target has stopped due to hitting
5213 breakpoint location BL. This function does not check if we should
5214 stop, only if BL explains the stop. */
5217 bpstat_check_location (const struct bp_location *bl,
5218 struct address_space *aspace, CORE_ADDR bp_addr,
5219 const struct target_waitstatus *ws)
5221 struct breakpoint *b = bl->owner;
5223 /* BL is from an existing breakpoint. */
5224 gdb_assert (b != NULL);
5226 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5229 /* Determine if the watched values have actually changed, and we
5230 should stop. If not, set BS->stop to 0. */
5233 bpstat_check_watchpoint (bpstat bs)
5235 const struct bp_location *bl;
5236 struct watchpoint *b;
5238 /* BS is built for existing struct breakpoint. */
5239 bl = bs->bp_location_at;
5240 gdb_assert (bl != NULL);
5241 b = (struct watchpoint *) bs->breakpoint_at;
5242 gdb_assert (b != NULL);
5245 int must_check_value = 0;
5247 if (b->base.type == bp_watchpoint)
5248 /* For a software watchpoint, we must always check the
5250 must_check_value = 1;
5251 else if (b->watchpoint_triggered == watch_triggered_yes)
5252 /* We have a hardware watchpoint (read, write, or access)
5253 and the target earlier reported an address watched by
5255 must_check_value = 1;
5256 else if (b->watchpoint_triggered == watch_triggered_unknown
5257 && b->base.type == bp_hardware_watchpoint)
5258 /* We were stopped by a hardware watchpoint, but the target could
5259 not report the data address. We must check the watchpoint's
5260 value. Access and read watchpoints are out of luck; without
5261 a data address, we can't figure it out. */
5262 must_check_value = 1;
5264 if (must_check_value)
5267 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5269 struct cleanup *cleanups = make_cleanup (xfree, message);
5270 int e = catch_errors (watchpoint_check, bs, message,
5272 do_cleanups (cleanups);
5276 /* We've already printed what needs to be printed. */
5277 bs->print_it = print_it_done;
5281 bs->print_it = print_it_noop;
5284 case WP_VALUE_CHANGED:
5285 if (b->base.type == bp_read_watchpoint)
5287 /* There are two cases to consider here:
5289 1. We're watching the triggered memory for reads.
5290 In that case, trust the target, and always report
5291 the watchpoint hit to the user. Even though
5292 reads don't cause value changes, the value may
5293 have changed since the last time it was read, and
5294 since we're not trapping writes, we will not see
5295 those, and as such we should ignore our notion of
5298 2. We're watching the triggered memory for both
5299 reads and writes. There are two ways this may
5302 2.1. This is a target that can't break on data
5303 reads only, but can break on accesses (reads or
5304 writes), such as e.g., x86. We detect this case
5305 at the time we try to insert read watchpoints.
5307 2.2. Otherwise, the target supports read
5308 watchpoints, but, the user set an access or write
5309 watchpoint watching the same memory as this read
5312 If we're watching memory writes as well as reads,
5313 ignore watchpoint hits when we find that the
5314 value hasn't changed, as reads don't cause
5315 changes. This still gives false positives when
5316 the program writes the same value to memory as
5317 what there was already in memory (we will confuse
5318 it for a read), but it's much better than
5321 int other_write_watchpoint = 0;
5323 if (bl->watchpoint_type == hw_read)
5325 struct breakpoint *other_b;
5327 ALL_BREAKPOINTS (other_b)
5328 if (other_b->type == bp_hardware_watchpoint
5329 || other_b->type == bp_access_watchpoint)
5331 struct watchpoint *other_w =
5332 (struct watchpoint *) other_b;
5334 if (other_w->watchpoint_triggered
5335 == watch_triggered_yes)
5337 other_write_watchpoint = 1;
5343 if (other_write_watchpoint
5344 || bl->watchpoint_type == hw_access)
5346 /* We're watching the same memory for writes,
5347 and the value changed since the last time we
5348 updated it, so this trap must be for a write.
5350 bs->print_it = print_it_noop;
5355 case WP_VALUE_NOT_CHANGED:
5356 if (b->base.type == bp_hardware_watchpoint
5357 || b->base.type == bp_watchpoint)
5359 /* Don't stop: write watchpoints shouldn't fire if
5360 the value hasn't changed. */
5361 bs->print_it = print_it_noop;
5369 /* Error from catch_errors. */
5370 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5371 watchpoint_del_at_next_stop (b);
5372 /* We've already printed what needs to be printed. */
5373 bs->print_it = print_it_done;
5377 else /* must_check_value == 0 */
5379 /* This is a case where some watchpoint(s) triggered, but
5380 not at the address of this watchpoint, or else no
5381 watchpoint triggered after all. So don't print
5382 anything for this watchpoint. */
5383 bs->print_it = print_it_noop;
5389 /* For breakpoints that are currently marked as telling gdb to stop,
5390 check conditions (condition proper, frame, thread and ignore count)
5391 of breakpoint referred to by BS. If we should not stop for this
5392 breakpoint, set BS->stop to 0. */
5395 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5397 const struct bp_location *bl;
5398 struct breakpoint *b;
5399 int value_is_zero = 0;
5400 struct expression *cond;
5402 gdb_assert (bs->stop);
5404 /* BS is built for existing struct breakpoint. */
5405 bl = bs->bp_location_at;
5406 gdb_assert (bl != NULL);
5407 b = bs->breakpoint_at;
5408 gdb_assert (b != NULL);
5410 /* Even if the target evaluated the condition on its end and notified GDB, we
5411 need to do so again since GDB does not know if we stopped due to a
5412 breakpoint or a single step breakpoint. */
5414 if (frame_id_p (b->frame_id)
5415 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5421 /* If this is a thread/task-specific breakpoint, don't waste cpu
5422 evaluating the condition if this isn't the specified
5424 if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid))
5425 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5432 /* Evaluate extension language breakpoints that have a "stop" method
5434 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5436 if (is_watchpoint (b))
5438 struct watchpoint *w = (struct watchpoint *) b;
5445 if (cond && b->disposition != disp_del_at_next_stop)
5447 int within_current_scope = 1;
5448 struct watchpoint * w;
5450 /* We use value_mark and value_free_to_mark because it could
5451 be a long time before we return to the command level and
5452 call free_all_values. We can't call free_all_values
5453 because we might be in the middle of evaluating a
5455 struct value *mark = value_mark ();
5457 if (is_watchpoint (b))
5458 w = (struct watchpoint *) b;
5462 /* Need to select the frame, with all that implies so that
5463 the conditions will have the right context. Because we
5464 use the frame, we will not see an inlined function's
5465 variables when we arrive at a breakpoint at the start
5466 of the inlined function; the current frame will be the
5468 if (w == NULL || w->cond_exp_valid_block == NULL)
5469 select_frame (get_current_frame ());
5472 struct frame_info *frame;
5474 /* For local watchpoint expressions, which particular
5475 instance of a local is being watched matters, so we
5476 keep track of the frame to evaluate the expression
5477 in. To evaluate the condition however, it doesn't
5478 really matter which instantiation of the function
5479 where the condition makes sense triggers the
5480 watchpoint. This allows an expression like "watch
5481 global if q > 10" set in `func', catch writes to
5482 global on all threads that call `func', or catch
5483 writes on all recursive calls of `func' by a single
5484 thread. We simply always evaluate the condition in
5485 the innermost frame that's executing where it makes
5486 sense to evaluate the condition. It seems
5488 frame = block_innermost_frame (w->cond_exp_valid_block);
5490 select_frame (frame);
5492 within_current_scope = 0;
5494 if (within_current_scope)
5496 = catch_errors (breakpoint_cond_eval, cond,
5497 "Error in testing breakpoint condition:\n",
5501 warning (_("Watchpoint condition cannot be tested "
5502 "in the current scope"));
5503 /* If we failed to set the right context for this
5504 watchpoint, unconditionally report it. */
5507 /* FIXME-someday, should give breakpoint #. */
5508 value_free_to_mark (mark);
5511 if (cond && value_is_zero)
5515 else if (b->ignore_count > 0)
5519 /* Increase the hit count even though we don't stop. */
5521 observer_notify_breakpoint_modified (b);
5526 /* Get a bpstat associated with having just stopped at address
5527 BP_ADDR in thread PTID.
5529 Determine whether we stopped at a breakpoint, etc, or whether we
5530 don't understand this stop. Result is a chain of bpstat's such
5533 if we don't understand the stop, the result is a null pointer.
5535 if we understand why we stopped, the result is not null.
5537 Each element of the chain refers to a particular breakpoint or
5538 watchpoint at which we have stopped. (We may have stopped for
5539 several reasons concurrently.)
5541 Each element of the chain has valid next, breakpoint_at,
5542 commands, FIXME??? fields. */
5545 bpstat_stop_status (struct address_space *aspace,
5546 CORE_ADDR bp_addr, ptid_t ptid,
5547 const struct target_waitstatus *ws)
5549 struct breakpoint *b = NULL;
5550 struct bp_location *bl;
5551 struct bp_location *loc;
5552 /* First item of allocated bpstat's. */
5553 bpstat bs_head = NULL, *bs_link = &bs_head;
5554 /* Pointer to the last thing in the chain currently. */
5557 int need_remove_insert;
5560 /* First, build the bpstat chain with locations that explain a
5561 target stop, while being careful to not set the target running,
5562 as that may invalidate locations (in particular watchpoint
5563 locations are recreated). Resuming will happen here with
5564 breakpoint conditions or watchpoint expressions that include
5565 inferior function calls. */
5569 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5572 for (bl = b->loc; bl != NULL; bl = bl->next)
5574 /* For hardware watchpoints, we look only at the first
5575 location. The watchpoint_check function will work on the
5576 entire expression, not the individual locations. For
5577 read watchpoints, the watchpoints_triggered function has
5578 checked all locations already. */
5579 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5582 if (!bl->enabled || bl->shlib_disabled)
5585 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5588 /* Come here if it's a watchpoint, or if the break address
5591 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5594 /* Assume we stop. Should we find a watchpoint that is not
5595 actually triggered, or if the condition of the breakpoint
5596 evaluates as false, we'll reset 'stop' to 0. */
5600 /* If this is a scope breakpoint, mark the associated
5601 watchpoint as triggered so that we will handle the
5602 out-of-scope event. We'll get to the watchpoint next
5604 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5606 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5608 w->watchpoint_triggered = watch_triggered_yes;
5613 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5615 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5617 bs = bpstat_alloc (loc, &bs_link);
5618 /* For hits of moribund locations, we should just proceed. */
5621 bs->print_it = print_it_noop;
5625 /* A bit of special processing for shlib breakpoints. We need to
5626 process solib loading here, so that the lists of loaded and
5627 unloaded libraries are correct before we handle "catch load" and
5629 for (bs = bs_head; bs != NULL; bs = bs->next)
5631 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5633 handle_solib_event ();
5638 /* Now go through the locations that caused the target to stop, and
5639 check whether we're interested in reporting this stop to higher
5640 layers, or whether we should resume the target transparently. */
5644 for (bs = bs_head; bs != NULL; bs = bs->next)
5649 b = bs->breakpoint_at;
5650 b->ops->check_status (bs);
5653 bpstat_check_breakpoint_conditions (bs, ptid);
5658 observer_notify_breakpoint_modified (b);
5660 /* We will stop here. */
5661 if (b->disposition == disp_disable)
5663 --(b->enable_count);
5664 if (b->enable_count <= 0
5665 && b->enable_state != bp_permanent)
5666 b->enable_state = bp_disabled;
5671 bs->commands = b->commands;
5672 incref_counted_command_line (bs->commands);
5673 if (command_line_is_silent (bs->commands
5674 ? bs->commands->commands : NULL))
5677 b->ops->after_condition_true (bs);
5682 /* Print nothing for this entry if we don't stop or don't
5684 if (!bs->stop || !bs->print)
5685 bs->print_it = print_it_noop;
5688 /* If we aren't stopping, the value of some hardware watchpoint may
5689 not have changed, but the intermediate memory locations we are
5690 watching may have. Don't bother if we're stopping; this will get
5692 need_remove_insert = 0;
5693 if (! bpstat_causes_stop (bs_head))
5694 for (bs = bs_head; bs != NULL; bs = bs->next)
5696 && bs->breakpoint_at
5697 && is_hardware_watchpoint (bs->breakpoint_at))
5699 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5701 update_watchpoint (w, 0 /* don't reparse. */);
5702 need_remove_insert = 1;
5705 if (need_remove_insert)
5706 update_global_location_list (UGLL_MAY_INSERT);
5707 else if (removed_any)
5708 update_global_location_list (UGLL_DONT_INSERT);
5714 handle_jit_event (void)
5716 struct frame_info *frame;
5717 struct gdbarch *gdbarch;
5719 /* Switch terminal for any messages produced by
5720 breakpoint_re_set. */
5721 target_terminal_ours_for_output ();
5723 frame = get_current_frame ();
5724 gdbarch = get_frame_arch (frame);
5726 jit_event_handler (gdbarch);
5728 target_terminal_inferior ();
5731 /* Prepare WHAT final decision for infrun. */
5733 /* Decide what infrun needs to do with this bpstat. */
5736 bpstat_what (bpstat bs_head)
5738 struct bpstat_what retval;
5742 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5743 retval.call_dummy = STOP_NONE;
5744 retval.is_longjmp = 0;
5746 for (bs = bs_head; bs != NULL; bs = bs->next)
5748 /* Extract this BS's action. After processing each BS, we check
5749 if its action overrides all we've seem so far. */
5750 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5753 if (bs->breakpoint_at == NULL)
5755 /* I suspect this can happen if it was a momentary
5756 breakpoint which has since been deleted. */
5760 bptype = bs->breakpoint_at->type;
5767 case bp_hardware_breakpoint:
5770 case bp_shlib_event:
5774 this_action = BPSTAT_WHAT_STOP_NOISY;
5776 this_action = BPSTAT_WHAT_STOP_SILENT;
5779 this_action = BPSTAT_WHAT_SINGLE;
5782 case bp_hardware_watchpoint:
5783 case bp_read_watchpoint:
5784 case bp_access_watchpoint:
5788 this_action = BPSTAT_WHAT_STOP_NOISY;
5790 this_action = BPSTAT_WHAT_STOP_SILENT;
5794 /* There was a watchpoint, but we're not stopping.
5795 This requires no further action. */
5799 case bp_longjmp_call_dummy:
5801 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5802 retval.is_longjmp = bptype != bp_exception;
5804 case bp_longjmp_resume:
5805 case bp_exception_resume:
5806 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5807 retval.is_longjmp = bptype == bp_longjmp_resume;
5809 case bp_step_resume:
5811 this_action = BPSTAT_WHAT_STEP_RESUME;
5814 /* It is for the wrong frame. */
5815 this_action = BPSTAT_WHAT_SINGLE;
5818 case bp_hp_step_resume:
5820 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5823 /* It is for the wrong frame. */
5824 this_action = BPSTAT_WHAT_SINGLE;
5827 case bp_watchpoint_scope:
5828 case bp_thread_event:
5829 case bp_overlay_event:
5830 case bp_longjmp_master:
5831 case bp_std_terminate_master:
5832 case bp_exception_master:
5833 this_action = BPSTAT_WHAT_SINGLE;
5839 this_action = BPSTAT_WHAT_STOP_NOISY;
5841 this_action = BPSTAT_WHAT_STOP_SILENT;
5845 /* There was a catchpoint, but we're not stopping.
5846 This requires no further action. */
5851 this_action = BPSTAT_WHAT_SINGLE;
5854 /* Make sure the action is stop (silent or noisy),
5855 so infrun.c pops the dummy frame. */
5856 retval.call_dummy = STOP_STACK_DUMMY;
5857 this_action = BPSTAT_WHAT_STOP_SILENT;
5859 case bp_std_terminate:
5860 /* Make sure the action is stop (silent or noisy),
5861 so infrun.c pops the dummy frame. */
5862 retval.call_dummy = STOP_STD_TERMINATE;
5863 this_action = BPSTAT_WHAT_STOP_SILENT;
5866 case bp_fast_tracepoint:
5867 case bp_static_tracepoint:
5868 /* Tracepoint hits should not be reported back to GDB, and
5869 if one got through somehow, it should have been filtered
5871 internal_error (__FILE__, __LINE__,
5872 _("bpstat_what: tracepoint encountered"));
5874 case bp_gnu_ifunc_resolver:
5875 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5876 this_action = BPSTAT_WHAT_SINGLE;
5878 case bp_gnu_ifunc_resolver_return:
5879 /* The breakpoint will be removed, execution will restart from the
5880 PC of the former breakpoint. */
5881 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5886 this_action = BPSTAT_WHAT_STOP_SILENT;
5888 this_action = BPSTAT_WHAT_SINGLE;
5892 internal_error (__FILE__, __LINE__,
5893 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5896 retval.main_action = max (retval.main_action, this_action);
5899 /* These operations may affect the bs->breakpoint_at state so they are
5900 delayed after MAIN_ACTION is decided above. */
5905 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5907 handle_jit_event ();
5910 for (bs = bs_head; bs != NULL; bs = bs->next)
5912 struct breakpoint *b = bs->breakpoint_at;
5918 case bp_gnu_ifunc_resolver:
5919 gnu_ifunc_resolver_stop (b);
5921 case bp_gnu_ifunc_resolver_return:
5922 gnu_ifunc_resolver_return_stop (b);
5930 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5931 without hardware support). This isn't related to a specific bpstat,
5932 just to things like whether watchpoints are set. */
5935 bpstat_should_step (void)
5937 struct breakpoint *b;
5940 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5946 bpstat_causes_stop (bpstat bs)
5948 for (; bs != NULL; bs = bs->next)
5957 /* Compute a string of spaces suitable to indent the next line
5958 so it starts at the position corresponding to the table column
5959 named COL_NAME in the currently active table of UIOUT. */
5962 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5964 static char wrap_indent[80];
5965 int i, total_width, width, align;
5969 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5971 if (strcmp (text, col_name) == 0)
5973 gdb_assert (total_width < sizeof wrap_indent);
5974 memset (wrap_indent, ' ', total_width);
5975 wrap_indent[total_width] = 0;
5980 total_width += width + 1;
5986 /* Determine if the locations of this breakpoint will have their conditions
5987 evaluated by the target, host or a mix of both. Returns the following:
5989 "host": Host evals condition.
5990 "host or target": Host or Target evals condition.
5991 "target": Target evals condition.
5995 bp_condition_evaluator (struct breakpoint *b)
5997 struct bp_location *bl;
5998 char host_evals = 0;
5999 char target_evals = 0;
6004 if (!is_breakpoint (b))
6007 if (gdb_evaluates_breakpoint_condition_p ()
6008 || !target_supports_evaluation_of_breakpoint_conditions ())
6009 return condition_evaluation_host;
6011 for (bl = b->loc; bl; bl = bl->next)
6013 if (bl->cond_bytecode)
6019 if (host_evals && target_evals)
6020 return condition_evaluation_both;
6021 else if (target_evals)
6022 return condition_evaluation_target;
6024 return condition_evaluation_host;
6027 /* Determine the breakpoint location's condition evaluator. This is
6028 similar to bp_condition_evaluator, but for locations. */
6031 bp_location_condition_evaluator (struct bp_location *bl)
6033 if (bl && !is_breakpoint (bl->owner))
6036 if (gdb_evaluates_breakpoint_condition_p ()
6037 || !target_supports_evaluation_of_breakpoint_conditions ())
6038 return condition_evaluation_host;
6040 if (bl && bl->cond_bytecode)
6041 return condition_evaluation_target;
6043 return condition_evaluation_host;
6046 /* Print the LOC location out of the list of B->LOC locations. */
6049 print_breakpoint_location (struct breakpoint *b,
6050 struct bp_location *loc)
6052 struct ui_out *uiout = current_uiout;
6053 struct cleanup *old_chain = save_current_program_space ();
6055 if (loc != NULL && loc->shlib_disabled)
6059 set_current_program_space (loc->pspace);
6061 if (b->display_canonical)
6062 ui_out_field_string (uiout, "what", b->addr_string);
6063 else if (loc && loc->symtab)
6066 = find_pc_sect_function (loc->address, loc->section);
6069 ui_out_text (uiout, "in ");
6070 ui_out_field_string (uiout, "func",
6071 SYMBOL_PRINT_NAME (sym));
6072 ui_out_text (uiout, " ");
6073 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6074 ui_out_text (uiout, "at ");
6076 ui_out_field_string (uiout, "file",
6077 symtab_to_filename_for_display (loc->symtab));
6078 ui_out_text (uiout, ":");
6080 if (ui_out_is_mi_like_p (uiout))
6081 ui_out_field_string (uiout, "fullname",
6082 symtab_to_fullname (loc->symtab));
6084 ui_out_field_int (uiout, "line", loc->line_number);
6088 struct ui_file *stb = mem_fileopen ();
6089 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6091 print_address_symbolic (loc->gdbarch, loc->address, stb,
6093 ui_out_field_stream (uiout, "at", stb);
6095 do_cleanups (stb_chain);
6098 ui_out_field_string (uiout, "pending", b->addr_string);
6100 if (loc && is_breakpoint (b)
6101 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6102 && bp_condition_evaluator (b) == condition_evaluation_both)
6104 ui_out_text (uiout, " (");
6105 ui_out_field_string (uiout, "evaluated-by",
6106 bp_location_condition_evaluator (loc));
6107 ui_out_text (uiout, ")");
6110 do_cleanups (old_chain);
6114 bptype_string (enum bptype type)
6116 struct ep_type_description
6121 static struct ep_type_description bptypes[] =
6123 {bp_none, "?deleted?"},
6124 {bp_breakpoint, "breakpoint"},
6125 {bp_hardware_breakpoint, "hw breakpoint"},
6126 {bp_until, "until"},
6127 {bp_finish, "finish"},
6128 {bp_watchpoint, "watchpoint"},
6129 {bp_hardware_watchpoint, "hw watchpoint"},
6130 {bp_read_watchpoint, "read watchpoint"},
6131 {bp_access_watchpoint, "acc watchpoint"},
6132 {bp_longjmp, "longjmp"},
6133 {bp_longjmp_resume, "longjmp resume"},
6134 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6135 {bp_exception, "exception"},
6136 {bp_exception_resume, "exception resume"},
6137 {bp_step_resume, "step resume"},
6138 {bp_hp_step_resume, "high-priority step resume"},
6139 {bp_watchpoint_scope, "watchpoint scope"},
6140 {bp_call_dummy, "call dummy"},
6141 {bp_std_terminate, "std::terminate"},
6142 {bp_shlib_event, "shlib events"},
6143 {bp_thread_event, "thread events"},
6144 {bp_overlay_event, "overlay events"},
6145 {bp_longjmp_master, "longjmp master"},
6146 {bp_std_terminate_master, "std::terminate master"},
6147 {bp_exception_master, "exception master"},
6148 {bp_catchpoint, "catchpoint"},
6149 {bp_tracepoint, "tracepoint"},
6150 {bp_fast_tracepoint, "fast tracepoint"},
6151 {bp_static_tracepoint, "static tracepoint"},
6152 {bp_dprintf, "dprintf"},
6153 {bp_jit_event, "jit events"},
6154 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6155 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6158 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6159 || ((int) type != bptypes[(int) type].type))
6160 internal_error (__FILE__, __LINE__,
6161 _("bptypes table does not describe type #%d."),
6164 return bptypes[(int) type].description;
6167 /* For MI, output a field named 'thread-groups' with a list as the value.
6168 For CLI, prefix the list with the string 'inf'. */
6171 output_thread_groups (struct ui_out *uiout,
6172 const char *field_name,
6176 struct cleanup *back_to;
6177 int is_mi = ui_out_is_mi_like_p (uiout);
6181 /* For backward compatibility, don't display inferiors in CLI unless
6182 there are several. Always display them for MI. */
6183 if (!is_mi && mi_only)
6186 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6188 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6194 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6195 ui_out_field_string (uiout, NULL, mi_group);
6200 ui_out_text (uiout, " inf ");
6202 ui_out_text (uiout, ", ");
6204 ui_out_text (uiout, plongest (inf));
6208 do_cleanups (back_to);
6211 /* Print B to gdb_stdout. */
6214 print_one_breakpoint_location (struct breakpoint *b,
6215 struct bp_location *loc,
6217 struct bp_location **last_loc,
6220 struct command_line *l;
6221 static char bpenables[] = "nynny";
6223 struct ui_out *uiout = current_uiout;
6224 int header_of_multiple = 0;
6225 int part_of_multiple = (loc != NULL);
6226 struct value_print_options opts;
6228 get_user_print_options (&opts);
6230 gdb_assert (!loc || loc_number != 0);
6231 /* See comment in print_one_breakpoint concerning treatment of
6232 breakpoints with single disabled location. */
6235 && (b->loc->next != NULL || !b->loc->enabled)))
6236 header_of_multiple = 1;
6244 if (part_of_multiple)
6247 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6248 ui_out_field_string (uiout, "number", formatted);
6253 ui_out_field_int (uiout, "number", b->number);
6258 if (part_of_multiple)
6259 ui_out_field_skip (uiout, "type");
6261 ui_out_field_string (uiout, "type", bptype_string (b->type));
6265 if (part_of_multiple)
6266 ui_out_field_skip (uiout, "disp");
6268 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6273 if (part_of_multiple)
6274 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6276 ui_out_field_fmt (uiout, "enabled", "%c",
6277 bpenables[(int) b->enable_state]);
6278 ui_out_spaces (uiout, 2);
6282 if (b->ops != NULL && b->ops->print_one != NULL)
6284 /* Although the print_one can possibly print all locations,
6285 calling it here is not likely to get any nice result. So,
6286 make sure there's just one location. */
6287 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6288 b->ops->print_one (b, last_loc);
6294 internal_error (__FILE__, __LINE__,
6295 _("print_one_breakpoint: bp_none encountered\n"));
6299 case bp_hardware_watchpoint:
6300 case bp_read_watchpoint:
6301 case bp_access_watchpoint:
6303 struct watchpoint *w = (struct watchpoint *) b;
6305 /* Field 4, the address, is omitted (which makes the columns
6306 not line up too nicely with the headers, but the effect
6307 is relatively readable). */
6308 if (opts.addressprint)
6309 ui_out_field_skip (uiout, "addr");
6311 ui_out_field_string (uiout, "what", w->exp_string);
6316 case bp_hardware_breakpoint:
6320 case bp_longjmp_resume:
6321 case bp_longjmp_call_dummy:
6323 case bp_exception_resume:
6324 case bp_step_resume:
6325 case bp_hp_step_resume:
6326 case bp_watchpoint_scope:
6328 case bp_std_terminate:
6329 case bp_shlib_event:
6330 case bp_thread_event:
6331 case bp_overlay_event:
6332 case bp_longjmp_master:
6333 case bp_std_terminate_master:
6334 case bp_exception_master:
6336 case bp_fast_tracepoint:
6337 case bp_static_tracepoint:
6340 case bp_gnu_ifunc_resolver:
6341 case bp_gnu_ifunc_resolver_return:
6342 if (opts.addressprint)
6345 if (header_of_multiple)
6346 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6347 else if (b->loc == NULL || loc->shlib_disabled)
6348 ui_out_field_string (uiout, "addr", "<PENDING>");
6350 ui_out_field_core_addr (uiout, "addr",
6351 loc->gdbarch, loc->address);
6354 if (!header_of_multiple)
6355 print_breakpoint_location (b, loc);
6362 if (loc != NULL && !header_of_multiple)
6364 struct inferior *inf;
6365 VEC(int) *inf_num = NULL;
6370 if (inf->pspace == loc->pspace)
6371 VEC_safe_push (int, inf_num, inf->num);
6374 /* For backward compatibility, don't display inferiors in CLI unless
6375 there are several. Always display for MI. */
6377 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6378 && (number_of_program_spaces () > 1
6379 || number_of_inferiors () > 1)
6380 /* LOC is for existing B, it cannot be in
6381 moribund_locations and thus having NULL OWNER. */
6382 && loc->owner->type != bp_catchpoint))
6384 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6385 VEC_free (int, inf_num);
6388 if (!part_of_multiple)
6390 if (b->thread != -1)
6392 /* FIXME: This seems to be redundant and lost here; see the
6393 "stop only in" line a little further down. */
6394 ui_out_text (uiout, " thread ");
6395 ui_out_field_int (uiout, "thread", b->thread);
6397 else if (b->task != 0)
6399 ui_out_text (uiout, " task ");
6400 ui_out_field_int (uiout, "task", b->task);
6404 ui_out_text (uiout, "\n");
6406 if (!part_of_multiple)
6407 b->ops->print_one_detail (b, uiout);
6409 if (part_of_multiple && frame_id_p (b->frame_id))
6412 ui_out_text (uiout, "\tstop only in stack frame at ");
6413 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6415 ui_out_field_core_addr (uiout, "frame",
6416 b->gdbarch, b->frame_id.stack_addr);
6417 ui_out_text (uiout, "\n");
6420 if (!part_of_multiple && b->cond_string)
6423 if (is_tracepoint (b))
6424 ui_out_text (uiout, "\ttrace only if ");
6426 ui_out_text (uiout, "\tstop only if ");
6427 ui_out_field_string (uiout, "cond", b->cond_string);
6429 /* Print whether the target is doing the breakpoint's condition
6430 evaluation. If GDB is doing the evaluation, don't print anything. */
6431 if (is_breakpoint (b)
6432 && breakpoint_condition_evaluation_mode ()
6433 == condition_evaluation_target)
6435 ui_out_text (uiout, " (");
6436 ui_out_field_string (uiout, "evaluated-by",
6437 bp_condition_evaluator (b));
6438 ui_out_text (uiout, " evals)");
6440 ui_out_text (uiout, "\n");
6443 if (!part_of_multiple && b->thread != -1)
6445 /* FIXME should make an annotation for this. */
6446 ui_out_text (uiout, "\tstop only in thread ");
6447 ui_out_field_int (uiout, "thread", b->thread);
6448 ui_out_text (uiout, "\n");
6451 if (!part_of_multiple)
6455 /* FIXME should make an annotation for this. */
6456 if (is_catchpoint (b))
6457 ui_out_text (uiout, "\tcatchpoint");
6458 else if (is_tracepoint (b))
6459 ui_out_text (uiout, "\ttracepoint");
6461 ui_out_text (uiout, "\tbreakpoint");
6462 ui_out_text (uiout, " already hit ");
6463 ui_out_field_int (uiout, "times", b->hit_count);
6464 if (b->hit_count == 1)
6465 ui_out_text (uiout, " time\n");
6467 ui_out_text (uiout, " times\n");
6471 /* Output the count also if it is zero, but only if this is mi. */
6472 if (ui_out_is_mi_like_p (uiout))
6473 ui_out_field_int (uiout, "times", b->hit_count);
6477 if (!part_of_multiple && b->ignore_count)
6480 ui_out_text (uiout, "\tignore next ");
6481 ui_out_field_int (uiout, "ignore", b->ignore_count);
6482 ui_out_text (uiout, " hits\n");
6485 /* Note that an enable count of 1 corresponds to "enable once"
6486 behavior, which is reported by the combination of enablement and
6487 disposition, so we don't need to mention it here. */
6488 if (!part_of_multiple && b->enable_count > 1)
6491 ui_out_text (uiout, "\tdisable after ");
6492 /* Tweak the wording to clarify that ignore and enable counts
6493 are distinct, and have additive effect. */
6494 if (b->ignore_count)
6495 ui_out_text (uiout, "additional ");
6497 ui_out_text (uiout, "next ");
6498 ui_out_field_int (uiout, "enable", b->enable_count);
6499 ui_out_text (uiout, " hits\n");
6502 if (!part_of_multiple && is_tracepoint (b))
6504 struct tracepoint *tp = (struct tracepoint *) b;
6506 if (tp->traceframe_usage)
6508 ui_out_text (uiout, "\ttrace buffer usage ");
6509 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6510 ui_out_text (uiout, " bytes\n");
6514 l = b->commands ? b->commands->commands : NULL;
6515 if (!part_of_multiple && l)
6517 struct cleanup *script_chain;
6520 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6521 print_command_lines (uiout, l, 4);
6522 do_cleanups (script_chain);
6525 if (is_tracepoint (b))
6527 struct tracepoint *t = (struct tracepoint *) b;
6529 if (!part_of_multiple && t->pass_count)
6531 annotate_field (10);
6532 ui_out_text (uiout, "\tpass count ");
6533 ui_out_field_int (uiout, "pass", t->pass_count);
6534 ui_out_text (uiout, " \n");
6537 /* Don't display it when tracepoint or tracepoint location is
6539 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6541 annotate_field (11);
6543 if (ui_out_is_mi_like_p (uiout))
6544 ui_out_field_string (uiout, "installed",
6545 loc->inserted ? "y" : "n");
6549 ui_out_text (uiout, "\t");
6551 ui_out_text (uiout, "\tnot ");
6552 ui_out_text (uiout, "installed on target\n");
6557 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6559 if (is_watchpoint (b))
6561 struct watchpoint *w = (struct watchpoint *) b;
6563 ui_out_field_string (uiout, "original-location", w->exp_string);
6565 else if (b->addr_string)
6566 ui_out_field_string (uiout, "original-location", b->addr_string);
6571 print_one_breakpoint (struct breakpoint *b,
6572 struct bp_location **last_loc,
6575 struct cleanup *bkpt_chain;
6576 struct ui_out *uiout = current_uiout;
6578 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6580 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6581 do_cleanups (bkpt_chain);
6583 /* If this breakpoint has custom print function,
6584 it's already printed. Otherwise, print individual
6585 locations, if any. */
6586 if (b->ops == NULL || b->ops->print_one == NULL)
6588 /* If breakpoint has a single location that is disabled, we
6589 print it as if it had several locations, since otherwise it's
6590 hard to represent "breakpoint enabled, location disabled"
6593 Note that while hardware watchpoints have several locations
6594 internally, that's not a property exposed to user. */
6596 && !is_hardware_watchpoint (b)
6597 && (b->loc->next || !b->loc->enabled))
6599 struct bp_location *loc;
6602 for (loc = b->loc; loc; loc = loc->next, ++n)
6604 struct cleanup *inner2 =
6605 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6606 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6607 do_cleanups (inner2);
6614 breakpoint_address_bits (struct breakpoint *b)
6616 int print_address_bits = 0;
6617 struct bp_location *loc;
6619 for (loc = b->loc; loc; loc = loc->next)
6623 /* Software watchpoints that aren't watching memory don't have
6624 an address to print. */
6625 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6628 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6629 if (addr_bit > print_address_bits)
6630 print_address_bits = addr_bit;
6633 return print_address_bits;
6636 struct captured_breakpoint_query_args
6642 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6644 struct captured_breakpoint_query_args *args = data;
6645 struct breakpoint *b;
6646 struct bp_location *dummy_loc = NULL;
6650 if (args->bnum == b->number)
6652 print_one_breakpoint (b, &dummy_loc, 0);
6660 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6661 char **error_message)
6663 struct captured_breakpoint_query_args args;
6666 /* For the moment we don't trust print_one_breakpoint() to not throw
6668 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6669 error_message, RETURN_MASK_ALL) < 0)
6675 /* Return true if this breakpoint was set by the user, false if it is
6676 internal or momentary. */
6679 user_breakpoint_p (struct breakpoint *b)
6681 return b->number > 0;
6684 /* Print information on user settable breakpoint (watchpoint, etc)
6685 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6686 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6687 FILTER is non-NULL, call it on each breakpoint and only include the
6688 ones for which it returns non-zero. Return the total number of
6689 breakpoints listed. */
6692 breakpoint_1 (char *args, int allflag,
6693 int (*filter) (const struct breakpoint *))
6695 struct breakpoint *b;
6696 struct bp_location *last_loc = NULL;
6697 int nr_printable_breakpoints;
6698 struct cleanup *bkpttbl_chain;
6699 struct value_print_options opts;
6700 int print_address_bits = 0;
6701 int print_type_col_width = 14;
6702 struct ui_out *uiout = current_uiout;
6704 get_user_print_options (&opts);
6706 /* Compute the number of rows in the table, as well as the size
6707 required for address fields. */
6708 nr_printable_breakpoints = 0;
6711 /* If we have a filter, only list the breakpoints it accepts. */
6712 if (filter && !filter (b))
6715 /* If we have an "args" string, it is a list of breakpoints to
6716 accept. Skip the others. */
6717 if (args != NULL && *args != '\0')
6719 if (allflag && parse_and_eval_long (args) != b->number)
6721 if (!allflag && !number_is_in_list (args, b->number))
6725 if (allflag || user_breakpoint_p (b))
6727 int addr_bit, type_len;
6729 addr_bit = breakpoint_address_bits (b);
6730 if (addr_bit > print_address_bits)
6731 print_address_bits = addr_bit;
6733 type_len = strlen (bptype_string (b->type));
6734 if (type_len > print_type_col_width)
6735 print_type_col_width = type_len;
6737 nr_printable_breakpoints++;
6741 if (opts.addressprint)
6743 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6744 nr_printable_breakpoints,
6748 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6749 nr_printable_breakpoints,
6752 if (nr_printable_breakpoints > 0)
6753 annotate_breakpoints_headers ();
6754 if (nr_printable_breakpoints > 0)
6756 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6757 if (nr_printable_breakpoints > 0)
6759 ui_out_table_header (uiout, print_type_col_width, ui_left,
6760 "type", "Type"); /* 2 */
6761 if (nr_printable_breakpoints > 0)
6763 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6764 if (nr_printable_breakpoints > 0)
6766 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6767 if (opts.addressprint)
6769 if (nr_printable_breakpoints > 0)
6771 if (print_address_bits <= 32)
6772 ui_out_table_header (uiout, 10, ui_left,
6773 "addr", "Address"); /* 5 */
6775 ui_out_table_header (uiout, 18, ui_left,
6776 "addr", "Address"); /* 5 */
6778 if (nr_printable_breakpoints > 0)
6780 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6781 ui_out_table_body (uiout);
6782 if (nr_printable_breakpoints > 0)
6783 annotate_breakpoints_table ();
6788 /* If we have a filter, only list the breakpoints it accepts. */
6789 if (filter && !filter (b))
6792 /* If we have an "args" string, it is a list of breakpoints to
6793 accept. Skip the others. */
6795 if (args != NULL && *args != '\0')
6797 if (allflag) /* maintenance info breakpoint */
6799 if (parse_and_eval_long (args) != b->number)
6802 else /* all others */
6804 if (!number_is_in_list (args, b->number))
6808 /* We only print out user settable breakpoints unless the
6810 if (allflag || user_breakpoint_p (b))
6811 print_one_breakpoint (b, &last_loc, allflag);
6814 do_cleanups (bkpttbl_chain);
6816 if (nr_printable_breakpoints == 0)
6818 /* If there's a filter, let the caller decide how to report
6822 if (args == NULL || *args == '\0')
6823 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6825 ui_out_message (uiout, 0,
6826 "No breakpoint or watchpoint matching '%s'.\n",
6832 if (last_loc && !server_command)
6833 set_next_address (last_loc->gdbarch, last_loc->address);
6836 /* FIXME? Should this be moved up so that it is only called when
6837 there have been breakpoints? */
6838 annotate_breakpoints_table_end ();
6840 return nr_printable_breakpoints;
6843 /* Display the value of default-collect in a way that is generally
6844 compatible with the breakpoint list. */
6847 default_collect_info (void)
6849 struct ui_out *uiout = current_uiout;
6851 /* If it has no value (which is frequently the case), say nothing; a
6852 message like "No default-collect." gets in user's face when it's
6854 if (!*default_collect)
6857 /* The following phrase lines up nicely with per-tracepoint collect
6859 ui_out_text (uiout, "default collect ");
6860 ui_out_field_string (uiout, "default-collect", default_collect);
6861 ui_out_text (uiout, " \n");
6865 breakpoints_info (char *args, int from_tty)
6867 breakpoint_1 (args, 0, NULL);
6869 default_collect_info ();
6873 watchpoints_info (char *args, int from_tty)
6875 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6876 struct ui_out *uiout = current_uiout;
6878 if (num_printed == 0)
6880 if (args == NULL || *args == '\0')
6881 ui_out_message (uiout, 0, "No watchpoints.\n");
6883 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6888 maintenance_info_breakpoints (char *args, int from_tty)
6890 breakpoint_1 (args, 1, NULL);
6892 default_collect_info ();
6896 breakpoint_has_pc (struct breakpoint *b,
6897 struct program_space *pspace,
6898 CORE_ADDR pc, struct obj_section *section)
6900 struct bp_location *bl = b->loc;
6902 for (; bl; bl = bl->next)
6904 if (bl->pspace == pspace
6905 && bl->address == pc
6906 && (!overlay_debugging || bl->section == section))
6912 /* Print a message describing any user-breakpoints set at PC. This
6913 concerns with logical breakpoints, so we match program spaces, not
6917 describe_other_breakpoints (struct gdbarch *gdbarch,
6918 struct program_space *pspace, CORE_ADDR pc,
6919 struct obj_section *section, int thread)
6922 struct breakpoint *b;
6925 others += (user_breakpoint_p (b)
6926 && breakpoint_has_pc (b, pspace, pc, section));
6930 printf_filtered (_("Note: breakpoint "));
6931 else /* if (others == ???) */
6932 printf_filtered (_("Note: breakpoints "));
6934 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6937 printf_filtered ("%d", b->number);
6938 if (b->thread == -1 && thread != -1)
6939 printf_filtered (" (all threads)");
6940 else if (b->thread != -1)
6941 printf_filtered (" (thread %d)", b->thread);
6942 printf_filtered ("%s%s ",
6943 ((b->enable_state == bp_disabled
6944 || b->enable_state == bp_call_disabled)
6946 : b->enable_state == bp_permanent
6950 : ((others == 1) ? " and" : ""));
6952 printf_filtered (_("also set at pc "));
6953 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6954 printf_filtered (".\n");
6959 /* Return true iff it is meaningful to use the address member of
6960 BPT. For some breakpoint types, the address member is irrelevant
6961 and it makes no sense to attempt to compare it to other addresses
6962 (or use it for any other purpose either).
6964 More specifically, each of the following breakpoint types will
6965 always have a zero valued address and we don't want to mark
6966 breakpoints of any of these types to be a duplicate of an actual
6967 breakpoint at address zero:
6975 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6977 enum bptype type = bpt->type;
6979 return (type != bp_watchpoint && type != bp_catchpoint);
6982 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6983 true if LOC1 and LOC2 represent the same watchpoint location. */
6986 watchpoint_locations_match (struct bp_location *loc1,
6987 struct bp_location *loc2)
6989 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6990 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6992 /* Both of them must exist. */
6993 gdb_assert (w1 != NULL);
6994 gdb_assert (w2 != NULL);
6996 /* If the target can evaluate the condition expression in hardware,
6997 then we we need to insert both watchpoints even if they are at
6998 the same place. Otherwise the watchpoint will only trigger when
6999 the condition of whichever watchpoint was inserted evaluates to
7000 true, not giving a chance for GDB to check the condition of the
7001 other watchpoint. */
7003 && target_can_accel_watchpoint_condition (loc1->address,
7005 loc1->watchpoint_type,
7008 && target_can_accel_watchpoint_condition (loc2->address,
7010 loc2->watchpoint_type,
7014 /* Note that this checks the owner's type, not the location's. In
7015 case the target does not support read watchpoints, but does
7016 support access watchpoints, we'll have bp_read_watchpoint
7017 watchpoints with hw_access locations. Those should be considered
7018 duplicates of hw_read locations. The hw_read locations will
7019 become hw_access locations later. */
7020 return (loc1->owner->type == loc2->owner->type
7021 && loc1->pspace->aspace == loc2->pspace->aspace
7022 && loc1->address == loc2->address
7023 && loc1->length == loc2->length);
7026 /* See breakpoint.h. */
7029 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7030 struct address_space *aspace2, CORE_ADDR addr2)
7032 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7033 || aspace1 == aspace2)
7037 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7038 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7039 matches ASPACE2. On targets that have global breakpoints, the address
7040 space doesn't really matter. */
7043 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7044 int len1, struct address_space *aspace2,
7047 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7048 || aspace1 == aspace2)
7049 && addr2 >= addr1 && addr2 < addr1 + len1);
7052 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7053 a ranged breakpoint. In most targets, a match happens only if ASPACE
7054 matches the breakpoint's address space. On targets that have global
7055 breakpoints, the address space doesn't really matter. */
7058 breakpoint_location_address_match (struct bp_location *bl,
7059 struct address_space *aspace,
7062 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7065 && breakpoint_address_match_range (bl->pspace->aspace,
7066 bl->address, bl->length,
7070 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7071 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7072 true, otherwise returns false. */
7075 tracepoint_locations_match (struct bp_location *loc1,
7076 struct bp_location *loc2)
7078 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7079 /* Since tracepoint locations are never duplicated with others', tracepoint
7080 locations at the same address of different tracepoints are regarded as
7081 different locations. */
7082 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7087 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7088 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7089 represent the same location. */
7092 breakpoint_locations_match (struct bp_location *loc1,
7093 struct bp_location *loc2)
7095 int hw_point1, hw_point2;
7097 /* Both of them must not be in moribund_locations. */
7098 gdb_assert (loc1->owner != NULL);
7099 gdb_assert (loc2->owner != NULL);
7101 hw_point1 = is_hardware_watchpoint (loc1->owner);
7102 hw_point2 = is_hardware_watchpoint (loc2->owner);
7104 if (hw_point1 != hw_point2)
7107 return watchpoint_locations_match (loc1, loc2);
7108 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7109 return tracepoint_locations_match (loc1, loc2);
7111 /* We compare bp_location.length in order to cover ranged breakpoints. */
7112 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7113 loc2->pspace->aspace, loc2->address)
7114 && loc1->length == loc2->length);
7118 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7119 int bnum, int have_bnum)
7121 /* The longest string possibly returned by hex_string_custom
7122 is 50 chars. These must be at least that big for safety. */
7126 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7127 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7129 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7130 bnum, astr1, astr2);
7132 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7135 /* Adjust a breakpoint's address to account for architectural
7136 constraints on breakpoint placement. Return the adjusted address.
7137 Note: Very few targets require this kind of adjustment. For most
7138 targets, this function is simply the identity function. */
7141 adjust_breakpoint_address (struct gdbarch *gdbarch,
7142 CORE_ADDR bpaddr, enum bptype bptype)
7144 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7146 /* Very few targets need any kind of breakpoint adjustment. */
7149 else if (bptype == bp_watchpoint
7150 || bptype == bp_hardware_watchpoint
7151 || bptype == bp_read_watchpoint
7152 || bptype == bp_access_watchpoint
7153 || bptype == bp_catchpoint)
7155 /* Watchpoints and the various bp_catch_* eventpoints should not
7156 have their addresses modified. */
7161 CORE_ADDR adjusted_bpaddr;
7163 /* Some targets have architectural constraints on the placement
7164 of breakpoint instructions. Obtain the adjusted address. */
7165 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7167 /* An adjusted breakpoint address can significantly alter
7168 a user's expectations. Print a warning if an adjustment
7170 if (adjusted_bpaddr != bpaddr)
7171 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7173 return adjusted_bpaddr;
7178 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7179 struct breakpoint *owner)
7181 memset (loc, 0, sizeof (*loc));
7183 gdb_assert (ops != NULL);
7188 loc->cond_bytecode = NULL;
7189 loc->shlib_disabled = 0;
7192 switch (owner->type)
7198 case bp_longjmp_resume:
7199 case bp_longjmp_call_dummy:
7201 case bp_exception_resume:
7202 case bp_step_resume:
7203 case bp_hp_step_resume:
7204 case bp_watchpoint_scope:
7206 case bp_std_terminate:
7207 case bp_shlib_event:
7208 case bp_thread_event:
7209 case bp_overlay_event:
7211 case bp_longjmp_master:
7212 case bp_std_terminate_master:
7213 case bp_exception_master:
7214 case bp_gnu_ifunc_resolver:
7215 case bp_gnu_ifunc_resolver_return:
7217 loc->loc_type = bp_loc_software_breakpoint;
7218 mark_breakpoint_location_modified (loc);
7220 case bp_hardware_breakpoint:
7221 loc->loc_type = bp_loc_hardware_breakpoint;
7222 mark_breakpoint_location_modified (loc);
7224 case bp_hardware_watchpoint:
7225 case bp_read_watchpoint:
7226 case bp_access_watchpoint:
7227 loc->loc_type = bp_loc_hardware_watchpoint;
7232 case bp_fast_tracepoint:
7233 case bp_static_tracepoint:
7234 loc->loc_type = bp_loc_other;
7237 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7243 /* Allocate a struct bp_location. */
7245 static struct bp_location *
7246 allocate_bp_location (struct breakpoint *bpt)
7248 return bpt->ops->allocate_location (bpt);
7252 free_bp_location (struct bp_location *loc)
7254 loc->ops->dtor (loc);
7258 /* Increment reference count. */
7261 incref_bp_location (struct bp_location *bl)
7266 /* Decrement reference count. If the reference count reaches 0,
7267 destroy the bp_location. Sets *BLP to NULL. */
7270 decref_bp_location (struct bp_location **blp)
7272 gdb_assert ((*blp)->refc > 0);
7274 if (--(*blp)->refc == 0)
7275 free_bp_location (*blp);
7279 /* Add breakpoint B at the end of the global breakpoint chain. */
7282 add_to_breakpoint_chain (struct breakpoint *b)
7284 struct breakpoint *b1;
7286 /* Add this breakpoint to the end of the chain so that a list of
7287 breakpoints will come out in order of increasing numbers. */
7289 b1 = breakpoint_chain;
7291 breakpoint_chain = b;
7300 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7303 init_raw_breakpoint_without_location (struct breakpoint *b,
7304 struct gdbarch *gdbarch,
7306 const struct breakpoint_ops *ops)
7308 memset (b, 0, sizeof (*b));
7310 gdb_assert (ops != NULL);
7314 b->gdbarch = gdbarch;
7315 b->language = current_language->la_language;
7316 b->input_radix = input_radix;
7318 b->enable_state = bp_enabled;
7321 b->ignore_count = 0;
7323 b->frame_id = null_frame_id;
7324 b->condition_not_parsed = 0;
7325 b->py_bp_object = NULL;
7326 b->related_breakpoint = b;
7329 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7330 that has type BPTYPE and has no locations as yet. */
7332 static struct breakpoint *
7333 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7335 const struct breakpoint_ops *ops)
7337 struct breakpoint *b = XNEW (struct breakpoint);
7339 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7340 add_to_breakpoint_chain (b);
7344 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7345 resolutions should be made as the user specified the location explicitly
7349 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7351 gdb_assert (loc->owner != NULL);
7353 if (loc->owner->type == bp_breakpoint
7354 || loc->owner->type == bp_hardware_breakpoint
7355 || is_tracepoint (loc->owner))
7358 const char *function_name;
7359 CORE_ADDR func_addr;
7361 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7362 &func_addr, NULL, &is_gnu_ifunc);
7364 if (is_gnu_ifunc && !explicit_loc)
7366 struct breakpoint *b = loc->owner;
7368 gdb_assert (loc->pspace == current_program_space);
7369 if (gnu_ifunc_resolve_name (function_name,
7370 &loc->requested_address))
7372 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7373 loc->address = adjust_breakpoint_address (loc->gdbarch,
7374 loc->requested_address,
7377 else if (b->type == bp_breakpoint && b->loc == loc
7378 && loc->next == NULL && b->related_breakpoint == b)
7380 /* Create only the whole new breakpoint of this type but do not
7381 mess more complicated breakpoints with multiple locations. */
7382 b->type = bp_gnu_ifunc_resolver;
7383 /* Remember the resolver's address for use by the return
7385 loc->related_address = func_addr;
7390 loc->function_name = xstrdup (function_name);
7394 /* Attempt to determine architecture of location identified by SAL. */
7396 get_sal_arch (struct symtab_and_line sal)
7399 return get_objfile_arch (sal.section->objfile);
7401 return get_objfile_arch (sal.symtab->objfile);
7406 /* Low level routine for partially initializing a breakpoint of type
7407 BPTYPE. The newly created breakpoint's address, section, source
7408 file name, and line number are provided by SAL.
7410 It is expected that the caller will complete the initialization of
7411 the newly created breakpoint struct as well as output any status
7412 information regarding the creation of a new breakpoint. */
7415 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7416 struct symtab_and_line sal, enum bptype bptype,
7417 const struct breakpoint_ops *ops)
7419 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7421 add_location_to_breakpoint (b, &sal);
7423 if (bptype != bp_catchpoint)
7424 gdb_assert (sal.pspace != NULL);
7426 /* Store the program space that was used to set the breakpoint,
7427 except for ordinary breakpoints, which are independent of the
7429 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7430 b->pspace = sal.pspace;
7433 /* set_raw_breakpoint is a low level routine for allocating and
7434 partially initializing a breakpoint of type BPTYPE. The newly
7435 created breakpoint's address, section, source file name, and line
7436 number are provided by SAL. The newly created and partially
7437 initialized breakpoint is added to the breakpoint chain and
7438 is also returned as the value of this function.
7440 It is expected that the caller will complete the initialization of
7441 the newly created breakpoint struct as well as output any status
7442 information regarding the creation of a new breakpoint. In
7443 particular, set_raw_breakpoint does NOT set the breakpoint
7444 number! Care should be taken to not allow an error to occur
7445 prior to completing the initialization of the breakpoint. If this
7446 should happen, a bogus breakpoint will be left on the chain. */
7449 set_raw_breakpoint (struct gdbarch *gdbarch,
7450 struct symtab_and_line sal, enum bptype bptype,
7451 const struct breakpoint_ops *ops)
7453 struct breakpoint *b = XNEW (struct breakpoint);
7455 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7456 add_to_breakpoint_chain (b);
7461 /* Note that the breakpoint object B describes a permanent breakpoint
7462 instruction, hard-wired into the inferior's code. */
7464 make_breakpoint_permanent (struct breakpoint *b)
7466 struct bp_location *bl;
7468 b->enable_state = bp_permanent;
7470 /* By definition, permanent breakpoints are already present in the
7471 code. Mark all locations as inserted. For now,
7472 make_breakpoint_permanent is called in just one place, so it's
7473 hard to say if it's reasonable to have permanent breakpoint with
7474 multiple locations or not, but it's easy to implement. */
7475 for (bl = b->loc; bl; bl = bl->next)
7479 /* Call this routine when stepping and nexting to enable a breakpoint
7480 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7481 initiated the operation. */
7484 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7486 struct breakpoint *b, *b_tmp;
7487 int thread = tp->num;
7489 /* To avoid having to rescan all objfile symbols at every step,
7490 we maintain a list of continually-inserted but always disabled
7491 longjmp "master" breakpoints. Here, we simply create momentary
7492 clones of those and enable them for the requested thread. */
7493 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7494 if (b->pspace == current_program_space
7495 && (b->type == bp_longjmp_master
7496 || b->type == bp_exception_master))
7498 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7499 struct breakpoint *clone;
7501 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7502 after their removal. */
7503 clone = momentary_breakpoint_from_master (b, type,
7504 &longjmp_breakpoint_ops, 1);
7505 clone->thread = thread;
7508 tp->initiating_frame = frame;
7511 /* Delete all longjmp breakpoints from THREAD. */
7513 delete_longjmp_breakpoint (int thread)
7515 struct breakpoint *b, *b_tmp;
7517 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7518 if (b->type == bp_longjmp || b->type == bp_exception)
7520 if (b->thread == thread)
7521 delete_breakpoint (b);
7526 delete_longjmp_breakpoint_at_next_stop (int thread)
7528 struct breakpoint *b, *b_tmp;
7530 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7531 if (b->type == bp_longjmp || b->type == bp_exception)
7533 if (b->thread == thread)
7534 b->disposition = disp_del_at_next_stop;
7538 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7539 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7540 pointer to any of them. Return NULL if this system cannot place longjmp
7544 set_longjmp_breakpoint_for_call_dummy (void)
7546 struct breakpoint *b, *retval = NULL;
7549 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7551 struct breakpoint *new_b;
7553 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7554 &momentary_breakpoint_ops,
7556 new_b->thread = pid_to_thread_id (inferior_ptid);
7558 /* Link NEW_B into the chain of RETVAL breakpoints. */
7560 gdb_assert (new_b->related_breakpoint == new_b);
7563 new_b->related_breakpoint = retval;
7564 while (retval->related_breakpoint != new_b->related_breakpoint)
7565 retval = retval->related_breakpoint;
7566 retval->related_breakpoint = new_b;
7572 /* Verify all existing dummy frames and their associated breakpoints for
7573 TP. Remove those which can no longer be found in the current frame
7576 You should call this function only at places where it is safe to currently
7577 unwind the whole stack. Failed stack unwind would discard live dummy
7581 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7583 struct breakpoint *b, *b_tmp;
7585 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7586 if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
7588 struct breakpoint *dummy_b = b->related_breakpoint;
7590 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7591 dummy_b = dummy_b->related_breakpoint;
7592 if (dummy_b->type != bp_call_dummy
7593 || frame_find_by_id (dummy_b->frame_id) != NULL)
7596 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7598 while (b->related_breakpoint != b)
7600 if (b_tmp == b->related_breakpoint)
7601 b_tmp = b->related_breakpoint->next;
7602 delete_breakpoint (b->related_breakpoint);
7604 delete_breakpoint (b);
7609 enable_overlay_breakpoints (void)
7611 struct breakpoint *b;
7614 if (b->type == bp_overlay_event)
7616 b->enable_state = bp_enabled;
7617 update_global_location_list (UGLL_MAY_INSERT);
7618 overlay_events_enabled = 1;
7623 disable_overlay_breakpoints (void)
7625 struct breakpoint *b;
7628 if (b->type == bp_overlay_event)
7630 b->enable_state = bp_disabled;
7631 update_global_location_list (UGLL_DONT_INSERT);
7632 overlay_events_enabled = 0;
7636 /* Set an active std::terminate breakpoint for each std::terminate
7637 master breakpoint. */
7639 set_std_terminate_breakpoint (void)
7641 struct breakpoint *b, *b_tmp;
7643 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7644 if (b->pspace == current_program_space
7645 && b->type == bp_std_terminate_master)
7647 momentary_breakpoint_from_master (b, bp_std_terminate,
7648 &momentary_breakpoint_ops, 1);
7652 /* Delete all the std::terminate breakpoints. */
7654 delete_std_terminate_breakpoint (void)
7656 struct breakpoint *b, *b_tmp;
7658 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7659 if (b->type == bp_std_terminate)
7660 delete_breakpoint (b);
7664 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7666 struct breakpoint *b;
7668 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7669 &internal_breakpoint_ops);
7671 b->enable_state = bp_enabled;
7672 /* addr_string has to be used or breakpoint_re_set will delete me. */
7674 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7676 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7682 remove_thread_event_breakpoints (void)
7684 struct breakpoint *b, *b_tmp;
7686 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7687 if (b->type == bp_thread_event
7688 && b->loc->pspace == current_program_space)
7689 delete_breakpoint (b);
7692 struct lang_and_radix
7698 /* Create a breakpoint for JIT code registration and unregistration. */
7701 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7703 struct breakpoint *b;
7705 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7706 &internal_breakpoint_ops);
7707 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7711 /* Remove JIT code registration and unregistration breakpoint(s). */
7714 remove_jit_event_breakpoints (void)
7716 struct breakpoint *b, *b_tmp;
7718 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7719 if (b->type == bp_jit_event
7720 && b->loc->pspace == current_program_space)
7721 delete_breakpoint (b);
7725 remove_solib_event_breakpoints (void)
7727 struct breakpoint *b, *b_tmp;
7729 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7730 if (b->type == bp_shlib_event
7731 && b->loc->pspace == current_program_space)
7732 delete_breakpoint (b);
7735 /* See breakpoint.h. */
7738 remove_solib_event_breakpoints_at_next_stop (void)
7740 struct breakpoint *b, *b_tmp;
7742 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7743 if (b->type == bp_shlib_event
7744 && b->loc->pspace == current_program_space)
7745 b->disposition = disp_del_at_next_stop;
7748 /* Helper for create_solib_event_breakpoint /
7749 create_and_insert_solib_event_breakpoint. Allows specifying which
7750 INSERT_MODE to pass through to update_global_location_list. */
7752 static struct breakpoint *
7753 create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address,
7754 enum ugll_insert_mode insert_mode)
7756 struct breakpoint *b;
7758 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7759 &internal_breakpoint_ops);
7760 update_global_location_list_nothrow (insert_mode);
7765 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7767 return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7770 /* See breakpoint.h. */
7773 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7775 struct breakpoint *b;
7777 /* Explicitly tell update_global_location_list to insert
7779 b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7780 if (!b->loc->inserted)
7782 delete_breakpoint (b);
7788 /* Disable any breakpoints that are on code in shared libraries. Only
7789 apply to enabled breakpoints, disabled ones can just stay disabled. */
7792 disable_breakpoints_in_shlibs (void)
7794 struct bp_location *loc, **locp_tmp;
7796 ALL_BP_LOCATIONS (loc, locp_tmp)
7798 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7799 struct breakpoint *b = loc->owner;
7801 /* We apply the check to all breakpoints, including disabled for
7802 those with loc->duplicate set. This is so that when breakpoint
7803 becomes enabled, or the duplicate is removed, gdb will try to
7804 insert all breakpoints. If we don't set shlib_disabled here,
7805 we'll try to insert those breakpoints and fail. */
7806 if (((b->type == bp_breakpoint)
7807 || (b->type == bp_jit_event)
7808 || (b->type == bp_hardware_breakpoint)
7809 || (is_tracepoint (b)))
7810 && loc->pspace == current_program_space
7811 && !loc->shlib_disabled
7812 && solib_name_from_address (loc->pspace, loc->address)
7815 loc->shlib_disabled = 1;
7820 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7821 notification of unloaded_shlib. Only apply to enabled breakpoints,
7822 disabled ones can just stay disabled. */
7825 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7827 struct bp_location *loc, **locp_tmp;
7828 int disabled_shlib_breaks = 0;
7830 /* SunOS a.out shared libraries are always mapped, so do not
7831 disable breakpoints; they will only be reported as unloaded
7832 through clear_solib when GDB discards its shared library
7833 list. See clear_solib for more information. */
7834 if (exec_bfd != NULL
7835 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7838 ALL_BP_LOCATIONS (loc, locp_tmp)
7840 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7841 struct breakpoint *b = loc->owner;
7843 if (solib->pspace == loc->pspace
7844 && !loc->shlib_disabled
7845 && (((b->type == bp_breakpoint
7846 || b->type == bp_jit_event
7847 || b->type == bp_hardware_breakpoint)
7848 && (loc->loc_type == bp_loc_hardware_breakpoint
7849 || loc->loc_type == bp_loc_software_breakpoint))
7850 || is_tracepoint (b))
7851 && solib_contains_address_p (solib, loc->address))
7853 loc->shlib_disabled = 1;
7854 /* At this point, we cannot rely on remove_breakpoint
7855 succeeding so we must mark the breakpoint as not inserted
7856 to prevent future errors occurring in remove_breakpoints. */
7859 /* This may cause duplicate notifications for the same breakpoint. */
7860 observer_notify_breakpoint_modified (b);
7862 if (!disabled_shlib_breaks)
7864 target_terminal_ours_for_output ();
7865 warning (_("Temporarily disabling breakpoints "
7866 "for unloaded shared library \"%s\""),
7869 disabled_shlib_breaks = 1;
7874 /* Disable any breakpoints and tracepoints in OBJFILE upon
7875 notification of free_objfile. Only apply to enabled breakpoints,
7876 disabled ones can just stay disabled. */
7879 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7881 struct breakpoint *b;
7883 if (objfile == NULL)
7886 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7887 managed by the user with add-symbol-file/remove-symbol-file.
7888 Similarly to how breakpoints in shared libraries are handled in
7889 response to "nosharedlibrary", mark breakpoints in such modules
7890 shlib_disabled so they end up uninserted on the next global
7891 location list update. Shared libraries not loaded by the user
7892 aren't handled here -- they're already handled in
7893 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7894 solib_unloaded observer. We skip objfiles that are not
7895 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7897 if ((objfile->flags & OBJF_SHARED) == 0
7898 || (objfile->flags & OBJF_USERLOADED) == 0)
7903 struct bp_location *loc;
7904 int bp_modified = 0;
7906 if (!is_breakpoint (b) && !is_tracepoint (b))
7909 for (loc = b->loc; loc != NULL; loc = loc->next)
7911 CORE_ADDR loc_addr = loc->address;
7913 if (loc->loc_type != bp_loc_hardware_breakpoint
7914 && loc->loc_type != bp_loc_software_breakpoint)
7917 if (loc->shlib_disabled != 0)
7920 if (objfile->pspace != loc->pspace)
7923 if (loc->loc_type != bp_loc_hardware_breakpoint
7924 && loc->loc_type != bp_loc_software_breakpoint)
7927 if (is_addr_in_objfile (loc_addr, objfile))
7929 loc->shlib_disabled = 1;
7930 /* At this point, we don't know whether the object was
7931 unmapped from the inferior or not, so leave the
7932 inserted flag alone. We'll handle failure to
7933 uninsert quietly, in case the object was indeed
7936 mark_breakpoint_location_modified (loc);
7943 observer_notify_breakpoint_modified (b);
7947 /* FORK & VFORK catchpoints. */
7949 /* An instance of this type is used to represent a fork or vfork
7950 catchpoint. It includes a "struct breakpoint" as a kind of base
7951 class; users downcast to "struct breakpoint *" when needed. A
7952 breakpoint is really of this type iff its ops pointer points to
7953 CATCH_FORK_BREAKPOINT_OPS. */
7955 struct fork_catchpoint
7957 /* The base class. */
7958 struct breakpoint base;
7960 /* Process id of a child process whose forking triggered this
7961 catchpoint. This field is only valid immediately after this
7962 catchpoint has triggered. */
7963 ptid_t forked_inferior_pid;
7966 /* Implement the "insert" breakpoint_ops method for fork
7970 insert_catch_fork (struct bp_location *bl)
7972 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7975 /* Implement the "remove" breakpoint_ops method for fork
7979 remove_catch_fork (struct bp_location *bl)
7981 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7984 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7988 breakpoint_hit_catch_fork (const struct bp_location *bl,
7989 struct address_space *aspace, CORE_ADDR bp_addr,
7990 const struct target_waitstatus *ws)
7992 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7994 if (ws->kind != TARGET_WAITKIND_FORKED)
7997 c->forked_inferior_pid = ws->value.related_pid;
8001 /* Implement the "print_it" breakpoint_ops method for fork
8004 static enum print_stop_action
8005 print_it_catch_fork (bpstat bs)
8007 struct ui_out *uiout = current_uiout;
8008 struct breakpoint *b = bs->breakpoint_at;
8009 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
8011 annotate_catchpoint (b->number);
8012 if (b->disposition == disp_del)
8013 ui_out_text (uiout, "\nTemporary catchpoint ");
8015 ui_out_text (uiout, "\nCatchpoint ");
8016 if (ui_out_is_mi_like_p (uiout))
8018 ui_out_field_string (uiout, "reason",
8019 async_reason_lookup (EXEC_ASYNC_FORK));
8020 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8022 ui_out_field_int (uiout, "bkptno", b->number);
8023 ui_out_text (uiout, " (forked process ");
8024 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8025 ui_out_text (uiout, "), ");
8026 return PRINT_SRC_AND_LOC;
8029 /* Implement the "print_one" breakpoint_ops method for fork
8033 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8035 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8036 struct value_print_options opts;
8037 struct ui_out *uiout = current_uiout;
8039 get_user_print_options (&opts);
8041 /* Field 4, the address, is omitted (which makes the columns not
8042 line up too nicely with the headers, but the effect is relatively
8044 if (opts.addressprint)
8045 ui_out_field_skip (uiout, "addr");
8047 ui_out_text (uiout, "fork");
8048 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8050 ui_out_text (uiout, ", process ");
8051 ui_out_field_int (uiout, "what",
8052 ptid_get_pid (c->forked_inferior_pid));
8053 ui_out_spaces (uiout, 1);
8056 if (ui_out_is_mi_like_p (uiout))
8057 ui_out_field_string (uiout, "catch-type", "fork");
8060 /* Implement the "print_mention" breakpoint_ops method for fork
8064 print_mention_catch_fork (struct breakpoint *b)
8066 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8069 /* Implement the "print_recreate" breakpoint_ops method for fork
8073 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8075 fprintf_unfiltered (fp, "catch fork");
8076 print_recreate_thread (b, fp);
8079 /* The breakpoint_ops structure to be used in fork catchpoints. */
8081 static struct breakpoint_ops catch_fork_breakpoint_ops;
8083 /* Implement the "insert" breakpoint_ops method for vfork
8087 insert_catch_vfork (struct bp_location *bl)
8089 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8092 /* Implement the "remove" breakpoint_ops method for vfork
8096 remove_catch_vfork (struct bp_location *bl)
8098 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8101 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8105 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8106 struct address_space *aspace, CORE_ADDR bp_addr,
8107 const struct target_waitstatus *ws)
8109 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8111 if (ws->kind != TARGET_WAITKIND_VFORKED)
8114 c->forked_inferior_pid = ws->value.related_pid;
8118 /* Implement the "print_it" breakpoint_ops method for vfork
8121 static enum print_stop_action
8122 print_it_catch_vfork (bpstat bs)
8124 struct ui_out *uiout = current_uiout;
8125 struct breakpoint *b = bs->breakpoint_at;
8126 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8128 annotate_catchpoint (b->number);
8129 if (b->disposition == disp_del)
8130 ui_out_text (uiout, "\nTemporary catchpoint ");
8132 ui_out_text (uiout, "\nCatchpoint ");
8133 if (ui_out_is_mi_like_p (uiout))
8135 ui_out_field_string (uiout, "reason",
8136 async_reason_lookup (EXEC_ASYNC_VFORK));
8137 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8139 ui_out_field_int (uiout, "bkptno", b->number);
8140 ui_out_text (uiout, " (vforked process ");
8141 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8142 ui_out_text (uiout, "), ");
8143 return PRINT_SRC_AND_LOC;
8146 /* Implement the "print_one" breakpoint_ops method for vfork
8150 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8152 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8153 struct value_print_options opts;
8154 struct ui_out *uiout = current_uiout;
8156 get_user_print_options (&opts);
8157 /* Field 4, the address, is omitted (which makes the columns not
8158 line up too nicely with the headers, but the effect is relatively
8160 if (opts.addressprint)
8161 ui_out_field_skip (uiout, "addr");
8163 ui_out_text (uiout, "vfork");
8164 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8166 ui_out_text (uiout, ", process ");
8167 ui_out_field_int (uiout, "what",
8168 ptid_get_pid (c->forked_inferior_pid));
8169 ui_out_spaces (uiout, 1);
8172 if (ui_out_is_mi_like_p (uiout))
8173 ui_out_field_string (uiout, "catch-type", "vfork");
8176 /* Implement the "print_mention" breakpoint_ops method for vfork
8180 print_mention_catch_vfork (struct breakpoint *b)
8182 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8185 /* Implement the "print_recreate" breakpoint_ops method for vfork
8189 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8191 fprintf_unfiltered (fp, "catch vfork");
8192 print_recreate_thread (b, fp);
8195 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8197 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8199 /* An instance of this type is used to represent an solib catchpoint.
8200 It includes a "struct breakpoint" as a kind of base class; users
8201 downcast to "struct breakpoint *" when needed. A breakpoint is
8202 really of this type iff its ops pointer points to
8203 CATCH_SOLIB_BREAKPOINT_OPS. */
8205 struct solib_catchpoint
8207 /* The base class. */
8208 struct breakpoint base;
8210 /* True for "catch load", false for "catch unload". */
8211 unsigned char is_load;
8213 /* Regular expression to match, if any. COMPILED is only valid when
8214 REGEX is non-NULL. */
8220 dtor_catch_solib (struct breakpoint *b)
8222 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8225 regfree (&self->compiled);
8226 xfree (self->regex);
8228 base_breakpoint_ops.dtor (b);
8232 insert_catch_solib (struct bp_location *ignore)
8238 remove_catch_solib (struct bp_location *ignore)
8244 breakpoint_hit_catch_solib (const struct bp_location *bl,
8245 struct address_space *aspace,
8247 const struct target_waitstatus *ws)
8249 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8250 struct breakpoint *other;
8252 if (ws->kind == TARGET_WAITKIND_LOADED)
8255 ALL_BREAKPOINTS (other)
8257 struct bp_location *other_bl;
8259 if (other == bl->owner)
8262 if (other->type != bp_shlib_event)
8265 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8268 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8270 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8279 check_status_catch_solib (struct bpstats *bs)
8281 struct solib_catchpoint *self
8282 = (struct solib_catchpoint *) bs->breakpoint_at;
8287 struct so_list *iter;
8290 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8295 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8304 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8309 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8315 bs->print_it = print_it_noop;
8318 static enum print_stop_action
8319 print_it_catch_solib (bpstat bs)
8321 struct breakpoint *b = bs->breakpoint_at;
8322 struct ui_out *uiout = current_uiout;
8324 annotate_catchpoint (b->number);
8325 if (b->disposition == disp_del)
8326 ui_out_text (uiout, "\nTemporary catchpoint ");
8328 ui_out_text (uiout, "\nCatchpoint ");
8329 ui_out_field_int (uiout, "bkptno", b->number);
8330 ui_out_text (uiout, "\n");
8331 if (ui_out_is_mi_like_p (uiout))
8332 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8333 print_solib_event (1);
8334 return PRINT_SRC_AND_LOC;
8338 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8340 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8341 struct value_print_options opts;
8342 struct ui_out *uiout = current_uiout;
8345 get_user_print_options (&opts);
8346 /* Field 4, the address, is omitted (which makes the columns not
8347 line up too nicely with the headers, but the effect is relatively
8349 if (opts.addressprint)
8352 ui_out_field_skip (uiout, "addr");
8359 msg = xstrprintf (_("load of library matching %s"), self->regex);
8361 msg = xstrdup (_("load of library"));
8366 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8368 msg = xstrdup (_("unload of library"));
8370 ui_out_field_string (uiout, "what", msg);
8373 if (ui_out_is_mi_like_p (uiout))
8374 ui_out_field_string (uiout, "catch-type",
8375 self->is_load ? "load" : "unload");
8379 print_mention_catch_solib (struct breakpoint *b)
8381 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8383 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8384 self->is_load ? "load" : "unload");
8388 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8390 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8392 fprintf_unfiltered (fp, "%s %s",
8393 b->disposition == disp_del ? "tcatch" : "catch",
8394 self->is_load ? "load" : "unload");
8396 fprintf_unfiltered (fp, " %s", self->regex);
8397 fprintf_unfiltered (fp, "\n");
8400 static struct breakpoint_ops catch_solib_breakpoint_ops;
8402 /* Shared helper function (MI and CLI) for creating and installing
8403 a shared object event catchpoint. If IS_LOAD is non-zero then
8404 the events to be caught are load events, otherwise they are
8405 unload events. If IS_TEMP is non-zero the catchpoint is a
8406 temporary one. If ENABLED is non-zero the catchpoint is
8407 created in an enabled state. */
8410 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8412 struct solib_catchpoint *c;
8413 struct gdbarch *gdbarch = get_current_arch ();
8414 struct cleanup *cleanup;
8418 arg = skip_spaces (arg);
8420 c = XCNEW (struct solib_catchpoint);
8421 cleanup = make_cleanup (xfree, c);
8427 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8430 char *err = get_regcomp_error (errcode, &c->compiled);
8432 make_cleanup (xfree, err);
8433 error (_("Invalid regexp (%s): %s"), err, arg);
8435 c->regex = xstrdup (arg);
8438 c->is_load = is_load;
8439 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8440 &catch_solib_breakpoint_ops);
8442 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8444 discard_cleanups (cleanup);
8445 install_breakpoint (0, &c->base, 1);
8448 /* A helper function that does all the work for "catch load" and
8452 catch_load_or_unload (char *arg, int from_tty, int is_load,
8453 struct cmd_list_element *command)
8456 const int enabled = 1;
8458 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8460 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8464 catch_load_command_1 (char *arg, int from_tty,
8465 struct cmd_list_element *command)
8467 catch_load_or_unload (arg, from_tty, 1, command);
8471 catch_unload_command_1 (char *arg, int from_tty,
8472 struct cmd_list_element *command)
8474 catch_load_or_unload (arg, from_tty, 0, command);
8477 /* An instance of this type is used to represent a syscall catchpoint.
8478 It includes a "struct breakpoint" as a kind of base class; users
8479 downcast to "struct breakpoint *" when needed. A breakpoint is
8480 really of this type iff its ops pointer points to
8481 CATCH_SYSCALL_BREAKPOINT_OPS. */
8483 struct syscall_catchpoint
8485 /* The base class. */
8486 struct breakpoint base;
8488 /* Syscall numbers used for the 'catch syscall' feature. If no
8489 syscall has been specified for filtering, its value is NULL.
8490 Otherwise, it holds a list of all syscalls to be caught. The
8491 list elements are allocated with xmalloc. */
8492 VEC(int) *syscalls_to_be_caught;
8495 /* Implement the "dtor" breakpoint_ops method for syscall
8499 dtor_catch_syscall (struct breakpoint *b)
8501 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8503 VEC_free (int, c->syscalls_to_be_caught);
8505 base_breakpoint_ops.dtor (b);
8508 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8510 struct catch_syscall_inferior_data
8512 /* We keep a count of the number of times the user has requested a
8513 particular syscall to be tracked, and pass this information to the
8514 target. This lets capable targets implement filtering directly. */
8516 /* Number of times that "any" syscall is requested. */
8517 int any_syscall_count;
8519 /* Count of each system call. */
8520 VEC(int) *syscalls_counts;
8522 /* This counts all syscall catch requests, so we can readily determine
8523 if any catching is necessary. */
8524 int total_syscalls_count;
8527 static struct catch_syscall_inferior_data*
8528 get_catch_syscall_inferior_data (struct inferior *inf)
8530 struct catch_syscall_inferior_data *inf_data;
8532 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8533 if (inf_data == NULL)
8535 inf_data = XCNEW (struct catch_syscall_inferior_data);
8536 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8543 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8549 /* Implement the "insert" breakpoint_ops method for syscall
8553 insert_catch_syscall (struct bp_location *bl)
8555 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8556 struct inferior *inf = current_inferior ();
8557 struct catch_syscall_inferior_data *inf_data
8558 = get_catch_syscall_inferior_data (inf);
8560 ++inf_data->total_syscalls_count;
8561 if (!c->syscalls_to_be_caught)
8562 ++inf_data->any_syscall_count;
8568 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8573 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8575 int old_size = VEC_length (int, inf_data->syscalls_counts);
8576 uintptr_t vec_addr_offset
8577 = old_size * ((uintptr_t) sizeof (int));
8579 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8580 vec_addr = ((uintptr_t) VEC_address (int,
8581 inf_data->syscalls_counts)
8583 memset ((void *) vec_addr, 0,
8584 (iter + 1 - old_size) * sizeof (int));
8586 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8587 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8591 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8592 inf_data->total_syscalls_count != 0,
8593 inf_data->any_syscall_count,
8595 inf_data->syscalls_counts),
8597 inf_data->syscalls_counts));
8600 /* Implement the "remove" breakpoint_ops method for syscall
8604 remove_catch_syscall (struct bp_location *bl)
8606 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8607 struct inferior *inf = current_inferior ();
8608 struct catch_syscall_inferior_data *inf_data
8609 = get_catch_syscall_inferior_data (inf);
8611 --inf_data->total_syscalls_count;
8612 if (!c->syscalls_to_be_caught)
8613 --inf_data->any_syscall_count;
8619 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8623 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8624 /* Shouldn't happen. */
8626 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8627 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8631 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8632 inf_data->total_syscalls_count != 0,
8633 inf_data->any_syscall_count,
8635 inf_data->syscalls_counts),
8637 inf_data->syscalls_counts));
8640 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8644 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8645 struct address_space *aspace, CORE_ADDR bp_addr,
8646 const struct target_waitstatus *ws)
8648 /* We must check if we are catching specific syscalls in this
8649 breakpoint. If we are, then we must guarantee that the called
8650 syscall is the same syscall we are catching. */
8651 int syscall_number = 0;
8652 const struct syscall_catchpoint *c
8653 = (const struct syscall_catchpoint *) bl->owner;
8655 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8656 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8659 syscall_number = ws->value.syscall_number;
8661 /* Now, checking if the syscall is the same. */
8662 if (c->syscalls_to_be_caught)
8667 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8669 if (syscall_number == iter)
8678 /* Implement the "print_it" breakpoint_ops method for syscall
8681 static enum print_stop_action
8682 print_it_catch_syscall (bpstat bs)
8684 struct ui_out *uiout = current_uiout;
8685 struct breakpoint *b = bs->breakpoint_at;
8686 /* These are needed because we want to know in which state a
8687 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8688 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8689 must print "called syscall" or "returned from syscall". */
8691 struct target_waitstatus last;
8694 get_last_target_status (&ptid, &last);
8696 get_syscall_by_number (last.value.syscall_number, &s);
8698 annotate_catchpoint (b->number);
8700 if (b->disposition == disp_del)
8701 ui_out_text (uiout, "\nTemporary catchpoint ");
8703 ui_out_text (uiout, "\nCatchpoint ");
8704 if (ui_out_is_mi_like_p (uiout))
8706 ui_out_field_string (uiout, "reason",
8707 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8708 ? EXEC_ASYNC_SYSCALL_ENTRY
8709 : EXEC_ASYNC_SYSCALL_RETURN));
8710 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8712 ui_out_field_int (uiout, "bkptno", b->number);
8714 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8715 ui_out_text (uiout, " (call to syscall ");
8717 ui_out_text (uiout, " (returned from syscall ");
8719 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8720 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8722 ui_out_field_string (uiout, "syscall-name", s.name);
8724 ui_out_text (uiout, "), ");
8726 return PRINT_SRC_AND_LOC;
8729 /* Implement the "print_one" breakpoint_ops method for syscall
8733 print_one_catch_syscall (struct breakpoint *b,
8734 struct bp_location **last_loc)
8736 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8737 struct value_print_options opts;
8738 struct ui_out *uiout = current_uiout;
8740 get_user_print_options (&opts);
8741 /* Field 4, the address, is omitted (which makes the columns not
8742 line up too nicely with the headers, but the effect is relatively
8744 if (opts.addressprint)
8745 ui_out_field_skip (uiout, "addr");
8748 if (c->syscalls_to_be_caught
8749 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8750 ui_out_text (uiout, "syscalls \"");
8752 ui_out_text (uiout, "syscall \"");
8754 if (c->syscalls_to_be_caught)
8757 char *text = xstrprintf ("%s", "");
8760 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8765 get_syscall_by_number (iter, &s);
8768 text = xstrprintf ("%s%s, ", text, s.name);
8770 text = xstrprintf ("%s%d, ", text, iter);
8772 /* We have to xfree the last 'text' (now stored at 'x')
8773 because xstrprintf dynamically allocates new space for it
8777 /* Remove the last comma. */
8778 text[strlen (text) - 2] = '\0';
8779 ui_out_field_string (uiout, "what", text);
8782 ui_out_field_string (uiout, "what", "<any syscall>");
8783 ui_out_text (uiout, "\" ");
8785 if (ui_out_is_mi_like_p (uiout))
8786 ui_out_field_string (uiout, "catch-type", "syscall");
8789 /* Implement the "print_mention" breakpoint_ops method for syscall
8793 print_mention_catch_syscall (struct breakpoint *b)
8795 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8797 if (c->syscalls_to_be_caught)
8801 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8802 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8804 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8807 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8811 get_syscall_by_number (iter, &s);
8814 printf_filtered (" '%s' [%d]", s.name, s.number);
8816 printf_filtered (" %d", s.number);
8818 printf_filtered (")");
8821 printf_filtered (_("Catchpoint %d (any syscall)"),
8825 /* Implement the "print_recreate" breakpoint_ops method for syscall
8829 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8831 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8833 fprintf_unfiltered (fp, "catch syscall");
8835 if (c->syscalls_to_be_caught)
8840 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8845 get_syscall_by_number (iter, &s);
8847 fprintf_unfiltered (fp, " %s", s.name);
8849 fprintf_unfiltered (fp, " %d", s.number);
8852 print_recreate_thread (b, fp);
8855 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8857 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8859 /* Returns non-zero if 'b' is a syscall catchpoint. */
8862 syscall_catchpoint_p (struct breakpoint *b)
8864 return (b->ops == &catch_syscall_breakpoint_ops);
8867 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8868 is non-zero, then make the breakpoint temporary. If COND_STRING is
8869 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8870 the breakpoint_ops structure associated to the catchpoint. */
8873 init_catchpoint (struct breakpoint *b,
8874 struct gdbarch *gdbarch, int tempflag,
8876 const struct breakpoint_ops *ops)
8878 struct symtab_and_line sal;
8881 sal.pspace = current_program_space;
8883 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8885 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8886 b->disposition = tempflag ? disp_del : disp_donttouch;
8890 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8892 add_to_breakpoint_chain (b);
8893 set_breakpoint_number (internal, b);
8894 if (is_tracepoint (b))
8895 set_tracepoint_count (breakpoint_count);
8898 observer_notify_breakpoint_created (b);
8901 update_global_location_list (UGLL_MAY_INSERT);
8905 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8906 int tempflag, char *cond_string,
8907 const struct breakpoint_ops *ops)
8909 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8911 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8913 c->forked_inferior_pid = null_ptid;
8915 install_breakpoint (0, &c->base, 1);
8918 /* Exec catchpoints. */
8920 /* An instance of this type is used to represent an exec catchpoint.
8921 It includes a "struct breakpoint" as a kind of base class; users
8922 downcast to "struct breakpoint *" when needed. A breakpoint is
8923 really of this type iff its ops pointer points to
8924 CATCH_EXEC_BREAKPOINT_OPS. */
8926 struct exec_catchpoint
8928 /* The base class. */
8929 struct breakpoint base;
8931 /* Filename of a program whose exec triggered this catchpoint.
8932 This field is only valid immediately after this catchpoint has
8934 char *exec_pathname;
8937 /* Implement the "dtor" breakpoint_ops method for exec
8941 dtor_catch_exec (struct breakpoint *b)
8943 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8945 xfree (c->exec_pathname);
8947 base_breakpoint_ops.dtor (b);
8951 insert_catch_exec (struct bp_location *bl)
8953 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8957 remove_catch_exec (struct bp_location *bl)
8959 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8963 breakpoint_hit_catch_exec (const struct bp_location *bl,
8964 struct address_space *aspace, CORE_ADDR bp_addr,
8965 const struct target_waitstatus *ws)
8967 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8969 if (ws->kind != TARGET_WAITKIND_EXECD)
8972 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8976 static enum print_stop_action
8977 print_it_catch_exec (bpstat bs)
8979 struct ui_out *uiout = current_uiout;
8980 struct breakpoint *b = bs->breakpoint_at;
8981 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8983 annotate_catchpoint (b->number);
8984 if (b->disposition == disp_del)
8985 ui_out_text (uiout, "\nTemporary catchpoint ");
8987 ui_out_text (uiout, "\nCatchpoint ");
8988 if (ui_out_is_mi_like_p (uiout))
8990 ui_out_field_string (uiout, "reason",
8991 async_reason_lookup (EXEC_ASYNC_EXEC));
8992 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8994 ui_out_field_int (uiout, "bkptno", b->number);
8995 ui_out_text (uiout, " (exec'd ");
8996 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8997 ui_out_text (uiout, "), ");
8999 return PRINT_SRC_AND_LOC;
9003 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
9005 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
9006 struct value_print_options opts;
9007 struct ui_out *uiout = current_uiout;
9009 get_user_print_options (&opts);
9011 /* Field 4, the address, is omitted (which makes the columns
9012 not line up too nicely with the headers, but the effect
9013 is relatively readable). */
9014 if (opts.addressprint)
9015 ui_out_field_skip (uiout, "addr");
9017 ui_out_text (uiout, "exec");
9018 if (c->exec_pathname != NULL)
9020 ui_out_text (uiout, ", program \"");
9021 ui_out_field_string (uiout, "what", c->exec_pathname);
9022 ui_out_text (uiout, "\" ");
9025 if (ui_out_is_mi_like_p (uiout))
9026 ui_out_field_string (uiout, "catch-type", "exec");
9030 print_mention_catch_exec (struct breakpoint *b)
9032 printf_filtered (_("Catchpoint %d (exec)"), b->number);
9035 /* Implement the "print_recreate" breakpoint_ops method for exec
9039 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
9041 fprintf_unfiltered (fp, "catch exec");
9042 print_recreate_thread (b, fp);
9045 static struct breakpoint_ops catch_exec_breakpoint_ops;
9048 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
9049 const struct breakpoint_ops *ops)
9051 struct syscall_catchpoint *c;
9052 struct gdbarch *gdbarch = get_current_arch ();
9054 c = XNEW (struct syscall_catchpoint);
9055 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
9056 c->syscalls_to_be_caught = filter;
9058 install_breakpoint (0, &c->base, 1);
9062 hw_breakpoint_used_count (void)
9065 struct breakpoint *b;
9066 struct bp_location *bl;
9070 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
9071 for (bl = b->loc; bl; bl = bl->next)
9073 /* Special types of hardware breakpoints may use more than
9075 i += b->ops->resources_needed (bl);
9082 /* Returns the resources B would use if it were a hardware
9086 hw_watchpoint_use_count (struct breakpoint *b)
9089 struct bp_location *bl;
9091 if (!breakpoint_enabled (b))
9094 for (bl = b->loc; bl; bl = bl->next)
9096 /* Special types of hardware watchpoints may use more than
9098 i += b->ops->resources_needed (bl);
9104 /* Returns the sum the used resources of all hardware watchpoints of
9105 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9106 the sum of the used resources of all hardware watchpoints of other
9107 types _not_ TYPE. */
9110 hw_watchpoint_used_count_others (struct breakpoint *except,
9111 enum bptype type, int *other_type_used)
9114 struct breakpoint *b;
9116 *other_type_used = 0;
9121 if (!breakpoint_enabled (b))
9124 if (b->type == type)
9125 i += hw_watchpoint_use_count (b);
9126 else if (is_hardware_watchpoint (b))
9127 *other_type_used = 1;
9134 disable_watchpoints_before_interactive_call_start (void)
9136 struct breakpoint *b;
9140 if (is_watchpoint (b) && breakpoint_enabled (b))
9142 b->enable_state = bp_call_disabled;
9143 update_global_location_list (UGLL_DONT_INSERT);
9149 enable_watchpoints_after_interactive_call_stop (void)
9151 struct breakpoint *b;
9155 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
9157 b->enable_state = bp_enabled;
9158 update_global_location_list (UGLL_MAY_INSERT);
9164 disable_breakpoints_before_startup (void)
9166 current_program_space->executing_startup = 1;
9167 update_global_location_list (UGLL_DONT_INSERT);
9171 enable_breakpoints_after_startup (void)
9173 current_program_space->executing_startup = 0;
9174 breakpoint_re_set ();
9178 /* Set a breakpoint that will evaporate an end of command
9179 at address specified by SAL.
9180 Restrict it to frame FRAME if FRAME is nonzero. */
9183 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
9184 struct frame_id frame_id, enum bptype type)
9186 struct breakpoint *b;
9188 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9190 gdb_assert (!frame_id_artificial_p (frame_id));
9192 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
9193 b->enable_state = bp_enabled;
9194 b->disposition = disp_donttouch;
9195 b->frame_id = frame_id;
9197 /* If we're debugging a multi-threaded program, then we want
9198 momentary breakpoints to be active in only a single thread of
9200 if (in_thread_list (inferior_ptid))
9201 b->thread = pid_to_thread_id (inferior_ptid);
9203 update_global_location_list_nothrow (UGLL_MAY_INSERT);
9208 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9209 The new breakpoint will have type TYPE, use OPS as its
9210 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9212 static struct breakpoint *
9213 momentary_breakpoint_from_master (struct breakpoint *orig,
9215 const struct breakpoint_ops *ops,
9218 struct breakpoint *copy;
9220 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
9221 copy->loc = allocate_bp_location (copy);
9222 set_breakpoint_location_function (copy->loc, 1);
9224 copy->loc->gdbarch = orig->loc->gdbarch;
9225 copy->loc->requested_address = orig->loc->requested_address;
9226 copy->loc->address = orig->loc->address;
9227 copy->loc->section = orig->loc->section;
9228 copy->loc->pspace = orig->loc->pspace;
9229 copy->loc->probe = orig->loc->probe;
9230 copy->loc->line_number = orig->loc->line_number;
9231 copy->loc->symtab = orig->loc->symtab;
9232 copy->loc->enabled = loc_enabled;
9233 copy->frame_id = orig->frame_id;
9234 copy->thread = orig->thread;
9235 copy->pspace = orig->pspace;
9237 copy->enable_state = bp_enabled;
9238 copy->disposition = disp_donttouch;
9239 copy->number = internal_breakpoint_number--;
9241 update_global_location_list_nothrow (UGLL_DONT_INSERT);
9245 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9249 clone_momentary_breakpoint (struct breakpoint *orig)
9251 /* If there's nothing to clone, then return nothing. */
9255 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
9259 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
9262 struct symtab_and_line sal;
9264 sal = find_pc_line (pc, 0);
9266 sal.section = find_pc_overlay (pc);
9267 sal.explicit_pc = 1;
9269 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
9273 /* Tell the user we have just set a breakpoint B. */
9276 mention (struct breakpoint *b)
9278 b->ops->print_mention (b);
9279 if (ui_out_is_mi_like_p (current_uiout))
9281 printf_filtered ("\n");
9285 static struct bp_location *
9286 add_location_to_breakpoint (struct breakpoint *b,
9287 const struct symtab_and_line *sal)
9289 struct bp_location *loc, **tmp;
9290 CORE_ADDR adjusted_address;
9291 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9293 if (loc_gdbarch == NULL)
9294 loc_gdbarch = b->gdbarch;
9296 /* Adjust the breakpoint's address prior to allocating a location.
9297 Once we call allocate_bp_location(), that mostly uninitialized
9298 location will be placed on the location chain. Adjustment of the
9299 breakpoint may cause target_read_memory() to be called and we do
9300 not want its scan of the location chain to find a breakpoint and
9301 location that's only been partially initialized. */
9302 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9305 /* Sort the locations by their ADDRESS. */
9306 loc = allocate_bp_location (b);
9307 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9308 tmp = &((*tmp)->next))
9313 loc->requested_address = sal->pc;
9314 loc->address = adjusted_address;
9315 loc->pspace = sal->pspace;
9316 loc->probe.probe = sal->probe;
9317 loc->probe.objfile = sal->objfile;
9318 gdb_assert (loc->pspace != NULL);
9319 loc->section = sal->section;
9320 loc->gdbarch = loc_gdbarch;
9321 loc->line_number = sal->line;
9322 loc->symtab = sal->symtab;
9324 set_breakpoint_location_function (loc,
9325 sal->explicit_pc || sal->explicit_line);
9330 /* Return 1 if LOC is pointing to a permanent breakpoint,
9331 return 0 otherwise. */
9334 bp_loc_is_permanent (struct bp_location *loc)
9338 const gdb_byte *bpoint;
9339 gdb_byte *target_mem;
9340 struct cleanup *cleanup;
9343 gdb_assert (loc != NULL);
9345 addr = loc->address;
9346 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
9348 /* Software breakpoints unsupported? */
9352 target_mem = alloca (len);
9354 /* Enable the automatic memory restoration from breakpoints while
9355 we read the memory. Otherwise we could say about our temporary
9356 breakpoints they are permanent. */
9357 cleanup = save_current_space_and_thread ();
9359 switch_to_program_space_and_thread (loc->pspace);
9360 make_show_memory_breakpoints_cleanup (0);
9362 if (target_read_memory (loc->address, target_mem, len) == 0
9363 && memcmp (target_mem, bpoint, len) == 0)
9366 do_cleanups (cleanup);
9371 /* Build a command list for the dprintf corresponding to the current
9372 settings of the dprintf style options. */
9375 update_dprintf_command_list (struct breakpoint *b)
9377 char *dprintf_args = b->extra_string;
9378 char *printf_line = NULL;
9383 dprintf_args = skip_spaces (dprintf_args);
9385 /* Allow a comma, as it may have terminated a location, but don't
9387 if (*dprintf_args == ',')
9389 dprintf_args = skip_spaces (dprintf_args);
9391 if (*dprintf_args != '"')
9392 error (_("Bad format string, missing '\"'."));
9394 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9395 printf_line = xstrprintf ("printf %s", dprintf_args);
9396 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9398 if (!dprintf_function)
9399 error (_("No function supplied for dprintf call"));
9401 if (dprintf_channel && strlen (dprintf_channel) > 0)
9402 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9407 printf_line = xstrprintf ("call (void) %s (%s)",
9411 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9413 if (target_can_run_breakpoint_commands ())
9414 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9417 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9418 printf_line = xstrprintf ("printf %s", dprintf_args);
9422 internal_error (__FILE__, __LINE__,
9423 _("Invalid dprintf style."));
9425 gdb_assert (printf_line != NULL);
9426 /* Manufacture a printf sequence. */
9428 struct command_line *printf_cmd_line
9429 = xmalloc (sizeof (struct command_line));
9431 printf_cmd_line = xmalloc (sizeof (struct command_line));
9432 printf_cmd_line->control_type = simple_control;
9433 printf_cmd_line->body_count = 0;
9434 printf_cmd_line->body_list = NULL;
9435 printf_cmd_line->next = NULL;
9436 printf_cmd_line->line = printf_line;
9438 breakpoint_set_commands (b, printf_cmd_line);
9442 /* Update all dprintf commands, making their command lists reflect
9443 current style settings. */
9446 update_dprintf_commands (char *args, int from_tty,
9447 struct cmd_list_element *c)
9449 struct breakpoint *b;
9453 if (b->type == bp_dprintf)
9454 update_dprintf_command_list (b);
9458 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9459 as textual description of the location, and COND_STRING
9460 as condition expression. */
9463 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9464 struct symtabs_and_lines sals, char *addr_string,
9465 char *filter, char *cond_string,
9467 enum bptype type, enum bpdisp disposition,
9468 int thread, int task, int ignore_count,
9469 const struct breakpoint_ops *ops, int from_tty,
9470 int enabled, int internal, unsigned flags,
9471 int display_canonical)
9475 if (type == bp_hardware_breakpoint)
9477 int target_resources_ok;
9479 i = hw_breakpoint_used_count ();
9480 target_resources_ok =
9481 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9483 if (target_resources_ok == 0)
9484 error (_("No hardware breakpoint support in the target."));
9485 else if (target_resources_ok < 0)
9486 error (_("Hardware breakpoints used exceeds limit."));
9489 gdb_assert (sals.nelts > 0);
9491 for (i = 0; i < sals.nelts; ++i)
9493 struct symtab_and_line sal = sals.sals[i];
9494 struct bp_location *loc;
9498 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9500 loc_gdbarch = gdbarch;
9502 describe_other_breakpoints (loc_gdbarch,
9503 sal.pspace, sal.pc, sal.section, thread);
9508 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9512 b->cond_string = cond_string;
9513 b->extra_string = extra_string;
9514 b->ignore_count = ignore_count;
9515 b->enable_state = enabled ? bp_enabled : bp_disabled;
9516 b->disposition = disposition;
9518 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9519 b->loc->inserted = 1;
9521 if (type == bp_static_tracepoint)
9523 struct tracepoint *t = (struct tracepoint *) b;
9524 struct static_tracepoint_marker marker;
9526 if (strace_marker_p (b))
9528 /* We already know the marker exists, otherwise, we
9529 wouldn't see a sal for it. */
9530 char *p = &addr_string[3];
9534 p = skip_spaces (p);
9536 endp = skip_to_space (p);
9538 marker_str = savestring (p, endp - p);
9539 t->static_trace_marker_id = marker_str;
9541 printf_filtered (_("Probed static tracepoint "
9543 t->static_trace_marker_id);
9545 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9547 t->static_trace_marker_id = xstrdup (marker.str_id);
9548 release_static_tracepoint_marker (&marker);
9550 printf_filtered (_("Probed static tracepoint "
9552 t->static_trace_marker_id);
9555 warning (_("Couldn't determine the static "
9556 "tracepoint marker to probe"));
9563 loc = add_location_to_breakpoint (b, &sal);
9564 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9568 if (bp_loc_is_permanent (loc))
9569 make_breakpoint_permanent (b);
9573 const char *arg = b->cond_string;
9575 loc->cond = parse_exp_1 (&arg, loc->address,
9576 block_for_pc (loc->address), 0);
9578 error (_("Garbage '%s' follows condition"), arg);
9581 /* Dynamic printf requires and uses additional arguments on the
9582 command line, otherwise it's an error. */
9583 if (type == bp_dprintf)
9585 if (b->extra_string)
9586 update_dprintf_command_list (b);
9588 error (_("Format string required"));
9590 else if (b->extra_string)
9591 error (_("Garbage '%s' at end of command"), b->extra_string);
9594 b->display_canonical = display_canonical;
9596 b->addr_string = addr_string;
9598 /* addr_string has to be used or breakpoint_re_set will delete
9601 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9606 create_breakpoint_sal (struct gdbarch *gdbarch,
9607 struct symtabs_and_lines sals, char *addr_string,
9608 char *filter, char *cond_string,
9610 enum bptype type, enum bpdisp disposition,
9611 int thread, int task, int ignore_count,
9612 const struct breakpoint_ops *ops, int from_tty,
9613 int enabled, int internal, unsigned flags,
9614 int display_canonical)
9616 struct breakpoint *b;
9617 struct cleanup *old_chain;
9619 if (is_tracepoint_type (type))
9621 struct tracepoint *t;
9623 t = XCNEW (struct tracepoint);
9627 b = XNEW (struct breakpoint);
9629 old_chain = make_cleanup (xfree, b);
9631 init_breakpoint_sal (b, gdbarch,
9633 filter, cond_string, extra_string,
9635 thread, task, ignore_count,
9637 enabled, internal, flags,
9639 discard_cleanups (old_chain);
9641 install_breakpoint (internal, b, 0);
9644 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9645 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9646 value. COND_STRING, if not NULL, specified the condition to be
9647 used for all breakpoints. Essentially the only case where
9648 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9649 function. In that case, it's still not possible to specify
9650 separate conditions for different overloaded functions, so
9651 we take just a single condition string.
9653 NOTE: If the function succeeds, the caller is expected to cleanup
9654 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9655 array contents). If the function fails (error() is called), the
9656 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9657 COND and SALS arrays and each of those arrays contents. */
9660 create_breakpoints_sal (struct gdbarch *gdbarch,
9661 struct linespec_result *canonical,
9662 char *cond_string, char *extra_string,
9663 enum bptype type, enum bpdisp disposition,
9664 int thread, int task, int ignore_count,
9665 const struct breakpoint_ops *ops, int from_tty,
9666 int enabled, int internal, unsigned flags)
9669 struct linespec_sals *lsal;
9671 if (canonical->pre_expanded)
9672 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9674 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9676 /* Note that 'addr_string' can be NULL in the case of a plain
9677 'break', without arguments. */
9678 char *addr_string = (canonical->addr_string
9679 ? xstrdup (canonical->addr_string)
9681 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9682 struct cleanup *inner = make_cleanup (xfree, addr_string);
9684 make_cleanup (xfree, filter_string);
9685 create_breakpoint_sal (gdbarch, lsal->sals,
9688 cond_string, extra_string,
9690 thread, task, ignore_count, ops,
9691 from_tty, enabled, internal, flags,
9692 canonical->special_display);
9693 discard_cleanups (inner);
9697 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9698 followed by conditionals. On return, SALS contains an array of SAL
9699 addresses found. ADDR_STRING contains a vector of (canonical)
9700 address strings. ADDRESS points to the end of the SAL.
9702 The array and the line spec strings are allocated on the heap, it is
9703 the caller's responsibility to free them. */
9706 parse_breakpoint_sals (char **address,
9707 struct linespec_result *canonical)
9709 /* If no arg given, or if first arg is 'if ', use the default
9711 if ((*address) == NULL
9712 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9714 /* The last displayed codepoint, if it's valid, is our default breakpoint
9716 if (last_displayed_sal_is_valid ())
9718 struct linespec_sals lsal;
9719 struct symtab_and_line sal;
9722 init_sal (&sal); /* Initialize to zeroes. */
9723 lsal.sals.sals = (struct symtab_and_line *)
9724 xmalloc (sizeof (struct symtab_and_line));
9726 /* Set sal's pspace, pc, symtab, and line to the values
9727 corresponding to the last call to print_frame_info.
9728 Be sure to reinitialize LINE with NOTCURRENT == 0
9729 as the breakpoint line number is inappropriate otherwise.
9730 find_pc_line would adjust PC, re-set it back. */
9731 get_last_displayed_sal (&sal);
9733 sal = find_pc_line (pc, 0);
9735 /* "break" without arguments is equivalent to "break *PC"
9736 where PC is the last displayed codepoint's address. So
9737 make sure to set sal.explicit_pc to prevent GDB from
9738 trying to expand the list of sals to include all other
9739 instances with the same symtab and line. */
9741 sal.explicit_pc = 1;
9743 lsal.sals.sals[0] = sal;
9744 lsal.sals.nelts = 1;
9745 lsal.canonical = NULL;
9747 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9750 error (_("No default breakpoint address now."));
9754 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9756 /* Force almost all breakpoints to be in terms of the
9757 current_source_symtab (which is decode_line_1's default).
9758 This should produce the results we want almost all of the
9759 time while leaving default_breakpoint_* alone.
9761 ObjC: However, don't match an Objective-C method name which
9762 may have a '+' or '-' succeeded by a '['. */
9763 if (last_displayed_sal_is_valid ()
9765 || ((strchr ("+-", (*address)[0]) != NULL)
9766 && ((*address)[1] != '['))))
9767 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9768 get_last_displayed_symtab (),
9769 get_last_displayed_line (),
9770 canonical, NULL, NULL);
9772 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9773 cursal.symtab, cursal.line, canonical, NULL, NULL);
9778 /* Convert each SAL into a real PC. Verify that the PC can be
9779 inserted as a breakpoint. If it can't throw an error. */
9782 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9786 for (i = 0; i < sals->nelts; i++)
9787 resolve_sal_pc (&sals->sals[i]);
9790 /* Fast tracepoints may have restrictions on valid locations. For
9791 instance, a fast tracepoint using a jump instead of a trap will
9792 likely have to overwrite more bytes than a trap would, and so can
9793 only be placed where the instruction is longer than the jump, or a
9794 multi-instruction sequence does not have a jump into the middle of
9798 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9799 struct symtabs_and_lines *sals)
9802 struct symtab_and_line *sal;
9804 struct cleanup *old_chain;
9806 for (i = 0; i < sals->nelts; i++)
9808 struct gdbarch *sarch;
9810 sal = &sals->sals[i];
9812 sarch = get_sal_arch (*sal);
9813 /* We fall back to GDBARCH if there is no architecture
9814 associated with SAL. */
9817 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9819 old_chain = make_cleanup (xfree, msg);
9822 error (_("May not have a fast tracepoint at 0x%s%s"),
9823 paddress (sarch, sal->pc), (msg ? msg : ""));
9825 do_cleanups (old_chain);
9829 /* Issue an invalid thread ID error. */
9831 static void ATTRIBUTE_NORETURN
9832 invalid_thread_id_error (int id)
9834 error (_("Unknown thread %d."), id);
9837 /* Given TOK, a string specification of condition and thread, as
9838 accepted by the 'break' command, extract the condition
9839 string and thread number and set *COND_STRING and *THREAD.
9840 PC identifies the context at which the condition should be parsed.
9841 If no condition is found, *COND_STRING is set to NULL.
9842 If no thread is found, *THREAD is set to -1. */
9845 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9846 char **cond_string, int *thread, int *task,
9849 *cond_string = NULL;
9856 const char *end_tok;
9858 const char *cond_start = NULL;
9859 const char *cond_end = NULL;
9861 tok = skip_spaces_const (tok);
9863 if ((*tok == '"' || *tok == ',') && rest)
9865 *rest = savestring (tok, strlen (tok));
9869 end_tok = skip_to_space_const (tok);
9871 toklen = end_tok - tok;
9873 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9875 struct expression *expr;
9877 tok = cond_start = end_tok + 1;
9878 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9881 *cond_string = savestring (cond_start, cond_end - cond_start);
9883 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9888 *thread = strtol (tok, &tmptok, 0);
9890 error (_("Junk after thread keyword."));
9891 if (!valid_thread_id (*thread))
9892 invalid_thread_id_error (*thread);
9895 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9900 *task = strtol (tok, &tmptok, 0);
9902 error (_("Junk after task keyword."));
9903 if (!valid_task_id (*task))
9904 error (_("Unknown task %d."), *task);
9909 *rest = savestring (tok, strlen (tok));
9913 error (_("Junk at end of arguments."));
9917 /* Decode a static tracepoint marker spec. */
9919 static struct symtabs_and_lines
9920 decode_static_tracepoint_spec (char **arg_p)
9922 VEC(static_tracepoint_marker_p) *markers = NULL;
9923 struct symtabs_and_lines sals;
9924 struct cleanup *old_chain;
9925 char *p = &(*arg_p)[3];
9930 p = skip_spaces (p);
9932 endp = skip_to_space (p);
9934 marker_str = savestring (p, endp - p);
9935 old_chain = make_cleanup (xfree, marker_str);
9937 markers = target_static_tracepoint_markers_by_strid (marker_str);
9938 if (VEC_empty(static_tracepoint_marker_p, markers))
9939 error (_("No known static tracepoint marker named %s"), marker_str);
9941 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9942 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9944 for (i = 0; i < sals.nelts; i++)
9946 struct static_tracepoint_marker *marker;
9948 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9950 init_sal (&sals.sals[i]);
9952 sals.sals[i] = find_pc_line (marker->address, 0);
9953 sals.sals[i].pc = marker->address;
9955 release_static_tracepoint_marker (marker);
9958 do_cleanups (old_chain);
9964 /* Set a breakpoint. This function is shared between CLI and MI
9965 functions for setting a breakpoint. This function has two major
9966 modes of operations, selected by the PARSE_ARG parameter. If
9967 non-zero, the function will parse ARG, extracting location,
9968 condition, thread and extra string. Otherwise, ARG is just the
9969 breakpoint's location, with condition, thread, and extra string
9970 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9971 If INTERNAL is non-zero, the breakpoint number will be allocated
9972 from the internal breakpoint count. Returns true if any breakpoint
9973 was created; false otherwise. */
9976 create_breakpoint (struct gdbarch *gdbarch,
9977 char *arg, char *cond_string,
9978 int thread, char *extra_string,
9980 int tempflag, enum bptype type_wanted,
9982 enum auto_boolean pending_break_support,
9983 const struct breakpoint_ops *ops,
9984 int from_tty, int enabled, int internal,
9987 volatile struct gdb_exception e;
9988 char *copy_arg = NULL;
9989 char *addr_start = arg;
9990 struct linespec_result canonical;
9991 struct cleanup *old_chain;
9992 struct cleanup *bkpt_chain = NULL;
9995 int prev_bkpt_count = breakpoint_count;
9997 gdb_assert (ops != NULL);
9999 init_linespec_result (&canonical);
10001 TRY_CATCH (e, RETURN_MASK_ALL)
10003 ops->create_sals_from_address (&arg, &canonical, type_wanted,
10004 addr_start, ©_arg);
10007 /* If caller is interested in rc value from parse, set value. */
10011 if (VEC_empty (linespec_sals, canonical.sals))
10017 case NOT_FOUND_ERROR:
10019 /* If pending breakpoint support is turned off, throw
10022 if (pending_break_support == AUTO_BOOLEAN_FALSE)
10023 throw_exception (e);
10025 exception_print (gdb_stderr, e);
10027 /* If pending breakpoint support is auto query and the user
10028 selects no, then simply return the error code. */
10029 if (pending_break_support == AUTO_BOOLEAN_AUTO
10030 && !nquery (_("Make %s pending on future shared library load? "),
10031 bptype_string (type_wanted)))
10034 /* At this point, either the user was queried about setting
10035 a pending breakpoint and selected yes, or pending
10036 breakpoint behavior is on and thus a pending breakpoint
10037 is defaulted on behalf of the user. */
10039 struct linespec_sals lsal;
10041 copy_arg = xstrdup (addr_start);
10042 lsal.canonical = xstrdup (copy_arg);
10043 lsal.sals.nelts = 1;
10044 lsal.sals.sals = XNEW (struct symtab_and_line);
10045 init_sal (&lsal.sals.sals[0]);
10047 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
10051 throw_exception (e);
10055 throw_exception (e);
10058 /* Create a chain of things that always need to be cleaned up. */
10059 old_chain = make_cleanup_destroy_linespec_result (&canonical);
10061 /* ----------------------------- SNIP -----------------------------
10062 Anything added to the cleanup chain beyond this point is assumed
10063 to be part of a breakpoint. If the breakpoint create succeeds
10064 then the memory is not reclaimed. */
10065 bkpt_chain = make_cleanup (null_cleanup, 0);
10067 /* Resolve all line numbers to PC's and verify that the addresses
10068 are ok for the target. */
10072 struct linespec_sals *iter;
10074 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10075 breakpoint_sals_to_pc (&iter->sals);
10078 /* Fast tracepoints may have additional restrictions on location. */
10079 if (!pending && type_wanted == bp_fast_tracepoint)
10082 struct linespec_sals *iter;
10084 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10085 check_fast_tracepoint_sals (gdbarch, &iter->sals);
10088 /* Verify that condition can be parsed, before setting any
10089 breakpoints. Allocate a separate condition expression for each
10096 struct linespec_sals *lsal;
10098 lsal = VEC_index (linespec_sals, canonical.sals, 0);
10100 /* Here we only parse 'arg' to separate condition
10101 from thread number, so parsing in context of first
10102 sal is OK. When setting the breakpoint we'll
10103 re-parse it in context of each sal. */
10105 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
10106 &thread, &task, &rest);
10108 make_cleanup (xfree, cond_string);
10110 make_cleanup (xfree, rest);
10112 extra_string = rest;
10117 error (_("Garbage '%s' at end of location"), arg);
10119 /* Create a private copy of condition string. */
10122 cond_string = xstrdup (cond_string);
10123 make_cleanup (xfree, cond_string);
10125 /* Create a private copy of any extra string. */
10128 extra_string = xstrdup (extra_string);
10129 make_cleanup (xfree, extra_string);
10133 ops->create_breakpoints_sal (gdbarch, &canonical,
10134 cond_string, extra_string, type_wanted,
10135 tempflag ? disp_del : disp_donttouch,
10136 thread, task, ignore_count, ops,
10137 from_tty, enabled, internal, flags);
10141 struct breakpoint *b;
10143 make_cleanup (xfree, copy_arg);
10145 if (is_tracepoint_type (type_wanted))
10147 struct tracepoint *t;
10149 t = XCNEW (struct tracepoint);
10153 b = XNEW (struct breakpoint);
10155 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
10157 b->addr_string = copy_arg;
10159 b->cond_string = NULL;
10162 /* Create a private copy of condition string. */
10165 cond_string = xstrdup (cond_string);
10166 make_cleanup (xfree, cond_string);
10168 b->cond_string = cond_string;
10170 b->extra_string = NULL;
10171 b->ignore_count = ignore_count;
10172 b->disposition = tempflag ? disp_del : disp_donttouch;
10173 b->condition_not_parsed = 1;
10174 b->enable_state = enabled ? bp_enabled : bp_disabled;
10175 if ((type_wanted != bp_breakpoint
10176 && type_wanted != bp_hardware_breakpoint) || thread != -1)
10177 b->pspace = current_program_space;
10179 install_breakpoint (internal, b, 0);
10182 if (VEC_length (linespec_sals, canonical.sals) > 1)
10184 warning (_("Multiple breakpoints were set.\nUse the "
10185 "\"delete\" command to delete unwanted breakpoints."));
10186 prev_breakpoint_count = prev_bkpt_count;
10189 /* That's it. Discard the cleanups for data inserted into the
10191 discard_cleanups (bkpt_chain);
10192 /* But cleanup everything else. */
10193 do_cleanups (old_chain);
10195 /* error call may happen here - have BKPT_CHAIN already discarded. */
10196 update_global_location_list (UGLL_MAY_INSERT);
10201 /* Set a breakpoint.
10202 ARG is a string describing breakpoint address,
10203 condition, and thread.
10204 FLAG specifies if a breakpoint is hardware on,
10205 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10206 and BP_TEMPFLAG. */
10209 break_command_1 (char *arg, int flag, int from_tty)
10211 int tempflag = flag & BP_TEMPFLAG;
10212 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
10213 ? bp_hardware_breakpoint
10215 struct breakpoint_ops *ops;
10216 const char *arg_cp = arg;
10218 /* Matching breakpoints on probes. */
10219 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
10220 ops = &bkpt_probe_breakpoint_ops;
10222 ops = &bkpt_breakpoint_ops;
10224 create_breakpoint (get_current_arch (),
10226 NULL, 0, NULL, 1 /* parse arg */,
10227 tempflag, type_wanted,
10228 0 /* Ignore count */,
10229 pending_break_support,
10237 /* Helper function for break_command_1 and disassemble_command. */
10240 resolve_sal_pc (struct symtab_and_line *sal)
10244 if (sal->pc == 0 && sal->symtab != NULL)
10246 if (!find_line_pc (sal->symtab, sal->line, &pc))
10247 error (_("No line %d in file \"%s\"."),
10248 sal->line, symtab_to_filename_for_display (sal->symtab));
10251 /* If this SAL corresponds to a breakpoint inserted using a line
10252 number, then skip the function prologue if necessary. */
10253 if (sal->explicit_line)
10254 skip_prologue_sal (sal);
10257 if (sal->section == 0 && sal->symtab != NULL)
10259 const struct blockvector *bv;
10260 const struct block *b;
10261 struct symbol *sym;
10263 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
10266 sym = block_linkage_function (b);
10269 fixup_symbol_section (sym, sal->symtab->objfile);
10270 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
10274 /* It really is worthwhile to have the section, so we'll
10275 just have to look harder. This case can be executed
10276 if we have line numbers but no functions (as can
10277 happen in assembly source). */
10279 struct bound_minimal_symbol msym;
10280 struct cleanup *old_chain = save_current_space_and_thread ();
10282 switch_to_program_space_and_thread (sal->pspace);
10284 msym = lookup_minimal_symbol_by_pc (sal->pc);
10286 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10288 do_cleanups (old_chain);
10295 break_command (char *arg, int from_tty)
10297 break_command_1 (arg, 0, from_tty);
10301 tbreak_command (char *arg, int from_tty)
10303 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10307 hbreak_command (char *arg, int from_tty)
10309 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10313 thbreak_command (char *arg, int from_tty)
10315 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10319 stop_command (char *arg, int from_tty)
10321 printf_filtered (_("Specify the type of breakpoint to set.\n\
10322 Usage: stop in <function | address>\n\
10323 stop at <line>\n"));
10327 stopin_command (char *arg, int from_tty)
10331 if (arg == (char *) NULL)
10333 else if (*arg != '*')
10335 char *argptr = arg;
10338 /* Look for a ':'. If this is a line number specification, then
10339 say it is bad, otherwise, it should be an address or
10340 function/method name. */
10341 while (*argptr && !hasColon)
10343 hasColon = (*argptr == ':');
10348 badInput = (*argptr != ':'); /* Not a class::method */
10350 badInput = isdigit (*arg); /* a simple line number */
10354 printf_filtered (_("Usage: stop in <function | address>\n"));
10356 break_command_1 (arg, 0, from_tty);
10360 stopat_command (char *arg, int from_tty)
10364 if (arg == (char *) NULL || *arg == '*') /* no line number */
10368 char *argptr = arg;
10371 /* Look for a ':'. If there is a '::' then get out, otherwise
10372 it is probably a line number. */
10373 while (*argptr && !hasColon)
10375 hasColon = (*argptr == ':');
10380 badInput = (*argptr == ':'); /* we have class::method */
10382 badInput = !isdigit (*arg); /* not a line number */
10386 printf_filtered (_("Usage: stop at <line>\n"));
10388 break_command_1 (arg, 0, from_tty);
10391 /* The dynamic printf command is mostly like a regular breakpoint, but
10392 with a prewired command list consisting of a single output command,
10393 built from extra arguments supplied on the dprintf command
10397 dprintf_command (char *arg, int from_tty)
10399 create_breakpoint (get_current_arch (),
10401 NULL, 0, NULL, 1 /* parse arg */,
10403 0 /* Ignore count */,
10404 pending_break_support,
10405 &dprintf_breakpoint_ops,
10413 agent_printf_command (char *arg, int from_tty)
10415 error (_("May only run agent-printf on the target"));
10418 /* Implement the "breakpoint_hit" breakpoint_ops method for
10419 ranged breakpoints. */
10422 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10423 struct address_space *aspace,
10425 const struct target_waitstatus *ws)
10427 if (ws->kind != TARGET_WAITKIND_STOPPED
10428 || ws->value.sig != GDB_SIGNAL_TRAP)
10431 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10432 bl->length, aspace, bp_addr);
10435 /* Implement the "resources_needed" breakpoint_ops method for
10436 ranged breakpoints. */
10439 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10441 return target_ranged_break_num_registers ();
10444 /* Implement the "print_it" breakpoint_ops method for
10445 ranged breakpoints. */
10447 static enum print_stop_action
10448 print_it_ranged_breakpoint (bpstat bs)
10450 struct breakpoint *b = bs->breakpoint_at;
10451 struct bp_location *bl = b->loc;
10452 struct ui_out *uiout = current_uiout;
10454 gdb_assert (b->type == bp_hardware_breakpoint);
10456 /* Ranged breakpoints have only one location. */
10457 gdb_assert (bl && bl->next == NULL);
10459 annotate_breakpoint (b->number);
10460 if (b->disposition == disp_del)
10461 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10463 ui_out_text (uiout, "\nRanged breakpoint ");
10464 if (ui_out_is_mi_like_p (uiout))
10466 ui_out_field_string (uiout, "reason",
10467 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10468 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10470 ui_out_field_int (uiout, "bkptno", b->number);
10471 ui_out_text (uiout, ", ");
10473 return PRINT_SRC_AND_LOC;
10476 /* Implement the "print_one" breakpoint_ops method for
10477 ranged breakpoints. */
10480 print_one_ranged_breakpoint (struct breakpoint *b,
10481 struct bp_location **last_loc)
10483 struct bp_location *bl = b->loc;
10484 struct value_print_options opts;
10485 struct ui_out *uiout = current_uiout;
10487 /* Ranged breakpoints have only one location. */
10488 gdb_assert (bl && bl->next == NULL);
10490 get_user_print_options (&opts);
10492 if (opts.addressprint)
10493 /* We don't print the address range here, it will be printed later
10494 by print_one_detail_ranged_breakpoint. */
10495 ui_out_field_skip (uiout, "addr");
10496 annotate_field (5);
10497 print_breakpoint_location (b, bl);
10501 /* Implement the "print_one_detail" breakpoint_ops method for
10502 ranged breakpoints. */
10505 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10506 struct ui_out *uiout)
10508 CORE_ADDR address_start, address_end;
10509 struct bp_location *bl = b->loc;
10510 struct ui_file *stb = mem_fileopen ();
10511 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10515 address_start = bl->address;
10516 address_end = address_start + bl->length - 1;
10518 ui_out_text (uiout, "\taddress range: ");
10519 fprintf_unfiltered (stb, "[%s, %s]",
10520 print_core_address (bl->gdbarch, address_start),
10521 print_core_address (bl->gdbarch, address_end));
10522 ui_out_field_stream (uiout, "addr", stb);
10523 ui_out_text (uiout, "\n");
10525 do_cleanups (cleanup);
10528 /* Implement the "print_mention" breakpoint_ops method for
10529 ranged breakpoints. */
10532 print_mention_ranged_breakpoint (struct breakpoint *b)
10534 struct bp_location *bl = b->loc;
10535 struct ui_out *uiout = current_uiout;
10538 gdb_assert (b->type == bp_hardware_breakpoint);
10540 if (ui_out_is_mi_like_p (uiout))
10543 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10544 b->number, paddress (bl->gdbarch, bl->address),
10545 paddress (bl->gdbarch, bl->address + bl->length - 1));
10548 /* Implement the "print_recreate" breakpoint_ops method for
10549 ranged breakpoints. */
10552 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10554 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10555 b->addr_string_range_end);
10556 print_recreate_thread (b, fp);
10559 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10561 static struct breakpoint_ops ranged_breakpoint_ops;
10563 /* Find the address where the end of the breakpoint range should be
10564 placed, given the SAL of the end of the range. This is so that if
10565 the user provides a line number, the end of the range is set to the
10566 last instruction of the given line. */
10569 find_breakpoint_range_end (struct symtab_and_line sal)
10573 /* If the user provided a PC value, use it. Otherwise,
10574 find the address of the end of the given location. */
10575 if (sal.explicit_pc)
10582 ret = find_line_pc_range (sal, &start, &end);
10584 error (_("Could not find location of the end of the range."));
10586 /* find_line_pc_range returns the start of the next line. */
10593 /* Implement the "break-range" CLI command. */
10596 break_range_command (char *arg, int from_tty)
10598 char *arg_start, *addr_string_start, *addr_string_end;
10599 struct linespec_result canonical_start, canonical_end;
10600 int bp_count, can_use_bp, length;
10602 struct breakpoint *b;
10603 struct symtab_and_line sal_start, sal_end;
10604 struct cleanup *cleanup_bkpt;
10605 struct linespec_sals *lsal_start, *lsal_end;
10607 /* We don't support software ranged breakpoints. */
10608 if (target_ranged_break_num_registers () < 0)
10609 error (_("This target does not support hardware ranged breakpoints."));
10611 bp_count = hw_breakpoint_used_count ();
10612 bp_count += target_ranged_break_num_registers ();
10613 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10615 if (can_use_bp < 0)
10616 error (_("Hardware breakpoints used exceeds limit."));
10618 arg = skip_spaces (arg);
10619 if (arg == NULL || arg[0] == '\0')
10620 error(_("No address range specified."));
10622 init_linespec_result (&canonical_start);
10625 parse_breakpoint_sals (&arg, &canonical_start);
10627 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10630 error (_("Too few arguments."));
10631 else if (VEC_empty (linespec_sals, canonical_start.sals))
10632 error (_("Could not find location of the beginning of the range."));
10634 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10636 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10637 || lsal_start->sals.nelts != 1)
10638 error (_("Cannot create a ranged breakpoint with multiple locations."));
10640 sal_start = lsal_start->sals.sals[0];
10641 addr_string_start = savestring (arg_start, arg - arg_start);
10642 make_cleanup (xfree, addr_string_start);
10644 arg++; /* Skip the comma. */
10645 arg = skip_spaces (arg);
10647 /* Parse the end location. */
10649 init_linespec_result (&canonical_end);
10652 /* We call decode_line_full directly here instead of using
10653 parse_breakpoint_sals because we need to specify the start location's
10654 symtab and line as the default symtab and line for the end of the
10655 range. This makes it possible to have ranges like "foo.c:27, +14",
10656 where +14 means 14 lines from the start location. */
10657 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10658 sal_start.symtab, sal_start.line,
10659 &canonical_end, NULL, NULL);
10661 make_cleanup_destroy_linespec_result (&canonical_end);
10663 if (VEC_empty (linespec_sals, canonical_end.sals))
10664 error (_("Could not find location of the end of the range."));
10666 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10667 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10668 || lsal_end->sals.nelts != 1)
10669 error (_("Cannot create a ranged breakpoint with multiple locations."));
10671 sal_end = lsal_end->sals.sals[0];
10672 addr_string_end = savestring (arg_start, arg - arg_start);
10673 make_cleanup (xfree, addr_string_end);
10675 end = find_breakpoint_range_end (sal_end);
10676 if (sal_start.pc > end)
10677 error (_("Invalid address range, end precedes start."));
10679 length = end - sal_start.pc + 1;
10681 /* Length overflowed. */
10682 error (_("Address range too large."));
10683 else if (length == 1)
10685 /* This range is simple enough to be handled by
10686 the `hbreak' command. */
10687 hbreak_command (addr_string_start, 1);
10689 do_cleanups (cleanup_bkpt);
10694 /* Now set up the breakpoint. */
10695 b = set_raw_breakpoint (get_current_arch (), sal_start,
10696 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10697 set_breakpoint_count (breakpoint_count + 1);
10698 b->number = breakpoint_count;
10699 b->disposition = disp_donttouch;
10700 b->addr_string = xstrdup (addr_string_start);
10701 b->addr_string_range_end = xstrdup (addr_string_end);
10702 b->loc->length = length;
10704 do_cleanups (cleanup_bkpt);
10707 observer_notify_breakpoint_created (b);
10708 update_global_location_list (UGLL_MAY_INSERT);
10711 /* Return non-zero if EXP is verified as constant. Returned zero
10712 means EXP is variable. Also the constant detection may fail for
10713 some constant expressions and in such case still falsely return
10717 watchpoint_exp_is_const (const struct expression *exp)
10719 int i = exp->nelts;
10725 /* We are only interested in the descriptor of each element. */
10726 operator_length (exp, i, &oplenp, &argsp);
10729 switch (exp->elts[i].opcode)
10739 case BINOP_LOGICAL_AND:
10740 case BINOP_LOGICAL_OR:
10741 case BINOP_BITWISE_AND:
10742 case BINOP_BITWISE_IOR:
10743 case BINOP_BITWISE_XOR:
10745 case BINOP_NOTEQUAL:
10772 case OP_OBJC_NSSTRING:
10775 case UNOP_LOGICAL_NOT:
10776 case UNOP_COMPLEMENT:
10781 case UNOP_CAST_TYPE:
10782 case UNOP_REINTERPRET_CAST:
10783 case UNOP_DYNAMIC_CAST:
10784 /* Unary, binary and ternary operators: We have to check
10785 their operands. If they are constant, then so is the
10786 result of that operation. For instance, if A and B are
10787 determined to be constants, then so is "A + B".
10789 UNOP_IND is one exception to the rule above, because the
10790 value of *ADDR is not necessarily a constant, even when
10795 /* Check whether the associated symbol is a constant.
10797 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10798 possible that a buggy compiler could mark a variable as
10799 constant even when it is not, and TYPE_CONST would return
10800 true in this case, while SYMBOL_CLASS wouldn't.
10802 We also have to check for function symbols because they
10803 are always constant. */
10805 struct symbol *s = exp->elts[i + 2].symbol;
10807 if (SYMBOL_CLASS (s) != LOC_BLOCK
10808 && SYMBOL_CLASS (s) != LOC_CONST
10809 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10814 /* The default action is to return 0 because we are using
10815 the optimistic approach here: If we don't know something,
10816 then it is not a constant. */
10825 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10828 dtor_watchpoint (struct breakpoint *self)
10830 struct watchpoint *w = (struct watchpoint *) self;
10832 xfree (w->cond_exp);
10834 xfree (w->exp_string);
10835 xfree (w->exp_string_reparse);
10836 value_free (w->val);
10838 base_breakpoint_ops.dtor (self);
10841 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10844 re_set_watchpoint (struct breakpoint *b)
10846 struct watchpoint *w = (struct watchpoint *) b;
10848 /* Watchpoint can be either on expression using entirely global
10849 variables, or it can be on local variables.
10851 Watchpoints of the first kind are never auto-deleted, and even
10852 persist across program restarts. Since they can use variables
10853 from shared libraries, we need to reparse expression as libraries
10854 are loaded and unloaded.
10856 Watchpoints on local variables can also change meaning as result
10857 of solib event. For example, if a watchpoint uses both a local
10858 and a global variables in expression, it's a local watchpoint,
10859 but unloading of a shared library will make the expression
10860 invalid. This is not a very common use case, but we still
10861 re-evaluate expression, to avoid surprises to the user.
10863 Note that for local watchpoints, we re-evaluate it only if
10864 watchpoints frame id is still valid. If it's not, it means the
10865 watchpoint is out of scope and will be deleted soon. In fact,
10866 I'm not sure we'll ever be called in this case.
10868 If a local watchpoint's frame id is still valid, then
10869 w->exp_valid_block is likewise valid, and we can safely use it.
10871 Don't do anything about disabled watchpoints, since they will be
10872 reevaluated again when enabled. */
10873 update_watchpoint (w, 1 /* reparse */);
10876 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10879 insert_watchpoint (struct bp_location *bl)
10881 struct watchpoint *w = (struct watchpoint *) bl->owner;
10882 int length = w->exact ? 1 : bl->length;
10884 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10888 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10891 remove_watchpoint (struct bp_location *bl)
10893 struct watchpoint *w = (struct watchpoint *) bl->owner;
10894 int length = w->exact ? 1 : bl->length;
10896 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10901 breakpoint_hit_watchpoint (const struct bp_location *bl,
10902 struct address_space *aspace, CORE_ADDR bp_addr,
10903 const struct target_waitstatus *ws)
10905 struct breakpoint *b = bl->owner;
10906 struct watchpoint *w = (struct watchpoint *) b;
10908 /* Continuable hardware watchpoints are treated as non-existent if the
10909 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10910 some data address). Otherwise gdb won't stop on a break instruction
10911 in the code (not from a breakpoint) when a hardware watchpoint has
10912 been defined. Also skip watchpoints which we know did not trigger
10913 (did not match the data address). */
10914 if (is_hardware_watchpoint (b)
10915 && w->watchpoint_triggered == watch_triggered_no)
10922 check_status_watchpoint (bpstat bs)
10924 gdb_assert (is_watchpoint (bs->breakpoint_at));
10926 bpstat_check_watchpoint (bs);
10929 /* Implement the "resources_needed" breakpoint_ops method for
10930 hardware watchpoints. */
10933 resources_needed_watchpoint (const struct bp_location *bl)
10935 struct watchpoint *w = (struct watchpoint *) bl->owner;
10936 int length = w->exact? 1 : bl->length;
10938 return target_region_ok_for_hw_watchpoint (bl->address, length);
10941 /* Implement the "works_in_software_mode" breakpoint_ops method for
10942 hardware watchpoints. */
10945 works_in_software_mode_watchpoint (const struct breakpoint *b)
10947 /* Read and access watchpoints only work with hardware support. */
10948 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10951 static enum print_stop_action
10952 print_it_watchpoint (bpstat bs)
10954 struct cleanup *old_chain;
10955 struct breakpoint *b;
10956 struct ui_file *stb;
10957 enum print_stop_action result;
10958 struct watchpoint *w;
10959 struct ui_out *uiout = current_uiout;
10961 gdb_assert (bs->bp_location_at != NULL);
10963 b = bs->breakpoint_at;
10964 w = (struct watchpoint *) b;
10966 stb = mem_fileopen ();
10967 old_chain = make_cleanup_ui_file_delete (stb);
10971 case bp_watchpoint:
10972 case bp_hardware_watchpoint:
10973 annotate_watchpoint (b->number);
10974 if (ui_out_is_mi_like_p (uiout))
10975 ui_out_field_string
10977 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10979 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10980 ui_out_text (uiout, "\nOld value = ");
10981 watchpoint_value_print (bs->old_val, stb);
10982 ui_out_field_stream (uiout, "old", stb);
10983 ui_out_text (uiout, "\nNew value = ");
10984 watchpoint_value_print (w->val, stb);
10985 ui_out_field_stream (uiout, "new", stb);
10986 ui_out_text (uiout, "\n");
10987 /* More than one watchpoint may have been triggered. */
10988 result = PRINT_UNKNOWN;
10991 case bp_read_watchpoint:
10992 if (ui_out_is_mi_like_p (uiout))
10993 ui_out_field_string
10995 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10997 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10998 ui_out_text (uiout, "\nValue = ");
10999 watchpoint_value_print (w->val, stb);
11000 ui_out_field_stream (uiout, "value", stb);
11001 ui_out_text (uiout, "\n");
11002 result = PRINT_UNKNOWN;
11005 case bp_access_watchpoint:
11006 if (bs->old_val != NULL)
11008 annotate_watchpoint (b->number);
11009 if (ui_out_is_mi_like_p (uiout))
11010 ui_out_field_string
11012 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11014 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11015 ui_out_text (uiout, "\nOld value = ");
11016 watchpoint_value_print (bs->old_val, stb);
11017 ui_out_field_stream (uiout, "old", stb);
11018 ui_out_text (uiout, "\nNew value = ");
11023 if (ui_out_is_mi_like_p (uiout))
11024 ui_out_field_string
11026 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11027 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
11028 ui_out_text (uiout, "\nValue = ");
11030 watchpoint_value_print (w->val, stb);
11031 ui_out_field_stream (uiout, "new", stb);
11032 ui_out_text (uiout, "\n");
11033 result = PRINT_UNKNOWN;
11036 result = PRINT_UNKNOWN;
11039 do_cleanups (old_chain);
11043 /* Implement the "print_mention" breakpoint_ops method for hardware
11047 print_mention_watchpoint (struct breakpoint *b)
11049 struct cleanup *ui_out_chain;
11050 struct watchpoint *w = (struct watchpoint *) b;
11051 struct ui_out *uiout = current_uiout;
11055 case bp_watchpoint:
11056 ui_out_text (uiout, "Watchpoint ");
11057 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11059 case bp_hardware_watchpoint:
11060 ui_out_text (uiout, "Hardware watchpoint ");
11061 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11063 case bp_read_watchpoint:
11064 ui_out_text (uiout, "Hardware read watchpoint ");
11065 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11067 case bp_access_watchpoint:
11068 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
11069 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11072 internal_error (__FILE__, __LINE__,
11073 _("Invalid hardware watchpoint type."));
11076 ui_out_field_int (uiout, "number", b->number);
11077 ui_out_text (uiout, ": ");
11078 ui_out_field_string (uiout, "exp", w->exp_string);
11079 do_cleanups (ui_out_chain);
11082 /* Implement the "print_recreate" breakpoint_ops method for
11086 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
11088 struct watchpoint *w = (struct watchpoint *) b;
11092 case bp_watchpoint:
11093 case bp_hardware_watchpoint:
11094 fprintf_unfiltered (fp, "watch");
11096 case bp_read_watchpoint:
11097 fprintf_unfiltered (fp, "rwatch");
11099 case bp_access_watchpoint:
11100 fprintf_unfiltered (fp, "awatch");
11103 internal_error (__FILE__, __LINE__,
11104 _("Invalid watchpoint type."));
11107 fprintf_unfiltered (fp, " %s", w->exp_string);
11108 print_recreate_thread (b, fp);
11111 /* Implement the "explains_signal" breakpoint_ops method for
11115 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
11117 /* A software watchpoint cannot cause a signal other than
11118 GDB_SIGNAL_TRAP. */
11119 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
11125 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11127 static struct breakpoint_ops watchpoint_breakpoint_ops;
11129 /* Implement the "insert" breakpoint_ops method for
11130 masked hardware watchpoints. */
11133 insert_masked_watchpoint (struct bp_location *bl)
11135 struct watchpoint *w = (struct watchpoint *) bl->owner;
11137 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
11138 bl->watchpoint_type);
11141 /* Implement the "remove" breakpoint_ops method for
11142 masked hardware watchpoints. */
11145 remove_masked_watchpoint (struct bp_location *bl)
11147 struct watchpoint *w = (struct watchpoint *) bl->owner;
11149 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
11150 bl->watchpoint_type);
11153 /* Implement the "resources_needed" breakpoint_ops method for
11154 masked hardware watchpoints. */
11157 resources_needed_masked_watchpoint (const struct bp_location *bl)
11159 struct watchpoint *w = (struct watchpoint *) bl->owner;
11161 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
11164 /* Implement the "works_in_software_mode" breakpoint_ops method for
11165 masked hardware watchpoints. */
11168 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
11173 /* Implement the "print_it" breakpoint_ops method for
11174 masked hardware watchpoints. */
11176 static enum print_stop_action
11177 print_it_masked_watchpoint (bpstat bs)
11179 struct breakpoint *b = bs->breakpoint_at;
11180 struct ui_out *uiout = current_uiout;
11182 /* Masked watchpoints have only one location. */
11183 gdb_assert (b->loc && b->loc->next == NULL);
11187 case bp_hardware_watchpoint:
11188 annotate_watchpoint (b->number);
11189 if (ui_out_is_mi_like_p (uiout))
11190 ui_out_field_string
11192 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11195 case bp_read_watchpoint:
11196 if (ui_out_is_mi_like_p (uiout))
11197 ui_out_field_string
11199 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11202 case bp_access_watchpoint:
11203 if (ui_out_is_mi_like_p (uiout))
11204 ui_out_field_string
11206 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11209 internal_error (__FILE__, __LINE__,
11210 _("Invalid hardware watchpoint type."));
11214 ui_out_text (uiout, _("\n\
11215 Check the underlying instruction at PC for the memory\n\
11216 address and value which triggered this watchpoint.\n"));
11217 ui_out_text (uiout, "\n");
11219 /* More than one watchpoint may have been triggered. */
11220 return PRINT_UNKNOWN;
11223 /* Implement the "print_one_detail" breakpoint_ops method for
11224 masked hardware watchpoints. */
11227 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11228 struct ui_out *uiout)
11230 struct watchpoint *w = (struct watchpoint *) b;
11232 /* Masked watchpoints have only one location. */
11233 gdb_assert (b->loc && b->loc->next == NULL);
11235 ui_out_text (uiout, "\tmask ");
11236 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11237 ui_out_text (uiout, "\n");
11240 /* Implement the "print_mention" breakpoint_ops method for
11241 masked hardware watchpoints. */
11244 print_mention_masked_watchpoint (struct breakpoint *b)
11246 struct watchpoint *w = (struct watchpoint *) b;
11247 struct ui_out *uiout = current_uiout;
11248 struct cleanup *ui_out_chain;
11252 case bp_hardware_watchpoint:
11253 ui_out_text (uiout, "Masked hardware watchpoint ");
11254 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11256 case bp_read_watchpoint:
11257 ui_out_text (uiout, "Masked hardware read watchpoint ");
11258 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11260 case bp_access_watchpoint:
11261 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11262 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11265 internal_error (__FILE__, __LINE__,
11266 _("Invalid hardware watchpoint type."));
11269 ui_out_field_int (uiout, "number", b->number);
11270 ui_out_text (uiout, ": ");
11271 ui_out_field_string (uiout, "exp", w->exp_string);
11272 do_cleanups (ui_out_chain);
11275 /* Implement the "print_recreate" breakpoint_ops method for
11276 masked hardware watchpoints. */
11279 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11281 struct watchpoint *w = (struct watchpoint *) b;
11286 case bp_hardware_watchpoint:
11287 fprintf_unfiltered (fp, "watch");
11289 case bp_read_watchpoint:
11290 fprintf_unfiltered (fp, "rwatch");
11292 case bp_access_watchpoint:
11293 fprintf_unfiltered (fp, "awatch");
11296 internal_error (__FILE__, __LINE__,
11297 _("Invalid hardware watchpoint type."));
11300 sprintf_vma (tmp, w->hw_wp_mask);
11301 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11302 print_recreate_thread (b, fp);
11305 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11307 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11309 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11312 is_masked_watchpoint (const struct breakpoint *b)
11314 return b->ops == &masked_watchpoint_breakpoint_ops;
11317 /* accessflag: hw_write: watch write,
11318 hw_read: watch read,
11319 hw_access: watch access (read or write) */
11321 watch_command_1 (const char *arg, int accessflag, int from_tty,
11322 int just_location, int internal)
11324 volatile struct gdb_exception e;
11325 struct breakpoint *b, *scope_breakpoint = NULL;
11326 struct expression *exp;
11327 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11328 struct value *val, *mark, *result;
11329 int saved_bitpos = 0, saved_bitsize = 0;
11330 struct frame_info *frame;
11331 const char *exp_start = NULL;
11332 const char *exp_end = NULL;
11333 const char *tok, *end_tok;
11335 const char *cond_start = NULL;
11336 const char *cond_end = NULL;
11337 enum bptype bp_type;
11340 /* Flag to indicate whether we are going to use masks for
11341 the hardware watchpoint. */
11343 CORE_ADDR mask = 0;
11344 struct watchpoint *w;
11346 struct cleanup *back_to;
11348 /* Make sure that we actually have parameters to parse. */
11349 if (arg != NULL && arg[0] != '\0')
11351 const char *value_start;
11353 exp_end = arg + strlen (arg);
11355 /* Look for "parameter value" pairs at the end
11356 of the arguments string. */
11357 for (tok = exp_end - 1; tok > arg; tok--)
11359 /* Skip whitespace at the end of the argument list. */
11360 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11363 /* Find the beginning of the last token.
11364 This is the value of the parameter. */
11365 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11367 value_start = tok + 1;
11369 /* Skip whitespace. */
11370 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11375 /* Find the beginning of the second to last token.
11376 This is the parameter itself. */
11377 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11380 toklen = end_tok - tok + 1;
11382 if (toklen == 6 && !strncmp (tok, "thread", 6))
11384 /* At this point we've found a "thread" token, which means
11385 the user is trying to set a watchpoint that triggers
11386 only in a specific thread. */
11390 error(_("You can specify only one thread."));
11392 /* Extract the thread ID from the next token. */
11393 thread = strtol (value_start, &endp, 0);
11395 /* Check if the user provided a valid numeric value for the
11397 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11398 error (_("Invalid thread ID specification %s."), value_start);
11400 /* Check if the thread actually exists. */
11401 if (!valid_thread_id (thread))
11402 invalid_thread_id_error (thread);
11404 else if (toklen == 4 && !strncmp (tok, "mask", 4))
11406 /* We've found a "mask" token, which means the user wants to
11407 create a hardware watchpoint that is going to have the mask
11409 struct value *mask_value, *mark;
11412 error(_("You can specify only one mask."));
11414 use_mask = just_location = 1;
11416 mark = value_mark ();
11417 mask_value = parse_to_comma_and_eval (&value_start);
11418 mask = value_as_address (mask_value);
11419 value_free_to_mark (mark);
11422 /* We didn't recognize what we found. We should stop here. */
11425 /* Truncate the string and get rid of the "parameter value" pair before
11426 the arguments string is parsed by the parse_exp_1 function. */
11433 /* Parse the rest of the arguments. From here on out, everything
11434 is in terms of a newly allocated string instead of the original
11436 innermost_block = NULL;
11437 expression = savestring (arg, exp_end - arg);
11438 back_to = make_cleanup (xfree, expression);
11439 exp_start = arg = expression;
11440 exp = parse_exp_1 (&arg, 0, 0, 0);
11442 /* Remove trailing whitespace from the expression before saving it.
11443 This makes the eventual display of the expression string a bit
11445 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11448 /* Checking if the expression is not constant. */
11449 if (watchpoint_exp_is_const (exp))
11453 len = exp_end - exp_start;
11454 while (len > 0 && isspace (exp_start[len - 1]))
11456 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11459 exp_valid_block = innermost_block;
11460 mark = value_mark ();
11461 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11463 if (val != NULL && just_location)
11465 saved_bitpos = value_bitpos (val);
11466 saved_bitsize = value_bitsize (val);
11473 exp_valid_block = NULL;
11474 val = value_addr (result);
11475 release_value (val);
11476 value_free_to_mark (mark);
11480 ret = target_masked_watch_num_registers (value_as_address (val),
11483 error (_("This target does not support masked watchpoints."));
11484 else if (ret == -2)
11485 error (_("Invalid mask or memory region."));
11488 else if (val != NULL)
11489 release_value (val);
11491 tok = skip_spaces_const (arg);
11492 end_tok = skip_to_space_const (tok);
11494 toklen = end_tok - tok;
11495 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11497 struct expression *cond;
11499 innermost_block = NULL;
11500 tok = cond_start = end_tok + 1;
11501 cond = parse_exp_1 (&tok, 0, 0, 0);
11503 /* The watchpoint expression may not be local, but the condition
11504 may still be. E.g.: `watch global if local > 0'. */
11505 cond_exp_valid_block = innermost_block;
11511 error (_("Junk at end of command."));
11513 frame = block_innermost_frame (exp_valid_block);
11515 /* If the expression is "local", then set up a "watchpoint scope"
11516 breakpoint at the point where we've left the scope of the watchpoint
11517 expression. Create the scope breakpoint before the watchpoint, so
11518 that we will encounter it first in bpstat_stop_status. */
11519 if (exp_valid_block && frame)
11521 if (frame_id_p (frame_unwind_caller_id (frame)))
11524 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11525 frame_unwind_caller_pc (frame),
11526 bp_watchpoint_scope,
11527 &momentary_breakpoint_ops);
11529 scope_breakpoint->enable_state = bp_enabled;
11531 /* Automatically delete the breakpoint when it hits. */
11532 scope_breakpoint->disposition = disp_del;
11534 /* Only break in the proper frame (help with recursion). */
11535 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11537 /* Set the address at which we will stop. */
11538 scope_breakpoint->loc->gdbarch
11539 = frame_unwind_caller_arch (frame);
11540 scope_breakpoint->loc->requested_address
11541 = frame_unwind_caller_pc (frame);
11542 scope_breakpoint->loc->address
11543 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11544 scope_breakpoint->loc->requested_address,
11545 scope_breakpoint->type);
11549 /* Now set up the breakpoint. We create all watchpoints as hardware
11550 watchpoints here even if hardware watchpoints are turned off, a call
11551 to update_watchpoint later in this function will cause the type to
11552 drop back to bp_watchpoint (software watchpoint) if required. */
11554 if (accessflag == hw_read)
11555 bp_type = bp_read_watchpoint;
11556 else if (accessflag == hw_access)
11557 bp_type = bp_access_watchpoint;
11559 bp_type = bp_hardware_watchpoint;
11561 w = XCNEW (struct watchpoint);
11564 init_raw_breakpoint_without_location (b, NULL, bp_type,
11565 &masked_watchpoint_breakpoint_ops);
11567 init_raw_breakpoint_without_location (b, NULL, bp_type,
11568 &watchpoint_breakpoint_ops);
11569 b->thread = thread;
11570 b->disposition = disp_donttouch;
11571 b->pspace = current_program_space;
11573 w->exp_valid_block = exp_valid_block;
11574 w->cond_exp_valid_block = cond_exp_valid_block;
11577 struct type *t = value_type (val);
11578 CORE_ADDR addr = value_as_address (val);
11581 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11582 name = type_to_string (t);
11584 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11585 core_addr_to_string (addr));
11588 w->exp_string = xstrprintf ("-location %.*s",
11589 (int) (exp_end - exp_start), exp_start);
11591 /* The above expression is in C. */
11592 b->language = language_c;
11595 w->exp_string = savestring (exp_start, exp_end - exp_start);
11599 w->hw_wp_mask = mask;
11604 w->val_bitpos = saved_bitpos;
11605 w->val_bitsize = saved_bitsize;
11610 b->cond_string = savestring (cond_start, cond_end - cond_start);
11612 b->cond_string = 0;
11616 w->watchpoint_frame = get_frame_id (frame);
11617 w->watchpoint_thread = inferior_ptid;
11621 w->watchpoint_frame = null_frame_id;
11622 w->watchpoint_thread = null_ptid;
11625 if (scope_breakpoint != NULL)
11627 /* The scope breakpoint is related to the watchpoint. We will
11628 need to act on them together. */
11629 b->related_breakpoint = scope_breakpoint;
11630 scope_breakpoint->related_breakpoint = b;
11633 if (!just_location)
11634 value_free_to_mark (mark);
11636 TRY_CATCH (e, RETURN_MASK_ALL)
11638 /* Finally update the new watchpoint. This creates the locations
11639 that should be inserted. */
11640 update_watchpoint (w, 1);
11644 delete_breakpoint (b);
11645 throw_exception (e);
11648 install_breakpoint (internal, b, 1);
11649 do_cleanups (back_to);
11652 /* Return count of debug registers needed to watch the given expression.
11653 If the watchpoint cannot be handled in hardware return zero. */
11656 can_use_hardware_watchpoint (struct value *v)
11658 int found_memory_cnt = 0;
11659 struct value *head = v;
11661 /* Did the user specifically forbid us to use hardware watchpoints? */
11662 if (!can_use_hw_watchpoints)
11665 /* Make sure that the value of the expression depends only upon
11666 memory contents, and values computed from them within GDB. If we
11667 find any register references or function calls, we can't use a
11668 hardware watchpoint.
11670 The idea here is that evaluating an expression generates a series
11671 of values, one holding the value of every subexpression. (The
11672 expression a*b+c has five subexpressions: a, b, a*b, c, and
11673 a*b+c.) GDB's values hold almost enough information to establish
11674 the criteria given above --- they identify memory lvalues,
11675 register lvalues, computed values, etcetera. So we can evaluate
11676 the expression, and then scan the chain of values that leaves
11677 behind to decide whether we can detect any possible change to the
11678 expression's final value using only hardware watchpoints.
11680 However, I don't think that the values returned by inferior
11681 function calls are special in any way. So this function may not
11682 notice that an expression involving an inferior function call
11683 can't be watched with hardware watchpoints. FIXME. */
11684 for (; v; v = value_next (v))
11686 if (VALUE_LVAL (v) == lval_memory)
11688 if (v != head && value_lazy (v))
11689 /* A lazy memory lvalue in the chain is one that GDB never
11690 needed to fetch; we either just used its address (e.g.,
11691 `a' in `a.b') or we never needed it at all (e.g., `a'
11692 in `a,b'). This doesn't apply to HEAD; if that is
11693 lazy then it was not readable, but watch it anyway. */
11697 /* Ahh, memory we actually used! Check if we can cover
11698 it with hardware watchpoints. */
11699 struct type *vtype = check_typedef (value_type (v));
11701 /* We only watch structs and arrays if user asked for it
11702 explicitly, never if they just happen to appear in a
11703 middle of some value chain. */
11705 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11706 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11708 CORE_ADDR vaddr = value_address (v);
11712 len = (target_exact_watchpoints
11713 && is_scalar_type_recursive (vtype))?
11714 1 : TYPE_LENGTH (value_type (v));
11716 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11720 found_memory_cnt += num_regs;
11724 else if (VALUE_LVAL (v) != not_lval
11725 && deprecated_value_modifiable (v) == 0)
11726 return 0; /* These are values from the history (e.g., $1). */
11727 else if (VALUE_LVAL (v) == lval_register)
11728 return 0; /* Cannot watch a register with a HW watchpoint. */
11731 /* The expression itself looks suitable for using a hardware
11732 watchpoint, but give the target machine a chance to reject it. */
11733 return found_memory_cnt;
11737 watch_command_wrapper (char *arg, int from_tty, int internal)
11739 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11742 /* A helper function that looks for the "-location" argument and then
11743 calls watch_command_1. */
11746 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11748 int just_location = 0;
11751 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11752 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11754 arg = skip_spaces (arg);
11758 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11762 watch_command (char *arg, int from_tty)
11764 watch_maybe_just_location (arg, hw_write, from_tty);
11768 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11770 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11774 rwatch_command (char *arg, int from_tty)
11776 watch_maybe_just_location (arg, hw_read, from_tty);
11780 awatch_command_wrapper (char *arg, int from_tty, int internal)
11782 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11786 awatch_command (char *arg, int from_tty)
11788 watch_maybe_just_location (arg, hw_access, from_tty);
11792 /* Helper routines for the until_command routine in infcmd.c. Here
11793 because it uses the mechanisms of breakpoints. */
11795 struct until_break_command_continuation_args
11797 struct breakpoint *breakpoint;
11798 struct breakpoint *breakpoint2;
11802 /* This function is called by fetch_inferior_event via the
11803 cmd_continuation pointer, to complete the until command. It takes
11804 care of cleaning up the temporary breakpoints set up by the until
11807 until_break_command_continuation (void *arg, int err)
11809 struct until_break_command_continuation_args *a = arg;
11811 delete_breakpoint (a->breakpoint);
11812 if (a->breakpoint2)
11813 delete_breakpoint (a->breakpoint2);
11814 delete_longjmp_breakpoint (a->thread_num);
11818 until_break_command (char *arg, int from_tty, int anywhere)
11820 struct symtabs_and_lines sals;
11821 struct symtab_and_line sal;
11822 struct frame_info *frame;
11823 struct gdbarch *frame_gdbarch;
11824 struct frame_id stack_frame_id;
11825 struct frame_id caller_frame_id;
11826 struct breakpoint *breakpoint;
11827 struct breakpoint *breakpoint2 = NULL;
11828 struct cleanup *old_chain;
11830 struct thread_info *tp;
11832 clear_proceed_status (0);
11834 /* Set a breakpoint where the user wants it and at return from
11837 if (last_displayed_sal_is_valid ())
11838 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11839 get_last_displayed_symtab (),
11840 get_last_displayed_line ());
11842 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11843 (struct symtab *) NULL, 0);
11845 if (sals.nelts != 1)
11846 error (_("Couldn't get information on specified line."));
11848 sal = sals.sals[0];
11849 xfree (sals.sals); /* malloc'd, so freed. */
11852 error (_("Junk at end of arguments."));
11854 resolve_sal_pc (&sal);
11856 tp = inferior_thread ();
11859 old_chain = make_cleanup (null_cleanup, NULL);
11861 /* Note linespec handling above invalidates the frame chain.
11862 Installing a breakpoint also invalidates the frame chain (as it
11863 may need to switch threads), so do any frame handling before
11866 frame = get_selected_frame (NULL);
11867 frame_gdbarch = get_frame_arch (frame);
11868 stack_frame_id = get_stack_frame_id (frame);
11869 caller_frame_id = frame_unwind_caller_id (frame);
11871 /* Keep within the current frame, or in frames called by the current
11874 if (frame_id_p (caller_frame_id))
11876 struct symtab_and_line sal2;
11878 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11879 sal2.pc = frame_unwind_caller_pc (frame);
11880 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11884 make_cleanup_delete_breakpoint (breakpoint2);
11886 set_longjmp_breakpoint (tp, caller_frame_id);
11887 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11890 /* set_momentary_breakpoint could invalidate FRAME. */
11894 /* If the user told us to continue until a specified location,
11895 we don't specify a frame at which we need to stop. */
11896 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11897 null_frame_id, bp_until);
11899 /* Otherwise, specify the selected frame, because we want to stop
11900 only at the very same frame. */
11901 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11902 stack_frame_id, bp_until);
11903 make_cleanup_delete_breakpoint (breakpoint);
11905 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11907 /* If we are running asynchronously, and proceed call above has
11908 actually managed to start the target, arrange for breakpoints to
11909 be deleted when the target stops. Otherwise, we're already
11910 stopped and delete breakpoints via cleanup chain. */
11912 if (target_can_async_p () && is_running (inferior_ptid))
11914 struct until_break_command_continuation_args *args;
11915 args = xmalloc (sizeof (*args));
11917 args->breakpoint = breakpoint;
11918 args->breakpoint2 = breakpoint2;
11919 args->thread_num = thread;
11921 discard_cleanups (old_chain);
11922 add_continuation (inferior_thread (),
11923 until_break_command_continuation, args,
11927 do_cleanups (old_chain);
11930 /* This function attempts to parse an optional "if <cond>" clause
11931 from the arg string. If one is not found, it returns NULL.
11933 Else, it returns a pointer to the condition string. (It does not
11934 attempt to evaluate the string against a particular block.) And,
11935 it updates arg to point to the first character following the parsed
11936 if clause in the arg string. */
11939 ep_parse_optional_if_clause (char **arg)
11943 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11946 /* Skip the "if" keyword. */
11949 /* Skip any extra leading whitespace, and record the start of the
11950 condition string. */
11951 *arg = skip_spaces (*arg);
11952 cond_string = *arg;
11954 /* Assume that the condition occupies the remainder of the arg
11956 (*arg) += strlen (cond_string);
11958 return cond_string;
11961 /* Commands to deal with catching events, such as signals, exceptions,
11962 process start/exit, etc. */
11966 catch_fork_temporary, catch_vfork_temporary,
11967 catch_fork_permanent, catch_vfork_permanent
11972 catch_fork_command_1 (char *arg, int from_tty,
11973 struct cmd_list_element *command)
11975 struct gdbarch *gdbarch = get_current_arch ();
11976 char *cond_string = NULL;
11977 catch_fork_kind fork_kind;
11980 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11981 tempflag = (fork_kind == catch_fork_temporary
11982 || fork_kind == catch_vfork_temporary);
11986 arg = skip_spaces (arg);
11988 /* The allowed syntax is:
11990 catch [v]fork if <cond>
11992 First, check if there's an if clause. */
11993 cond_string = ep_parse_optional_if_clause (&arg);
11995 if ((*arg != '\0') && !isspace (*arg))
11996 error (_("Junk at end of arguments."));
11998 /* If this target supports it, create a fork or vfork catchpoint
11999 and enable reporting of such events. */
12002 case catch_fork_temporary:
12003 case catch_fork_permanent:
12004 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
12005 &catch_fork_breakpoint_ops);
12007 case catch_vfork_temporary:
12008 case catch_vfork_permanent:
12009 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
12010 &catch_vfork_breakpoint_ops);
12013 error (_("unsupported or unknown fork kind; cannot catch it"));
12019 catch_exec_command_1 (char *arg, int from_tty,
12020 struct cmd_list_element *command)
12022 struct exec_catchpoint *c;
12023 struct gdbarch *gdbarch = get_current_arch ();
12025 char *cond_string = NULL;
12027 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12031 arg = skip_spaces (arg);
12033 /* The allowed syntax is:
12035 catch exec if <cond>
12037 First, check if there's an if clause. */
12038 cond_string = ep_parse_optional_if_clause (&arg);
12040 if ((*arg != '\0') && !isspace (*arg))
12041 error (_("Junk at end of arguments."));
12043 c = XNEW (struct exec_catchpoint);
12044 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
12045 &catch_exec_breakpoint_ops);
12046 c->exec_pathname = NULL;
12048 install_breakpoint (0, &c->base, 1);
12052 init_ada_exception_breakpoint (struct breakpoint *b,
12053 struct gdbarch *gdbarch,
12054 struct symtab_and_line sal,
12056 const struct breakpoint_ops *ops,
12063 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
12065 loc_gdbarch = gdbarch;
12067 describe_other_breakpoints (loc_gdbarch,
12068 sal.pspace, sal.pc, sal.section, -1);
12069 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12070 version for exception catchpoints, because two catchpoints
12071 used for different exception names will use the same address.
12072 In this case, a "breakpoint ... also set at..." warning is
12073 unproductive. Besides, the warning phrasing is also a bit
12074 inappropriate, we should use the word catchpoint, and tell
12075 the user what type of catchpoint it is. The above is good
12076 enough for now, though. */
12079 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
12081 b->enable_state = enabled ? bp_enabled : bp_disabled;
12082 b->disposition = tempflag ? disp_del : disp_donttouch;
12083 b->addr_string = addr_string;
12084 b->language = language_ada;
12087 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12088 filter list, or NULL if no filtering is required. */
12090 catch_syscall_split_args (char *arg)
12092 VEC(int) *result = NULL;
12093 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
12095 while (*arg != '\0')
12097 int i, syscall_number;
12099 char cur_name[128];
12102 /* Skip whitespace. */
12103 arg = skip_spaces (arg);
12105 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
12106 cur_name[i] = arg[i];
12107 cur_name[i] = '\0';
12110 /* Check if the user provided a syscall name or a number. */
12111 syscall_number = (int) strtol (cur_name, &endptr, 0);
12112 if (*endptr == '\0')
12113 get_syscall_by_number (syscall_number, &s);
12116 /* We have a name. Let's check if it's valid and convert it
12118 get_syscall_by_name (cur_name, &s);
12120 if (s.number == UNKNOWN_SYSCALL)
12121 /* Here we have to issue an error instead of a warning,
12122 because GDB cannot do anything useful if there's no
12123 syscall number to be caught. */
12124 error (_("Unknown syscall name '%s'."), cur_name);
12127 /* Ok, it's valid. */
12128 VEC_safe_push (int, result, s.number);
12131 discard_cleanups (cleanup);
12135 /* Implement the "catch syscall" command. */
12138 catch_syscall_command_1 (char *arg, int from_tty,
12139 struct cmd_list_element *command)
12144 struct gdbarch *gdbarch = get_current_arch ();
12146 /* Checking if the feature if supported. */
12147 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
12148 error (_("The feature 'catch syscall' is not supported on \
12149 this architecture yet."));
12151 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12153 arg = skip_spaces (arg);
12155 /* We need to do this first "dummy" translation in order
12156 to get the syscall XML file loaded or, most important,
12157 to display a warning to the user if there's no XML file
12158 for his/her architecture. */
12159 get_syscall_by_number (0, &s);
12161 /* The allowed syntax is:
12163 catch syscall <name | number> [<name | number> ... <name | number>]
12165 Let's check if there's a syscall name. */
12168 filter = catch_syscall_split_args (arg);
12172 create_syscall_event_catchpoint (tempflag, filter,
12173 &catch_syscall_breakpoint_ops);
12177 catch_command (char *arg, int from_tty)
12179 error (_("Catch requires an event name."));
12184 tcatch_command (char *arg, int from_tty)
12186 error (_("Catch requires an event name."));
12189 /* A qsort comparison function that sorts breakpoints in order. */
12192 compare_breakpoints (const void *a, const void *b)
12194 const breakpoint_p *ba = a;
12195 uintptr_t ua = (uintptr_t) *ba;
12196 const breakpoint_p *bb = b;
12197 uintptr_t ub = (uintptr_t) *bb;
12199 if ((*ba)->number < (*bb)->number)
12201 else if ((*ba)->number > (*bb)->number)
12204 /* Now sort by address, in case we see, e..g, two breakpoints with
12208 return ua > ub ? 1 : 0;
12211 /* Delete breakpoints by address or line. */
12214 clear_command (char *arg, int from_tty)
12216 struct breakpoint *b, *prev;
12217 VEC(breakpoint_p) *found = 0;
12220 struct symtabs_and_lines sals;
12221 struct symtab_and_line sal;
12223 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12227 sals = decode_line_with_current_source (arg,
12228 (DECODE_LINE_FUNFIRSTLINE
12229 | DECODE_LINE_LIST_MODE));
12230 make_cleanup (xfree, sals.sals);
12235 sals.sals = (struct symtab_and_line *)
12236 xmalloc (sizeof (struct symtab_and_line));
12237 make_cleanup (xfree, sals.sals);
12238 init_sal (&sal); /* Initialize to zeroes. */
12240 /* Set sal's line, symtab, pc, and pspace to the values
12241 corresponding to the last call to print_frame_info. If the
12242 codepoint is not valid, this will set all the fields to 0. */
12243 get_last_displayed_sal (&sal);
12244 if (sal.symtab == 0)
12245 error (_("No source file specified."));
12247 sals.sals[0] = sal;
12253 /* We don't call resolve_sal_pc here. That's not as bad as it
12254 seems, because all existing breakpoints typically have both
12255 file/line and pc set. So, if clear is given file/line, we can
12256 match this to existing breakpoint without obtaining pc at all.
12258 We only support clearing given the address explicitly
12259 present in breakpoint table. Say, we've set breakpoint
12260 at file:line. There were several PC values for that file:line,
12261 due to optimization, all in one block.
12263 We've picked one PC value. If "clear" is issued with another
12264 PC corresponding to the same file:line, the breakpoint won't
12265 be cleared. We probably can still clear the breakpoint, but
12266 since the other PC value is never presented to user, user
12267 can only find it by guessing, and it does not seem important
12268 to support that. */
12270 /* For each line spec given, delete bps which correspond to it. Do
12271 it in two passes, solely to preserve the current behavior that
12272 from_tty is forced true if we delete more than one
12276 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12277 for (i = 0; i < sals.nelts; i++)
12279 const char *sal_fullname;
12281 /* If exact pc given, clear bpts at that pc.
12282 If line given (pc == 0), clear all bpts on specified line.
12283 If defaulting, clear all bpts on default line
12286 defaulting sal.pc != 0 tests to do
12291 1 0 <can't happen> */
12293 sal = sals.sals[i];
12294 sal_fullname = (sal.symtab == NULL
12295 ? NULL : symtab_to_fullname (sal.symtab));
12297 /* Find all matching breakpoints and add them to 'found'. */
12298 ALL_BREAKPOINTS (b)
12301 /* Are we going to delete b? */
12302 if (b->type != bp_none && !is_watchpoint (b))
12304 struct bp_location *loc = b->loc;
12305 for (; loc; loc = loc->next)
12307 /* If the user specified file:line, don't allow a PC
12308 match. This matches historical gdb behavior. */
12309 int pc_match = (!sal.explicit_line
12311 && (loc->pspace == sal.pspace)
12312 && (loc->address == sal.pc)
12313 && (!section_is_overlay (loc->section)
12314 || loc->section == sal.section));
12315 int line_match = 0;
12317 if ((default_match || sal.explicit_line)
12318 && loc->symtab != NULL
12319 && sal_fullname != NULL
12320 && sal.pspace == loc->pspace
12321 && loc->line_number == sal.line
12322 && filename_cmp (symtab_to_fullname (loc->symtab),
12323 sal_fullname) == 0)
12326 if (pc_match || line_match)
12335 VEC_safe_push(breakpoint_p, found, b);
12339 /* Now go thru the 'found' chain and delete them. */
12340 if (VEC_empty(breakpoint_p, found))
12343 error (_("No breakpoint at %s."), arg);
12345 error (_("No breakpoint at this line."));
12348 /* Remove duplicates from the vec. */
12349 qsort (VEC_address (breakpoint_p, found),
12350 VEC_length (breakpoint_p, found),
12351 sizeof (breakpoint_p),
12352 compare_breakpoints);
12353 prev = VEC_index (breakpoint_p, found, 0);
12354 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12358 VEC_ordered_remove (breakpoint_p, found, ix);
12363 if (VEC_length(breakpoint_p, found) > 1)
12364 from_tty = 1; /* Always report if deleted more than one. */
12367 if (VEC_length(breakpoint_p, found) == 1)
12368 printf_unfiltered (_("Deleted breakpoint "));
12370 printf_unfiltered (_("Deleted breakpoints "));
12373 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12376 printf_unfiltered ("%d ", b->number);
12377 delete_breakpoint (b);
12380 putchar_unfiltered ('\n');
12382 do_cleanups (cleanups);
12385 /* Delete breakpoint in BS if they are `delete' breakpoints and
12386 all breakpoints that are marked for deletion, whether hit or not.
12387 This is called after any breakpoint is hit, or after errors. */
12390 breakpoint_auto_delete (bpstat bs)
12392 struct breakpoint *b, *b_tmp;
12394 for (; bs; bs = bs->next)
12395 if (bs->breakpoint_at
12396 && bs->breakpoint_at->disposition == disp_del
12398 delete_breakpoint (bs->breakpoint_at);
12400 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12402 if (b->disposition == disp_del_at_next_stop)
12403 delete_breakpoint (b);
12407 /* A comparison function for bp_location AP and BP being interfaced to
12408 qsort. Sort elements primarily by their ADDRESS (no matter what
12409 does breakpoint_address_is_meaningful say for its OWNER),
12410 secondarily by ordering first bp_permanent OWNERed elements and
12411 terciarily just ensuring the array is sorted stable way despite
12412 qsort being an unstable algorithm. */
12415 bp_location_compare (const void *ap, const void *bp)
12417 struct bp_location *a = *(void **) ap;
12418 struct bp_location *b = *(void **) bp;
12419 /* A and B come from existing breakpoints having non-NULL OWNER. */
12420 int a_perm = a->owner->enable_state == bp_permanent;
12421 int b_perm = b->owner->enable_state == bp_permanent;
12423 if (a->address != b->address)
12424 return (a->address > b->address) - (a->address < b->address);
12426 /* Sort locations at the same address by their pspace number, keeping
12427 locations of the same inferior (in a multi-inferior environment)
12430 if (a->pspace->num != b->pspace->num)
12431 return ((a->pspace->num > b->pspace->num)
12432 - (a->pspace->num < b->pspace->num));
12434 /* Sort permanent breakpoints first. */
12435 if (a_perm != b_perm)
12436 return (a_perm < b_perm) - (a_perm > b_perm);
12438 /* Make the internal GDB representation stable across GDB runs
12439 where A and B memory inside GDB can differ. Breakpoint locations of
12440 the same type at the same address can be sorted in arbitrary order. */
12442 if (a->owner->number != b->owner->number)
12443 return ((a->owner->number > b->owner->number)
12444 - (a->owner->number < b->owner->number));
12446 return (a > b) - (a < b);
12449 /* Set bp_location_placed_address_before_address_max and
12450 bp_location_shadow_len_after_address_max according to the current
12451 content of the bp_location array. */
12454 bp_location_target_extensions_update (void)
12456 struct bp_location *bl, **blp_tmp;
12458 bp_location_placed_address_before_address_max = 0;
12459 bp_location_shadow_len_after_address_max = 0;
12461 ALL_BP_LOCATIONS (bl, blp_tmp)
12463 CORE_ADDR start, end, addr;
12465 if (!bp_location_has_shadow (bl))
12468 start = bl->target_info.placed_address;
12469 end = start + bl->target_info.shadow_len;
12471 gdb_assert (bl->address >= start);
12472 addr = bl->address - start;
12473 if (addr > bp_location_placed_address_before_address_max)
12474 bp_location_placed_address_before_address_max = addr;
12476 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12478 gdb_assert (bl->address < end);
12479 addr = end - bl->address;
12480 if (addr > bp_location_shadow_len_after_address_max)
12481 bp_location_shadow_len_after_address_max = addr;
12485 /* Download tracepoint locations if they haven't been. */
12488 download_tracepoint_locations (void)
12490 struct breakpoint *b;
12491 struct cleanup *old_chain;
12493 if (!target_can_download_tracepoint ())
12496 old_chain = save_current_space_and_thread ();
12498 ALL_TRACEPOINTS (b)
12500 struct bp_location *bl;
12501 struct tracepoint *t;
12502 int bp_location_downloaded = 0;
12504 if ((b->type == bp_fast_tracepoint
12505 ? !may_insert_fast_tracepoints
12506 : !may_insert_tracepoints))
12509 for (bl = b->loc; bl; bl = bl->next)
12511 /* In tracepoint, locations are _never_ duplicated, so
12512 should_be_inserted is equivalent to
12513 unduplicated_should_be_inserted. */
12514 if (!should_be_inserted (bl) || bl->inserted)
12517 switch_to_program_space_and_thread (bl->pspace);
12519 target_download_tracepoint (bl);
12522 bp_location_downloaded = 1;
12524 t = (struct tracepoint *) b;
12525 t->number_on_target = b->number;
12526 if (bp_location_downloaded)
12527 observer_notify_breakpoint_modified (b);
12530 do_cleanups (old_chain);
12533 /* Swap the insertion/duplication state between two locations. */
12536 swap_insertion (struct bp_location *left, struct bp_location *right)
12538 const int left_inserted = left->inserted;
12539 const int left_duplicate = left->duplicate;
12540 const int left_needs_update = left->needs_update;
12541 const struct bp_target_info left_target_info = left->target_info;
12543 /* Locations of tracepoints can never be duplicated. */
12544 if (is_tracepoint (left->owner))
12545 gdb_assert (!left->duplicate);
12546 if (is_tracepoint (right->owner))
12547 gdb_assert (!right->duplicate);
12549 left->inserted = right->inserted;
12550 left->duplicate = right->duplicate;
12551 left->needs_update = right->needs_update;
12552 left->target_info = right->target_info;
12553 right->inserted = left_inserted;
12554 right->duplicate = left_duplicate;
12555 right->needs_update = left_needs_update;
12556 right->target_info = left_target_info;
12559 /* Force the re-insertion of the locations at ADDRESS. This is called
12560 once a new/deleted/modified duplicate location is found and we are evaluating
12561 conditions on the target's side. Such conditions need to be updated on
12565 force_breakpoint_reinsertion (struct bp_location *bl)
12567 struct bp_location **locp = NULL, **loc2p;
12568 struct bp_location *loc;
12569 CORE_ADDR address = 0;
12572 address = bl->address;
12573 pspace_num = bl->pspace->num;
12575 /* This is only meaningful if the target is
12576 evaluating conditions and if the user has
12577 opted for condition evaluation on the target's
12579 if (gdb_evaluates_breakpoint_condition_p ()
12580 || !target_supports_evaluation_of_breakpoint_conditions ())
12583 /* Flag all breakpoint locations with this address and
12584 the same program space as the location
12585 as "its condition has changed". We need to
12586 update the conditions on the target's side. */
12587 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12591 if (!is_breakpoint (loc->owner)
12592 || pspace_num != loc->pspace->num)
12595 /* Flag the location appropriately. We use a different state to
12596 let everyone know that we already updated the set of locations
12597 with addr bl->address and program space bl->pspace. This is so
12598 we don't have to keep calling these functions just to mark locations
12599 that have already been marked. */
12600 loc->condition_changed = condition_updated;
12602 /* Free the agent expression bytecode as well. We will compute
12604 if (loc->cond_bytecode)
12606 free_agent_expr (loc->cond_bytecode);
12607 loc->cond_bytecode = NULL;
12611 /* Called whether new breakpoints are created, or existing breakpoints
12612 deleted, to update the global location list and recompute which
12613 locations are duplicate of which.
12615 The INSERT_MODE flag determines whether locations may not, may, or
12616 shall be inserted now. See 'enum ugll_insert_mode' for more
12620 update_global_location_list (enum ugll_insert_mode insert_mode)
12622 struct breakpoint *b;
12623 struct bp_location **locp, *loc;
12624 struct cleanup *cleanups;
12625 /* Last breakpoint location address that was marked for update. */
12626 CORE_ADDR last_addr = 0;
12627 /* Last breakpoint location program space that was marked for update. */
12628 int last_pspace_num = -1;
12630 /* Used in the duplicates detection below. When iterating over all
12631 bp_locations, points to the first bp_location of a given address.
12632 Breakpoints and watchpoints of different types are never
12633 duplicates of each other. Keep one pointer for each type of
12634 breakpoint/watchpoint, so we only need to loop over all locations
12636 struct bp_location *bp_loc_first; /* breakpoint */
12637 struct bp_location *wp_loc_first; /* hardware watchpoint */
12638 struct bp_location *awp_loc_first; /* access watchpoint */
12639 struct bp_location *rwp_loc_first; /* read watchpoint */
12641 /* Saved former bp_location array which we compare against the newly
12642 built bp_location from the current state of ALL_BREAKPOINTS. */
12643 struct bp_location **old_location, **old_locp;
12644 unsigned old_location_count;
12646 old_location = bp_location;
12647 old_location_count = bp_location_count;
12648 bp_location = NULL;
12649 bp_location_count = 0;
12650 cleanups = make_cleanup (xfree, old_location);
12652 ALL_BREAKPOINTS (b)
12653 for (loc = b->loc; loc; loc = loc->next)
12654 bp_location_count++;
12656 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12657 locp = bp_location;
12658 ALL_BREAKPOINTS (b)
12659 for (loc = b->loc; loc; loc = loc->next)
12661 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12662 bp_location_compare);
12664 bp_location_target_extensions_update ();
12666 /* Identify bp_location instances that are no longer present in the
12667 new list, and therefore should be freed. Note that it's not
12668 necessary that those locations should be removed from inferior --
12669 if there's another location at the same address (previously
12670 marked as duplicate), we don't need to remove/insert the
12673 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12674 and former bp_location array state respectively. */
12676 locp = bp_location;
12677 for (old_locp = old_location; old_locp < old_location + old_location_count;
12680 struct bp_location *old_loc = *old_locp;
12681 struct bp_location **loc2p;
12683 /* Tells if 'old_loc' is found among the new locations. If
12684 not, we have to free it. */
12685 int found_object = 0;
12686 /* Tells if the location should remain inserted in the target. */
12687 int keep_in_target = 0;
12690 /* Skip LOCP entries which will definitely never be needed.
12691 Stop either at or being the one matching OLD_LOC. */
12692 while (locp < bp_location + bp_location_count
12693 && (*locp)->address < old_loc->address)
12697 (loc2p < bp_location + bp_location_count
12698 && (*loc2p)->address == old_loc->address);
12701 /* Check if this is a new/duplicated location or a duplicated
12702 location that had its condition modified. If so, we want to send
12703 its condition to the target if evaluation of conditions is taking
12705 if ((*loc2p)->condition_changed == condition_modified
12706 && (last_addr != old_loc->address
12707 || last_pspace_num != old_loc->pspace->num))
12709 force_breakpoint_reinsertion (*loc2p);
12710 last_pspace_num = old_loc->pspace->num;
12713 if (*loc2p == old_loc)
12717 /* We have already handled this address, update it so that we don't
12718 have to go through updates again. */
12719 last_addr = old_loc->address;
12721 /* Target-side condition evaluation: Handle deleted locations. */
12723 force_breakpoint_reinsertion (old_loc);
12725 /* If this location is no longer present, and inserted, look if
12726 there's maybe a new location at the same address. If so,
12727 mark that one inserted, and don't remove this one. This is
12728 needed so that we don't have a time window where a breakpoint
12729 at certain location is not inserted. */
12731 if (old_loc->inserted)
12733 /* If the location is inserted now, we might have to remove
12736 if (found_object && should_be_inserted (old_loc))
12738 /* The location is still present in the location list,
12739 and still should be inserted. Don't do anything. */
12740 keep_in_target = 1;
12744 /* This location still exists, but it won't be kept in the
12745 target since it may have been disabled. We proceed to
12746 remove its target-side condition. */
12748 /* The location is either no longer present, or got
12749 disabled. See if there's another location at the
12750 same address, in which case we don't need to remove
12751 this one from the target. */
12753 /* OLD_LOC comes from existing struct breakpoint. */
12754 if (breakpoint_address_is_meaningful (old_loc->owner))
12757 (loc2p < bp_location + bp_location_count
12758 && (*loc2p)->address == old_loc->address);
12761 struct bp_location *loc2 = *loc2p;
12763 if (breakpoint_locations_match (loc2, old_loc))
12765 /* Read watchpoint locations are switched to
12766 access watchpoints, if the former are not
12767 supported, but the latter are. */
12768 if (is_hardware_watchpoint (old_loc->owner))
12770 gdb_assert (is_hardware_watchpoint (loc2->owner));
12771 loc2->watchpoint_type = old_loc->watchpoint_type;
12774 /* loc2 is a duplicated location. We need to check
12775 if it should be inserted in case it will be
12777 if (loc2 != old_loc
12778 && unduplicated_should_be_inserted (loc2))
12780 swap_insertion (old_loc, loc2);
12781 keep_in_target = 1;
12789 if (!keep_in_target)
12791 if (remove_breakpoint (old_loc, mark_uninserted))
12793 /* This is just about all we can do. We could keep
12794 this location on the global list, and try to
12795 remove it next time, but there's no particular
12796 reason why we will succeed next time.
12798 Note that at this point, old_loc->owner is still
12799 valid, as delete_breakpoint frees the breakpoint
12800 only after calling us. */
12801 printf_filtered (_("warning: Error removing "
12802 "breakpoint %d\n"),
12803 old_loc->owner->number);
12811 if (removed && non_stop
12812 && breakpoint_address_is_meaningful (old_loc->owner)
12813 && !is_hardware_watchpoint (old_loc->owner))
12815 /* This location was removed from the target. In
12816 non-stop mode, a race condition is possible where
12817 we've removed a breakpoint, but stop events for that
12818 breakpoint are already queued and will arrive later.
12819 We apply an heuristic to be able to distinguish such
12820 SIGTRAPs from other random SIGTRAPs: we keep this
12821 breakpoint location for a bit, and will retire it
12822 after we see some number of events. The theory here
12823 is that reporting of events should, "on the average",
12824 be fair, so after a while we'll see events from all
12825 threads that have anything of interest, and no longer
12826 need to keep this breakpoint location around. We
12827 don't hold locations forever so to reduce chances of
12828 mistaking a non-breakpoint SIGTRAP for a breakpoint
12831 The heuristic failing can be disastrous on
12832 decr_pc_after_break targets.
12834 On decr_pc_after_break targets, like e.g., x86-linux,
12835 if we fail to recognize a late breakpoint SIGTRAP,
12836 because events_till_retirement has reached 0 too
12837 soon, we'll fail to do the PC adjustment, and report
12838 a random SIGTRAP to the user. When the user resumes
12839 the inferior, it will most likely immediately crash
12840 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12841 corrupted, because of being resumed e.g., in the
12842 middle of a multi-byte instruction, or skipped a
12843 one-byte instruction. This was actually seen happen
12844 on native x86-linux, and should be less rare on
12845 targets that do not support new thread events, like
12846 remote, due to the heuristic depending on
12849 Mistaking a random SIGTRAP for a breakpoint trap
12850 causes similar symptoms (PC adjustment applied when
12851 it shouldn't), but then again, playing with SIGTRAPs
12852 behind the debugger's back is asking for trouble.
12854 Since hardware watchpoint traps are always
12855 distinguishable from other traps, so we don't need to
12856 apply keep hardware watchpoint moribund locations
12857 around. We simply always ignore hardware watchpoint
12858 traps we can no longer explain. */
12860 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12861 old_loc->owner = NULL;
12863 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12867 old_loc->owner = NULL;
12868 decref_bp_location (&old_loc);
12873 /* Rescan breakpoints at the same address and section, marking the
12874 first one as "first" and any others as "duplicates". This is so
12875 that the bpt instruction is only inserted once. If we have a
12876 permanent breakpoint at the same place as BPT, make that one the
12877 official one, and the rest as duplicates. Permanent breakpoints
12878 are sorted first for the same address.
12880 Do the same for hardware watchpoints, but also considering the
12881 watchpoint's type (regular/access/read) and length. */
12883 bp_loc_first = NULL;
12884 wp_loc_first = NULL;
12885 awp_loc_first = NULL;
12886 rwp_loc_first = NULL;
12887 ALL_BP_LOCATIONS (loc, locp)
12889 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12891 struct bp_location **loc_first_p;
12894 if (!unduplicated_should_be_inserted (loc)
12895 || !breakpoint_address_is_meaningful (b)
12896 /* Don't detect duplicate for tracepoint locations because they are
12897 never duplicated. See the comments in field `duplicate' of
12898 `struct bp_location'. */
12899 || is_tracepoint (b))
12901 /* Clear the condition modification flag. */
12902 loc->condition_changed = condition_unchanged;
12906 /* Permanent breakpoint should always be inserted. */
12907 if (b->enable_state == bp_permanent && ! loc->inserted)
12908 internal_error (__FILE__, __LINE__,
12909 _("allegedly permanent breakpoint is not "
12910 "actually inserted"));
12912 if (b->type == bp_hardware_watchpoint)
12913 loc_first_p = &wp_loc_first;
12914 else if (b->type == bp_read_watchpoint)
12915 loc_first_p = &rwp_loc_first;
12916 else if (b->type == bp_access_watchpoint)
12917 loc_first_p = &awp_loc_first;
12919 loc_first_p = &bp_loc_first;
12921 if (*loc_first_p == NULL
12922 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12923 || !breakpoint_locations_match (loc, *loc_first_p))
12925 *loc_first_p = loc;
12926 loc->duplicate = 0;
12928 if (is_breakpoint (loc->owner) && loc->condition_changed)
12930 loc->needs_update = 1;
12931 /* Clear the condition modification flag. */
12932 loc->condition_changed = condition_unchanged;
12938 /* This and the above ensure the invariant that the first location
12939 is not duplicated, and is the inserted one.
12940 All following are marked as duplicated, and are not inserted. */
12942 swap_insertion (loc, *loc_first_p);
12943 loc->duplicate = 1;
12945 /* Clear the condition modification flag. */
12946 loc->condition_changed = condition_unchanged;
12948 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12949 && b->enable_state != bp_permanent)
12950 internal_error (__FILE__, __LINE__,
12951 _("another breakpoint was inserted on top of "
12952 "a permanent breakpoint"));
12955 if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12957 if (insert_mode != UGLL_DONT_INSERT)
12958 insert_breakpoint_locations ();
12961 /* Even though the caller told us to not insert new
12962 locations, we may still need to update conditions on the
12963 target's side of breakpoints that were already inserted
12964 if the target is evaluating breakpoint conditions. We
12965 only update conditions for locations that are marked
12967 update_inserted_breakpoint_locations ();
12971 if (insert_mode != UGLL_DONT_INSERT)
12972 download_tracepoint_locations ();
12974 do_cleanups (cleanups);
12978 breakpoint_retire_moribund (void)
12980 struct bp_location *loc;
12983 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12984 if (--(loc->events_till_retirement) == 0)
12986 decref_bp_location (&loc);
12987 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12993 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12995 volatile struct gdb_exception e;
12997 TRY_CATCH (e, RETURN_MASK_ERROR)
12998 update_global_location_list (insert_mode);
13001 /* Clear BKP from a BPS. */
13004 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
13008 for (bs = bps; bs; bs = bs->next)
13009 if (bs->breakpoint_at == bpt)
13011 bs->breakpoint_at = NULL;
13012 bs->old_val = NULL;
13013 /* bs->commands will be freed later. */
13017 /* Callback for iterate_over_threads. */
13019 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
13021 struct breakpoint *bpt = data;
13023 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
13027 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
13031 say_where (struct breakpoint *b)
13033 struct value_print_options opts;
13035 get_user_print_options (&opts);
13037 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13039 if (b->loc == NULL)
13041 printf_filtered (_(" (%s) pending."), b->addr_string);
13045 if (opts.addressprint || b->loc->symtab == NULL)
13047 printf_filtered (" at ");
13048 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
13051 if (b->loc->symtab != NULL)
13053 /* If there is a single location, we can print the location
13055 if (b->loc->next == NULL)
13056 printf_filtered (": file %s, line %d.",
13057 symtab_to_filename_for_display (b->loc->symtab),
13058 b->loc->line_number);
13060 /* This is not ideal, but each location may have a
13061 different file name, and this at least reflects the
13062 real situation somewhat. */
13063 printf_filtered (": %s.", b->addr_string);
13068 struct bp_location *loc = b->loc;
13070 for (; loc; loc = loc->next)
13072 printf_filtered (" (%d locations)", n);
13077 /* Default bp_location_ops methods. */
13080 bp_location_dtor (struct bp_location *self)
13082 xfree (self->cond);
13083 if (self->cond_bytecode)
13084 free_agent_expr (self->cond_bytecode);
13085 xfree (self->function_name);
13087 VEC_free (agent_expr_p, self->target_info.conditions);
13088 VEC_free (agent_expr_p, self->target_info.tcommands);
13091 static const struct bp_location_ops bp_location_ops =
13096 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13100 base_breakpoint_dtor (struct breakpoint *self)
13102 decref_counted_command_line (&self->commands);
13103 xfree (self->cond_string);
13104 xfree (self->extra_string);
13105 xfree (self->addr_string);
13106 xfree (self->filter);
13107 xfree (self->addr_string_range_end);
13110 static struct bp_location *
13111 base_breakpoint_allocate_location (struct breakpoint *self)
13113 struct bp_location *loc;
13115 loc = XNEW (struct bp_location);
13116 init_bp_location (loc, &bp_location_ops, self);
13121 base_breakpoint_re_set (struct breakpoint *b)
13123 /* Nothing to re-set. */
13126 #define internal_error_pure_virtual_called() \
13127 gdb_assert_not_reached ("pure virtual function called")
13130 base_breakpoint_insert_location (struct bp_location *bl)
13132 internal_error_pure_virtual_called ();
13136 base_breakpoint_remove_location (struct bp_location *bl)
13138 internal_error_pure_virtual_called ();
13142 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
13143 struct address_space *aspace,
13145 const struct target_waitstatus *ws)
13147 internal_error_pure_virtual_called ();
13151 base_breakpoint_check_status (bpstat bs)
13156 /* A "works_in_software_mode" breakpoint_ops method that just internal
13160 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
13162 internal_error_pure_virtual_called ();
13165 /* A "resources_needed" breakpoint_ops method that just internal
13169 base_breakpoint_resources_needed (const struct bp_location *bl)
13171 internal_error_pure_virtual_called ();
13174 static enum print_stop_action
13175 base_breakpoint_print_it (bpstat bs)
13177 internal_error_pure_virtual_called ();
13181 base_breakpoint_print_one_detail (const struct breakpoint *self,
13182 struct ui_out *uiout)
13188 base_breakpoint_print_mention (struct breakpoint *b)
13190 internal_error_pure_virtual_called ();
13194 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
13196 internal_error_pure_virtual_called ();
13200 base_breakpoint_create_sals_from_address (char **arg,
13201 struct linespec_result *canonical,
13202 enum bptype type_wanted,
13206 internal_error_pure_virtual_called ();
13210 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13211 struct linespec_result *c,
13213 char *extra_string,
13214 enum bptype type_wanted,
13215 enum bpdisp disposition,
13217 int task, int ignore_count,
13218 const struct breakpoint_ops *o,
13219 int from_tty, int enabled,
13220 int internal, unsigned flags)
13222 internal_error_pure_virtual_called ();
13226 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
13227 struct symtabs_and_lines *sals)
13229 internal_error_pure_virtual_called ();
13232 /* The default 'explains_signal' method. */
13235 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13240 /* The default "after_condition_true" method. */
13243 base_breakpoint_after_condition_true (struct bpstats *bs)
13245 /* Nothing to do. */
13248 struct breakpoint_ops base_breakpoint_ops =
13250 base_breakpoint_dtor,
13251 base_breakpoint_allocate_location,
13252 base_breakpoint_re_set,
13253 base_breakpoint_insert_location,
13254 base_breakpoint_remove_location,
13255 base_breakpoint_breakpoint_hit,
13256 base_breakpoint_check_status,
13257 base_breakpoint_resources_needed,
13258 base_breakpoint_works_in_software_mode,
13259 base_breakpoint_print_it,
13261 base_breakpoint_print_one_detail,
13262 base_breakpoint_print_mention,
13263 base_breakpoint_print_recreate,
13264 base_breakpoint_create_sals_from_address,
13265 base_breakpoint_create_breakpoints_sal,
13266 base_breakpoint_decode_linespec,
13267 base_breakpoint_explains_signal,
13268 base_breakpoint_after_condition_true,
13271 /* Default breakpoint_ops methods. */
13274 bkpt_re_set (struct breakpoint *b)
13276 /* FIXME: is this still reachable? */
13277 if (b->addr_string == NULL)
13279 /* Anything without a string can't be re-set. */
13280 delete_breakpoint (b);
13284 breakpoint_re_set_default (b);
13287 /* Copy SRC's shadow buffer and whatever else we'd set if we actually
13288 inserted DEST, so we can remove it later, in case SRC is removed
13292 bp_target_info_copy_insertion_state (struct bp_target_info *dest,
13293 const struct bp_target_info *src)
13295 dest->shadow_len = src->shadow_len;
13296 memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len);
13297 dest->placed_size = src->placed_size;
13301 bkpt_insert_location (struct bp_location *bl)
13303 if (bl->loc_type == bp_loc_hardware_breakpoint)
13304 return target_insert_hw_breakpoint (bl->gdbarch,
13308 struct bp_target_info *bp_tgt = &bl->target_info;
13312 /* There is no need to insert a breakpoint if an unconditional
13313 raw/sss breakpoint is already inserted at that location. */
13314 sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space,
13315 bp_tgt->placed_address);
13318 struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot];
13320 bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt);
13324 return target_insert_breakpoint (bl->gdbarch, bp_tgt);
13329 bkpt_remove_location (struct bp_location *bl)
13331 if (bl->loc_type == bp_loc_hardware_breakpoint)
13332 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13335 struct bp_target_info *bp_tgt = &bl->target_info;
13336 struct address_space *aspace = bp_tgt->placed_address_space;
13337 CORE_ADDR address = bp_tgt->placed_address;
13339 /* Only remove the breakpoint if there is no raw/sss breakpoint
13340 still inserted at this location. Otherwise, we would be
13341 effectively disabling the raw/sss breakpoint. */
13342 if (single_step_breakpoint_inserted_here_p (aspace, address))
13345 return target_remove_breakpoint (bl->gdbarch, bp_tgt);
13350 bkpt_breakpoint_hit (const struct bp_location *bl,
13351 struct address_space *aspace, CORE_ADDR bp_addr,
13352 const struct target_waitstatus *ws)
13354 if (ws->kind != TARGET_WAITKIND_STOPPED
13355 || ws->value.sig != GDB_SIGNAL_TRAP)
13358 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13362 if (overlay_debugging /* unmapped overlay section */
13363 && section_is_overlay (bl->section)
13364 && !section_is_mapped (bl->section))
13371 dprintf_breakpoint_hit (const struct bp_location *bl,
13372 struct address_space *aspace, CORE_ADDR bp_addr,
13373 const struct target_waitstatus *ws)
13375 if (dprintf_style == dprintf_style_agent
13376 && target_can_run_breakpoint_commands ())
13378 /* An agent-style dprintf never causes a stop. If we see a trap
13379 for this address it must be for a breakpoint that happens to
13380 be set at the same address. */
13384 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13388 bkpt_resources_needed (const struct bp_location *bl)
13390 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13395 static enum print_stop_action
13396 bkpt_print_it (bpstat bs)
13398 struct breakpoint *b;
13399 const struct bp_location *bl;
13401 struct ui_out *uiout = current_uiout;
13403 gdb_assert (bs->bp_location_at != NULL);
13405 bl = bs->bp_location_at;
13406 b = bs->breakpoint_at;
13408 bp_temp = b->disposition == disp_del;
13409 if (bl->address != bl->requested_address)
13410 breakpoint_adjustment_warning (bl->requested_address,
13413 annotate_breakpoint (b->number);
13415 ui_out_text (uiout, "\nTemporary breakpoint ");
13417 ui_out_text (uiout, "\nBreakpoint ");
13418 if (ui_out_is_mi_like_p (uiout))
13420 ui_out_field_string (uiout, "reason",
13421 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13422 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13424 ui_out_field_int (uiout, "bkptno", b->number);
13425 ui_out_text (uiout, ", ");
13427 return PRINT_SRC_AND_LOC;
13431 bkpt_print_mention (struct breakpoint *b)
13433 if (ui_out_is_mi_like_p (current_uiout))
13438 case bp_breakpoint:
13439 case bp_gnu_ifunc_resolver:
13440 if (b->disposition == disp_del)
13441 printf_filtered (_("Temporary breakpoint"));
13443 printf_filtered (_("Breakpoint"));
13444 printf_filtered (_(" %d"), b->number);
13445 if (b->type == bp_gnu_ifunc_resolver)
13446 printf_filtered (_(" at gnu-indirect-function resolver"));
13448 case bp_hardware_breakpoint:
13449 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13452 printf_filtered (_("Dprintf %d"), b->number);
13460 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13462 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13463 fprintf_unfiltered (fp, "tbreak");
13464 else if (tp->type == bp_breakpoint)
13465 fprintf_unfiltered (fp, "break");
13466 else if (tp->type == bp_hardware_breakpoint
13467 && tp->disposition == disp_del)
13468 fprintf_unfiltered (fp, "thbreak");
13469 else if (tp->type == bp_hardware_breakpoint)
13470 fprintf_unfiltered (fp, "hbreak");
13472 internal_error (__FILE__, __LINE__,
13473 _("unhandled breakpoint type %d"), (int) tp->type);
13475 fprintf_unfiltered (fp, " %s", tp->addr_string);
13476 print_recreate_thread (tp, fp);
13480 bkpt_create_sals_from_address (char **arg,
13481 struct linespec_result *canonical,
13482 enum bptype type_wanted,
13483 char *addr_start, char **copy_arg)
13485 create_sals_from_address_default (arg, canonical, type_wanted,
13486 addr_start, copy_arg);
13490 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13491 struct linespec_result *canonical,
13493 char *extra_string,
13494 enum bptype type_wanted,
13495 enum bpdisp disposition,
13497 int task, int ignore_count,
13498 const struct breakpoint_ops *ops,
13499 int from_tty, int enabled,
13500 int internal, unsigned flags)
13502 create_breakpoints_sal_default (gdbarch, canonical,
13503 cond_string, extra_string,
13505 disposition, thread, task,
13506 ignore_count, ops, from_tty,
13507 enabled, internal, flags);
13511 bkpt_decode_linespec (struct breakpoint *b, char **s,
13512 struct symtabs_and_lines *sals)
13514 decode_linespec_default (b, s, sals);
13517 /* Virtual table for internal breakpoints. */
13520 internal_bkpt_re_set (struct breakpoint *b)
13524 /* Delete overlay event and longjmp master breakpoints; they
13525 will be reset later by breakpoint_re_set. */
13526 case bp_overlay_event:
13527 case bp_longjmp_master:
13528 case bp_std_terminate_master:
13529 case bp_exception_master:
13530 delete_breakpoint (b);
13533 /* This breakpoint is special, it's set up when the inferior
13534 starts and we really don't want to touch it. */
13535 case bp_shlib_event:
13537 /* Like bp_shlib_event, this breakpoint type is special. Once
13538 it is set up, we do not want to touch it. */
13539 case bp_thread_event:
13545 internal_bkpt_check_status (bpstat bs)
13547 if (bs->breakpoint_at->type == bp_shlib_event)
13549 /* If requested, stop when the dynamic linker notifies GDB of
13550 events. This allows the user to get control and place
13551 breakpoints in initializer routines for dynamically loaded
13552 objects (among other things). */
13553 bs->stop = stop_on_solib_events;
13554 bs->print = stop_on_solib_events;
13560 static enum print_stop_action
13561 internal_bkpt_print_it (bpstat bs)
13563 struct breakpoint *b;
13565 b = bs->breakpoint_at;
13569 case bp_shlib_event:
13570 /* Did we stop because the user set the stop_on_solib_events
13571 variable? (If so, we report this as a generic, "Stopped due
13572 to shlib event" message.) */
13573 print_solib_event (0);
13576 case bp_thread_event:
13577 /* Not sure how we will get here.
13578 GDB should not stop for these breakpoints. */
13579 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13582 case bp_overlay_event:
13583 /* By analogy with the thread event, GDB should not stop for these. */
13584 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13587 case bp_longjmp_master:
13588 /* These should never be enabled. */
13589 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13592 case bp_std_terminate_master:
13593 /* These should never be enabled. */
13594 printf_filtered (_("std::terminate Master Breakpoint: "
13595 "gdb should not stop!\n"));
13598 case bp_exception_master:
13599 /* These should never be enabled. */
13600 printf_filtered (_("Exception Master Breakpoint: "
13601 "gdb should not stop!\n"));
13605 return PRINT_NOTHING;
13609 internal_bkpt_print_mention (struct breakpoint *b)
13611 /* Nothing to mention. These breakpoints are internal. */
13614 /* Virtual table for momentary breakpoints */
13617 momentary_bkpt_re_set (struct breakpoint *b)
13619 /* Keep temporary breakpoints, which can be encountered when we step
13620 over a dlopen call and solib_add is resetting the breakpoints.
13621 Otherwise these should have been blown away via the cleanup chain
13622 or by breakpoint_init_inferior when we rerun the executable. */
13626 momentary_bkpt_check_status (bpstat bs)
13628 /* Nothing. The point of these breakpoints is causing a stop. */
13631 static enum print_stop_action
13632 momentary_bkpt_print_it (bpstat bs)
13634 struct ui_out *uiout = current_uiout;
13636 if (ui_out_is_mi_like_p (uiout))
13638 struct breakpoint *b = bs->breakpoint_at;
13643 ui_out_field_string
13645 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13649 ui_out_field_string
13651 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13656 return PRINT_UNKNOWN;
13660 momentary_bkpt_print_mention (struct breakpoint *b)
13662 /* Nothing to mention. These breakpoints are internal. */
13665 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13667 It gets cleared already on the removal of the first one of such placed
13668 breakpoints. This is OK as they get all removed altogether. */
13671 longjmp_bkpt_dtor (struct breakpoint *self)
13673 struct thread_info *tp = find_thread_id (self->thread);
13676 tp->initiating_frame = null_frame_id;
13678 momentary_breakpoint_ops.dtor (self);
13681 /* Specific methods for probe breakpoints. */
13684 bkpt_probe_insert_location (struct bp_location *bl)
13686 int v = bkpt_insert_location (bl);
13690 /* The insertion was successful, now let's set the probe's semaphore
13692 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13701 bkpt_probe_remove_location (struct bp_location *bl)
13703 /* Let's clear the semaphore before removing the location. */
13704 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13708 return bkpt_remove_location (bl);
13712 bkpt_probe_create_sals_from_address (char **arg,
13713 struct linespec_result *canonical,
13714 enum bptype type_wanted,
13715 char *addr_start, char **copy_arg)
13717 struct linespec_sals lsal;
13719 lsal.sals = parse_probes (arg, canonical);
13721 *copy_arg = xstrdup (canonical->addr_string);
13722 lsal.canonical = xstrdup (*copy_arg);
13724 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13728 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13729 struct symtabs_and_lines *sals)
13731 *sals = parse_probes (s, NULL);
13733 error (_("probe not found"));
13736 /* The breakpoint_ops structure to be used in tracepoints. */
13739 tracepoint_re_set (struct breakpoint *b)
13741 breakpoint_re_set_default (b);
13745 tracepoint_breakpoint_hit (const struct bp_location *bl,
13746 struct address_space *aspace, CORE_ADDR bp_addr,
13747 const struct target_waitstatus *ws)
13749 /* By definition, the inferior does not report stops at
13755 tracepoint_print_one_detail (const struct breakpoint *self,
13756 struct ui_out *uiout)
13758 struct tracepoint *tp = (struct tracepoint *) self;
13759 if (tp->static_trace_marker_id)
13761 gdb_assert (self->type == bp_static_tracepoint);
13763 ui_out_text (uiout, "\tmarker id is ");
13764 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13765 tp->static_trace_marker_id);
13766 ui_out_text (uiout, "\n");
13771 tracepoint_print_mention (struct breakpoint *b)
13773 if (ui_out_is_mi_like_p (current_uiout))
13778 case bp_tracepoint:
13779 printf_filtered (_("Tracepoint"));
13780 printf_filtered (_(" %d"), b->number);
13782 case bp_fast_tracepoint:
13783 printf_filtered (_("Fast tracepoint"));
13784 printf_filtered (_(" %d"), b->number);
13786 case bp_static_tracepoint:
13787 printf_filtered (_("Static tracepoint"));
13788 printf_filtered (_(" %d"), b->number);
13791 internal_error (__FILE__, __LINE__,
13792 _("unhandled tracepoint type %d"), (int) b->type);
13799 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13801 struct tracepoint *tp = (struct tracepoint *) self;
13803 if (self->type == bp_fast_tracepoint)
13804 fprintf_unfiltered (fp, "ftrace");
13805 if (self->type == bp_static_tracepoint)
13806 fprintf_unfiltered (fp, "strace");
13807 else if (self->type == bp_tracepoint)
13808 fprintf_unfiltered (fp, "trace");
13810 internal_error (__FILE__, __LINE__,
13811 _("unhandled tracepoint type %d"), (int) self->type);
13813 fprintf_unfiltered (fp, " %s", self->addr_string);
13814 print_recreate_thread (self, fp);
13816 if (tp->pass_count)
13817 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13821 tracepoint_create_sals_from_address (char **arg,
13822 struct linespec_result *canonical,
13823 enum bptype type_wanted,
13824 char *addr_start, char **copy_arg)
13826 create_sals_from_address_default (arg, canonical, type_wanted,
13827 addr_start, copy_arg);
13831 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13832 struct linespec_result *canonical,
13834 char *extra_string,
13835 enum bptype type_wanted,
13836 enum bpdisp disposition,
13838 int task, int ignore_count,
13839 const struct breakpoint_ops *ops,
13840 int from_tty, int enabled,
13841 int internal, unsigned flags)
13843 create_breakpoints_sal_default (gdbarch, canonical,
13844 cond_string, extra_string,
13846 disposition, thread, task,
13847 ignore_count, ops, from_tty,
13848 enabled, internal, flags);
13852 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13853 struct symtabs_and_lines *sals)
13855 decode_linespec_default (b, s, sals);
13858 struct breakpoint_ops tracepoint_breakpoint_ops;
13860 /* The breakpoint_ops structure to be use on tracepoints placed in a
13864 tracepoint_probe_create_sals_from_address (char **arg,
13865 struct linespec_result *canonical,
13866 enum bptype type_wanted,
13867 char *addr_start, char **copy_arg)
13869 /* We use the same method for breakpoint on probes. */
13870 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13871 addr_start, copy_arg);
13875 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13876 struct symtabs_and_lines *sals)
13878 /* We use the same method for breakpoint on probes. */
13879 bkpt_probe_decode_linespec (b, s, sals);
13882 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13884 /* Dprintf breakpoint_ops methods. */
13887 dprintf_re_set (struct breakpoint *b)
13889 breakpoint_re_set_default (b);
13891 /* This breakpoint could have been pending, and be resolved now, and
13892 if so, we should now have the extra string. If we don't, the
13893 dprintf was malformed when created, but we couldn't tell because
13894 we can't extract the extra string until the location is
13896 if (b->loc != NULL && b->extra_string == NULL)
13897 error (_("Format string required"));
13899 /* 1 - connect to target 1, that can run breakpoint commands.
13900 2 - create a dprintf, which resolves fine.
13901 3 - disconnect from target 1
13902 4 - connect to target 2, that can NOT run breakpoint commands.
13904 After steps #3/#4, you'll want the dprintf command list to
13905 be updated, because target 1 and 2 may well return different
13906 answers for target_can_run_breakpoint_commands().
13907 Given absence of finer grained resetting, we get to do
13908 it all the time. */
13909 if (b->extra_string != NULL)
13910 update_dprintf_command_list (b);
13913 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13916 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13918 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13920 print_recreate_thread (tp, fp);
13923 /* Implement the "after_condition_true" breakpoint_ops method for
13926 dprintf's are implemented with regular commands in their command
13927 list, but we run the commands here instead of before presenting the
13928 stop to the user, as dprintf's don't actually cause a stop. This
13929 also makes it so that the commands of multiple dprintfs at the same
13930 address are all handled. */
13933 dprintf_after_condition_true (struct bpstats *bs)
13935 struct cleanup *old_chain;
13936 struct bpstats tmp_bs = { NULL };
13937 struct bpstats *tmp_bs_p = &tmp_bs;
13939 /* dprintf's never cause a stop. This wasn't set in the
13940 check_status hook instead because that would make the dprintf's
13941 condition not be evaluated. */
13944 /* Run the command list here. Take ownership of it instead of
13945 copying. We never want these commands to run later in
13946 bpstat_do_actions, if a breakpoint that causes a stop happens to
13947 be set at same address as this dprintf, or even if running the
13948 commands here throws. */
13949 tmp_bs.commands = bs->commands;
13950 bs->commands = NULL;
13951 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13953 bpstat_do_actions_1 (&tmp_bs_p);
13955 /* 'tmp_bs.commands' will usually be NULL by now, but
13956 bpstat_do_actions_1 may return early without processing the whole
13958 do_cleanups (old_chain);
13961 /* The breakpoint_ops structure to be used on static tracepoints with
13965 strace_marker_create_sals_from_address (char **arg,
13966 struct linespec_result *canonical,
13967 enum bptype type_wanted,
13968 char *addr_start, char **copy_arg)
13970 struct linespec_sals lsal;
13972 lsal.sals = decode_static_tracepoint_spec (arg);
13974 *copy_arg = savestring (addr_start, *arg - addr_start);
13976 canonical->addr_string = xstrdup (*copy_arg);
13977 lsal.canonical = xstrdup (*copy_arg);
13978 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13982 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13983 struct linespec_result *canonical,
13985 char *extra_string,
13986 enum bptype type_wanted,
13987 enum bpdisp disposition,
13989 int task, int ignore_count,
13990 const struct breakpoint_ops *ops,
13991 int from_tty, int enabled,
13992 int internal, unsigned flags)
13995 struct linespec_sals *lsal = VEC_index (linespec_sals,
13996 canonical->sals, 0);
13998 /* If the user is creating a static tracepoint by marker id
13999 (strace -m MARKER_ID), then store the sals index, so that
14000 breakpoint_re_set can try to match up which of the newly
14001 found markers corresponds to this one, and, don't try to
14002 expand multiple locations for each sal, given than SALS
14003 already should contain all sals for MARKER_ID. */
14005 for (i = 0; i < lsal->sals.nelts; ++i)
14007 struct symtabs_and_lines expanded;
14008 struct tracepoint *tp;
14009 struct cleanup *old_chain;
14012 expanded.nelts = 1;
14013 expanded.sals = &lsal->sals.sals[i];
14015 addr_string = xstrdup (canonical->addr_string);
14016 old_chain = make_cleanup (xfree, addr_string);
14018 tp = XCNEW (struct tracepoint);
14019 init_breakpoint_sal (&tp->base, gdbarch, expanded,
14021 cond_string, extra_string,
14022 type_wanted, disposition,
14023 thread, task, ignore_count, ops,
14024 from_tty, enabled, internal, flags,
14025 canonical->special_display);
14026 /* Given that its possible to have multiple markers with
14027 the same string id, if the user is creating a static
14028 tracepoint by marker id ("strace -m MARKER_ID"), then
14029 store the sals index, so that breakpoint_re_set can
14030 try to match up which of the newly found markers
14031 corresponds to this one */
14032 tp->static_trace_marker_id_idx = i;
14034 install_breakpoint (internal, &tp->base, 0);
14036 discard_cleanups (old_chain);
14041 strace_marker_decode_linespec (struct breakpoint *b, char **s,
14042 struct symtabs_and_lines *sals)
14044 struct tracepoint *tp = (struct tracepoint *) b;
14046 *sals = decode_static_tracepoint_spec (s);
14047 if (sals->nelts > tp->static_trace_marker_id_idx)
14049 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
14053 error (_("marker %s not found"), tp->static_trace_marker_id);
14056 static struct breakpoint_ops strace_marker_breakpoint_ops;
14059 strace_marker_p (struct breakpoint *b)
14061 return b->ops == &strace_marker_breakpoint_ops;
14064 /* Delete a breakpoint and clean up all traces of it in the data
14068 delete_breakpoint (struct breakpoint *bpt)
14070 struct breakpoint *b;
14072 gdb_assert (bpt != NULL);
14074 /* Has this bp already been deleted? This can happen because
14075 multiple lists can hold pointers to bp's. bpstat lists are
14078 One example of this happening is a watchpoint's scope bp. When
14079 the scope bp triggers, we notice that the watchpoint is out of
14080 scope, and delete it. We also delete its scope bp. But the
14081 scope bp is marked "auto-deleting", and is already on a bpstat.
14082 That bpstat is then checked for auto-deleting bp's, which are
14085 A real solution to this problem might involve reference counts in
14086 bp's, and/or giving them pointers back to their referencing
14087 bpstat's, and teaching delete_breakpoint to only free a bp's
14088 storage when no more references were extent. A cheaper bandaid
14090 if (bpt->type == bp_none)
14093 /* At least avoid this stale reference until the reference counting
14094 of breakpoints gets resolved. */
14095 if (bpt->related_breakpoint != bpt)
14097 struct breakpoint *related;
14098 struct watchpoint *w;
14100 if (bpt->type == bp_watchpoint_scope)
14101 w = (struct watchpoint *) bpt->related_breakpoint;
14102 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
14103 w = (struct watchpoint *) bpt;
14107 watchpoint_del_at_next_stop (w);
14109 /* Unlink bpt from the bpt->related_breakpoint ring. */
14110 for (related = bpt; related->related_breakpoint != bpt;
14111 related = related->related_breakpoint);
14112 related->related_breakpoint = bpt->related_breakpoint;
14113 bpt->related_breakpoint = bpt;
14116 /* watch_command_1 creates a watchpoint but only sets its number if
14117 update_watchpoint succeeds in creating its bp_locations. If there's
14118 a problem in that process, we'll be asked to delete the half-created
14119 watchpoint. In that case, don't announce the deletion. */
14121 observer_notify_breakpoint_deleted (bpt);
14123 if (breakpoint_chain == bpt)
14124 breakpoint_chain = bpt->next;
14126 ALL_BREAKPOINTS (b)
14127 if (b->next == bpt)
14129 b->next = bpt->next;
14133 /* Be sure no bpstat's are pointing at the breakpoint after it's
14135 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14136 in all threads for now. Note that we cannot just remove bpstats
14137 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14138 commands are associated with the bpstat; if we remove it here,
14139 then the later call to bpstat_do_actions (&stop_bpstat); in
14140 event-top.c won't do anything, and temporary breakpoints with
14141 commands won't work. */
14143 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
14145 /* Now that breakpoint is removed from breakpoint list, update the
14146 global location list. This will remove locations that used to
14147 belong to this breakpoint. Do this before freeing the breakpoint
14148 itself, since remove_breakpoint looks at location's owner. It
14149 might be better design to have location completely
14150 self-contained, but it's not the case now. */
14151 update_global_location_list (UGLL_DONT_INSERT);
14153 bpt->ops->dtor (bpt);
14154 /* On the chance that someone will soon try again to delete this
14155 same bp, we mark it as deleted before freeing its storage. */
14156 bpt->type = bp_none;
14161 do_delete_breakpoint_cleanup (void *b)
14163 delete_breakpoint (b);
14167 make_cleanup_delete_breakpoint (struct breakpoint *b)
14169 return make_cleanup (do_delete_breakpoint_cleanup, b);
14172 /* Iterator function to call a user-provided callback function once
14173 for each of B and its related breakpoints. */
14176 iterate_over_related_breakpoints (struct breakpoint *b,
14177 void (*function) (struct breakpoint *,
14181 struct breakpoint *related;
14186 struct breakpoint *next;
14188 /* FUNCTION may delete RELATED. */
14189 next = related->related_breakpoint;
14191 if (next == related)
14193 /* RELATED is the last ring entry. */
14194 function (related, data);
14196 /* FUNCTION may have deleted it, so we'd never reach back to
14197 B. There's nothing left to do anyway, so just break
14202 function (related, data);
14206 while (related != b);
14210 do_delete_breakpoint (struct breakpoint *b, void *ignore)
14212 delete_breakpoint (b);
14215 /* A callback for map_breakpoint_numbers that calls
14216 delete_breakpoint. */
14219 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
14221 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
14225 delete_command (char *arg, int from_tty)
14227 struct breakpoint *b, *b_tmp;
14233 int breaks_to_delete = 0;
14235 /* Delete all breakpoints if no argument. Do not delete
14236 internal breakpoints, these have to be deleted with an
14237 explicit breakpoint number argument. */
14238 ALL_BREAKPOINTS (b)
14239 if (user_breakpoint_p (b))
14241 breaks_to_delete = 1;
14245 /* Ask user only if there are some breakpoints to delete. */
14247 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
14249 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14250 if (user_breakpoint_p (b))
14251 delete_breakpoint (b);
14255 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14259 all_locations_are_pending (struct bp_location *loc)
14261 for (; loc; loc = loc->next)
14262 if (!loc->shlib_disabled
14263 && !loc->pspace->executing_startup)
14268 /* Subroutine of update_breakpoint_locations to simplify it.
14269 Return non-zero if multiple fns in list LOC have the same name.
14270 Null names are ignored. */
14273 ambiguous_names_p (struct bp_location *loc)
14275 struct bp_location *l;
14276 htab_t htab = htab_create_alloc (13, htab_hash_string,
14277 (int (*) (const void *,
14278 const void *)) streq,
14279 NULL, xcalloc, xfree);
14281 for (l = loc; l != NULL; l = l->next)
14284 const char *name = l->function_name;
14286 /* Allow for some names to be NULL, ignore them. */
14290 slot = (const char **) htab_find_slot (htab, (const void *) name,
14292 /* NOTE: We can assume slot != NULL here because xcalloc never
14296 htab_delete (htab);
14302 htab_delete (htab);
14306 /* When symbols change, it probably means the sources changed as well,
14307 and it might mean the static tracepoint markers are no longer at
14308 the same address or line numbers they used to be at last we
14309 checked. Losing your static tracepoints whenever you rebuild is
14310 undesirable. This function tries to resync/rematch gdb static
14311 tracepoints with the markers on the target, for static tracepoints
14312 that have not been set by marker id. Static tracepoint that have
14313 been set by marker id are reset by marker id in breakpoint_re_set.
14316 1) For a tracepoint set at a specific address, look for a marker at
14317 the old PC. If one is found there, assume to be the same marker.
14318 If the name / string id of the marker found is different from the
14319 previous known name, assume that means the user renamed the marker
14320 in the sources, and output a warning.
14322 2) For a tracepoint set at a given line number, look for a marker
14323 at the new address of the old line number. If one is found there,
14324 assume to be the same marker. If the name / string id of the
14325 marker found is different from the previous known name, assume that
14326 means the user renamed the marker in the sources, and output a
14329 3) If a marker is no longer found at the same address or line, it
14330 may mean the marker no longer exists. But it may also just mean
14331 the code changed a bit. Maybe the user added a few lines of code
14332 that made the marker move up or down (in line number terms). Ask
14333 the target for info about the marker with the string id as we knew
14334 it. If found, update line number and address in the matching
14335 static tracepoint. This will get confused if there's more than one
14336 marker with the same ID (possible in UST, although unadvised
14337 precisely because it confuses tools). */
14339 static struct symtab_and_line
14340 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14342 struct tracepoint *tp = (struct tracepoint *) b;
14343 struct static_tracepoint_marker marker;
14348 find_line_pc (sal.symtab, sal.line, &pc);
14350 if (target_static_tracepoint_marker_at (pc, &marker))
14352 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14353 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14355 tp->static_trace_marker_id, marker.str_id);
14357 xfree (tp->static_trace_marker_id);
14358 tp->static_trace_marker_id = xstrdup (marker.str_id);
14359 release_static_tracepoint_marker (&marker);
14364 /* Old marker wasn't found on target at lineno. Try looking it up
14366 if (!sal.explicit_pc
14368 && sal.symtab != NULL
14369 && tp->static_trace_marker_id != NULL)
14371 VEC(static_tracepoint_marker_p) *markers;
14374 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14376 if (!VEC_empty(static_tracepoint_marker_p, markers))
14378 struct symtab_and_line sal2;
14379 struct symbol *sym;
14380 struct static_tracepoint_marker *tpmarker;
14381 struct ui_out *uiout = current_uiout;
14383 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14385 xfree (tp->static_trace_marker_id);
14386 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14388 warning (_("marker for static tracepoint %d (%s) not "
14389 "found at previous line number"),
14390 b->number, tp->static_trace_marker_id);
14394 sal2.pc = tpmarker->address;
14396 sal2 = find_pc_line (tpmarker->address, 0);
14397 sym = find_pc_sect_function (tpmarker->address, NULL);
14398 ui_out_text (uiout, "Now in ");
14401 ui_out_field_string (uiout, "func",
14402 SYMBOL_PRINT_NAME (sym));
14403 ui_out_text (uiout, " at ");
14405 ui_out_field_string (uiout, "file",
14406 symtab_to_filename_for_display (sal2.symtab));
14407 ui_out_text (uiout, ":");
14409 if (ui_out_is_mi_like_p (uiout))
14411 const char *fullname = symtab_to_fullname (sal2.symtab);
14413 ui_out_field_string (uiout, "fullname", fullname);
14416 ui_out_field_int (uiout, "line", sal2.line);
14417 ui_out_text (uiout, "\n");
14419 b->loc->line_number = sal2.line;
14420 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14422 xfree (b->addr_string);
14423 b->addr_string = xstrprintf ("%s:%d",
14424 symtab_to_filename_for_display (sal2.symtab),
14425 b->loc->line_number);
14427 /* Might be nice to check if function changed, and warn if
14430 release_static_tracepoint_marker (tpmarker);
14436 /* Returns 1 iff locations A and B are sufficiently same that
14437 we don't need to report breakpoint as changed. */
14440 locations_are_equal (struct bp_location *a, struct bp_location *b)
14444 if (a->address != b->address)
14447 if (a->shlib_disabled != b->shlib_disabled)
14450 if (a->enabled != b->enabled)
14457 if ((a == NULL) != (b == NULL))
14463 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14464 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14465 a ranged breakpoint. */
14468 update_breakpoint_locations (struct breakpoint *b,
14469 struct symtabs_and_lines sals,
14470 struct symtabs_and_lines sals_end)
14473 struct bp_location *existing_locations = b->loc;
14475 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14477 /* Ranged breakpoints have only one start location and one end
14479 b->enable_state = bp_disabled;
14480 update_global_location_list (UGLL_MAY_INSERT);
14481 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14482 "multiple locations found\n"),
14487 /* If there's no new locations, and all existing locations are
14488 pending, don't do anything. This optimizes the common case where
14489 all locations are in the same shared library, that was unloaded.
14490 We'd like to retain the location, so that when the library is
14491 loaded again, we don't loose the enabled/disabled status of the
14492 individual locations. */
14493 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14498 for (i = 0; i < sals.nelts; ++i)
14500 struct bp_location *new_loc;
14502 switch_to_program_space_and_thread (sals.sals[i].pspace);
14504 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14506 /* Reparse conditions, they might contain references to the
14508 if (b->cond_string != NULL)
14511 volatile struct gdb_exception e;
14513 s = b->cond_string;
14514 TRY_CATCH (e, RETURN_MASK_ERROR)
14516 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14517 block_for_pc (sals.sals[i].pc),
14522 warning (_("failed to reevaluate condition "
14523 "for breakpoint %d: %s"),
14524 b->number, e.message);
14525 new_loc->enabled = 0;
14529 if (sals_end.nelts)
14531 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14533 new_loc->length = end - sals.sals[0].pc + 1;
14537 /* Update locations of permanent breakpoints. */
14538 if (b->enable_state == bp_permanent)
14539 make_breakpoint_permanent (b);
14541 /* If possible, carry over 'disable' status from existing
14544 struct bp_location *e = existing_locations;
14545 /* If there are multiple breakpoints with the same function name,
14546 e.g. for inline functions, comparing function names won't work.
14547 Instead compare pc addresses; this is just a heuristic as things
14548 may have moved, but in practice it gives the correct answer
14549 often enough until a better solution is found. */
14550 int have_ambiguous_names = ambiguous_names_p (b->loc);
14552 for (; e; e = e->next)
14554 if (!e->enabled && e->function_name)
14556 struct bp_location *l = b->loc;
14557 if (have_ambiguous_names)
14559 for (; l; l = l->next)
14560 if (breakpoint_locations_match (e, l))
14568 for (; l; l = l->next)
14569 if (l->function_name
14570 && strcmp (e->function_name, l->function_name) == 0)
14580 if (!locations_are_equal (existing_locations, b->loc))
14581 observer_notify_breakpoint_modified (b);
14583 update_global_location_list (UGLL_MAY_INSERT);
14586 /* Find the SaL locations corresponding to the given ADDR_STRING.
14587 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14589 static struct symtabs_and_lines
14590 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14593 struct symtabs_and_lines sals = {0};
14594 volatile struct gdb_exception e;
14596 gdb_assert (b->ops != NULL);
14599 TRY_CATCH (e, RETURN_MASK_ERROR)
14601 b->ops->decode_linespec (b, &s, &sals);
14605 int not_found_and_ok = 0;
14606 /* For pending breakpoints, it's expected that parsing will
14607 fail until the right shared library is loaded. User has
14608 already told to create pending breakpoints and don't need
14609 extra messages. If breakpoint is in bp_shlib_disabled
14610 state, then user already saw the message about that
14611 breakpoint being disabled, and don't want to see more
14613 if (e.error == NOT_FOUND_ERROR
14614 && (b->condition_not_parsed
14615 || (b->loc && b->loc->shlib_disabled)
14616 || (b->loc && b->loc->pspace->executing_startup)
14617 || b->enable_state == bp_disabled))
14618 not_found_and_ok = 1;
14620 if (!not_found_and_ok)
14622 /* We surely don't want to warn about the same breakpoint
14623 10 times. One solution, implemented here, is disable
14624 the breakpoint on error. Another solution would be to
14625 have separate 'warning emitted' flag. Since this
14626 happens only when a binary has changed, I don't know
14627 which approach is better. */
14628 b->enable_state = bp_disabled;
14629 throw_exception (e);
14633 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14637 for (i = 0; i < sals.nelts; ++i)
14638 resolve_sal_pc (&sals.sals[i]);
14639 if (b->condition_not_parsed && s && s[0])
14641 char *cond_string, *extra_string;
14644 find_condition_and_thread (s, sals.sals[0].pc,
14645 &cond_string, &thread, &task,
14648 b->cond_string = cond_string;
14649 b->thread = thread;
14652 b->extra_string = extra_string;
14653 b->condition_not_parsed = 0;
14656 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14657 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14667 /* The default re_set method, for typical hardware or software
14668 breakpoints. Reevaluate the breakpoint and recreate its
14672 breakpoint_re_set_default (struct breakpoint *b)
14675 struct symtabs_and_lines sals, sals_end;
14676 struct symtabs_and_lines expanded = {0};
14677 struct symtabs_and_lines expanded_end = {0};
14679 sals = addr_string_to_sals (b, b->addr_string, &found);
14682 make_cleanup (xfree, sals.sals);
14686 if (b->addr_string_range_end)
14688 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14691 make_cleanup (xfree, sals_end.sals);
14692 expanded_end = sals_end;
14696 update_breakpoint_locations (b, expanded, expanded_end);
14699 /* Default method for creating SALs from an address string. It basically
14700 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14703 create_sals_from_address_default (char **arg,
14704 struct linespec_result *canonical,
14705 enum bptype type_wanted,
14706 char *addr_start, char **copy_arg)
14708 parse_breakpoint_sals (arg, canonical);
14711 /* Call create_breakpoints_sal for the given arguments. This is the default
14712 function for the `create_breakpoints_sal' method of
14716 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14717 struct linespec_result *canonical,
14719 char *extra_string,
14720 enum bptype type_wanted,
14721 enum bpdisp disposition,
14723 int task, int ignore_count,
14724 const struct breakpoint_ops *ops,
14725 int from_tty, int enabled,
14726 int internal, unsigned flags)
14728 create_breakpoints_sal (gdbarch, canonical, cond_string,
14730 type_wanted, disposition,
14731 thread, task, ignore_count, ops, from_tty,
14732 enabled, internal, flags);
14735 /* Decode the line represented by S by calling decode_line_full. This is the
14736 default function for the `decode_linespec' method of breakpoint_ops. */
14739 decode_linespec_default (struct breakpoint *b, char **s,
14740 struct symtabs_and_lines *sals)
14742 struct linespec_result canonical;
14744 init_linespec_result (&canonical);
14745 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14746 (struct symtab *) NULL, 0,
14747 &canonical, multiple_symbols_all,
14750 /* We should get 0 or 1 resulting SALs. */
14751 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14753 if (VEC_length (linespec_sals, canonical.sals) > 0)
14755 struct linespec_sals *lsal;
14757 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14758 *sals = lsal->sals;
14759 /* Arrange it so the destructor does not free the
14761 lsal->sals.sals = NULL;
14764 destroy_linespec_result (&canonical);
14767 /* Prepare the global context for a re-set of breakpoint B. */
14769 static struct cleanup *
14770 prepare_re_set_context (struct breakpoint *b)
14772 struct cleanup *cleanups;
14774 input_radix = b->input_radix;
14775 cleanups = save_current_space_and_thread ();
14776 if (b->pspace != NULL)
14777 switch_to_program_space_and_thread (b->pspace);
14778 set_language (b->language);
14783 /* Reset a breakpoint given it's struct breakpoint * BINT.
14784 The value we return ends up being the return value from catch_errors.
14785 Unused in this case. */
14788 breakpoint_re_set_one (void *bint)
14790 /* Get past catch_errs. */
14791 struct breakpoint *b = (struct breakpoint *) bint;
14792 struct cleanup *cleanups;
14794 cleanups = prepare_re_set_context (b);
14795 b->ops->re_set (b);
14796 do_cleanups (cleanups);
14800 /* Re-set all breakpoints after symbols have been re-loaded. */
14802 breakpoint_re_set (void)
14804 struct breakpoint *b, *b_tmp;
14805 enum language save_language;
14806 int save_input_radix;
14807 struct cleanup *old_chain;
14809 save_language = current_language->la_language;
14810 save_input_radix = input_radix;
14811 old_chain = save_current_program_space ();
14813 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14815 /* Format possible error msg. */
14816 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14818 struct cleanup *cleanups = make_cleanup (xfree, message);
14819 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14820 do_cleanups (cleanups);
14822 set_language (save_language);
14823 input_radix = save_input_radix;
14825 jit_breakpoint_re_set ();
14827 do_cleanups (old_chain);
14829 create_overlay_event_breakpoint ();
14830 create_longjmp_master_breakpoint ();
14831 create_std_terminate_master_breakpoint ();
14832 create_exception_master_breakpoint ();
14835 /* Reset the thread number of this breakpoint:
14837 - If the breakpoint is for all threads, leave it as-is.
14838 - Else, reset it to the current thread for inferior_ptid. */
14840 breakpoint_re_set_thread (struct breakpoint *b)
14842 if (b->thread != -1)
14844 if (in_thread_list (inferior_ptid))
14845 b->thread = pid_to_thread_id (inferior_ptid);
14847 /* We're being called after following a fork. The new fork is
14848 selected as current, and unless this was a vfork will have a
14849 different program space from the original thread. Reset that
14851 b->loc->pspace = current_program_space;
14855 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14856 If from_tty is nonzero, it prints a message to that effect,
14857 which ends with a period (no newline). */
14860 set_ignore_count (int bptnum, int count, int from_tty)
14862 struct breakpoint *b;
14867 ALL_BREAKPOINTS (b)
14868 if (b->number == bptnum)
14870 if (is_tracepoint (b))
14872 if (from_tty && count != 0)
14873 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14878 b->ignore_count = count;
14882 printf_filtered (_("Will stop next time "
14883 "breakpoint %d is reached."),
14885 else if (count == 1)
14886 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14889 printf_filtered (_("Will ignore next %d "
14890 "crossings of breakpoint %d."),
14893 observer_notify_breakpoint_modified (b);
14897 error (_("No breakpoint number %d."), bptnum);
14900 /* Command to set ignore-count of breakpoint N to COUNT. */
14903 ignore_command (char *args, int from_tty)
14909 error_no_arg (_("a breakpoint number"));
14911 num = get_number (&p);
14913 error (_("bad breakpoint number: '%s'"), args);
14915 error (_("Second argument (specified ignore-count) is missing."));
14917 set_ignore_count (num,
14918 longest_to_int (value_as_long (parse_and_eval (p))),
14921 printf_filtered ("\n");
14924 /* Call FUNCTION on each of the breakpoints
14925 whose numbers are given in ARGS. */
14928 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14933 struct breakpoint *b, *tmp;
14935 struct get_number_or_range_state state;
14938 error_no_arg (_("one or more breakpoint numbers"));
14940 init_number_or_range (&state, args);
14942 while (!state.finished)
14944 const char *p = state.string;
14948 num = get_number_or_range (&state);
14951 warning (_("bad breakpoint number at or near '%s'"), p);
14955 ALL_BREAKPOINTS_SAFE (b, tmp)
14956 if (b->number == num)
14959 function (b, data);
14963 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14968 static struct bp_location *
14969 find_location_by_number (char *number)
14971 char *dot = strchr (number, '.');
14975 struct breakpoint *b;
14976 struct bp_location *loc;
14981 bp_num = get_number (&p1);
14983 error (_("Bad breakpoint number '%s'"), number);
14985 ALL_BREAKPOINTS (b)
14986 if (b->number == bp_num)
14991 if (!b || b->number != bp_num)
14992 error (_("Bad breakpoint number '%s'"), number);
14995 loc_num = get_number (&p1);
14997 error (_("Bad breakpoint location number '%s'"), number);
15001 for (;loc_num && loc; --loc_num, loc = loc->next)
15004 error (_("Bad breakpoint location number '%s'"), dot+1);
15010 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
15011 If from_tty is nonzero, it prints a message to that effect,
15012 which ends with a period (no newline). */
15015 disable_breakpoint (struct breakpoint *bpt)
15017 /* Never disable a watchpoint scope breakpoint; we want to
15018 hit them when we leave scope so we can delete both the
15019 watchpoint and its scope breakpoint at that time. */
15020 if (bpt->type == bp_watchpoint_scope)
15023 /* You can't disable permanent breakpoints. */
15024 if (bpt->enable_state == bp_permanent)
15027 bpt->enable_state = bp_disabled;
15029 /* Mark breakpoint locations modified. */
15030 mark_breakpoint_modified (bpt);
15032 if (target_supports_enable_disable_tracepoint ()
15033 && current_trace_status ()->running && is_tracepoint (bpt))
15035 struct bp_location *location;
15037 for (location = bpt->loc; location; location = location->next)
15038 target_disable_tracepoint (location);
15041 update_global_location_list (UGLL_DONT_INSERT);
15043 observer_notify_breakpoint_modified (bpt);
15046 /* A callback for iterate_over_related_breakpoints. */
15049 do_disable_breakpoint (struct breakpoint *b, void *ignore)
15051 disable_breakpoint (b);
15054 /* A callback for map_breakpoint_numbers that calls
15055 disable_breakpoint. */
15058 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
15060 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
15064 disable_command (char *args, int from_tty)
15068 struct breakpoint *bpt;
15070 ALL_BREAKPOINTS (bpt)
15071 if (user_breakpoint_p (bpt))
15072 disable_breakpoint (bpt);
15076 char *num = extract_arg (&args);
15080 if (strchr (num, '.'))
15082 struct bp_location *loc = find_location_by_number (num);
15089 mark_breakpoint_location_modified (loc);
15091 if (target_supports_enable_disable_tracepoint ()
15092 && current_trace_status ()->running && loc->owner
15093 && is_tracepoint (loc->owner))
15094 target_disable_tracepoint (loc);
15096 update_global_location_list (UGLL_DONT_INSERT);
15099 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
15100 num = extract_arg (&args);
15106 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
15109 int target_resources_ok;
15111 if (bpt->type == bp_hardware_breakpoint)
15114 i = hw_breakpoint_used_count ();
15115 target_resources_ok =
15116 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
15118 if (target_resources_ok == 0)
15119 error (_("No hardware breakpoint support in the target."));
15120 else if (target_resources_ok < 0)
15121 error (_("Hardware breakpoints used exceeds limit."));
15124 if (is_watchpoint (bpt))
15126 /* Initialize it just to avoid a GCC false warning. */
15127 enum enable_state orig_enable_state = 0;
15128 volatile struct gdb_exception e;
15130 TRY_CATCH (e, RETURN_MASK_ALL)
15132 struct watchpoint *w = (struct watchpoint *) bpt;
15134 orig_enable_state = bpt->enable_state;
15135 bpt->enable_state = bp_enabled;
15136 update_watchpoint (w, 1 /* reparse */);
15140 bpt->enable_state = orig_enable_state;
15141 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
15147 if (bpt->enable_state != bp_permanent)
15148 bpt->enable_state = bp_enabled;
15150 bpt->enable_state = bp_enabled;
15152 /* Mark breakpoint locations modified. */
15153 mark_breakpoint_modified (bpt);
15155 if (target_supports_enable_disable_tracepoint ()
15156 && current_trace_status ()->running && is_tracepoint (bpt))
15158 struct bp_location *location;
15160 for (location = bpt->loc; location; location = location->next)
15161 target_enable_tracepoint (location);
15164 bpt->disposition = disposition;
15165 bpt->enable_count = count;
15166 update_global_location_list (UGLL_MAY_INSERT);
15168 observer_notify_breakpoint_modified (bpt);
15173 enable_breakpoint (struct breakpoint *bpt)
15175 enable_breakpoint_disp (bpt, bpt->disposition, 0);
15179 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
15181 enable_breakpoint (bpt);
15184 /* A callback for map_breakpoint_numbers that calls
15185 enable_breakpoint. */
15188 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
15190 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
15193 /* The enable command enables the specified breakpoints (or all defined
15194 breakpoints) so they once again become (or continue to be) effective
15195 in stopping the inferior. */
15198 enable_command (char *args, int from_tty)
15202 struct breakpoint *bpt;
15204 ALL_BREAKPOINTS (bpt)
15205 if (user_breakpoint_p (bpt))
15206 enable_breakpoint (bpt);
15210 char *num = extract_arg (&args);
15214 if (strchr (num, '.'))
15216 struct bp_location *loc = find_location_by_number (num);
15223 mark_breakpoint_location_modified (loc);
15225 if (target_supports_enable_disable_tracepoint ()
15226 && current_trace_status ()->running && loc->owner
15227 && is_tracepoint (loc->owner))
15228 target_enable_tracepoint (loc);
15230 update_global_location_list (UGLL_MAY_INSERT);
15233 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15234 num = extract_arg (&args);
15239 /* This struct packages up disposition data for application to multiple
15249 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15251 struct disp_data disp_data = *(struct disp_data *) arg;
15253 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15257 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15259 struct disp_data disp = { disp_disable, 1 };
15261 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15265 enable_once_command (char *args, int from_tty)
15267 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15271 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15273 struct disp_data disp = { disp_disable, *(int *) countptr };
15275 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15279 enable_count_command (char *args, int from_tty)
15281 int count = get_number (&args);
15283 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15287 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15289 struct disp_data disp = { disp_del, 1 };
15291 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15295 enable_delete_command (char *args, int from_tty)
15297 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15301 set_breakpoint_cmd (char *args, int from_tty)
15306 show_breakpoint_cmd (char *args, int from_tty)
15310 /* Invalidate last known value of any hardware watchpoint if
15311 the memory which that value represents has been written to by
15315 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15316 CORE_ADDR addr, ssize_t len,
15317 const bfd_byte *data)
15319 struct breakpoint *bp;
15321 ALL_BREAKPOINTS (bp)
15322 if (bp->enable_state == bp_enabled
15323 && bp->type == bp_hardware_watchpoint)
15325 struct watchpoint *wp = (struct watchpoint *) bp;
15327 if (wp->val_valid && wp->val)
15329 struct bp_location *loc;
15331 for (loc = bp->loc; loc != NULL; loc = loc->next)
15332 if (loc->loc_type == bp_loc_hardware_watchpoint
15333 && loc->address + loc->length > addr
15334 && addr + len > loc->address)
15336 value_free (wp->val);
15344 /* Create and insert a raw software breakpoint at PC. Return an
15345 identifier, which should be used to remove the breakpoint later.
15346 In general, places which call this should be using something on the
15347 breakpoint chain instead; this function should be eliminated
15351 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
15352 struct address_space *aspace, CORE_ADDR pc)
15354 struct bp_target_info *bp_tgt;
15355 struct bp_location *bl;
15357 bp_tgt = XCNEW (struct bp_target_info);
15359 bp_tgt->placed_address_space = aspace;
15360 bp_tgt->placed_address = pc;
15362 /* If an unconditional non-raw breakpoint is already inserted at
15363 that location, there's no need to insert another. However, with
15364 target-side evaluation of breakpoint conditions, if the
15365 breakpoint that is currently inserted on the target is
15366 conditional, we need to make it unconditional. Note that a
15367 breakpoint with target-side commands is not reported even if
15368 unconditional, so we need to remove the commands from the target
15370 bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc);
15372 && VEC_empty (agent_expr_p, bl->target_info.conditions)
15373 && VEC_empty (agent_expr_p, bl->target_info.tcommands))
15375 bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info);
15379 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
15381 /* Could not insert the breakpoint. */
15389 /* Remove a breakpoint BP inserted by
15390 deprecated_insert_raw_breakpoint. */
15393 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
15395 struct bp_target_info *bp_tgt = bp;
15396 struct address_space *aspace = bp_tgt->placed_address_space;
15397 CORE_ADDR address = bp_tgt->placed_address;
15398 struct bp_location *bl;
15401 bl = find_non_raw_software_breakpoint_inserted_here (aspace, address);
15403 /* Only remove the raw breakpoint if there are no other non-raw
15404 breakpoints still inserted at this location. Otherwise, we would
15405 be effectively disabling those breakpoints. */
15407 ret = target_remove_breakpoint (gdbarch, bp_tgt);
15408 else if (!VEC_empty (agent_expr_p, bl->target_info.conditions)
15409 || !VEC_empty (agent_expr_p, bl->target_info.tcommands))
15411 /* The target is evaluating conditions, and when we inserted the
15412 software single-step breakpoint, we had made the breakpoint
15413 unconditional and command-less on the target side. Reinsert
15414 to restore the conditions/commands. */
15415 ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
15425 /* Create and insert a breakpoint for software single step. */
15428 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15429 struct address_space *aspace,
15434 if (single_step_breakpoints[0] == NULL)
15436 bpt_p = &single_step_breakpoints[0];
15437 single_step_gdbarch[0] = gdbarch;
15441 gdb_assert (single_step_breakpoints[1] == NULL);
15442 bpt_p = &single_step_breakpoints[1];
15443 single_step_gdbarch[1] = gdbarch;
15446 /* NOTE drow/2006-04-11: A future improvement to this function would
15447 be to only create the breakpoints once, and actually put them on
15448 the breakpoint chain. That would let us use set_raw_breakpoint.
15449 We could adjust the addresses each time they were needed. Doing
15450 this requires corresponding changes elsewhere where single step
15451 breakpoints are handled, however. So, for now, we use this. */
15453 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
15454 if (*bpt_p == NULL)
15455 error (_("Could not insert single-step breakpoint at %s"),
15456 paddress (gdbarch, next_pc));
15459 /* Check if the breakpoints used for software single stepping
15460 were inserted or not. */
15463 single_step_breakpoints_inserted (void)
15465 return (single_step_breakpoints[0] != NULL
15466 || single_step_breakpoints[1] != NULL);
15469 /* Remove and delete any breakpoints used for software single step. */
15472 remove_single_step_breakpoints (void)
15474 gdb_assert (single_step_breakpoints[0] != NULL);
15476 /* See insert_single_step_breakpoint for more about this deprecated
15478 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
15479 single_step_breakpoints[0]);
15480 single_step_gdbarch[0] = NULL;
15481 single_step_breakpoints[0] = NULL;
15483 if (single_step_breakpoints[1] != NULL)
15485 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
15486 single_step_breakpoints[1]);
15487 single_step_gdbarch[1] = NULL;
15488 single_step_breakpoints[1] = NULL;
15492 /* Delete software single step breakpoints without removing them from
15493 the inferior. This is intended to be used if the inferior's address
15494 space where they were inserted is already gone, e.g. after exit or
15498 cancel_single_step_breakpoints (void)
15502 for (i = 0; i < 2; i++)
15503 if (single_step_breakpoints[i])
15505 xfree (single_step_breakpoints[i]);
15506 single_step_breakpoints[i] = NULL;
15507 single_step_gdbarch[i] = NULL;
15511 /* Detach software single-step breakpoints from INFERIOR_PTID without
15515 detach_single_step_breakpoints (void)
15519 for (i = 0; i < 2; i++)
15520 if (single_step_breakpoints[i])
15521 target_remove_breakpoint (single_step_gdbarch[i],
15522 single_step_breakpoints[i]);
15525 /* Find the software single-step breakpoint that inserted at PC.
15526 Returns its slot if found, and -1 if not found. */
15529 find_single_step_breakpoint (struct address_space *aspace,
15534 for (i = 0; i < 2; i++)
15536 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15538 && breakpoint_address_match (bp_tgt->placed_address_space,
15539 bp_tgt->placed_address,
15547 /* Check whether a software single-step breakpoint is inserted at
15551 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15554 return find_single_step_breakpoint (aspace, pc) >= 0;
15557 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15558 non-zero otherwise. */
15560 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15562 if (syscall_catchpoint_p (bp)
15563 && bp->enable_state != bp_disabled
15564 && bp->enable_state != bp_call_disabled)
15571 catch_syscall_enabled (void)
15573 struct catch_syscall_inferior_data *inf_data
15574 = get_catch_syscall_inferior_data (current_inferior ());
15576 return inf_data->total_syscalls_count != 0;
15580 catching_syscall_number (int syscall_number)
15582 struct breakpoint *bp;
15584 ALL_BREAKPOINTS (bp)
15585 if (is_syscall_catchpoint_enabled (bp))
15587 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15589 if (c->syscalls_to_be_caught)
15593 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15595 if (syscall_number == iter)
15605 /* Complete syscall names. Used by "catch syscall". */
15606 static VEC (char_ptr) *
15607 catch_syscall_completer (struct cmd_list_element *cmd,
15608 const char *text, const char *word)
15610 const char **list = get_syscall_names ();
15611 VEC (char_ptr) *retlist
15612 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15618 /* Tracepoint-specific operations. */
15620 /* Set tracepoint count to NUM. */
15622 set_tracepoint_count (int num)
15624 tracepoint_count = num;
15625 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15629 trace_command (char *arg, int from_tty)
15631 struct breakpoint_ops *ops;
15632 const char *arg_cp = arg;
15634 if (arg && probe_linespec_to_ops (&arg_cp))
15635 ops = &tracepoint_probe_breakpoint_ops;
15637 ops = &tracepoint_breakpoint_ops;
15639 create_breakpoint (get_current_arch (),
15641 NULL, 0, NULL, 1 /* parse arg */,
15643 bp_tracepoint /* type_wanted */,
15644 0 /* Ignore count */,
15645 pending_break_support,
15649 0 /* internal */, 0);
15653 ftrace_command (char *arg, int from_tty)
15655 create_breakpoint (get_current_arch (),
15657 NULL, 0, NULL, 1 /* parse arg */,
15659 bp_fast_tracepoint /* type_wanted */,
15660 0 /* Ignore count */,
15661 pending_break_support,
15662 &tracepoint_breakpoint_ops,
15665 0 /* internal */, 0);
15668 /* strace command implementation. Creates a static tracepoint. */
15671 strace_command (char *arg, int from_tty)
15673 struct breakpoint_ops *ops;
15675 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15676 or with a normal static tracepoint. */
15677 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15678 ops = &strace_marker_breakpoint_ops;
15680 ops = &tracepoint_breakpoint_ops;
15682 create_breakpoint (get_current_arch (),
15684 NULL, 0, NULL, 1 /* parse arg */,
15686 bp_static_tracepoint /* type_wanted */,
15687 0 /* Ignore count */,
15688 pending_break_support,
15692 0 /* internal */, 0);
15695 /* Set up a fake reader function that gets command lines from a linked
15696 list that was acquired during tracepoint uploading. */
15698 static struct uploaded_tp *this_utp;
15699 static int next_cmd;
15702 read_uploaded_action (void)
15706 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15713 /* Given information about a tracepoint as recorded on a target (which
15714 can be either a live system or a trace file), attempt to create an
15715 equivalent GDB tracepoint. This is not a reliable process, since
15716 the target does not necessarily have all the information used when
15717 the tracepoint was originally defined. */
15719 struct tracepoint *
15720 create_tracepoint_from_upload (struct uploaded_tp *utp)
15722 char *addr_str, small_buf[100];
15723 struct tracepoint *tp;
15725 if (utp->at_string)
15726 addr_str = utp->at_string;
15729 /* In the absence of a source location, fall back to raw
15730 address. Since there is no way to confirm that the address
15731 means the same thing as when the trace was started, warn the
15733 warning (_("Uploaded tracepoint %d has no "
15734 "source location, using raw address"),
15736 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15737 addr_str = small_buf;
15740 /* There's not much we can do with a sequence of bytecodes. */
15741 if (utp->cond && !utp->cond_string)
15742 warning (_("Uploaded tracepoint %d condition "
15743 "has no source form, ignoring it"),
15746 if (!create_breakpoint (get_current_arch (),
15748 utp->cond_string, -1, NULL,
15749 0 /* parse cond/thread */,
15751 utp->type /* type_wanted */,
15752 0 /* Ignore count */,
15753 pending_break_support,
15754 &tracepoint_breakpoint_ops,
15756 utp->enabled /* enabled */,
15758 CREATE_BREAKPOINT_FLAGS_INSERTED))
15761 /* Get the tracepoint we just created. */
15762 tp = get_tracepoint (tracepoint_count);
15763 gdb_assert (tp != NULL);
15767 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15770 trace_pass_command (small_buf, 0);
15773 /* If we have uploaded versions of the original commands, set up a
15774 special-purpose "reader" function and call the usual command line
15775 reader, then pass the result to the breakpoint command-setting
15777 if (!VEC_empty (char_ptr, utp->cmd_strings))
15779 struct command_line *cmd_list;
15784 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15786 breakpoint_set_commands (&tp->base, cmd_list);
15788 else if (!VEC_empty (char_ptr, utp->actions)
15789 || !VEC_empty (char_ptr, utp->step_actions))
15790 warning (_("Uploaded tracepoint %d actions "
15791 "have no source form, ignoring them"),
15794 /* Copy any status information that might be available. */
15795 tp->base.hit_count = utp->hit_count;
15796 tp->traceframe_usage = utp->traceframe_usage;
15801 /* Print information on tracepoint number TPNUM_EXP, or all if
15805 tracepoints_info (char *args, int from_tty)
15807 struct ui_out *uiout = current_uiout;
15810 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15812 if (num_printed == 0)
15814 if (args == NULL || *args == '\0')
15815 ui_out_message (uiout, 0, "No tracepoints.\n");
15817 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15820 default_collect_info ();
15823 /* The 'enable trace' command enables tracepoints.
15824 Not supported by all targets. */
15826 enable_trace_command (char *args, int from_tty)
15828 enable_command (args, from_tty);
15831 /* The 'disable trace' command disables tracepoints.
15832 Not supported by all targets. */
15834 disable_trace_command (char *args, int from_tty)
15836 disable_command (args, from_tty);
15839 /* Remove a tracepoint (or all if no argument). */
15841 delete_trace_command (char *arg, int from_tty)
15843 struct breakpoint *b, *b_tmp;
15849 int breaks_to_delete = 0;
15851 /* Delete all breakpoints if no argument.
15852 Do not delete internal or call-dummy breakpoints, these
15853 have to be deleted with an explicit breakpoint number
15855 ALL_TRACEPOINTS (b)
15856 if (is_tracepoint (b) && user_breakpoint_p (b))
15858 breaks_to_delete = 1;
15862 /* Ask user only if there are some breakpoints to delete. */
15864 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15866 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15867 if (is_tracepoint (b) && user_breakpoint_p (b))
15868 delete_breakpoint (b);
15872 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15875 /* Helper function for trace_pass_command. */
15878 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15880 tp->pass_count = count;
15881 observer_notify_breakpoint_modified (&tp->base);
15883 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15884 tp->base.number, count);
15887 /* Set passcount for tracepoint.
15889 First command argument is passcount, second is tracepoint number.
15890 If tracepoint number omitted, apply to most recently defined.
15891 Also accepts special argument "all". */
15894 trace_pass_command (char *args, int from_tty)
15896 struct tracepoint *t1;
15897 unsigned int count;
15899 if (args == 0 || *args == 0)
15900 error (_("passcount command requires an "
15901 "argument (count + optional TP num)"));
15903 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15905 args = skip_spaces (args);
15906 if (*args && strncasecmp (args, "all", 3) == 0)
15908 struct breakpoint *b;
15910 args += 3; /* Skip special argument "all". */
15912 error (_("Junk at end of arguments."));
15914 ALL_TRACEPOINTS (b)
15916 t1 = (struct tracepoint *) b;
15917 trace_pass_set_count (t1, count, from_tty);
15920 else if (*args == '\0')
15922 t1 = get_tracepoint_by_number (&args, NULL);
15924 trace_pass_set_count (t1, count, from_tty);
15928 struct get_number_or_range_state state;
15930 init_number_or_range (&state, args);
15931 while (!state.finished)
15933 t1 = get_tracepoint_by_number (&args, &state);
15935 trace_pass_set_count (t1, count, from_tty);
15940 struct tracepoint *
15941 get_tracepoint (int num)
15943 struct breakpoint *t;
15945 ALL_TRACEPOINTS (t)
15946 if (t->number == num)
15947 return (struct tracepoint *) t;
15952 /* Find the tracepoint with the given target-side number (which may be
15953 different from the tracepoint number after disconnecting and
15956 struct tracepoint *
15957 get_tracepoint_by_number_on_target (int num)
15959 struct breakpoint *b;
15961 ALL_TRACEPOINTS (b)
15963 struct tracepoint *t = (struct tracepoint *) b;
15965 if (t->number_on_target == num)
15972 /* Utility: parse a tracepoint number and look it up in the list.
15973 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15974 If the argument is missing, the most recent tracepoint
15975 (tracepoint_count) is returned. */
15977 struct tracepoint *
15978 get_tracepoint_by_number (char **arg,
15979 struct get_number_or_range_state *state)
15981 struct breakpoint *t;
15983 char *instring = arg == NULL ? NULL : *arg;
15987 gdb_assert (!state->finished);
15988 tpnum = get_number_or_range (state);
15990 else if (arg == NULL || *arg == NULL || ! **arg)
15991 tpnum = tracepoint_count;
15993 tpnum = get_number (arg);
15997 if (instring && *instring)
15998 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
16001 printf_filtered (_("No previous tracepoint\n"));
16005 ALL_TRACEPOINTS (t)
16006 if (t->number == tpnum)
16008 return (struct tracepoint *) t;
16011 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
16016 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
16018 if (b->thread != -1)
16019 fprintf_unfiltered (fp, " thread %d", b->thread);
16022 fprintf_unfiltered (fp, " task %d", b->task);
16024 fprintf_unfiltered (fp, "\n");
16027 /* Save information on user settable breakpoints (watchpoints, etc) to
16028 a new script file named FILENAME. If FILTER is non-NULL, call it
16029 on each breakpoint and only include the ones for which it returns
16033 save_breakpoints (char *filename, int from_tty,
16034 int (*filter) (const struct breakpoint *))
16036 struct breakpoint *tp;
16038 struct cleanup *cleanup;
16039 struct ui_file *fp;
16040 int extra_trace_bits = 0;
16042 if (filename == 0 || *filename == 0)
16043 error (_("Argument required (file name in which to save)"));
16045 /* See if we have anything to save. */
16046 ALL_BREAKPOINTS (tp)
16048 /* Skip internal and momentary breakpoints. */
16049 if (!user_breakpoint_p (tp))
16052 /* If we have a filter, only save the breakpoints it accepts. */
16053 if (filter && !filter (tp))
16058 if (is_tracepoint (tp))
16060 extra_trace_bits = 1;
16062 /* We can stop searching. */
16069 warning (_("Nothing to save."));
16073 filename = tilde_expand (filename);
16074 cleanup = make_cleanup (xfree, filename);
16075 fp = gdb_fopen (filename, "w");
16077 error (_("Unable to open file '%s' for saving (%s)"),
16078 filename, safe_strerror (errno));
16079 make_cleanup_ui_file_delete (fp);
16081 if (extra_trace_bits)
16082 save_trace_state_variables (fp);
16084 ALL_BREAKPOINTS (tp)
16086 /* Skip internal and momentary breakpoints. */
16087 if (!user_breakpoint_p (tp))
16090 /* If we have a filter, only save the breakpoints it accepts. */
16091 if (filter && !filter (tp))
16094 tp->ops->print_recreate (tp, fp);
16096 /* Note, we can't rely on tp->number for anything, as we can't
16097 assume the recreated breakpoint numbers will match. Use $bpnum
16100 if (tp->cond_string)
16101 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
16103 if (tp->ignore_count)
16104 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
16106 if (tp->type != bp_dprintf && tp->commands)
16108 volatile struct gdb_exception ex;
16110 fprintf_unfiltered (fp, " commands\n");
16112 ui_out_redirect (current_uiout, fp);
16113 TRY_CATCH (ex, RETURN_MASK_ALL)
16115 print_command_lines (current_uiout, tp->commands->commands, 2);
16117 ui_out_redirect (current_uiout, NULL);
16120 throw_exception (ex);
16122 fprintf_unfiltered (fp, " end\n");
16125 if (tp->enable_state == bp_disabled)
16126 fprintf_unfiltered (fp, "disable\n");
16128 /* If this is a multi-location breakpoint, check if the locations
16129 should be individually disabled. Watchpoint locations are
16130 special, and not user visible. */
16131 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
16133 struct bp_location *loc;
16136 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
16138 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
16142 if (extra_trace_bits && *default_collect)
16143 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
16146 printf_filtered (_("Saved to file '%s'.\n"), filename);
16147 do_cleanups (cleanup);
16150 /* The `save breakpoints' command. */
16153 save_breakpoints_command (char *args, int from_tty)
16155 save_breakpoints (args, from_tty, NULL);
16158 /* The `save tracepoints' command. */
16161 save_tracepoints_command (char *args, int from_tty)
16163 save_breakpoints (args, from_tty, is_tracepoint);
16166 /* Create a vector of all tracepoints. */
16168 VEC(breakpoint_p) *
16169 all_tracepoints (void)
16171 VEC(breakpoint_p) *tp_vec = 0;
16172 struct breakpoint *tp;
16174 ALL_TRACEPOINTS (tp)
16176 VEC_safe_push (breakpoint_p, tp_vec, tp);
16183 /* This help string is used for the break, hbreak, tbreak and thbreak
16184 commands. It is defined as a macro to prevent duplication.
16185 COMMAND should be a string constant containing the name of the
16187 #define BREAK_ARGS_HELP(command) \
16188 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16189 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16190 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16191 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
16192 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16193 If a line number is specified, break at start of code for that line.\n\
16194 If a function is specified, break at start of code for that function.\n\
16195 If an address is specified, break at that exact address.\n\
16196 With no LOCATION, uses current execution address of the selected\n\
16197 stack frame. This is useful for breaking on return to a stack frame.\n\
16199 THREADNUM is the number from \"info threads\".\n\
16200 CONDITION is a boolean expression.\n\
16202 Multiple breakpoints at one place are permitted, and useful if their\n\
16203 conditions are different.\n\
16205 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16207 /* List of subcommands for "catch". */
16208 static struct cmd_list_element *catch_cmdlist;
16210 /* List of subcommands for "tcatch". */
16211 static struct cmd_list_element *tcatch_cmdlist;
16214 add_catch_command (char *name, char *docstring,
16215 cmd_sfunc_ftype *sfunc,
16216 completer_ftype *completer,
16217 void *user_data_catch,
16218 void *user_data_tcatch)
16220 struct cmd_list_element *command;
16222 command = add_cmd (name, class_breakpoint, NULL, docstring,
16224 set_cmd_sfunc (command, sfunc);
16225 set_cmd_context (command, user_data_catch);
16226 set_cmd_completer (command, completer);
16228 command = add_cmd (name, class_breakpoint, NULL, docstring,
16230 set_cmd_sfunc (command, sfunc);
16231 set_cmd_context (command, user_data_tcatch);
16232 set_cmd_completer (command, completer);
16236 clear_syscall_counts (struct inferior *inf)
16238 struct catch_syscall_inferior_data *inf_data
16239 = get_catch_syscall_inferior_data (inf);
16241 inf_data->total_syscalls_count = 0;
16242 inf_data->any_syscall_count = 0;
16243 VEC_free (int, inf_data->syscalls_counts);
16247 save_command (char *arg, int from_tty)
16249 printf_unfiltered (_("\"save\" must be followed by "
16250 "the name of a save subcommand.\n"));
16251 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
16254 struct breakpoint *
16255 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
16258 struct breakpoint *b, *b_tmp;
16260 ALL_BREAKPOINTS_SAFE (b, b_tmp)
16262 if ((*callback) (b, data))
16269 /* Zero if any of the breakpoint's locations could be a location where
16270 functions have been inlined, nonzero otherwise. */
16273 is_non_inline_function (struct breakpoint *b)
16275 /* The shared library event breakpoint is set on the address of a
16276 non-inline function. */
16277 if (b->type == bp_shlib_event)
16283 /* Nonzero if the specified PC cannot be a location where functions
16284 have been inlined. */
16287 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
16288 const struct target_waitstatus *ws)
16290 struct breakpoint *b;
16291 struct bp_location *bl;
16293 ALL_BREAKPOINTS (b)
16295 if (!is_non_inline_function (b))
16298 for (bl = b->loc; bl != NULL; bl = bl->next)
16300 if (!bl->shlib_disabled
16301 && bpstat_check_location (bl, aspace, pc, ws))
16309 /* Remove any references to OBJFILE which is going to be freed. */
16312 breakpoint_free_objfile (struct objfile *objfile)
16314 struct bp_location **locp, *loc;
16316 ALL_BP_LOCATIONS (loc, locp)
16317 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
16318 loc->symtab = NULL;
16322 initialize_breakpoint_ops (void)
16324 static int initialized = 0;
16326 struct breakpoint_ops *ops;
16332 /* The breakpoint_ops structure to be inherit by all kinds of
16333 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16334 internal and momentary breakpoints, etc.). */
16335 ops = &bkpt_base_breakpoint_ops;
16336 *ops = base_breakpoint_ops;
16337 ops->re_set = bkpt_re_set;
16338 ops->insert_location = bkpt_insert_location;
16339 ops->remove_location = bkpt_remove_location;
16340 ops->breakpoint_hit = bkpt_breakpoint_hit;
16341 ops->create_sals_from_address = bkpt_create_sals_from_address;
16342 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
16343 ops->decode_linespec = bkpt_decode_linespec;
16345 /* The breakpoint_ops structure to be used in regular breakpoints. */
16346 ops = &bkpt_breakpoint_ops;
16347 *ops = bkpt_base_breakpoint_ops;
16348 ops->re_set = bkpt_re_set;
16349 ops->resources_needed = bkpt_resources_needed;
16350 ops->print_it = bkpt_print_it;
16351 ops->print_mention = bkpt_print_mention;
16352 ops->print_recreate = bkpt_print_recreate;
16354 /* Ranged breakpoints. */
16355 ops = &ranged_breakpoint_ops;
16356 *ops = bkpt_breakpoint_ops;
16357 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16358 ops->resources_needed = resources_needed_ranged_breakpoint;
16359 ops->print_it = print_it_ranged_breakpoint;
16360 ops->print_one = print_one_ranged_breakpoint;
16361 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16362 ops->print_mention = print_mention_ranged_breakpoint;
16363 ops->print_recreate = print_recreate_ranged_breakpoint;
16365 /* Internal breakpoints. */
16366 ops = &internal_breakpoint_ops;
16367 *ops = bkpt_base_breakpoint_ops;
16368 ops->re_set = internal_bkpt_re_set;
16369 ops->check_status = internal_bkpt_check_status;
16370 ops->print_it = internal_bkpt_print_it;
16371 ops->print_mention = internal_bkpt_print_mention;
16373 /* Momentary breakpoints. */
16374 ops = &momentary_breakpoint_ops;
16375 *ops = bkpt_base_breakpoint_ops;
16376 ops->re_set = momentary_bkpt_re_set;
16377 ops->check_status = momentary_bkpt_check_status;
16378 ops->print_it = momentary_bkpt_print_it;
16379 ops->print_mention = momentary_bkpt_print_mention;
16381 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16382 ops = &longjmp_breakpoint_ops;
16383 *ops = momentary_breakpoint_ops;
16384 ops->dtor = longjmp_bkpt_dtor;
16386 /* Probe breakpoints. */
16387 ops = &bkpt_probe_breakpoint_ops;
16388 *ops = bkpt_breakpoint_ops;
16389 ops->insert_location = bkpt_probe_insert_location;
16390 ops->remove_location = bkpt_probe_remove_location;
16391 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
16392 ops->decode_linespec = bkpt_probe_decode_linespec;
16395 ops = &watchpoint_breakpoint_ops;
16396 *ops = base_breakpoint_ops;
16397 ops->dtor = dtor_watchpoint;
16398 ops->re_set = re_set_watchpoint;
16399 ops->insert_location = insert_watchpoint;
16400 ops->remove_location = remove_watchpoint;
16401 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16402 ops->check_status = check_status_watchpoint;
16403 ops->resources_needed = resources_needed_watchpoint;
16404 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16405 ops->print_it = print_it_watchpoint;
16406 ops->print_mention = print_mention_watchpoint;
16407 ops->print_recreate = print_recreate_watchpoint;
16408 ops->explains_signal = explains_signal_watchpoint;
16410 /* Masked watchpoints. */
16411 ops = &masked_watchpoint_breakpoint_ops;
16412 *ops = watchpoint_breakpoint_ops;
16413 ops->insert_location = insert_masked_watchpoint;
16414 ops->remove_location = remove_masked_watchpoint;
16415 ops->resources_needed = resources_needed_masked_watchpoint;
16416 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16417 ops->print_it = print_it_masked_watchpoint;
16418 ops->print_one_detail = print_one_detail_masked_watchpoint;
16419 ops->print_mention = print_mention_masked_watchpoint;
16420 ops->print_recreate = print_recreate_masked_watchpoint;
16423 ops = &tracepoint_breakpoint_ops;
16424 *ops = base_breakpoint_ops;
16425 ops->re_set = tracepoint_re_set;
16426 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16427 ops->print_one_detail = tracepoint_print_one_detail;
16428 ops->print_mention = tracepoint_print_mention;
16429 ops->print_recreate = tracepoint_print_recreate;
16430 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16431 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16432 ops->decode_linespec = tracepoint_decode_linespec;
16434 /* Probe tracepoints. */
16435 ops = &tracepoint_probe_breakpoint_ops;
16436 *ops = tracepoint_breakpoint_ops;
16437 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16438 ops->decode_linespec = tracepoint_probe_decode_linespec;
16440 /* Static tracepoints with marker (`-m'). */
16441 ops = &strace_marker_breakpoint_ops;
16442 *ops = tracepoint_breakpoint_ops;
16443 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16444 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16445 ops->decode_linespec = strace_marker_decode_linespec;
16447 /* Fork catchpoints. */
16448 ops = &catch_fork_breakpoint_ops;
16449 *ops = base_breakpoint_ops;
16450 ops->insert_location = insert_catch_fork;
16451 ops->remove_location = remove_catch_fork;
16452 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16453 ops->print_it = print_it_catch_fork;
16454 ops->print_one = print_one_catch_fork;
16455 ops->print_mention = print_mention_catch_fork;
16456 ops->print_recreate = print_recreate_catch_fork;
16458 /* Vfork catchpoints. */
16459 ops = &catch_vfork_breakpoint_ops;
16460 *ops = base_breakpoint_ops;
16461 ops->insert_location = insert_catch_vfork;
16462 ops->remove_location = remove_catch_vfork;
16463 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16464 ops->print_it = print_it_catch_vfork;
16465 ops->print_one = print_one_catch_vfork;
16466 ops->print_mention = print_mention_catch_vfork;
16467 ops->print_recreate = print_recreate_catch_vfork;
16469 /* Exec catchpoints. */
16470 ops = &catch_exec_breakpoint_ops;
16471 *ops = base_breakpoint_ops;
16472 ops->dtor = dtor_catch_exec;
16473 ops->insert_location = insert_catch_exec;
16474 ops->remove_location = remove_catch_exec;
16475 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16476 ops->print_it = print_it_catch_exec;
16477 ops->print_one = print_one_catch_exec;
16478 ops->print_mention = print_mention_catch_exec;
16479 ops->print_recreate = print_recreate_catch_exec;
16481 /* Syscall catchpoints. */
16482 ops = &catch_syscall_breakpoint_ops;
16483 *ops = base_breakpoint_ops;
16484 ops->dtor = dtor_catch_syscall;
16485 ops->insert_location = insert_catch_syscall;
16486 ops->remove_location = remove_catch_syscall;
16487 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16488 ops->print_it = print_it_catch_syscall;
16489 ops->print_one = print_one_catch_syscall;
16490 ops->print_mention = print_mention_catch_syscall;
16491 ops->print_recreate = print_recreate_catch_syscall;
16493 /* Solib-related catchpoints. */
16494 ops = &catch_solib_breakpoint_ops;
16495 *ops = base_breakpoint_ops;
16496 ops->dtor = dtor_catch_solib;
16497 ops->insert_location = insert_catch_solib;
16498 ops->remove_location = remove_catch_solib;
16499 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16500 ops->check_status = check_status_catch_solib;
16501 ops->print_it = print_it_catch_solib;
16502 ops->print_one = print_one_catch_solib;
16503 ops->print_mention = print_mention_catch_solib;
16504 ops->print_recreate = print_recreate_catch_solib;
16506 ops = &dprintf_breakpoint_ops;
16507 *ops = bkpt_base_breakpoint_ops;
16508 ops->re_set = dprintf_re_set;
16509 ops->resources_needed = bkpt_resources_needed;
16510 ops->print_it = bkpt_print_it;
16511 ops->print_mention = bkpt_print_mention;
16512 ops->print_recreate = dprintf_print_recreate;
16513 ops->after_condition_true = dprintf_after_condition_true;
16514 ops->breakpoint_hit = dprintf_breakpoint_hit;
16517 /* Chain containing all defined "enable breakpoint" subcommands. */
16519 static struct cmd_list_element *enablebreaklist = NULL;
16522 _initialize_breakpoint (void)
16524 struct cmd_list_element *c;
16526 initialize_breakpoint_ops ();
16528 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16529 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16530 observer_attach_inferior_exit (clear_syscall_counts);
16531 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16533 breakpoint_objfile_key
16534 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16536 catch_syscall_inferior_data
16537 = register_inferior_data_with_cleanup (NULL,
16538 catch_syscall_inferior_data_cleanup);
16540 breakpoint_chain = 0;
16541 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16542 before a breakpoint is set. */
16543 breakpoint_count = 0;
16545 tracepoint_count = 0;
16547 add_com ("ignore", class_breakpoint, ignore_command, _("\
16548 Set ignore-count of breakpoint number N to COUNT.\n\
16549 Usage is `ignore N COUNT'."));
16551 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16553 add_com ("commands", class_breakpoint, commands_command, _("\
16554 Set commands to be executed when a breakpoint is hit.\n\
16555 Give breakpoint number as argument after \"commands\".\n\
16556 With no argument, the targeted breakpoint is the last one set.\n\
16557 The commands themselves follow starting on the next line.\n\
16558 Type a line containing \"end\" to indicate the end of them.\n\
16559 Give \"silent\" as the first line to make the breakpoint silent;\n\
16560 then no output is printed when it is hit, except what the commands print."));
16562 c = add_com ("condition", class_breakpoint, condition_command, _("\
16563 Specify breakpoint number N to break only if COND is true.\n\
16564 Usage is `condition N COND', where N is an integer and COND is an\n\
16565 expression to be evaluated whenever breakpoint N is reached."));
16566 set_cmd_completer (c, condition_completer);
16568 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16569 Set a temporary breakpoint.\n\
16570 Like \"break\" except the breakpoint is only temporary,\n\
16571 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16572 by using \"enable delete\" on the breakpoint number.\n\
16574 BREAK_ARGS_HELP ("tbreak")));
16575 set_cmd_completer (c, location_completer);
16577 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16578 Set a hardware assisted breakpoint.\n\
16579 Like \"break\" except the breakpoint requires hardware support,\n\
16580 some target hardware may not have this support.\n\
16582 BREAK_ARGS_HELP ("hbreak")));
16583 set_cmd_completer (c, location_completer);
16585 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16586 Set a temporary hardware assisted breakpoint.\n\
16587 Like \"hbreak\" except the breakpoint is only temporary,\n\
16588 so it will be deleted when hit.\n\
16590 BREAK_ARGS_HELP ("thbreak")));
16591 set_cmd_completer (c, location_completer);
16593 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16594 Enable some breakpoints.\n\
16595 Give breakpoint numbers (separated by spaces) as arguments.\n\
16596 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16597 This is used to cancel the effect of the \"disable\" command.\n\
16598 With a subcommand you can enable temporarily."),
16599 &enablelist, "enable ", 1, &cmdlist);
16601 add_com ("ab", class_breakpoint, enable_command, _("\
16602 Enable some breakpoints.\n\
16603 Give breakpoint numbers (separated by spaces) as arguments.\n\
16604 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16605 This is used to cancel the effect of the \"disable\" command.\n\
16606 With a subcommand you can enable temporarily."));
16608 add_com_alias ("en", "enable", class_breakpoint, 1);
16610 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16611 Enable some breakpoints.\n\
16612 Give breakpoint numbers (separated by spaces) as arguments.\n\
16613 This is used to cancel the effect of the \"disable\" command.\n\
16614 May be abbreviated to simply \"enable\".\n"),
16615 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16617 add_cmd ("once", no_class, enable_once_command, _("\
16618 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16619 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16622 add_cmd ("delete", no_class, enable_delete_command, _("\
16623 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16624 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16627 add_cmd ("count", no_class, enable_count_command, _("\
16628 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16629 If a breakpoint is hit while enabled in this fashion,\n\
16630 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16633 add_cmd ("delete", no_class, enable_delete_command, _("\
16634 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16635 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16638 add_cmd ("once", no_class, enable_once_command, _("\
16639 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16640 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16643 add_cmd ("count", no_class, enable_count_command, _("\
16644 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16645 If a breakpoint is hit while enabled in this fashion,\n\
16646 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16649 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16650 Disable some breakpoints.\n\
16651 Arguments are breakpoint numbers with spaces in between.\n\
16652 To disable all breakpoints, give no argument.\n\
16653 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16654 &disablelist, "disable ", 1, &cmdlist);
16655 add_com_alias ("dis", "disable", class_breakpoint, 1);
16656 add_com_alias ("disa", "disable", class_breakpoint, 1);
16658 add_com ("sb", class_breakpoint, disable_command, _("\
16659 Disable some breakpoints.\n\
16660 Arguments are breakpoint numbers with spaces in between.\n\
16661 To disable all breakpoints, give no argument.\n\
16662 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16664 add_cmd ("breakpoints", class_alias, disable_command, _("\
16665 Disable some breakpoints.\n\
16666 Arguments are breakpoint numbers with spaces in between.\n\
16667 To disable all breakpoints, give no argument.\n\
16668 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16669 This command may be abbreviated \"disable\"."),
16672 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16673 Delete some breakpoints or auto-display expressions.\n\
16674 Arguments are breakpoint numbers with spaces in between.\n\
16675 To delete all breakpoints, give no argument.\n\
16677 Also a prefix command for deletion of other GDB objects.\n\
16678 The \"unset\" command is also an alias for \"delete\"."),
16679 &deletelist, "delete ", 1, &cmdlist);
16680 add_com_alias ("d", "delete", class_breakpoint, 1);
16681 add_com_alias ("del", "delete", class_breakpoint, 1);
16683 add_com ("db", class_breakpoint, delete_command, _("\
16684 Delete some breakpoints.\n\
16685 Arguments are breakpoint numbers with spaces in between.\n\
16686 To delete all breakpoints, give no argument.\n"));
16688 add_cmd ("breakpoints", class_alias, delete_command, _("\
16689 Delete some breakpoints or auto-display expressions.\n\
16690 Arguments are breakpoint numbers with spaces in between.\n\
16691 To delete all breakpoints, give no argument.\n\
16692 This command may be abbreviated \"delete\"."),
16695 add_com ("clear", class_breakpoint, clear_command, _("\
16696 Clear breakpoint at specified line or function.\n\
16697 Argument may be line number, function name, or \"*\" and an address.\n\
16698 If line number is specified, all breakpoints in that line are cleared.\n\
16699 If function is specified, breakpoints at beginning of function are cleared.\n\
16700 If an address is specified, breakpoints at that address are cleared.\n\
16702 With no argument, clears all breakpoints in the line that the selected frame\n\
16703 is executing in.\n\
16705 See also the \"delete\" command which clears breakpoints by number."));
16706 add_com_alias ("cl", "clear", class_breakpoint, 1);
16708 c = add_com ("break", class_breakpoint, break_command, _("\
16709 Set breakpoint at specified line or function.\n"
16710 BREAK_ARGS_HELP ("break")));
16711 set_cmd_completer (c, location_completer);
16713 add_com_alias ("b", "break", class_run, 1);
16714 add_com_alias ("br", "break", class_run, 1);
16715 add_com_alias ("bre", "break", class_run, 1);
16716 add_com_alias ("brea", "break", class_run, 1);
16719 add_com_alias ("ba", "break", class_breakpoint, 1);
16723 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16724 Break in function/address or break at a line in the current file."),
16725 &stoplist, "stop ", 1, &cmdlist);
16726 add_cmd ("in", class_breakpoint, stopin_command,
16727 _("Break in function or address."), &stoplist);
16728 add_cmd ("at", class_breakpoint, stopat_command,
16729 _("Break at a line in the current file."), &stoplist);
16730 add_com ("status", class_info, breakpoints_info, _("\
16731 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16732 The \"Type\" column indicates one of:\n\
16733 \tbreakpoint - normal breakpoint\n\
16734 \twatchpoint - watchpoint\n\
16735 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16736 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16737 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16738 address and file/line number respectively.\n\
16740 Convenience variable \"$_\" and default examine address for \"x\"\n\
16741 are set to the address of the last breakpoint listed unless the command\n\
16742 is prefixed with \"server \".\n\n\
16743 Convenience variable \"$bpnum\" contains the number of the last\n\
16744 breakpoint set."));
16747 add_info ("breakpoints", breakpoints_info, _("\
16748 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16749 The \"Type\" column indicates one of:\n\
16750 \tbreakpoint - normal breakpoint\n\
16751 \twatchpoint - watchpoint\n\
16752 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16753 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16754 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16755 address and file/line number respectively.\n\
16757 Convenience variable \"$_\" and default examine address for \"x\"\n\
16758 are set to the address of the last breakpoint listed unless the command\n\
16759 is prefixed with \"server \".\n\n\
16760 Convenience variable \"$bpnum\" contains the number of the last\n\
16761 breakpoint set."));
16763 add_info_alias ("b", "breakpoints", 1);
16766 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16767 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16768 The \"Type\" column indicates one of:\n\
16769 \tbreakpoint - normal breakpoint\n\
16770 \twatchpoint - watchpoint\n\
16771 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16772 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16773 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16774 address and file/line number respectively.\n\
16776 Convenience variable \"$_\" and default examine address for \"x\"\n\
16777 are set to the address of the last breakpoint listed unless the command\n\
16778 is prefixed with \"server \".\n\n\
16779 Convenience variable \"$bpnum\" contains the number of the last\n\
16780 breakpoint set."));
16782 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16783 Status of all breakpoints, or breakpoint number NUMBER.\n\
16784 The \"Type\" column indicates one of:\n\
16785 \tbreakpoint - normal breakpoint\n\
16786 \twatchpoint - watchpoint\n\
16787 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16788 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16789 \tuntil - internal breakpoint used by the \"until\" command\n\
16790 \tfinish - internal breakpoint used by the \"finish\" command\n\
16791 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16792 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16793 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16794 address and file/line number respectively.\n\
16796 Convenience variable \"$_\" and default examine address for \"x\"\n\
16797 are set to the address of the last breakpoint listed unless the command\n\
16798 is prefixed with \"server \".\n\n\
16799 Convenience variable \"$bpnum\" contains the number of the last\n\
16801 &maintenanceinfolist);
16803 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16804 Set catchpoints to catch events."),
16805 &catch_cmdlist, "catch ",
16806 0/*allow-unknown*/, &cmdlist);
16808 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16809 Set temporary catchpoints to catch events."),
16810 &tcatch_cmdlist, "tcatch ",
16811 0/*allow-unknown*/, &cmdlist);
16813 add_catch_command ("fork", _("Catch calls to fork."),
16814 catch_fork_command_1,
16816 (void *) (uintptr_t) catch_fork_permanent,
16817 (void *) (uintptr_t) catch_fork_temporary);
16818 add_catch_command ("vfork", _("Catch calls to vfork."),
16819 catch_fork_command_1,
16821 (void *) (uintptr_t) catch_vfork_permanent,
16822 (void *) (uintptr_t) catch_vfork_temporary);
16823 add_catch_command ("exec", _("Catch calls to exec."),
16824 catch_exec_command_1,
16828 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16829 Usage: catch load [REGEX]\n\
16830 If REGEX is given, only stop for libraries matching the regular expression."),
16831 catch_load_command_1,
16835 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16836 Usage: catch unload [REGEX]\n\
16837 If REGEX is given, only stop for libraries matching the regular expression."),
16838 catch_unload_command_1,
16842 add_catch_command ("syscall", _("\
16843 Catch system calls by their names and/or numbers.\n\
16844 Arguments say which system calls to catch. If no arguments\n\
16845 are given, every system call will be caught.\n\
16846 Arguments, if given, should be one or more system call names\n\
16847 (if your system supports that), or system call numbers."),
16848 catch_syscall_command_1,
16849 catch_syscall_completer,
16853 c = add_com ("watch", class_breakpoint, watch_command, _("\
16854 Set a watchpoint for an expression.\n\
16855 Usage: watch [-l|-location] EXPRESSION\n\
16856 A watchpoint stops execution of your program whenever the value of\n\
16857 an expression changes.\n\
16858 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16859 the memory to which it refers."));
16860 set_cmd_completer (c, expression_completer);
16862 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16863 Set a read watchpoint for an expression.\n\
16864 Usage: rwatch [-l|-location] EXPRESSION\n\
16865 A watchpoint stops execution of your program whenever the value of\n\
16866 an expression is read.\n\
16867 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16868 the memory to which it refers."));
16869 set_cmd_completer (c, expression_completer);
16871 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16872 Set a watchpoint for an expression.\n\
16873 Usage: awatch [-l|-location] EXPRESSION\n\
16874 A watchpoint stops execution of your program whenever the value of\n\
16875 an expression is either read or written.\n\
16876 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16877 the memory to which it refers."));
16878 set_cmd_completer (c, expression_completer);
16880 add_info ("watchpoints", watchpoints_info, _("\
16881 Status of specified watchpoints (all watchpoints if no argument)."));
16883 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16884 respond to changes - contrary to the description. */
16885 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16886 &can_use_hw_watchpoints, _("\
16887 Set debugger's willingness to use watchpoint hardware."), _("\
16888 Show debugger's willingness to use watchpoint hardware."), _("\
16889 If zero, gdb will not use hardware for new watchpoints, even if\n\
16890 such is available. (However, any hardware watchpoints that were\n\
16891 created before setting this to nonzero, will continue to use watchpoint\n\
16894 show_can_use_hw_watchpoints,
16895 &setlist, &showlist);
16897 can_use_hw_watchpoints = 1;
16899 /* Tracepoint manipulation commands. */
16901 c = add_com ("trace", class_breakpoint, trace_command, _("\
16902 Set a tracepoint at specified line or function.\n\
16904 BREAK_ARGS_HELP ("trace") "\n\
16905 Do \"help tracepoints\" for info on other tracepoint commands."));
16906 set_cmd_completer (c, location_completer);
16908 add_com_alias ("tp", "trace", class_alias, 0);
16909 add_com_alias ("tr", "trace", class_alias, 1);
16910 add_com_alias ("tra", "trace", class_alias, 1);
16911 add_com_alias ("trac", "trace", class_alias, 1);
16913 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16914 Set a fast tracepoint at specified line or function.\n\
16916 BREAK_ARGS_HELP ("ftrace") "\n\
16917 Do \"help tracepoints\" for info on other tracepoint commands."));
16918 set_cmd_completer (c, location_completer);
16920 c = add_com ("strace", class_breakpoint, strace_command, _("\
16921 Set a static tracepoint at specified line, function or marker.\n\
16923 strace [LOCATION] [if CONDITION]\n\
16924 LOCATION may be a line number, function name, \"*\" and an address,\n\
16925 or -m MARKER_ID.\n\
16926 If a line number is specified, probe the marker at start of code\n\
16927 for that line. If a function is specified, probe the marker at start\n\
16928 of code for that function. If an address is specified, probe the marker\n\
16929 at that exact address. If a marker id is specified, probe the marker\n\
16930 with that name. With no LOCATION, uses current execution address of\n\
16931 the selected stack frame.\n\
16932 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16933 This collects arbitrary user data passed in the probe point call to the\n\
16934 tracing library. You can inspect it when analyzing the trace buffer,\n\
16935 by printing the $_sdata variable like any other convenience variable.\n\
16937 CONDITION is a boolean expression.\n\
16939 Multiple tracepoints at one place are permitted, and useful if their\n\
16940 conditions are different.\n\
16942 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16943 Do \"help tracepoints\" for info on other tracepoint commands."));
16944 set_cmd_completer (c, location_completer);
16946 add_info ("tracepoints", tracepoints_info, _("\
16947 Status of specified tracepoints (all tracepoints if no argument).\n\
16948 Convenience variable \"$tpnum\" contains the number of the\n\
16949 last tracepoint set."));
16951 add_info_alias ("tp", "tracepoints", 1);
16953 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16954 Delete specified tracepoints.\n\
16955 Arguments are tracepoint numbers, separated by spaces.\n\
16956 No argument means delete all tracepoints."),
16958 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16960 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16961 Disable specified tracepoints.\n\
16962 Arguments are tracepoint numbers, separated by spaces.\n\
16963 No argument means disable all tracepoints."),
16965 deprecate_cmd (c, "disable");
16967 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16968 Enable specified tracepoints.\n\
16969 Arguments are tracepoint numbers, separated by spaces.\n\
16970 No argument means enable all tracepoints."),
16972 deprecate_cmd (c, "enable");
16974 add_com ("passcount", class_trace, trace_pass_command, _("\
16975 Set the passcount for a tracepoint.\n\
16976 The trace will end when the tracepoint has been passed 'count' times.\n\
16977 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16978 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16980 add_prefix_cmd ("save", class_breakpoint, save_command,
16981 _("Save breakpoint definitions as a script."),
16982 &save_cmdlist, "save ",
16983 0/*allow-unknown*/, &cmdlist);
16985 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16986 Save current breakpoint definitions as a script.\n\
16987 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16988 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16989 session to restore them."),
16991 set_cmd_completer (c, filename_completer);
16993 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16994 Save current tracepoint definitions as a script.\n\
16995 Use the 'source' command in another debug session to restore them."),
16997 set_cmd_completer (c, filename_completer);
16999 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
17000 deprecate_cmd (c, "save tracepoints");
17002 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
17003 Breakpoint specific settings\n\
17004 Configure various breakpoint-specific variables such as\n\
17005 pending breakpoint behavior"),
17006 &breakpoint_set_cmdlist, "set breakpoint ",
17007 0/*allow-unknown*/, &setlist);
17008 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
17009 Breakpoint specific settings\n\
17010 Configure various breakpoint-specific variables such as\n\
17011 pending breakpoint behavior"),
17012 &breakpoint_show_cmdlist, "show breakpoint ",
17013 0/*allow-unknown*/, &showlist);
17015 add_setshow_auto_boolean_cmd ("pending", no_class,
17016 &pending_break_support, _("\
17017 Set debugger's behavior regarding pending breakpoints."), _("\
17018 Show debugger's behavior regarding pending breakpoints."), _("\
17019 If on, an unrecognized breakpoint location will cause gdb to create a\n\
17020 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
17021 an error. If auto, an unrecognized breakpoint location results in a\n\
17022 user-query to see if a pending breakpoint should be created."),
17024 show_pending_break_support,
17025 &breakpoint_set_cmdlist,
17026 &breakpoint_show_cmdlist);
17028 pending_break_support = AUTO_BOOLEAN_AUTO;
17030 add_setshow_boolean_cmd ("auto-hw", no_class,
17031 &automatic_hardware_breakpoints, _("\
17032 Set automatic usage of hardware breakpoints."), _("\
17033 Show automatic usage of hardware breakpoints."), _("\
17034 If set, the debugger will automatically use hardware breakpoints for\n\
17035 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
17036 a warning will be emitted for such breakpoints."),
17038 show_automatic_hardware_breakpoints,
17039 &breakpoint_set_cmdlist,
17040 &breakpoint_show_cmdlist);
17042 add_setshow_boolean_cmd ("always-inserted", class_support,
17043 &always_inserted_mode, _("\
17044 Set mode for inserting breakpoints."), _("\
17045 Show mode for inserting breakpoints."), _("\
17046 When this mode is on, breakpoints are inserted immediately as soon as\n\
17047 they're created, kept inserted even when execution stops, and removed\n\
17048 only when the user deletes them. When this mode is off (the default),\n\
17049 breakpoints are inserted only when execution continues, and removed\n\
17050 when execution stops."),
17052 &show_always_inserted_mode,
17053 &breakpoint_set_cmdlist,
17054 &breakpoint_show_cmdlist);
17056 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
17057 condition_evaluation_enums,
17058 &condition_evaluation_mode_1, _("\
17059 Set mode of breakpoint condition evaluation."), _("\
17060 Show mode of breakpoint condition evaluation."), _("\
17061 When this is set to \"host\", breakpoint conditions will be\n\
17062 evaluated on the host's side by GDB. When it is set to \"target\",\n\
17063 breakpoint conditions will be downloaded to the target (if the target\n\
17064 supports such feature) and conditions will be evaluated on the target's side.\n\
17065 If this is set to \"auto\" (default), this will be automatically set to\n\
17066 \"target\" if it supports condition evaluation, otherwise it will\n\
17067 be set to \"gdb\""),
17068 &set_condition_evaluation_mode,
17069 &show_condition_evaluation_mode,
17070 &breakpoint_set_cmdlist,
17071 &breakpoint_show_cmdlist);
17073 add_com ("break-range", class_breakpoint, break_range_command, _("\
17074 Set a breakpoint for an address range.\n\
17075 break-range START-LOCATION, END-LOCATION\n\
17076 where START-LOCATION and END-LOCATION can be one of the following:\n\
17077 LINENUM, for that line in the current file,\n\
17078 FILE:LINENUM, for that line in that file,\n\
17079 +OFFSET, for that number of lines after the current line\n\
17080 or the start of the range\n\
17081 FUNCTION, for the first line in that function,\n\
17082 FILE:FUNCTION, to distinguish among like-named static functions.\n\
17083 *ADDRESS, for the instruction at that address.\n\
17085 The breakpoint will stop execution of the inferior whenever it executes\n\
17086 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
17087 range (including START-LOCATION and END-LOCATION)."));
17089 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
17090 Set a dynamic printf at specified line or function.\n\
17091 dprintf location,format string,arg1,arg2,...\n\
17092 location may be a line number, function name, or \"*\" and an address.\n\
17093 If a line number is specified, break at start of code for that line.\n\
17094 If a function is specified, break at start of code for that function."));
17095 set_cmd_completer (c, location_completer);
17097 add_setshow_enum_cmd ("dprintf-style", class_support,
17098 dprintf_style_enums, &dprintf_style, _("\
17099 Set the style of usage for dynamic printf."), _("\
17100 Show the style of usage for dynamic printf."), _("\
17101 This setting chooses how GDB will do a dynamic printf.\n\
17102 If the value is \"gdb\", then the printing is done by GDB to its own\n\
17103 console, as with the \"printf\" command.\n\
17104 If the value is \"call\", the print is done by calling a function in your\n\
17105 program; by default printf(), but you can choose a different function or\n\
17106 output stream by setting dprintf-function and dprintf-channel."),
17107 update_dprintf_commands, NULL,
17108 &setlist, &showlist);
17110 dprintf_function = xstrdup ("printf");
17111 add_setshow_string_cmd ("dprintf-function", class_support,
17112 &dprintf_function, _("\
17113 Set the function to use for dynamic printf"), _("\
17114 Show the function to use for dynamic printf"), NULL,
17115 update_dprintf_commands, NULL,
17116 &setlist, &showlist);
17118 dprintf_channel = xstrdup ("");
17119 add_setshow_string_cmd ("dprintf-channel", class_support,
17120 &dprintf_channel, _("\
17121 Set the channel to use for dynamic printf"), _("\
17122 Show the channel to use for dynamic printf"), NULL,
17123 update_dprintf_commands, NULL,
17124 &setlist, &showlist);
17126 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
17127 &disconnected_dprintf, _("\
17128 Set whether dprintf continues after GDB disconnects."), _("\
17129 Show whether dprintf continues after GDB disconnects."), _("\
17130 Use this to let dprintf commands continue to hit and produce output\n\
17131 even if GDB disconnects or detaches from the target."),
17134 &setlist, &showlist);
17136 add_com ("agent-printf", class_vars, agent_printf_command, _("\
17137 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
17138 (target agent only) This is useful for formatted output in user-defined commands."));
17140 automatic_hardware_breakpoints = 1;
17142 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
17143 observer_attach_thread_exit (remove_threaded_breakpoints);