1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
41 #include "gdb-demangle.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "python/python.h"
81 /* Prototypes for local functions. */
83 static void enable_delete_command (char *, int);
85 static void enable_once_command (char *, int);
87 static void disable_command (char *, int);
89 static void enable_command (char *, int);
91 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
95 static void ignore_command (char *, int);
97 static int breakpoint_re_set_one (void *);
99 static void breakpoint_re_set_default (struct breakpoint *);
101 static void clear_command (char *, int);
103 static void catch_command (char *, int);
105 static int can_use_hardware_watchpoint (struct value *);
107 static void break_command_1 (char *, int, int);
109 static void mention (struct breakpoint *);
111 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
113 const struct breakpoint_ops *);
114 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
115 const struct symtab_and_line *);
117 /* This function is used in gdbtk sources and thus can not be made
119 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
120 struct symtab_and_line,
122 const struct breakpoint_ops *);
124 static struct breakpoint *
125 momentary_breakpoint_from_master (struct breakpoint *orig,
127 const struct breakpoint_ops *ops);
129 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
131 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
135 static void describe_other_breakpoints (struct gdbarch *,
136 struct program_space *, CORE_ADDR,
137 struct obj_section *, int);
139 static int breakpoint_address_match (struct address_space *aspace1,
141 struct address_space *aspace2,
144 static int watchpoint_locations_match (struct bp_location *loc1,
145 struct bp_location *loc2);
147 static int breakpoint_location_address_match (struct bp_location *bl,
148 struct address_space *aspace,
151 static void breakpoints_info (char *, int);
153 static void watchpoints_info (char *, int);
155 static int breakpoint_1 (char *, int,
156 int (*) (const struct breakpoint *));
158 static int breakpoint_cond_eval (void *);
160 static void cleanup_executing_breakpoints (void *);
162 static void commands_command (char *, int);
164 static void condition_command (char *, int);
173 static int remove_breakpoint (struct bp_location *, insertion_state_t);
174 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
176 static enum print_stop_action print_bp_stop_message (bpstat bs);
178 static int watchpoint_check (void *);
180 static void maintenance_info_breakpoints (char *, int);
182 static int hw_breakpoint_used_count (void);
184 static int hw_watchpoint_use_count (struct breakpoint *);
186 static int hw_watchpoint_used_count_others (struct breakpoint *except,
188 int *other_type_used);
190 static void hbreak_command (char *, int);
192 static void thbreak_command (char *, int);
194 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp);
196 static void stop_command (char *arg, int from_tty);
198 static void stopin_command (char *arg, int from_tty);
200 static void stopat_command (char *arg, int from_tty);
202 static char *ep_parse_optional_if_clause (char **arg);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event,
205 char *arg, int tempflag, int from_tty);
207 static void tcatch_command (char *arg, int from_tty);
209 static void detach_single_step_breakpoints (void);
211 static int single_step_breakpoint_inserted_here_p (struct address_space *,
214 static void free_bp_location (struct bp_location *loc);
215 static void incref_bp_location (struct bp_location *loc);
216 static void decref_bp_location (struct bp_location **loc);
218 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
220 static void update_global_location_list (int);
222 static void update_global_location_list_nothrow (int);
224 static int is_hardware_watchpoint (const struct breakpoint *bpt);
226 static void insert_breakpoint_locations (void);
228 static int syscall_catchpoint_p (struct breakpoint *b);
230 static void tracepoints_info (char *, int);
232 static void delete_trace_command (char *, int);
234 static void enable_trace_command (char *, int);
236 static void disable_trace_command (char *, int);
238 static void trace_pass_command (char *, int);
240 static int is_masked_watchpoint (const struct breakpoint *b);
242 /* Assuming we're creating a static tracepoint, does S look like a
243 static tracepoint marker spec ("-m MARKER_ID")? */
244 #define is_marker_spec(s) \
245 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
247 /* The abstract base class all breakpoint_ops structures inherit
249 static struct breakpoint_ops base_breakpoint_ops;
251 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
252 that are implemented on top of software or hardware breakpoints
253 (user breakpoints, internal and momentary breakpoints, etc.). */
254 static struct breakpoint_ops bkpt_base_breakpoint_ops;
256 /* Internal breakpoints class type. */
257 static struct breakpoint_ops internal_breakpoint_ops;
259 /* Momentary breakpoints class type. */
260 static struct breakpoint_ops momentary_breakpoint_ops;
262 /* The breakpoint_ops structure to be used in regular user created
264 struct breakpoint_ops bkpt_breakpoint_ops;
266 /* A reference-counted struct command_line. This lets multiple
267 breakpoints share a single command list. */
268 struct counted_command_line
270 /* The reference count. */
273 /* The command list. */
274 struct command_line *commands;
277 struct command_line *
278 breakpoint_commands (struct breakpoint *b)
280 return b->commands ? b->commands->commands : NULL;
283 /* Flag indicating that a command has proceeded the inferior past the
284 current breakpoint. */
286 static int breakpoint_proceeded;
289 bpdisp_text (enum bpdisp disp)
291 /* NOTE: the following values are a part of MI protocol and
292 represent values of 'disp' field returned when inferior stops at
294 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
296 return bpdisps[(int) disp];
299 /* Prototypes for exported functions. */
300 /* If FALSE, gdb will not use hardware support for watchpoints, even
301 if such is available. */
302 static int can_use_hw_watchpoints;
305 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
306 struct cmd_list_element *c,
309 fprintf_filtered (file,
310 _("Debugger's willingness to use "
311 "watchpoint hardware is %s.\n"),
315 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
316 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
317 for unrecognized breakpoint locations.
318 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
319 static enum auto_boolean pending_break_support;
321 show_pending_break_support (struct ui_file *file, int from_tty,
322 struct cmd_list_element *c,
325 fprintf_filtered (file,
326 _("Debugger's behavior regarding "
327 "pending breakpoints is %s.\n"),
331 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
332 set with "break" but falling in read-only memory.
333 If 0, gdb will warn about such breakpoints, but won't automatically
334 use hardware breakpoints. */
335 static int automatic_hardware_breakpoints;
337 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
338 struct cmd_list_element *c,
341 fprintf_filtered (file,
342 _("Automatic usage of hardware breakpoints is %s.\n"),
346 /* If on, gdb will keep breakpoints inserted even as inferior is
347 stopped, and immediately insert any new breakpoints. If off, gdb
348 will insert breakpoints into inferior only when resuming it, and
349 will remove breakpoints upon stop. If auto, GDB will behave as ON
350 if in non-stop mode, and as OFF if all-stop mode.*/
352 static const char always_inserted_auto[] = "auto";
353 static const char always_inserted_on[] = "on";
354 static const char always_inserted_off[] = "off";
355 static const char *always_inserted_enums[] = {
356 always_inserted_auto,
361 static const char *always_inserted_mode = always_inserted_auto;
363 show_always_inserted_mode (struct ui_file *file, int from_tty,
364 struct cmd_list_element *c, const char *value)
366 if (always_inserted_mode == always_inserted_auto)
367 fprintf_filtered (file,
368 _("Always inserted breakpoint "
369 "mode is %s (currently %s).\n"),
371 breakpoints_always_inserted_mode () ? "on" : "off");
373 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
378 breakpoints_always_inserted_mode (void)
380 return (always_inserted_mode == always_inserted_on
381 || (always_inserted_mode == always_inserted_auto && non_stop));
384 void _initialize_breakpoint (void);
386 /* Are we executing breakpoint commands? */
387 static int executing_breakpoint_commands;
389 /* Are overlay event breakpoints enabled? */
390 static int overlay_events_enabled;
392 /* See description in breakpoint.h. */
393 int target_exact_watchpoints = 0;
395 /* Walk the following statement or block through all breakpoints.
396 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
397 current breakpoint. */
399 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
401 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
402 for (B = breakpoint_chain; \
403 B ? (TMP=B->next, 1): 0; \
406 /* Similar iterator for the low-level breakpoints. SAFE variant is
407 not provided so update_global_location_list must not be called
408 while executing the block of ALL_BP_LOCATIONS. */
410 #define ALL_BP_LOCATIONS(B,BP_TMP) \
411 for (BP_TMP = bp_location; \
412 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
415 /* Iterator for tracepoints only. */
417 #define ALL_TRACEPOINTS(B) \
418 for (B = breakpoint_chain; B; B = B->next) \
419 if (is_tracepoint (B))
421 /* Chains of all breakpoints defined. */
423 struct breakpoint *breakpoint_chain;
425 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
427 static struct bp_location **bp_location;
429 /* Number of elements of BP_LOCATION. */
431 static unsigned bp_location_count;
433 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
434 ADDRESS for the current elements of BP_LOCATION which get a valid
435 result from bp_location_has_shadow. You can use it for roughly
436 limiting the subrange of BP_LOCATION to scan for shadow bytes for
437 an address you need to read. */
439 static CORE_ADDR bp_location_placed_address_before_address_max;
441 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
442 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
443 BP_LOCATION which get a valid result from bp_location_has_shadow.
444 You can use it for roughly limiting the subrange of BP_LOCATION to
445 scan for shadow bytes for an address you need to read. */
447 static CORE_ADDR bp_location_shadow_len_after_address_max;
449 /* The locations that no longer correspond to any breakpoint, unlinked
450 from bp_location array, but for which a hit may still be reported
452 VEC(bp_location_p) *moribund_locations = NULL;
454 /* Number of last breakpoint made. */
456 static int breakpoint_count;
458 /* The value of `breakpoint_count' before the last command that
459 created breakpoints. If the last (break-like) command created more
460 than one breakpoint, then the difference between BREAKPOINT_COUNT
461 and PREV_BREAKPOINT_COUNT is more than one. */
462 static int prev_breakpoint_count;
464 /* Number of last tracepoint made. */
466 static int tracepoint_count;
468 static struct cmd_list_element *breakpoint_set_cmdlist;
469 static struct cmd_list_element *breakpoint_show_cmdlist;
470 struct cmd_list_element *save_cmdlist;
472 /* Return whether a breakpoint is an active enabled breakpoint. */
474 breakpoint_enabled (struct breakpoint *b)
476 return (b->enable_state == bp_enabled);
479 /* Set breakpoint count to NUM. */
482 set_breakpoint_count (int num)
484 prev_breakpoint_count = breakpoint_count;
485 breakpoint_count = num;
486 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
489 /* Used by `start_rbreak_breakpoints' below, to record the current
490 breakpoint count before "rbreak" creates any breakpoint. */
491 static int rbreak_start_breakpoint_count;
493 /* Called at the start an "rbreak" command to record the first
497 start_rbreak_breakpoints (void)
499 rbreak_start_breakpoint_count = breakpoint_count;
502 /* Called at the end of an "rbreak" command to record the last
506 end_rbreak_breakpoints (void)
508 prev_breakpoint_count = rbreak_start_breakpoint_count;
511 /* Used in run_command to zero the hit count when a new run starts. */
514 clear_breakpoint_hit_counts (void)
516 struct breakpoint *b;
522 /* Allocate a new counted_command_line with reference count of 1.
523 The new structure owns COMMANDS. */
525 static struct counted_command_line *
526 alloc_counted_command_line (struct command_line *commands)
528 struct counted_command_line *result
529 = xmalloc (sizeof (struct counted_command_line));
532 result->commands = commands;
536 /* Increment reference count. This does nothing if CMD is NULL. */
539 incref_counted_command_line (struct counted_command_line *cmd)
545 /* Decrement reference count. If the reference count reaches 0,
546 destroy the counted_command_line. Sets *CMDP to NULL. This does
547 nothing if *CMDP is NULL. */
550 decref_counted_command_line (struct counted_command_line **cmdp)
554 if (--(*cmdp)->refc == 0)
556 free_command_lines (&(*cmdp)->commands);
563 /* A cleanup function that calls decref_counted_command_line. */
566 do_cleanup_counted_command_line (void *arg)
568 decref_counted_command_line (arg);
571 /* Create a cleanup that calls decref_counted_command_line on the
574 static struct cleanup *
575 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
577 return make_cleanup (do_cleanup_counted_command_line, cmdp);
581 /* Return the breakpoint with the specified number, or NULL
582 if the number does not refer to an existing breakpoint. */
585 get_breakpoint (int num)
587 struct breakpoint *b;
590 if (b->number == num)
599 set_breakpoint_condition (struct breakpoint *b, char *exp,
602 xfree (b->cond_string);
603 b->cond_string = NULL;
605 if (is_watchpoint (b))
607 struct watchpoint *w = (struct watchpoint *) b;
614 struct bp_location *loc;
616 for (loc = b->loc; loc; loc = loc->next)
626 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
632 /* I don't know if it matters whether this is the string the user
633 typed in or the decompiled expression. */
634 b->cond_string = xstrdup (arg);
635 b->condition_not_parsed = 0;
637 if (is_watchpoint (b))
639 struct watchpoint *w = (struct watchpoint *) b;
641 innermost_block = NULL;
643 w->cond_exp = parse_exp_1 (&arg, 0, 0);
645 error (_("Junk at end of expression"));
646 w->cond_exp_valid_block = innermost_block;
650 struct bp_location *loc;
652 for (loc = b->loc; loc; loc = loc->next)
656 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
658 error (_("Junk at end of expression"));
662 breakpoints_changed ();
663 observer_notify_breakpoint_modified (b);
666 /* condition N EXP -- set break condition of breakpoint N to EXP. */
669 condition_command (char *arg, int from_tty)
671 struct breakpoint *b;
676 error_no_arg (_("breakpoint number"));
679 bnum = get_number (&p);
681 error (_("Bad breakpoint argument: '%s'"), arg);
684 if (b->number == bnum)
686 /* Check if this breakpoint has a Python object assigned to
687 it, and if it has a definition of the "stop"
688 method. This method and conditions entered into GDB from
689 the CLI are mutually exclusive. */
691 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
692 error (_("Cannot set a condition where a Python 'stop' "
693 "method has been defined in the breakpoint."));
694 set_breakpoint_condition (b, p, from_tty);
698 error (_("No breakpoint number %d."), bnum);
701 /* Check that COMMAND do not contain commands that are suitable
702 only for tracepoints and not suitable for ordinary breakpoints.
703 Throw if any such commands is found. */
706 check_no_tracepoint_commands (struct command_line *commands)
708 struct command_line *c;
710 for (c = commands; c; c = c->next)
714 if (c->control_type == while_stepping_control)
715 error (_("The 'while-stepping' command can "
716 "only be used for tracepoints"));
718 for (i = 0; i < c->body_count; ++i)
719 check_no_tracepoint_commands ((c->body_list)[i]);
721 /* Not that command parsing removes leading whitespace and comment
722 lines and also empty lines. So, we only need to check for
724 if (strstr (c->line, "collect ") == c->line)
725 error (_("The 'collect' command can only be used for tracepoints"));
727 if (strstr (c->line, "teval ") == c->line)
728 error (_("The 'teval' command can only be used for tracepoints"));
732 /* Encapsulate tests for different types of tracepoints. */
735 is_tracepoint_type (enum bptype type)
737 return (type == bp_tracepoint
738 || type == bp_fast_tracepoint
739 || type == bp_static_tracepoint);
743 is_tracepoint (const struct breakpoint *b)
745 return is_tracepoint_type (b->type);
748 /* A helper function that validates that COMMANDS are valid for a
749 breakpoint. This function will throw an exception if a problem is
753 validate_commands_for_breakpoint (struct breakpoint *b,
754 struct command_line *commands)
756 if (is_tracepoint (b))
758 /* We need to verify that each top-level element of commands is
759 valid for tracepoints, that there's at most one
760 while-stepping element, and that while-stepping's body has
761 valid tracing commands excluding nested while-stepping. */
762 struct command_line *c;
763 struct command_line *while_stepping = 0;
764 for (c = commands; c; c = c->next)
766 if (c->control_type == while_stepping_control)
768 if (b->type == bp_fast_tracepoint)
769 error (_("The 'while-stepping' command "
770 "cannot be used for fast tracepoint"));
771 else if (b->type == bp_static_tracepoint)
772 error (_("The 'while-stepping' command "
773 "cannot be used for static tracepoint"));
776 error (_("The 'while-stepping' command "
777 "can be used only once"));
784 struct command_line *c2;
786 gdb_assert (while_stepping->body_count == 1);
787 c2 = while_stepping->body_list[0];
788 for (; c2; c2 = c2->next)
790 if (c2->control_type == while_stepping_control)
791 error (_("The 'while-stepping' command cannot be nested"));
797 check_no_tracepoint_commands (commands);
801 /* Return a vector of all the static tracepoints set at ADDR. The
802 caller is responsible for releasing the vector. */
805 static_tracepoints_here (CORE_ADDR addr)
807 struct breakpoint *b;
808 VEC(breakpoint_p) *found = 0;
809 struct bp_location *loc;
812 if (b->type == bp_static_tracepoint)
814 for (loc = b->loc; loc; loc = loc->next)
815 if (loc->address == addr)
816 VEC_safe_push(breakpoint_p, found, b);
822 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
823 validate that only allowed commands are included. */
826 breakpoint_set_commands (struct breakpoint *b,
827 struct command_line *commands)
829 validate_commands_for_breakpoint (b, commands);
831 decref_counted_command_line (&b->commands);
832 b->commands = alloc_counted_command_line (commands);
833 breakpoints_changed ();
834 observer_notify_breakpoint_modified (b);
837 /* Set the internal `silent' flag on the breakpoint. Note that this
838 is not the same as the "silent" that may appear in the breakpoint's
842 breakpoint_set_silent (struct breakpoint *b, int silent)
844 int old_silent = b->silent;
847 if (old_silent != silent)
848 observer_notify_breakpoint_modified (b);
851 /* Set the thread for this breakpoint. If THREAD is -1, make the
852 breakpoint work for any thread. */
855 breakpoint_set_thread (struct breakpoint *b, int thread)
857 int old_thread = b->thread;
860 if (old_thread != thread)
861 observer_notify_breakpoint_modified (b);
864 /* Set the task for this breakpoint. If TASK is 0, make the
865 breakpoint work for any task. */
868 breakpoint_set_task (struct breakpoint *b, int task)
870 int old_task = b->task;
873 if (old_task != task)
874 observer_notify_breakpoint_modified (b);
878 check_tracepoint_command (char *line, void *closure)
880 struct breakpoint *b = closure;
882 validate_actionline (&line, b);
885 /* A structure used to pass information through
886 map_breakpoint_numbers. */
890 /* True if the command was typed at a tty. */
893 /* The breakpoint range spec. */
896 /* Non-NULL if the body of the commands are being read from this
897 already-parsed command. */
898 struct command_line *control;
900 /* The command lines read from the user, or NULL if they have not
902 struct counted_command_line *cmd;
905 /* A callback for map_breakpoint_numbers that sets the commands for
909 do_map_commands_command (struct breakpoint *b, void *data)
911 struct commands_info *info = data;
913 if (info->cmd == NULL)
915 struct command_line *l;
917 if (info->control != NULL)
918 l = copy_command_lines (info->control->body_list[0]);
921 struct cleanup *old_chain;
924 str = xstrprintf (_("Type commands for breakpoint(s) "
925 "%s, one per line."),
928 old_chain = make_cleanup (xfree, str);
930 l = read_command_lines (str,
933 ? check_tracepoint_command : 0),
936 do_cleanups (old_chain);
939 info->cmd = alloc_counted_command_line (l);
942 /* If a breakpoint was on the list more than once, we don't need to
944 if (b->commands != info->cmd)
946 validate_commands_for_breakpoint (b, info->cmd->commands);
947 incref_counted_command_line (info->cmd);
948 decref_counted_command_line (&b->commands);
949 b->commands = info->cmd;
950 breakpoints_changed ();
951 observer_notify_breakpoint_modified (b);
956 commands_command_1 (char *arg, int from_tty,
957 struct command_line *control)
959 struct cleanup *cleanups;
960 struct commands_info info;
962 info.from_tty = from_tty;
963 info.control = control;
965 /* If we read command lines from the user, then `info' will hold an
966 extra reference to the commands that we must clean up. */
967 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
969 if (arg == NULL || !*arg)
971 if (breakpoint_count - prev_breakpoint_count > 1)
972 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
974 else if (breakpoint_count > 0)
975 arg = xstrprintf ("%d", breakpoint_count);
978 /* So that we don't try to free the incoming non-NULL
979 argument in the cleanup below. Mapping breakpoint
980 numbers will fail in this case. */
985 /* The command loop has some static state, so we need to preserve
990 make_cleanup (xfree, arg);
994 map_breakpoint_numbers (arg, do_map_commands_command, &info);
996 if (info.cmd == NULL)
997 error (_("No breakpoints specified."));
999 do_cleanups (cleanups);
1003 commands_command (char *arg, int from_tty)
1005 commands_command_1 (arg, from_tty, NULL);
1008 /* Like commands_command, but instead of reading the commands from
1009 input stream, takes them from an already parsed command structure.
1011 This is used by cli-script.c to DTRT with breakpoint commands
1012 that are part of if and while bodies. */
1013 enum command_control_type
1014 commands_from_control_command (char *arg, struct command_line *cmd)
1016 commands_command_1 (arg, 0, cmd);
1017 return simple_control;
1020 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1023 bp_location_has_shadow (struct bp_location *bl)
1025 if (bl->loc_type != bp_loc_software_breakpoint)
1029 if (bl->target_info.shadow_len == 0)
1030 /* BL isn't valid, or doesn't shadow memory. */
1035 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1036 by replacing any memory breakpoints with their shadowed contents.
1038 The range of shadowed area by each bp_location is:
1039 bl->address - bp_location_placed_address_before_address_max
1040 up to bl->address + bp_location_shadow_len_after_address_max
1041 The range we were requested to resolve shadows for is:
1042 memaddr ... memaddr + len
1043 Thus the safe cutoff boundaries for performance optimization are
1044 memaddr + len <= (bl->address
1045 - bp_location_placed_address_before_address_max)
1047 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1050 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1052 /* Left boundary, right boundary and median element of our binary
1054 unsigned bc_l, bc_r, bc;
1056 /* Find BC_L which is a leftmost element which may affect BUF
1057 content. It is safe to report lower value but a failure to
1058 report higher one. */
1061 bc_r = bp_location_count;
1062 while (bc_l + 1 < bc_r)
1064 struct bp_location *bl;
1066 bc = (bc_l + bc_r) / 2;
1067 bl = bp_location[bc];
1069 /* Check first BL->ADDRESS will not overflow due to the added
1070 constant. Then advance the left boundary only if we are sure
1071 the BC element can in no way affect the BUF content (MEMADDR
1072 to MEMADDR + LEN range).
1074 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1075 offset so that we cannot miss a breakpoint with its shadow
1076 range tail still reaching MEMADDR. */
1078 if ((bl->address + bp_location_shadow_len_after_address_max
1080 && (bl->address + bp_location_shadow_len_after_address_max
1087 /* Due to the binary search above, we need to make sure we pick the
1088 first location that's at BC_L's address. E.g., if there are
1089 multiple locations at the same address, BC_L may end up pointing
1090 at a duplicate location, and miss the "master"/"inserted"
1091 location. Say, given locations L1, L2 and L3 at addresses A and
1094 L1@A, L2@A, L3@B, ...
1096 BC_L could end up pointing at location L2, while the "master"
1097 location could be L1. Since the `loc->inserted' flag is only set
1098 on "master" locations, we'd forget to restore the shadow of L1
1101 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1104 /* Now do full processing of the found relevant range of elements. */
1106 for (bc = bc_l; bc < bp_location_count; bc++)
1108 struct bp_location *bl = bp_location[bc];
1109 CORE_ADDR bp_addr = 0;
1113 /* bp_location array has BL->OWNER always non-NULL. */
1114 if (bl->owner->type == bp_none)
1115 warning (_("reading through apparently deleted breakpoint #%d?"),
1118 /* Performance optimization: any further element can no longer affect BUF
1121 if (bl->address >= bp_location_placed_address_before_address_max
1122 && memaddr + len <= (bl->address
1123 - bp_location_placed_address_before_address_max))
1126 if (!bp_location_has_shadow (bl))
1128 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1129 current_program_space->aspace, 0))
1132 /* Addresses and length of the part of the breakpoint that
1134 bp_addr = bl->target_info.placed_address;
1135 bp_size = bl->target_info.shadow_len;
1137 if (bp_addr + bp_size <= memaddr)
1138 /* The breakpoint is entirely before the chunk of memory we
1142 if (bp_addr >= memaddr + len)
1143 /* The breakpoint is entirely after the chunk of memory we are
1147 /* Offset within shadow_contents. */
1148 if (bp_addr < memaddr)
1150 /* Only copy the second part of the breakpoint. */
1151 bp_size -= memaddr - bp_addr;
1152 bptoffset = memaddr - bp_addr;
1156 if (bp_addr + bp_size > memaddr + len)
1158 /* Only copy the first part of the breakpoint. */
1159 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1162 memcpy (buf + bp_addr - memaddr,
1163 bl->target_info.shadow_contents + bptoffset, bp_size);
1168 /* Return true if BPT is of any hardware watchpoint kind. */
1171 is_hardware_watchpoint (const struct breakpoint *bpt)
1173 return (bpt->type == bp_hardware_watchpoint
1174 || bpt->type == bp_read_watchpoint
1175 || bpt->type == bp_access_watchpoint);
1178 /* Return true if BPT is of any watchpoint kind, hardware or
1182 is_watchpoint (const struct breakpoint *bpt)
1184 return (is_hardware_watchpoint (bpt)
1185 || bpt->type == bp_watchpoint);
1188 /* Returns true if the current thread and its running state are safe
1189 to evaluate or update watchpoint B. Watchpoints on local
1190 expressions need to be evaluated in the context of the thread that
1191 was current when the watchpoint was created, and, that thread needs
1192 to be stopped to be able to select the correct frame context.
1193 Watchpoints on global expressions can be evaluated on any thread,
1194 and in any state. It is presently left to the target allowing
1195 memory accesses when threads are running. */
1198 watchpoint_in_thread_scope (struct watchpoint *b)
1200 return (ptid_equal (b->watchpoint_thread, null_ptid)
1201 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1202 && !is_executing (inferior_ptid)));
1205 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1206 associated bp_watchpoint_scope breakpoint. */
1209 watchpoint_del_at_next_stop (struct watchpoint *w)
1211 struct breakpoint *b = &w->base;
1213 if (b->related_breakpoint != b)
1215 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1216 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1217 b->related_breakpoint->disposition = disp_del_at_next_stop;
1218 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1219 b->related_breakpoint = b;
1221 b->disposition = disp_del_at_next_stop;
1224 /* Assuming that B is a watchpoint:
1225 - Reparse watchpoint expression, if REPARSE is non-zero
1226 - Evaluate expression and store the result in B->val
1227 - Evaluate the condition if there is one, and store the result
1229 - Update the list of values that must be watched in B->loc.
1231 If the watchpoint disposition is disp_del_at_next_stop, then do
1232 nothing. If this is local watchpoint that is out of scope, delete
1235 Even with `set breakpoint always-inserted on' the watchpoints are
1236 removed + inserted on each stop here. Normal breakpoints must
1237 never be removed because they might be missed by a running thread
1238 when debugging in non-stop mode. On the other hand, hardware
1239 watchpoints (is_hardware_watchpoint; processed here) are specific
1240 to each LWP since they are stored in each LWP's hardware debug
1241 registers. Therefore, such LWP must be stopped first in order to
1242 be able to modify its hardware watchpoints.
1244 Hardware watchpoints must be reset exactly once after being
1245 presented to the user. It cannot be done sooner, because it would
1246 reset the data used to present the watchpoint hit to the user. And
1247 it must not be done later because it could display the same single
1248 watchpoint hit during multiple GDB stops. Note that the latter is
1249 relevant only to the hardware watchpoint types bp_read_watchpoint
1250 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1251 not user-visible - its hit is suppressed if the memory content has
1254 The following constraints influence the location where we can reset
1255 hardware watchpoints:
1257 * target_stopped_by_watchpoint and target_stopped_data_address are
1258 called several times when GDB stops.
1261 * Multiple hardware watchpoints can be hit at the same time,
1262 causing GDB to stop. GDB only presents one hardware watchpoint
1263 hit at a time as the reason for stopping, and all the other hits
1264 are presented later, one after the other, each time the user
1265 requests the execution to be resumed. Execution is not resumed
1266 for the threads still having pending hit event stored in
1267 LWP_INFO->STATUS. While the watchpoint is already removed from
1268 the inferior on the first stop the thread hit event is kept being
1269 reported from its cached value by linux_nat_stopped_data_address
1270 until the real thread resume happens after the watchpoint gets
1271 presented and thus its LWP_INFO->STATUS gets reset.
1273 Therefore the hardware watchpoint hit can get safely reset on the
1274 watchpoint removal from inferior. */
1277 update_watchpoint (struct watchpoint *b, int reparse)
1279 int within_current_scope;
1280 struct frame_id saved_frame_id;
1283 /* If this is a local watchpoint, we only want to check if the
1284 watchpoint frame is in scope if the current thread is the thread
1285 that was used to create the watchpoint. */
1286 if (!watchpoint_in_thread_scope (b))
1289 if (b->base.disposition == disp_del_at_next_stop)
1294 /* Determine if the watchpoint is within scope. */
1295 if (b->exp_valid_block == NULL)
1296 within_current_scope = 1;
1299 struct frame_info *fi = get_current_frame ();
1300 struct gdbarch *frame_arch = get_frame_arch (fi);
1301 CORE_ADDR frame_pc = get_frame_pc (fi);
1303 /* If we're in a function epilogue, unwinding may not work
1304 properly, so do not attempt to recreate locations at this
1305 point. See similar comments in watchpoint_check. */
1306 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1309 /* Save the current frame's ID so we can restore it after
1310 evaluating the watchpoint expression on its own frame. */
1311 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1312 took a frame parameter, so that we didn't have to change the
1315 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1317 fi = frame_find_by_id (b->watchpoint_frame);
1318 within_current_scope = (fi != NULL);
1319 if (within_current_scope)
1323 /* We don't free locations. They are stored in the bp_location array
1324 and update_global_location_list will eventually delete them and
1325 remove breakpoints if needed. */
1328 if (within_current_scope && reparse)
1337 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1338 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1339 /* If the meaning of expression itself changed, the old value is
1340 no longer relevant. We don't want to report a watchpoint hit
1341 to the user when the old value and the new value may actually
1342 be completely different objects. */
1343 value_free (b->val);
1347 /* Note that unlike with breakpoints, the watchpoint's condition
1348 expression is stored in the breakpoint object, not in the
1349 locations (re)created below. */
1350 if (b->base.cond_string != NULL)
1352 if (b->cond_exp != NULL)
1354 xfree (b->cond_exp);
1358 s = b->base.cond_string;
1359 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1363 /* If we failed to parse the expression, for example because
1364 it refers to a global variable in a not-yet-loaded shared library,
1365 don't try to insert watchpoint. We don't automatically delete
1366 such watchpoint, though, since failure to parse expression
1367 is different from out-of-scope watchpoint. */
1368 if ( !target_has_execution)
1370 /* Without execution, memory can't change. No use to try and
1371 set watchpoint locations. The watchpoint will be reset when
1372 the target gains execution, through breakpoint_re_set. */
1374 else if (within_current_scope && b->exp)
1377 struct value *val_chain, *v, *result, *next;
1378 struct program_space *frame_pspace;
1380 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1382 /* Avoid setting b->val if it's already set. The meaning of
1383 b->val is 'the last value' user saw, and we should update
1384 it only if we reported that last value to user. As it
1385 happens, the code that reports it updates b->val directly.
1386 We don't keep track of the memory value for masked
1388 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1394 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1396 /* Look at each value on the value chain. */
1397 for (v = val_chain; v; v = value_next (v))
1399 /* If it's a memory location, and GDB actually needed
1400 its contents to evaluate the expression, then we
1401 must watch it. If the first value returned is
1402 still lazy, that means an error occurred reading it;
1403 watch it anyway in case it becomes readable. */
1404 if (VALUE_LVAL (v) == lval_memory
1405 && (v == val_chain || ! value_lazy (v)))
1407 struct type *vtype = check_typedef (value_type (v));
1409 /* We only watch structs and arrays if user asked
1410 for it explicitly, never if they just happen to
1411 appear in the middle of some value chain. */
1413 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1414 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1418 struct bp_location *loc, **tmp;
1420 addr = value_address (v);
1421 len = TYPE_LENGTH (value_type (v));
1423 if (b->base.type == bp_read_watchpoint)
1425 else if (b->base.type == bp_access_watchpoint)
1428 loc = allocate_bp_location (&b->base);
1429 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1432 loc->gdbarch = get_type_arch (value_type (v));
1434 loc->pspace = frame_pspace;
1435 loc->address = addr;
1437 loc->watchpoint_type = type;
1442 /* Change the type of breakpoint between hardware assisted or
1443 an ordinary watchpoint depending on the hardware support
1444 and free hardware slots. REPARSE is set when the inferior
1449 enum bp_loc_type loc_type;
1450 struct bp_location *bl;
1452 reg_cnt = can_use_hardware_watchpoint (val_chain);
1456 int i, target_resources_ok, other_type_used;
1459 /* Use an exact watchpoint when there's only one memory region to be
1460 watched, and only one debug register is needed to watch it. */
1461 b->exact = target_exact_watchpoints && reg_cnt == 1;
1463 /* We need to determine how many resources are already
1464 used for all other hardware watchpoints plus this one
1465 to see if we still have enough resources to also fit
1466 this watchpoint in as well. */
1468 /* If this is a software watchpoint, we try to turn it
1469 to a hardware one -- count resources as if B was of
1470 hardware watchpoint type. */
1471 type = b->base.type;
1472 if (type == bp_watchpoint)
1473 type = bp_hardware_watchpoint;
1475 /* This watchpoint may or may not have been placed on
1476 the list yet at this point (it won't be in the list
1477 if we're trying to create it for the first time,
1478 through watch_command), so always account for it
1481 /* Count resources used by all watchpoints except B. */
1482 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1484 /* Add in the resources needed for B. */
1485 i += hw_watchpoint_use_count (&b->base);
1488 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1489 if (target_resources_ok <= 0)
1491 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1493 if (target_resources_ok == 0 && !sw_mode)
1494 error (_("Target does not support this type of "
1495 "hardware watchpoint."));
1496 else if (target_resources_ok < 0 && !sw_mode)
1497 error (_("There are not enough available hardware "
1498 "resources for this watchpoint."));
1500 /* Downgrade to software watchpoint. */
1501 b->base.type = bp_watchpoint;
1505 /* If this was a software watchpoint, we've just
1506 found we have enough resources to turn it to a
1507 hardware watchpoint. Otherwise, this is a
1509 b->base.type = type;
1512 else if (!b->base.ops->works_in_software_mode (&b->base))
1513 error (_("Expression cannot be implemented with "
1514 "read/access watchpoint."));
1516 b->base.type = bp_watchpoint;
1518 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1519 : bp_loc_hardware_watchpoint);
1520 for (bl = b->base.loc; bl; bl = bl->next)
1521 bl->loc_type = loc_type;
1524 for (v = val_chain; v; v = next)
1526 next = value_next (v);
1531 /* If a software watchpoint is not watching any memory, then the
1532 above left it without any location set up. But,
1533 bpstat_stop_status requires a location to be able to report
1534 stops, so make sure there's at least a dummy one. */
1535 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1537 struct breakpoint *base = &b->base;
1538 base->loc = allocate_bp_location (base);
1539 base->loc->pspace = frame_pspace;
1540 base->loc->address = -1;
1541 base->loc->length = -1;
1542 base->loc->watchpoint_type = -1;
1545 else if (!within_current_scope)
1547 printf_filtered (_("\
1548 Watchpoint %d deleted because the program has left the block\n\
1549 in which its expression is valid.\n"),
1551 watchpoint_del_at_next_stop (b);
1554 /* Restore the selected frame. */
1556 select_frame (frame_find_by_id (saved_frame_id));
1560 /* Returns 1 iff breakpoint location should be
1561 inserted in the inferior. */
1563 should_be_inserted (struct bp_location *bl)
1565 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1568 if (bl->owner->disposition == disp_del_at_next_stop)
1571 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1574 /* This is set for example, when we're attached to the parent of a
1575 vfork, and have detached from the child. The child is running
1576 free, and we expect it to do an exec or exit, at which point the
1577 OS makes the parent schedulable again (and the target reports
1578 that the vfork is done). Until the child is done with the shared
1579 memory region, do not insert breakpoints in the parent, otherwise
1580 the child could still trip on the parent's breakpoints. Since
1581 the parent is blocked anyway, it won't miss any breakpoint. */
1582 if (bl->pspace->breakpoints_not_allowed)
1585 /* Tracepoints are inserted by the target at a time of its choosing,
1587 if (is_tracepoint (bl->owner))
1593 /* Same as should_be_inserted but does the check assuming
1594 that the location is not duplicated. */
1597 unduplicated_should_be_inserted (struct bp_location *bl)
1600 const int save_duplicate = bl->duplicate;
1603 result = should_be_inserted (bl);
1604 bl->duplicate = save_duplicate;
1608 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1609 location. Any error messages are printed to TMP_ERROR_STREAM; and
1610 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1611 Returns 0 for success, 1 if the bp_location type is not supported or
1614 NOTE drow/2003-09-09: This routine could be broken down to an
1615 object-style method for each breakpoint or catchpoint type. */
1617 insert_bp_location (struct bp_location *bl,
1618 struct ui_file *tmp_error_stream,
1619 int *disabled_breaks,
1620 int *hw_breakpoint_error)
1624 if (!should_be_inserted (bl) || bl->inserted)
1627 /* Initialize the target-specific information. */
1628 memset (&bl->target_info, 0, sizeof (bl->target_info));
1629 bl->target_info.placed_address = bl->address;
1630 bl->target_info.placed_address_space = bl->pspace->aspace;
1631 bl->target_info.length = bl->length;
1633 if (bl->loc_type == bp_loc_software_breakpoint
1634 || bl->loc_type == bp_loc_hardware_breakpoint)
1636 if (bl->owner->type != bp_hardware_breakpoint)
1638 /* If the explicitly specified breakpoint type
1639 is not hardware breakpoint, check the memory map to see
1640 if the breakpoint address is in read only memory or not.
1642 Two important cases are:
1643 - location type is not hardware breakpoint, memory
1644 is readonly. We change the type of the location to
1645 hardware breakpoint.
1646 - location type is hardware breakpoint, memory is
1647 read-write. This means we've previously made the
1648 location hardware one, but then the memory map changed,
1651 When breakpoints are removed, remove_breakpoints will use
1652 location types we've just set here, the only possible
1653 problem is that memory map has changed during running
1654 program, but it's not going to work anyway with current
1656 struct mem_region *mr
1657 = lookup_mem_region (bl->target_info.placed_address);
1661 if (automatic_hardware_breakpoints)
1663 enum bp_loc_type new_type;
1665 if (mr->attrib.mode != MEM_RW)
1666 new_type = bp_loc_hardware_breakpoint;
1668 new_type = bp_loc_software_breakpoint;
1670 if (new_type != bl->loc_type)
1672 static int said = 0;
1674 bl->loc_type = new_type;
1677 fprintf_filtered (gdb_stdout,
1678 _("Note: automatically using "
1679 "hardware breakpoints for "
1680 "read-only addresses.\n"));
1685 else if (bl->loc_type == bp_loc_software_breakpoint
1686 && mr->attrib.mode != MEM_RW)
1687 warning (_("cannot set software breakpoint "
1688 "at readonly address %s"),
1689 paddress (bl->gdbarch, bl->address));
1693 /* First check to see if we have to handle an overlay. */
1694 if (overlay_debugging == ovly_off
1695 || bl->section == NULL
1696 || !(section_is_overlay (bl->section)))
1698 /* No overlay handling: just set the breakpoint. */
1700 val = bl->owner->ops->insert_location (bl);
1704 /* This breakpoint is in an overlay section.
1705 Shall we set a breakpoint at the LMA? */
1706 if (!overlay_events_enabled)
1708 /* Yes -- overlay event support is not active,
1709 so we must try to set a breakpoint at the LMA.
1710 This will not work for a hardware breakpoint. */
1711 if (bl->loc_type == bp_loc_hardware_breakpoint)
1712 warning (_("hardware breakpoint %d not supported in overlay!"),
1716 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1718 /* Set a software (trap) breakpoint at the LMA. */
1719 bl->overlay_target_info = bl->target_info;
1720 bl->overlay_target_info.placed_address = addr;
1721 val = target_insert_breakpoint (bl->gdbarch,
1722 &bl->overlay_target_info);
1724 fprintf_unfiltered (tmp_error_stream,
1725 "Overlay breakpoint %d "
1726 "failed: in ROM?\n",
1730 /* Shall we set a breakpoint at the VMA? */
1731 if (section_is_mapped (bl->section))
1733 /* Yes. This overlay section is mapped into memory. */
1734 val = bl->owner->ops->insert_location (bl);
1738 /* No. This breakpoint will not be inserted.
1739 No error, but do not mark the bp as 'inserted'. */
1746 /* Can't set the breakpoint. */
1747 if (solib_name_from_address (bl->pspace, bl->address))
1749 /* See also: disable_breakpoints_in_shlibs. */
1751 bl->shlib_disabled = 1;
1752 observer_notify_breakpoint_modified (bl->owner);
1753 if (!*disabled_breaks)
1755 fprintf_unfiltered (tmp_error_stream,
1756 "Cannot insert breakpoint %d.\n",
1758 fprintf_unfiltered (tmp_error_stream,
1759 "Temporarily disabling shared "
1760 "library breakpoints:\n");
1762 *disabled_breaks = 1;
1763 fprintf_unfiltered (tmp_error_stream,
1764 "breakpoint #%d\n", bl->owner->number);
1768 if (bl->loc_type == bp_loc_hardware_breakpoint)
1770 *hw_breakpoint_error = 1;
1771 fprintf_unfiltered (tmp_error_stream,
1772 "Cannot insert hardware "
1778 fprintf_unfiltered (tmp_error_stream,
1779 "Cannot insert breakpoint %d.\n",
1781 fprintf_filtered (tmp_error_stream,
1782 "Error accessing memory address ");
1783 fputs_filtered (paddress (bl->gdbarch, bl->address),
1785 fprintf_filtered (tmp_error_stream, ": %s.\n",
1786 safe_strerror (val));
1797 else if (bl->loc_type == bp_loc_hardware_watchpoint
1798 /* NOTE drow/2003-09-08: This state only exists for removing
1799 watchpoints. It's not clear that it's necessary... */
1800 && bl->owner->disposition != disp_del_at_next_stop)
1802 gdb_assert (bl->owner->ops != NULL
1803 && bl->owner->ops->insert_location != NULL);
1805 val = bl->owner->ops->insert_location (bl);
1807 /* If trying to set a read-watchpoint, and it turns out it's not
1808 supported, try emulating one with an access watchpoint. */
1809 if (val == 1 && bl->watchpoint_type == hw_read)
1811 struct bp_location *loc, **loc_temp;
1813 /* But don't try to insert it, if there's already another
1814 hw_access location that would be considered a duplicate
1816 ALL_BP_LOCATIONS (loc, loc_temp)
1818 && loc->watchpoint_type == hw_access
1819 && watchpoint_locations_match (bl, loc))
1823 bl->target_info = loc->target_info;
1824 bl->watchpoint_type = hw_access;
1831 bl->watchpoint_type = hw_access;
1832 val = bl->owner->ops->insert_location (bl);
1835 /* Back to the original value. */
1836 bl->watchpoint_type = hw_read;
1840 bl->inserted = (val == 0);
1843 else if (bl->owner->type == bp_catchpoint)
1845 gdb_assert (bl->owner->ops != NULL
1846 && bl->owner->ops->insert_location != NULL);
1848 val = bl->owner->ops->insert_location (bl);
1851 bl->owner->enable_state = bp_disabled;
1855 Error inserting catchpoint %d: Your system does not support this type\n\
1856 of catchpoint."), bl->owner->number);
1858 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1861 bl->inserted = (val == 0);
1863 /* We've already printed an error message if there was a problem
1864 inserting this catchpoint, and we've disabled the catchpoint,
1865 so just return success. */
1872 /* This function is called when program space PSPACE is about to be
1873 deleted. It takes care of updating breakpoints to not reference
1877 breakpoint_program_space_exit (struct program_space *pspace)
1879 struct breakpoint *b, *b_temp;
1880 struct bp_location *loc, **loc_temp;
1882 /* Remove any breakpoint that was set through this program space. */
1883 ALL_BREAKPOINTS_SAFE (b, b_temp)
1885 if (b->pspace == pspace)
1886 delete_breakpoint (b);
1889 /* Breakpoints set through other program spaces could have locations
1890 bound to PSPACE as well. Remove those. */
1891 ALL_BP_LOCATIONS (loc, loc_temp)
1893 struct bp_location *tmp;
1895 if (loc->pspace == pspace)
1897 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1898 if (loc->owner->loc == loc)
1899 loc->owner->loc = loc->next;
1901 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1902 if (tmp->next == loc)
1904 tmp->next = loc->next;
1910 /* Now update the global location list to permanently delete the
1911 removed locations above. */
1912 update_global_location_list (0);
1915 /* Make sure all breakpoints are inserted in inferior.
1916 Throws exception on any error.
1917 A breakpoint that is already inserted won't be inserted
1918 again, so calling this function twice is safe. */
1920 insert_breakpoints (void)
1922 struct breakpoint *bpt;
1924 ALL_BREAKPOINTS (bpt)
1925 if (is_hardware_watchpoint (bpt))
1927 struct watchpoint *w = (struct watchpoint *) bpt;
1929 update_watchpoint (w, 0 /* don't reparse. */);
1932 update_global_location_list (1);
1934 /* update_global_location_list does not insert breakpoints when
1935 always_inserted_mode is not enabled. Explicitly insert them
1937 if (!breakpoints_always_inserted_mode ())
1938 insert_breakpoint_locations ();
1941 /* Used when starting or continuing the program. */
1944 insert_breakpoint_locations (void)
1946 struct breakpoint *bpt;
1947 struct bp_location *bl, **blp_tmp;
1950 int disabled_breaks = 0;
1951 int hw_breakpoint_error = 0;
1953 struct ui_file *tmp_error_stream = mem_fileopen ();
1954 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1956 /* Explicitly mark the warning -- this will only be printed if
1957 there was an error. */
1958 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1960 save_current_space_and_thread ();
1962 ALL_BP_LOCATIONS (bl, blp_tmp)
1964 if (!should_be_inserted (bl) || bl->inserted)
1967 /* There is no point inserting thread-specific breakpoints if
1968 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1969 has BL->OWNER always non-NULL. */
1970 if (bl->owner->thread != -1
1971 && !valid_thread_id (bl->owner->thread))
1974 switch_to_program_space_and_thread (bl->pspace);
1976 /* For targets that support global breakpoints, there's no need
1977 to select an inferior to insert breakpoint to. In fact, even
1978 if we aren't attached to any process yet, we should still
1979 insert breakpoints. */
1980 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1981 && ptid_equal (inferior_ptid, null_ptid))
1984 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1985 &hw_breakpoint_error);
1990 /* If we failed to insert all locations of a watchpoint, remove
1991 them, as half-inserted watchpoint is of limited use. */
1992 ALL_BREAKPOINTS (bpt)
1994 int some_failed = 0;
1995 struct bp_location *loc;
1997 if (!is_hardware_watchpoint (bpt))
2000 if (!breakpoint_enabled (bpt))
2003 if (bpt->disposition == disp_del_at_next_stop)
2006 for (loc = bpt->loc; loc; loc = loc->next)
2007 if (!loc->inserted && should_be_inserted (loc))
2014 for (loc = bpt->loc; loc; loc = loc->next)
2016 remove_breakpoint (loc, mark_uninserted);
2018 hw_breakpoint_error = 1;
2019 fprintf_unfiltered (tmp_error_stream,
2020 "Could not insert hardware watchpoint %d.\n",
2028 /* If a hardware breakpoint or watchpoint was inserted, add a
2029 message about possibly exhausted resources. */
2030 if (hw_breakpoint_error)
2032 fprintf_unfiltered (tmp_error_stream,
2033 "Could not insert hardware breakpoints:\n\
2034 You may have requested too many hardware breakpoints/watchpoints.\n");
2036 target_terminal_ours_for_output ();
2037 error_stream (tmp_error_stream);
2040 do_cleanups (cleanups);
2043 /* Used when the program stops.
2044 Returns zero if successful, or non-zero if there was a problem
2045 removing a breakpoint location. */
2048 remove_breakpoints (void)
2050 struct bp_location *bl, **blp_tmp;
2053 ALL_BP_LOCATIONS (bl, blp_tmp)
2056 val |= remove_breakpoint (bl, mark_uninserted);
2061 /* Remove breakpoints of process PID. */
2064 remove_breakpoints_pid (int pid)
2066 struct bp_location *bl, **blp_tmp;
2068 struct inferior *inf = find_inferior_pid (pid);
2070 ALL_BP_LOCATIONS (bl, blp_tmp)
2072 if (bl->pspace != inf->pspace)
2077 val = remove_breakpoint (bl, mark_uninserted);
2086 reattach_breakpoints (int pid)
2088 struct cleanup *old_chain;
2089 struct bp_location *bl, **blp_tmp;
2091 struct ui_file *tmp_error_stream;
2092 int dummy1 = 0, dummy2 = 0;
2093 struct inferior *inf;
2094 struct thread_info *tp;
2096 tp = any_live_thread_of_process (pid);
2100 inf = find_inferior_pid (pid);
2101 old_chain = save_inferior_ptid ();
2103 inferior_ptid = tp->ptid;
2105 tmp_error_stream = mem_fileopen ();
2106 make_cleanup_ui_file_delete (tmp_error_stream);
2108 ALL_BP_LOCATIONS (bl, blp_tmp)
2110 if (bl->pspace != inf->pspace)
2116 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2119 do_cleanups (old_chain);
2124 do_cleanups (old_chain);
2128 static int internal_breakpoint_number = -1;
2130 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2131 If INTERNAL is non-zero, the breakpoint number will be populated
2132 from internal_breakpoint_number and that variable decremented.
2133 Otherwise the breakpoint number will be populated from
2134 breakpoint_count and that value incremented. Internal breakpoints
2135 do not set the internal var bpnum. */
2137 set_breakpoint_number (int internal, struct breakpoint *b)
2140 b->number = internal_breakpoint_number--;
2143 set_breakpoint_count (breakpoint_count + 1);
2144 b->number = breakpoint_count;
2148 static struct breakpoint *
2149 create_internal_breakpoint (struct gdbarch *gdbarch,
2150 CORE_ADDR address, enum bptype type,
2151 const struct breakpoint_ops *ops)
2153 struct symtab_and_line sal;
2154 struct breakpoint *b;
2156 init_sal (&sal); /* Initialize to zeroes. */
2159 sal.section = find_pc_overlay (sal.pc);
2160 sal.pspace = current_program_space;
2162 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2163 b->number = internal_breakpoint_number--;
2164 b->disposition = disp_donttouch;
2169 static const char *const longjmp_names[] =
2171 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2173 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2175 /* Per-objfile data private to breakpoint.c. */
2176 struct breakpoint_objfile_data
2178 /* Minimal symbol for "_ovly_debug_event" (if any). */
2179 struct minimal_symbol *overlay_msym;
2181 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2182 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2184 /* Minimal symbol for "std::terminate()" (if any). */
2185 struct minimal_symbol *terminate_msym;
2187 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2188 struct minimal_symbol *exception_msym;
2191 static const struct objfile_data *breakpoint_objfile_key;
2193 /* Minimal symbol not found sentinel. */
2194 static struct minimal_symbol msym_not_found;
2196 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2199 msym_not_found_p (const struct minimal_symbol *msym)
2201 return msym == &msym_not_found;
2204 /* Return per-objfile data needed by breakpoint.c.
2205 Allocate the data if necessary. */
2207 static struct breakpoint_objfile_data *
2208 get_breakpoint_objfile_data (struct objfile *objfile)
2210 struct breakpoint_objfile_data *bp_objfile_data;
2212 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2213 if (bp_objfile_data == NULL)
2215 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2216 sizeof (*bp_objfile_data));
2218 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2219 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2221 return bp_objfile_data;
2225 create_overlay_event_breakpoint (void)
2227 struct objfile *objfile;
2228 const char *const func_name = "_ovly_debug_event";
2230 ALL_OBJFILES (objfile)
2232 struct breakpoint *b;
2233 struct breakpoint_objfile_data *bp_objfile_data;
2236 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2238 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2241 if (bp_objfile_data->overlay_msym == NULL)
2243 struct minimal_symbol *m;
2245 m = lookup_minimal_symbol_text (func_name, objfile);
2248 /* Avoid future lookups in this objfile. */
2249 bp_objfile_data->overlay_msym = &msym_not_found;
2252 bp_objfile_data->overlay_msym = m;
2255 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2256 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2258 &internal_breakpoint_ops);
2259 b->addr_string = xstrdup (func_name);
2261 if (overlay_debugging == ovly_auto)
2263 b->enable_state = bp_enabled;
2264 overlay_events_enabled = 1;
2268 b->enable_state = bp_disabled;
2269 overlay_events_enabled = 0;
2272 update_global_location_list (1);
2276 create_longjmp_master_breakpoint (void)
2278 struct program_space *pspace;
2279 struct cleanup *old_chain;
2281 old_chain = save_current_program_space ();
2283 ALL_PSPACES (pspace)
2285 struct objfile *objfile;
2287 set_current_program_space (pspace);
2289 ALL_OBJFILES (objfile)
2292 struct gdbarch *gdbarch;
2293 struct breakpoint_objfile_data *bp_objfile_data;
2295 gdbarch = get_objfile_arch (objfile);
2296 if (!gdbarch_get_longjmp_target_p (gdbarch))
2299 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2301 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2303 struct breakpoint *b;
2304 const char *func_name;
2307 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2310 func_name = longjmp_names[i];
2311 if (bp_objfile_data->longjmp_msym[i] == NULL)
2313 struct minimal_symbol *m;
2315 m = lookup_minimal_symbol_text (func_name, objfile);
2318 /* Prevent future lookups in this objfile. */
2319 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2322 bp_objfile_data->longjmp_msym[i] = m;
2325 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2326 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2327 &internal_breakpoint_ops);
2328 b->addr_string = xstrdup (func_name);
2329 b->enable_state = bp_disabled;
2333 update_global_location_list (1);
2335 do_cleanups (old_chain);
2338 /* Create a master std::terminate breakpoint. */
2340 create_std_terminate_master_breakpoint (void)
2342 struct program_space *pspace;
2343 struct cleanup *old_chain;
2344 const char *const func_name = "std::terminate()";
2346 old_chain = save_current_program_space ();
2348 ALL_PSPACES (pspace)
2350 struct objfile *objfile;
2353 set_current_program_space (pspace);
2355 ALL_OBJFILES (objfile)
2357 struct breakpoint *b;
2358 struct breakpoint_objfile_data *bp_objfile_data;
2360 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2362 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2365 if (bp_objfile_data->terminate_msym == NULL)
2367 struct minimal_symbol *m;
2369 m = lookup_minimal_symbol (func_name, NULL, objfile);
2370 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2371 && MSYMBOL_TYPE (m) != mst_file_text))
2373 /* Prevent future lookups in this objfile. */
2374 bp_objfile_data->terminate_msym = &msym_not_found;
2377 bp_objfile_data->terminate_msym = m;
2380 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2381 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2382 bp_std_terminate_master,
2383 &internal_breakpoint_ops);
2384 b->addr_string = xstrdup (func_name);
2385 b->enable_state = bp_disabled;
2389 update_global_location_list (1);
2391 do_cleanups (old_chain);
2394 /* Install a master breakpoint on the unwinder's debug hook. */
2397 create_exception_master_breakpoint (void)
2399 struct objfile *objfile;
2400 const char *const func_name = "_Unwind_DebugHook";
2402 ALL_OBJFILES (objfile)
2404 struct breakpoint *b;
2405 struct gdbarch *gdbarch;
2406 struct breakpoint_objfile_data *bp_objfile_data;
2409 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2411 if (msym_not_found_p (bp_objfile_data->exception_msym))
2414 gdbarch = get_objfile_arch (objfile);
2416 if (bp_objfile_data->exception_msym == NULL)
2418 struct minimal_symbol *debug_hook;
2420 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2421 if (debug_hook == NULL)
2423 bp_objfile_data->exception_msym = &msym_not_found;
2427 bp_objfile_data->exception_msym = debug_hook;
2430 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2431 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2433 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2434 &internal_breakpoint_ops);
2435 b->addr_string = xstrdup (func_name);
2436 b->enable_state = bp_disabled;
2439 update_global_location_list (1);
2443 update_breakpoints_after_exec (void)
2445 struct breakpoint *b, *b_tmp;
2446 struct bp_location *bploc, **bplocp_tmp;
2448 /* We're about to delete breakpoints from GDB's lists. If the
2449 INSERTED flag is true, GDB will try to lift the breakpoints by
2450 writing the breakpoints' "shadow contents" back into memory. The
2451 "shadow contents" are NOT valid after an exec, so GDB should not
2452 do that. Instead, the target is responsible from marking
2453 breakpoints out as soon as it detects an exec. We don't do that
2454 here instead, because there may be other attempts to delete
2455 breakpoints after detecting an exec and before reaching here. */
2456 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2457 if (bploc->pspace == current_program_space)
2458 gdb_assert (!bploc->inserted);
2460 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2462 if (b->pspace != current_program_space)
2465 /* Solib breakpoints must be explicitly reset after an exec(). */
2466 if (b->type == bp_shlib_event)
2468 delete_breakpoint (b);
2472 /* JIT breakpoints must be explicitly reset after an exec(). */
2473 if (b->type == bp_jit_event)
2475 delete_breakpoint (b);
2479 /* Thread event breakpoints must be set anew after an exec(),
2480 as must overlay event and longjmp master breakpoints. */
2481 if (b->type == bp_thread_event || b->type == bp_overlay_event
2482 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2483 || b->type == bp_exception_master)
2485 delete_breakpoint (b);
2489 /* Step-resume breakpoints are meaningless after an exec(). */
2490 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
2492 delete_breakpoint (b);
2496 /* Longjmp and longjmp-resume breakpoints are also meaningless
2498 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2499 || b->type == bp_exception || b->type == bp_exception_resume)
2501 delete_breakpoint (b);
2505 if (b->type == bp_catchpoint)
2507 /* For now, none of the bp_catchpoint breakpoints need to
2508 do anything at this point. In the future, if some of
2509 the catchpoints need to something, we will need to add
2510 a new method, and call this method from here. */
2514 /* bp_finish is a special case. The only way we ought to be able
2515 to see one of these when an exec() has happened, is if the user
2516 caught a vfork, and then said "finish". Ordinarily a finish just
2517 carries them to the call-site of the current callee, by setting
2518 a temporary bp there and resuming. But in this case, the finish
2519 will carry them entirely through the vfork & exec.
2521 We don't want to allow a bp_finish to remain inserted now. But
2522 we can't safely delete it, 'cause finish_command has a handle to
2523 the bp on a bpstat, and will later want to delete it. There's a
2524 chance (and I've seen it happen) that if we delete the bp_finish
2525 here, that its storage will get reused by the time finish_command
2526 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2527 We really must allow finish_command to delete a bp_finish.
2529 In the absence of a general solution for the "how do we know
2530 it's safe to delete something others may have handles to?"
2531 problem, what we'll do here is just uninsert the bp_finish, and
2532 let finish_command delete it.
2534 (We know the bp_finish is "doomed" in the sense that it's
2535 momentary, and will be deleted as soon as finish_command sees
2536 the inferior stopped. So it doesn't matter that the bp's
2537 address is probably bogus in the new a.out, unlike e.g., the
2538 solib breakpoints.) */
2540 if (b->type == bp_finish)
2545 /* Without a symbolic address, we have little hope of the
2546 pre-exec() address meaning the same thing in the post-exec()
2548 if (b->addr_string == NULL)
2550 delete_breakpoint (b);
2554 /* FIXME what about longjmp breakpoints? Re-create them here? */
2555 create_overlay_event_breakpoint ();
2556 create_longjmp_master_breakpoint ();
2557 create_std_terminate_master_breakpoint ();
2558 create_exception_master_breakpoint ();
2562 detach_breakpoints (int pid)
2564 struct bp_location *bl, **blp_tmp;
2566 struct cleanup *old_chain = save_inferior_ptid ();
2567 struct inferior *inf = current_inferior ();
2569 if (pid == PIDGET (inferior_ptid))
2570 error (_("Cannot detach breakpoints of inferior_ptid"));
2572 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2573 inferior_ptid = pid_to_ptid (pid);
2574 ALL_BP_LOCATIONS (bl, blp_tmp)
2576 if (bl->pspace != inf->pspace)
2580 val |= remove_breakpoint_1 (bl, mark_inserted);
2583 /* Detach single-step breakpoints as well. */
2584 detach_single_step_breakpoints ();
2586 do_cleanups (old_chain);
2590 /* Remove the breakpoint location BL from the current address space.
2591 Note that this is used to detach breakpoints from a child fork.
2592 When we get here, the child isn't in the inferior list, and neither
2593 do we have objects to represent its address space --- we should
2594 *not* look at bl->pspace->aspace here. */
2597 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2601 /* BL is never in moribund_locations by our callers. */
2602 gdb_assert (bl->owner != NULL);
2604 if (bl->owner->enable_state == bp_permanent)
2605 /* Permanent breakpoints cannot be inserted or removed. */
2608 /* The type of none suggests that owner is actually deleted.
2609 This should not ever happen. */
2610 gdb_assert (bl->owner->type != bp_none);
2612 if (bl->loc_type == bp_loc_software_breakpoint
2613 || bl->loc_type == bp_loc_hardware_breakpoint)
2615 /* "Normal" instruction breakpoint: either the standard
2616 trap-instruction bp (bp_breakpoint), or a
2617 bp_hardware_breakpoint. */
2619 /* First check to see if we have to handle an overlay. */
2620 if (overlay_debugging == ovly_off
2621 || bl->section == NULL
2622 || !(section_is_overlay (bl->section)))
2624 /* No overlay handling: just remove the breakpoint. */
2625 val = bl->owner->ops->remove_location (bl);
2629 /* This breakpoint is in an overlay section.
2630 Did we set a breakpoint at the LMA? */
2631 if (!overlay_events_enabled)
2633 /* Yes -- overlay event support is not active, so we
2634 should have set a breakpoint at the LMA. Remove it.
2636 /* Ignore any failures: if the LMA is in ROM, we will
2637 have already warned when we failed to insert it. */
2638 if (bl->loc_type == bp_loc_hardware_breakpoint)
2639 target_remove_hw_breakpoint (bl->gdbarch,
2640 &bl->overlay_target_info);
2642 target_remove_breakpoint (bl->gdbarch,
2643 &bl->overlay_target_info);
2645 /* Did we set a breakpoint at the VMA?
2646 If so, we will have marked the breakpoint 'inserted'. */
2649 /* Yes -- remove it. Previously we did not bother to
2650 remove the breakpoint if the section had been
2651 unmapped, but let's not rely on that being safe. We
2652 don't know what the overlay manager might do. */
2654 /* However, we should remove *software* breakpoints only
2655 if the section is still mapped, or else we overwrite
2656 wrong code with the saved shadow contents. */
2657 if (bl->loc_type == bp_loc_hardware_breakpoint
2658 || section_is_mapped (bl->section))
2659 val = bl->owner->ops->remove_location (bl);
2665 /* No -- not inserted, so no need to remove. No error. */
2670 /* In some cases, we might not be able to remove a breakpoint
2671 in a shared library that has already been removed, but we
2672 have not yet processed the shlib unload event. */
2673 if (val && solib_name_from_address (bl->pspace, bl->address))
2678 bl->inserted = (is == mark_inserted);
2680 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2682 gdb_assert (bl->owner->ops != NULL
2683 && bl->owner->ops->remove_location != NULL);
2685 bl->inserted = (is == mark_inserted);
2686 bl->owner->ops->remove_location (bl);
2688 /* Failure to remove any of the hardware watchpoints comes here. */
2689 if ((is == mark_uninserted) && (bl->inserted))
2690 warning (_("Could not remove hardware watchpoint %d."),
2693 else if (bl->owner->type == bp_catchpoint
2694 && breakpoint_enabled (bl->owner)
2697 gdb_assert (bl->owner->ops != NULL
2698 && bl->owner->ops->remove_location != NULL);
2700 val = bl->owner->ops->remove_location (bl);
2704 bl->inserted = (is == mark_inserted);
2711 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2714 struct cleanup *old_chain;
2716 /* BL is never in moribund_locations by our callers. */
2717 gdb_assert (bl->owner != NULL);
2719 if (bl->owner->enable_state == bp_permanent)
2720 /* Permanent breakpoints cannot be inserted or removed. */
2723 /* The type of none suggests that owner is actually deleted.
2724 This should not ever happen. */
2725 gdb_assert (bl->owner->type != bp_none);
2727 old_chain = save_current_space_and_thread ();
2729 switch_to_program_space_and_thread (bl->pspace);
2731 ret = remove_breakpoint_1 (bl, is);
2733 do_cleanups (old_chain);
2737 /* Clear the "inserted" flag in all breakpoints. */
2740 mark_breakpoints_out (void)
2742 struct bp_location *bl, **blp_tmp;
2744 ALL_BP_LOCATIONS (bl, blp_tmp)
2745 if (bl->pspace == current_program_space)
2749 /* Clear the "inserted" flag in all breakpoints and delete any
2750 breakpoints which should go away between runs of the program.
2752 Plus other such housekeeping that has to be done for breakpoints
2755 Note: this function gets called at the end of a run (by
2756 generic_mourn_inferior) and when a run begins (by
2757 init_wait_for_inferior). */
2762 breakpoint_init_inferior (enum inf_context context)
2764 struct breakpoint *b, *b_tmp;
2765 struct bp_location *bl, **blp_tmp;
2767 struct program_space *pspace = current_program_space;
2769 /* If breakpoint locations are shared across processes, then there's
2771 if (gdbarch_has_global_breakpoints (target_gdbarch))
2774 ALL_BP_LOCATIONS (bl, blp_tmp)
2776 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2777 if (bl->pspace == pspace
2778 && bl->owner->enable_state != bp_permanent)
2782 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2784 if (b->loc && b->loc->pspace != pspace)
2791 /* If the call dummy breakpoint is at the entry point it will
2792 cause problems when the inferior is rerun, so we better get
2795 case bp_watchpoint_scope:
2797 /* Also get rid of scope breakpoints. */
2799 case bp_shlib_event:
2801 /* Also remove solib event breakpoints. Their addresses may
2802 have changed since the last time we ran the program.
2803 Actually we may now be debugging against different target;
2804 and so the solib backend that installed this breakpoint may
2805 not be used in by the target. E.g.,
2807 (gdb) file prog-linux
2808 (gdb) run # native linux target
2811 (gdb) file prog-win.exe
2812 (gdb) tar rem :9999 # remote Windows gdbserver.
2815 delete_breakpoint (b);
2819 case bp_hardware_watchpoint:
2820 case bp_read_watchpoint:
2821 case bp_access_watchpoint:
2823 struct watchpoint *w = (struct watchpoint *) b;
2825 /* Likewise for watchpoints on local expressions. */
2826 if (w->exp_valid_block != NULL)
2827 delete_breakpoint (b);
2828 else if (context == inf_starting)
2830 /* Reset val field to force reread of starting value in
2831 insert_breakpoints. */
2833 value_free (w->val);
2844 /* Get rid of the moribund locations. */
2845 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2846 decref_bp_location (&bl);
2847 VEC_free (bp_location_p, moribund_locations);
2850 /* These functions concern about actual breakpoints inserted in the
2851 target --- to e.g. check if we need to do decr_pc adjustment or if
2852 we need to hop over the bkpt --- so we check for address space
2853 match, not program space. */
2855 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2856 exists at PC. It returns ordinary_breakpoint_here if it's an
2857 ordinary breakpoint, or permanent_breakpoint_here if it's a
2858 permanent breakpoint.
2859 - When continuing from a location with an ordinary breakpoint, we
2860 actually single step once before calling insert_breakpoints.
2861 - When continuing from a location with a permanent breakpoint, we
2862 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2863 the target, to advance the PC past the breakpoint. */
2865 enum breakpoint_here
2866 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2868 struct bp_location *bl, **blp_tmp;
2869 int any_breakpoint_here = 0;
2871 ALL_BP_LOCATIONS (bl, blp_tmp)
2873 if (bl->loc_type != bp_loc_software_breakpoint
2874 && bl->loc_type != bp_loc_hardware_breakpoint)
2877 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2878 if ((breakpoint_enabled (bl->owner)
2879 || bl->owner->enable_state == bp_permanent)
2880 && breakpoint_location_address_match (bl, aspace, pc))
2882 if (overlay_debugging
2883 && section_is_overlay (bl->section)
2884 && !section_is_mapped (bl->section))
2885 continue; /* unmapped overlay -- can't be a match */
2886 else if (bl->owner->enable_state == bp_permanent)
2887 return permanent_breakpoint_here;
2889 any_breakpoint_here = 1;
2893 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2896 /* Return true if there's a moribund breakpoint at PC. */
2899 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2901 struct bp_location *loc;
2904 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2905 if (breakpoint_location_address_match (loc, aspace, pc))
2911 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2912 inserted using regular breakpoint_chain / bp_location array
2913 mechanism. This does not check for single-step breakpoints, which
2914 are inserted and removed using direct target manipulation. */
2917 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2920 struct bp_location *bl, **blp_tmp;
2922 ALL_BP_LOCATIONS (bl, blp_tmp)
2924 if (bl->loc_type != bp_loc_software_breakpoint
2925 && bl->loc_type != bp_loc_hardware_breakpoint)
2929 && breakpoint_location_address_match (bl, aspace, pc))
2931 if (overlay_debugging
2932 && section_is_overlay (bl->section)
2933 && !section_is_mapped (bl->section))
2934 continue; /* unmapped overlay -- can't be a match */
2942 /* Returns non-zero iff there's either regular breakpoint
2943 or a single step breakpoint inserted at PC. */
2946 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2948 if (regular_breakpoint_inserted_here_p (aspace, pc))
2951 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2957 /* This function returns non-zero iff there is a software breakpoint
2961 software_breakpoint_inserted_here_p (struct address_space *aspace,
2964 struct bp_location *bl, **blp_tmp;
2966 ALL_BP_LOCATIONS (bl, blp_tmp)
2968 if (bl->loc_type != bp_loc_software_breakpoint)
2972 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2975 if (overlay_debugging
2976 && section_is_overlay (bl->section)
2977 && !section_is_mapped (bl->section))
2978 continue; /* unmapped overlay -- can't be a match */
2984 /* Also check for software single-step breakpoints. */
2985 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2992 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2993 CORE_ADDR addr, ULONGEST len)
2995 struct breakpoint *bpt;
2997 ALL_BREAKPOINTS (bpt)
2999 struct bp_location *loc;
3001 if (bpt->type != bp_hardware_watchpoint
3002 && bpt->type != bp_access_watchpoint)
3005 if (!breakpoint_enabled (bpt))
3008 for (loc = bpt->loc; loc; loc = loc->next)
3009 if (loc->pspace->aspace == aspace && loc->inserted)
3013 /* Check for intersection. */
3014 l = max (loc->address, addr);
3015 h = min (loc->address + loc->length, addr + len);
3023 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3024 PC is valid for process/thread PTID. */
3027 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3030 struct bp_location *bl, **blp_tmp;
3031 /* The thread and task IDs associated to PTID, computed lazily. */
3035 ALL_BP_LOCATIONS (bl, blp_tmp)
3037 if (bl->loc_type != bp_loc_software_breakpoint
3038 && bl->loc_type != bp_loc_hardware_breakpoint)
3041 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3042 if (!breakpoint_enabled (bl->owner)
3043 && bl->owner->enable_state != bp_permanent)
3046 if (!breakpoint_location_address_match (bl, aspace, pc))
3049 if (bl->owner->thread != -1)
3051 /* This is a thread-specific breakpoint. Check that ptid
3052 matches that thread. If thread hasn't been computed yet,
3053 it is now time to do so. */
3055 thread = pid_to_thread_id (ptid);
3056 if (bl->owner->thread != thread)
3060 if (bl->owner->task != 0)
3062 /* This is a task-specific breakpoint. Check that ptid
3063 matches that task. If task hasn't been computed yet,
3064 it is now time to do so. */
3066 task = ada_get_task_number (ptid);
3067 if (bl->owner->task != task)
3071 if (overlay_debugging
3072 && section_is_overlay (bl->section)
3073 && !section_is_mapped (bl->section))
3074 continue; /* unmapped overlay -- can't be a match */
3083 /* bpstat stuff. External routines' interfaces are documented
3087 ep_is_catchpoint (struct breakpoint *ep)
3089 return (ep->type == bp_catchpoint);
3092 /* Frees any storage that is part of a bpstat. Does not walk the
3096 bpstat_free (bpstat bs)
3098 if (bs->old_val != NULL)
3099 value_free (bs->old_val);
3100 decref_counted_command_line (&bs->commands);
3101 decref_bp_location (&bs->bp_location_at);
3105 /* Clear a bpstat so that it says we are not at any breakpoint.
3106 Also free any storage that is part of a bpstat. */
3109 bpstat_clear (bpstat *bsp)
3126 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3127 is part of the bpstat is copied as well. */
3130 bpstat_copy (bpstat bs)
3134 bpstat retval = NULL;
3139 for (; bs != NULL; bs = bs->next)
3141 tmp = (bpstat) xmalloc (sizeof (*tmp));
3142 memcpy (tmp, bs, sizeof (*tmp));
3143 incref_counted_command_line (tmp->commands);
3144 incref_bp_location (tmp->bp_location_at);
3145 if (bs->old_val != NULL)
3147 tmp->old_val = value_copy (bs->old_val);
3148 release_value (tmp->old_val);
3152 /* This is the first thing in the chain. */
3162 /* Find the bpstat associated with this breakpoint. */
3165 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3170 for (; bsp != NULL; bsp = bsp->next)
3172 if (bsp->breakpoint_at == breakpoint)
3178 /* Put in *NUM the breakpoint number of the first breakpoint we are
3179 stopped at. *BSP upon return is a bpstat which points to the
3180 remaining breakpoints stopped at (but which is not guaranteed to be
3181 good for anything but further calls to bpstat_num).
3183 Return 0 if passed a bpstat which does not indicate any breakpoints.
3184 Return -1 if stopped at a breakpoint that has been deleted since
3186 Return 1 otherwise. */
3189 bpstat_num (bpstat *bsp, int *num)
3191 struct breakpoint *b;
3194 return 0; /* No more breakpoint values */
3196 /* We assume we'll never have several bpstats that correspond to a
3197 single breakpoint -- otherwise, this function might return the
3198 same number more than once and this will look ugly. */
3199 b = (*bsp)->breakpoint_at;
3200 *bsp = (*bsp)->next;
3202 return -1; /* breakpoint that's been deleted since */
3204 *num = b->number; /* We have its number */
3208 /* See breakpoint.h. */
3211 bpstat_clear_actions (void)
3213 struct thread_info *tp;
3216 if (ptid_equal (inferior_ptid, null_ptid))
3219 tp = find_thread_ptid (inferior_ptid);
3223 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3225 decref_counted_command_line (&bs->commands);
3227 if (bs->old_val != NULL)
3229 value_free (bs->old_val);
3235 /* Called when a command is about to proceed the inferior. */
3238 breakpoint_about_to_proceed (void)
3240 if (!ptid_equal (inferior_ptid, null_ptid))
3242 struct thread_info *tp = inferior_thread ();
3244 /* Allow inferior function calls in breakpoint commands to not
3245 interrupt the command list. When the call finishes
3246 successfully, the inferior will be standing at the same
3247 breakpoint as if nothing happened. */
3248 if (tp->control.in_infcall)
3252 breakpoint_proceeded = 1;
3255 /* Stub for cleaning up our state if we error-out of a breakpoint
3258 cleanup_executing_breakpoints (void *ignore)
3260 executing_breakpoint_commands = 0;
3263 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3264 or its equivalent. */
3267 command_line_is_silent (struct command_line *cmd)
3269 return cmd && (strcmp ("silent", cmd->line) == 0
3270 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3273 /* Execute all the commands associated with all the breakpoints at
3274 this location. Any of these commands could cause the process to
3275 proceed beyond this point, etc. We look out for such changes by
3276 checking the global "breakpoint_proceeded" after each command.
3278 Returns true if a breakpoint command resumed the inferior. In that
3279 case, it is the caller's responsibility to recall it again with the
3280 bpstat of the current thread. */
3283 bpstat_do_actions_1 (bpstat *bsp)
3286 struct cleanup *old_chain;
3289 /* Avoid endless recursion if a `source' command is contained
3291 if (executing_breakpoint_commands)
3294 executing_breakpoint_commands = 1;
3295 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3297 prevent_dont_repeat ();
3299 /* This pointer will iterate over the list of bpstat's. */
3302 breakpoint_proceeded = 0;
3303 for (; bs != NULL; bs = bs->next)
3305 struct counted_command_line *ccmd;
3306 struct command_line *cmd;
3307 struct cleanup *this_cmd_tree_chain;
3309 /* Take ownership of the BSP's command tree, if it has one.
3311 The command tree could legitimately contain commands like
3312 'step' and 'next', which call clear_proceed_status, which
3313 frees stop_bpstat's command tree. To make sure this doesn't
3314 free the tree we're executing out from under us, we need to
3315 take ownership of the tree ourselves. Since a given bpstat's
3316 commands are only executed once, we don't need to copy it; we
3317 can clear the pointer in the bpstat, and make sure we free
3318 the tree when we're done. */
3319 ccmd = bs->commands;
3320 bs->commands = NULL;
3321 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3322 cmd = ccmd ? ccmd->commands : NULL;
3323 if (command_line_is_silent (cmd))
3325 /* The action has been already done by bpstat_stop_status. */
3331 execute_control_command (cmd);
3333 if (breakpoint_proceeded)
3339 /* We can free this command tree now. */
3340 do_cleanups (this_cmd_tree_chain);
3342 if (breakpoint_proceeded)
3344 if (target_can_async_p ())
3345 /* If we are in async mode, then the target might be still
3346 running, not stopped at any breakpoint, so nothing for
3347 us to do here -- just return to the event loop. */
3350 /* In sync mode, when execute_control_command returns
3351 we're already standing on the next breakpoint.
3352 Breakpoint commands for that stop were not run, since
3353 execute_command does not run breakpoint commands --
3354 only command_line_handler does, but that one is not
3355 involved in execution of breakpoint commands. So, we
3356 can now execute breakpoint commands. It should be
3357 noted that making execute_command do bpstat actions is
3358 not an option -- in this case we'll have recursive
3359 invocation of bpstat for each breakpoint with a
3360 command, and can easily blow up GDB stack. Instead, we
3361 return true, which will trigger the caller to recall us
3362 with the new stop_bpstat. */
3367 do_cleanups (old_chain);
3372 bpstat_do_actions (void)
3374 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
3376 /* Do any commands attached to breakpoint we are stopped at. */
3377 while (!ptid_equal (inferior_ptid, null_ptid)
3378 && target_has_execution
3379 && !is_exited (inferior_ptid)
3380 && !is_executing (inferior_ptid))
3381 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3382 and only return when it is stopped at the next breakpoint, we
3383 keep doing breakpoint actions until it returns false to
3384 indicate the inferior was not resumed. */
3385 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3388 discard_cleanups (cleanup_if_error);
3391 /* Print out the (old or new) value associated with a watchpoint. */
3394 watchpoint_value_print (struct value *val, struct ui_file *stream)
3397 fprintf_unfiltered (stream, _("<unreadable>"));
3400 struct value_print_options opts;
3401 get_user_print_options (&opts);
3402 value_print (val, stream, &opts);
3406 /* Generic routine for printing messages indicating why we
3407 stopped. The behavior of this function depends on the value
3408 'print_it' in the bpstat structure. Under some circumstances we
3409 may decide not to print anything here and delegate the task to
3412 static enum print_stop_action
3413 print_bp_stop_message (bpstat bs)
3415 switch (bs->print_it)
3418 /* Nothing should be printed for this bpstat entry. */
3419 return PRINT_UNKNOWN;
3423 /* We still want to print the frame, but we already printed the
3424 relevant messages. */
3425 return PRINT_SRC_AND_LOC;
3428 case print_it_normal:
3430 struct breakpoint *b = bs->breakpoint_at;
3432 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3433 which has since been deleted. */
3435 return PRINT_UNKNOWN;
3437 /* Normal case. Call the breakpoint's print_it method. */
3438 return b->ops->print_it (bs);
3443 internal_error (__FILE__, __LINE__,
3444 _("print_bp_stop_message: unrecognized enum value"));
3449 /* Print a message indicating what happened. This is called from
3450 normal_stop(). The input to this routine is the head of the bpstat
3451 list - a list of the eventpoints that caused this stop. This
3452 routine calls the generic print routine for printing a message
3453 about reasons for stopping. This will print (for example) the
3454 "Breakpoint n," part of the output. The return value of this
3457 PRINT_UNKNOWN: Means we printed nothing.
3458 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3459 code to print the location. An example is
3460 "Breakpoint 1, " which should be followed by
3462 PRINT_SRC_ONLY: Means we printed something, but there is no need
3463 to also print the location part of the message.
3464 An example is the catch/throw messages, which
3465 don't require a location appended to the end.
3466 PRINT_NOTHING: We have done some printing and we don't need any
3467 further info to be printed. */
3469 enum print_stop_action
3470 bpstat_print (bpstat bs)
3474 /* Maybe another breakpoint in the chain caused us to stop.
3475 (Currently all watchpoints go on the bpstat whether hit or not.
3476 That probably could (should) be changed, provided care is taken
3477 with respect to bpstat_explains_signal). */
3478 for (; bs; bs = bs->next)
3480 val = print_bp_stop_message (bs);
3481 if (val == PRINT_SRC_ONLY
3482 || val == PRINT_SRC_AND_LOC
3483 || val == PRINT_NOTHING)
3487 /* We reached the end of the chain, or we got a null BS to start
3488 with and nothing was printed. */
3489 return PRINT_UNKNOWN;
3492 /* Evaluate the expression EXP and return 1 if value is zero. This is
3493 used inside a catch_errors to evaluate the breakpoint condition.
3494 The argument is a "struct expression *" that has been cast to a
3495 "char *" to make it pass through catch_errors. */
3498 breakpoint_cond_eval (void *exp)
3500 struct value *mark = value_mark ();
3501 int i = !value_true (evaluate_expression ((struct expression *) exp));
3503 value_free_to_mark (mark);
3507 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3510 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3514 bs = (bpstat) xmalloc (sizeof (*bs));
3516 **bs_link_pointer = bs;
3517 *bs_link_pointer = &bs->next;
3518 bs->breakpoint_at = bl->owner;
3519 bs->bp_location_at = bl;
3520 incref_bp_location (bl);
3521 /* If the condition is false, etc., don't do the commands. */
3522 bs->commands = NULL;
3524 bs->print_it = print_it_normal;
3528 /* The target has stopped with waitstatus WS. Check if any hardware
3529 watchpoints have triggered, according to the target. */
3532 watchpoints_triggered (struct target_waitstatus *ws)
3534 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3536 struct breakpoint *b;
3538 if (!stopped_by_watchpoint)
3540 /* We were not stopped by a watchpoint. Mark all watchpoints
3541 as not triggered. */
3543 if (is_hardware_watchpoint (b))
3545 struct watchpoint *w = (struct watchpoint *) b;
3547 w->watchpoint_triggered = watch_triggered_no;
3553 if (!target_stopped_data_address (¤t_target, &addr))
3555 /* We were stopped by a watchpoint, but we don't know where.
3556 Mark all watchpoints as unknown. */
3558 if (is_hardware_watchpoint (b))
3560 struct watchpoint *w = (struct watchpoint *) b;
3562 w->watchpoint_triggered = watch_triggered_unknown;
3565 return stopped_by_watchpoint;
3568 /* The target could report the data address. Mark watchpoints
3569 affected by this data address as triggered, and all others as not
3573 if (is_hardware_watchpoint (b))
3575 struct watchpoint *w = (struct watchpoint *) b;
3576 struct bp_location *loc;
3578 w->watchpoint_triggered = watch_triggered_no;
3579 for (loc = b->loc; loc; loc = loc->next)
3581 if (is_masked_watchpoint (b))
3583 CORE_ADDR newaddr = addr & w->hw_wp_mask;
3584 CORE_ADDR start = loc->address & w->hw_wp_mask;
3586 if (newaddr == start)
3588 w->watchpoint_triggered = watch_triggered_yes;
3592 /* Exact match not required. Within range is sufficient. */
3593 else if (target_watchpoint_addr_within_range (¤t_target,
3597 w->watchpoint_triggered = watch_triggered_yes;
3606 /* Possible return values for watchpoint_check (this can't be an enum
3607 because of check_errors). */
3608 /* The watchpoint has been deleted. */
3609 #define WP_DELETED 1
3610 /* The value has changed. */
3611 #define WP_VALUE_CHANGED 2
3612 /* The value has not changed. */
3613 #define WP_VALUE_NOT_CHANGED 3
3614 /* Ignore this watchpoint, no matter if the value changed or not. */
3617 #define BP_TEMPFLAG 1
3618 #define BP_HARDWAREFLAG 2
3620 /* Evaluate watchpoint condition expression and check if its value
3623 P should be a pointer to struct bpstat, but is defined as a void *
3624 in order for this function to be usable with catch_errors. */
3627 watchpoint_check (void *p)
3629 bpstat bs = (bpstat) p;
3630 struct watchpoint *b;
3631 struct frame_info *fr;
3632 int within_current_scope;
3634 /* BS is built from an existing struct breakpoint. */
3635 gdb_assert (bs->breakpoint_at != NULL);
3636 b = (struct watchpoint *) bs->breakpoint_at;
3638 /* If this is a local watchpoint, we only want to check if the
3639 watchpoint frame is in scope if the current thread is the thread
3640 that was used to create the watchpoint. */
3641 if (!watchpoint_in_thread_scope (b))
3644 if (b->exp_valid_block == NULL)
3645 within_current_scope = 1;
3648 struct frame_info *frame = get_current_frame ();
3649 struct gdbarch *frame_arch = get_frame_arch (frame);
3650 CORE_ADDR frame_pc = get_frame_pc (frame);
3652 /* in_function_epilogue_p() returns a non-zero value if we're
3653 still in the function but the stack frame has already been
3654 invalidated. Since we can't rely on the values of local
3655 variables after the stack has been destroyed, we are treating
3656 the watchpoint in that state as `not changed' without further
3657 checking. Don't mark watchpoints as changed if the current
3658 frame is in an epilogue - even if they are in some other
3659 frame, our view of the stack is likely to be wrong and
3660 frame_find_by_id could error out. */
3661 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3664 fr = frame_find_by_id (b->watchpoint_frame);
3665 within_current_scope = (fr != NULL);
3667 /* If we've gotten confused in the unwinder, we might have
3668 returned a frame that can't describe this variable. */
3669 if (within_current_scope)
3671 struct symbol *function;
3673 function = get_frame_function (fr);
3674 if (function == NULL
3675 || !contained_in (b->exp_valid_block,
3676 SYMBOL_BLOCK_VALUE (function)))
3677 within_current_scope = 0;
3680 if (within_current_scope)
3681 /* If we end up stopping, the current frame will get selected
3682 in normal_stop. So this call to select_frame won't affect
3687 if (within_current_scope)
3689 /* We use value_{,free_to_}mark because it could be a *long*
3690 time before we return to the command level and call
3691 free_all_values. We can't call free_all_values because we
3692 might be in the middle of evaluating a function call. */
3696 struct value *new_val;
3698 if (is_masked_watchpoint (&b->base))
3699 /* Since we don't know the exact trigger address (from
3700 stopped_data_address), just tell the user we've triggered
3701 a mask watchpoint. */
3702 return WP_VALUE_CHANGED;
3704 mark = value_mark ();
3705 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3707 /* We use value_equal_contents instead of value_equal because
3708 the latter coerces an array to a pointer, thus comparing just
3709 the address of the array instead of its contents. This is
3710 not what we want. */
3711 if ((b->val != NULL) != (new_val != NULL)
3712 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3714 if (new_val != NULL)
3716 release_value (new_val);
3717 value_free_to_mark (mark);
3719 bs->old_val = b->val;
3722 return WP_VALUE_CHANGED;
3726 /* Nothing changed. */
3727 value_free_to_mark (mark);
3728 return WP_VALUE_NOT_CHANGED;
3733 struct ui_out *uiout = current_uiout;
3735 /* This seems like the only logical thing to do because
3736 if we temporarily ignored the watchpoint, then when
3737 we reenter the block in which it is valid it contains
3738 garbage (in the case of a function, it may have two
3739 garbage values, one before and one after the prologue).
3740 So we can't even detect the first assignment to it and
3741 watch after that (since the garbage may or may not equal
3742 the first value assigned). */
3743 /* We print all the stop information in
3744 breakpoint_ops->print_it, but in this case, by the time we
3745 call breakpoint_ops->print_it this bp will be deleted
3746 already. So we have no choice but print the information
3748 if (ui_out_is_mi_like_p (uiout))
3750 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3751 ui_out_text (uiout, "\nWatchpoint ");
3752 ui_out_field_int (uiout, "wpnum", b->base.number);
3754 " deleted because the program has left the block in\n\
3755 which its expression is valid.\n");
3757 /* Make sure the watchpoint's commands aren't executed. */
3758 decref_counted_command_line (&b->base.commands);
3759 watchpoint_del_at_next_stop (b);
3765 /* Return true if it looks like target has stopped due to hitting
3766 breakpoint location BL. This function does not check if we should
3767 stop, only if BL explains the stop. */
3770 bpstat_check_location (const struct bp_location *bl,
3771 struct address_space *aspace, CORE_ADDR bp_addr)
3773 struct breakpoint *b = bl->owner;
3775 /* BL is from an existing breakpoint. */
3776 gdb_assert (b != NULL);
3778 return b->ops->breakpoint_hit (bl, aspace, bp_addr);
3781 /* Determine if the watched values have actually changed, and we
3782 should stop. If not, set BS->stop to 0. */
3785 bpstat_check_watchpoint (bpstat bs)
3787 const struct bp_location *bl;
3788 struct watchpoint *b;
3790 /* BS is built for existing struct breakpoint. */
3791 bl = bs->bp_location_at;
3792 gdb_assert (bl != NULL);
3793 b = (struct watchpoint *) bs->breakpoint_at;
3794 gdb_assert (b != NULL);
3797 int must_check_value = 0;
3799 if (b->base.type == bp_watchpoint)
3800 /* For a software watchpoint, we must always check the
3802 must_check_value = 1;
3803 else if (b->watchpoint_triggered == watch_triggered_yes)
3804 /* We have a hardware watchpoint (read, write, or access)
3805 and the target earlier reported an address watched by
3807 must_check_value = 1;
3808 else if (b->watchpoint_triggered == watch_triggered_unknown
3809 && b->base.type == bp_hardware_watchpoint)
3810 /* We were stopped by a hardware watchpoint, but the target could
3811 not report the data address. We must check the watchpoint's
3812 value. Access and read watchpoints are out of luck; without
3813 a data address, we can't figure it out. */
3814 must_check_value = 1;
3816 if (must_check_value)
3819 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3821 struct cleanup *cleanups = make_cleanup (xfree, message);
3822 int e = catch_errors (watchpoint_check, bs, message,
3824 do_cleanups (cleanups);
3828 /* We've already printed what needs to be printed. */
3829 bs->print_it = print_it_done;
3833 bs->print_it = print_it_noop;
3836 case WP_VALUE_CHANGED:
3837 if (b->base.type == bp_read_watchpoint)
3839 /* There are two cases to consider here:
3841 1. We're watching the triggered memory for reads.
3842 In that case, trust the target, and always report
3843 the watchpoint hit to the user. Even though
3844 reads don't cause value changes, the value may
3845 have changed since the last time it was read, and
3846 since we're not trapping writes, we will not see
3847 those, and as such we should ignore our notion of
3850 2. We're watching the triggered memory for both
3851 reads and writes. There are two ways this may
3854 2.1. This is a target that can't break on data
3855 reads only, but can break on accesses (reads or
3856 writes), such as e.g., x86. We detect this case
3857 at the time we try to insert read watchpoints.
3859 2.2. Otherwise, the target supports read
3860 watchpoints, but, the user set an access or write
3861 watchpoint watching the same memory as this read
3864 If we're watching memory writes as well as reads,
3865 ignore watchpoint hits when we find that the
3866 value hasn't changed, as reads don't cause
3867 changes. This still gives false positives when
3868 the program writes the same value to memory as
3869 what there was already in memory (we will confuse
3870 it for a read), but it's much better than
3873 int other_write_watchpoint = 0;
3875 if (bl->watchpoint_type == hw_read)
3877 struct breakpoint *other_b;
3879 ALL_BREAKPOINTS (other_b)
3880 if (other_b->type == bp_hardware_watchpoint
3881 || other_b->type == bp_access_watchpoint)
3883 struct watchpoint *other_w =
3884 (struct watchpoint *) other_b;
3886 if (other_w->watchpoint_triggered
3887 == watch_triggered_yes)
3889 other_write_watchpoint = 1;
3895 if (other_write_watchpoint
3896 || bl->watchpoint_type == hw_access)
3898 /* We're watching the same memory for writes,
3899 and the value changed since the last time we
3900 updated it, so this trap must be for a write.
3902 bs->print_it = print_it_noop;
3907 case WP_VALUE_NOT_CHANGED:
3908 if (b->base.type == bp_hardware_watchpoint
3909 || b->base.type == bp_watchpoint)
3911 /* Don't stop: write watchpoints shouldn't fire if
3912 the value hasn't changed. */
3913 bs->print_it = print_it_noop;
3921 /* Error from catch_errors. */
3922 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
3923 watchpoint_del_at_next_stop (b);
3924 /* We've already printed what needs to be printed. */
3925 bs->print_it = print_it_done;
3929 else /* must_check_value == 0 */
3931 /* This is a case where some watchpoint(s) triggered, but
3932 not at the address of this watchpoint, or else no
3933 watchpoint triggered after all. So don't print
3934 anything for this watchpoint. */
3935 bs->print_it = print_it_noop;
3942 /* Check conditions (condition proper, frame, thread and ignore count)
3943 of breakpoint referred to by BS. If we should not stop for this
3944 breakpoint, set BS->stop to 0. */
3947 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3949 int thread_id = pid_to_thread_id (ptid);
3950 const struct bp_location *bl;
3951 struct breakpoint *b;
3953 /* BS is built for existing struct breakpoint. */
3954 bl = bs->bp_location_at;
3955 gdb_assert (bl != NULL);
3956 b = bs->breakpoint_at;
3957 gdb_assert (b != NULL);
3959 if (frame_id_p (b->frame_id)
3960 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3964 int value_is_zero = 0;
3965 struct expression *cond;
3967 /* Evaluate Python breakpoints that have a "stop"
3968 method implemented. */
3969 if (b->py_bp_object)
3970 bs->stop = gdbpy_should_stop (b->py_bp_object);
3972 if (is_watchpoint (b))
3974 struct watchpoint *w = (struct watchpoint *) b;
3981 if (cond && b->disposition != disp_del_at_next_stop)
3983 int within_current_scope = 1;
3984 struct watchpoint * w;
3986 /* We use value_mark and value_free_to_mark because it could
3987 be a long time before we return to the command level and
3988 call free_all_values. We can't call free_all_values
3989 because we might be in the middle of evaluating a
3991 struct value *mark = value_mark ();
3993 if (is_watchpoint (b))
3994 w = (struct watchpoint *) b;
3998 /* Need to select the frame, with all that implies so that
3999 the conditions will have the right context. Because we
4000 use the frame, we will not see an inlined function's
4001 variables when we arrive at a breakpoint at the start
4002 of the inlined function; the current frame will be the
4004 if (w == NULL || w->cond_exp_valid_block == NULL)
4005 select_frame (get_current_frame ());
4008 struct frame_info *frame;
4010 /* For local watchpoint expressions, which particular
4011 instance of a local is being watched matters, so we
4012 keep track of the frame to evaluate the expression
4013 in. To evaluate the condition however, it doesn't
4014 really matter which instantiation of the function
4015 where the condition makes sense triggers the
4016 watchpoint. This allows an expression like "watch
4017 global if q > 10" set in `func', catch writes to
4018 global on all threads that call `func', or catch
4019 writes on all recursive calls of `func' by a single
4020 thread. We simply always evaluate the condition in
4021 the innermost frame that's executing where it makes
4022 sense to evaluate the condition. It seems
4024 frame = block_innermost_frame (w->cond_exp_valid_block);
4026 select_frame (frame);
4028 within_current_scope = 0;
4030 if (within_current_scope)
4032 = catch_errors (breakpoint_cond_eval, cond,
4033 "Error in testing breakpoint condition:\n",
4037 warning (_("Watchpoint condition cannot be tested "
4038 "in the current scope"));
4039 /* If we failed to set the right context for this
4040 watchpoint, unconditionally report it. */
4043 /* FIXME-someday, should give breakpoint #. */
4044 value_free_to_mark (mark);
4047 if (cond && value_is_zero)
4051 else if (b->thread != -1 && b->thread != thread_id)
4055 else if (b->ignore_count > 0)
4058 annotate_ignore_count_change ();
4060 /* Increase the hit count even though we don't stop. */
4062 observer_notify_breakpoint_modified (b);
4068 /* Get a bpstat associated with having just stopped at address
4069 BP_ADDR in thread PTID.
4071 Determine whether we stopped at a breakpoint, etc, or whether we
4072 don't understand this stop. Result is a chain of bpstat's such
4075 if we don't understand the stop, the result is a null pointer.
4077 if we understand why we stopped, the result is not null.
4079 Each element of the chain refers to a particular breakpoint or
4080 watchpoint at which we have stopped. (We may have stopped for
4081 several reasons concurrently.)
4083 Each element of the chain has valid next, breakpoint_at,
4084 commands, FIXME??? fields. */
4087 bpstat_stop_status (struct address_space *aspace,
4088 CORE_ADDR bp_addr, ptid_t ptid)
4090 struct breakpoint *b = NULL;
4091 struct bp_location *bl;
4092 struct bp_location *loc;
4093 /* First item of allocated bpstat's. */
4094 bpstat bs_head = NULL, *bs_link = &bs_head;
4095 /* Pointer to the last thing in the chain currently. */
4098 int need_remove_insert;
4101 /* First, build the bpstat chain with locations that explain a
4102 target stop, while being careful to not set the target running,
4103 as that may invalidate locations (in particular watchpoint
4104 locations are recreated). Resuming will happen here with
4105 breakpoint conditions or watchpoint expressions that include
4106 inferior function calls. */
4110 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4113 for (bl = b->loc; bl != NULL; bl = bl->next)
4115 /* For hardware watchpoints, we look only at the first
4116 location. The watchpoint_check function will work on the
4117 entire expression, not the individual locations. For
4118 read watchpoints, the watchpoints_triggered function has
4119 checked all locations already. */
4120 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4123 if (bl->shlib_disabled)
4126 if (!bpstat_check_location (bl, aspace, bp_addr))
4129 /* Come here if it's a watchpoint, or if the break address
4132 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4135 /* Assume we stop. Should we find a watchpoint that is not
4136 actually triggered, or if the condition of the breakpoint
4137 evaluates as false, we'll reset 'stop' to 0. */
4141 /* If this is a scope breakpoint, mark the associated
4142 watchpoint as triggered so that we will handle the
4143 out-of-scope event. We'll get to the watchpoint next
4145 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4147 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4149 w->watchpoint_triggered = watch_triggered_yes;
4154 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4156 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4158 bs = bpstat_alloc (loc, &bs_link);
4159 /* For hits of moribund locations, we should just proceed. */
4162 bs->print_it = print_it_noop;
4166 /* Now go through the locations that caused the target to stop, and
4167 check whether we're interested in reporting this stop to higher
4168 layers, or whether we should resume the target transparently. */
4172 for (bs = bs_head; bs != NULL; bs = bs->next)
4177 b = bs->breakpoint_at;
4178 b->ops->check_status (bs);
4181 bpstat_check_breakpoint_conditions (bs, ptid);
4186 observer_notify_breakpoint_modified (b);
4188 /* We will stop here. */
4189 if (b->disposition == disp_disable)
4191 if (b->enable_state != bp_permanent)
4192 b->enable_state = bp_disabled;
4197 bs->commands = b->commands;
4198 incref_counted_command_line (bs->commands);
4199 if (command_line_is_silent (bs->commands
4200 ? bs->commands->commands : NULL))
4204 /* Print nothing for this entry if we don't stop or don't print. */
4205 if (bs->stop == 0 || bs->print == 0)
4206 bs->print_it = print_it_noop;
4210 /* If we aren't stopping, the value of some hardware watchpoint may
4211 not have changed, but the intermediate memory locations we are
4212 watching may have. Don't bother if we're stopping; this will get
4214 need_remove_insert = 0;
4215 if (! bpstat_causes_stop (bs_head))
4216 for (bs = bs_head; bs != NULL; bs = bs->next)
4218 && bs->breakpoint_at
4219 && is_hardware_watchpoint (bs->breakpoint_at))
4221 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4223 update_watchpoint (w, 0 /* don't reparse. */);
4224 need_remove_insert = 1;
4227 if (need_remove_insert)
4228 update_global_location_list (1);
4229 else if (removed_any)
4230 update_global_location_list (0);
4236 handle_jit_event (void)
4238 struct frame_info *frame;
4239 struct gdbarch *gdbarch;
4241 /* Switch terminal for any messages produced by
4242 breakpoint_re_set. */
4243 target_terminal_ours_for_output ();
4245 frame = get_current_frame ();
4246 gdbarch = get_frame_arch (frame);
4248 jit_event_handler (gdbarch);
4250 target_terminal_inferior ();
4253 /* Prepare WHAT final decision for infrun. */
4255 /* Decide what infrun needs to do with this bpstat. */
4258 bpstat_what (bpstat bs_head)
4260 struct bpstat_what retval;
4261 /* We need to defer calling `solib_add', as adding new symbols
4262 resets breakpoints, which in turn deletes breakpoint locations,
4263 and hence may clear unprocessed entries in the BS chain. */
4264 int shlib_event = 0;
4268 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4269 retval.call_dummy = STOP_NONE;
4270 retval.is_longjmp = 0;
4272 for (bs = bs_head; bs != NULL; bs = bs->next)
4274 /* Extract this BS's action. After processing each BS, we check
4275 if its action overrides all we've seem so far. */
4276 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4279 if (bs->breakpoint_at == NULL)
4281 /* I suspect this can happen if it was a momentary
4282 breakpoint which has since been deleted. */
4286 bptype = bs->breakpoint_at->type;
4293 case bp_hardware_breakpoint:
4299 this_action = BPSTAT_WHAT_STOP_NOISY;
4301 this_action = BPSTAT_WHAT_STOP_SILENT;
4304 this_action = BPSTAT_WHAT_SINGLE;
4307 case bp_hardware_watchpoint:
4308 case bp_read_watchpoint:
4309 case bp_access_watchpoint:
4313 this_action = BPSTAT_WHAT_STOP_NOISY;
4315 this_action = BPSTAT_WHAT_STOP_SILENT;
4319 /* There was a watchpoint, but we're not stopping.
4320 This requires no further action. */
4325 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4326 retval.is_longjmp = bptype == bp_longjmp;
4328 case bp_longjmp_resume:
4329 case bp_exception_resume:
4330 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4331 retval.is_longjmp = bptype == bp_longjmp_resume;
4333 case bp_step_resume:
4335 this_action = BPSTAT_WHAT_STEP_RESUME;
4338 /* It is for the wrong frame. */
4339 this_action = BPSTAT_WHAT_SINGLE;
4342 case bp_hp_step_resume:
4344 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4347 /* It is for the wrong frame. */
4348 this_action = BPSTAT_WHAT_SINGLE;
4351 case bp_watchpoint_scope:
4352 case bp_thread_event:
4353 case bp_overlay_event:
4354 case bp_longjmp_master:
4355 case bp_std_terminate_master:
4356 case bp_exception_master:
4357 this_action = BPSTAT_WHAT_SINGLE;
4363 this_action = BPSTAT_WHAT_STOP_NOISY;
4365 this_action = BPSTAT_WHAT_STOP_SILENT;
4369 /* There was a catchpoint, but we're not stopping.
4370 This requires no further action. */
4373 case bp_shlib_event:
4376 /* If requested, stop when the dynamic linker notifies GDB
4377 of events. This allows the user to get control and place
4378 breakpoints in initializer routines for dynamically
4379 loaded objects (among other things). */
4380 if (stop_on_solib_events)
4381 this_action = BPSTAT_WHAT_STOP_NOISY;
4383 this_action = BPSTAT_WHAT_SINGLE;
4387 this_action = BPSTAT_WHAT_SINGLE;
4390 /* Make sure the action is stop (silent or noisy),
4391 so infrun.c pops the dummy frame. */
4392 retval.call_dummy = STOP_STACK_DUMMY;
4393 this_action = BPSTAT_WHAT_STOP_SILENT;
4395 case bp_std_terminate:
4396 /* Make sure the action is stop (silent or noisy),
4397 so infrun.c pops the dummy frame. */
4398 retval.call_dummy = STOP_STD_TERMINATE;
4399 this_action = BPSTAT_WHAT_STOP_SILENT;
4402 case bp_fast_tracepoint:
4403 case bp_static_tracepoint:
4404 /* Tracepoint hits should not be reported back to GDB, and
4405 if one got through somehow, it should have been filtered
4407 internal_error (__FILE__, __LINE__,
4408 _("bpstat_what: tracepoint encountered"));
4410 case bp_gnu_ifunc_resolver:
4411 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4412 this_action = BPSTAT_WHAT_SINGLE;
4414 case bp_gnu_ifunc_resolver_return:
4415 /* The breakpoint will be removed, execution will restart from the
4416 PC of the former breakpoint. */
4417 this_action = BPSTAT_WHAT_KEEP_CHECKING;
4420 internal_error (__FILE__, __LINE__,
4421 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4424 retval.main_action = max (retval.main_action, this_action);
4427 /* These operations may affect the bs->breakpoint_at state so they are
4428 delayed after MAIN_ACTION is decided above. */
4433 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4435 /* Check for any newly added shared libraries if we're supposed
4436 to be adding them automatically. */
4438 /* Switch terminal for any messages produced by
4439 breakpoint_re_set. */
4440 target_terminal_ours_for_output ();
4443 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4445 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4448 target_terminal_inferior ();
4454 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4456 handle_jit_event ();
4459 for (bs = bs_head; bs != NULL; bs = bs->next)
4461 struct breakpoint *b = bs->breakpoint_at;
4467 case bp_gnu_ifunc_resolver:
4468 gnu_ifunc_resolver_stop (b);
4470 case bp_gnu_ifunc_resolver_return:
4471 gnu_ifunc_resolver_return_stop (b);
4479 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4480 without hardware support). This isn't related to a specific bpstat,
4481 just to things like whether watchpoints are set. */
4484 bpstat_should_step (void)
4486 struct breakpoint *b;
4489 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4495 bpstat_causes_stop (bpstat bs)
4497 for (; bs != NULL; bs = bs->next)
4506 /* Compute a string of spaces suitable to indent the next line
4507 so it starts at the position corresponding to the table column
4508 named COL_NAME in the currently active table of UIOUT. */
4511 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
4513 static char wrap_indent[80];
4514 int i, total_width, width, align;
4518 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
4520 if (strcmp (text, col_name) == 0)
4522 gdb_assert (total_width < sizeof wrap_indent);
4523 memset (wrap_indent, ' ', total_width);
4524 wrap_indent[total_width] = 0;
4529 total_width += width + 1;
4535 /* Print the LOC location out of the list of B->LOC locations. */
4538 print_breakpoint_location (struct breakpoint *b,
4539 struct bp_location *loc)
4541 struct ui_out *uiout = current_uiout;
4542 struct cleanup *old_chain = save_current_program_space ();
4544 if (loc != NULL && loc->shlib_disabled)
4548 set_current_program_space (loc->pspace);
4550 if (b->display_canonical)
4551 ui_out_field_string (uiout, "what", b->addr_string);
4552 else if (b->source_file && loc)
4555 = find_pc_sect_function (loc->address, loc->section);
4558 ui_out_text (uiout, "in ");
4559 ui_out_field_string (uiout, "func",
4560 SYMBOL_PRINT_NAME (sym));
4561 ui_out_text (uiout, " ");
4562 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
4563 ui_out_text (uiout, "at ");
4565 ui_out_field_string (uiout, "file", b->source_file);
4566 ui_out_text (uiout, ":");
4568 if (ui_out_is_mi_like_p (uiout))
4570 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4571 char *fullname = symtab_to_fullname (sal.symtab);
4574 ui_out_field_string (uiout, "fullname", fullname);
4577 ui_out_field_int (uiout, "line", b->line_number);
4581 struct ui_stream *stb = ui_out_stream_new (uiout);
4582 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
4584 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4586 ui_out_field_stream (uiout, "at", stb);
4588 do_cleanups (stb_chain);
4591 ui_out_field_string (uiout, "pending", b->addr_string);
4593 do_cleanups (old_chain);
4597 bptype_string (enum bptype type)
4599 struct ep_type_description
4604 static struct ep_type_description bptypes[] =
4606 {bp_none, "?deleted?"},
4607 {bp_breakpoint, "breakpoint"},
4608 {bp_hardware_breakpoint, "hw breakpoint"},
4609 {bp_until, "until"},
4610 {bp_finish, "finish"},
4611 {bp_watchpoint, "watchpoint"},
4612 {bp_hardware_watchpoint, "hw watchpoint"},
4613 {bp_read_watchpoint, "read watchpoint"},
4614 {bp_access_watchpoint, "acc watchpoint"},
4615 {bp_longjmp, "longjmp"},
4616 {bp_longjmp_resume, "longjmp resume"},
4617 {bp_exception, "exception"},
4618 {bp_exception_resume, "exception resume"},
4619 {bp_step_resume, "step resume"},
4620 {bp_hp_step_resume, "high-priority step resume"},
4621 {bp_watchpoint_scope, "watchpoint scope"},
4622 {bp_call_dummy, "call dummy"},
4623 {bp_std_terminate, "std::terminate"},
4624 {bp_shlib_event, "shlib events"},
4625 {bp_thread_event, "thread events"},
4626 {bp_overlay_event, "overlay events"},
4627 {bp_longjmp_master, "longjmp master"},
4628 {bp_std_terminate_master, "std::terminate master"},
4629 {bp_exception_master, "exception master"},
4630 {bp_catchpoint, "catchpoint"},
4631 {bp_tracepoint, "tracepoint"},
4632 {bp_fast_tracepoint, "fast tracepoint"},
4633 {bp_static_tracepoint, "static tracepoint"},
4634 {bp_jit_event, "jit events"},
4635 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
4636 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
4639 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4640 || ((int) type != bptypes[(int) type].type))
4641 internal_error (__FILE__, __LINE__,
4642 _("bptypes table does not describe type #%d."),
4645 return bptypes[(int) type].description;
4648 /* Print B to gdb_stdout. */
4651 print_one_breakpoint_location (struct breakpoint *b,
4652 struct bp_location *loc,
4654 struct bp_location **last_loc,
4657 struct command_line *l;
4658 static char bpenables[] = "nynny";
4660 struct ui_out *uiout = current_uiout;
4661 int header_of_multiple = 0;
4662 int part_of_multiple = (loc != NULL);
4663 struct value_print_options opts;
4665 get_user_print_options (&opts);
4667 gdb_assert (!loc || loc_number != 0);
4668 /* See comment in print_one_breakpoint concerning treatment of
4669 breakpoints with single disabled location. */
4672 && (b->loc->next != NULL || !b->loc->enabled)))
4673 header_of_multiple = 1;
4681 if (part_of_multiple)
4684 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4685 ui_out_field_string (uiout, "number", formatted);
4690 ui_out_field_int (uiout, "number", b->number);
4695 if (part_of_multiple)
4696 ui_out_field_skip (uiout, "type");
4698 ui_out_field_string (uiout, "type", bptype_string (b->type));
4702 if (part_of_multiple)
4703 ui_out_field_skip (uiout, "disp");
4705 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4710 if (part_of_multiple)
4711 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4713 ui_out_field_fmt (uiout, "enabled", "%c",
4714 bpenables[(int) b->enable_state]);
4715 ui_out_spaces (uiout, 2);
4719 if (b->ops != NULL && b->ops->print_one != NULL)
4721 /* Although the print_one can possibly print all locations,
4722 calling it here is not likely to get any nice result. So,
4723 make sure there's just one location. */
4724 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4725 b->ops->print_one (b, last_loc);
4731 internal_error (__FILE__, __LINE__,
4732 _("print_one_breakpoint: bp_none encountered\n"));
4736 case bp_hardware_watchpoint:
4737 case bp_read_watchpoint:
4738 case bp_access_watchpoint:
4740 struct watchpoint *w = (struct watchpoint *) b;
4742 /* Field 4, the address, is omitted (which makes the columns
4743 not line up too nicely with the headers, but the effect
4744 is relatively readable). */
4745 if (opts.addressprint)
4746 ui_out_field_skip (uiout, "addr");
4748 ui_out_field_string (uiout, "what", w->exp_string);
4753 case bp_hardware_breakpoint:
4757 case bp_longjmp_resume:
4759 case bp_exception_resume:
4760 case bp_step_resume:
4761 case bp_hp_step_resume:
4762 case bp_watchpoint_scope:
4764 case bp_std_terminate:
4765 case bp_shlib_event:
4766 case bp_thread_event:
4767 case bp_overlay_event:
4768 case bp_longjmp_master:
4769 case bp_std_terminate_master:
4770 case bp_exception_master:
4772 case bp_fast_tracepoint:
4773 case bp_static_tracepoint:
4775 case bp_gnu_ifunc_resolver:
4776 case bp_gnu_ifunc_resolver_return:
4777 if (opts.addressprint)
4780 if (header_of_multiple)
4781 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4782 else if (b->loc == NULL || loc->shlib_disabled)
4783 ui_out_field_string (uiout, "addr", "<PENDING>");
4785 ui_out_field_core_addr (uiout, "addr",
4786 loc->gdbarch, loc->address);
4789 if (!header_of_multiple)
4790 print_breakpoint_location (b, loc);
4797 /* For backward compatibility, don't display inferiors unless there
4800 && !header_of_multiple
4802 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4803 && (number_of_program_spaces () > 1
4804 || number_of_inferiors () > 1)
4805 /* LOC is for existing B, it cannot be in
4806 moribund_locations and thus having NULL OWNER. */
4807 && loc->owner->type != bp_catchpoint)))
4809 struct inferior *inf;
4812 for (inf = inferior_list; inf != NULL; inf = inf->next)
4814 if (inf->pspace == loc->pspace)
4819 ui_out_text (uiout, " inf ");
4822 ui_out_text (uiout, ", ");
4823 ui_out_text (uiout, plongest (inf->num));
4828 if (!part_of_multiple)
4830 if (b->thread != -1)
4832 /* FIXME: This seems to be redundant and lost here; see the
4833 "stop only in" line a little further down. */
4834 ui_out_text (uiout, " thread ");
4835 ui_out_field_int (uiout, "thread", b->thread);
4837 else if (b->task != 0)
4839 ui_out_text (uiout, " task ");
4840 ui_out_field_int (uiout, "task", b->task);
4844 ui_out_text (uiout, "\n");
4846 if (!part_of_multiple)
4847 b->ops->print_one_detail (b, uiout);
4849 if (part_of_multiple && frame_id_p (b->frame_id))
4852 ui_out_text (uiout, "\tstop only in stack frame at ");
4853 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4855 ui_out_field_core_addr (uiout, "frame",
4856 b->gdbarch, b->frame_id.stack_addr);
4857 ui_out_text (uiout, "\n");
4860 if (!part_of_multiple && b->cond_string)
4863 if (is_tracepoint (b))
4864 ui_out_text (uiout, "\ttrace only if ");
4866 ui_out_text (uiout, "\tstop only if ");
4867 ui_out_field_string (uiout, "cond", b->cond_string);
4868 ui_out_text (uiout, "\n");
4871 if (!part_of_multiple && b->thread != -1)
4873 /* FIXME should make an annotation for this. */
4874 ui_out_text (uiout, "\tstop only in thread ");
4875 ui_out_field_int (uiout, "thread", b->thread);
4876 ui_out_text (uiout, "\n");
4879 if (!part_of_multiple && b->hit_count)
4881 /* FIXME should make an annotation for this. */
4882 if (ep_is_catchpoint (b))
4883 ui_out_text (uiout, "\tcatchpoint");
4885 ui_out_text (uiout, "\tbreakpoint");
4886 ui_out_text (uiout, " already hit ");
4887 ui_out_field_int (uiout, "times", b->hit_count);
4888 if (b->hit_count == 1)
4889 ui_out_text (uiout, " time\n");
4891 ui_out_text (uiout, " times\n");
4894 /* Output the count also if it is zero, but only if this is mi.
4895 FIXME: Should have a better test for this. */
4896 if (ui_out_is_mi_like_p (uiout))
4897 if (!part_of_multiple && b->hit_count == 0)
4898 ui_out_field_int (uiout, "times", b->hit_count);
4900 if (!part_of_multiple && b->ignore_count)
4903 ui_out_text (uiout, "\tignore next ");
4904 ui_out_field_int (uiout, "ignore", b->ignore_count);
4905 ui_out_text (uiout, " hits\n");
4908 l = b->commands ? b->commands->commands : NULL;
4909 if (!part_of_multiple && l)
4911 struct cleanup *script_chain;
4914 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4915 print_command_lines (uiout, l, 4);
4916 do_cleanups (script_chain);
4919 if (is_tracepoint (b))
4921 struct tracepoint *t = (struct tracepoint *) b;
4923 if (!part_of_multiple && t->pass_count)
4925 annotate_field (10);
4926 ui_out_text (uiout, "\tpass count ");
4927 ui_out_field_int (uiout, "pass", t->pass_count);
4928 ui_out_text (uiout, " \n");
4932 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4934 if (is_watchpoint (b))
4936 struct watchpoint *w = (struct watchpoint *) b;
4938 ui_out_field_string (uiout, "original-location", w->exp_string);
4940 else if (b->addr_string)
4941 ui_out_field_string (uiout, "original-location", b->addr_string);
4946 print_one_breakpoint (struct breakpoint *b,
4947 struct bp_location **last_loc,
4950 struct cleanup *bkpt_chain;
4951 struct ui_out *uiout = current_uiout;
4953 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4955 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
4956 do_cleanups (bkpt_chain);
4958 /* If this breakpoint has custom print function,
4959 it's already printed. Otherwise, print individual
4960 locations, if any. */
4961 if (b->ops == NULL || b->ops->print_one == NULL)
4963 /* If breakpoint has a single location that is disabled, we
4964 print it as if it had several locations, since otherwise it's
4965 hard to represent "breakpoint enabled, location disabled"
4968 Note that while hardware watchpoints have several locations
4969 internally, that's not a property exposed to user. */
4971 && !is_hardware_watchpoint (b)
4972 && (b->loc->next || !b->loc->enabled))
4974 struct bp_location *loc;
4977 for (loc = b->loc; loc; loc = loc->next, ++n)
4979 struct cleanup *inner2 =
4980 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
4981 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
4982 do_cleanups (inner2);
4989 breakpoint_address_bits (struct breakpoint *b)
4991 int print_address_bits = 0;
4992 struct bp_location *loc;
4994 for (loc = b->loc; loc; loc = loc->next)
4998 /* Software watchpoints that aren't watching memory don't have
4999 an address to print. */
5000 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5003 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5004 if (addr_bit > print_address_bits)
5005 print_address_bits = addr_bit;
5008 return print_address_bits;
5011 struct captured_breakpoint_query_args
5017 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5019 struct captured_breakpoint_query_args *args = data;
5020 struct breakpoint *b;
5021 struct bp_location *dummy_loc = NULL;
5025 if (args->bnum == b->number)
5027 print_one_breakpoint (b, &dummy_loc, 0);
5035 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5036 char **error_message)
5038 struct captured_breakpoint_query_args args;
5041 /* For the moment we don't trust print_one_breakpoint() to not throw
5043 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5044 error_message, RETURN_MASK_ALL) < 0)
5050 /* Return true if this breakpoint was set by the user, false if it is
5051 internal or momentary. */
5054 user_breakpoint_p (struct breakpoint *b)
5056 return b->number > 0;
5059 /* Print information on user settable breakpoint (watchpoint, etc)
5060 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5061 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5062 FILTER is non-NULL, call it on each breakpoint and only include the
5063 ones for which it returns non-zero. Return the total number of
5064 breakpoints listed. */
5067 breakpoint_1 (char *args, int allflag,
5068 int (*filter) (const struct breakpoint *))
5070 struct breakpoint *b;
5071 struct bp_location *last_loc = NULL;
5072 int nr_printable_breakpoints;
5073 struct cleanup *bkpttbl_chain;
5074 struct value_print_options opts;
5075 int print_address_bits = 0;
5076 int print_type_col_width = 14;
5077 struct ui_out *uiout = current_uiout;
5079 get_user_print_options (&opts);
5081 /* Compute the number of rows in the table, as well as the size
5082 required for address fields. */
5083 nr_printable_breakpoints = 0;
5086 /* If we have a filter, only list the breakpoints it accepts. */
5087 if (filter && !filter (b))
5090 /* If we have an "args" string, it is a list of breakpoints to
5091 accept. Skip the others. */
5092 if (args != NULL && *args != '\0')
5094 if (allflag && parse_and_eval_long (args) != b->number)
5096 if (!allflag && !number_is_in_list (args, b->number))
5100 if (allflag || user_breakpoint_p (b))
5102 int addr_bit, type_len;
5104 addr_bit = breakpoint_address_bits (b);
5105 if (addr_bit > print_address_bits)
5106 print_address_bits = addr_bit;
5108 type_len = strlen (bptype_string (b->type));
5109 if (type_len > print_type_col_width)
5110 print_type_col_width = type_len;
5112 nr_printable_breakpoints++;
5116 if (opts.addressprint)
5118 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5119 nr_printable_breakpoints,
5123 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5124 nr_printable_breakpoints,
5127 if (nr_printable_breakpoints > 0)
5128 annotate_breakpoints_headers ();
5129 if (nr_printable_breakpoints > 0)
5131 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5132 if (nr_printable_breakpoints > 0)
5134 ui_out_table_header (uiout, print_type_col_width, ui_left,
5135 "type", "Type"); /* 2 */
5136 if (nr_printable_breakpoints > 0)
5138 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5139 if (nr_printable_breakpoints > 0)
5141 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5142 if (opts.addressprint)
5144 if (nr_printable_breakpoints > 0)
5146 if (print_address_bits <= 32)
5147 ui_out_table_header (uiout, 10, ui_left,
5148 "addr", "Address"); /* 5 */
5150 ui_out_table_header (uiout, 18, ui_left,
5151 "addr", "Address"); /* 5 */
5153 if (nr_printable_breakpoints > 0)
5155 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5156 ui_out_table_body (uiout);
5157 if (nr_printable_breakpoints > 0)
5158 annotate_breakpoints_table ();
5163 /* If we have a filter, only list the breakpoints it accepts. */
5164 if (filter && !filter (b))
5167 /* If we have an "args" string, it is a list of breakpoints to
5168 accept. Skip the others. */
5170 if (args != NULL && *args != '\0')
5172 if (allflag) /* maintenance info breakpoint */
5174 if (parse_and_eval_long (args) != b->number)
5177 else /* all others */
5179 if (!number_is_in_list (args, b->number))
5183 /* We only print out user settable breakpoints unless the
5185 if (allflag || user_breakpoint_p (b))
5186 print_one_breakpoint (b, &last_loc, allflag);
5189 do_cleanups (bkpttbl_chain);
5191 if (nr_printable_breakpoints == 0)
5193 /* If there's a filter, let the caller decide how to report
5197 if (args == NULL || *args == '\0')
5198 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5200 ui_out_message (uiout, 0,
5201 "No breakpoint or watchpoint matching '%s'.\n",
5207 if (last_loc && !server_command)
5208 set_next_address (last_loc->gdbarch, last_loc->address);
5211 /* FIXME? Should this be moved up so that it is only called when
5212 there have been breakpoints? */
5213 annotate_breakpoints_table_end ();
5215 return nr_printable_breakpoints;
5218 /* Display the value of default-collect in a way that is generally
5219 compatible with the breakpoint list. */
5222 default_collect_info (void)
5224 struct ui_out *uiout = current_uiout;
5226 /* If it has no value (which is frequently the case), say nothing; a
5227 message like "No default-collect." gets in user's face when it's
5229 if (!*default_collect)
5232 /* The following phrase lines up nicely with per-tracepoint collect
5234 ui_out_text (uiout, "default collect ");
5235 ui_out_field_string (uiout, "default-collect", default_collect);
5236 ui_out_text (uiout, " \n");
5240 breakpoints_info (char *args, int from_tty)
5242 breakpoint_1 (args, 0, NULL);
5244 default_collect_info ();
5248 watchpoints_info (char *args, int from_tty)
5250 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5251 struct ui_out *uiout = current_uiout;
5253 if (num_printed == 0)
5255 if (args == NULL || *args == '\0')
5256 ui_out_message (uiout, 0, "No watchpoints.\n");
5258 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5263 maintenance_info_breakpoints (char *args, int from_tty)
5265 breakpoint_1 (args, 1, NULL);
5267 default_collect_info ();
5271 breakpoint_has_pc (struct breakpoint *b,
5272 struct program_space *pspace,
5273 CORE_ADDR pc, struct obj_section *section)
5275 struct bp_location *bl = b->loc;
5277 for (; bl; bl = bl->next)
5279 if (bl->pspace == pspace
5280 && bl->address == pc
5281 && (!overlay_debugging || bl->section == section))
5287 /* Print a message describing any user-breakpoints set at PC. This
5288 concerns with logical breakpoints, so we match program spaces, not
5292 describe_other_breakpoints (struct gdbarch *gdbarch,
5293 struct program_space *pspace, CORE_ADDR pc,
5294 struct obj_section *section, int thread)
5297 struct breakpoint *b;
5300 others += (user_breakpoint_p (b)
5301 && breakpoint_has_pc (b, pspace, pc, section));
5305 printf_filtered (_("Note: breakpoint "));
5306 else /* if (others == ???) */
5307 printf_filtered (_("Note: breakpoints "));
5309 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
5312 printf_filtered ("%d", b->number);
5313 if (b->thread == -1 && thread != -1)
5314 printf_filtered (" (all threads)");
5315 else if (b->thread != -1)
5316 printf_filtered (" (thread %d)", b->thread);
5317 printf_filtered ("%s%s ",
5318 ((b->enable_state == bp_disabled
5319 || b->enable_state == bp_call_disabled
5320 || b->enable_state == bp_startup_disabled)
5322 : b->enable_state == bp_permanent
5326 : ((others == 1) ? " and" : ""));
5328 printf_filtered (_("also set at pc "));
5329 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5330 printf_filtered (".\n");
5335 /* Return true iff it is meaningful to use the address member of
5336 BPT. For some breakpoint types, the address member is irrelevant
5337 and it makes no sense to attempt to compare it to other addresses
5338 (or use it for any other purpose either).
5340 More specifically, each of the following breakpoint types will
5341 always have a zero valued address and we don't want to mark
5342 breakpoints of any of these types to be a duplicate of an actual
5343 breakpoint at address zero:
5351 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5353 enum bptype type = bpt->type;
5355 return (type != bp_watchpoint && type != bp_catchpoint);
5358 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5359 true if LOC1 and LOC2 represent the same watchpoint location. */
5362 watchpoint_locations_match (struct bp_location *loc1,
5363 struct bp_location *loc2)
5365 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
5366 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
5368 /* Both of them must exist. */
5369 gdb_assert (w1 != NULL);
5370 gdb_assert (w2 != NULL);
5372 /* If the target can evaluate the condition expression in hardware,
5373 then we we need to insert both watchpoints even if they are at
5374 the same place. Otherwise the watchpoint will only trigger when
5375 the condition of whichever watchpoint was inserted evaluates to
5376 true, not giving a chance for GDB to check the condition of the
5377 other watchpoint. */
5379 && target_can_accel_watchpoint_condition (loc1->address,
5381 loc1->watchpoint_type,
5384 && target_can_accel_watchpoint_condition (loc2->address,
5386 loc2->watchpoint_type,
5390 /* Note that this checks the owner's type, not the location's. In
5391 case the target does not support read watchpoints, but does
5392 support access watchpoints, we'll have bp_read_watchpoint
5393 watchpoints with hw_access locations. Those should be considered
5394 duplicates of hw_read locations. The hw_read locations will
5395 become hw_access locations later. */
5396 return (loc1->owner->type == loc2->owner->type
5397 && loc1->pspace->aspace == loc2->pspace->aspace
5398 && loc1->address == loc2->address
5399 && loc1->length == loc2->length);
5402 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5403 same breakpoint location. In most targets, this can only be true
5404 if ASPACE1 matches ASPACE2. On targets that have global
5405 breakpoints, the address space doesn't really matter. */
5408 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5409 struct address_space *aspace2, CORE_ADDR addr2)
5411 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5412 || aspace1 == aspace2)
5416 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5417 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5418 matches ASPACE2. On targets that have global breakpoints, the address
5419 space doesn't really matter. */
5422 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
5423 int len1, struct address_space *aspace2,
5426 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5427 || aspace1 == aspace2)
5428 && addr2 >= addr1 && addr2 < addr1 + len1);
5431 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5432 a ranged breakpoint. In most targets, a match happens only if ASPACE
5433 matches the breakpoint's address space. On targets that have global
5434 breakpoints, the address space doesn't really matter. */
5437 breakpoint_location_address_match (struct bp_location *bl,
5438 struct address_space *aspace,
5441 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
5444 && breakpoint_address_match_range (bl->pspace->aspace,
5445 bl->address, bl->length,
5449 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5450 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5451 represent the same location. */
5454 breakpoint_locations_match (struct bp_location *loc1,
5455 struct bp_location *loc2)
5457 int hw_point1, hw_point2;
5459 /* Both of them must not be in moribund_locations. */
5460 gdb_assert (loc1->owner != NULL);
5461 gdb_assert (loc2->owner != NULL);
5463 hw_point1 = is_hardware_watchpoint (loc1->owner);
5464 hw_point2 = is_hardware_watchpoint (loc2->owner);
5466 if (hw_point1 != hw_point2)
5469 return watchpoint_locations_match (loc1, loc2);
5471 /* We compare bp_location.length in order to cover ranged breakpoints. */
5472 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5473 loc2->pspace->aspace, loc2->address)
5474 && loc1->length == loc2->length);
5478 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5479 int bnum, int have_bnum)
5481 /* The longest string possibly returned by hex_string_custom
5482 is 50 chars. These must be at least that big for safety. */
5486 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5487 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5489 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5490 bnum, astr1, astr2);
5492 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5495 /* Adjust a breakpoint's address to account for architectural
5496 constraints on breakpoint placement. Return the adjusted address.
5497 Note: Very few targets require this kind of adjustment. For most
5498 targets, this function is simply the identity function. */
5501 adjust_breakpoint_address (struct gdbarch *gdbarch,
5502 CORE_ADDR bpaddr, enum bptype bptype)
5504 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5506 /* Very few targets need any kind of breakpoint adjustment. */
5509 else if (bptype == bp_watchpoint
5510 || bptype == bp_hardware_watchpoint
5511 || bptype == bp_read_watchpoint
5512 || bptype == bp_access_watchpoint
5513 || bptype == bp_catchpoint)
5515 /* Watchpoints and the various bp_catch_* eventpoints should not
5516 have their addresses modified. */
5521 CORE_ADDR adjusted_bpaddr;
5523 /* Some targets have architectural constraints on the placement
5524 of breakpoint instructions. Obtain the adjusted address. */
5525 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5527 /* An adjusted breakpoint address can significantly alter
5528 a user's expectations. Print a warning if an adjustment
5530 if (adjusted_bpaddr != bpaddr)
5531 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5533 return adjusted_bpaddr;
5538 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
5539 struct breakpoint *owner)
5541 memset (loc, 0, sizeof (*loc));
5543 gdb_assert (ops != NULL);
5548 loc->shlib_disabled = 0;
5551 switch (owner->type)
5557 case bp_longjmp_resume:
5559 case bp_exception_resume:
5560 case bp_step_resume:
5561 case bp_hp_step_resume:
5562 case bp_watchpoint_scope:
5564 case bp_std_terminate:
5565 case bp_shlib_event:
5566 case bp_thread_event:
5567 case bp_overlay_event:
5569 case bp_longjmp_master:
5570 case bp_std_terminate_master:
5571 case bp_exception_master:
5572 case bp_gnu_ifunc_resolver:
5573 case bp_gnu_ifunc_resolver_return:
5574 loc->loc_type = bp_loc_software_breakpoint;
5576 case bp_hardware_breakpoint:
5577 loc->loc_type = bp_loc_hardware_breakpoint;
5579 case bp_hardware_watchpoint:
5580 case bp_read_watchpoint:
5581 case bp_access_watchpoint:
5582 loc->loc_type = bp_loc_hardware_watchpoint;
5587 case bp_fast_tracepoint:
5588 case bp_static_tracepoint:
5589 loc->loc_type = bp_loc_other;
5592 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5598 /* Allocate a struct bp_location. */
5600 static struct bp_location *
5601 allocate_bp_location (struct breakpoint *bpt)
5603 return bpt->ops->allocate_location (bpt);
5607 free_bp_location (struct bp_location *loc)
5609 loc->ops->dtor (loc);
5613 /* Increment reference count. */
5616 incref_bp_location (struct bp_location *bl)
5621 /* Decrement reference count. If the reference count reaches 0,
5622 destroy the bp_location. Sets *BLP to NULL. */
5625 decref_bp_location (struct bp_location **blp)
5627 gdb_assert ((*blp)->refc > 0);
5629 if (--(*blp)->refc == 0)
5630 free_bp_location (*blp);
5634 /* Add breakpoint B at the end of the global breakpoint chain. */
5637 add_to_breakpoint_chain (struct breakpoint *b)
5639 struct breakpoint *b1;
5641 /* Add this breakpoint to the end of the chain so that a list of
5642 breakpoints will come out in order of increasing numbers. */
5644 b1 = breakpoint_chain;
5646 breakpoint_chain = b;
5655 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5658 init_raw_breakpoint_without_location (struct breakpoint *b,
5659 struct gdbarch *gdbarch,
5661 const struct breakpoint_ops *ops)
5663 memset (b, 0, sizeof (*b));
5665 gdb_assert (ops != NULL);
5669 b->gdbarch = gdbarch;
5670 b->language = current_language->la_language;
5671 b->input_radix = input_radix;
5673 b->enable_state = bp_enabled;
5676 b->ignore_count = 0;
5678 b->frame_id = null_frame_id;
5679 b->condition_not_parsed = 0;
5680 b->py_bp_object = NULL;
5681 b->related_breakpoint = b;
5684 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5685 that has type BPTYPE and has no locations as yet. */
5687 static struct breakpoint *
5688 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5690 const struct breakpoint_ops *ops)
5692 struct breakpoint *b = XNEW (struct breakpoint);
5694 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5695 add_to_breakpoint_chain (b);
5699 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5700 resolutions should be made as the user specified the location explicitly
5704 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
5706 gdb_assert (loc->owner != NULL);
5708 if (loc->owner->type == bp_breakpoint
5709 || loc->owner->type == bp_hardware_breakpoint
5710 || is_tracepoint (loc->owner))
5714 find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name,
5715 NULL, NULL, &is_gnu_ifunc);
5717 if (is_gnu_ifunc && !explicit_loc)
5719 struct breakpoint *b = loc->owner;
5721 gdb_assert (loc->pspace == current_program_space);
5722 if (gnu_ifunc_resolve_name (loc->function_name,
5723 &loc->requested_address))
5725 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5726 loc->address = adjust_breakpoint_address (loc->gdbarch,
5727 loc->requested_address,
5730 else if (b->type == bp_breakpoint && b->loc == loc
5731 && loc->next == NULL && b->related_breakpoint == b)
5733 /* Create only the whole new breakpoint of this type but do not
5734 mess more complicated breakpoints with multiple locations. */
5735 b->type = bp_gnu_ifunc_resolver;
5739 if (loc->function_name)
5740 loc->function_name = xstrdup (loc->function_name);
5744 /* Attempt to determine architecture of location identified by SAL. */
5746 get_sal_arch (struct symtab_and_line sal)
5749 return get_objfile_arch (sal.section->objfile);
5751 return get_objfile_arch (sal.symtab->objfile);
5756 /* Low level routine for partially initializing a breakpoint of type
5757 BPTYPE. The newly created breakpoint's address, section, source
5758 file name, and line number are provided by SAL.
5760 It is expected that the caller will complete the initialization of
5761 the newly created breakpoint struct as well as output any status
5762 information regarding the creation of a new breakpoint. */
5765 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
5766 struct symtab_and_line sal, enum bptype bptype,
5767 const struct breakpoint_ops *ops)
5769 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5771 add_location_to_breakpoint (b, &sal);
5773 if (bptype != bp_catchpoint)
5774 gdb_assert (sal.pspace != NULL);
5776 /* Store the program space that was used to set the breakpoint, for
5777 breakpoint resetting. */
5778 b->pspace = sal.pspace;
5780 if (sal.symtab == NULL)
5781 b->source_file = NULL;
5783 b->source_file = xstrdup (sal.symtab->filename);
5784 b->line_number = sal.line;
5786 breakpoints_changed ();
5789 /* set_raw_breakpoint is a low level routine for allocating and
5790 partially initializing a breakpoint of type BPTYPE. The newly
5791 created breakpoint's address, section, source file name, and line
5792 number are provided by SAL. The newly created and partially
5793 initialized breakpoint is added to the breakpoint chain and
5794 is also returned as the value of this function.
5796 It is expected that the caller will complete the initialization of
5797 the newly created breakpoint struct as well as output any status
5798 information regarding the creation of a new breakpoint. In
5799 particular, set_raw_breakpoint does NOT set the breakpoint
5800 number! Care should be taken to not allow an error to occur
5801 prior to completing the initialization of the breakpoint. If this
5802 should happen, a bogus breakpoint will be left on the chain. */
5805 set_raw_breakpoint (struct gdbarch *gdbarch,
5806 struct symtab_and_line sal, enum bptype bptype,
5807 const struct breakpoint_ops *ops)
5809 struct breakpoint *b = XNEW (struct breakpoint);
5811 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
5812 add_to_breakpoint_chain (b);
5817 /* Note that the breakpoint object B describes a permanent breakpoint
5818 instruction, hard-wired into the inferior's code. */
5820 make_breakpoint_permanent (struct breakpoint *b)
5822 struct bp_location *bl;
5824 b->enable_state = bp_permanent;
5826 /* By definition, permanent breakpoints are already present in the
5827 code. Mark all locations as inserted. For now,
5828 make_breakpoint_permanent is called in just one place, so it's
5829 hard to say if it's reasonable to have permanent breakpoint with
5830 multiple locations or not, but it's easy to implement. */
5831 for (bl = b->loc; bl; bl = bl->next)
5835 /* Call this routine when stepping and nexting to enable a breakpoint
5836 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5837 initiated the operation. */
5840 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
5842 struct breakpoint *b, *b_tmp;
5843 int thread = tp->num;
5845 /* To avoid having to rescan all objfile symbols at every step,
5846 we maintain a list of continually-inserted but always disabled
5847 longjmp "master" breakpoints. Here, we simply create momentary
5848 clones of those and enable them for the requested thread. */
5849 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5850 if (b->pspace == current_program_space
5851 && (b->type == bp_longjmp_master
5852 || b->type == bp_exception_master))
5854 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
5855 struct breakpoint *clone;
5857 clone = momentary_breakpoint_from_master (b, type,
5858 &momentary_breakpoint_ops);
5859 clone->thread = thread;
5862 tp->initiating_frame = frame;
5865 /* Delete all longjmp breakpoints from THREAD. */
5867 delete_longjmp_breakpoint (int thread)
5869 struct breakpoint *b, *b_tmp;
5871 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5872 if (b->type == bp_longjmp || b->type == bp_exception)
5874 if (b->thread == thread)
5875 delete_breakpoint (b);
5880 enable_overlay_breakpoints (void)
5882 struct breakpoint *b;
5885 if (b->type == bp_overlay_event)
5887 b->enable_state = bp_enabled;
5888 update_global_location_list (1);
5889 overlay_events_enabled = 1;
5894 disable_overlay_breakpoints (void)
5896 struct breakpoint *b;
5899 if (b->type == bp_overlay_event)
5901 b->enable_state = bp_disabled;
5902 update_global_location_list (0);
5903 overlay_events_enabled = 0;
5907 /* Set an active std::terminate breakpoint for each std::terminate
5908 master breakpoint. */
5910 set_std_terminate_breakpoint (void)
5912 struct breakpoint *b, *b_tmp;
5914 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5915 if (b->pspace == current_program_space
5916 && b->type == bp_std_terminate_master)
5918 momentary_breakpoint_from_master (b, bp_std_terminate,
5919 &momentary_breakpoint_ops);
5923 /* Delete all the std::terminate breakpoints. */
5925 delete_std_terminate_breakpoint (void)
5927 struct breakpoint *b, *b_tmp;
5929 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5930 if (b->type == bp_std_terminate)
5931 delete_breakpoint (b);
5935 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5937 struct breakpoint *b;
5939 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
5940 &internal_breakpoint_ops);
5942 b->enable_state = bp_enabled;
5943 /* addr_string has to be used or breakpoint_re_set will delete me. */
5945 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5947 update_global_location_list_nothrow (1);
5953 remove_thread_event_breakpoints (void)
5955 struct breakpoint *b, *b_tmp;
5957 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5958 if (b->type == bp_thread_event
5959 && b->loc->pspace == current_program_space)
5960 delete_breakpoint (b);
5963 struct lang_and_radix
5969 /* Create a breakpoint for JIT code registration and unregistration. */
5972 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5974 struct breakpoint *b;
5976 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
5977 &internal_breakpoint_ops);
5978 update_global_location_list_nothrow (1);
5982 /* Remove JIT code registration and unregistration breakpoint(s). */
5985 remove_jit_event_breakpoints (void)
5987 struct breakpoint *b, *b_tmp;
5989 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5990 if (b->type == bp_jit_event
5991 && b->loc->pspace == current_program_space)
5992 delete_breakpoint (b);
5996 remove_solib_event_breakpoints (void)
5998 struct breakpoint *b, *b_tmp;
6000 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6001 if (b->type == bp_shlib_event
6002 && b->loc->pspace == current_program_space)
6003 delete_breakpoint (b);
6007 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6009 struct breakpoint *b;
6011 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6012 &internal_breakpoint_ops);
6013 update_global_location_list_nothrow (1);
6017 /* Disable any breakpoints that are on code in shared libraries. Only
6018 apply to enabled breakpoints, disabled ones can just stay disabled. */
6021 disable_breakpoints_in_shlibs (void)
6023 struct bp_location *loc, **locp_tmp;
6025 ALL_BP_LOCATIONS (loc, locp_tmp)
6027 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6028 struct breakpoint *b = loc->owner;
6030 /* We apply the check to all breakpoints, including disabled for
6031 those with loc->duplicate set. This is so that when breakpoint
6032 becomes enabled, or the duplicate is removed, gdb will try to
6033 insert all breakpoints. If we don't set shlib_disabled here,
6034 we'll try to insert those breakpoints and fail. */
6035 if (((b->type == bp_breakpoint)
6036 || (b->type == bp_jit_event)
6037 || (b->type == bp_hardware_breakpoint)
6038 || (is_tracepoint (b)))
6039 && loc->pspace == current_program_space
6040 && !loc->shlib_disabled
6042 && PC_SOLIB (loc->address)
6044 && solib_name_from_address (loc->pspace, loc->address)
6048 loc->shlib_disabled = 1;
6053 /* Disable any breakpoints that are in an unloaded shared library.
6054 Only apply to enabled breakpoints, disabled ones can just stay
6058 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6060 struct bp_location *loc, **locp_tmp;
6061 int disabled_shlib_breaks = 0;
6063 /* SunOS a.out shared libraries are always mapped, so do not
6064 disable breakpoints; they will only be reported as unloaded
6065 through clear_solib when GDB discards its shared library
6066 list. See clear_solib for more information. */
6067 if (exec_bfd != NULL
6068 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6071 ALL_BP_LOCATIONS (loc, locp_tmp)
6073 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6074 struct breakpoint *b = loc->owner;
6076 if ((loc->loc_type == bp_loc_hardware_breakpoint
6077 || loc->loc_type == bp_loc_software_breakpoint)
6078 && solib->pspace == loc->pspace
6079 && !loc->shlib_disabled
6080 && (b->type == bp_breakpoint
6081 || b->type == bp_jit_event
6082 || b->type == bp_hardware_breakpoint)
6083 && solib_contains_address_p (solib, loc->address))
6085 loc->shlib_disabled = 1;
6086 /* At this point, we cannot rely on remove_breakpoint
6087 succeeding so we must mark the breakpoint as not inserted
6088 to prevent future errors occurring in remove_breakpoints. */
6091 /* This may cause duplicate notifications for the same breakpoint. */
6092 observer_notify_breakpoint_modified (b);
6094 if (!disabled_shlib_breaks)
6096 target_terminal_ours_for_output ();
6097 warning (_("Temporarily disabling breakpoints "
6098 "for unloaded shared library \"%s\""),
6101 disabled_shlib_breaks = 1;
6106 /* FORK & VFORK catchpoints. */
6108 /* An instance of this type is used to represent a fork or vfork
6109 catchpoint. It includes a "struct breakpoint" as a kind of base
6110 class; users downcast to "struct breakpoint *" when needed. A
6111 breakpoint is really of this type iff its ops pointer points to
6112 CATCH_FORK_BREAKPOINT_OPS. */
6114 struct fork_catchpoint
6116 /* The base class. */
6117 struct breakpoint base;
6119 /* Process id of a child process whose forking triggered this
6120 catchpoint. This field is only valid immediately after this
6121 catchpoint has triggered. */
6122 ptid_t forked_inferior_pid;
6125 /* Implement the "insert" breakpoint_ops method for fork
6129 insert_catch_fork (struct bp_location *bl)
6131 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6134 /* Implement the "remove" breakpoint_ops method for fork
6138 remove_catch_fork (struct bp_location *bl)
6140 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6143 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6147 breakpoint_hit_catch_fork (const struct bp_location *bl,
6148 struct address_space *aspace, CORE_ADDR bp_addr)
6150 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6152 return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid);
6155 /* Implement the "print_it" breakpoint_ops method for fork
6158 static enum print_stop_action
6159 print_it_catch_fork (bpstat bs)
6161 struct breakpoint *b = bs->breakpoint_at;
6162 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6164 annotate_catchpoint (b->number);
6165 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6166 b->number, ptid_get_pid (c->forked_inferior_pid));
6167 return PRINT_SRC_AND_LOC;
6170 /* Implement the "print_one" breakpoint_ops method for fork
6174 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6176 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6177 struct value_print_options opts;
6178 struct ui_out *uiout = current_uiout;
6180 get_user_print_options (&opts);
6182 /* Field 4, the address, is omitted (which makes the columns not
6183 line up too nicely with the headers, but the effect is relatively
6185 if (opts.addressprint)
6186 ui_out_field_skip (uiout, "addr");
6188 ui_out_text (uiout, "fork");
6189 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6191 ui_out_text (uiout, ", process ");
6192 ui_out_field_int (uiout, "what",
6193 ptid_get_pid (c->forked_inferior_pid));
6194 ui_out_spaces (uiout, 1);
6198 /* Implement the "print_mention" breakpoint_ops method for fork
6202 print_mention_catch_fork (struct breakpoint *b)
6204 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6207 /* Implement the "print_recreate" breakpoint_ops method for fork
6211 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6213 fprintf_unfiltered (fp, "catch fork");
6214 print_recreate_thread (b, fp);
6217 /* The breakpoint_ops structure to be used in fork catchpoints. */
6219 static struct breakpoint_ops catch_fork_breakpoint_ops;
6221 /* Implement the "insert" breakpoint_ops method for vfork
6225 insert_catch_vfork (struct bp_location *bl)
6227 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6230 /* Implement the "remove" breakpoint_ops method for vfork
6234 remove_catch_vfork (struct bp_location *bl)
6236 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6239 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6243 breakpoint_hit_catch_vfork (const struct bp_location *bl,
6244 struct address_space *aspace, CORE_ADDR bp_addr)
6246 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6248 return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid);
6251 /* Implement the "print_it" breakpoint_ops method for vfork
6254 static enum print_stop_action
6255 print_it_catch_vfork (bpstat bs)
6257 struct breakpoint *b = bs->breakpoint_at;
6258 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6260 annotate_catchpoint (b->number);
6261 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6262 b->number, ptid_get_pid (c->forked_inferior_pid));
6263 return PRINT_SRC_AND_LOC;
6266 /* Implement the "print_one" breakpoint_ops method for vfork
6270 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6272 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6273 struct value_print_options opts;
6274 struct ui_out *uiout = current_uiout;
6276 get_user_print_options (&opts);
6277 /* Field 4, the address, is omitted (which makes the columns not
6278 line up too nicely with the headers, but the effect is relatively
6280 if (opts.addressprint)
6281 ui_out_field_skip (uiout, "addr");
6283 ui_out_text (uiout, "vfork");
6284 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6286 ui_out_text (uiout, ", process ");
6287 ui_out_field_int (uiout, "what",
6288 ptid_get_pid (c->forked_inferior_pid));
6289 ui_out_spaces (uiout, 1);
6293 /* Implement the "print_mention" breakpoint_ops method for vfork
6297 print_mention_catch_vfork (struct breakpoint *b)
6299 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6302 /* Implement the "print_recreate" breakpoint_ops method for vfork
6306 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6308 fprintf_unfiltered (fp, "catch vfork");
6309 print_recreate_thread (b, fp);
6312 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6314 static struct breakpoint_ops catch_vfork_breakpoint_ops;
6316 /* An instance of this type is used to represent a syscall catchpoint.
6317 It includes a "struct breakpoint" as a kind of base class; users
6318 downcast to "struct breakpoint *" when needed. A breakpoint is
6319 really of this type iff its ops pointer points to
6320 CATCH_SYSCALL_BREAKPOINT_OPS. */
6322 struct syscall_catchpoint
6324 /* The base class. */
6325 struct breakpoint base;
6327 /* Syscall numbers used for the 'catch syscall' feature. If no
6328 syscall has been specified for filtering, its value is NULL.
6329 Otherwise, it holds a list of all syscalls to be caught. The
6330 list elements are allocated with xmalloc. */
6331 VEC(int) *syscalls_to_be_caught;
6334 /* Implement the "dtor" breakpoint_ops method for syscall
6338 dtor_catch_syscall (struct breakpoint *b)
6340 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6342 VEC_free (int, c->syscalls_to_be_caught);
6344 base_breakpoint_ops.dtor (b);
6347 /* Implement the "insert" breakpoint_ops method for syscall
6351 insert_catch_syscall (struct bp_location *bl)
6353 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6354 struct inferior *inf = current_inferior ();
6356 ++inf->total_syscalls_count;
6357 if (!c->syscalls_to_be_caught)
6358 ++inf->any_syscall_count;
6364 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6369 if (iter >= VEC_length (int, inf->syscalls_counts))
6371 int old_size = VEC_length (int, inf->syscalls_counts);
6372 uintptr_t vec_addr_offset
6373 = old_size * ((uintptr_t) sizeof (int));
6375 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6376 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6378 memset ((void *) vec_addr, 0,
6379 (iter + 1 - old_size) * sizeof (int));
6381 elem = VEC_index (int, inf->syscalls_counts, iter);
6382 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6386 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6387 inf->total_syscalls_count != 0,
6388 inf->any_syscall_count,
6389 VEC_length (int, inf->syscalls_counts),
6390 VEC_address (int, inf->syscalls_counts));
6393 /* Implement the "remove" breakpoint_ops method for syscall
6397 remove_catch_syscall (struct bp_location *bl)
6399 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6400 struct inferior *inf = current_inferior ();
6402 --inf->total_syscalls_count;
6403 if (!c->syscalls_to_be_caught)
6404 --inf->any_syscall_count;
6410 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6414 if (iter >= VEC_length (int, inf->syscalls_counts))
6415 /* Shouldn't happen. */
6417 elem = VEC_index (int, inf->syscalls_counts, iter);
6418 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6422 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6423 inf->total_syscalls_count != 0,
6424 inf->any_syscall_count,
6425 VEC_length (int, inf->syscalls_counts),
6427 inf->syscalls_counts));
6430 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6434 breakpoint_hit_catch_syscall (const struct bp_location *bl,
6435 struct address_space *aspace, CORE_ADDR bp_addr)
6437 /* We must check if we are catching specific syscalls in this
6438 breakpoint. If we are, then we must guarantee that the called
6439 syscall is the same syscall we are catching. */
6440 int syscall_number = 0;
6441 const struct syscall_catchpoint *c
6442 = (const struct syscall_catchpoint *) bl->owner;
6444 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6447 /* Now, checking if the syscall is the same. */
6448 if (c->syscalls_to_be_caught)
6453 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6455 if (syscall_number == iter)
6465 /* Implement the "print_it" breakpoint_ops method for syscall
6468 static enum print_stop_action
6469 print_it_catch_syscall (bpstat bs)
6471 struct breakpoint *b = bs->breakpoint_at;
6472 /* These are needed because we want to know in which state a
6473 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6474 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6475 must print "called syscall" or "returned from syscall". */
6477 struct target_waitstatus last;
6479 struct cleanup *old_chain;
6482 get_last_target_status (&ptid, &last);
6484 get_syscall_by_number (last.value.syscall_number, &s);
6486 annotate_catchpoint (b->number);
6489 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6491 syscall_id = xstrprintf ("'%s'", s.name);
6493 old_chain = make_cleanup (xfree, syscall_id);
6495 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6496 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6497 b->number, syscall_id);
6498 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6499 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6500 b->number, syscall_id);
6502 do_cleanups (old_chain);
6504 return PRINT_SRC_AND_LOC;
6507 /* Implement the "print_one" breakpoint_ops method for syscall
6511 print_one_catch_syscall (struct breakpoint *b,
6512 struct bp_location **last_loc)
6514 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6515 struct value_print_options opts;
6516 struct ui_out *uiout = current_uiout;
6518 get_user_print_options (&opts);
6519 /* Field 4, the address, is omitted (which makes the columns not
6520 line up too nicely with the headers, but the effect is relatively
6522 if (opts.addressprint)
6523 ui_out_field_skip (uiout, "addr");
6526 if (c->syscalls_to_be_caught
6527 && VEC_length (int, c->syscalls_to_be_caught) > 1)
6528 ui_out_text (uiout, "syscalls \"");
6530 ui_out_text (uiout, "syscall \"");
6532 if (c->syscalls_to_be_caught)
6535 char *text = xstrprintf ("%s", "");
6538 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6543 get_syscall_by_number (iter, &s);
6546 text = xstrprintf ("%s%s, ", text, s.name);
6548 text = xstrprintf ("%s%d, ", text, iter);
6550 /* We have to xfree the last 'text' (now stored at 'x')
6551 because xstrprintf dynamically allocates new space for it
6555 /* Remove the last comma. */
6556 text[strlen (text) - 2] = '\0';
6557 ui_out_field_string (uiout, "what", text);
6560 ui_out_field_string (uiout, "what", "<any syscall>");
6561 ui_out_text (uiout, "\" ");
6564 /* Implement the "print_mention" breakpoint_ops method for syscall
6568 print_mention_catch_syscall (struct breakpoint *b)
6570 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6572 if (c->syscalls_to_be_caught)
6576 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
6577 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6579 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6582 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6586 get_syscall_by_number (iter, &s);
6589 printf_filtered (" '%s' [%d]", s.name, s.number);
6591 printf_filtered (" %d", s.number);
6593 printf_filtered (")");
6596 printf_filtered (_("Catchpoint %d (any syscall)"),
6600 /* Implement the "print_recreate" breakpoint_ops method for syscall
6604 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6606 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6608 fprintf_unfiltered (fp, "catch syscall");
6610 if (c->syscalls_to_be_caught)
6615 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6620 get_syscall_by_number (iter, &s);
6622 fprintf_unfiltered (fp, " %s", s.name);
6624 fprintf_unfiltered (fp, " %d", s.number);
6627 print_recreate_thread (b, fp);
6630 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6632 static struct breakpoint_ops catch_syscall_breakpoint_ops;
6634 /* Returns non-zero if 'b' is a syscall catchpoint. */
6637 syscall_catchpoint_p (struct breakpoint *b)
6639 return (b->ops == &catch_syscall_breakpoint_ops);
6642 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6643 is non-zero, then make the breakpoint temporary. If COND_STRING is
6644 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6645 the breakpoint_ops structure associated to the catchpoint. */
6648 init_catchpoint (struct breakpoint *b,
6649 struct gdbarch *gdbarch, int tempflag,
6651 const struct breakpoint_ops *ops)
6653 struct symtab_and_line sal;
6656 sal.pspace = current_program_space;
6658 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
6660 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6661 b->disposition = tempflag ? disp_del : disp_donttouch;
6665 install_breakpoint (int internal, struct breakpoint *b)
6667 add_to_breakpoint_chain (b);
6668 set_breakpoint_number (internal, b);
6671 observer_notify_breakpoint_created (b);
6672 update_global_location_list (1);
6676 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6677 int tempflag, char *cond_string,
6678 const struct breakpoint_ops *ops)
6680 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
6682 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
6684 c->forked_inferior_pid = null_ptid;
6686 install_breakpoint (0, &c->base);
6689 /* Exec catchpoints. */
6691 /* An instance of this type is used to represent an exec catchpoint.
6692 It includes a "struct breakpoint" as a kind of base class; users
6693 downcast to "struct breakpoint *" when needed. A breakpoint is
6694 really of this type iff its ops pointer points to
6695 CATCH_EXEC_BREAKPOINT_OPS. */
6697 struct exec_catchpoint
6699 /* The base class. */
6700 struct breakpoint base;
6702 /* Filename of a program whose exec triggered this catchpoint.
6703 This field is only valid immediately after this catchpoint has
6705 char *exec_pathname;
6708 /* Implement the "dtor" breakpoint_ops method for exec
6712 dtor_catch_exec (struct breakpoint *b)
6714 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6716 xfree (c->exec_pathname);
6718 base_breakpoint_ops.dtor (b);
6722 insert_catch_exec (struct bp_location *bl)
6724 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6728 remove_catch_exec (struct bp_location *bl)
6730 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6734 breakpoint_hit_catch_exec (const struct bp_location *bl,
6735 struct address_space *aspace, CORE_ADDR bp_addr)
6737 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
6739 return inferior_has_execd (inferior_ptid, &c->exec_pathname);
6742 static enum print_stop_action
6743 print_it_catch_exec (bpstat bs)
6745 struct breakpoint *b = bs->breakpoint_at;
6746 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6748 annotate_catchpoint (b->number);
6749 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6751 return PRINT_SRC_AND_LOC;
6755 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6757 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6758 struct value_print_options opts;
6759 struct ui_out *uiout = current_uiout;
6761 get_user_print_options (&opts);
6763 /* Field 4, the address, is omitted (which makes the columns
6764 not line up too nicely with the headers, but the effect
6765 is relatively readable). */
6766 if (opts.addressprint)
6767 ui_out_field_skip (uiout, "addr");
6769 ui_out_text (uiout, "exec");
6770 if (c->exec_pathname != NULL)
6772 ui_out_text (uiout, ", program \"");
6773 ui_out_field_string (uiout, "what", c->exec_pathname);
6774 ui_out_text (uiout, "\" ");
6779 print_mention_catch_exec (struct breakpoint *b)
6781 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6784 /* Implement the "print_recreate" breakpoint_ops method for exec
6788 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6790 fprintf_unfiltered (fp, "catch exec");
6791 print_recreate_thread (b, fp);
6794 static struct breakpoint_ops catch_exec_breakpoint_ops;
6797 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6798 const struct breakpoint_ops *ops)
6800 struct syscall_catchpoint *c;
6801 struct gdbarch *gdbarch = get_current_arch ();
6803 c = XNEW (struct syscall_catchpoint);
6804 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
6805 c->syscalls_to_be_caught = filter;
6807 install_breakpoint (0, &c->base);
6811 hw_breakpoint_used_count (void)
6814 struct breakpoint *b;
6815 struct bp_location *bl;
6819 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6820 for (bl = b->loc; bl; bl = bl->next)
6822 /* Special types of hardware breakpoints may use more than
6824 i += b->ops->resources_needed (bl);
6831 /* Returns the resources B would use if it were a hardware
6835 hw_watchpoint_use_count (struct breakpoint *b)
6838 struct bp_location *bl;
6840 if (!breakpoint_enabled (b))
6843 for (bl = b->loc; bl; bl = bl->next)
6845 /* Special types of hardware watchpoints may use more than
6847 i += b->ops->resources_needed (bl);
6853 /* Returns the sum the used resources of all hardware watchpoints of
6854 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6855 the sum of the used resources of all hardware watchpoints of other
6856 types _not_ TYPE. */
6859 hw_watchpoint_used_count_others (struct breakpoint *except,
6860 enum bptype type, int *other_type_used)
6863 struct breakpoint *b;
6865 *other_type_used = 0;
6870 if (!breakpoint_enabled (b))
6873 if (b->type == type)
6874 i += hw_watchpoint_use_count (b);
6875 else if (is_hardware_watchpoint (b))
6876 *other_type_used = 1;
6883 disable_watchpoints_before_interactive_call_start (void)
6885 struct breakpoint *b;
6889 if (is_watchpoint (b) && breakpoint_enabled (b))
6891 b->enable_state = bp_call_disabled;
6892 update_global_location_list (0);
6898 enable_watchpoints_after_interactive_call_stop (void)
6900 struct breakpoint *b;
6904 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6906 b->enable_state = bp_enabled;
6907 update_global_location_list (1);
6913 disable_breakpoints_before_startup (void)
6915 struct breakpoint *b;
6920 if (b->pspace != current_program_space)
6923 if ((b->type == bp_breakpoint
6924 || b->type == bp_hardware_breakpoint)
6925 && breakpoint_enabled (b))
6927 b->enable_state = bp_startup_disabled;
6933 update_global_location_list (0);
6935 current_program_space->executing_startup = 1;
6939 enable_breakpoints_after_startup (void)
6941 struct breakpoint *b;
6944 current_program_space->executing_startup = 0;
6948 if (b->pspace != current_program_space)
6951 if ((b->type == bp_breakpoint
6952 || b->type == bp_hardware_breakpoint)
6953 && b->enable_state == bp_startup_disabled)
6955 b->enable_state = bp_enabled;
6961 breakpoint_re_set ();
6965 /* Set a breakpoint that will evaporate an end of command
6966 at address specified by SAL.
6967 Restrict it to frame FRAME if FRAME is nonzero. */
6970 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6971 struct frame_id frame_id, enum bptype type)
6973 struct breakpoint *b;
6975 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6977 gdb_assert (!frame_id_inlined_p (frame_id));
6979 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
6980 b->enable_state = bp_enabled;
6981 b->disposition = disp_donttouch;
6982 b->frame_id = frame_id;
6984 /* If we're debugging a multi-threaded program, then we want
6985 momentary breakpoints to be active in only a single thread of
6987 if (in_thread_list (inferior_ptid))
6988 b->thread = pid_to_thread_id (inferior_ptid);
6990 update_global_location_list_nothrow (1);
6995 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6996 The new breakpoint will have type TYPE, and use OPS as it
6999 static struct breakpoint *
7000 momentary_breakpoint_from_master (struct breakpoint *orig,
7002 const struct breakpoint_ops *ops)
7004 struct breakpoint *copy;
7006 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
7007 copy->loc = allocate_bp_location (copy);
7008 set_breakpoint_location_function (copy->loc, 1);
7010 copy->loc->gdbarch = orig->loc->gdbarch;
7011 copy->loc->requested_address = orig->loc->requested_address;
7012 copy->loc->address = orig->loc->address;
7013 copy->loc->section = orig->loc->section;
7014 copy->loc->pspace = orig->loc->pspace;
7016 if (orig->source_file == NULL)
7017 copy->source_file = NULL;
7019 copy->source_file = xstrdup (orig->source_file);
7021 copy->line_number = orig->line_number;
7022 copy->frame_id = orig->frame_id;
7023 copy->thread = orig->thread;
7024 copy->pspace = orig->pspace;
7026 copy->enable_state = bp_enabled;
7027 copy->disposition = disp_donttouch;
7028 copy->number = internal_breakpoint_number--;
7030 update_global_location_list_nothrow (0);
7034 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7038 clone_momentary_breakpoint (struct breakpoint *orig)
7040 /* If there's nothing to clone, then return nothing. */
7044 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
7048 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
7051 struct symtab_and_line sal;
7053 sal = find_pc_line (pc, 0);
7055 sal.section = find_pc_overlay (pc);
7056 sal.explicit_pc = 1;
7058 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
7062 /* Tell the user we have just set a breakpoint B. */
7065 mention (struct breakpoint *b)
7067 b->ops->print_mention (b);
7068 if (ui_out_is_mi_like_p (current_uiout))
7070 printf_filtered ("\n");
7074 static struct bp_location *
7075 add_location_to_breakpoint (struct breakpoint *b,
7076 const struct symtab_and_line *sal)
7078 struct bp_location *loc, **tmp;
7079 CORE_ADDR adjusted_address;
7080 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
7082 if (loc_gdbarch == NULL)
7083 loc_gdbarch = b->gdbarch;
7085 /* Adjust the breakpoint's address prior to allocating a location.
7086 Once we call allocate_bp_location(), that mostly uninitialized
7087 location will be placed on the location chain. Adjustment of the
7088 breakpoint may cause target_read_memory() to be called and we do
7089 not want its scan of the location chain to find a breakpoint and
7090 location that's only been partially initialized. */
7091 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
7094 loc = allocate_bp_location (b);
7095 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7099 loc->requested_address = sal->pc;
7100 loc->address = adjusted_address;
7101 loc->pspace = sal->pspace;
7102 gdb_assert (loc->pspace != NULL);
7103 loc->section = sal->section;
7104 loc->gdbarch = loc_gdbarch;
7105 set_breakpoint_location_function (loc,
7106 sal->explicit_pc || sal->explicit_line);
7111 /* Return 1 if LOC is pointing to a permanent breakpoint,
7112 return 0 otherwise. */
7115 bp_loc_is_permanent (struct bp_location *loc)
7119 const gdb_byte *brk;
7120 gdb_byte *target_mem;
7121 struct cleanup *cleanup;
7124 gdb_assert (loc != NULL);
7126 addr = loc->address;
7127 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7129 /* Software breakpoints unsupported? */
7133 target_mem = alloca (len);
7135 /* Enable the automatic memory restoration from breakpoints while
7136 we read the memory. Otherwise we could say about our temporary
7137 breakpoints they are permanent. */
7138 cleanup = save_current_space_and_thread ();
7140 switch_to_program_space_and_thread (loc->pspace);
7141 make_show_memory_breakpoints_cleanup (0);
7143 if (target_read_memory (loc->address, target_mem, len) == 0
7144 && memcmp (target_mem, brk, len) == 0)
7147 do_cleanups (cleanup);
7154 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7155 as textual description of the location, and COND_STRING
7156 as condition expression. */
7159 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
7160 struct symtabs_and_lines sals, char *addr_string,
7162 enum bptype type, enum bpdisp disposition,
7163 int thread, int task, int ignore_count,
7164 const struct breakpoint_ops *ops, int from_tty,
7165 int enabled, int internal, int display_canonical)
7169 if (type == bp_hardware_breakpoint)
7171 int i = hw_breakpoint_used_count ();
7172 int target_resources_ok =
7173 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7175 if (target_resources_ok == 0)
7176 error (_("No hardware breakpoint support in the target."));
7177 else if (target_resources_ok < 0)
7178 error (_("Hardware breakpoints used exceeds limit."));
7181 gdb_assert (sals.nelts > 0);
7183 for (i = 0; i < sals.nelts; ++i)
7185 struct symtab_and_line sal = sals.sals[i];
7186 struct bp_location *loc;
7190 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7192 loc_gdbarch = gdbarch;
7194 describe_other_breakpoints (loc_gdbarch,
7195 sal.pspace, sal.pc, sal.section, thread);
7200 init_raw_breakpoint (b, gdbarch, sal, type, ops);
7204 b->cond_string = cond_string;
7205 b->ignore_count = ignore_count;
7206 b->enable_state = enabled ? bp_enabled : bp_disabled;
7207 b->disposition = disposition;
7208 b->pspace = sals.sals[0].pspace;
7210 if (type == bp_static_tracepoint)
7212 struct tracepoint *t = (struct tracepoint *) b;
7213 struct static_tracepoint_marker marker;
7215 if (is_marker_spec (addr_string))
7217 /* We already know the marker exists, otherwise, we
7218 wouldn't see a sal for it. */
7219 char *p = &addr_string[3];
7224 p = skip_spaces (p);
7226 endp = skip_to_space (p);
7228 marker_str = savestring (p, endp - p);
7229 t->static_trace_marker_id = marker_str;
7231 printf_filtered (_("Probed static tracepoint "
7233 t->static_trace_marker_id);
7235 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7237 t->static_trace_marker_id = xstrdup (marker.str_id);
7238 release_static_tracepoint_marker (&marker);
7240 printf_filtered (_("Probed static tracepoint "
7242 t->static_trace_marker_id);
7245 warning (_("Couldn't determine the static "
7246 "tracepoint marker to probe"));
7249 if (enabled && b->pspace->executing_startup
7250 && (b->type == bp_breakpoint
7251 || b->type == bp_hardware_breakpoint))
7252 b->enable_state = bp_startup_disabled;
7258 loc = add_location_to_breakpoint (b, &sal);
7261 if (bp_loc_is_permanent (loc))
7262 make_breakpoint_permanent (b);
7266 char *arg = b->cond_string;
7267 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7269 error (_("Garbage %s follows condition"), arg);
7273 b->display_canonical = display_canonical;
7275 b->addr_string = addr_string;
7277 /* addr_string has to be used or breakpoint_re_set will delete
7280 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7284 create_breakpoint_sal (struct gdbarch *gdbarch,
7285 struct symtabs_and_lines sals, char *addr_string,
7287 enum bptype type, enum bpdisp disposition,
7288 int thread, int task, int ignore_count,
7289 const struct breakpoint_ops *ops, int from_tty,
7290 int enabled, int internal, int display_canonical)
7292 struct breakpoint *b;
7293 struct cleanup *old_chain;
7295 if (is_tracepoint_type (type))
7297 struct tracepoint *t;
7299 t = XCNEW (struct tracepoint);
7303 b = XNEW (struct breakpoint);
7305 old_chain = make_cleanup (xfree, b);
7307 init_breakpoint_sal (b, gdbarch,
7311 thread, task, ignore_count,
7313 enabled, internal, display_canonical);
7314 discard_cleanups (old_chain);
7316 install_breakpoint (internal, b);
7319 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7320 elements to fill the void space. */
7322 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7324 int i = index_to_remove+1;
7325 int last_index = sal->nelts-1;
7327 for (;i <= last_index; ++i)
7328 sal->sals[i-1] = sal->sals[i];
7333 /* If appropriate, obtains all sals that correspond to the same file
7334 and line as SAL, in all program spaces. Users debugging with IDEs,
7335 will want to set a breakpoint at foo.c:line, and not really care
7336 about program spaces. This is done only if SAL does not have
7337 explicit PC and has line and file information. If we got just a
7338 single expanded sal, return the original.
7340 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7341 which the name of enclosing function is different from SAL. This
7342 makes sure that if we have breakpoint originally set in template
7343 instantiation, say foo<int>(), we won't expand SAL to locations at
7344 the same line in all existing instantiations of 'foo'. */
7346 static struct symtabs_and_lines
7347 expand_line_sal_maybe (struct symtab_and_line sal)
7349 struct symtabs_and_lines expanded;
7350 CORE_ADDR original_pc = sal.pc;
7351 char *original_function = NULL;
7354 struct cleanup *old_chain;
7356 /* If we have explicit pc, don't expand.
7357 If we have no line number, we can't expand. */
7358 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7361 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7362 expanded.sals[0] = sal;
7368 old_chain = save_current_space_and_thread ();
7370 switch_to_program_space_and_thread (sal.pspace);
7372 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7374 /* Note that expand_line_sal visits *all* program spaces. */
7375 expanded = expand_line_sal (sal);
7377 if (expanded.nelts == 1)
7379 /* We had one sal, we got one sal. Return that sal, adjusting it
7380 past the function prologue if necessary. */
7381 xfree (expanded.sals);
7383 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7384 sal.pc = original_pc;
7385 expanded.sals[0] = sal;
7386 skip_prologue_sal (&expanded.sals[0]);
7387 do_cleanups (old_chain);
7391 if (!sal.explicit_line)
7393 CORE_ADDR func_addr, func_end;
7394 for (i = 0; i < expanded.nelts; ++i)
7396 CORE_ADDR pc = expanded.sals[i].pc;
7397 char *this_function;
7399 /* We need to switch threads as well since we're about to
7401 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7403 if (find_pc_partial_function (pc, &this_function,
7404 &func_addr, &func_end))
7407 && strcmp (this_function, original_function) != 0)
7409 remove_sal (&expanded, i);
7416 /* Skip the function prologue if necessary. */
7417 for (i = 0; i < expanded.nelts; ++i)
7418 skip_prologue_sal (&expanded.sals[i]);
7420 do_cleanups (old_chain);
7422 if (expanded.nelts <= 1)
7424 /* This is an ugly workaround. If we get zero expanded sals
7425 then something is really wrong. Fix that by returning the
7428 xfree (expanded.sals);
7430 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7431 sal.pc = original_pc;
7432 expanded.sals[0] = sal;
7439 for (i = 0; i < expanded.nelts; ++i)
7440 if (expanded.sals[i].pc == original_pc)
7451 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7452 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7453 value. COND_STRING, if not NULL, specified the condition to be
7454 used for all breakpoints. Essentially the only case where
7455 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7456 function. In that case, it's still not possible to specify
7457 separate conditions for different overloaded functions, so
7458 we take just a single condition string.
7460 NOTE: If the function succeeds, the caller is expected to cleanup
7461 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7462 array contents). If the function fails (error() is called), the
7463 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7464 COND and SALS arrays and each of those arrays contents. */
7467 create_breakpoints_sal (struct gdbarch *gdbarch,
7468 struct symtabs_and_lines sals,
7469 struct linespec_result *canonical,
7471 enum bptype type, enum bpdisp disposition,
7472 int thread, int task, int ignore_count,
7473 const struct breakpoint_ops *ops, int from_tty,
7474 int enabled, int internal)
7478 for (i = 0; i < sals.nelts; ++i)
7480 struct symtabs_and_lines expanded =
7481 expand_line_sal_maybe (sals.sals[i]);
7483 create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i],
7484 cond_string, type, disposition,
7485 thread, task, ignore_count, ops,
7486 from_tty, enabled, internal,
7487 canonical->special_display);
7491 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7492 followed by conditionals. On return, SALS contains an array of SAL
7493 addresses found. ADDR_STRING contains a vector of (canonical)
7494 address strings. ADDRESS points to the end of the SAL.
7496 The array and the line spec strings are allocated on the heap, it is
7497 the caller's responsibility to free them. */
7500 parse_breakpoint_sals (char **address,
7501 struct symtabs_and_lines *sals,
7502 struct linespec_result *canonical)
7504 char *addr_start = *address;
7506 /* If no arg given, or if first arg is 'if ', use the default
7508 if ((*address) == NULL
7509 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7511 /* The last displayed codepoint, if it's valid, is our default breakpoint
7513 if (last_displayed_sal_is_valid ())
7515 struct symtab_and_line sal;
7517 init_sal (&sal); /* Initialize to zeroes. */
7518 sals->sals = (struct symtab_and_line *)
7519 xmalloc (sizeof (struct symtab_and_line));
7521 /* Set sal's pspace, pc, symtab, and line to the values
7522 corresponding to the last call to print_frame_info. */
7523 get_last_displayed_sal (&sal);
7524 sal.section = find_pc_overlay (sal.pc);
7526 /* "break" without arguments is equivalent to "break *PC"
7527 where PC is the last displayed codepoint's address. So
7528 make sure to set sal.explicit_pc to prevent GDB from
7529 trying to expand the list of sals to include all other
7530 instances with the same symtab and line. */
7531 sal.explicit_pc = 1;
7533 sals->sals[0] = sal;
7537 error (_("No default breakpoint address now."));
7541 /* Force almost all breakpoints to be in terms of the
7542 current_source_symtab (which is decode_line_1's default).
7543 This should produce the results we want almost all of the
7544 time while leaving the last displayed codepoint pointers
7547 ObjC: However, don't match an Objective-C method name which
7548 may have a '+' or '-' succeeded by a '[' */
7550 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7552 if (last_displayed_sal_is_valid ()
7554 || ((strchr ("+-", (*address)[0]) != NULL)
7555 && ((*address)[1] != '['))))
7556 *sals = decode_line_1 (address, 1,
7557 get_last_displayed_symtab (),
7558 get_last_displayed_line (),
7561 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7564 /* For any SAL that didn't have a canonical string, fill one in. */
7565 if (sals->nelts > 0 && canonical->canonical == NULL)
7566 canonical->canonical = xcalloc (sals->nelts, sizeof (char *));
7567 if (addr_start != (*address))
7571 for (i = 0; i < sals->nelts; i++)
7573 /* Add the string if not present. */
7574 if (canonical->canonical[i] == NULL)
7575 canonical->canonical[i] = savestring (addr_start,
7576 (*address) - addr_start);
7582 /* Convert each SAL into a real PC. Verify that the PC can be
7583 inserted as a breakpoint. If it can't throw an error. */
7586 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7590 for (i = 0; i < sals->nelts; i++)
7591 resolve_sal_pc (&sals->sals[i]);
7594 /* Fast tracepoints may have restrictions on valid locations. For
7595 instance, a fast tracepoint using a jump instead of a trap will
7596 likely have to overwrite more bytes than a trap would, and so can
7597 only be placed where the instruction is longer than the jump, or a
7598 multi-instruction sequence does not have a jump into the middle of
7602 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7603 struct symtabs_and_lines *sals)
7606 struct symtab_and_line *sal;
7608 struct cleanup *old_chain;
7610 for (i = 0; i < sals->nelts; i++)
7612 sal = &sals->sals[i];
7614 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7616 old_chain = make_cleanup (xfree, msg);
7619 error (_("May not have a fast tracepoint at 0x%s%s"),
7620 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7622 do_cleanups (old_chain);
7626 /* Given TOK, a string specification of condition and thread, as
7627 accepted by the 'break' command, extract the condition
7628 string and thread number and set *COND_STRING and *THREAD.
7629 PC identifies the context at which the condition should be parsed.
7630 If no condition is found, *COND_STRING is set to NULL.
7631 If no thread is found, *THREAD is set to -1. */
7633 find_condition_and_thread (char *tok, CORE_ADDR pc,
7634 char **cond_string, int *thread, int *task)
7636 *cond_string = NULL;
7642 char *cond_start = NULL;
7643 char *cond_end = NULL;
7645 tok = skip_spaces (tok);
7647 end_tok = skip_to_space (tok);
7649 toklen = end_tok - tok;
7651 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7653 struct expression *expr;
7655 tok = cond_start = end_tok + 1;
7656 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7659 *cond_string = savestring (cond_start,
7660 cond_end - cond_start);
7662 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7668 *thread = strtol (tok, &tok, 0);
7670 error (_("Junk after thread keyword."));
7671 if (!valid_thread_id (*thread))
7672 error (_("Unknown thread %d."), *thread);
7674 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7680 *task = strtol (tok, &tok, 0);
7682 error (_("Junk after task keyword."));
7683 if (!valid_task_id (*task))
7684 error (_("Unknown task %d."), *task);
7687 error (_("Junk at end of arguments."));
7691 /* Decode a static tracepoint marker spec. */
7693 static struct symtabs_and_lines
7694 decode_static_tracepoint_spec (char **arg_p)
7696 VEC(static_tracepoint_marker_p) *markers = NULL;
7697 struct symtabs_and_lines sals;
7698 struct symtab_and_line sal;
7700 struct cleanup *old_chain;
7701 char *p = &(*arg_p)[3];
7706 p = skip_spaces (p);
7708 endp = skip_to_space (p);
7710 marker_str = savestring (p, endp - p);
7711 old_chain = make_cleanup (xfree, marker_str);
7713 markers = target_static_tracepoint_markers_by_strid (marker_str);
7714 if (VEC_empty(static_tracepoint_marker_p, markers))
7715 error (_("No known static tracepoint marker named %s"), marker_str);
7717 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7718 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7720 for (i = 0; i < sals.nelts; i++)
7722 struct static_tracepoint_marker *marker;
7724 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7726 init_sal (&sals.sals[i]);
7728 sals.sals[i] = find_pc_line (marker->address, 0);
7729 sals.sals[i].pc = marker->address;
7731 release_static_tracepoint_marker (marker);
7734 do_cleanups (old_chain);
7740 /* Set a breakpoint. This function is shared between CLI and MI
7741 functions for setting a breakpoint. This function has two major
7742 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7743 parameter. If non-zero, the function will parse arg, extracting
7744 breakpoint location, address and thread. Otherwise, ARG is just
7745 the location of breakpoint, with condition and thread specified by
7746 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7747 the breakpoint number will be allocated from the internal
7748 breakpoint count. Returns true if any breakpoint was created;
7752 create_breakpoint (struct gdbarch *gdbarch,
7753 char *arg, char *cond_string, int thread,
7754 int parse_condition_and_thread,
7755 int tempflag, enum bptype type_wanted,
7757 enum auto_boolean pending_break_support,
7758 const struct breakpoint_ops *ops,
7759 int from_tty, int enabled, int internal)
7761 volatile struct gdb_exception e;
7762 struct symtabs_and_lines sals;
7763 struct symtab_and_line pending_sal;
7765 char *addr_start = arg;
7766 struct linespec_result canonical;
7767 struct cleanup *old_chain;
7768 struct cleanup *bkpt_chain = NULL;
7772 int prev_bkpt_count = breakpoint_count;
7774 gdb_assert (ops != NULL);
7778 init_linespec_result (&canonical);
7780 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7784 sals = decode_static_tracepoint_spec (&arg);
7786 copy_arg = savestring (addr_start, arg - addr_start);
7787 canonical.canonical = xcalloc (sals.nelts, sizeof (char *));
7788 for (i = 0; i < sals.nelts; i++)
7789 canonical.canonical[i] = xstrdup (copy_arg);
7793 TRY_CATCH (e, RETURN_MASK_ALL)
7795 parse_breakpoint_sals (&arg, &sals, &canonical);
7798 /* If caller is interested in rc value from parse, set value. */
7802 throw_exception (e);
7806 case NOT_FOUND_ERROR:
7808 /* If pending breakpoint support is turned off, throw
7811 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7812 throw_exception (e);
7814 exception_print (gdb_stderr, e);
7816 /* If pending breakpoint support is auto query and the user
7817 selects no, then simply return the error code. */
7818 if (pending_break_support == AUTO_BOOLEAN_AUTO
7819 && !nquery (_("Make breakpoint pending on "
7820 "future shared library load? ")))
7823 /* At this point, either the user was queried about setting
7824 a pending breakpoint and selected yes, or pending
7825 breakpoint behavior is on and thus a pending breakpoint
7826 is defaulted on behalf of the user. */
7827 copy_arg = xstrdup (addr_start);
7828 canonical.canonical = ©_arg;
7830 sals.sals = &pending_sal;
7835 throw_exception (e);
7845 /* Create a chain of things that always need to be cleaned up. */
7846 old_chain = make_cleanup (null_cleanup, 0);
7850 /* Make sure that all storage allocated to SALS gets freed. */
7851 make_cleanup (xfree, sals.sals);
7853 /* Cleanup the canonical array but not its contents. */
7854 make_cleanup (xfree, canonical.canonical);
7857 /* ----------------------------- SNIP -----------------------------
7858 Anything added to the cleanup chain beyond this point is assumed
7859 to be part of a breakpoint. If the breakpoint create succeeds
7860 then the memory is not reclaimed. */
7861 bkpt_chain = make_cleanup (null_cleanup, 0);
7863 /* Mark the contents of the canonical for cleanup. These go on
7864 the bkpt_chain and only occur if the breakpoint create fails. */
7865 for (i = 0; i < sals.nelts; i++)
7867 if (canonical.canonical[i] != NULL)
7868 make_cleanup (xfree, canonical.canonical[i]);
7871 /* Resolve all line numbers to PC's and verify that the addresses
7872 are ok for the target. */
7874 breakpoint_sals_to_pc (&sals);
7876 /* Fast tracepoints may have additional restrictions on location. */
7877 if (type_wanted == bp_fast_tracepoint)
7878 check_fast_tracepoint_sals (gdbarch, &sals);
7880 /* Verify that condition can be parsed, before setting any
7881 breakpoints. Allocate a separate condition expression for each
7885 if (parse_condition_and_thread)
7887 /* Here we only parse 'arg' to separate condition
7888 from thread number, so parsing in context of first
7889 sal is OK. When setting the breakpoint we'll
7890 re-parse it in context of each sal. */
7893 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7896 make_cleanup (xfree, cond_string);
7900 /* Create a private copy of condition string. */
7903 cond_string = xstrdup (cond_string);
7904 make_cleanup (xfree, cond_string);
7908 /* If the user is creating a static tracepoint by marker id
7909 (strace -m MARKER_ID), then store the sals index, so that
7910 breakpoint_re_set can try to match up which of the newly
7911 found markers corresponds to this one, and, don't try to
7912 expand multiple locations for each sal, given than SALS
7913 already should contain all sals for MARKER_ID. */
7914 if (type_wanted == bp_static_tracepoint
7915 && is_marker_spec (canonical.canonical[0]))
7919 for (i = 0; i < sals.nelts; ++i)
7921 struct symtabs_and_lines expanded;
7922 struct tracepoint *tp;
7923 struct cleanup *old_chain;
7926 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7927 expanded.sals[0] = sals.sals[i];
7928 old_chain = make_cleanup (xfree, expanded.sals);
7930 tp = XCNEW (struct tracepoint);
7931 init_breakpoint_sal (&tp->base, gdbarch, expanded,
7932 canonical.canonical[i],
7933 cond_string, type_wanted,
7934 tempflag ? disp_del : disp_donttouch,
7935 thread, task, ignore_count, ops,
7936 from_tty, enabled, internal,
7937 canonical.special_display);
7938 /* Given that its possible to have multiple markers with
7939 the same string id, if the user is creating a static
7940 tracepoint by marker id ("strace -m MARKER_ID"), then
7941 store the sals index, so that breakpoint_re_set can
7942 try to match up which of the newly found markers
7943 corresponds to this one */
7944 tp->static_trace_marker_id_idx = i;
7946 install_breakpoint (internal, &tp->base);
7948 do_cleanups (old_chain);
7952 create_breakpoints_sal (gdbarch, sals, &canonical, cond_string,
7954 tempflag ? disp_del : disp_donttouch,
7955 thread, task, ignore_count, ops, from_tty,
7960 struct breakpoint *b;
7962 make_cleanup (xfree, copy_arg);
7964 b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops);
7965 set_breakpoint_number (internal, b);
7967 b->addr_string = canonical.canonical[0];
7968 b->cond_string = NULL;
7969 b->ignore_count = ignore_count;
7970 b->disposition = tempflag ? disp_del : disp_donttouch;
7971 b->condition_not_parsed = 1;
7972 b->enable_state = enabled ? bp_enabled : bp_disabled;
7973 b->pspace = current_program_space;
7974 b->py_bp_object = NULL;
7976 if (enabled && b->pspace->executing_startup
7977 && (b->type == bp_breakpoint
7978 || b->type == bp_hardware_breakpoint))
7979 b->enable_state = bp_startup_disabled;
7982 /* Do not mention breakpoints with a negative number,
7983 but do notify observers. */
7985 observer_notify_breakpoint_created (b);
7990 warning (_("Multiple breakpoints were set.\nUse the "
7991 "\"delete\" command to delete unwanted breakpoints."));
7992 prev_breakpoint_count = prev_bkpt_count;
7995 /* That's it. Discard the cleanups for data inserted into the
7997 discard_cleanups (bkpt_chain);
7998 /* But cleanup everything else. */
7999 do_cleanups (old_chain);
8001 /* error call may happen here - have BKPT_CHAIN already discarded. */
8002 update_global_location_list (1);
8007 /* Set a breakpoint.
8008 ARG is a string describing breakpoint address,
8009 condition, and thread.
8010 FLAG specifies if a breakpoint is hardware on,
8011 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8015 break_command_1 (char *arg, int flag, int from_tty)
8017 int tempflag = flag & BP_TEMPFLAG;
8018 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8019 ? bp_hardware_breakpoint
8022 create_breakpoint (get_current_arch (),
8024 NULL, 0, 1 /* parse arg */,
8025 tempflag, type_wanted,
8026 0 /* Ignore count */,
8027 pending_break_support,
8028 &bkpt_breakpoint_ops,
8034 /* Helper function for break_command_1 and disassemble_command. */
8037 resolve_sal_pc (struct symtab_and_line *sal)
8041 if (sal->pc == 0 && sal->symtab != NULL)
8043 if (!find_line_pc (sal->symtab, sal->line, &pc))
8044 error (_("No line %d in file \"%s\"."),
8045 sal->line, sal->symtab->filename);
8048 /* If this SAL corresponds to a breakpoint inserted using a line
8049 number, then skip the function prologue if necessary. */
8050 if (sal->explicit_line)
8051 skip_prologue_sal (sal);
8054 if (sal->section == 0 && sal->symtab != NULL)
8056 struct blockvector *bv;
8060 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8063 sym = block_linkage_function (b);
8066 fixup_symbol_section (sym, sal->symtab->objfile);
8067 sal->section = SYMBOL_OBJ_SECTION (sym);
8071 /* It really is worthwhile to have the section, so we'll
8072 just have to look harder. This case can be executed
8073 if we have line numbers but no functions (as can
8074 happen in assembly source). */
8076 struct minimal_symbol *msym;
8077 struct cleanup *old_chain = save_current_space_and_thread ();
8079 switch_to_program_space_and_thread (sal->pspace);
8081 msym = lookup_minimal_symbol_by_pc (sal->pc);
8083 sal->section = SYMBOL_OBJ_SECTION (msym);
8085 do_cleanups (old_chain);
8092 break_command (char *arg, int from_tty)
8094 break_command_1 (arg, 0, from_tty);
8098 tbreak_command (char *arg, int from_tty)
8100 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8104 hbreak_command (char *arg, int from_tty)
8106 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8110 thbreak_command (char *arg, int from_tty)
8112 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8116 stop_command (char *arg, int from_tty)
8118 printf_filtered (_("Specify the type of breakpoint to set.\n\
8119 Usage: stop in <function | address>\n\
8120 stop at <line>\n"));
8124 stopin_command (char *arg, int from_tty)
8128 if (arg == (char *) NULL)
8130 else if (*arg != '*')
8135 /* Look for a ':'. If this is a line number specification, then
8136 say it is bad, otherwise, it should be an address or
8137 function/method name. */
8138 while (*argptr && !hasColon)
8140 hasColon = (*argptr == ':');
8145 badInput = (*argptr != ':'); /* Not a class::method */
8147 badInput = isdigit (*arg); /* a simple line number */
8151 printf_filtered (_("Usage: stop in <function | address>\n"));
8153 break_command_1 (arg, 0, from_tty);
8157 stopat_command (char *arg, int from_tty)
8161 if (arg == (char *) NULL || *arg == '*') /* no line number */
8168 /* Look for a ':'. If there is a '::' then get out, otherwise
8169 it is probably a line number. */
8170 while (*argptr && !hasColon)
8172 hasColon = (*argptr == ':');
8177 badInput = (*argptr == ':'); /* we have class::method */
8179 badInput = !isdigit (*arg); /* not a line number */
8183 printf_filtered (_("Usage: stop at <line>\n"));
8185 break_command_1 (arg, 0, from_tty);
8188 /* Implement the "breakpoint_hit" breakpoint_ops method for
8189 ranged breakpoints. */
8192 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
8193 struct address_space *aspace,
8196 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
8197 bl->length, aspace, bp_addr);
8200 /* Implement the "resources_needed" breakpoint_ops method for
8201 ranged breakpoints. */
8204 resources_needed_ranged_breakpoint (const struct bp_location *bl)
8206 return target_ranged_break_num_registers ();
8209 /* Implement the "print_it" breakpoint_ops method for
8210 ranged breakpoints. */
8212 static enum print_stop_action
8213 print_it_ranged_breakpoint (bpstat bs)
8215 struct breakpoint *b = bs->breakpoint_at;
8216 struct bp_location *bl = b->loc;
8217 struct ui_out *uiout = current_uiout;
8219 gdb_assert (b->type == bp_hardware_breakpoint);
8221 /* Ranged breakpoints have only one location. */
8222 gdb_assert (bl && bl->next == NULL);
8224 annotate_breakpoint (b->number);
8225 if (b->disposition == disp_del)
8226 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
8228 ui_out_text (uiout, "\nRanged breakpoint ");
8229 if (ui_out_is_mi_like_p (uiout))
8231 ui_out_field_string (uiout, "reason",
8232 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8233 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8235 ui_out_field_int (uiout, "bkptno", b->number);
8236 ui_out_text (uiout, ", ");
8238 return PRINT_SRC_AND_LOC;
8241 /* Implement the "print_one" breakpoint_ops method for
8242 ranged breakpoints. */
8245 print_one_ranged_breakpoint (struct breakpoint *b,
8246 struct bp_location **last_loc)
8248 struct bp_location *bl = b->loc;
8249 struct value_print_options opts;
8250 struct ui_out *uiout = current_uiout;
8252 /* Ranged breakpoints have only one location. */
8253 gdb_assert (bl && bl->next == NULL);
8255 get_user_print_options (&opts);
8257 if (opts.addressprint)
8258 /* We don't print the address range here, it will be printed later
8259 by print_one_detail_ranged_breakpoint. */
8260 ui_out_field_skip (uiout, "addr");
8262 print_breakpoint_location (b, bl);
8266 /* Implement the "print_one_detail" breakpoint_ops method for
8267 ranged breakpoints. */
8270 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
8271 struct ui_out *uiout)
8273 CORE_ADDR address_start, address_end;
8274 struct bp_location *bl = b->loc;
8275 struct ui_stream *stb = ui_out_stream_new (uiout);
8276 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
8280 address_start = bl->address;
8281 address_end = address_start + bl->length - 1;
8283 ui_out_text (uiout, "\taddress range: ");
8284 fprintf_unfiltered (stb->stream, "[%s, %s]",
8285 print_core_address (bl->gdbarch, address_start),
8286 print_core_address (bl->gdbarch, address_end));
8287 ui_out_field_stream (uiout, "addr", stb);
8288 ui_out_text (uiout, "\n");
8290 do_cleanups (cleanup);
8293 /* Implement the "print_mention" breakpoint_ops method for
8294 ranged breakpoints. */
8297 print_mention_ranged_breakpoint (struct breakpoint *b)
8299 struct bp_location *bl = b->loc;
8300 struct ui_out *uiout = current_uiout;
8303 gdb_assert (b->type == bp_hardware_breakpoint);
8305 if (ui_out_is_mi_like_p (uiout))
8308 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8309 b->number, paddress (bl->gdbarch, bl->address),
8310 paddress (bl->gdbarch, bl->address + bl->length - 1));
8313 /* Implement the "print_recreate" breakpoint_ops method for
8314 ranged breakpoints. */
8317 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
8319 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
8320 b->addr_string_range_end);
8321 print_recreate_thread (b, fp);
8324 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8326 static struct breakpoint_ops ranged_breakpoint_ops;
8328 /* Find the address where the end of the breakpoint range should be
8329 placed, given the SAL of the end of the range. This is so that if
8330 the user provides a line number, the end of the range is set to the
8331 last instruction of the given line. */
8334 find_breakpoint_range_end (struct symtab_and_line sal)
8338 /* If the user provided a PC value, use it. Otherwise,
8339 find the address of the end of the given location. */
8340 if (sal.explicit_pc)
8347 ret = find_line_pc_range (sal, &start, &end);
8349 error (_("Could not find location of the end of the range."));
8351 /* find_line_pc_range returns the start of the next line. */
8358 /* Implement the "break-range" CLI command. */
8361 break_range_command (char *arg, int from_tty)
8363 char *arg_start, *addr_string_start, *addr_string_end;
8364 struct linespec_result canonical_start, canonical_end;
8365 int bp_count, can_use_bp, length;
8367 struct breakpoint *b;
8368 struct symtab_and_line sal_start, sal_end;
8369 struct symtabs_and_lines sals_start, sals_end;
8370 struct cleanup *cleanup_bkpt;
8372 /* We don't support software ranged breakpoints. */
8373 if (target_ranged_break_num_registers () < 0)
8374 error (_("This target does not support hardware ranged breakpoints."));
8376 bp_count = hw_breakpoint_used_count ();
8377 bp_count += target_ranged_break_num_registers ();
8378 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8381 error (_("Hardware breakpoints used exceeds limit."));
8383 if (arg == NULL || arg[0] == '\0')
8384 error(_("No address range specified."));
8386 sals_start.sals = NULL;
8387 sals_start.nelts = 0;
8388 init_linespec_result (&canonical_start);
8390 while (*arg == ' ' || *arg == '\t')
8393 parse_breakpoint_sals (&arg, &sals_start, &canonical_start);
8395 sal_start = sals_start.sals[0];
8396 addr_string_start = canonical_start.canonical[0];
8397 cleanup_bkpt = make_cleanup (xfree, addr_string_start);
8398 xfree (sals_start.sals);
8399 xfree (canonical_start.canonical);
8402 error (_("Too few arguments."));
8403 else if (sals_start.nelts == 0)
8404 error (_("Could not find location of the beginning of the range."));
8405 else if (sals_start.nelts != 1)
8406 error (_("Cannot create a ranged breakpoint with multiple locations."));
8408 resolve_sal_pc (&sal_start);
8410 arg++; /* Skip the comma. */
8411 while (*arg == ' ' || *arg == '\t')
8414 /* Parse the end location. */
8416 sals_end.sals = NULL;
8418 init_linespec_result (&canonical_end);
8421 /* We call decode_line_1 directly here instead of using
8422 parse_breakpoint_sals because we need to specify the start location's
8423 symtab and line as the default symtab and line for the end of the
8424 range. This makes it possible to have ranges like "foo.c:27, +14",
8425 where +14 means 14 lines from the start location. */
8426 sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line,
8429 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8430 if (canonical_end.canonical == NULL)
8431 canonical_end.canonical = xcalloc (1, sizeof (char *));
8432 /* Add the string if not present. */
8433 if (arg_start != arg && canonical_end.canonical[0] == NULL)
8434 canonical_end.canonical[0] = savestring (arg_start, arg - arg_start);
8436 sal_end = sals_end.sals[0];
8437 addr_string_end = canonical_end.canonical[0];
8438 make_cleanup (xfree, addr_string_end);
8439 xfree (sals_end.sals);
8440 xfree (canonical_end.canonical);
8442 if (sals_end.nelts == 0)
8443 error (_("Could not find location of the end of the range."));
8444 else if (sals_end.nelts != 1)
8445 error (_("Cannot create a ranged breakpoint with multiple locations."));
8447 resolve_sal_pc (&sal_end);
8449 end = find_breakpoint_range_end (sal_end);
8450 if (sal_start.pc > end)
8451 error (_("Invalid address range, end precedes start."));
8453 length = end - sal_start.pc + 1;
8455 /* Length overflowed. */
8456 error (_("Address range too large."));
8457 else if (length == 1)
8459 /* This range is simple enough to be handled by
8460 the `hbreak' command. */
8461 hbreak_command (addr_string_start, 1);
8463 do_cleanups (cleanup_bkpt);
8468 /* Now set up the breakpoint. */
8469 b = set_raw_breakpoint (get_current_arch (), sal_start,
8470 bp_hardware_breakpoint, &ranged_breakpoint_ops);
8471 set_breakpoint_count (breakpoint_count + 1);
8472 b->number = breakpoint_count;
8473 b->disposition = disp_donttouch;
8474 b->addr_string = addr_string_start;
8475 b->addr_string_range_end = addr_string_end;
8476 b->loc->length = length;
8478 discard_cleanups (cleanup_bkpt);
8481 observer_notify_breakpoint_created (b);
8482 update_global_location_list (1);
8485 /* Return non-zero if EXP is verified as constant. Returned zero
8486 means EXP is variable. Also the constant detection may fail for
8487 some constant expressions and in such case still falsely return
8490 watchpoint_exp_is_const (const struct expression *exp)
8498 /* We are only interested in the descriptor of each element. */
8499 operator_length (exp, i, &oplenp, &argsp);
8502 switch (exp->elts[i].opcode)
8512 case BINOP_LOGICAL_AND:
8513 case BINOP_LOGICAL_OR:
8514 case BINOP_BITWISE_AND:
8515 case BINOP_BITWISE_IOR:
8516 case BINOP_BITWISE_XOR:
8518 case BINOP_NOTEQUAL:
8534 case TERNOP_SLICE_COUNT:
8546 case OP_OBJC_NSSTRING:
8549 case UNOP_LOGICAL_NOT:
8550 case UNOP_COMPLEMENT:
8553 /* Unary, binary and ternary operators: We have to check
8554 their operands. If they are constant, then so is the
8555 result of that operation. For instance, if A and B are
8556 determined to be constants, then so is "A + B".
8558 UNOP_IND is one exception to the rule above, because the
8559 value of *ADDR is not necessarily a constant, even when
8564 /* Check whether the associated symbol is a constant.
8566 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8567 possible that a buggy compiler could mark a variable as
8568 constant even when it is not, and TYPE_CONST would return
8569 true in this case, while SYMBOL_CLASS wouldn't.
8571 We also have to check for function symbols because they
8572 are always constant. */
8574 struct symbol *s = exp->elts[i + 2].symbol;
8576 if (SYMBOL_CLASS (s) != LOC_BLOCK
8577 && SYMBOL_CLASS (s) != LOC_CONST
8578 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8583 /* The default action is to return 0 because we are using
8584 the optimistic approach here: If we don't know something,
8585 then it is not a constant. */
8594 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8597 dtor_watchpoint (struct breakpoint *self)
8599 struct watchpoint *w = (struct watchpoint *) self;
8601 xfree (w->cond_exp);
8603 xfree (w->exp_string);
8604 xfree (w->exp_string_reparse);
8605 value_free (w->val);
8607 base_breakpoint_ops.dtor (self);
8610 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8613 re_set_watchpoint (struct breakpoint *b)
8615 struct watchpoint *w = (struct watchpoint *) b;
8617 /* Watchpoint can be either on expression using entirely global
8618 variables, or it can be on local variables.
8620 Watchpoints of the first kind are never auto-deleted, and even
8621 persist across program restarts. Since they can use variables
8622 from shared libraries, we need to reparse expression as libraries
8623 are loaded and unloaded.
8625 Watchpoints on local variables can also change meaning as result
8626 of solib event. For example, if a watchpoint uses both a local
8627 and a global variables in expression, it's a local watchpoint,
8628 but unloading of a shared library will make the expression
8629 invalid. This is not a very common use case, but we still
8630 re-evaluate expression, to avoid surprises to the user.
8632 Note that for local watchpoints, we re-evaluate it only if
8633 watchpoints frame id is still valid. If it's not, it means the
8634 watchpoint is out of scope and will be deleted soon. In fact,
8635 I'm not sure we'll ever be called in this case.
8637 If a local watchpoint's frame id is still valid, then
8638 w->exp_valid_block is likewise valid, and we can safely use it.
8640 Don't do anything about disabled watchpoints, since they will be
8641 reevaluated again when enabled. */
8642 update_watchpoint (w, 1 /* reparse */);
8645 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8648 insert_watchpoint (struct bp_location *bl)
8650 struct watchpoint *w = (struct watchpoint *) bl->owner;
8651 int length = w->exact ? 1 : bl->length;
8653 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8657 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8660 remove_watchpoint (struct bp_location *bl)
8662 struct watchpoint *w = (struct watchpoint *) bl->owner;
8663 int length = w->exact ? 1 : bl->length;
8665 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8670 breakpoint_hit_watchpoint (const struct bp_location *bl,
8671 struct address_space *aspace, CORE_ADDR bp_addr)
8673 struct breakpoint *b = bl->owner;
8674 struct watchpoint *w = (struct watchpoint *) b;
8676 /* Continuable hardware watchpoints are treated as non-existent if the
8677 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8678 some data address). Otherwise gdb won't stop on a break instruction
8679 in the code (not from a breakpoint) when a hardware watchpoint has
8680 been defined. Also skip watchpoints which we know did not trigger
8681 (did not match the data address). */
8682 if (is_hardware_watchpoint (b)
8683 && w->watchpoint_triggered == watch_triggered_no)
8690 check_status_watchpoint (bpstat bs)
8692 gdb_assert (is_watchpoint (bs->breakpoint_at));
8694 bpstat_check_watchpoint (bs);
8697 /* Implement the "resources_needed" breakpoint_ops method for
8698 hardware watchpoints. */
8701 resources_needed_watchpoint (const struct bp_location *bl)
8703 struct watchpoint *w = (struct watchpoint *) bl->owner;
8704 int length = w->exact? 1 : bl->length;
8706 return target_region_ok_for_hw_watchpoint (bl->address, length);
8709 /* Implement the "works_in_software_mode" breakpoint_ops method for
8710 hardware watchpoints. */
8713 works_in_software_mode_watchpoint (const struct breakpoint *b)
8715 /* Read and access watchpoints only work with hardware support. */
8716 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
8719 static enum print_stop_action
8720 print_it_watchpoint (bpstat bs)
8722 struct cleanup *old_chain;
8723 struct breakpoint *b;
8724 const struct bp_location *bl;
8725 struct ui_stream *stb;
8726 enum print_stop_action result;
8727 struct watchpoint *w;
8728 struct ui_out *uiout = current_uiout;
8730 gdb_assert (bs->bp_location_at != NULL);
8732 bl = bs->bp_location_at;
8733 b = bs->breakpoint_at;
8734 w = (struct watchpoint *) b;
8736 stb = ui_out_stream_new (uiout);
8737 old_chain = make_cleanup_ui_out_stream_delete (stb);
8742 case bp_hardware_watchpoint:
8743 annotate_watchpoint (b->number);
8744 if (ui_out_is_mi_like_p (uiout))
8747 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8749 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8750 ui_out_text (uiout, "\nOld value = ");
8751 watchpoint_value_print (bs->old_val, stb->stream);
8752 ui_out_field_stream (uiout, "old", stb);
8753 ui_out_text (uiout, "\nNew value = ");
8754 watchpoint_value_print (w->val, stb->stream);
8755 ui_out_field_stream (uiout, "new", stb);
8756 ui_out_text (uiout, "\n");
8757 /* More than one watchpoint may have been triggered. */
8758 result = PRINT_UNKNOWN;
8761 case bp_read_watchpoint:
8762 if (ui_out_is_mi_like_p (uiout))
8765 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8767 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8768 ui_out_text (uiout, "\nValue = ");
8769 watchpoint_value_print (w->val, stb->stream);
8770 ui_out_field_stream (uiout, "value", stb);
8771 ui_out_text (uiout, "\n");
8772 result = PRINT_UNKNOWN;
8775 case bp_access_watchpoint:
8776 if (bs->old_val != NULL)
8778 annotate_watchpoint (b->number);
8779 if (ui_out_is_mi_like_p (uiout))
8782 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8784 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8785 ui_out_text (uiout, "\nOld value = ");
8786 watchpoint_value_print (bs->old_val, stb->stream);
8787 ui_out_field_stream (uiout, "old", stb);
8788 ui_out_text (uiout, "\nNew value = ");
8793 if (ui_out_is_mi_like_p (uiout))
8796 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8797 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8798 ui_out_text (uiout, "\nValue = ");
8800 watchpoint_value_print (w->val, stb->stream);
8801 ui_out_field_stream (uiout, "new", stb);
8802 ui_out_text (uiout, "\n");
8803 result = PRINT_UNKNOWN;
8806 result = PRINT_UNKNOWN;
8809 do_cleanups (old_chain);
8813 /* Implement the "print_mention" breakpoint_ops method for hardware
8817 print_mention_watchpoint (struct breakpoint *b)
8819 struct cleanup *ui_out_chain;
8820 struct watchpoint *w = (struct watchpoint *) b;
8821 struct ui_out *uiout = current_uiout;
8826 ui_out_text (uiout, "Watchpoint ");
8827 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8829 case bp_hardware_watchpoint:
8830 ui_out_text (uiout, "Hardware watchpoint ");
8831 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8833 case bp_read_watchpoint:
8834 ui_out_text (uiout, "Hardware read watchpoint ");
8835 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
8837 case bp_access_watchpoint:
8838 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
8839 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
8842 internal_error (__FILE__, __LINE__,
8843 _("Invalid hardware watchpoint type."));
8846 ui_out_field_int (uiout, "number", b->number);
8847 ui_out_text (uiout, ": ");
8848 ui_out_field_string (uiout, "exp", w->exp_string);
8849 do_cleanups (ui_out_chain);
8852 /* Implement the "print_recreate" breakpoint_ops method for
8856 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
8858 struct watchpoint *w = (struct watchpoint *) b;
8863 case bp_hardware_watchpoint:
8864 fprintf_unfiltered (fp, "watch");
8866 case bp_read_watchpoint:
8867 fprintf_unfiltered (fp, "rwatch");
8869 case bp_access_watchpoint:
8870 fprintf_unfiltered (fp, "awatch");
8873 internal_error (__FILE__, __LINE__,
8874 _("Invalid watchpoint type."));
8877 fprintf_unfiltered (fp, " %s", w->exp_string);
8878 print_recreate_thread (b, fp);
8881 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8883 static struct breakpoint_ops watchpoint_breakpoint_ops;
8885 /* Implement the "insert" breakpoint_ops method for
8886 masked hardware watchpoints. */
8889 insert_masked_watchpoint (struct bp_location *bl)
8891 struct watchpoint *w = (struct watchpoint *) bl->owner;
8893 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
8894 bl->watchpoint_type);
8897 /* Implement the "remove" breakpoint_ops method for
8898 masked hardware watchpoints. */
8901 remove_masked_watchpoint (struct bp_location *bl)
8903 struct watchpoint *w = (struct watchpoint *) bl->owner;
8905 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
8906 bl->watchpoint_type);
8909 /* Implement the "resources_needed" breakpoint_ops method for
8910 masked hardware watchpoints. */
8913 resources_needed_masked_watchpoint (const struct bp_location *bl)
8915 struct watchpoint *w = (struct watchpoint *) bl->owner;
8917 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
8920 /* Implement the "works_in_software_mode" breakpoint_ops method for
8921 masked hardware watchpoints. */
8924 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
8929 /* Implement the "print_it" breakpoint_ops method for
8930 masked hardware watchpoints. */
8932 static enum print_stop_action
8933 print_it_masked_watchpoint (bpstat bs)
8935 struct breakpoint *b = bs->breakpoint_at;
8936 struct ui_out *uiout = current_uiout;
8938 /* Masked watchpoints have only one location. */
8939 gdb_assert (b->loc && b->loc->next == NULL);
8943 case bp_hardware_watchpoint:
8944 annotate_watchpoint (b->number);
8945 if (ui_out_is_mi_like_p (uiout))
8948 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8951 case bp_read_watchpoint:
8952 if (ui_out_is_mi_like_p (uiout))
8955 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8958 case bp_access_watchpoint:
8959 if (ui_out_is_mi_like_p (uiout))
8962 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8965 internal_error (__FILE__, __LINE__,
8966 _("Invalid hardware watchpoint type."));
8970 ui_out_text (uiout, _("\n\
8971 Check the underlying instruction at PC for the memory\n\
8972 address and value which triggered this watchpoint.\n"));
8973 ui_out_text (uiout, "\n");
8975 /* More than one watchpoint may have been triggered. */
8976 return PRINT_UNKNOWN;
8979 /* Implement the "print_one_detail" breakpoint_ops method for
8980 masked hardware watchpoints. */
8983 print_one_detail_masked_watchpoint (const struct breakpoint *b,
8984 struct ui_out *uiout)
8986 struct watchpoint *w = (struct watchpoint *) b;
8988 /* Masked watchpoints have only one location. */
8989 gdb_assert (b->loc && b->loc->next == NULL);
8991 ui_out_text (uiout, "\tmask ");
8992 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
8993 ui_out_text (uiout, "\n");
8996 /* Implement the "print_mention" breakpoint_ops method for
8997 masked hardware watchpoints. */
9000 print_mention_masked_watchpoint (struct breakpoint *b)
9002 struct watchpoint *w = (struct watchpoint *) b;
9003 struct ui_out *uiout = current_uiout;
9004 struct cleanup *ui_out_chain;
9008 case bp_hardware_watchpoint:
9009 ui_out_text (uiout, "Masked hardware watchpoint ");
9010 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9012 case bp_read_watchpoint:
9013 ui_out_text (uiout, "Masked hardware read watchpoint ");
9014 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9016 case bp_access_watchpoint:
9017 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9018 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9021 internal_error (__FILE__, __LINE__,
9022 _("Invalid hardware watchpoint type."));
9025 ui_out_field_int (uiout, "number", b->number);
9026 ui_out_text (uiout, ": ");
9027 ui_out_field_string (uiout, "exp", w->exp_string);
9028 do_cleanups (ui_out_chain);
9031 /* Implement the "print_recreate" breakpoint_ops method for
9032 masked hardware watchpoints. */
9035 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9037 struct watchpoint *w = (struct watchpoint *) b;
9042 case bp_hardware_watchpoint:
9043 fprintf_unfiltered (fp, "watch");
9045 case bp_read_watchpoint:
9046 fprintf_unfiltered (fp, "rwatch");
9048 case bp_access_watchpoint:
9049 fprintf_unfiltered (fp, "awatch");
9052 internal_error (__FILE__, __LINE__,
9053 _("Invalid hardware watchpoint type."));
9056 sprintf_vma (tmp, w->hw_wp_mask);
9057 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
9058 print_recreate_thread (b, fp);
9061 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9063 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9065 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9068 is_masked_watchpoint (const struct breakpoint *b)
9070 return b->ops == &masked_watchpoint_breakpoint_ops;
9073 /* accessflag: hw_write: watch write,
9074 hw_read: watch read,
9075 hw_access: watch access (read or write) */
9077 watch_command_1 (char *arg, int accessflag, int from_tty,
9078 int just_location, int internal)
9080 volatile struct gdb_exception e;
9081 struct breakpoint *b, *scope_breakpoint = NULL;
9082 struct expression *exp;
9083 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9084 struct value *val, *mark, *result;
9085 struct frame_info *frame;
9086 char *exp_start = NULL;
9087 char *exp_end = NULL;
9088 char *tok, *end_tok;
9090 char *cond_start = NULL;
9091 char *cond_end = NULL;
9092 enum bptype bp_type;
9095 /* Flag to indicate whether we are going to use masks for
9096 the hardware watchpoint. */
9099 struct watchpoint *w;
9101 /* Make sure that we actually have parameters to parse. */
9102 if (arg != NULL && arg[0] != '\0')
9106 /* Look for "parameter value" pairs at the end
9107 of the arguments string. */
9108 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9110 /* Skip whitespace at the end of the argument list. */
9111 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9114 /* Find the beginning of the last token.
9115 This is the value of the parameter. */
9116 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9118 value_start = tok + 1;
9120 /* Skip whitespace. */
9121 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9126 /* Find the beginning of the second to last token.
9127 This is the parameter itself. */
9128 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9131 toklen = end_tok - tok + 1;
9133 if (toklen == 6 && !strncmp (tok, "thread", 6))
9135 /* At this point we've found a "thread" token, which means
9136 the user is trying to set a watchpoint that triggers
9137 only in a specific thread. */
9141 error(_("You can specify only one thread."));
9143 /* Extract the thread ID from the next token. */
9144 thread = strtol (value_start, &endp, 0);
9146 /* Check if the user provided a valid numeric value for the
9148 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9149 error (_("Invalid thread ID specification %s."), value_start);
9151 /* Check if the thread actually exists. */
9152 if (!valid_thread_id (thread))
9153 error (_("Unknown thread %d."), thread);
9155 else if (toklen == 4 && !strncmp (tok, "mask", 4))
9157 /* We've found a "mask" token, which means the user wants to
9158 create a hardware watchpoint that is going to have the mask
9160 struct value *mask_value, *mark;
9163 error(_("You can specify only one mask."));
9165 use_mask = just_location = 1;
9167 mark = value_mark ();
9168 mask_value = parse_to_comma_and_eval (&value_start);
9169 mask = value_as_address (mask_value);
9170 value_free_to_mark (mark);
9173 /* We didn't recognize what we found. We should stop here. */
9176 /* Truncate the string and get rid of the "parameter value" pair before
9177 the arguments string is parsed by the parse_exp_1 function. */
9182 /* Parse the rest of the arguments. */
9183 innermost_block = NULL;
9185 exp = parse_exp_1 (&arg, 0, 0);
9187 /* Remove trailing whitespace from the expression before saving it.
9188 This makes the eventual display of the expression string a bit
9190 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
9193 /* Checking if the expression is not constant. */
9194 if (watchpoint_exp_is_const (exp))
9198 len = exp_end - exp_start;
9199 while (len > 0 && isspace (exp_start[len - 1]))
9201 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
9204 exp_valid_block = innermost_block;
9205 mark = value_mark ();
9206 fetch_subexp_value (exp, &pc, &val, &result, NULL);
9212 exp_valid_block = NULL;
9213 val = value_addr (result);
9214 release_value (val);
9215 value_free_to_mark (mark);
9219 ret = target_masked_watch_num_registers (value_as_address (val),
9222 error (_("This target does not support masked watchpoints."));
9224 error (_("Invalid mask or memory region."));
9227 else if (val != NULL)
9228 release_value (val);
9230 tok = skip_spaces (arg);
9231 end_tok = skip_to_space (tok);
9233 toklen = end_tok - tok;
9234 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9236 struct expression *cond;
9238 innermost_block = NULL;
9239 tok = cond_start = end_tok + 1;
9240 cond = parse_exp_1 (&tok, 0, 0);
9242 /* The watchpoint expression may not be local, but the condition
9243 may still be. E.g.: `watch global if local > 0'. */
9244 cond_exp_valid_block = innermost_block;
9250 error (_("Junk at end of command."));
9252 if (accessflag == hw_read)
9253 bp_type = bp_read_watchpoint;
9254 else if (accessflag == hw_access)
9255 bp_type = bp_access_watchpoint;
9257 bp_type = bp_hardware_watchpoint;
9259 frame = block_innermost_frame (exp_valid_block);
9261 /* If the expression is "local", then set up a "watchpoint scope"
9262 breakpoint at the point where we've left the scope of the watchpoint
9263 expression. Create the scope breakpoint before the watchpoint, so
9264 that we will encounter it first in bpstat_stop_status. */
9265 if (exp_valid_block && frame)
9267 if (frame_id_p (frame_unwind_caller_id (frame)))
9270 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
9271 frame_unwind_caller_pc (frame),
9272 bp_watchpoint_scope,
9273 &momentary_breakpoint_ops);
9275 scope_breakpoint->enable_state = bp_enabled;
9277 /* Automatically delete the breakpoint when it hits. */
9278 scope_breakpoint->disposition = disp_del;
9280 /* Only break in the proper frame (help with recursion). */
9281 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
9283 /* Set the address at which we will stop. */
9284 scope_breakpoint->loc->gdbarch
9285 = frame_unwind_caller_arch (frame);
9286 scope_breakpoint->loc->requested_address
9287 = frame_unwind_caller_pc (frame);
9288 scope_breakpoint->loc->address
9289 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
9290 scope_breakpoint->loc->requested_address,
9291 scope_breakpoint->type);
9295 /* Now set up the breakpoint. */
9297 w = XCNEW (struct watchpoint);
9300 init_raw_breakpoint_without_location (b, NULL, bp_type,
9301 &masked_watchpoint_breakpoint_ops);
9303 init_raw_breakpoint_without_location (b, NULL, bp_type,
9304 &watchpoint_breakpoint_ops);
9306 b->disposition = disp_donttouch;
9307 b->pspace = current_program_space;
9309 w->exp_valid_block = exp_valid_block;
9310 w->cond_exp_valid_block = cond_exp_valid_block;
9313 struct type *t = value_type (val);
9314 CORE_ADDR addr = value_as_address (val);
9317 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
9318 name = type_to_string (t);
9320 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
9321 core_addr_to_string (addr));
9324 w->exp_string = xstrprintf ("-location %.*s",
9325 (int) (exp_end - exp_start), exp_start);
9327 /* The above expression is in C. */
9328 b->language = language_c;
9331 w->exp_string = savestring (exp_start, exp_end - exp_start);
9335 w->hw_wp_mask = mask;
9344 b->cond_string = savestring (cond_start, cond_end - cond_start);
9350 w->watchpoint_frame = get_frame_id (frame);
9351 w->watchpoint_thread = inferior_ptid;
9355 w->watchpoint_frame = null_frame_id;
9356 w->watchpoint_thread = null_ptid;
9359 if (scope_breakpoint != NULL)
9361 /* The scope breakpoint is related to the watchpoint. We will
9362 need to act on them together. */
9363 b->related_breakpoint = scope_breakpoint;
9364 scope_breakpoint->related_breakpoint = b;
9368 value_free_to_mark (mark);
9370 TRY_CATCH (e, RETURN_MASK_ALL)
9372 /* Finally update the new watchpoint. This creates the locations
9373 that should be inserted. */
9374 update_watchpoint (w, 1);
9378 delete_breakpoint (b);
9379 throw_exception (e);
9382 install_breakpoint (internal, b);
9385 /* Return count of debug registers needed to watch the given expression.
9386 If the watchpoint cannot be handled in hardware return zero. */
9389 can_use_hardware_watchpoint (struct value *v)
9391 int found_memory_cnt = 0;
9392 struct value *head = v;
9394 /* Did the user specifically forbid us to use hardware watchpoints? */
9395 if (!can_use_hw_watchpoints)
9398 /* Make sure that the value of the expression depends only upon
9399 memory contents, and values computed from them within GDB. If we
9400 find any register references or function calls, we can't use a
9401 hardware watchpoint.
9403 The idea here is that evaluating an expression generates a series
9404 of values, one holding the value of every subexpression. (The
9405 expression a*b+c has five subexpressions: a, b, a*b, c, and
9406 a*b+c.) GDB's values hold almost enough information to establish
9407 the criteria given above --- they identify memory lvalues,
9408 register lvalues, computed values, etcetera. So we can evaluate
9409 the expression, and then scan the chain of values that leaves
9410 behind to decide whether we can detect any possible change to the
9411 expression's final value using only hardware watchpoints.
9413 However, I don't think that the values returned by inferior
9414 function calls are special in any way. So this function may not
9415 notice that an expression involving an inferior function call
9416 can't be watched with hardware watchpoints. FIXME. */
9417 for (; v; v = value_next (v))
9419 if (VALUE_LVAL (v) == lval_memory)
9421 if (v != head && value_lazy (v))
9422 /* A lazy memory lvalue in the chain is one that GDB never
9423 needed to fetch; we either just used its address (e.g.,
9424 `a' in `a.b') or we never needed it at all (e.g., `a'
9425 in `a,b'). This doesn't apply to HEAD; if that is
9426 lazy then it was not readable, but watch it anyway. */
9430 /* Ahh, memory we actually used! Check if we can cover
9431 it with hardware watchpoints. */
9432 struct type *vtype = check_typedef (value_type (v));
9434 /* We only watch structs and arrays if user asked for it
9435 explicitly, never if they just happen to appear in a
9436 middle of some value chain. */
9438 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9439 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
9441 CORE_ADDR vaddr = value_address (v);
9445 len = (target_exact_watchpoints
9446 && is_scalar_type_recursive (vtype))?
9447 1 : TYPE_LENGTH (value_type (v));
9449 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
9453 found_memory_cnt += num_regs;
9457 else if (VALUE_LVAL (v) != not_lval
9458 && deprecated_value_modifiable (v) == 0)
9459 return 0; /* These are values from the history (e.g., $1). */
9460 else if (VALUE_LVAL (v) == lval_register)
9461 return 0; /* Cannot watch a register with a HW watchpoint. */
9464 /* The expression itself looks suitable for using a hardware
9465 watchpoint, but give the target machine a chance to reject it. */
9466 return found_memory_cnt;
9470 watch_command_wrapper (char *arg, int from_tty, int internal)
9472 watch_command_1 (arg, hw_write, from_tty, 0, internal);
9475 /* A helper function that looks for an argument at the start of a
9476 string. The argument must also either be at the end of the string,
9477 or be followed by whitespace. Returns 1 if it finds the argument,
9478 0 otherwise. If the argument is found, it updates *STR. */
9481 check_for_argument (char **str, char *arg, int arg_len)
9483 if (strncmp (*str, arg, arg_len) == 0
9484 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
9492 /* A helper function that looks for the "-location" argument and then
9493 calls watch_command_1. */
9496 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
9498 int just_location = 0;
9501 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
9502 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
9504 arg = skip_spaces (arg);
9508 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
9512 watch_command (char *arg, int from_tty)
9514 watch_maybe_just_location (arg, hw_write, from_tty);
9518 rwatch_command_wrapper (char *arg, int from_tty, int internal)
9520 watch_command_1 (arg, hw_read, from_tty, 0, internal);
9524 rwatch_command (char *arg, int from_tty)
9526 watch_maybe_just_location (arg, hw_read, from_tty);
9530 awatch_command_wrapper (char *arg, int from_tty, int internal)
9532 watch_command_1 (arg, hw_access, from_tty, 0, internal);
9536 awatch_command (char *arg, int from_tty)
9538 watch_maybe_just_location (arg, hw_access, from_tty);
9542 /* Helper routines for the until_command routine in infcmd.c. Here
9543 because it uses the mechanisms of breakpoints. */
9545 struct until_break_command_continuation_args
9547 struct breakpoint *breakpoint;
9548 struct breakpoint *breakpoint2;
9552 /* This function is called by fetch_inferior_event via the
9553 cmd_continuation pointer, to complete the until command. It takes
9554 care of cleaning up the temporary breakpoints set up by the until
9557 until_break_command_continuation (void *arg, int err)
9559 struct until_break_command_continuation_args *a = arg;
9561 delete_breakpoint (a->breakpoint);
9563 delete_breakpoint (a->breakpoint2);
9564 delete_longjmp_breakpoint (a->thread_num);
9568 until_break_command (char *arg, int from_tty, int anywhere)
9570 struct symtabs_and_lines sals;
9571 struct symtab_and_line sal;
9572 struct frame_info *frame = get_selected_frame (NULL);
9573 struct breakpoint *breakpoint;
9574 struct breakpoint *breakpoint2 = NULL;
9575 struct cleanup *old_chain;
9577 struct thread_info *tp;
9579 clear_proceed_status ();
9581 /* Set a breakpoint where the user wants it and at return from
9584 if (last_displayed_sal_is_valid ())
9585 sals = decode_line_1 (&arg, 1,
9586 get_last_displayed_symtab (),
9587 get_last_displayed_line (),
9590 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL);
9592 if (sals.nelts != 1)
9593 error (_("Couldn't get information on specified line."));
9596 xfree (sals.sals); /* malloc'd, so freed. */
9599 error (_("Junk at end of arguments."));
9601 resolve_sal_pc (&sal);
9604 /* If the user told us to continue until a specified location,
9605 we don't specify a frame at which we need to stop. */
9606 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9607 null_frame_id, bp_until);
9609 /* Otherwise, specify the selected frame, because we want to stop
9610 only at the very same frame. */
9611 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9612 get_stack_frame_id (frame),
9615 old_chain = make_cleanup_delete_breakpoint (breakpoint);
9617 tp = inferior_thread ();
9620 /* Keep within the current frame, or in frames called by the current
9623 if (frame_id_p (frame_unwind_caller_id (frame)))
9625 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
9626 sal.pc = frame_unwind_caller_pc (frame);
9627 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
9629 frame_unwind_caller_id (frame),
9631 make_cleanup_delete_breakpoint (breakpoint2);
9633 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
9634 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
9637 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
9639 /* If we are running asynchronously, and proceed call above has
9640 actually managed to start the target, arrange for breakpoints to
9641 be deleted when the target stops. Otherwise, we're already
9642 stopped and delete breakpoints via cleanup chain. */
9644 if (target_can_async_p () && is_running (inferior_ptid))
9646 struct until_break_command_continuation_args *args;
9647 args = xmalloc (sizeof (*args));
9649 args->breakpoint = breakpoint;
9650 args->breakpoint2 = breakpoint2;
9651 args->thread_num = thread;
9653 discard_cleanups (old_chain);
9654 add_continuation (inferior_thread (),
9655 until_break_command_continuation, args,
9659 do_cleanups (old_chain);
9662 /* This function attempts to parse an optional "if <cond>" clause
9663 from the arg string. If one is not found, it returns NULL.
9665 Else, it returns a pointer to the condition string. (It does not
9666 attempt to evaluate the string against a particular block.) And,
9667 it updates arg to point to the first character following the parsed
9668 if clause in the arg string. */
9671 ep_parse_optional_if_clause (char **arg)
9675 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
9678 /* Skip the "if" keyword. */
9681 /* Skip any extra leading whitespace, and record the start of the
9682 condition string. */
9683 *arg = skip_spaces (*arg);
9686 /* Assume that the condition occupies the remainder of the arg
9688 (*arg) += strlen (cond_string);
9693 /* Commands to deal with catching events, such as signals, exceptions,
9694 process start/exit, etc. */
9698 catch_fork_temporary, catch_vfork_temporary,
9699 catch_fork_permanent, catch_vfork_permanent
9704 catch_fork_command_1 (char *arg, int from_tty,
9705 struct cmd_list_element *command)
9707 struct gdbarch *gdbarch = get_current_arch ();
9708 char *cond_string = NULL;
9709 catch_fork_kind fork_kind;
9712 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
9713 tempflag = (fork_kind == catch_fork_temporary
9714 || fork_kind == catch_vfork_temporary);
9718 arg = skip_spaces (arg);
9720 /* The allowed syntax is:
9722 catch [v]fork if <cond>
9724 First, check if there's an if clause. */
9725 cond_string = ep_parse_optional_if_clause (&arg);
9727 if ((*arg != '\0') && !isspace (*arg))
9728 error (_("Junk at end of arguments."));
9730 /* If this target supports it, create a fork or vfork catchpoint
9731 and enable reporting of such events. */
9734 case catch_fork_temporary:
9735 case catch_fork_permanent:
9736 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9737 &catch_fork_breakpoint_ops);
9739 case catch_vfork_temporary:
9740 case catch_vfork_permanent:
9741 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9742 &catch_vfork_breakpoint_ops);
9745 error (_("unsupported or unknown fork kind; cannot catch it"));
9751 catch_exec_command_1 (char *arg, int from_tty,
9752 struct cmd_list_element *command)
9754 struct exec_catchpoint *c;
9755 struct gdbarch *gdbarch = get_current_arch ();
9757 char *cond_string = NULL;
9759 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9763 arg = skip_spaces (arg);
9765 /* The allowed syntax is:
9767 catch exec if <cond>
9769 First, check if there's an if clause. */
9770 cond_string = ep_parse_optional_if_clause (&arg);
9772 if ((*arg != '\0') && !isspace (*arg))
9773 error (_("Junk at end of arguments."));
9775 c = XNEW (struct exec_catchpoint);
9776 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
9777 &catch_exec_breakpoint_ops);
9778 c->exec_pathname = NULL;
9780 install_breakpoint (0, &c->base);
9783 static enum print_stop_action
9784 print_it_exception_catchpoint (bpstat bs)
9786 struct ui_out *uiout = current_uiout;
9787 struct breakpoint *b = bs->breakpoint_at;
9788 int bp_temp, bp_throw;
9790 annotate_catchpoint (b->number);
9792 bp_throw = strstr (b->addr_string, "throw") != NULL;
9793 if (b->loc->address != b->loc->requested_address)
9794 breakpoint_adjustment_warning (b->loc->requested_address,
9797 bp_temp = b->disposition == disp_del;
9799 bp_temp ? "Temporary catchpoint "
9801 if (!ui_out_is_mi_like_p (uiout))
9802 ui_out_field_int (uiout, "bkptno", b->number);
9804 bp_throw ? " (exception thrown), "
9805 : " (exception caught), ");
9806 if (ui_out_is_mi_like_p (uiout))
9808 ui_out_field_string (uiout, "reason",
9809 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9810 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9811 ui_out_field_int (uiout, "bkptno", b->number);
9813 return PRINT_SRC_AND_LOC;
9817 print_one_exception_catchpoint (struct breakpoint *b,
9818 struct bp_location **last_loc)
9820 struct value_print_options opts;
9821 struct ui_out *uiout = current_uiout;
9823 get_user_print_options (&opts);
9824 if (opts.addressprint)
9827 if (b->loc == NULL || b->loc->shlib_disabled)
9828 ui_out_field_string (uiout, "addr", "<PENDING>");
9830 ui_out_field_core_addr (uiout, "addr",
9831 b->loc->gdbarch, b->loc->address);
9836 if (strstr (b->addr_string, "throw") != NULL)
9837 ui_out_field_string (uiout, "what", "exception throw");
9839 ui_out_field_string (uiout, "what", "exception catch");
9843 print_mention_exception_catchpoint (struct breakpoint *b)
9845 struct ui_out *uiout = current_uiout;
9849 bp_temp = b->disposition == disp_del;
9850 bp_throw = strstr (b->addr_string, "throw") != NULL;
9851 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
9852 : _("Catchpoint "));
9853 ui_out_field_int (uiout, "bkptno", b->number);
9854 ui_out_text (uiout, bp_throw ? _(" (throw)")
9858 /* Implement the "print_recreate" breakpoint_ops method for throw and
9859 catch catchpoints. */
9862 print_recreate_exception_catchpoint (struct breakpoint *b,
9868 bp_temp = b->disposition == disp_del;
9869 bp_throw = strstr (b->addr_string, "throw") != NULL;
9870 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
9871 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
9872 print_recreate_thread (b, fp);
9875 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
9878 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
9879 enum exception_event_kind ex_event, int from_tty)
9881 char *trigger_func_name;
9883 if (ex_event == EX_EVENT_CATCH)
9884 trigger_func_name = "__cxa_begin_catch";
9886 trigger_func_name = "__cxa_throw";
9888 create_breakpoint (get_current_arch (),
9889 trigger_func_name, cond_string, -1,
9890 0 /* condition and thread are valid. */,
9891 tempflag, bp_breakpoint,
9893 AUTO_BOOLEAN_TRUE /* pending */,
9894 &gnu_v3_exception_catchpoint_ops, from_tty,
9901 /* Deal with "catch catch" and "catch throw" commands. */
9904 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
9905 int tempflag, int from_tty)
9907 char *cond_string = NULL;
9911 arg = skip_spaces (arg);
9913 cond_string = ep_parse_optional_if_clause (&arg);
9915 if ((*arg != '\0') && !isspace (*arg))
9916 error (_("Junk at end of arguments."));
9918 if (ex_event != EX_EVENT_THROW
9919 && ex_event != EX_EVENT_CATCH)
9920 error (_("Unsupported or unknown exception event; cannot catch it"));
9922 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
9925 warning (_("Unsupported with this platform/compiler combination."));
9928 /* Implementation of "catch catch" command. */
9931 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
9933 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9935 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
9938 /* Implementation of "catch throw" command. */
9941 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
9943 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9945 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
9949 init_ada_exception_breakpoint (struct breakpoint *b,
9950 struct gdbarch *gdbarch,
9951 struct symtab_and_line sal,
9953 const struct breakpoint_ops *ops,
9959 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9961 loc_gdbarch = gdbarch;
9963 describe_other_breakpoints (loc_gdbarch,
9964 sal.pspace, sal.pc, sal.section, -1);
9965 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9966 version for exception catchpoints, because two catchpoints
9967 used for different exception names will use the same address.
9968 In this case, a "breakpoint ... also set at..." warning is
9969 unproductive. Besides, the warning phrasing is also a bit
9970 inappropriate, we should use the word catchpoint, and tell
9971 the user what type of catchpoint it is. The above is good
9972 enough for now, though. */
9975 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
9977 b->enable_state = bp_enabled;
9978 b->disposition = tempflag ? disp_del : disp_donttouch;
9979 b->addr_string = addr_string;
9980 b->language = language_ada;
9983 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9984 filter list, or NULL if no filtering is required. */
9986 catch_syscall_split_args (char *arg)
9988 VEC(int) *result = NULL;
9989 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
9991 while (*arg != '\0')
9993 int i, syscall_number;
9998 /* Skip whitespace. */
9999 while (isspace (*arg))
10002 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10003 cur_name[i] = arg[i];
10004 cur_name[i] = '\0';
10007 /* Check if the user provided a syscall name or a number. */
10008 syscall_number = (int) strtol (cur_name, &endptr, 0);
10009 if (*endptr == '\0')
10010 get_syscall_by_number (syscall_number, &s);
10013 /* We have a name. Let's check if it's valid and convert it
10015 get_syscall_by_name (cur_name, &s);
10017 if (s.number == UNKNOWN_SYSCALL)
10018 /* Here we have to issue an error instead of a warning,
10019 because GDB cannot do anything useful if there's no
10020 syscall number to be caught. */
10021 error (_("Unknown syscall name '%s'."), cur_name);
10024 /* Ok, it's valid. */
10025 VEC_safe_push (int, result, s.number);
10028 discard_cleanups (cleanup);
10032 /* Implement the "catch syscall" command. */
10035 catch_syscall_command_1 (char *arg, int from_tty,
10036 struct cmd_list_element *command)
10041 struct gdbarch *gdbarch = get_current_arch ();
10043 /* Checking if the feature if supported. */
10044 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10045 error (_("The feature 'catch syscall' is not supported on \
10046 this architecture yet."));
10048 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10050 arg = skip_spaces (arg);
10052 /* We need to do this first "dummy" translation in order
10053 to get the syscall XML file loaded or, most important,
10054 to display a warning to the user if there's no XML file
10055 for his/her architecture. */
10056 get_syscall_by_number (0, &s);
10058 /* The allowed syntax is:
10060 catch syscall <name | number> [<name | number> ... <name | number>]
10062 Let's check if there's a syscall name. */
10065 filter = catch_syscall_split_args (arg);
10069 create_syscall_event_catchpoint (tempflag, filter,
10070 &catch_syscall_breakpoint_ops);
10074 catch_command (char *arg, int from_tty)
10076 error (_("Catch requires an event name."));
10081 tcatch_command (char *arg, int from_tty)
10083 error (_("Catch requires an event name."));
10086 /* Delete breakpoints by address or line. */
10089 clear_command (char *arg, int from_tty)
10091 struct breakpoint *b;
10092 VEC(breakpoint_p) *found = 0;
10095 struct symtabs_and_lines sals;
10096 struct symtab_and_line sal;
10101 sals = decode_line_spec (arg, 1);
10106 sals.sals = (struct symtab_and_line *)
10107 xmalloc (sizeof (struct symtab_and_line));
10108 make_cleanup (xfree, sals.sals);
10109 init_sal (&sal); /* Initialize to zeroes. */
10111 /* Set sal's line, symtab, pc, and pspace to the values
10112 corresponding to the last call to print_frame_info. If the
10113 codepoint is not valid, this will set all the fields to 0. */
10114 get_last_displayed_sal (&sal);
10115 if (sal.symtab == 0)
10116 error (_("No source file specified."));
10118 sals.sals[0] = sal;
10124 /* We don't call resolve_sal_pc here. That's not as bad as it
10125 seems, because all existing breakpoints typically have both
10126 file/line and pc set. So, if clear is given file/line, we can
10127 match this to existing breakpoint without obtaining pc at all.
10129 We only support clearing given the address explicitly
10130 present in breakpoint table. Say, we've set breakpoint
10131 at file:line. There were several PC values for that file:line,
10132 due to optimization, all in one block.
10134 We've picked one PC value. If "clear" is issued with another
10135 PC corresponding to the same file:line, the breakpoint won't
10136 be cleared. We probably can still clear the breakpoint, but
10137 since the other PC value is never presented to user, user
10138 can only find it by guessing, and it does not seem important
10139 to support that. */
10141 /* For each line spec given, delete bps which correspond to it. Do
10142 it in two passes, solely to preserve the current behavior that
10143 from_tty is forced true if we delete more than one
10147 for (i = 0; i < sals.nelts; i++)
10149 /* If exact pc given, clear bpts at that pc.
10150 If line given (pc == 0), clear all bpts on specified line.
10151 If defaulting, clear all bpts on default line
10154 defaulting sal.pc != 0 tests to do
10159 1 0 <can't happen> */
10161 sal = sals.sals[i];
10163 /* Find all matching breakpoints and add them to 'found'. */
10164 ALL_BREAKPOINTS (b)
10167 /* Are we going to delete b? */
10168 if (b->type != bp_none && !is_watchpoint (b))
10170 struct bp_location *loc = b->loc;
10171 for (; loc; loc = loc->next)
10173 int pc_match = sal.pc
10174 && (loc->pspace == sal.pspace)
10175 && (loc->address == sal.pc)
10176 && (!section_is_overlay (loc->section)
10177 || loc->section == sal.section);
10178 int line_match = ((default_match || (0 == sal.pc))
10179 && b->source_file != NULL
10180 && sal.symtab != NULL
10181 && sal.pspace == loc->pspace
10182 && filename_cmp (b->source_file,
10183 sal.symtab->filename) == 0
10184 && b->line_number == sal.line);
10185 if (pc_match || line_match)
10194 VEC_safe_push(breakpoint_p, found, b);
10197 /* Now go thru the 'found' chain and delete them. */
10198 if (VEC_empty(breakpoint_p, found))
10201 error (_("No breakpoint at %s."), arg);
10203 error (_("No breakpoint at this line."));
10206 if (VEC_length(breakpoint_p, found) > 1)
10207 from_tty = 1; /* Always report if deleted more than one. */
10210 if (VEC_length(breakpoint_p, found) == 1)
10211 printf_unfiltered (_("Deleted breakpoint "));
10213 printf_unfiltered (_("Deleted breakpoints "));
10215 breakpoints_changed ();
10217 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
10220 printf_unfiltered ("%d ", b->number);
10221 delete_breakpoint (b);
10224 putchar_unfiltered ('\n');
10227 /* Delete breakpoint in BS if they are `delete' breakpoints and
10228 all breakpoints that are marked for deletion, whether hit or not.
10229 This is called after any breakpoint is hit, or after errors. */
10232 breakpoint_auto_delete (bpstat bs)
10234 struct breakpoint *b, *b_tmp;
10236 for (; bs; bs = bs->next)
10237 if (bs->breakpoint_at
10238 && bs->breakpoint_at->disposition == disp_del
10240 delete_breakpoint (bs->breakpoint_at);
10242 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10244 if (b->disposition == disp_del_at_next_stop)
10245 delete_breakpoint (b);
10249 /* A comparison function for bp_location AP and BP being interfaced to
10250 qsort. Sort elements primarily by their ADDRESS (no matter what
10251 does breakpoint_address_is_meaningful say for its OWNER),
10252 secondarily by ordering first bp_permanent OWNERed elements and
10253 terciarily just ensuring the array is sorted stable way despite
10254 qsort being an unstable algorithm. */
10257 bp_location_compare (const void *ap, const void *bp)
10259 struct bp_location *a = *(void **) ap;
10260 struct bp_location *b = *(void **) bp;
10261 /* A and B come from existing breakpoints having non-NULL OWNER. */
10262 int a_perm = a->owner->enable_state == bp_permanent;
10263 int b_perm = b->owner->enable_state == bp_permanent;
10265 if (a->address != b->address)
10266 return (a->address > b->address) - (a->address < b->address);
10268 /* Sort permanent breakpoints first. */
10269 if (a_perm != b_perm)
10270 return (a_perm < b_perm) - (a_perm > b_perm);
10272 /* Make the user-visible order stable across GDB runs. Locations of
10273 the same breakpoint can be sorted in arbitrary order. */
10275 if (a->owner->number != b->owner->number)
10276 return (a->owner->number > b->owner->number)
10277 - (a->owner->number < b->owner->number);
10279 return (a > b) - (a < b);
10282 /* Set bp_location_placed_address_before_address_max and
10283 bp_location_shadow_len_after_address_max according to the current
10284 content of the bp_location array. */
10287 bp_location_target_extensions_update (void)
10289 struct bp_location *bl, **blp_tmp;
10291 bp_location_placed_address_before_address_max = 0;
10292 bp_location_shadow_len_after_address_max = 0;
10294 ALL_BP_LOCATIONS (bl, blp_tmp)
10296 CORE_ADDR start, end, addr;
10298 if (!bp_location_has_shadow (bl))
10301 start = bl->target_info.placed_address;
10302 end = start + bl->target_info.shadow_len;
10304 gdb_assert (bl->address >= start);
10305 addr = bl->address - start;
10306 if (addr > bp_location_placed_address_before_address_max)
10307 bp_location_placed_address_before_address_max = addr;
10309 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10311 gdb_assert (bl->address < end);
10312 addr = end - bl->address;
10313 if (addr > bp_location_shadow_len_after_address_max)
10314 bp_location_shadow_len_after_address_max = addr;
10318 /* Swap the insertion/duplication state between two locations. */
10321 swap_insertion (struct bp_location *left, struct bp_location *right)
10323 const int left_inserted = left->inserted;
10324 const int left_duplicate = left->duplicate;
10325 const struct bp_target_info left_target_info = left->target_info;
10327 left->inserted = right->inserted;
10328 left->duplicate = right->duplicate;
10329 left->target_info = right->target_info;
10330 right->inserted = left_inserted;
10331 right->duplicate = left_duplicate;
10332 right->target_info = left_target_info;
10335 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10336 into the inferior, only remove already-inserted locations that no
10337 longer should be inserted. Functions that delete a breakpoint or
10338 breakpoints should pass false, so that deleting a breakpoint
10339 doesn't have the side effect of inserting the locations of other
10340 breakpoints that are marked not-inserted, but should_be_inserted
10341 returns true on them.
10343 This behaviour is useful is situations close to tear-down -- e.g.,
10344 after an exec, while the target still has execution, but breakpoint
10345 shadows of the previous executable image should *NOT* be restored
10346 to the new image; or before detaching, where the target still has
10347 execution and wants to delete breakpoints from GDB's lists, and all
10348 breakpoints had already been removed from the inferior. */
10351 update_global_location_list (int should_insert)
10353 struct breakpoint *b;
10354 struct bp_location **locp, *loc;
10355 struct cleanup *cleanups;
10357 /* Used in the duplicates detection below. When iterating over all
10358 bp_locations, points to the first bp_location of a given address.
10359 Breakpoints and watchpoints of different types are never
10360 duplicates of each other. Keep one pointer for each type of
10361 breakpoint/watchpoint, so we only need to loop over all locations
10363 struct bp_location *bp_loc_first; /* breakpoint */
10364 struct bp_location *wp_loc_first; /* hardware watchpoint */
10365 struct bp_location *awp_loc_first; /* access watchpoint */
10366 struct bp_location *rwp_loc_first; /* read watchpoint */
10368 /* Saved former bp_location array which we compare against the newly
10369 built bp_location from the current state of ALL_BREAKPOINTS. */
10370 struct bp_location **old_location, **old_locp;
10371 unsigned old_location_count;
10373 old_location = bp_location;
10374 old_location_count = bp_location_count;
10375 bp_location = NULL;
10376 bp_location_count = 0;
10377 cleanups = make_cleanup (xfree, old_location);
10379 ALL_BREAKPOINTS (b)
10380 for (loc = b->loc; loc; loc = loc->next)
10381 bp_location_count++;
10383 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
10384 locp = bp_location;
10385 ALL_BREAKPOINTS (b)
10386 for (loc = b->loc; loc; loc = loc->next)
10388 qsort (bp_location, bp_location_count, sizeof (*bp_location),
10389 bp_location_compare);
10391 bp_location_target_extensions_update ();
10393 /* Identify bp_location instances that are no longer present in the
10394 new list, and therefore should be freed. Note that it's not
10395 necessary that those locations should be removed from inferior --
10396 if there's another location at the same address (previously
10397 marked as duplicate), we don't need to remove/insert the
10400 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10401 and former bp_location array state respectively. */
10403 locp = bp_location;
10404 for (old_locp = old_location; old_locp < old_location + old_location_count;
10407 struct bp_location *old_loc = *old_locp;
10408 struct bp_location **loc2p;
10410 /* Tells if 'old_loc' is found among the new locations. If
10411 not, we have to free it. */
10412 int found_object = 0;
10413 /* Tells if the location should remain inserted in the target. */
10414 int keep_in_target = 0;
10417 /* Skip LOCP entries which will definitely never be needed.
10418 Stop either at or being the one matching OLD_LOC. */
10419 while (locp < bp_location + bp_location_count
10420 && (*locp)->address < old_loc->address)
10424 (loc2p < bp_location + bp_location_count
10425 && (*loc2p)->address == old_loc->address);
10428 if (*loc2p == old_loc)
10435 /* If this location is no longer present, and inserted, look if
10436 there's maybe a new location at the same address. If so,
10437 mark that one inserted, and don't remove this one. This is
10438 needed so that we don't have a time window where a breakpoint
10439 at certain location is not inserted. */
10441 if (old_loc->inserted)
10443 /* If the location is inserted now, we might have to remove
10446 if (found_object && should_be_inserted (old_loc))
10448 /* The location is still present in the location list,
10449 and still should be inserted. Don't do anything. */
10450 keep_in_target = 1;
10454 /* The location is either no longer present, or got
10455 disabled. See if there's another location at the
10456 same address, in which case we don't need to remove
10457 this one from the target. */
10459 /* OLD_LOC comes from existing struct breakpoint. */
10460 if (breakpoint_address_is_meaningful (old_loc->owner))
10463 (loc2p < bp_location + bp_location_count
10464 && (*loc2p)->address == old_loc->address);
10467 struct bp_location *loc2 = *loc2p;
10469 if (breakpoint_locations_match (loc2, old_loc))
10471 /* Read watchpoint locations are switched to
10472 access watchpoints, if the former are not
10473 supported, but the latter are. */
10474 if (is_hardware_watchpoint (old_loc->owner))
10476 gdb_assert (is_hardware_watchpoint (loc2->owner));
10477 loc2->watchpoint_type = old_loc->watchpoint_type;
10480 /* loc2 is a duplicated location. We need to check
10481 if it should be inserted in case it will be
10483 if (loc2 != old_loc
10484 && unduplicated_should_be_inserted (loc2))
10486 swap_insertion (old_loc, loc2);
10487 keep_in_target = 1;
10495 if (!keep_in_target)
10497 if (remove_breakpoint (old_loc, mark_uninserted))
10499 /* This is just about all we can do. We could keep
10500 this location on the global list, and try to
10501 remove it next time, but there's no particular
10502 reason why we will succeed next time.
10504 Note that at this point, old_loc->owner is still
10505 valid, as delete_breakpoint frees the breakpoint
10506 only after calling us. */
10507 printf_filtered (_("warning: Error removing "
10508 "breakpoint %d\n"),
10509 old_loc->owner->number);
10517 if (removed && non_stop
10518 && breakpoint_address_is_meaningful (old_loc->owner)
10519 && !is_hardware_watchpoint (old_loc->owner))
10521 /* This location was removed from the target. In
10522 non-stop mode, a race condition is possible where
10523 we've removed a breakpoint, but stop events for that
10524 breakpoint are already queued and will arrive later.
10525 We apply an heuristic to be able to distinguish such
10526 SIGTRAPs from other random SIGTRAPs: we keep this
10527 breakpoint location for a bit, and will retire it
10528 after we see some number of events. The theory here
10529 is that reporting of events should, "on the average",
10530 be fair, so after a while we'll see events from all
10531 threads that have anything of interest, and no longer
10532 need to keep this breakpoint location around. We
10533 don't hold locations forever so to reduce chances of
10534 mistaking a non-breakpoint SIGTRAP for a breakpoint
10537 The heuristic failing can be disastrous on
10538 decr_pc_after_break targets.
10540 On decr_pc_after_break targets, like e.g., x86-linux,
10541 if we fail to recognize a late breakpoint SIGTRAP,
10542 because events_till_retirement has reached 0 too
10543 soon, we'll fail to do the PC adjustment, and report
10544 a random SIGTRAP to the user. When the user resumes
10545 the inferior, it will most likely immediately crash
10546 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10547 corrupted, because of being resumed e.g., in the
10548 middle of a multi-byte instruction, or skipped a
10549 one-byte instruction. This was actually seen happen
10550 on native x86-linux, and should be less rare on
10551 targets that do not support new thread events, like
10552 remote, due to the heuristic depending on
10555 Mistaking a random SIGTRAP for a breakpoint trap
10556 causes similar symptoms (PC adjustment applied when
10557 it shouldn't), but then again, playing with SIGTRAPs
10558 behind the debugger's back is asking for trouble.
10560 Since hardware watchpoint traps are always
10561 distinguishable from other traps, so we don't need to
10562 apply keep hardware watchpoint moribund locations
10563 around. We simply always ignore hardware watchpoint
10564 traps we can no longer explain. */
10566 old_loc->events_till_retirement = 3 * (thread_count () + 1);
10567 old_loc->owner = NULL;
10569 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
10573 old_loc->owner = NULL;
10574 decref_bp_location (&old_loc);
10579 /* Rescan breakpoints at the same address and section, marking the
10580 first one as "first" and any others as "duplicates". This is so
10581 that the bpt instruction is only inserted once. If we have a
10582 permanent breakpoint at the same place as BPT, make that one the
10583 official one, and the rest as duplicates. Permanent breakpoints
10584 are sorted first for the same address.
10586 Do the same for hardware watchpoints, but also considering the
10587 watchpoint's type (regular/access/read) and length. */
10589 bp_loc_first = NULL;
10590 wp_loc_first = NULL;
10591 awp_loc_first = NULL;
10592 rwp_loc_first = NULL;
10593 ALL_BP_LOCATIONS (loc, locp)
10595 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10597 struct breakpoint *b = loc->owner;
10598 struct bp_location **loc_first_p;
10600 if (b->enable_state == bp_disabled
10601 || b->enable_state == bp_call_disabled
10602 || b->enable_state == bp_startup_disabled
10604 || loc->shlib_disabled
10605 || !breakpoint_address_is_meaningful (b)
10606 || is_tracepoint (b))
10609 /* Permanent breakpoint should always be inserted. */
10610 if (b->enable_state == bp_permanent && ! loc->inserted)
10611 internal_error (__FILE__, __LINE__,
10612 _("allegedly permanent breakpoint is not "
10613 "actually inserted"));
10615 if (b->type == bp_hardware_watchpoint)
10616 loc_first_p = &wp_loc_first;
10617 else if (b->type == bp_read_watchpoint)
10618 loc_first_p = &rwp_loc_first;
10619 else if (b->type == bp_access_watchpoint)
10620 loc_first_p = &awp_loc_first;
10622 loc_first_p = &bp_loc_first;
10624 if (*loc_first_p == NULL
10625 || (overlay_debugging && loc->section != (*loc_first_p)->section)
10626 || !breakpoint_locations_match (loc, *loc_first_p))
10628 *loc_first_p = loc;
10629 loc->duplicate = 0;
10634 /* This and the above ensure the invariant that the first location
10635 is not duplicated, and is the inserted one.
10636 All following are marked as duplicated, and are not inserted. */
10638 swap_insertion (loc, *loc_first_p);
10639 loc->duplicate = 1;
10641 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
10642 && b->enable_state != bp_permanent)
10643 internal_error (__FILE__, __LINE__,
10644 _("another breakpoint was inserted on top of "
10645 "a permanent breakpoint"));
10648 if (breakpoints_always_inserted_mode () && should_insert
10649 && (have_live_inferiors ()
10650 || (gdbarch_has_global_breakpoints (target_gdbarch))))
10651 insert_breakpoint_locations ();
10653 do_cleanups (cleanups);
10657 breakpoint_retire_moribund (void)
10659 struct bp_location *loc;
10662 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
10663 if (--(loc->events_till_retirement) == 0)
10665 decref_bp_location (&loc);
10666 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
10672 update_global_location_list_nothrow (int inserting)
10674 struct gdb_exception e;
10676 TRY_CATCH (e, RETURN_MASK_ERROR)
10677 update_global_location_list (inserting);
10680 /* Clear BKP from a BPS. */
10683 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
10687 for (bs = bps; bs; bs = bs->next)
10688 if (bs->breakpoint_at == bpt)
10690 bs->breakpoint_at = NULL;
10691 bs->old_val = NULL;
10692 /* bs->commands will be freed later. */
10696 /* Callback for iterate_over_threads. */
10698 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
10700 struct breakpoint *bpt = data;
10702 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
10706 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10710 say_where (struct breakpoint *b)
10712 struct ui_out *uiout = current_uiout;
10713 struct value_print_options opts;
10715 get_user_print_options (&opts);
10717 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10719 if (b->loc == NULL)
10721 printf_filtered (_(" (%s) pending."), b->addr_string);
10725 if (opts.addressprint || b->source_file == NULL)
10727 printf_filtered (" at ");
10728 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
10731 if (b->source_file)
10732 printf_filtered (": file %s, line %d.",
10733 b->source_file, b->line_number);
10737 struct bp_location *loc = b->loc;
10739 for (; loc; loc = loc->next)
10741 printf_filtered (" (%d locations)", n);
10746 /* Default bp_location_ops methods. */
10749 bp_location_dtor (struct bp_location *self)
10751 xfree (self->cond);
10752 xfree (self->function_name);
10755 static const struct bp_location_ops bp_location_ops =
10760 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10764 base_breakpoint_dtor (struct breakpoint *self)
10766 decref_counted_command_line (&self->commands);
10767 xfree (self->cond_string);
10768 xfree (self->addr_string);
10769 xfree (self->addr_string_range_end);
10770 xfree (self->source_file);
10773 static struct bp_location *
10774 base_breakpoint_allocate_location (struct breakpoint *self)
10776 struct bp_location *loc;
10778 loc = XNEW (struct bp_location);
10779 init_bp_location (loc, &bp_location_ops, self);
10784 base_breakpoint_re_set (struct breakpoint *b)
10786 /* Nothing to re-set. */
10789 #define internal_error_pure_virtual_called() \
10790 gdb_assert_not_reached ("pure virtual function called")
10793 base_breakpoint_insert_location (struct bp_location *bl)
10795 internal_error_pure_virtual_called ();
10799 base_breakpoint_remove_location (struct bp_location *bl)
10801 internal_error_pure_virtual_called ();
10805 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
10806 struct address_space *aspace,
10809 internal_error_pure_virtual_called ();
10813 base_breakpoint_check_status (bpstat bs)
10818 /* A "works_in_software_mode" breakpoint_ops method that just internal
10822 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
10824 internal_error_pure_virtual_called ();
10827 /* A "resources_needed" breakpoint_ops method that just internal
10831 base_breakpoint_resources_needed (const struct bp_location *bl)
10833 internal_error_pure_virtual_called ();
10836 static enum print_stop_action
10837 base_breakpoint_print_it (bpstat bs)
10839 internal_error_pure_virtual_called ();
10843 base_breakpoint_print_one_detail (const struct breakpoint *self,
10844 struct ui_out *uiout)
10850 base_breakpoint_print_mention (struct breakpoint *b)
10852 internal_error_pure_virtual_called ();
10856 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
10858 internal_error_pure_virtual_called ();
10861 static struct breakpoint_ops base_breakpoint_ops =
10863 base_breakpoint_dtor,
10864 base_breakpoint_allocate_location,
10865 base_breakpoint_re_set,
10866 base_breakpoint_insert_location,
10867 base_breakpoint_remove_location,
10868 base_breakpoint_breakpoint_hit,
10869 base_breakpoint_check_status,
10870 base_breakpoint_resources_needed,
10871 base_breakpoint_works_in_software_mode,
10872 base_breakpoint_print_it,
10874 base_breakpoint_print_one_detail,
10875 base_breakpoint_print_mention,
10876 base_breakpoint_print_recreate
10879 /* Default breakpoint_ops methods. */
10882 bkpt_re_set (struct breakpoint *b)
10884 /* Do not attempt to re-set breakpoints disabled during startup. */
10885 if (b->enable_state == bp_startup_disabled)
10888 /* FIXME: is this still reachable? */
10889 if (b->addr_string == NULL)
10891 /* Anything without a string can't be re-set. */
10892 delete_breakpoint (b);
10896 breakpoint_re_set_default (b);
10900 bkpt_insert_location (struct bp_location *bl)
10902 if (bl->loc_type == bp_loc_hardware_breakpoint)
10903 return target_insert_hw_breakpoint (bl->gdbarch,
10906 return target_insert_breakpoint (bl->gdbarch,
10911 bkpt_remove_location (struct bp_location *bl)
10913 if (bl->loc_type == bp_loc_hardware_breakpoint)
10914 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
10916 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
10920 bkpt_breakpoint_hit (const struct bp_location *bl,
10921 struct address_space *aspace, CORE_ADDR bp_addr)
10923 struct breakpoint *b = bl->owner;
10925 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
10929 if (overlay_debugging /* unmapped overlay section */
10930 && section_is_overlay (bl->section)
10931 && !section_is_mapped (bl->section))
10938 bkpt_resources_needed (const struct bp_location *bl)
10940 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
10945 static enum print_stop_action
10946 bkpt_print_it (bpstat bs)
10948 struct breakpoint *b;
10949 const struct bp_location *bl;
10951 struct ui_out *uiout = current_uiout;
10953 gdb_assert (bs->bp_location_at != NULL);
10955 bl = bs->bp_location_at;
10956 b = bs->breakpoint_at;
10958 bp_temp = b->disposition == disp_del;
10959 if (bl->address != bl->requested_address)
10960 breakpoint_adjustment_warning (bl->requested_address,
10963 annotate_breakpoint (b->number);
10965 ui_out_text (uiout, "\nTemporary breakpoint ");
10967 ui_out_text (uiout, "\nBreakpoint ");
10968 if (ui_out_is_mi_like_p (uiout))
10970 ui_out_field_string (uiout, "reason",
10971 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10972 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10974 ui_out_field_int (uiout, "bkptno", b->number);
10975 ui_out_text (uiout, ", ");
10977 return PRINT_SRC_AND_LOC;
10981 bkpt_print_mention (struct breakpoint *b)
10983 if (ui_out_is_mi_like_p (current_uiout))
10988 case bp_breakpoint:
10989 case bp_gnu_ifunc_resolver:
10990 if (b->disposition == disp_del)
10991 printf_filtered (_("Temporary breakpoint"));
10993 printf_filtered (_("Breakpoint"));
10994 printf_filtered (_(" %d"), b->number);
10995 if (b->type == bp_gnu_ifunc_resolver)
10996 printf_filtered (_(" at gnu-indirect-function resolver"));
10998 case bp_hardware_breakpoint:
10999 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
11007 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
11009 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11010 fprintf_unfiltered (fp, "tbreak");
11011 else if (tp->type == bp_breakpoint)
11012 fprintf_unfiltered (fp, "break");
11013 else if (tp->type == bp_hardware_breakpoint
11014 && tp->disposition == disp_del)
11015 fprintf_unfiltered (fp, "thbreak");
11016 else if (tp->type == bp_hardware_breakpoint)
11017 fprintf_unfiltered (fp, "hbreak");
11019 internal_error (__FILE__, __LINE__,
11020 _("unhandled breakpoint type %d"), (int) tp->type);
11022 fprintf_unfiltered (fp, " %s", tp->addr_string);
11023 print_recreate_thread (tp, fp);
11026 /* Virtual table for internal breakpoints. */
11029 internal_bkpt_re_set (struct breakpoint *b)
11033 /* Delete overlay event and longjmp master breakpoints; they
11034 will be reset later by breakpoint_re_set. */
11035 case bp_overlay_event:
11036 case bp_longjmp_master:
11037 case bp_std_terminate_master:
11038 case bp_exception_master:
11039 delete_breakpoint (b);
11042 /* This breakpoint is special, it's set up when the inferior
11043 starts and we really don't want to touch it. */
11044 case bp_shlib_event:
11046 /* Like bp_shlib_event, this breakpoint type is special. Once
11047 it is set up, we do not want to touch it. */
11048 case bp_thread_event:
11054 internal_bkpt_check_status (bpstat bs)
11056 /* We do not stop for these. */
11060 static enum print_stop_action
11061 internal_bkpt_print_it (bpstat bs)
11063 struct breakpoint *b;
11065 b = bs->breakpoint_at;
11069 case bp_shlib_event:
11070 /* Did we stop because the user set the stop_on_solib_events
11071 variable? (If so, we report this as a generic, "Stopped due
11072 to shlib event" message.) */
11073 printf_filtered (_("Stopped due to shared library event\n"));
11076 case bp_thread_event:
11077 /* Not sure how we will get here.
11078 GDB should not stop for these breakpoints. */
11079 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11082 case bp_overlay_event:
11083 /* By analogy with the thread event, GDB should not stop for these. */
11084 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11087 case bp_longjmp_master:
11088 /* These should never be enabled. */
11089 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11092 case bp_std_terminate_master:
11093 /* These should never be enabled. */
11094 printf_filtered (_("std::terminate Master Breakpoint: "
11095 "gdb should not stop!\n"));
11098 case bp_exception_master:
11099 /* These should never be enabled. */
11100 printf_filtered (_("Exception Master Breakpoint: "
11101 "gdb should not stop!\n"));
11105 return PRINT_NOTHING;
11109 internal_bkpt_print_mention (struct breakpoint *b)
11111 /* Nothing to mention. These breakpoints are internal. */
11114 /* Virtual table for momentary breakpoints */
11117 momentary_bkpt_re_set (struct breakpoint *b)
11119 /* Keep temporary breakpoints, which can be encountered when we step
11120 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11121 Otherwise these should have been blown away via the cleanup chain
11122 or by breakpoint_init_inferior when we rerun the executable. */
11126 momentary_bkpt_check_status (bpstat bs)
11128 /* Nothing. The point of these breakpoints is causing a stop. */
11131 static enum print_stop_action
11132 momentary_bkpt_print_it (bpstat bs)
11134 struct ui_out *uiout = current_uiout;
11136 if (ui_out_is_mi_like_p (uiout))
11138 struct breakpoint *b = bs->breakpoint_at;
11143 ui_out_field_string
11145 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
11149 ui_out_field_string
11151 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
11156 return PRINT_UNKNOWN;
11160 momentary_bkpt_print_mention (struct breakpoint *b)
11162 /* Nothing to mention. These breakpoints are internal. */
11165 /* The breakpoint_ops structure to be used in tracepoints. */
11168 tracepoint_re_set (struct breakpoint *b)
11170 breakpoint_re_set_default (b);
11174 tracepoint_breakpoint_hit (const struct bp_location *bl,
11175 struct address_space *aspace, CORE_ADDR bp_addr)
11177 /* By definition, the inferior does not report stops at
11183 tracepoint_print_one_detail (const struct breakpoint *self,
11184 struct ui_out *uiout)
11186 struct tracepoint *tp = (struct tracepoint *) self;
11187 if (tp->static_trace_marker_id)
11189 gdb_assert (self->type == bp_static_tracepoint);
11191 ui_out_text (uiout, "\tmarker id is ");
11192 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
11193 tp->static_trace_marker_id);
11194 ui_out_text (uiout, "\n");
11199 tracepoint_print_mention (struct breakpoint *b)
11201 if (ui_out_is_mi_like_p (current_uiout))
11206 case bp_tracepoint:
11207 printf_filtered (_("Tracepoint"));
11208 printf_filtered (_(" %d"), b->number);
11210 case bp_fast_tracepoint:
11211 printf_filtered (_("Fast tracepoint"));
11212 printf_filtered (_(" %d"), b->number);
11214 case bp_static_tracepoint:
11215 printf_filtered (_("Static tracepoint"));
11216 printf_filtered (_(" %d"), b->number);
11219 internal_error (__FILE__, __LINE__,
11220 _("unhandled tracepoint type %d"), (int) b->type);
11227 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
11229 struct tracepoint *tp = (struct tracepoint *) self;
11231 if (self->type == bp_fast_tracepoint)
11232 fprintf_unfiltered (fp, "ftrace");
11233 if (self->type == bp_static_tracepoint)
11234 fprintf_unfiltered (fp, "strace");
11235 else if (self->type == bp_tracepoint)
11236 fprintf_unfiltered (fp, "trace");
11238 internal_error (__FILE__, __LINE__,
11239 _("unhandled tracepoint type %d"), (int) self->type);
11241 fprintf_unfiltered (fp, " %s", self->addr_string);
11242 print_recreate_thread (self, fp);
11244 if (tp->pass_count)
11245 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11248 struct breakpoint_ops tracepoint_breakpoint_ops;
11250 /* Delete a breakpoint and clean up all traces of it in the data
11254 delete_breakpoint (struct breakpoint *bpt)
11256 struct breakpoint *b;
11258 gdb_assert (bpt != NULL);
11260 /* Has this bp already been deleted? This can happen because
11261 multiple lists can hold pointers to bp's. bpstat lists are
11264 One example of this happening is a watchpoint's scope bp. When
11265 the scope bp triggers, we notice that the watchpoint is out of
11266 scope, and delete it. We also delete its scope bp. But the
11267 scope bp is marked "auto-deleting", and is already on a bpstat.
11268 That bpstat is then checked for auto-deleting bp's, which are
11271 A real solution to this problem might involve reference counts in
11272 bp's, and/or giving them pointers back to their referencing
11273 bpstat's, and teaching delete_breakpoint to only free a bp's
11274 storage when no more references were extent. A cheaper bandaid
11276 if (bpt->type == bp_none)
11279 /* At least avoid this stale reference until the reference counting
11280 of breakpoints gets resolved. */
11281 if (bpt->related_breakpoint != bpt)
11283 struct breakpoint *related;
11284 struct watchpoint *w;
11286 if (bpt->type == bp_watchpoint_scope)
11287 w = (struct watchpoint *) bpt->related_breakpoint;
11288 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
11289 w = (struct watchpoint *) bpt;
11293 watchpoint_del_at_next_stop (w);
11295 /* Unlink bpt from the bpt->related_breakpoint ring. */
11296 for (related = bpt; related->related_breakpoint != bpt;
11297 related = related->related_breakpoint);
11298 related->related_breakpoint = bpt->related_breakpoint;
11299 bpt->related_breakpoint = bpt;
11302 /* watch_command_1 creates a watchpoint but only sets its number if
11303 update_watchpoint succeeds in creating its bp_locations. If there's
11304 a problem in that process, we'll be asked to delete the half-created
11305 watchpoint. In that case, don't announce the deletion. */
11307 observer_notify_breakpoint_deleted (bpt);
11309 if (breakpoint_chain == bpt)
11310 breakpoint_chain = bpt->next;
11312 ALL_BREAKPOINTS (b)
11313 if (b->next == bpt)
11315 b->next = bpt->next;
11319 /* Be sure no bpstat's are pointing at the breakpoint after it's
11321 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11322 in all threads for now. Note that we cannot just remove bpstats
11323 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11324 commands are associated with the bpstat; if we remove it here,
11325 then the later call to bpstat_do_actions (&stop_bpstat); in
11326 event-top.c won't do anything, and temporary breakpoints with
11327 commands won't work. */
11329 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
11331 /* Now that breakpoint is removed from breakpoint list, update the
11332 global location list. This will remove locations that used to
11333 belong to this breakpoint. Do this before freeing the breakpoint
11334 itself, since remove_breakpoint looks at location's owner. It
11335 might be better design to have location completely
11336 self-contained, but it's not the case now. */
11337 update_global_location_list (0);
11339 bpt->ops->dtor (bpt);
11340 /* On the chance that someone will soon try again to delete this
11341 same bp, we mark it as deleted before freeing its storage. */
11342 bpt->type = bp_none;
11347 do_delete_breakpoint_cleanup (void *b)
11349 delete_breakpoint (b);
11353 make_cleanup_delete_breakpoint (struct breakpoint *b)
11355 return make_cleanup (do_delete_breakpoint_cleanup, b);
11358 /* Iterator function to call a user-provided callback function once
11359 for each of B and its related breakpoints. */
11362 iterate_over_related_breakpoints (struct breakpoint *b,
11363 void (*function) (struct breakpoint *,
11367 struct breakpoint *related;
11372 struct breakpoint *next;
11374 /* FUNCTION may delete RELATED. */
11375 next = related->related_breakpoint;
11377 if (next == related)
11379 /* RELATED is the last ring entry. */
11380 function (related, data);
11382 /* FUNCTION may have deleted it, so we'd never reach back to
11383 B. There's nothing left to do anyway, so just break
11388 function (related, data);
11392 while (related != b);
11396 do_delete_breakpoint (struct breakpoint *b, void *ignore)
11398 delete_breakpoint (b);
11401 /* A callback for map_breakpoint_numbers that calls
11402 delete_breakpoint. */
11405 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
11407 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
11411 delete_command (char *arg, int from_tty)
11413 struct breakpoint *b, *b_tmp;
11419 int breaks_to_delete = 0;
11421 /* Delete all breakpoints if no argument. Do not delete
11422 internal breakpoints, these have to be deleted with an
11423 explicit breakpoint number argument. */
11424 ALL_BREAKPOINTS (b)
11425 if (user_breakpoint_p (b))
11427 breaks_to_delete = 1;
11431 /* Ask user only if there are some breakpoints to delete. */
11433 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
11435 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11436 if (user_breakpoint_p (b))
11437 delete_breakpoint (b);
11441 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
11445 all_locations_are_pending (struct bp_location *loc)
11447 for (; loc; loc = loc->next)
11448 if (!loc->shlib_disabled)
11453 /* Subroutine of update_breakpoint_locations to simplify it.
11454 Return non-zero if multiple fns in list LOC have the same name.
11455 Null names are ignored. */
11458 ambiguous_names_p (struct bp_location *loc)
11460 struct bp_location *l;
11461 htab_t htab = htab_create_alloc (13, htab_hash_string,
11462 (int (*) (const void *,
11463 const void *)) streq,
11464 NULL, xcalloc, xfree);
11466 for (l = loc; l != NULL; l = l->next)
11469 const char *name = l->function_name;
11471 /* Allow for some names to be NULL, ignore them. */
11475 slot = (const char **) htab_find_slot (htab, (const void *) name,
11477 /* NOTE: We can assume slot != NULL here because xcalloc never
11481 htab_delete (htab);
11487 htab_delete (htab);
11491 /* When symbols change, it probably means the sources changed as well,
11492 and it might mean the static tracepoint markers are no longer at
11493 the same address or line numbers they used to be at last we
11494 checked. Losing your static tracepoints whenever you rebuild is
11495 undesirable. This function tries to resync/rematch gdb static
11496 tracepoints with the markers on the target, for static tracepoints
11497 that have not been set by marker id. Static tracepoint that have
11498 been set by marker id are reset by marker id in breakpoint_re_set.
11501 1) For a tracepoint set at a specific address, look for a marker at
11502 the old PC. If one is found there, assume to be the same marker.
11503 If the name / string id of the marker found is different from the
11504 previous known name, assume that means the user renamed the marker
11505 in the sources, and output a warning.
11507 2) For a tracepoint set at a given line number, look for a marker
11508 at the new address of the old line number. If one is found there,
11509 assume to be the same marker. If the name / string id of the
11510 marker found is different from the previous known name, assume that
11511 means the user renamed the marker in the sources, and output a
11514 3) If a marker is no longer found at the same address or line, it
11515 may mean the marker no longer exists. But it may also just mean
11516 the code changed a bit. Maybe the user added a few lines of code
11517 that made the marker move up or down (in line number terms). Ask
11518 the target for info about the marker with the string id as we knew
11519 it. If found, update line number and address in the matching
11520 static tracepoint. This will get confused if there's more than one
11521 marker with the same ID (possible in UST, although unadvised
11522 precisely because it confuses tools). */
11524 static struct symtab_and_line
11525 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
11527 struct tracepoint *tp = (struct tracepoint *) b;
11528 struct static_tracepoint_marker marker;
11534 find_line_pc (sal.symtab, sal.line, &pc);
11536 if (target_static_tracepoint_marker_at (pc, &marker))
11538 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
11539 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11541 tp->static_trace_marker_id, marker.str_id);
11543 xfree (tp->static_trace_marker_id);
11544 tp->static_trace_marker_id = xstrdup (marker.str_id);
11545 release_static_tracepoint_marker (&marker);
11550 /* Old marker wasn't found on target at lineno. Try looking it up
11552 if (!sal.explicit_pc
11554 && sal.symtab != NULL
11555 && tp->static_trace_marker_id != NULL)
11557 VEC(static_tracepoint_marker_p) *markers;
11560 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
11562 if (!VEC_empty(static_tracepoint_marker_p, markers))
11564 struct symtab_and_line sal;
11565 struct symbol *sym;
11566 struct static_tracepoint_marker *marker;
11567 struct ui_out *uiout = current_uiout;
11569 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
11571 xfree (tp->static_trace_marker_id);
11572 tp->static_trace_marker_id = xstrdup (marker->str_id);
11574 warning (_("marker for static tracepoint %d (%s) not "
11575 "found at previous line number"),
11576 b->number, tp->static_trace_marker_id);
11580 sal.pc = marker->address;
11582 sal = find_pc_line (marker->address, 0);
11583 sym = find_pc_sect_function (marker->address, NULL);
11584 ui_out_text (uiout, "Now in ");
11587 ui_out_field_string (uiout, "func",
11588 SYMBOL_PRINT_NAME (sym));
11589 ui_out_text (uiout, " at ");
11591 ui_out_field_string (uiout, "file", sal.symtab->filename);
11592 ui_out_text (uiout, ":");
11594 if (ui_out_is_mi_like_p (uiout))
11596 char *fullname = symtab_to_fullname (sal.symtab);
11599 ui_out_field_string (uiout, "fullname", fullname);
11602 ui_out_field_int (uiout, "line", sal.line);
11603 ui_out_text (uiout, "\n");
11605 b->line_number = sal.line;
11607 xfree (b->source_file);
11609 b->source_file = xstrdup (sal.symtab->filename);
11611 b->source_file = NULL;
11613 xfree (b->addr_string);
11614 b->addr_string = xstrprintf ("%s:%d",
11615 sal.symtab->filename, b->line_number);
11617 /* Might be nice to check if function changed, and warn if
11620 release_static_tracepoint_marker (marker);
11626 /* Returns 1 iff locations A and B are sufficiently same that
11627 we don't need to report breakpoint as changed. */
11630 locations_are_equal (struct bp_location *a, struct bp_location *b)
11634 if (a->address != b->address)
11637 if (a->shlib_disabled != b->shlib_disabled)
11640 if (a->enabled != b->enabled)
11647 if ((a == NULL) != (b == NULL))
11653 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11654 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11655 a ranged breakpoint. */
11658 update_breakpoint_locations (struct breakpoint *b,
11659 struct symtabs_and_lines sals,
11660 struct symtabs_and_lines sals_end)
11663 struct bp_location *existing_locations = b->loc;
11665 /* Ranged breakpoints have only one start location and one end location. */
11666 gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1));
11668 /* If there's no new locations, and all existing locations are
11669 pending, don't do anything. This optimizes the common case where
11670 all locations are in the same shared library, that was unloaded.
11671 We'd like to retain the location, so that when the library is
11672 loaded again, we don't loose the enabled/disabled status of the
11673 individual locations. */
11674 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
11679 for (i = 0; i < sals.nelts; ++i)
11681 struct bp_location *new_loc =
11682 add_location_to_breakpoint (b, &(sals.sals[i]));
11684 /* Reparse conditions, they might contain references to the
11686 if (b->cond_string != NULL)
11689 struct gdb_exception e;
11691 s = b->cond_string;
11692 TRY_CATCH (e, RETURN_MASK_ERROR)
11694 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
11699 warning (_("failed to reevaluate condition "
11700 "for breakpoint %d: %s"),
11701 b->number, e.message);
11702 new_loc->enabled = 0;
11706 if (b->source_file != NULL)
11707 xfree (b->source_file);
11708 if (sals.sals[i].symtab == NULL)
11709 b->source_file = NULL;
11711 b->source_file = xstrdup (sals.sals[i].symtab->filename);
11713 if (b->line_number == 0)
11714 b->line_number = sals.sals[i].line;
11716 if (sals_end.nelts)
11718 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
11720 new_loc->length = end - sals.sals[0].pc + 1;
11724 /* Update locations of permanent breakpoints. */
11725 if (b->enable_state == bp_permanent)
11726 make_breakpoint_permanent (b);
11728 /* If possible, carry over 'disable' status from existing
11731 struct bp_location *e = existing_locations;
11732 /* If there are multiple breakpoints with the same function name,
11733 e.g. for inline functions, comparing function names won't work.
11734 Instead compare pc addresses; this is just a heuristic as things
11735 may have moved, but in practice it gives the correct answer
11736 often enough until a better solution is found. */
11737 int have_ambiguous_names = ambiguous_names_p (b->loc);
11739 for (; e; e = e->next)
11741 if (!e->enabled && e->function_name)
11743 struct bp_location *l = b->loc;
11744 if (have_ambiguous_names)
11746 for (; l; l = l->next)
11747 if (breakpoint_locations_match (e, l))
11755 for (; l; l = l->next)
11756 if (l->function_name
11757 && strcmp (e->function_name, l->function_name) == 0)
11767 if (!locations_are_equal (existing_locations, b->loc))
11768 observer_notify_breakpoint_modified (b);
11770 update_global_location_list (1);
11773 /* Find the SaL locations corresponding to the given ADDR_STRING.
11774 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11776 static struct symtabs_and_lines
11777 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
11781 struct symtabs_and_lines sals = {0};
11782 struct gdb_exception e;
11785 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
11787 TRY_CATCH (e, RETURN_MASK_ERROR)
11791 struct tracepoint *tp = (struct tracepoint *) b;
11793 sals = decode_static_tracepoint_spec (&s);
11794 if (sals.nelts > tp->static_trace_marker_id_idx)
11796 sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx];
11800 error (_("marker %s not found"), tp->static_trace_marker_id);
11803 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL);
11807 int not_found_and_ok = 0;
11808 /* For pending breakpoints, it's expected that parsing will
11809 fail until the right shared library is loaded. User has
11810 already told to create pending breakpoints and don't need
11811 extra messages. If breakpoint is in bp_shlib_disabled
11812 state, then user already saw the message about that
11813 breakpoint being disabled, and don't want to see more
11815 if (e.error == NOT_FOUND_ERROR
11816 && (b->condition_not_parsed
11817 || (b->loc && b->loc->shlib_disabled)
11818 || b->enable_state == bp_disabled))
11819 not_found_and_ok = 1;
11821 if (!not_found_and_ok)
11823 /* We surely don't want to warn about the same breakpoint
11824 10 times. One solution, implemented here, is disable
11825 the breakpoint on error. Another solution would be to
11826 have separate 'warning emitted' flag. Since this
11827 happens only when a binary has changed, I don't know
11828 which approach is better. */
11829 b->enable_state = bp_disabled;
11830 throw_exception (e);
11834 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
11836 gdb_assert (sals.nelts == 1);
11838 resolve_sal_pc (&sals.sals[0]);
11839 if (b->condition_not_parsed && s && s[0])
11841 char *cond_string = 0;
11845 find_condition_and_thread (s, sals.sals[0].pc,
11846 &cond_string, &thread, &task);
11848 b->cond_string = cond_string;
11849 b->thread = thread;
11851 b->condition_not_parsed = 0;
11854 if (b->type == bp_static_tracepoint && !marker_spec)
11855 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
11865 /* The default re_set method, for typical hardware or software
11866 breakpoints. Reevaluate the breakpoint and recreate its
11870 breakpoint_re_set_default (struct breakpoint *b)
11873 struct symtabs_and_lines sals, sals_end;
11874 struct symtabs_and_lines expanded = {0};
11875 struct symtabs_and_lines expanded_end = {0};
11877 sals = addr_string_to_sals (b, b->addr_string, &found);
11880 make_cleanup (xfree, sals.sals);
11881 expanded = expand_line_sal_maybe (sals.sals[0]);
11884 if (b->addr_string_range_end)
11886 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
11889 make_cleanup (xfree, sals_end.sals);
11890 expanded_end = expand_line_sal_maybe (sals_end.sals[0]);
11894 update_breakpoint_locations (b, expanded, expanded_end);
11897 /* Prepare the global context for a re-set of breakpoint B. */
11899 static struct cleanup *
11900 prepare_re_set_context (struct breakpoint *b)
11902 struct cleanup *cleanups;
11904 input_radix = b->input_radix;
11905 cleanups = save_current_space_and_thread ();
11906 switch_to_program_space_and_thread (b->pspace);
11907 set_language (b->language);
11912 /* Reset a breakpoint given it's struct breakpoint * BINT.
11913 The value we return ends up being the return value from catch_errors.
11914 Unused in this case. */
11917 breakpoint_re_set_one (void *bint)
11919 /* Get past catch_errs. */
11920 struct breakpoint *b = (struct breakpoint *) bint;
11921 struct cleanup *cleanups;
11923 cleanups = prepare_re_set_context (b);
11924 b->ops->re_set (b);
11925 do_cleanups (cleanups);
11929 /* Re-set all breakpoints after symbols have been re-loaded. */
11931 breakpoint_re_set (void)
11933 struct breakpoint *b, *b_tmp;
11934 enum language save_language;
11935 int save_input_radix;
11936 struct cleanup *old_chain;
11938 save_language = current_language->la_language;
11939 save_input_radix = input_radix;
11940 old_chain = save_current_program_space ();
11942 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11944 /* Format possible error msg. */
11945 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
11947 struct cleanup *cleanups = make_cleanup (xfree, message);
11948 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
11949 do_cleanups (cleanups);
11951 set_language (save_language);
11952 input_radix = save_input_radix;
11954 jit_breakpoint_re_set ();
11956 do_cleanups (old_chain);
11958 create_overlay_event_breakpoint ();
11959 create_longjmp_master_breakpoint ();
11960 create_std_terminate_master_breakpoint ();
11961 create_exception_master_breakpoint ();
11963 /* While we're at it, reset the skip list too. */
11967 /* Reset the thread number of this breakpoint:
11969 - If the breakpoint is for all threads, leave it as-is.
11970 - Else, reset it to the current thread for inferior_ptid. */
11972 breakpoint_re_set_thread (struct breakpoint *b)
11974 if (b->thread != -1)
11976 if (in_thread_list (inferior_ptid))
11977 b->thread = pid_to_thread_id (inferior_ptid);
11979 /* We're being called after following a fork. The new fork is
11980 selected as current, and unless this was a vfork will have a
11981 different program space from the original thread. Reset that
11983 b->loc->pspace = current_program_space;
11987 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11988 If from_tty is nonzero, it prints a message to that effect,
11989 which ends with a period (no newline). */
11992 set_ignore_count (int bptnum, int count, int from_tty)
11994 struct breakpoint *b;
11999 ALL_BREAKPOINTS (b)
12000 if (b->number == bptnum)
12002 if (is_tracepoint (b))
12004 if (from_tty && count != 0)
12005 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12010 b->ignore_count = count;
12014 printf_filtered (_("Will stop next time "
12015 "breakpoint %d is reached."),
12017 else if (count == 1)
12018 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12021 printf_filtered (_("Will ignore next %d "
12022 "crossings of breakpoint %d."),
12025 breakpoints_changed ();
12026 observer_notify_breakpoint_modified (b);
12030 error (_("No breakpoint number %d."), bptnum);
12033 /* Command to set ignore-count of breakpoint N to COUNT. */
12036 ignore_command (char *args, int from_tty)
12042 error_no_arg (_("a breakpoint number"));
12044 num = get_number (&p);
12046 error (_("bad breakpoint number: '%s'"), args);
12048 error (_("Second argument (specified ignore-count) is missing."));
12050 set_ignore_count (num,
12051 longest_to_int (value_as_long (parse_and_eval (p))),
12054 printf_filtered ("\n");
12057 /* Call FUNCTION on each of the breakpoints
12058 whose numbers are given in ARGS. */
12061 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
12066 struct breakpoint *b, *tmp;
12068 struct get_number_or_range_state state;
12071 error_no_arg (_("one or more breakpoint numbers"));
12073 init_number_or_range (&state, args);
12075 while (!state.finished)
12077 char *p = state.string;
12081 num = get_number_or_range (&state);
12084 warning (_("bad breakpoint number at or near '%s'"), p);
12088 ALL_BREAKPOINTS_SAFE (b, tmp)
12089 if (b->number == num)
12092 function (b, data);
12096 printf_unfiltered (_("No breakpoint number %d.\n"), num);
12101 static struct bp_location *
12102 find_location_by_number (char *number)
12104 char *dot = strchr (number, '.');
12108 struct breakpoint *b;
12109 struct bp_location *loc;
12114 bp_num = get_number (&p1);
12116 error (_("Bad breakpoint number '%s'"), number);
12118 ALL_BREAKPOINTS (b)
12119 if (b->number == bp_num)
12124 if (!b || b->number != bp_num)
12125 error (_("Bad breakpoint number '%s'"), number);
12128 loc_num = get_number (&p1);
12130 error (_("Bad breakpoint location number '%s'"), number);
12134 for (;loc_num && loc; --loc_num, loc = loc->next)
12137 error (_("Bad breakpoint location number '%s'"), dot+1);
12143 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12144 If from_tty is nonzero, it prints a message to that effect,
12145 which ends with a period (no newline). */
12148 disable_breakpoint (struct breakpoint *bpt)
12150 /* Never disable a watchpoint scope breakpoint; we want to
12151 hit them when we leave scope so we can delete both the
12152 watchpoint and its scope breakpoint at that time. */
12153 if (bpt->type == bp_watchpoint_scope)
12156 /* You can't disable permanent breakpoints. */
12157 if (bpt->enable_state == bp_permanent)
12160 bpt->enable_state = bp_disabled;
12162 if (target_supports_enable_disable_tracepoint ()
12163 && current_trace_status ()->running && is_tracepoint (bpt))
12165 struct bp_location *location;
12167 for (location = bpt->loc; location; location = location->next)
12168 target_disable_tracepoint (location);
12171 update_global_location_list (0);
12173 observer_notify_breakpoint_modified (bpt);
12176 /* A callback for iterate_over_related_breakpoints. */
12179 do_disable_breakpoint (struct breakpoint *b, void *ignore)
12181 disable_breakpoint (b);
12184 /* A callback for map_breakpoint_numbers that calls
12185 disable_breakpoint. */
12188 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
12190 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
12194 disable_command (char *args, int from_tty)
12198 struct breakpoint *bpt;
12200 ALL_BREAKPOINTS (bpt)
12201 if (user_breakpoint_p (bpt))
12202 disable_breakpoint (bpt);
12204 else if (strchr (args, '.'))
12206 struct bp_location *loc = find_location_by_number (args);
12210 if (target_supports_enable_disable_tracepoint ()
12211 && current_trace_status ()->running && loc->owner
12212 && is_tracepoint (loc->owner))
12213 target_disable_tracepoint (loc);
12215 update_global_location_list (0);
12218 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
12222 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition)
12224 int target_resources_ok;
12226 if (bpt->type == bp_hardware_breakpoint)
12229 i = hw_breakpoint_used_count ();
12230 target_resources_ok =
12231 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
12233 if (target_resources_ok == 0)
12234 error (_("No hardware breakpoint support in the target."));
12235 else if (target_resources_ok < 0)
12236 error (_("Hardware breakpoints used exceeds limit."));
12239 if (is_watchpoint (bpt))
12241 /* Initialize it just to avoid a GCC false warning. */
12242 enum enable_state orig_enable_state = 0;
12243 struct gdb_exception e;
12245 TRY_CATCH (e, RETURN_MASK_ALL)
12247 struct watchpoint *w = (struct watchpoint *) bpt;
12249 orig_enable_state = bpt->enable_state;
12250 bpt->enable_state = bp_enabled;
12251 update_watchpoint (w, 1 /* reparse */);
12255 bpt->enable_state = orig_enable_state;
12256 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
12262 if (bpt->enable_state != bp_permanent)
12263 bpt->enable_state = bp_enabled;
12265 if (target_supports_enable_disable_tracepoint ()
12266 && current_trace_status ()->running && is_tracepoint (bpt))
12268 struct bp_location *location;
12270 for (location = bpt->loc; location; location = location->next)
12271 target_enable_tracepoint (location);
12274 bpt->disposition = disposition;
12275 update_global_location_list (1);
12276 breakpoints_changed ();
12278 observer_notify_breakpoint_modified (bpt);
12283 enable_breakpoint (struct breakpoint *bpt)
12285 enable_breakpoint_disp (bpt, bpt->disposition);
12289 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
12291 enable_breakpoint (bpt);
12294 /* A callback for map_breakpoint_numbers that calls
12295 enable_breakpoint. */
12298 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
12300 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
12303 /* The enable command enables the specified breakpoints (or all defined
12304 breakpoints) so they once again become (or continue to be) effective
12305 in stopping the inferior. */
12308 enable_command (char *args, int from_tty)
12312 struct breakpoint *bpt;
12314 ALL_BREAKPOINTS (bpt)
12315 if (user_breakpoint_p (bpt))
12316 enable_breakpoint (bpt);
12318 else if (strchr (args, '.'))
12320 struct bp_location *loc = find_location_by_number (args);
12324 if (target_supports_enable_disable_tracepoint ()
12325 && current_trace_status ()->running && loc->owner
12326 && is_tracepoint (loc->owner))
12327 target_enable_tracepoint (loc);
12329 update_global_location_list (1);
12332 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
12336 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
12338 enum bpdisp disp = *(enum bpdisp *) arg;
12340 enable_breakpoint_disp (bpt, disp);
12344 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
12346 enum bpdisp disp = disp_disable;
12348 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12352 enable_once_command (char *args, int from_tty)
12354 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
12358 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
12360 enum bpdisp disp = disp_del;
12362 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12366 enable_delete_command (char *args, int from_tty)
12368 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
12372 set_breakpoint_cmd (char *args, int from_tty)
12377 show_breakpoint_cmd (char *args, int from_tty)
12381 /* Invalidate last known value of any hardware watchpoint if
12382 the memory which that value represents has been written to by
12386 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
12387 const bfd_byte *data)
12389 struct breakpoint *bp;
12391 ALL_BREAKPOINTS (bp)
12392 if (bp->enable_state == bp_enabled
12393 && bp->type == bp_hardware_watchpoint)
12395 struct watchpoint *wp = (struct watchpoint *) bp;
12397 if (wp->val_valid && wp->val)
12399 struct bp_location *loc;
12401 for (loc = bp->loc; loc != NULL; loc = loc->next)
12402 if (loc->loc_type == bp_loc_hardware_watchpoint
12403 && loc->address + loc->length > addr
12404 && addr + len > loc->address)
12406 value_free (wp->val);
12414 /* Use the last displayed codepoint's values, or nothing
12415 if they aren't valid. */
12417 struct symtabs_and_lines
12418 decode_line_spec_1 (char *string, int funfirstline)
12420 struct symtabs_and_lines sals;
12423 error (_("Empty line specification."));
12424 if (last_displayed_sal_is_valid ())
12425 sals = decode_line_1 (&string, funfirstline,
12426 get_last_displayed_symtab (),
12427 get_last_displayed_line (),
12430 sals = decode_line_1 (&string, funfirstline,
12431 (struct symtab *) NULL, 0, NULL);
12433 error (_("Junk at end of line specification: %s"), string);
12437 /* Create and insert a raw software breakpoint at PC. Return an
12438 identifier, which should be used to remove the breakpoint later.
12439 In general, places which call this should be using something on the
12440 breakpoint chain instead; this function should be eliminated
12444 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
12445 struct address_space *aspace, CORE_ADDR pc)
12447 struct bp_target_info *bp_tgt;
12449 bp_tgt = XZALLOC (struct bp_target_info);
12451 bp_tgt->placed_address_space = aspace;
12452 bp_tgt->placed_address = pc;
12454 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
12456 /* Could not insert the breakpoint. */
12464 /* Remove a breakpoint BP inserted by
12465 deprecated_insert_raw_breakpoint. */
12468 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
12470 struct bp_target_info *bp_tgt = bp;
12473 ret = target_remove_breakpoint (gdbarch, bp_tgt);
12479 /* One (or perhaps two) breakpoints used for software single
12482 static void *single_step_breakpoints[2];
12483 static struct gdbarch *single_step_gdbarch[2];
12485 /* Create and insert a breakpoint for software single step. */
12488 insert_single_step_breakpoint (struct gdbarch *gdbarch,
12489 struct address_space *aspace,
12494 if (single_step_breakpoints[0] == NULL)
12496 bpt_p = &single_step_breakpoints[0];
12497 single_step_gdbarch[0] = gdbarch;
12501 gdb_assert (single_step_breakpoints[1] == NULL);
12502 bpt_p = &single_step_breakpoints[1];
12503 single_step_gdbarch[1] = gdbarch;
12506 /* NOTE drow/2006-04-11: A future improvement to this function would
12507 be to only create the breakpoints once, and actually put them on
12508 the breakpoint chain. That would let us use set_raw_breakpoint.
12509 We could adjust the addresses each time they were needed. Doing
12510 this requires corresponding changes elsewhere where single step
12511 breakpoints are handled, however. So, for now, we use this. */
12513 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
12514 if (*bpt_p == NULL)
12515 error (_("Could not insert single-step breakpoint at %s"),
12516 paddress (gdbarch, next_pc));
12519 /* Check if the breakpoints used for software single stepping
12520 were inserted or not. */
12523 single_step_breakpoints_inserted (void)
12525 return (single_step_breakpoints[0] != NULL
12526 || single_step_breakpoints[1] != NULL);
12529 /* Remove and delete any breakpoints used for software single step. */
12532 remove_single_step_breakpoints (void)
12534 gdb_assert (single_step_breakpoints[0] != NULL);
12536 /* See insert_single_step_breakpoint for more about this deprecated
12538 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
12539 single_step_breakpoints[0]);
12540 single_step_gdbarch[0] = NULL;
12541 single_step_breakpoints[0] = NULL;
12543 if (single_step_breakpoints[1] != NULL)
12545 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
12546 single_step_breakpoints[1]);
12547 single_step_gdbarch[1] = NULL;
12548 single_step_breakpoints[1] = NULL;
12552 /* Delete software single step breakpoints without removing them from
12553 the inferior. This is intended to be used if the inferior's address
12554 space where they were inserted is already gone, e.g. after exit or
12558 cancel_single_step_breakpoints (void)
12562 for (i = 0; i < 2; i++)
12563 if (single_step_breakpoints[i])
12565 xfree (single_step_breakpoints[i]);
12566 single_step_breakpoints[i] = NULL;
12567 single_step_gdbarch[i] = NULL;
12571 /* Detach software single-step breakpoints from INFERIOR_PTID without
12575 detach_single_step_breakpoints (void)
12579 for (i = 0; i < 2; i++)
12580 if (single_step_breakpoints[i])
12581 target_remove_breakpoint (single_step_gdbarch[i],
12582 single_step_breakpoints[i]);
12585 /* Check whether a software single-step breakpoint is inserted at
12589 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
12594 for (i = 0; i < 2; i++)
12596 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
12598 && breakpoint_address_match (bp_tgt->placed_address_space,
12599 bp_tgt->placed_address,
12607 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12608 non-zero otherwise. */
12610 is_syscall_catchpoint_enabled (struct breakpoint *bp)
12612 if (syscall_catchpoint_p (bp)
12613 && bp->enable_state != bp_disabled
12614 && bp->enable_state != bp_call_disabled)
12621 catch_syscall_enabled (void)
12623 struct inferior *inf = current_inferior ();
12625 return inf->total_syscalls_count != 0;
12629 catching_syscall_number (int syscall_number)
12631 struct breakpoint *bp;
12633 ALL_BREAKPOINTS (bp)
12634 if (is_syscall_catchpoint_enabled (bp))
12636 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
12638 if (c->syscalls_to_be_caught)
12642 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
12644 if (syscall_number == iter)
12654 /* Complete syscall names. Used by "catch syscall". */
12656 catch_syscall_completer (struct cmd_list_element *cmd,
12657 char *text, char *word)
12659 const char **list = get_syscall_names ();
12661 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
12667 /* Tracepoint-specific operations. */
12669 /* Set tracepoint count to NUM. */
12671 set_tracepoint_count (int num)
12673 tracepoint_count = num;
12674 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
12678 trace_command (char *arg, int from_tty)
12680 if (create_breakpoint (get_current_arch (),
12682 NULL, 0, 1 /* parse arg */,
12684 bp_tracepoint /* type_wanted */,
12685 0 /* Ignore count */,
12686 pending_break_support,
12687 &tracepoint_breakpoint_ops,
12691 set_tracepoint_count (breakpoint_count);
12695 ftrace_command (char *arg, int from_tty)
12697 if (create_breakpoint (get_current_arch (),
12699 NULL, 0, 1 /* parse arg */,
12701 bp_fast_tracepoint /* type_wanted */,
12702 0 /* Ignore count */,
12703 pending_break_support,
12704 &tracepoint_breakpoint_ops,
12708 set_tracepoint_count (breakpoint_count);
12711 /* strace command implementation. Creates a static tracepoint. */
12714 strace_command (char *arg, int from_tty)
12716 if (create_breakpoint (get_current_arch (),
12718 NULL, 0, 1 /* parse arg */,
12720 bp_static_tracepoint /* type_wanted */,
12721 0 /* Ignore count */,
12722 pending_break_support,
12723 &tracepoint_breakpoint_ops,
12727 set_tracepoint_count (breakpoint_count);
12730 /* Set up a fake reader function that gets command lines from a linked
12731 list that was acquired during tracepoint uploading. */
12733 static struct uploaded_tp *this_utp;
12734 static int next_cmd;
12737 read_uploaded_action (void)
12741 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
12748 /* Given information about a tracepoint as recorded on a target (which
12749 can be either a live system or a trace file), attempt to create an
12750 equivalent GDB tracepoint. This is not a reliable process, since
12751 the target does not necessarily have all the information used when
12752 the tracepoint was originally defined. */
12754 struct tracepoint *
12755 create_tracepoint_from_upload (struct uploaded_tp *utp)
12757 char *addr_str, small_buf[100];
12758 struct tracepoint *tp;
12760 if (utp->at_string)
12761 addr_str = utp->at_string;
12764 /* In the absence of a source location, fall back to raw
12765 address. Since there is no way to confirm that the address
12766 means the same thing as when the trace was started, warn the
12768 warning (_("Uploaded tracepoint %d has no "
12769 "source location, using raw address"),
12771 sprintf (small_buf, "*%s", hex_string (utp->addr));
12772 addr_str = small_buf;
12775 /* There's not much we can do with a sequence of bytecodes. */
12776 if (utp->cond && !utp->cond_string)
12777 warning (_("Uploaded tracepoint %d condition "
12778 "has no source form, ignoring it"),
12781 if (!create_breakpoint (get_current_arch (),
12783 utp->cond_string, -1, 0 /* parse cond/thread */,
12785 utp->type /* type_wanted */,
12786 0 /* Ignore count */,
12787 pending_break_support,
12788 &tracepoint_breakpoint_ops,
12790 utp->enabled /* enabled */,
12794 set_tracepoint_count (breakpoint_count);
12796 /* Get the tracepoint we just created. */
12797 tp = get_tracepoint (tracepoint_count);
12798 gdb_assert (tp != NULL);
12802 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
12804 trace_pass_command (small_buf, 0);
12807 /* If we have uploaded versions of the original commands, set up a
12808 special-purpose "reader" function and call the usual command line
12809 reader, then pass the result to the breakpoint command-setting
12811 if (!VEC_empty (char_ptr, utp->cmd_strings))
12813 struct command_line *cmd_list;
12818 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
12820 breakpoint_set_commands (&tp->base, cmd_list);
12822 else if (!VEC_empty (char_ptr, utp->actions)
12823 || !VEC_empty (char_ptr, utp->step_actions))
12824 warning (_("Uploaded tracepoint %d actions "
12825 "have no source form, ignoring them"),
12831 /* Print information on tracepoint number TPNUM_EXP, or all if
12835 tracepoints_info (char *args, int from_tty)
12837 struct ui_out *uiout = current_uiout;
12840 num_printed = breakpoint_1 (args, 0, is_tracepoint);
12842 if (num_printed == 0)
12844 if (args == NULL || *args == '\0')
12845 ui_out_message (uiout, 0, "No tracepoints.\n");
12847 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
12850 default_collect_info ();
12853 /* The 'enable trace' command enables tracepoints.
12854 Not supported by all targets. */
12856 enable_trace_command (char *args, int from_tty)
12858 enable_command (args, from_tty);
12861 /* The 'disable trace' command disables tracepoints.
12862 Not supported by all targets. */
12864 disable_trace_command (char *args, int from_tty)
12866 disable_command (args, from_tty);
12869 /* Remove a tracepoint (or all if no argument). */
12871 delete_trace_command (char *arg, int from_tty)
12873 struct breakpoint *b, *b_tmp;
12879 int breaks_to_delete = 0;
12881 /* Delete all breakpoints if no argument.
12882 Do not delete internal or call-dummy breakpoints, these
12883 have to be deleted with an explicit breakpoint number
12885 ALL_TRACEPOINTS (b)
12886 if (is_tracepoint (b) && user_breakpoint_p (b))
12888 breaks_to_delete = 1;
12892 /* Ask user only if there are some breakpoints to delete. */
12894 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
12896 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12897 if (is_tracepoint (b) && user_breakpoint_p (b))
12898 delete_breakpoint (b);
12902 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12905 /* Helper function for trace_pass_command. */
12908 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
12910 tp->pass_count = count;
12911 observer_notify_tracepoint_modified (tp->base.number);
12913 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12914 tp->base.number, count);
12917 /* Set passcount for tracepoint.
12919 First command argument is passcount, second is tracepoint number.
12920 If tracepoint number omitted, apply to most recently defined.
12921 Also accepts special argument "all". */
12924 trace_pass_command (char *args, int from_tty)
12926 struct tracepoint *t1;
12927 unsigned int count;
12929 if (args == 0 || *args == 0)
12930 error (_("passcount command requires an "
12931 "argument (count + optional TP num)"));
12933 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
12935 while (*args && isspace ((int) *args))
12938 if (*args && strncasecmp (args, "all", 3) == 0)
12940 struct breakpoint *b;
12942 args += 3; /* Skip special argument "all". */
12944 error (_("Junk at end of arguments."));
12946 ALL_TRACEPOINTS (b)
12948 t1 = (struct tracepoint *) b;
12949 trace_pass_set_count (t1, count, from_tty);
12952 else if (*args == '\0')
12954 t1 = get_tracepoint_by_number (&args, NULL, 1);
12956 trace_pass_set_count (t1, count, from_tty);
12960 struct get_number_or_range_state state;
12962 init_number_or_range (&state, args);
12963 while (!state.finished)
12965 t1 = get_tracepoint_by_number (&args, &state, 1);
12967 trace_pass_set_count (t1, count, from_tty);
12972 struct tracepoint *
12973 get_tracepoint (int num)
12975 struct breakpoint *t;
12977 ALL_TRACEPOINTS (t)
12978 if (t->number == num)
12979 return (struct tracepoint *) t;
12984 /* Find the tracepoint with the given target-side number (which may be
12985 different from the tracepoint number after disconnecting and
12988 struct tracepoint *
12989 get_tracepoint_by_number_on_target (int num)
12991 struct breakpoint *b;
12993 ALL_TRACEPOINTS (b)
12995 struct tracepoint *t = (struct tracepoint *) b;
12997 if (t->number_on_target == num)
13004 /* Utility: parse a tracepoint number and look it up in the list.
13005 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13006 If OPTIONAL_P is true, then if the argument is missing, the most
13007 recent tracepoint (tracepoint_count) is returned. */
13008 struct tracepoint *
13009 get_tracepoint_by_number (char **arg,
13010 struct get_number_or_range_state *state,
13013 extern int tracepoint_count;
13014 struct breakpoint *t;
13016 char *instring = arg == NULL ? NULL : *arg;
13020 gdb_assert (!state->finished);
13021 tpnum = get_number_or_range (state);
13023 else if (arg == NULL || *arg == NULL || ! **arg)
13026 tpnum = tracepoint_count;
13028 error_no_arg (_("tracepoint number"));
13031 tpnum = get_number (arg);
13035 if (instring && *instring)
13036 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13039 printf_filtered (_("Tracepoint argument missing "
13040 "and no previous tracepoint\n"));
13044 ALL_TRACEPOINTS (t)
13045 if (t->number == tpnum)
13047 return (struct tracepoint *) t;
13050 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
13055 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
13057 if (b->thread != -1)
13058 fprintf_unfiltered (fp, " thread %d", b->thread);
13061 fprintf_unfiltered (fp, " task %d", b->task);
13063 fprintf_unfiltered (fp, "\n");
13066 /* Save information on user settable breakpoints (watchpoints, etc) to
13067 a new script file named FILENAME. If FILTER is non-NULL, call it
13068 on each breakpoint and only include the ones for which it returns
13072 save_breakpoints (char *filename, int from_tty,
13073 int (*filter) (const struct breakpoint *))
13075 struct breakpoint *tp;
13078 struct cleanup *cleanup;
13079 struct ui_file *fp;
13080 int extra_trace_bits = 0;
13082 if (filename == 0 || *filename == 0)
13083 error (_("Argument required (file name in which to save)"));
13085 /* See if we have anything to save. */
13086 ALL_BREAKPOINTS (tp)
13088 /* Skip internal and momentary breakpoints. */
13089 if (!user_breakpoint_p (tp))
13092 /* If we have a filter, only save the breakpoints it accepts. */
13093 if (filter && !filter (tp))
13098 if (is_tracepoint (tp))
13100 extra_trace_bits = 1;
13102 /* We can stop searching. */
13109 warning (_("Nothing to save."));
13113 pathname = tilde_expand (filename);
13114 cleanup = make_cleanup (xfree, pathname);
13115 fp = gdb_fopen (pathname, "w");
13117 error (_("Unable to open file '%s' for saving (%s)"),
13118 filename, safe_strerror (errno));
13119 make_cleanup_ui_file_delete (fp);
13121 if (extra_trace_bits)
13122 save_trace_state_variables (fp);
13124 ALL_BREAKPOINTS (tp)
13126 /* Skip internal and momentary breakpoints. */
13127 if (!user_breakpoint_p (tp))
13130 /* If we have a filter, only save the breakpoints it accepts. */
13131 if (filter && !filter (tp))
13134 tp->ops->print_recreate (tp, fp);
13136 /* Note, we can't rely on tp->number for anything, as we can't
13137 assume the recreated breakpoint numbers will match. Use $bpnum
13140 if (tp->cond_string)
13141 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
13143 if (tp->ignore_count)
13144 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
13148 volatile struct gdb_exception ex;
13150 fprintf_unfiltered (fp, " commands\n");
13152 ui_out_redirect (current_uiout, fp);
13153 TRY_CATCH (ex, RETURN_MASK_ALL)
13155 print_command_lines (current_uiout, tp->commands->commands, 2);
13157 ui_out_redirect (current_uiout, NULL);
13160 throw_exception (ex);
13162 fprintf_unfiltered (fp, " end\n");
13165 if (tp->enable_state == bp_disabled)
13166 fprintf_unfiltered (fp, "disable\n");
13168 /* If this is a multi-location breakpoint, check if the locations
13169 should be individually disabled. Watchpoint locations are
13170 special, and not user visible. */
13171 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
13173 struct bp_location *loc;
13176 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
13178 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
13182 if (extra_trace_bits && *default_collect)
13183 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
13185 do_cleanups (cleanup);
13187 printf_filtered (_("Saved to file '%s'.\n"), filename);
13190 /* The `save breakpoints' command. */
13193 save_breakpoints_command (char *args, int from_tty)
13195 save_breakpoints (args, from_tty, NULL);
13198 /* The `save tracepoints' command. */
13201 save_tracepoints_command (char *args, int from_tty)
13203 save_breakpoints (args, from_tty, is_tracepoint);
13206 /* Create a vector of all tracepoints. */
13208 VEC(breakpoint_p) *
13209 all_tracepoints (void)
13211 VEC(breakpoint_p) *tp_vec = 0;
13212 struct breakpoint *tp;
13214 ALL_TRACEPOINTS (tp)
13216 VEC_safe_push (breakpoint_p, tp_vec, tp);
13223 /* This help string is used for the break, hbreak, tbreak and thbreak
13224 commands. It is defined as a macro to prevent duplication.
13225 COMMAND should be a string constant containing the name of the
13227 #define BREAK_ARGS_HELP(command) \
13228 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13229 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13230 If a line number is specified, break at start of code for that line.\n\
13231 If a function is specified, break at start of code for that function.\n\
13232 If an address is specified, break at that exact address.\n\
13233 With no LOCATION, uses current execution address of the selected\n\
13234 stack frame. This is useful for breaking on return to a stack frame.\n\
13236 THREADNUM is the number from \"info threads\".\n\
13237 CONDITION is a boolean expression.\n\
13239 Multiple breakpoints at one place are permitted, and useful if their\n\
13240 conditions are different.\n\
13242 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13244 /* List of subcommands for "catch". */
13245 static struct cmd_list_element *catch_cmdlist;
13247 /* List of subcommands for "tcatch". */
13248 static struct cmd_list_element *tcatch_cmdlist;
13251 add_catch_command (char *name, char *docstring,
13252 void (*sfunc) (char *args, int from_tty,
13253 struct cmd_list_element *command),
13254 char **(*completer) (struct cmd_list_element *cmd,
13255 char *text, char *word),
13256 void *user_data_catch,
13257 void *user_data_tcatch)
13259 struct cmd_list_element *command;
13261 command = add_cmd (name, class_breakpoint, NULL, docstring,
13263 set_cmd_sfunc (command, sfunc);
13264 set_cmd_context (command, user_data_catch);
13265 set_cmd_completer (command, completer);
13267 command = add_cmd (name, class_breakpoint, NULL, docstring,
13269 set_cmd_sfunc (command, sfunc);
13270 set_cmd_context (command, user_data_tcatch);
13271 set_cmd_completer (command, completer);
13275 clear_syscall_counts (struct inferior *inf)
13277 inf->total_syscalls_count = 0;
13278 inf->any_syscall_count = 0;
13279 VEC_free (int, inf->syscalls_counts);
13283 save_command (char *arg, int from_tty)
13285 printf_unfiltered (_("\"save\" must be followed by "
13286 "the name of a save subcommand.\n"));
13287 help_list (save_cmdlist, "save ", -1, gdb_stdout);
13290 struct breakpoint *
13291 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
13294 struct breakpoint *b, *b_tmp;
13296 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13298 if ((*callback) (b, data))
13305 /* Zero if any of the breakpoint's locations could be a location where
13306 functions have been inlined, nonzero otherwise. */
13309 is_non_inline_function (struct breakpoint *b)
13311 /* The shared library event breakpoint is set on the address of a
13312 non-inline function. */
13313 if (b->type == bp_shlib_event)
13319 /* Nonzero if the specified PC cannot be a location where functions
13320 have been inlined. */
13323 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc)
13325 struct breakpoint *b;
13326 struct bp_location *bl;
13328 ALL_BREAKPOINTS (b)
13330 if (!is_non_inline_function (b))
13333 for (bl = b->loc; bl != NULL; bl = bl->next)
13335 if (!bl->shlib_disabled
13336 && bpstat_check_location (bl, aspace, pc))
13345 initialize_breakpoint_ops (void)
13347 static int initialized = 0;
13349 struct breakpoint_ops *ops;
13355 /* The breakpoint_ops structure to be inherit by all kinds of
13356 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13357 internal and momentary breakpoints, etc.). */
13358 ops = &bkpt_base_breakpoint_ops;
13359 *ops = base_breakpoint_ops;
13360 ops->re_set = bkpt_re_set;
13361 ops->insert_location = bkpt_insert_location;
13362 ops->remove_location = bkpt_remove_location;
13363 ops->breakpoint_hit = bkpt_breakpoint_hit;
13365 /* The breakpoint_ops structure to be used in regular breakpoints. */
13366 ops = &bkpt_breakpoint_ops;
13367 *ops = bkpt_base_breakpoint_ops;
13368 ops->re_set = bkpt_re_set;
13369 ops->resources_needed = bkpt_resources_needed;
13370 ops->print_it = bkpt_print_it;
13371 ops->print_mention = bkpt_print_mention;
13372 ops->print_recreate = bkpt_print_recreate;
13374 /* Ranged breakpoints. */
13375 ops = &ranged_breakpoint_ops;
13376 *ops = bkpt_breakpoint_ops;
13377 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
13378 ops->resources_needed = resources_needed_ranged_breakpoint;
13379 ops->print_it = print_it_ranged_breakpoint;
13380 ops->print_one = print_one_ranged_breakpoint;
13381 ops->print_one_detail = print_one_detail_ranged_breakpoint;
13382 ops->print_mention = print_mention_ranged_breakpoint;
13383 ops->print_recreate = print_recreate_ranged_breakpoint;
13385 /* Internal breakpoints. */
13386 ops = &internal_breakpoint_ops;
13387 *ops = bkpt_base_breakpoint_ops;
13388 ops->re_set = internal_bkpt_re_set;
13389 ops->check_status = internal_bkpt_check_status;
13390 ops->print_it = internal_bkpt_print_it;
13391 ops->print_mention = internal_bkpt_print_mention;
13393 /* Momentary breakpoints. */
13394 ops = &momentary_breakpoint_ops;
13395 *ops = bkpt_base_breakpoint_ops;
13396 ops->re_set = momentary_bkpt_re_set;
13397 ops->check_status = momentary_bkpt_check_status;
13398 ops->print_it = momentary_bkpt_print_it;
13399 ops->print_mention = momentary_bkpt_print_mention;
13401 /* GNU v3 exception catchpoints. */
13402 ops = &gnu_v3_exception_catchpoint_ops;
13403 *ops = bkpt_breakpoint_ops;
13404 ops->print_it = print_it_exception_catchpoint;
13405 ops->print_one = print_one_exception_catchpoint;
13406 ops->print_mention = print_mention_exception_catchpoint;
13407 ops->print_recreate = print_recreate_exception_catchpoint;
13410 ops = &watchpoint_breakpoint_ops;
13411 *ops = base_breakpoint_ops;
13412 ops->dtor = dtor_watchpoint;
13413 ops->re_set = re_set_watchpoint;
13414 ops->insert_location = insert_watchpoint;
13415 ops->remove_location = remove_watchpoint;
13416 ops->breakpoint_hit = breakpoint_hit_watchpoint;
13417 ops->check_status = check_status_watchpoint;
13418 ops->resources_needed = resources_needed_watchpoint;
13419 ops->works_in_software_mode = works_in_software_mode_watchpoint;
13420 ops->print_it = print_it_watchpoint;
13421 ops->print_mention = print_mention_watchpoint;
13422 ops->print_recreate = print_recreate_watchpoint;
13424 /* Masked watchpoints. */
13425 ops = &masked_watchpoint_breakpoint_ops;
13426 *ops = watchpoint_breakpoint_ops;
13427 ops->insert_location = insert_masked_watchpoint;
13428 ops->remove_location = remove_masked_watchpoint;
13429 ops->resources_needed = resources_needed_masked_watchpoint;
13430 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
13431 ops->print_it = print_it_masked_watchpoint;
13432 ops->print_one_detail = print_one_detail_masked_watchpoint;
13433 ops->print_mention = print_mention_masked_watchpoint;
13434 ops->print_recreate = print_recreate_masked_watchpoint;
13437 ops = &tracepoint_breakpoint_ops;
13438 *ops = base_breakpoint_ops;
13439 ops->re_set = tracepoint_re_set;
13440 ops->breakpoint_hit = tracepoint_breakpoint_hit;
13441 ops->print_one_detail = tracepoint_print_one_detail;
13442 ops->print_mention = tracepoint_print_mention;
13443 ops->print_recreate = tracepoint_print_recreate;
13445 /* Fork catchpoints. */
13446 ops = &catch_fork_breakpoint_ops;
13447 *ops = base_breakpoint_ops;
13448 ops->insert_location = insert_catch_fork;
13449 ops->remove_location = remove_catch_fork;
13450 ops->breakpoint_hit = breakpoint_hit_catch_fork;
13451 ops->print_it = print_it_catch_fork;
13452 ops->print_one = print_one_catch_fork;
13453 ops->print_mention = print_mention_catch_fork;
13454 ops->print_recreate = print_recreate_catch_fork;
13456 /* Vfork catchpoints. */
13457 ops = &catch_vfork_breakpoint_ops;
13458 *ops = base_breakpoint_ops;
13459 ops->insert_location = insert_catch_vfork;
13460 ops->remove_location = remove_catch_vfork;
13461 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
13462 ops->print_it = print_it_catch_vfork;
13463 ops->print_one = print_one_catch_vfork;
13464 ops->print_mention = print_mention_catch_vfork;
13465 ops->print_recreate = print_recreate_catch_vfork;
13467 /* Exec catchpoints. */
13468 ops = &catch_exec_breakpoint_ops;
13469 *ops = base_breakpoint_ops;
13470 ops->dtor = dtor_catch_exec;
13471 ops->insert_location = insert_catch_exec;
13472 ops->remove_location = remove_catch_exec;
13473 ops->breakpoint_hit = breakpoint_hit_catch_exec;
13474 ops->print_it = print_it_catch_exec;
13475 ops->print_one = print_one_catch_exec;
13476 ops->print_mention = print_mention_catch_exec;
13477 ops->print_recreate = print_recreate_catch_exec;
13479 /* Syscall catchpoints. */
13480 ops = &catch_syscall_breakpoint_ops;
13481 *ops = base_breakpoint_ops;
13482 ops->dtor = dtor_catch_syscall;
13483 ops->insert_location = insert_catch_syscall;
13484 ops->remove_location = remove_catch_syscall;
13485 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
13486 ops->print_it = print_it_catch_syscall;
13487 ops->print_one = print_one_catch_syscall;
13488 ops->print_mention = print_mention_catch_syscall;
13489 ops->print_recreate = print_recreate_catch_syscall;
13493 _initialize_breakpoint (void)
13495 struct cmd_list_element *c;
13497 initialize_breakpoint_ops ();
13499 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
13500 observer_attach_inferior_exit (clear_syscall_counts);
13501 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
13503 breakpoint_objfile_key = register_objfile_data ();
13505 breakpoint_chain = 0;
13506 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13507 before a breakpoint is set. */
13508 breakpoint_count = 0;
13510 tracepoint_count = 0;
13512 add_com ("ignore", class_breakpoint, ignore_command, _("\
13513 Set ignore-count of breakpoint number N to COUNT.\n\
13514 Usage is `ignore N COUNT'."));
13516 add_com_alias ("bc", "ignore", class_breakpoint, 1);
13518 add_com ("commands", class_breakpoint, commands_command, _("\
13519 Set commands to be executed when a breakpoint is hit.\n\
13520 Give breakpoint number as argument after \"commands\".\n\
13521 With no argument, the targeted breakpoint is the last one set.\n\
13522 The commands themselves follow starting on the next line.\n\
13523 Type a line containing \"end\" to indicate the end of them.\n\
13524 Give \"silent\" as the first line to make the breakpoint silent;\n\
13525 then no output is printed when it is hit, except what the commands print."));
13527 add_com ("condition", class_breakpoint, condition_command, _("\
13528 Specify breakpoint number N to break only if COND is true.\n\
13529 Usage is `condition N COND', where N is an integer and COND is an\n\
13530 expression to be evaluated whenever breakpoint N is reached."));
13532 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
13533 Set a temporary breakpoint.\n\
13534 Like \"break\" except the breakpoint is only temporary,\n\
13535 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13536 by using \"enable delete\" on the breakpoint number.\n\
13538 BREAK_ARGS_HELP ("tbreak")));
13539 set_cmd_completer (c, location_completer);
13541 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
13542 Set a hardware assisted breakpoint.\n\
13543 Like \"break\" except the breakpoint requires hardware support,\n\
13544 some target hardware may not have this support.\n\
13546 BREAK_ARGS_HELP ("hbreak")));
13547 set_cmd_completer (c, location_completer);
13549 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
13550 Set a temporary hardware assisted breakpoint.\n\
13551 Like \"hbreak\" except the breakpoint is only temporary,\n\
13552 so it will be deleted when hit.\n\
13554 BREAK_ARGS_HELP ("thbreak")));
13555 set_cmd_completer (c, location_completer);
13557 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
13558 Enable some breakpoints.\n\
13559 Give breakpoint numbers (separated by spaces) as arguments.\n\
13560 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13561 This is used to cancel the effect of the \"disable\" command.\n\
13562 With a subcommand you can enable temporarily."),
13563 &enablelist, "enable ", 1, &cmdlist);
13565 add_com ("ab", class_breakpoint, enable_command, _("\
13566 Enable some breakpoints.\n\
13567 Give breakpoint numbers (separated by spaces) as arguments.\n\
13568 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13569 This is used to cancel the effect of the \"disable\" command.\n\
13570 With a subcommand you can enable temporarily."));
13572 add_com_alias ("en", "enable", class_breakpoint, 1);
13574 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
13575 Enable some breakpoints.\n\
13576 Give breakpoint numbers (separated by spaces) as arguments.\n\
13577 This is used to cancel the effect of the \"disable\" command.\n\
13578 May be abbreviated to simply \"enable\".\n"),
13579 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
13581 add_cmd ("once", no_class, enable_once_command, _("\
13582 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13583 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13586 add_cmd ("delete", no_class, enable_delete_command, _("\
13587 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13588 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13591 add_cmd ("delete", no_class, enable_delete_command, _("\
13592 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13593 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13596 add_cmd ("once", no_class, enable_once_command, _("\
13597 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13598 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13601 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
13602 Disable some breakpoints.\n\
13603 Arguments are breakpoint numbers with spaces in between.\n\
13604 To disable all breakpoints, give no argument.\n\
13605 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13606 &disablelist, "disable ", 1, &cmdlist);
13607 add_com_alias ("dis", "disable", class_breakpoint, 1);
13608 add_com_alias ("disa", "disable", class_breakpoint, 1);
13610 add_com ("sb", class_breakpoint, disable_command, _("\
13611 Disable some breakpoints.\n\
13612 Arguments are breakpoint numbers with spaces in between.\n\
13613 To disable all breakpoints, give no argument.\n\
13614 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13616 add_cmd ("breakpoints", class_alias, disable_command, _("\
13617 Disable some breakpoints.\n\
13618 Arguments are breakpoint numbers with spaces in between.\n\
13619 To disable all breakpoints, give no argument.\n\
13620 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13621 This command may be abbreviated \"disable\"."),
13624 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
13625 Delete some breakpoints or auto-display expressions.\n\
13626 Arguments are breakpoint numbers with spaces in between.\n\
13627 To delete all breakpoints, give no argument.\n\
13629 Also a prefix command for deletion of other GDB objects.\n\
13630 The \"unset\" command is also an alias for \"delete\"."),
13631 &deletelist, "delete ", 1, &cmdlist);
13632 add_com_alias ("d", "delete", class_breakpoint, 1);
13633 add_com_alias ("del", "delete", class_breakpoint, 1);
13635 add_com ("db", class_breakpoint, delete_command, _("\
13636 Delete some breakpoints.\n\
13637 Arguments are breakpoint numbers with spaces in between.\n\
13638 To delete all breakpoints, give no argument.\n"));
13640 add_cmd ("breakpoints", class_alias, delete_command, _("\
13641 Delete some breakpoints or auto-display expressions.\n\
13642 Arguments are breakpoint numbers with spaces in between.\n\
13643 To delete all breakpoints, give no argument.\n\
13644 This command may be abbreviated \"delete\"."),
13647 add_com ("clear", class_breakpoint, clear_command, _("\
13648 Clear breakpoint at specified line or function.\n\
13649 Argument may be line number, function name, or \"*\" and an address.\n\
13650 If line number is specified, all breakpoints in that line are cleared.\n\
13651 If function is specified, breakpoints at beginning of function are cleared.\n\
13652 If an address is specified, breakpoints at that address are cleared.\n\
13654 With no argument, clears all breakpoints in the line that the selected frame\n\
13655 is executing in.\n\
13657 See also the \"delete\" command which clears breakpoints by number."));
13658 add_com_alias ("cl", "clear", class_breakpoint, 1);
13660 c = add_com ("break", class_breakpoint, break_command, _("\
13661 Set breakpoint at specified line or function.\n"
13662 BREAK_ARGS_HELP ("break")));
13663 set_cmd_completer (c, location_completer);
13665 add_com_alias ("b", "break", class_run, 1);
13666 add_com_alias ("br", "break", class_run, 1);
13667 add_com_alias ("bre", "break", class_run, 1);
13668 add_com_alias ("brea", "break", class_run, 1);
13671 add_com_alias ("ba", "break", class_breakpoint, 1);
13675 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
13676 Break in function/address or break at a line in the current file."),
13677 &stoplist, "stop ", 1, &cmdlist);
13678 add_cmd ("in", class_breakpoint, stopin_command,
13679 _("Break in function or address."), &stoplist);
13680 add_cmd ("at", class_breakpoint, stopat_command,
13681 _("Break at a line in the current file."), &stoplist);
13682 add_com ("status", class_info, breakpoints_info, _("\
13683 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13684 The \"Type\" column indicates one of:\n\
13685 \tbreakpoint - normal breakpoint\n\
13686 \twatchpoint - watchpoint\n\
13687 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13688 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13689 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13690 address and file/line number respectively.\n\
13692 Convenience variable \"$_\" and default examine address for \"x\"\n\
13693 are set to the address of the last breakpoint listed unless the command\n\
13694 is prefixed with \"server \".\n\n\
13695 Convenience variable \"$bpnum\" contains the number of the last\n\
13696 breakpoint set."));
13699 add_info ("breakpoints", breakpoints_info, _("\
13700 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13701 The \"Type\" column indicates one of:\n\
13702 \tbreakpoint - normal breakpoint\n\
13703 \twatchpoint - watchpoint\n\
13704 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13705 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13706 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13707 address and file/line number respectively.\n\
13709 Convenience variable \"$_\" and default examine address for \"x\"\n\
13710 are set to the address of the last breakpoint listed unless the command\n\
13711 is prefixed with \"server \".\n\n\
13712 Convenience variable \"$bpnum\" contains the number of the last\n\
13713 breakpoint set."));
13715 add_info_alias ("b", "breakpoints", 1);
13718 add_com ("lb", class_breakpoint, breakpoints_info, _("\
13719 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13720 The \"Type\" column indicates one of:\n\
13721 \tbreakpoint - normal breakpoint\n\
13722 \twatchpoint - watchpoint\n\
13723 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13724 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13725 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13726 address and file/line number respectively.\n\
13728 Convenience variable \"$_\" and default examine address for \"x\"\n\
13729 are set to the address of the last breakpoint listed unless the command\n\
13730 is prefixed with \"server \".\n\n\
13731 Convenience variable \"$bpnum\" contains the number of the last\n\
13732 breakpoint set."));
13734 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
13735 Status of all breakpoints, or breakpoint number NUMBER.\n\
13736 The \"Type\" column indicates one of:\n\
13737 \tbreakpoint - normal breakpoint\n\
13738 \twatchpoint - watchpoint\n\
13739 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13740 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13741 \tuntil - internal breakpoint used by the \"until\" command\n\
13742 \tfinish - internal breakpoint used by the \"finish\" command\n\
13743 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13744 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13745 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13746 address and file/line number respectively.\n\
13748 Convenience variable \"$_\" and default examine address for \"x\"\n\
13749 are set to the address of the last breakpoint listed unless the command\n\
13750 is prefixed with \"server \".\n\n\
13751 Convenience variable \"$bpnum\" contains the number of the last\n\
13753 &maintenanceinfolist);
13755 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
13756 Set catchpoints to catch events."),
13757 &catch_cmdlist, "catch ",
13758 0/*allow-unknown*/, &cmdlist);
13760 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
13761 Set temporary catchpoints to catch events."),
13762 &tcatch_cmdlist, "tcatch ",
13763 0/*allow-unknown*/, &cmdlist);
13765 /* Add catch and tcatch sub-commands. */
13766 add_catch_command ("catch", _("\
13767 Catch an exception, when caught.\n\
13768 With an argument, catch only exceptions with the given name."),
13769 catch_catch_command,
13773 add_catch_command ("throw", _("\
13774 Catch an exception, when thrown.\n\
13775 With an argument, catch only exceptions with the given name."),
13776 catch_throw_command,
13780 add_catch_command ("fork", _("Catch calls to fork."),
13781 catch_fork_command_1,
13783 (void *) (uintptr_t) catch_fork_permanent,
13784 (void *) (uintptr_t) catch_fork_temporary);
13785 add_catch_command ("vfork", _("Catch calls to vfork."),
13786 catch_fork_command_1,
13788 (void *) (uintptr_t) catch_vfork_permanent,
13789 (void *) (uintptr_t) catch_vfork_temporary);
13790 add_catch_command ("exec", _("Catch calls to exec."),
13791 catch_exec_command_1,
13795 add_catch_command ("syscall", _("\
13796 Catch system calls by their names and/or numbers.\n\
13797 Arguments say which system calls to catch. If no arguments\n\
13798 are given, every system call will be caught.\n\
13799 Arguments, if given, should be one or more system call names\n\
13800 (if your system supports that), or system call numbers."),
13801 catch_syscall_command_1,
13802 catch_syscall_completer,
13806 c = add_com ("watch", class_breakpoint, watch_command, _("\
13807 Set a watchpoint for an expression.\n\
13808 Usage: watch [-l|-location] EXPRESSION\n\
13809 A watchpoint stops execution of your program whenever the value of\n\
13810 an expression changes.\n\
13811 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13812 the memory to which it refers."));
13813 set_cmd_completer (c, expression_completer);
13815 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
13816 Set a read watchpoint for an expression.\n\
13817 Usage: rwatch [-l|-location] EXPRESSION\n\
13818 A watchpoint stops execution of your program whenever the value of\n\
13819 an expression is read.\n\
13820 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13821 the memory to which it refers."));
13822 set_cmd_completer (c, expression_completer);
13824 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
13825 Set a watchpoint for an expression.\n\
13826 Usage: awatch [-l|-location] EXPRESSION\n\
13827 A watchpoint stops execution of your program whenever the value of\n\
13828 an expression is either read or written.\n\
13829 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13830 the memory to which it refers."));
13831 set_cmd_completer (c, expression_completer);
13833 add_info ("watchpoints", watchpoints_info, _("\
13834 Status of specified watchpoints (all watchpoints if no argument)."));
13836 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13837 respond to changes - contrary to the description. */
13838 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
13839 &can_use_hw_watchpoints, _("\
13840 Set debugger's willingness to use watchpoint hardware."), _("\
13841 Show debugger's willingness to use watchpoint hardware."), _("\
13842 If zero, gdb will not use hardware for new watchpoints, even if\n\
13843 such is available. (However, any hardware watchpoints that were\n\
13844 created before setting this to nonzero, will continue to use watchpoint\n\
13847 show_can_use_hw_watchpoints,
13848 &setlist, &showlist);
13850 can_use_hw_watchpoints = 1;
13852 /* Tracepoint manipulation commands. */
13854 c = add_com ("trace", class_breakpoint, trace_command, _("\
13855 Set a tracepoint at specified line or function.\n\
13857 BREAK_ARGS_HELP ("trace") "\n\
13858 Do \"help tracepoints\" for info on other tracepoint commands."));
13859 set_cmd_completer (c, location_completer);
13861 add_com_alias ("tp", "trace", class_alias, 0);
13862 add_com_alias ("tr", "trace", class_alias, 1);
13863 add_com_alias ("tra", "trace", class_alias, 1);
13864 add_com_alias ("trac", "trace", class_alias, 1);
13866 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
13867 Set a fast tracepoint at specified line or function.\n\
13869 BREAK_ARGS_HELP ("ftrace") "\n\
13870 Do \"help tracepoints\" for info on other tracepoint commands."));
13871 set_cmd_completer (c, location_completer);
13873 c = add_com ("strace", class_breakpoint, strace_command, _("\
13874 Set a static tracepoint at specified line, function or marker.\n\
13876 strace [LOCATION] [if CONDITION]\n\
13877 LOCATION may be a line number, function name, \"*\" and an address,\n\
13878 or -m MARKER_ID.\n\
13879 If a line number is specified, probe the marker at start of code\n\
13880 for that line. If a function is specified, probe the marker at start\n\
13881 of code for that function. If an address is specified, probe the marker\n\
13882 at that exact address. If a marker id is specified, probe the marker\n\
13883 with that name. With no LOCATION, uses current execution address of\n\
13884 the selected stack frame.\n\
13885 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13886 This collects arbitrary user data passed in the probe point call to the\n\
13887 tracing library. You can inspect it when analyzing the trace buffer,\n\
13888 by printing the $_sdata variable like any other convenience variable.\n\
13890 CONDITION is a boolean expression.\n\
13892 Multiple tracepoints at one place are permitted, and useful if their\n\
13893 conditions are different.\n\
13895 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13896 Do \"help tracepoints\" for info on other tracepoint commands."));
13897 set_cmd_completer (c, location_completer);
13899 add_info ("tracepoints", tracepoints_info, _("\
13900 Status of specified tracepoints (all tracepoints if no argument).\n\
13901 Convenience variable \"$tpnum\" contains the number of the\n\
13902 last tracepoint set."));
13904 add_info_alias ("tp", "tracepoints", 1);
13906 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
13907 Delete specified tracepoints.\n\
13908 Arguments are tracepoint numbers, separated by spaces.\n\
13909 No argument means delete all tracepoints."),
13912 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
13913 Disable specified tracepoints.\n\
13914 Arguments are tracepoint numbers, separated by spaces.\n\
13915 No argument means disable all tracepoints."),
13917 deprecate_cmd (c, "disable");
13919 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
13920 Enable specified tracepoints.\n\
13921 Arguments are tracepoint numbers, separated by spaces.\n\
13922 No argument means enable all tracepoints."),
13924 deprecate_cmd (c, "enable");
13926 add_com ("passcount", class_trace, trace_pass_command, _("\
13927 Set the passcount for a tracepoint.\n\
13928 The trace will end when the tracepoint has been passed 'count' times.\n\
13929 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13930 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13932 add_prefix_cmd ("save", class_breakpoint, save_command,
13933 _("Save breakpoint definitions as a script."),
13934 &save_cmdlist, "save ",
13935 0/*allow-unknown*/, &cmdlist);
13937 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
13938 Save current breakpoint definitions as a script.\n\
13939 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13940 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13941 session to restore them."),
13943 set_cmd_completer (c, filename_completer);
13945 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
13946 Save current tracepoint definitions as a script.\n\
13947 Use the 'source' command in another debug session to restore them."),
13949 set_cmd_completer (c, filename_completer);
13951 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
13952 deprecate_cmd (c, "save tracepoints");
13954 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
13955 Breakpoint specific settings\n\
13956 Configure various breakpoint-specific variables such as\n\
13957 pending breakpoint behavior"),
13958 &breakpoint_set_cmdlist, "set breakpoint ",
13959 0/*allow-unknown*/, &setlist);
13960 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
13961 Breakpoint specific settings\n\
13962 Configure various breakpoint-specific variables such as\n\
13963 pending breakpoint behavior"),
13964 &breakpoint_show_cmdlist, "show breakpoint ",
13965 0/*allow-unknown*/, &showlist);
13967 add_setshow_auto_boolean_cmd ("pending", no_class,
13968 &pending_break_support, _("\
13969 Set debugger's behavior regarding pending breakpoints."), _("\
13970 Show debugger's behavior regarding pending breakpoints."), _("\
13971 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13972 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13973 an error. If auto, an unrecognized breakpoint location results in a\n\
13974 user-query to see if a pending breakpoint should be created."),
13976 show_pending_break_support,
13977 &breakpoint_set_cmdlist,
13978 &breakpoint_show_cmdlist);
13980 pending_break_support = AUTO_BOOLEAN_AUTO;
13982 add_setshow_boolean_cmd ("auto-hw", no_class,
13983 &automatic_hardware_breakpoints, _("\
13984 Set automatic usage of hardware breakpoints."), _("\
13985 Show automatic usage of hardware breakpoints."), _("\
13986 If set, the debugger will automatically use hardware breakpoints for\n\
13987 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13988 a warning will be emitted for such breakpoints."),
13990 show_automatic_hardware_breakpoints,
13991 &breakpoint_set_cmdlist,
13992 &breakpoint_show_cmdlist);
13994 add_setshow_enum_cmd ("always-inserted", class_support,
13995 always_inserted_enums, &always_inserted_mode, _("\
13996 Set mode for inserting breakpoints."), _("\
13997 Show mode for inserting breakpoints."), _("\
13998 When this mode is off, breakpoints are inserted in inferior when it is\n\
13999 resumed, and removed when execution stops. When this mode is on,\n\
14000 breakpoints are inserted immediately and removed only when the user\n\
14001 deletes the breakpoint. When this mode is auto (which is the default),\n\
14002 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14003 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14004 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14005 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14007 &show_always_inserted_mode,
14008 &breakpoint_set_cmdlist,
14009 &breakpoint_show_cmdlist);
14011 add_com ("break-range", class_breakpoint, break_range_command, _("\
14012 Set a breakpoint for an address range.\n\
14013 break-range START-LOCATION, END-LOCATION\n\
14014 where START-LOCATION and END-LOCATION can be one of the following:\n\
14015 LINENUM, for that line in the current file,\n\
14016 FILE:LINENUM, for that line in that file,\n\
14017 +OFFSET, for that number of lines after the current line\n\
14018 or the start of the range\n\
14019 FUNCTION, for the first line in that function,\n\
14020 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14021 *ADDRESS, for the instruction at that address.\n\
14023 The breakpoint will stop execution of the inferior whenever it executes\n\
14024 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14025 range (including START-LOCATION and END-LOCATION)."));
14027 automatic_hardware_breakpoints = 1;
14029 observer_attach_about_to_proceed (breakpoint_about_to_proceed);