1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2013 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"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
71 #include "dummy-frame.h"
75 /* readline include files */
76 #include "readline/readline.h"
77 #include "readline/history.h"
79 /* readline defines this. */
82 #include "mi/mi-common.h"
83 #include "python/python.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
108 static void ignore_command (char *, int);
110 static int breakpoint_re_set_one (void *);
112 static void breakpoint_re_set_default (struct breakpoint *);
114 static void create_sals_from_address_default (char **,
115 struct linespec_result *,
119 static void create_breakpoints_sal_default (struct gdbarch *,
120 struct linespec_result *,
121 struct linespec_sals *,
122 char *, char *, enum bptype,
123 enum bpdisp, int, int,
125 const struct breakpoint_ops *,
126 int, int, int, unsigned);
128 static void decode_linespec_default (struct breakpoint *, char **,
129 struct symtabs_and_lines *);
131 static void clear_command (char *, int);
133 static void catch_command (char *, int);
135 static int can_use_hardware_watchpoint (struct value *);
137 static void break_command_1 (char *, int, int);
139 static void mention (struct breakpoint *);
141 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
143 const struct breakpoint_ops *);
144 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
145 const struct symtab_and_line *);
147 /* This function is used in gdbtk sources and thus can not be made
149 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
150 struct symtab_and_line,
152 const struct breakpoint_ops *);
154 static struct breakpoint *
155 momentary_breakpoint_from_master (struct breakpoint *orig,
157 const struct breakpoint_ops *ops);
159 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
161 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
165 static void describe_other_breakpoints (struct gdbarch *,
166 struct program_space *, CORE_ADDR,
167 struct obj_section *, int);
169 static int breakpoint_address_match (struct address_space *aspace1,
171 struct address_space *aspace2,
174 static int watchpoint_locations_match (struct bp_location *loc1,
175 struct bp_location *loc2);
177 static int breakpoint_location_address_match (struct bp_location *bl,
178 struct address_space *aspace,
181 static void breakpoints_info (char *, int);
183 static void watchpoints_info (char *, int);
185 static int breakpoint_1 (char *, int,
186 int (*) (const struct breakpoint *));
188 static int breakpoint_cond_eval (void *);
190 static void cleanup_executing_breakpoints (void *);
192 static void commands_command (char *, int);
194 static void condition_command (char *, int);
203 static int remove_breakpoint (struct bp_location *, insertion_state_t);
204 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
206 static enum print_stop_action print_bp_stop_message (bpstat bs);
208 static int watchpoint_check (void *);
210 static void maintenance_info_breakpoints (char *, int);
212 static int hw_breakpoint_used_count (void);
214 static int hw_watchpoint_use_count (struct breakpoint *);
216 static int hw_watchpoint_used_count_others (struct breakpoint *except,
218 int *other_type_used);
220 static void hbreak_command (char *, int);
222 static void thbreak_command (char *, int);
224 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
227 static void stop_command (char *arg, int from_tty);
229 static void stopin_command (char *arg, int from_tty);
231 static void stopat_command (char *arg, int from_tty);
233 static char *ep_parse_optional_if_clause (char **arg);
235 static void catch_exception_command_1 (enum exception_event_kind ex_event,
236 char *arg, int tempflag, int from_tty);
238 static void tcatch_command (char *arg, int from_tty);
240 static void detach_single_step_breakpoints (void);
242 static int single_step_breakpoint_inserted_here_p (struct address_space *,
245 static void free_bp_location (struct bp_location *loc);
246 static void incref_bp_location (struct bp_location *loc);
247 static void decref_bp_location (struct bp_location **loc);
249 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
251 static void update_global_location_list (int);
253 static void update_global_location_list_nothrow (int);
255 static int is_hardware_watchpoint (const struct breakpoint *bpt);
257 static void insert_breakpoint_locations (void);
259 static int syscall_catchpoint_p (struct breakpoint *b);
261 static void tracepoints_info (char *, int);
263 static void delete_trace_command (char *, int);
265 static void enable_trace_command (char *, int);
267 static void disable_trace_command (char *, int);
269 static void trace_pass_command (char *, int);
271 static void set_tracepoint_count (int num);
273 static int is_masked_watchpoint (const struct breakpoint *b);
275 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
277 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
280 static int strace_marker_p (struct breakpoint *b);
282 /* The abstract base class all breakpoint_ops structures inherit
284 struct breakpoint_ops base_breakpoint_ops;
286 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
287 that are implemented on top of software or hardware breakpoints
288 (user breakpoints, internal and momentary breakpoints, etc.). */
289 static struct breakpoint_ops bkpt_base_breakpoint_ops;
291 /* Internal breakpoints class type. */
292 static struct breakpoint_ops internal_breakpoint_ops;
294 /* Momentary breakpoints class type. */
295 static struct breakpoint_ops momentary_breakpoint_ops;
297 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
298 static struct breakpoint_ops longjmp_breakpoint_ops;
300 /* The breakpoint_ops structure to be used in regular user created
302 struct breakpoint_ops bkpt_breakpoint_ops;
304 /* Breakpoints set on probes. */
305 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
307 /* Dynamic printf class type. */
308 static struct breakpoint_ops dprintf_breakpoint_ops;
310 /* The style in which to perform a dynamic printf. This is a user
311 option because different output options have different tradeoffs;
312 if GDB does the printing, there is better error handling if there
313 is a problem with any of the arguments, but using an inferior
314 function lets you have special-purpose printers and sending of
315 output to the same place as compiled-in print functions. */
317 static const char dprintf_style_gdb[] = "gdb";
318 static const char dprintf_style_call[] = "call";
319 static const char dprintf_style_agent[] = "agent";
320 static const char *const dprintf_style_enums[] = {
326 static const char *dprintf_style = dprintf_style_gdb;
328 /* The function to use for dynamic printf if the preferred style is to
329 call into the inferior. The value is simply a string that is
330 copied into the command, so it can be anything that GDB can
331 evaluate to a callable address, not necessarily a function name. */
333 static char *dprintf_function = "";
335 /* The channel to use for dynamic printf if the preferred style is to
336 call into the inferior; if a nonempty string, it will be passed to
337 the call as the first argument, with the format string as the
338 second. As with the dprintf function, this can be anything that
339 GDB knows how to evaluate, so in addition to common choices like
340 "stderr", this could be an app-specific expression like
341 "mystreams[curlogger]". */
343 static char *dprintf_channel = "";
345 /* True if dprintf commands should continue to operate even if GDB
347 static int disconnected_dprintf = 1;
349 /* A reference-counted struct command_line. This lets multiple
350 breakpoints share a single command list. */
351 struct counted_command_line
353 /* The reference count. */
356 /* The command list. */
357 struct command_line *commands;
360 struct command_line *
361 breakpoint_commands (struct breakpoint *b)
363 return b->commands ? b->commands->commands : NULL;
366 /* Flag indicating that a command has proceeded the inferior past the
367 current breakpoint. */
369 static int breakpoint_proceeded;
372 bpdisp_text (enum bpdisp disp)
374 /* NOTE: the following values are a part of MI protocol and
375 represent values of 'disp' field returned when inferior stops at
377 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
379 return bpdisps[(int) disp];
382 /* Prototypes for exported functions. */
383 /* If FALSE, gdb will not use hardware support for watchpoints, even
384 if such is available. */
385 static int can_use_hw_watchpoints;
388 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
389 struct cmd_list_element *c,
392 fprintf_filtered (file,
393 _("Debugger's willingness to use "
394 "watchpoint hardware is %s.\n"),
398 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
399 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
400 for unrecognized breakpoint locations.
401 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
402 static enum auto_boolean pending_break_support;
404 show_pending_break_support (struct ui_file *file, int from_tty,
405 struct cmd_list_element *c,
408 fprintf_filtered (file,
409 _("Debugger's behavior regarding "
410 "pending breakpoints is %s.\n"),
414 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
415 set with "break" but falling in read-only memory.
416 If 0, gdb will warn about such breakpoints, but won't automatically
417 use hardware breakpoints. */
418 static int automatic_hardware_breakpoints;
420 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
421 struct cmd_list_element *c,
424 fprintf_filtered (file,
425 _("Automatic usage of hardware breakpoints is %s.\n"),
429 /* If on, gdb will keep breakpoints inserted even as inferior is
430 stopped, and immediately insert any new breakpoints. If off, gdb
431 will insert breakpoints into inferior only when resuming it, and
432 will remove breakpoints upon stop. If auto, GDB will behave as ON
433 if in non-stop mode, and as OFF if all-stop mode.*/
435 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
438 show_always_inserted_mode (struct ui_file *file, int from_tty,
439 struct cmd_list_element *c, const char *value)
441 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
442 fprintf_filtered (file,
443 _("Always inserted breakpoint "
444 "mode is %s (currently %s).\n"),
446 breakpoints_always_inserted_mode () ? "on" : "off");
448 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
453 breakpoints_always_inserted_mode (void)
455 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
456 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
459 static const char condition_evaluation_both[] = "host or target";
461 /* Modes for breakpoint condition evaluation. */
462 static const char condition_evaluation_auto[] = "auto";
463 static const char condition_evaluation_host[] = "host";
464 static const char condition_evaluation_target[] = "target";
465 static const char *const condition_evaluation_enums[] = {
466 condition_evaluation_auto,
467 condition_evaluation_host,
468 condition_evaluation_target,
472 /* Global that holds the current mode for breakpoint condition evaluation. */
473 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
475 /* Global that we use to display information to the user (gets its value from
476 condition_evaluation_mode_1. */
477 static const char *condition_evaluation_mode = condition_evaluation_auto;
479 /* Translate a condition evaluation mode MODE into either "host"
480 or "target". This is used mostly to translate from "auto" to the
481 real setting that is being used. It returns the translated
485 translate_condition_evaluation_mode (const char *mode)
487 if (mode == condition_evaluation_auto)
489 if (target_supports_evaluation_of_breakpoint_conditions ())
490 return condition_evaluation_target;
492 return condition_evaluation_host;
498 /* Discovers what condition_evaluation_auto translates to. */
501 breakpoint_condition_evaluation_mode (void)
503 return translate_condition_evaluation_mode (condition_evaluation_mode);
506 /* Return true if GDB should evaluate breakpoint conditions or false
510 gdb_evaluates_breakpoint_condition_p (void)
512 const char *mode = breakpoint_condition_evaluation_mode ();
514 return (mode == condition_evaluation_host);
517 void _initialize_breakpoint (void);
519 /* Are we executing breakpoint commands? */
520 static int executing_breakpoint_commands;
522 /* Are overlay event breakpoints enabled? */
523 static int overlay_events_enabled;
525 /* See description in breakpoint.h. */
526 int target_exact_watchpoints = 0;
528 /* Walk the following statement or block through all breakpoints.
529 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
530 current breakpoint. */
532 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
534 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
535 for (B = breakpoint_chain; \
536 B ? (TMP=B->next, 1): 0; \
539 /* Similar iterator for the low-level breakpoints. SAFE variant is
540 not provided so update_global_location_list must not be called
541 while executing the block of ALL_BP_LOCATIONS. */
543 #define ALL_BP_LOCATIONS(B,BP_TMP) \
544 for (BP_TMP = bp_location; \
545 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
548 /* Iterates through locations with address ADDRESS for the currently selected
549 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
550 to where the loop should start from.
551 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
552 appropriate location to start with. */
554 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
555 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
556 BP_LOCP_TMP = BP_LOCP_START; \
558 && (BP_LOCP_TMP < bp_location + bp_location_count \
559 && (*BP_LOCP_TMP)->address == ADDRESS); \
562 /* Iterator for tracepoints only. */
564 #define ALL_TRACEPOINTS(B) \
565 for (B = breakpoint_chain; B; B = B->next) \
566 if (is_tracepoint (B))
568 /* Chains of all breakpoints defined. */
570 struct breakpoint *breakpoint_chain;
572 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
574 static struct bp_location **bp_location;
576 /* Number of elements of BP_LOCATION. */
578 static unsigned bp_location_count;
580 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
581 ADDRESS for the current elements of BP_LOCATION which get a valid
582 result from bp_location_has_shadow. You can use it for roughly
583 limiting the subrange of BP_LOCATION to scan for shadow bytes for
584 an address you need to read. */
586 static CORE_ADDR bp_location_placed_address_before_address_max;
588 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
589 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
590 BP_LOCATION which get a valid result from bp_location_has_shadow.
591 You can use it for roughly limiting the subrange of BP_LOCATION to
592 scan for shadow bytes for an address you need to read. */
594 static CORE_ADDR bp_location_shadow_len_after_address_max;
596 /* The locations that no longer correspond to any breakpoint, unlinked
597 from bp_location array, but for which a hit may still be reported
599 VEC(bp_location_p) *moribund_locations = NULL;
601 /* Number of last breakpoint made. */
603 static int breakpoint_count;
605 /* The value of `breakpoint_count' before the last command that
606 created breakpoints. If the last (break-like) command created more
607 than one breakpoint, then the difference between BREAKPOINT_COUNT
608 and PREV_BREAKPOINT_COUNT is more than one. */
609 static int prev_breakpoint_count;
611 /* Number of last tracepoint made. */
613 static int tracepoint_count;
615 static struct cmd_list_element *breakpoint_set_cmdlist;
616 static struct cmd_list_element *breakpoint_show_cmdlist;
617 struct cmd_list_element *save_cmdlist;
619 /* Return whether a breakpoint is an active enabled breakpoint. */
621 breakpoint_enabled (struct breakpoint *b)
623 return (b->enable_state == bp_enabled);
626 /* Set breakpoint count to NUM. */
629 set_breakpoint_count (int num)
631 prev_breakpoint_count = breakpoint_count;
632 breakpoint_count = num;
633 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
636 /* Used by `start_rbreak_breakpoints' below, to record the current
637 breakpoint count before "rbreak" creates any breakpoint. */
638 static int rbreak_start_breakpoint_count;
640 /* Called at the start an "rbreak" command to record the first
644 start_rbreak_breakpoints (void)
646 rbreak_start_breakpoint_count = breakpoint_count;
649 /* Called at the end of an "rbreak" command to record the last
653 end_rbreak_breakpoints (void)
655 prev_breakpoint_count = rbreak_start_breakpoint_count;
658 /* Used in run_command to zero the hit count when a new run starts. */
661 clear_breakpoint_hit_counts (void)
663 struct breakpoint *b;
669 /* Allocate a new counted_command_line with reference count of 1.
670 The new structure owns COMMANDS. */
672 static struct counted_command_line *
673 alloc_counted_command_line (struct command_line *commands)
675 struct counted_command_line *result
676 = xmalloc (sizeof (struct counted_command_line));
679 result->commands = commands;
683 /* Increment reference count. This does nothing if CMD is NULL. */
686 incref_counted_command_line (struct counted_command_line *cmd)
692 /* Decrement reference count. If the reference count reaches 0,
693 destroy the counted_command_line. Sets *CMDP to NULL. This does
694 nothing if *CMDP is NULL. */
697 decref_counted_command_line (struct counted_command_line **cmdp)
701 if (--(*cmdp)->refc == 0)
703 free_command_lines (&(*cmdp)->commands);
710 /* A cleanup function that calls decref_counted_command_line. */
713 do_cleanup_counted_command_line (void *arg)
715 decref_counted_command_line (arg);
718 /* Create a cleanup that calls decref_counted_command_line on the
721 static struct cleanup *
722 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
724 return make_cleanup (do_cleanup_counted_command_line, cmdp);
728 /* Return the breakpoint with the specified number, or NULL
729 if the number does not refer to an existing breakpoint. */
732 get_breakpoint (int num)
734 struct breakpoint *b;
737 if (b->number == num)
745 /* Mark locations as "conditions have changed" in case the target supports
746 evaluating conditions on its side. */
749 mark_breakpoint_modified (struct breakpoint *b)
751 struct bp_location *loc;
753 /* This is only meaningful if the target is
754 evaluating conditions and if the user has
755 opted for condition evaluation on the target's
757 if (gdb_evaluates_breakpoint_condition_p ()
758 || !target_supports_evaluation_of_breakpoint_conditions ())
761 if (!is_breakpoint (b))
764 for (loc = b->loc; loc; loc = loc->next)
765 loc->condition_changed = condition_modified;
768 /* Mark location as "conditions have changed" in case the target supports
769 evaluating conditions on its side. */
772 mark_breakpoint_location_modified (struct bp_location *loc)
774 /* This is only meaningful if the target is
775 evaluating conditions and if the user has
776 opted for condition evaluation on the target's
778 if (gdb_evaluates_breakpoint_condition_p ()
779 || !target_supports_evaluation_of_breakpoint_conditions ())
783 if (!is_breakpoint (loc->owner))
786 loc->condition_changed = condition_modified;
789 /* Sets the condition-evaluation mode using the static global
790 condition_evaluation_mode. */
793 set_condition_evaluation_mode (char *args, int from_tty,
794 struct cmd_list_element *c)
796 const char *old_mode, *new_mode;
798 if ((condition_evaluation_mode_1 == condition_evaluation_target)
799 && !target_supports_evaluation_of_breakpoint_conditions ())
801 condition_evaluation_mode_1 = condition_evaluation_mode;
802 warning (_("Target does not support breakpoint condition evaluation.\n"
803 "Using host evaluation mode instead."));
807 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
808 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
810 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
811 settings was "auto". */
812 condition_evaluation_mode = condition_evaluation_mode_1;
814 /* Only update the mode if the user picked a different one. */
815 if (new_mode != old_mode)
817 struct bp_location *loc, **loc_tmp;
818 /* If the user switched to a different evaluation mode, we
819 need to synch the changes with the target as follows:
821 "host" -> "target": Send all (valid) conditions to the target.
822 "target" -> "host": Remove all the conditions from the target.
825 if (new_mode == condition_evaluation_target)
827 /* Mark everything modified and synch conditions with the
829 ALL_BP_LOCATIONS (loc, loc_tmp)
830 mark_breakpoint_location_modified (loc);
834 /* Manually mark non-duplicate locations to synch conditions
835 with the target. We do this to remove all the conditions the
836 target knows about. */
837 ALL_BP_LOCATIONS (loc, loc_tmp)
838 if (is_breakpoint (loc->owner) && loc->inserted)
839 loc->needs_update = 1;
843 update_global_location_list (1);
849 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
850 what "auto" is translating to. */
853 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
854 struct cmd_list_element *c, const char *value)
856 if (condition_evaluation_mode == condition_evaluation_auto)
857 fprintf_filtered (file,
858 _("Breakpoint condition evaluation "
859 "mode is %s (currently %s).\n"),
861 breakpoint_condition_evaluation_mode ());
863 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
867 /* A comparison function for bp_location AP and BP that is used by
868 bsearch. This comparison function only cares about addresses, unlike
869 the more general bp_location_compare function. */
872 bp_location_compare_addrs (const void *ap, const void *bp)
874 struct bp_location *a = *(void **) ap;
875 struct bp_location *b = *(void **) bp;
877 if (a->address == b->address)
880 return ((a->address > b->address) - (a->address < b->address));
883 /* Helper function to skip all bp_locations with addresses
884 less than ADDRESS. It returns the first bp_location that
885 is greater than or equal to ADDRESS. If none is found, just
888 static struct bp_location **
889 get_first_locp_gte_addr (CORE_ADDR address)
891 struct bp_location dummy_loc;
892 struct bp_location *dummy_locp = &dummy_loc;
893 struct bp_location **locp_found = NULL;
895 /* Initialize the dummy location's address field. */
896 memset (&dummy_loc, 0, sizeof (struct bp_location));
897 dummy_loc.address = address;
899 /* Find a close match to the first location at ADDRESS. */
900 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
901 sizeof (struct bp_location **),
902 bp_location_compare_addrs);
904 /* Nothing was found, nothing left to do. */
905 if (locp_found == NULL)
908 /* We may have found a location that is at ADDRESS but is not the first in the
909 location's list. Go backwards (if possible) and locate the first one. */
910 while ((locp_found - 1) >= bp_location
911 && (*(locp_found - 1))->address == address)
918 set_breakpoint_condition (struct breakpoint *b, char *exp,
921 xfree (b->cond_string);
922 b->cond_string = NULL;
924 if (is_watchpoint (b))
926 struct watchpoint *w = (struct watchpoint *) b;
933 struct bp_location *loc;
935 for (loc = b->loc; loc; loc = loc->next)
940 /* No need to free the condition agent expression
941 bytecode (if we have one). We will handle this
942 when we go through update_global_location_list. */
949 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
953 const char *arg = exp;
955 /* I don't know if it matters whether this is the string the user
956 typed in or the decompiled expression. */
957 b->cond_string = xstrdup (arg);
958 b->condition_not_parsed = 0;
960 if (is_watchpoint (b))
962 struct watchpoint *w = (struct watchpoint *) b;
964 innermost_block = NULL;
966 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
968 error (_("Junk at end of expression"));
969 w->cond_exp_valid_block = innermost_block;
973 struct bp_location *loc;
975 for (loc = b->loc; loc; loc = loc->next)
979 parse_exp_1 (&arg, loc->address,
980 block_for_pc (loc->address), 0);
982 error (_("Junk at end of expression"));
986 mark_breakpoint_modified (b);
988 observer_notify_breakpoint_modified (b);
991 /* Completion for the "condition" command. */
993 static VEC (char_ptr) *
994 condition_completer (struct cmd_list_element *cmd,
995 const char *text, const char *word)
999 text = skip_spaces_const (text);
1000 space = skip_to_space_const (text);
1004 struct breakpoint *b;
1005 VEC (char_ptr) *result = NULL;
1009 /* We don't support completion of history indices. */
1010 if (isdigit (text[1]))
1012 return complete_internalvar (&text[1]);
1015 /* We're completing the breakpoint number. */
1016 len = strlen (text);
1020 int single = b->loc->next == NULL;
1021 struct bp_location *loc;
1024 for (loc = b->loc; loc; loc = loc->next)
1029 xsnprintf (location, sizeof (location), "%d", b->number);
1031 xsnprintf (location, sizeof (location), "%d.%d", b->number,
1034 if (strncmp (location, text, len) == 0)
1035 VEC_safe_push (char_ptr, result, xstrdup (location));
1044 /* We're completing the expression part. */
1045 text = skip_spaces_const (space);
1046 return expression_completer (cmd, text, word);
1049 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1052 condition_command (char *arg, int from_tty)
1054 struct breakpoint *b;
1059 error_no_arg (_("breakpoint number"));
1062 bnum = get_number (&p);
1064 error (_("Bad breakpoint argument: '%s'"), arg);
1067 if (b->number == bnum)
1069 /* Check if this breakpoint has a Python object assigned to
1070 it, and if it has a definition of the "stop"
1071 method. This method and conditions entered into GDB from
1072 the CLI are mutually exclusive. */
1074 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1075 error (_("Cannot set a condition where a Python 'stop' "
1076 "method has been defined in the breakpoint."));
1077 set_breakpoint_condition (b, p, from_tty);
1079 if (is_breakpoint (b))
1080 update_global_location_list (1);
1085 error (_("No breakpoint number %d."), bnum);
1088 /* Check that COMMAND do not contain commands that are suitable
1089 only for tracepoints and not suitable for ordinary breakpoints.
1090 Throw if any such commands is found. */
1093 check_no_tracepoint_commands (struct command_line *commands)
1095 struct command_line *c;
1097 for (c = commands; c; c = c->next)
1101 if (c->control_type == while_stepping_control)
1102 error (_("The 'while-stepping' command can "
1103 "only be used for tracepoints"));
1105 for (i = 0; i < c->body_count; ++i)
1106 check_no_tracepoint_commands ((c->body_list)[i]);
1108 /* Not that command parsing removes leading whitespace and comment
1109 lines and also empty lines. So, we only need to check for
1110 command directly. */
1111 if (strstr (c->line, "collect ") == c->line)
1112 error (_("The 'collect' command can only be used for tracepoints"));
1114 if (strstr (c->line, "teval ") == c->line)
1115 error (_("The 'teval' command can only be used for tracepoints"));
1119 /* Encapsulate tests for different types of tracepoints. */
1122 is_tracepoint_type (enum bptype type)
1124 return (type == bp_tracepoint
1125 || type == bp_fast_tracepoint
1126 || type == bp_static_tracepoint);
1130 is_tracepoint (const struct breakpoint *b)
1132 return is_tracepoint_type (b->type);
1135 /* A helper function that validates that COMMANDS are valid for a
1136 breakpoint. This function will throw an exception if a problem is
1140 validate_commands_for_breakpoint (struct breakpoint *b,
1141 struct command_line *commands)
1143 if (is_tracepoint (b))
1145 struct tracepoint *t = (struct tracepoint *) b;
1146 struct command_line *c;
1147 struct command_line *while_stepping = 0;
1149 /* Reset the while-stepping step count. The previous commands
1150 might have included a while-stepping action, while the new
1154 /* We need to verify that each top-level element of commands is
1155 valid for tracepoints, that there's at most one
1156 while-stepping element, and that the while-stepping's body
1157 has valid tracing commands excluding nested while-stepping.
1158 We also need to validate the tracepoint action line in the
1159 context of the tracepoint --- validate_actionline actually
1160 has side effects, like setting the tracepoint's
1161 while-stepping STEP_COUNT, in addition to checking if the
1162 collect/teval actions parse and make sense in the
1163 tracepoint's context. */
1164 for (c = commands; c; c = c->next)
1166 if (c->control_type == while_stepping_control)
1168 if (b->type == bp_fast_tracepoint)
1169 error (_("The 'while-stepping' command "
1170 "cannot be used for fast tracepoint"));
1171 else if (b->type == bp_static_tracepoint)
1172 error (_("The 'while-stepping' command "
1173 "cannot be used for static tracepoint"));
1176 error (_("The 'while-stepping' command "
1177 "can be used only once"));
1182 validate_actionline (c->line, b);
1186 struct command_line *c2;
1188 gdb_assert (while_stepping->body_count == 1);
1189 c2 = while_stepping->body_list[0];
1190 for (; c2; c2 = c2->next)
1192 if (c2->control_type == while_stepping_control)
1193 error (_("The 'while-stepping' command cannot be nested"));
1199 check_no_tracepoint_commands (commands);
1203 /* Return a vector of all the static tracepoints set at ADDR. The
1204 caller is responsible for releasing the vector. */
1207 static_tracepoints_here (CORE_ADDR addr)
1209 struct breakpoint *b;
1210 VEC(breakpoint_p) *found = 0;
1211 struct bp_location *loc;
1214 if (b->type == bp_static_tracepoint)
1216 for (loc = b->loc; loc; loc = loc->next)
1217 if (loc->address == addr)
1218 VEC_safe_push(breakpoint_p, found, b);
1224 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1225 validate that only allowed commands are included. */
1228 breakpoint_set_commands (struct breakpoint *b,
1229 struct command_line *commands)
1231 validate_commands_for_breakpoint (b, commands);
1233 decref_counted_command_line (&b->commands);
1234 b->commands = alloc_counted_command_line (commands);
1235 observer_notify_breakpoint_modified (b);
1238 /* Set the internal `silent' flag on the breakpoint. Note that this
1239 is not the same as the "silent" that may appear in the breakpoint's
1243 breakpoint_set_silent (struct breakpoint *b, int silent)
1245 int old_silent = b->silent;
1248 if (old_silent != silent)
1249 observer_notify_breakpoint_modified (b);
1252 /* Set the thread for this breakpoint. If THREAD is -1, make the
1253 breakpoint work for any thread. */
1256 breakpoint_set_thread (struct breakpoint *b, int thread)
1258 int old_thread = b->thread;
1261 if (old_thread != thread)
1262 observer_notify_breakpoint_modified (b);
1265 /* Set the task for this breakpoint. If TASK is 0, make the
1266 breakpoint work for any task. */
1269 breakpoint_set_task (struct breakpoint *b, int task)
1271 int old_task = b->task;
1274 if (old_task != task)
1275 observer_notify_breakpoint_modified (b);
1279 check_tracepoint_command (char *line, void *closure)
1281 struct breakpoint *b = closure;
1283 validate_actionline (line, b);
1286 /* A structure used to pass information through
1287 map_breakpoint_numbers. */
1289 struct commands_info
1291 /* True if the command was typed at a tty. */
1294 /* The breakpoint range spec. */
1297 /* Non-NULL if the body of the commands are being read from this
1298 already-parsed command. */
1299 struct command_line *control;
1301 /* The command lines read from the user, or NULL if they have not
1303 struct counted_command_line *cmd;
1306 /* A callback for map_breakpoint_numbers that sets the commands for
1307 commands_command. */
1310 do_map_commands_command (struct breakpoint *b, void *data)
1312 struct commands_info *info = data;
1314 if (info->cmd == NULL)
1316 struct command_line *l;
1318 if (info->control != NULL)
1319 l = copy_command_lines (info->control->body_list[0]);
1322 struct cleanup *old_chain;
1325 str = xstrprintf (_("Type commands for breakpoint(s) "
1326 "%s, one per line."),
1329 old_chain = make_cleanup (xfree, str);
1331 l = read_command_lines (str,
1334 ? check_tracepoint_command : 0),
1337 do_cleanups (old_chain);
1340 info->cmd = alloc_counted_command_line (l);
1343 /* If a breakpoint was on the list more than once, we don't need to
1345 if (b->commands != info->cmd)
1347 validate_commands_for_breakpoint (b, info->cmd->commands);
1348 incref_counted_command_line (info->cmd);
1349 decref_counted_command_line (&b->commands);
1350 b->commands = info->cmd;
1351 observer_notify_breakpoint_modified (b);
1356 commands_command_1 (char *arg, int from_tty,
1357 struct command_line *control)
1359 struct cleanup *cleanups;
1360 struct commands_info info;
1362 info.from_tty = from_tty;
1363 info.control = control;
1365 /* If we read command lines from the user, then `info' will hold an
1366 extra reference to the commands that we must clean up. */
1367 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1369 if (arg == NULL || !*arg)
1371 if (breakpoint_count - prev_breakpoint_count > 1)
1372 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1374 else if (breakpoint_count > 0)
1375 arg = xstrprintf ("%d", breakpoint_count);
1378 /* So that we don't try to free the incoming non-NULL
1379 argument in the cleanup below. Mapping breakpoint
1380 numbers will fail in this case. */
1385 /* The command loop has some static state, so we need to preserve
1387 arg = xstrdup (arg);
1390 make_cleanup (xfree, arg);
1394 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1396 if (info.cmd == NULL)
1397 error (_("No breakpoints specified."));
1399 do_cleanups (cleanups);
1403 commands_command (char *arg, int from_tty)
1405 commands_command_1 (arg, from_tty, NULL);
1408 /* Like commands_command, but instead of reading the commands from
1409 input stream, takes them from an already parsed command structure.
1411 This is used by cli-script.c to DTRT with breakpoint commands
1412 that are part of if and while bodies. */
1413 enum command_control_type
1414 commands_from_control_command (char *arg, struct command_line *cmd)
1416 commands_command_1 (arg, 0, cmd);
1417 return simple_control;
1420 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1423 bp_location_has_shadow (struct bp_location *bl)
1425 if (bl->loc_type != bp_loc_software_breakpoint)
1429 if (bl->target_info.shadow_len == 0)
1430 /* BL isn't valid, or doesn't shadow memory. */
1435 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1436 by replacing any memory breakpoints with their shadowed contents.
1438 If READBUF is not NULL, this buffer must not overlap with any of
1439 the breakpoint location's shadow_contents buffers. Otherwise,
1440 a failed assertion internal error will be raised.
1442 The range of shadowed area by each bp_location is:
1443 bl->address - bp_location_placed_address_before_address_max
1444 up to bl->address + bp_location_shadow_len_after_address_max
1445 The range we were requested to resolve shadows for is:
1446 memaddr ... memaddr + len
1447 Thus the safe cutoff boundaries for performance optimization are
1448 memaddr + len <= (bl->address
1449 - bp_location_placed_address_before_address_max)
1451 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1454 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1455 const gdb_byte *writebuf_org,
1456 ULONGEST memaddr, LONGEST len)
1458 /* Left boundary, right boundary and median element of our binary
1460 unsigned bc_l, bc_r, bc;
1462 /* Find BC_L which is a leftmost element which may affect BUF
1463 content. It is safe to report lower value but a failure to
1464 report higher one. */
1467 bc_r = bp_location_count;
1468 while (bc_l + 1 < bc_r)
1470 struct bp_location *bl;
1472 bc = (bc_l + bc_r) / 2;
1473 bl = bp_location[bc];
1475 /* Check first BL->ADDRESS will not overflow due to the added
1476 constant. Then advance the left boundary only if we are sure
1477 the BC element can in no way affect the BUF content (MEMADDR
1478 to MEMADDR + LEN range).
1480 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1481 offset so that we cannot miss a breakpoint with its shadow
1482 range tail still reaching MEMADDR. */
1484 if ((bl->address + bp_location_shadow_len_after_address_max
1486 && (bl->address + bp_location_shadow_len_after_address_max
1493 /* Due to the binary search above, we need to make sure we pick the
1494 first location that's at BC_L's address. E.g., if there are
1495 multiple locations at the same address, BC_L may end up pointing
1496 at a duplicate location, and miss the "master"/"inserted"
1497 location. Say, given locations L1, L2 and L3 at addresses A and
1500 L1@A, L2@A, L3@B, ...
1502 BC_L could end up pointing at location L2, while the "master"
1503 location could be L1. Since the `loc->inserted' flag is only set
1504 on "master" locations, we'd forget to restore the shadow of L1
1507 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1510 /* Now do full processing of the found relevant range of elements. */
1512 for (bc = bc_l; bc < bp_location_count; bc++)
1514 struct bp_location *bl = bp_location[bc];
1515 CORE_ADDR bp_addr = 0;
1519 /* bp_location array has BL->OWNER always non-NULL. */
1520 if (bl->owner->type == bp_none)
1521 warning (_("reading through apparently deleted breakpoint #%d?"),
1524 /* Performance optimization: any further element can no longer affect BUF
1527 if (bl->address >= bp_location_placed_address_before_address_max
1528 && memaddr + len <= (bl->address
1529 - bp_location_placed_address_before_address_max))
1532 if (!bp_location_has_shadow (bl))
1534 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1535 current_program_space->aspace, 0))
1538 /* Addresses and length of the part of the breakpoint that
1540 bp_addr = bl->target_info.placed_address;
1541 bp_size = bl->target_info.shadow_len;
1543 if (bp_addr + bp_size <= memaddr)
1544 /* The breakpoint is entirely before the chunk of memory we
1548 if (bp_addr >= memaddr + len)
1549 /* The breakpoint is entirely after the chunk of memory we are
1553 /* Offset within shadow_contents. */
1554 if (bp_addr < memaddr)
1556 /* Only copy the second part of the breakpoint. */
1557 bp_size -= memaddr - bp_addr;
1558 bptoffset = memaddr - bp_addr;
1562 if (bp_addr + bp_size > memaddr + len)
1564 /* Only copy the first part of the breakpoint. */
1565 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1568 if (readbuf != NULL)
1570 /* Verify that the readbuf buffer does not overlap with
1571 the shadow_contents buffer. */
1572 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1573 || readbuf >= (bl->target_info.shadow_contents
1574 + bl->target_info.shadow_len));
1576 /* Update the read buffer with this inserted breakpoint's
1578 memcpy (readbuf + bp_addr - memaddr,
1579 bl->target_info.shadow_contents + bptoffset, bp_size);
1583 struct gdbarch *gdbarch = bl->gdbarch;
1584 const unsigned char *bp;
1585 CORE_ADDR placed_address = bl->target_info.placed_address;
1586 int placed_size = bl->target_info.placed_size;
1588 /* Update the shadow with what we want to write to memory. */
1589 memcpy (bl->target_info.shadow_contents + bptoffset,
1590 writebuf_org + bp_addr - memaddr, bp_size);
1592 /* Determine appropriate breakpoint contents and size for this
1594 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1596 /* Update the final write buffer with this inserted
1597 breakpoint's INSN. */
1598 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1604 /* Return true if BPT is either a software breakpoint or a hardware
1608 is_breakpoint (const struct breakpoint *bpt)
1610 return (bpt->type == bp_breakpoint
1611 || bpt->type == bp_hardware_breakpoint
1612 || bpt->type == bp_dprintf);
1615 /* Return true if BPT is of any hardware watchpoint kind. */
1618 is_hardware_watchpoint (const struct breakpoint *bpt)
1620 return (bpt->type == bp_hardware_watchpoint
1621 || bpt->type == bp_read_watchpoint
1622 || bpt->type == bp_access_watchpoint);
1625 /* Return true if BPT is of any watchpoint kind, hardware or
1629 is_watchpoint (const struct breakpoint *bpt)
1631 return (is_hardware_watchpoint (bpt)
1632 || bpt->type == bp_watchpoint);
1635 /* Returns true if the current thread and its running state are safe
1636 to evaluate or update watchpoint B. Watchpoints on local
1637 expressions need to be evaluated in the context of the thread that
1638 was current when the watchpoint was created, and, that thread needs
1639 to be stopped to be able to select the correct frame context.
1640 Watchpoints on global expressions can be evaluated on any thread,
1641 and in any state. It is presently left to the target allowing
1642 memory accesses when threads are running. */
1645 watchpoint_in_thread_scope (struct watchpoint *b)
1647 return (b->base.pspace == current_program_space
1648 && (ptid_equal (b->watchpoint_thread, null_ptid)
1649 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1650 && !is_executing (inferior_ptid))));
1653 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1654 associated bp_watchpoint_scope breakpoint. */
1657 watchpoint_del_at_next_stop (struct watchpoint *w)
1659 struct breakpoint *b = &w->base;
1661 if (b->related_breakpoint != b)
1663 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1664 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1665 b->related_breakpoint->disposition = disp_del_at_next_stop;
1666 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1667 b->related_breakpoint = b;
1669 b->disposition = disp_del_at_next_stop;
1672 /* Assuming that B is a watchpoint:
1673 - Reparse watchpoint expression, if REPARSE is non-zero
1674 - Evaluate expression and store the result in B->val
1675 - Evaluate the condition if there is one, and store the result
1677 - Update the list of values that must be watched in B->loc.
1679 If the watchpoint disposition is disp_del_at_next_stop, then do
1680 nothing. If this is local watchpoint that is out of scope, delete
1683 Even with `set breakpoint always-inserted on' the watchpoints are
1684 removed + inserted on each stop here. Normal breakpoints must
1685 never be removed because they might be missed by a running thread
1686 when debugging in non-stop mode. On the other hand, hardware
1687 watchpoints (is_hardware_watchpoint; processed here) are specific
1688 to each LWP since they are stored in each LWP's hardware debug
1689 registers. Therefore, such LWP must be stopped first in order to
1690 be able to modify its hardware watchpoints.
1692 Hardware watchpoints must be reset exactly once after being
1693 presented to the user. It cannot be done sooner, because it would
1694 reset the data used to present the watchpoint hit to the user. And
1695 it must not be done later because it could display the same single
1696 watchpoint hit during multiple GDB stops. Note that the latter is
1697 relevant only to the hardware watchpoint types bp_read_watchpoint
1698 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1699 not user-visible - its hit is suppressed if the memory content has
1702 The following constraints influence the location where we can reset
1703 hardware watchpoints:
1705 * target_stopped_by_watchpoint and target_stopped_data_address are
1706 called several times when GDB stops.
1709 * Multiple hardware watchpoints can be hit at the same time,
1710 causing GDB to stop. GDB only presents one hardware watchpoint
1711 hit at a time as the reason for stopping, and all the other hits
1712 are presented later, one after the other, each time the user
1713 requests the execution to be resumed. Execution is not resumed
1714 for the threads still having pending hit event stored in
1715 LWP_INFO->STATUS. While the watchpoint is already removed from
1716 the inferior on the first stop the thread hit event is kept being
1717 reported from its cached value by linux_nat_stopped_data_address
1718 until the real thread resume happens after the watchpoint gets
1719 presented and thus its LWP_INFO->STATUS gets reset.
1721 Therefore the hardware watchpoint hit can get safely reset on the
1722 watchpoint removal from inferior. */
1725 update_watchpoint (struct watchpoint *b, int reparse)
1727 int within_current_scope;
1728 struct frame_id saved_frame_id;
1731 /* If this is a local watchpoint, we only want to check if the
1732 watchpoint frame is in scope if the current thread is the thread
1733 that was used to create the watchpoint. */
1734 if (!watchpoint_in_thread_scope (b))
1737 if (b->base.disposition == disp_del_at_next_stop)
1742 /* Determine if the watchpoint is within scope. */
1743 if (b->exp_valid_block == NULL)
1744 within_current_scope = 1;
1747 struct frame_info *fi = get_current_frame ();
1748 struct gdbarch *frame_arch = get_frame_arch (fi);
1749 CORE_ADDR frame_pc = get_frame_pc (fi);
1751 /* If we're in a function epilogue, unwinding may not work
1752 properly, so do not attempt to recreate locations at this
1753 point. See similar comments in watchpoint_check. */
1754 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1757 /* Save the current frame's ID so we can restore it after
1758 evaluating the watchpoint expression on its own frame. */
1759 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1760 took a frame parameter, so that we didn't have to change the
1763 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1765 fi = frame_find_by_id (b->watchpoint_frame);
1766 within_current_scope = (fi != NULL);
1767 if (within_current_scope)
1771 /* We don't free locations. They are stored in the bp_location array
1772 and update_global_location_list will eventually delete them and
1773 remove breakpoints if needed. */
1776 if (within_current_scope && reparse)
1785 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1786 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1787 /* If the meaning of expression itself changed, the old value is
1788 no longer relevant. We don't want to report a watchpoint hit
1789 to the user when the old value and the new value may actually
1790 be completely different objects. */
1791 value_free (b->val);
1795 /* Note that unlike with breakpoints, the watchpoint's condition
1796 expression is stored in the breakpoint object, not in the
1797 locations (re)created below. */
1798 if (b->base.cond_string != NULL)
1800 if (b->cond_exp != NULL)
1802 xfree (b->cond_exp);
1806 s = b->base.cond_string;
1807 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1811 /* If we failed to parse the expression, for example because
1812 it refers to a global variable in a not-yet-loaded shared library,
1813 don't try to insert watchpoint. We don't automatically delete
1814 such watchpoint, though, since failure to parse expression
1815 is different from out-of-scope watchpoint. */
1816 if ( !target_has_execution)
1818 /* Without execution, memory can't change. No use to try and
1819 set watchpoint locations. The watchpoint will be reset when
1820 the target gains execution, through breakpoint_re_set. */
1822 else if (within_current_scope && b->exp)
1825 struct value *val_chain, *v, *result, *next;
1826 struct program_space *frame_pspace;
1828 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1830 /* Avoid setting b->val if it's already set. The meaning of
1831 b->val is 'the last value' user saw, and we should update
1832 it only if we reported that last value to user. As it
1833 happens, the code that reports it updates b->val directly.
1834 We don't keep track of the memory value for masked
1836 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1842 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1844 /* Look at each value on the value chain. */
1845 for (v = val_chain; v; v = value_next (v))
1847 /* If it's a memory location, and GDB actually needed
1848 its contents to evaluate the expression, then we
1849 must watch it. If the first value returned is
1850 still lazy, that means an error occurred reading it;
1851 watch it anyway in case it becomes readable. */
1852 if (VALUE_LVAL (v) == lval_memory
1853 && (v == val_chain || ! value_lazy (v)))
1855 struct type *vtype = check_typedef (value_type (v));
1857 /* We only watch structs and arrays if user asked
1858 for it explicitly, never if they just happen to
1859 appear in the middle of some value chain. */
1861 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1862 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1866 struct bp_location *loc, **tmp;
1868 addr = value_address (v);
1870 if (b->base.type == bp_read_watchpoint)
1872 else if (b->base.type == bp_access_watchpoint)
1875 loc = allocate_bp_location (&b->base);
1876 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1879 loc->gdbarch = get_type_arch (value_type (v));
1881 loc->pspace = frame_pspace;
1882 loc->address = addr;
1883 loc->length = TYPE_LENGTH (value_type (v));
1884 loc->watchpoint_type = type;
1889 /* Change the type of breakpoint between hardware assisted or
1890 an ordinary watchpoint depending on the hardware support
1891 and free hardware slots. REPARSE is set when the inferior
1896 enum bp_loc_type loc_type;
1897 struct bp_location *bl;
1899 reg_cnt = can_use_hardware_watchpoint (val_chain);
1903 int i, target_resources_ok, other_type_used;
1906 /* Use an exact watchpoint when there's only one memory region to be
1907 watched, and only one debug register is needed to watch it. */
1908 b->exact = target_exact_watchpoints && reg_cnt == 1;
1910 /* We need to determine how many resources are already
1911 used for all other hardware watchpoints plus this one
1912 to see if we still have enough resources to also fit
1913 this watchpoint in as well. */
1915 /* If this is a software watchpoint, we try to turn it
1916 to a hardware one -- count resources as if B was of
1917 hardware watchpoint type. */
1918 type = b->base.type;
1919 if (type == bp_watchpoint)
1920 type = bp_hardware_watchpoint;
1922 /* This watchpoint may or may not have been placed on
1923 the list yet at this point (it won't be in the list
1924 if we're trying to create it for the first time,
1925 through watch_command), so always account for it
1928 /* Count resources used by all watchpoints except B. */
1929 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1931 /* Add in the resources needed for B. */
1932 i += hw_watchpoint_use_count (&b->base);
1935 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1936 if (target_resources_ok <= 0)
1938 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1940 if (target_resources_ok == 0 && !sw_mode)
1941 error (_("Target does not support this type of "
1942 "hardware watchpoint."));
1943 else if (target_resources_ok < 0 && !sw_mode)
1944 error (_("There are not enough available hardware "
1945 "resources for this watchpoint."));
1947 /* Downgrade to software watchpoint. */
1948 b->base.type = bp_watchpoint;
1952 /* If this was a software watchpoint, we've just
1953 found we have enough resources to turn it to a
1954 hardware watchpoint. Otherwise, this is a
1956 b->base.type = type;
1959 else if (!b->base.ops->works_in_software_mode (&b->base))
1960 error (_("Expression cannot be implemented with "
1961 "read/access watchpoint."));
1963 b->base.type = bp_watchpoint;
1965 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1966 : bp_loc_hardware_watchpoint);
1967 for (bl = b->base.loc; bl; bl = bl->next)
1968 bl->loc_type = loc_type;
1971 for (v = val_chain; v; v = next)
1973 next = value_next (v);
1978 /* If a software watchpoint is not watching any memory, then the
1979 above left it without any location set up. But,
1980 bpstat_stop_status requires a location to be able to report
1981 stops, so make sure there's at least a dummy one. */
1982 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1984 struct breakpoint *base = &b->base;
1985 base->loc = allocate_bp_location (base);
1986 base->loc->pspace = frame_pspace;
1987 base->loc->address = -1;
1988 base->loc->length = -1;
1989 base->loc->watchpoint_type = -1;
1992 else if (!within_current_scope)
1994 printf_filtered (_("\
1995 Watchpoint %d deleted because the program has left the block\n\
1996 in which its expression is valid.\n"),
1998 watchpoint_del_at_next_stop (b);
2001 /* Restore the selected frame. */
2003 select_frame (frame_find_by_id (saved_frame_id));
2007 /* Returns 1 iff breakpoint location should be
2008 inserted in the inferior. We don't differentiate the type of BL's owner
2009 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2010 breakpoint_ops is not defined, because in insert_bp_location,
2011 tracepoint's insert_location will not be called. */
2013 should_be_inserted (struct bp_location *bl)
2015 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2018 if (bl->owner->disposition == disp_del_at_next_stop)
2021 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2024 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2027 /* This is set for example, when we're attached to the parent of a
2028 vfork, and have detached from the child. The child is running
2029 free, and we expect it to do an exec or exit, at which point the
2030 OS makes the parent schedulable again (and the target reports
2031 that the vfork is done). Until the child is done with the shared
2032 memory region, do not insert breakpoints in the parent, otherwise
2033 the child could still trip on the parent's breakpoints. Since
2034 the parent is blocked anyway, it won't miss any breakpoint. */
2035 if (bl->pspace->breakpoints_not_allowed)
2041 /* Same as should_be_inserted but does the check assuming
2042 that the location is not duplicated. */
2045 unduplicated_should_be_inserted (struct bp_location *bl)
2048 const int save_duplicate = bl->duplicate;
2051 result = should_be_inserted (bl);
2052 bl->duplicate = save_duplicate;
2056 /* Parses a conditional described by an expression COND into an
2057 agent expression bytecode suitable for evaluation
2058 by the bytecode interpreter. Return NULL if there was
2059 any error during parsing. */
2061 static struct agent_expr *
2062 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2064 struct agent_expr *aexpr = NULL;
2065 volatile struct gdb_exception ex;
2070 /* We don't want to stop processing, so catch any errors
2071 that may show up. */
2072 TRY_CATCH (ex, RETURN_MASK_ERROR)
2074 aexpr = gen_eval_for_expr (scope, cond);
2079 /* If we got here, it means the condition could not be parsed to a valid
2080 bytecode expression and thus can't be evaluated on the target's side.
2081 It's no use iterating through the conditions. */
2085 /* We have a valid agent expression. */
2089 /* Based on location BL, create a list of breakpoint conditions to be
2090 passed on to the target. If we have duplicated locations with different
2091 conditions, we will add such conditions to the list. The idea is that the
2092 target will evaluate the list of conditions and will only notify GDB when
2093 one of them is true. */
2096 build_target_condition_list (struct bp_location *bl)
2098 struct bp_location **locp = NULL, **loc2p;
2099 int null_condition_or_parse_error = 0;
2100 int modified = bl->needs_update;
2101 struct bp_location *loc;
2103 /* This is only meaningful if the target is
2104 evaluating conditions and if the user has
2105 opted for condition evaluation on the target's
2107 if (gdb_evaluates_breakpoint_condition_p ()
2108 || !target_supports_evaluation_of_breakpoint_conditions ())
2111 /* Do a first pass to check for locations with no assigned
2112 conditions or conditions that fail to parse to a valid agent expression
2113 bytecode. If any of these happen, then it's no use to send conditions
2114 to the target since this location will always trigger and generate a
2115 response back to GDB. */
2116 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2119 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2123 struct agent_expr *aexpr;
2125 /* Re-parse the conditions since something changed. In that
2126 case we already freed the condition bytecodes (see
2127 force_breakpoint_reinsertion). We just
2128 need to parse the condition to bytecodes again. */
2129 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2130 loc->cond_bytecode = aexpr;
2132 /* Check if we managed to parse the conditional expression
2133 correctly. If not, we will not send this condition
2139 /* If we have a NULL bytecode expression, it means something
2140 went wrong or we have a null condition expression. */
2141 if (!loc->cond_bytecode)
2143 null_condition_or_parse_error = 1;
2149 /* If any of these happened, it means we will have to evaluate the conditions
2150 for the location's address on gdb's side. It is no use keeping bytecodes
2151 for all the other duplicate locations, thus we free all of them here.
2153 This is so we have a finer control over which locations' conditions are
2154 being evaluated by GDB or the remote stub. */
2155 if (null_condition_or_parse_error)
2157 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2160 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2162 /* Only go as far as the first NULL bytecode is
2164 if (!loc->cond_bytecode)
2167 free_agent_expr (loc->cond_bytecode);
2168 loc->cond_bytecode = NULL;
2173 /* No NULL conditions or failed bytecode generation. Build a condition list
2174 for this location's address. */
2175 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2179 && is_breakpoint (loc->owner)
2180 && loc->pspace->num == bl->pspace->num
2181 && loc->owner->enable_state == bp_enabled
2183 /* Add the condition to the vector. This will be used later to send the
2184 conditions to the target. */
2185 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2186 loc->cond_bytecode);
2192 /* Parses a command described by string CMD into an agent expression
2193 bytecode suitable for evaluation by the bytecode interpreter.
2194 Return NULL if there was any error during parsing. */
2196 static struct agent_expr *
2197 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2199 struct cleanup *old_cleanups = 0;
2200 struct expression *expr, **argvec;
2201 struct agent_expr *aexpr = NULL;
2202 volatile struct gdb_exception ex;
2203 const char *cmdrest;
2204 const char *format_start, *format_end;
2205 struct format_piece *fpieces;
2207 struct gdbarch *gdbarch = get_current_arch ();
2214 if (*cmdrest == ',')
2216 cmdrest = skip_spaces_const (cmdrest);
2218 if (*cmdrest++ != '"')
2219 error (_("No format string following the location"));
2221 format_start = cmdrest;
2223 fpieces = parse_format_string (&cmdrest);
2225 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2227 format_end = cmdrest;
2229 if (*cmdrest++ != '"')
2230 error (_("Bad format string, non-terminated '\"'."));
2232 cmdrest = skip_spaces_const (cmdrest);
2234 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2235 error (_("Invalid argument syntax"));
2237 if (*cmdrest == ',')
2239 cmdrest = skip_spaces_const (cmdrest);
2241 /* For each argument, make an expression. */
2243 argvec = (struct expression **) alloca (strlen (cmd)
2244 * sizeof (struct expression *));
2247 while (*cmdrest != '\0')
2252 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2253 argvec[nargs++] = expr;
2255 if (*cmdrest == ',')
2259 /* We don't want to stop processing, so catch any errors
2260 that may show up. */
2261 TRY_CATCH (ex, RETURN_MASK_ERROR)
2263 aexpr = gen_printf (scope, gdbarch, 0, 0,
2264 format_start, format_end - format_start,
2265 fpieces, nargs, argvec);
2270 /* If we got here, it means the command could not be parsed to a valid
2271 bytecode expression and thus can't be evaluated on the target's side.
2272 It's no use iterating through the other commands. */
2276 do_cleanups (old_cleanups);
2278 /* We have a valid agent expression, return it. */
2282 /* Based on location BL, create a list of breakpoint commands to be
2283 passed on to the target. If we have duplicated locations with
2284 different commands, we will add any such to the list. */
2287 build_target_command_list (struct bp_location *bl)
2289 struct bp_location **locp = NULL, **loc2p;
2290 int null_command_or_parse_error = 0;
2291 int modified = bl->needs_update;
2292 struct bp_location *loc;
2294 /* For now, limit to agent-style dprintf breakpoints. */
2295 if (bl->owner->type != bp_dprintf
2296 || strcmp (dprintf_style, dprintf_style_agent) != 0)
2299 if (!target_can_run_breakpoint_commands ())
2302 /* Do a first pass to check for locations with no assigned
2303 conditions or conditions that fail to parse to a valid agent expression
2304 bytecode. If any of these happen, then it's no use to send conditions
2305 to the target since this location will always trigger and generate a
2306 response back to GDB. */
2307 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2310 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2314 struct agent_expr *aexpr;
2316 /* Re-parse the commands since something changed. In that
2317 case we already freed the command bytecodes (see
2318 force_breakpoint_reinsertion). We just
2319 need to parse the command to bytecodes again. */
2320 aexpr = parse_cmd_to_aexpr (bl->address,
2321 loc->owner->extra_string);
2322 loc->cmd_bytecode = aexpr;
2328 /* If we have a NULL bytecode expression, it means something
2329 went wrong or we have a null command expression. */
2330 if (!loc->cmd_bytecode)
2332 null_command_or_parse_error = 1;
2338 /* If anything failed, then we're not doing target-side commands,
2340 if (null_command_or_parse_error)
2342 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2345 if (is_breakpoint (loc->owner)
2346 && loc->pspace->num == bl->pspace->num)
2348 /* Only go as far as the first NULL bytecode is
2350 if (!loc->cond_bytecode)
2353 free_agent_expr (loc->cond_bytecode);
2354 loc->cond_bytecode = NULL;
2359 /* No NULL commands or failed bytecode generation. Build a command list
2360 for this location's address. */
2361 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2364 if (loc->owner->extra_string
2365 && is_breakpoint (loc->owner)
2366 && loc->pspace->num == bl->pspace->num
2367 && loc->owner->enable_state == bp_enabled
2369 /* Add the command to the vector. This will be used later
2370 to send the commands to the target. */
2371 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2375 bl->target_info.persist = 0;
2376 /* Maybe flag this location as persistent. */
2377 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2378 bl->target_info.persist = 1;
2381 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2382 location. Any error messages are printed to TMP_ERROR_STREAM; and
2383 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2384 Returns 0 for success, 1 if the bp_location type is not supported or
2387 NOTE drow/2003-09-09: This routine could be broken down to an
2388 object-style method for each breakpoint or catchpoint type. */
2390 insert_bp_location (struct bp_location *bl,
2391 struct ui_file *tmp_error_stream,
2392 int *disabled_breaks,
2393 int *hw_breakpoint_error,
2394 int *hw_bp_error_explained_already)
2397 char *hw_bp_err_string = NULL;
2398 struct gdb_exception e;
2400 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2403 /* Note we don't initialize bl->target_info, as that wipes out
2404 the breakpoint location's shadow_contents if the breakpoint
2405 is still inserted at that location. This in turn breaks
2406 target_read_memory which depends on these buffers when
2407 a memory read is requested at the breakpoint location:
2408 Once the target_info has been wiped, we fail to see that
2409 we have a breakpoint inserted at that address and thus
2410 read the breakpoint instead of returning the data saved in
2411 the breakpoint location's shadow contents. */
2412 bl->target_info.placed_address = bl->address;
2413 bl->target_info.placed_address_space = bl->pspace->aspace;
2414 bl->target_info.length = bl->length;
2416 /* When working with target-side conditions, we must pass all the conditions
2417 for the same breakpoint address down to the target since GDB will not
2418 insert those locations. With a list of breakpoint conditions, the target
2419 can decide when to stop and notify GDB. */
2421 if (is_breakpoint (bl->owner))
2423 build_target_condition_list (bl);
2424 build_target_command_list (bl);
2425 /* Reset the modification marker. */
2426 bl->needs_update = 0;
2429 if (bl->loc_type == bp_loc_software_breakpoint
2430 || bl->loc_type == bp_loc_hardware_breakpoint)
2432 if (bl->owner->type != bp_hardware_breakpoint)
2434 /* If the explicitly specified breakpoint type
2435 is not hardware breakpoint, check the memory map to see
2436 if the breakpoint address is in read only memory or not.
2438 Two important cases are:
2439 - location type is not hardware breakpoint, memory
2440 is readonly. We change the type of the location to
2441 hardware breakpoint.
2442 - location type is hardware breakpoint, memory is
2443 read-write. This means we've previously made the
2444 location hardware one, but then the memory map changed,
2447 When breakpoints are removed, remove_breakpoints will use
2448 location types we've just set here, the only possible
2449 problem is that memory map has changed during running
2450 program, but it's not going to work anyway with current
2452 struct mem_region *mr
2453 = lookup_mem_region (bl->target_info.placed_address);
2457 if (automatic_hardware_breakpoints)
2459 enum bp_loc_type new_type;
2461 if (mr->attrib.mode != MEM_RW)
2462 new_type = bp_loc_hardware_breakpoint;
2464 new_type = bp_loc_software_breakpoint;
2466 if (new_type != bl->loc_type)
2468 static int said = 0;
2470 bl->loc_type = new_type;
2473 fprintf_filtered (gdb_stdout,
2474 _("Note: automatically using "
2475 "hardware breakpoints for "
2476 "read-only addresses.\n"));
2481 else if (bl->loc_type == bp_loc_software_breakpoint
2482 && mr->attrib.mode != MEM_RW)
2483 warning (_("cannot set software breakpoint "
2484 "at readonly address %s"),
2485 paddress (bl->gdbarch, bl->address));
2489 /* First check to see if we have to handle an overlay. */
2490 if (overlay_debugging == ovly_off
2491 || bl->section == NULL
2492 || !(section_is_overlay (bl->section)))
2494 /* No overlay handling: just set the breakpoint. */
2495 TRY_CATCH (e, RETURN_MASK_ALL)
2497 val = bl->owner->ops->insert_location (bl);
2502 hw_bp_err_string = (char *) e.message;
2507 /* This breakpoint is in an overlay section.
2508 Shall we set a breakpoint at the LMA? */
2509 if (!overlay_events_enabled)
2511 /* Yes -- overlay event support is not active,
2512 so we must try to set a breakpoint at the LMA.
2513 This will not work for a hardware breakpoint. */
2514 if (bl->loc_type == bp_loc_hardware_breakpoint)
2515 warning (_("hardware breakpoint %d not supported in overlay!"),
2519 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2521 /* Set a software (trap) breakpoint at the LMA. */
2522 bl->overlay_target_info = bl->target_info;
2523 bl->overlay_target_info.placed_address = addr;
2524 val = target_insert_breakpoint (bl->gdbarch,
2525 &bl->overlay_target_info);
2527 fprintf_unfiltered (tmp_error_stream,
2528 "Overlay breakpoint %d "
2529 "failed: in ROM?\n",
2533 /* Shall we set a breakpoint at the VMA? */
2534 if (section_is_mapped (bl->section))
2536 /* Yes. This overlay section is mapped into memory. */
2537 TRY_CATCH (e, RETURN_MASK_ALL)
2539 val = bl->owner->ops->insert_location (bl);
2544 hw_bp_err_string = (char *) e.message;
2549 /* No. This breakpoint will not be inserted.
2550 No error, but do not mark the bp as 'inserted'. */
2557 /* Can't set the breakpoint. */
2558 if (solib_name_from_address (bl->pspace, bl->address))
2560 /* See also: disable_breakpoints_in_shlibs. */
2562 bl->shlib_disabled = 1;
2563 observer_notify_breakpoint_modified (bl->owner);
2564 if (!*disabled_breaks)
2566 fprintf_unfiltered (tmp_error_stream,
2567 "Cannot insert breakpoint %d.\n",
2569 fprintf_unfiltered (tmp_error_stream,
2570 "Temporarily disabling shared "
2571 "library breakpoints:\n");
2573 *disabled_breaks = 1;
2574 fprintf_unfiltered (tmp_error_stream,
2575 "breakpoint #%d\n", bl->owner->number);
2579 if (bl->loc_type == bp_loc_hardware_breakpoint)
2581 *hw_breakpoint_error = 1;
2582 *hw_bp_error_explained_already = hw_bp_err_string != NULL;
2583 fprintf_unfiltered (tmp_error_stream,
2584 "Cannot insert hardware breakpoint %d%s",
2585 bl->owner->number, hw_bp_err_string ? ":" : ".\n");
2586 if (hw_bp_err_string)
2587 fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string);
2591 fprintf_unfiltered (tmp_error_stream,
2592 "Cannot insert breakpoint %d.\n",
2594 fprintf_filtered (tmp_error_stream,
2595 "Error accessing memory address ");
2596 fputs_filtered (paddress (bl->gdbarch, bl->address),
2598 fprintf_filtered (tmp_error_stream, ": %s.\n",
2599 safe_strerror (val));
2610 else if (bl->loc_type == bp_loc_hardware_watchpoint
2611 /* NOTE drow/2003-09-08: This state only exists for removing
2612 watchpoints. It's not clear that it's necessary... */
2613 && bl->owner->disposition != disp_del_at_next_stop)
2615 gdb_assert (bl->owner->ops != NULL
2616 && bl->owner->ops->insert_location != NULL);
2618 val = bl->owner->ops->insert_location (bl);
2620 /* If trying to set a read-watchpoint, and it turns out it's not
2621 supported, try emulating one with an access watchpoint. */
2622 if (val == 1 && bl->watchpoint_type == hw_read)
2624 struct bp_location *loc, **loc_temp;
2626 /* But don't try to insert it, if there's already another
2627 hw_access location that would be considered a duplicate
2629 ALL_BP_LOCATIONS (loc, loc_temp)
2631 && loc->watchpoint_type == hw_access
2632 && watchpoint_locations_match (bl, loc))
2636 bl->target_info = loc->target_info;
2637 bl->watchpoint_type = hw_access;
2644 bl->watchpoint_type = hw_access;
2645 val = bl->owner->ops->insert_location (bl);
2648 /* Back to the original value. */
2649 bl->watchpoint_type = hw_read;
2653 bl->inserted = (val == 0);
2656 else if (bl->owner->type == bp_catchpoint)
2658 gdb_assert (bl->owner->ops != NULL
2659 && bl->owner->ops->insert_location != NULL);
2661 val = bl->owner->ops->insert_location (bl);
2664 bl->owner->enable_state = bp_disabled;
2668 Error inserting catchpoint %d: Your system does not support this type\n\
2669 of catchpoint."), bl->owner->number);
2671 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2674 bl->inserted = (val == 0);
2676 /* We've already printed an error message if there was a problem
2677 inserting this catchpoint, and we've disabled the catchpoint,
2678 so just return success. */
2685 /* This function is called when program space PSPACE is about to be
2686 deleted. It takes care of updating breakpoints to not reference
2690 breakpoint_program_space_exit (struct program_space *pspace)
2692 struct breakpoint *b, *b_temp;
2693 struct bp_location *loc, **loc_temp;
2695 /* Remove any breakpoint that was set through this program space. */
2696 ALL_BREAKPOINTS_SAFE (b, b_temp)
2698 if (b->pspace == pspace)
2699 delete_breakpoint (b);
2702 /* Breakpoints set through other program spaces could have locations
2703 bound to PSPACE as well. Remove those. */
2704 ALL_BP_LOCATIONS (loc, loc_temp)
2706 struct bp_location *tmp;
2708 if (loc->pspace == pspace)
2710 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2711 if (loc->owner->loc == loc)
2712 loc->owner->loc = loc->next;
2714 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2715 if (tmp->next == loc)
2717 tmp->next = loc->next;
2723 /* Now update the global location list to permanently delete the
2724 removed locations above. */
2725 update_global_location_list (0);
2728 /* Make sure all breakpoints are inserted in inferior.
2729 Throws exception on any error.
2730 A breakpoint that is already inserted won't be inserted
2731 again, so calling this function twice is safe. */
2733 insert_breakpoints (void)
2735 struct breakpoint *bpt;
2737 ALL_BREAKPOINTS (bpt)
2738 if (is_hardware_watchpoint (bpt))
2740 struct watchpoint *w = (struct watchpoint *) bpt;
2742 update_watchpoint (w, 0 /* don't reparse. */);
2745 update_global_location_list (1);
2747 /* update_global_location_list does not insert breakpoints when
2748 always_inserted_mode is not enabled. Explicitly insert them
2750 if (!breakpoints_always_inserted_mode ())
2751 insert_breakpoint_locations ();
2754 /* Invoke CALLBACK for each of bp_location. */
2757 iterate_over_bp_locations (walk_bp_location_callback callback)
2759 struct bp_location *loc, **loc_tmp;
2761 ALL_BP_LOCATIONS (loc, loc_tmp)
2763 callback (loc, NULL);
2767 /* This is used when we need to synch breakpoint conditions between GDB and the
2768 target. It is the case with deleting and disabling of breakpoints when using
2769 always-inserted mode. */
2772 update_inserted_breakpoint_locations (void)
2774 struct bp_location *bl, **blp_tmp;
2777 int disabled_breaks = 0;
2778 int hw_breakpoint_error = 0;
2779 int hw_bp_details_reported = 0;
2781 struct ui_file *tmp_error_stream = mem_fileopen ();
2782 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2784 /* Explicitly mark the warning -- this will only be printed if
2785 there was an error. */
2786 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2788 save_current_space_and_thread ();
2790 ALL_BP_LOCATIONS (bl, blp_tmp)
2792 /* We only want to update software breakpoints and hardware
2794 if (!is_breakpoint (bl->owner))
2797 /* We only want to update locations that are already inserted
2798 and need updating. This is to avoid unwanted insertion during
2799 deletion of breakpoints. */
2800 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2803 switch_to_program_space_and_thread (bl->pspace);
2805 /* For targets that support global breakpoints, there's no need
2806 to select an inferior to insert breakpoint to. In fact, even
2807 if we aren't attached to any process yet, we should still
2808 insert breakpoints. */
2809 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2810 && ptid_equal (inferior_ptid, null_ptid))
2813 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2814 &hw_breakpoint_error, &hw_bp_details_reported);
2821 target_terminal_ours_for_output ();
2822 error_stream (tmp_error_stream);
2825 do_cleanups (cleanups);
2828 /* Used when starting or continuing the program. */
2831 insert_breakpoint_locations (void)
2833 struct breakpoint *bpt;
2834 struct bp_location *bl, **blp_tmp;
2837 int disabled_breaks = 0;
2838 int hw_breakpoint_error = 0;
2839 int hw_bp_error_explained_already = 0;
2841 struct ui_file *tmp_error_stream = mem_fileopen ();
2842 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2844 /* Explicitly mark the warning -- this will only be printed if
2845 there was an error. */
2846 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2848 save_current_space_and_thread ();
2850 ALL_BP_LOCATIONS (bl, blp_tmp)
2852 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2855 /* There is no point inserting thread-specific breakpoints if
2856 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2857 has BL->OWNER always non-NULL. */
2858 if (bl->owner->thread != -1
2859 && !valid_thread_id (bl->owner->thread))
2862 switch_to_program_space_and_thread (bl->pspace);
2864 /* For targets that support global breakpoints, there's no need
2865 to select an inferior to insert breakpoint to. In fact, even
2866 if we aren't attached to any process yet, we should still
2867 insert breakpoints. */
2868 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2869 && ptid_equal (inferior_ptid, null_ptid))
2872 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2873 &hw_breakpoint_error, &hw_bp_error_explained_already);
2878 /* If we failed to insert all locations of a watchpoint, remove
2879 them, as half-inserted watchpoint is of limited use. */
2880 ALL_BREAKPOINTS (bpt)
2882 int some_failed = 0;
2883 struct bp_location *loc;
2885 if (!is_hardware_watchpoint (bpt))
2888 if (!breakpoint_enabled (bpt))
2891 if (bpt->disposition == disp_del_at_next_stop)
2894 for (loc = bpt->loc; loc; loc = loc->next)
2895 if (!loc->inserted && should_be_inserted (loc))
2902 for (loc = bpt->loc; loc; loc = loc->next)
2904 remove_breakpoint (loc, mark_uninserted);
2906 hw_breakpoint_error = 1;
2907 fprintf_unfiltered (tmp_error_stream,
2908 "Could not insert hardware watchpoint %d.\n",
2916 /* If a hardware breakpoint or watchpoint was inserted, add a
2917 message about possibly exhausted resources. */
2918 if (hw_breakpoint_error && !hw_bp_error_explained_already)
2920 fprintf_unfiltered (tmp_error_stream,
2921 "Could not insert hardware breakpoints:\n\
2922 You may have requested too many hardware breakpoints/watchpoints.\n");
2924 target_terminal_ours_for_output ();
2925 error_stream (tmp_error_stream);
2928 do_cleanups (cleanups);
2931 /* Used when the program stops.
2932 Returns zero if successful, or non-zero if there was a problem
2933 removing a breakpoint location. */
2936 remove_breakpoints (void)
2938 struct bp_location *bl, **blp_tmp;
2941 ALL_BP_LOCATIONS (bl, blp_tmp)
2943 if (bl->inserted && !is_tracepoint (bl->owner))
2944 val |= remove_breakpoint (bl, mark_uninserted);
2949 /* Remove breakpoints of process PID. */
2952 remove_breakpoints_pid (int pid)
2954 struct bp_location *bl, **blp_tmp;
2956 struct inferior *inf = find_inferior_pid (pid);
2958 ALL_BP_LOCATIONS (bl, blp_tmp)
2960 if (bl->pspace != inf->pspace)
2963 if (bl->owner->type == bp_dprintf)
2968 val = remove_breakpoint (bl, mark_uninserted);
2977 reattach_breakpoints (int pid)
2979 struct cleanup *old_chain;
2980 struct bp_location *bl, **blp_tmp;
2982 struct ui_file *tmp_error_stream;
2983 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
2984 struct inferior *inf;
2985 struct thread_info *tp;
2987 tp = any_live_thread_of_process (pid);
2991 inf = find_inferior_pid (pid);
2992 old_chain = save_inferior_ptid ();
2994 inferior_ptid = tp->ptid;
2996 tmp_error_stream = mem_fileopen ();
2997 make_cleanup_ui_file_delete (tmp_error_stream);
2999 ALL_BP_LOCATIONS (bl, blp_tmp)
3001 if (bl->pspace != inf->pspace)
3007 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3010 do_cleanups (old_chain);
3015 do_cleanups (old_chain);
3019 static int internal_breakpoint_number = -1;
3021 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3022 If INTERNAL is non-zero, the breakpoint number will be populated
3023 from internal_breakpoint_number and that variable decremented.
3024 Otherwise the breakpoint number will be populated from
3025 breakpoint_count and that value incremented. Internal breakpoints
3026 do not set the internal var bpnum. */
3028 set_breakpoint_number (int internal, struct breakpoint *b)
3031 b->number = internal_breakpoint_number--;
3034 set_breakpoint_count (breakpoint_count + 1);
3035 b->number = breakpoint_count;
3039 static struct breakpoint *
3040 create_internal_breakpoint (struct gdbarch *gdbarch,
3041 CORE_ADDR address, enum bptype type,
3042 const struct breakpoint_ops *ops)
3044 struct symtab_and_line sal;
3045 struct breakpoint *b;
3047 init_sal (&sal); /* Initialize to zeroes. */
3050 sal.section = find_pc_overlay (sal.pc);
3051 sal.pspace = current_program_space;
3053 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3054 b->number = internal_breakpoint_number--;
3055 b->disposition = disp_donttouch;
3060 static const char *const longjmp_names[] =
3062 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3064 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3066 /* Per-objfile data private to breakpoint.c. */
3067 struct breakpoint_objfile_data
3069 /* Minimal symbol for "_ovly_debug_event" (if any). */
3070 struct minimal_symbol *overlay_msym;
3072 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3073 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
3075 /* True if we have looked for longjmp probes. */
3076 int longjmp_searched;
3078 /* SystemTap probe points for longjmp (if any). */
3079 VEC (probe_p) *longjmp_probes;
3081 /* Minimal symbol for "std::terminate()" (if any). */
3082 struct minimal_symbol *terminate_msym;
3084 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3085 struct minimal_symbol *exception_msym;
3087 /* True if we have looked for exception probes. */
3088 int exception_searched;
3090 /* SystemTap probe points for unwinding (if any). */
3091 VEC (probe_p) *exception_probes;
3094 static const struct objfile_data *breakpoint_objfile_key;
3096 /* Minimal symbol not found sentinel. */
3097 static struct minimal_symbol msym_not_found;
3099 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3102 msym_not_found_p (const struct minimal_symbol *msym)
3104 return msym == &msym_not_found;
3107 /* Return per-objfile data needed by breakpoint.c.
3108 Allocate the data if necessary. */
3110 static struct breakpoint_objfile_data *
3111 get_breakpoint_objfile_data (struct objfile *objfile)
3113 struct breakpoint_objfile_data *bp_objfile_data;
3115 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3116 if (bp_objfile_data == NULL)
3118 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3119 sizeof (*bp_objfile_data));
3121 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3122 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3124 return bp_objfile_data;
3128 free_breakpoint_probes (struct objfile *obj, void *data)
3130 struct breakpoint_objfile_data *bp_objfile_data = data;
3132 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3133 VEC_free (probe_p, bp_objfile_data->exception_probes);
3137 create_overlay_event_breakpoint (void)
3139 struct objfile *objfile;
3140 const char *const func_name = "_ovly_debug_event";
3142 ALL_OBJFILES (objfile)
3144 struct breakpoint *b;
3145 struct breakpoint_objfile_data *bp_objfile_data;
3148 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3150 if (msym_not_found_p (bp_objfile_data->overlay_msym))
3153 if (bp_objfile_data->overlay_msym == NULL)
3155 struct minimal_symbol *m;
3157 m = lookup_minimal_symbol_text (func_name, objfile);
3160 /* Avoid future lookups in this objfile. */
3161 bp_objfile_data->overlay_msym = &msym_not_found;
3164 bp_objfile_data->overlay_msym = m;
3167 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3168 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3170 &internal_breakpoint_ops);
3171 b->addr_string = xstrdup (func_name);
3173 if (overlay_debugging == ovly_auto)
3175 b->enable_state = bp_enabled;
3176 overlay_events_enabled = 1;
3180 b->enable_state = bp_disabled;
3181 overlay_events_enabled = 0;
3184 update_global_location_list (1);
3188 create_longjmp_master_breakpoint (void)
3190 struct program_space *pspace;
3191 struct cleanup *old_chain;
3193 old_chain = save_current_program_space ();
3195 ALL_PSPACES (pspace)
3197 struct objfile *objfile;
3199 set_current_program_space (pspace);
3201 ALL_OBJFILES (objfile)
3204 struct gdbarch *gdbarch;
3205 struct breakpoint_objfile_data *bp_objfile_data;
3207 gdbarch = get_objfile_arch (objfile);
3208 if (!gdbarch_get_longjmp_target_p (gdbarch))
3211 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3213 if (!bp_objfile_data->longjmp_searched)
3215 bp_objfile_data->longjmp_probes
3216 = find_probes_in_objfile (objfile, "libc", "longjmp");
3217 bp_objfile_data->longjmp_searched = 1;
3220 if (bp_objfile_data->longjmp_probes != NULL)
3223 struct probe *probe;
3224 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3227 VEC_iterate (probe_p,
3228 bp_objfile_data->longjmp_probes,
3232 struct breakpoint *b;
3234 b = create_internal_breakpoint (gdbarch, probe->address,
3236 &internal_breakpoint_ops);
3237 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3238 b->enable_state = bp_disabled;
3244 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3246 struct breakpoint *b;
3247 const char *func_name;
3250 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
3253 func_name = longjmp_names[i];
3254 if (bp_objfile_data->longjmp_msym[i] == NULL)
3256 struct minimal_symbol *m;
3258 m = lookup_minimal_symbol_text (func_name, objfile);
3261 /* Prevent future lookups in this objfile. */
3262 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
3265 bp_objfile_data->longjmp_msym[i] = m;
3268 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3269 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3270 &internal_breakpoint_ops);
3271 b->addr_string = xstrdup (func_name);
3272 b->enable_state = bp_disabled;
3276 update_global_location_list (1);
3278 do_cleanups (old_chain);
3281 /* Create a master std::terminate breakpoint. */
3283 create_std_terminate_master_breakpoint (void)
3285 struct program_space *pspace;
3286 struct cleanup *old_chain;
3287 const char *const func_name = "std::terminate()";
3289 old_chain = save_current_program_space ();
3291 ALL_PSPACES (pspace)
3293 struct objfile *objfile;
3296 set_current_program_space (pspace);
3298 ALL_OBJFILES (objfile)
3300 struct breakpoint *b;
3301 struct breakpoint_objfile_data *bp_objfile_data;
3303 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3305 if (msym_not_found_p (bp_objfile_data->terminate_msym))
3308 if (bp_objfile_data->terminate_msym == NULL)
3310 struct minimal_symbol *m;
3312 m = lookup_minimal_symbol (func_name, NULL, objfile);
3313 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3314 && MSYMBOL_TYPE (m) != mst_file_text))
3316 /* Prevent future lookups in this objfile. */
3317 bp_objfile_data->terminate_msym = &msym_not_found;
3320 bp_objfile_data->terminate_msym = m;
3323 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3324 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3325 bp_std_terminate_master,
3326 &internal_breakpoint_ops);
3327 b->addr_string = xstrdup (func_name);
3328 b->enable_state = bp_disabled;
3332 update_global_location_list (1);
3334 do_cleanups (old_chain);
3337 /* Install a master breakpoint on the unwinder's debug hook. */
3340 create_exception_master_breakpoint (void)
3342 struct objfile *objfile;
3343 const char *const func_name = "_Unwind_DebugHook";
3345 ALL_OBJFILES (objfile)
3347 struct breakpoint *b;
3348 struct gdbarch *gdbarch;
3349 struct breakpoint_objfile_data *bp_objfile_data;
3352 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3354 /* We prefer the SystemTap probe point if it exists. */
3355 if (!bp_objfile_data->exception_searched)
3357 bp_objfile_data->exception_probes
3358 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3359 bp_objfile_data->exception_searched = 1;
3362 if (bp_objfile_data->exception_probes != NULL)
3364 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3366 struct probe *probe;
3369 VEC_iterate (probe_p,
3370 bp_objfile_data->exception_probes,
3374 struct breakpoint *b;
3376 b = create_internal_breakpoint (gdbarch, probe->address,
3377 bp_exception_master,
3378 &internal_breakpoint_ops);
3379 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3380 b->enable_state = bp_disabled;
3386 /* Otherwise, try the hook function. */
3388 if (msym_not_found_p (bp_objfile_data->exception_msym))
3391 gdbarch = get_objfile_arch (objfile);
3393 if (bp_objfile_data->exception_msym == NULL)
3395 struct minimal_symbol *debug_hook;
3397 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3398 if (debug_hook == NULL)
3400 bp_objfile_data->exception_msym = &msym_not_found;
3404 bp_objfile_data->exception_msym = debug_hook;
3407 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3408 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3410 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3411 &internal_breakpoint_ops);
3412 b->addr_string = xstrdup (func_name);
3413 b->enable_state = bp_disabled;
3416 update_global_location_list (1);
3420 update_breakpoints_after_exec (void)
3422 struct breakpoint *b, *b_tmp;
3423 struct bp_location *bploc, **bplocp_tmp;
3425 /* We're about to delete breakpoints from GDB's lists. If the
3426 INSERTED flag is true, GDB will try to lift the breakpoints by
3427 writing the breakpoints' "shadow contents" back into memory. The
3428 "shadow contents" are NOT valid after an exec, so GDB should not
3429 do that. Instead, the target is responsible from marking
3430 breakpoints out as soon as it detects an exec. We don't do that
3431 here instead, because there may be other attempts to delete
3432 breakpoints after detecting an exec and before reaching here. */
3433 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3434 if (bploc->pspace == current_program_space)
3435 gdb_assert (!bploc->inserted);
3437 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3439 if (b->pspace != current_program_space)
3442 /* Solib breakpoints must be explicitly reset after an exec(). */
3443 if (b->type == bp_shlib_event)
3445 delete_breakpoint (b);
3449 /* JIT breakpoints must be explicitly reset after an exec(). */
3450 if (b->type == bp_jit_event)
3452 delete_breakpoint (b);
3456 /* Thread event breakpoints must be set anew after an exec(),
3457 as must overlay event and longjmp master breakpoints. */
3458 if (b->type == bp_thread_event || b->type == bp_overlay_event
3459 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3460 || b->type == bp_exception_master)
3462 delete_breakpoint (b);
3466 /* Step-resume breakpoints are meaningless after an exec(). */
3467 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3469 delete_breakpoint (b);
3473 /* Longjmp and longjmp-resume breakpoints are also meaningless
3475 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3476 || b->type == bp_longjmp_call_dummy
3477 || b->type == bp_exception || b->type == bp_exception_resume)
3479 delete_breakpoint (b);
3483 if (b->type == bp_catchpoint)
3485 /* For now, none of the bp_catchpoint breakpoints need to
3486 do anything at this point. In the future, if some of
3487 the catchpoints need to something, we will need to add
3488 a new method, and call this method from here. */
3492 /* bp_finish is a special case. The only way we ought to be able
3493 to see one of these when an exec() has happened, is if the user
3494 caught a vfork, and then said "finish". Ordinarily a finish just
3495 carries them to the call-site of the current callee, by setting
3496 a temporary bp there and resuming. But in this case, the finish
3497 will carry them entirely through the vfork & exec.
3499 We don't want to allow a bp_finish to remain inserted now. But
3500 we can't safely delete it, 'cause finish_command has a handle to
3501 the bp on a bpstat, and will later want to delete it. There's a
3502 chance (and I've seen it happen) that if we delete the bp_finish
3503 here, that its storage will get reused by the time finish_command
3504 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3505 We really must allow finish_command to delete a bp_finish.
3507 In the absence of a general solution for the "how do we know
3508 it's safe to delete something others may have handles to?"
3509 problem, what we'll do here is just uninsert the bp_finish, and
3510 let finish_command delete it.
3512 (We know the bp_finish is "doomed" in the sense that it's
3513 momentary, and will be deleted as soon as finish_command sees
3514 the inferior stopped. So it doesn't matter that the bp's
3515 address is probably bogus in the new a.out, unlike e.g., the
3516 solib breakpoints.) */
3518 if (b->type == bp_finish)
3523 /* Without a symbolic address, we have little hope of the
3524 pre-exec() address meaning the same thing in the post-exec()
3526 if (b->addr_string == NULL)
3528 delete_breakpoint (b);
3532 /* FIXME what about longjmp breakpoints? Re-create them here? */
3533 create_overlay_event_breakpoint ();
3534 create_longjmp_master_breakpoint ();
3535 create_std_terminate_master_breakpoint ();
3536 create_exception_master_breakpoint ();
3540 detach_breakpoints (ptid_t ptid)
3542 struct bp_location *bl, **blp_tmp;
3544 struct cleanup *old_chain = save_inferior_ptid ();
3545 struct inferior *inf = current_inferior ();
3547 if (PIDGET (ptid) == PIDGET (inferior_ptid))
3548 error (_("Cannot detach breakpoints of inferior_ptid"));
3550 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3551 inferior_ptid = ptid;
3552 ALL_BP_LOCATIONS (bl, blp_tmp)
3554 if (bl->pspace != inf->pspace)
3558 val |= remove_breakpoint_1 (bl, mark_inserted);
3561 /* Detach single-step breakpoints as well. */
3562 detach_single_step_breakpoints ();
3564 do_cleanups (old_chain);
3568 /* Remove the breakpoint location BL from the current address space.
3569 Note that this is used to detach breakpoints from a child fork.
3570 When we get here, the child isn't in the inferior list, and neither
3571 do we have objects to represent its address space --- we should
3572 *not* look at bl->pspace->aspace here. */
3575 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3579 /* BL is never in moribund_locations by our callers. */
3580 gdb_assert (bl->owner != NULL);
3582 if (bl->owner->enable_state == bp_permanent)
3583 /* Permanent breakpoints cannot be inserted or removed. */
3586 /* The type of none suggests that owner is actually deleted.
3587 This should not ever happen. */
3588 gdb_assert (bl->owner->type != bp_none);
3590 if (bl->loc_type == bp_loc_software_breakpoint
3591 || bl->loc_type == bp_loc_hardware_breakpoint)
3593 /* "Normal" instruction breakpoint: either the standard
3594 trap-instruction bp (bp_breakpoint), or a
3595 bp_hardware_breakpoint. */
3597 /* First check to see if we have to handle an overlay. */
3598 if (overlay_debugging == ovly_off
3599 || bl->section == NULL
3600 || !(section_is_overlay (bl->section)))
3602 /* No overlay handling: just remove the breakpoint. */
3603 val = bl->owner->ops->remove_location (bl);
3607 /* This breakpoint is in an overlay section.
3608 Did we set a breakpoint at the LMA? */
3609 if (!overlay_events_enabled)
3611 /* Yes -- overlay event support is not active, so we
3612 should have set a breakpoint at the LMA. Remove it.
3614 /* Ignore any failures: if the LMA is in ROM, we will
3615 have already warned when we failed to insert it. */
3616 if (bl->loc_type == bp_loc_hardware_breakpoint)
3617 target_remove_hw_breakpoint (bl->gdbarch,
3618 &bl->overlay_target_info);
3620 target_remove_breakpoint (bl->gdbarch,
3621 &bl->overlay_target_info);
3623 /* Did we set a breakpoint at the VMA?
3624 If so, we will have marked the breakpoint 'inserted'. */
3627 /* Yes -- remove it. Previously we did not bother to
3628 remove the breakpoint if the section had been
3629 unmapped, but let's not rely on that being safe. We
3630 don't know what the overlay manager might do. */
3632 /* However, we should remove *software* breakpoints only
3633 if the section is still mapped, or else we overwrite
3634 wrong code with the saved shadow contents. */
3635 if (bl->loc_type == bp_loc_hardware_breakpoint
3636 || section_is_mapped (bl->section))
3637 val = bl->owner->ops->remove_location (bl);
3643 /* No -- not inserted, so no need to remove. No error. */
3648 /* In some cases, we might not be able to remove a breakpoint
3649 in a shared library that has already been removed, but we
3650 have not yet processed the shlib unload event. */
3651 if (val && solib_name_from_address (bl->pspace, bl->address))
3656 bl->inserted = (is == mark_inserted);
3658 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3660 gdb_assert (bl->owner->ops != NULL
3661 && bl->owner->ops->remove_location != NULL);
3663 bl->inserted = (is == mark_inserted);
3664 bl->owner->ops->remove_location (bl);
3666 /* Failure to remove any of the hardware watchpoints comes here. */
3667 if ((is == mark_uninserted) && (bl->inserted))
3668 warning (_("Could not remove hardware watchpoint %d."),
3671 else if (bl->owner->type == bp_catchpoint
3672 && breakpoint_enabled (bl->owner)
3675 gdb_assert (bl->owner->ops != NULL
3676 && bl->owner->ops->remove_location != NULL);
3678 val = bl->owner->ops->remove_location (bl);
3682 bl->inserted = (is == mark_inserted);
3689 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3692 struct cleanup *old_chain;
3694 /* BL is never in moribund_locations by our callers. */
3695 gdb_assert (bl->owner != NULL);
3697 if (bl->owner->enable_state == bp_permanent)
3698 /* Permanent breakpoints cannot be inserted or removed. */
3701 /* The type of none suggests that owner is actually deleted.
3702 This should not ever happen. */
3703 gdb_assert (bl->owner->type != bp_none);
3705 old_chain = save_current_space_and_thread ();
3707 switch_to_program_space_and_thread (bl->pspace);
3709 ret = remove_breakpoint_1 (bl, is);
3711 do_cleanups (old_chain);
3715 /* Clear the "inserted" flag in all breakpoints. */
3718 mark_breakpoints_out (void)
3720 struct bp_location *bl, **blp_tmp;
3722 ALL_BP_LOCATIONS (bl, blp_tmp)
3723 if (bl->pspace == current_program_space)
3727 /* Clear the "inserted" flag in all breakpoints and delete any
3728 breakpoints which should go away between runs of the program.
3730 Plus other such housekeeping that has to be done for breakpoints
3733 Note: this function gets called at the end of a run (by
3734 generic_mourn_inferior) and when a run begins (by
3735 init_wait_for_inferior). */
3740 breakpoint_init_inferior (enum inf_context context)
3742 struct breakpoint *b, *b_tmp;
3743 struct bp_location *bl, **blp_tmp;
3745 struct program_space *pspace = current_program_space;
3747 /* If breakpoint locations are shared across processes, then there's
3749 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3752 ALL_BP_LOCATIONS (bl, blp_tmp)
3754 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3755 if (bl->pspace == pspace
3756 && bl->owner->enable_state != bp_permanent)
3760 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3762 if (b->loc && b->loc->pspace != pspace)
3768 case bp_longjmp_call_dummy:
3770 /* If the call dummy breakpoint is at the entry point it will
3771 cause problems when the inferior is rerun, so we better get
3774 case bp_watchpoint_scope:
3776 /* Also get rid of scope breakpoints. */
3778 case bp_shlib_event:
3780 /* Also remove solib event breakpoints. Their addresses may
3781 have changed since the last time we ran the program.
3782 Actually we may now be debugging against different target;
3783 and so the solib backend that installed this breakpoint may
3784 not be used in by the target. E.g.,
3786 (gdb) file prog-linux
3787 (gdb) run # native linux target
3790 (gdb) file prog-win.exe
3791 (gdb) tar rem :9999 # remote Windows gdbserver.
3794 case bp_step_resume:
3796 /* Also remove step-resume breakpoints. */
3798 delete_breakpoint (b);
3802 case bp_hardware_watchpoint:
3803 case bp_read_watchpoint:
3804 case bp_access_watchpoint:
3806 struct watchpoint *w = (struct watchpoint *) b;
3808 /* Likewise for watchpoints on local expressions. */
3809 if (w->exp_valid_block != NULL)
3810 delete_breakpoint (b);
3811 else if (context == inf_starting)
3813 /* Reset val field to force reread of starting value in
3814 insert_breakpoints. */
3816 value_free (w->val);
3827 /* Get rid of the moribund locations. */
3828 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3829 decref_bp_location (&bl);
3830 VEC_free (bp_location_p, moribund_locations);
3833 /* These functions concern about actual breakpoints inserted in the
3834 target --- to e.g. check if we need to do decr_pc adjustment or if
3835 we need to hop over the bkpt --- so we check for address space
3836 match, not program space. */
3838 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3839 exists at PC. It returns ordinary_breakpoint_here if it's an
3840 ordinary breakpoint, or permanent_breakpoint_here if it's a
3841 permanent breakpoint.
3842 - When continuing from a location with an ordinary breakpoint, we
3843 actually single step once before calling insert_breakpoints.
3844 - When continuing from a location with a permanent breakpoint, we
3845 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3846 the target, to advance the PC past the breakpoint. */
3848 enum breakpoint_here
3849 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3851 struct bp_location *bl, **blp_tmp;
3852 int any_breakpoint_here = 0;
3854 ALL_BP_LOCATIONS (bl, blp_tmp)
3856 if (bl->loc_type != bp_loc_software_breakpoint
3857 && bl->loc_type != bp_loc_hardware_breakpoint)
3860 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3861 if ((breakpoint_enabled (bl->owner)
3862 || bl->owner->enable_state == bp_permanent)
3863 && breakpoint_location_address_match (bl, aspace, pc))
3865 if (overlay_debugging
3866 && section_is_overlay (bl->section)
3867 && !section_is_mapped (bl->section))
3868 continue; /* unmapped overlay -- can't be a match */
3869 else if (bl->owner->enable_state == bp_permanent)
3870 return permanent_breakpoint_here;
3872 any_breakpoint_here = 1;
3876 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3879 /* Return true if there's a moribund breakpoint at PC. */
3882 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3884 struct bp_location *loc;
3887 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3888 if (breakpoint_location_address_match (loc, aspace, pc))
3894 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3895 inserted using regular breakpoint_chain / bp_location array
3896 mechanism. This does not check for single-step breakpoints, which
3897 are inserted and removed using direct target manipulation. */
3900 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3903 struct bp_location *bl, **blp_tmp;
3905 ALL_BP_LOCATIONS (bl, blp_tmp)
3907 if (bl->loc_type != bp_loc_software_breakpoint
3908 && bl->loc_type != bp_loc_hardware_breakpoint)
3912 && breakpoint_location_address_match (bl, aspace, pc))
3914 if (overlay_debugging
3915 && section_is_overlay (bl->section)
3916 && !section_is_mapped (bl->section))
3917 continue; /* unmapped overlay -- can't be a match */
3925 /* Returns non-zero iff there's either regular breakpoint
3926 or a single step breakpoint inserted at PC. */
3929 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3931 if (regular_breakpoint_inserted_here_p (aspace, pc))
3934 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3940 /* This function returns non-zero iff there is a software breakpoint
3944 software_breakpoint_inserted_here_p (struct address_space *aspace,
3947 struct bp_location *bl, **blp_tmp;
3949 ALL_BP_LOCATIONS (bl, blp_tmp)
3951 if (bl->loc_type != bp_loc_software_breakpoint)
3955 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3958 if (overlay_debugging
3959 && section_is_overlay (bl->section)
3960 && !section_is_mapped (bl->section))
3961 continue; /* unmapped overlay -- can't be a match */
3967 /* Also check for software single-step breakpoints. */
3968 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3975 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3976 CORE_ADDR addr, ULONGEST len)
3978 struct breakpoint *bpt;
3980 ALL_BREAKPOINTS (bpt)
3982 struct bp_location *loc;
3984 if (bpt->type != bp_hardware_watchpoint
3985 && bpt->type != bp_access_watchpoint)
3988 if (!breakpoint_enabled (bpt))
3991 for (loc = bpt->loc; loc; loc = loc->next)
3992 if (loc->pspace->aspace == aspace && loc->inserted)
3996 /* Check for intersection. */
3997 l = max (loc->address, addr);
3998 h = min (loc->address + loc->length, addr + len);
4006 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4007 PC is valid for process/thread PTID. */
4010 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4013 struct bp_location *bl, **blp_tmp;
4014 /* The thread and task IDs associated to PTID, computed lazily. */
4018 ALL_BP_LOCATIONS (bl, blp_tmp)
4020 if (bl->loc_type != bp_loc_software_breakpoint
4021 && bl->loc_type != bp_loc_hardware_breakpoint)
4024 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4025 if (!breakpoint_enabled (bl->owner)
4026 && bl->owner->enable_state != bp_permanent)
4029 if (!breakpoint_location_address_match (bl, aspace, pc))
4032 if (bl->owner->thread != -1)
4034 /* This is a thread-specific breakpoint. Check that ptid
4035 matches that thread. If thread hasn't been computed yet,
4036 it is now time to do so. */
4038 thread = pid_to_thread_id (ptid);
4039 if (bl->owner->thread != thread)
4043 if (bl->owner->task != 0)
4045 /* This is a task-specific breakpoint. Check that ptid
4046 matches that task. If task hasn't been computed yet,
4047 it is now time to do so. */
4049 task = ada_get_task_number (ptid);
4050 if (bl->owner->task != task)
4054 if (overlay_debugging
4055 && section_is_overlay (bl->section)
4056 && !section_is_mapped (bl->section))
4057 continue; /* unmapped overlay -- can't be a match */
4066 /* bpstat stuff. External routines' interfaces are documented
4070 is_catchpoint (struct breakpoint *ep)
4072 return (ep->type == bp_catchpoint);
4075 /* Frees any storage that is part of a bpstat. Does not walk the
4079 bpstat_free (bpstat bs)
4081 if (bs->old_val != NULL)
4082 value_free (bs->old_val);
4083 decref_counted_command_line (&bs->commands);
4084 decref_bp_location (&bs->bp_location_at);
4088 /* Clear a bpstat so that it says we are not at any breakpoint.
4089 Also free any storage that is part of a bpstat. */
4092 bpstat_clear (bpstat *bsp)
4109 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4110 is part of the bpstat is copied as well. */
4113 bpstat_copy (bpstat bs)
4117 bpstat retval = NULL;
4122 for (; bs != NULL; bs = bs->next)
4124 tmp = (bpstat) xmalloc (sizeof (*tmp));
4125 memcpy (tmp, bs, sizeof (*tmp));
4126 incref_counted_command_line (tmp->commands);
4127 incref_bp_location (tmp->bp_location_at);
4128 if (bs->old_val != NULL)
4130 tmp->old_val = value_copy (bs->old_val);
4131 release_value (tmp->old_val);
4135 /* This is the first thing in the chain. */
4145 /* Find the bpstat associated with this breakpoint. */
4148 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4153 for (; bsp != NULL; bsp = bsp->next)
4155 if (bsp->breakpoint_at == breakpoint)
4161 /* See breakpoint.h. */
4163 enum bpstat_signal_value
4164 bpstat_explains_signal (bpstat bsp)
4166 enum bpstat_signal_value result = BPSTAT_SIGNAL_NO;
4168 for (; bsp != NULL; bsp = bsp->next)
4170 /* Ensure that, if we ever entered this loop, then we at least
4171 return BPSTAT_SIGNAL_HIDE. */
4172 enum bpstat_signal_value newval = BPSTAT_SIGNAL_HIDE;
4174 if (bsp->breakpoint_at != NULL)
4175 newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at);
4177 if (newval > result)
4184 /* Put in *NUM the breakpoint number of the first breakpoint we are
4185 stopped at. *BSP upon return is a bpstat which points to the
4186 remaining breakpoints stopped at (but which is not guaranteed to be
4187 good for anything but further calls to bpstat_num).
4189 Return 0 if passed a bpstat which does not indicate any breakpoints.
4190 Return -1 if stopped at a breakpoint that has been deleted since
4192 Return 1 otherwise. */
4195 bpstat_num (bpstat *bsp, int *num)
4197 struct breakpoint *b;
4200 return 0; /* No more breakpoint values */
4202 /* We assume we'll never have several bpstats that correspond to a
4203 single breakpoint -- otherwise, this function might return the
4204 same number more than once and this will look ugly. */
4205 b = (*bsp)->breakpoint_at;
4206 *bsp = (*bsp)->next;
4208 return -1; /* breakpoint that's been deleted since */
4210 *num = b->number; /* We have its number */
4214 /* See breakpoint.h. */
4217 bpstat_clear_actions (void)
4219 struct thread_info *tp;
4222 if (ptid_equal (inferior_ptid, null_ptid))
4225 tp = find_thread_ptid (inferior_ptid);
4229 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4231 decref_counted_command_line (&bs->commands);
4233 if (bs->old_val != NULL)
4235 value_free (bs->old_val);
4241 /* Called when a command is about to proceed the inferior. */
4244 breakpoint_about_to_proceed (void)
4246 if (!ptid_equal (inferior_ptid, null_ptid))
4248 struct thread_info *tp = inferior_thread ();
4250 /* Allow inferior function calls in breakpoint commands to not
4251 interrupt the command list. When the call finishes
4252 successfully, the inferior will be standing at the same
4253 breakpoint as if nothing happened. */
4254 if (tp->control.in_infcall)
4258 breakpoint_proceeded = 1;
4261 /* Stub for cleaning up our state if we error-out of a breakpoint
4264 cleanup_executing_breakpoints (void *ignore)
4266 executing_breakpoint_commands = 0;
4269 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4270 or its equivalent. */
4273 command_line_is_silent (struct command_line *cmd)
4275 return cmd && (strcmp ("silent", cmd->line) == 0
4276 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4279 /* Execute all the commands associated with all the breakpoints at
4280 this location. Any of these commands could cause the process to
4281 proceed beyond this point, etc. We look out for such changes by
4282 checking the global "breakpoint_proceeded" after each command.
4284 Returns true if a breakpoint command resumed the inferior. In that
4285 case, it is the caller's responsibility to recall it again with the
4286 bpstat of the current thread. */
4289 bpstat_do_actions_1 (bpstat *bsp)
4292 struct cleanup *old_chain;
4295 /* Avoid endless recursion if a `source' command is contained
4297 if (executing_breakpoint_commands)
4300 executing_breakpoint_commands = 1;
4301 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4303 prevent_dont_repeat ();
4305 /* This pointer will iterate over the list of bpstat's. */
4308 breakpoint_proceeded = 0;
4309 for (; bs != NULL; bs = bs->next)
4311 struct counted_command_line *ccmd;
4312 struct command_line *cmd;
4313 struct cleanup *this_cmd_tree_chain;
4315 /* Take ownership of the BSP's command tree, if it has one.
4317 The command tree could legitimately contain commands like
4318 'step' and 'next', which call clear_proceed_status, which
4319 frees stop_bpstat's command tree. To make sure this doesn't
4320 free the tree we're executing out from under us, we need to
4321 take ownership of the tree ourselves. Since a given bpstat's
4322 commands are only executed once, we don't need to copy it; we
4323 can clear the pointer in the bpstat, and make sure we free
4324 the tree when we're done. */
4325 ccmd = bs->commands;
4326 bs->commands = NULL;
4327 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4328 cmd = ccmd ? ccmd->commands : NULL;
4329 if (command_line_is_silent (cmd))
4331 /* The action has been already done by bpstat_stop_status. */
4337 execute_control_command (cmd);
4339 if (breakpoint_proceeded)
4345 /* We can free this command tree now. */
4346 do_cleanups (this_cmd_tree_chain);
4348 if (breakpoint_proceeded)
4350 if (target_can_async_p ())
4351 /* If we are in async mode, then the target might be still
4352 running, not stopped at any breakpoint, so nothing for
4353 us to do here -- just return to the event loop. */
4356 /* In sync mode, when execute_control_command returns
4357 we're already standing on the next breakpoint.
4358 Breakpoint commands for that stop were not run, since
4359 execute_command does not run breakpoint commands --
4360 only command_line_handler does, but that one is not
4361 involved in execution of breakpoint commands. So, we
4362 can now execute breakpoint commands. It should be
4363 noted that making execute_command do bpstat actions is
4364 not an option -- in this case we'll have recursive
4365 invocation of bpstat for each breakpoint with a
4366 command, and can easily blow up GDB stack. Instead, we
4367 return true, which will trigger the caller to recall us
4368 with the new stop_bpstat. */
4373 do_cleanups (old_chain);
4378 bpstat_do_actions (void)
4380 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4382 /* Do any commands attached to breakpoint we are stopped at. */
4383 while (!ptid_equal (inferior_ptid, null_ptid)
4384 && target_has_execution
4385 && !is_exited (inferior_ptid)
4386 && !is_executing (inferior_ptid))
4387 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4388 and only return when it is stopped at the next breakpoint, we
4389 keep doing breakpoint actions until it returns false to
4390 indicate the inferior was not resumed. */
4391 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4394 discard_cleanups (cleanup_if_error);
4397 /* Print out the (old or new) value associated with a watchpoint. */
4400 watchpoint_value_print (struct value *val, struct ui_file *stream)
4403 fprintf_unfiltered (stream, _("<unreadable>"));
4406 struct value_print_options opts;
4407 get_user_print_options (&opts);
4408 value_print (val, stream, &opts);
4412 /* Generic routine for printing messages indicating why we
4413 stopped. The behavior of this function depends on the value
4414 'print_it' in the bpstat structure. Under some circumstances we
4415 may decide not to print anything here and delegate the task to
4418 static enum print_stop_action
4419 print_bp_stop_message (bpstat bs)
4421 switch (bs->print_it)
4424 /* Nothing should be printed for this bpstat entry. */
4425 return PRINT_UNKNOWN;
4429 /* We still want to print the frame, but we already printed the
4430 relevant messages. */
4431 return PRINT_SRC_AND_LOC;
4434 case print_it_normal:
4436 struct breakpoint *b = bs->breakpoint_at;
4438 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4439 which has since been deleted. */
4441 return PRINT_UNKNOWN;
4443 /* Normal case. Call the breakpoint's print_it method. */
4444 return b->ops->print_it (bs);
4449 internal_error (__FILE__, __LINE__,
4450 _("print_bp_stop_message: unrecognized enum value"));
4455 /* A helper function that prints a shared library stopped event. */
4458 print_solib_event (int is_catchpoint)
4461 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4463 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4467 if (any_added || any_deleted)
4468 ui_out_text (current_uiout,
4469 _("Stopped due to shared library event:\n"));
4471 ui_out_text (current_uiout,
4472 _("Stopped due to shared library event (no "
4473 "libraries added or removed)\n"));
4476 if (ui_out_is_mi_like_p (current_uiout))
4477 ui_out_field_string (current_uiout, "reason",
4478 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4482 struct cleanup *cleanup;
4486 ui_out_text (current_uiout, _(" Inferior unloaded "));
4487 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4490 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4495 ui_out_text (current_uiout, " ");
4496 ui_out_field_string (current_uiout, "library", name);
4497 ui_out_text (current_uiout, "\n");
4500 do_cleanups (cleanup);
4505 struct so_list *iter;
4507 struct cleanup *cleanup;
4509 ui_out_text (current_uiout, _(" Inferior loaded "));
4510 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4513 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4518 ui_out_text (current_uiout, " ");
4519 ui_out_field_string (current_uiout, "library", iter->so_name);
4520 ui_out_text (current_uiout, "\n");
4523 do_cleanups (cleanup);
4527 /* Print a message indicating what happened. This is called from
4528 normal_stop(). The input to this routine is the head of the bpstat
4529 list - a list of the eventpoints that caused this stop. KIND is
4530 the target_waitkind for the stopping event. This
4531 routine calls the generic print routine for printing a message
4532 about reasons for stopping. This will print (for example) the
4533 "Breakpoint n," part of the output. The return value of this
4536 PRINT_UNKNOWN: Means we printed nothing.
4537 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4538 code to print the location. An example is
4539 "Breakpoint 1, " which should be followed by
4541 PRINT_SRC_ONLY: Means we printed something, but there is no need
4542 to also print the location part of the message.
4543 An example is the catch/throw messages, which
4544 don't require a location appended to the end.
4545 PRINT_NOTHING: We have done some printing and we don't need any
4546 further info to be printed. */
4548 enum print_stop_action
4549 bpstat_print (bpstat bs, int kind)
4553 /* Maybe another breakpoint in the chain caused us to stop.
4554 (Currently all watchpoints go on the bpstat whether hit or not.
4555 That probably could (should) be changed, provided care is taken
4556 with respect to bpstat_explains_signal). */
4557 for (; bs; bs = bs->next)
4559 val = print_bp_stop_message (bs);
4560 if (val == PRINT_SRC_ONLY
4561 || val == PRINT_SRC_AND_LOC
4562 || val == PRINT_NOTHING)
4566 /* If we had hit a shared library event breakpoint,
4567 print_bp_stop_message would print out this message. If we hit an
4568 OS-level shared library event, do the same thing. */
4569 if (kind == TARGET_WAITKIND_LOADED)
4571 print_solib_event (0);
4572 return PRINT_NOTHING;
4575 /* We reached the end of the chain, or we got a null BS to start
4576 with and nothing was printed. */
4577 return PRINT_UNKNOWN;
4580 /* Evaluate the expression EXP and return 1 if value is zero. This is
4581 used inside a catch_errors to evaluate the breakpoint condition.
4582 The argument is a "struct expression *" that has been cast to a
4583 "char *" to make it pass through catch_errors. */
4586 breakpoint_cond_eval (void *exp)
4588 struct value *mark = value_mark ();
4589 int i = !value_true (evaluate_expression ((struct expression *) exp));
4591 value_free_to_mark (mark);
4595 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4598 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4602 bs = (bpstat) xmalloc (sizeof (*bs));
4604 **bs_link_pointer = bs;
4605 *bs_link_pointer = &bs->next;
4606 bs->breakpoint_at = bl->owner;
4607 bs->bp_location_at = bl;
4608 incref_bp_location (bl);
4609 /* If the condition is false, etc., don't do the commands. */
4610 bs->commands = NULL;
4612 bs->print_it = print_it_normal;
4616 /* The target has stopped with waitstatus WS. Check if any hardware
4617 watchpoints have triggered, according to the target. */
4620 watchpoints_triggered (struct target_waitstatus *ws)
4622 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4624 struct breakpoint *b;
4626 if (!stopped_by_watchpoint)
4628 /* We were not stopped by a watchpoint. Mark all watchpoints
4629 as not triggered. */
4631 if (is_hardware_watchpoint (b))
4633 struct watchpoint *w = (struct watchpoint *) b;
4635 w->watchpoint_triggered = watch_triggered_no;
4641 if (!target_stopped_data_address (¤t_target, &addr))
4643 /* We were stopped by a watchpoint, but we don't know where.
4644 Mark all watchpoints as unknown. */
4646 if (is_hardware_watchpoint (b))
4648 struct watchpoint *w = (struct watchpoint *) b;
4650 w->watchpoint_triggered = watch_triggered_unknown;
4653 return stopped_by_watchpoint;
4656 /* The target could report the data address. Mark watchpoints
4657 affected by this data address as triggered, and all others as not
4661 if (is_hardware_watchpoint (b))
4663 struct watchpoint *w = (struct watchpoint *) b;
4664 struct bp_location *loc;
4666 w->watchpoint_triggered = watch_triggered_no;
4667 for (loc = b->loc; loc; loc = loc->next)
4669 if (is_masked_watchpoint (b))
4671 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4672 CORE_ADDR start = loc->address & w->hw_wp_mask;
4674 if (newaddr == start)
4676 w->watchpoint_triggered = watch_triggered_yes;
4680 /* Exact match not required. Within range is sufficient. */
4681 else if (target_watchpoint_addr_within_range (¤t_target,
4685 w->watchpoint_triggered = watch_triggered_yes;
4694 /* Possible return values for watchpoint_check (this can't be an enum
4695 because of check_errors). */
4696 /* The watchpoint has been deleted. */
4697 #define WP_DELETED 1
4698 /* The value has changed. */
4699 #define WP_VALUE_CHANGED 2
4700 /* The value has not changed. */
4701 #define WP_VALUE_NOT_CHANGED 3
4702 /* Ignore this watchpoint, no matter if the value changed or not. */
4705 #define BP_TEMPFLAG 1
4706 #define BP_HARDWAREFLAG 2
4708 /* Evaluate watchpoint condition expression and check if its value
4711 P should be a pointer to struct bpstat, but is defined as a void *
4712 in order for this function to be usable with catch_errors. */
4715 watchpoint_check (void *p)
4717 bpstat bs = (bpstat) p;
4718 struct watchpoint *b;
4719 struct frame_info *fr;
4720 int within_current_scope;
4722 /* BS is built from an existing struct breakpoint. */
4723 gdb_assert (bs->breakpoint_at != NULL);
4724 b = (struct watchpoint *) bs->breakpoint_at;
4726 /* If this is a local watchpoint, we only want to check if the
4727 watchpoint frame is in scope if the current thread is the thread
4728 that was used to create the watchpoint. */
4729 if (!watchpoint_in_thread_scope (b))
4732 if (b->exp_valid_block == NULL)
4733 within_current_scope = 1;
4736 struct frame_info *frame = get_current_frame ();
4737 struct gdbarch *frame_arch = get_frame_arch (frame);
4738 CORE_ADDR frame_pc = get_frame_pc (frame);
4740 /* in_function_epilogue_p() returns a non-zero value if we're
4741 still in the function but the stack frame has already been
4742 invalidated. Since we can't rely on the values of local
4743 variables after the stack has been destroyed, we are treating
4744 the watchpoint in that state as `not changed' without further
4745 checking. Don't mark watchpoints as changed if the current
4746 frame is in an epilogue - even if they are in some other
4747 frame, our view of the stack is likely to be wrong and
4748 frame_find_by_id could error out. */
4749 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4752 fr = frame_find_by_id (b->watchpoint_frame);
4753 within_current_scope = (fr != NULL);
4755 /* If we've gotten confused in the unwinder, we might have
4756 returned a frame that can't describe this variable. */
4757 if (within_current_scope)
4759 struct symbol *function;
4761 function = get_frame_function (fr);
4762 if (function == NULL
4763 || !contained_in (b->exp_valid_block,
4764 SYMBOL_BLOCK_VALUE (function)))
4765 within_current_scope = 0;
4768 if (within_current_scope)
4769 /* If we end up stopping, the current frame will get selected
4770 in normal_stop. So this call to select_frame won't affect
4775 if (within_current_scope)
4777 /* We use value_{,free_to_}mark because it could be a *long*
4778 time before we return to the command level and call
4779 free_all_values. We can't call free_all_values because we
4780 might be in the middle of evaluating a function call. */
4784 struct value *new_val;
4786 if (is_masked_watchpoint (&b->base))
4787 /* Since we don't know the exact trigger address (from
4788 stopped_data_address), just tell the user we've triggered
4789 a mask watchpoint. */
4790 return WP_VALUE_CHANGED;
4792 mark = value_mark ();
4793 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4795 /* We use value_equal_contents instead of value_equal because
4796 the latter coerces an array to a pointer, thus comparing just
4797 the address of the array instead of its contents. This is
4798 not what we want. */
4799 if ((b->val != NULL) != (new_val != NULL)
4800 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4802 if (new_val != NULL)
4804 release_value (new_val);
4805 value_free_to_mark (mark);
4807 bs->old_val = b->val;
4810 return WP_VALUE_CHANGED;
4814 /* Nothing changed. */
4815 value_free_to_mark (mark);
4816 return WP_VALUE_NOT_CHANGED;
4821 struct ui_out *uiout = current_uiout;
4823 /* This seems like the only logical thing to do because
4824 if we temporarily ignored the watchpoint, then when
4825 we reenter the block in which it is valid it contains
4826 garbage (in the case of a function, it may have two
4827 garbage values, one before and one after the prologue).
4828 So we can't even detect the first assignment to it and
4829 watch after that (since the garbage may or may not equal
4830 the first value assigned). */
4831 /* We print all the stop information in
4832 breakpoint_ops->print_it, but in this case, by the time we
4833 call breakpoint_ops->print_it this bp will be deleted
4834 already. So we have no choice but print the information
4836 if (ui_out_is_mi_like_p (uiout))
4838 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4839 ui_out_text (uiout, "\nWatchpoint ");
4840 ui_out_field_int (uiout, "wpnum", b->base.number);
4842 " deleted because the program has left the block in\n\
4843 which its expression is valid.\n");
4845 /* Make sure the watchpoint's commands aren't executed. */
4846 decref_counted_command_line (&b->base.commands);
4847 watchpoint_del_at_next_stop (b);
4853 /* Return true if it looks like target has stopped due to hitting
4854 breakpoint location BL. This function does not check if we should
4855 stop, only if BL explains the stop. */
4858 bpstat_check_location (const struct bp_location *bl,
4859 struct address_space *aspace, CORE_ADDR bp_addr,
4860 const struct target_waitstatus *ws)
4862 struct breakpoint *b = bl->owner;
4864 /* BL is from an existing breakpoint. */
4865 gdb_assert (b != NULL);
4867 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4870 /* Determine if the watched values have actually changed, and we
4871 should stop. If not, set BS->stop to 0. */
4874 bpstat_check_watchpoint (bpstat bs)
4876 const struct bp_location *bl;
4877 struct watchpoint *b;
4879 /* BS is built for existing struct breakpoint. */
4880 bl = bs->bp_location_at;
4881 gdb_assert (bl != NULL);
4882 b = (struct watchpoint *) bs->breakpoint_at;
4883 gdb_assert (b != NULL);
4886 int must_check_value = 0;
4888 if (b->base.type == bp_watchpoint)
4889 /* For a software watchpoint, we must always check the
4891 must_check_value = 1;
4892 else if (b->watchpoint_triggered == watch_triggered_yes)
4893 /* We have a hardware watchpoint (read, write, or access)
4894 and the target earlier reported an address watched by
4896 must_check_value = 1;
4897 else if (b->watchpoint_triggered == watch_triggered_unknown
4898 && b->base.type == bp_hardware_watchpoint)
4899 /* We were stopped by a hardware watchpoint, but the target could
4900 not report the data address. We must check the watchpoint's
4901 value. Access and read watchpoints are out of luck; without
4902 a data address, we can't figure it out. */
4903 must_check_value = 1;
4905 if (must_check_value)
4908 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4910 struct cleanup *cleanups = make_cleanup (xfree, message);
4911 int e = catch_errors (watchpoint_check, bs, message,
4913 do_cleanups (cleanups);
4917 /* We've already printed what needs to be printed. */
4918 bs->print_it = print_it_done;
4922 bs->print_it = print_it_noop;
4925 case WP_VALUE_CHANGED:
4926 if (b->base.type == bp_read_watchpoint)
4928 /* There are two cases to consider here:
4930 1. We're watching the triggered memory for reads.
4931 In that case, trust the target, and always report
4932 the watchpoint hit to the user. Even though
4933 reads don't cause value changes, the value may
4934 have changed since the last time it was read, and
4935 since we're not trapping writes, we will not see
4936 those, and as such we should ignore our notion of
4939 2. We're watching the triggered memory for both
4940 reads and writes. There are two ways this may
4943 2.1. This is a target that can't break on data
4944 reads only, but can break on accesses (reads or
4945 writes), such as e.g., x86. We detect this case
4946 at the time we try to insert read watchpoints.
4948 2.2. Otherwise, the target supports read
4949 watchpoints, but, the user set an access or write
4950 watchpoint watching the same memory as this read
4953 If we're watching memory writes as well as reads,
4954 ignore watchpoint hits when we find that the
4955 value hasn't changed, as reads don't cause
4956 changes. This still gives false positives when
4957 the program writes the same value to memory as
4958 what there was already in memory (we will confuse
4959 it for a read), but it's much better than
4962 int other_write_watchpoint = 0;
4964 if (bl->watchpoint_type == hw_read)
4966 struct breakpoint *other_b;
4968 ALL_BREAKPOINTS (other_b)
4969 if (other_b->type == bp_hardware_watchpoint
4970 || other_b->type == bp_access_watchpoint)
4972 struct watchpoint *other_w =
4973 (struct watchpoint *) other_b;
4975 if (other_w->watchpoint_triggered
4976 == watch_triggered_yes)
4978 other_write_watchpoint = 1;
4984 if (other_write_watchpoint
4985 || bl->watchpoint_type == hw_access)
4987 /* We're watching the same memory for writes,
4988 and the value changed since the last time we
4989 updated it, so this trap must be for a write.
4991 bs->print_it = print_it_noop;
4996 case WP_VALUE_NOT_CHANGED:
4997 if (b->base.type == bp_hardware_watchpoint
4998 || b->base.type == bp_watchpoint)
5000 /* Don't stop: write watchpoints shouldn't fire if
5001 the value hasn't changed. */
5002 bs->print_it = print_it_noop;
5010 /* Error from catch_errors. */
5011 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5012 watchpoint_del_at_next_stop (b);
5013 /* We've already printed what needs to be printed. */
5014 bs->print_it = print_it_done;
5018 else /* must_check_value == 0 */
5020 /* This is a case where some watchpoint(s) triggered, but
5021 not at the address of this watchpoint, or else no
5022 watchpoint triggered after all. So don't print
5023 anything for this watchpoint. */
5024 bs->print_it = print_it_noop;
5031 /* Check conditions (condition proper, frame, thread and ignore count)
5032 of breakpoint referred to by BS. If we should not stop for this
5033 breakpoint, set BS->stop to 0. */
5036 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5038 int thread_id = pid_to_thread_id (ptid);
5039 const struct bp_location *bl;
5040 struct breakpoint *b;
5042 /* BS is built for existing struct breakpoint. */
5043 bl = bs->bp_location_at;
5044 gdb_assert (bl != NULL);
5045 b = bs->breakpoint_at;
5046 gdb_assert (b != NULL);
5048 /* Even if the target evaluated the condition on its end and notified GDB, we
5049 need to do so again since GDB does not know if we stopped due to a
5050 breakpoint or a single step breakpoint. */
5052 if (frame_id_p (b->frame_id)
5053 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5057 int value_is_zero = 0;
5058 struct expression *cond;
5060 /* Evaluate Python breakpoints that have a "stop"
5061 method implemented. */
5062 if (b->py_bp_object)
5063 bs->stop = gdbpy_should_stop (b->py_bp_object);
5065 if (is_watchpoint (b))
5067 struct watchpoint *w = (struct watchpoint *) b;
5074 if (cond && b->disposition != disp_del_at_next_stop)
5076 int within_current_scope = 1;
5077 struct watchpoint * w;
5079 /* We use value_mark and value_free_to_mark because it could
5080 be a long time before we return to the command level and
5081 call free_all_values. We can't call free_all_values
5082 because we might be in the middle of evaluating a
5084 struct value *mark = value_mark ();
5086 if (is_watchpoint (b))
5087 w = (struct watchpoint *) b;
5091 /* Need to select the frame, with all that implies so that
5092 the conditions will have the right context. Because we
5093 use the frame, we will not see an inlined function's
5094 variables when we arrive at a breakpoint at the start
5095 of the inlined function; the current frame will be the
5097 if (w == NULL || w->cond_exp_valid_block == NULL)
5098 select_frame (get_current_frame ());
5101 struct frame_info *frame;
5103 /* For local watchpoint expressions, which particular
5104 instance of a local is being watched matters, so we
5105 keep track of the frame to evaluate the expression
5106 in. To evaluate the condition however, it doesn't
5107 really matter which instantiation of the function
5108 where the condition makes sense triggers the
5109 watchpoint. This allows an expression like "watch
5110 global if q > 10" set in `func', catch writes to
5111 global on all threads that call `func', or catch
5112 writes on all recursive calls of `func' by a single
5113 thread. We simply always evaluate the condition in
5114 the innermost frame that's executing where it makes
5115 sense to evaluate the condition. It seems
5117 frame = block_innermost_frame (w->cond_exp_valid_block);
5119 select_frame (frame);
5121 within_current_scope = 0;
5123 if (within_current_scope)
5125 = catch_errors (breakpoint_cond_eval, cond,
5126 "Error in testing breakpoint condition:\n",
5130 warning (_("Watchpoint condition cannot be tested "
5131 "in the current scope"));
5132 /* If we failed to set the right context for this
5133 watchpoint, unconditionally report it. */
5136 /* FIXME-someday, should give breakpoint #. */
5137 value_free_to_mark (mark);
5140 if (cond && value_is_zero)
5144 else if (b->thread != -1 && b->thread != thread_id)
5148 else if (b->ignore_count > 0)
5152 /* Increase the hit count even though we don't stop. */
5154 observer_notify_breakpoint_modified (b);
5160 /* Get a bpstat associated with having just stopped at address
5161 BP_ADDR in thread PTID.
5163 Determine whether we stopped at a breakpoint, etc, or whether we
5164 don't understand this stop. Result is a chain of bpstat's such
5167 if we don't understand the stop, the result is a null pointer.
5169 if we understand why we stopped, the result is not null.
5171 Each element of the chain refers to a particular breakpoint or
5172 watchpoint at which we have stopped. (We may have stopped for
5173 several reasons concurrently.)
5175 Each element of the chain has valid next, breakpoint_at,
5176 commands, FIXME??? fields. */
5179 bpstat_stop_status (struct address_space *aspace,
5180 CORE_ADDR bp_addr, ptid_t ptid,
5181 const struct target_waitstatus *ws)
5183 struct breakpoint *b = NULL;
5184 struct bp_location *bl;
5185 struct bp_location *loc;
5186 /* First item of allocated bpstat's. */
5187 bpstat bs_head = NULL, *bs_link = &bs_head;
5188 /* Pointer to the last thing in the chain currently. */
5191 int need_remove_insert;
5194 /* First, build the bpstat chain with locations that explain a
5195 target stop, while being careful to not set the target running,
5196 as that may invalidate locations (in particular watchpoint
5197 locations are recreated). Resuming will happen here with
5198 breakpoint conditions or watchpoint expressions that include
5199 inferior function calls. */
5203 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5206 for (bl = b->loc; bl != NULL; bl = bl->next)
5208 /* For hardware watchpoints, we look only at the first
5209 location. The watchpoint_check function will work on the
5210 entire expression, not the individual locations. For
5211 read watchpoints, the watchpoints_triggered function has
5212 checked all locations already. */
5213 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5216 if (!bl->enabled || bl->shlib_disabled)
5219 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5222 /* Come here if it's a watchpoint, or if the break address
5225 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5228 /* Assume we stop. Should we find a watchpoint that is not
5229 actually triggered, or if the condition of the breakpoint
5230 evaluates as false, we'll reset 'stop' to 0. */
5234 /* If this is a scope breakpoint, mark the associated
5235 watchpoint as triggered so that we will handle the
5236 out-of-scope event. We'll get to the watchpoint next
5238 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5240 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5242 w->watchpoint_triggered = watch_triggered_yes;
5247 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5249 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5251 bs = bpstat_alloc (loc, &bs_link);
5252 /* For hits of moribund locations, we should just proceed. */
5255 bs->print_it = print_it_noop;
5259 /* A bit of special processing for shlib breakpoints. We need to
5260 process solib loading here, so that the lists of loaded and
5261 unloaded libraries are correct before we handle "catch load" and
5263 for (bs = bs_head; bs != NULL; bs = bs->next)
5265 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5267 handle_solib_event ();
5272 /* Now go through the locations that caused the target to stop, and
5273 check whether we're interested in reporting this stop to higher
5274 layers, or whether we should resume the target transparently. */
5278 for (bs = bs_head; bs != NULL; bs = bs->next)
5283 b = bs->breakpoint_at;
5284 b->ops->check_status (bs);
5287 bpstat_check_breakpoint_conditions (bs, ptid);
5292 observer_notify_breakpoint_modified (b);
5294 /* We will stop here. */
5295 if (b->disposition == disp_disable)
5297 --(b->enable_count);
5298 if (b->enable_count <= 0
5299 && b->enable_state != bp_permanent)
5300 b->enable_state = bp_disabled;
5305 bs->commands = b->commands;
5306 incref_counted_command_line (bs->commands);
5307 if (command_line_is_silent (bs->commands
5308 ? bs->commands->commands : NULL))
5314 /* Print nothing for this entry if we don't stop or don't
5316 if (!bs->stop || !bs->print)
5317 bs->print_it = print_it_noop;
5320 /* If we aren't stopping, the value of some hardware watchpoint may
5321 not have changed, but the intermediate memory locations we are
5322 watching may have. Don't bother if we're stopping; this will get
5324 need_remove_insert = 0;
5325 if (! bpstat_causes_stop (bs_head))
5326 for (bs = bs_head; bs != NULL; bs = bs->next)
5328 && bs->breakpoint_at
5329 && is_hardware_watchpoint (bs->breakpoint_at))
5331 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5333 update_watchpoint (w, 0 /* don't reparse. */);
5334 need_remove_insert = 1;
5337 if (need_remove_insert)
5338 update_global_location_list (1);
5339 else if (removed_any)
5340 update_global_location_list (0);
5346 handle_jit_event (void)
5348 struct frame_info *frame;
5349 struct gdbarch *gdbarch;
5351 /* Switch terminal for any messages produced by
5352 breakpoint_re_set. */
5353 target_terminal_ours_for_output ();
5355 frame = get_current_frame ();
5356 gdbarch = get_frame_arch (frame);
5358 jit_event_handler (gdbarch);
5360 target_terminal_inferior ();
5363 /* Handle an solib event by calling solib_add. */
5366 handle_solib_event (void)
5368 clear_program_space_solib_cache (current_inferior ()->pspace);
5370 /* Check for any newly added shared libraries if we're supposed to
5371 be adding them automatically. Switch terminal for any messages
5372 produced by breakpoint_re_set. */
5373 target_terminal_ours_for_output ();
5375 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5377 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5379 target_terminal_inferior ();
5382 /* Prepare WHAT final decision for infrun. */
5384 /* Decide what infrun needs to do with this bpstat. */
5387 bpstat_what (bpstat bs_head)
5389 struct bpstat_what retval;
5393 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5394 retval.call_dummy = STOP_NONE;
5395 retval.is_longjmp = 0;
5397 for (bs = bs_head; bs != NULL; bs = bs->next)
5399 /* Extract this BS's action. After processing each BS, we check
5400 if its action overrides all we've seem so far. */
5401 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5404 if (bs->breakpoint_at == NULL)
5406 /* I suspect this can happen if it was a momentary
5407 breakpoint which has since been deleted. */
5411 bptype = bs->breakpoint_at->type;
5418 case bp_hardware_breakpoint:
5421 case bp_shlib_event:
5425 this_action = BPSTAT_WHAT_STOP_NOISY;
5427 this_action = BPSTAT_WHAT_STOP_SILENT;
5430 this_action = BPSTAT_WHAT_SINGLE;
5433 case bp_hardware_watchpoint:
5434 case bp_read_watchpoint:
5435 case bp_access_watchpoint:
5439 this_action = BPSTAT_WHAT_STOP_NOISY;
5441 this_action = BPSTAT_WHAT_STOP_SILENT;
5445 /* There was a watchpoint, but we're not stopping.
5446 This requires no further action. */
5450 case bp_longjmp_call_dummy:
5452 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5453 retval.is_longjmp = bptype != bp_exception;
5455 case bp_longjmp_resume:
5456 case bp_exception_resume:
5457 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5458 retval.is_longjmp = bptype == bp_longjmp_resume;
5460 case bp_step_resume:
5462 this_action = BPSTAT_WHAT_STEP_RESUME;
5465 /* It is for the wrong frame. */
5466 this_action = BPSTAT_WHAT_SINGLE;
5469 case bp_hp_step_resume:
5471 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5474 /* It is for the wrong frame. */
5475 this_action = BPSTAT_WHAT_SINGLE;
5478 case bp_watchpoint_scope:
5479 case bp_thread_event:
5480 case bp_overlay_event:
5481 case bp_longjmp_master:
5482 case bp_std_terminate_master:
5483 case bp_exception_master:
5484 this_action = BPSTAT_WHAT_SINGLE;
5490 this_action = BPSTAT_WHAT_STOP_NOISY;
5492 this_action = BPSTAT_WHAT_STOP_SILENT;
5496 /* There was a catchpoint, but we're not stopping.
5497 This requires no further action. */
5502 this_action = BPSTAT_WHAT_SINGLE;
5505 /* Make sure the action is stop (silent or noisy),
5506 so infrun.c pops the dummy frame. */
5507 retval.call_dummy = STOP_STACK_DUMMY;
5508 this_action = BPSTAT_WHAT_STOP_SILENT;
5510 case bp_std_terminate:
5511 /* Make sure the action is stop (silent or noisy),
5512 so infrun.c pops the dummy frame. */
5513 retval.call_dummy = STOP_STD_TERMINATE;
5514 this_action = BPSTAT_WHAT_STOP_SILENT;
5517 case bp_fast_tracepoint:
5518 case bp_static_tracepoint:
5519 /* Tracepoint hits should not be reported back to GDB, and
5520 if one got through somehow, it should have been filtered
5522 internal_error (__FILE__, __LINE__,
5523 _("bpstat_what: tracepoint encountered"));
5525 case bp_gnu_ifunc_resolver:
5526 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5527 this_action = BPSTAT_WHAT_SINGLE;
5529 case bp_gnu_ifunc_resolver_return:
5530 /* The breakpoint will be removed, execution will restart from the
5531 PC of the former breakpoint. */
5532 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5536 this_action = BPSTAT_WHAT_STOP_SILENT;
5540 internal_error (__FILE__, __LINE__,
5541 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5544 retval.main_action = max (retval.main_action, this_action);
5547 /* These operations may affect the bs->breakpoint_at state so they are
5548 delayed after MAIN_ACTION is decided above. */
5553 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5555 handle_jit_event ();
5558 for (bs = bs_head; bs != NULL; bs = bs->next)
5560 struct breakpoint *b = bs->breakpoint_at;
5566 case bp_gnu_ifunc_resolver:
5567 gnu_ifunc_resolver_stop (b);
5569 case bp_gnu_ifunc_resolver_return:
5570 gnu_ifunc_resolver_return_stop (b);
5578 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5579 without hardware support). This isn't related to a specific bpstat,
5580 just to things like whether watchpoints are set. */
5583 bpstat_should_step (void)
5585 struct breakpoint *b;
5588 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5594 bpstat_causes_stop (bpstat bs)
5596 for (; bs != NULL; bs = bs->next)
5605 /* Compute a string of spaces suitable to indent the next line
5606 so it starts at the position corresponding to the table column
5607 named COL_NAME in the currently active table of UIOUT. */
5610 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5612 static char wrap_indent[80];
5613 int i, total_width, width, align;
5617 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5619 if (strcmp (text, col_name) == 0)
5621 gdb_assert (total_width < sizeof wrap_indent);
5622 memset (wrap_indent, ' ', total_width);
5623 wrap_indent[total_width] = 0;
5628 total_width += width + 1;
5634 /* Determine if the locations of this breakpoint will have their conditions
5635 evaluated by the target, host or a mix of both. Returns the following:
5637 "host": Host evals condition.
5638 "host or target": Host or Target evals condition.
5639 "target": Target evals condition.
5643 bp_condition_evaluator (struct breakpoint *b)
5645 struct bp_location *bl;
5646 char host_evals = 0;
5647 char target_evals = 0;
5652 if (!is_breakpoint (b))
5655 if (gdb_evaluates_breakpoint_condition_p ()
5656 || !target_supports_evaluation_of_breakpoint_conditions ())
5657 return condition_evaluation_host;
5659 for (bl = b->loc; bl; bl = bl->next)
5661 if (bl->cond_bytecode)
5667 if (host_evals && target_evals)
5668 return condition_evaluation_both;
5669 else if (target_evals)
5670 return condition_evaluation_target;
5672 return condition_evaluation_host;
5675 /* Determine the breakpoint location's condition evaluator. This is
5676 similar to bp_condition_evaluator, but for locations. */
5679 bp_location_condition_evaluator (struct bp_location *bl)
5681 if (bl && !is_breakpoint (bl->owner))
5684 if (gdb_evaluates_breakpoint_condition_p ()
5685 || !target_supports_evaluation_of_breakpoint_conditions ())
5686 return condition_evaluation_host;
5688 if (bl && bl->cond_bytecode)
5689 return condition_evaluation_target;
5691 return condition_evaluation_host;
5694 /* Print the LOC location out of the list of B->LOC locations. */
5697 print_breakpoint_location (struct breakpoint *b,
5698 struct bp_location *loc)
5700 struct ui_out *uiout = current_uiout;
5701 struct cleanup *old_chain = save_current_program_space ();
5703 if (loc != NULL && loc->shlib_disabled)
5707 set_current_program_space (loc->pspace);
5709 if (b->display_canonical)
5710 ui_out_field_string (uiout, "what", b->addr_string);
5711 else if (loc && loc->symtab)
5714 = find_pc_sect_function (loc->address, loc->section);
5717 ui_out_text (uiout, "in ");
5718 ui_out_field_string (uiout, "func",
5719 SYMBOL_PRINT_NAME (sym));
5720 ui_out_text (uiout, " ");
5721 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5722 ui_out_text (uiout, "at ");
5724 ui_out_field_string (uiout, "file",
5725 symtab_to_filename_for_display (loc->symtab));
5726 ui_out_text (uiout, ":");
5728 if (ui_out_is_mi_like_p (uiout))
5729 ui_out_field_string (uiout, "fullname",
5730 symtab_to_fullname (loc->symtab));
5732 ui_out_field_int (uiout, "line", loc->line_number);
5736 struct ui_file *stb = mem_fileopen ();
5737 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5739 print_address_symbolic (loc->gdbarch, loc->address, stb,
5741 ui_out_field_stream (uiout, "at", stb);
5743 do_cleanups (stb_chain);
5746 ui_out_field_string (uiout, "pending", b->addr_string);
5748 if (loc && is_breakpoint (b)
5749 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5750 && bp_condition_evaluator (b) == condition_evaluation_both)
5752 ui_out_text (uiout, " (");
5753 ui_out_field_string (uiout, "evaluated-by",
5754 bp_location_condition_evaluator (loc));
5755 ui_out_text (uiout, ")");
5758 do_cleanups (old_chain);
5762 bptype_string (enum bptype type)
5764 struct ep_type_description
5769 static struct ep_type_description bptypes[] =
5771 {bp_none, "?deleted?"},
5772 {bp_breakpoint, "breakpoint"},
5773 {bp_hardware_breakpoint, "hw breakpoint"},
5774 {bp_until, "until"},
5775 {bp_finish, "finish"},
5776 {bp_watchpoint, "watchpoint"},
5777 {bp_hardware_watchpoint, "hw watchpoint"},
5778 {bp_read_watchpoint, "read watchpoint"},
5779 {bp_access_watchpoint, "acc watchpoint"},
5780 {bp_longjmp, "longjmp"},
5781 {bp_longjmp_resume, "longjmp resume"},
5782 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5783 {bp_exception, "exception"},
5784 {bp_exception_resume, "exception resume"},
5785 {bp_step_resume, "step resume"},
5786 {bp_hp_step_resume, "high-priority step resume"},
5787 {bp_watchpoint_scope, "watchpoint scope"},
5788 {bp_call_dummy, "call dummy"},
5789 {bp_std_terminate, "std::terminate"},
5790 {bp_shlib_event, "shlib events"},
5791 {bp_thread_event, "thread events"},
5792 {bp_overlay_event, "overlay events"},
5793 {bp_longjmp_master, "longjmp master"},
5794 {bp_std_terminate_master, "std::terminate master"},
5795 {bp_exception_master, "exception master"},
5796 {bp_catchpoint, "catchpoint"},
5797 {bp_tracepoint, "tracepoint"},
5798 {bp_fast_tracepoint, "fast tracepoint"},
5799 {bp_static_tracepoint, "static tracepoint"},
5800 {bp_dprintf, "dprintf"},
5801 {bp_jit_event, "jit events"},
5802 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5803 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5806 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5807 || ((int) type != bptypes[(int) type].type))
5808 internal_error (__FILE__, __LINE__,
5809 _("bptypes table does not describe type #%d."),
5812 return bptypes[(int) type].description;
5817 /* For MI, output a field named 'thread-groups' with a list as the value.
5818 For CLI, prefix the list with the string 'inf'. */
5821 output_thread_groups (struct ui_out *uiout,
5822 const char *field_name,
5826 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
5828 int is_mi = ui_out_is_mi_like_p (uiout);
5832 /* For backward compatibility, don't display inferiors in CLI unless
5833 there are several. Always display them for MI. */
5834 if (!is_mi && mi_only)
5837 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
5843 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
5844 ui_out_field_string (uiout, NULL, mi_group);
5849 ui_out_text (uiout, " inf ");
5851 ui_out_text (uiout, ", ");
5853 ui_out_text (uiout, plongest (inf));
5857 do_cleanups (back_to);
5860 /* Print B to gdb_stdout. */
5863 print_one_breakpoint_location (struct breakpoint *b,
5864 struct bp_location *loc,
5866 struct bp_location **last_loc,
5869 struct command_line *l;
5870 static char bpenables[] = "nynny";
5872 struct ui_out *uiout = current_uiout;
5873 int header_of_multiple = 0;
5874 int part_of_multiple = (loc != NULL);
5875 struct value_print_options opts;
5877 get_user_print_options (&opts);
5879 gdb_assert (!loc || loc_number != 0);
5880 /* See comment in print_one_breakpoint concerning treatment of
5881 breakpoints with single disabled location. */
5884 && (b->loc->next != NULL || !b->loc->enabled)))
5885 header_of_multiple = 1;
5893 if (part_of_multiple)
5896 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5897 ui_out_field_string (uiout, "number", formatted);
5902 ui_out_field_int (uiout, "number", b->number);
5907 if (part_of_multiple)
5908 ui_out_field_skip (uiout, "type");
5910 ui_out_field_string (uiout, "type", bptype_string (b->type));
5914 if (part_of_multiple)
5915 ui_out_field_skip (uiout, "disp");
5917 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5922 if (part_of_multiple)
5923 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5925 ui_out_field_fmt (uiout, "enabled", "%c",
5926 bpenables[(int) b->enable_state]);
5927 ui_out_spaces (uiout, 2);
5931 if (b->ops != NULL && b->ops->print_one != NULL)
5933 /* Although the print_one can possibly print all locations,
5934 calling it here is not likely to get any nice result. So,
5935 make sure there's just one location. */
5936 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5937 b->ops->print_one (b, last_loc);
5943 internal_error (__FILE__, __LINE__,
5944 _("print_one_breakpoint: bp_none encountered\n"));
5948 case bp_hardware_watchpoint:
5949 case bp_read_watchpoint:
5950 case bp_access_watchpoint:
5952 struct watchpoint *w = (struct watchpoint *) b;
5954 /* Field 4, the address, is omitted (which makes the columns
5955 not line up too nicely with the headers, but the effect
5956 is relatively readable). */
5957 if (opts.addressprint)
5958 ui_out_field_skip (uiout, "addr");
5960 ui_out_field_string (uiout, "what", w->exp_string);
5965 case bp_hardware_breakpoint:
5969 case bp_longjmp_resume:
5970 case bp_longjmp_call_dummy:
5972 case bp_exception_resume:
5973 case bp_step_resume:
5974 case bp_hp_step_resume:
5975 case bp_watchpoint_scope:
5977 case bp_std_terminate:
5978 case bp_shlib_event:
5979 case bp_thread_event:
5980 case bp_overlay_event:
5981 case bp_longjmp_master:
5982 case bp_std_terminate_master:
5983 case bp_exception_master:
5985 case bp_fast_tracepoint:
5986 case bp_static_tracepoint:
5989 case bp_gnu_ifunc_resolver:
5990 case bp_gnu_ifunc_resolver_return:
5991 if (opts.addressprint)
5994 if (header_of_multiple)
5995 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5996 else if (b->loc == NULL || loc->shlib_disabled)
5997 ui_out_field_string (uiout, "addr", "<PENDING>");
5999 ui_out_field_core_addr (uiout, "addr",
6000 loc->gdbarch, loc->address);
6003 if (!header_of_multiple)
6004 print_breakpoint_location (b, loc);
6011 if (loc != NULL && !header_of_multiple)
6013 struct inferior *inf;
6014 VEC(int) *inf_num = NULL;
6019 if (inf->pspace == loc->pspace)
6020 VEC_safe_push (int, inf_num, inf->num);
6023 /* For backward compatibility, don't display inferiors in CLI unless
6024 there are several. Always display for MI. */
6026 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6027 && (number_of_program_spaces () > 1
6028 || number_of_inferiors () > 1)
6029 /* LOC is for existing B, it cannot be in
6030 moribund_locations and thus having NULL OWNER. */
6031 && loc->owner->type != bp_catchpoint))
6033 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6034 VEC_free (int, inf_num);
6037 if (!part_of_multiple)
6039 if (b->thread != -1)
6041 /* FIXME: This seems to be redundant and lost here; see the
6042 "stop only in" line a little further down. */
6043 ui_out_text (uiout, " thread ");
6044 ui_out_field_int (uiout, "thread", b->thread);
6046 else if (b->task != 0)
6048 ui_out_text (uiout, " task ");
6049 ui_out_field_int (uiout, "task", b->task);
6053 ui_out_text (uiout, "\n");
6055 if (!part_of_multiple)
6056 b->ops->print_one_detail (b, uiout);
6058 if (part_of_multiple && frame_id_p (b->frame_id))
6061 ui_out_text (uiout, "\tstop only in stack frame at ");
6062 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6064 ui_out_field_core_addr (uiout, "frame",
6065 b->gdbarch, b->frame_id.stack_addr);
6066 ui_out_text (uiout, "\n");
6069 if (!part_of_multiple && b->cond_string)
6072 if (is_tracepoint (b))
6073 ui_out_text (uiout, "\ttrace only if ");
6075 ui_out_text (uiout, "\tstop only if ");
6076 ui_out_field_string (uiout, "cond", b->cond_string);
6078 /* Print whether the target is doing the breakpoint's condition
6079 evaluation. If GDB is doing the evaluation, don't print anything. */
6080 if (is_breakpoint (b)
6081 && breakpoint_condition_evaluation_mode ()
6082 == condition_evaluation_target)
6084 ui_out_text (uiout, " (");
6085 ui_out_field_string (uiout, "evaluated-by",
6086 bp_condition_evaluator (b));
6087 ui_out_text (uiout, " evals)");
6089 ui_out_text (uiout, "\n");
6092 if (!part_of_multiple && b->thread != -1)
6094 /* FIXME should make an annotation for this. */
6095 ui_out_text (uiout, "\tstop only in thread ");
6096 ui_out_field_int (uiout, "thread", b->thread);
6097 ui_out_text (uiout, "\n");
6100 if (!part_of_multiple)
6104 /* FIXME should make an annotation for this. */
6105 if (is_catchpoint (b))
6106 ui_out_text (uiout, "\tcatchpoint");
6107 else if (is_tracepoint (b))
6108 ui_out_text (uiout, "\ttracepoint");
6110 ui_out_text (uiout, "\tbreakpoint");
6111 ui_out_text (uiout, " already hit ");
6112 ui_out_field_int (uiout, "times", b->hit_count);
6113 if (b->hit_count == 1)
6114 ui_out_text (uiout, " time\n");
6116 ui_out_text (uiout, " times\n");
6120 /* Output the count also if it is zero, but only if this is mi. */
6121 if (ui_out_is_mi_like_p (uiout))
6122 ui_out_field_int (uiout, "times", b->hit_count);
6126 if (!part_of_multiple && b->ignore_count)
6129 ui_out_text (uiout, "\tignore next ");
6130 ui_out_field_int (uiout, "ignore", b->ignore_count);
6131 ui_out_text (uiout, " hits\n");
6134 /* Note that an enable count of 1 corresponds to "enable once"
6135 behavior, which is reported by the combination of enablement and
6136 disposition, so we don't need to mention it here. */
6137 if (!part_of_multiple && b->enable_count > 1)
6140 ui_out_text (uiout, "\tdisable after ");
6141 /* Tweak the wording to clarify that ignore and enable counts
6142 are distinct, and have additive effect. */
6143 if (b->ignore_count)
6144 ui_out_text (uiout, "additional ");
6146 ui_out_text (uiout, "next ");
6147 ui_out_field_int (uiout, "enable", b->enable_count);
6148 ui_out_text (uiout, " hits\n");
6151 if (!part_of_multiple && is_tracepoint (b))
6153 struct tracepoint *tp = (struct tracepoint *) b;
6155 if (tp->traceframe_usage)
6157 ui_out_text (uiout, "\ttrace buffer usage ");
6158 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6159 ui_out_text (uiout, " bytes\n");
6163 l = b->commands ? b->commands->commands : NULL;
6164 if (!part_of_multiple && l)
6166 struct cleanup *script_chain;
6169 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6170 print_command_lines (uiout, l, 4);
6171 do_cleanups (script_chain);
6174 if (is_tracepoint (b))
6176 struct tracepoint *t = (struct tracepoint *) b;
6178 if (!part_of_multiple && t->pass_count)
6180 annotate_field (10);
6181 ui_out_text (uiout, "\tpass count ");
6182 ui_out_field_int (uiout, "pass", t->pass_count);
6183 ui_out_text (uiout, " \n");
6186 /* Don't display it when tracepoint or tracepoint location is
6188 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6190 annotate_field (11);
6192 if (ui_out_is_mi_like_p (uiout))
6193 ui_out_field_string (uiout, "installed",
6194 loc->inserted ? "y" : "n");
6198 ui_out_text (uiout, "\t");
6200 ui_out_text (uiout, "\tnot ");
6201 ui_out_text (uiout, "installed on target\n");
6206 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6208 if (is_watchpoint (b))
6210 struct watchpoint *w = (struct watchpoint *) b;
6212 ui_out_field_string (uiout, "original-location", w->exp_string);
6214 else if (b->addr_string)
6215 ui_out_field_string (uiout, "original-location", b->addr_string);
6220 print_one_breakpoint (struct breakpoint *b,
6221 struct bp_location **last_loc,
6224 struct cleanup *bkpt_chain;
6225 struct ui_out *uiout = current_uiout;
6227 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6229 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6230 do_cleanups (bkpt_chain);
6232 /* If this breakpoint has custom print function,
6233 it's already printed. Otherwise, print individual
6234 locations, if any. */
6235 if (b->ops == NULL || b->ops->print_one == NULL)
6237 /* If breakpoint has a single location that is disabled, we
6238 print it as if it had several locations, since otherwise it's
6239 hard to represent "breakpoint enabled, location disabled"
6242 Note that while hardware watchpoints have several locations
6243 internally, that's not a property exposed to user. */
6245 && !is_hardware_watchpoint (b)
6246 && (b->loc->next || !b->loc->enabled))
6248 struct bp_location *loc;
6251 for (loc = b->loc; loc; loc = loc->next, ++n)
6253 struct cleanup *inner2 =
6254 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6255 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6256 do_cleanups (inner2);
6263 breakpoint_address_bits (struct breakpoint *b)
6265 int print_address_bits = 0;
6266 struct bp_location *loc;
6268 for (loc = b->loc; loc; loc = loc->next)
6272 /* Software watchpoints that aren't watching memory don't have
6273 an address to print. */
6274 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6277 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6278 if (addr_bit > print_address_bits)
6279 print_address_bits = addr_bit;
6282 return print_address_bits;
6285 struct captured_breakpoint_query_args
6291 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6293 struct captured_breakpoint_query_args *args = data;
6294 struct breakpoint *b;
6295 struct bp_location *dummy_loc = NULL;
6299 if (args->bnum == b->number)
6301 print_one_breakpoint (b, &dummy_loc, 0);
6309 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6310 char **error_message)
6312 struct captured_breakpoint_query_args args;
6315 /* For the moment we don't trust print_one_breakpoint() to not throw
6317 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6318 error_message, RETURN_MASK_ALL) < 0)
6324 /* Return true if this breakpoint was set by the user, false if it is
6325 internal or momentary. */
6328 user_breakpoint_p (struct breakpoint *b)
6330 return b->number > 0;
6333 /* Print information on user settable breakpoint (watchpoint, etc)
6334 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6335 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6336 FILTER is non-NULL, call it on each breakpoint and only include the
6337 ones for which it returns non-zero. Return the total number of
6338 breakpoints listed. */
6341 breakpoint_1 (char *args, int allflag,
6342 int (*filter) (const struct breakpoint *))
6344 struct breakpoint *b;
6345 struct bp_location *last_loc = NULL;
6346 int nr_printable_breakpoints;
6347 struct cleanup *bkpttbl_chain;
6348 struct value_print_options opts;
6349 int print_address_bits = 0;
6350 int print_type_col_width = 14;
6351 struct ui_out *uiout = current_uiout;
6353 get_user_print_options (&opts);
6355 /* Compute the number of rows in the table, as well as the size
6356 required for address fields. */
6357 nr_printable_breakpoints = 0;
6360 /* If we have a filter, only list the breakpoints it accepts. */
6361 if (filter && !filter (b))
6364 /* If we have an "args" string, it is a list of breakpoints to
6365 accept. Skip the others. */
6366 if (args != NULL && *args != '\0')
6368 if (allflag && parse_and_eval_long (args) != b->number)
6370 if (!allflag && !number_is_in_list (args, b->number))
6374 if (allflag || user_breakpoint_p (b))
6376 int addr_bit, type_len;
6378 addr_bit = breakpoint_address_bits (b);
6379 if (addr_bit > print_address_bits)
6380 print_address_bits = addr_bit;
6382 type_len = strlen (bptype_string (b->type));
6383 if (type_len > print_type_col_width)
6384 print_type_col_width = type_len;
6386 nr_printable_breakpoints++;
6390 if (opts.addressprint)
6392 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6393 nr_printable_breakpoints,
6397 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6398 nr_printable_breakpoints,
6401 if (nr_printable_breakpoints > 0)
6402 annotate_breakpoints_headers ();
6403 if (nr_printable_breakpoints > 0)
6405 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6406 if (nr_printable_breakpoints > 0)
6408 ui_out_table_header (uiout, print_type_col_width, ui_left,
6409 "type", "Type"); /* 2 */
6410 if (nr_printable_breakpoints > 0)
6412 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6413 if (nr_printable_breakpoints > 0)
6415 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6416 if (opts.addressprint)
6418 if (nr_printable_breakpoints > 0)
6420 if (print_address_bits <= 32)
6421 ui_out_table_header (uiout, 10, ui_left,
6422 "addr", "Address"); /* 5 */
6424 ui_out_table_header (uiout, 18, ui_left,
6425 "addr", "Address"); /* 5 */
6427 if (nr_printable_breakpoints > 0)
6429 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6430 ui_out_table_body (uiout);
6431 if (nr_printable_breakpoints > 0)
6432 annotate_breakpoints_table ();
6437 /* If we have a filter, only list the breakpoints it accepts. */
6438 if (filter && !filter (b))
6441 /* If we have an "args" string, it is a list of breakpoints to
6442 accept. Skip the others. */
6444 if (args != NULL && *args != '\0')
6446 if (allflag) /* maintenance info breakpoint */
6448 if (parse_and_eval_long (args) != b->number)
6451 else /* all others */
6453 if (!number_is_in_list (args, b->number))
6457 /* We only print out user settable breakpoints unless the
6459 if (allflag || user_breakpoint_p (b))
6460 print_one_breakpoint (b, &last_loc, allflag);
6463 do_cleanups (bkpttbl_chain);
6465 if (nr_printable_breakpoints == 0)
6467 /* If there's a filter, let the caller decide how to report
6471 if (args == NULL || *args == '\0')
6472 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6474 ui_out_message (uiout, 0,
6475 "No breakpoint or watchpoint matching '%s'.\n",
6481 if (last_loc && !server_command)
6482 set_next_address (last_loc->gdbarch, last_loc->address);
6485 /* FIXME? Should this be moved up so that it is only called when
6486 there have been breakpoints? */
6487 annotate_breakpoints_table_end ();
6489 return nr_printable_breakpoints;
6492 /* Display the value of default-collect in a way that is generally
6493 compatible with the breakpoint list. */
6496 default_collect_info (void)
6498 struct ui_out *uiout = current_uiout;
6500 /* If it has no value (which is frequently the case), say nothing; a
6501 message like "No default-collect." gets in user's face when it's
6503 if (!*default_collect)
6506 /* The following phrase lines up nicely with per-tracepoint collect
6508 ui_out_text (uiout, "default collect ");
6509 ui_out_field_string (uiout, "default-collect", default_collect);
6510 ui_out_text (uiout, " \n");
6514 breakpoints_info (char *args, int from_tty)
6516 breakpoint_1 (args, 0, NULL);
6518 default_collect_info ();
6522 watchpoints_info (char *args, int from_tty)
6524 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6525 struct ui_out *uiout = current_uiout;
6527 if (num_printed == 0)
6529 if (args == NULL || *args == '\0')
6530 ui_out_message (uiout, 0, "No watchpoints.\n");
6532 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6537 maintenance_info_breakpoints (char *args, int from_tty)
6539 breakpoint_1 (args, 1, NULL);
6541 default_collect_info ();
6545 breakpoint_has_pc (struct breakpoint *b,
6546 struct program_space *pspace,
6547 CORE_ADDR pc, struct obj_section *section)
6549 struct bp_location *bl = b->loc;
6551 for (; bl; bl = bl->next)
6553 if (bl->pspace == pspace
6554 && bl->address == pc
6555 && (!overlay_debugging || bl->section == section))
6561 /* Print a message describing any user-breakpoints set at PC. This
6562 concerns with logical breakpoints, so we match program spaces, not
6566 describe_other_breakpoints (struct gdbarch *gdbarch,
6567 struct program_space *pspace, CORE_ADDR pc,
6568 struct obj_section *section, int thread)
6571 struct breakpoint *b;
6574 others += (user_breakpoint_p (b)
6575 && breakpoint_has_pc (b, pspace, pc, section));
6579 printf_filtered (_("Note: breakpoint "));
6580 else /* if (others == ???) */
6581 printf_filtered (_("Note: breakpoints "));
6583 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6586 printf_filtered ("%d", b->number);
6587 if (b->thread == -1 && thread != -1)
6588 printf_filtered (" (all threads)");
6589 else if (b->thread != -1)
6590 printf_filtered (" (thread %d)", b->thread);
6591 printf_filtered ("%s%s ",
6592 ((b->enable_state == bp_disabled
6593 || b->enable_state == bp_call_disabled)
6595 : b->enable_state == bp_permanent
6599 : ((others == 1) ? " and" : ""));
6601 printf_filtered (_("also set at pc "));
6602 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6603 printf_filtered (".\n");
6608 /* Return true iff it is meaningful to use the address member of
6609 BPT. For some breakpoint types, the address member is irrelevant
6610 and it makes no sense to attempt to compare it to other addresses
6611 (or use it for any other purpose either).
6613 More specifically, each of the following breakpoint types will
6614 always have a zero valued address and we don't want to mark
6615 breakpoints of any of these types to be a duplicate of an actual
6616 breakpoint at address zero:
6624 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6626 enum bptype type = bpt->type;
6628 return (type != bp_watchpoint && type != bp_catchpoint);
6631 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6632 true if LOC1 and LOC2 represent the same watchpoint location. */
6635 watchpoint_locations_match (struct bp_location *loc1,
6636 struct bp_location *loc2)
6638 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6639 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6641 /* Both of them must exist. */
6642 gdb_assert (w1 != NULL);
6643 gdb_assert (w2 != NULL);
6645 /* If the target can evaluate the condition expression in hardware,
6646 then we we need to insert both watchpoints even if they are at
6647 the same place. Otherwise the watchpoint will only trigger when
6648 the condition of whichever watchpoint was inserted evaluates to
6649 true, not giving a chance for GDB to check the condition of the
6650 other watchpoint. */
6652 && target_can_accel_watchpoint_condition (loc1->address,
6654 loc1->watchpoint_type,
6657 && target_can_accel_watchpoint_condition (loc2->address,
6659 loc2->watchpoint_type,
6663 /* Note that this checks the owner's type, not the location's. In
6664 case the target does not support read watchpoints, but does
6665 support access watchpoints, we'll have bp_read_watchpoint
6666 watchpoints with hw_access locations. Those should be considered
6667 duplicates of hw_read locations. The hw_read locations will
6668 become hw_access locations later. */
6669 return (loc1->owner->type == loc2->owner->type
6670 && loc1->pspace->aspace == loc2->pspace->aspace
6671 && loc1->address == loc2->address
6672 && loc1->length == loc2->length);
6675 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6676 same breakpoint location. In most targets, this can only be true
6677 if ASPACE1 matches ASPACE2. On targets that have global
6678 breakpoints, the address space doesn't really matter. */
6681 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6682 struct address_space *aspace2, CORE_ADDR addr2)
6684 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6685 || aspace1 == aspace2)
6689 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6690 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6691 matches ASPACE2. On targets that have global breakpoints, the address
6692 space doesn't really matter. */
6695 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6696 int len1, struct address_space *aspace2,
6699 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6700 || aspace1 == aspace2)
6701 && addr2 >= addr1 && addr2 < addr1 + len1);
6704 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6705 a ranged breakpoint. In most targets, a match happens only if ASPACE
6706 matches the breakpoint's address space. On targets that have global
6707 breakpoints, the address space doesn't really matter. */
6710 breakpoint_location_address_match (struct bp_location *bl,
6711 struct address_space *aspace,
6714 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6717 && breakpoint_address_match_range (bl->pspace->aspace,
6718 bl->address, bl->length,
6722 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6723 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6724 true, otherwise returns false. */
6727 tracepoint_locations_match (struct bp_location *loc1,
6728 struct bp_location *loc2)
6730 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6731 /* Since tracepoint locations are never duplicated with others', tracepoint
6732 locations at the same address of different tracepoints are regarded as
6733 different locations. */
6734 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6739 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6740 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6741 represent the same location. */
6744 breakpoint_locations_match (struct bp_location *loc1,
6745 struct bp_location *loc2)
6747 int hw_point1, hw_point2;
6749 /* Both of them must not be in moribund_locations. */
6750 gdb_assert (loc1->owner != NULL);
6751 gdb_assert (loc2->owner != NULL);
6753 hw_point1 = is_hardware_watchpoint (loc1->owner);
6754 hw_point2 = is_hardware_watchpoint (loc2->owner);
6756 if (hw_point1 != hw_point2)
6759 return watchpoint_locations_match (loc1, loc2);
6760 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6761 return tracepoint_locations_match (loc1, loc2);
6763 /* We compare bp_location.length in order to cover ranged breakpoints. */
6764 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6765 loc2->pspace->aspace, loc2->address)
6766 && loc1->length == loc2->length);
6770 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6771 int bnum, int have_bnum)
6773 /* The longest string possibly returned by hex_string_custom
6774 is 50 chars. These must be at least that big for safety. */
6778 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6779 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6781 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6782 bnum, astr1, astr2);
6784 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6787 /* Adjust a breakpoint's address to account for architectural
6788 constraints on breakpoint placement. Return the adjusted address.
6789 Note: Very few targets require this kind of adjustment. For most
6790 targets, this function is simply the identity function. */
6793 adjust_breakpoint_address (struct gdbarch *gdbarch,
6794 CORE_ADDR bpaddr, enum bptype bptype)
6796 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6798 /* Very few targets need any kind of breakpoint adjustment. */
6801 else if (bptype == bp_watchpoint
6802 || bptype == bp_hardware_watchpoint
6803 || bptype == bp_read_watchpoint
6804 || bptype == bp_access_watchpoint
6805 || bptype == bp_catchpoint)
6807 /* Watchpoints and the various bp_catch_* eventpoints should not
6808 have their addresses modified. */
6813 CORE_ADDR adjusted_bpaddr;
6815 /* Some targets have architectural constraints on the placement
6816 of breakpoint instructions. Obtain the adjusted address. */
6817 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6819 /* An adjusted breakpoint address can significantly alter
6820 a user's expectations. Print a warning if an adjustment
6822 if (adjusted_bpaddr != bpaddr)
6823 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6825 return adjusted_bpaddr;
6830 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6831 struct breakpoint *owner)
6833 memset (loc, 0, sizeof (*loc));
6835 gdb_assert (ops != NULL);
6840 loc->cond_bytecode = NULL;
6841 loc->shlib_disabled = 0;
6844 switch (owner->type)
6850 case bp_longjmp_resume:
6851 case bp_longjmp_call_dummy:
6853 case bp_exception_resume:
6854 case bp_step_resume:
6855 case bp_hp_step_resume:
6856 case bp_watchpoint_scope:
6858 case bp_std_terminate:
6859 case bp_shlib_event:
6860 case bp_thread_event:
6861 case bp_overlay_event:
6863 case bp_longjmp_master:
6864 case bp_std_terminate_master:
6865 case bp_exception_master:
6866 case bp_gnu_ifunc_resolver:
6867 case bp_gnu_ifunc_resolver_return:
6869 loc->loc_type = bp_loc_software_breakpoint;
6870 mark_breakpoint_location_modified (loc);
6872 case bp_hardware_breakpoint:
6873 loc->loc_type = bp_loc_hardware_breakpoint;
6874 mark_breakpoint_location_modified (loc);
6876 case bp_hardware_watchpoint:
6877 case bp_read_watchpoint:
6878 case bp_access_watchpoint:
6879 loc->loc_type = bp_loc_hardware_watchpoint;
6884 case bp_fast_tracepoint:
6885 case bp_static_tracepoint:
6886 loc->loc_type = bp_loc_other;
6889 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6895 /* Allocate a struct bp_location. */
6897 static struct bp_location *
6898 allocate_bp_location (struct breakpoint *bpt)
6900 return bpt->ops->allocate_location (bpt);
6904 free_bp_location (struct bp_location *loc)
6906 loc->ops->dtor (loc);
6910 /* Increment reference count. */
6913 incref_bp_location (struct bp_location *bl)
6918 /* Decrement reference count. If the reference count reaches 0,
6919 destroy the bp_location. Sets *BLP to NULL. */
6922 decref_bp_location (struct bp_location **blp)
6924 gdb_assert ((*blp)->refc > 0);
6926 if (--(*blp)->refc == 0)
6927 free_bp_location (*blp);
6931 /* Add breakpoint B at the end of the global breakpoint chain. */
6934 add_to_breakpoint_chain (struct breakpoint *b)
6936 struct breakpoint *b1;
6938 /* Add this breakpoint to the end of the chain so that a list of
6939 breakpoints will come out in order of increasing numbers. */
6941 b1 = breakpoint_chain;
6943 breakpoint_chain = b;
6952 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6955 init_raw_breakpoint_without_location (struct breakpoint *b,
6956 struct gdbarch *gdbarch,
6958 const struct breakpoint_ops *ops)
6960 memset (b, 0, sizeof (*b));
6962 gdb_assert (ops != NULL);
6966 b->gdbarch = gdbarch;
6967 b->language = current_language->la_language;
6968 b->input_radix = input_radix;
6970 b->enable_state = bp_enabled;
6973 b->ignore_count = 0;
6975 b->frame_id = null_frame_id;
6976 b->condition_not_parsed = 0;
6977 b->py_bp_object = NULL;
6978 b->related_breakpoint = b;
6981 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6982 that has type BPTYPE and has no locations as yet. */
6984 static struct breakpoint *
6985 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6987 const struct breakpoint_ops *ops)
6989 struct breakpoint *b = XNEW (struct breakpoint);
6991 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6992 add_to_breakpoint_chain (b);
6996 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6997 resolutions should be made as the user specified the location explicitly
7001 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7003 gdb_assert (loc->owner != NULL);
7005 if (loc->owner->type == bp_breakpoint
7006 || loc->owner->type == bp_hardware_breakpoint
7007 || is_tracepoint (loc->owner))
7010 const char *function_name;
7011 CORE_ADDR func_addr;
7013 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7014 &func_addr, NULL, &is_gnu_ifunc);
7016 if (is_gnu_ifunc && !explicit_loc)
7018 struct breakpoint *b = loc->owner;
7020 gdb_assert (loc->pspace == current_program_space);
7021 if (gnu_ifunc_resolve_name (function_name,
7022 &loc->requested_address))
7024 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7025 loc->address = adjust_breakpoint_address (loc->gdbarch,
7026 loc->requested_address,
7029 else if (b->type == bp_breakpoint && b->loc == loc
7030 && loc->next == NULL && b->related_breakpoint == b)
7032 /* Create only the whole new breakpoint of this type but do not
7033 mess more complicated breakpoints with multiple locations. */
7034 b->type = bp_gnu_ifunc_resolver;
7035 /* Remember the resolver's address for use by the return
7037 loc->related_address = func_addr;
7042 loc->function_name = xstrdup (function_name);
7046 /* Attempt to determine architecture of location identified by SAL. */
7048 get_sal_arch (struct symtab_and_line sal)
7051 return get_objfile_arch (sal.section->objfile);
7053 return get_objfile_arch (sal.symtab->objfile);
7058 /* Low level routine for partially initializing a breakpoint of type
7059 BPTYPE. The newly created breakpoint's address, section, source
7060 file name, and line number are provided by SAL.
7062 It is expected that the caller will complete the initialization of
7063 the newly created breakpoint struct as well as output any status
7064 information regarding the creation of a new breakpoint. */
7067 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7068 struct symtab_and_line sal, enum bptype bptype,
7069 const struct breakpoint_ops *ops)
7071 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7073 add_location_to_breakpoint (b, &sal);
7075 if (bptype != bp_catchpoint)
7076 gdb_assert (sal.pspace != NULL);
7078 /* Store the program space that was used to set the breakpoint,
7079 except for ordinary breakpoints, which are independent of the
7081 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7082 b->pspace = sal.pspace;
7085 /* set_raw_breakpoint is a low level routine for allocating and
7086 partially initializing a breakpoint of type BPTYPE. The newly
7087 created breakpoint's address, section, source file name, and line
7088 number are provided by SAL. The newly created and partially
7089 initialized breakpoint is added to the breakpoint chain and
7090 is also returned as the value of this function.
7092 It is expected that the caller will complete the initialization of
7093 the newly created breakpoint struct as well as output any status
7094 information regarding the creation of a new breakpoint. In
7095 particular, set_raw_breakpoint does NOT set the breakpoint
7096 number! Care should be taken to not allow an error to occur
7097 prior to completing the initialization of the breakpoint. If this
7098 should happen, a bogus breakpoint will be left on the chain. */
7101 set_raw_breakpoint (struct gdbarch *gdbarch,
7102 struct symtab_and_line sal, enum bptype bptype,
7103 const struct breakpoint_ops *ops)
7105 struct breakpoint *b = XNEW (struct breakpoint);
7107 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7108 add_to_breakpoint_chain (b);
7113 /* Note that the breakpoint object B describes a permanent breakpoint
7114 instruction, hard-wired into the inferior's code. */
7116 make_breakpoint_permanent (struct breakpoint *b)
7118 struct bp_location *bl;
7120 b->enable_state = bp_permanent;
7122 /* By definition, permanent breakpoints are already present in the
7123 code. Mark all locations as inserted. For now,
7124 make_breakpoint_permanent is called in just one place, so it's
7125 hard to say if it's reasonable to have permanent breakpoint with
7126 multiple locations or not, but it's easy to implement. */
7127 for (bl = b->loc; bl; bl = bl->next)
7131 /* Call this routine when stepping and nexting to enable a breakpoint
7132 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7133 initiated the operation. */
7136 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7138 struct breakpoint *b, *b_tmp;
7139 int thread = tp->num;
7141 /* To avoid having to rescan all objfile symbols at every step,
7142 we maintain a list of continually-inserted but always disabled
7143 longjmp "master" breakpoints. Here, we simply create momentary
7144 clones of those and enable them for the requested thread. */
7145 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7146 if (b->pspace == current_program_space
7147 && (b->type == bp_longjmp_master
7148 || b->type == bp_exception_master))
7150 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7151 struct breakpoint *clone;
7153 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7154 after their removal. */
7155 clone = momentary_breakpoint_from_master (b, type,
7156 &longjmp_breakpoint_ops);
7157 clone->thread = thread;
7160 tp->initiating_frame = frame;
7163 /* Delete all longjmp breakpoints from THREAD. */
7165 delete_longjmp_breakpoint (int thread)
7167 struct breakpoint *b, *b_tmp;
7169 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7170 if (b->type == bp_longjmp || b->type == bp_exception)
7172 if (b->thread == thread)
7173 delete_breakpoint (b);
7178 delete_longjmp_breakpoint_at_next_stop (int thread)
7180 struct breakpoint *b, *b_tmp;
7182 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7183 if (b->type == bp_longjmp || b->type == bp_exception)
7185 if (b->thread == thread)
7186 b->disposition = disp_del_at_next_stop;
7190 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7191 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7192 pointer to any of them. Return NULL if this system cannot place longjmp
7196 set_longjmp_breakpoint_for_call_dummy (void)
7198 struct breakpoint *b, *retval = NULL;
7201 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7203 struct breakpoint *new_b;
7205 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7206 &momentary_breakpoint_ops);
7207 new_b->thread = pid_to_thread_id (inferior_ptid);
7209 /* Link NEW_B into the chain of RETVAL breakpoints. */
7211 gdb_assert (new_b->related_breakpoint == new_b);
7214 new_b->related_breakpoint = retval;
7215 while (retval->related_breakpoint != new_b->related_breakpoint)
7216 retval = retval->related_breakpoint;
7217 retval->related_breakpoint = new_b;
7223 /* Verify all existing dummy frames and their associated breakpoints for
7224 THREAD. Remove those which can no longer be found in the current frame
7227 You should call this function only at places where it is safe to currently
7228 unwind the whole stack. Failed stack unwind would discard live dummy
7232 check_longjmp_breakpoint_for_call_dummy (int thread)
7234 struct breakpoint *b, *b_tmp;
7236 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7237 if (b->type == bp_longjmp_call_dummy && b->thread == thread)
7239 struct breakpoint *dummy_b = b->related_breakpoint;
7241 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7242 dummy_b = dummy_b->related_breakpoint;
7243 if (dummy_b->type != bp_call_dummy
7244 || frame_find_by_id (dummy_b->frame_id) != NULL)
7247 dummy_frame_discard (dummy_b->frame_id);
7249 while (b->related_breakpoint != b)
7251 if (b_tmp == b->related_breakpoint)
7252 b_tmp = b->related_breakpoint->next;
7253 delete_breakpoint (b->related_breakpoint);
7255 delete_breakpoint (b);
7260 enable_overlay_breakpoints (void)
7262 struct breakpoint *b;
7265 if (b->type == bp_overlay_event)
7267 b->enable_state = bp_enabled;
7268 update_global_location_list (1);
7269 overlay_events_enabled = 1;
7274 disable_overlay_breakpoints (void)
7276 struct breakpoint *b;
7279 if (b->type == bp_overlay_event)
7281 b->enable_state = bp_disabled;
7282 update_global_location_list (0);
7283 overlay_events_enabled = 0;
7287 /* Set an active std::terminate breakpoint for each std::terminate
7288 master breakpoint. */
7290 set_std_terminate_breakpoint (void)
7292 struct breakpoint *b, *b_tmp;
7294 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7295 if (b->pspace == current_program_space
7296 && b->type == bp_std_terminate_master)
7298 momentary_breakpoint_from_master (b, bp_std_terminate,
7299 &momentary_breakpoint_ops);
7303 /* Delete all the std::terminate breakpoints. */
7305 delete_std_terminate_breakpoint (void)
7307 struct breakpoint *b, *b_tmp;
7309 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7310 if (b->type == bp_std_terminate)
7311 delete_breakpoint (b);
7315 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7317 struct breakpoint *b;
7319 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7320 &internal_breakpoint_ops);
7322 b->enable_state = bp_enabled;
7323 /* addr_string has to be used or breakpoint_re_set will delete me. */
7325 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7327 update_global_location_list_nothrow (1);
7333 remove_thread_event_breakpoints (void)
7335 struct breakpoint *b, *b_tmp;
7337 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7338 if (b->type == bp_thread_event
7339 && b->loc->pspace == current_program_space)
7340 delete_breakpoint (b);
7343 struct lang_and_radix
7349 /* Create a breakpoint for JIT code registration and unregistration. */
7352 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7354 struct breakpoint *b;
7356 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7357 &internal_breakpoint_ops);
7358 update_global_location_list_nothrow (1);
7362 /* Remove JIT code registration and unregistration breakpoint(s). */
7365 remove_jit_event_breakpoints (void)
7367 struct breakpoint *b, *b_tmp;
7369 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7370 if (b->type == bp_jit_event
7371 && b->loc->pspace == current_program_space)
7372 delete_breakpoint (b);
7376 remove_solib_event_breakpoints (void)
7378 struct breakpoint *b, *b_tmp;
7380 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7381 if (b->type == bp_shlib_event
7382 && b->loc->pspace == current_program_space)
7383 delete_breakpoint (b);
7387 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7389 struct breakpoint *b;
7391 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7392 &internal_breakpoint_ops);
7393 update_global_location_list_nothrow (1);
7397 /* Disable any breakpoints that are on code in shared libraries. Only
7398 apply to enabled breakpoints, disabled ones can just stay disabled. */
7401 disable_breakpoints_in_shlibs (void)
7403 struct bp_location *loc, **locp_tmp;
7405 ALL_BP_LOCATIONS (loc, locp_tmp)
7407 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7408 struct breakpoint *b = loc->owner;
7410 /* We apply the check to all breakpoints, including disabled for
7411 those with loc->duplicate set. This is so that when breakpoint
7412 becomes enabled, or the duplicate is removed, gdb will try to
7413 insert all breakpoints. If we don't set shlib_disabled here,
7414 we'll try to insert those breakpoints and fail. */
7415 if (((b->type == bp_breakpoint)
7416 || (b->type == bp_jit_event)
7417 || (b->type == bp_hardware_breakpoint)
7418 || (is_tracepoint (b)))
7419 && loc->pspace == current_program_space
7420 && !loc->shlib_disabled
7422 && PC_SOLIB (loc->address)
7424 && solib_name_from_address (loc->pspace, loc->address)
7428 loc->shlib_disabled = 1;
7433 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7434 library. Only apply to enabled breakpoints, disabled ones can just stay
7438 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7440 struct bp_location *loc, **locp_tmp;
7441 int disabled_shlib_breaks = 0;
7443 /* SunOS a.out shared libraries are always mapped, so do not
7444 disable breakpoints; they will only be reported as unloaded
7445 through clear_solib when GDB discards its shared library
7446 list. See clear_solib for more information. */
7447 if (exec_bfd != NULL
7448 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7451 ALL_BP_LOCATIONS (loc, locp_tmp)
7453 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7454 struct breakpoint *b = loc->owner;
7456 if (solib->pspace == loc->pspace
7457 && !loc->shlib_disabled
7458 && (((b->type == bp_breakpoint
7459 || b->type == bp_jit_event
7460 || b->type == bp_hardware_breakpoint)
7461 && (loc->loc_type == bp_loc_hardware_breakpoint
7462 || loc->loc_type == bp_loc_software_breakpoint))
7463 || is_tracepoint (b))
7464 && solib_contains_address_p (solib, loc->address))
7466 loc->shlib_disabled = 1;
7467 /* At this point, we cannot rely on remove_breakpoint
7468 succeeding so we must mark the breakpoint as not inserted
7469 to prevent future errors occurring in remove_breakpoints. */
7472 /* This may cause duplicate notifications for the same breakpoint. */
7473 observer_notify_breakpoint_modified (b);
7475 if (!disabled_shlib_breaks)
7477 target_terminal_ours_for_output ();
7478 warning (_("Temporarily disabling breakpoints "
7479 "for unloaded shared library \"%s\""),
7482 disabled_shlib_breaks = 1;
7487 /* FORK & VFORK catchpoints. */
7489 /* An instance of this type is used to represent a fork or vfork
7490 catchpoint. It includes a "struct breakpoint" as a kind of base
7491 class; users downcast to "struct breakpoint *" when needed. A
7492 breakpoint is really of this type iff its ops pointer points to
7493 CATCH_FORK_BREAKPOINT_OPS. */
7495 struct fork_catchpoint
7497 /* The base class. */
7498 struct breakpoint base;
7500 /* Process id of a child process whose forking triggered this
7501 catchpoint. This field is only valid immediately after this
7502 catchpoint has triggered. */
7503 ptid_t forked_inferior_pid;
7506 /* Implement the "insert" breakpoint_ops method for fork
7510 insert_catch_fork (struct bp_location *bl)
7512 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7515 /* Implement the "remove" breakpoint_ops method for fork
7519 remove_catch_fork (struct bp_location *bl)
7521 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7524 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7528 breakpoint_hit_catch_fork (const struct bp_location *bl,
7529 struct address_space *aspace, CORE_ADDR bp_addr,
7530 const struct target_waitstatus *ws)
7532 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7534 if (ws->kind != TARGET_WAITKIND_FORKED)
7537 c->forked_inferior_pid = ws->value.related_pid;
7541 /* Implement the "print_it" breakpoint_ops method for fork
7544 static enum print_stop_action
7545 print_it_catch_fork (bpstat bs)
7547 struct ui_out *uiout = current_uiout;
7548 struct breakpoint *b = bs->breakpoint_at;
7549 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7551 annotate_catchpoint (b->number);
7552 if (b->disposition == disp_del)
7553 ui_out_text (uiout, "\nTemporary catchpoint ");
7555 ui_out_text (uiout, "\nCatchpoint ");
7556 if (ui_out_is_mi_like_p (uiout))
7558 ui_out_field_string (uiout, "reason",
7559 async_reason_lookup (EXEC_ASYNC_FORK));
7560 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7562 ui_out_field_int (uiout, "bkptno", b->number);
7563 ui_out_text (uiout, " (forked process ");
7564 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7565 ui_out_text (uiout, "), ");
7566 return PRINT_SRC_AND_LOC;
7569 /* Implement the "print_one" breakpoint_ops method for fork
7573 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7575 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7576 struct value_print_options opts;
7577 struct ui_out *uiout = current_uiout;
7579 get_user_print_options (&opts);
7581 /* Field 4, the address, is omitted (which makes the columns not
7582 line up too nicely with the headers, but the effect is relatively
7584 if (opts.addressprint)
7585 ui_out_field_skip (uiout, "addr");
7587 ui_out_text (uiout, "fork");
7588 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7590 ui_out_text (uiout, ", process ");
7591 ui_out_field_int (uiout, "what",
7592 ptid_get_pid (c->forked_inferior_pid));
7593 ui_out_spaces (uiout, 1);
7596 if (ui_out_is_mi_like_p (uiout))
7597 ui_out_field_string (uiout, "catch-type", "fork");
7600 /* Implement the "print_mention" breakpoint_ops method for fork
7604 print_mention_catch_fork (struct breakpoint *b)
7606 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7609 /* Implement the "print_recreate" breakpoint_ops method for fork
7613 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7615 fprintf_unfiltered (fp, "catch fork");
7616 print_recreate_thread (b, fp);
7619 /* The breakpoint_ops structure to be used in fork catchpoints. */
7621 static struct breakpoint_ops catch_fork_breakpoint_ops;
7623 /* Implement the "insert" breakpoint_ops method for vfork
7627 insert_catch_vfork (struct bp_location *bl)
7629 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7632 /* Implement the "remove" breakpoint_ops method for vfork
7636 remove_catch_vfork (struct bp_location *bl)
7638 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7641 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7645 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7646 struct address_space *aspace, CORE_ADDR bp_addr,
7647 const struct target_waitstatus *ws)
7649 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7651 if (ws->kind != TARGET_WAITKIND_VFORKED)
7654 c->forked_inferior_pid = ws->value.related_pid;
7658 /* Implement the "print_it" breakpoint_ops method for vfork
7661 static enum print_stop_action
7662 print_it_catch_vfork (bpstat bs)
7664 struct ui_out *uiout = current_uiout;
7665 struct breakpoint *b = bs->breakpoint_at;
7666 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7668 annotate_catchpoint (b->number);
7669 if (b->disposition == disp_del)
7670 ui_out_text (uiout, "\nTemporary catchpoint ");
7672 ui_out_text (uiout, "\nCatchpoint ");
7673 if (ui_out_is_mi_like_p (uiout))
7675 ui_out_field_string (uiout, "reason",
7676 async_reason_lookup (EXEC_ASYNC_VFORK));
7677 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7679 ui_out_field_int (uiout, "bkptno", b->number);
7680 ui_out_text (uiout, " (vforked process ");
7681 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7682 ui_out_text (uiout, "), ");
7683 return PRINT_SRC_AND_LOC;
7686 /* Implement the "print_one" breakpoint_ops method for vfork
7690 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7692 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7693 struct value_print_options opts;
7694 struct ui_out *uiout = current_uiout;
7696 get_user_print_options (&opts);
7697 /* Field 4, the address, is omitted (which makes the columns not
7698 line up too nicely with the headers, but the effect is relatively
7700 if (opts.addressprint)
7701 ui_out_field_skip (uiout, "addr");
7703 ui_out_text (uiout, "vfork");
7704 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7706 ui_out_text (uiout, ", process ");
7707 ui_out_field_int (uiout, "what",
7708 ptid_get_pid (c->forked_inferior_pid));
7709 ui_out_spaces (uiout, 1);
7712 if (ui_out_is_mi_like_p (uiout))
7713 ui_out_field_string (uiout, "catch-type", "vfork");
7716 /* Implement the "print_mention" breakpoint_ops method for vfork
7720 print_mention_catch_vfork (struct breakpoint *b)
7722 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7725 /* Implement the "print_recreate" breakpoint_ops method for vfork
7729 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7731 fprintf_unfiltered (fp, "catch vfork");
7732 print_recreate_thread (b, fp);
7735 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7737 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7739 /* An instance of this type is used to represent an solib catchpoint.
7740 It includes a "struct breakpoint" as a kind of base class; users
7741 downcast to "struct breakpoint *" when needed. A breakpoint is
7742 really of this type iff its ops pointer points to
7743 CATCH_SOLIB_BREAKPOINT_OPS. */
7745 struct solib_catchpoint
7747 /* The base class. */
7748 struct breakpoint base;
7750 /* True for "catch load", false for "catch unload". */
7751 unsigned char is_load;
7753 /* Regular expression to match, if any. COMPILED is only valid when
7754 REGEX is non-NULL. */
7760 dtor_catch_solib (struct breakpoint *b)
7762 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7765 regfree (&self->compiled);
7766 xfree (self->regex);
7768 base_breakpoint_ops.dtor (b);
7772 insert_catch_solib (struct bp_location *ignore)
7778 remove_catch_solib (struct bp_location *ignore)
7784 breakpoint_hit_catch_solib (const struct bp_location *bl,
7785 struct address_space *aspace,
7787 const struct target_waitstatus *ws)
7789 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7790 struct breakpoint *other;
7792 if (ws->kind == TARGET_WAITKIND_LOADED)
7795 ALL_BREAKPOINTS (other)
7797 struct bp_location *other_bl;
7799 if (other == bl->owner)
7802 if (other->type != bp_shlib_event)
7805 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7808 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7810 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7819 check_status_catch_solib (struct bpstats *bs)
7821 struct solib_catchpoint *self
7822 = (struct solib_catchpoint *) bs->breakpoint_at;
7827 struct so_list *iter;
7830 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7835 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7844 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7849 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7855 bs->print_it = print_it_noop;
7858 static enum print_stop_action
7859 print_it_catch_solib (bpstat bs)
7861 struct breakpoint *b = bs->breakpoint_at;
7862 struct ui_out *uiout = current_uiout;
7864 annotate_catchpoint (b->number);
7865 if (b->disposition == disp_del)
7866 ui_out_text (uiout, "\nTemporary catchpoint ");
7868 ui_out_text (uiout, "\nCatchpoint ");
7869 ui_out_field_int (uiout, "bkptno", b->number);
7870 ui_out_text (uiout, "\n");
7871 if (ui_out_is_mi_like_p (uiout))
7872 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7873 print_solib_event (1);
7874 return PRINT_SRC_AND_LOC;
7878 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7880 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7881 struct value_print_options opts;
7882 struct ui_out *uiout = current_uiout;
7885 get_user_print_options (&opts);
7886 /* Field 4, the address, is omitted (which makes the columns not
7887 line up too nicely with the headers, but the effect is relatively
7889 if (opts.addressprint)
7892 ui_out_field_skip (uiout, "addr");
7899 msg = xstrprintf (_("load of library matching %s"), self->regex);
7901 msg = xstrdup (_("load of library"));
7906 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7908 msg = xstrdup (_("unload of library"));
7910 ui_out_field_string (uiout, "what", msg);
7913 if (ui_out_is_mi_like_p (uiout))
7914 ui_out_field_string (uiout, "catch-type",
7915 self->is_load ? "load" : "unload");
7919 print_mention_catch_solib (struct breakpoint *b)
7921 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7923 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7924 self->is_load ? "load" : "unload");
7928 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7930 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7932 fprintf_unfiltered (fp, "%s %s",
7933 b->disposition == disp_del ? "tcatch" : "catch",
7934 self->is_load ? "load" : "unload");
7936 fprintf_unfiltered (fp, " %s", self->regex);
7937 fprintf_unfiltered (fp, "\n");
7940 static struct breakpoint_ops catch_solib_breakpoint_ops;
7942 /* Shared helper function (MI and CLI) for creating and installing
7943 a shared object event catchpoint. If IS_LOAD is non-zero then
7944 the events to be caught are load events, otherwise they are
7945 unload events. If IS_TEMP is non-zero the catchpoint is a
7946 temporary one. If ENABLED is non-zero the catchpoint is
7947 created in an enabled state. */
7950 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
7952 struct solib_catchpoint *c;
7953 struct gdbarch *gdbarch = get_current_arch ();
7954 struct cleanup *cleanup;
7958 arg = skip_spaces (arg);
7960 c = XCNEW (struct solib_catchpoint);
7961 cleanup = make_cleanup (xfree, c);
7967 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7970 char *err = get_regcomp_error (errcode, &c->compiled);
7972 make_cleanup (xfree, err);
7973 error (_("Invalid regexp (%s): %s"), err, arg);
7975 c->regex = xstrdup (arg);
7978 c->is_load = is_load;
7979 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
7980 &catch_solib_breakpoint_ops);
7982 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
7984 discard_cleanups (cleanup);
7985 install_breakpoint (0, &c->base, 1);
7988 /* A helper function that does all the work for "catch load" and
7992 catch_load_or_unload (char *arg, int from_tty, int is_load,
7993 struct cmd_list_element *command)
7996 const int enabled = 1;
7998 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8000 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8004 catch_load_command_1 (char *arg, int from_tty,
8005 struct cmd_list_element *command)
8007 catch_load_or_unload (arg, from_tty, 1, command);
8011 catch_unload_command_1 (char *arg, int from_tty,
8012 struct cmd_list_element *command)
8014 catch_load_or_unload (arg, from_tty, 0, command);
8017 /* An instance of this type is used to represent a syscall catchpoint.
8018 It includes a "struct breakpoint" as a kind of base class; users
8019 downcast to "struct breakpoint *" when needed. A breakpoint is
8020 really of this type iff its ops pointer points to
8021 CATCH_SYSCALL_BREAKPOINT_OPS. */
8023 struct syscall_catchpoint
8025 /* The base class. */
8026 struct breakpoint base;
8028 /* Syscall numbers used for the 'catch syscall' feature. If no
8029 syscall has been specified for filtering, its value is NULL.
8030 Otherwise, it holds a list of all syscalls to be caught. The
8031 list elements are allocated with xmalloc. */
8032 VEC(int) *syscalls_to_be_caught;
8035 /* Implement the "dtor" breakpoint_ops method for syscall
8039 dtor_catch_syscall (struct breakpoint *b)
8041 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8043 VEC_free (int, c->syscalls_to_be_caught);
8045 base_breakpoint_ops.dtor (b);
8048 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8050 struct catch_syscall_inferior_data
8052 /* We keep a count of the number of times the user has requested a
8053 particular syscall to be tracked, and pass this information to the
8054 target. This lets capable targets implement filtering directly. */
8056 /* Number of times that "any" syscall is requested. */
8057 int any_syscall_count;
8059 /* Count of each system call. */
8060 VEC(int) *syscalls_counts;
8062 /* This counts all syscall catch requests, so we can readily determine
8063 if any catching is necessary. */
8064 int total_syscalls_count;
8067 static struct catch_syscall_inferior_data*
8068 get_catch_syscall_inferior_data (struct inferior *inf)
8070 struct catch_syscall_inferior_data *inf_data;
8072 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8073 if (inf_data == NULL)
8075 inf_data = XZALLOC (struct catch_syscall_inferior_data);
8076 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8083 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8089 /* Implement the "insert" breakpoint_ops method for syscall
8093 insert_catch_syscall (struct bp_location *bl)
8095 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8096 struct inferior *inf = current_inferior ();
8097 struct catch_syscall_inferior_data *inf_data
8098 = get_catch_syscall_inferior_data (inf);
8100 ++inf_data->total_syscalls_count;
8101 if (!c->syscalls_to_be_caught)
8102 ++inf_data->any_syscall_count;
8108 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8113 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8115 int old_size = VEC_length (int, inf_data->syscalls_counts);
8116 uintptr_t vec_addr_offset
8117 = old_size * ((uintptr_t) sizeof (int));
8119 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8120 vec_addr = ((uintptr_t) VEC_address (int,
8121 inf_data->syscalls_counts)
8123 memset ((void *) vec_addr, 0,
8124 (iter + 1 - old_size) * sizeof (int));
8126 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8127 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8131 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8132 inf_data->total_syscalls_count != 0,
8133 inf_data->any_syscall_count,
8135 inf_data->syscalls_counts),
8137 inf_data->syscalls_counts));
8140 /* Implement the "remove" breakpoint_ops method for syscall
8144 remove_catch_syscall (struct bp_location *bl)
8146 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8147 struct inferior *inf = current_inferior ();
8148 struct catch_syscall_inferior_data *inf_data
8149 = get_catch_syscall_inferior_data (inf);
8151 --inf_data->total_syscalls_count;
8152 if (!c->syscalls_to_be_caught)
8153 --inf_data->any_syscall_count;
8159 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8163 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8164 /* Shouldn't happen. */
8166 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8167 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8171 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8172 inf_data->total_syscalls_count != 0,
8173 inf_data->any_syscall_count,
8175 inf_data->syscalls_counts),
8177 inf_data->syscalls_counts));
8180 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8184 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8185 struct address_space *aspace, CORE_ADDR bp_addr,
8186 const struct target_waitstatus *ws)
8188 /* We must check if we are catching specific syscalls in this
8189 breakpoint. If we are, then we must guarantee that the called
8190 syscall is the same syscall we are catching. */
8191 int syscall_number = 0;
8192 const struct syscall_catchpoint *c
8193 = (const struct syscall_catchpoint *) bl->owner;
8195 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8196 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8199 syscall_number = ws->value.syscall_number;
8201 /* Now, checking if the syscall is the same. */
8202 if (c->syscalls_to_be_caught)
8207 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8209 if (syscall_number == iter)
8219 /* Implement the "print_it" breakpoint_ops method for syscall
8222 static enum print_stop_action
8223 print_it_catch_syscall (bpstat bs)
8225 struct ui_out *uiout = current_uiout;
8226 struct breakpoint *b = bs->breakpoint_at;
8227 /* These are needed because we want to know in which state a
8228 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8229 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8230 must print "called syscall" or "returned from syscall". */
8232 struct target_waitstatus last;
8235 get_last_target_status (&ptid, &last);
8237 get_syscall_by_number (last.value.syscall_number, &s);
8239 annotate_catchpoint (b->number);
8241 if (b->disposition == disp_del)
8242 ui_out_text (uiout, "\nTemporary catchpoint ");
8244 ui_out_text (uiout, "\nCatchpoint ");
8245 if (ui_out_is_mi_like_p (uiout))
8247 ui_out_field_string (uiout, "reason",
8248 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8249 ? EXEC_ASYNC_SYSCALL_ENTRY
8250 : EXEC_ASYNC_SYSCALL_RETURN));
8251 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8253 ui_out_field_int (uiout, "bkptno", b->number);
8255 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8256 ui_out_text (uiout, " (call to syscall ");
8258 ui_out_text (uiout, " (returned from syscall ");
8260 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8261 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8263 ui_out_field_string (uiout, "syscall-name", s.name);
8265 ui_out_text (uiout, "), ");
8267 return PRINT_SRC_AND_LOC;
8270 /* Implement the "print_one" breakpoint_ops method for syscall
8274 print_one_catch_syscall (struct breakpoint *b,
8275 struct bp_location **last_loc)
8277 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8278 struct value_print_options opts;
8279 struct ui_out *uiout = current_uiout;
8281 get_user_print_options (&opts);
8282 /* Field 4, the address, is omitted (which makes the columns not
8283 line up too nicely with the headers, but the effect is relatively
8285 if (opts.addressprint)
8286 ui_out_field_skip (uiout, "addr");
8289 if (c->syscalls_to_be_caught
8290 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8291 ui_out_text (uiout, "syscalls \"");
8293 ui_out_text (uiout, "syscall \"");
8295 if (c->syscalls_to_be_caught)
8298 char *text = xstrprintf ("%s", "");
8301 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8306 get_syscall_by_number (iter, &s);
8309 text = xstrprintf ("%s%s, ", text, s.name);
8311 text = xstrprintf ("%s%d, ", text, iter);
8313 /* We have to xfree the last 'text' (now stored at 'x')
8314 because xstrprintf dynamically allocates new space for it
8318 /* Remove the last comma. */
8319 text[strlen (text) - 2] = '\0';
8320 ui_out_field_string (uiout, "what", text);
8323 ui_out_field_string (uiout, "what", "<any syscall>");
8324 ui_out_text (uiout, "\" ");
8326 if (ui_out_is_mi_like_p (uiout))
8327 ui_out_field_string (uiout, "catch-type", "syscall");
8330 /* Implement the "print_mention" breakpoint_ops method for syscall
8334 print_mention_catch_syscall (struct breakpoint *b)
8336 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8338 if (c->syscalls_to_be_caught)
8342 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8343 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8345 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8348 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8352 get_syscall_by_number (iter, &s);
8355 printf_filtered (" '%s' [%d]", s.name, s.number);
8357 printf_filtered (" %d", s.number);
8359 printf_filtered (")");
8362 printf_filtered (_("Catchpoint %d (any syscall)"),
8366 /* Implement the "print_recreate" breakpoint_ops method for syscall
8370 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8372 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8374 fprintf_unfiltered (fp, "catch syscall");
8376 if (c->syscalls_to_be_caught)
8381 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8386 get_syscall_by_number (iter, &s);
8388 fprintf_unfiltered (fp, " %s", s.name);
8390 fprintf_unfiltered (fp, " %d", s.number);
8393 print_recreate_thread (b, fp);
8396 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8398 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8400 /* Returns non-zero if 'b' is a syscall catchpoint. */
8403 syscall_catchpoint_p (struct breakpoint *b)
8405 return (b->ops == &catch_syscall_breakpoint_ops);
8408 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8409 is non-zero, then make the breakpoint temporary. If COND_STRING is
8410 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8411 the breakpoint_ops structure associated to the catchpoint. */
8414 init_catchpoint (struct breakpoint *b,
8415 struct gdbarch *gdbarch, int tempflag,
8417 const struct breakpoint_ops *ops)
8419 struct symtab_and_line sal;
8422 sal.pspace = current_program_space;
8424 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8426 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8427 b->disposition = tempflag ? disp_del : disp_donttouch;
8431 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8433 add_to_breakpoint_chain (b);
8434 set_breakpoint_number (internal, b);
8435 if (is_tracepoint (b))
8436 set_tracepoint_count (breakpoint_count);
8439 observer_notify_breakpoint_created (b);
8442 update_global_location_list (1);
8446 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8447 int tempflag, char *cond_string,
8448 const struct breakpoint_ops *ops)
8450 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8452 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8454 c->forked_inferior_pid = null_ptid;
8456 install_breakpoint (0, &c->base, 1);
8459 /* Exec catchpoints. */
8461 /* An instance of this type is used to represent an exec catchpoint.
8462 It includes a "struct breakpoint" as a kind of base class; users
8463 downcast to "struct breakpoint *" when needed. A breakpoint is
8464 really of this type iff its ops pointer points to
8465 CATCH_EXEC_BREAKPOINT_OPS. */
8467 struct exec_catchpoint
8469 /* The base class. */
8470 struct breakpoint base;
8472 /* Filename of a program whose exec triggered this catchpoint.
8473 This field is only valid immediately after this catchpoint has
8475 char *exec_pathname;
8478 /* Implement the "dtor" breakpoint_ops method for exec
8482 dtor_catch_exec (struct breakpoint *b)
8484 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8486 xfree (c->exec_pathname);
8488 base_breakpoint_ops.dtor (b);
8492 insert_catch_exec (struct bp_location *bl)
8494 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
8498 remove_catch_exec (struct bp_location *bl)
8500 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
8504 breakpoint_hit_catch_exec (const struct bp_location *bl,
8505 struct address_space *aspace, CORE_ADDR bp_addr,
8506 const struct target_waitstatus *ws)
8508 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8510 if (ws->kind != TARGET_WAITKIND_EXECD)
8513 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8517 static enum print_stop_action
8518 print_it_catch_exec (bpstat bs)
8520 struct ui_out *uiout = current_uiout;
8521 struct breakpoint *b = bs->breakpoint_at;
8522 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8524 annotate_catchpoint (b->number);
8525 if (b->disposition == disp_del)
8526 ui_out_text (uiout, "\nTemporary catchpoint ");
8528 ui_out_text (uiout, "\nCatchpoint ");
8529 if (ui_out_is_mi_like_p (uiout))
8531 ui_out_field_string (uiout, "reason",
8532 async_reason_lookup (EXEC_ASYNC_EXEC));
8533 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8535 ui_out_field_int (uiout, "bkptno", b->number);
8536 ui_out_text (uiout, " (exec'd ");
8537 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8538 ui_out_text (uiout, "), ");
8540 return PRINT_SRC_AND_LOC;
8544 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8546 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8547 struct value_print_options opts;
8548 struct ui_out *uiout = current_uiout;
8550 get_user_print_options (&opts);
8552 /* Field 4, the address, is omitted (which makes the columns
8553 not line up too nicely with the headers, but the effect
8554 is relatively readable). */
8555 if (opts.addressprint)
8556 ui_out_field_skip (uiout, "addr");
8558 ui_out_text (uiout, "exec");
8559 if (c->exec_pathname != NULL)
8561 ui_out_text (uiout, ", program \"");
8562 ui_out_field_string (uiout, "what", c->exec_pathname);
8563 ui_out_text (uiout, "\" ");
8566 if (ui_out_is_mi_like_p (uiout))
8567 ui_out_field_string (uiout, "catch-type", "exec");
8571 print_mention_catch_exec (struct breakpoint *b)
8573 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8576 /* Implement the "print_recreate" breakpoint_ops method for exec
8580 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8582 fprintf_unfiltered (fp, "catch exec");
8583 print_recreate_thread (b, fp);
8586 static struct breakpoint_ops catch_exec_breakpoint_ops;
8589 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8590 const struct breakpoint_ops *ops)
8592 struct syscall_catchpoint *c;
8593 struct gdbarch *gdbarch = get_current_arch ();
8595 c = XNEW (struct syscall_catchpoint);
8596 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8597 c->syscalls_to_be_caught = filter;
8599 install_breakpoint (0, &c->base, 1);
8603 hw_breakpoint_used_count (void)
8606 struct breakpoint *b;
8607 struct bp_location *bl;
8611 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8612 for (bl = b->loc; bl; bl = bl->next)
8614 /* Special types of hardware breakpoints may use more than
8616 i += b->ops->resources_needed (bl);
8623 /* Returns the resources B would use if it were a hardware
8627 hw_watchpoint_use_count (struct breakpoint *b)
8630 struct bp_location *bl;
8632 if (!breakpoint_enabled (b))
8635 for (bl = b->loc; bl; bl = bl->next)
8637 /* Special types of hardware watchpoints may use more than
8639 i += b->ops->resources_needed (bl);
8645 /* Returns the sum the used resources of all hardware watchpoints of
8646 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8647 the sum of the used resources of all hardware watchpoints of other
8648 types _not_ TYPE. */
8651 hw_watchpoint_used_count_others (struct breakpoint *except,
8652 enum bptype type, int *other_type_used)
8655 struct breakpoint *b;
8657 *other_type_used = 0;
8662 if (!breakpoint_enabled (b))
8665 if (b->type == type)
8666 i += hw_watchpoint_use_count (b);
8667 else if (is_hardware_watchpoint (b))
8668 *other_type_used = 1;
8675 disable_watchpoints_before_interactive_call_start (void)
8677 struct breakpoint *b;
8681 if (is_watchpoint (b) && breakpoint_enabled (b))
8683 b->enable_state = bp_call_disabled;
8684 update_global_location_list (0);
8690 enable_watchpoints_after_interactive_call_stop (void)
8692 struct breakpoint *b;
8696 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8698 b->enable_state = bp_enabled;
8699 update_global_location_list (1);
8705 disable_breakpoints_before_startup (void)
8707 current_program_space->executing_startup = 1;
8708 update_global_location_list (0);
8712 enable_breakpoints_after_startup (void)
8714 current_program_space->executing_startup = 0;
8715 breakpoint_re_set ();
8719 /* Set a breakpoint that will evaporate an end of command
8720 at address specified by SAL.
8721 Restrict it to frame FRAME if FRAME is nonzero. */
8724 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8725 struct frame_id frame_id, enum bptype type)
8727 struct breakpoint *b;
8729 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8731 gdb_assert (!frame_id_artificial_p (frame_id));
8733 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8734 b->enable_state = bp_enabled;
8735 b->disposition = disp_donttouch;
8736 b->frame_id = frame_id;
8738 /* If we're debugging a multi-threaded program, then we want
8739 momentary breakpoints to be active in only a single thread of
8741 if (in_thread_list (inferior_ptid))
8742 b->thread = pid_to_thread_id (inferior_ptid);
8744 update_global_location_list_nothrow (1);
8749 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8750 The new breakpoint will have type TYPE, and use OPS as it
8753 static struct breakpoint *
8754 momentary_breakpoint_from_master (struct breakpoint *orig,
8756 const struct breakpoint_ops *ops)
8758 struct breakpoint *copy;
8760 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8761 copy->loc = allocate_bp_location (copy);
8762 set_breakpoint_location_function (copy->loc, 1);
8764 copy->loc->gdbarch = orig->loc->gdbarch;
8765 copy->loc->requested_address = orig->loc->requested_address;
8766 copy->loc->address = orig->loc->address;
8767 copy->loc->section = orig->loc->section;
8768 copy->loc->pspace = orig->loc->pspace;
8769 copy->loc->probe = orig->loc->probe;
8770 copy->loc->line_number = orig->loc->line_number;
8771 copy->loc->symtab = orig->loc->symtab;
8772 copy->frame_id = orig->frame_id;
8773 copy->thread = orig->thread;
8774 copy->pspace = orig->pspace;
8776 copy->enable_state = bp_enabled;
8777 copy->disposition = disp_donttouch;
8778 copy->number = internal_breakpoint_number--;
8780 update_global_location_list_nothrow (0);
8784 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8788 clone_momentary_breakpoint (struct breakpoint *orig)
8790 /* If there's nothing to clone, then return nothing. */
8794 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8798 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8801 struct symtab_and_line sal;
8803 sal = find_pc_line (pc, 0);
8805 sal.section = find_pc_overlay (pc);
8806 sal.explicit_pc = 1;
8808 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8812 /* Tell the user we have just set a breakpoint B. */
8815 mention (struct breakpoint *b)
8817 b->ops->print_mention (b);
8818 if (ui_out_is_mi_like_p (current_uiout))
8820 printf_filtered ("\n");
8824 static struct bp_location *
8825 add_location_to_breakpoint (struct breakpoint *b,
8826 const struct symtab_and_line *sal)
8828 struct bp_location *loc, **tmp;
8829 CORE_ADDR adjusted_address;
8830 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8832 if (loc_gdbarch == NULL)
8833 loc_gdbarch = b->gdbarch;
8835 /* Adjust the breakpoint's address prior to allocating a location.
8836 Once we call allocate_bp_location(), that mostly uninitialized
8837 location will be placed on the location chain. Adjustment of the
8838 breakpoint may cause target_read_memory() to be called and we do
8839 not want its scan of the location chain to find a breakpoint and
8840 location that's only been partially initialized. */
8841 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8844 /* Sort the locations by their ADDRESS. */
8845 loc = allocate_bp_location (b);
8846 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8847 tmp = &((*tmp)->next))
8852 loc->requested_address = sal->pc;
8853 loc->address = adjusted_address;
8854 loc->pspace = sal->pspace;
8855 loc->probe = sal->probe;
8856 gdb_assert (loc->pspace != NULL);
8857 loc->section = sal->section;
8858 loc->gdbarch = loc_gdbarch;
8859 loc->line_number = sal->line;
8860 loc->symtab = sal->symtab;
8862 set_breakpoint_location_function (loc,
8863 sal->explicit_pc || sal->explicit_line);
8868 /* Return 1 if LOC is pointing to a permanent breakpoint,
8869 return 0 otherwise. */
8872 bp_loc_is_permanent (struct bp_location *loc)
8876 const gdb_byte *bpoint;
8877 gdb_byte *target_mem;
8878 struct cleanup *cleanup;
8881 gdb_assert (loc != NULL);
8883 addr = loc->address;
8884 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8886 /* Software breakpoints unsupported? */
8890 target_mem = alloca (len);
8892 /* Enable the automatic memory restoration from breakpoints while
8893 we read the memory. Otherwise we could say about our temporary
8894 breakpoints they are permanent. */
8895 cleanup = save_current_space_and_thread ();
8897 switch_to_program_space_and_thread (loc->pspace);
8898 make_show_memory_breakpoints_cleanup (0);
8900 if (target_read_memory (loc->address, target_mem, len) == 0
8901 && memcmp (target_mem, bpoint, len) == 0)
8904 do_cleanups (cleanup);
8909 /* Build a command list for the dprintf corresponding to the current
8910 settings of the dprintf style options. */
8913 update_dprintf_command_list (struct breakpoint *b)
8915 char *dprintf_args = b->extra_string;
8916 char *printf_line = NULL;
8921 dprintf_args = skip_spaces (dprintf_args);
8923 /* Allow a comma, as it may have terminated a location, but don't
8925 if (*dprintf_args == ',')
8927 dprintf_args = skip_spaces (dprintf_args);
8929 if (*dprintf_args != '"')
8930 error (_("Bad format string, missing '\"'."));
8932 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8933 printf_line = xstrprintf ("printf %s", dprintf_args);
8934 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8936 if (!dprintf_function)
8937 error (_("No function supplied for dprintf call"));
8939 if (dprintf_channel && strlen (dprintf_channel) > 0)
8940 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8945 printf_line = xstrprintf ("call (void) %s (%s)",
8949 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8951 if (target_can_run_breakpoint_commands ())
8952 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8955 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8956 printf_line = xstrprintf ("printf %s", dprintf_args);
8960 internal_error (__FILE__, __LINE__,
8961 _("Invalid dprintf style."));
8963 gdb_assert (printf_line != NULL);
8964 /* Manufacture a printf/continue sequence. */
8966 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8968 if (strcmp (dprintf_style, dprintf_style_agent) != 0)
8970 cont_cmd_line = xmalloc (sizeof (struct command_line));
8971 cont_cmd_line->control_type = simple_control;
8972 cont_cmd_line->body_count = 0;
8973 cont_cmd_line->body_list = NULL;
8974 cont_cmd_line->next = NULL;
8975 cont_cmd_line->line = xstrdup ("continue");
8978 printf_cmd_line = xmalloc (sizeof (struct command_line));
8979 printf_cmd_line->control_type = simple_control;
8980 printf_cmd_line->body_count = 0;
8981 printf_cmd_line->body_list = NULL;
8982 printf_cmd_line->next = cont_cmd_line;
8983 printf_cmd_line->line = printf_line;
8985 breakpoint_set_commands (b, printf_cmd_line);
8989 /* Update all dprintf commands, making their command lists reflect
8990 current style settings. */
8993 update_dprintf_commands (char *args, int from_tty,
8994 struct cmd_list_element *c)
8996 struct breakpoint *b;
9000 if (b->type == bp_dprintf)
9001 update_dprintf_command_list (b);
9005 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9006 as textual description of the location, and COND_STRING
9007 as condition expression. */
9010 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9011 struct symtabs_and_lines sals, char *addr_string,
9012 char *filter, char *cond_string,
9014 enum bptype type, enum bpdisp disposition,
9015 int thread, int task, int ignore_count,
9016 const struct breakpoint_ops *ops, int from_tty,
9017 int enabled, int internal, unsigned flags,
9018 int display_canonical)
9022 if (type == bp_hardware_breakpoint)
9024 int target_resources_ok;
9026 i = hw_breakpoint_used_count ();
9027 target_resources_ok =
9028 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9030 if (target_resources_ok == 0)
9031 error (_("No hardware breakpoint support in the target."));
9032 else if (target_resources_ok < 0)
9033 error (_("Hardware breakpoints used exceeds limit."));
9036 gdb_assert (sals.nelts > 0);
9038 for (i = 0; i < sals.nelts; ++i)
9040 struct symtab_and_line sal = sals.sals[i];
9041 struct bp_location *loc;
9045 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9047 loc_gdbarch = gdbarch;
9049 describe_other_breakpoints (loc_gdbarch,
9050 sal.pspace, sal.pc, sal.section, thread);
9055 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9059 b->cond_string = cond_string;
9060 b->extra_string = extra_string;
9061 b->ignore_count = ignore_count;
9062 b->enable_state = enabled ? bp_enabled : bp_disabled;
9063 b->disposition = disposition;
9065 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9066 b->loc->inserted = 1;
9068 if (type == bp_static_tracepoint)
9070 struct tracepoint *t = (struct tracepoint *) b;
9071 struct static_tracepoint_marker marker;
9073 if (strace_marker_p (b))
9075 /* We already know the marker exists, otherwise, we
9076 wouldn't see a sal for it. */
9077 char *p = &addr_string[3];
9081 p = skip_spaces (p);
9083 endp = skip_to_space (p);
9085 marker_str = savestring (p, endp - p);
9086 t->static_trace_marker_id = marker_str;
9088 printf_filtered (_("Probed static tracepoint "
9090 t->static_trace_marker_id);
9092 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9094 t->static_trace_marker_id = xstrdup (marker.str_id);
9095 release_static_tracepoint_marker (&marker);
9097 printf_filtered (_("Probed static tracepoint "
9099 t->static_trace_marker_id);
9102 warning (_("Couldn't determine the static "
9103 "tracepoint marker to probe"));
9110 loc = add_location_to_breakpoint (b, &sal);
9111 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9115 if (bp_loc_is_permanent (loc))
9116 make_breakpoint_permanent (b);
9120 const char *arg = b->cond_string;
9122 loc->cond = parse_exp_1 (&arg, loc->address,
9123 block_for_pc (loc->address), 0);
9125 error (_("Garbage '%s' follows condition"), arg);
9128 /* Dynamic printf requires and uses additional arguments on the
9129 command line, otherwise it's an error. */
9130 if (type == bp_dprintf)
9132 if (b->extra_string)
9133 update_dprintf_command_list (b);
9135 error (_("Format string required"));
9137 else if (b->extra_string)
9138 error (_("Garbage '%s' at end of command"), b->extra_string);
9141 b->display_canonical = display_canonical;
9143 b->addr_string = addr_string;
9145 /* addr_string has to be used or breakpoint_re_set will delete
9148 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9153 create_breakpoint_sal (struct gdbarch *gdbarch,
9154 struct symtabs_and_lines sals, char *addr_string,
9155 char *filter, char *cond_string,
9157 enum bptype type, enum bpdisp disposition,
9158 int thread, int task, int ignore_count,
9159 const struct breakpoint_ops *ops, int from_tty,
9160 int enabled, int internal, unsigned flags,
9161 int display_canonical)
9163 struct breakpoint *b;
9164 struct cleanup *old_chain;
9166 if (is_tracepoint_type (type))
9168 struct tracepoint *t;
9170 t = XCNEW (struct tracepoint);
9174 b = XNEW (struct breakpoint);
9176 old_chain = make_cleanup (xfree, b);
9178 init_breakpoint_sal (b, gdbarch,
9180 filter, cond_string, extra_string,
9182 thread, task, ignore_count,
9184 enabled, internal, flags,
9186 discard_cleanups (old_chain);
9188 install_breakpoint (internal, b, 0);
9191 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9192 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9193 value. COND_STRING, if not NULL, specified the condition to be
9194 used for all breakpoints. Essentially the only case where
9195 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9196 function. In that case, it's still not possible to specify
9197 separate conditions for different overloaded functions, so
9198 we take just a single condition string.
9200 NOTE: If the function succeeds, the caller is expected to cleanup
9201 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9202 array contents). If the function fails (error() is called), the
9203 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9204 COND and SALS arrays and each of those arrays contents. */
9207 create_breakpoints_sal (struct gdbarch *gdbarch,
9208 struct linespec_result *canonical,
9209 char *cond_string, char *extra_string,
9210 enum bptype type, enum bpdisp disposition,
9211 int thread, int task, int ignore_count,
9212 const struct breakpoint_ops *ops, int from_tty,
9213 int enabled, int internal, unsigned flags)
9216 struct linespec_sals *lsal;
9218 if (canonical->pre_expanded)
9219 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9221 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9223 /* Note that 'addr_string' can be NULL in the case of a plain
9224 'break', without arguments. */
9225 char *addr_string = (canonical->addr_string
9226 ? xstrdup (canonical->addr_string)
9228 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9229 struct cleanup *inner = make_cleanup (xfree, addr_string);
9231 make_cleanup (xfree, filter_string);
9232 create_breakpoint_sal (gdbarch, lsal->sals,
9235 cond_string, extra_string,
9237 thread, task, ignore_count, ops,
9238 from_tty, enabled, internal, flags,
9239 canonical->special_display);
9240 discard_cleanups (inner);
9244 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9245 followed by conditionals. On return, SALS contains an array of SAL
9246 addresses found. ADDR_STRING contains a vector of (canonical)
9247 address strings. ADDRESS points to the end of the SAL.
9249 The array and the line spec strings are allocated on the heap, it is
9250 the caller's responsibility to free them. */
9253 parse_breakpoint_sals (char **address,
9254 struct linespec_result *canonical)
9256 /* If no arg given, or if first arg is 'if ', use the default
9258 if ((*address) == NULL
9259 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9261 /* The last displayed codepoint, if it's valid, is our default breakpoint
9263 if (last_displayed_sal_is_valid ())
9265 struct linespec_sals lsal;
9266 struct symtab_and_line sal;
9269 init_sal (&sal); /* Initialize to zeroes. */
9270 lsal.sals.sals = (struct symtab_and_line *)
9271 xmalloc (sizeof (struct symtab_and_line));
9273 /* Set sal's pspace, pc, symtab, and line to the values
9274 corresponding to the last call to print_frame_info.
9275 Be sure to reinitialize LINE with NOTCURRENT == 0
9276 as the breakpoint line number is inappropriate otherwise.
9277 find_pc_line would adjust PC, re-set it back. */
9278 get_last_displayed_sal (&sal);
9280 sal = find_pc_line (pc, 0);
9282 /* "break" without arguments is equivalent to "break *PC"
9283 where PC is the last displayed codepoint's address. So
9284 make sure to set sal.explicit_pc to prevent GDB from
9285 trying to expand the list of sals to include all other
9286 instances with the same symtab and line. */
9288 sal.explicit_pc = 1;
9290 lsal.sals.sals[0] = sal;
9291 lsal.sals.nelts = 1;
9292 lsal.canonical = NULL;
9294 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9297 error (_("No default breakpoint address now."));
9301 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9303 /* Force almost all breakpoints to be in terms of the
9304 current_source_symtab (which is decode_line_1's default).
9305 This should produce the results we want almost all of the
9306 time while leaving default_breakpoint_* alone.
9308 ObjC: However, don't match an Objective-C method name which
9309 may have a '+' or '-' succeeded by a '['. */
9310 if (last_displayed_sal_is_valid ()
9312 || ((strchr ("+-", (*address)[0]) != NULL)
9313 && ((*address)[1] != '['))))
9314 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9315 get_last_displayed_symtab (),
9316 get_last_displayed_line (),
9317 canonical, NULL, NULL);
9319 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9320 cursal.symtab, cursal.line, canonical, NULL, NULL);
9325 /* Convert each SAL into a real PC. Verify that the PC can be
9326 inserted as a breakpoint. If it can't throw an error. */
9329 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9333 for (i = 0; i < sals->nelts; i++)
9334 resolve_sal_pc (&sals->sals[i]);
9337 /* Fast tracepoints may have restrictions on valid locations. For
9338 instance, a fast tracepoint using a jump instead of a trap will
9339 likely have to overwrite more bytes than a trap would, and so can
9340 only be placed where the instruction is longer than the jump, or a
9341 multi-instruction sequence does not have a jump into the middle of
9345 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9346 struct symtabs_and_lines *sals)
9349 struct symtab_and_line *sal;
9351 struct cleanup *old_chain;
9353 for (i = 0; i < sals->nelts; i++)
9355 struct gdbarch *sarch;
9357 sal = &sals->sals[i];
9359 sarch = get_sal_arch (*sal);
9360 /* We fall back to GDBARCH if there is no architecture
9361 associated with SAL. */
9364 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9366 old_chain = make_cleanup (xfree, msg);
9369 error (_("May not have a fast tracepoint at 0x%s%s"),
9370 paddress (sarch, sal->pc), (msg ? msg : ""));
9372 do_cleanups (old_chain);
9376 /* Issue an invalid thread ID error. */
9378 static void ATTRIBUTE_NORETURN
9379 invalid_thread_id_error (int id)
9381 error (_("Unknown thread %d."), id);
9384 /* Given TOK, a string specification of condition and thread, as
9385 accepted by the 'break' command, extract the condition
9386 string and thread number and set *COND_STRING and *THREAD.
9387 PC identifies the context at which the condition should be parsed.
9388 If no condition is found, *COND_STRING is set to NULL.
9389 If no thread is found, *THREAD is set to -1. */
9392 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9393 char **cond_string, int *thread, int *task,
9396 *cond_string = NULL;
9403 const char *end_tok;
9405 const char *cond_start = NULL;
9406 const char *cond_end = NULL;
9408 tok = skip_spaces_const (tok);
9410 if ((*tok == '"' || *tok == ',') && rest)
9412 *rest = savestring (tok, strlen (tok));
9416 end_tok = skip_to_space_const (tok);
9418 toklen = end_tok - tok;
9420 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9422 struct expression *expr;
9424 tok = cond_start = end_tok + 1;
9425 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9428 *cond_string = savestring (cond_start, cond_end - cond_start);
9430 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9435 *thread = strtol (tok, &tmptok, 0);
9437 error (_("Junk after thread keyword."));
9438 if (!valid_thread_id (*thread))
9439 invalid_thread_id_error (*thread);
9442 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9447 *task = strtol (tok, &tmptok, 0);
9449 error (_("Junk after task keyword."));
9450 if (!valid_task_id (*task))
9451 error (_("Unknown task %d."), *task);
9456 *rest = savestring (tok, strlen (tok));
9460 error (_("Junk at end of arguments."));
9464 /* Decode a static tracepoint marker spec. */
9466 static struct symtabs_and_lines
9467 decode_static_tracepoint_spec (char **arg_p)
9469 VEC(static_tracepoint_marker_p) *markers = NULL;
9470 struct symtabs_and_lines sals;
9471 struct cleanup *old_chain;
9472 char *p = &(*arg_p)[3];
9477 p = skip_spaces (p);
9479 endp = skip_to_space (p);
9481 marker_str = savestring (p, endp - p);
9482 old_chain = make_cleanup (xfree, marker_str);
9484 markers = target_static_tracepoint_markers_by_strid (marker_str);
9485 if (VEC_empty(static_tracepoint_marker_p, markers))
9486 error (_("No known static tracepoint marker named %s"), marker_str);
9488 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9489 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9491 for (i = 0; i < sals.nelts; i++)
9493 struct static_tracepoint_marker *marker;
9495 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9497 init_sal (&sals.sals[i]);
9499 sals.sals[i] = find_pc_line (marker->address, 0);
9500 sals.sals[i].pc = marker->address;
9502 release_static_tracepoint_marker (marker);
9505 do_cleanups (old_chain);
9511 /* Set a breakpoint. This function is shared between CLI and MI
9512 functions for setting a breakpoint. This function has two major
9513 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9514 parameter. If non-zero, the function will parse arg, extracting
9515 breakpoint location, address and thread. Otherwise, ARG is just
9516 the location of breakpoint, with condition and thread specified by
9517 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9518 the breakpoint number will be allocated from the internal
9519 breakpoint count. Returns true if any breakpoint was created;
9523 create_breakpoint (struct gdbarch *gdbarch,
9524 char *arg, char *cond_string,
9525 int thread, char *extra_string,
9526 int parse_condition_and_thread,
9527 int tempflag, enum bptype type_wanted,
9529 enum auto_boolean pending_break_support,
9530 const struct breakpoint_ops *ops,
9531 int from_tty, int enabled, int internal,
9534 volatile struct gdb_exception e;
9535 char *copy_arg = NULL;
9536 char *addr_start = arg;
9537 struct linespec_result canonical;
9538 struct cleanup *old_chain;
9539 struct cleanup *bkpt_chain = NULL;
9542 int prev_bkpt_count = breakpoint_count;
9544 gdb_assert (ops != NULL);
9546 init_linespec_result (&canonical);
9548 TRY_CATCH (e, RETURN_MASK_ALL)
9550 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9551 addr_start, ©_arg);
9554 /* If caller is interested in rc value from parse, set value. */
9558 if (VEC_empty (linespec_sals, canonical.sals))
9564 case NOT_FOUND_ERROR:
9566 /* If pending breakpoint support is turned off, throw
9569 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9570 throw_exception (e);
9572 exception_print (gdb_stderr, e);
9574 /* If pending breakpoint support is auto query and the user
9575 selects no, then simply return the error code. */
9576 if (pending_break_support == AUTO_BOOLEAN_AUTO
9577 && !nquery (_("Make %s pending on future shared library load? "),
9578 bptype_string (type_wanted)))
9581 /* At this point, either the user was queried about setting
9582 a pending breakpoint and selected yes, or pending
9583 breakpoint behavior is on and thus a pending breakpoint
9584 is defaulted on behalf of the user. */
9586 struct linespec_sals lsal;
9588 copy_arg = xstrdup (addr_start);
9589 lsal.canonical = xstrdup (copy_arg);
9590 lsal.sals.nelts = 1;
9591 lsal.sals.sals = XNEW (struct symtab_and_line);
9592 init_sal (&lsal.sals.sals[0]);
9594 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9598 throw_exception (e);
9602 throw_exception (e);
9605 /* Create a chain of things that always need to be cleaned up. */
9606 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9608 /* ----------------------------- SNIP -----------------------------
9609 Anything added to the cleanup chain beyond this point is assumed
9610 to be part of a breakpoint. If the breakpoint create succeeds
9611 then the memory is not reclaimed. */
9612 bkpt_chain = make_cleanup (null_cleanup, 0);
9614 /* Resolve all line numbers to PC's and verify that the addresses
9615 are ok for the target. */
9619 struct linespec_sals *iter;
9621 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9622 breakpoint_sals_to_pc (&iter->sals);
9625 /* Fast tracepoints may have additional restrictions on location. */
9626 if (!pending && type_wanted == bp_fast_tracepoint)
9629 struct linespec_sals *iter;
9631 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9632 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9635 /* Verify that condition can be parsed, before setting any
9636 breakpoints. Allocate a separate condition expression for each
9640 struct linespec_sals *lsal;
9642 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9644 if (parse_condition_and_thread)
9647 /* Here we only parse 'arg' to separate condition
9648 from thread number, so parsing in context of first
9649 sal is OK. When setting the breakpoint we'll
9650 re-parse it in context of each sal. */
9652 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9653 &thread, &task, &rest);
9655 make_cleanup (xfree, cond_string);
9657 make_cleanup (xfree, rest);
9659 extra_string = rest;
9663 /* Create a private copy of condition string. */
9666 cond_string = xstrdup (cond_string);
9667 make_cleanup (xfree, cond_string);
9669 /* Create a private copy of any extra string. */
9672 extra_string = xstrdup (extra_string);
9673 make_cleanup (xfree, extra_string);
9677 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9678 cond_string, extra_string, type_wanted,
9679 tempflag ? disp_del : disp_donttouch,
9680 thread, task, ignore_count, ops,
9681 from_tty, enabled, internal, flags);
9685 struct breakpoint *b;
9687 make_cleanup (xfree, copy_arg);
9689 if (is_tracepoint_type (type_wanted))
9691 struct tracepoint *t;
9693 t = XCNEW (struct tracepoint);
9697 b = XNEW (struct breakpoint);
9699 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9701 b->addr_string = copy_arg;
9702 if (parse_condition_and_thread)
9703 b->cond_string = NULL;
9706 /* Create a private copy of condition string. */
9709 cond_string = xstrdup (cond_string);
9710 make_cleanup (xfree, cond_string);
9712 b->cond_string = cond_string;
9714 b->extra_string = NULL;
9715 b->ignore_count = ignore_count;
9716 b->disposition = tempflag ? disp_del : disp_donttouch;
9717 b->condition_not_parsed = 1;
9718 b->enable_state = enabled ? bp_enabled : bp_disabled;
9719 if ((type_wanted != bp_breakpoint
9720 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9721 b->pspace = current_program_space;
9723 install_breakpoint (internal, b, 0);
9726 if (VEC_length (linespec_sals, canonical.sals) > 1)
9728 warning (_("Multiple breakpoints were set.\nUse the "
9729 "\"delete\" command to delete unwanted breakpoints."));
9730 prev_breakpoint_count = prev_bkpt_count;
9733 /* That's it. Discard the cleanups for data inserted into the
9735 discard_cleanups (bkpt_chain);
9736 /* But cleanup everything else. */
9737 do_cleanups (old_chain);
9739 /* error call may happen here - have BKPT_CHAIN already discarded. */
9740 update_global_location_list (1);
9745 /* Set a breakpoint.
9746 ARG is a string describing breakpoint address,
9747 condition, and thread.
9748 FLAG specifies if a breakpoint is hardware on,
9749 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9753 break_command_1 (char *arg, int flag, int from_tty)
9755 int tempflag = flag & BP_TEMPFLAG;
9756 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9757 ? bp_hardware_breakpoint
9759 struct breakpoint_ops *ops;
9760 const char *arg_cp = arg;
9762 /* Matching breakpoints on probes. */
9763 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9764 ops = &bkpt_probe_breakpoint_ops;
9766 ops = &bkpt_breakpoint_ops;
9768 create_breakpoint (get_current_arch (),
9770 NULL, 0, NULL, 1 /* parse arg */,
9771 tempflag, type_wanted,
9772 0 /* Ignore count */,
9773 pending_break_support,
9781 /* Helper function for break_command_1 and disassemble_command. */
9784 resolve_sal_pc (struct symtab_and_line *sal)
9788 if (sal->pc == 0 && sal->symtab != NULL)
9790 if (!find_line_pc (sal->symtab, sal->line, &pc))
9791 error (_("No line %d in file \"%s\"."),
9792 sal->line, symtab_to_filename_for_display (sal->symtab));
9795 /* If this SAL corresponds to a breakpoint inserted using a line
9796 number, then skip the function prologue if necessary. */
9797 if (sal->explicit_line)
9798 skip_prologue_sal (sal);
9801 if (sal->section == 0 && sal->symtab != NULL)
9803 struct blockvector *bv;
9807 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9810 sym = block_linkage_function (b);
9813 fixup_symbol_section (sym, sal->symtab->objfile);
9814 sal->section = SYMBOL_OBJ_SECTION (sym);
9818 /* It really is worthwhile to have the section, so we'll
9819 just have to look harder. This case can be executed
9820 if we have line numbers but no functions (as can
9821 happen in assembly source). */
9823 struct minimal_symbol *msym;
9824 struct cleanup *old_chain = save_current_space_and_thread ();
9826 switch_to_program_space_and_thread (sal->pspace);
9828 msym = lookup_minimal_symbol_by_pc (sal->pc);
9830 sal->section = SYMBOL_OBJ_SECTION (msym);
9832 do_cleanups (old_chain);
9839 break_command (char *arg, int from_tty)
9841 break_command_1 (arg, 0, from_tty);
9845 tbreak_command (char *arg, int from_tty)
9847 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9851 hbreak_command (char *arg, int from_tty)
9853 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9857 thbreak_command (char *arg, int from_tty)
9859 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9863 stop_command (char *arg, int from_tty)
9865 printf_filtered (_("Specify the type of breakpoint to set.\n\
9866 Usage: stop in <function | address>\n\
9867 stop at <line>\n"));
9871 stopin_command (char *arg, int from_tty)
9875 if (arg == (char *) NULL)
9877 else if (*arg != '*')
9882 /* Look for a ':'. If this is a line number specification, then
9883 say it is bad, otherwise, it should be an address or
9884 function/method name. */
9885 while (*argptr && !hasColon)
9887 hasColon = (*argptr == ':');
9892 badInput = (*argptr != ':'); /* Not a class::method */
9894 badInput = isdigit (*arg); /* a simple line number */
9898 printf_filtered (_("Usage: stop in <function | address>\n"));
9900 break_command_1 (arg, 0, from_tty);
9904 stopat_command (char *arg, int from_tty)
9908 if (arg == (char *) NULL || *arg == '*') /* no line number */
9915 /* Look for a ':'. If there is a '::' then get out, otherwise
9916 it is probably a line number. */
9917 while (*argptr && !hasColon)
9919 hasColon = (*argptr == ':');
9924 badInput = (*argptr == ':'); /* we have class::method */
9926 badInput = !isdigit (*arg); /* not a line number */
9930 printf_filtered (_("Usage: stop at <line>\n"));
9932 break_command_1 (arg, 0, from_tty);
9935 /* The dynamic printf command is mostly like a regular breakpoint, but
9936 with a prewired command list consisting of a single output command,
9937 built from extra arguments supplied on the dprintf command
9941 dprintf_command (char *arg, int from_tty)
9943 create_breakpoint (get_current_arch (),
9945 NULL, 0, NULL, 1 /* parse arg */,
9947 0 /* Ignore count */,
9948 pending_break_support,
9949 &dprintf_breakpoint_ops,
9957 agent_printf_command (char *arg, int from_tty)
9959 error (_("May only run agent-printf on the target"));
9962 /* Implement the "breakpoint_hit" breakpoint_ops method for
9963 ranged breakpoints. */
9966 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9967 struct address_space *aspace,
9969 const struct target_waitstatus *ws)
9971 if (ws->kind != TARGET_WAITKIND_STOPPED
9972 || ws->value.sig != GDB_SIGNAL_TRAP)
9975 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9976 bl->length, aspace, bp_addr);
9979 /* Implement the "resources_needed" breakpoint_ops method for
9980 ranged breakpoints. */
9983 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9985 return target_ranged_break_num_registers ();
9988 /* Implement the "print_it" breakpoint_ops method for
9989 ranged breakpoints. */
9991 static enum print_stop_action
9992 print_it_ranged_breakpoint (bpstat bs)
9994 struct breakpoint *b = bs->breakpoint_at;
9995 struct bp_location *bl = b->loc;
9996 struct ui_out *uiout = current_uiout;
9998 gdb_assert (b->type == bp_hardware_breakpoint);
10000 /* Ranged breakpoints have only one location. */
10001 gdb_assert (bl && bl->next == NULL);
10003 annotate_breakpoint (b->number);
10004 if (b->disposition == disp_del)
10005 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10007 ui_out_text (uiout, "\nRanged breakpoint ");
10008 if (ui_out_is_mi_like_p (uiout))
10010 ui_out_field_string (uiout, "reason",
10011 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10012 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10014 ui_out_field_int (uiout, "bkptno", b->number);
10015 ui_out_text (uiout, ", ");
10017 return PRINT_SRC_AND_LOC;
10020 /* Implement the "print_one" breakpoint_ops method for
10021 ranged breakpoints. */
10024 print_one_ranged_breakpoint (struct breakpoint *b,
10025 struct bp_location **last_loc)
10027 struct bp_location *bl = b->loc;
10028 struct value_print_options opts;
10029 struct ui_out *uiout = current_uiout;
10031 /* Ranged breakpoints have only one location. */
10032 gdb_assert (bl && bl->next == NULL);
10034 get_user_print_options (&opts);
10036 if (opts.addressprint)
10037 /* We don't print the address range here, it will be printed later
10038 by print_one_detail_ranged_breakpoint. */
10039 ui_out_field_skip (uiout, "addr");
10040 annotate_field (5);
10041 print_breakpoint_location (b, bl);
10045 /* Implement the "print_one_detail" breakpoint_ops method for
10046 ranged breakpoints. */
10049 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10050 struct ui_out *uiout)
10052 CORE_ADDR address_start, address_end;
10053 struct bp_location *bl = b->loc;
10054 struct ui_file *stb = mem_fileopen ();
10055 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10059 address_start = bl->address;
10060 address_end = address_start + bl->length - 1;
10062 ui_out_text (uiout, "\taddress range: ");
10063 fprintf_unfiltered (stb, "[%s, %s]",
10064 print_core_address (bl->gdbarch, address_start),
10065 print_core_address (bl->gdbarch, address_end));
10066 ui_out_field_stream (uiout, "addr", stb);
10067 ui_out_text (uiout, "\n");
10069 do_cleanups (cleanup);
10072 /* Implement the "print_mention" breakpoint_ops method for
10073 ranged breakpoints. */
10076 print_mention_ranged_breakpoint (struct breakpoint *b)
10078 struct bp_location *bl = b->loc;
10079 struct ui_out *uiout = current_uiout;
10082 gdb_assert (b->type == bp_hardware_breakpoint);
10084 if (ui_out_is_mi_like_p (uiout))
10087 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10088 b->number, paddress (bl->gdbarch, bl->address),
10089 paddress (bl->gdbarch, bl->address + bl->length - 1));
10092 /* Implement the "print_recreate" breakpoint_ops method for
10093 ranged breakpoints. */
10096 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10098 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10099 b->addr_string_range_end);
10100 print_recreate_thread (b, fp);
10103 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10105 static struct breakpoint_ops ranged_breakpoint_ops;
10107 /* Find the address where the end of the breakpoint range should be
10108 placed, given the SAL of the end of the range. This is so that if
10109 the user provides a line number, the end of the range is set to the
10110 last instruction of the given line. */
10113 find_breakpoint_range_end (struct symtab_and_line sal)
10117 /* If the user provided a PC value, use it. Otherwise,
10118 find the address of the end of the given location. */
10119 if (sal.explicit_pc)
10126 ret = find_line_pc_range (sal, &start, &end);
10128 error (_("Could not find location of the end of the range."));
10130 /* find_line_pc_range returns the start of the next line. */
10137 /* Implement the "break-range" CLI command. */
10140 break_range_command (char *arg, int from_tty)
10142 char *arg_start, *addr_string_start, *addr_string_end;
10143 struct linespec_result canonical_start, canonical_end;
10144 int bp_count, can_use_bp, length;
10146 struct breakpoint *b;
10147 struct symtab_and_line sal_start, sal_end;
10148 struct cleanup *cleanup_bkpt;
10149 struct linespec_sals *lsal_start, *lsal_end;
10151 /* We don't support software ranged breakpoints. */
10152 if (target_ranged_break_num_registers () < 0)
10153 error (_("This target does not support hardware ranged breakpoints."));
10155 bp_count = hw_breakpoint_used_count ();
10156 bp_count += target_ranged_break_num_registers ();
10157 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10159 if (can_use_bp < 0)
10160 error (_("Hardware breakpoints used exceeds limit."));
10162 arg = skip_spaces (arg);
10163 if (arg == NULL || arg[0] == '\0')
10164 error(_("No address range specified."));
10166 init_linespec_result (&canonical_start);
10169 parse_breakpoint_sals (&arg, &canonical_start);
10171 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10174 error (_("Too few arguments."));
10175 else if (VEC_empty (linespec_sals, canonical_start.sals))
10176 error (_("Could not find location of the beginning of the range."));
10178 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10180 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10181 || lsal_start->sals.nelts != 1)
10182 error (_("Cannot create a ranged breakpoint with multiple locations."));
10184 sal_start = lsal_start->sals.sals[0];
10185 addr_string_start = savestring (arg_start, arg - arg_start);
10186 make_cleanup (xfree, addr_string_start);
10188 arg++; /* Skip the comma. */
10189 arg = skip_spaces (arg);
10191 /* Parse the end location. */
10193 init_linespec_result (&canonical_end);
10196 /* We call decode_line_full directly here instead of using
10197 parse_breakpoint_sals because we need to specify the start location's
10198 symtab and line as the default symtab and line for the end of the
10199 range. This makes it possible to have ranges like "foo.c:27, +14",
10200 where +14 means 14 lines from the start location. */
10201 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10202 sal_start.symtab, sal_start.line,
10203 &canonical_end, NULL, NULL);
10205 make_cleanup_destroy_linespec_result (&canonical_end);
10207 if (VEC_empty (linespec_sals, canonical_end.sals))
10208 error (_("Could not find location of the end of the range."));
10210 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10211 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10212 || lsal_end->sals.nelts != 1)
10213 error (_("Cannot create a ranged breakpoint with multiple locations."));
10215 sal_end = lsal_end->sals.sals[0];
10216 addr_string_end = savestring (arg_start, arg - arg_start);
10217 make_cleanup (xfree, addr_string_end);
10219 end = find_breakpoint_range_end (sal_end);
10220 if (sal_start.pc > end)
10221 error (_("Invalid address range, end precedes start."));
10223 length = end - sal_start.pc + 1;
10225 /* Length overflowed. */
10226 error (_("Address range too large."));
10227 else if (length == 1)
10229 /* This range is simple enough to be handled by
10230 the `hbreak' command. */
10231 hbreak_command (addr_string_start, 1);
10233 do_cleanups (cleanup_bkpt);
10238 /* Now set up the breakpoint. */
10239 b = set_raw_breakpoint (get_current_arch (), sal_start,
10240 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10241 set_breakpoint_count (breakpoint_count + 1);
10242 b->number = breakpoint_count;
10243 b->disposition = disp_donttouch;
10244 b->addr_string = xstrdup (addr_string_start);
10245 b->addr_string_range_end = xstrdup (addr_string_end);
10246 b->loc->length = length;
10248 do_cleanups (cleanup_bkpt);
10251 observer_notify_breakpoint_created (b);
10252 update_global_location_list (1);
10255 /* Return non-zero if EXP is verified as constant. Returned zero
10256 means EXP is variable. Also the constant detection may fail for
10257 some constant expressions and in such case still falsely return
10261 watchpoint_exp_is_const (const struct expression *exp)
10263 int i = exp->nelts;
10269 /* We are only interested in the descriptor of each element. */
10270 operator_length (exp, i, &oplenp, &argsp);
10273 switch (exp->elts[i].opcode)
10283 case BINOP_LOGICAL_AND:
10284 case BINOP_LOGICAL_OR:
10285 case BINOP_BITWISE_AND:
10286 case BINOP_BITWISE_IOR:
10287 case BINOP_BITWISE_XOR:
10289 case BINOP_NOTEQUAL:
10317 case OP_OBJC_NSSTRING:
10320 case UNOP_LOGICAL_NOT:
10321 case UNOP_COMPLEMENT:
10326 case UNOP_CAST_TYPE:
10327 case UNOP_REINTERPRET_CAST:
10328 case UNOP_DYNAMIC_CAST:
10329 /* Unary, binary and ternary operators: We have to check
10330 their operands. If they are constant, then so is the
10331 result of that operation. For instance, if A and B are
10332 determined to be constants, then so is "A + B".
10334 UNOP_IND is one exception to the rule above, because the
10335 value of *ADDR is not necessarily a constant, even when
10340 /* Check whether the associated symbol is a constant.
10342 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10343 possible that a buggy compiler could mark a variable as
10344 constant even when it is not, and TYPE_CONST would return
10345 true in this case, while SYMBOL_CLASS wouldn't.
10347 We also have to check for function symbols because they
10348 are always constant. */
10350 struct symbol *s = exp->elts[i + 2].symbol;
10352 if (SYMBOL_CLASS (s) != LOC_BLOCK
10353 && SYMBOL_CLASS (s) != LOC_CONST
10354 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10359 /* The default action is to return 0 because we are using
10360 the optimistic approach here: If we don't know something,
10361 then it is not a constant. */
10370 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10373 dtor_watchpoint (struct breakpoint *self)
10375 struct watchpoint *w = (struct watchpoint *) self;
10377 xfree (w->cond_exp);
10379 xfree (w->exp_string);
10380 xfree (w->exp_string_reparse);
10381 value_free (w->val);
10383 base_breakpoint_ops.dtor (self);
10386 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10389 re_set_watchpoint (struct breakpoint *b)
10391 struct watchpoint *w = (struct watchpoint *) b;
10393 /* Watchpoint can be either on expression using entirely global
10394 variables, or it can be on local variables.
10396 Watchpoints of the first kind are never auto-deleted, and even
10397 persist across program restarts. Since they can use variables
10398 from shared libraries, we need to reparse expression as libraries
10399 are loaded and unloaded.
10401 Watchpoints on local variables can also change meaning as result
10402 of solib event. For example, if a watchpoint uses both a local
10403 and a global variables in expression, it's a local watchpoint,
10404 but unloading of a shared library will make the expression
10405 invalid. This is not a very common use case, but we still
10406 re-evaluate expression, to avoid surprises to the user.
10408 Note that for local watchpoints, we re-evaluate it only if
10409 watchpoints frame id is still valid. If it's not, it means the
10410 watchpoint is out of scope and will be deleted soon. In fact,
10411 I'm not sure we'll ever be called in this case.
10413 If a local watchpoint's frame id is still valid, then
10414 w->exp_valid_block is likewise valid, and we can safely use it.
10416 Don't do anything about disabled watchpoints, since they will be
10417 reevaluated again when enabled. */
10418 update_watchpoint (w, 1 /* reparse */);
10421 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10424 insert_watchpoint (struct bp_location *bl)
10426 struct watchpoint *w = (struct watchpoint *) bl->owner;
10427 int length = w->exact ? 1 : bl->length;
10429 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10433 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10436 remove_watchpoint (struct bp_location *bl)
10438 struct watchpoint *w = (struct watchpoint *) bl->owner;
10439 int length = w->exact ? 1 : bl->length;
10441 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10446 breakpoint_hit_watchpoint (const struct bp_location *bl,
10447 struct address_space *aspace, CORE_ADDR bp_addr,
10448 const struct target_waitstatus *ws)
10450 struct breakpoint *b = bl->owner;
10451 struct watchpoint *w = (struct watchpoint *) b;
10453 /* Continuable hardware watchpoints are treated as non-existent if the
10454 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10455 some data address). Otherwise gdb won't stop on a break instruction
10456 in the code (not from a breakpoint) when a hardware watchpoint has
10457 been defined. Also skip watchpoints which we know did not trigger
10458 (did not match the data address). */
10459 if (is_hardware_watchpoint (b)
10460 && w->watchpoint_triggered == watch_triggered_no)
10467 check_status_watchpoint (bpstat bs)
10469 gdb_assert (is_watchpoint (bs->breakpoint_at));
10471 bpstat_check_watchpoint (bs);
10474 /* Implement the "resources_needed" breakpoint_ops method for
10475 hardware watchpoints. */
10478 resources_needed_watchpoint (const struct bp_location *bl)
10480 struct watchpoint *w = (struct watchpoint *) bl->owner;
10481 int length = w->exact? 1 : bl->length;
10483 return target_region_ok_for_hw_watchpoint (bl->address, length);
10486 /* Implement the "works_in_software_mode" breakpoint_ops method for
10487 hardware watchpoints. */
10490 works_in_software_mode_watchpoint (const struct breakpoint *b)
10492 /* Read and access watchpoints only work with hardware support. */
10493 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10496 static enum print_stop_action
10497 print_it_watchpoint (bpstat bs)
10499 struct cleanup *old_chain;
10500 struct breakpoint *b;
10501 struct ui_file *stb;
10502 enum print_stop_action result;
10503 struct watchpoint *w;
10504 struct ui_out *uiout = current_uiout;
10506 gdb_assert (bs->bp_location_at != NULL);
10508 b = bs->breakpoint_at;
10509 w = (struct watchpoint *) b;
10511 stb = mem_fileopen ();
10512 old_chain = make_cleanup_ui_file_delete (stb);
10516 case bp_watchpoint:
10517 case bp_hardware_watchpoint:
10518 annotate_watchpoint (b->number);
10519 if (ui_out_is_mi_like_p (uiout))
10520 ui_out_field_string
10522 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10524 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10525 ui_out_text (uiout, "\nOld value = ");
10526 watchpoint_value_print (bs->old_val, stb);
10527 ui_out_field_stream (uiout, "old", stb);
10528 ui_out_text (uiout, "\nNew value = ");
10529 watchpoint_value_print (w->val, stb);
10530 ui_out_field_stream (uiout, "new", stb);
10531 ui_out_text (uiout, "\n");
10532 /* More than one watchpoint may have been triggered. */
10533 result = PRINT_UNKNOWN;
10536 case bp_read_watchpoint:
10537 if (ui_out_is_mi_like_p (uiout))
10538 ui_out_field_string
10540 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10542 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10543 ui_out_text (uiout, "\nValue = ");
10544 watchpoint_value_print (w->val, stb);
10545 ui_out_field_stream (uiout, "value", stb);
10546 ui_out_text (uiout, "\n");
10547 result = PRINT_UNKNOWN;
10550 case bp_access_watchpoint:
10551 if (bs->old_val != NULL)
10553 annotate_watchpoint (b->number);
10554 if (ui_out_is_mi_like_p (uiout))
10555 ui_out_field_string
10557 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10559 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10560 ui_out_text (uiout, "\nOld value = ");
10561 watchpoint_value_print (bs->old_val, stb);
10562 ui_out_field_stream (uiout, "old", stb);
10563 ui_out_text (uiout, "\nNew value = ");
10568 if (ui_out_is_mi_like_p (uiout))
10569 ui_out_field_string
10571 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10572 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10573 ui_out_text (uiout, "\nValue = ");
10575 watchpoint_value_print (w->val, stb);
10576 ui_out_field_stream (uiout, "new", stb);
10577 ui_out_text (uiout, "\n");
10578 result = PRINT_UNKNOWN;
10581 result = PRINT_UNKNOWN;
10584 do_cleanups (old_chain);
10588 /* Implement the "print_mention" breakpoint_ops method for hardware
10592 print_mention_watchpoint (struct breakpoint *b)
10594 struct cleanup *ui_out_chain;
10595 struct watchpoint *w = (struct watchpoint *) b;
10596 struct ui_out *uiout = current_uiout;
10600 case bp_watchpoint:
10601 ui_out_text (uiout, "Watchpoint ");
10602 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10604 case bp_hardware_watchpoint:
10605 ui_out_text (uiout, "Hardware watchpoint ");
10606 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10608 case bp_read_watchpoint:
10609 ui_out_text (uiout, "Hardware read watchpoint ");
10610 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10612 case bp_access_watchpoint:
10613 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10614 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10617 internal_error (__FILE__, __LINE__,
10618 _("Invalid hardware watchpoint type."));
10621 ui_out_field_int (uiout, "number", b->number);
10622 ui_out_text (uiout, ": ");
10623 ui_out_field_string (uiout, "exp", w->exp_string);
10624 do_cleanups (ui_out_chain);
10627 /* Implement the "print_recreate" breakpoint_ops method for
10631 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10633 struct watchpoint *w = (struct watchpoint *) b;
10637 case bp_watchpoint:
10638 case bp_hardware_watchpoint:
10639 fprintf_unfiltered (fp, "watch");
10641 case bp_read_watchpoint:
10642 fprintf_unfiltered (fp, "rwatch");
10644 case bp_access_watchpoint:
10645 fprintf_unfiltered (fp, "awatch");
10648 internal_error (__FILE__, __LINE__,
10649 _("Invalid watchpoint type."));
10652 fprintf_unfiltered (fp, " %s", w->exp_string);
10653 print_recreate_thread (b, fp);
10656 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10658 static struct breakpoint_ops watchpoint_breakpoint_ops;
10660 /* Implement the "insert" breakpoint_ops method for
10661 masked hardware watchpoints. */
10664 insert_masked_watchpoint (struct bp_location *bl)
10666 struct watchpoint *w = (struct watchpoint *) bl->owner;
10668 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10669 bl->watchpoint_type);
10672 /* Implement the "remove" breakpoint_ops method for
10673 masked hardware watchpoints. */
10676 remove_masked_watchpoint (struct bp_location *bl)
10678 struct watchpoint *w = (struct watchpoint *) bl->owner;
10680 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10681 bl->watchpoint_type);
10684 /* Implement the "resources_needed" breakpoint_ops method for
10685 masked hardware watchpoints. */
10688 resources_needed_masked_watchpoint (const struct bp_location *bl)
10690 struct watchpoint *w = (struct watchpoint *) bl->owner;
10692 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10695 /* Implement the "works_in_software_mode" breakpoint_ops method for
10696 masked hardware watchpoints. */
10699 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10704 /* Implement the "print_it" breakpoint_ops method for
10705 masked hardware watchpoints. */
10707 static enum print_stop_action
10708 print_it_masked_watchpoint (bpstat bs)
10710 struct breakpoint *b = bs->breakpoint_at;
10711 struct ui_out *uiout = current_uiout;
10713 /* Masked watchpoints have only one location. */
10714 gdb_assert (b->loc && b->loc->next == NULL);
10718 case bp_hardware_watchpoint:
10719 annotate_watchpoint (b->number);
10720 if (ui_out_is_mi_like_p (uiout))
10721 ui_out_field_string
10723 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10726 case bp_read_watchpoint:
10727 if (ui_out_is_mi_like_p (uiout))
10728 ui_out_field_string
10730 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10733 case bp_access_watchpoint:
10734 if (ui_out_is_mi_like_p (uiout))
10735 ui_out_field_string
10737 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10740 internal_error (__FILE__, __LINE__,
10741 _("Invalid hardware watchpoint type."));
10745 ui_out_text (uiout, _("\n\
10746 Check the underlying instruction at PC for the memory\n\
10747 address and value which triggered this watchpoint.\n"));
10748 ui_out_text (uiout, "\n");
10750 /* More than one watchpoint may have been triggered. */
10751 return PRINT_UNKNOWN;
10754 /* Implement the "print_one_detail" breakpoint_ops method for
10755 masked hardware watchpoints. */
10758 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10759 struct ui_out *uiout)
10761 struct watchpoint *w = (struct watchpoint *) b;
10763 /* Masked watchpoints have only one location. */
10764 gdb_assert (b->loc && b->loc->next == NULL);
10766 ui_out_text (uiout, "\tmask ");
10767 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10768 ui_out_text (uiout, "\n");
10771 /* Implement the "print_mention" breakpoint_ops method for
10772 masked hardware watchpoints. */
10775 print_mention_masked_watchpoint (struct breakpoint *b)
10777 struct watchpoint *w = (struct watchpoint *) b;
10778 struct ui_out *uiout = current_uiout;
10779 struct cleanup *ui_out_chain;
10783 case bp_hardware_watchpoint:
10784 ui_out_text (uiout, "Masked hardware watchpoint ");
10785 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10787 case bp_read_watchpoint:
10788 ui_out_text (uiout, "Masked hardware read watchpoint ");
10789 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10791 case bp_access_watchpoint:
10792 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10793 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10796 internal_error (__FILE__, __LINE__,
10797 _("Invalid hardware watchpoint type."));
10800 ui_out_field_int (uiout, "number", b->number);
10801 ui_out_text (uiout, ": ");
10802 ui_out_field_string (uiout, "exp", w->exp_string);
10803 do_cleanups (ui_out_chain);
10806 /* Implement the "print_recreate" breakpoint_ops method for
10807 masked hardware watchpoints. */
10810 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10812 struct watchpoint *w = (struct watchpoint *) b;
10817 case bp_hardware_watchpoint:
10818 fprintf_unfiltered (fp, "watch");
10820 case bp_read_watchpoint:
10821 fprintf_unfiltered (fp, "rwatch");
10823 case bp_access_watchpoint:
10824 fprintf_unfiltered (fp, "awatch");
10827 internal_error (__FILE__, __LINE__,
10828 _("Invalid hardware watchpoint type."));
10831 sprintf_vma (tmp, w->hw_wp_mask);
10832 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10833 print_recreate_thread (b, fp);
10836 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10838 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10840 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10843 is_masked_watchpoint (const struct breakpoint *b)
10845 return b->ops == &masked_watchpoint_breakpoint_ops;
10848 /* accessflag: hw_write: watch write,
10849 hw_read: watch read,
10850 hw_access: watch access (read or write) */
10852 watch_command_1 (const char *arg, int accessflag, int from_tty,
10853 int just_location, int internal)
10855 volatile struct gdb_exception e;
10856 struct breakpoint *b, *scope_breakpoint = NULL;
10857 struct expression *exp;
10858 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10859 struct value *val, *mark, *result;
10860 struct frame_info *frame;
10861 const char *exp_start = NULL;
10862 const char *exp_end = NULL;
10863 const char *tok, *end_tok;
10865 const char *cond_start = NULL;
10866 const char *cond_end = NULL;
10867 enum bptype bp_type;
10870 /* Flag to indicate whether we are going to use masks for
10871 the hardware watchpoint. */
10873 CORE_ADDR mask = 0;
10874 struct watchpoint *w;
10876 struct cleanup *back_to;
10878 /* Make sure that we actually have parameters to parse. */
10879 if (arg != NULL && arg[0] != '\0')
10881 const char *value_start;
10883 exp_end = arg + strlen (arg);
10885 /* Look for "parameter value" pairs at the end
10886 of the arguments string. */
10887 for (tok = exp_end - 1; tok > arg; tok--)
10889 /* Skip whitespace at the end of the argument list. */
10890 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10893 /* Find the beginning of the last token.
10894 This is the value of the parameter. */
10895 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10897 value_start = tok + 1;
10899 /* Skip whitespace. */
10900 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10905 /* Find the beginning of the second to last token.
10906 This is the parameter itself. */
10907 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10910 toklen = end_tok - tok + 1;
10912 if (toklen == 6 && !strncmp (tok, "thread", 6))
10914 /* At this point we've found a "thread" token, which means
10915 the user is trying to set a watchpoint that triggers
10916 only in a specific thread. */
10920 error(_("You can specify only one thread."));
10922 /* Extract the thread ID from the next token. */
10923 thread = strtol (value_start, &endp, 0);
10925 /* Check if the user provided a valid numeric value for the
10927 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10928 error (_("Invalid thread ID specification %s."), value_start);
10930 /* Check if the thread actually exists. */
10931 if (!valid_thread_id (thread))
10932 invalid_thread_id_error (thread);
10934 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10936 /* We've found a "mask" token, which means the user wants to
10937 create a hardware watchpoint that is going to have the mask
10939 struct value *mask_value, *mark;
10942 error(_("You can specify only one mask."));
10944 use_mask = just_location = 1;
10946 mark = value_mark ();
10947 mask_value = parse_to_comma_and_eval (&value_start);
10948 mask = value_as_address (mask_value);
10949 value_free_to_mark (mark);
10952 /* We didn't recognize what we found. We should stop here. */
10955 /* Truncate the string and get rid of the "parameter value" pair before
10956 the arguments string is parsed by the parse_exp_1 function. */
10963 /* Parse the rest of the arguments. From here on out, everything
10964 is in terms of a newly allocated string instead of the original
10966 innermost_block = NULL;
10967 expression = savestring (arg, exp_end - arg);
10968 back_to = make_cleanup (xfree, expression);
10969 exp_start = arg = expression;
10970 exp = parse_exp_1 (&arg, 0, 0, 0);
10972 /* Remove trailing whitespace from the expression before saving it.
10973 This makes the eventual display of the expression string a bit
10975 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10978 /* Checking if the expression is not constant. */
10979 if (watchpoint_exp_is_const (exp))
10983 len = exp_end - exp_start;
10984 while (len > 0 && isspace (exp_start[len - 1]))
10986 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10989 exp_valid_block = innermost_block;
10990 mark = value_mark ();
10991 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10997 exp_valid_block = NULL;
10998 val = value_addr (result);
10999 release_value (val);
11000 value_free_to_mark (mark);
11004 ret = target_masked_watch_num_registers (value_as_address (val),
11007 error (_("This target does not support masked watchpoints."));
11008 else if (ret == -2)
11009 error (_("Invalid mask or memory region."));
11012 else if (val != NULL)
11013 release_value (val);
11015 tok = skip_spaces_const (arg);
11016 end_tok = skip_to_space_const (tok);
11018 toklen = end_tok - tok;
11019 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11021 struct expression *cond;
11023 innermost_block = NULL;
11024 tok = cond_start = end_tok + 1;
11025 cond = parse_exp_1 (&tok, 0, 0, 0);
11027 /* The watchpoint expression may not be local, but the condition
11028 may still be. E.g.: `watch global if local > 0'. */
11029 cond_exp_valid_block = innermost_block;
11035 error (_("Junk at end of command."));
11037 if (accessflag == hw_read)
11038 bp_type = bp_read_watchpoint;
11039 else if (accessflag == hw_access)
11040 bp_type = bp_access_watchpoint;
11042 bp_type = bp_hardware_watchpoint;
11044 frame = block_innermost_frame (exp_valid_block);
11046 /* If the expression is "local", then set up a "watchpoint scope"
11047 breakpoint at the point where we've left the scope of the watchpoint
11048 expression. Create the scope breakpoint before the watchpoint, so
11049 that we will encounter it first in bpstat_stop_status. */
11050 if (exp_valid_block && frame)
11052 if (frame_id_p (frame_unwind_caller_id (frame)))
11055 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11056 frame_unwind_caller_pc (frame),
11057 bp_watchpoint_scope,
11058 &momentary_breakpoint_ops);
11060 scope_breakpoint->enable_state = bp_enabled;
11062 /* Automatically delete the breakpoint when it hits. */
11063 scope_breakpoint->disposition = disp_del;
11065 /* Only break in the proper frame (help with recursion). */
11066 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11068 /* Set the address at which we will stop. */
11069 scope_breakpoint->loc->gdbarch
11070 = frame_unwind_caller_arch (frame);
11071 scope_breakpoint->loc->requested_address
11072 = frame_unwind_caller_pc (frame);
11073 scope_breakpoint->loc->address
11074 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11075 scope_breakpoint->loc->requested_address,
11076 scope_breakpoint->type);
11080 /* Now set up the breakpoint. */
11082 w = XCNEW (struct watchpoint);
11085 init_raw_breakpoint_without_location (b, NULL, bp_type,
11086 &masked_watchpoint_breakpoint_ops);
11088 init_raw_breakpoint_without_location (b, NULL, bp_type,
11089 &watchpoint_breakpoint_ops);
11090 b->thread = thread;
11091 b->disposition = disp_donttouch;
11092 b->pspace = current_program_space;
11094 w->exp_valid_block = exp_valid_block;
11095 w->cond_exp_valid_block = cond_exp_valid_block;
11098 struct type *t = value_type (val);
11099 CORE_ADDR addr = value_as_address (val);
11102 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11103 name = type_to_string (t);
11105 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11106 core_addr_to_string (addr));
11109 w->exp_string = xstrprintf ("-location %.*s",
11110 (int) (exp_end - exp_start), exp_start);
11112 /* The above expression is in C. */
11113 b->language = language_c;
11116 w->exp_string = savestring (exp_start, exp_end - exp_start);
11120 w->hw_wp_mask = mask;
11129 b->cond_string = savestring (cond_start, cond_end - cond_start);
11131 b->cond_string = 0;
11135 w->watchpoint_frame = get_frame_id (frame);
11136 w->watchpoint_thread = inferior_ptid;
11140 w->watchpoint_frame = null_frame_id;
11141 w->watchpoint_thread = null_ptid;
11144 if (scope_breakpoint != NULL)
11146 /* The scope breakpoint is related to the watchpoint. We will
11147 need to act on them together. */
11148 b->related_breakpoint = scope_breakpoint;
11149 scope_breakpoint->related_breakpoint = b;
11152 if (!just_location)
11153 value_free_to_mark (mark);
11155 TRY_CATCH (e, RETURN_MASK_ALL)
11157 /* Finally update the new watchpoint. This creates the locations
11158 that should be inserted. */
11159 update_watchpoint (w, 1);
11163 delete_breakpoint (b);
11164 throw_exception (e);
11167 install_breakpoint (internal, b, 1);
11168 do_cleanups (back_to);
11171 /* Return count of debug registers needed to watch the given expression.
11172 If the watchpoint cannot be handled in hardware return zero. */
11175 can_use_hardware_watchpoint (struct value *v)
11177 int found_memory_cnt = 0;
11178 struct value *head = v;
11180 /* Did the user specifically forbid us to use hardware watchpoints? */
11181 if (!can_use_hw_watchpoints)
11184 /* Make sure that the value of the expression depends only upon
11185 memory contents, and values computed from them within GDB. If we
11186 find any register references or function calls, we can't use a
11187 hardware watchpoint.
11189 The idea here is that evaluating an expression generates a series
11190 of values, one holding the value of every subexpression. (The
11191 expression a*b+c has five subexpressions: a, b, a*b, c, and
11192 a*b+c.) GDB's values hold almost enough information to establish
11193 the criteria given above --- they identify memory lvalues,
11194 register lvalues, computed values, etcetera. So we can evaluate
11195 the expression, and then scan the chain of values that leaves
11196 behind to decide whether we can detect any possible change to the
11197 expression's final value using only hardware watchpoints.
11199 However, I don't think that the values returned by inferior
11200 function calls are special in any way. So this function may not
11201 notice that an expression involving an inferior function call
11202 can't be watched with hardware watchpoints. FIXME. */
11203 for (; v; v = value_next (v))
11205 if (VALUE_LVAL (v) == lval_memory)
11207 if (v != head && value_lazy (v))
11208 /* A lazy memory lvalue in the chain is one that GDB never
11209 needed to fetch; we either just used its address (e.g.,
11210 `a' in `a.b') or we never needed it at all (e.g., `a'
11211 in `a,b'). This doesn't apply to HEAD; if that is
11212 lazy then it was not readable, but watch it anyway. */
11216 /* Ahh, memory we actually used! Check if we can cover
11217 it with hardware watchpoints. */
11218 struct type *vtype = check_typedef (value_type (v));
11220 /* We only watch structs and arrays if user asked for it
11221 explicitly, never if they just happen to appear in a
11222 middle of some value chain. */
11224 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11225 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11227 CORE_ADDR vaddr = value_address (v);
11231 len = (target_exact_watchpoints
11232 && is_scalar_type_recursive (vtype))?
11233 1 : TYPE_LENGTH (value_type (v));
11235 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11239 found_memory_cnt += num_regs;
11243 else if (VALUE_LVAL (v) != not_lval
11244 && deprecated_value_modifiable (v) == 0)
11245 return 0; /* These are values from the history (e.g., $1). */
11246 else if (VALUE_LVAL (v) == lval_register)
11247 return 0; /* Cannot watch a register with a HW watchpoint. */
11250 /* The expression itself looks suitable for using a hardware
11251 watchpoint, but give the target machine a chance to reject it. */
11252 return found_memory_cnt;
11256 watch_command_wrapper (char *arg, int from_tty, int internal)
11258 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11261 /* A helper function that looks for the "-location" argument and then
11262 calls watch_command_1. */
11265 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11267 int just_location = 0;
11270 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11271 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11273 arg = skip_spaces (arg);
11277 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11281 watch_command (char *arg, int from_tty)
11283 watch_maybe_just_location (arg, hw_write, from_tty);
11287 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11289 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11293 rwatch_command (char *arg, int from_tty)
11295 watch_maybe_just_location (arg, hw_read, from_tty);
11299 awatch_command_wrapper (char *arg, int from_tty, int internal)
11301 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11305 awatch_command (char *arg, int from_tty)
11307 watch_maybe_just_location (arg, hw_access, from_tty);
11311 /* Helper routines for the until_command routine in infcmd.c. Here
11312 because it uses the mechanisms of breakpoints. */
11314 struct until_break_command_continuation_args
11316 struct breakpoint *breakpoint;
11317 struct breakpoint *breakpoint2;
11321 /* This function is called by fetch_inferior_event via the
11322 cmd_continuation pointer, to complete the until command. It takes
11323 care of cleaning up the temporary breakpoints set up by the until
11326 until_break_command_continuation (void *arg, int err)
11328 struct until_break_command_continuation_args *a = arg;
11330 delete_breakpoint (a->breakpoint);
11331 if (a->breakpoint2)
11332 delete_breakpoint (a->breakpoint2);
11333 delete_longjmp_breakpoint (a->thread_num);
11337 until_break_command (char *arg, int from_tty, int anywhere)
11339 struct symtabs_and_lines sals;
11340 struct symtab_and_line sal;
11341 struct frame_info *frame;
11342 struct gdbarch *frame_gdbarch;
11343 struct frame_id stack_frame_id;
11344 struct frame_id caller_frame_id;
11345 struct breakpoint *breakpoint;
11346 struct breakpoint *breakpoint2 = NULL;
11347 struct cleanup *old_chain;
11349 struct thread_info *tp;
11351 clear_proceed_status ();
11353 /* Set a breakpoint where the user wants it and at return from
11356 if (last_displayed_sal_is_valid ())
11357 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11358 get_last_displayed_symtab (),
11359 get_last_displayed_line ());
11361 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11362 (struct symtab *) NULL, 0);
11364 if (sals.nelts != 1)
11365 error (_("Couldn't get information on specified line."));
11367 sal = sals.sals[0];
11368 xfree (sals.sals); /* malloc'd, so freed. */
11371 error (_("Junk at end of arguments."));
11373 resolve_sal_pc (&sal);
11375 tp = inferior_thread ();
11378 old_chain = make_cleanup (null_cleanup, NULL);
11380 /* Note linespec handling above invalidates the frame chain.
11381 Installing a breakpoint also invalidates the frame chain (as it
11382 may need to switch threads), so do any frame handling before
11385 frame = get_selected_frame (NULL);
11386 frame_gdbarch = get_frame_arch (frame);
11387 stack_frame_id = get_stack_frame_id (frame);
11388 caller_frame_id = frame_unwind_caller_id (frame);
11390 /* Keep within the current frame, or in frames called by the current
11393 if (frame_id_p (caller_frame_id))
11395 struct symtab_and_line sal2;
11397 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11398 sal2.pc = frame_unwind_caller_pc (frame);
11399 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11403 make_cleanup_delete_breakpoint (breakpoint2);
11405 set_longjmp_breakpoint (tp, caller_frame_id);
11406 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11409 /* set_momentary_breakpoint could invalidate FRAME. */
11413 /* If the user told us to continue until a specified location,
11414 we don't specify a frame at which we need to stop. */
11415 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11416 null_frame_id, bp_until);
11418 /* Otherwise, specify the selected frame, because we want to stop
11419 only at the very same frame. */
11420 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11421 stack_frame_id, bp_until);
11422 make_cleanup_delete_breakpoint (breakpoint);
11424 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11426 /* If we are running asynchronously, and proceed call above has
11427 actually managed to start the target, arrange for breakpoints to
11428 be deleted when the target stops. Otherwise, we're already
11429 stopped and delete breakpoints via cleanup chain. */
11431 if (target_can_async_p () && is_running (inferior_ptid))
11433 struct until_break_command_continuation_args *args;
11434 args = xmalloc (sizeof (*args));
11436 args->breakpoint = breakpoint;
11437 args->breakpoint2 = breakpoint2;
11438 args->thread_num = thread;
11440 discard_cleanups (old_chain);
11441 add_continuation (inferior_thread (),
11442 until_break_command_continuation, args,
11446 do_cleanups (old_chain);
11449 /* This function attempts to parse an optional "if <cond>" clause
11450 from the arg string. If one is not found, it returns NULL.
11452 Else, it returns a pointer to the condition string. (It does not
11453 attempt to evaluate the string against a particular block.) And,
11454 it updates arg to point to the first character following the parsed
11455 if clause in the arg string. */
11458 ep_parse_optional_if_clause (char **arg)
11462 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11465 /* Skip the "if" keyword. */
11468 /* Skip any extra leading whitespace, and record the start of the
11469 condition string. */
11470 *arg = skip_spaces (*arg);
11471 cond_string = *arg;
11473 /* Assume that the condition occupies the remainder of the arg
11475 (*arg) += strlen (cond_string);
11477 return cond_string;
11480 /* Commands to deal with catching events, such as signals, exceptions,
11481 process start/exit, etc. */
11485 catch_fork_temporary, catch_vfork_temporary,
11486 catch_fork_permanent, catch_vfork_permanent
11491 catch_fork_command_1 (char *arg, int from_tty,
11492 struct cmd_list_element *command)
11494 struct gdbarch *gdbarch = get_current_arch ();
11495 char *cond_string = NULL;
11496 catch_fork_kind fork_kind;
11499 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11500 tempflag = (fork_kind == catch_fork_temporary
11501 || fork_kind == catch_vfork_temporary);
11505 arg = skip_spaces (arg);
11507 /* The allowed syntax is:
11509 catch [v]fork if <cond>
11511 First, check if there's an if clause. */
11512 cond_string = ep_parse_optional_if_clause (&arg);
11514 if ((*arg != '\0') && !isspace (*arg))
11515 error (_("Junk at end of arguments."));
11517 /* If this target supports it, create a fork or vfork catchpoint
11518 and enable reporting of such events. */
11521 case catch_fork_temporary:
11522 case catch_fork_permanent:
11523 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11524 &catch_fork_breakpoint_ops);
11526 case catch_vfork_temporary:
11527 case catch_vfork_permanent:
11528 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11529 &catch_vfork_breakpoint_ops);
11532 error (_("unsupported or unknown fork kind; cannot catch it"));
11538 catch_exec_command_1 (char *arg, int from_tty,
11539 struct cmd_list_element *command)
11541 struct exec_catchpoint *c;
11542 struct gdbarch *gdbarch = get_current_arch ();
11544 char *cond_string = NULL;
11546 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11550 arg = skip_spaces (arg);
11552 /* The allowed syntax is:
11554 catch exec if <cond>
11556 First, check if there's an if clause. */
11557 cond_string = ep_parse_optional_if_clause (&arg);
11559 if ((*arg != '\0') && !isspace (*arg))
11560 error (_("Junk at end of arguments."));
11562 c = XNEW (struct exec_catchpoint);
11563 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11564 &catch_exec_breakpoint_ops);
11565 c->exec_pathname = NULL;
11567 install_breakpoint (0, &c->base, 1);
11570 static enum print_stop_action
11571 print_it_exception_catchpoint (bpstat bs)
11573 struct ui_out *uiout = current_uiout;
11574 struct breakpoint *b = bs->breakpoint_at;
11575 int bp_temp, bp_throw;
11577 annotate_catchpoint (b->number);
11579 bp_throw = strstr (b->addr_string, "throw") != NULL;
11580 if (b->loc->address != b->loc->requested_address)
11581 breakpoint_adjustment_warning (b->loc->requested_address,
11584 bp_temp = b->disposition == disp_del;
11585 ui_out_text (uiout,
11586 bp_temp ? "Temporary catchpoint "
11588 if (!ui_out_is_mi_like_p (uiout))
11589 ui_out_field_int (uiout, "bkptno", b->number);
11590 ui_out_text (uiout,
11591 bp_throw ? " (exception thrown), "
11592 : " (exception caught), ");
11593 if (ui_out_is_mi_like_p (uiout))
11595 ui_out_field_string (uiout, "reason",
11596 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11597 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11598 ui_out_field_int (uiout, "bkptno", b->number);
11600 return PRINT_SRC_AND_LOC;
11604 print_one_exception_catchpoint (struct breakpoint *b,
11605 struct bp_location **last_loc)
11607 struct value_print_options opts;
11608 struct ui_out *uiout = current_uiout;
11610 get_user_print_options (&opts);
11611 if (opts.addressprint)
11613 annotate_field (4);
11614 if (b->loc == NULL || b->loc->shlib_disabled)
11615 ui_out_field_string (uiout, "addr", "<PENDING>");
11617 ui_out_field_core_addr (uiout, "addr",
11618 b->loc->gdbarch, b->loc->address);
11620 annotate_field (5);
11622 *last_loc = b->loc;
11623 if (strstr (b->addr_string, "throw") != NULL)
11625 ui_out_field_string (uiout, "what", "exception throw");
11626 if (ui_out_is_mi_like_p (uiout))
11627 ui_out_field_string (uiout, "catch-type", "throw");
11631 ui_out_field_string (uiout, "what", "exception catch");
11632 if (ui_out_is_mi_like_p (uiout))
11633 ui_out_field_string (uiout, "catch-type", "catch");
11638 print_mention_exception_catchpoint (struct breakpoint *b)
11640 struct ui_out *uiout = current_uiout;
11644 bp_temp = b->disposition == disp_del;
11645 bp_throw = strstr (b->addr_string, "throw") != NULL;
11646 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11647 : _("Catchpoint "));
11648 ui_out_field_int (uiout, "bkptno", b->number);
11649 ui_out_text (uiout, bp_throw ? _(" (throw)")
11653 /* Implement the "print_recreate" breakpoint_ops method for throw and
11654 catch catchpoints. */
11657 print_recreate_exception_catchpoint (struct breakpoint *b,
11658 struct ui_file *fp)
11663 bp_temp = b->disposition == disp_del;
11664 bp_throw = strstr (b->addr_string, "throw") != NULL;
11665 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11666 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11667 print_recreate_thread (b, fp);
11670 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11673 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11674 enum exception_event_kind ex_event, int from_tty)
11676 char *trigger_func_name;
11678 if (ex_event == EX_EVENT_CATCH)
11679 trigger_func_name = "__cxa_begin_catch";
11681 trigger_func_name = "__cxa_throw";
11683 create_breakpoint (get_current_arch (),
11684 trigger_func_name, cond_string, -1, NULL,
11685 0 /* condition and thread are valid. */,
11686 tempflag, bp_breakpoint,
11688 AUTO_BOOLEAN_TRUE /* pending */,
11689 &gnu_v3_exception_catchpoint_ops, from_tty,
11697 /* Deal with "catch catch" and "catch throw" commands. */
11700 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11701 int tempflag, int from_tty)
11703 char *cond_string = NULL;
11707 arg = skip_spaces (arg);
11709 cond_string = ep_parse_optional_if_clause (&arg);
11711 if ((*arg != '\0') && !isspace (*arg))
11712 error (_("Junk at end of arguments."));
11714 if (ex_event != EX_EVENT_THROW
11715 && ex_event != EX_EVENT_CATCH)
11716 error (_("Unsupported or unknown exception event; cannot catch it"));
11718 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11721 warning (_("Unsupported with this platform/compiler combination."));
11724 /* Implementation of "catch catch" command. */
11727 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11729 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11731 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11734 /* Implementation of "catch throw" command. */
11737 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11739 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11741 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11745 init_ada_exception_breakpoint (struct breakpoint *b,
11746 struct gdbarch *gdbarch,
11747 struct symtab_and_line sal,
11749 const struct breakpoint_ops *ops,
11755 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11757 loc_gdbarch = gdbarch;
11759 describe_other_breakpoints (loc_gdbarch,
11760 sal.pspace, sal.pc, sal.section, -1);
11761 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11762 version for exception catchpoints, because two catchpoints
11763 used for different exception names will use the same address.
11764 In this case, a "breakpoint ... also set at..." warning is
11765 unproductive. Besides, the warning phrasing is also a bit
11766 inappropriate, we should use the word catchpoint, and tell
11767 the user what type of catchpoint it is. The above is good
11768 enough for now, though. */
11771 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11773 b->enable_state = bp_enabled;
11774 b->disposition = tempflag ? disp_del : disp_donttouch;
11775 b->addr_string = addr_string;
11776 b->language = language_ada;
11779 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11780 filter list, or NULL if no filtering is required. */
11782 catch_syscall_split_args (char *arg)
11784 VEC(int) *result = NULL;
11785 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11787 while (*arg != '\0')
11789 int i, syscall_number;
11791 char cur_name[128];
11794 /* Skip whitespace. */
11795 arg = skip_spaces (arg);
11797 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11798 cur_name[i] = arg[i];
11799 cur_name[i] = '\0';
11802 /* Check if the user provided a syscall name or a number. */
11803 syscall_number = (int) strtol (cur_name, &endptr, 0);
11804 if (*endptr == '\0')
11805 get_syscall_by_number (syscall_number, &s);
11808 /* We have a name. Let's check if it's valid and convert it
11810 get_syscall_by_name (cur_name, &s);
11812 if (s.number == UNKNOWN_SYSCALL)
11813 /* Here we have to issue an error instead of a warning,
11814 because GDB cannot do anything useful if there's no
11815 syscall number to be caught. */
11816 error (_("Unknown syscall name '%s'."), cur_name);
11819 /* Ok, it's valid. */
11820 VEC_safe_push (int, result, s.number);
11823 discard_cleanups (cleanup);
11827 /* Implement the "catch syscall" command. */
11830 catch_syscall_command_1 (char *arg, int from_tty,
11831 struct cmd_list_element *command)
11836 struct gdbarch *gdbarch = get_current_arch ();
11838 /* Checking if the feature if supported. */
11839 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11840 error (_("The feature 'catch syscall' is not supported on \
11841 this architecture yet."));
11843 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11845 arg = skip_spaces (arg);
11847 /* We need to do this first "dummy" translation in order
11848 to get the syscall XML file loaded or, most important,
11849 to display a warning to the user if there's no XML file
11850 for his/her architecture. */
11851 get_syscall_by_number (0, &s);
11853 /* The allowed syntax is:
11855 catch syscall <name | number> [<name | number> ... <name | number>]
11857 Let's check if there's a syscall name. */
11860 filter = catch_syscall_split_args (arg);
11864 create_syscall_event_catchpoint (tempflag, filter,
11865 &catch_syscall_breakpoint_ops);
11869 catch_command (char *arg, int from_tty)
11871 error (_("Catch requires an event name."));
11876 tcatch_command (char *arg, int from_tty)
11878 error (_("Catch requires an event name."));
11881 /* A qsort comparison function that sorts breakpoints in order. */
11884 compare_breakpoints (const void *a, const void *b)
11886 const breakpoint_p *ba = a;
11887 uintptr_t ua = (uintptr_t) *ba;
11888 const breakpoint_p *bb = b;
11889 uintptr_t ub = (uintptr_t) *bb;
11891 if ((*ba)->number < (*bb)->number)
11893 else if ((*ba)->number > (*bb)->number)
11896 /* Now sort by address, in case we see, e..g, two breakpoints with
11900 return ua > ub ? 1 : 0;
11903 /* Delete breakpoints by address or line. */
11906 clear_command (char *arg, int from_tty)
11908 struct breakpoint *b, *prev;
11909 VEC(breakpoint_p) *found = 0;
11912 struct symtabs_and_lines sals;
11913 struct symtab_and_line sal;
11915 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11919 sals = decode_line_with_current_source (arg,
11920 (DECODE_LINE_FUNFIRSTLINE
11921 | DECODE_LINE_LIST_MODE));
11922 make_cleanup (xfree, sals.sals);
11927 sals.sals = (struct symtab_and_line *)
11928 xmalloc (sizeof (struct symtab_and_line));
11929 make_cleanup (xfree, sals.sals);
11930 init_sal (&sal); /* Initialize to zeroes. */
11932 /* Set sal's line, symtab, pc, and pspace to the values
11933 corresponding to the last call to print_frame_info. If the
11934 codepoint is not valid, this will set all the fields to 0. */
11935 get_last_displayed_sal (&sal);
11936 if (sal.symtab == 0)
11937 error (_("No source file specified."));
11939 sals.sals[0] = sal;
11945 /* We don't call resolve_sal_pc here. That's not as bad as it
11946 seems, because all existing breakpoints typically have both
11947 file/line and pc set. So, if clear is given file/line, we can
11948 match this to existing breakpoint without obtaining pc at all.
11950 We only support clearing given the address explicitly
11951 present in breakpoint table. Say, we've set breakpoint
11952 at file:line. There were several PC values for that file:line,
11953 due to optimization, all in one block.
11955 We've picked one PC value. If "clear" is issued with another
11956 PC corresponding to the same file:line, the breakpoint won't
11957 be cleared. We probably can still clear the breakpoint, but
11958 since the other PC value is never presented to user, user
11959 can only find it by guessing, and it does not seem important
11960 to support that. */
11962 /* For each line spec given, delete bps which correspond to it. Do
11963 it in two passes, solely to preserve the current behavior that
11964 from_tty is forced true if we delete more than one
11968 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11969 for (i = 0; i < sals.nelts; i++)
11971 const char *sal_fullname;
11973 /* If exact pc given, clear bpts at that pc.
11974 If line given (pc == 0), clear all bpts on specified line.
11975 If defaulting, clear all bpts on default line
11978 defaulting sal.pc != 0 tests to do
11983 1 0 <can't happen> */
11985 sal = sals.sals[i];
11986 sal_fullname = (sal.symtab == NULL
11987 ? NULL : symtab_to_fullname (sal.symtab));
11989 /* Find all matching breakpoints and add them to 'found'. */
11990 ALL_BREAKPOINTS (b)
11993 /* Are we going to delete b? */
11994 if (b->type != bp_none && !is_watchpoint (b))
11996 struct bp_location *loc = b->loc;
11997 for (; loc; loc = loc->next)
11999 /* If the user specified file:line, don't allow a PC
12000 match. This matches historical gdb behavior. */
12001 int pc_match = (!sal.explicit_line
12003 && (loc->pspace == sal.pspace)
12004 && (loc->address == sal.pc)
12005 && (!section_is_overlay (loc->section)
12006 || loc->section == sal.section));
12007 int line_match = 0;
12009 if ((default_match || sal.explicit_line)
12010 && loc->symtab != NULL
12011 && sal_fullname != NULL
12012 && sal.pspace == loc->pspace
12013 && loc->line_number == sal.line
12014 && filename_cmp (symtab_to_fullname (loc->symtab),
12015 sal_fullname) == 0)
12018 if (pc_match || line_match)
12027 VEC_safe_push(breakpoint_p, found, b);
12031 /* Now go thru the 'found' chain and delete them. */
12032 if (VEC_empty(breakpoint_p, found))
12035 error (_("No breakpoint at %s."), arg);
12037 error (_("No breakpoint at this line."));
12040 /* Remove duplicates from the vec. */
12041 qsort (VEC_address (breakpoint_p, found),
12042 VEC_length (breakpoint_p, found),
12043 sizeof (breakpoint_p),
12044 compare_breakpoints);
12045 prev = VEC_index (breakpoint_p, found, 0);
12046 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12050 VEC_ordered_remove (breakpoint_p, found, ix);
12055 if (VEC_length(breakpoint_p, found) > 1)
12056 from_tty = 1; /* Always report if deleted more than one. */
12059 if (VEC_length(breakpoint_p, found) == 1)
12060 printf_unfiltered (_("Deleted breakpoint "));
12062 printf_unfiltered (_("Deleted breakpoints "));
12065 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12068 printf_unfiltered ("%d ", b->number);
12069 delete_breakpoint (b);
12072 putchar_unfiltered ('\n');
12074 do_cleanups (cleanups);
12077 /* Delete breakpoint in BS if they are `delete' breakpoints and
12078 all breakpoints that are marked for deletion, whether hit or not.
12079 This is called after any breakpoint is hit, or after errors. */
12082 breakpoint_auto_delete (bpstat bs)
12084 struct breakpoint *b, *b_tmp;
12086 for (; bs; bs = bs->next)
12087 if (bs->breakpoint_at
12088 && bs->breakpoint_at->disposition == disp_del
12090 delete_breakpoint (bs->breakpoint_at);
12092 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12094 if (b->disposition == disp_del_at_next_stop)
12095 delete_breakpoint (b);
12099 /* A comparison function for bp_location AP and BP being interfaced to
12100 qsort. Sort elements primarily by their ADDRESS (no matter what
12101 does breakpoint_address_is_meaningful say for its OWNER),
12102 secondarily by ordering first bp_permanent OWNERed elements and
12103 terciarily just ensuring the array is sorted stable way despite
12104 qsort being an unstable algorithm. */
12107 bp_location_compare (const void *ap, const void *bp)
12109 struct bp_location *a = *(void **) ap;
12110 struct bp_location *b = *(void **) bp;
12111 /* A and B come from existing breakpoints having non-NULL OWNER. */
12112 int a_perm = a->owner->enable_state == bp_permanent;
12113 int b_perm = b->owner->enable_state == bp_permanent;
12115 if (a->address != b->address)
12116 return (a->address > b->address) - (a->address < b->address);
12118 /* Sort locations at the same address by their pspace number, keeping
12119 locations of the same inferior (in a multi-inferior environment)
12122 if (a->pspace->num != b->pspace->num)
12123 return ((a->pspace->num > b->pspace->num)
12124 - (a->pspace->num < b->pspace->num));
12126 /* Sort permanent breakpoints first. */
12127 if (a_perm != b_perm)
12128 return (a_perm < b_perm) - (a_perm > b_perm);
12130 /* Make the internal GDB representation stable across GDB runs
12131 where A and B memory inside GDB can differ. Breakpoint locations of
12132 the same type at the same address can be sorted in arbitrary order. */
12134 if (a->owner->number != b->owner->number)
12135 return ((a->owner->number > b->owner->number)
12136 - (a->owner->number < b->owner->number));
12138 return (a > b) - (a < b);
12141 /* Set bp_location_placed_address_before_address_max and
12142 bp_location_shadow_len_after_address_max according to the current
12143 content of the bp_location array. */
12146 bp_location_target_extensions_update (void)
12148 struct bp_location *bl, **blp_tmp;
12150 bp_location_placed_address_before_address_max = 0;
12151 bp_location_shadow_len_after_address_max = 0;
12153 ALL_BP_LOCATIONS (bl, blp_tmp)
12155 CORE_ADDR start, end, addr;
12157 if (!bp_location_has_shadow (bl))
12160 start = bl->target_info.placed_address;
12161 end = start + bl->target_info.shadow_len;
12163 gdb_assert (bl->address >= start);
12164 addr = bl->address - start;
12165 if (addr > bp_location_placed_address_before_address_max)
12166 bp_location_placed_address_before_address_max = addr;
12168 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12170 gdb_assert (bl->address < end);
12171 addr = end - bl->address;
12172 if (addr > bp_location_shadow_len_after_address_max)
12173 bp_location_shadow_len_after_address_max = addr;
12177 /* Download tracepoint locations if they haven't been. */
12180 download_tracepoint_locations (void)
12182 struct breakpoint *b;
12183 struct cleanup *old_chain;
12185 if (!target_can_download_tracepoint ())
12188 old_chain = save_current_space_and_thread ();
12190 ALL_TRACEPOINTS (b)
12192 struct bp_location *bl;
12193 struct tracepoint *t;
12194 int bp_location_downloaded = 0;
12196 if ((b->type == bp_fast_tracepoint
12197 ? !may_insert_fast_tracepoints
12198 : !may_insert_tracepoints))
12201 for (bl = b->loc; bl; bl = bl->next)
12203 /* In tracepoint, locations are _never_ duplicated, so
12204 should_be_inserted is equivalent to
12205 unduplicated_should_be_inserted. */
12206 if (!should_be_inserted (bl) || bl->inserted)
12209 switch_to_program_space_and_thread (bl->pspace);
12211 target_download_tracepoint (bl);
12214 bp_location_downloaded = 1;
12216 t = (struct tracepoint *) b;
12217 t->number_on_target = b->number;
12218 if (bp_location_downloaded)
12219 observer_notify_breakpoint_modified (b);
12222 do_cleanups (old_chain);
12225 /* Swap the insertion/duplication state between two locations. */
12228 swap_insertion (struct bp_location *left, struct bp_location *right)
12230 const int left_inserted = left->inserted;
12231 const int left_duplicate = left->duplicate;
12232 const int left_needs_update = left->needs_update;
12233 const struct bp_target_info left_target_info = left->target_info;
12235 /* Locations of tracepoints can never be duplicated. */
12236 if (is_tracepoint (left->owner))
12237 gdb_assert (!left->duplicate);
12238 if (is_tracepoint (right->owner))
12239 gdb_assert (!right->duplicate);
12241 left->inserted = right->inserted;
12242 left->duplicate = right->duplicate;
12243 left->needs_update = right->needs_update;
12244 left->target_info = right->target_info;
12245 right->inserted = left_inserted;
12246 right->duplicate = left_duplicate;
12247 right->needs_update = left_needs_update;
12248 right->target_info = left_target_info;
12251 /* Force the re-insertion of the locations at ADDRESS. This is called
12252 once a new/deleted/modified duplicate location is found and we are evaluating
12253 conditions on the target's side. Such conditions need to be updated on
12257 force_breakpoint_reinsertion (struct bp_location *bl)
12259 struct bp_location **locp = NULL, **loc2p;
12260 struct bp_location *loc;
12261 CORE_ADDR address = 0;
12264 address = bl->address;
12265 pspace_num = bl->pspace->num;
12267 /* This is only meaningful if the target is
12268 evaluating conditions and if the user has
12269 opted for condition evaluation on the target's
12271 if (gdb_evaluates_breakpoint_condition_p ()
12272 || !target_supports_evaluation_of_breakpoint_conditions ())
12275 /* Flag all breakpoint locations with this address and
12276 the same program space as the location
12277 as "its condition has changed". We need to
12278 update the conditions on the target's side. */
12279 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12283 if (!is_breakpoint (loc->owner)
12284 || pspace_num != loc->pspace->num)
12287 /* Flag the location appropriately. We use a different state to
12288 let everyone know that we already updated the set of locations
12289 with addr bl->address and program space bl->pspace. This is so
12290 we don't have to keep calling these functions just to mark locations
12291 that have already been marked. */
12292 loc->condition_changed = condition_updated;
12294 /* Free the agent expression bytecode as well. We will compute
12296 if (loc->cond_bytecode)
12298 free_agent_expr (loc->cond_bytecode);
12299 loc->cond_bytecode = NULL;
12304 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12305 into the inferior, only remove already-inserted locations that no
12306 longer should be inserted. Functions that delete a breakpoint or
12307 breakpoints should pass false, so that deleting a breakpoint
12308 doesn't have the side effect of inserting the locations of other
12309 breakpoints that are marked not-inserted, but should_be_inserted
12310 returns true on them.
12312 This behaviour is useful is situations close to tear-down -- e.g.,
12313 after an exec, while the target still has execution, but breakpoint
12314 shadows of the previous executable image should *NOT* be restored
12315 to the new image; or before detaching, where the target still has
12316 execution and wants to delete breakpoints from GDB's lists, and all
12317 breakpoints had already been removed from the inferior. */
12320 update_global_location_list (int should_insert)
12322 struct breakpoint *b;
12323 struct bp_location **locp, *loc;
12324 struct cleanup *cleanups;
12325 /* Last breakpoint location address that was marked for update. */
12326 CORE_ADDR last_addr = 0;
12327 /* Last breakpoint location program space that was marked for update. */
12328 int last_pspace_num = -1;
12330 /* Used in the duplicates detection below. When iterating over all
12331 bp_locations, points to the first bp_location of a given address.
12332 Breakpoints and watchpoints of different types are never
12333 duplicates of each other. Keep one pointer for each type of
12334 breakpoint/watchpoint, so we only need to loop over all locations
12336 struct bp_location *bp_loc_first; /* breakpoint */
12337 struct bp_location *wp_loc_first; /* hardware watchpoint */
12338 struct bp_location *awp_loc_first; /* access watchpoint */
12339 struct bp_location *rwp_loc_first; /* read watchpoint */
12341 /* Saved former bp_location array which we compare against the newly
12342 built bp_location from the current state of ALL_BREAKPOINTS. */
12343 struct bp_location **old_location, **old_locp;
12344 unsigned old_location_count;
12346 old_location = bp_location;
12347 old_location_count = bp_location_count;
12348 bp_location = NULL;
12349 bp_location_count = 0;
12350 cleanups = make_cleanup (xfree, old_location);
12352 ALL_BREAKPOINTS (b)
12353 for (loc = b->loc; loc; loc = loc->next)
12354 bp_location_count++;
12356 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12357 locp = bp_location;
12358 ALL_BREAKPOINTS (b)
12359 for (loc = b->loc; loc; loc = loc->next)
12361 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12362 bp_location_compare);
12364 bp_location_target_extensions_update ();
12366 /* Identify bp_location instances that are no longer present in the
12367 new list, and therefore should be freed. Note that it's not
12368 necessary that those locations should be removed from inferior --
12369 if there's another location at the same address (previously
12370 marked as duplicate), we don't need to remove/insert the
12373 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12374 and former bp_location array state respectively. */
12376 locp = bp_location;
12377 for (old_locp = old_location; old_locp < old_location + old_location_count;
12380 struct bp_location *old_loc = *old_locp;
12381 struct bp_location **loc2p;
12383 /* Tells if 'old_loc' is found among the new locations. If
12384 not, we have to free it. */
12385 int found_object = 0;
12386 /* Tells if the location should remain inserted in the target. */
12387 int keep_in_target = 0;
12390 /* Skip LOCP entries which will definitely never be needed.
12391 Stop either at or being the one matching OLD_LOC. */
12392 while (locp < bp_location + bp_location_count
12393 && (*locp)->address < old_loc->address)
12397 (loc2p < bp_location + bp_location_count
12398 && (*loc2p)->address == old_loc->address);
12401 /* Check if this is a new/duplicated location or a duplicated
12402 location that had its condition modified. If so, we want to send
12403 its condition to the target if evaluation of conditions is taking
12405 if ((*loc2p)->condition_changed == condition_modified
12406 && (last_addr != old_loc->address
12407 || last_pspace_num != old_loc->pspace->num))
12409 force_breakpoint_reinsertion (*loc2p);
12410 last_pspace_num = old_loc->pspace->num;
12413 if (*loc2p == old_loc)
12417 /* We have already handled this address, update it so that we don't
12418 have to go through updates again. */
12419 last_addr = old_loc->address;
12421 /* Target-side condition evaluation: Handle deleted locations. */
12423 force_breakpoint_reinsertion (old_loc);
12425 /* If this location is no longer present, and inserted, look if
12426 there's maybe a new location at the same address. If so,
12427 mark that one inserted, and don't remove this one. This is
12428 needed so that we don't have a time window where a breakpoint
12429 at certain location is not inserted. */
12431 if (old_loc->inserted)
12433 /* If the location is inserted now, we might have to remove
12436 if (found_object && should_be_inserted (old_loc))
12438 /* The location is still present in the location list,
12439 and still should be inserted. Don't do anything. */
12440 keep_in_target = 1;
12444 /* This location still exists, but it won't be kept in the
12445 target since it may have been disabled. We proceed to
12446 remove its target-side condition. */
12448 /* The location is either no longer present, or got
12449 disabled. See if there's another location at the
12450 same address, in which case we don't need to remove
12451 this one from the target. */
12453 /* OLD_LOC comes from existing struct breakpoint. */
12454 if (breakpoint_address_is_meaningful (old_loc->owner))
12457 (loc2p < bp_location + bp_location_count
12458 && (*loc2p)->address == old_loc->address);
12461 struct bp_location *loc2 = *loc2p;
12463 if (breakpoint_locations_match (loc2, old_loc))
12465 /* Read watchpoint locations are switched to
12466 access watchpoints, if the former are not
12467 supported, but the latter are. */
12468 if (is_hardware_watchpoint (old_loc->owner))
12470 gdb_assert (is_hardware_watchpoint (loc2->owner));
12471 loc2->watchpoint_type = old_loc->watchpoint_type;
12474 /* loc2 is a duplicated location. We need to check
12475 if it should be inserted in case it will be
12477 if (loc2 != old_loc
12478 && unduplicated_should_be_inserted (loc2))
12480 swap_insertion (old_loc, loc2);
12481 keep_in_target = 1;
12489 if (!keep_in_target)
12491 if (remove_breakpoint (old_loc, mark_uninserted))
12493 /* This is just about all we can do. We could keep
12494 this location on the global list, and try to
12495 remove it next time, but there's no particular
12496 reason why we will succeed next time.
12498 Note that at this point, old_loc->owner is still
12499 valid, as delete_breakpoint frees the breakpoint
12500 only after calling us. */
12501 printf_filtered (_("warning: Error removing "
12502 "breakpoint %d\n"),
12503 old_loc->owner->number);
12511 if (removed && non_stop
12512 && breakpoint_address_is_meaningful (old_loc->owner)
12513 && !is_hardware_watchpoint (old_loc->owner))
12515 /* This location was removed from the target. In
12516 non-stop mode, a race condition is possible where
12517 we've removed a breakpoint, but stop events for that
12518 breakpoint are already queued and will arrive later.
12519 We apply an heuristic to be able to distinguish such
12520 SIGTRAPs from other random SIGTRAPs: we keep this
12521 breakpoint location for a bit, and will retire it
12522 after we see some number of events. The theory here
12523 is that reporting of events should, "on the average",
12524 be fair, so after a while we'll see events from all
12525 threads that have anything of interest, and no longer
12526 need to keep this breakpoint location around. We
12527 don't hold locations forever so to reduce chances of
12528 mistaking a non-breakpoint SIGTRAP for a breakpoint
12531 The heuristic failing can be disastrous on
12532 decr_pc_after_break targets.
12534 On decr_pc_after_break targets, like e.g., x86-linux,
12535 if we fail to recognize a late breakpoint SIGTRAP,
12536 because events_till_retirement has reached 0 too
12537 soon, we'll fail to do the PC adjustment, and report
12538 a random SIGTRAP to the user. When the user resumes
12539 the inferior, it will most likely immediately crash
12540 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12541 corrupted, because of being resumed e.g., in the
12542 middle of a multi-byte instruction, or skipped a
12543 one-byte instruction. This was actually seen happen
12544 on native x86-linux, and should be less rare on
12545 targets that do not support new thread events, like
12546 remote, due to the heuristic depending on
12549 Mistaking a random SIGTRAP for a breakpoint trap
12550 causes similar symptoms (PC adjustment applied when
12551 it shouldn't), but then again, playing with SIGTRAPs
12552 behind the debugger's back is asking for trouble.
12554 Since hardware watchpoint traps are always
12555 distinguishable from other traps, so we don't need to
12556 apply keep hardware watchpoint moribund locations
12557 around. We simply always ignore hardware watchpoint
12558 traps we can no longer explain. */
12560 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12561 old_loc->owner = NULL;
12563 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12567 old_loc->owner = NULL;
12568 decref_bp_location (&old_loc);
12573 /* Rescan breakpoints at the same address and section, marking the
12574 first one as "first" and any others as "duplicates". This is so
12575 that the bpt instruction is only inserted once. If we have a
12576 permanent breakpoint at the same place as BPT, make that one the
12577 official one, and the rest as duplicates. Permanent breakpoints
12578 are sorted first for the same address.
12580 Do the same for hardware watchpoints, but also considering the
12581 watchpoint's type (regular/access/read) and length. */
12583 bp_loc_first = NULL;
12584 wp_loc_first = NULL;
12585 awp_loc_first = NULL;
12586 rwp_loc_first = NULL;
12587 ALL_BP_LOCATIONS (loc, locp)
12589 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12591 struct bp_location **loc_first_p;
12594 if (!unduplicated_should_be_inserted (loc)
12595 || !breakpoint_address_is_meaningful (b)
12596 /* Don't detect duplicate for tracepoint locations because they are
12597 never duplicated. See the comments in field `duplicate' of
12598 `struct bp_location'. */
12599 || is_tracepoint (b))
12601 /* Clear the condition modification flag. */
12602 loc->condition_changed = condition_unchanged;
12606 /* Permanent breakpoint should always be inserted. */
12607 if (b->enable_state == bp_permanent && ! loc->inserted)
12608 internal_error (__FILE__, __LINE__,
12609 _("allegedly permanent breakpoint is not "
12610 "actually inserted"));
12612 if (b->type == bp_hardware_watchpoint)
12613 loc_first_p = &wp_loc_first;
12614 else if (b->type == bp_read_watchpoint)
12615 loc_first_p = &rwp_loc_first;
12616 else if (b->type == bp_access_watchpoint)
12617 loc_first_p = &awp_loc_first;
12619 loc_first_p = &bp_loc_first;
12621 if (*loc_first_p == NULL
12622 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12623 || !breakpoint_locations_match (loc, *loc_first_p))
12625 *loc_first_p = loc;
12626 loc->duplicate = 0;
12628 if (is_breakpoint (loc->owner) && loc->condition_changed)
12630 loc->needs_update = 1;
12631 /* Clear the condition modification flag. */
12632 loc->condition_changed = condition_unchanged;
12638 /* This and the above ensure the invariant that the first location
12639 is not duplicated, and is the inserted one.
12640 All following are marked as duplicated, and are not inserted. */
12642 swap_insertion (loc, *loc_first_p);
12643 loc->duplicate = 1;
12645 /* Clear the condition modification flag. */
12646 loc->condition_changed = condition_unchanged;
12648 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12649 && b->enable_state != bp_permanent)
12650 internal_error (__FILE__, __LINE__,
12651 _("another breakpoint was inserted on top of "
12652 "a permanent breakpoint"));
12655 if (breakpoints_always_inserted_mode ()
12656 && (have_live_inferiors ()
12657 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12660 insert_breakpoint_locations ();
12663 /* Though should_insert is false, we may need to update conditions
12664 on the target's side if it is evaluating such conditions. We
12665 only update conditions for locations that are marked
12667 update_inserted_breakpoint_locations ();
12672 download_tracepoint_locations ();
12674 do_cleanups (cleanups);
12678 breakpoint_retire_moribund (void)
12680 struct bp_location *loc;
12683 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12684 if (--(loc->events_till_retirement) == 0)
12686 decref_bp_location (&loc);
12687 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12693 update_global_location_list_nothrow (int inserting)
12695 volatile struct gdb_exception e;
12697 TRY_CATCH (e, RETURN_MASK_ERROR)
12698 update_global_location_list (inserting);
12701 /* Clear BKP from a BPS. */
12704 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12708 for (bs = bps; bs; bs = bs->next)
12709 if (bs->breakpoint_at == bpt)
12711 bs->breakpoint_at = NULL;
12712 bs->old_val = NULL;
12713 /* bs->commands will be freed later. */
12717 /* Callback for iterate_over_threads. */
12719 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12721 struct breakpoint *bpt = data;
12723 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12727 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12731 say_where (struct breakpoint *b)
12733 struct value_print_options opts;
12735 get_user_print_options (&opts);
12737 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12739 if (b->loc == NULL)
12741 printf_filtered (_(" (%s) pending."), b->addr_string);
12745 if (opts.addressprint || b->loc->symtab == NULL)
12747 printf_filtered (" at ");
12748 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12751 if (b->loc->symtab != NULL)
12753 /* If there is a single location, we can print the location
12755 if (b->loc->next == NULL)
12756 printf_filtered (": file %s, line %d.",
12757 symtab_to_filename_for_display (b->loc->symtab),
12758 b->loc->line_number);
12760 /* This is not ideal, but each location may have a
12761 different file name, and this at least reflects the
12762 real situation somewhat. */
12763 printf_filtered (": %s.", b->addr_string);
12768 struct bp_location *loc = b->loc;
12770 for (; loc; loc = loc->next)
12772 printf_filtered (" (%d locations)", n);
12777 /* Default bp_location_ops methods. */
12780 bp_location_dtor (struct bp_location *self)
12782 xfree (self->cond);
12783 if (self->cond_bytecode)
12784 free_agent_expr (self->cond_bytecode);
12785 xfree (self->function_name);
12788 static const struct bp_location_ops bp_location_ops =
12793 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12797 base_breakpoint_dtor (struct breakpoint *self)
12799 decref_counted_command_line (&self->commands);
12800 xfree (self->cond_string);
12801 xfree (self->extra_string);
12802 xfree (self->addr_string);
12803 xfree (self->filter);
12804 xfree (self->addr_string_range_end);
12807 static struct bp_location *
12808 base_breakpoint_allocate_location (struct breakpoint *self)
12810 struct bp_location *loc;
12812 loc = XNEW (struct bp_location);
12813 init_bp_location (loc, &bp_location_ops, self);
12818 base_breakpoint_re_set (struct breakpoint *b)
12820 /* Nothing to re-set. */
12823 #define internal_error_pure_virtual_called() \
12824 gdb_assert_not_reached ("pure virtual function called")
12827 base_breakpoint_insert_location (struct bp_location *bl)
12829 internal_error_pure_virtual_called ();
12833 base_breakpoint_remove_location (struct bp_location *bl)
12835 internal_error_pure_virtual_called ();
12839 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12840 struct address_space *aspace,
12842 const struct target_waitstatus *ws)
12844 internal_error_pure_virtual_called ();
12848 base_breakpoint_check_status (bpstat bs)
12853 /* A "works_in_software_mode" breakpoint_ops method that just internal
12857 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12859 internal_error_pure_virtual_called ();
12862 /* A "resources_needed" breakpoint_ops method that just internal
12866 base_breakpoint_resources_needed (const struct bp_location *bl)
12868 internal_error_pure_virtual_called ();
12871 static enum print_stop_action
12872 base_breakpoint_print_it (bpstat bs)
12874 internal_error_pure_virtual_called ();
12878 base_breakpoint_print_one_detail (const struct breakpoint *self,
12879 struct ui_out *uiout)
12885 base_breakpoint_print_mention (struct breakpoint *b)
12887 internal_error_pure_virtual_called ();
12891 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12893 internal_error_pure_virtual_called ();
12897 base_breakpoint_create_sals_from_address (char **arg,
12898 struct linespec_result *canonical,
12899 enum bptype type_wanted,
12903 internal_error_pure_virtual_called ();
12907 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12908 struct linespec_result *c,
12909 struct linespec_sals *lsal,
12911 char *extra_string,
12912 enum bptype type_wanted,
12913 enum bpdisp disposition,
12915 int task, int ignore_count,
12916 const struct breakpoint_ops *o,
12917 int from_tty, int enabled,
12918 int internal, unsigned flags)
12920 internal_error_pure_virtual_called ();
12924 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12925 struct symtabs_and_lines *sals)
12927 internal_error_pure_virtual_called ();
12930 /* The default 'explains_signal' method. */
12932 static enum bpstat_signal_value
12933 base_breakpoint_explains_signal (struct breakpoint *b)
12935 return BPSTAT_SIGNAL_HIDE;
12938 struct breakpoint_ops base_breakpoint_ops =
12940 base_breakpoint_dtor,
12941 base_breakpoint_allocate_location,
12942 base_breakpoint_re_set,
12943 base_breakpoint_insert_location,
12944 base_breakpoint_remove_location,
12945 base_breakpoint_breakpoint_hit,
12946 base_breakpoint_check_status,
12947 base_breakpoint_resources_needed,
12948 base_breakpoint_works_in_software_mode,
12949 base_breakpoint_print_it,
12951 base_breakpoint_print_one_detail,
12952 base_breakpoint_print_mention,
12953 base_breakpoint_print_recreate,
12954 base_breakpoint_create_sals_from_address,
12955 base_breakpoint_create_breakpoints_sal,
12956 base_breakpoint_decode_linespec,
12957 base_breakpoint_explains_signal
12960 /* Default breakpoint_ops methods. */
12963 bkpt_re_set (struct breakpoint *b)
12965 /* FIXME: is this still reachable? */
12966 if (b->addr_string == NULL)
12968 /* Anything without a string can't be re-set. */
12969 delete_breakpoint (b);
12973 breakpoint_re_set_default (b);
12977 bkpt_insert_location (struct bp_location *bl)
12979 if (bl->loc_type == bp_loc_hardware_breakpoint)
12980 return target_insert_hw_breakpoint (bl->gdbarch,
12983 return target_insert_breakpoint (bl->gdbarch,
12988 bkpt_remove_location (struct bp_location *bl)
12990 if (bl->loc_type == bp_loc_hardware_breakpoint)
12991 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12993 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12997 bkpt_breakpoint_hit (const struct bp_location *bl,
12998 struct address_space *aspace, CORE_ADDR bp_addr,
12999 const struct target_waitstatus *ws)
13001 if (ws->kind != TARGET_WAITKIND_STOPPED
13002 || ws->value.sig != GDB_SIGNAL_TRAP)
13005 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13009 if (overlay_debugging /* unmapped overlay section */
13010 && section_is_overlay (bl->section)
13011 && !section_is_mapped (bl->section))
13018 bkpt_resources_needed (const struct bp_location *bl)
13020 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13025 static enum print_stop_action
13026 bkpt_print_it (bpstat bs)
13028 struct breakpoint *b;
13029 const struct bp_location *bl;
13031 struct ui_out *uiout = current_uiout;
13033 gdb_assert (bs->bp_location_at != NULL);
13035 bl = bs->bp_location_at;
13036 b = bs->breakpoint_at;
13038 bp_temp = b->disposition == disp_del;
13039 if (bl->address != bl->requested_address)
13040 breakpoint_adjustment_warning (bl->requested_address,
13043 annotate_breakpoint (b->number);
13045 ui_out_text (uiout, "\nTemporary breakpoint ");
13047 ui_out_text (uiout, "\nBreakpoint ");
13048 if (ui_out_is_mi_like_p (uiout))
13050 ui_out_field_string (uiout, "reason",
13051 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13052 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13054 ui_out_field_int (uiout, "bkptno", b->number);
13055 ui_out_text (uiout, ", ");
13057 return PRINT_SRC_AND_LOC;
13061 bkpt_print_mention (struct breakpoint *b)
13063 if (ui_out_is_mi_like_p (current_uiout))
13068 case bp_breakpoint:
13069 case bp_gnu_ifunc_resolver:
13070 if (b->disposition == disp_del)
13071 printf_filtered (_("Temporary breakpoint"));
13073 printf_filtered (_("Breakpoint"));
13074 printf_filtered (_(" %d"), b->number);
13075 if (b->type == bp_gnu_ifunc_resolver)
13076 printf_filtered (_(" at gnu-indirect-function resolver"));
13078 case bp_hardware_breakpoint:
13079 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13082 printf_filtered (_("Dprintf %d"), b->number);
13090 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13092 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13093 fprintf_unfiltered (fp, "tbreak");
13094 else if (tp->type == bp_breakpoint)
13095 fprintf_unfiltered (fp, "break");
13096 else if (tp->type == bp_hardware_breakpoint
13097 && tp->disposition == disp_del)
13098 fprintf_unfiltered (fp, "thbreak");
13099 else if (tp->type == bp_hardware_breakpoint)
13100 fprintf_unfiltered (fp, "hbreak");
13102 internal_error (__FILE__, __LINE__,
13103 _("unhandled breakpoint type %d"), (int) tp->type);
13105 fprintf_unfiltered (fp, " %s", tp->addr_string);
13106 print_recreate_thread (tp, fp);
13110 bkpt_create_sals_from_address (char **arg,
13111 struct linespec_result *canonical,
13112 enum bptype type_wanted,
13113 char *addr_start, char **copy_arg)
13115 create_sals_from_address_default (arg, canonical, type_wanted,
13116 addr_start, copy_arg);
13120 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13121 struct linespec_result *canonical,
13122 struct linespec_sals *lsal,
13124 char *extra_string,
13125 enum bptype type_wanted,
13126 enum bpdisp disposition,
13128 int task, int ignore_count,
13129 const struct breakpoint_ops *ops,
13130 int from_tty, int enabled,
13131 int internal, unsigned flags)
13133 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13134 cond_string, extra_string,
13136 disposition, thread, task,
13137 ignore_count, ops, from_tty,
13138 enabled, internal, flags);
13142 bkpt_decode_linespec (struct breakpoint *b, char **s,
13143 struct symtabs_and_lines *sals)
13145 decode_linespec_default (b, s, sals);
13148 /* Virtual table for internal breakpoints. */
13151 internal_bkpt_re_set (struct breakpoint *b)
13155 /* Delete overlay event and longjmp master breakpoints; they
13156 will be reset later by breakpoint_re_set. */
13157 case bp_overlay_event:
13158 case bp_longjmp_master:
13159 case bp_std_terminate_master:
13160 case bp_exception_master:
13161 delete_breakpoint (b);
13164 /* This breakpoint is special, it's set up when the inferior
13165 starts and we really don't want to touch it. */
13166 case bp_shlib_event:
13168 /* Like bp_shlib_event, this breakpoint type is special. Once
13169 it is set up, we do not want to touch it. */
13170 case bp_thread_event:
13176 internal_bkpt_check_status (bpstat bs)
13178 if (bs->breakpoint_at->type == bp_shlib_event)
13180 /* If requested, stop when the dynamic linker notifies GDB of
13181 events. This allows the user to get control and place
13182 breakpoints in initializer routines for dynamically loaded
13183 objects (among other things). */
13184 bs->stop = stop_on_solib_events;
13185 bs->print = stop_on_solib_events;
13191 static enum print_stop_action
13192 internal_bkpt_print_it (bpstat bs)
13194 struct breakpoint *b;
13196 b = bs->breakpoint_at;
13200 case bp_shlib_event:
13201 /* Did we stop because the user set the stop_on_solib_events
13202 variable? (If so, we report this as a generic, "Stopped due
13203 to shlib event" message.) */
13204 print_solib_event (0);
13207 case bp_thread_event:
13208 /* Not sure how we will get here.
13209 GDB should not stop for these breakpoints. */
13210 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13213 case bp_overlay_event:
13214 /* By analogy with the thread event, GDB should not stop for these. */
13215 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13218 case bp_longjmp_master:
13219 /* These should never be enabled. */
13220 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13223 case bp_std_terminate_master:
13224 /* These should never be enabled. */
13225 printf_filtered (_("std::terminate Master Breakpoint: "
13226 "gdb should not stop!\n"));
13229 case bp_exception_master:
13230 /* These should never be enabled. */
13231 printf_filtered (_("Exception Master Breakpoint: "
13232 "gdb should not stop!\n"));
13236 return PRINT_NOTHING;
13240 internal_bkpt_print_mention (struct breakpoint *b)
13242 /* Nothing to mention. These breakpoints are internal. */
13245 /* Virtual table for momentary breakpoints */
13248 momentary_bkpt_re_set (struct breakpoint *b)
13250 /* Keep temporary breakpoints, which can be encountered when we step
13251 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
13252 Otherwise these should have been blown away via the cleanup chain
13253 or by breakpoint_init_inferior when we rerun the executable. */
13257 momentary_bkpt_check_status (bpstat bs)
13259 /* Nothing. The point of these breakpoints is causing a stop. */
13262 static enum print_stop_action
13263 momentary_bkpt_print_it (bpstat bs)
13265 struct ui_out *uiout = current_uiout;
13267 if (ui_out_is_mi_like_p (uiout))
13269 struct breakpoint *b = bs->breakpoint_at;
13274 ui_out_field_string
13276 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13280 ui_out_field_string
13282 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13287 return PRINT_UNKNOWN;
13291 momentary_bkpt_print_mention (struct breakpoint *b)
13293 /* Nothing to mention. These breakpoints are internal. */
13296 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13298 It gets cleared already on the removal of the first one of such placed
13299 breakpoints. This is OK as they get all removed altogether. */
13302 longjmp_bkpt_dtor (struct breakpoint *self)
13304 struct thread_info *tp = find_thread_id (self->thread);
13307 tp->initiating_frame = null_frame_id;
13309 momentary_breakpoint_ops.dtor (self);
13312 /* Specific methods for probe breakpoints. */
13315 bkpt_probe_insert_location (struct bp_location *bl)
13317 int v = bkpt_insert_location (bl);
13321 /* The insertion was successful, now let's set the probe's semaphore
13323 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
13330 bkpt_probe_remove_location (struct bp_location *bl)
13332 /* Let's clear the semaphore before removing the location. */
13333 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
13335 return bkpt_remove_location (bl);
13339 bkpt_probe_create_sals_from_address (char **arg,
13340 struct linespec_result *canonical,
13341 enum bptype type_wanted,
13342 char *addr_start, char **copy_arg)
13344 struct linespec_sals lsal;
13346 lsal.sals = parse_probes (arg, canonical);
13348 *copy_arg = xstrdup (canonical->addr_string);
13349 lsal.canonical = xstrdup (*copy_arg);
13351 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13355 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13356 struct symtabs_and_lines *sals)
13358 *sals = parse_probes (s, NULL);
13360 error (_("probe not found"));
13363 /* The breakpoint_ops structure to be used in tracepoints. */
13366 tracepoint_re_set (struct breakpoint *b)
13368 breakpoint_re_set_default (b);
13372 tracepoint_breakpoint_hit (const struct bp_location *bl,
13373 struct address_space *aspace, CORE_ADDR bp_addr,
13374 const struct target_waitstatus *ws)
13376 /* By definition, the inferior does not report stops at
13382 tracepoint_print_one_detail (const struct breakpoint *self,
13383 struct ui_out *uiout)
13385 struct tracepoint *tp = (struct tracepoint *) self;
13386 if (tp->static_trace_marker_id)
13388 gdb_assert (self->type == bp_static_tracepoint);
13390 ui_out_text (uiout, "\tmarker id is ");
13391 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13392 tp->static_trace_marker_id);
13393 ui_out_text (uiout, "\n");
13398 tracepoint_print_mention (struct breakpoint *b)
13400 if (ui_out_is_mi_like_p (current_uiout))
13405 case bp_tracepoint:
13406 printf_filtered (_("Tracepoint"));
13407 printf_filtered (_(" %d"), b->number);
13409 case bp_fast_tracepoint:
13410 printf_filtered (_("Fast tracepoint"));
13411 printf_filtered (_(" %d"), b->number);
13413 case bp_static_tracepoint:
13414 printf_filtered (_("Static tracepoint"));
13415 printf_filtered (_(" %d"), b->number);
13418 internal_error (__FILE__, __LINE__,
13419 _("unhandled tracepoint type %d"), (int) b->type);
13426 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13428 struct tracepoint *tp = (struct tracepoint *) self;
13430 if (self->type == bp_fast_tracepoint)
13431 fprintf_unfiltered (fp, "ftrace");
13432 if (self->type == bp_static_tracepoint)
13433 fprintf_unfiltered (fp, "strace");
13434 else if (self->type == bp_tracepoint)
13435 fprintf_unfiltered (fp, "trace");
13437 internal_error (__FILE__, __LINE__,
13438 _("unhandled tracepoint type %d"), (int) self->type);
13440 fprintf_unfiltered (fp, " %s", self->addr_string);
13441 print_recreate_thread (self, fp);
13443 if (tp->pass_count)
13444 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13448 tracepoint_create_sals_from_address (char **arg,
13449 struct linespec_result *canonical,
13450 enum bptype type_wanted,
13451 char *addr_start, char **copy_arg)
13453 create_sals_from_address_default (arg, canonical, type_wanted,
13454 addr_start, copy_arg);
13458 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13459 struct linespec_result *canonical,
13460 struct linespec_sals *lsal,
13462 char *extra_string,
13463 enum bptype type_wanted,
13464 enum bpdisp disposition,
13466 int task, int ignore_count,
13467 const struct breakpoint_ops *ops,
13468 int from_tty, int enabled,
13469 int internal, unsigned flags)
13471 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13472 cond_string, extra_string,
13474 disposition, thread, task,
13475 ignore_count, ops, from_tty,
13476 enabled, internal, flags);
13480 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13481 struct symtabs_and_lines *sals)
13483 decode_linespec_default (b, s, sals);
13486 struct breakpoint_ops tracepoint_breakpoint_ops;
13488 /* The breakpoint_ops structure to be use on tracepoints placed in a
13492 tracepoint_probe_create_sals_from_address (char **arg,
13493 struct linespec_result *canonical,
13494 enum bptype type_wanted,
13495 char *addr_start, char **copy_arg)
13497 /* We use the same method for breakpoint on probes. */
13498 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13499 addr_start, copy_arg);
13503 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13504 struct symtabs_and_lines *sals)
13506 /* We use the same method for breakpoint on probes. */
13507 bkpt_probe_decode_linespec (b, s, sals);
13510 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13512 /* The breakpoint_ops structure to be used on static tracepoints with
13516 strace_marker_create_sals_from_address (char **arg,
13517 struct linespec_result *canonical,
13518 enum bptype type_wanted,
13519 char *addr_start, char **copy_arg)
13521 struct linespec_sals lsal;
13523 lsal.sals = decode_static_tracepoint_spec (arg);
13525 *copy_arg = savestring (addr_start, *arg - addr_start);
13527 canonical->addr_string = xstrdup (*copy_arg);
13528 lsal.canonical = xstrdup (*copy_arg);
13529 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13533 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13534 struct linespec_result *canonical,
13535 struct linespec_sals *lsal,
13537 char *extra_string,
13538 enum bptype type_wanted,
13539 enum bpdisp disposition,
13541 int task, int ignore_count,
13542 const struct breakpoint_ops *ops,
13543 int from_tty, int enabled,
13544 int internal, unsigned flags)
13548 /* If the user is creating a static tracepoint by marker id
13549 (strace -m MARKER_ID), then store the sals index, so that
13550 breakpoint_re_set can try to match up which of the newly
13551 found markers corresponds to this one, and, don't try to
13552 expand multiple locations for each sal, given than SALS
13553 already should contain all sals for MARKER_ID. */
13555 for (i = 0; i < lsal->sals.nelts; ++i)
13557 struct symtabs_and_lines expanded;
13558 struct tracepoint *tp;
13559 struct cleanup *old_chain;
13562 expanded.nelts = 1;
13563 expanded.sals = &lsal->sals.sals[i];
13565 addr_string = xstrdup (canonical->addr_string);
13566 old_chain = make_cleanup (xfree, addr_string);
13568 tp = XCNEW (struct tracepoint);
13569 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13571 cond_string, extra_string,
13572 type_wanted, disposition,
13573 thread, task, ignore_count, ops,
13574 from_tty, enabled, internal, flags,
13575 canonical->special_display);
13576 /* Given that its possible to have multiple markers with
13577 the same string id, if the user is creating a static
13578 tracepoint by marker id ("strace -m MARKER_ID"), then
13579 store the sals index, so that breakpoint_re_set can
13580 try to match up which of the newly found markers
13581 corresponds to this one */
13582 tp->static_trace_marker_id_idx = i;
13584 install_breakpoint (internal, &tp->base, 0);
13586 discard_cleanups (old_chain);
13591 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13592 struct symtabs_and_lines *sals)
13594 struct tracepoint *tp = (struct tracepoint *) b;
13596 *sals = decode_static_tracepoint_spec (s);
13597 if (sals->nelts > tp->static_trace_marker_id_idx)
13599 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13603 error (_("marker %s not found"), tp->static_trace_marker_id);
13606 static struct breakpoint_ops strace_marker_breakpoint_ops;
13609 strace_marker_p (struct breakpoint *b)
13611 return b->ops == &strace_marker_breakpoint_ops;
13614 /* Delete a breakpoint and clean up all traces of it in the data
13618 delete_breakpoint (struct breakpoint *bpt)
13620 struct breakpoint *b;
13622 gdb_assert (bpt != NULL);
13624 /* Has this bp already been deleted? This can happen because
13625 multiple lists can hold pointers to bp's. bpstat lists are
13628 One example of this happening is a watchpoint's scope bp. When
13629 the scope bp triggers, we notice that the watchpoint is out of
13630 scope, and delete it. We also delete its scope bp. But the
13631 scope bp is marked "auto-deleting", and is already on a bpstat.
13632 That bpstat is then checked for auto-deleting bp's, which are
13635 A real solution to this problem might involve reference counts in
13636 bp's, and/or giving them pointers back to their referencing
13637 bpstat's, and teaching delete_breakpoint to only free a bp's
13638 storage when no more references were extent. A cheaper bandaid
13640 if (bpt->type == bp_none)
13643 /* At least avoid this stale reference until the reference counting
13644 of breakpoints gets resolved. */
13645 if (bpt->related_breakpoint != bpt)
13647 struct breakpoint *related;
13648 struct watchpoint *w;
13650 if (bpt->type == bp_watchpoint_scope)
13651 w = (struct watchpoint *) bpt->related_breakpoint;
13652 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13653 w = (struct watchpoint *) bpt;
13657 watchpoint_del_at_next_stop (w);
13659 /* Unlink bpt from the bpt->related_breakpoint ring. */
13660 for (related = bpt; related->related_breakpoint != bpt;
13661 related = related->related_breakpoint);
13662 related->related_breakpoint = bpt->related_breakpoint;
13663 bpt->related_breakpoint = bpt;
13666 /* watch_command_1 creates a watchpoint but only sets its number if
13667 update_watchpoint succeeds in creating its bp_locations. If there's
13668 a problem in that process, we'll be asked to delete the half-created
13669 watchpoint. In that case, don't announce the deletion. */
13671 observer_notify_breakpoint_deleted (bpt);
13673 if (breakpoint_chain == bpt)
13674 breakpoint_chain = bpt->next;
13676 ALL_BREAKPOINTS (b)
13677 if (b->next == bpt)
13679 b->next = bpt->next;
13683 /* Be sure no bpstat's are pointing at the breakpoint after it's
13685 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13686 in all threads for now. Note that we cannot just remove bpstats
13687 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13688 commands are associated with the bpstat; if we remove it here,
13689 then the later call to bpstat_do_actions (&stop_bpstat); in
13690 event-top.c won't do anything, and temporary breakpoints with
13691 commands won't work. */
13693 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13695 /* Now that breakpoint is removed from breakpoint list, update the
13696 global location list. This will remove locations that used to
13697 belong to this breakpoint. Do this before freeing the breakpoint
13698 itself, since remove_breakpoint looks at location's owner. It
13699 might be better design to have location completely
13700 self-contained, but it's not the case now. */
13701 update_global_location_list (0);
13703 bpt->ops->dtor (bpt);
13704 /* On the chance that someone will soon try again to delete this
13705 same bp, we mark it as deleted before freeing its storage. */
13706 bpt->type = bp_none;
13711 do_delete_breakpoint_cleanup (void *b)
13713 delete_breakpoint (b);
13717 make_cleanup_delete_breakpoint (struct breakpoint *b)
13719 return make_cleanup (do_delete_breakpoint_cleanup, b);
13722 /* Iterator function to call a user-provided callback function once
13723 for each of B and its related breakpoints. */
13726 iterate_over_related_breakpoints (struct breakpoint *b,
13727 void (*function) (struct breakpoint *,
13731 struct breakpoint *related;
13736 struct breakpoint *next;
13738 /* FUNCTION may delete RELATED. */
13739 next = related->related_breakpoint;
13741 if (next == related)
13743 /* RELATED is the last ring entry. */
13744 function (related, data);
13746 /* FUNCTION may have deleted it, so we'd never reach back to
13747 B. There's nothing left to do anyway, so just break
13752 function (related, data);
13756 while (related != b);
13760 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13762 delete_breakpoint (b);
13765 /* A callback for map_breakpoint_numbers that calls
13766 delete_breakpoint. */
13769 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13771 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13775 delete_command (char *arg, int from_tty)
13777 struct breakpoint *b, *b_tmp;
13783 int breaks_to_delete = 0;
13785 /* Delete all breakpoints if no argument. Do not delete
13786 internal breakpoints, these have to be deleted with an
13787 explicit breakpoint number argument. */
13788 ALL_BREAKPOINTS (b)
13789 if (user_breakpoint_p (b))
13791 breaks_to_delete = 1;
13795 /* Ask user only if there are some breakpoints to delete. */
13797 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13799 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13800 if (user_breakpoint_p (b))
13801 delete_breakpoint (b);
13805 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13809 all_locations_are_pending (struct bp_location *loc)
13811 for (; loc; loc = loc->next)
13812 if (!loc->shlib_disabled
13813 && !loc->pspace->executing_startup)
13818 /* Subroutine of update_breakpoint_locations to simplify it.
13819 Return non-zero if multiple fns in list LOC have the same name.
13820 Null names are ignored. */
13823 ambiguous_names_p (struct bp_location *loc)
13825 struct bp_location *l;
13826 htab_t htab = htab_create_alloc (13, htab_hash_string,
13827 (int (*) (const void *,
13828 const void *)) streq,
13829 NULL, xcalloc, xfree);
13831 for (l = loc; l != NULL; l = l->next)
13834 const char *name = l->function_name;
13836 /* Allow for some names to be NULL, ignore them. */
13840 slot = (const char **) htab_find_slot (htab, (const void *) name,
13842 /* NOTE: We can assume slot != NULL here because xcalloc never
13846 htab_delete (htab);
13852 htab_delete (htab);
13856 /* When symbols change, it probably means the sources changed as well,
13857 and it might mean the static tracepoint markers are no longer at
13858 the same address or line numbers they used to be at last we
13859 checked. Losing your static tracepoints whenever you rebuild is
13860 undesirable. This function tries to resync/rematch gdb static
13861 tracepoints with the markers on the target, for static tracepoints
13862 that have not been set by marker id. Static tracepoint that have
13863 been set by marker id are reset by marker id in breakpoint_re_set.
13866 1) For a tracepoint set at a specific address, look for a marker at
13867 the old PC. If one is found there, assume to be the same marker.
13868 If the name / string id of the marker found is different from the
13869 previous known name, assume that means the user renamed the marker
13870 in the sources, and output a warning.
13872 2) For a tracepoint set at a given line number, look for a marker
13873 at the new address of the old line number. If one is found there,
13874 assume to be the same marker. If the name / string id of the
13875 marker found is different from the previous known name, assume that
13876 means the user renamed the marker in the sources, and output a
13879 3) If a marker is no longer found at the same address or line, it
13880 may mean the marker no longer exists. But it may also just mean
13881 the code changed a bit. Maybe the user added a few lines of code
13882 that made the marker move up or down (in line number terms). Ask
13883 the target for info about the marker with the string id as we knew
13884 it. If found, update line number and address in the matching
13885 static tracepoint. This will get confused if there's more than one
13886 marker with the same ID (possible in UST, although unadvised
13887 precisely because it confuses tools). */
13889 static struct symtab_and_line
13890 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13892 struct tracepoint *tp = (struct tracepoint *) b;
13893 struct static_tracepoint_marker marker;
13898 find_line_pc (sal.symtab, sal.line, &pc);
13900 if (target_static_tracepoint_marker_at (pc, &marker))
13902 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13903 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13905 tp->static_trace_marker_id, marker.str_id);
13907 xfree (tp->static_trace_marker_id);
13908 tp->static_trace_marker_id = xstrdup (marker.str_id);
13909 release_static_tracepoint_marker (&marker);
13914 /* Old marker wasn't found on target at lineno. Try looking it up
13916 if (!sal.explicit_pc
13918 && sal.symtab != NULL
13919 && tp->static_trace_marker_id != NULL)
13921 VEC(static_tracepoint_marker_p) *markers;
13924 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13926 if (!VEC_empty(static_tracepoint_marker_p, markers))
13928 struct symtab_and_line sal2;
13929 struct symbol *sym;
13930 struct static_tracepoint_marker *tpmarker;
13931 struct ui_out *uiout = current_uiout;
13933 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13935 xfree (tp->static_trace_marker_id);
13936 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13938 warning (_("marker for static tracepoint %d (%s) not "
13939 "found at previous line number"),
13940 b->number, tp->static_trace_marker_id);
13944 sal2.pc = tpmarker->address;
13946 sal2 = find_pc_line (tpmarker->address, 0);
13947 sym = find_pc_sect_function (tpmarker->address, NULL);
13948 ui_out_text (uiout, "Now in ");
13951 ui_out_field_string (uiout, "func",
13952 SYMBOL_PRINT_NAME (sym));
13953 ui_out_text (uiout, " at ");
13955 ui_out_field_string (uiout, "file",
13956 symtab_to_filename_for_display (sal2.symtab));
13957 ui_out_text (uiout, ":");
13959 if (ui_out_is_mi_like_p (uiout))
13961 const char *fullname = symtab_to_fullname (sal2.symtab);
13963 ui_out_field_string (uiout, "fullname", fullname);
13966 ui_out_field_int (uiout, "line", sal2.line);
13967 ui_out_text (uiout, "\n");
13969 b->loc->line_number = sal2.line;
13970 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13972 xfree (b->addr_string);
13973 b->addr_string = xstrprintf ("%s:%d",
13974 symtab_to_filename_for_display (sal2.symtab),
13975 b->loc->line_number);
13977 /* Might be nice to check if function changed, and warn if
13980 release_static_tracepoint_marker (tpmarker);
13986 /* Returns 1 iff locations A and B are sufficiently same that
13987 we don't need to report breakpoint as changed. */
13990 locations_are_equal (struct bp_location *a, struct bp_location *b)
13994 if (a->address != b->address)
13997 if (a->shlib_disabled != b->shlib_disabled)
14000 if (a->enabled != b->enabled)
14007 if ((a == NULL) != (b == NULL))
14013 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14014 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14015 a ranged breakpoint. */
14018 update_breakpoint_locations (struct breakpoint *b,
14019 struct symtabs_and_lines sals,
14020 struct symtabs_and_lines sals_end)
14023 struct bp_location *existing_locations = b->loc;
14025 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14027 /* Ranged breakpoints have only one start location and one end
14029 b->enable_state = bp_disabled;
14030 update_global_location_list (1);
14031 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14032 "multiple locations found\n"),
14037 /* If there's no new locations, and all existing locations are
14038 pending, don't do anything. This optimizes the common case where
14039 all locations are in the same shared library, that was unloaded.
14040 We'd like to retain the location, so that when the library is
14041 loaded again, we don't loose the enabled/disabled status of the
14042 individual locations. */
14043 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14048 for (i = 0; i < sals.nelts; ++i)
14050 struct bp_location *new_loc;
14052 switch_to_program_space_and_thread (sals.sals[i].pspace);
14054 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14056 /* Reparse conditions, they might contain references to the
14058 if (b->cond_string != NULL)
14061 volatile struct gdb_exception e;
14063 s = b->cond_string;
14064 TRY_CATCH (e, RETURN_MASK_ERROR)
14066 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14067 block_for_pc (sals.sals[i].pc),
14072 warning (_("failed to reevaluate condition "
14073 "for breakpoint %d: %s"),
14074 b->number, e.message);
14075 new_loc->enabled = 0;
14079 if (sals_end.nelts)
14081 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14083 new_loc->length = end - sals.sals[0].pc + 1;
14087 /* Update locations of permanent breakpoints. */
14088 if (b->enable_state == bp_permanent)
14089 make_breakpoint_permanent (b);
14091 /* If possible, carry over 'disable' status from existing
14094 struct bp_location *e = existing_locations;
14095 /* If there are multiple breakpoints with the same function name,
14096 e.g. for inline functions, comparing function names won't work.
14097 Instead compare pc addresses; this is just a heuristic as things
14098 may have moved, but in practice it gives the correct answer
14099 often enough until a better solution is found. */
14100 int have_ambiguous_names = ambiguous_names_p (b->loc);
14102 for (; e; e = e->next)
14104 if (!e->enabled && e->function_name)
14106 struct bp_location *l = b->loc;
14107 if (have_ambiguous_names)
14109 for (; l; l = l->next)
14110 if (breakpoint_locations_match (e, l))
14118 for (; l; l = l->next)
14119 if (l->function_name
14120 && strcmp (e->function_name, l->function_name) == 0)
14130 if (!locations_are_equal (existing_locations, b->loc))
14131 observer_notify_breakpoint_modified (b);
14133 update_global_location_list (1);
14136 /* Find the SaL locations corresponding to the given ADDR_STRING.
14137 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14139 static struct symtabs_and_lines
14140 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14143 struct symtabs_and_lines sals = {0};
14144 volatile struct gdb_exception e;
14146 gdb_assert (b->ops != NULL);
14149 TRY_CATCH (e, RETURN_MASK_ERROR)
14151 b->ops->decode_linespec (b, &s, &sals);
14155 int not_found_and_ok = 0;
14156 /* For pending breakpoints, it's expected that parsing will
14157 fail until the right shared library is loaded. User has
14158 already told to create pending breakpoints and don't need
14159 extra messages. If breakpoint is in bp_shlib_disabled
14160 state, then user already saw the message about that
14161 breakpoint being disabled, and don't want to see more
14163 if (e.error == NOT_FOUND_ERROR
14164 && (b->condition_not_parsed
14165 || (b->loc && b->loc->shlib_disabled)
14166 || (b->loc && b->loc->pspace->executing_startup)
14167 || b->enable_state == bp_disabled))
14168 not_found_and_ok = 1;
14170 if (!not_found_and_ok)
14172 /* We surely don't want to warn about the same breakpoint
14173 10 times. One solution, implemented here, is disable
14174 the breakpoint on error. Another solution would be to
14175 have separate 'warning emitted' flag. Since this
14176 happens only when a binary has changed, I don't know
14177 which approach is better. */
14178 b->enable_state = bp_disabled;
14179 throw_exception (e);
14183 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14187 for (i = 0; i < sals.nelts; ++i)
14188 resolve_sal_pc (&sals.sals[i]);
14189 if (b->condition_not_parsed && s && s[0])
14191 char *cond_string, *extra_string;
14194 find_condition_and_thread (s, sals.sals[0].pc,
14195 &cond_string, &thread, &task,
14198 b->cond_string = cond_string;
14199 b->thread = thread;
14202 b->extra_string = extra_string;
14203 b->condition_not_parsed = 0;
14206 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14207 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14217 /* The default re_set method, for typical hardware or software
14218 breakpoints. Reevaluate the breakpoint and recreate its
14222 breakpoint_re_set_default (struct breakpoint *b)
14225 struct symtabs_and_lines sals, sals_end;
14226 struct symtabs_and_lines expanded = {0};
14227 struct symtabs_and_lines expanded_end = {0};
14229 sals = addr_string_to_sals (b, b->addr_string, &found);
14232 make_cleanup (xfree, sals.sals);
14236 if (b->addr_string_range_end)
14238 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14241 make_cleanup (xfree, sals_end.sals);
14242 expanded_end = sals_end;
14246 update_breakpoint_locations (b, expanded, expanded_end);
14249 /* Default method for creating SALs from an address string. It basically
14250 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14253 create_sals_from_address_default (char **arg,
14254 struct linespec_result *canonical,
14255 enum bptype type_wanted,
14256 char *addr_start, char **copy_arg)
14258 parse_breakpoint_sals (arg, canonical);
14261 /* Call create_breakpoints_sal for the given arguments. This is the default
14262 function for the `create_breakpoints_sal' method of
14266 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14267 struct linespec_result *canonical,
14268 struct linespec_sals *lsal,
14270 char *extra_string,
14271 enum bptype type_wanted,
14272 enum bpdisp disposition,
14274 int task, int ignore_count,
14275 const struct breakpoint_ops *ops,
14276 int from_tty, int enabled,
14277 int internal, unsigned flags)
14279 create_breakpoints_sal (gdbarch, canonical, cond_string,
14281 type_wanted, disposition,
14282 thread, task, ignore_count, ops, from_tty,
14283 enabled, internal, flags);
14286 /* Decode the line represented by S by calling decode_line_full. This is the
14287 default function for the `decode_linespec' method of breakpoint_ops. */
14290 decode_linespec_default (struct breakpoint *b, char **s,
14291 struct symtabs_and_lines *sals)
14293 struct linespec_result canonical;
14295 init_linespec_result (&canonical);
14296 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14297 (struct symtab *) NULL, 0,
14298 &canonical, multiple_symbols_all,
14301 /* We should get 0 or 1 resulting SALs. */
14302 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14304 if (VEC_length (linespec_sals, canonical.sals) > 0)
14306 struct linespec_sals *lsal;
14308 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14309 *sals = lsal->sals;
14310 /* Arrange it so the destructor does not free the
14312 lsal->sals.sals = NULL;
14315 destroy_linespec_result (&canonical);
14318 /* Prepare the global context for a re-set of breakpoint B. */
14320 static struct cleanup *
14321 prepare_re_set_context (struct breakpoint *b)
14323 struct cleanup *cleanups;
14325 input_radix = b->input_radix;
14326 cleanups = save_current_space_and_thread ();
14327 if (b->pspace != NULL)
14328 switch_to_program_space_and_thread (b->pspace);
14329 set_language (b->language);
14334 /* Reset a breakpoint given it's struct breakpoint * BINT.
14335 The value we return ends up being the return value from catch_errors.
14336 Unused in this case. */
14339 breakpoint_re_set_one (void *bint)
14341 /* Get past catch_errs. */
14342 struct breakpoint *b = (struct breakpoint *) bint;
14343 struct cleanup *cleanups;
14345 cleanups = prepare_re_set_context (b);
14346 b->ops->re_set (b);
14347 do_cleanups (cleanups);
14351 /* Re-set all breakpoints after symbols have been re-loaded. */
14353 breakpoint_re_set (void)
14355 struct breakpoint *b, *b_tmp;
14356 enum language save_language;
14357 int save_input_radix;
14358 struct cleanup *old_chain;
14360 save_language = current_language->la_language;
14361 save_input_radix = input_radix;
14362 old_chain = save_current_program_space ();
14364 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14366 /* Format possible error msg. */
14367 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14369 struct cleanup *cleanups = make_cleanup (xfree, message);
14370 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14371 do_cleanups (cleanups);
14373 set_language (save_language);
14374 input_radix = save_input_radix;
14376 jit_breakpoint_re_set ();
14378 do_cleanups (old_chain);
14380 create_overlay_event_breakpoint ();
14381 create_longjmp_master_breakpoint ();
14382 create_std_terminate_master_breakpoint ();
14383 create_exception_master_breakpoint ();
14386 /* Reset the thread number of this breakpoint:
14388 - If the breakpoint is for all threads, leave it as-is.
14389 - Else, reset it to the current thread for inferior_ptid. */
14391 breakpoint_re_set_thread (struct breakpoint *b)
14393 if (b->thread != -1)
14395 if (in_thread_list (inferior_ptid))
14396 b->thread = pid_to_thread_id (inferior_ptid);
14398 /* We're being called after following a fork. The new fork is
14399 selected as current, and unless this was a vfork will have a
14400 different program space from the original thread. Reset that
14402 b->loc->pspace = current_program_space;
14406 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14407 If from_tty is nonzero, it prints a message to that effect,
14408 which ends with a period (no newline). */
14411 set_ignore_count (int bptnum, int count, int from_tty)
14413 struct breakpoint *b;
14418 ALL_BREAKPOINTS (b)
14419 if (b->number == bptnum)
14421 if (is_tracepoint (b))
14423 if (from_tty && count != 0)
14424 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14429 b->ignore_count = count;
14433 printf_filtered (_("Will stop next time "
14434 "breakpoint %d is reached."),
14436 else if (count == 1)
14437 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14440 printf_filtered (_("Will ignore next %d "
14441 "crossings of breakpoint %d."),
14444 observer_notify_breakpoint_modified (b);
14448 error (_("No breakpoint number %d."), bptnum);
14451 /* Command to set ignore-count of breakpoint N to COUNT. */
14454 ignore_command (char *args, int from_tty)
14460 error_no_arg (_("a breakpoint number"));
14462 num = get_number (&p);
14464 error (_("bad breakpoint number: '%s'"), args);
14466 error (_("Second argument (specified ignore-count) is missing."));
14468 set_ignore_count (num,
14469 longest_to_int (value_as_long (parse_and_eval (p))),
14472 printf_filtered ("\n");
14475 /* Call FUNCTION on each of the breakpoints
14476 whose numbers are given in ARGS. */
14479 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14484 struct breakpoint *b, *tmp;
14486 struct get_number_or_range_state state;
14489 error_no_arg (_("one or more breakpoint numbers"));
14491 init_number_or_range (&state, args);
14493 while (!state.finished)
14495 char *p = state.string;
14499 num = get_number_or_range (&state);
14502 warning (_("bad breakpoint number at or near '%s'"), p);
14506 ALL_BREAKPOINTS_SAFE (b, tmp)
14507 if (b->number == num)
14510 function (b, data);
14514 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14519 static struct bp_location *
14520 find_location_by_number (char *number)
14522 char *dot = strchr (number, '.');
14526 struct breakpoint *b;
14527 struct bp_location *loc;
14532 bp_num = get_number (&p1);
14534 error (_("Bad breakpoint number '%s'"), number);
14536 ALL_BREAKPOINTS (b)
14537 if (b->number == bp_num)
14542 if (!b || b->number != bp_num)
14543 error (_("Bad breakpoint number '%s'"), number);
14546 loc_num = get_number (&p1);
14548 error (_("Bad breakpoint location number '%s'"), number);
14552 for (;loc_num && loc; --loc_num, loc = loc->next)
14555 error (_("Bad breakpoint location number '%s'"), dot+1);
14561 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14562 If from_tty is nonzero, it prints a message to that effect,
14563 which ends with a period (no newline). */
14566 disable_breakpoint (struct breakpoint *bpt)
14568 /* Never disable a watchpoint scope breakpoint; we want to
14569 hit them when we leave scope so we can delete both the
14570 watchpoint and its scope breakpoint at that time. */
14571 if (bpt->type == bp_watchpoint_scope)
14574 /* You can't disable permanent breakpoints. */
14575 if (bpt->enable_state == bp_permanent)
14578 bpt->enable_state = bp_disabled;
14580 /* Mark breakpoint locations modified. */
14581 mark_breakpoint_modified (bpt);
14583 if (target_supports_enable_disable_tracepoint ()
14584 && current_trace_status ()->running && is_tracepoint (bpt))
14586 struct bp_location *location;
14588 for (location = bpt->loc; location; location = location->next)
14589 target_disable_tracepoint (location);
14592 update_global_location_list (0);
14594 observer_notify_breakpoint_modified (bpt);
14597 /* A callback for iterate_over_related_breakpoints. */
14600 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14602 disable_breakpoint (b);
14605 /* A callback for map_breakpoint_numbers that calls
14606 disable_breakpoint. */
14609 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14611 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14615 disable_command (char *args, int from_tty)
14619 struct breakpoint *bpt;
14621 ALL_BREAKPOINTS (bpt)
14622 if (user_breakpoint_p (bpt))
14623 disable_breakpoint (bpt);
14625 else if (strchr (args, '.'))
14627 struct bp_location *loc = find_location_by_number (args);
14633 mark_breakpoint_location_modified (loc);
14635 if (target_supports_enable_disable_tracepoint ()
14636 && current_trace_status ()->running && loc->owner
14637 && is_tracepoint (loc->owner))
14638 target_disable_tracepoint (loc);
14640 update_global_location_list (0);
14643 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14647 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14650 int target_resources_ok;
14652 if (bpt->type == bp_hardware_breakpoint)
14655 i = hw_breakpoint_used_count ();
14656 target_resources_ok =
14657 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14659 if (target_resources_ok == 0)
14660 error (_("No hardware breakpoint support in the target."));
14661 else if (target_resources_ok < 0)
14662 error (_("Hardware breakpoints used exceeds limit."));
14665 if (is_watchpoint (bpt))
14667 /* Initialize it just to avoid a GCC false warning. */
14668 enum enable_state orig_enable_state = 0;
14669 volatile struct gdb_exception e;
14671 TRY_CATCH (e, RETURN_MASK_ALL)
14673 struct watchpoint *w = (struct watchpoint *) bpt;
14675 orig_enable_state = bpt->enable_state;
14676 bpt->enable_state = bp_enabled;
14677 update_watchpoint (w, 1 /* reparse */);
14681 bpt->enable_state = orig_enable_state;
14682 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14688 if (bpt->enable_state != bp_permanent)
14689 bpt->enable_state = bp_enabled;
14691 bpt->enable_state = bp_enabled;
14693 /* Mark breakpoint locations modified. */
14694 mark_breakpoint_modified (bpt);
14696 if (target_supports_enable_disable_tracepoint ()
14697 && current_trace_status ()->running && is_tracepoint (bpt))
14699 struct bp_location *location;
14701 for (location = bpt->loc; location; location = location->next)
14702 target_enable_tracepoint (location);
14705 bpt->disposition = disposition;
14706 bpt->enable_count = count;
14707 update_global_location_list (1);
14709 observer_notify_breakpoint_modified (bpt);
14714 enable_breakpoint (struct breakpoint *bpt)
14716 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14720 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14722 enable_breakpoint (bpt);
14725 /* A callback for map_breakpoint_numbers that calls
14726 enable_breakpoint. */
14729 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14731 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14734 /* The enable command enables the specified breakpoints (or all defined
14735 breakpoints) so they once again become (or continue to be) effective
14736 in stopping the inferior. */
14739 enable_command (char *args, int from_tty)
14743 struct breakpoint *bpt;
14745 ALL_BREAKPOINTS (bpt)
14746 if (user_breakpoint_p (bpt))
14747 enable_breakpoint (bpt);
14749 else if (strchr (args, '.'))
14751 struct bp_location *loc = find_location_by_number (args);
14757 mark_breakpoint_location_modified (loc);
14759 if (target_supports_enable_disable_tracepoint ()
14760 && current_trace_status ()->running && loc->owner
14761 && is_tracepoint (loc->owner))
14762 target_enable_tracepoint (loc);
14764 update_global_location_list (1);
14767 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14770 /* This struct packages up disposition data for application to multiple
14780 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14782 struct disp_data disp_data = *(struct disp_data *) arg;
14784 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14788 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14790 struct disp_data disp = { disp_disable, 1 };
14792 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14796 enable_once_command (char *args, int from_tty)
14798 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14802 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14804 struct disp_data disp = { disp_disable, *(int *) countptr };
14806 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14810 enable_count_command (char *args, int from_tty)
14812 int count = get_number (&args);
14814 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14818 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14820 struct disp_data disp = { disp_del, 1 };
14822 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14826 enable_delete_command (char *args, int from_tty)
14828 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14832 set_breakpoint_cmd (char *args, int from_tty)
14837 show_breakpoint_cmd (char *args, int from_tty)
14841 /* Invalidate last known value of any hardware watchpoint if
14842 the memory which that value represents has been written to by
14846 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14847 CORE_ADDR addr, ssize_t len,
14848 const bfd_byte *data)
14850 struct breakpoint *bp;
14852 ALL_BREAKPOINTS (bp)
14853 if (bp->enable_state == bp_enabled
14854 && bp->type == bp_hardware_watchpoint)
14856 struct watchpoint *wp = (struct watchpoint *) bp;
14858 if (wp->val_valid && wp->val)
14860 struct bp_location *loc;
14862 for (loc = bp->loc; loc != NULL; loc = loc->next)
14863 if (loc->loc_type == bp_loc_hardware_watchpoint
14864 && loc->address + loc->length > addr
14865 && addr + len > loc->address)
14867 value_free (wp->val);
14875 /* Create and insert a raw software breakpoint at PC. Return an
14876 identifier, which should be used to remove the breakpoint later.
14877 In general, places which call this should be using something on the
14878 breakpoint chain instead; this function should be eliminated
14882 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14883 struct address_space *aspace, CORE_ADDR pc)
14885 struct bp_target_info *bp_tgt;
14887 bp_tgt = XZALLOC (struct bp_target_info);
14889 bp_tgt->placed_address_space = aspace;
14890 bp_tgt->placed_address = pc;
14892 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14894 /* Could not insert the breakpoint. */
14902 /* Remove a breakpoint BP inserted by
14903 deprecated_insert_raw_breakpoint. */
14906 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14908 struct bp_target_info *bp_tgt = bp;
14911 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14917 /* One (or perhaps two) breakpoints used for software single
14920 static void *single_step_breakpoints[2];
14921 static struct gdbarch *single_step_gdbarch[2];
14923 /* Create and insert a breakpoint for software single step. */
14926 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14927 struct address_space *aspace,
14932 if (single_step_breakpoints[0] == NULL)
14934 bpt_p = &single_step_breakpoints[0];
14935 single_step_gdbarch[0] = gdbarch;
14939 gdb_assert (single_step_breakpoints[1] == NULL);
14940 bpt_p = &single_step_breakpoints[1];
14941 single_step_gdbarch[1] = gdbarch;
14944 /* NOTE drow/2006-04-11: A future improvement to this function would
14945 be to only create the breakpoints once, and actually put them on
14946 the breakpoint chain. That would let us use set_raw_breakpoint.
14947 We could adjust the addresses each time they were needed. Doing
14948 this requires corresponding changes elsewhere where single step
14949 breakpoints are handled, however. So, for now, we use this. */
14951 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14952 if (*bpt_p == NULL)
14953 error (_("Could not insert single-step breakpoint at %s"),
14954 paddress (gdbarch, next_pc));
14957 /* Check if the breakpoints used for software single stepping
14958 were inserted or not. */
14961 single_step_breakpoints_inserted (void)
14963 return (single_step_breakpoints[0] != NULL
14964 || single_step_breakpoints[1] != NULL);
14967 /* Remove and delete any breakpoints used for software single step. */
14970 remove_single_step_breakpoints (void)
14972 gdb_assert (single_step_breakpoints[0] != NULL);
14974 /* See insert_single_step_breakpoint for more about this deprecated
14976 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14977 single_step_breakpoints[0]);
14978 single_step_gdbarch[0] = NULL;
14979 single_step_breakpoints[0] = NULL;
14981 if (single_step_breakpoints[1] != NULL)
14983 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14984 single_step_breakpoints[1]);
14985 single_step_gdbarch[1] = NULL;
14986 single_step_breakpoints[1] = NULL;
14990 /* Delete software single step breakpoints without removing them from
14991 the inferior. This is intended to be used if the inferior's address
14992 space where they were inserted is already gone, e.g. after exit or
14996 cancel_single_step_breakpoints (void)
15000 for (i = 0; i < 2; i++)
15001 if (single_step_breakpoints[i])
15003 xfree (single_step_breakpoints[i]);
15004 single_step_breakpoints[i] = NULL;
15005 single_step_gdbarch[i] = NULL;
15009 /* Detach software single-step breakpoints from INFERIOR_PTID without
15013 detach_single_step_breakpoints (void)
15017 for (i = 0; i < 2; i++)
15018 if (single_step_breakpoints[i])
15019 target_remove_breakpoint (single_step_gdbarch[i],
15020 single_step_breakpoints[i]);
15023 /* Check whether a software single-step breakpoint is inserted at
15027 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15032 for (i = 0; i < 2; i++)
15034 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15036 && breakpoint_address_match (bp_tgt->placed_address_space,
15037 bp_tgt->placed_address,
15045 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15046 non-zero otherwise. */
15048 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15050 if (syscall_catchpoint_p (bp)
15051 && bp->enable_state != bp_disabled
15052 && bp->enable_state != bp_call_disabled)
15059 catch_syscall_enabled (void)
15061 struct catch_syscall_inferior_data *inf_data
15062 = get_catch_syscall_inferior_data (current_inferior ());
15064 return inf_data->total_syscalls_count != 0;
15068 catching_syscall_number (int syscall_number)
15070 struct breakpoint *bp;
15072 ALL_BREAKPOINTS (bp)
15073 if (is_syscall_catchpoint_enabled (bp))
15075 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15077 if (c->syscalls_to_be_caught)
15081 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15083 if (syscall_number == iter)
15093 /* Complete syscall names. Used by "catch syscall". */
15094 static VEC (char_ptr) *
15095 catch_syscall_completer (struct cmd_list_element *cmd,
15096 const char *text, const char *word)
15098 const char **list = get_syscall_names ();
15099 VEC (char_ptr) *retlist
15100 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15106 /* Tracepoint-specific operations. */
15108 /* Set tracepoint count to NUM. */
15110 set_tracepoint_count (int num)
15112 tracepoint_count = num;
15113 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15117 trace_command (char *arg, int from_tty)
15119 struct breakpoint_ops *ops;
15120 const char *arg_cp = arg;
15122 if (arg && probe_linespec_to_ops (&arg_cp))
15123 ops = &tracepoint_probe_breakpoint_ops;
15125 ops = &tracepoint_breakpoint_ops;
15127 create_breakpoint (get_current_arch (),
15129 NULL, 0, NULL, 1 /* parse arg */,
15131 bp_tracepoint /* type_wanted */,
15132 0 /* Ignore count */,
15133 pending_break_support,
15137 0 /* internal */, 0);
15141 ftrace_command (char *arg, int from_tty)
15143 create_breakpoint (get_current_arch (),
15145 NULL, 0, NULL, 1 /* parse arg */,
15147 bp_fast_tracepoint /* type_wanted */,
15148 0 /* Ignore count */,
15149 pending_break_support,
15150 &tracepoint_breakpoint_ops,
15153 0 /* internal */, 0);
15156 /* strace command implementation. Creates a static tracepoint. */
15159 strace_command (char *arg, int from_tty)
15161 struct breakpoint_ops *ops;
15163 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15164 or with a normal static tracepoint. */
15165 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15166 ops = &strace_marker_breakpoint_ops;
15168 ops = &tracepoint_breakpoint_ops;
15170 create_breakpoint (get_current_arch (),
15172 NULL, 0, NULL, 1 /* parse arg */,
15174 bp_static_tracepoint /* type_wanted */,
15175 0 /* Ignore count */,
15176 pending_break_support,
15180 0 /* internal */, 0);
15183 /* Set up a fake reader function that gets command lines from a linked
15184 list that was acquired during tracepoint uploading. */
15186 static struct uploaded_tp *this_utp;
15187 static int next_cmd;
15190 read_uploaded_action (void)
15194 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15201 /* Given information about a tracepoint as recorded on a target (which
15202 can be either a live system or a trace file), attempt to create an
15203 equivalent GDB tracepoint. This is not a reliable process, since
15204 the target does not necessarily have all the information used when
15205 the tracepoint was originally defined. */
15207 struct tracepoint *
15208 create_tracepoint_from_upload (struct uploaded_tp *utp)
15210 char *addr_str, small_buf[100];
15211 struct tracepoint *tp;
15213 if (utp->at_string)
15214 addr_str = utp->at_string;
15217 /* In the absence of a source location, fall back to raw
15218 address. Since there is no way to confirm that the address
15219 means the same thing as when the trace was started, warn the
15221 warning (_("Uploaded tracepoint %d has no "
15222 "source location, using raw address"),
15224 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15225 addr_str = small_buf;
15228 /* There's not much we can do with a sequence of bytecodes. */
15229 if (utp->cond && !utp->cond_string)
15230 warning (_("Uploaded tracepoint %d condition "
15231 "has no source form, ignoring it"),
15234 if (!create_breakpoint (get_current_arch (),
15236 utp->cond_string, -1, NULL,
15237 0 /* parse cond/thread */,
15239 utp->type /* type_wanted */,
15240 0 /* Ignore count */,
15241 pending_break_support,
15242 &tracepoint_breakpoint_ops,
15244 utp->enabled /* enabled */,
15246 CREATE_BREAKPOINT_FLAGS_INSERTED))
15249 /* Get the tracepoint we just created. */
15250 tp = get_tracepoint (tracepoint_count);
15251 gdb_assert (tp != NULL);
15255 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15258 trace_pass_command (small_buf, 0);
15261 /* If we have uploaded versions of the original commands, set up a
15262 special-purpose "reader" function and call the usual command line
15263 reader, then pass the result to the breakpoint command-setting
15265 if (!VEC_empty (char_ptr, utp->cmd_strings))
15267 struct command_line *cmd_list;
15272 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15274 breakpoint_set_commands (&tp->base, cmd_list);
15276 else if (!VEC_empty (char_ptr, utp->actions)
15277 || !VEC_empty (char_ptr, utp->step_actions))
15278 warning (_("Uploaded tracepoint %d actions "
15279 "have no source form, ignoring them"),
15282 /* Copy any status information that might be available. */
15283 tp->base.hit_count = utp->hit_count;
15284 tp->traceframe_usage = utp->traceframe_usage;
15289 /* Print information on tracepoint number TPNUM_EXP, or all if
15293 tracepoints_info (char *args, int from_tty)
15295 struct ui_out *uiout = current_uiout;
15298 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15300 if (num_printed == 0)
15302 if (args == NULL || *args == '\0')
15303 ui_out_message (uiout, 0, "No tracepoints.\n");
15305 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15308 default_collect_info ();
15311 /* The 'enable trace' command enables tracepoints.
15312 Not supported by all targets. */
15314 enable_trace_command (char *args, int from_tty)
15316 enable_command (args, from_tty);
15319 /* The 'disable trace' command disables tracepoints.
15320 Not supported by all targets. */
15322 disable_trace_command (char *args, int from_tty)
15324 disable_command (args, from_tty);
15327 /* Remove a tracepoint (or all if no argument). */
15329 delete_trace_command (char *arg, int from_tty)
15331 struct breakpoint *b, *b_tmp;
15337 int breaks_to_delete = 0;
15339 /* Delete all breakpoints if no argument.
15340 Do not delete internal or call-dummy breakpoints, these
15341 have to be deleted with an explicit breakpoint number
15343 ALL_TRACEPOINTS (b)
15344 if (is_tracepoint (b) && user_breakpoint_p (b))
15346 breaks_to_delete = 1;
15350 /* Ask user only if there are some breakpoints to delete. */
15352 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15354 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15355 if (is_tracepoint (b) && user_breakpoint_p (b))
15356 delete_breakpoint (b);
15360 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15363 /* Helper function for trace_pass_command. */
15366 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15368 tp->pass_count = count;
15369 observer_notify_breakpoint_modified (&tp->base);
15371 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15372 tp->base.number, count);
15375 /* Set passcount for tracepoint.
15377 First command argument is passcount, second is tracepoint number.
15378 If tracepoint number omitted, apply to most recently defined.
15379 Also accepts special argument "all". */
15382 trace_pass_command (char *args, int from_tty)
15384 struct tracepoint *t1;
15385 unsigned int count;
15387 if (args == 0 || *args == 0)
15388 error (_("passcount command requires an "
15389 "argument (count + optional TP num)"));
15391 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15393 args = skip_spaces (args);
15394 if (*args && strncasecmp (args, "all", 3) == 0)
15396 struct breakpoint *b;
15398 args += 3; /* Skip special argument "all". */
15400 error (_("Junk at end of arguments."));
15402 ALL_TRACEPOINTS (b)
15404 t1 = (struct tracepoint *) b;
15405 trace_pass_set_count (t1, count, from_tty);
15408 else if (*args == '\0')
15410 t1 = get_tracepoint_by_number (&args, NULL, 1);
15412 trace_pass_set_count (t1, count, from_tty);
15416 struct get_number_or_range_state state;
15418 init_number_or_range (&state, args);
15419 while (!state.finished)
15421 t1 = get_tracepoint_by_number (&args, &state, 1);
15423 trace_pass_set_count (t1, count, from_tty);
15428 struct tracepoint *
15429 get_tracepoint (int num)
15431 struct breakpoint *t;
15433 ALL_TRACEPOINTS (t)
15434 if (t->number == num)
15435 return (struct tracepoint *) t;
15440 /* Find the tracepoint with the given target-side number (which may be
15441 different from the tracepoint number after disconnecting and
15444 struct tracepoint *
15445 get_tracepoint_by_number_on_target (int num)
15447 struct breakpoint *b;
15449 ALL_TRACEPOINTS (b)
15451 struct tracepoint *t = (struct tracepoint *) b;
15453 if (t->number_on_target == num)
15460 /* Utility: parse a tracepoint number and look it up in the list.
15461 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15462 If OPTIONAL_P is true, then if the argument is missing, the most
15463 recent tracepoint (tracepoint_count) is returned. */
15464 struct tracepoint *
15465 get_tracepoint_by_number (char **arg,
15466 struct get_number_or_range_state *state,
15469 struct breakpoint *t;
15471 char *instring = arg == NULL ? NULL : *arg;
15475 gdb_assert (!state->finished);
15476 tpnum = get_number_or_range (state);
15478 else if (arg == NULL || *arg == NULL || ! **arg)
15481 tpnum = tracepoint_count;
15483 error_no_arg (_("tracepoint number"));
15486 tpnum = get_number (arg);
15490 if (instring && *instring)
15491 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15494 printf_filtered (_("Tracepoint argument missing "
15495 "and no previous tracepoint\n"));
15499 ALL_TRACEPOINTS (t)
15500 if (t->number == tpnum)
15502 return (struct tracepoint *) t;
15505 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15510 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15512 if (b->thread != -1)
15513 fprintf_unfiltered (fp, " thread %d", b->thread);
15516 fprintf_unfiltered (fp, " task %d", b->task);
15518 fprintf_unfiltered (fp, "\n");
15521 /* Save information on user settable breakpoints (watchpoints, etc) to
15522 a new script file named FILENAME. If FILTER is non-NULL, call it
15523 on each breakpoint and only include the ones for which it returns
15527 save_breakpoints (char *filename, int from_tty,
15528 int (*filter) (const struct breakpoint *))
15530 struct breakpoint *tp;
15533 struct cleanup *cleanup;
15534 struct ui_file *fp;
15535 int extra_trace_bits = 0;
15537 if (filename == 0 || *filename == 0)
15538 error (_("Argument required (file name in which to save)"));
15540 /* See if we have anything to save. */
15541 ALL_BREAKPOINTS (tp)
15543 /* Skip internal and momentary breakpoints. */
15544 if (!user_breakpoint_p (tp))
15547 /* If we have a filter, only save the breakpoints it accepts. */
15548 if (filter && !filter (tp))
15553 if (is_tracepoint (tp))
15555 extra_trace_bits = 1;
15557 /* We can stop searching. */
15564 warning (_("Nothing to save."));
15568 pathname = tilde_expand (filename);
15569 cleanup = make_cleanup (xfree, pathname);
15570 fp = gdb_fopen (pathname, "w");
15572 error (_("Unable to open file '%s' for saving (%s)"),
15573 filename, safe_strerror (errno));
15574 make_cleanup_ui_file_delete (fp);
15576 if (extra_trace_bits)
15577 save_trace_state_variables (fp);
15579 ALL_BREAKPOINTS (tp)
15581 /* Skip internal and momentary breakpoints. */
15582 if (!user_breakpoint_p (tp))
15585 /* If we have a filter, only save the breakpoints it accepts. */
15586 if (filter && !filter (tp))
15589 tp->ops->print_recreate (tp, fp);
15591 /* Note, we can't rely on tp->number for anything, as we can't
15592 assume the recreated breakpoint numbers will match. Use $bpnum
15595 if (tp->cond_string)
15596 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15598 if (tp->ignore_count)
15599 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15603 volatile struct gdb_exception ex;
15605 fprintf_unfiltered (fp, " commands\n");
15607 ui_out_redirect (current_uiout, fp);
15608 TRY_CATCH (ex, RETURN_MASK_ALL)
15610 print_command_lines (current_uiout, tp->commands->commands, 2);
15612 ui_out_redirect (current_uiout, NULL);
15615 throw_exception (ex);
15617 fprintf_unfiltered (fp, " end\n");
15620 if (tp->enable_state == bp_disabled)
15621 fprintf_unfiltered (fp, "disable\n");
15623 /* If this is a multi-location breakpoint, check if the locations
15624 should be individually disabled. Watchpoint locations are
15625 special, and not user visible. */
15626 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15628 struct bp_location *loc;
15631 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15633 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15637 if (extra_trace_bits && *default_collect)
15638 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15640 do_cleanups (cleanup);
15642 printf_filtered (_("Saved to file '%s'.\n"), filename);
15645 /* The `save breakpoints' command. */
15648 save_breakpoints_command (char *args, int from_tty)
15650 save_breakpoints (args, from_tty, NULL);
15653 /* The `save tracepoints' command. */
15656 save_tracepoints_command (char *args, int from_tty)
15658 save_breakpoints (args, from_tty, is_tracepoint);
15661 /* Create a vector of all tracepoints. */
15663 VEC(breakpoint_p) *
15664 all_tracepoints (void)
15666 VEC(breakpoint_p) *tp_vec = 0;
15667 struct breakpoint *tp;
15669 ALL_TRACEPOINTS (tp)
15671 VEC_safe_push (breakpoint_p, tp_vec, tp);
15678 /* This help string is used for the break, hbreak, tbreak and thbreak
15679 commands. It is defined as a macro to prevent duplication.
15680 COMMAND should be a string constant containing the name of the
15682 #define BREAK_ARGS_HELP(command) \
15683 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15684 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15685 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15686 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15687 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15688 If a line number is specified, break at start of code for that line.\n\
15689 If a function is specified, break at start of code for that function.\n\
15690 If an address is specified, break at that exact address.\n\
15691 With no LOCATION, uses current execution address of the selected\n\
15692 stack frame. This is useful for breaking on return to a stack frame.\n\
15694 THREADNUM is the number from \"info threads\".\n\
15695 CONDITION is a boolean expression.\n\
15697 Multiple breakpoints at one place are permitted, and useful if their\n\
15698 conditions are different.\n\
15700 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15702 /* List of subcommands for "catch". */
15703 static struct cmd_list_element *catch_cmdlist;
15705 /* List of subcommands for "tcatch". */
15706 static struct cmd_list_element *tcatch_cmdlist;
15709 add_catch_command (char *name, char *docstring,
15710 void (*sfunc) (char *args, int from_tty,
15711 struct cmd_list_element *command),
15712 completer_ftype *completer,
15713 void *user_data_catch,
15714 void *user_data_tcatch)
15716 struct cmd_list_element *command;
15718 command = add_cmd (name, class_breakpoint, NULL, docstring,
15720 set_cmd_sfunc (command, sfunc);
15721 set_cmd_context (command, user_data_catch);
15722 set_cmd_completer (command, completer);
15724 command = add_cmd (name, class_breakpoint, NULL, docstring,
15726 set_cmd_sfunc (command, sfunc);
15727 set_cmd_context (command, user_data_tcatch);
15728 set_cmd_completer (command, completer);
15732 clear_syscall_counts (struct inferior *inf)
15734 struct catch_syscall_inferior_data *inf_data
15735 = get_catch_syscall_inferior_data (inf);
15737 inf_data->total_syscalls_count = 0;
15738 inf_data->any_syscall_count = 0;
15739 VEC_free (int, inf_data->syscalls_counts);
15743 save_command (char *arg, int from_tty)
15745 printf_unfiltered (_("\"save\" must be followed by "
15746 "the name of a save subcommand.\n"));
15747 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15750 struct breakpoint *
15751 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15754 struct breakpoint *b, *b_tmp;
15756 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15758 if ((*callback) (b, data))
15765 /* Zero if any of the breakpoint's locations could be a location where
15766 functions have been inlined, nonzero otherwise. */
15769 is_non_inline_function (struct breakpoint *b)
15771 /* The shared library event breakpoint is set on the address of a
15772 non-inline function. */
15773 if (b->type == bp_shlib_event)
15779 /* Nonzero if the specified PC cannot be a location where functions
15780 have been inlined. */
15783 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15784 const struct target_waitstatus *ws)
15786 struct breakpoint *b;
15787 struct bp_location *bl;
15789 ALL_BREAKPOINTS (b)
15791 if (!is_non_inline_function (b))
15794 for (bl = b->loc; bl != NULL; bl = bl->next)
15796 if (!bl->shlib_disabled
15797 && bpstat_check_location (bl, aspace, pc, ws))
15805 /* Remove any references to OBJFILE which is going to be freed. */
15808 breakpoint_free_objfile (struct objfile *objfile)
15810 struct bp_location **locp, *loc;
15812 ALL_BP_LOCATIONS (loc, locp)
15813 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
15814 loc->symtab = NULL;
15818 initialize_breakpoint_ops (void)
15820 static int initialized = 0;
15822 struct breakpoint_ops *ops;
15828 /* The breakpoint_ops structure to be inherit by all kinds of
15829 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15830 internal and momentary breakpoints, etc.). */
15831 ops = &bkpt_base_breakpoint_ops;
15832 *ops = base_breakpoint_ops;
15833 ops->re_set = bkpt_re_set;
15834 ops->insert_location = bkpt_insert_location;
15835 ops->remove_location = bkpt_remove_location;
15836 ops->breakpoint_hit = bkpt_breakpoint_hit;
15837 ops->create_sals_from_address = bkpt_create_sals_from_address;
15838 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15839 ops->decode_linespec = bkpt_decode_linespec;
15841 /* The breakpoint_ops structure to be used in regular breakpoints. */
15842 ops = &bkpt_breakpoint_ops;
15843 *ops = bkpt_base_breakpoint_ops;
15844 ops->re_set = bkpt_re_set;
15845 ops->resources_needed = bkpt_resources_needed;
15846 ops->print_it = bkpt_print_it;
15847 ops->print_mention = bkpt_print_mention;
15848 ops->print_recreate = bkpt_print_recreate;
15850 /* Ranged breakpoints. */
15851 ops = &ranged_breakpoint_ops;
15852 *ops = bkpt_breakpoint_ops;
15853 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15854 ops->resources_needed = resources_needed_ranged_breakpoint;
15855 ops->print_it = print_it_ranged_breakpoint;
15856 ops->print_one = print_one_ranged_breakpoint;
15857 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15858 ops->print_mention = print_mention_ranged_breakpoint;
15859 ops->print_recreate = print_recreate_ranged_breakpoint;
15861 /* Internal breakpoints. */
15862 ops = &internal_breakpoint_ops;
15863 *ops = bkpt_base_breakpoint_ops;
15864 ops->re_set = internal_bkpt_re_set;
15865 ops->check_status = internal_bkpt_check_status;
15866 ops->print_it = internal_bkpt_print_it;
15867 ops->print_mention = internal_bkpt_print_mention;
15869 /* Momentary breakpoints. */
15870 ops = &momentary_breakpoint_ops;
15871 *ops = bkpt_base_breakpoint_ops;
15872 ops->re_set = momentary_bkpt_re_set;
15873 ops->check_status = momentary_bkpt_check_status;
15874 ops->print_it = momentary_bkpt_print_it;
15875 ops->print_mention = momentary_bkpt_print_mention;
15877 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15878 ops = &longjmp_breakpoint_ops;
15879 *ops = momentary_breakpoint_ops;
15880 ops->dtor = longjmp_bkpt_dtor;
15882 /* Probe breakpoints. */
15883 ops = &bkpt_probe_breakpoint_ops;
15884 *ops = bkpt_breakpoint_ops;
15885 ops->insert_location = bkpt_probe_insert_location;
15886 ops->remove_location = bkpt_probe_remove_location;
15887 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15888 ops->decode_linespec = bkpt_probe_decode_linespec;
15890 /* GNU v3 exception catchpoints. */
15891 ops = &gnu_v3_exception_catchpoint_ops;
15892 *ops = bkpt_breakpoint_ops;
15893 ops->print_it = print_it_exception_catchpoint;
15894 ops->print_one = print_one_exception_catchpoint;
15895 ops->print_mention = print_mention_exception_catchpoint;
15896 ops->print_recreate = print_recreate_exception_catchpoint;
15899 ops = &watchpoint_breakpoint_ops;
15900 *ops = base_breakpoint_ops;
15901 ops->dtor = dtor_watchpoint;
15902 ops->re_set = re_set_watchpoint;
15903 ops->insert_location = insert_watchpoint;
15904 ops->remove_location = remove_watchpoint;
15905 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15906 ops->check_status = check_status_watchpoint;
15907 ops->resources_needed = resources_needed_watchpoint;
15908 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15909 ops->print_it = print_it_watchpoint;
15910 ops->print_mention = print_mention_watchpoint;
15911 ops->print_recreate = print_recreate_watchpoint;
15913 /* Masked watchpoints. */
15914 ops = &masked_watchpoint_breakpoint_ops;
15915 *ops = watchpoint_breakpoint_ops;
15916 ops->insert_location = insert_masked_watchpoint;
15917 ops->remove_location = remove_masked_watchpoint;
15918 ops->resources_needed = resources_needed_masked_watchpoint;
15919 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15920 ops->print_it = print_it_masked_watchpoint;
15921 ops->print_one_detail = print_one_detail_masked_watchpoint;
15922 ops->print_mention = print_mention_masked_watchpoint;
15923 ops->print_recreate = print_recreate_masked_watchpoint;
15926 ops = &tracepoint_breakpoint_ops;
15927 *ops = base_breakpoint_ops;
15928 ops->re_set = tracepoint_re_set;
15929 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15930 ops->print_one_detail = tracepoint_print_one_detail;
15931 ops->print_mention = tracepoint_print_mention;
15932 ops->print_recreate = tracepoint_print_recreate;
15933 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15934 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15935 ops->decode_linespec = tracepoint_decode_linespec;
15937 /* Probe tracepoints. */
15938 ops = &tracepoint_probe_breakpoint_ops;
15939 *ops = tracepoint_breakpoint_ops;
15940 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15941 ops->decode_linespec = tracepoint_probe_decode_linespec;
15943 /* Static tracepoints with marker (`-m'). */
15944 ops = &strace_marker_breakpoint_ops;
15945 *ops = tracepoint_breakpoint_ops;
15946 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15947 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15948 ops->decode_linespec = strace_marker_decode_linespec;
15950 /* Fork catchpoints. */
15951 ops = &catch_fork_breakpoint_ops;
15952 *ops = base_breakpoint_ops;
15953 ops->insert_location = insert_catch_fork;
15954 ops->remove_location = remove_catch_fork;
15955 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15956 ops->print_it = print_it_catch_fork;
15957 ops->print_one = print_one_catch_fork;
15958 ops->print_mention = print_mention_catch_fork;
15959 ops->print_recreate = print_recreate_catch_fork;
15961 /* Vfork catchpoints. */
15962 ops = &catch_vfork_breakpoint_ops;
15963 *ops = base_breakpoint_ops;
15964 ops->insert_location = insert_catch_vfork;
15965 ops->remove_location = remove_catch_vfork;
15966 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15967 ops->print_it = print_it_catch_vfork;
15968 ops->print_one = print_one_catch_vfork;
15969 ops->print_mention = print_mention_catch_vfork;
15970 ops->print_recreate = print_recreate_catch_vfork;
15972 /* Exec catchpoints. */
15973 ops = &catch_exec_breakpoint_ops;
15974 *ops = base_breakpoint_ops;
15975 ops->dtor = dtor_catch_exec;
15976 ops->insert_location = insert_catch_exec;
15977 ops->remove_location = remove_catch_exec;
15978 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15979 ops->print_it = print_it_catch_exec;
15980 ops->print_one = print_one_catch_exec;
15981 ops->print_mention = print_mention_catch_exec;
15982 ops->print_recreate = print_recreate_catch_exec;
15984 /* Syscall catchpoints. */
15985 ops = &catch_syscall_breakpoint_ops;
15986 *ops = base_breakpoint_ops;
15987 ops->dtor = dtor_catch_syscall;
15988 ops->insert_location = insert_catch_syscall;
15989 ops->remove_location = remove_catch_syscall;
15990 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15991 ops->print_it = print_it_catch_syscall;
15992 ops->print_one = print_one_catch_syscall;
15993 ops->print_mention = print_mention_catch_syscall;
15994 ops->print_recreate = print_recreate_catch_syscall;
15996 /* Solib-related catchpoints. */
15997 ops = &catch_solib_breakpoint_ops;
15998 *ops = base_breakpoint_ops;
15999 ops->dtor = dtor_catch_solib;
16000 ops->insert_location = insert_catch_solib;
16001 ops->remove_location = remove_catch_solib;
16002 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16003 ops->check_status = check_status_catch_solib;
16004 ops->print_it = print_it_catch_solib;
16005 ops->print_one = print_one_catch_solib;
16006 ops->print_mention = print_mention_catch_solib;
16007 ops->print_recreate = print_recreate_catch_solib;
16009 ops = &dprintf_breakpoint_ops;
16010 *ops = bkpt_base_breakpoint_ops;
16011 ops->re_set = bkpt_re_set;
16012 ops->resources_needed = bkpt_resources_needed;
16013 ops->print_it = bkpt_print_it;
16014 ops->print_mention = bkpt_print_mention;
16015 ops->print_recreate = bkpt_print_recreate;
16018 /* Chain containing all defined "enable breakpoint" subcommands. */
16020 static struct cmd_list_element *enablebreaklist = NULL;
16023 _initialize_breakpoint (void)
16025 struct cmd_list_element *c;
16027 initialize_breakpoint_ops ();
16029 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16030 observer_attach_inferior_exit (clear_syscall_counts);
16031 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16033 breakpoint_objfile_key
16034 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16036 catch_syscall_inferior_data
16037 = register_inferior_data_with_cleanup (NULL,
16038 catch_syscall_inferior_data_cleanup);
16040 breakpoint_chain = 0;
16041 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16042 before a breakpoint is set. */
16043 breakpoint_count = 0;
16045 tracepoint_count = 0;
16047 add_com ("ignore", class_breakpoint, ignore_command, _("\
16048 Set ignore-count of breakpoint number N to COUNT.\n\
16049 Usage is `ignore N COUNT'."));
16051 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16053 add_com ("commands", class_breakpoint, commands_command, _("\
16054 Set commands to be executed when a breakpoint is hit.\n\
16055 Give breakpoint number as argument after \"commands\".\n\
16056 With no argument, the targeted breakpoint is the last one set.\n\
16057 The commands themselves follow starting on the next line.\n\
16058 Type a line containing \"end\" to indicate the end of them.\n\
16059 Give \"silent\" as the first line to make the breakpoint silent;\n\
16060 then no output is printed when it is hit, except what the commands print."));
16062 c = add_com ("condition", class_breakpoint, condition_command, _("\
16063 Specify breakpoint number N to break only if COND is true.\n\
16064 Usage is `condition N COND', where N is an integer and COND is an\n\
16065 expression to be evaluated whenever breakpoint N is reached."));
16066 set_cmd_completer (c, condition_completer);
16068 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16069 Set a temporary breakpoint.\n\
16070 Like \"break\" except the breakpoint is only temporary,\n\
16071 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16072 by using \"enable delete\" on the breakpoint number.\n\
16074 BREAK_ARGS_HELP ("tbreak")));
16075 set_cmd_completer (c, location_completer);
16077 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16078 Set a hardware assisted breakpoint.\n\
16079 Like \"break\" except the breakpoint requires hardware support,\n\
16080 some target hardware may not have this support.\n\
16082 BREAK_ARGS_HELP ("hbreak")));
16083 set_cmd_completer (c, location_completer);
16085 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16086 Set a temporary hardware assisted breakpoint.\n\
16087 Like \"hbreak\" except the breakpoint is only temporary,\n\
16088 so it will be deleted when hit.\n\
16090 BREAK_ARGS_HELP ("thbreak")));
16091 set_cmd_completer (c, location_completer);
16093 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16094 Enable some breakpoints.\n\
16095 Give breakpoint numbers (separated by spaces) as arguments.\n\
16096 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16097 This is used to cancel the effect of the \"disable\" command.\n\
16098 With a subcommand you can enable temporarily."),
16099 &enablelist, "enable ", 1, &cmdlist);
16101 add_com ("ab", class_breakpoint, enable_command, _("\
16102 Enable some breakpoints.\n\
16103 Give breakpoint numbers (separated by spaces) as arguments.\n\
16104 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16105 This is used to cancel the effect of the \"disable\" command.\n\
16106 With a subcommand you can enable temporarily."));
16108 add_com_alias ("en", "enable", class_breakpoint, 1);
16110 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16111 Enable some breakpoints.\n\
16112 Give breakpoint numbers (separated by spaces) as arguments.\n\
16113 This is used to cancel the effect of the \"disable\" command.\n\
16114 May be abbreviated to simply \"enable\".\n"),
16115 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16117 add_cmd ("once", no_class, enable_once_command, _("\
16118 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16119 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16122 add_cmd ("delete", no_class, enable_delete_command, _("\
16123 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16124 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16127 add_cmd ("count", no_class, enable_count_command, _("\
16128 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16129 If a breakpoint is hit while enabled in this fashion,\n\
16130 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16133 add_cmd ("delete", no_class, enable_delete_command, _("\
16134 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16135 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16138 add_cmd ("once", no_class, enable_once_command, _("\
16139 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16140 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16143 add_cmd ("count", no_class, enable_count_command, _("\
16144 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16145 If a breakpoint is hit while enabled in this fashion,\n\
16146 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16149 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16150 Disable some breakpoints.\n\
16151 Arguments are breakpoint numbers with spaces in between.\n\
16152 To disable all breakpoints, give no argument.\n\
16153 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16154 &disablelist, "disable ", 1, &cmdlist);
16155 add_com_alias ("dis", "disable", class_breakpoint, 1);
16156 add_com_alias ("disa", "disable", class_breakpoint, 1);
16158 add_com ("sb", class_breakpoint, disable_command, _("\
16159 Disable some breakpoints.\n\
16160 Arguments are breakpoint numbers with spaces in between.\n\
16161 To disable all breakpoints, give no argument.\n\
16162 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16164 add_cmd ("breakpoints", class_alias, disable_command, _("\
16165 Disable some breakpoints.\n\
16166 Arguments are breakpoint numbers with spaces in between.\n\
16167 To disable all breakpoints, give no argument.\n\
16168 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16169 This command may be abbreviated \"disable\"."),
16172 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16173 Delete some breakpoints or auto-display expressions.\n\
16174 Arguments are breakpoint numbers with spaces in between.\n\
16175 To delete all breakpoints, give no argument.\n\
16177 Also a prefix command for deletion of other GDB objects.\n\
16178 The \"unset\" command is also an alias for \"delete\"."),
16179 &deletelist, "delete ", 1, &cmdlist);
16180 add_com_alias ("d", "delete", class_breakpoint, 1);
16181 add_com_alias ("del", "delete", class_breakpoint, 1);
16183 add_com ("db", class_breakpoint, delete_command, _("\
16184 Delete some breakpoints.\n\
16185 Arguments are breakpoint numbers with spaces in between.\n\
16186 To delete all breakpoints, give no argument.\n"));
16188 add_cmd ("breakpoints", class_alias, delete_command, _("\
16189 Delete some breakpoints or auto-display expressions.\n\
16190 Arguments are breakpoint numbers with spaces in between.\n\
16191 To delete all breakpoints, give no argument.\n\
16192 This command may be abbreviated \"delete\"."),
16195 add_com ("clear", class_breakpoint, clear_command, _("\
16196 Clear breakpoint at specified line or function.\n\
16197 Argument may be line number, function name, or \"*\" and an address.\n\
16198 If line number is specified, all breakpoints in that line are cleared.\n\
16199 If function is specified, breakpoints at beginning of function are cleared.\n\
16200 If an address is specified, breakpoints at that address are cleared.\n\
16202 With no argument, clears all breakpoints in the line that the selected frame\n\
16203 is executing in.\n\
16205 See also the \"delete\" command which clears breakpoints by number."));
16206 add_com_alias ("cl", "clear", class_breakpoint, 1);
16208 c = add_com ("break", class_breakpoint, break_command, _("\
16209 Set breakpoint at specified line or function.\n"
16210 BREAK_ARGS_HELP ("break")));
16211 set_cmd_completer (c, location_completer);
16213 add_com_alias ("b", "break", class_run, 1);
16214 add_com_alias ("br", "break", class_run, 1);
16215 add_com_alias ("bre", "break", class_run, 1);
16216 add_com_alias ("brea", "break", class_run, 1);
16219 add_com_alias ("ba", "break", class_breakpoint, 1);
16223 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16224 Break in function/address or break at a line in the current file."),
16225 &stoplist, "stop ", 1, &cmdlist);
16226 add_cmd ("in", class_breakpoint, stopin_command,
16227 _("Break in function or address."), &stoplist);
16228 add_cmd ("at", class_breakpoint, stopat_command,
16229 _("Break at a line in the current file."), &stoplist);
16230 add_com ("status", class_info, breakpoints_info, _("\
16231 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16232 The \"Type\" column indicates one of:\n\
16233 \tbreakpoint - normal breakpoint\n\
16234 \twatchpoint - watchpoint\n\
16235 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16236 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16237 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16238 address and file/line number respectively.\n\
16240 Convenience variable \"$_\" and default examine address for \"x\"\n\
16241 are set to the address of the last breakpoint listed unless the command\n\
16242 is prefixed with \"server \".\n\n\
16243 Convenience variable \"$bpnum\" contains the number of the last\n\
16244 breakpoint set."));
16247 add_info ("breakpoints", breakpoints_info, _("\
16248 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16249 The \"Type\" column indicates one of:\n\
16250 \tbreakpoint - normal breakpoint\n\
16251 \twatchpoint - watchpoint\n\
16252 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16253 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16254 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16255 address and file/line number respectively.\n\
16257 Convenience variable \"$_\" and default examine address for \"x\"\n\
16258 are set to the address of the last breakpoint listed unless the command\n\
16259 is prefixed with \"server \".\n\n\
16260 Convenience variable \"$bpnum\" contains the number of the last\n\
16261 breakpoint set."));
16263 add_info_alias ("b", "breakpoints", 1);
16266 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16267 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16268 The \"Type\" column indicates one of:\n\
16269 \tbreakpoint - normal breakpoint\n\
16270 \twatchpoint - watchpoint\n\
16271 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16272 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16273 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16274 address and file/line number respectively.\n\
16276 Convenience variable \"$_\" and default examine address for \"x\"\n\
16277 are set to the address of the last breakpoint listed unless the command\n\
16278 is prefixed with \"server \".\n\n\
16279 Convenience variable \"$bpnum\" contains the number of the last\n\
16280 breakpoint set."));
16282 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16283 Status of all breakpoints, or breakpoint number NUMBER.\n\
16284 The \"Type\" column indicates one of:\n\
16285 \tbreakpoint - normal breakpoint\n\
16286 \twatchpoint - watchpoint\n\
16287 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16288 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16289 \tuntil - internal breakpoint used by the \"until\" command\n\
16290 \tfinish - internal breakpoint used by the \"finish\" command\n\
16291 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16292 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16293 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16294 address and file/line number respectively.\n\
16296 Convenience variable \"$_\" and default examine address for \"x\"\n\
16297 are set to the address of the last breakpoint listed unless the command\n\
16298 is prefixed with \"server \".\n\n\
16299 Convenience variable \"$bpnum\" contains the number of the last\n\
16301 &maintenanceinfolist);
16303 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16304 Set catchpoints to catch events."),
16305 &catch_cmdlist, "catch ",
16306 0/*allow-unknown*/, &cmdlist);
16308 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16309 Set temporary catchpoints to catch events."),
16310 &tcatch_cmdlist, "tcatch ",
16311 0/*allow-unknown*/, &cmdlist);
16313 /* Add catch and tcatch sub-commands. */
16314 add_catch_command ("catch", _("\
16315 Catch an exception, when caught."),
16316 catch_catch_command,
16320 add_catch_command ("throw", _("\
16321 Catch an exception, when thrown."),
16322 catch_throw_command,
16326 add_catch_command ("fork", _("Catch calls to fork."),
16327 catch_fork_command_1,
16329 (void *) (uintptr_t) catch_fork_permanent,
16330 (void *) (uintptr_t) catch_fork_temporary);
16331 add_catch_command ("vfork", _("Catch calls to vfork."),
16332 catch_fork_command_1,
16334 (void *) (uintptr_t) catch_vfork_permanent,
16335 (void *) (uintptr_t) catch_vfork_temporary);
16336 add_catch_command ("exec", _("Catch calls to exec."),
16337 catch_exec_command_1,
16341 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16342 Usage: catch load [REGEX]\n\
16343 If REGEX is given, only stop for libraries matching the regular expression."),
16344 catch_load_command_1,
16348 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16349 Usage: catch unload [REGEX]\n\
16350 If REGEX is given, only stop for libraries matching the regular expression."),
16351 catch_unload_command_1,
16355 add_catch_command ("syscall", _("\
16356 Catch system calls by their names and/or numbers.\n\
16357 Arguments say which system calls to catch. If no arguments\n\
16358 are given, every system call will be caught.\n\
16359 Arguments, if given, should be one or more system call names\n\
16360 (if your system supports that), or system call numbers."),
16361 catch_syscall_command_1,
16362 catch_syscall_completer,
16366 c = add_com ("watch", class_breakpoint, watch_command, _("\
16367 Set a watchpoint for an expression.\n\
16368 Usage: watch [-l|-location] EXPRESSION\n\
16369 A watchpoint stops execution of your program whenever the value of\n\
16370 an expression changes.\n\
16371 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16372 the memory to which it refers."));
16373 set_cmd_completer (c, expression_completer);
16375 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16376 Set a read watchpoint for an expression.\n\
16377 Usage: rwatch [-l|-location] EXPRESSION\n\
16378 A watchpoint stops execution of your program whenever the value of\n\
16379 an expression is read.\n\
16380 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16381 the memory to which it refers."));
16382 set_cmd_completer (c, expression_completer);
16384 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16385 Set a watchpoint for an expression.\n\
16386 Usage: awatch [-l|-location] EXPRESSION\n\
16387 A watchpoint stops execution of your program whenever the value of\n\
16388 an expression is either read or written.\n\
16389 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16390 the memory to which it refers."));
16391 set_cmd_completer (c, expression_completer);
16393 add_info ("watchpoints", watchpoints_info, _("\
16394 Status of specified watchpoints (all watchpoints if no argument)."));
16396 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16397 respond to changes - contrary to the description. */
16398 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16399 &can_use_hw_watchpoints, _("\
16400 Set debugger's willingness to use watchpoint hardware."), _("\
16401 Show debugger's willingness to use watchpoint hardware."), _("\
16402 If zero, gdb will not use hardware for new watchpoints, even if\n\
16403 such is available. (However, any hardware watchpoints that were\n\
16404 created before setting this to nonzero, will continue to use watchpoint\n\
16407 show_can_use_hw_watchpoints,
16408 &setlist, &showlist);
16410 can_use_hw_watchpoints = 1;
16412 /* Tracepoint manipulation commands. */
16414 c = add_com ("trace", class_breakpoint, trace_command, _("\
16415 Set a tracepoint at specified line or function.\n\
16417 BREAK_ARGS_HELP ("trace") "\n\
16418 Do \"help tracepoints\" for info on other tracepoint commands."));
16419 set_cmd_completer (c, location_completer);
16421 add_com_alias ("tp", "trace", class_alias, 0);
16422 add_com_alias ("tr", "trace", class_alias, 1);
16423 add_com_alias ("tra", "trace", class_alias, 1);
16424 add_com_alias ("trac", "trace", class_alias, 1);
16426 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16427 Set a fast tracepoint at specified line or function.\n\
16429 BREAK_ARGS_HELP ("ftrace") "\n\
16430 Do \"help tracepoints\" for info on other tracepoint commands."));
16431 set_cmd_completer (c, location_completer);
16433 c = add_com ("strace", class_breakpoint, strace_command, _("\
16434 Set a static tracepoint at specified line, function or marker.\n\
16436 strace [LOCATION] [if CONDITION]\n\
16437 LOCATION may be a line number, function name, \"*\" and an address,\n\
16438 or -m MARKER_ID.\n\
16439 If a line number is specified, probe the marker at start of code\n\
16440 for that line. If a function is specified, probe the marker at start\n\
16441 of code for that function. If an address is specified, probe the marker\n\
16442 at that exact address. If a marker id is specified, probe the marker\n\
16443 with that name. With no LOCATION, uses current execution address of\n\
16444 the selected stack frame.\n\
16445 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16446 This collects arbitrary user data passed in the probe point call to the\n\
16447 tracing library. You can inspect it when analyzing the trace buffer,\n\
16448 by printing the $_sdata variable like any other convenience variable.\n\
16450 CONDITION is a boolean expression.\n\
16452 Multiple tracepoints at one place are permitted, and useful if their\n\
16453 conditions are different.\n\
16455 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16456 Do \"help tracepoints\" for info on other tracepoint commands."));
16457 set_cmd_completer (c, location_completer);
16459 add_info ("tracepoints", tracepoints_info, _("\
16460 Status of specified tracepoints (all tracepoints if no argument).\n\
16461 Convenience variable \"$tpnum\" contains the number of the\n\
16462 last tracepoint set."));
16464 add_info_alias ("tp", "tracepoints", 1);
16466 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16467 Delete specified tracepoints.\n\
16468 Arguments are tracepoint numbers, separated by spaces.\n\
16469 No argument means delete all tracepoints."),
16471 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16473 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16474 Disable specified tracepoints.\n\
16475 Arguments are tracepoint numbers, separated by spaces.\n\
16476 No argument means disable all tracepoints."),
16478 deprecate_cmd (c, "disable");
16480 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16481 Enable specified tracepoints.\n\
16482 Arguments are tracepoint numbers, separated by spaces.\n\
16483 No argument means enable all tracepoints."),
16485 deprecate_cmd (c, "enable");
16487 add_com ("passcount", class_trace, trace_pass_command, _("\
16488 Set the passcount for a tracepoint.\n\
16489 The trace will end when the tracepoint has been passed 'count' times.\n\
16490 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16491 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16493 add_prefix_cmd ("save", class_breakpoint, save_command,
16494 _("Save breakpoint definitions as a script."),
16495 &save_cmdlist, "save ",
16496 0/*allow-unknown*/, &cmdlist);
16498 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16499 Save current breakpoint definitions as a script.\n\
16500 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16501 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16502 session to restore them."),
16504 set_cmd_completer (c, filename_completer);
16506 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16507 Save current tracepoint definitions as a script.\n\
16508 Use the 'source' command in another debug session to restore them."),
16510 set_cmd_completer (c, filename_completer);
16512 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16513 deprecate_cmd (c, "save tracepoints");
16515 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16516 Breakpoint specific settings\n\
16517 Configure various breakpoint-specific variables such as\n\
16518 pending breakpoint behavior"),
16519 &breakpoint_set_cmdlist, "set breakpoint ",
16520 0/*allow-unknown*/, &setlist);
16521 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16522 Breakpoint specific settings\n\
16523 Configure various breakpoint-specific variables such as\n\
16524 pending breakpoint behavior"),
16525 &breakpoint_show_cmdlist, "show breakpoint ",
16526 0/*allow-unknown*/, &showlist);
16528 add_setshow_auto_boolean_cmd ("pending", no_class,
16529 &pending_break_support, _("\
16530 Set debugger's behavior regarding pending breakpoints."), _("\
16531 Show debugger's behavior regarding pending breakpoints."), _("\
16532 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16533 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16534 an error. If auto, an unrecognized breakpoint location results in a\n\
16535 user-query to see if a pending breakpoint should be created."),
16537 show_pending_break_support,
16538 &breakpoint_set_cmdlist,
16539 &breakpoint_show_cmdlist);
16541 pending_break_support = AUTO_BOOLEAN_AUTO;
16543 add_setshow_boolean_cmd ("auto-hw", no_class,
16544 &automatic_hardware_breakpoints, _("\
16545 Set automatic usage of hardware breakpoints."), _("\
16546 Show automatic usage of hardware breakpoints."), _("\
16547 If set, the debugger will automatically use hardware breakpoints for\n\
16548 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16549 a warning will be emitted for such breakpoints."),
16551 show_automatic_hardware_breakpoints,
16552 &breakpoint_set_cmdlist,
16553 &breakpoint_show_cmdlist);
16555 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16556 &always_inserted_mode, _("\
16557 Set mode for inserting breakpoints."), _("\
16558 Show mode for inserting breakpoints."), _("\
16559 When this mode is off, breakpoints are inserted in inferior when it is\n\
16560 resumed, and removed when execution stops. When this mode is on,\n\
16561 breakpoints are inserted immediately and removed only when the user\n\
16562 deletes the breakpoint. When this mode is auto (which is the default),\n\
16563 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16564 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16565 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16566 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16568 &show_always_inserted_mode,
16569 &breakpoint_set_cmdlist,
16570 &breakpoint_show_cmdlist);
16572 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16573 condition_evaluation_enums,
16574 &condition_evaluation_mode_1, _("\
16575 Set mode of breakpoint condition evaluation."), _("\
16576 Show mode of breakpoint condition evaluation."), _("\
16577 When this is set to \"host\", breakpoint conditions will be\n\
16578 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16579 breakpoint conditions will be downloaded to the target (if the target\n\
16580 supports such feature) and conditions will be evaluated on the target's side.\n\
16581 If this is set to \"auto\" (default), this will be automatically set to\n\
16582 \"target\" if it supports condition evaluation, otherwise it will\n\
16583 be set to \"gdb\""),
16584 &set_condition_evaluation_mode,
16585 &show_condition_evaluation_mode,
16586 &breakpoint_set_cmdlist,
16587 &breakpoint_show_cmdlist);
16589 add_com ("break-range", class_breakpoint, break_range_command, _("\
16590 Set a breakpoint for an address range.\n\
16591 break-range START-LOCATION, END-LOCATION\n\
16592 where START-LOCATION and END-LOCATION can be one of the following:\n\
16593 LINENUM, for that line in the current file,\n\
16594 FILE:LINENUM, for that line in that file,\n\
16595 +OFFSET, for that number of lines after the current line\n\
16596 or the start of the range\n\
16597 FUNCTION, for the first line in that function,\n\
16598 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16599 *ADDRESS, for the instruction at that address.\n\
16601 The breakpoint will stop execution of the inferior whenever it executes\n\
16602 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16603 range (including START-LOCATION and END-LOCATION)."));
16605 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16606 Set a dynamic printf at specified line or function.\n\
16607 dprintf location,format string,arg1,arg2,...\n\
16608 location may be a line number, function name, or \"*\" and an address.\n\
16609 If a line number is specified, break at start of code for that line.\n\
16610 If a function is specified, break at start of code for that function.\n\
16612 set_cmd_completer (c, location_completer);
16614 add_setshow_enum_cmd ("dprintf-style", class_support,
16615 dprintf_style_enums, &dprintf_style, _("\
16616 Set the style of usage for dynamic printf."), _("\
16617 Show the style of usage for dynamic printf."), _("\
16618 This setting chooses how GDB will do a dynamic printf.\n\
16619 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16620 console, as with the \"printf\" command.\n\
16621 If the value is \"call\", the print is done by calling a function in your\n\
16622 program; by default printf(), but you can choose a different function or\n\
16623 output stream by setting dprintf-function and dprintf-channel."),
16624 update_dprintf_commands, NULL,
16625 &setlist, &showlist);
16627 dprintf_function = xstrdup ("printf");
16628 add_setshow_string_cmd ("dprintf-function", class_support,
16629 &dprintf_function, _("\
16630 Set the function to use for dynamic printf"), _("\
16631 Show the function to use for dynamic printf"), NULL,
16632 update_dprintf_commands, NULL,
16633 &setlist, &showlist);
16635 dprintf_channel = xstrdup ("");
16636 add_setshow_string_cmd ("dprintf-channel", class_support,
16637 &dprintf_channel, _("\
16638 Set the channel to use for dynamic printf"), _("\
16639 Show the channel to use for dynamic printf"), NULL,
16640 update_dprintf_commands, NULL,
16641 &setlist, &showlist);
16643 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16644 &disconnected_dprintf, _("\
16645 Set whether dprintf continues after GDB disconnects."), _("\
16646 Show whether dprintf continues after GDB disconnects."), _("\
16647 Use this to let dprintf commands continue to hit and produce output\n\
16648 even if GDB disconnects or detaches from the target."),
16651 &setlist, &showlist);
16653 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16654 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16655 (target agent only) This is useful for formatted output in user-defined commands."));
16657 automatic_hardware_breakpoints = 1;
16659 observer_attach_about_to_proceed (breakpoint_about_to_proceed);