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_ARG parameter. If
9514 non-zero, the function will parse ARG, extracting location,
9515 condition, thread and extra string. Otherwise, ARG is just the
9516 breakpoint's location, with condition, thread, and extra string
9517 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9518 If INTERNAL is non-zero, the breakpoint number will be allocated
9519 from the internal breakpoint count. Returns true if any breakpoint
9520 was created; false otherwise. */
9523 create_breakpoint (struct gdbarch *gdbarch,
9524 char *arg, char *cond_string,
9525 int thread, char *extra_string,
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);
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;
9664 error (_("Garbage '%s' at end of location"), arg);
9666 /* Create a private copy of condition string. */
9669 cond_string = xstrdup (cond_string);
9670 make_cleanup (xfree, cond_string);
9672 /* Create a private copy of any extra string. */
9675 extra_string = xstrdup (extra_string);
9676 make_cleanup (xfree, extra_string);
9680 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9681 cond_string, extra_string, type_wanted,
9682 tempflag ? disp_del : disp_donttouch,
9683 thread, task, ignore_count, ops,
9684 from_tty, enabled, internal, flags);
9688 struct breakpoint *b;
9690 make_cleanup (xfree, copy_arg);
9692 if (is_tracepoint_type (type_wanted))
9694 struct tracepoint *t;
9696 t = XCNEW (struct tracepoint);
9700 b = XNEW (struct breakpoint);
9702 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9704 b->addr_string = copy_arg;
9706 b->cond_string = NULL;
9709 /* Create a private copy of condition string. */
9712 cond_string = xstrdup (cond_string);
9713 make_cleanup (xfree, cond_string);
9715 b->cond_string = cond_string;
9717 b->extra_string = NULL;
9718 b->ignore_count = ignore_count;
9719 b->disposition = tempflag ? disp_del : disp_donttouch;
9720 b->condition_not_parsed = 1;
9721 b->enable_state = enabled ? bp_enabled : bp_disabled;
9722 if ((type_wanted != bp_breakpoint
9723 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9724 b->pspace = current_program_space;
9726 install_breakpoint (internal, b, 0);
9729 if (VEC_length (linespec_sals, canonical.sals) > 1)
9731 warning (_("Multiple breakpoints were set.\nUse the "
9732 "\"delete\" command to delete unwanted breakpoints."));
9733 prev_breakpoint_count = prev_bkpt_count;
9736 /* That's it. Discard the cleanups for data inserted into the
9738 discard_cleanups (bkpt_chain);
9739 /* But cleanup everything else. */
9740 do_cleanups (old_chain);
9742 /* error call may happen here - have BKPT_CHAIN already discarded. */
9743 update_global_location_list (1);
9748 /* Set a breakpoint.
9749 ARG is a string describing breakpoint address,
9750 condition, and thread.
9751 FLAG specifies if a breakpoint is hardware on,
9752 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9756 break_command_1 (char *arg, int flag, int from_tty)
9758 int tempflag = flag & BP_TEMPFLAG;
9759 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9760 ? bp_hardware_breakpoint
9762 struct breakpoint_ops *ops;
9763 const char *arg_cp = arg;
9765 /* Matching breakpoints on probes. */
9766 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9767 ops = &bkpt_probe_breakpoint_ops;
9769 ops = &bkpt_breakpoint_ops;
9771 create_breakpoint (get_current_arch (),
9773 NULL, 0, NULL, 1 /* parse arg */,
9774 tempflag, type_wanted,
9775 0 /* Ignore count */,
9776 pending_break_support,
9784 /* Helper function for break_command_1 and disassemble_command. */
9787 resolve_sal_pc (struct symtab_and_line *sal)
9791 if (sal->pc == 0 && sal->symtab != NULL)
9793 if (!find_line_pc (sal->symtab, sal->line, &pc))
9794 error (_("No line %d in file \"%s\"."),
9795 sal->line, symtab_to_filename_for_display (sal->symtab));
9798 /* If this SAL corresponds to a breakpoint inserted using a line
9799 number, then skip the function prologue if necessary. */
9800 if (sal->explicit_line)
9801 skip_prologue_sal (sal);
9804 if (sal->section == 0 && sal->symtab != NULL)
9806 struct blockvector *bv;
9810 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9813 sym = block_linkage_function (b);
9816 fixup_symbol_section (sym, sal->symtab->objfile);
9817 sal->section = SYMBOL_OBJ_SECTION (sym);
9821 /* It really is worthwhile to have the section, so we'll
9822 just have to look harder. This case can be executed
9823 if we have line numbers but no functions (as can
9824 happen in assembly source). */
9826 struct bound_minimal_symbol msym;
9827 struct cleanup *old_chain = save_current_space_and_thread ();
9829 switch_to_program_space_and_thread (sal->pspace);
9831 msym = lookup_minimal_symbol_by_pc (sal->pc);
9833 sal->section = SYMBOL_OBJ_SECTION (msym.minsym);
9835 do_cleanups (old_chain);
9842 break_command (char *arg, int from_tty)
9844 break_command_1 (arg, 0, from_tty);
9848 tbreak_command (char *arg, int from_tty)
9850 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9854 hbreak_command (char *arg, int from_tty)
9856 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9860 thbreak_command (char *arg, int from_tty)
9862 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9866 stop_command (char *arg, int from_tty)
9868 printf_filtered (_("Specify the type of breakpoint to set.\n\
9869 Usage: stop in <function | address>\n\
9870 stop at <line>\n"));
9874 stopin_command (char *arg, int from_tty)
9878 if (arg == (char *) NULL)
9880 else if (*arg != '*')
9885 /* Look for a ':'. If this is a line number specification, then
9886 say it is bad, otherwise, it should be an address or
9887 function/method name. */
9888 while (*argptr && !hasColon)
9890 hasColon = (*argptr == ':');
9895 badInput = (*argptr != ':'); /* Not a class::method */
9897 badInput = isdigit (*arg); /* a simple line number */
9901 printf_filtered (_("Usage: stop in <function | address>\n"));
9903 break_command_1 (arg, 0, from_tty);
9907 stopat_command (char *arg, int from_tty)
9911 if (arg == (char *) NULL || *arg == '*') /* no line number */
9918 /* Look for a ':'. If there is a '::' then get out, otherwise
9919 it is probably a line number. */
9920 while (*argptr && !hasColon)
9922 hasColon = (*argptr == ':');
9927 badInput = (*argptr == ':'); /* we have class::method */
9929 badInput = !isdigit (*arg); /* not a line number */
9933 printf_filtered (_("Usage: stop at <line>\n"));
9935 break_command_1 (arg, 0, from_tty);
9938 /* The dynamic printf command is mostly like a regular breakpoint, but
9939 with a prewired command list consisting of a single output command,
9940 built from extra arguments supplied on the dprintf command
9944 dprintf_command (char *arg, int from_tty)
9946 create_breakpoint (get_current_arch (),
9948 NULL, 0, NULL, 1 /* parse arg */,
9950 0 /* Ignore count */,
9951 pending_break_support,
9952 &dprintf_breakpoint_ops,
9960 agent_printf_command (char *arg, int from_tty)
9962 error (_("May only run agent-printf on the target"));
9965 /* Implement the "breakpoint_hit" breakpoint_ops method for
9966 ranged breakpoints. */
9969 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9970 struct address_space *aspace,
9972 const struct target_waitstatus *ws)
9974 if (ws->kind != TARGET_WAITKIND_STOPPED
9975 || ws->value.sig != GDB_SIGNAL_TRAP)
9978 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9979 bl->length, aspace, bp_addr);
9982 /* Implement the "resources_needed" breakpoint_ops method for
9983 ranged breakpoints. */
9986 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9988 return target_ranged_break_num_registers ();
9991 /* Implement the "print_it" breakpoint_ops method for
9992 ranged breakpoints. */
9994 static enum print_stop_action
9995 print_it_ranged_breakpoint (bpstat bs)
9997 struct breakpoint *b = bs->breakpoint_at;
9998 struct bp_location *bl = b->loc;
9999 struct ui_out *uiout = current_uiout;
10001 gdb_assert (b->type == bp_hardware_breakpoint);
10003 /* Ranged breakpoints have only one location. */
10004 gdb_assert (bl && bl->next == NULL);
10006 annotate_breakpoint (b->number);
10007 if (b->disposition == disp_del)
10008 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10010 ui_out_text (uiout, "\nRanged breakpoint ");
10011 if (ui_out_is_mi_like_p (uiout))
10013 ui_out_field_string (uiout, "reason",
10014 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10015 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10017 ui_out_field_int (uiout, "bkptno", b->number);
10018 ui_out_text (uiout, ", ");
10020 return PRINT_SRC_AND_LOC;
10023 /* Implement the "print_one" breakpoint_ops method for
10024 ranged breakpoints. */
10027 print_one_ranged_breakpoint (struct breakpoint *b,
10028 struct bp_location **last_loc)
10030 struct bp_location *bl = b->loc;
10031 struct value_print_options opts;
10032 struct ui_out *uiout = current_uiout;
10034 /* Ranged breakpoints have only one location. */
10035 gdb_assert (bl && bl->next == NULL);
10037 get_user_print_options (&opts);
10039 if (opts.addressprint)
10040 /* We don't print the address range here, it will be printed later
10041 by print_one_detail_ranged_breakpoint. */
10042 ui_out_field_skip (uiout, "addr");
10043 annotate_field (5);
10044 print_breakpoint_location (b, bl);
10048 /* Implement the "print_one_detail" breakpoint_ops method for
10049 ranged breakpoints. */
10052 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10053 struct ui_out *uiout)
10055 CORE_ADDR address_start, address_end;
10056 struct bp_location *bl = b->loc;
10057 struct ui_file *stb = mem_fileopen ();
10058 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10062 address_start = bl->address;
10063 address_end = address_start + bl->length - 1;
10065 ui_out_text (uiout, "\taddress range: ");
10066 fprintf_unfiltered (stb, "[%s, %s]",
10067 print_core_address (bl->gdbarch, address_start),
10068 print_core_address (bl->gdbarch, address_end));
10069 ui_out_field_stream (uiout, "addr", stb);
10070 ui_out_text (uiout, "\n");
10072 do_cleanups (cleanup);
10075 /* Implement the "print_mention" breakpoint_ops method for
10076 ranged breakpoints. */
10079 print_mention_ranged_breakpoint (struct breakpoint *b)
10081 struct bp_location *bl = b->loc;
10082 struct ui_out *uiout = current_uiout;
10085 gdb_assert (b->type == bp_hardware_breakpoint);
10087 if (ui_out_is_mi_like_p (uiout))
10090 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10091 b->number, paddress (bl->gdbarch, bl->address),
10092 paddress (bl->gdbarch, bl->address + bl->length - 1));
10095 /* Implement the "print_recreate" breakpoint_ops method for
10096 ranged breakpoints. */
10099 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10101 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10102 b->addr_string_range_end);
10103 print_recreate_thread (b, fp);
10106 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10108 static struct breakpoint_ops ranged_breakpoint_ops;
10110 /* Find the address where the end of the breakpoint range should be
10111 placed, given the SAL of the end of the range. This is so that if
10112 the user provides a line number, the end of the range is set to the
10113 last instruction of the given line. */
10116 find_breakpoint_range_end (struct symtab_and_line sal)
10120 /* If the user provided a PC value, use it. Otherwise,
10121 find the address of the end of the given location. */
10122 if (sal.explicit_pc)
10129 ret = find_line_pc_range (sal, &start, &end);
10131 error (_("Could not find location of the end of the range."));
10133 /* find_line_pc_range returns the start of the next line. */
10140 /* Implement the "break-range" CLI command. */
10143 break_range_command (char *arg, int from_tty)
10145 char *arg_start, *addr_string_start, *addr_string_end;
10146 struct linespec_result canonical_start, canonical_end;
10147 int bp_count, can_use_bp, length;
10149 struct breakpoint *b;
10150 struct symtab_and_line sal_start, sal_end;
10151 struct cleanup *cleanup_bkpt;
10152 struct linespec_sals *lsal_start, *lsal_end;
10154 /* We don't support software ranged breakpoints. */
10155 if (target_ranged_break_num_registers () < 0)
10156 error (_("This target does not support hardware ranged breakpoints."));
10158 bp_count = hw_breakpoint_used_count ();
10159 bp_count += target_ranged_break_num_registers ();
10160 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10162 if (can_use_bp < 0)
10163 error (_("Hardware breakpoints used exceeds limit."));
10165 arg = skip_spaces (arg);
10166 if (arg == NULL || arg[0] == '\0')
10167 error(_("No address range specified."));
10169 init_linespec_result (&canonical_start);
10172 parse_breakpoint_sals (&arg, &canonical_start);
10174 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10177 error (_("Too few arguments."));
10178 else if (VEC_empty (linespec_sals, canonical_start.sals))
10179 error (_("Could not find location of the beginning of the range."));
10181 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10183 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10184 || lsal_start->sals.nelts != 1)
10185 error (_("Cannot create a ranged breakpoint with multiple locations."));
10187 sal_start = lsal_start->sals.sals[0];
10188 addr_string_start = savestring (arg_start, arg - arg_start);
10189 make_cleanup (xfree, addr_string_start);
10191 arg++; /* Skip the comma. */
10192 arg = skip_spaces (arg);
10194 /* Parse the end location. */
10196 init_linespec_result (&canonical_end);
10199 /* We call decode_line_full directly here instead of using
10200 parse_breakpoint_sals because we need to specify the start location's
10201 symtab and line as the default symtab and line for the end of the
10202 range. This makes it possible to have ranges like "foo.c:27, +14",
10203 where +14 means 14 lines from the start location. */
10204 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10205 sal_start.symtab, sal_start.line,
10206 &canonical_end, NULL, NULL);
10208 make_cleanup_destroy_linespec_result (&canonical_end);
10210 if (VEC_empty (linespec_sals, canonical_end.sals))
10211 error (_("Could not find location of the end of the range."));
10213 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10214 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10215 || lsal_end->sals.nelts != 1)
10216 error (_("Cannot create a ranged breakpoint with multiple locations."));
10218 sal_end = lsal_end->sals.sals[0];
10219 addr_string_end = savestring (arg_start, arg - arg_start);
10220 make_cleanup (xfree, addr_string_end);
10222 end = find_breakpoint_range_end (sal_end);
10223 if (sal_start.pc > end)
10224 error (_("Invalid address range, end precedes start."));
10226 length = end - sal_start.pc + 1;
10228 /* Length overflowed. */
10229 error (_("Address range too large."));
10230 else if (length == 1)
10232 /* This range is simple enough to be handled by
10233 the `hbreak' command. */
10234 hbreak_command (addr_string_start, 1);
10236 do_cleanups (cleanup_bkpt);
10241 /* Now set up the breakpoint. */
10242 b = set_raw_breakpoint (get_current_arch (), sal_start,
10243 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10244 set_breakpoint_count (breakpoint_count + 1);
10245 b->number = breakpoint_count;
10246 b->disposition = disp_donttouch;
10247 b->addr_string = xstrdup (addr_string_start);
10248 b->addr_string_range_end = xstrdup (addr_string_end);
10249 b->loc->length = length;
10251 do_cleanups (cleanup_bkpt);
10254 observer_notify_breakpoint_created (b);
10255 update_global_location_list (1);
10258 /* Return non-zero if EXP is verified as constant. Returned zero
10259 means EXP is variable. Also the constant detection may fail for
10260 some constant expressions and in such case still falsely return
10264 watchpoint_exp_is_const (const struct expression *exp)
10266 int i = exp->nelts;
10272 /* We are only interested in the descriptor of each element. */
10273 operator_length (exp, i, &oplenp, &argsp);
10276 switch (exp->elts[i].opcode)
10286 case BINOP_LOGICAL_AND:
10287 case BINOP_LOGICAL_OR:
10288 case BINOP_BITWISE_AND:
10289 case BINOP_BITWISE_IOR:
10290 case BINOP_BITWISE_XOR:
10292 case BINOP_NOTEQUAL:
10320 case OP_OBJC_NSSTRING:
10323 case UNOP_LOGICAL_NOT:
10324 case UNOP_COMPLEMENT:
10329 case UNOP_CAST_TYPE:
10330 case UNOP_REINTERPRET_CAST:
10331 case UNOP_DYNAMIC_CAST:
10332 /* Unary, binary and ternary operators: We have to check
10333 their operands. If they are constant, then so is the
10334 result of that operation. For instance, if A and B are
10335 determined to be constants, then so is "A + B".
10337 UNOP_IND is one exception to the rule above, because the
10338 value of *ADDR is not necessarily a constant, even when
10343 /* Check whether the associated symbol is a constant.
10345 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10346 possible that a buggy compiler could mark a variable as
10347 constant even when it is not, and TYPE_CONST would return
10348 true in this case, while SYMBOL_CLASS wouldn't.
10350 We also have to check for function symbols because they
10351 are always constant. */
10353 struct symbol *s = exp->elts[i + 2].symbol;
10355 if (SYMBOL_CLASS (s) != LOC_BLOCK
10356 && SYMBOL_CLASS (s) != LOC_CONST
10357 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10362 /* The default action is to return 0 because we are using
10363 the optimistic approach here: If we don't know something,
10364 then it is not a constant. */
10373 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10376 dtor_watchpoint (struct breakpoint *self)
10378 struct watchpoint *w = (struct watchpoint *) self;
10380 xfree (w->cond_exp);
10382 xfree (w->exp_string);
10383 xfree (w->exp_string_reparse);
10384 value_free (w->val);
10386 base_breakpoint_ops.dtor (self);
10389 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10392 re_set_watchpoint (struct breakpoint *b)
10394 struct watchpoint *w = (struct watchpoint *) b;
10396 /* Watchpoint can be either on expression using entirely global
10397 variables, or it can be on local variables.
10399 Watchpoints of the first kind are never auto-deleted, and even
10400 persist across program restarts. Since they can use variables
10401 from shared libraries, we need to reparse expression as libraries
10402 are loaded and unloaded.
10404 Watchpoints on local variables can also change meaning as result
10405 of solib event. For example, if a watchpoint uses both a local
10406 and a global variables in expression, it's a local watchpoint,
10407 but unloading of a shared library will make the expression
10408 invalid. This is not a very common use case, but we still
10409 re-evaluate expression, to avoid surprises to the user.
10411 Note that for local watchpoints, we re-evaluate it only if
10412 watchpoints frame id is still valid. If it's not, it means the
10413 watchpoint is out of scope and will be deleted soon. In fact,
10414 I'm not sure we'll ever be called in this case.
10416 If a local watchpoint's frame id is still valid, then
10417 w->exp_valid_block is likewise valid, and we can safely use it.
10419 Don't do anything about disabled watchpoints, since they will be
10420 reevaluated again when enabled. */
10421 update_watchpoint (w, 1 /* reparse */);
10424 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10427 insert_watchpoint (struct bp_location *bl)
10429 struct watchpoint *w = (struct watchpoint *) bl->owner;
10430 int length = w->exact ? 1 : bl->length;
10432 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10436 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10439 remove_watchpoint (struct bp_location *bl)
10441 struct watchpoint *w = (struct watchpoint *) bl->owner;
10442 int length = w->exact ? 1 : bl->length;
10444 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10449 breakpoint_hit_watchpoint (const struct bp_location *bl,
10450 struct address_space *aspace, CORE_ADDR bp_addr,
10451 const struct target_waitstatus *ws)
10453 struct breakpoint *b = bl->owner;
10454 struct watchpoint *w = (struct watchpoint *) b;
10456 /* Continuable hardware watchpoints are treated as non-existent if the
10457 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10458 some data address). Otherwise gdb won't stop on a break instruction
10459 in the code (not from a breakpoint) when a hardware watchpoint has
10460 been defined. Also skip watchpoints which we know did not trigger
10461 (did not match the data address). */
10462 if (is_hardware_watchpoint (b)
10463 && w->watchpoint_triggered == watch_triggered_no)
10470 check_status_watchpoint (bpstat bs)
10472 gdb_assert (is_watchpoint (bs->breakpoint_at));
10474 bpstat_check_watchpoint (bs);
10477 /* Implement the "resources_needed" breakpoint_ops method for
10478 hardware watchpoints. */
10481 resources_needed_watchpoint (const struct bp_location *bl)
10483 struct watchpoint *w = (struct watchpoint *) bl->owner;
10484 int length = w->exact? 1 : bl->length;
10486 return target_region_ok_for_hw_watchpoint (bl->address, length);
10489 /* Implement the "works_in_software_mode" breakpoint_ops method for
10490 hardware watchpoints. */
10493 works_in_software_mode_watchpoint (const struct breakpoint *b)
10495 /* Read and access watchpoints only work with hardware support. */
10496 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10499 static enum print_stop_action
10500 print_it_watchpoint (bpstat bs)
10502 struct cleanup *old_chain;
10503 struct breakpoint *b;
10504 struct ui_file *stb;
10505 enum print_stop_action result;
10506 struct watchpoint *w;
10507 struct ui_out *uiout = current_uiout;
10509 gdb_assert (bs->bp_location_at != NULL);
10511 b = bs->breakpoint_at;
10512 w = (struct watchpoint *) b;
10514 stb = mem_fileopen ();
10515 old_chain = make_cleanup_ui_file_delete (stb);
10519 case bp_watchpoint:
10520 case bp_hardware_watchpoint:
10521 annotate_watchpoint (b->number);
10522 if (ui_out_is_mi_like_p (uiout))
10523 ui_out_field_string
10525 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10527 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10528 ui_out_text (uiout, "\nOld value = ");
10529 watchpoint_value_print (bs->old_val, stb);
10530 ui_out_field_stream (uiout, "old", stb);
10531 ui_out_text (uiout, "\nNew value = ");
10532 watchpoint_value_print (w->val, stb);
10533 ui_out_field_stream (uiout, "new", stb);
10534 ui_out_text (uiout, "\n");
10535 /* More than one watchpoint may have been triggered. */
10536 result = PRINT_UNKNOWN;
10539 case bp_read_watchpoint:
10540 if (ui_out_is_mi_like_p (uiout))
10541 ui_out_field_string
10543 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10545 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10546 ui_out_text (uiout, "\nValue = ");
10547 watchpoint_value_print (w->val, stb);
10548 ui_out_field_stream (uiout, "value", stb);
10549 ui_out_text (uiout, "\n");
10550 result = PRINT_UNKNOWN;
10553 case bp_access_watchpoint:
10554 if (bs->old_val != NULL)
10556 annotate_watchpoint (b->number);
10557 if (ui_out_is_mi_like_p (uiout))
10558 ui_out_field_string
10560 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10562 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10563 ui_out_text (uiout, "\nOld value = ");
10564 watchpoint_value_print (bs->old_val, stb);
10565 ui_out_field_stream (uiout, "old", stb);
10566 ui_out_text (uiout, "\nNew value = ");
10571 if (ui_out_is_mi_like_p (uiout))
10572 ui_out_field_string
10574 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10575 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10576 ui_out_text (uiout, "\nValue = ");
10578 watchpoint_value_print (w->val, stb);
10579 ui_out_field_stream (uiout, "new", stb);
10580 ui_out_text (uiout, "\n");
10581 result = PRINT_UNKNOWN;
10584 result = PRINT_UNKNOWN;
10587 do_cleanups (old_chain);
10591 /* Implement the "print_mention" breakpoint_ops method for hardware
10595 print_mention_watchpoint (struct breakpoint *b)
10597 struct cleanup *ui_out_chain;
10598 struct watchpoint *w = (struct watchpoint *) b;
10599 struct ui_out *uiout = current_uiout;
10603 case bp_watchpoint:
10604 ui_out_text (uiout, "Watchpoint ");
10605 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10607 case bp_hardware_watchpoint:
10608 ui_out_text (uiout, "Hardware watchpoint ");
10609 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10611 case bp_read_watchpoint:
10612 ui_out_text (uiout, "Hardware read watchpoint ");
10613 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10615 case bp_access_watchpoint:
10616 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10617 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10620 internal_error (__FILE__, __LINE__,
10621 _("Invalid hardware watchpoint type."));
10624 ui_out_field_int (uiout, "number", b->number);
10625 ui_out_text (uiout, ": ");
10626 ui_out_field_string (uiout, "exp", w->exp_string);
10627 do_cleanups (ui_out_chain);
10630 /* Implement the "print_recreate" breakpoint_ops method for
10634 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10636 struct watchpoint *w = (struct watchpoint *) b;
10640 case bp_watchpoint:
10641 case bp_hardware_watchpoint:
10642 fprintf_unfiltered (fp, "watch");
10644 case bp_read_watchpoint:
10645 fprintf_unfiltered (fp, "rwatch");
10647 case bp_access_watchpoint:
10648 fprintf_unfiltered (fp, "awatch");
10651 internal_error (__FILE__, __LINE__,
10652 _("Invalid watchpoint type."));
10655 fprintf_unfiltered (fp, " %s", w->exp_string);
10656 print_recreate_thread (b, fp);
10659 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10661 static struct breakpoint_ops watchpoint_breakpoint_ops;
10663 /* Implement the "insert" breakpoint_ops method for
10664 masked hardware watchpoints. */
10667 insert_masked_watchpoint (struct bp_location *bl)
10669 struct watchpoint *w = (struct watchpoint *) bl->owner;
10671 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10672 bl->watchpoint_type);
10675 /* Implement the "remove" breakpoint_ops method for
10676 masked hardware watchpoints. */
10679 remove_masked_watchpoint (struct bp_location *bl)
10681 struct watchpoint *w = (struct watchpoint *) bl->owner;
10683 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10684 bl->watchpoint_type);
10687 /* Implement the "resources_needed" breakpoint_ops method for
10688 masked hardware watchpoints. */
10691 resources_needed_masked_watchpoint (const struct bp_location *bl)
10693 struct watchpoint *w = (struct watchpoint *) bl->owner;
10695 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10698 /* Implement the "works_in_software_mode" breakpoint_ops method for
10699 masked hardware watchpoints. */
10702 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10707 /* Implement the "print_it" breakpoint_ops method for
10708 masked hardware watchpoints. */
10710 static enum print_stop_action
10711 print_it_masked_watchpoint (bpstat bs)
10713 struct breakpoint *b = bs->breakpoint_at;
10714 struct ui_out *uiout = current_uiout;
10716 /* Masked watchpoints have only one location. */
10717 gdb_assert (b->loc && b->loc->next == NULL);
10721 case bp_hardware_watchpoint:
10722 annotate_watchpoint (b->number);
10723 if (ui_out_is_mi_like_p (uiout))
10724 ui_out_field_string
10726 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10729 case bp_read_watchpoint:
10730 if (ui_out_is_mi_like_p (uiout))
10731 ui_out_field_string
10733 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10736 case bp_access_watchpoint:
10737 if (ui_out_is_mi_like_p (uiout))
10738 ui_out_field_string
10740 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10743 internal_error (__FILE__, __LINE__,
10744 _("Invalid hardware watchpoint type."));
10748 ui_out_text (uiout, _("\n\
10749 Check the underlying instruction at PC for the memory\n\
10750 address and value which triggered this watchpoint.\n"));
10751 ui_out_text (uiout, "\n");
10753 /* More than one watchpoint may have been triggered. */
10754 return PRINT_UNKNOWN;
10757 /* Implement the "print_one_detail" breakpoint_ops method for
10758 masked hardware watchpoints. */
10761 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10762 struct ui_out *uiout)
10764 struct watchpoint *w = (struct watchpoint *) b;
10766 /* Masked watchpoints have only one location. */
10767 gdb_assert (b->loc && b->loc->next == NULL);
10769 ui_out_text (uiout, "\tmask ");
10770 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10771 ui_out_text (uiout, "\n");
10774 /* Implement the "print_mention" breakpoint_ops method for
10775 masked hardware watchpoints. */
10778 print_mention_masked_watchpoint (struct breakpoint *b)
10780 struct watchpoint *w = (struct watchpoint *) b;
10781 struct ui_out *uiout = current_uiout;
10782 struct cleanup *ui_out_chain;
10786 case bp_hardware_watchpoint:
10787 ui_out_text (uiout, "Masked hardware watchpoint ");
10788 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10790 case bp_read_watchpoint:
10791 ui_out_text (uiout, "Masked hardware read watchpoint ");
10792 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10794 case bp_access_watchpoint:
10795 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10796 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10799 internal_error (__FILE__, __LINE__,
10800 _("Invalid hardware watchpoint type."));
10803 ui_out_field_int (uiout, "number", b->number);
10804 ui_out_text (uiout, ": ");
10805 ui_out_field_string (uiout, "exp", w->exp_string);
10806 do_cleanups (ui_out_chain);
10809 /* Implement the "print_recreate" breakpoint_ops method for
10810 masked hardware watchpoints. */
10813 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10815 struct watchpoint *w = (struct watchpoint *) b;
10820 case bp_hardware_watchpoint:
10821 fprintf_unfiltered (fp, "watch");
10823 case bp_read_watchpoint:
10824 fprintf_unfiltered (fp, "rwatch");
10826 case bp_access_watchpoint:
10827 fprintf_unfiltered (fp, "awatch");
10830 internal_error (__FILE__, __LINE__,
10831 _("Invalid hardware watchpoint type."));
10834 sprintf_vma (tmp, w->hw_wp_mask);
10835 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10836 print_recreate_thread (b, fp);
10839 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10841 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10843 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10846 is_masked_watchpoint (const struct breakpoint *b)
10848 return b->ops == &masked_watchpoint_breakpoint_ops;
10851 /* accessflag: hw_write: watch write,
10852 hw_read: watch read,
10853 hw_access: watch access (read or write) */
10855 watch_command_1 (const char *arg, int accessflag, int from_tty,
10856 int just_location, int internal)
10858 volatile struct gdb_exception e;
10859 struct breakpoint *b, *scope_breakpoint = NULL;
10860 struct expression *exp;
10861 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10862 struct value *val, *mark, *result;
10863 struct frame_info *frame;
10864 const char *exp_start = NULL;
10865 const char *exp_end = NULL;
10866 const char *tok, *end_tok;
10868 const char *cond_start = NULL;
10869 const char *cond_end = NULL;
10870 enum bptype bp_type;
10873 /* Flag to indicate whether we are going to use masks for
10874 the hardware watchpoint. */
10876 CORE_ADDR mask = 0;
10877 struct watchpoint *w;
10879 struct cleanup *back_to;
10881 /* Make sure that we actually have parameters to parse. */
10882 if (arg != NULL && arg[0] != '\0')
10884 const char *value_start;
10886 exp_end = arg + strlen (arg);
10888 /* Look for "parameter value" pairs at the end
10889 of the arguments string. */
10890 for (tok = exp_end - 1; tok > arg; tok--)
10892 /* Skip whitespace at the end of the argument list. */
10893 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10896 /* Find the beginning of the last token.
10897 This is the value of the parameter. */
10898 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10900 value_start = tok + 1;
10902 /* Skip whitespace. */
10903 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10908 /* Find the beginning of the second to last token.
10909 This is the parameter itself. */
10910 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10913 toklen = end_tok - tok + 1;
10915 if (toklen == 6 && !strncmp (tok, "thread", 6))
10917 /* At this point we've found a "thread" token, which means
10918 the user is trying to set a watchpoint that triggers
10919 only in a specific thread. */
10923 error(_("You can specify only one thread."));
10925 /* Extract the thread ID from the next token. */
10926 thread = strtol (value_start, &endp, 0);
10928 /* Check if the user provided a valid numeric value for the
10930 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10931 error (_("Invalid thread ID specification %s."), value_start);
10933 /* Check if the thread actually exists. */
10934 if (!valid_thread_id (thread))
10935 invalid_thread_id_error (thread);
10937 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10939 /* We've found a "mask" token, which means the user wants to
10940 create a hardware watchpoint that is going to have the mask
10942 struct value *mask_value, *mark;
10945 error(_("You can specify only one mask."));
10947 use_mask = just_location = 1;
10949 mark = value_mark ();
10950 mask_value = parse_to_comma_and_eval (&value_start);
10951 mask = value_as_address (mask_value);
10952 value_free_to_mark (mark);
10955 /* We didn't recognize what we found. We should stop here. */
10958 /* Truncate the string and get rid of the "parameter value" pair before
10959 the arguments string is parsed by the parse_exp_1 function. */
10966 /* Parse the rest of the arguments. From here on out, everything
10967 is in terms of a newly allocated string instead of the original
10969 innermost_block = NULL;
10970 expression = savestring (arg, exp_end - arg);
10971 back_to = make_cleanup (xfree, expression);
10972 exp_start = arg = expression;
10973 exp = parse_exp_1 (&arg, 0, 0, 0);
10975 /* Remove trailing whitespace from the expression before saving it.
10976 This makes the eventual display of the expression string a bit
10978 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10981 /* Checking if the expression is not constant. */
10982 if (watchpoint_exp_is_const (exp))
10986 len = exp_end - exp_start;
10987 while (len > 0 && isspace (exp_start[len - 1]))
10989 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10992 exp_valid_block = innermost_block;
10993 mark = value_mark ();
10994 fetch_subexp_value (exp, &pc, &val, &result, NULL);
11000 exp_valid_block = NULL;
11001 val = value_addr (result);
11002 release_value (val);
11003 value_free_to_mark (mark);
11007 ret = target_masked_watch_num_registers (value_as_address (val),
11010 error (_("This target does not support masked watchpoints."));
11011 else if (ret == -2)
11012 error (_("Invalid mask or memory region."));
11015 else if (val != NULL)
11016 release_value (val);
11018 tok = skip_spaces_const (arg);
11019 end_tok = skip_to_space_const (tok);
11021 toklen = end_tok - tok;
11022 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11024 struct expression *cond;
11026 innermost_block = NULL;
11027 tok = cond_start = end_tok + 1;
11028 cond = parse_exp_1 (&tok, 0, 0, 0);
11030 /* The watchpoint expression may not be local, but the condition
11031 may still be. E.g.: `watch global if local > 0'. */
11032 cond_exp_valid_block = innermost_block;
11038 error (_("Junk at end of command."));
11040 if (accessflag == hw_read)
11041 bp_type = bp_read_watchpoint;
11042 else if (accessflag == hw_access)
11043 bp_type = bp_access_watchpoint;
11045 bp_type = bp_hardware_watchpoint;
11047 frame = block_innermost_frame (exp_valid_block);
11049 /* If the expression is "local", then set up a "watchpoint scope"
11050 breakpoint at the point where we've left the scope of the watchpoint
11051 expression. Create the scope breakpoint before the watchpoint, so
11052 that we will encounter it first in bpstat_stop_status. */
11053 if (exp_valid_block && frame)
11055 if (frame_id_p (frame_unwind_caller_id (frame)))
11058 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11059 frame_unwind_caller_pc (frame),
11060 bp_watchpoint_scope,
11061 &momentary_breakpoint_ops);
11063 scope_breakpoint->enable_state = bp_enabled;
11065 /* Automatically delete the breakpoint when it hits. */
11066 scope_breakpoint->disposition = disp_del;
11068 /* Only break in the proper frame (help with recursion). */
11069 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11071 /* Set the address at which we will stop. */
11072 scope_breakpoint->loc->gdbarch
11073 = frame_unwind_caller_arch (frame);
11074 scope_breakpoint->loc->requested_address
11075 = frame_unwind_caller_pc (frame);
11076 scope_breakpoint->loc->address
11077 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11078 scope_breakpoint->loc->requested_address,
11079 scope_breakpoint->type);
11083 /* Now set up the breakpoint. */
11085 w = XCNEW (struct watchpoint);
11088 init_raw_breakpoint_without_location (b, NULL, bp_type,
11089 &masked_watchpoint_breakpoint_ops);
11091 init_raw_breakpoint_without_location (b, NULL, bp_type,
11092 &watchpoint_breakpoint_ops);
11093 b->thread = thread;
11094 b->disposition = disp_donttouch;
11095 b->pspace = current_program_space;
11097 w->exp_valid_block = exp_valid_block;
11098 w->cond_exp_valid_block = cond_exp_valid_block;
11101 struct type *t = value_type (val);
11102 CORE_ADDR addr = value_as_address (val);
11105 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11106 name = type_to_string (t);
11108 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11109 core_addr_to_string (addr));
11112 w->exp_string = xstrprintf ("-location %.*s",
11113 (int) (exp_end - exp_start), exp_start);
11115 /* The above expression is in C. */
11116 b->language = language_c;
11119 w->exp_string = savestring (exp_start, exp_end - exp_start);
11123 w->hw_wp_mask = mask;
11132 b->cond_string = savestring (cond_start, cond_end - cond_start);
11134 b->cond_string = 0;
11138 w->watchpoint_frame = get_frame_id (frame);
11139 w->watchpoint_thread = inferior_ptid;
11143 w->watchpoint_frame = null_frame_id;
11144 w->watchpoint_thread = null_ptid;
11147 if (scope_breakpoint != NULL)
11149 /* The scope breakpoint is related to the watchpoint. We will
11150 need to act on them together. */
11151 b->related_breakpoint = scope_breakpoint;
11152 scope_breakpoint->related_breakpoint = b;
11155 if (!just_location)
11156 value_free_to_mark (mark);
11158 TRY_CATCH (e, RETURN_MASK_ALL)
11160 /* Finally update the new watchpoint. This creates the locations
11161 that should be inserted. */
11162 update_watchpoint (w, 1);
11166 delete_breakpoint (b);
11167 throw_exception (e);
11170 install_breakpoint (internal, b, 1);
11171 do_cleanups (back_to);
11174 /* Return count of debug registers needed to watch the given expression.
11175 If the watchpoint cannot be handled in hardware return zero. */
11178 can_use_hardware_watchpoint (struct value *v)
11180 int found_memory_cnt = 0;
11181 struct value *head = v;
11183 /* Did the user specifically forbid us to use hardware watchpoints? */
11184 if (!can_use_hw_watchpoints)
11187 /* Make sure that the value of the expression depends only upon
11188 memory contents, and values computed from them within GDB. If we
11189 find any register references or function calls, we can't use a
11190 hardware watchpoint.
11192 The idea here is that evaluating an expression generates a series
11193 of values, one holding the value of every subexpression. (The
11194 expression a*b+c has five subexpressions: a, b, a*b, c, and
11195 a*b+c.) GDB's values hold almost enough information to establish
11196 the criteria given above --- they identify memory lvalues,
11197 register lvalues, computed values, etcetera. So we can evaluate
11198 the expression, and then scan the chain of values that leaves
11199 behind to decide whether we can detect any possible change to the
11200 expression's final value using only hardware watchpoints.
11202 However, I don't think that the values returned by inferior
11203 function calls are special in any way. So this function may not
11204 notice that an expression involving an inferior function call
11205 can't be watched with hardware watchpoints. FIXME. */
11206 for (; v; v = value_next (v))
11208 if (VALUE_LVAL (v) == lval_memory)
11210 if (v != head && value_lazy (v))
11211 /* A lazy memory lvalue in the chain is one that GDB never
11212 needed to fetch; we either just used its address (e.g.,
11213 `a' in `a.b') or we never needed it at all (e.g., `a'
11214 in `a,b'). This doesn't apply to HEAD; if that is
11215 lazy then it was not readable, but watch it anyway. */
11219 /* Ahh, memory we actually used! Check if we can cover
11220 it with hardware watchpoints. */
11221 struct type *vtype = check_typedef (value_type (v));
11223 /* We only watch structs and arrays if user asked for it
11224 explicitly, never if they just happen to appear in a
11225 middle of some value chain. */
11227 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11228 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11230 CORE_ADDR vaddr = value_address (v);
11234 len = (target_exact_watchpoints
11235 && is_scalar_type_recursive (vtype))?
11236 1 : TYPE_LENGTH (value_type (v));
11238 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11242 found_memory_cnt += num_regs;
11246 else if (VALUE_LVAL (v) != not_lval
11247 && deprecated_value_modifiable (v) == 0)
11248 return 0; /* These are values from the history (e.g., $1). */
11249 else if (VALUE_LVAL (v) == lval_register)
11250 return 0; /* Cannot watch a register with a HW watchpoint. */
11253 /* The expression itself looks suitable for using a hardware
11254 watchpoint, but give the target machine a chance to reject it. */
11255 return found_memory_cnt;
11259 watch_command_wrapper (char *arg, int from_tty, int internal)
11261 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11264 /* A helper function that looks for the "-location" argument and then
11265 calls watch_command_1. */
11268 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11270 int just_location = 0;
11273 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11274 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11276 arg = skip_spaces (arg);
11280 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11284 watch_command (char *arg, int from_tty)
11286 watch_maybe_just_location (arg, hw_write, from_tty);
11290 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11292 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11296 rwatch_command (char *arg, int from_tty)
11298 watch_maybe_just_location (arg, hw_read, from_tty);
11302 awatch_command_wrapper (char *arg, int from_tty, int internal)
11304 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11308 awatch_command (char *arg, int from_tty)
11310 watch_maybe_just_location (arg, hw_access, from_tty);
11314 /* Helper routines for the until_command routine in infcmd.c. Here
11315 because it uses the mechanisms of breakpoints. */
11317 struct until_break_command_continuation_args
11319 struct breakpoint *breakpoint;
11320 struct breakpoint *breakpoint2;
11324 /* This function is called by fetch_inferior_event via the
11325 cmd_continuation pointer, to complete the until command. It takes
11326 care of cleaning up the temporary breakpoints set up by the until
11329 until_break_command_continuation (void *arg, int err)
11331 struct until_break_command_continuation_args *a = arg;
11333 delete_breakpoint (a->breakpoint);
11334 if (a->breakpoint2)
11335 delete_breakpoint (a->breakpoint2);
11336 delete_longjmp_breakpoint (a->thread_num);
11340 until_break_command (char *arg, int from_tty, int anywhere)
11342 struct symtabs_and_lines sals;
11343 struct symtab_and_line sal;
11344 struct frame_info *frame;
11345 struct gdbarch *frame_gdbarch;
11346 struct frame_id stack_frame_id;
11347 struct frame_id caller_frame_id;
11348 struct breakpoint *breakpoint;
11349 struct breakpoint *breakpoint2 = NULL;
11350 struct cleanup *old_chain;
11352 struct thread_info *tp;
11354 clear_proceed_status ();
11356 /* Set a breakpoint where the user wants it and at return from
11359 if (last_displayed_sal_is_valid ())
11360 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11361 get_last_displayed_symtab (),
11362 get_last_displayed_line ());
11364 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11365 (struct symtab *) NULL, 0);
11367 if (sals.nelts != 1)
11368 error (_("Couldn't get information on specified line."));
11370 sal = sals.sals[0];
11371 xfree (sals.sals); /* malloc'd, so freed. */
11374 error (_("Junk at end of arguments."));
11376 resolve_sal_pc (&sal);
11378 tp = inferior_thread ();
11381 old_chain = make_cleanup (null_cleanup, NULL);
11383 /* Note linespec handling above invalidates the frame chain.
11384 Installing a breakpoint also invalidates the frame chain (as it
11385 may need to switch threads), so do any frame handling before
11388 frame = get_selected_frame (NULL);
11389 frame_gdbarch = get_frame_arch (frame);
11390 stack_frame_id = get_stack_frame_id (frame);
11391 caller_frame_id = frame_unwind_caller_id (frame);
11393 /* Keep within the current frame, or in frames called by the current
11396 if (frame_id_p (caller_frame_id))
11398 struct symtab_and_line sal2;
11400 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11401 sal2.pc = frame_unwind_caller_pc (frame);
11402 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11406 make_cleanup_delete_breakpoint (breakpoint2);
11408 set_longjmp_breakpoint (tp, caller_frame_id);
11409 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11412 /* set_momentary_breakpoint could invalidate FRAME. */
11416 /* If the user told us to continue until a specified location,
11417 we don't specify a frame at which we need to stop. */
11418 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11419 null_frame_id, bp_until);
11421 /* Otherwise, specify the selected frame, because we want to stop
11422 only at the very same frame. */
11423 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11424 stack_frame_id, bp_until);
11425 make_cleanup_delete_breakpoint (breakpoint);
11427 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11429 /* If we are running asynchronously, and proceed call above has
11430 actually managed to start the target, arrange for breakpoints to
11431 be deleted when the target stops. Otherwise, we're already
11432 stopped and delete breakpoints via cleanup chain. */
11434 if (target_can_async_p () && is_running (inferior_ptid))
11436 struct until_break_command_continuation_args *args;
11437 args = xmalloc (sizeof (*args));
11439 args->breakpoint = breakpoint;
11440 args->breakpoint2 = breakpoint2;
11441 args->thread_num = thread;
11443 discard_cleanups (old_chain);
11444 add_continuation (inferior_thread (),
11445 until_break_command_continuation, args,
11449 do_cleanups (old_chain);
11452 /* This function attempts to parse an optional "if <cond>" clause
11453 from the arg string. If one is not found, it returns NULL.
11455 Else, it returns a pointer to the condition string. (It does not
11456 attempt to evaluate the string against a particular block.) And,
11457 it updates arg to point to the first character following the parsed
11458 if clause in the arg string. */
11461 ep_parse_optional_if_clause (char **arg)
11465 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11468 /* Skip the "if" keyword. */
11471 /* Skip any extra leading whitespace, and record the start of the
11472 condition string. */
11473 *arg = skip_spaces (*arg);
11474 cond_string = *arg;
11476 /* Assume that the condition occupies the remainder of the arg
11478 (*arg) += strlen (cond_string);
11480 return cond_string;
11483 /* Commands to deal with catching events, such as signals, exceptions,
11484 process start/exit, etc. */
11488 catch_fork_temporary, catch_vfork_temporary,
11489 catch_fork_permanent, catch_vfork_permanent
11494 catch_fork_command_1 (char *arg, int from_tty,
11495 struct cmd_list_element *command)
11497 struct gdbarch *gdbarch = get_current_arch ();
11498 char *cond_string = NULL;
11499 catch_fork_kind fork_kind;
11502 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11503 tempflag = (fork_kind == catch_fork_temporary
11504 || fork_kind == catch_vfork_temporary);
11508 arg = skip_spaces (arg);
11510 /* The allowed syntax is:
11512 catch [v]fork if <cond>
11514 First, check if there's an if clause. */
11515 cond_string = ep_parse_optional_if_clause (&arg);
11517 if ((*arg != '\0') && !isspace (*arg))
11518 error (_("Junk at end of arguments."));
11520 /* If this target supports it, create a fork or vfork catchpoint
11521 and enable reporting of such events. */
11524 case catch_fork_temporary:
11525 case catch_fork_permanent:
11526 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11527 &catch_fork_breakpoint_ops);
11529 case catch_vfork_temporary:
11530 case catch_vfork_permanent:
11531 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11532 &catch_vfork_breakpoint_ops);
11535 error (_("unsupported or unknown fork kind; cannot catch it"));
11541 catch_exec_command_1 (char *arg, int from_tty,
11542 struct cmd_list_element *command)
11544 struct exec_catchpoint *c;
11545 struct gdbarch *gdbarch = get_current_arch ();
11547 char *cond_string = NULL;
11549 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11553 arg = skip_spaces (arg);
11555 /* The allowed syntax is:
11557 catch exec if <cond>
11559 First, check if there's an if clause. */
11560 cond_string = ep_parse_optional_if_clause (&arg);
11562 if ((*arg != '\0') && !isspace (*arg))
11563 error (_("Junk at end of arguments."));
11565 c = XNEW (struct exec_catchpoint);
11566 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11567 &catch_exec_breakpoint_ops);
11568 c->exec_pathname = NULL;
11570 install_breakpoint (0, &c->base, 1);
11573 static enum print_stop_action
11574 print_it_exception_catchpoint (bpstat bs)
11576 struct ui_out *uiout = current_uiout;
11577 struct breakpoint *b = bs->breakpoint_at;
11578 int bp_temp, bp_throw;
11580 annotate_catchpoint (b->number);
11582 bp_throw = strstr (b->addr_string, "throw") != NULL;
11583 if (b->loc->address != b->loc->requested_address)
11584 breakpoint_adjustment_warning (b->loc->requested_address,
11587 bp_temp = b->disposition == disp_del;
11588 ui_out_text (uiout,
11589 bp_temp ? "Temporary catchpoint "
11591 if (!ui_out_is_mi_like_p (uiout))
11592 ui_out_field_int (uiout, "bkptno", b->number);
11593 ui_out_text (uiout,
11594 bp_throw ? " (exception thrown), "
11595 : " (exception caught), ");
11596 if (ui_out_is_mi_like_p (uiout))
11598 ui_out_field_string (uiout, "reason",
11599 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11600 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11601 ui_out_field_int (uiout, "bkptno", b->number);
11603 return PRINT_SRC_AND_LOC;
11607 print_one_exception_catchpoint (struct breakpoint *b,
11608 struct bp_location **last_loc)
11610 struct value_print_options opts;
11611 struct ui_out *uiout = current_uiout;
11613 get_user_print_options (&opts);
11614 if (opts.addressprint)
11616 annotate_field (4);
11617 if (b->loc == NULL || b->loc->shlib_disabled)
11618 ui_out_field_string (uiout, "addr", "<PENDING>");
11620 ui_out_field_core_addr (uiout, "addr",
11621 b->loc->gdbarch, b->loc->address);
11623 annotate_field (5);
11625 *last_loc = b->loc;
11626 if (strstr (b->addr_string, "throw") != NULL)
11628 ui_out_field_string (uiout, "what", "exception throw");
11629 if (ui_out_is_mi_like_p (uiout))
11630 ui_out_field_string (uiout, "catch-type", "throw");
11634 ui_out_field_string (uiout, "what", "exception catch");
11635 if (ui_out_is_mi_like_p (uiout))
11636 ui_out_field_string (uiout, "catch-type", "catch");
11641 print_mention_exception_catchpoint (struct breakpoint *b)
11643 struct ui_out *uiout = current_uiout;
11647 bp_temp = b->disposition == disp_del;
11648 bp_throw = strstr (b->addr_string, "throw") != NULL;
11649 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11650 : _("Catchpoint "));
11651 ui_out_field_int (uiout, "bkptno", b->number);
11652 ui_out_text (uiout, bp_throw ? _(" (throw)")
11656 /* Implement the "print_recreate" breakpoint_ops method for throw and
11657 catch catchpoints. */
11660 print_recreate_exception_catchpoint (struct breakpoint *b,
11661 struct ui_file *fp)
11666 bp_temp = b->disposition == disp_del;
11667 bp_throw = strstr (b->addr_string, "throw") != NULL;
11668 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11669 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11670 print_recreate_thread (b, fp);
11673 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11676 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11677 enum exception_event_kind ex_event, int from_tty)
11679 char *trigger_func_name;
11681 if (ex_event == EX_EVENT_CATCH)
11682 trigger_func_name = "__cxa_begin_catch";
11684 trigger_func_name = "__cxa_throw";
11686 create_breakpoint (get_current_arch (),
11687 trigger_func_name, cond_string, -1, NULL,
11688 0 /* condition and thread are valid. */,
11689 tempflag, bp_breakpoint,
11691 AUTO_BOOLEAN_TRUE /* pending */,
11692 &gnu_v3_exception_catchpoint_ops, from_tty,
11700 /* Deal with "catch catch" and "catch throw" commands. */
11703 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11704 int tempflag, int from_tty)
11706 char *cond_string = NULL;
11710 arg = skip_spaces (arg);
11712 cond_string = ep_parse_optional_if_clause (&arg);
11714 if ((*arg != '\0') && !isspace (*arg))
11715 error (_("Junk at end of arguments."));
11717 if (ex_event != EX_EVENT_THROW
11718 && ex_event != EX_EVENT_CATCH)
11719 error (_("Unsupported or unknown exception event; cannot catch it"));
11721 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11724 warning (_("Unsupported with this platform/compiler combination."));
11727 /* Implementation of "catch catch" command. */
11730 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11732 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11734 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11737 /* Implementation of "catch throw" command. */
11740 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11742 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11744 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11748 init_ada_exception_breakpoint (struct breakpoint *b,
11749 struct gdbarch *gdbarch,
11750 struct symtab_and_line sal,
11752 const struct breakpoint_ops *ops,
11758 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11760 loc_gdbarch = gdbarch;
11762 describe_other_breakpoints (loc_gdbarch,
11763 sal.pspace, sal.pc, sal.section, -1);
11764 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11765 version for exception catchpoints, because two catchpoints
11766 used for different exception names will use the same address.
11767 In this case, a "breakpoint ... also set at..." warning is
11768 unproductive. Besides, the warning phrasing is also a bit
11769 inappropriate, we should use the word catchpoint, and tell
11770 the user what type of catchpoint it is. The above is good
11771 enough for now, though. */
11774 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11776 b->enable_state = bp_enabled;
11777 b->disposition = tempflag ? disp_del : disp_donttouch;
11778 b->addr_string = addr_string;
11779 b->language = language_ada;
11782 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11783 filter list, or NULL if no filtering is required. */
11785 catch_syscall_split_args (char *arg)
11787 VEC(int) *result = NULL;
11788 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11790 while (*arg != '\0')
11792 int i, syscall_number;
11794 char cur_name[128];
11797 /* Skip whitespace. */
11798 arg = skip_spaces (arg);
11800 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11801 cur_name[i] = arg[i];
11802 cur_name[i] = '\0';
11805 /* Check if the user provided a syscall name or a number. */
11806 syscall_number = (int) strtol (cur_name, &endptr, 0);
11807 if (*endptr == '\0')
11808 get_syscall_by_number (syscall_number, &s);
11811 /* We have a name. Let's check if it's valid and convert it
11813 get_syscall_by_name (cur_name, &s);
11815 if (s.number == UNKNOWN_SYSCALL)
11816 /* Here we have to issue an error instead of a warning,
11817 because GDB cannot do anything useful if there's no
11818 syscall number to be caught. */
11819 error (_("Unknown syscall name '%s'."), cur_name);
11822 /* Ok, it's valid. */
11823 VEC_safe_push (int, result, s.number);
11826 discard_cleanups (cleanup);
11830 /* Implement the "catch syscall" command. */
11833 catch_syscall_command_1 (char *arg, int from_tty,
11834 struct cmd_list_element *command)
11839 struct gdbarch *gdbarch = get_current_arch ();
11841 /* Checking if the feature if supported. */
11842 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11843 error (_("The feature 'catch syscall' is not supported on \
11844 this architecture yet."));
11846 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11848 arg = skip_spaces (arg);
11850 /* We need to do this first "dummy" translation in order
11851 to get the syscall XML file loaded or, most important,
11852 to display a warning to the user if there's no XML file
11853 for his/her architecture. */
11854 get_syscall_by_number (0, &s);
11856 /* The allowed syntax is:
11858 catch syscall <name | number> [<name | number> ... <name | number>]
11860 Let's check if there's a syscall name. */
11863 filter = catch_syscall_split_args (arg);
11867 create_syscall_event_catchpoint (tempflag, filter,
11868 &catch_syscall_breakpoint_ops);
11872 catch_command (char *arg, int from_tty)
11874 error (_("Catch requires an event name."));
11879 tcatch_command (char *arg, int from_tty)
11881 error (_("Catch requires an event name."));
11884 /* A qsort comparison function that sorts breakpoints in order. */
11887 compare_breakpoints (const void *a, const void *b)
11889 const breakpoint_p *ba = a;
11890 uintptr_t ua = (uintptr_t) *ba;
11891 const breakpoint_p *bb = b;
11892 uintptr_t ub = (uintptr_t) *bb;
11894 if ((*ba)->number < (*bb)->number)
11896 else if ((*ba)->number > (*bb)->number)
11899 /* Now sort by address, in case we see, e..g, two breakpoints with
11903 return ua > ub ? 1 : 0;
11906 /* Delete breakpoints by address or line. */
11909 clear_command (char *arg, int from_tty)
11911 struct breakpoint *b, *prev;
11912 VEC(breakpoint_p) *found = 0;
11915 struct symtabs_and_lines sals;
11916 struct symtab_and_line sal;
11918 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11922 sals = decode_line_with_current_source (arg,
11923 (DECODE_LINE_FUNFIRSTLINE
11924 | DECODE_LINE_LIST_MODE));
11925 make_cleanup (xfree, sals.sals);
11930 sals.sals = (struct symtab_and_line *)
11931 xmalloc (sizeof (struct symtab_and_line));
11932 make_cleanup (xfree, sals.sals);
11933 init_sal (&sal); /* Initialize to zeroes. */
11935 /* Set sal's line, symtab, pc, and pspace to the values
11936 corresponding to the last call to print_frame_info. If the
11937 codepoint is not valid, this will set all the fields to 0. */
11938 get_last_displayed_sal (&sal);
11939 if (sal.symtab == 0)
11940 error (_("No source file specified."));
11942 sals.sals[0] = sal;
11948 /* We don't call resolve_sal_pc here. That's not as bad as it
11949 seems, because all existing breakpoints typically have both
11950 file/line and pc set. So, if clear is given file/line, we can
11951 match this to existing breakpoint without obtaining pc at all.
11953 We only support clearing given the address explicitly
11954 present in breakpoint table. Say, we've set breakpoint
11955 at file:line. There were several PC values for that file:line,
11956 due to optimization, all in one block.
11958 We've picked one PC value. If "clear" is issued with another
11959 PC corresponding to the same file:line, the breakpoint won't
11960 be cleared. We probably can still clear the breakpoint, but
11961 since the other PC value is never presented to user, user
11962 can only find it by guessing, and it does not seem important
11963 to support that. */
11965 /* For each line spec given, delete bps which correspond to it. Do
11966 it in two passes, solely to preserve the current behavior that
11967 from_tty is forced true if we delete more than one
11971 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11972 for (i = 0; i < sals.nelts; i++)
11974 const char *sal_fullname;
11976 /* If exact pc given, clear bpts at that pc.
11977 If line given (pc == 0), clear all bpts on specified line.
11978 If defaulting, clear all bpts on default line
11981 defaulting sal.pc != 0 tests to do
11986 1 0 <can't happen> */
11988 sal = sals.sals[i];
11989 sal_fullname = (sal.symtab == NULL
11990 ? NULL : symtab_to_fullname (sal.symtab));
11992 /* Find all matching breakpoints and add them to 'found'. */
11993 ALL_BREAKPOINTS (b)
11996 /* Are we going to delete b? */
11997 if (b->type != bp_none && !is_watchpoint (b))
11999 struct bp_location *loc = b->loc;
12000 for (; loc; loc = loc->next)
12002 /* If the user specified file:line, don't allow a PC
12003 match. This matches historical gdb behavior. */
12004 int pc_match = (!sal.explicit_line
12006 && (loc->pspace == sal.pspace)
12007 && (loc->address == sal.pc)
12008 && (!section_is_overlay (loc->section)
12009 || loc->section == sal.section));
12010 int line_match = 0;
12012 if ((default_match || sal.explicit_line)
12013 && loc->symtab != NULL
12014 && sal_fullname != NULL
12015 && sal.pspace == loc->pspace
12016 && loc->line_number == sal.line
12017 && filename_cmp (symtab_to_fullname (loc->symtab),
12018 sal_fullname) == 0)
12021 if (pc_match || line_match)
12030 VEC_safe_push(breakpoint_p, found, b);
12034 /* Now go thru the 'found' chain and delete them. */
12035 if (VEC_empty(breakpoint_p, found))
12038 error (_("No breakpoint at %s."), arg);
12040 error (_("No breakpoint at this line."));
12043 /* Remove duplicates from the vec. */
12044 qsort (VEC_address (breakpoint_p, found),
12045 VEC_length (breakpoint_p, found),
12046 sizeof (breakpoint_p),
12047 compare_breakpoints);
12048 prev = VEC_index (breakpoint_p, found, 0);
12049 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12053 VEC_ordered_remove (breakpoint_p, found, ix);
12058 if (VEC_length(breakpoint_p, found) > 1)
12059 from_tty = 1; /* Always report if deleted more than one. */
12062 if (VEC_length(breakpoint_p, found) == 1)
12063 printf_unfiltered (_("Deleted breakpoint "));
12065 printf_unfiltered (_("Deleted breakpoints "));
12068 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12071 printf_unfiltered ("%d ", b->number);
12072 delete_breakpoint (b);
12075 putchar_unfiltered ('\n');
12077 do_cleanups (cleanups);
12080 /* Delete breakpoint in BS if they are `delete' breakpoints and
12081 all breakpoints that are marked for deletion, whether hit or not.
12082 This is called after any breakpoint is hit, or after errors. */
12085 breakpoint_auto_delete (bpstat bs)
12087 struct breakpoint *b, *b_tmp;
12089 for (; bs; bs = bs->next)
12090 if (bs->breakpoint_at
12091 && bs->breakpoint_at->disposition == disp_del
12093 delete_breakpoint (bs->breakpoint_at);
12095 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12097 if (b->disposition == disp_del_at_next_stop)
12098 delete_breakpoint (b);
12102 /* A comparison function for bp_location AP and BP being interfaced to
12103 qsort. Sort elements primarily by their ADDRESS (no matter what
12104 does breakpoint_address_is_meaningful say for its OWNER),
12105 secondarily by ordering first bp_permanent OWNERed elements and
12106 terciarily just ensuring the array is sorted stable way despite
12107 qsort being an unstable algorithm. */
12110 bp_location_compare (const void *ap, const void *bp)
12112 struct bp_location *a = *(void **) ap;
12113 struct bp_location *b = *(void **) bp;
12114 /* A and B come from existing breakpoints having non-NULL OWNER. */
12115 int a_perm = a->owner->enable_state == bp_permanent;
12116 int b_perm = b->owner->enable_state == bp_permanent;
12118 if (a->address != b->address)
12119 return (a->address > b->address) - (a->address < b->address);
12121 /* Sort locations at the same address by their pspace number, keeping
12122 locations of the same inferior (in a multi-inferior environment)
12125 if (a->pspace->num != b->pspace->num)
12126 return ((a->pspace->num > b->pspace->num)
12127 - (a->pspace->num < b->pspace->num));
12129 /* Sort permanent breakpoints first. */
12130 if (a_perm != b_perm)
12131 return (a_perm < b_perm) - (a_perm > b_perm);
12133 /* Make the internal GDB representation stable across GDB runs
12134 where A and B memory inside GDB can differ. Breakpoint locations of
12135 the same type at the same address can be sorted in arbitrary order. */
12137 if (a->owner->number != b->owner->number)
12138 return ((a->owner->number > b->owner->number)
12139 - (a->owner->number < b->owner->number));
12141 return (a > b) - (a < b);
12144 /* Set bp_location_placed_address_before_address_max and
12145 bp_location_shadow_len_after_address_max according to the current
12146 content of the bp_location array. */
12149 bp_location_target_extensions_update (void)
12151 struct bp_location *bl, **blp_tmp;
12153 bp_location_placed_address_before_address_max = 0;
12154 bp_location_shadow_len_after_address_max = 0;
12156 ALL_BP_LOCATIONS (bl, blp_tmp)
12158 CORE_ADDR start, end, addr;
12160 if (!bp_location_has_shadow (bl))
12163 start = bl->target_info.placed_address;
12164 end = start + bl->target_info.shadow_len;
12166 gdb_assert (bl->address >= start);
12167 addr = bl->address - start;
12168 if (addr > bp_location_placed_address_before_address_max)
12169 bp_location_placed_address_before_address_max = addr;
12171 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12173 gdb_assert (bl->address < end);
12174 addr = end - bl->address;
12175 if (addr > bp_location_shadow_len_after_address_max)
12176 bp_location_shadow_len_after_address_max = addr;
12180 /* Download tracepoint locations if they haven't been. */
12183 download_tracepoint_locations (void)
12185 struct breakpoint *b;
12186 struct cleanup *old_chain;
12188 if (!target_can_download_tracepoint ())
12191 old_chain = save_current_space_and_thread ();
12193 ALL_TRACEPOINTS (b)
12195 struct bp_location *bl;
12196 struct tracepoint *t;
12197 int bp_location_downloaded = 0;
12199 if ((b->type == bp_fast_tracepoint
12200 ? !may_insert_fast_tracepoints
12201 : !may_insert_tracepoints))
12204 for (bl = b->loc; bl; bl = bl->next)
12206 /* In tracepoint, locations are _never_ duplicated, so
12207 should_be_inserted is equivalent to
12208 unduplicated_should_be_inserted. */
12209 if (!should_be_inserted (bl) || bl->inserted)
12212 switch_to_program_space_and_thread (bl->pspace);
12214 target_download_tracepoint (bl);
12217 bp_location_downloaded = 1;
12219 t = (struct tracepoint *) b;
12220 t->number_on_target = b->number;
12221 if (bp_location_downloaded)
12222 observer_notify_breakpoint_modified (b);
12225 do_cleanups (old_chain);
12228 /* Swap the insertion/duplication state between two locations. */
12231 swap_insertion (struct bp_location *left, struct bp_location *right)
12233 const int left_inserted = left->inserted;
12234 const int left_duplicate = left->duplicate;
12235 const int left_needs_update = left->needs_update;
12236 const struct bp_target_info left_target_info = left->target_info;
12238 /* Locations of tracepoints can never be duplicated. */
12239 if (is_tracepoint (left->owner))
12240 gdb_assert (!left->duplicate);
12241 if (is_tracepoint (right->owner))
12242 gdb_assert (!right->duplicate);
12244 left->inserted = right->inserted;
12245 left->duplicate = right->duplicate;
12246 left->needs_update = right->needs_update;
12247 left->target_info = right->target_info;
12248 right->inserted = left_inserted;
12249 right->duplicate = left_duplicate;
12250 right->needs_update = left_needs_update;
12251 right->target_info = left_target_info;
12254 /* Force the re-insertion of the locations at ADDRESS. This is called
12255 once a new/deleted/modified duplicate location is found and we are evaluating
12256 conditions on the target's side. Such conditions need to be updated on
12260 force_breakpoint_reinsertion (struct bp_location *bl)
12262 struct bp_location **locp = NULL, **loc2p;
12263 struct bp_location *loc;
12264 CORE_ADDR address = 0;
12267 address = bl->address;
12268 pspace_num = bl->pspace->num;
12270 /* This is only meaningful if the target is
12271 evaluating conditions and if the user has
12272 opted for condition evaluation on the target's
12274 if (gdb_evaluates_breakpoint_condition_p ()
12275 || !target_supports_evaluation_of_breakpoint_conditions ())
12278 /* Flag all breakpoint locations with this address and
12279 the same program space as the location
12280 as "its condition has changed". We need to
12281 update the conditions on the target's side. */
12282 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12286 if (!is_breakpoint (loc->owner)
12287 || pspace_num != loc->pspace->num)
12290 /* Flag the location appropriately. We use a different state to
12291 let everyone know that we already updated the set of locations
12292 with addr bl->address and program space bl->pspace. This is so
12293 we don't have to keep calling these functions just to mark locations
12294 that have already been marked. */
12295 loc->condition_changed = condition_updated;
12297 /* Free the agent expression bytecode as well. We will compute
12299 if (loc->cond_bytecode)
12301 free_agent_expr (loc->cond_bytecode);
12302 loc->cond_bytecode = NULL;
12307 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12308 into the inferior, only remove already-inserted locations that no
12309 longer should be inserted. Functions that delete a breakpoint or
12310 breakpoints should pass false, so that deleting a breakpoint
12311 doesn't have the side effect of inserting the locations of other
12312 breakpoints that are marked not-inserted, but should_be_inserted
12313 returns true on them.
12315 This behaviour is useful is situations close to tear-down -- e.g.,
12316 after an exec, while the target still has execution, but breakpoint
12317 shadows of the previous executable image should *NOT* be restored
12318 to the new image; or before detaching, where the target still has
12319 execution and wants to delete breakpoints from GDB's lists, and all
12320 breakpoints had already been removed from the inferior. */
12323 update_global_location_list (int should_insert)
12325 struct breakpoint *b;
12326 struct bp_location **locp, *loc;
12327 struct cleanup *cleanups;
12328 /* Last breakpoint location address that was marked for update. */
12329 CORE_ADDR last_addr = 0;
12330 /* Last breakpoint location program space that was marked for update. */
12331 int last_pspace_num = -1;
12333 /* Used in the duplicates detection below. When iterating over all
12334 bp_locations, points to the first bp_location of a given address.
12335 Breakpoints and watchpoints of different types are never
12336 duplicates of each other. Keep one pointer for each type of
12337 breakpoint/watchpoint, so we only need to loop over all locations
12339 struct bp_location *bp_loc_first; /* breakpoint */
12340 struct bp_location *wp_loc_first; /* hardware watchpoint */
12341 struct bp_location *awp_loc_first; /* access watchpoint */
12342 struct bp_location *rwp_loc_first; /* read watchpoint */
12344 /* Saved former bp_location array which we compare against the newly
12345 built bp_location from the current state of ALL_BREAKPOINTS. */
12346 struct bp_location **old_location, **old_locp;
12347 unsigned old_location_count;
12349 old_location = bp_location;
12350 old_location_count = bp_location_count;
12351 bp_location = NULL;
12352 bp_location_count = 0;
12353 cleanups = make_cleanup (xfree, old_location);
12355 ALL_BREAKPOINTS (b)
12356 for (loc = b->loc; loc; loc = loc->next)
12357 bp_location_count++;
12359 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12360 locp = bp_location;
12361 ALL_BREAKPOINTS (b)
12362 for (loc = b->loc; loc; loc = loc->next)
12364 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12365 bp_location_compare);
12367 bp_location_target_extensions_update ();
12369 /* Identify bp_location instances that are no longer present in the
12370 new list, and therefore should be freed. Note that it's not
12371 necessary that those locations should be removed from inferior --
12372 if there's another location at the same address (previously
12373 marked as duplicate), we don't need to remove/insert the
12376 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12377 and former bp_location array state respectively. */
12379 locp = bp_location;
12380 for (old_locp = old_location; old_locp < old_location + old_location_count;
12383 struct bp_location *old_loc = *old_locp;
12384 struct bp_location **loc2p;
12386 /* Tells if 'old_loc' is found among the new locations. If
12387 not, we have to free it. */
12388 int found_object = 0;
12389 /* Tells if the location should remain inserted in the target. */
12390 int keep_in_target = 0;
12393 /* Skip LOCP entries which will definitely never be needed.
12394 Stop either at or being the one matching OLD_LOC. */
12395 while (locp < bp_location + bp_location_count
12396 && (*locp)->address < old_loc->address)
12400 (loc2p < bp_location + bp_location_count
12401 && (*loc2p)->address == old_loc->address);
12404 /* Check if this is a new/duplicated location or a duplicated
12405 location that had its condition modified. If so, we want to send
12406 its condition to the target if evaluation of conditions is taking
12408 if ((*loc2p)->condition_changed == condition_modified
12409 && (last_addr != old_loc->address
12410 || last_pspace_num != old_loc->pspace->num))
12412 force_breakpoint_reinsertion (*loc2p);
12413 last_pspace_num = old_loc->pspace->num;
12416 if (*loc2p == old_loc)
12420 /* We have already handled this address, update it so that we don't
12421 have to go through updates again. */
12422 last_addr = old_loc->address;
12424 /* Target-side condition evaluation: Handle deleted locations. */
12426 force_breakpoint_reinsertion (old_loc);
12428 /* If this location is no longer present, and inserted, look if
12429 there's maybe a new location at the same address. If so,
12430 mark that one inserted, and don't remove this one. This is
12431 needed so that we don't have a time window where a breakpoint
12432 at certain location is not inserted. */
12434 if (old_loc->inserted)
12436 /* If the location is inserted now, we might have to remove
12439 if (found_object && should_be_inserted (old_loc))
12441 /* The location is still present in the location list,
12442 and still should be inserted. Don't do anything. */
12443 keep_in_target = 1;
12447 /* This location still exists, but it won't be kept in the
12448 target since it may have been disabled. We proceed to
12449 remove its target-side condition. */
12451 /* The location is either no longer present, or got
12452 disabled. See if there's another location at the
12453 same address, in which case we don't need to remove
12454 this one from the target. */
12456 /* OLD_LOC comes from existing struct breakpoint. */
12457 if (breakpoint_address_is_meaningful (old_loc->owner))
12460 (loc2p < bp_location + bp_location_count
12461 && (*loc2p)->address == old_loc->address);
12464 struct bp_location *loc2 = *loc2p;
12466 if (breakpoint_locations_match (loc2, old_loc))
12468 /* Read watchpoint locations are switched to
12469 access watchpoints, if the former are not
12470 supported, but the latter are. */
12471 if (is_hardware_watchpoint (old_loc->owner))
12473 gdb_assert (is_hardware_watchpoint (loc2->owner));
12474 loc2->watchpoint_type = old_loc->watchpoint_type;
12477 /* loc2 is a duplicated location. We need to check
12478 if it should be inserted in case it will be
12480 if (loc2 != old_loc
12481 && unduplicated_should_be_inserted (loc2))
12483 swap_insertion (old_loc, loc2);
12484 keep_in_target = 1;
12492 if (!keep_in_target)
12494 if (remove_breakpoint (old_loc, mark_uninserted))
12496 /* This is just about all we can do. We could keep
12497 this location on the global list, and try to
12498 remove it next time, but there's no particular
12499 reason why we will succeed next time.
12501 Note that at this point, old_loc->owner is still
12502 valid, as delete_breakpoint frees the breakpoint
12503 only after calling us. */
12504 printf_filtered (_("warning: Error removing "
12505 "breakpoint %d\n"),
12506 old_loc->owner->number);
12514 if (removed && non_stop
12515 && breakpoint_address_is_meaningful (old_loc->owner)
12516 && !is_hardware_watchpoint (old_loc->owner))
12518 /* This location was removed from the target. In
12519 non-stop mode, a race condition is possible where
12520 we've removed a breakpoint, but stop events for that
12521 breakpoint are already queued and will arrive later.
12522 We apply an heuristic to be able to distinguish such
12523 SIGTRAPs from other random SIGTRAPs: we keep this
12524 breakpoint location for a bit, and will retire it
12525 after we see some number of events. The theory here
12526 is that reporting of events should, "on the average",
12527 be fair, so after a while we'll see events from all
12528 threads that have anything of interest, and no longer
12529 need to keep this breakpoint location around. We
12530 don't hold locations forever so to reduce chances of
12531 mistaking a non-breakpoint SIGTRAP for a breakpoint
12534 The heuristic failing can be disastrous on
12535 decr_pc_after_break targets.
12537 On decr_pc_after_break targets, like e.g., x86-linux,
12538 if we fail to recognize a late breakpoint SIGTRAP,
12539 because events_till_retirement has reached 0 too
12540 soon, we'll fail to do the PC adjustment, and report
12541 a random SIGTRAP to the user. When the user resumes
12542 the inferior, it will most likely immediately crash
12543 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12544 corrupted, because of being resumed e.g., in the
12545 middle of a multi-byte instruction, or skipped a
12546 one-byte instruction. This was actually seen happen
12547 on native x86-linux, and should be less rare on
12548 targets that do not support new thread events, like
12549 remote, due to the heuristic depending on
12552 Mistaking a random SIGTRAP for a breakpoint trap
12553 causes similar symptoms (PC adjustment applied when
12554 it shouldn't), but then again, playing with SIGTRAPs
12555 behind the debugger's back is asking for trouble.
12557 Since hardware watchpoint traps are always
12558 distinguishable from other traps, so we don't need to
12559 apply keep hardware watchpoint moribund locations
12560 around. We simply always ignore hardware watchpoint
12561 traps we can no longer explain. */
12563 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12564 old_loc->owner = NULL;
12566 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12570 old_loc->owner = NULL;
12571 decref_bp_location (&old_loc);
12576 /* Rescan breakpoints at the same address and section, marking the
12577 first one as "first" and any others as "duplicates". This is so
12578 that the bpt instruction is only inserted once. If we have a
12579 permanent breakpoint at the same place as BPT, make that one the
12580 official one, and the rest as duplicates. Permanent breakpoints
12581 are sorted first for the same address.
12583 Do the same for hardware watchpoints, but also considering the
12584 watchpoint's type (regular/access/read) and length. */
12586 bp_loc_first = NULL;
12587 wp_loc_first = NULL;
12588 awp_loc_first = NULL;
12589 rwp_loc_first = NULL;
12590 ALL_BP_LOCATIONS (loc, locp)
12592 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12594 struct bp_location **loc_first_p;
12597 if (!unduplicated_should_be_inserted (loc)
12598 || !breakpoint_address_is_meaningful (b)
12599 /* Don't detect duplicate for tracepoint locations because they are
12600 never duplicated. See the comments in field `duplicate' of
12601 `struct bp_location'. */
12602 || is_tracepoint (b))
12604 /* Clear the condition modification flag. */
12605 loc->condition_changed = condition_unchanged;
12609 /* Permanent breakpoint should always be inserted. */
12610 if (b->enable_state == bp_permanent && ! loc->inserted)
12611 internal_error (__FILE__, __LINE__,
12612 _("allegedly permanent breakpoint is not "
12613 "actually inserted"));
12615 if (b->type == bp_hardware_watchpoint)
12616 loc_first_p = &wp_loc_first;
12617 else if (b->type == bp_read_watchpoint)
12618 loc_first_p = &rwp_loc_first;
12619 else if (b->type == bp_access_watchpoint)
12620 loc_first_p = &awp_loc_first;
12622 loc_first_p = &bp_loc_first;
12624 if (*loc_first_p == NULL
12625 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12626 || !breakpoint_locations_match (loc, *loc_first_p))
12628 *loc_first_p = loc;
12629 loc->duplicate = 0;
12631 if (is_breakpoint (loc->owner) && loc->condition_changed)
12633 loc->needs_update = 1;
12634 /* Clear the condition modification flag. */
12635 loc->condition_changed = condition_unchanged;
12641 /* This and the above ensure the invariant that the first location
12642 is not duplicated, and is the inserted one.
12643 All following are marked as duplicated, and are not inserted. */
12645 swap_insertion (loc, *loc_first_p);
12646 loc->duplicate = 1;
12648 /* Clear the condition modification flag. */
12649 loc->condition_changed = condition_unchanged;
12651 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12652 && b->enable_state != bp_permanent)
12653 internal_error (__FILE__, __LINE__,
12654 _("another breakpoint was inserted on top of "
12655 "a permanent breakpoint"));
12658 if (breakpoints_always_inserted_mode ()
12659 && (have_live_inferiors ()
12660 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12663 insert_breakpoint_locations ();
12666 /* Though should_insert is false, we may need to update conditions
12667 on the target's side if it is evaluating such conditions. We
12668 only update conditions for locations that are marked
12670 update_inserted_breakpoint_locations ();
12675 download_tracepoint_locations ();
12677 do_cleanups (cleanups);
12681 breakpoint_retire_moribund (void)
12683 struct bp_location *loc;
12686 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12687 if (--(loc->events_till_retirement) == 0)
12689 decref_bp_location (&loc);
12690 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12696 update_global_location_list_nothrow (int inserting)
12698 volatile struct gdb_exception e;
12700 TRY_CATCH (e, RETURN_MASK_ERROR)
12701 update_global_location_list (inserting);
12704 /* Clear BKP from a BPS. */
12707 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12711 for (bs = bps; bs; bs = bs->next)
12712 if (bs->breakpoint_at == bpt)
12714 bs->breakpoint_at = NULL;
12715 bs->old_val = NULL;
12716 /* bs->commands will be freed later. */
12720 /* Callback for iterate_over_threads. */
12722 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12724 struct breakpoint *bpt = data;
12726 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12730 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12734 say_where (struct breakpoint *b)
12736 struct value_print_options opts;
12738 get_user_print_options (&opts);
12740 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12742 if (b->loc == NULL)
12744 printf_filtered (_(" (%s) pending."), b->addr_string);
12748 if (opts.addressprint || b->loc->symtab == NULL)
12750 printf_filtered (" at ");
12751 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12754 if (b->loc->symtab != NULL)
12756 /* If there is a single location, we can print the location
12758 if (b->loc->next == NULL)
12759 printf_filtered (": file %s, line %d.",
12760 symtab_to_filename_for_display (b->loc->symtab),
12761 b->loc->line_number);
12763 /* This is not ideal, but each location may have a
12764 different file name, and this at least reflects the
12765 real situation somewhat. */
12766 printf_filtered (": %s.", b->addr_string);
12771 struct bp_location *loc = b->loc;
12773 for (; loc; loc = loc->next)
12775 printf_filtered (" (%d locations)", n);
12780 /* Default bp_location_ops methods. */
12783 bp_location_dtor (struct bp_location *self)
12785 xfree (self->cond);
12786 if (self->cond_bytecode)
12787 free_agent_expr (self->cond_bytecode);
12788 xfree (self->function_name);
12791 static const struct bp_location_ops bp_location_ops =
12796 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12800 base_breakpoint_dtor (struct breakpoint *self)
12802 decref_counted_command_line (&self->commands);
12803 xfree (self->cond_string);
12804 xfree (self->extra_string);
12805 xfree (self->addr_string);
12806 xfree (self->filter);
12807 xfree (self->addr_string_range_end);
12810 static struct bp_location *
12811 base_breakpoint_allocate_location (struct breakpoint *self)
12813 struct bp_location *loc;
12815 loc = XNEW (struct bp_location);
12816 init_bp_location (loc, &bp_location_ops, self);
12821 base_breakpoint_re_set (struct breakpoint *b)
12823 /* Nothing to re-set. */
12826 #define internal_error_pure_virtual_called() \
12827 gdb_assert_not_reached ("pure virtual function called")
12830 base_breakpoint_insert_location (struct bp_location *bl)
12832 internal_error_pure_virtual_called ();
12836 base_breakpoint_remove_location (struct bp_location *bl)
12838 internal_error_pure_virtual_called ();
12842 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12843 struct address_space *aspace,
12845 const struct target_waitstatus *ws)
12847 internal_error_pure_virtual_called ();
12851 base_breakpoint_check_status (bpstat bs)
12856 /* A "works_in_software_mode" breakpoint_ops method that just internal
12860 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12862 internal_error_pure_virtual_called ();
12865 /* A "resources_needed" breakpoint_ops method that just internal
12869 base_breakpoint_resources_needed (const struct bp_location *bl)
12871 internal_error_pure_virtual_called ();
12874 static enum print_stop_action
12875 base_breakpoint_print_it (bpstat bs)
12877 internal_error_pure_virtual_called ();
12881 base_breakpoint_print_one_detail (const struct breakpoint *self,
12882 struct ui_out *uiout)
12888 base_breakpoint_print_mention (struct breakpoint *b)
12890 internal_error_pure_virtual_called ();
12894 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12896 internal_error_pure_virtual_called ();
12900 base_breakpoint_create_sals_from_address (char **arg,
12901 struct linespec_result *canonical,
12902 enum bptype type_wanted,
12906 internal_error_pure_virtual_called ();
12910 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12911 struct linespec_result *c,
12912 struct linespec_sals *lsal,
12914 char *extra_string,
12915 enum bptype type_wanted,
12916 enum bpdisp disposition,
12918 int task, int ignore_count,
12919 const struct breakpoint_ops *o,
12920 int from_tty, int enabled,
12921 int internal, unsigned flags)
12923 internal_error_pure_virtual_called ();
12927 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12928 struct symtabs_and_lines *sals)
12930 internal_error_pure_virtual_called ();
12933 /* The default 'explains_signal' method. */
12935 static enum bpstat_signal_value
12936 base_breakpoint_explains_signal (struct breakpoint *b)
12938 return BPSTAT_SIGNAL_HIDE;
12941 struct breakpoint_ops base_breakpoint_ops =
12943 base_breakpoint_dtor,
12944 base_breakpoint_allocate_location,
12945 base_breakpoint_re_set,
12946 base_breakpoint_insert_location,
12947 base_breakpoint_remove_location,
12948 base_breakpoint_breakpoint_hit,
12949 base_breakpoint_check_status,
12950 base_breakpoint_resources_needed,
12951 base_breakpoint_works_in_software_mode,
12952 base_breakpoint_print_it,
12954 base_breakpoint_print_one_detail,
12955 base_breakpoint_print_mention,
12956 base_breakpoint_print_recreate,
12957 base_breakpoint_create_sals_from_address,
12958 base_breakpoint_create_breakpoints_sal,
12959 base_breakpoint_decode_linespec,
12960 base_breakpoint_explains_signal
12963 /* Default breakpoint_ops methods. */
12966 bkpt_re_set (struct breakpoint *b)
12968 /* FIXME: is this still reachable? */
12969 if (b->addr_string == NULL)
12971 /* Anything without a string can't be re-set. */
12972 delete_breakpoint (b);
12976 breakpoint_re_set_default (b);
12980 bkpt_insert_location (struct bp_location *bl)
12982 if (bl->loc_type == bp_loc_hardware_breakpoint)
12983 return target_insert_hw_breakpoint (bl->gdbarch,
12986 return target_insert_breakpoint (bl->gdbarch,
12991 bkpt_remove_location (struct bp_location *bl)
12993 if (bl->loc_type == bp_loc_hardware_breakpoint)
12994 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12996 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13000 bkpt_breakpoint_hit (const struct bp_location *bl,
13001 struct address_space *aspace, CORE_ADDR bp_addr,
13002 const struct target_waitstatus *ws)
13004 if (ws->kind != TARGET_WAITKIND_STOPPED
13005 || ws->value.sig != GDB_SIGNAL_TRAP)
13008 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13012 if (overlay_debugging /* unmapped overlay section */
13013 && section_is_overlay (bl->section)
13014 && !section_is_mapped (bl->section))
13021 bkpt_resources_needed (const struct bp_location *bl)
13023 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13028 static enum print_stop_action
13029 bkpt_print_it (bpstat bs)
13031 struct breakpoint *b;
13032 const struct bp_location *bl;
13034 struct ui_out *uiout = current_uiout;
13036 gdb_assert (bs->bp_location_at != NULL);
13038 bl = bs->bp_location_at;
13039 b = bs->breakpoint_at;
13041 bp_temp = b->disposition == disp_del;
13042 if (bl->address != bl->requested_address)
13043 breakpoint_adjustment_warning (bl->requested_address,
13046 annotate_breakpoint (b->number);
13048 ui_out_text (uiout, "\nTemporary breakpoint ");
13050 ui_out_text (uiout, "\nBreakpoint ");
13051 if (ui_out_is_mi_like_p (uiout))
13053 ui_out_field_string (uiout, "reason",
13054 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13055 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13057 ui_out_field_int (uiout, "bkptno", b->number);
13058 ui_out_text (uiout, ", ");
13060 return PRINT_SRC_AND_LOC;
13064 bkpt_print_mention (struct breakpoint *b)
13066 if (ui_out_is_mi_like_p (current_uiout))
13071 case bp_breakpoint:
13072 case bp_gnu_ifunc_resolver:
13073 if (b->disposition == disp_del)
13074 printf_filtered (_("Temporary breakpoint"));
13076 printf_filtered (_("Breakpoint"));
13077 printf_filtered (_(" %d"), b->number);
13078 if (b->type == bp_gnu_ifunc_resolver)
13079 printf_filtered (_(" at gnu-indirect-function resolver"));
13081 case bp_hardware_breakpoint:
13082 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13085 printf_filtered (_("Dprintf %d"), b->number);
13093 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13095 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13096 fprintf_unfiltered (fp, "tbreak");
13097 else if (tp->type == bp_breakpoint)
13098 fprintf_unfiltered (fp, "break");
13099 else if (tp->type == bp_hardware_breakpoint
13100 && tp->disposition == disp_del)
13101 fprintf_unfiltered (fp, "thbreak");
13102 else if (tp->type == bp_hardware_breakpoint)
13103 fprintf_unfiltered (fp, "hbreak");
13105 internal_error (__FILE__, __LINE__,
13106 _("unhandled breakpoint type %d"), (int) tp->type);
13108 fprintf_unfiltered (fp, " %s", tp->addr_string);
13109 print_recreate_thread (tp, fp);
13113 bkpt_create_sals_from_address (char **arg,
13114 struct linespec_result *canonical,
13115 enum bptype type_wanted,
13116 char *addr_start, char **copy_arg)
13118 create_sals_from_address_default (arg, canonical, type_wanted,
13119 addr_start, copy_arg);
13123 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13124 struct linespec_result *canonical,
13125 struct linespec_sals *lsal,
13127 char *extra_string,
13128 enum bptype type_wanted,
13129 enum bpdisp disposition,
13131 int task, int ignore_count,
13132 const struct breakpoint_ops *ops,
13133 int from_tty, int enabled,
13134 int internal, unsigned flags)
13136 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13137 cond_string, extra_string,
13139 disposition, thread, task,
13140 ignore_count, ops, from_tty,
13141 enabled, internal, flags);
13145 bkpt_decode_linespec (struct breakpoint *b, char **s,
13146 struct symtabs_and_lines *sals)
13148 decode_linespec_default (b, s, sals);
13151 /* Virtual table for internal breakpoints. */
13154 internal_bkpt_re_set (struct breakpoint *b)
13158 /* Delete overlay event and longjmp master breakpoints; they
13159 will be reset later by breakpoint_re_set. */
13160 case bp_overlay_event:
13161 case bp_longjmp_master:
13162 case bp_std_terminate_master:
13163 case bp_exception_master:
13164 delete_breakpoint (b);
13167 /* This breakpoint is special, it's set up when the inferior
13168 starts and we really don't want to touch it. */
13169 case bp_shlib_event:
13171 /* Like bp_shlib_event, this breakpoint type is special. Once
13172 it is set up, we do not want to touch it. */
13173 case bp_thread_event:
13179 internal_bkpt_check_status (bpstat bs)
13181 if (bs->breakpoint_at->type == bp_shlib_event)
13183 /* If requested, stop when the dynamic linker notifies GDB of
13184 events. This allows the user to get control and place
13185 breakpoints in initializer routines for dynamically loaded
13186 objects (among other things). */
13187 bs->stop = stop_on_solib_events;
13188 bs->print = stop_on_solib_events;
13194 static enum print_stop_action
13195 internal_bkpt_print_it (bpstat bs)
13197 struct breakpoint *b;
13199 b = bs->breakpoint_at;
13203 case bp_shlib_event:
13204 /* Did we stop because the user set the stop_on_solib_events
13205 variable? (If so, we report this as a generic, "Stopped due
13206 to shlib event" message.) */
13207 print_solib_event (0);
13210 case bp_thread_event:
13211 /* Not sure how we will get here.
13212 GDB should not stop for these breakpoints. */
13213 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13216 case bp_overlay_event:
13217 /* By analogy with the thread event, GDB should not stop for these. */
13218 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13221 case bp_longjmp_master:
13222 /* These should never be enabled. */
13223 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13226 case bp_std_terminate_master:
13227 /* These should never be enabled. */
13228 printf_filtered (_("std::terminate Master Breakpoint: "
13229 "gdb should not stop!\n"));
13232 case bp_exception_master:
13233 /* These should never be enabled. */
13234 printf_filtered (_("Exception Master Breakpoint: "
13235 "gdb should not stop!\n"));
13239 return PRINT_NOTHING;
13243 internal_bkpt_print_mention (struct breakpoint *b)
13245 /* Nothing to mention. These breakpoints are internal. */
13248 /* Virtual table for momentary breakpoints */
13251 momentary_bkpt_re_set (struct breakpoint *b)
13253 /* Keep temporary breakpoints, which can be encountered when we step
13254 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
13255 Otherwise these should have been blown away via the cleanup chain
13256 or by breakpoint_init_inferior when we rerun the executable. */
13260 momentary_bkpt_check_status (bpstat bs)
13262 /* Nothing. The point of these breakpoints is causing a stop. */
13265 static enum print_stop_action
13266 momentary_bkpt_print_it (bpstat bs)
13268 struct ui_out *uiout = current_uiout;
13270 if (ui_out_is_mi_like_p (uiout))
13272 struct breakpoint *b = bs->breakpoint_at;
13277 ui_out_field_string
13279 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13283 ui_out_field_string
13285 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13290 return PRINT_UNKNOWN;
13294 momentary_bkpt_print_mention (struct breakpoint *b)
13296 /* Nothing to mention. These breakpoints are internal. */
13299 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13301 It gets cleared already on the removal of the first one of such placed
13302 breakpoints. This is OK as they get all removed altogether. */
13305 longjmp_bkpt_dtor (struct breakpoint *self)
13307 struct thread_info *tp = find_thread_id (self->thread);
13310 tp->initiating_frame = null_frame_id;
13312 momentary_breakpoint_ops.dtor (self);
13315 /* Specific methods for probe breakpoints. */
13318 bkpt_probe_insert_location (struct bp_location *bl)
13320 int v = bkpt_insert_location (bl);
13324 /* The insertion was successful, now let's set the probe's semaphore
13326 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
13333 bkpt_probe_remove_location (struct bp_location *bl)
13335 /* Let's clear the semaphore before removing the location. */
13336 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
13338 return bkpt_remove_location (bl);
13342 bkpt_probe_create_sals_from_address (char **arg,
13343 struct linespec_result *canonical,
13344 enum bptype type_wanted,
13345 char *addr_start, char **copy_arg)
13347 struct linespec_sals lsal;
13349 lsal.sals = parse_probes (arg, canonical);
13351 *copy_arg = xstrdup (canonical->addr_string);
13352 lsal.canonical = xstrdup (*copy_arg);
13354 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13358 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13359 struct symtabs_and_lines *sals)
13361 *sals = parse_probes (s, NULL);
13363 error (_("probe not found"));
13366 /* The breakpoint_ops structure to be used in tracepoints. */
13369 tracepoint_re_set (struct breakpoint *b)
13371 breakpoint_re_set_default (b);
13375 tracepoint_breakpoint_hit (const struct bp_location *bl,
13376 struct address_space *aspace, CORE_ADDR bp_addr,
13377 const struct target_waitstatus *ws)
13379 /* By definition, the inferior does not report stops at
13385 tracepoint_print_one_detail (const struct breakpoint *self,
13386 struct ui_out *uiout)
13388 struct tracepoint *tp = (struct tracepoint *) self;
13389 if (tp->static_trace_marker_id)
13391 gdb_assert (self->type == bp_static_tracepoint);
13393 ui_out_text (uiout, "\tmarker id is ");
13394 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13395 tp->static_trace_marker_id);
13396 ui_out_text (uiout, "\n");
13401 tracepoint_print_mention (struct breakpoint *b)
13403 if (ui_out_is_mi_like_p (current_uiout))
13408 case bp_tracepoint:
13409 printf_filtered (_("Tracepoint"));
13410 printf_filtered (_(" %d"), b->number);
13412 case bp_fast_tracepoint:
13413 printf_filtered (_("Fast tracepoint"));
13414 printf_filtered (_(" %d"), b->number);
13416 case bp_static_tracepoint:
13417 printf_filtered (_("Static tracepoint"));
13418 printf_filtered (_(" %d"), b->number);
13421 internal_error (__FILE__, __LINE__,
13422 _("unhandled tracepoint type %d"), (int) b->type);
13429 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13431 struct tracepoint *tp = (struct tracepoint *) self;
13433 if (self->type == bp_fast_tracepoint)
13434 fprintf_unfiltered (fp, "ftrace");
13435 if (self->type == bp_static_tracepoint)
13436 fprintf_unfiltered (fp, "strace");
13437 else if (self->type == bp_tracepoint)
13438 fprintf_unfiltered (fp, "trace");
13440 internal_error (__FILE__, __LINE__,
13441 _("unhandled tracepoint type %d"), (int) self->type);
13443 fprintf_unfiltered (fp, " %s", self->addr_string);
13444 print_recreate_thread (self, fp);
13446 if (tp->pass_count)
13447 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13451 tracepoint_create_sals_from_address (char **arg,
13452 struct linespec_result *canonical,
13453 enum bptype type_wanted,
13454 char *addr_start, char **copy_arg)
13456 create_sals_from_address_default (arg, canonical, type_wanted,
13457 addr_start, copy_arg);
13461 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13462 struct linespec_result *canonical,
13463 struct linespec_sals *lsal,
13465 char *extra_string,
13466 enum bptype type_wanted,
13467 enum bpdisp disposition,
13469 int task, int ignore_count,
13470 const struct breakpoint_ops *ops,
13471 int from_tty, int enabled,
13472 int internal, unsigned flags)
13474 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13475 cond_string, extra_string,
13477 disposition, thread, task,
13478 ignore_count, ops, from_tty,
13479 enabled, internal, flags);
13483 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13484 struct symtabs_and_lines *sals)
13486 decode_linespec_default (b, s, sals);
13489 struct breakpoint_ops tracepoint_breakpoint_ops;
13491 /* The breakpoint_ops structure to be use on tracepoints placed in a
13495 tracepoint_probe_create_sals_from_address (char **arg,
13496 struct linespec_result *canonical,
13497 enum bptype type_wanted,
13498 char *addr_start, char **copy_arg)
13500 /* We use the same method for breakpoint on probes. */
13501 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13502 addr_start, copy_arg);
13506 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13507 struct symtabs_and_lines *sals)
13509 /* We use the same method for breakpoint on probes. */
13510 bkpt_probe_decode_linespec (b, s, sals);
13513 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13515 /* The breakpoint_ops structure to be used on static tracepoints with
13519 strace_marker_create_sals_from_address (char **arg,
13520 struct linespec_result *canonical,
13521 enum bptype type_wanted,
13522 char *addr_start, char **copy_arg)
13524 struct linespec_sals lsal;
13526 lsal.sals = decode_static_tracepoint_spec (arg);
13528 *copy_arg = savestring (addr_start, *arg - addr_start);
13530 canonical->addr_string = xstrdup (*copy_arg);
13531 lsal.canonical = xstrdup (*copy_arg);
13532 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13536 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13537 struct linespec_result *canonical,
13538 struct linespec_sals *lsal,
13540 char *extra_string,
13541 enum bptype type_wanted,
13542 enum bpdisp disposition,
13544 int task, int ignore_count,
13545 const struct breakpoint_ops *ops,
13546 int from_tty, int enabled,
13547 int internal, unsigned flags)
13551 /* If the user is creating a static tracepoint by marker id
13552 (strace -m MARKER_ID), then store the sals index, so that
13553 breakpoint_re_set can try to match up which of the newly
13554 found markers corresponds to this one, and, don't try to
13555 expand multiple locations for each sal, given than SALS
13556 already should contain all sals for MARKER_ID. */
13558 for (i = 0; i < lsal->sals.nelts; ++i)
13560 struct symtabs_and_lines expanded;
13561 struct tracepoint *tp;
13562 struct cleanup *old_chain;
13565 expanded.nelts = 1;
13566 expanded.sals = &lsal->sals.sals[i];
13568 addr_string = xstrdup (canonical->addr_string);
13569 old_chain = make_cleanup (xfree, addr_string);
13571 tp = XCNEW (struct tracepoint);
13572 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13574 cond_string, extra_string,
13575 type_wanted, disposition,
13576 thread, task, ignore_count, ops,
13577 from_tty, enabled, internal, flags,
13578 canonical->special_display);
13579 /* Given that its possible to have multiple markers with
13580 the same string id, if the user is creating a static
13581 tracepoint by marker id ("strace -m MARKER_ID"), then
13582 store the sals index, so that breakpoint_re_set can
13583 try to match up which of the newly found markers
13584 corresponds to this one */
13585 tp->static_trace_marker_id_idx = i;
13587 install_breakpoint (internal, &tp->base, 0);
13589 discard_cleanups (old_chain);
13594 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13595 struct symtabs_and_lines *sals)
13597 struct tracepoint *tp = (struct tracepoint *) b;
13599 *sals = decode_static_tracepoint_spec (s);
13600 if (sals->nelts > tp->static_trace_marker_id_idx)
13602 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13606 error (_("marker %s not found"), tp->static_trace_marker_id);
13609 static struct breakpoint_ops strace_marker_breakpoint_ops;
13612 strace_marker_p (struct breakpoint *b)
13614 return b->ops == &strace_marker_breakpoint_ops;
13617 /* Delete a breakpoint and clean up all traces of it in the data
13621 delete_breakpoint (struct breakpoint *bpt)
13623 struct breakpoint *b;
13625 gdb_assert (bpt != NULL);
13627 /* Has this bp already been deleted? This can happen because
13628 multiple lists can hold pointers to bp's. bpstat lists are
13631 One example of this happening is a watchpoint's scope bp. When
13632 the scope bp triggers, we notice that the watchpoint is out of
13633 scope, and delete it. We also delete its scope bp. But the
13634 scope bp is marked "auto-deleting", and is already on a bpstat.
13635 That bpstat is then checked for auto-deleting bp's, which are
13638 A real solution to this problem might involve reference counts in
13639 bp's, and/or giving them pointers back to their referencing
13640 bpstat's, and teaching delete_breakpoint to only free a bp's
13641 storage when no more references were extent. A cheaper bandaid
13643 if (bpt->type == bp_none)
13646 /* At least avoid this stale reference until the reference counting
13647 of breakpoints gets resolved. */
13648 if (bpt->related_breakpoint != bpt)
13650 struct breakpoint *related;
13651 struct watchpoint *w;
13653 if (bpt->type == bp_watchpoint_scope)
13654 w = (struct watchpoint *) bpt->related_breakpoint;
13655 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13656 w = (struct watchpoint *) bpt;
13660 watchpoint_del_at_next_stop (w);
13662 /* Unlink bpt from the bpt->related_breakpoint ring. */
13663 for (related = bpt; related->related_breakpoint != bpt;
13664 related = related->related_breakpoint);
13665 related->related_breakpoint = bpt->related_breakpoint;
13666 bpt->related_breakpoint = bpt;
13669 /* watch_command_1 creates a watchpoint but only sets its number if
13670 update_watchpoint succeeds in creating its bp_locations. If there's
13671 a problem in that process, we'll be asked to delete the half-created
13672 watchpoint. In that case, don't announce the deletion. */
13674 observer_notify_breakpoint_deleted (bpt);
13676 if (breakpoint_chain == bpt)
13677 breakpoint_chain = bpt->next;
13679 ALL_BREAKPOINTS (b)
13680 if (b->next == bpt)
13682 b->next = bpt->next;
13686 /* Be sure no bpstat's are pointing at the breakpoint after it's
13688 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13689 in all threads for now. Note that we cannot just remove bpstats
13690 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13691 commands are associated with the bpstat; if we remove it here,
13692 then the later call to bpstat_do_actions (&stop_bpstat); in
13693 event-top.c won't do anything, and temporary breakpoints with
13694 commands won't work. */
13696 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13698 /* Now that breakpoint is removed from breakpoint list, update the
13699 global location list. This will remove locations that used to
13700 belong to this breakpoint. Do this before freeing the breakpoint
13701 itself, since remove_breakpoint looks at location's owner. It
13702 might be better design to have location completely
13703 self-contained, but it's not the case now. */
13704 update_global_location_list (0);
13706 bpt->ops->dtor (bpt);
13707 /* On the chance that someone will soon try again to delete this
13708 same bp, we mark it as deleted before freeing its storage. */
13709 bpt->type = bp_none;
13714 do_delete_breakpoint_cleanup (void *b)
13716 delete_breakpoint (b);
13720 make_cleanup_delete_breakpoint (struct breakpoint *b)
13722 return make_cleanup (do_delete_breakpoint_cleanup, b);
13725 /* Iterator function to call a user-provided callback function once
13726 for each of B and its related breakpoints. */
13729 iterate_over_related_breakpoints (struct breakpoint *b,
13730 void (*function) (struct breakpoint *,
13734 struct breakpoint *related;
13739 struct breakpoint *next;
13741 /* FUNCTION may delete RELATED. */
13742 next = related->related_breakpoint;
13744 if (next == related)
13746 /* RELATED is the last ring entry. */
13747 function (related, data);
13749 /* FUNCTION may have deleted it, so we'd never reach back to
13750 B. There's nothing left to do anyway, so just break
13755 function (related, data);
13759 while (related != b);
13763 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13765 delete_breakpoint (b);
13768 /* A callback for map_breakpoint_numbers that calls
13769 delete_breakpoint. */
13772 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13774 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13778 delete_command (char *arg, int from_tty)
13780 struct breakpoint *b, *b_tmp;
13786 int breaks_to_delete = 0;
13788 /* Delete all breakpoints if no argument. Do not delete
13789 internal breakpoints, these have to be deleted with an
13790 explicit breakpoint number argument. */
13791 ALL_BREAKPOINTS (b)
13792 if (user_breakpoint_p (b))
13794 breaks_to_delete = 1;
13798 /* Ask user only if there are some breakpoints to delete. */
13800 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13802 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13803 if (user_breakpoint_p (b))
13804 delete_breakpoint (b);
13808 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13812 all_locations_are_pending (struct bp_location *loc)
13814 for (; loc; loc = loc->next)
13815 if (!loc->shlib_disabled
13816 && !loc->pspace->executing_startup)
13821 /* Subroutine of update_breakpoint_locations to simplify it.
13822 Return non-zero if multiple fns in list LOC have the same name.
13823 Null names are ignored. */
13826 ambiguous_names_p (struct bp_location *loc)
13828 struct bp_location *l;
13829 htab_t htab = htab_create_alloc (13, htab_hash_string,
13830 (int (*) (const void *,
13831 const void *)) streq,
13832 NULL, xcalloc, xfree);
13834 for (l = loc; l != NULL; l = l->next)
13837 const char *name = l->function_name;
13839 /* Allow for some names to be NULL, ignore them. */
13843 slot = (const char **) htab_find_slot (htab, (const void *) name,
13845 /* NOTE: We can assume slot != NULL here because xcalloc never
13849 htab_delete (htab);
13855 htab_delete (htab);
13859 /* When symbols change, it probably means the sources changed as well,
13860 and it might mean the static tracepoint markers are no longer at
13861 the same address or line numbers they used to be at last we
13862 checked. Losing your static tracepoints whenever you rebuild is
13863 undesirable. This function tries to resync/rematch gdb static
13864 tracepoints with the markers on the target, for static tracepoints
13865 that have not been set by marker id. Static tracepoint that have
13866 been set by marker id are reset by marker id in breakpoint_re_set.
13869 1) For a tracepoint set at a specific address, look for a marker at
13870 the old PC. If one is found there, assume to be the same marker.
13871 If the name / string id of the marker found is different from the
13872 previous known name, assume that means the user renamed the marker
13873 in the sources, and output a warning.
13875 2) For a tracepoint set at a given line number, look for a marker
13876 at the new address of the old line number. If one is found there,
13877 assume to be the same marker. If the name / string id of the
13878 marker found is different from the previous known name, assume that
13879 means the user renamed the marker in the sources, and output a
13882 3) If a marker is no longer found at the same address or line, it
13883 may mean the marker no longer exists. But it may also just mean
13884 the code changed a bit. Maybe the user added a few lines of code
13885 that made the marker move up or down (in line number terms). Ask
13886 the target for info about the marker with the string id as we knew
13887 it. If found, update line number and address in the matching
13888 static tracepoint. This will get confused if there's more than one
13889 marker with the same ID (possible in UST, although unadvised
13890 precisely because it confuses tools). */
13892 static struct symtab_and_line
13893 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13895 struct tracepoint *tp = (struct tracepoint *) b;
13896 struct static_tracepoint_marker marker;
13901 find_line_pc (sal.symtab, sal.line, &pc);
13903 if (target_static_tracepoint_marker_at (pc, &marker))
13905 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13906 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13908 tp->static_trace_marker_id, marker.str_id);
13910 xfree (tp->static_trace_marker_id);
13911 tp->static_trace_marker_id = xstrdup (marker.str_id);
13912 release_static_tracepoint_marker (&marker);
13917 /* Old marker wasn't found on target at lineno. Try looking it up
13919 if (!sal.explicit_pc
13921 && sal.symtab != NULL
13922 && tp->static_trace_marker_id != NULL)
13924 VEC(static_tracepoint_marker_p) *markers;
13927 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13929 if (!VEC_empty(static_tracepoint_marker_p, markers))
13931 struct symtab_and_line sal2;
13932 struct symbol *sym;
13933 struct static_tracepoint_marker *tpmarker;
13934 struct ui_out *uiout = current_uiout;
13936 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13938 xfree (tp->static_trace_marker_id);
13939 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13941 warning (_("marker for static tracepoint %d (%s) not "
13942 "found at previous line number"),
13943 b->number, tp->static_trace_marker_id);
13947 sal2.pc = tpmarker->address;
13949 sal2 = find_pc_line (tpmarker->address, 0);
13950 sym = find_pc_sect_function (tpmarker->address, NULL);
13951 ui_out_text (uiout, "Now in ");
13954 ui_out_field_string (uiout, "func",
13955 SYMBOL_PRINT_NAME (sym));
13956 ui_out_text (uiout, " at ");
13958 ui_out_field_string (uiout, "file",
13959 symtab_to_filename_for_display (sal2.symtab));
13960 ui_out_text (uiout, ":");
13962 if (ui_out_is_mi_like_p (uiout))
13964 const char *fullname = symtab_to_fullname (sal2.symtab);
13966 ui_out_field_string (uiout, "fullname", fullname);
13969 ui_out_field_int (uiout, "line", sal2.line);
13970 ui_out_text (uiout, "\n");
13972 b->loc->line_number = sal2.line;
13973 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13975 xfree (b->addr_string);
13976 b->addr_string = xstrprintf ("%s:%d",
13977 symtab_to_filename_for_display (sal2.symtab),
13978 b->loc->line_number);
13980 /* Might be nice to check if function changed, and warn if
13983 release_static_tracepoint_marker (tpmarker);
13989 /* Returns 1 iff locations A and B are sufficiently same that
13990 we don't need to report breakpoint as changed. */
13993 locations_are_equal (struct bp_location *a, struct bp_location *b)
13997 if (a->address != b->address)
14000 if (a->shlib_disabled != b->shlib_disabled)
14003 if (a->enabled != b->enabled)
14010 if ((a == NULL) != (b == NULL))
14016 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14017 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14018 a ranged breakpoint. */
14021 update_breakpoint_locations (struct breakpoint *b,
14022 struct symtabs_and_lines sals,
14023 struct symtabs_and_lines sals_end)
14026 struct bp_location *existing_locations = b->loc;
14028 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14030 /* Ranged breakpoints have only one start location and one end
14032 b->enable_state = bp_disabled;
14033 update_global_location_list (1);
14034 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14035 "multiple locations found\n"),
14040 /* If there's no new locations, and all existing locations are
14041 pending, don't do anything. This optimizes the common case where
14042 all locations are in the same shared library, that was unloaded.
14043 We'd like to retain the location, so that when the library is
14044 loaded again, we don't loose the enabled/disabled status of the
14045 individual locations. */
14046 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14051 for (i = 0; i < sals.nelts; ++i)
14053 struct bp_location *new_loc;
14055 switch_to_program_space_and_thread (sals.sals[i].pspace);
14057 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14059 /* Reparse conditions, they might contain references to the
14061 if (b->cond_string != NULL)
14064 volatile struct gdb_exception e;
14066 s = b->cond_string;
14067 TRY_CATCH (e, RETURN_MASK_ERROR)
14069 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14070 block_for_pc (sals.sals[i].pc),
14075 warning (_("failed to reevaluate condition "
14076 "for breakpoint %d: %s"),
14077 b->number, e.message);
14078 new_loc->enabled = 0;
14082 if (sals_end.nelts)
14084 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14086 new_loc->length = end - sals.sals[0].pc + 1;
14090 /* Update locations of permanent breakpoints. */
14091 if (b->enable_state == bp_permanent)
14092 make_breakpoint_permanent (b);
14094 /* If possible, carry over 'disable' status from existing
14097 struct bp_location *e = existing_locations;
14098 /* If there are multiple breakpoints with the same function name,
14099 e.g. for inline functions, comparing function names won't work.
14100 Instead compare pc addresses; this is just a heuristic as things
14101 may have moved, but in practice it gives the correct answer
14102 often enough until a better solution is found. */
14103 int have_ambiguous_names = ambiguous_names_p (b->loc);
14105 for (; e; e = e->next)
14107 if (!e->enabled && e->function_name)
14109 struct bp_location *l = b->loc;
14110 if (have_ambiguous_names)
14112 for (; l; l = l->next)
14113 if (breakpoint_locations_match (e, l))
14121 for (; l; l = l->next)
14122 if (l->function_name
14123 && strcmp (e->function_name, l->function_name) == 0)
14133 if (!locations_are_equal (existing_locations, b->loc))
14134 observer_notify_breakpoint_modified (b);
14136 update_global_location_list (1);
14139 /* Find the SaL locations corresponding to the given ADDR_STRING.
14140 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14142 static struct symtabs_and_lines
14143 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14146 struct symtabs_and_lines sals = {0};
14147 volatile struct gdb_exception e;
14149 gdb_assert (b->ops != NULL);
14152 TRY_CATCH (e, RETURN_MASK_ERROR)
14154 b->ops->decode_linespec (b, &s, &sals);
14158 int not_found_and_ok = 0;
14159 /* For pending breakpoints, it's expected that parsing will
14160 fail until the right shared library is loaded. User has
14161 already told to create pending breakpoints and don't need
14162 extra messages. If breakpoint is in bp_shlib_disabled
14163 state, then user already saw the message about that
14164 breakpoint being disabled, and don't want to see more
14166 if (e.error == NOT_FOUND_ERROR
14167 && (b->condition_not_parsed
14168 || (b->loc && b->loc->shlib_disabled)
14169 || (b->loc && b->loc->pspace->executing_startup)
14170 || b->enable_state == bp_disabled))
14171 not_found_and_ok = 1;
14173 if (!not_found_and_ok)
14175 /* We surely don't want to warn about the same breakpoint
14176 10 times. One solution, implemented here, is disable
14177 the breakpoint on error. Another solution would be to
14178 have separate 'warning emitted' flag. Since this
14179 happens only when a binary has changed, I don't know
14180 which approach is better. */
14181 b->enable_state = bp_disabled;
14182 throw_exception (e);
14186 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14190 for (i = 0; i < sals.nelts; ++i)
14191 resolve_sal_pc (&sals.sals[i]);
14192 if (b->condition_not_parsed && s && s[0])
14194 char *cond_string, *extra_string;
14197 find_condition_and_thread (s, sals.sals[0].pc,
14198 &cond_string, &thread, &task,
14201 b->cond_string = cond_string;
14202 b->thread = thread;
14205 b->extra_string = extra_string;
14206 b->condition_not_parsed = 0;
14209 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14210 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14220 /* The default re_set method, for typical hardware or software
14221 breakpoints. Reevaluate the breakpoint and recreate its
14225 breakpoint_re_set_default (struct breakpoint *b)
14228 struct symtabs_and_lines sals, sals_end;
14229 struct symtabs_and_lines expanded = {0};
14230 struct symtabs_and_lines expanded_end = {0};
14232 sals = addr_string_to_sals (b, b->addr_string, &found);
14235 make_cleanup (xfree, sals.sals);
14239 if (b->addr_string_range_end)
14241 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14244 make_cleanup (xfree, sals_end.sals);
14245 expanded_end = sals_end;
14249 update_breakpoint_locations (b, expanded, expanded_end);
14252 /* Default method for creating SALs from an address string. It basically
14253 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14256 create_sals_from_address_default (char **arg,
14257 struct linespec_result *canonical,
14258 enum bptype type_wanted,
14259 char *addr_start, char **copy_arg)
14261 parse_breakpoint_sals (arg, canonical);
14264 /* Call create_breakpoints_sal for the given arguments. This is the default
14265 function for the `create_breakpoints_sal' method of
14269 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14270 struct linespec_result *canonical,
14271 struct linespec_sals *lsal,
14273 char *extra_string,
14274 enum bptype type_wanted,
14275 enum bpdisp disposition,
14277 int task, int ignore_count,
14278 const struct breakpoint_ops *ops,
14279 int from_tty, int enabled,
14280 int internal, unsigned flags)
14282 create_breakpoints_sal (gdbarch, canonical, cond_string,
14284 type_wanted, disposition,
14285 thread, task, ignore_count, ops, from_tty,
14286 enabled, internal, flags);
14289 /* Decode the line represented by S by calling decode_line_full. This is the
14290 default function for the `decode_linespec' method of breakpoint_ops. */
14293 decode_linespec_default (struct breakpoint *b, char **s,
14294 struct symtabs_and_lines *sals)
14296 struct linespec_result canonical;
14298 init_linespec_result (&canonical);
14299 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14300 (struct symtab *) NULL, 0,
14301 &canonical, multiple_symbols_all,
14304 /* We should get 0 or 1 resulting SALs. */
14305 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14307 if (VEC_length (linespec_sals, canonical.sals) > 0)
14309 struct linespec_sals *lsal;
14311 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14312 *sals = lsal->sals;
14313 /* Arrange it so the destructor does not free the
14315 lsal->sals.sals = NULL;
14318 destroy_linespec_result (&canonical);
14321 /* Prepare the global context for a re-set of breakpoint B. */
14323 static struct cleanup *
14324 prepare_re_set_context (struct breakpoint *b)
14326 struct cleanup *cleanups;
14328 input_radix = b->input_radix;
14329 cleanups = save_current_space_and_thread ();
14330 if (b->pspace != NULL)
14331 switch_to_program_space_and_thread (b->pspace);
14332 set_language (b->language);
14337 /* Reset a breakpoint given it's struct breakpoint * BINT.
14338 The value we return ends up being the return value from catch_errors.
14339 Unused in this case. */
14342 breakpoint_re_set_one (void *bint)
14344 /* Get past catch_errs. */
14345 struct breakpoint *b = (struct breakpoint *) bint;
14346 struct cleanup *cleanups;
14348 cleanups = prepare_re_set_context (b);
14349 b->ops->re_set (b);
14350 do_cleanups (cleanups);
14354 /* Re-set all breakpoints after symbols have been re-loaded. */
14356 breakpoint_re_set (void)
14358 struct breakpoint *b, *b_tmp;
14359 enum language save_language;
14360 int save_input_radix;
14361 struct cleanup *old_chain;
14363 save_language = current_language->la_language;
14364 save_input_radix = input_radix;
14365 old_chain = save_current_program_space ();
14367 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14369 /* Format possible error msg. */
14370 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14372 struct cleanup *cleanups = make_cleanup (xfree, message);
14373 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14374 do_cleanups (cleanups);
14376 set_language (save_language);
14377 input_radix = save_input_radix;
14379 jit_breakpoint_re_set ();
14381 do_cleanups (old_chain);
14383 create_overlay_event_breakpoint ();
14384 create_longjmp_master_breakpoint ();
14385 create_std_terminate_master_breakpoint ();
14386 create_exception_master_breakpoint ();
14389 /* Reset the thread number of this breakpoint:
14391 - If the breakpoint is for all threads, leave it as-is.
14392 - Else, reset it to the current thread for inferior_ptid. */
14394 breakpoint_re_set_thread (struct breakpoint *b)
14396 if (b->thread != -1)
14398 if (in_thread_list (inferior_ptid))
14399 b->thread = pid_to_thread_id (inferior_ptid);
14401 /* We're being called after following a fork. The new fork is
14402 selected as current, and unless this was a vfork will have a
14403 different program space from the original thread. Reset that
14405 b->loc->pspace = current_program_space;
14409 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14410 If from_tty is nonzero, it prints a message to that effect,
14411 which ends with a period (no newline). */
14414 set_ignore_count (int bptnum, int count, int from_tty)
14416 struct breakpoint *b;
14421 ALL_BREAKPOINTS (b)
14422 if (b->number == bptnum)
14424 if (is_tracepoint (b))
14426 if (from_tty && count != 0)
14427 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14432 b->ignore_count = count;
14436 printf_filtered (_("Will stop next time "
14437 "breakpoint %d is reached."),
14439 else if (count == 1)
14440 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14443 printf_filtered (_("Will ignore next %d "
14444 "crossings of breakpoint %d."),
14447 observer_notify_breakpoint_modified (b);
14451 error (_("No breakpoint number %d."), bptnum);
14454 /* Command to set ignore-count of breakpoint N to COUNT. */
14457 ignore_command (char *args, int from_tty)
14463 error_no_arg (_("a breakpoint number"));
14465 num = get_number (&p);
14467 error (_("bad breakpoint number: '%s'"), args);
14469 error (_("Second argument (specified ignore-count) is missing."));
14471 set_ignore_count (num,
14472 longest_to_int (value_as_long (parse_and_eval (p))),
14475 printf_filtered ("\n");
14478 /* Call FUNCTION on each of the breakpoints
14479 whose numbers are given in ARGS. */
14482 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14487 struct breakpoint *b, *tmp;
14489 struct get_number_or_range_state state;
14492 error_no_arg (_("one or more breakpoint numbers"));
14494 init_number_or_range (&state, args);
14496 while (!state.finished)
14498 char *p = state.string;
14502 num = get_number_or_range (&state);
14505 warning (_("bad breakpoint number at or near '%s'"), p);
14509 ALL_BREAKPOINTS_SAFE (b, tmp)
14510 if (b->number == num)
14513 function (b, data);
14517 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14522 static struct bp_location *
14523 find_location_by_number (char *number)
14525 char *dot = strchr (number, '.');
14529 struct breakpoint *b;
14530 struct bp_location *loc;
14535 bp_num = get_number (&p1);
14537 error (_("Bad breakpoint number '%s'"), number);
14539 ALL_BREAKPOINTS (b)
14540 if (b->number == bp_num)
14545 if (!b || b->number != bp_num)
14546 error (_("Bad breakpoint number '%s'"), number);
14549 loc_num = get_number (&p1);
14551 error (_("Bad breakpoint location number '%s'"), number);
14555 for (;loc_num && loc; --loc_num, loc = loc->next)
14558 error (_("Bad breakpoint location number '%s'"), dot+1);
14564 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14565 If from_tty is nonzero, it prints a message to that effect,
14566 which ends with a period (no newline). */
14569 disable_breakpoint (struct breakpoint *bpt)
14571 /* Never disable a watchpoint scope breakpoint; we want to
14572 hit them when we leave scope so we can delete both the
14573 watchpoint and its scope breakpoint at that time. */
14574 if (bpt->type == bp_watchpoint_scope)
14577 /* You can't disable permanent breakpoints. */
14578 if (bpt->enable_state == bp_permanent)
14581 bpt->enable_state = bp_disabled;
14583 /* Mark breakpoint locations modified. */
14584 mark_breakpoint_modified (bpt);
14586 if (target_supports_enable_disable_tracepoint ()
14587 && current_trace_status ()->running && is_tracepoint (bpt))
14589 struct bp_location *location;
14591 for (location = bpt->loc; location; location = location->next)
14592 target_disable_tracepoint (location);
14595 update_global_location_list (0);
14597 observer_notify_breakpoint_modified (bpt);
14600 /* A callback for iterate_over_related_breakpoints. */
14603 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14605 disable_breakpoint (b);
14608 /* A callback for map_breakpoint_numbers that calls
14609 disable_breakpoint. */
14612 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14614 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14618 disable_command (char *args, int from_tty)
14622 struct breakpoint *bpt;
14624 ALL_BREAKPOINTS (bpt)
14625 if (user_breakpoint_p (bpt))
14626 disable_breakpoint (bpt);
14628 else if (strchr (args, '.'))
14630 struct bp_location *loc = find_location_by_number (args);
14636 mark_breakpoint_location_modified (loc);
14638 if (target_supports_enable_disable_tracepoint ()
14639 && current_trace_status ()->running && loc->owner
14640 && is_tracepoint (loc->owner))
14641 target_disable_tracepoint (loc);
14643 update_global_location_list (0);
14646 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14650 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14653 int target_resources_ok;
14655 if (bpt->type == bp_hardware_breakpoint)
14658 i = hw_breakpoint_used_count ();
14659 target_resources_ok =
14660 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14662 if (target_resources_ok == 0)
14663 error (_("No hardware breakpoint support in the target."));
14664 else if (target_resources_ok < 0)
14665 error (_("Hardware breakpoints used exceeds limit."));
14668 if (is_watchpoint (bpt))
14670 /* Initialize it just to avoid a GCC false warning. */
14671 enum enable_state orig_enable_state = 0;
14672 volatile struct gdb_exception e;
14674 TRY_CATCH (e, RETURN_MASK_ALL)
14676 struct watchpoint *w = (struct watchpoint *) bpt;
14678 orig_enable_state = bpt->enable_state;
14679 bpt->enable_state = bp_enabled;
14680 update_watchpoint (w, 1 /* reparse */);
14684 bpt->enable_state = orig_enable_state;
14685 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14691 if (bpt->enable_state != bp_permanent)
14692 bpt->enable_state = bp_enabled;
14694 bpt->enable_state = bp_enabled;
14696 /* Mark breakpoint locations modified. */
14697 mark_breakpoint_modified (bpt);
14699 if (target_supports_enable_disable_tracepoint ()
14700 && current_trace_status ()->running && is_tracepoint (bpt))
14702 struct bp_location *location;
14704 for (location = bpt->loc; location; location = location->next)
14705 target_enable_tracepoint (location);
14708 bpt->disposition = disposition;
14709 bpt->enable_count = count;
14710 update_global_location_list (1);
14712 observer_notify_breakpoint_modified (bpt);
14717 enable_breakpoint (struct breakpoint *bpt)
14719 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14723 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14725 enable_breakpoint (bpt);
14728 /* A callback for map_breakpoint_numbers that calls
14729 enable_breakpoint. */
14732 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14734 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14737 /* The enable command enables the specified breakpoints (or all defined
14738 breakpoints) so they once again become (or continue to be) effective
14739 in stopping the inferior. */
14742 enable_command (char *args, int from_tty)
14746 struct breakpoint *bpt;
14748 ALL_BREAKPOINTS (bpt)
14749 if (user_breakpoint_p (bpt))
14750 enable_breakpoint (bpt);
14752 else if (strchr (args, '.'))
14754 struct bp_location *loc = find_location_by_number (args);
14760 mark_breakpoint_location_modified (loc);
14762 if (target_supports_enable_disable_tracepoint ()
14763 && current_trace_status ()->running && loc->owner
14764 && is_tracepoint (loc->owner))
14765 target_enable_tracepoint (loc);
14767 update_global_location_list (1);
14770 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14773 /* This struct packages up disposition data for application to multiple
14783 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14785 struct disp_data disp_data = *(struct disp_data *) arg;
14787 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14791 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14793 struct disp_data disp = { disp_disable, 1 };
14795 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14799 enable_once_command (char *args, int from_tty)
14801 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14805 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14807 struct disp_data disp = { disp_disable, *(int *) countptr };
14809 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14813 enable_count_command (char *args, int from_tty)
14815 int count = get_number (&args);
14817 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14821 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14823 struct disp_data disp = { disp_del, 1 };
14825 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14829 enable_delete_command (char *args, int from_tty)
14831 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14835 set_breakpoint_cmd (char *args, int from_tty)
14840 show_breakpoint_cmd (char *args, int from_tty)
14844 /* Invalidate last known value of any hardware watchpoint if
14845 the memory which that value represents has been written to by
14849 invalidate_bp_value_on_memory_change (struct inferior *inferior,
14850 CORE_ADDR addr, ssize_t len,
14851 const bfd_byte *data)
14853 struct breakpoint *bp;
14855 ALL_BREAKPOINTS (bp)
14856 if (bp->enable_state == bp_enabled
14857 && bp->type == bp_hardware_watchpoint)
14859 struct watchpoint *wp = (struct watchpoint *) bp;
14861 if (wp->val_valid && wp->val)
14863 struct bp_location *loc;
14865 for (loc = bp->loc; loc != NULL; loc = loc->next)
14866 if (loc->loc_type == bp_loc_hardware_watchpoint
14867 && loc->address + loc->length > addr
14868 && addr + len > loc->address)
14870 value_free (wp->val);
14878 /* Create and insert a raw software breakpoint at PC. Return an
14879 identifier, which should be used to remove the breakpoint later.
14880 In general, places which call this should be using something on the
14881 breakpoint chain instead; this function should be eliminated
14885 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14886 struct address_space *aspace, CORE_ADDR pc)
14888 struct bp_target_info *bp_tgt;
14890 bp_tgt = XZALLOC (struct bp_target_info);
14892 bp_tgt->placed_address_space = aspace;
14893 bp_tgt->placed_address = pc;
14895 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14897 /* Could not insert the breakpoint. */
14905 /* Remove a breakpoint BP inserted by
14906 deprecated_insert_raw_breakpoint. */
14909 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14911 struct bp_target_info *bp_tgt = bp;
14914 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14920 /* One (or perhaps two) breakpoints used for software single
14923 static void *single_step_breakpoints[2];
14924 static struct gdbarch *single_step_gdbarch[2];
14926 /* Create and insert a breakpoint for software single step. */
14929 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14930 struct address_space *aspace,
14935 if (single_step_breakpoints[0] == NULL)
14937 bpt_p = &single_step_breakpoints[0];
14938 single_step_gdbarch[0] = gdbarch;
14942 gdb_assert (single_step_breakpoints[1] == NULL);
14943 bpt_p = &single_step_breakpoints[1];
14944 single_step_gdbarch[1] = gdbarch;
14947 /* NOTE drow/2006-04-11: A future improvement to this function would
14948 be to only create the breakpoints once, and actually put them on
14949 the breakpoint chain. That would let us use set_raw_breakpoint.
14950 We could adjust the addresses each time they were needed. Doing
14951 this requires corresponding changes elsewhere where single step
14952 breakpoints are handled, however. So, for now, we use this. */
14954 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14955 if (*bpt_p == NULL)
14956 error (_("Could not insert single-step breakpoint at %s"),
14957 paddress (gdbarch, next_pc));
14960 /* Check if the breakpoints used for software single stepping
14961 were inserted or not. */
14964 single_step_breakpoints_inserted (void)
14966 return (single_step_breakpoints[0] != NULL
14967 || single_step_breakpoints[1] != NULL);
14970 /* Remove and delete any breakpoints used for software single step. */
14973 remove_single_step_breakpoints (void)
14975 gdb_assert (single_step_breakpoints[0] != NULL);
14977 /* See insert_single_step_breakpoint for more about this deprecated
14979 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14980 single_step_breakpoints[0]);
14981 single_step_gdbarch[0] = NULL;
14982 single_step_breakpoints[0] = NULL;
14984 if (single_step_breakpoints[1] != NULL)
14986 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14987 single_step_breakpoints[1]);
14988 single_step_gdbarch[1] = NULL;
14989 single_step_breakpoints[1] = NULL;
14993 /* Delete software single step breakpoints without removing them from
14994 the inferior. This is intended to be used if the inferior's address
14995 space where they were inserted is already gone, e.g. after exit or
14999 cancel_single_step_breakpoints (void)
15003 for (i = 0; i < 2; i++)
15004 if (single_step_breakpoints[i])
15006 xfree (single_step_breakpoints[i]);
15007 single_step_breakpoints[i] = NULL;
15008 single_step_gdbarch[i] = NULL;
15012 /* Detach software single-step breakpoints from INFERIOR_PTID without
15016 detach_single_step_breakpoints (void)
15020 for (i = 0; i < 2; i++)
15021 if (single_step_breakpoints[i])
15022 target_remove_breakpoint (single_step_gdbarch[i],
15023 single_step_breakpoints[i]);
15026 /* Check whether a software single-step breakpoint is inserted at
15030 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15035 for (i = 0; i < 2; i++)
15037 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15039 && breakpoint_address_match (bp_tgt->placed_address_space,
15040 bp_tgt->placed_address,
15048 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15049 non-zero otherwise. */
15051 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15053 if (syscall_catchpoint_p (bp)
15054 && bp->enable_state != bp_disabled
15055 && bp->enable_state != bp_call_disabled)
15062 catch_syscall_enabled (void)
15064 struct catch_syscall_inferior_data *inf_data
15065 = get_catch_syscall_inferior_data (current_inferior ());
15067 return inf_data->total_syscalls_count != 0;
15071 catching_syscall_number (int syscall_number)
15073 struct breakpoint *bp;
15075 ALL_BREAKPOINTS (bp)
15076 if (is_syscall_catchpoint_enabled (bp))
15078 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15080 if (c->syscalls_to_be_caught)
15084 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15086 if (syscall_number == iter)
15096 /* Complete syscall names. Used by "catch syscall". */
15097 static VEC (char_ptr) *
15098 catch_syscall_completer (struct cmd_list_element *cmd,
15099 const char *text, const char *word)
15101 const char **list = get_syscall_names ();
15102 VEC (char_ptr) *retlist
15103 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15109 /* Tracepoint-specific operations. */
15111 /* Set tracepoint count to NUM. */
15113 set_tracepoint_count (int num)
15115 tracepoint_count = num;
15116 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15120 trace_command (char *arg, int from_tty)
15122 struct breakpoint_ops *ops;
15123 const char *arg_cp = arg;
15125 if (arg && probe_linespec_to_ops (&arg_cp))
15126 ops = &tracepoint_probe_breakpoint_ops;
15128 ops = &tracepoint_breakpoint_ops;
15130 create_breakpoint (get_current_arch (),
15132 NULL, 0, NULL, 1 /* parse arg */,
15134 bp_tracepoint /* type_wanted */,
15135 0 /* Ignore count */,
15136 pending_break_support,
15140 0 /* internal */, 0);
15144 ftrace_command (char *arg, int from_tty)
15146 create_breakpoint (get_current_arch (),
15148 NULL, 0, NULL, 1 /* parse arg */,
15150 bp_fast_tracepoint /* type_wanted */,
15151 0 /* Ignore count */,
15152 pending_break_support,
15153 &tracepoint_breakpoint_ops,
15156 0 /* internal */, 0);
15159 /* strace command implementation. Creates a static tracepoint. */
15162 strace_command (char *arg, int from_tty)
15164 struct breakpoint_ops *ops;
15166 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15167 or with a normal static tracepoint. */
15168 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15169 ops = &strace_marker_breakpoint_ops;
15171 ops = &tracepoint_breakpoint_ops;
15173 create_breakpoint (get_current_arch (),
15175 NULL, 0, NULL, 1 /* parse arg */,
15177 bp_static_tracepoint /* type_wanted */,
15178 0 /* Ignore count */,
15179 pending_break_support,
15183 0 /* internal */, 0);
15186 /* Set up a fake reader function that gets command lines from a linked
15187 list that was acquired during tracepoint uploading. */
15189 static struct uploaded_tp *this_utp;
15190 static int next_cmd;
15193 read_uploaded_action (void)
15197 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15204 /* Given information about a tracepoint as recorded on a target (which
15205 can be either a live system or a trace file), attempt to create an
15206 equivalent GDB tracepoint. This is not a reliable process, since
15207 the target does not necessarily have all the information used when
15208 the tracepoint was originally defined. */
15210 struct tracepoint *
15211 create_tracepoint_from_upload (struct uploaded_tp *utp)
15213 char *addr_str, small_buf[100];
15214 struct tracepoint *tp;
15216 if (utp->at_string)
15217 addr_str = utp->at_string;
15220 /* In the absence of a source location, fall back to raw
15221 address. Since there is no way to confirm that the address
15222 means the same thing as when the trace was started, warn the
15224 warning (_("Uploaded tracepoint %d has no "
15225 "source location, using raw address"),
15227 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15228 addr_str = small_buf;
15231 /* There's not much we can do with a sequence of bytecodes. */
15232 if (utp->cond && !utp->cond_string)
15233 warning (_("Uploaded tracepoint %d condition "
15234 "has no source form, ignoring it"),
15237 if (!create_breakpoint (get_current_arch (),
15239 utp->cond_string, -1, NULL,
15240 0 /* parse cond/thread */,
15242 utp->type /* type_wanted */,
15243 0 /* Ignore count */,
15244 pending_break_support,
15245 &tracepoint_breakpoint_ops,
15247 utp->enabled /* enabled */,
15249 CREATE_BREAKPOINT_FLAGS_INSERTED))
15252 /* Get the tracepoint we just created. */
15253 tp = get_tracepoint (tracepoint_count);
15254 gdb_assert (tp != NULL);
15258 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15261 trace_pass_command (small_buf, 0);
15264 /* If we have uploaded versions of the original commands, set up a
15265 special-purpose "reader" function and call the usual command line
15266 reader, then pass the result to the breakpoint command-setting
15268 if (!VEC_empty (char_ptr, utp->cmd_strings))
15270 struct command_line *cmd_list;
15275 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15277 breakpoint_set_commands (&tp->base, cmd_list);
15279 else if (!VEC_empty (char_ptr, utp->actions)
15280 || !VEC_empty (char_ptr, utp->step_actions))
15281 warning (_("Uploaded tracepoint %d actions "
15282 "have no source form, ignoring them"),
15285 /* Copy any status information that might be available. */
15286 tp->base.hit_count = utp->hit_count;
15287 tp->traceframe_usage = utp->traceframe_usage;
15292 /* Print information on tracepoint number TPNUM_EXP, or all if
15296 tracepoints_info (char *args, int from_tty)
15298 struct ui_out *uiout = current_uiout;
15301 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15303 if (num_printed == 0)
15305 if (args == NULL || *args == '\0')
15306 ui_out_message (uiout, 0, "No tracepoints.\n");
15308 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15311 default_collect_info ();
15314 /* The 'enable trace' command enables tracepoints.
15315 Not supported by all targets. */
15317 enable_trace_command (char *args, int from_tty)
15319 enable_command (args, from_tty);
15322 /* The 'disable trace' command disables tracepoints.
15323 Not supported by all targets. */
15325 disable_trace_command (char *args, int from_tty)
15327 disable_command (args, from_tty);
15330 /* Remove a tracepoint (or all if no argument). */
15332 delete_trace_command (char *arg, int from_tty)
15334 struct breakpoint *b, *b_tmp;
15340 int breaks_to_delete = 0;
15342 /* Delete all breakpoints if no argument.
15343 Do not delete internal or call-dummy breakpoints, these
15344 have to be deleted with an explicit breakpoint number
15346 ALL_TRACEPOINTS (b)
15347 if (is_tracepoint (b) && user_breakpoint_p (b))
15349 breaks_to_delete = 1;
15353 /* Ask user only if there are some breakpoints to delete. */
15355 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15357 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15358 if (is_tracepoint (b) && user_breakpoint_p (b))
15359 delete_breakpoint (b);
15363 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15366 /* Helper function for trace_pass_command. */
15369 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15371 tp->pass_count = count;
15372 observer_notify_breakpoint_modified (&tp->base);
15374 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15375 tp->base.number, count);
15378 /* Set passcount for tracepoint.
15380 First command argument is passcount, second is tracepoint number.
15381 If tracepoint number omitted, apply to most recently defined.
15382 Also accepts special argument "all". */
15385 trace_pass_command (char *args, int from_tty)
15387 struct tracepoint *t1;
15388 unsigned int count;
15390 if (args == 0 || *args == 0)
15391 error (_("passcount command requires an "
15392 "argument (count + optional TP num)"));
15394 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15396 args = skip_spaces (args);
15397 if (*args && strncasecmp (args, "all", 3) == 0)
15399 struct breakpoint *b;
15401 args += 3; /* Skip special argument "all". */
15403 error (_("Junk at end of arguments."));
15405 ALL_TRACEPOINTS (b)
15407 t1 = (struct tracepoint *) b;
15408 trace_pass_set_count (t1, count, from_tty);
15411 else if (*args == '\0')
15413 t1 = get_tracepoint_by_number (&args, NULL, 1);
15415 trace_pass_set_count (t1, count, from_tty);
15419 struct get_number_or_range_state state;
15421 init_number_or_range (&state, args);
15422 while (!state.finished)
15424 t1 = get_tracepoint_by_number (&args, &state, 1);
15426 trace_pass_set_count (t1, count, from_tty);
15431 struct tracepoint *
15432 get_tracepoint (int num)
15434 struct breakpoint *t;
15436 ALL_TRACEPOINTS (t)
15437 if (t->number == num)
15438 return (struct tracepoint *) t;
15443 /* Find the tracepoint with the given target-side number (which may be
15444 different from the tracepoint number after disconnecting and
15447 struct tracepoint *
15448 get_tracepoint_by_number_on_target (int num)
15450 struct breakpoint *b;
15452 ALL_TRACEPOINTS (b)
15454 struct tracepoint *t = (struct tracepoint *) b;
15456 if (t->number_on_target == num)
15463 /* Utility: parse a tracepoint number and look it up in the list.
15464 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15465 If OPTIONAL_P is true, then if the argument is missing, the most
15466 recent tracepoint (tracepoint_count) is returned. */
15467 struct tracepoint *
15468 get_tracepoint_by_number (char **arg,
15469 struct get_number_or_range_state *state,
15472 struct breakpoint *t;
15474 char *instring = arg == NULL ? NULL : *arg;
15478 gdb_assert (!state->finished);
15479 tpnum = get_number_or_range (state);
15481 else if (arg == NULL || *arg == NULL || ! **arg)
15484 tpnum = tracepoint_count;
15486 error_no_arg (_("tracepoint number"));
15489 tpnum = get_number (arg);
15493 if (instring && *instring)
15494 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15497 printf_filtered (_("Tracepoint argument missing "
15498 "and no previous tracepoint\n"));
15502 ALL_TRACEPOINTS (t)
15503 if (t->number == tpnum)
15505 return (struct tracepoint *) t;
15508 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15513 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15515 if (b->thread != -1)
15516 fprintf_unfiltered (fp, " thread %d", b->thread);
15519 fprintf_unfiltered (fp, " task %d", b->task);
15521 fprintf_unfiltered (fp, "\n");
15524 /* Save information on user settable breakpoints (watchpoints, etc) to
15525 a new script file named FILENAME. If FILTER is non-NULL, call it
15526 on each breakpoint and only include the ones for which it returns
15530 save_breakpoints (char *filename, int from_tty,
15531 int (*filter) (const struct breakpoint *))
15533 struct breakpoint *tp;
15536 struct cleanup *cleanup;
15537 struct ui_file *fp;
15538 int extra_trace_bits = 0;
15540 if (filename == 0 || *filename == 0)
15541 error (_("Argument required (file name in which to save)"));
15543 /* See if we have anything to save. */
15544 ALL_BREAKPOINTS (tp)
15546 /* Skip internal and momentary breakpoints. */
15547 if (!user_breakpoint_p (tp))
15550 /* If we have a filter, only save the breakpoints it accepts. */
15551 if (filter && !filter (tp))
15556 if (is_tracepoint (tp))
15558 extra_trace_bits = 1;
15560 /* We can stop searching. */
15567 warning (_("Nothing to save."));
15571 pathname = tilde_expand (filename);
15572 cleanup = make_cleanup (xfree, pathname);
15573 fp = gdb_fopen (pathname, "w");
15575 error (_("Unable to open file '%s' for saving (%s)"),
15576 filename, safe_strerror (errno));
15577 make_cleanup_ui_file_delete (fp);
15579 if (extra_trace_bits)
15580 save_trace_state_variables (fp);
15582 ALL_BREAKPOINTS (tp)
15584 /* Skip internal and momentary breakpoints. */
15585 if (!user_breakpoint_p (tp))
15588 /* If we have a filter, only save the breakpoints it accepts. */
15589 if (filter && !filter (tp))
15592 tp->ops->print_recreate (tp, fp);
15594 /* Note, we can't rely on tp->number for anything, as we can't
15595 assume the recreated breakpoint numbers will match. Use $bpnum
15598 if (tp->cond_string)
15599 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15601 if (tp->ignore_count)
15602 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15606 volatile struct gdb_exception ex;
15608 fprintf_unfiltered (fp, " commands\n");
15610 ui_out_redirect (current_uiout, fp);
15611 TRY_CATCH (ex, RETURN_MASK_ALL)
15613 print_command_lines (current_uiout, tp->commands->commands, 2);
15615 ui_out_redirect (current_uiout, NULL);
15618 throw_exception (ex);
15620 fprintf_unfiltered (fp, " end\n");
15623 if (tp->enable_state == bp_disabled)
15624 fprintf_unfiltered (fp, "disable\n");
15626 /* If this is a multi-location breakpoint, check if the locations
15627 should be individually disabled. Watchpoint locations are
15628 special, and not user visible. */
15629 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15631 struct bp_location *loc;
15634 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15636 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15640 if (extra_trace_bits && *default_collect)
15641 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15643 do_cleanups (cleanup);
15645 printf_filtered (_("Saved to file '%s'.\n"), filename);
15648 /* The `save breakpoints' command. */
15651 save_breakpoints_command (char *args, int from_tty)
15653 save_breakpoints (args, from_tty, NULL);
15656 /* The `save tracepoints' command. */
15659 save_tracepoints_command (char *args, int from_tty)
15661 save_breakpoints (args, from_tty, is_tracepoint);
15664 /* Create a vector of all tracepoints. */
15666 VEC(breakpoint_p) *
15667 all_tracepoints (void)
15669 VEC(breakpoint_p) *tp_vec = 0;
15670 struct breakpoint *tp;
15672 ALL_TRACEPOINTS (tp)
15674 VEC_safe_push (breakpoint_p, tp_vec, tp);
15681 /* This help string is used for the break, hbreak, tbreak and thbreak
15682 commands. It is defined as a macro to prevent duplication.
15683 COMMAND should be a string constant containing the name of the
15685 #define BREAK_ARGS_HELP(command) \
15686 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15687 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15688 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15689 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15690 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15691 If a line number is specified, break at start of code for that line.\n\
15692 If a function is specified, break at start of code for that function.\n\
15693 If an address is specified, break at that exact address.\n\
15694 With no LOCATION, uses current execution address of the selected\n\
15695 stack frame. This is useful for breaking on return to a stack frame.\n\
15697 THREADNUM is the number from \"info threads\".\n\
15698 CONDITION is a boolean expression.\n\
15700 Multiple breakpoints at one place are permitted, and useful if their\n\
15701 conditions are different.\n\
15703 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15705 /* List of subcommands for "catch". */
15706 static struct cmd_list_element *catch_cmdlist;
15708 /* List of subcommands for "tcatch". */
15709 static struct cmd_list_element *tcatch_cmdlist;
15712 add_catch_command (char *name, char *docstring,
15713 void (*sfunc) (char *args, int from_tty,
15714 struct cmd_list_element *command),
15715 completer_ftype *completer,
15716 void *user_data_catch,
15717 void *user_data_tcatch)
15719 struct cmd_list_element *command;
15721 command = add_cmd (name, class_breakpoint, NULL, docstring,
15723 set_cmd_sfunc (command, sfunc);
15724 set_cmd_context (command, user_data_catch);
15725 set_cmd_completer (command, completer);
15727 command = add_cmd (name, class_breakpoint, NULL, docstring,
15729 set_cmd_sfunc (command, sfunc);
15730 set_cmd_context (command, user_data_tcatch);
15731 set_cmd_completer (command, completer);
15735 clear_syscall_counts (struct inferior *inf)
15737 struct catch_syscall_inferior_data *inf_data
15738 = get_catch_syscall_inferior_data (inf);
15740 inf_data->total_syscalls_count = 0;
15741 inf_data->any_syscall_count = 0;
15742 VEC_free (int, inf_data->syscalls_counts);
15746 save_command (char *arg, int from_tty)
15748 printf_unfiltered (_("\"save\" must be followed by "
15749 "the name of a save subcommand.\n"));
15750 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15753 struct breakpoint *
15754 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15757 struct breakpoint *b, *b_tmp;
15759 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15761 if ((*callback) (b, data))
15768 /* Zero if any of the breakpoint's locations could be a location where
15769 functions have been inlined, nonzero otherwise. */
15772 is_non_inline_function (struct breakpoint *b)
15774 /* The shared library event breakpoint is set on the address of a
15775 non-inline function. */
15776 if (b->type == bp_shlib_event)
15782 /* Nonzero if the specified PC cannot be a location where functions
15783 have been inlined. */
15786 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15787 const struct target_waitstatus *ws)
15789 struct breakpoint *b;
15790 struct bp_location *bl;
15792 ALL_BREAKPOINTS (b)
15794 if (!is_non_inline_function (b))
15797 for (bl = b->loc; bl != NULL; bl = bl->next)
15799 if (!bl->shlib_disabled
15800 && bpstat_check_location (bl, aspace, pc, ws))
15808 /* Remove any references to OBJFILE which is going to be freed. */
15811 breakpoint_free_objfile (struct objfile *objfile)
15813 struct bp_location **locp, *loc;
15815 ALL_BP_LOCATIONS (loc, locp)
15816 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
15817 loc->symtab = NULL;
15821 initialize_breakpoint_ops (void)
15823 static int initialized = 0;
15825 struct breakpoint_ops *ops;
15831 /* The breakpoint_ops structure to be inherit by all kinds of
15832 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15833 internal and momentary breakpoints, etc.). */
15834 ops = &bkpt_base_breakpoint_ops;
15835 *ops = base_breakpoint_ops;
15836 ops->re_set = bkpt_re_set;
15837 ops->insert_location = bkpt_insert_location;
15838 ops->remove_location = bkpt_remove_location;
15839 ops->breakpoint_hit = bkpt_breakpoint_hit;
15840 ops->create_sals_from_address = bkpt_create_sals_from_address;
15841 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15842 ops->decode_linespec = bkpt_decode_linespec;
15844 /* The breakpoint_ops structure to be used in regular breakpoints. */
15845 ops = &bkpt_breakpoint_ops;
15846 *ops = bkpt_base_breakpoint_ops;
15847 ops->re_set = bkpt_re_set;
15848 ops->resources_needed = bkpt_resources_needed;
15849 ops->print_it = bkpt_print_it;
15850 ops->print_mention = bkpt_print_mention;
15851 ops->print_recreate = bkpt_print_recreate;
15853 /* Ranged breakpoints. */
15854 ops = &ranged_breakpoint_ops;
15855 *ops = bkpt_breakpoint_ops;
15856 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15857 ops->resources_needed = resources_needed_ranged_breakpoint;
15858 ops->print_it = print_it_ranged_breakpoint;
15859 ops->print_one = print_one_ranged_breakpoint;
15860 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15861 ops->print_mention = print_mention_ranged_breakpoint;
15862 ops->print_recreate = print_recreate_ranged_breakpoint;
15864 /* Internal breakpoints. */
15865 ops = &internal_breakpoint_ops;
15866 *ops = bkpt_base_breakpoint_ops;
15867 ops->re_set = internal_bkpt_re_set;
15868 ops->check_status = internal_bkpt_check_status;
15869 ops->print_it = internal_bkpt_print_it;
15870 ops->print_mention = internal_bkpt_print_mention;
15872 /* Momentary breakpoints. */
15873 ops = &momentary_breakpoint_ops;
15874 *ops = bkpt_base_breakpoint_ops;
15875 ops->re_set = momentary_bkpt_re_set;
15876 ops->check_status = momentary_bkpt_check_status;
15877 ops->print_it = momentary_bkpt_print_it;
15878 ops->print_mention = momentary_bkpt_print_mention;
15880 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15881 ops = &longjmp_breakpoint_ops;
15882 *ops = momentary_breakpoint_ops;
15883 ops->dtor = longjmp_bkpt_dtor;
15885 /* Probe breakpoints. */
15886 ops = &bkpt_probe_breakpoint_ops;
15887 *ops = bkpt_breakpoint_ops;
15888 ops->insert_location = bkpt_probe_insert_location;
15889 ops->remove_location = bkpt_probe_remove_location;
15890 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15891 ops->decode_linespec = bkpt_probe_decode_linespec;
15893 /* GNU v3 exception catchpoints. */
15894 ops = &gnu_v3_exception_catchpoint_ops;
15895 *ops = bkpt_breakpoint_ops;
15896 ops->print_it = print_it_exception_catchpoint;
15897 ops->print_one = print_one_exception_catchpoint;
15898 ops->print_mention = print_mention_exception_catchpoint;
15899 ops->print_recreate = print_recreate_exception_catchpoint;
15902 ops = &watchpoint_breakpoint_ops;
15903 *ops = base_breakpoint_ops;
15904 ops->dtor = dtor_watchpoint;
15905 ops->re_set = re_set_watchpoint;
15906 ops->insert_location = insert_watchpoint;
15907 ops->remove_location = remove_watchpoint;
15908 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15909 ops->check_status = check_status_watchpoint;
15910 ops->resources_needed = resources_needed_watchpoint;
15911 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15912 ops->print_it = print_it_watchpoint;
15913 ops->print_mention = print_mention_watchpoint;
15914 ops->print_recreate = print_recreate_watchpoint;
15916 /* Masked watchpoints. */
15917 ops = &masked_watchpoint_breakpoint_ops;
15918 *ops = watchpoint_breakpoint_ops;
15919 ops->insert_location = insert_masked_watchpoint;
15920 ops->remove_location = remove_masked_watchpoint;
15921 ops->resources_needed = resources_needed_masked_watchpoint;
15922 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15923 ops->print_it = print_it_masked_watchpoint;
15924 ops->print_one_detail = print_one_detail_masked_watchpoint;
15925 ops->print_mention = print_mention_masked_watchpoint;
15926 ops->print_recreate = print_recreate_masked_watchpoint;
15929 ops = &tracepoint_breakpoint_ops;
15930 *ops = base_breakpoint_ops;
15931 ops->re_set = tracepoint_re_set;
15932 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15933 ops->print_one_detail = tracepoint_print_one_detail;
15934 ops->print_mention = tracepoint_print_mention;
15935 ops->print_recreate = tracepoint_print_recreate;
15936 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15937 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15938 ops->decode_linespec = tracepoint_decode_linespec;
15940 /* Probe tracepoints. */
15941 ops = &tracepoint_probe_breakpoint_ops;
15942 *ops = tracepoint_breakpoint_ops;
15943 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15944 ops->decode_linespec = tracepoint_probe_decode_linespec;
15946 /* Static tracepoints with marker (`-m'). */
15947 ops = &strace_marker_breakpoint_ops;
15948 *ops = tracepoint_breakpoint_ops;
15949 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15950 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15951 ops->decode_linespec = strace_marker_decode_linespec;
15953 /* Fork catchpoints. */
15954 ops = &catch_fork_breakpoint_ops;
15955 *ops = base_breakpoint_ops;
15956 ops->insert_location = insert_catch_fork;
15957 ops->remove_location = remove_catch_fork;
15958 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15959 ops->print_it = print_it_catch_fork;
15960 ops->print_one = print_one_catch_fork;
15961 ops->print_mention = print_mention_catch_fork;
15962 ops->print_recreate = print_recreate_catch_fork;
15964 /* Vfork catchpoints. */
15965 ops = &catch_vfork_breakpoint_ops;
15966 *ops = base_breakpoint_ops;
15967 ops->insert_location = insert_catch_vfork;
15968 ops->remove_location = remove_catch_vfork;
15969 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15970 ops->print_it = print_it_catch_vfork;
15971 ops->print_one = print_one_catch_vfork;
15972 ops->print_mention = print_mention_catch_vfork;
15973 ops->print_recreate = print_recreate_catch_vfork;
15975 /* Exec catchpoints. */
15976 ops = &catch_exec_breakpoint_ops;
15977 *ops = base_breakpoint_ops;
15978 ops->dtor = dtor_catch_exec;
15979 ops->insert_location = insert_catch_exec;
15980 ops->remove_location = remove_catch_exec;
15981 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15982 ops->print_it = print_it_catch_exec;
15983 ops->print_one = print_one_catch_exec;
15984 ops->print_mention = print_mention_catch_exec;
15985 ops->print_recreate = print_recreate_catch_exec;
15987 /* Syscall catchpoints. */
15988 ops = &catch_syscall_breakpoint_ops;
15989 *ops = base_breakpoint_ops;
15990 ops->dtor = dtor_catch_syscall;
15991 ops->insert_location = insert_catch_syscall;
15992 ops->remove_location = remove_catch_syscall;
15993 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15994 ops->print_it = print_it_catch_syscall;
15995 ops->print_one = print_one_catch_syscall;
15996 ops->print_mention = print_mention_catch_syscall;
15997 ops->print_recreate = print_recreate_catch_syscall;
15999 /* Solib-related catchpoints. */
16000 ops = &catch_solib_breakpoint_ops;
16001 *ops = base_breakpoint_ops;
16002 ops->dtor = dtor_catch_solib;
16003 ops->insert_location = insert_catch_solib;
16004 ops->remove_location = remove_catch_solib;
16005 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16006 ops->check_status = check_status_catch_solib;
16007 ops->print_it = print_it_catch_solib;
16008 ops->print_one = print_one_catch_solib;
16009 ops->print_mention = print_mention_catch_solib;
16010 ops->print_recreate = print_recreate_catch_solib;
16012 ops = &dprintf_breakpoint_ops;
16013 *ops = bkpt_base_breakpoint_ops;
16014 ops->re_set = bkpt_re_set;
16015 ops->resources_needed = bkpt_resources_needed;
16016 ops->print_it = bkpt_print_it;
16017 ops->print_mention = bkpt_print_mention;
16018 ops->print_recreate = bkpt_print_recreate;
16021 /* Chain containing all defined "enable breakpoint" subcommands. */
16023 static struct cmd_list_element *enablebreaklist = NULL;
16026 _initialize_breakpoint (void)
16028 struct cmd_list_element *c;
16030 initialize_breakpoint_ops ();
16032 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16033 observer_attach_inferior_exit (clear_syscall_counts);
16034 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16036 breakpoint_objfile_key
16037 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16039 catch_syscall_inferior_data
16040 = register_inferior_data_with_cleanup (NULL,
16041 catch_syscall_inferior_data_cleanup);
16043 breakpoint_chain = 0;
16044 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16045 before a breakpoint is set. */
16046 breakpoint_count = 0;
16048 tracepoint_count = 0;
16050 add_com ("ignore", class_breakpoint, ignore_command, _("\
16051 Set ignore-count of breakpoint number N to COUNT.\n\
16052 Usage is `ignore N COUNT'."));
16054 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16056 add_com ("commands", class_breakpoint, commands_command, _("\
16057 Set commands to be executed when a breakpoint is hit.\n\
16058 Give breakpoint number as argument after \"commands\".\n\
16059 With no argument, the targeted breakpoint is the last one set.\n\
16060 The commands themselves follow starting on the next line.\n\
16061 Type a line containing \"end\" to indicate the end of them.\n\
16062 Give \"silent\" as the first line to make the breakpoint silent;\n\
16063 then no output is printed when it is hit, except what the commands print."));
16065 c = add_com ("condition", class_breakpoint, condition_command, _("\
16066 Specify breakpoint number N to break only if COND is true.\n\
16067 Usage is `condition N COND', where N is an integer and COND is an\n\
16068 expression to be evaluated whenever breakpoint N is reached."));
16069 set_cmd_completer (c, condition_completer);
16071 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16072 Set a temporary breakpoint.\n\
16073 Like \"break\" except the breakpoint is only temporary,\n\
16074 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16075 by using \"enable delete\" on the breakpoint number.\n\
16077 BREAK_ARGS_HELP ("tbreak")));
16078 set_cmd_completer (c, location_completer);
16080 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16081 Set a hardware assisted breakpoint.\n\
16082 Like \"break\" except the breakpoint requires hardware support,\n\
16083 some target hardware may not have this support.\n\
16085 BREAK_ARGS_HELP ("hbreak")));
16086 set_cmd_completer (c, location_completer);
16088 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16089 Set a temporary hardware assisted breakpoint.\n\
16090 Like \"hbreak\" except the breakpoint is only temporary,\n\
16091 so it will be deleted when hit.\n\
16093 BREAK_ARGS_HELP ("thbreak")));
16094 set_cmd_completer (c, location_completer);
16096 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16097 Enable some breakpoints.\n\
16098 Give breakpoint numbers (separated by spaces) as arguments.\n\
16099 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16100 This is used to cancel the effect of the \"disable\" command.\n\
16101 With a subcommand you can enable temporarily."),
16102 &enablelist, "enable ", 1, &cmdlist);
16104 add_com ("ab", class_breakpoint, enable_command, _("\
16105 Enable some breakpoints.\n\
16106 Give breakpoint numbers (separated by spaces) as arguments.\n\
16107 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16108 This is used to cancel the effect of the \"disable\" command.\n\
16109 With a subcommand you can enable temporarily."));
16111 add_com_alias ("en", "enable", class_breakpoint, 1);
16113 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16114 Enable some breakpoints.\n\
16115 Give breakpoint numbers (separated by spaces) as arguments.\n\
16116 This is used to cancel the effect of the \"disable\" command.\n\
16117 May be abbreviated to simply \"enable\".\n"),
16118 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16120 add_cmd ("once", no_class, enable_once_command, _("\
16121 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16122 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16125 add_cmd ("delete", no_class, enable_delete_command, _("\
16126 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16127 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16130 add_cmd ("count", no_class, enable_count_command, _("\
16131 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16132 If a breakpoint is hit while enabled in this fashion,\n\
16133 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16136 add_cmd ("delete", no_class, enable_delete_command, _("\
16137 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16138 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16141 add_cmd ("once", no_class, enable_once_command, _("\
16142 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16143 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16146 add_cmd ("count", no_class, enable_count_command, _("\
16147 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16148 If a breakpoint is hit while enabled in this fashion,\n\
16149 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16152 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16153 Disable some breakpoints.\n\
16154 Arguments are breakpoint numbers with spaces in between.\n\
16155 To disable all breakpoints, give no argument.\n\
16156 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16157 &disablelist, "disable ", 1, &cmdlist);
16158 add_com_alias ("dis", "disable", class_breakpoint, 1);
16159 add_com_alias ("disa", "disable", class_breakpoint, 1);
16161 add_com ("sb", class_breakpoint, disable_command, _("\
16162 Disable some breakpoints.\n\
16163 Arguments are breakpoint numbers with spaces in between.\n\
16164 To disable all breakpoints, give no argument.\n\
16165 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16167 add_cmd ("breakpoints", class_alias, disable_command, _("\
16168 Disable some breakpoints.\n\
16169 Arguments are breakpoint numbers with spaces in between.\n\
16170 To disable all breakpoints, give no argument.\n\
16171 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16172 This command may be abbreviated \"disable\"."),
16175 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16176 Delete some breakpoints or auto-display expressions.\n\
16177 Arguments are breakpoint numbers with spaces in between.\n\
16178 To delete all breakpoints, give no argument.\n\
16180 Also a prefix command for deletion of other GDB objects.\n\
16181 The \"unset\" command is also an alias for \"delete\"."),
16182 &deletelist, "delete ", 1, &cmdlist);
16183 add_com_alias ("d", "delete", class_breakpoint, 1);
16184 add_com_alias ("del", "delete", class_breakpoint, 1);
16186 add_com ("db", class_breakpoint, delete_command, _("\
16187 Delete some breakpoints.\n\
16188 Arguments are breakpoint numbers with spaces in between.\n\
16189 To delete all breakpoints, give no argument.\n"));
16191 add_cmd ("breakpoints", class_alias, delete_command, _("\
16192 Delete some breakpoints or auto-display expressions.\n\
16193 Arguments are breakpoint numbers with spaces in between.\n\
16194 To delete all breakpoints, give no argument.\n\
16195 This command may be abbreviated \"delete\"."),
16198 add_com ("clear", class_breakpoint, clear_command, _("\
16199 Clear breakpoint at specified line or function.\n\
16200 Argument may be line number, function name, or \"*\" and an address.\n\
16201 If line number is specified, all breakpoints in that line are cleared.\n\
16202 If function is specified, breakpoints at beginning of function are cleared.\n\
16203 If an address is specified, breakpoints at that address are cleared.\n\
16205 With no argument, clears all breakpoints in the line that the selected frame\n\
16206 is executing in.\n\
16208 See also the \"delete\" command which clears breakpoints by number."));
16209 add_com_alias ("cl", "clear", class_breakpoint, 1);
16211 c = add_com ("break", class_breakpoint, break_command, _("\
16212 Set breakpoint at specified line or function.\n"
16213 BREAK_ARGS_HELP ("break")));
16214 set_cmd_completer (c, location_completer);
16216 add_com_alias ("b", "break", class_run, 1);
16217 add_com_alias ("br", "break", class_run, 1);
16218 add_com_alias ("bre", "break", class_run, 1);
16219 add_com_alias ("brea", "break", class_run, 1);
16222 add_com_alias ("ba", "break", class_breakpoint, 1);
16226 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16227 Break in function/address or break at a line in the current file."),
16228 &stoplist, "stop ", 1, &cmdlist);
16229 add_cmd ("in", class_breakpoint, stopin_command,
16230 _("Break in function or address."), &stoplist);
16231 add_cmd ("at", class_breakpoint, stopat_command,
16232 _("Break at a line in the current file."), &stoplist);
16233 add_com ("status", class_info, breakpoints_info, _("\
16234 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16235 The \"Type\" column indicates one of:\n\
16236 \tbreakpoint - normal breakpoint\n\
16237 \twatchpoint - watchpoint\n\
16238 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16239 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16240 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16241 address and file/line number respectively.\n\
16243 Convenience variable \"$_\" and default examine address for \"x\"\n\
16244 are set to the address of the last breakpoint listed unless the command\n\
16245 is prefixed with \"server \".\n\n\
16246 Convenience variable \"$bpnum\" contains the number of the last\n\
16247 breakpoint set."));
16250 add_info ("breakpoints", breakpoints_info, _("\
16251 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16252 The \"Type\" column indicates one of:\n\
16253 \tbreakpoint - normal breakpoint\n\
16254 \twatchpoint - watchpoint\n\
16255 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16256 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16257 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16258 address and file/line number respectively.\n\
16260 Convenience variable \"$_\" and default examine address for \"x\"\n\
16261 are set to the address of the last breakpoint listed unless the command\n\
16262 is prefixed with \"server \".\n\n\
16263 Convenience variable \"$bpnum\" contains the number of the last\n\
16264 breakpoint set."));
16266 add_info_alias ("b", "breakpoints", 1);
16269 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16270 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16271 The \"Type\" column indicates one of:\n\
16272 \tbreakpoint - normal breakpoint\n\
16273 \twatchpoint - watchpoint\n\
16274 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16275 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16276 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16277 address and file/line number respectively.\n\
16279 Convenience variable \"$_\" and default examine address for \"x\"\n\
16280 are set to the address of the last breakpoint listed unless the command\n\
16281 is prefixed with \"server \".\n\n\
16282 Convenience variable \"$bpnum\" contains the number of the last\n\
16283 breakpoint set."));
16285 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16286 Status of all breakpoints, or breakpoint number NUMBER.\n\
16287 The \"Type\" column indicates one of:\n\
16288 \tbreakpoint - normal breakpoint\n\
16289 \twatchpoint - watchpoint\n\
16290 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16291 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16292 \tuntil - internal breakpoint used by the \"until\" command\n\
16293 \tfinish - internal breakpoint used by the \"finish\" command\n\
16294 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16295 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16296 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16297 address and file/line number respectively.\n\
16299 Convenience variable \"$_\" and default examine address for \"x\"\n\
16300 are set to the address of the last breakpoint listed unless the command\n\
16301 is prefixed with \"server \".\n\n\
16302 Convenience variable \"$bpnum\" contains the number of the last\n\
16304 &maintenanceinfolist);
16306 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16307 Set catchpoints to catch events."),
16308 &catch_cmdlist, "catch ",
16309 0/*allow-unknown*/, &cmdlist);
16311 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16312 Set temporary catchpoints to catch events."),
16313 &tcatch_cmdlist, "tcatch ",
16314 0/*allow-unknown*/, &cmdlist);
16316 /* Add catch and tcatch sub-commands. */
16317 add_catch_command ("catch", _("\
16318 Catch an exception, when caught."),
16319 catch_catch_command,
16323 add_catch_command ("throw", _("\
16324 Catch an exception, when thrown."),
16325 catch_throw_command,
16329 add_catch_command ("fork", _("Catch calls to fork."),
16330 catch_fork_command_1,
16332 (void *) (uintptr_t) catch_fork_permanent,
16333 (void *) (uintptr_t) catch_fork_temporary);
16334 add_catch_command ("vfork", _("Catch calls to vfork."),
16335 catch_fork_command_1,
16337 (void *) (uintptr_t) catch_vfork_permanent,
16338 (void *) (uintptr_t) catch_vfork_temporary);
16339 add_catch_command ("exec", _("Catch calls to exec."),
16340 catch_exec_command_1,
16344 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16345 Usage: catch load [REGEX]\n\
16346 If REGEX is given, only stop for libraries matching the regular expression."),
16347 catch_load_command_1,
16351 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16352 Usage: catch unload [REGEX]\n\
16353 If REGEX is given, only stop for libraries matching the regular expression."),
16354 catch_unload_command_1,
16358 add_catch_command ("syscall", _("\
16359 Catch system calls by their names and/or numbers.\n\
16360 Arguments say which system calls to catch. If no arguments\n\
16361 are given, every system call will be caught.\n\
16362 Arguments, if given, should be one or more system call names\n\
16363 (if your system supports that), or system call numbers."),
16364 catch_syscall_command_1,
16365 catch_syscall_completer,
16369 c = add_com ("watch", class_breakpoint, watch_command, _("\
16370 Set a watchpoint for an expression.\n\
16371 Usage: watch [-l|-location] EXPRESSION\n\
16372 A watchpoint stops execution of your program whenever the value of\n\
16373 an expression changes.\n\
16374 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16375 the memory to which it refers."));
16376 set_cmd_completer (c, expression_completer);
16378 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16379 Set a read watchpoint for an expression.\n\
16380 Usage: rwatch [-l|-location] EXPRESSION\n\
16381 A watchpoint stops execution of your program whenever the value of\n\
16382 an expression is read.\n\
16383 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16384 the memory to which it refers."));
16385 set_cmd_completer (c, expression_completer);
16387 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16388 Set a watchpoint for an expression.\n\
16389 Usage: awatch [-l|-location] EXPRESSION\n\
16390 A watchpoint stops execution of your program whenever the value of\n\
16391 an expression is either read or written.\n\
16392 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16393 the memory to which it refers."));
16394 set_cmd_completer (c, expression_completer);
16396 add_info ("watchpoints", watchpoints_info, _("\
16397 Status of specified watchpoints (all watchpoints if no argument)."));
16399 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16400 respond to changes - contrary to the description. */
16401 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16402 &can_use_hw_watchpoints, _("\
16403 Set debugger's willingness to use watchpoint hardware."), _("\
16404 Show debugger's willingness to use watchpoint hardware."), _("\
16405 If zero, gdb will not use hardware for new watchpoints, even if\n\
16406 such is available. (However, any hardware watchpoints that were\n\
16407 created before setting this to nonzero, will continue to use watchpoint\n\
16410 show_can_use_hw_watchpoints,
16411 &setlist, &showlist);
16413 can_use_hw_watchpoints = 1;
16415 /* Tracepoint manipulation commands. */
16417 c = add_com ("trace", class_breakpoint, trace_command, _("\
16418 Set a tracepoint at specified line or function.\n\
16420 BREAK_ARGS_HELP ("trace") "\n\
16421 Do \"help tracepoints\" for info on other tracepoint commands."));
16422 set_cmd_completer (c, location_completer);
16424 add_com_alias ("tp", "trace", class_alias, 0);
16425 add_com_alias ("tr", "trace", class_alias, 1);
16426 add_com_alias ("tra", "trace", class_alias, 1);
16427 add_com_alias ("trac", "trace", class_alias, 1);
16429 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16430 Set a fast tracepoint at specified line or function.\n\
16432 BREAK_ARGS_HELP ("ftrace") "\n\
16433 Do \"help tracepoints\" for info on other tracepoint commands."));
16434 set_cmd_completer (c, location_completer);
16436 c = add_com ("strace", class_breakpoint, strace_command, _("\
16437 Set a static tracepoint at specified line, function or marker.\n\
16439 strace [LOCATION] [if CONDITION]\n\
16440 LOCATION may be a line number, function name, \"*\" and an address,\n\
16441 or -m MARKER_ID.\n\
16442 If a line number is specified, probe the marker at start of code\n\
16443 for that line. If a function is specified, probe the marker at start\n\
16444 of code for that function. If an address is specified, probe the marker\n\
16445 at that exact address. If a marker id is specified, probe the marker\n\
16446 with that name. With no LOCATION, uses current execution address of\n\
16447 the selected stack frame.\n\
16448 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16449 This collects arbitrary user data passed in the probe point call to the\n\
16450 tracing library. You can inspect it when analyzing the trace buffer,\n\
16451 by printing the $_sdata variable like any other convenience variable.\n\
16453 CONDITION is a boolean expression.\n\
16455 Multiple tracepoints at one place are permitted, and useful if their\n\
16456 conditions are different.\n\
16458 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16459 Do \"help tracepoints\" for info on other tracepoint commands."));
16460 set_cmd_completer (c, location_completer);
16462 add_info ("tracepoints", tracepoints_info, _("\
16463 Status of specified tracepoints (all tracepoints if no argument).\n\
16464 Convenience variable \"$tpnum\" contains the number of the\n\
16465 last tracepoint set."));
16467 add_info_alias ("tp", "tracepoints", 1);
16469 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16470 Delete specified tracepoints.\n\
16471 Arguments are tracepoint numbers, separated by spaces.\n\
16472 No argument means delete all tracepoints."),
16474 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16476 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16477 Disable specified tracepoints.\n\
16478 Arguments are tracepoint numbers, separated by spaces.\n\
16479 No argument means disable all tracepoints."),
16481 deprecate_cmd (c, "disable");
16483 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16484 Enable specified tracepoints.\n\
16485 Arguments are tracepoint numbers, separated by spaces.\n\
16486 No argument means enable all tracepoints."),
16488 deprecate_cmd (c, "enable");
16490 add_com ("passcount", class_trace, trace_pass_command, _("\
16491 Set the passcount for a tracepoint.\n\
16492 The trace will end when the tracepoint has been passed 'count' times.\n\
16493 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16494 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16496 add_prefix_cmd ("save", class_breakpoint, save_command,
16497 _("Save breakpoint definitions as a script."),
16498 &save_cmdlist, "save ",
16499 0/*allow-unknown*/, &cmdlist);
16501 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16502 Save current breakpoint definitions as a script.\n\
16503 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16504 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16505 session to restore them."),
16507 set_cmd_completer (c, filename_completer);
16509 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16510 Save current tracepoint definitions as a script.\n\
16511 Use the 'source' command in another debug session to restore them."),
16513 set_cmd_completer (c, filename_completer);
16515 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16516 deprecate_cmd (c, "save tracepoints");
16518 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16519 Breakpoint specific settings\n\
16520 Configure various breakpoint-specific variables such as\n\
16521 pending breakpoint behavior"),
16522 &breakpoint_set_cmdlist, "set breakpoint ",
16523 0/*allow-unknown*/, &setlist);
16524 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16525 Breakpoint specific settings\n\
16526 Configure various breakpoint-specific variables such as\n\
16527 pending breakpoint behavior"),
16528 &breakpoint_show_cmdlist, "show breakpoint ",
16529 0/*allow-unknown*/, &showlist);
16531 add_setshow_auto_boolean_cmd ("pending", no_class,
16532 &pending_break_support, _("\
16533 Set debugger's behavior regarding pending breakpoints."), _("\
16534 Show debugger's behavior regarding pending breakpoints."), _("\
16535 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16536 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16537 an error. If auto, an unrecognized breakpoint location results in a\n\
16538 user-query to see if a pending breakpoint should be created."),
16540 show_pending_break_support,
16541 &breakpoint_set_cmdlist,
16542 &breakpoint_show_cmdlist);
16544 pending_break_support = AUTO_BOOLEAN_AUTO;
16546 add_setshow_boolean_cmd ("auto-hw", no_class,
16547 &automatic_hardware_breakpoints, _("\
16548 Set automatic usage of hardware breakpoints."), _("\
16549 Show automatic usage of hardware breakpoints."), _("\
16550 If set, the debugger will automatically use hardware breakpoints for\n\
16551 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16552 a warning will be emitted for such breakpoints."),
16554 show_automatic_hardware_breakpoints,
16555 &breakpoint_set_cmdlist,
16556 &breakpoint_show_cmdlist);
16558 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16559 &always_inserted_mode, _("\
16560 Set mode for inserting breakpoints."), _("\
16561 Show mode for inserting breakpoints."), _("\
16562 When this mode is off, breakpoints are inserted in inferior when it is\n\
16563 resumed, and removed when execution stops. When this mode is on,\n\
16564 breakpoints are inserted immediately and removed only when the user\n\
16565 deletes the breakpoint. When this mode is auto (which is the default),\n\
16566 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16567 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16568 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16569 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16571 &show_always_inserted_mode,
16572 &breakpoint_set_cmdlist,
16573 &breakpoint_show_cmdlist);
16575 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16576 condition_evaluation_enums,
16577 &condition_evaluation_mode_1, _("\
16578 Set mode of breakpoint condition evaluation."), _("\
16579 Show mode of breakpoint condition evaluation."), _("\
16580 When this is set to \"host\", breakpoint conditions will be\n\
16581 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16582 breakpoint conditions will be downloaded to the target (if the target\n\
16583 supports such feature) and conditions will be evaluated on the target's side.\n\
16584 If this is set to \"auto\" (default), this will be automatically set to\n\
16585 \"target\" if it supports condition evaluation, otherwise it will\n\
16586 be set to \"gdb\""),
16587 &set_condition_evaluation_mode,
16588 &show_condition_evaluation_mode,
16589 &breakpoint_set_cmdlist,
16590 &breakpoint_show_cmdlist);
16592 add_com ("break-range", class_breakpoint, break_range_command, _("\
16593 Set a breakpoint for an address range.\n\
16594 break-range START-LOCATION, END-LOCATION\n\
16595 where START-LOCATION and END-LOCATION can be one of the following:\n\
16596 LINENUM, for that line in the current file,\n\
16597 FILE:LINENUM, for that line in that file,\n\
16598 +OFFSET, for that number of lines after the current line\n\
16599 or the start of the range\n\
16600 FUNCTION, for the first line in that function,\n\
16601 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16602 *ADDRESS, for the instruction at that address.\n\
16604 The breakpoint will stop execution of the inferior whenever it executes\n\
16605 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16606 range (including START-LOCATION and END-LOCATION)."));
16608 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16609 Set a dynamic printf at specified line or function.\n\
16610 dprintf location,format string,arg1,arg2,...\n\
16611 location may be a line number, function name, or \"*\" and an address.\n\
16612 If a line number is specified, break at start of code for that line.\n\
16613 If a function is specified, break at start of code for that function.\n\
16615 set_cmd_completer (c, location_completer);
16617 add_setshow_enum_cmd ("dprintf-style", class_support,
16618 dprintf_style_enums, &dprintf_style, _("\
16619 Set the style of usage for dynamic printf."), _("\
16620 Show the style of usage for dynamic printf."), _("\
16621 This setting chooses how GDB will do a dynamic printf.\n\
16622 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16623 console, as with the \"printf\" command.\n\
16624 If the value is \"call\", the print is done by calling a function in your\n\
16625 program; by default printf(), but you can choose a different function or\n\
16626 output stream by setting dprintf-function and dprintf-channel."),
16627 update_dprintf_commands, NULL,
16628 &setlist, &showlist);
16630 dprintf_function = xstrdup ("printf");
16631 add_setshow_string_cmd ("dprintf-function", class_support,
16632 &dprintf_function, _("\
16633 Set the function to use for dynamic printf"), _("\
16634 Show the function to use for dynamic printf"), NULL,
16635 update_dprintf_commands, NULL,
16636 &setlist, &showlist);
16638 dprintf_channel = xstrdup ("");
16639 add_setshow_string_cmd ("dprintf-channel", class_support,
16640 &dprintf_channel, _("\
16641 Set the channel to use for dynamic printf"), _("\
16642 Show the channel to use for dynamic printf"), NULL,
16643 update_dprintf_commands, NULL,
16644 &setlist, &showlist);
16646 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16647 &disconnected_dprintf, _("\
16648 Set whether dprintf continues after GDB disconnects."), _("\
16649 Show whether dprintf continues after GDB disconnects."), _("\
16650 Use this to let dprintf commands continue to hit and produce output\n\
16651 even if GDB disconnects or detaches from the target."),
16654 &setlist, &showlist);
16656 add_com ("agent-printf", class_vars, agent_printf_command, _("\
16657 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16658 (target agent only) This is useful for formatted output in user-defined commands."));
16660 automatic_hardware_breakpoints = 1;
16662 observer_attach_about_to_proceed (breakpoint_about_to_proceed);