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. We don't differentiate the type of BL's owner
1562 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1563 breakpoint_ops is not defined, because in insert_bp_location,
1564 tracepoint's insert_location will not be called. */
1566 should_be_inserted (struct bp_location *bl)
1568 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1571 if (bl->owner->disposition == disp_del_at_next_stop)
1574 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1577 /* This is set for example, when we're attached to the parent of a
1578 vfork, and have detached from the child. The child is running
1579 free, and we expect it to do an exec or exit, at which point the
1580 OS makes the parent schedulable again (and the target reports
1581 that the vfork is done). Until the child is done with the shared
1582 memory region, do not insert breakpoints in the parent, otherwise
1583 the child could still trip on the parent's breakpoints. Since
1584 the parent is blocked anyway, it won't miss any breakpoint. */
1585 if (bl->pspace->breakpoints_not_allowed)
1591 /* Same as should_be_inserted but does the check assuming
1592 that the location is not duplicated. */
1595 unduplicated_should_be_inserted (struct bp_location *bl)
1598 const int save_duplicate = bl->duplicate;
1601 result = should_be_inserted (bl);
1602 bl->duplicate = save_duplicate;
1606 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1607 location. Any error messages are printed to TMP_ERROR_STREAM; and
1608 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1609 Returns 0 for success, 1 if the bp_location type is not supported or
1612 NOTE drow/2003-09-09: This routine could be broken down to an
1613 object-style method for each breakpoint or catchpoint type. */
1615 insert_bp_location (struct bp_location *bl,
1616 struct ui_file *tmp_error_stream,
1617 int *disabled_breaks,
1618 int *hw_breakpoint_error)
1622 if (!should_be_inserted (bl) || bl->inserted)
1625 /* Initialize the target-specific information. */
1626 memset (&bl->target_info, 0, sizeof (bl->target_info));
1627 bl->target_info.placed_address = bl->address;
1628 bl->target_info.placed_address_space = bl->pspace->aspace;
1629 bl->target_info.length = bl->length;
1631 if (bl->loc_type == bp_loc_software_breakpoint
1632 || bl->loc_type == bp_loc_hardware_breakpoint)
1634 if (bl->owner->type != bp_hardware_breakpoint)
1636 /* If the explicitly specified breakpoint type
1637 is not hardware breakpoint, check the memory map to see
1638 if the breakpoint address is in read only memory or not.
1640 Two important cases are:
1641 - location type is not hardware breakpoint, memory
1642 is readonly. We change the type of the location to
1643 hardware breakpoint.
1644 - location type is hardware breakpoint, memory is
1645 read-write. This means we've previously made the
1646 location hardware one, but then the memory map changed,
1649 When breakpoints are removed, remove_breakpoints will use
1650 location types we've just set here, the only possible
1651 problem is that memory map has changed during running
1652 program, but it's not going to work anyway with current
1654 struct mem_region *mr
1655 = lookup_mem_region (bl->target_info.placed_address);
1659 if (automatic_hardware_breakpoints)
1661 enum bp_loc_type new_type;
1663 if (mr->attrib.mode != MEM_RW)
1664 new_type = bp_loc_hardware_breakpoint;
1666 new_type = bp_loc_software_breakpoint;
1668 if (new_type != bl->loc_type)
1670 static int said = 0;
1672 bl->loc_type = new_type;
1675 fprintf_filtered (gdb_stdout,
1676 _("Note: automatically using "
1677 "hardware breakpoints for "
1678 "read-only addresses.\n"));
1683 else if (bl->loc_type == bp_loc_software_breakpoint
1684 && mr->attrib.mode != MEM_RW)
1685 warning (_("cannot set software breakpoint "
1686 "at readonly address %s"),
1687 paddress (bl->gdbarch, bl->address));
1691 /* First check to see if we have to handle an overlay. */
1692 if (overlay_debugging == ovly_off
1693 || bl->section == NULL
1694 || !(section_is_overlay (bl->section)))
1696 /* No overlay handling: just set the breakpoint. */
1698 val = bl->owner->ops->insert_location (bl);
1702 /* This breakpoint is in an overlay section.
1703 Shall we set a breakpoint at the LMA? */
1704 if (!overlay_events_enabled)
1706 /* Yes -- overlay event support is not active,
1707 so we must try to set a breakpoint at the LMA.
1708 This will not work for a hardware breakpoint. */
1709 if (bl->loc_type == bp_loc_hardware_breakpoint)
1710 warning (_("hardware breakpoint %d not supported in overlay!"),
1714 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1716 /* Set a software (trap) breakpoint at the LMA. */
1717 bl->overlay_target_info = bl->target_info;
1718 bl->overlay_target_info.placed_address = addr;
1719 val = target_insert_breakpoint (bl->gdbarch,
1720 &bl->overlay_target_info);
1722 fprintf_unfiltered (tmp_error_stream,
1723 "Overlay breakpoint %d "
1724 "failed: in ROM?\n",
1728 /* Shall we set a breakpoint at the VMA? */
1729 if (section_is_mapped (bl->section))
1731 /* Yes. This overlay section is mapped into memory. */
1732 val = bl->owner->ops->insert_location (bl);
1736 /* No. This breakpoint will not be inserted.
1737 No error, but do not mark the bp as 'inserted'. */
1744 /* Can't set the breakpoint. */
1745 if (solib_name_from_address (bl->pspace, bl->address))
1747 /* See also: disable_breakpoints_in_shlibs. */
1749 bl->shlib_disabled = 1;
1750 observer_notify_breakpoint_modified (bl->owner);
1751 if (!*disabled_breaks)
1753 fprintf_unfiltered (tmp_error_stream,
1754 "Cannot insert breakpoint %d.\n",
1756 fprintf_unfiltered (tmp_error_stream,
1757 "Temporarily disabling shared "
1758 "library breakpoints:\n");
1760 *disabled_breaks = 1;
1761 fprintf_unfiltered (tmp_error_stream,
1762 "breakpoint #%d\n", bl->owner->number);
1766 if (bl->loc_type == bp_loc_hardware_breakpoint)
1768 *hw_breakpoint_error = 1;
1769 fprintf_unfiltered (tmp_error_stream,
1770 "Cannot insert hardware "
1776 fprintf_unfiltered (tmp_error_stream,
1777 "Cannot insert breakpoint %d.\n",
1779 fprintf_filtered (tmp_error_stream,
1780 "Error accessing memory address ");
1781 fputs_filtered (paddress (bl->gdbarch, bl->address),
1783 fprintf_filtered (tmp_error_stream, ": %s.\n",
1784 safe_strerror (val));
1795 else if (bl->loc_type == bp_loc_hardware_watchpoint
1796 /* NOTE drow/2003-09-08: This state only exists for removing
1797 watchpoints. It's not clear that it's necessary... */
1798 && bl->owner->disposition != disp_del_at_next_stop)
1800 gdb_assert (bl->owner->ops != NULL
1801 && bl->owner->ops->insert_location != NULL);
1803 val = bl->owner->ops->insert_location (bl);
1805 /* If trying to set a read-watchpoint, and it turns out it's not
1806 supported, try emulating one with an access watchpoint. */
1807 if (val == 1 && bl->watchpoint_type == hw_read)
1809 struct bp_location *loc, **loc_temp;
1811 /* But don't try to insert it, if there's already another
1812 hw_access location that would be considered a duplicate
1814 ALL_BP_LOCATIONS (loc, loc_temp)
1816 && loc->watchpoint_type == hw_access
1817 && watchpoint_locations_match (bl, loc))
1821 bl->target_info = loc->target_info;
1822 bl->watchpoint_type = hw_access;
1829 bl->watchpoint_type = hw_access;
1830 val = bl->owner->ops->insert_location (bl);
1833 /* Back to the original value. */
1834 bl->watchpoint_type = hw_read;
1838 bl->inserted = (val == 0);
1841 else if (bl->owner->type == bp_catchpoint)
1843 gdb_assert (bl->owner->ops != NULL
1844 && bl->owner->ops->insert_location != NULL);
1846 val = bl->owner->ops->insert_location (bl);
1849 bl->owner->enable_state = bp_disabled;
1853 Error inserting catchpoint %d: Your system does not support this type\n\
1854 of catchpoint."), bl->owner->number);
1856 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1859 bl->inserted = (val == 0);
1861 /* We've already printed an error message if there was a problem
1862 inserting this catchpoint, and we've disabled the catchpoint,
1863 so just return success. */
1870 /* This function is called when program space PSPACE is about to be
1871 deleted. It takes care of updating breakpoints to not reference
1875 breakpoint_program_space_exit (struct program_space *pspace)
1877 struct breakpoint *b, *b_temp;
1878 struct bp_location *loc, **loc_temp;
1880 /* Remove any breakpoint that was set through this program space. */
1881 ALL_BREAKPOINTS_SAFE (b, b_temp)
1883 if (b->pspace == pspace)
1884 delete_breakpoint (b);
1887 /* Breakpoints set through other program spaces could have locations
1888 bound to PSPACE as well. Remove those. */
1889 ALL_BP_LOCATIONS (loc, loc_temp)
1891 struct bp_location *tmp;
1893 if (loc->pspace == pspace)
1895 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1896 if (loc->owner->loc == loc)
1897 loc->owner->loc = loc->next;
1899 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1900 if (tmp->next == loc)
1902 tmp->next = loc->next;
1908 /* Now update the global location list to permanently delete the
1909 removed locations above. */
1910 update_global_location_list (0);
1913 /* Make sure all breakpoints are inserted in inferior.
1914 Throws exception on any error.
1915 A breakpoint that is already inserted won't be inserted
1916 again, so calling this function twice is safe. */
1918 insert_breakpoints (void)
1920 struct breakpoint *bpt;
1922 ALL_BREAKPOINTS (bpt)
1923 if (is_hardware_watchpoint (bpt))
1925 struct watchpoint *w = (struct watchpoint *) bpt;
1927 update_watchpoint (w, 0 /* don't reparse. */);
1930 update_global_location_list (1);
1932 /* update_global_location_list does not insert breakpoints when
1933 always_inserted_mode is not enabled. Explicitly insert them
1935 if (!breakpoints_always_inserted_mode ())
1936 insert_breakpoint_locations ();
1939 /* Used when starting or continuing the program. */
1942 insert_breakpoint_locations (void)
1944 struct breakpoint *bpt;
1945 struct bp_location *bl, **blp_tmp;
1948 int disabled_breaks = 0;
1949 int hw_breakpoint_error = 0;
1951 struct ui_file *tmp_error_stream = mem_fileopen ();
1952 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1954 /* Explicitly mark the warning -- this will only be printed if
1955 there was an error. */
1956 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1958 save_current_space_and_thread ();
1960 ALL_BP_LOCATIONS (bl, blp_tmp)
1962 if (!should_be_inserted (bl) || bl->inserted)
1965 /* There is no point inserting thread-specific breakpoints if
1966 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1967 has BL->OWNER always non-NULL. */
1968 if (bl->owner->thread != -1
1969 && !valid_thread_id (bl->owner->thread))
1972 switch_to_program_space_and_thread (bl->pspace);
1974 /* For targets that support global breakpoints, there's no need
1975 to select an inferior to insert breakpoint to. In fact, even
1976 if we aren't attached to any process yet, we should still
1977 insert breakpoints. */
1978 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1979 && ptid_equal (inferior_ptid, null_ptid))
1982 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1983 &hw_breakpoint_error);
1988 /* If we failed to insert all locations of a watchpoint, remove
1989 them, as half-inserted watchpoint is of limited use. */
1990 ALL_BREAKPOINTS (bpt)
1992 int some_failed = 0;
1993 struct bp_location *loc;
1995 if (!is_hardware_watchpoint (bpt))
1998 if (!breakpoint_enabled (bpt))
2001 if (bpt->disposition == disp_del_at_next_stop)
2004 for (loc = bpt->loc; loc; loc = loc->next)
2005 if (!loc->inserted && should_be_inserted (loc))
2012 for (loc = bpt->loc; loc; loc = loc->next)
2014 remove_breakpoint (loc, mark_uninserted);
2016 hw_breakpoint_error = 1;
2017 fprintf_unfiltered (tmp_error_stream,
2018 "Could not insert hardware watchpoint %d.\n",
2026 /* If a hardware breakpoint or watchpoint was inserted, add a
2027 message about possibly exhausted resources. */
2028 if (hw_breakpoint_error)
2030 fprintf_unfiltered (tmp_error_stream,
2031 "Could not insert hardware breakpoints:\n\
2032 You may have requested too many hardware breakpoints/watchpoints.\n");
2034 target_terminal_ours_for_output ();
2035 error_stream (tmp_error_stream);
2038 do_cleanups (cleanups);
2041 /* Used when the program stops.
2042 Returns zero if successful, or non-zero if there was a problem
2043 removing a breakpoint location. */
2046 remove_breakpoints (void)
2048 struct bp_location *bl, **blp_tmp;
2051 ALL_BP_LOCATIONS (bl, blp_tmp)
2053 if (bl->inserted && !is_tracepoint (bl->owner))
2054 val |= remove_breakpoint (bl, mark_uninserted);
2059 /* Remove breakpoints of process PID. */
2062 remove_breakpoints_pid (int pid)
2064 struct bp_location *bl, **blp_tmp;
2066 struct inferior *inf = find_inferior_pid (pid);
2068 ALL_BP_LOCATIONS (bl, blp_tmp)
2070 if (bl->pspace != inf->pspace)
2075 val = remove_breakpoint (bl, mark_uninserted);
2084 reattach_breakpoints (int pid)
2086 struct cleanup *old_chain;
2087 struct bp_location *bl, **blp_tmp;
2089 struct ui_file *tmp_error_stream;
2090 int dummy1 = 0, dummy2 = 0;
2091 struct inferior *inf;
2092 struct thread_info *tp;
2094 tp = any_live_thread_of_process (pid);
2098 inf = find_inferior_pid (pid);
2099 old_chain = save_inferior_ptid ();
2101 inferior_ptid = tp->ptid;
2103 tmp_error_stream = mem_fileopen ();
2104 make_cleanup_ui_file_delete (tmp_error_stream);
2106 ALL_BP_LOCATIONS (bl, blp_tmp)
2108 if (bl->pspace != inf->pspace)
2114 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2117 do_cleanups (old_chain);
2122 do_cleanups (old_chain);
2126 static int internal_breakpoint_number = -1;
2128 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2129 If INTERNAL is non-zero, the breakpoint number will be populated
2130 from internal_breakpoint_number and that variable decremented.
2131 Otherwise the breakpoint number will be populated from
2132 breakpoint_count and that value incremented. Internal breakpoints
2133 do not set the internal var bpnum. */
2135 set_breakpoint_number (int internal, struct breakpoint *b)
2138 b->number = internal_breakpoint_number--;
2141 set_breakpoint_count (breakpoint_count + 1);
2142 b->number = breakpoint_count;
2146 static struct breakpoint *
2147 create_internal_breakpoint (struct gdbarch *gdbarch,
2148 CORE_ADDR address, enum bptype type,
2149 const struct breakpoint_ops *ops)
2151 struct symtab_and_line sal;
2152 struct breakpoint *b;
2154 init_sal (&sal); /* Initialize to zeroes. */
2157 sal.section = find_pc_overlay (sal.pc);
2158 sal.pspace = current_program_space;
2160 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2161 b->number = internal_breakpoint_number--;
2162 b->disposition = disp_donttouch;
2167 static const char *const longjmp_names[] =
2169 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2171 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2173 /* Per-objfile data private to breakpoint.c. */
2174 struct breakpoint_objfile_data
2176 /* Minimal symbol for "_ovly_debug_event" (if any). */
2177 struct minimal_symbol *overlay_msym;
2179 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2180 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2182 /* Minimal symbol for "std::terminate()" (if any). */
2183 struct minimal_symbol *terminate_msym;
2185 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2186 struct minimal_symbol *exception_msym;
2189 static const struct objfile_data *breakpoint_objfile_key;
2191 /* Minimal symbol not found sentinel. */
2192 static struct minimal_symbol msym_not_found;
2194 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2197 msym_not_found_p (const struct minimal_symbol *msym)
2199 return msym == &msym_not_found;
2202 /* Return per-objfile data needed by breakpoint.c.
2203 Allocate the data if necessary. */
2205 static struct breakpoint_objfile_data *
2206 get_breakpoint_objfile_data (struct objfile *objfile)
2208 struct breakpoint_objfile_data *bp_objfile_data;
2210 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2211 if (bp_objfile_data == NULL)
2213 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2214 sizeof (*bp_objfile_data));
2216 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2217 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2219 return bp_objfile_data;
2223 create_overlay_event_breakpoint (void)
2225 struct objfile *objfile;
2226 const char *const func_name = "_ovly_debug_event";
2228 ALL_OBJFILES (objfile)
2230 struct breakpoint *b;
2231 struct breakpoint_objfile_data *bp_objfile_data;
2234 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2236 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2239 if (bp_objfile_data->overlay_msym == NULL)
2241 struct minimal_symbol *m;
2243 m = lookup_minimal_symbol_text (func_name, objfile);
2246 /* Avoid future lookups in this objfile. */
2247 bp_objfile_data->overlay_msym = &msym_not_found;
2250 bp_objfile_data->overlay_msym = m;
2253 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2254 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2256 &internal_breakpoint_ops);
2257 b->addr_string = xstrdup (func_name);
2259 if (overlay_debugging == ovly_auto)
2261 b->enable_state = bp_enabled;
2262 overlay_events_enabled = 1;
2266 b->enable_state = bp_disabled;
2267 overlay_events_enabled = 0;
2270 update_global_location_list (1);
2274 create_longjmp_master_breakpoint (void)
2276 struct program_space *pspace;
2277 struct cleanup *old_chain;
2279 old_chain = save_current_program_space ();
2281 ALL_PSPACES (pspace)
2283 struct objfile *objfile;
2285 set_current_program_space (pspace);
2287 ALL_OBJFILES (objfile)
2290 struct gdbarch *gdbarch;
2291 struct breakpoint_objfile_data *bp_objfile_data;
2293 gdbarch = get_objfile_arch (objfile);
2294 if (!gdbarch_get_longjmp_target_p (gdbarch))
2297 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2299 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2301 struct breakpoint *b;
2302 const char *func_name;
2305 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2308 func_name = longjmp_names[i];
2309 if (bp_objfile_data->longjmp_msym[i] == NULL)
2311 struct minimal_symbol *m;
2313 m = lookup_minimal_symbol_text (func_name, objfile);
2316 /* Prevent future lookups in this objfile. */
2317 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2320 bp_objfile_data->longjmp_msym[i] = m;
2323 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2324 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2325 &internal_breakpoint_ops);
2326 b->addr_string = xstrdup (func_name);
2327 b->enable_state = bp_disabled;
2331 update_global_location_list (1);
2333 do_cleanups (old_chain);
2336 /* Create a master std::terminate breakpoint. */
2338 create_std_terminate_master_breakpoint (void)
2340 struct program_space *pspace;
2341 struct cleanup *old_chain;
2342 const char *const func_name = "std::terminate()";
2344 old_chain = save_current_program_space ();
2346 ALL_PSPACES (pspace)
2348 struct objfile *objfile;
2351 set_current_program_space (pspace);
2353 ALL_OBJFILES (objfile)
2355 struct breakpoint *b;
2356 struct breakpoint_objfile_data *bp_objfile_data;
2358 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2360 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2363 if (bp_objfile_data->terminate_msym == NULL)
2365 struct minimal_symbol *m;
2367 m = lookup_minimal_symbol (func_name, NULL, objfile);
2368 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2369 && MSYMBOL_TYPE (m) != mst_file_text))
2371 /* Prevent future lookups in this objfile. */
2372 bp_objfile_data->terminate_msym = &msym_not_found;
2375 bp_objfile_data->terminate_msym = m;
2378 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2379 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2380 bp_std_terminate_master,
2381 &internal_breakpoint_ops);
2382 b->addr_string = xstrdup (func_name);
2383 b->enable_state = bp_disabled;
2387 update_global_location_list (1);
2389 do_cleanups (old_chain);
2392 /* Install a master breakpoint on the unwinder's debug hook. */
2395 create_exception_master_breakpoint (void)
2397 struct objfile *objfile;
2398 const char *const func_name = "_Unwind_DebugHook";
2400 ALL_OBJFILES (objfile)
2402 struct breakpoint *b;
2403 struct gdbarch *gdbarch;
2404 struct breakpoint_objfile_data *bp_objfile_data;
2407 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2409 if (msym_not_found_p (bp_objfile_data->exception_msym))
2412 gdbarch = get_objfile_arch (objfile);
2414 if (bp_objfile_data->exception_msym == NULL)
2416 struct minimal_symbol *debug_hook;
2418 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2419 if (debug_hook == NULL)
2421 bp_objfile_data->exception_msym = &msym_not_found;
2425 bp_objfile_data->exception_msym = debug_hook;
2428 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2429 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2431 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2432 &internal_breakpoint_ops);
2433 b->addr_string = xstrdup (func_name);
2434 b->enable_state = bp_disabled;
2437 update_global_location_list (1);
2441 update_breakpoints_after_exec (void)
2443 struct breakpoint *b, *b_tmp;
2444 struct bp_location *bploc, **bplocp_tmp;
2446 /* We're about to delete breakpoints from GDB's lists. If the
2447 INSERTED flag is true, GDB will try to lift the breakpoints by
2448 writing the breakpoints' "shadow contents" back into memory. The
2449 "shadow contents" are NOT valid after an exec, so GDB should not
2450 do that. Instead, the target is responsible from marking
2451 breakpoints out as soon as it detects an exec. We don't do that
2452 here instead, because there may be other attempts to delete
2453 breakpoints after detecting an exec and before reaching here. */
2454 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2455 if (bploc->pspace == current_program_space)
2456 gdb_assert (!bploc->inserted);
2458 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2460 if (b->pspace != current_program_space)
2463 /* Solib breakpoints must be explicitly reset after an exec(). */
2464 if (b->type == bp_shlib_event)
2466 delete_breakpoint (b);
2470 /* JIT breakpoints must be explicitly reset after an exec(). */
2471 if (b->type == bp_jit_event)
2473 delete_breakpoint (b);
2477 /* Thread event breakpoints must be set anew after an exec(),
2478 as must overlay event and longjmp master breakpoints. */
2479 if (b->type == bp_thread_event || b->type == bp_overlay_event
2480 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2481 || b->type == bp_exception_master)
2483 delete_breakpoint (b);
2487 /* Step-resume breakpoints are meaningless after an exec(). */
2488 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
2490 delete_breakpoint (b);
2494 /* Longjmp and longjmp-resume breakpoints are also meaningless
2496 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2497 || b->type == bp_exception || b->type == bp_exception_resume)
2499 delete_breakpoint (b);
2503 if (b->type == bp_catchpoint)
2505 /* For now, none of the bp_catchpoint breakpoints need to
2506 do anything at this point. In the future, if some of
2507 the catchpoints need to something, we will need to add
2508 a new method, and call this method from here. */
2512 /* bp_finish is a special case. The only way we ought to be able
2513 to see one of these when an exec() has happened, is if the user
2514 caught a vfork, and then said "finish". Ordinarily a finish just
2515 carries them to the call-site of the current callee, by setting
2516 a temporary bp there and resuming. But in this case, the finish
2517 will carry them entirely through the vfork & exec.
2519 We don't want to allow a bp_finish to remain inserted now. But
2520 we can't safely delete it, 'cause finish_command has a handle to
2521 the bp on a bpstat, and will later want to delete it. There's a
2522 chance (and I've seen it happen) that if we delete the bp_finish
2523 here, that its storage will get reused by the time finish_command
2524 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2525 We really must allow finish_command to delete a bp_finish.
2527 In the absence of a general solution for the "how do we know
2528 it's safe to delete something others may have handles to?"
2529 problem, what we'll do here is just uninsert the bp_finish, and
2530 let finish_command delete it.
2532 (We know the bp_finish is "doomed" in the sense that it's
2533 momentary, and will be deleted as soon as finish_command sees
2534 the inferior stopped. So it doesn't matter that the bp's
2535 address is probably bogus in the new a.out, unlike e.g., the
2536 solib breakpoints.) */
2538 if (b->type == bp_finish)
2543 /* Without a symbolic address, we have little hope of the
2544 pre-exec() address meaning the same thing in the post-exec()
2546 if (b->addr_string == NULL)
2548 delete_breakpoint (b);
2552 /* FIXME what about longjmp breakpoints? Re-create them here? */
2553 create_overlay_event_breakpoint ();
2554 create_longjmp_master_breakpoint ();
2555 create_std_terminate_master_breakpoint ();
2556 create_exception_master_breakpoint ();
2560 detach_breakpoints (int pid)
2562 struct bp_location *bl, **blp_tmp;
2564 struct cleanup *old_chain = save_inferior_ptid ();
2565 struct inferior *inf = current_inferior ();
2567 if (pid == PIDGET (inferior_ptid))
2568 error (_("Cannot detach breakpoints of inferior_ptid"));
2570 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2571 inferior_ptid = pid_to_ptid (pid);
2572 ALL_BP_LOCATIONS (bl, blp_tmp)
2574 if (bl->pspace != inf->pspace)
2578 val |= remove_breakpoint_1 (bl, mark_inserted);
2581 /* Detach single-step breakpoints as well. */
2582 detach_single_step_breakpoints ();
2584 do_cleanups (old_chain);
2588 /* Remove the breakpoint location BL from the current address space.
2589 Note that this is used to detach breakpoints from a child fork.
2590 When we get here, the child isn't in the inferior list, and neither
2591 do we have objects to represent its address space --- we should
2592 *not* look at bl->pspace->aspace here. */
2595 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2599 /* BL is never in moribund_locations by our callers. */
2600 gdb_assert (bl->owner != NULL);
2602 if (bl->owner->enable_state == bp_permanent)
2603 /* Permanent breakpoints cannot be inserted or removed. */
2606 /* The type of none suggests that owner is actually deleted.
2607 This should not ever happen. */
2608 gdb_assert (bl->owner->type != bp_none);
2610 if (bl->loc_type == bp_loc_software_breakpoint
2611 || bl->loc_type == bp_loc_hardware_breakpoint)
2613 /* "Normal" instruction breakpoint: either the standard
2614 trap-instruction bp (bp_breakpoint), or a
2615 bp_hardware_breakpoint. */
2617 /* First check to see if we have to handle an overlay. */
2618 if (overlay_debugging == ovly_off
2619 || bl->section == NULL
2620 || !(section_is_overlay (bl->section)))
2622 /* No overlay handling: just remove the breakpoint. */
2623 val = bl->owner->ops->remove_location (bl);
2627 /* This breakpoint is in an overlay section.
2628 Did we set a breakpoint at the LMA? */
2629 if (!overlay_events_enabled)
2631 /* Yes -- overlay event support is not active, so we
2632 should have set a breakpoint at the LMA. Remove it.
2634 /* Ignore any failures: if the LMA is in ROM, we will
2635 have already warned when we failed to insert it. */
2636 if (bl->loc_type == bp_loc_hardware_breakpoint)
2637 target_remove_hw_breakpoint (bl->gdbarch,
2638 &bl->overlay_target_info);
2640 target_remove_breakpoint (bl->gdbarch,
2641 &bl->overlay_target_info);
2643 /* Did we set a breakpoint at the VMA?
2644 If so, we will have marked the breakpoint 'inserted'. */
2647 /* Yes -- remove it. Previously we did not bother to
2648 remove the breakpoint if the section had been
2649 unmapped, but let's not rely on that being safe. We
2650 don't know what the overlay manager might do. */
2652 /* However, we should remove *software* breakpoints only
2653 if the section is still mapped, or else we overwrite
2654 wrong code with the saved shadow contents. */
2655 if (bl->loc_type == bp_loc_hardware_breakpoint
2656 || section_is_mapped (bl->section))
2657 val = bl->owner->ops->remove_location (bl);
2663 /* No -- not inserted, so no need to remove. No error. */
2668 /* In some cases, we might not be able to remove a breakpoint
2669 in a shared library that has already been removed, but we
2670 have not yet processed the shlib unload event. */
2671 if (val && solib_name_from_address (bl->pspace, bl->address))
2676 bl->inserted = (is == mark_inserted);
2678 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2680 gdb_assert (bl->owner->ops != NULL
2681 && bl->owner->ops->remove_location != NULL);
2683 bl->inserted = (is == mark_inserted);
2684 bl->owner->ops->remove_location (bl);
2686 /* Failure to remove any of the hardware watchpoints comes here. */
2687 if ((is == mark_uninserted) && (bl->inserted))
2688 warning (_("Could not remove hardware watchpoint %d."),
2691 else if (bl->owner->type == bp_catchpoint
2692 && breakpoint_enabled (bl->owner)
2695 gdb_assert (bl->owner->ops != NULL
2696 && bl->owner->ops->remove_location != NULL);
2698 val = bl->owner->ops->remove_location (bl);
2702 bl->inserted = (is == mark_inserted);
2709 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2712 struct cleanup *old_chain;
2714 /* BL is never in moribund_locations by our callers. */
2715 gdb_assert (bl->owner != NULL);
2717 if (bl->owner->enable_state == bp_permanent)
2718 /* Permanent breakpoints cannot be inserted or removed. */
2721 /* The type of none suggests that owner is actually deleted.
2722 This should not ever happen. */
2723 gdb_assert (bl->owner->type != bp_none);
2725 old_chain = save_current_space_and_thread ();
2727 switch_to_program_space_and_thread (bl->pspace);
2729 ret = remove_breakpoint_1 (bl, is);
2731 do_cleanups (old_chain);
2735 /* Clear the "inserted" flag in all breakpoints. */
2738 mark_breakpoints_out (void)
2740 struct bp_location *bl, **blp_tmp;
2742 ALL_BP_LOCATIONS (bl, blp_tmp)
2743 if (bl->pspace == current_program_space)
2747 /* Clear the "inserted" flag in all breakpoints and delete any
2748 breakpoints which should go away between runs of the program.
2750 Plus other such housekeeping that has to be done for breakpoints
2753 Note: this function gets called at the end of a run (by
2754 generic_mourn_inferior) and when a run begins (by
2755 init_wait_for_inferior). */
2760 breakpoint_init_inferior (enum inf_context context)
2762 struct breakpoint *b, *b_tmp;
2763 struct bp_location *bl, **blp_tmp;
2765 struct program_space *pspace = current_program_space;
2767 /* If breakpoint locations are shared across processes, then there's
2769 if (gdbarch_has_global_breakpoints (target_gdbarch))
2772 ALL_BP_LOCATIONS (bl, blp_tmp)
2774 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2775 if (bl->pspace == pspace
2776 && bl->owner->enable_state != bp_permanent)
2780 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2782 if (b->loc && b->loc->pspace != pspace)
2789 /* If the call dummy breakpoint is at the entry point it will
2790 cause problems when the inferior is rerun, so we better get
2793 case bp_watchpoint_scope:
2795 /* Also get rid of scope breakpoints. */
2797 case bp_shlib_event:
2799 /* Also remove solib event breakpoints. Their addresses may
2800 have changed since the last time we ran the program.
2801 Actually we may now be debugging against different target;
2802 and so the solib backend that installed this breakpoint may
2803 not be used in by the target. E.g.,
2805 (gdb) file prog-linux
2806 (gdb) run # native linux target
2809 (gdb) file prog-win.exe
2810 (gdb) tar rem :9999 # remote Windows gdbserver.
2813 delete_breakpoint (b);
2817 case bp_hardware_watchpoint:
2818 case bp_read_watchpoint:
2819 case bp_access_watchpoint:
2821 struct watchpoint *w = (struct watchpoint *) b;
2823 /* Likewise for watchpoints on local expressions. */
2824 if (w->exp_valid_block != NULL)
2825 delete_breakpoint (b);
2826 else if (context == inf_starting)
2828 /* Reset val field to force reread of starting value in
2829 insert_breakpoints. */
2831 value_free (w->val);
2842 /* Get rid of the moribund locations. */
2843 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2844 decref_bp_location (&bl);
2845 VEC_free (bp_location_p, moribund_locations);
2848 /* These functions concern about actual breakpoints inserted in the
2849 target --- to e.g. check if we need to do decr_pc adjustment or if
2850 we need to hop over the bkpt --- so we check for address space
2851 match, not program space. */
2853 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2854 exists at PC. It returns ordinary_breakpoint_here if it's an
2855 ordinary breakpoint, or permanent_breakpoint_here if it's a
2856 permanent breakpoint.
2857 - When continuing from a location with an ordinary breakpoint, we
2858 actually single step once before calling insert_breakpoints.
2859 - When continuing from a location with a permanent breakpoint, we
2860 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2861 the target, to advance the PC past the breakpoint. */
2863 enum breakpoint_here
2864 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2866 struct bp_location *bl, **blp_tmp;
2867 int any_breakpoint_here = 0;
2869 ALL_BP_LOCATIONS (bl, blp_tmp)
2871 if (bl->loc_type != bp_loc_software_breakpoint
2872 && bl->loc_type != bp_loc_hardware_breakpoint)
2875 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2876 if ((breakpoint_enabled (bl->owner)
2877 || bl->owner->enable_state == bp_permanent)
2878 && breakpoint_location_address_match (bl, aspace, pc))
2880 if (overlay_debugging
2881 && section_is_overlay (bl->section)
2882 && !section_is_mapped (bl->section))
2883 continue; /* unmapped overlay -- can't be a match */
2884 else if (bl->owner->enable_state == bp_permanent)
2885 return permanent_breakpoint_here;
2887 any_breakpoint_here = 1;
2891 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2894 /* Return true if there's a moribund breakpoint at PC. */
2897 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2899 struct bp_location *loc;
2902 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2903 if (breakpoint_location_address_match (loc, aspace, pc))
2909 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2910 inserted using regular breakpoint_chain / bp_location array
2911 mechanism. This does not check for single-step breakpoints, which
2912 are inserted and removed using direct target manipulation. */
2915 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2918 struct bp_location *bl, **blp_tmp;
2920 ALL_BP_LOCATIONS (bl, blp_tmp)
2922 if (bl->loc_type != bp_loc_software_breakpoint
2923 && bl->loc_type != bp_loc_hardware_breakpoint)
2927 && breakpoint_location_address_match (bl, aspace, pc))
2929 if (overlay_debugging
2930 && section_is_overlay (bl->section)
2931 && !section_is_mapped (bl->section))
2932 continue; /* unmapped overlay -- can't be a match */
2940 /* Returns non-zero iff there's either regular breakpoint
2941 or a single step breakpoint inserted at PC. */
2944 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2946 if (regular_breakpoint_inserted_here_p (aspace, pc))
2949 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2955 /* This function returns non-zero iff there is a software breakpoint
2959 software_breakpoint_inserted_here_p (struct address_space *aspace,
2962 struct bp_location *bl, **blp_tmp;
2964 ALL_BP_LOCATIONS (bl, blp_tmp)
2966 if (bl->loc_type != bp_loc_software_breakpoint)
2970 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2973 if (overlay_debugging
2974 && section_is_overlay (bl->section)
2975 && !section_is_mapped (bl->section))
2976 continue; /* unmapped overlay -- can't be a match */
2982 /* Also check for software single-step breakpoints. */
2983 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2990 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2991 CORE_ADDR addr, ULONGEST len)
2993 struct breakpoint *bpt;
2995 ALL_BREAKPOINTS (bpt)
2997 struct bp_location *loc;
2999 if (bpt->type != bp_hardware_watchpoint
3000 && bpt->type != bp_access_watchpoint)
3003 if (!breakpoint_enabled (bpt))
3006 for (loc = bpt->loc; loc; loc = loc->next)
3007 if (loc->pspace->aspace == aspace && loc->inserted)
3011 /* Check for intersection. */
3012 l = max (loc->address, addr);
3013 h = min (loc->address + loc->length, addr + len);
3021 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3022 PC is valid for process/thread PTID. */
3025 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3028 struct bp_location *bl, **blp_tmp;
3029 /* The thread and task IDs associated to PTID, computed lazily. */
3033 ALL_BP_LOCATIONS (bl, blp_tmp)
3035 if (bl->loc_type != bp_loc_software_breakpoint
3036 && bl->loc_type != bp_loc_hardware_breakpoint)
3039 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3040 if (!breakpoint_enabled (bl->owner)
3041 && bl->owner->enable_state != bp_permanent)
3044 if (!breakpoint_location_address_match (bl, aspace, pc))
3047 if (bl->owner->thread != -1)
3049 /* This is a thread-specific breakpoint. Check that ptid
3050 matches that thread. If thread hasn't been computed yet,
3051 it is now time to do so. */
3053 thread = pid_to_thread_id (ptid);
3054 if (bl->owner->thread != thread)
3058 if (bl->owner->task != 0)
3060 /* This is a task-specific breakpoint. Check that ptid
3061 matches that task. If task hasn't been computed yet,
3062 it is now time to do so. */
3064 task = ada_get_task_number (ptid);
3065 if (bl->owner->task != task)
3069 if (overlay_debugging
3070 && section_is_overlay (bl->section)
3071 && !section_is_mapped (bl->section))
3072 continue; /* unmapped overlay -- can't be a match */
3081 /* bpstat stuff. External routines' interfaces are documented
3085 ep_is_catchpoint (struct breakpoint *ep)
3087 return (ep->type == bp_catchpoint);
3090 /* Frees any storage that is part of a bpstat. Does not walk the
3094 bpstat_free (bpstat bs)
3096 if (bs->old_val != NULL)
3097 value_free (bs->old_val);
3098 decref_counted_command_line (&bs->commands);
3099 decref_bp_location (&bs->bp_location_at);
3103 /* Clear a bpstat so that it says we are not at any breakpoint.
3104 Also free any storage that is part of a bpstat. */
3107 bpstat_clear (bpstat *bsp)
3124 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3125 is part of the bpstat is copied as well. */
3128 bpstat_copy (bpstat bs)
3132 bpstat retval = NULL;
3137 for (; bs != NULL; bs = bs->next)
3139 tmp = (bpstat) xmalloc (sizeof (*tmp));
3140 memcpy (tmp, bs, sizeof (*tmp));
3141 incref_counted_command_line (tmp->commands);
3142 incref_bp_location (tmp->bp_location_at);
3143 if (bs->old_val != NULL)
3145 tmp->old_val = value_copy (bs->old_val);
3146 release_value (tmp->old_val);
3150 /* This is the first thing in the chain. */
3160 /* Find the bpstat associated with this breakpoint. */
3163 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3168 for (; bsp != NULL; bsp = bsp->next)
3170 if (bsp->breakpoint_at == breakpoint)
3176 /* Put in *NUM the breakpoint number of the first breakpoint we are
3177 stopped at. *BSP upon return is a bpstat which points to the
3178 remaining breakpoints stopped at (but which is not guaranteed to be
3179 good for anything but further calls to bpstat_num).
3181 Return 0 if passed a bpstat which does not indicate any breakpoints.
3182 Return -1 if stopped at a breakpoint that has been deleted since
3184 Return 1 otherwise. */
3187 bpstat_num (bpstat *bsp, int *num)
3189 struct breakpoint *b;
3192 return 0; /* No more breakpoint values */
3194 /* We assume we'll never have several bpstats that correspond to a
3195 single breakpoint -- otherwise, this function might return the
3196 same number more than once and this will look ugly. */
3197 b = (*bsp)->breakpoint_at;
3198 *bsp = (*bsp)->next;
3200 return -1; /* breakpoint that's been deleted since */
3202 *num = b->number; /* We have its number */
3206 /* See breakpoint.h. */
3209 bpstat_clear_actions (void)
3211 struct thread_info *tp;
3214 if (ptid_equal (inferior_ptid, null_ptid))
3217 tp = find_thread_ptid (inferior_ptid);
3221 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3223 decref_counted_command_line (&bs->commands);
3225 if (bs->old_val != NULL)
3227 value_free (bs->old_val);
3233 /* Called when a command is about to proceed the inferior. */
3236 breakpoint_about_to_proceed (void)
3238 if (!ptid_equal (inferior_ptid, null_ptid))
3240 struct thread_info *tp = inferior_thread ();
3242 /* Allow inferior function calls in breakpoint commands to not
3243 interrupt the command list. When the call finishes
3244 successfully, the inferior will be standing at the same
3245 breakpoint as if nothing happened. */
3246 if (tp->control.in_infcall)
3250 breakpoint_proceeded = 1;
3253 /* Stub for cleaning up our state if we error-out of a breakpoint
3256 cleanup_executing_breakpoints (void *ignore)
3258 executing_breakpoint_commands = 0;
3261 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3262 or its equivalent. */
3265 command_line_is_silent (struct command_line *cmd)
3267 return cmd && (strcmp ("silent", cmd->line) == 0
3268 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3271 /* Execute all the commands associated with all the breakpoints at
3272 this location. Any of these commands could cause the process to
3273 proceed beyond this point, etc. We look out for such changes by
3274 checking the global "breakpoint_proceeded" after each command.
3276 Returns true if a breakpoint command resumed the inferior. In that
3277 case, it is the caller's responsibility to recall it again with the
3278 bpstat of the current thread. */
3281 bpstat_do_actions_1 (bpstat *bsp)
3284 struct cleanup *old_chain;
3287 /* Avoid endless recursion if a `source' command is contained
3289 if (executing_breakpoint_commands)
3292 executing_breakpoint_commands = 1;
3293 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3295 prevent_dont_repeat ();
3297 /* This pointer will iterate over the list of bpstat's. */
3300 breakpoint_proceeded = 0;
3301 for (; bs != NULL; bs = bs->next)
3303 struct counted_command_line *ccmd;
3304 struct command_line *cmd;
3305 struct cleanup *this_cmd_tree_chain;
3307 /* Take ownership of the BSP's command tree, if it has one.
3309 The command tree could legitimately contain commands like
3310 'step' and 'next', which call clear_proceed_status, which
3311 frees stop_bpstat's command tree. To make sure this doesn't
3312 free the tree we're executing out from under us, we need to
3313 take ownership of the tree ourselves. Since a given bpstat's
3314 commands are only executed once, we don't need to copy it; we
3315 can clear the pointer in the bpstat, and make sure we free
3316 the tree when we're done. */
3317 ccmd = bs->commands;
3318 bs->commands = NULL;
3319 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3320 cmd = ccmd ? ccmd->commands : NULL;
3321 if (command_line_is_silent (cmd))
3323 /* The action has been already done by bpstat_stop_status. */
3329 execute_control_command (cmd);
3331 if (breakpoint_proceeded)
3337 /* We can free this command tree now. */
3338 do_cleanups (this_cmd_tree_chain);
3340 if (breakpoint_proceeded)
3342 if (target_can_async_p ())
3343 /* If we are in async mode, then the target might be still
3344 running, not stopped at any breakpoint, so nothing for
3345 us to do here -- just return to the event loop. */
3348 /* In sync mode, when execute_control_command returns
3349 we're already standing on the next breakpoint.
3350 Breakpoint commands for that stop were not run, since
3351 execute_command does not run breakpoint commands --
3352 only command_line_handler does, but that one is not
3353 involved in execution of breakpoint commands. So, we
3354 can now execute breakpoint commands. It should be
3355 noted that making execute_command do bpstat actions is
3356 not an option -- in this case we'll have recursive
3357 invocation of bpstat for each breakpoint with a
3358 command, and can easily blow up GDB stack. Instead, we
3359 return true, which will trigger the caller to recall us
3360 with the new stop_bpstat. */
3365 do_cleanups (old_chain);
3370 bpstat_do_actions (void)
3372 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
3374 /* Do any commands attached to breakpoint we are stopped at. */
3375 while (!ptid_equal (inferior_ptid, null_ptid)
3376 && target_has_execution
3377 && !is_exited (inferior_ptid)
3378 && !is_executing (inferior_ptid))
3379 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3380 and only return when it is stopped at the next breakpoint, we
3381 keep doing breakpoint actions until it returns false to
3382 indicate the inferior was not resumed. */
3383 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3386 discard_cleanups (cleanup_if_error);
3389 /* Print out the (old or new) value associated with a watchpoint. */
3392 watchpoint_value_print (struct value *val, struct ui_file *stream)
3395 fprintf_unfiltered (stream, _("<unreadable>"));
3398 struct value_print_options opts;
3399 get_user_print_options (&opts);
3400 value_print (val, stream, &opts);
3404 /* Generic routine for printing messages indicating why we
3405 stopped. The behavior of this function depends on the value
3406 'print_it' in the bpstat structure. Under some circumstances we
3407 may decide not to print anything here and delegate the task to
3410 static enum print_stop_action
3411 print_bp_stop_message (bpstat bs)
3413 switch (bs->print_it)
3416 /* Nothing should be printed for this bpstat entry. */
3417 return PRINT_UNKNOWN;
3421 /* We still want to print the frame, but we already printed the
3422 relevant messages. */
3423 return PRINT_SRC_AND_LOC;
3426 case print_it_normal:
3428 struct breakpoint *b = bs->breakpoint_at;
3430 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3431 which has since been deleted. */
3433 return PRINT_UNKNOWN;
3435 /* Normal case. Call the breakpoint's print_it method. */
3436 return b->ops->print_it (bs);
3441 internal_error (__FILE__, __LINE__,
3442 _("print_bp_stop_message: unrecognized enum value"));
3447 /* Print a message indicating what happened. This is called from
3448 normal_stop(). The input to this routine is the head of the bpstat
3449 list - a list of the eventpoints that caused this stop. This
3450 routine calls the generic print routine for printing a message
3451 about reasons for stopping. This will print (for example) the
3452 "Breakpoint n," part of the output. The return value of this
3455 PRINT_UNKNOWN: Means we printed nothing.
3456 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3457 code to print the location. An example is
3458 "Breakpoint 1, " which should be followed by
3460 PRINT_SRC_ONLY: Means we printed something, but there is no need
3461 to also print the location part of the message.
3462 An example is the catch/throw messages, which
3463 don't require a location appended to the end.
3464 PRINT_NOTHING: We have done some printing and we don't need any
3465 further info to be printed. */
3467 enum print_stop_action
3468 bpstat_print (bpstat bs)
3472 /* Maybe another breakpoint in the chain caused us to stop.
3473 (Currently all watchpoints go on the bpstat whether hit or not.
3474 That probably could (should) be changed, provided care is taken
3475 with respect to bpstat_explains_signal). */
3476 for (; bs; bs = bs->next)
3478 val = print_bp_stop_message (bs);
3479 if (val == PRINT_SRC_ONLY
3480 || val == PRINT_SRC_AND_LOC
3481 || val == PRINT_NOTHING)
3485 /* We reached the end of the chain, or we got a null BS to start
3486 with and nothing was printed. */
3487 return PRINT_UNKNOWN;
3490 /* Evaluate the expression EXP and return 1 if value is zero. This is
3491 used inside a catch_errors to evaluate the breakpoint condition.
3492 The argument is a "struct expression *" that has been cast to a
3493 "char *" to make it pass through catch_errors. */
3496 breakpoint_cond_eval (void *exp)
3498 struct value *mark = value_mark ();
3499 int i = !value_true (evaluate_expression ((struct expression *) exp));
3501 value_free_to_mark (mark);
3505 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3508 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3512 bs = (bpstat) xmalloc (sizeof (*bs));
3514 **bs_link_pointer = bs;
3515 *bs_link_pointer = &bs->next;
3516 bs->breakpoint_at = bl->owner;
3517 bs->bp_location_at = bl;
3518 incref_bp_location (bl);
3519 /* If the condition is false, etc., don't do the commands. */
3520 bs->commands = NULL;
3522 bs->print_it = print_it_normal;
3526 /* The target has stopped with waitstatus WS. Check if any hardware
3527 watchpoints have triggered, according to the target. */
3530 watchpoints_triggered (struct target_waitstatus *ws)
3532 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3534 struct breakpoint *b;
3536 if (!stopped_by_watchpoint)
3538 /* We were not stopped by a watchpoint. Mark all watchpoints
3539 as not triggered. */
3541 if (is_hardware_watchpoint (b))
3543 struct watchpoint *w = (struct watchpoint *) b;
3545 w->watchpoint_triggered = watch_triggered_no;
3551 if (!target_stopped_data_address (¤t_target, &addr))
3553 /* We were stopped by a watchpoint, but we don't know where.
3554 Mark all watchpoints as unknown. */
3556 if (is_hardware_watchpoint (b))
3558 struct watchpoint *w = (struct watchpoint *) b;
3560 w->watchpoint_triggered = watch_triggered_unknown;
3563 return stopped_by_watchpoint;
3566 /* The target could report the data address. Mark watchpoints
3567 affected by this data address as triggered, and all others as not
3571 if (is_hardware_watchpoint (b))
3573 struct watchpoint *w = (struct watchpoint *) b;
3574 struct bp_location *loc;
3576 w->watchpoint_triggered = watch_triggered_no;
3577 for (loc = b->loc; loc; loc = loc->next)
3579 if (is_masked_watchpoint (b))
3581 CORE_ADDR newaddr = addr & w->hw_wp_mask;
3582 CORE_ADDR start = loc->address & w->hw_wp_mask;
3584 if (newaddr == start)
3586 w->watchpoint_triggered = watch_triggered_yes;
3590 /* Exact match not required. Within range is sufficient. */
3591 else if (target_watchpoint_addr_within_range (¤t_target,
3595 w->watchpoint_triggered = watch_triggered_yes;
3604 /* Possible return values for watchpoint_check (this can't be an enum
3605 because of check_errors). */
3606 /* The watchpoint has been deleted. */
3607 #define WP_DELETED 1
3608 /* The value has changed. */
3609 #define WP_VALUE_CHANGED 2
3610 /* The value has not changed. */
3611 #define WP_VALUE_NOT_CHANGED 3
3612 /* Ignore this watchpoint, no matter if the value changed or not. */
3615 #define BP_TEMPFLAG 1
3616 #define BP_HARDWAREFLAG 2
3618 /* Evaluate watchpoint condition expression and check if its value
3621 P should be a pointer to struct bpstat, but is defined as a void *
3622 in order for this function to be usable with catch_errors. */
3625 watchpoint_check (void *p)
3627 bpstat bs = (bpstat) p;
3628 struct watchpoint *b;
3629 struct frame_info *fr;
3630 int within_current_scope;
3632 /* BS is built from an existing struct breakpoint. */
3633 gdb_assert (bs->breakpoint_at != NULL);
3634 b = (struct watchpoint *) bs->breakpoint_at;
3636 /* If this is a local watchpoint, we only want to check if the
3637 watchpoint frame is in scope if the current thread is the thread
3638 that was used to create the watchpoint. */
3639 if (!watchpoint_in_thread_scope (b))
3642 if (b->exp_valid_block == NULL)
3643 within_current_scope = 1;
3646 struct frame_info *frame = get_current_frame ();
3647 struct gdbarch *frame_arch = get_frame_arch (frame);
3648 CORE_ADDR frame_pc = get_frame_pc (frame);
3650 /* in_function_epilogue_p() returns a non-zero value if we're
3651 still in the function but the stack frame has already been
3652 invalidated. Since we can't rely on the values of local
3653 variables after the stack has been destroyed, we are treating
3654 the watchpoint in that state as `not changed' without further
3655 checking. Don't mark watchpoints as changed if the current
3656 frame is in an epilogue - even if they are in some other
3657 frame, our view of the stack is likely to be wrong and
3658 frame_find_by_id could error out. */
3659 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3662 fr = frame_find_by_id (b->watchpoint_frame);
3663 within_current_scope = (fr != NULL);
3665 /* If we've gotten confused in the unwinder, we might have
3666 returned a frame that can't describe this variable. */
3667 if (within_current_scope)
3669 struct symbol *function;
3671 function = get_frame_function (fr);
3672 if (function == NULL
3673 || !contained_in (b->exp_valid_block,
3674 SYMBOL_BLOCK_VALUE (function)))
3675 within_current_scope = 0;
3678 if (within_current_scope)
3679 /* If we end up stopping, the current frame will get selected
3680 in normal_stop. So this call to select_frame won't affect
3685 if (within_current_scope)
3687 /* We use value_{,free_to_}mark because it could be a *long*
3688 time before we return to the command level and call
3689 free_all_values. We can't call free_all_values because we
3690 might be in the middle of evaluating a function call. */
3694 struct value *new_val;
3696 if (is_masked_watchpoint (&b->base))
3697 /* Since we don't know the exact trigger address (from
3698 stopped_data_address), just tell the user we've triggered
3699 a mask watchpoint. */
3700 return WP_VALUE_CHANGED;
3702 mark = value_mark ();
3703 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3705 /* We use value_equal_contents instead of value_equal because
3706 the latter coerces an array to a pointer, thus comparing just
3707 the address of the array instead of its contents. This is
3708 not what we want. */
3709 if ((b->val != NULL) != (new_val != NULL)
3710 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3712 if (new_val != NULL)
3714 release_value (new_val);
3715 value_free_to_mark (mark);
3717 bs->old_val = b->val;
3720 return WP_VALUE_CHANGED;
3724 /* Nothing changed. */
3725 value_free_to_mark (mark);
3726 return WP_VALUE_NOT_CHANGED;
3731 struct ui_out *uiout = current_uiout;
3733 /* This seems like the only logical thing to do because
3734 if we temporarily ignored the watchpoint, then when
3735 we reenter the block in which it is valid it contains
3736 garbage (in the case of a function, it may have two
3737 garbage values, one before and one after the prologue).
3738 So we can't even detect the first assignment to it and
3739 watch after that (since the garbage may or may not equal
3740 the first value assigned). */
3741 /* We print all the stop information in
3742 breakpoint_ops->print_it, but in this case, by the time we
3743 call breakpoint_ops->print_it this bp will be deleted
3744 already. So we have no choice but print the information
3746 if (ui_out_is_mi_like_p (uiout))
3748 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3749 ui_out_text (uiout, "\nWatchpoint ");
3750 ui_out_field_int (uiout, "wpnum", b->base.number);
3752 " deleted because the program has left the block in\n\
3753 which its expression is valid.\n");
3755 /* Make sure the watchpoint's commands aren't executed. */
3756 decref_counted_command_line (&b->base.commands);
3757 watchpoint_del_at_next_stop (b);
3763 /* Return true if it looks like target has stopped due to hitting
3764 breakpoint location BL. This function does not check if we should
3765 stop, only if BL explains the stop. */
3768 bpstat_check_location (const struct bp_location *bl,
3769 struct address_space *aspace, CORE_ADDR bp_addr)
3771 struct breakpoint *b = bl->owner;
3773 /* BL is from an existing breakpoint. */
3774 gdb_assert (b != NULL);
3776 return b->ops->breakpoint_hit (bl, aspace, bp_addr);
3779 /* Determine if the watched values have actually changed, and we
3780 should stop. If not, set BS->stop to 0. */
3783 bpstat_check_watchpoint (bpstat bs)
3785 const struct bp_location *bl;
3786 struct watchpoint *b;
3788 /* BS is built for existing struct breakpoint. */
3789 bl = bs->bp_location_at;
3790 gdb_assert (bl != NULL);
3791 b = (struct watchpoint *) bs->breakpoint_at;
3792 gdb_assert (b != NULL);
3795 int must_check_value = 0;
3797 if (b->base.type == bp_watchpoint)
3798 /* For a software watchpoint, we must always check the
3800 must_check_value = 1;
3801 else if (b->watchpoint_triggered == watch_triggered_yes)
3802 /* We have a hardware watchpoint (read, write, or access)
3803 and the target earlier reported an address watched by
3805 must_check_value = 1;
3806 else if (b->watchpoint_triggered == watch_triggered_unknown
3807 && b->base.type == bp_hardware_watchpoint)
3808 /* We were stopped by a hardware watchpoint, but the target could
3809 not report the data address. We must check the watchpoint's
3810 value. Access and read watchpoints are out of luck; without
3811 a data address, we can't figure it out. */
3812 must_check_value = 1;
3814 if (must_check_value)
3817 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3819 struct cleanup *cleanups = make_cleanup (xfree, message);
3820 int e = catch_errors (watchpoint_check, bs, message,
3822 do_cleanups (cleanups);
3826 /* We've already printed what needs to be printed. */
3827 bs->print_it = print_it_done;
3831 bs->print_it = print_it_noop;
3834 case WP_VALUE_CHANGED:
3835 if (b->base.type == bp_read_watchpoint)
3837 /* There are two cases to consider here:
3839 1. We're watching the triggered memory for reads.
3840 In that case, trust the target, and always report
3841 the watchpoint hit to the user. Even though
3842 reads don't cause value changes, the value may
3843 have changed since the last time it was read, and
3844 since we're not trapping writes, we will not see
3845 those, and as such we should ignore our notion of
3848 2. We're watching the triggered memory for both
3849 reads and writes. There are two ways this may
3852 2.1. This is a target that can't break on data
3853 reads only, but can break on accesses (reads or
3854 writes), such as e.g., x86. We detect this case
3855 at the time we try to insert read watchpoints.
3857 2.2. Otherwise, the target supports read
3858 watchpoints, but, the user set an access or write
3859 watchpoint watching the same memory as this read
3862 If we're watching memory writes as well as reads,
3863 ignore watchpoint hits when we find that the
3864 value hasn't changed, as reads don't cause
3865 changes. This still gives false positives when
3866 the program writes the same value to memory as
3867 what there was already in memory (we will confuse
3868 it for a read), but it's much better than
3871 int other_write_watchpoint = 0;
3873 if (bl->watchpoint_type == hw_read)
3875 struct breakpoint *other_b;
3877 ALL_BREAKPOINTS (other_b)
3878 if (other_b->type == bp_hardware_watchpoint
3879 || other_b->type == bp_access_watchpoint)
3881 struct watchpoint *other_w =
3882 (struct watchpoint *) other_b;
3884 if (other_w->watchpoint_triggered
3885 == watch_triggered_yes)
3887 other_write_watchpoint = 1;
3893 if (other_write_watchpoint
3894 || bl->watchpoint_type == hw_access)
3896 /* We're watching the same memory for writes,
3897 and the value changed since the last time we
3898 updated it, so this trap must be for a write.
3900 bs->print_it = print_it_noop;
3905 case WP_VALUE_NOT_CHANGED:
3906 if (b->base.type == bp_hardware_watchpoint
3907 || b->base.type == bp_watchpoint)
3909 /* Don't stop: write watchpoints shouldn't fire if
3910 the value hasn't changed. */
3911 bs->print_it = print_it_noop;
3919 /* Error from catch_errors. */
3920 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
3921 watchpoint_del_at_next_stop (b);
3922 /* We've already printed what needs to be printed. */
3923 bs->print_it = print_it_done;
3927 else /* must_check_value == 0 */
3929 /* This is a case where some watchpoint(s) triggered, but
3930 not at the address of this watchpoint, or else no
3931 watchpoint triggered after all. So don't print
3932 anything for this watchpoint. */
3933 bs->print_it = print_it_noop;
3940 /* Check conditions (condition proper, frame, thread and ignore count)
3941 of breakpoint referred to by BS. If we should not stop for this
3942 breakpoint, set BS->stop to 0. */
3945 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3947 int thread_id = pid_to_thread_id (ptid);
3948 const struct bp_location *bl;
3949 struct breakpoint *b;
3951 /* BS is built for existing struct breakpoint. */
3952 bl = bs->bp_location_at;
3953 gdb_assert (bl != NULL);
3954 b = bs->breakpoint_at;
3955 gdb_assert (b != NULL);
3957 if (frame_id_p (b->frame_id)
3958 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3962 int value_is_zero = 0;
3963 struct expression *cond;
3965 /* Evaluate Python breakpoints that have a "stop"
3966 method implemented. */
3967 if (b->py_bp_object)
3968 bs->stop = gdbpy_should_stop (b->py_bp_object);
3970 if (is_watchpoint (b))
3972 struct watchpoint *w = (struct watchpoint *) b;
3979 if (cond && b->disposition != disp_del_at_next_stop)
3981 int within_current_scope = 1;
3982 struct watchpoint * w;
3984 /* We use value_mark and value_free_to_mark because it could
3985 be a long time before we return to the command level and
3986 call free_all_values. We can't call free_all_values
3987 because we might be in the middle of evaluating a
3989 struct value *mark = value_mark ();
3991 if (is_watchpoint (b))
3992 w = (struct watchpoint *) b;
3996 /* Need to select the frame, with all that implies so that
3997 the conditions will have the right context. Because we
3998 use the frame, we will not see an inlined function's
3999 variables when we arrive at a breakpoint at the start
4000 of the inlined function; the current frame will be the
4002 if (w == NULL || w->cond_exp_valid_block == NULL)
4003 select_frame (get_current_frame ());
4006 struct frame_info *frame;
4008 /* For local watchpoint expressions, which particular
4009 instance of a local is being watched matters, so we
4010 keep track of the frame to evaluate the expression
4011 in. To evaluate the condition however, it doesn't
4012 really matter which instantiation of the function
4013 where the condition makes sense triggers the
4014 watchpoint. This allows an expression like "watch
4015 global if q > 10" set in `func', catch writes to
4016 global on all threads that call `func', or catch
4017 writes on all recursive calls of `func' by a single
4018 thread. We simply always evaluate the condition in
4019 the innermost frame that's executing where it makes
4020 sense to evaluate the condition. It seems
4022 frame = block_innermost_frame (w->cond_exp_valid_block);
4024 select_frame (frame);
4026 within_current_scope = 0;
4028 if (within_current_scope)
4030 = catch_errors (breakpoint_cond_eval, cond,
4031 "Error in testing breakpoint condition:\n",
4035 warning (_("Watchpoint condition cannot be tested "
4036 "in the current scope"));
4037 /* If we failed to set the right context for this
4038 watchpoint, unconditionally report it. */
4041 /* FIXME-someday, should give breakpoint #. */
4042 value_free_to_mark (mark);
4045 if (cond && value_is_zero)
4049 else if (b->thread != -1 && b->thread != thread_id)
4053 else if (b->ignore_count > 0)
4056 annotate_ignore_count_change ();
4058 /* Increase the hit count even though we don't stop. */
4060 observer_notify_breakpoint_modified (b);
4066 /* Get a bpstat associated with having just stopped at address
4067 BP_ADDR in thread PTID.
4069 Determine whether we stopped at a breakpoint, etc, or whether we
4070 don't understand this stop. Result is a chain of bpstat's such
4073 if we don't understand the stop, the result is a null pointer.
4075 if we understand why we stopped, the result is not null.
4077 Each element of the chain refers to a particular breakpoint or
4078 watchpoint at which we have stopped. (We may have stopped for
4079 several reasons concurrently.)
4081 Each element of the chain has valid next, breakpoint_at,
4082 commands, FIXME??? fields. */
4085 bpstat_stop_status (struct address_space *aspace,
4086 CORE_ADDR bp_addr, ptid_t ptid)
4088 struct breakpoint *b = NULL;
4089 struct bp_location *bl;
4090 struct bp_location *loc;
4091 /* First item of allocated bpstat's. */
4092 bpstat bs_head = NULL, *bs_link = &bs_head;
4093 /* Pointer to the last thing in the chain currently. */
4096 int need_remove_insert;
4099 /* First, build the bpstat chain with locations that explain a
4100 target stop, while being careful to not set the target running,
4101 as that may invalidate locations (in particular watchpoint
4102 locations are recreated). Resuming will happen here with
4103 breakpoint conditions or watchpoint expressions that include
4104 inferior function calls. */
4108 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4111 for (bl = b->loc; bl != NULL; bl = bl->next)
4113 /* For hardware watchpoints, we look only at the first
4114 location. The watchpoint_check function will work on the
4115 entire expression, not the individual locations. For
4116 read watchpoints, the watchpoints_triggered function has
4117 checked all locations already. */
4118 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4121 if (bl->shlib_disabled)
4124 if (!bpstat_check_location (bl, aspace, bp_addr))
4127 /* Come here if it's a watchpoint, or if the break address
4130 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4133 /* Assume we stop. Should we find a watchpoint that is not
4134 actually triggered, or if the condition of the breakpoint
4135 evaluates as false, we'll reset 'stop' to 0. */
4139 /* If this is a scope breakpoint, mark the associated
4140 watchpoint as triggered so that we will handle the
4141 out-of-scope event. We'll get to the watchpoint next
4143 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4145 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4147 w->watchpoint_triggered = watch_triggered_yes;
4152 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4154 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4156 bs = bpstat_alloc (loc, &bs_link);
4157 /* For hits of moribund locations, we should just proceed. */
4160 bs->print_it = print_it_noop;
4164 /* Now go through the locations that caused the target to stop, and
4165 check whether we're interested in reporting this stop to higher
4166 layers, or whether we should resume the target transparently. */
4170 for (bs = bs_head; bs != NULL; bs = bs->next)
4175 b = bs->breakpoint_at;
4176 b->ops->check_status (bs);
4179 bpstat_check_breakpoint_conditions (bs, ptid);
4184 observer_notify_breakpoint_modified (b);
4186 /* We will stop here. */
4187 if (b->disposition == disp_disable)
4189 if (b->enable_state != bp_permanent)
4190 b->enable_state = bp_disabled;
4195 bs->commands = b->commands;
4196 incref_counted_command_line (bs->commands);
4197 if (command_line_is_silent (bs->commands
4198 ? bs->commands->commands : NULL))
4202 /* Print nothing for this entry if we don't stop or don't print. */
4203 if (bs->stop == 0 || bs->print == 0)
4204 bs->print_it = print_it_noop;
4208 /* If we aren't stopping, the value of some hardware watchpoint may
4209 not have changed, but the intermediate memory locations we are
4210 watching may have. Don't bother if we're stopping; this will get
4212 need_remove_insert = 0;
4213 if (! bpstat_causes_stop (bs_head))
4214 for (bs = bs_head; bs != NULL; bs = bs->next)
4216 && bs->breakpoint_at
4217 && is_hardware_watchpoint (bs->breakpoint_at))
4219 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4221 update_watchpoint (w, 0 /* don't reparse. */);
4222 need_remove_insert = 1;
4225 if (need_remove_insert)
4226 update_global_location_list (1);
4227 else if (removed_any)
4228 update_global_location_list (0);
4234 handle_jit_event (void)
4236 struct frame_info *frame;
4237 struct gdbarch *gdbarch;
4239 /* Switch terminal for any messages produced by
4240 breakpoint_re_set. */
4241 target_terminal_ours_for_output ();
4243 frame = get_current_frame ();
4244 gdbarch = get_frame_arch (frame);
4246 jit_event_handler (gdbarch);
4248 target_terminal_inferior ();
4251 /* Prepare WHAT final decision for infrun. */
4253 /* Decide what infrun needs to do with this bpstat. */
4256 bpstat_what (bpstat bs_head)
4258 struct bpstat_what retval;
4259 /* We need to defer calling `solib_add', as adding new symbols
4260 resets breakpoints, which in turn deletes breakpoint locations,
4261 and hence may clear unprocessed entries in the BS chain. */
4262 int shlib_event = 0;
4266 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4267 retval.call_dummy = STOP_NONE;
4268 retval.is_longjmp = 0;
4270 for (bs = bs_head; bs != NULL; bs = bs->next)
4272 /* Extract this BS's action. After processing each BS, we check
4273 if its action overrides all we've seem so far. */
4274 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4277 if (bs->breakpoint_at == NULL)
4279 /* I suspect this can happen if it was a momentary
4280 breakpoint which has since been deleted. */
4284 bptype = bs->breakpoint_at->type;
4291 case bp_hardware_breakpoint:
4297 this_action = BPSTAT_WHAT_STOP_NOISY;
4299 this_action = BPSTAT_WHAT_STOP_SILENT;
4302 this_action = BPSTAT_WHAT_SINGLE;
4305 case bp_hardware_watchpoint:
4306 case bp_read_watchpoint:
4307 case bp_access_watchpoint:
4311 this_action = BPSTAT_WHAT_STOP_NOISY;
4313 this_action = BPSTAT_WHAT_STOP_SILENT;
4317 /* There was a watchpoint, but we're not stopping.
4318 This requires no further action. */
4323 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4324 retval.is_longjmp = bptype == bp_longjmp;
4326 case bp_longjmp_resume:
4327 case bp_exception_resume:
4328 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4329 retval.is_longjmp = bptype == bp_longjmp_resume;
4331 case bp_step_resume:
4333 this_action = BPSTAT_WHAT_STEP_RESUME;
4336 /* It is for the wrong frame. */
4337 this_action = BPSTAT_WHAT_SINGLE;
4340 case bp_hp_step_resume:
4342 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4345 /* It is for the wrong frame. */
4346 this_action = BPSTAT_WHAT_SINGLE;
4349 case bp_watchpoint_scope:
4350 case bp_thread_event:
4351 case bp_overlay_event:
4352 case bp_longjmp_master:
4353 case bp_std_terminate_master:
4354 case bp_exception_master:
4355 this_action = BPSTAT_WHAT_SINGLE;
4361 this_action = BPSTAT_WHAT_STOP_NOISY;
4363 this_action = BPSTAT_WHAT_STOP_SILENT;
4367 /* There was a catchpoint, but we're not stopping.
4368 This requires no further action. */
4371 case bp_shlib_event:
4374 /* If requested, stop when the dynamic linker notifies GDB
4375 of events. This allows the user to get control and place
4376 breakpoints in initializer routines for dynamically
4377 loaded objects (among other things). */
4378 if (stop_on_solib_events)
4379 this_action = BPSTAT_WHAT_STOP_NOISY;
4381 this_action = BPSTAT_WHAT_SINGLE;
4385 this_action = BPSTAT_WHAT_SINGLE;
4388 /* Make sure the action is stop (silent or noisy),
4389 so infrun.c pops the dummy frame. */
4390 retval.call_dummy = STOP_STACK_DUMMY;
4391 this_action = BPSTAT_WHAT_STOP_SILENT;
4393 case bp_std_terminate:
4394 /* Make sure the action is stop (silent or noisy),
4395 so infrun.c pops the dummy frame. */
4396 retval.call_dummy = STOP_STD_TERMINATE;
4397 this_action = BPSTAT_WHAT_STOP_SILENT;
4400 case bp_fast_tracepoint:
4401 case bp_static_tracepoint:
4402 /* Tracepoint hits should not be reported back to GDB, and
4403 if one got through somehow, it should have been filtered
4405 internal_error (__FILE__, __LINE__,
4406 _("bpstat_what: tracepoint encountered"));
4408 case bp_gnu_ifunc_resolver:
4409 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4410 this_action = BPSTAT_WHAT_SINGLE;
4412 case bp_gnu_ifunc_resolver_return:
4413 /* The breakpoint will be removed, execution will restart from the
4414 PC of the former breakpoint. */
4415 this_action = BPSTAT_WHAT_KEEP_CHECKING;
4418 internal_error (__FILE__, __LINE__,
4419 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4422 retval.main_action = max (retval.main_action, this_action);
4425 /* These operations may affect the bs->breakpoint_at state so they are
4426 delayed after MAIN_ACTION is decided above. */
4431 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4433 /* Check for any newly added shared libraries if we're supposed
4434 to be adding them automatically. */
4436 /* Switch terminal for any messages produced by
4437 breakpoint_re_set. */
4438 target_terminal_ours_for_output ();
4441 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4443 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4446 target_terminal_inferior ();
4452 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4454 handle_jit_event ();
4457 for (bs = bs_head; bs != NULL; bs = bs->next)
4459 struct breakpoint *b = bs->breakpoint_at;
4465 case bp_gnu_ifunc_resolver:
4466 gnu_ifunc_resolver_stop (b);
4468 case bp_gnu_ifunc_resolver_return:
4469 gnu_ifunc_resolver_return_stop (b);
4477 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4478 without hardware support). This isn't related to a specific bpstat,
4479 just to things like whether watchpoints are set. */
4482 bpstat_should_step (void)
4484 struct breakpoint *b;
4487 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4493 bpstat_causes_stop (bpstat bs)
4495 for (; bs != NULL; bs = bs->next)
4504 /* Compute a string of spaces suitable to indent the next line
4505 so it starts at the position corresponding to the table column
4506 named COL_NAME in the currently active table of UIOUT. */
4509 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
4511 static char wrap_indent[80];
4512 int i, total_width, width, align;
4516 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
4518 if (strcmp (text, col_name) == 0)
4520 gdb_assert (total_width < sizeof wrap_indent);
4521 memset (wrap_indent, ' ', total_width);
4522 wrap_indent[total_width] = 0;
4527 total_width += width + 1;
4533 /* Print the LOC location out of the list of B->LOC locations. */
4536 print_breakpoint_location (struct breakpoint *b,
4537 struct bp_location *loc)
4539 struct ui_out *uiout = current_uiout;
4540 struct cleanup *old_chain = save_current_program_space ();
4542 if (loc != NULL && loc->shlib_disabled)
4546 set_current_program_space (loc->pspace);
4548 if (b->display_canonical)
4549 ui_out_field_string (uiout, "what", b->addr_string);
4550 else if (b->source_file && loc)
4553 = find_pc_sect_function (loc->address, loc->section);
4556 ui_out_text (uiout, "in ");
4557 ui_out_field_string (uiout, "func",
4558 SYMBOL_PRINT_NAME (sym));
4559 ui_out_text (uiout, " ");
4560 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
4561 ui_out_text (uiout, "at ");
4563 ui_out_field_string (uiout, "file", b->source_file);
4564 ui_out_text (uiout, ":");
4566 if (ui_out_is_mi_like_p (uiout))
4568 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4569 char *fullname = symtab_to_fullname (sal.symtab);
4572 ui_out_field_string (uiout, "fullname", fullname);
4575 ui_out_field_int (uiout, "line", b->line_number);
4579 struct ui_stream *stb = ui_out_stream_new (uiout);
4580 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
4582 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4584 ui_out_field_stream (uiout, "at", stb);
4586 do_cleanups (stb_chain);
4589 ui_out_field_string (uiout, "pending", b->addr_string);
4591 do_cleanups (old_chain);
4595 bptype_string (enum bptype type)
4597 struct ep_type_description
4602 static struct ep_type_description bptypes[] =
4604 {bp_none, "?deleted?"},
4605 {bp_breakpoint, "breakpoint"},
4606 {bp_hardware_breakpoint, "hw breakpoint"},
4607 {bp_until, "until"},
4608 {bp_finish, "finish"},
4609 {bp_watchpoint, "watchpoint"},
4610 {bp_hardware_watchpoint, "hw watchpoint"},
4611 {bp_read_watchpoint, "read watchpoint"},
4612 {bp_access_watchpoint, "acc watchpoint"},
4613 {bp_longjmp, "longjmp"},
4614 {bp_longjmp_resume, "longjmp resume"},
4615 {bp_exception, "exception"},
4616 {bp_exception_resume, "exception resume"},
4617 {bp_step_resume, "step resume"},
4618 {bp_hp_step_resume, "high-priority step resume"},
4619 {bp_watchpoint_scope, "watchpoint scope"},
4620 {bp_call_dummy, "call dummy"},
4621 {bp_std_terminate, "std::terminate"},
4622 {bp_shlib_event, "shlib events"},
4623 {bp_thread_event, "thread events"},
4624 {bp_overlay_event, "overlay events"},
4625 {bp_longjmp_master, "longjmp master"},
4626 {bp_std_terminate_master, "std::terminate master"},
4627 {bp_exception_master, "exception master"},
4628 {bp_catchpoint, "catchpoint"},
4629 {bp_tracepoint, "tracepoint"},
4630 {bp_fast_tracepoint, "fast tracepoint"},
4631 {bp_static_tracepoint, "static tracepoint"},
4632 {bp_jit_event, "jit events"},
4633 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
4634 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
4637 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4638 || ((int) type != bptypes[(int) type].type))
4639 internal_error (__FILE__, __LINE__,
4640 _("bptypes table does not describe type #%d."),
4643 return bptypes[(int) type].description;
4646 /* Print B to gdb_stdout. */
4649 print_one_breakpoint_location (struct breakpoint *b,
4650 struct bp_location *loc,
4652 struct bp_location **last_loc,
4655 struct command_line *l;
4656 static char bpenables[] = "nynny";
4658 struct ui_out *uiout = current_uiout;
4659 int header_of_multiple = 0;
4660 int part_of_multiple = (loc != NULL);
4661 struct value_print_options opts;
4663 get_user_print_options (&opts);
4665 gdb_assert (!loc || loc_number != 0);
4666 /* See comment in print_one_breakpoint concerning treatment of
4667 breakpoints with single disabled location. */
4670 && (b->loc->next != NULL || !b->loc->enabled)))
4671 header_of_multiple = 1;
4679 if (part_of_multiple)
4682 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4683 ui_out_field_string (uiout, "number", formatted);
4688 ui_out_field_int (uiout, "number", b->number);
4693 if (part_of_multiple)
4694 ui_out_field_skip (uiout, "type");
4696 ui_out_field_string (uiout, "type", bptype_string (b->type));
4700 if (part_of_multiple)
4701 ui_out_field_skip (uiout, "disp");
4703 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4708 if (part_of_multiple)
4709 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4711 ui_out_field_fmt (uiout, "enabled", "%c",
4712 bpenables[(int) b->enable_state]);
4713 ui_out_spaces (uiout, 2);
4717 if (b->ops != NULL && b->ops->print_one != NULL)
4719 /* Although the print_one can possibly print all locations,
4720 calling it here is not likely to get any nice result. So,
4721 make sure there's just one location. */
4722 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4723 b->ops->print_one (b, last_loc);
4729 internal_error (__FILE__, __LINE__,
4730 _("print_one_breakpoint: bp_none encountered\n"));
4734 case bp_hardware_watchpoint:
4735 case bp_read_watchpoint:
4736 case bp_access_watchpoint:
4738 struct watchpoint *w = (struct watchpoint *) b;
4740 /* Field 4, the address, is omitted (which makes the columns
4741 not line up too nicely with the headers, but the effect
4742 is relatively readable). */
4743 if (opts.addressprint)
4744 ui_out_field_skip (uiout, "addr");
4746 ui_out_field_string (uiout, "what", w->exp_string);
4751 case bp_hardware_breakpoint:
4755 case bp_longjmp_resume:
4757 case bp_exception_resume:
4758 case bp_step_resume:
4759 case bp_hp_step_resume:
4760 case bp_watchpoint_scope:
4762 case bp_std_terminate:
4763 case bp_shlib_event:
4764 case bp_thread_event:
4765 case bp_overlay_event:
4766 case bp_longjmp_master:
4767 case bp_std_terminate_master:
4768 case bp_exception_master:
4770 case bp_fast_tracepoint:
4771 case bp_static_tracepoint:
4773 case bp_gnu_ifunc_resolver:
4774 case bp_gnu_ifunc_resolver_return:
4775 if (opts.addressprint)
4778 if (header_of_multiple)
4779 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4780 else if (b->loc == NULL || loc->shlib_disabled)
4781 ui_out_field_string (uiout, "addr", "<PENDING>");
4783 ui_out_field_core_addr (uiout, "addr",
4784 loc->gdbarch, loc->address);
4787 if (!header_of_multiple)
4788 print_breakpoint_location (b, loc);
4795 /* For backward compatibility, don't display inferiors unless there
4798 && !header_of_multiple
4800 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4801 && (number_of_program_spaces () > 1
4802 || number_of_inferiors () > 1)
4803 /* LOC is for existing B, it cannot be in
4804 moribund_locations and thus having NULL OWNER. */
4805 && loc->owner->type != bp_catchpoint)))
4807 struct inferior *inf;
4810 for (inf = inferior_list; inf != NULL; inf = inf->next)
4812 if (inf->pspace == loc->pspace)
4817 ui_out_text (uiout, " inf ");
4820 ui_out_text (uiout, ", ");
4821 ui_out_text (uiout, plongest (inf->num));
4826 if (!part_of_multiple)
4828 if (b->thread != -1)
4830 /* FIXME: This seems to be redundant and lost here; see the
4831 "stop only in" line a little further down. */
4832 ui_out_text (uiout, " thread ");
4833 ui_out_field_int (uiout, "thread", b->thread);
4835 else if (b->task != 0)
4837 ui_out_text (uiout, " task ");
4838 ui_out_field_int (uiout, "task", b->task);
4842 ui_out_text (uiout, "\n");
4844 if (!part_of_multiple)
4845 b->ops->print_one_detail (b, uiout);
4847 if (part_of_multiple && frame_id_p (b->frame_id))
4850 ui_out_text (uiout, "\tstop only in stack frame at ");
4851 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4853 ui_out_field_core_addr (uiout, "frame",
4854 b->gdbarch, b->frame_id.stack_addr);
4855 ui_out_text (uiout, "\n");
4858 if (!part_of_multiple && b->cond_string)
4861 if (is_tracepoint (b))
4862 ui_out_text (uiout, "\ttrace only if ");
4864 ui_out_text (uiout, "\tstop only if ");
4865 ui_out_field_string (uiout, "cond", b->cond_string);
4866 ui_out_text (uiout, "\n");
4869 if (!part_of_multiple && b->thread != -1)
4871 /* FIXME should make an annotation for this. */
4872 ui_out_text (uiout, "\tstop only in thread ");
4873 ui_out_field_int (uiout, "thread", b->thread);
4874 ui_out_text (uiout, "\n");
4877 if (!part_of_multiple && b->hit_count)
4879 /* FIXME should make an annotation for this. */
4880 if (ep_is_catchpoint (b))
4881 ui_out_text (uiout, "\tcatchpoint");
4883 ui_out_text (uiout, "\tbreakpoint");
4884 ui_out_text (uiout, " already hit ");
4885 ui_out_field_int (uiout, "times", b->hit_count);
4886 if (b->hit_count == 1)
4887 ui_out_text (uiout, " time\n");
4889 ui_out_text (uiout, " times\n");
4892 /* Output the count also if it is zero, but only if this is mi.
4893 FIXME: Should have a better test for this. */
4894 if (ui_out_is_mi_like_p (uiout))
4895 if (!part_of_multiple && b->hit_count == 0)
4896 ui_out_field_int (uiout, "times", b->hit_count);
4898 if (!part_of_multiple && b->ignore_count)
4901 ui_out_text (uiout, "\tignore next ");
4902 ui_out_field_int (uiout, "ignore", b->ignore_count);
4903 ui_out_text (uiout, " hits\n");
4906 l = b->commands ? b->commands->commands : NULL;
4907 if (!part_of_multiple && l)
4909 struct cleanup *script_chain;
4912 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4913 print_command_lines (uiout, l, 4);
4914 do_cleanups (script_chain);
4917 if (is_tracepoint (b))
4919 struct tracepoint *t = (struct tracepoint *) b;
4921 if (!part_of_multiple && t->pass_count)
4923 annotate_field (10);
4924 ui_out_text (uiout, "\tpass count ");
4925 ui_out_field_int (uiout, "pass", t->pass_count);
4926 ui_out_text (uiout, " \n");
4930 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4932 if (is_watchpoint (b))
4934 struct watchpoint *w = (struct watchpoint *) b;
4936 ui_out_field_string (uiout, "original-location", w->exp_string);
4938 else if (b->addr_string)
4939 ui_out_field_string (uiout, "original-location", b->addr_string);
4944 print_one_breakpoint (struct breakpoint *b,
4945 struct bp_location **last_loc,
4948 struct cleanup *bkpt_chain;
4949 struct ui_out *uiout = current_uiout;
4951 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4953 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
4954 do_cleanups (bkpt_chain);
4956 /* If this breakpoint has custom print function,
4957 it's already printed. Otherwise, print individual
4958 locations, if any. */
4959 if (b->ops == NULL || b->ops->print_one == NULL)
4961 /* If breakpoint has a single location that is disabled, we
4962 print it as if it had several locations, since otherwise it's
4963 hard to represent "breakpoint enabled, location disabled"
4966 Note that while hardware watchpoints have several locations
4967 internally, that's not a property exposed to user. */
4969 && !is_hardware_watchpoint (b)
4970 && (b->loc->next || !b->loc->enabled))
4972 struct bp_location *loc;
4975 for (loc = b->loc; loc; loc = loc->next, ++n)
4977 struct cleanup *inner2 =
4978 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
4979 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
4980 do_cleanups (inner2);
4987 breakpoint_address_bits (struct breakpoint *b)
4989 int print_address_bits = 0;
4990 struct bp_location *loc;
4992 for (loc = b->loc; loc; loc = loc->next)
4996 /* Software watchpoints that aren't watching memory don't have
4997 an address to print. */
4998 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5001 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5002 if (addr_bit > print_address_bits)
5003 print_address_bits = addr_bit;
5006 return print_address_bits;
5009 struct captured_breakpoint_query_args
5015 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5017 struct captured_breakpoint_query_args *args = data;
5018 struct breakpoint *b;
5019 struct bp_location *dummy_loc = NULL;
5023 if (args->bnum == b->number)
5025 print_one_breakpoint (b, &dummy_loc, 0);
5033 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5034 char **error_message)
5036 struct captured_breakpoint_query_args args;
5039 /* For the moment we don't trust print_one_breakpoint() to not throw
5041 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5042 error_message, RETURN_MASK_ALL) < 0)
5048 /* Return true if this breakpoint was set by the user, false if it is
5049 internal or momentary. */
5052 user_breakpoint_p (struct breakpoint *b)
5054 return b->number > 0;
5057 /* Print information on user settable breakpoint (watchpoint, etc)
5058 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5059 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5060 FILTER is non-NULL, call it on each breakpoint and only include the
5061 ones for which it returns non-zero. Return the total number of
5062 breakpoints listed. */
5065 breakpoint_1 (char *args, int allflag,
5066 int (*filter) (const struct breakpoint *))
5068 struct breakpoint *b;
5069 struct bp_location *last_loc = NULL;
5070 int nr_printable_breakpoints;
5071 struct cleanup *bkpttbl_chain;
5072 struct value_print_options opts;
5073 int print_address_bits = 0;
5074 int print_type_col_width = 14;
5075 struct ui_out *uiout = current_uiout;
5077 get_user_print_options (&opts);
5079 /* Compute the number of rows in the table, as well as the size
5080 required for address fields. */
5081 nr_printable_breakpoints = 0;
5084 /* If we have a filter, only list the breakpoints it accepts. */
5085 if (filter && !filter (b))
5088 /* If we have an "args" string, it is a list of breakpoints to
5089 accept. Skip the others. */
5090 if (args != NULL && *args != '\0')
5092 if (allflag && parse_and_eval_long (args) != b->number)
5094 if (!allflag && !number_is_in_list (args, b->number))
5098 if (allflag || user_breakpoint_p (b))
5100 int addr_bit, type_len;
5102 addr_bit = breakpoint_address_bits (b);
5103 if (addr_bit > print_address_bits)
5104 print_address_bits = addr_bit;
5106 type_len = strlen (bptype_string (b->type));
5107 if (type_len > print_type_col_width)
5108 print_type_col_width = type_len;
5110 nr_printable_breakpoints++;
5114 if (opts.addressprint)
5116 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5117 nr_printable_breakpoints,
5121 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5122 nr_printable_breakpoints,
5125 if (nr_printable_breakpoints > 0)
5126 annotate_breakpoints_headers ();
5127 if (nr_printable_breakpoints > 0)
5129 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5130 if (nr_printable_breakpoints > 0)
5132 ui_out_table_header (uiout, print_type_col_width, ui_left,
5133 "type", "Type"); /* 2 */
5134 if (nr_printable_breakpoints > 0)
5136 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5137 if (nr_printable_breakpoints > 0)
5139 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5140 if (opts.addressprint)
5142 if (nr_printable_breakpoints > 0)
5144 if (print_address_bits <= 32)
5145 ui_out_table_header (uiout, 10, ui_left,
5146 "addr", "Address"); /* 5 */
5148 ui_out_table_header (uiout, 18, ui_left,
5149 "addr", "Address"); /* 5 */
5151 if (nr_printable_breakpoints > 0)
5153 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5154 ui_out_table_body (uiout);
5155 if (nr_printable_breakpoints > 0)
5156 annotate_breakpoints_table ();
5161 /* If we have a filter, only list the breakpoints it accepts. */
5162 if (filter && !filter (b))
5165 /* If we have an "args" string, it is a list of breakpoints to
5166 accept. Skip the others. */
5168 if (args != NULL && *args != '\0')
5170 if (allflag) /* maintenance info breakpoint */
5172 if (parse_and_eval_long (args) != b->number)
5175 else /* all others */
5177 if (!number_is_in_list (args, b->number))
5181 /* We only print out user settable breakpoints unless the
5183 if (allflag || user_breakpoint_p (b))
5184 print_one_breakpoint (b, &last_loc, allflag);
5187 do_cleanups (bkpttbl_chain);
5189 if (nr_printable_breakpoints == 0)
5191 /* If there's a filter, let the caller decide how to report
5195 if (args == NULL || *args == '\0')
5196 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5198 ui_out_message (uiout, 0,
5199 "No breakpoint or watchpoint matching '%s'.\n",
5205 if (last_loc && !server_command)
5206 set_next_address (last_loc->gdbarch, last_loc->address);
5209 /* FIXME? Should this be moved up so that it is only called when
5210 there have been breakpoints? */
5211 annotate_breakpoints_table_end ();
5213 return nr_printable_breakpoints;
5216 /* Display the value of default-collect in a way that is generally
5217 compatible with the breakpoint list. */
5220 default_collect_info (void)
5222 struct ui_out *uiout = current_uiout;
5224 /* If it has no value (which is frequently the case), say nothing; a
5225 message like "No default-collect." gets in user's face when it's
5227 if (!*default_collect)
5230 /* The following phrase lines up nicely with per-tracepoint collect
5232 ui_out_text (uiout, "default collect ");
5233 ui_out_field_string (uiout, "default-collect", default_collect);
5234 ui_out_text (uiout, " \n");
5238 breakpoints_info (char *args, int from_tty)
5240 breakpoint_1 (args, 0, NULL);
5242 default_collect_info ();
5246 watchpoints_info (char *args, int from_tty)
5248 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5249 struct ui_out *uiout = current_uiout;
5251 if (num_printed == 0)
5253 if (args == NULL || *args == '\0')
5254 ui_out_message (uiout, 0, "No watchpoints.\n");
5256 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5261 maintenance_info_breakpoints (char *args, int from_tty)
5263 breakpoint_1 (args, 1, NULL);
5265 default_collect_info ();
5269 breakpoint_has_pc (struct breakpoint *b,
5270 struct program_space *pspace,
5271 CORE_ADDR pc, struct obj_section *section)
5273 struct bp_location *bl = b->loc;
5275 for (; bl; bl = bl->next)
5277 if (bl->pspace == pspace
5278 && bl->address == pc
5279 && (!overlay_debugging || bl->section == section))
5285 /* Print a message describing any user-breakpoints set at PC. This
5286 concerns with logical breakpoints, so we match program spaces, not
5290 describe_other_breakpoints (struct gdbarch *gdbarch,
5291 struct program_space *pspace, CORE_ADDR pc,
5292 struct obj_section *section, int thread)
5295 struct breakpoint *b;
5298 others += (user_breakpoint_p (b)
5299 && breakpoint_has_pc (b, pspace, pc, section));
5303 printf_filtered (_("Note: breakpoint "));
5304 else /* if (others == ???) */
5305 printf_filtered (_("Note: breakpoints "));
5307 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
5310 printf_filtered ("%d", b->number);
5311 if (b->thread == -1 && thread != -1)
5312 printf_filtered (" (all threads)");
5313 else if (b->thread != -1)
5314 printf_filtered (" (thread %d)", b->thread);
5315 printf_filtered ("%s%s ",
5316 ((b->enable_state == bp_disabled
5317 || b->enable_state == bp_call_disabled
5318 || b->enable_state == bp_startup_disabled)
5320 : b->enable_state == bp_permanent
5324 : ((others == 1) ? " and" : ""));
5326 printf_filtered (_("also set at pc "));
5327 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5328 printf_filtered (".\n");
5333 /* Return true iff it is meaningful to use the address member of
5334 BPT. For some breakpoint types, the address member is irrelevant
5335 and it makes no sense to attempt to compare it to other addresses
5336 (or use it for any other purpose either).
5338 More specifically, each of the following breakpoint types will
5339 always have a zero valued address and we don't want to mark
5340 breakpoints of any of these types to be a duplicate of an actual
5341 breakpoint at address zero:
5349 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5351 enum bptype type = bpt->type;
5353 return (type != bp_watchpoint && type != bp_catchpoint);
5356 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5357 true if LOC1 and LOC2 represent the same watchpoint location. */
5360 watchpoint_locations_match (struct bp_location *loc1,
5361 struct bp_location *loc2)
5363 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
5364 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
5366 /* Both of them must exist. */
5367 gdb_assert (w1 != NULL);
5368 gdb_assert (w2 != NULL);
5370 /* If the target can evaluate the condition expression in hardware,
5371 then we we need to insert both watchpoints even if they are at
5372 the same place. Otherwise the watchpoint will only trigger when
5373 the condition of whichever watchpoint was inserted evaluates to
5374 true, not giving a chance for GDB to check the condition of the
5375 other watchpoint. */
5377 && target_can_accel_watchpoint_condition (loc1->address,
5379 loc1->watchpoint_type,
5382 && target_can_accel_watchpoint_condition (loc2->address,
5384 loc2->watchpoint_type,
5388 /* Note that this checks the owner's type, not the location's. In
5389 case the target does not support read watchpoints, but does
5390 support access watchpoints, we'll have bp_read_watchpoint
5391 watchpoints with hw_access locations. Those should be considered
5392 duplicates of hw_read locations. The hw_read locations will
5393 become hw_access locations later. */
5394 return (loc1->owner->type == loc2->owner->type
5395 && loc1->pspace->aspace == loc2->pspace->aspace
5396 && loc1->address == loc2->address
5397 && loc1->length == loc2->length);
5400 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5401 same breakpoint location. In most targets, this can only be true
5402 if ASPACE1 matches ASPACE2. On targets that have global
5403 breakpoints, the address space doesn't really matter. */
5406 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5407 struct address_space *aspace2, CORE_ADDR addr2)
5409 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5410 || aspace1 == aspace2)
5414 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5415 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5416 matches ASPACE2. On targets that have global breakpoints, the address
5417 space doesn't really matter. */
5420 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
5421 int len1, struct address_space *aspace2,
5424 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5425 || aspace1 == aspace2)
5426 && addr2 >= addr1 && addr2 < addr1 + len1);
5429 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5430 a ranged breakpoint. In most targets, a match happens only if ASPACE
5431 matches the breakpoint's address space. On targets that have global
5432 breakpoints, the address space doesn't really matter. */
5435 breakpoint_location_address_match (struct bp_location *bl,
5436 struct address_space *aspace,
5439 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
5442 && breakpoint_address_match_range (bl->pspace->aspace,
5443 bl->address, bl->length,
5447 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5448 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5449 true, otherwise returns false. */
5452 tracepoint_locations_match (struct bp_location *loc1,
5453 struct bp_location *loc2)
5455 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
5456 /* Since tracepoint locations are never duplicated with others', tracepoint
5457 locations at the same address of different tracepoints are regarded as
5458 different locations. */
5459 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
5464 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5465 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5466 represent the same location. */
5469 breakpoint_locations_match (struct bp_location *loc1,
5470 struct bp_location *loc2)
5472 int hw_point1, hw_point2;
5474 /* Both of them must not be in moribund_locations. */
5475 gdb_assert (loc1->owner != NULL);
5476 gdb_assert (loc2->owner != NULL);
5478 hw_point1 = is_hardware_watchpoint (loc1->owner);
5479 hw_point2 = is_hardware_watchpoint (loc2->owner);
5481 if (hw_point1 != hw_point2)
5484 return watchpoint_locations_match (loc1, loc2);
5485 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
5486 return tracepoint_locations_match (loc1, loc2);
5488 /* We compare bp_location.length in order to cover ranged breakpoints. */
5489 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5490 loc2->pspace->aspace, loc2->address)
5491 && loc1->length == loc2->length);
5495 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5496 int bnum, int have_bnum)
5498 /* The longest string possibly returned by hex_string_custom
5499 is 50 chars. These must be at least that big for safety. */
5503 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5504 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5506 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5507 bnum, astr1, astr2);
5509 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5512 /* Adjust a breakpoint's address to account for architectural
5513 constraints on breakpoint placement. Return the adjusted address.
5514 Note: Very few targets require this kind of adjustment. For most
5515 targets, this function is simply the identity function. */
5518 adjust_breakpoint_address (struct gdbarch *gdbarch,
5519 CORE_ADDR bpaddr, enum bptype bptype)
5521 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5523 /* Very few targets need any kind of breakpoint adjustment. */
5526 else if (bptype == bp_watchpoint
5527 || bptype == bp_hardware_watchpoint
5528 || bptype == bp_read_watchpoint
5529 || bptype == bp_access_watchpoint
5530 || bptype == bp_catchpoint)
5532 /* Watchpoints and the various bp_catch_* eventpoints should not
5533 have their addresses modified. */
5538 CORE_ADDR adjusted_bpaddr;
5540 /* Some targets have architectural constraints on the placement
5541 of breakpoint instructions. Obtain the adjusted address. */
5542 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5544 /* An adjusted breakpoint address can significantly alter
5545 a user's expectations. Print a warning if an adjustment
5547 if (adjusted_bpaddr != bpaddr)
5548 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5550 return adjusted_bpaddr;
5555 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
5556 struct breakpoint *owner)
5558 memset (loc, 0, sizeof (*loc));
5560 gdb_assert (ops != NULL);
5565 loc->shlib_disabled = 0;
5568 switch (owner->type)
5574 case bp_longjmp_resume:
5576 case bp_exception_resume:
5577 case bp_step_resume:
5578 case bp_hp_step_resume:
5579 case bp_watchpoint_scope:
5581 case bp_std_terminate:
5582 case bp_shlib_event:
5583 case bp_thread_event:
5584 case bp_overlay_event:
5586 case bp_longjmp_master:
5587 case bp_std_terminate_master:
5588 case bp_exception_master:
5589 case bp_gnu_ifunc_resolver:
5590 case bp_gnu_ifunc_resolver_return:
5591 loc->loc_type = bp_loc_software_breakpoint;
5593 case bp_hardware_breakpoint:
5594 loc->loc_type = bp_loc_hardware_breakpoint;
5596 case bp_hardware_watchpoint:
5597 case bp_read_watchpoint:
5598 case bp_access_watchpoint:
5599 loc->loc_type = bp_loc_hardware_watchpoint;
5604 case bp_fast_tracepoint:
5605 case bp_static_tracepoint:
5606 loc->loc_type = bp_loc_other;
5609 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5615 /* Allocate a struct bp_location. */
5617 static struct bp_location *
5618 allocate_bp_location (struct breakpoint *bpt)
5620 return bpt->ops->allocate_location (bpt);
5624 free_bp_location (struct bp_location *loc)
5626 loc->ops->dtor (loc);
5630 /* Increment reference count. */
5633 incref_bp_location (struct bp_location *bl)
5638 /* Decrement reference count. If the reference count reaches 0,
5639 destroy the bp_location. Sets *BLP to NULL. */
5642 decref_bp_location (struct bp_location **blp)
5644 gdb_assert ((*blp)->refc > 0);
5646 if (--(*blp)->refc == 0)
5647 free_bp_location (*blp);
5651 /* Add breakpoint B at the end of the global breakpoint chain. */
5654 add_to_breakpoint_chain (struct breakpoint *b)
5656 struct breakpoint *b1;
5658 /* Add this breakpoint to the end of the chain so that a list of
5659 breakpoints will come out in order of increasing numbers. */
5661 b1 = breakpoint_chain;
5663 breakpoint_chain = b;
5672 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5675 init_raw_breakpoint_without_location (struct breakpoint *b,
5676 struct gdbarch *gdbarch,
5678 const struct breakpoint_ops *ops)
5680 memset (b, 0, sizeof (*b));
5682 gdb_assert (ops != NULL);
5686 b->gdbarch = gdbarch;
5687 b->language = current_language->la_language;
5688 b->input_radix = input_radix;
5690 b->enable_state = bp_enabled;
5693 b->ignore_count = 0;
5695 b->frame_id = null_frame_id;
5696 b->condition_not_parsed = 0;
5697 b->py_bp_object = NULL;
5698 b->related_breakpoint = b;
5701 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5702 that has type BPTYPE and has no locations as yet. */
5704 static struct breakpoint *
5705 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5707 const struct breakpoint_ops *ops)
5709 struct breakpoint *b = XNEW (struct breakpoint);
5711 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5712 add_to_breakpoint_chain (b);
5716 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5717 resolutions should be made as the user specified the location explicitly
5721 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
5723 gdb_assert (loc->owner != NULL);
5725 if (loc->owner->type == bp_breakpoint
5726 || loc->owner->type == bp_hardware_breakpoint
5727 || is_tracepoint (loc->owner))
5731 find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name,
5732 NULL, NULL, &is_gnu_ifunc);
5734 if (is_gnu_ifunc && !explicit_loc)
5736 struct breakpoint *b = loc->owner;
5738 gdb_assert (loc->pspace == current_program_space);
5739 if (gnu_ifunc_resolve_name (loc->function_name,
5740 &loc->requested_address))
5742 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5743 loc->address = adjust_breakpoint_address (loc->gdbarch,
5744 loc->requested_address,
5747 else if (b->type == bp_breakpoint && b->loc == loc
5748 && loc->next == NULL && b->related_breakpoint == b)
5750 /* Create only the whole new breakpoint of this type but do not
5751 mess more complicated breakpoints with multiple locations. */
5752 b->type = bp_gnu_ifunc_resolver;
5756 if (loc->function_name)
5757 loc->function_name = xstrdup (loc->function_name);
5761 /* Attempt to determine architecture of location identified by SAL. */
5763 get_sal_arch (struct symtab_and_line sal)
5766 return get_objfile_arch (sal.section->objfile);
5768 return get_objfile_arch (sal.symtab->objfile);
5773 /* Low level routine for partially initializing a breakpoint of type
5774 BPTYPE. The newly created breakpoint's address, section, source
5775 file name, and line number are provided by SAL.
5777 It is expected that the caller will complete the initialization of
5778 the newly created breakpoint struct as well as output any status
5779 information regarding the creation of a new breakpoint. */
5782 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
5783 struct symtab_and_line sal, enum bptype bptype,
5784 const struct breakpoint_ops *ops)
5786 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5788 add_location_to_breakpoint (b, &sal);
5790 if (bptype != bp_catchpoint)
5791 gdb_assert (sal.pspace != NULL);
5793 /* Store the program space that was used to set the breakpoint, for
5794 breakpoint resetting. */
5795 b->pspace = sal.pspace;
5797 if (sal.symtab == NULL)
5798 b->source_file = NULL;
5800 b->source_file = xstrdup (sal.symtab->filename);
5801 b->line_number = sal.line;
5803 breakpoints_changed ();
5806 /* set_raw_breakpoint is a low level routine for allocating and
5807 partially initializing a breakpoint of type BPTYPE. The newly
5808 created breakpoint's address, section, source file name, and line
5809 number are provided by SAL. The newly created and partially
5810 initialized breakpoint is added to the breakpoint chain and
5811 is also returned as the value of this function.
5813 It is expected that the caller will complete the initialization of
5814 the newly created breakpoint struct as well as output any status
5815 information regarding the creation of a new breakpoint. In
5816 particular, set_raw_breakpoint does NOT set the breakpoint
5817 number! Care should be taken to not allow an error to occur
5818 prior to completing the initialization of the breakpoint. If this
5819 should happen, a bogus breakpoint will be left on the chain. */
5822 set_raw_breakpoint (struct gdbarch *gdbarch,
5823 struct symtab_and_line sal, enum bptype bptype,
5824 const struct breakpoint_ops *ops)
5826 struct breakpoint *b = XNEW (struct breakpoint);
5828 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
5829 add_to_breakpoint_chain (b);
5834 /* Note that the breakpoint object B describes a permanent breakpoint
5835 instruction, hard-wired into the inferior's code. */
5837 make_breakpoint_permanent (struct breakpoint *b)
5839 struct bp_location *bl;
5841 b->enable_state = bp_permanent;
5843 /* By definition, permanent breakpoints are already present in the
5844 code. Mark all locations as inserted. For now,
5845 make_breakpoint_permanent is called in just one place, so it's
5846 hard to say if it's reasonable to have permanent breakpoint with
5847 multiple locations or not, but it's easy to implement. */
5848 for (bl = b->loc; bl; bl = bl->next)
5852 /* Call this routine when stepping and nexting to enable a breakpoint
5853 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5854 initiated the operation. */
5857 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
5859 struct breakpoint *b, *b_tmp;
5860 int thread = tp->num;
5862 /* To avoid having to rescan all objfile symbols at every step,
5863 we maintain a list of continually-inserted but always disabled
5864 longjmp "master" breakpoints. Here, we simply create momentary
5865 clones of those and enable them for the requested thread. */
5866 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5867 if (b->pspace == current_program_space
5868 && (b->type == bp_longjmp_master
5869 || b->type == bp_exception_master))
5871 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
5872 struct breakpoint *clone;
5874 clone = momentary_breakpoint_from_master (b, type,
5875 &momentary_breakpoint_ops);
5876 clone->thread = thread;
5879 tp->initiating_frame = frame;
5882 /* Delete all longjmp breakpoints from THREAD. */
5884 delete_longjmp_breakpoint (int thread)
5886 struct breakpoint *b, *b_tmp;
5888 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5889 if (b->type == bp_longjmp || b->type == bp_exception)
5891 if (b->thread == thread)
5892 delete_breakpoint (b);
5897 enable_overlay_breakpoints (void)
5899 struct breakpoint *b;
5902 if (b->type == bp_overlay_event)
5904 b->enable_state = bp_enabled;
5905 update_global_location_list (1);
5906 overlay_events_enabled = 1;
5911 disable_overlay_breakpoints (void)
5913 struct breakpoint *b;
5916 if (b->type == bp_overlay_event)
5918 b->enable_state = bp_disabled;
5919 update_global_location_list (0);
5920 overlay_events_enabled = 0;
5924 /* Set an active std::terminate breakpoint for each std::terminate
5925 master breakpoint. */
5927 set_std_terminate_breakpoint (void)
5929 struct breakpoint *b, *b_tmp;
5931 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5932 if (b->pspace == current_program_space
5933 && b->type == bp_std_terminate_master)
5935 momentary_breakpoint_from_master (b, bp_std_terminate,
5936 &momentary_breakpoint_ops);
5940 /* Delete all the std::terminate breakpoints. */
5942 delete_std_terminate_breakpoint (void)
5944 struct breakpoint *b, *b_tmp;
5946 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5947 if (b->type == bp_std_terminate)
5948 delete_breakpoint (b);
5952 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5954 struct breakpoint *b;
5956 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
5957 &internal_breakpoint_ops);
5959 b->enable_state = bp_enabled;
5960 /* addr_string has to be used or breakpoint_re_set will delete me. */
5962 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5964 update_global_location_list_nothrow (1);
5970 remove_thread_event_breakpoints (void)
5972 struct breakpoint *b, *b_tmp;
5974 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5975 if (b->type == bp_thread_event
5976 && b->loc->pspace == current_program_space)
5977 delete_breakpoint (b);
5980 struct lang_and_radix
5986 /* Create a breakpoint for JIT code registration and unregistration. */
5989 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5991 struct breakpoint *b;
5993 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
5994 &internal_breakpoint_ops);
5995 update_global_location_list_nothrow (1);
5999 /* Remove JIT code registration and unregistration breakpoint(s). */
6002 remove_jit_event_breakpoints (void)
6004 struct breakpoint *b, *b_tmp;
6006 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6007 if (b->type == bp_jit_event
6008 && b->loc->pspace == current_program_space)
6009 delete_breakpoint (b);
6013 remove_solib_event_breakpoints (void)
6015 struct breakpoint *b, *b_tmp;
6017 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6018 if (b->type == bp_shlib_event
6019 && b->loc->pspace == current_program_space)
6020 delete_breakpoint (b);
6024 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6026 struct breakpoint *b;
6028 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6029 &internal_breakpoint_ops);
6030 update_global_location_list_nothrow (1);
6034 /* Disable any breakpoints that are on code in shared libraries. Only
6035 apply to enabled breakpoints, disabled ones can just stay disabled. */
6038 disable_breakpoints_in_shlibs (void)
6040 struct bp_location *loc, **locp_tmp;
6042 ALL_BP_LOCATIONS (loc, locp_tmp)
6044 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6045 struct breakpoint *b = loc->owner;
6047 /* We apply the check to all breakpoints, including disabled for
6048 those with loc->duplicate set. This is so that when breakpoint
6049 becomes enabled, or the duplicate is removed, gdb will try to
6050 insert all breakpoints. If we don't set shlib_disabled here,
6051 we'll try to insert those breakpoints and fail. */
6052 if (((b->type == bp_breakpoint)
6053 || (b->type == bp_jit_event)
6054 || (b->type == bp_hardware_breakpoint)
6055 || (is_tracepoint (b)))
6056 && loc->pspace == current_program_space
6057 && !loc->shlib_disabled
6059 && PC_SOLIB (loc->address)
6061 && solib_name_from_address (loc->pspace, loc->address)
6065 loc->shlib_disabled = 1;
6070 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6071 library. Only apply to enabled breakpoints, disabled ones can just stay
6075 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6077 struct bp_location *loc, **locp_tmp;
6078 int disabled_shlib_breaks = 0;
6080 /* SunOS a.out shared libraries are always mapped, so do not
6081 disable breakpoints; they will only be reported as unloaded
6082 through clear_solib when GDB discards its shared library
6083 list. See clear_solib for more information. */
6084 if (exec_bfd != NULL
6085 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6088 ALL_BP_LOCATIONS (loc, locp_tmp)
6090 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6091 struct breakpoint *b = loc->owner;
6093 if (solib->pspace == loc->pspace
6094 && !loc->shlib_disabled
6095 && (((b->type == bp_breakpoint
6096 || b->type == bp_jit_event
6097 || b->type == bp_hardware_breakpoint)
6098 && (loc->loc_type == bp_loc_hardware_breakpoint
6099 || loc->loc_type == bp_loc_software_breakpoint))
6100 || is_tracepoint (b))
6101 && solib_contains_address_p (solib, loc->address))
6103 loc->shlib_disabled = 1;
6104 /* At this point, we cannot rely on remove_breakpoint
6105 succeeding so we must mark the breakpoint as not inserted
6106 to prevent future errors occurring in remove_breakpoints. */
6109 /* This may cause duplicate notifications for the same breakpoint. */
6110 observer_notify_breakpoint_modified (b);
6112 if (!disabled_shlib_breaks)
6114 target_terminal_ours_for_output ();
6115 warning (_("Temporarily disabling breakpoints "
6116 "for unloaded shared library \"%s\""),
6119 disabled_shlib_breaks = 1;
6124 /* FORK & VFORK catchpoints. */
6126 /* An instance of this type is used to represent a fork or vfork
6127 catchpoint. It includes a "struct breakpoint" as a kind of base
6128 class; users downcast to "struct breakpoint *" when needed. A
6129 breakpoint is really of this type iff its ops pointer points to
6130 CATCH_FORK_BREAKPOINT_OPS. */
6132 struct fork_catchpoint
6134 /* The base class. */
6135 struct breakpoint base;
6137 /* Process id of a child process whose forking triggered this
6138 catchpoint. This field is only valid immediately after this
6139 catchpoint has triggered. */
6140 ptid_t forked_inferior_pid;
6143 /* Implement the "insert" breakpoint_ops method for fork
6147 insert_catch_fork (struct bp_location *bl)
6149 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6152 /* Implement the "remove" breakpoint_ops method for fork
6156 remove_catch_fork (struct bp_location *bl)
6158 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6161 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6165 breakpoint_hit_catch_fork (const struct bp_location *bl,
6166 struct address_space *aspace, CORE_ADDR bp_addr)
6168 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6170 return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid);
6173 /* Implement the "print_it" breakpoint_ops method for fork
6176 static enum print_stop_action
6177 print_it_catch_fork (bpstat bs)
6179 struct breakpoint *b = bs->breakpoint_at;
6180 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6182 annotate_catchpoint (b->number);
6183 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6184 b->number, ptid_get_pid (c->forked_inferior_pid));
6185 return PRINT_SRC_AND_LOC;
6188 /* Implement the "print_one" breakpoint_ops method for fork
6192 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6194 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6195 struct value_print_options opts;
6196 struct ui_out *uiout = current_uiout;
6198 get_user_print_options (&opts);
6200 /* Field 4, the address, is omitted (which makes the columns not
6201 line up too nicely with the headers, but the effect is relatively
6203 if (opts.addressprint)
6204 ui_out_field_skip (uiout, "addr");
6206 ui_out_text (uiout, "fork");
6207 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6209 ui_out_text (uiout, ", process ");
6210 ui_out_field_int (uiout, "what",
6211 ptid_get_pid (c->forked_inferior_pid));
6212 ui_out_spaces (uiout, 1);
6216 /* Implement the "print_mention" breakpoint_ops method for fork
6220 print_mention_catch_fork (struct breakpoint *b)
6222 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6225 /* Implement the "print_recreate" breakpoint_ops method for fork
6229 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6231 fprintf_unfiltered (fp, "catch fork");
6232 print_recreate_thread (b, fp);
6235 /* The breakpoint_ops structure to be used in fork catchpoints. */
6237 static struct breakpoint_ops catch_fork_breakpoint_ops;
6239 /* Implement the "insert" breakpoint_ops method for vfork
6243 insert_catch_vfork (struct bp_location *bl)
6245 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6248 /* Implement the "remove" breakpoint_ops method for vfork
6252 remove_catch_vfork (struct bp_location *bl)
6254 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6257 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6261 breakpoint_hit_catch_vfork (const struct bp_location *bl,
6262 struct address_space *aspace, CORE_ADDR bp_addr)
6264 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6266 return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid);
6269 /* Implement the "print_it" breakpoint_ops method for vfork
6272 static enum print_stop_action
6273 print_it_catch_vfork (bpstat bs)
6275 struct breakpoint *b = bs->breakpoint_at;
6276 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6278 annotate_catchpoint (b->number);
6279 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6280 b->number, ptid_get_pid (c->forked_inferior_pid));
6281 return PRINT_SRC_AND_LOC;
6284 /* Implement the "print_one" breakpoint_ops method for vfork
6288 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6290 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6291 struct value_print_options opts;
6292 struct ui_out *uiout = current_uiout;
6294 get_user_print_options (&opts);
6295 /* Field 4, the address, is omitted (which makes the columns not
6296 line up too nicely with the headers, but the effect is relatively
6298 if (opts.addressprint)
6299 ui_out_field_skip (uiout, "addr");
6301 ui_out_text (uiout, "vfork");
6302 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6304 ui_out_text (uiout, ", process ");
6305 ui_out_field_int (uiout, "what",
6306 ptid_get_pid (c->forked_inferior_pid));
6307 ui_out_spaces (uiout, 1);
6311 /* Implement the "print_mention" breakpoint_ops method for vfork
6315 print_mention_catch_vfork (struct breakpoint *b)
6317 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6320 /* Implement the "print_recreate" breakpoint_ops method for vfork
6324 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6326 fprintf_unfiltered (fp, "catch vfork");
6327 print_recreate_thread (b, fp);
6330 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6332 static struct breakpoint_ops catch_vfork_breakpoint_ops;
6334 /* An instance of this type is used to represent a syscall catchpoint.
6335 It includes a "struct breakpoint" as a kind of base class; users
6336 downcast to "struct breakpoint *" when needed. A breakpoint is
6337 really of this type iff its ops pointer points to
6338 CATCH_SYSCALL_BREAKPOINT_OPS. */
6340 struct syscall_catchpoint
6342 /* The base class. */
6343 struct breakpoint base;
6345 /* Syscall numbers used for the 'catch syscall' feature. If no
6346 syscall has been specified for filtering, its value is NULL.
6347 Otherwise, it holds a list of all syscalls to be caught. The
6348 list elements are allocated with xmalloc. */
6349 VEC(int) *syscalls_to_be_caught;
6352 /* Implement the "dtor" breakpoint_ops method for syscall
6356 dtor_catch_syscall (struct breakpoint *b)
6358 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6360 VEC_free (int, c->syscalls_to_be_caught);
6362 base_breakpoint_ops.dtor (b);
6365 /* Implement the "insert" breakpoint_ops method for syscall
6369 insert_catch_syscall (struct bp_location *bl)
6371 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6372 struct inferior *inf = current_inferior ();
6374 ++inf->total_syscalls_count;
6375 if (!c->syscalls_to_be_caught)
6376 ++inf->any_syscall_count;
6382 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6387 if (iter >= VEC_length (int, inf->syscalls_counts))
6389 int old_size = VEC_length (int, inf->syscalls_counts);
6390 uintptr_t vec_addr_offset
6391 = old_size * ((uintptr_t) sizeof (int));
6393 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6394 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6396 memset ((void *) vec_addr, 0,
6397 (iter + 1 - old_size) * sizeof (int));
6399 elem = VEC_index (int, inf->syscalls_counts, iter);
6400 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6404 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6405 inf->total_syscalls_count != 0,
6406 inf->any_syscall_count,
6407 VEC_length (int, inf->syscalls_counts),
6408 VEC_address (int, inf->syscalls_counts));
6411 /* Implement the "remove" breakpoint_ops method for syscall
6415 remove_catch_syscall (struct bp_location *bl)
6417 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6418 struct inferior *inf = current_inferior ();
6420 --inf->total_syscalls_count;
6421 if (!c->syscalls_to_be_caught)
6422 --inf->any_syscall_count;
6428 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6432 if (iter >= VEC_length (int, inf->syscalls_counts))
6433 /* Shouldn't happen. */
6435 elem = VEC_index (int, inf->syscalls_counts, iter);
6436 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6440 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6441 inf->total_syscalls_count != 0,
6442 inf->any_syscall_count,
6443 VEC_length (int, inf->syscalls_counts),
6445 inf->syscalls_counts));
6448 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6452 breakpoint_hit_catch_syscall (const struct bp_location *bl,
6453 struct address_space *aspace, CORE_ADDR bp_addr)
6455 /* We must check if we are catching specific syscalls in this
6456 breakpoint. If we are, then we must guarantee that the called
6457 syscall is the same syscall we are catching. */
6458 int syscall_number = 0;
6459 const struct syscall_catchpoint *c
6460 = (const struct syscall_catchpoint *) bl->owner;
6462 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6465 /* Now, checking if the syscall is the same. */
6466 if (c->syscalls_to_be_caught)
6471 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6473 if (syscall_number == iter)
6483 /* Implement the "print_it" breakpoint_ops method for syscall
6486 static enum print_stop_action
6487 print_it_catch_syscall (bpstat bs)
6489 struct breakpoint *b = bs->breakpoint_at;
6490 /* These are needed because we want to know in which state a
6491 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6492 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6493 must print "called syscall" or "returned from syscall". */
6495 struct target_waitstatus last;
6497 struct cleanup *old_chain;
6500 get_last_target_status (&ptid, &last);
6502 get_syscall_by_number (last.value.syscall_number, &s);
6504 annotate_catchpoint (b->number);
6507 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6509 syscall_id = xstrprintf ("'%s'", s.name);
6511 old_chain = make_cleanup (xfree, syscall_id);
6513 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6514 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6515 b->number, syscall_id);
6516 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6517 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6518 b->number, syscall_id);
6520 do_cleanups (old_chain);
6522 return PRINT_SRC_AND_LOC;
6525 /* Implement the "print_one" breakpoint_ops method for syscall
6529 print_one_catch_syscall (struct breakpoint *b,
6530 struct bp_location **last_loc)
6532 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6533 struct value_print_options opts;
6534 struct ui_out *uiout = current_uiout;
6536 get_user_print_options (&opts);
6537 /* Field 4, the address, is omitted (which makes the columns not
6538 line up too nicely with the headers, but the effect is relatively
6540 if (opts.addressprint)
6541 ui_out_field_skip (uiout, "addr");
6544 if (c->syscalls_to_be_caught
6545 && VEC_length (int, c->syscalls_to_be_caught) > 1)
6546 ui_out_text (uiout, "syscalls \"");
6548 ui_out_text (uiout, "syscall \"");
6550 if (c->syscalls_to_be_caught)
6553 char *text = xstrprintf ("%s", "");
6556 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6561 get_syscall_by_number (iter, &s);
6564 text = xstrprintf ("%s%s, ", text, s.name);
6566 text = xstrprintf ("%s%d, ", text, iter);
6568 /* We have to xfree the last 'text' (now stored at 'x')
6569 because xstrprintf dynamically allocates new space for it
6573 /* Remove the last comma. */
6574 text[strlen (text) - 2] = '\0';
6575 ui_out_field_string (uiout, "what", text);
6578 ui_out_field_string (uiout, "what", "<any syscall>");
6579 ui_out_text (uiout, "\" ");
6582 /* Implement the "print_mention" breakpoint_ops method for syscall
6586 print_mention_catch_syscall (struct breakpoint *b)
6588 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6590 if (c->syscalls_to_be_caught)
6594 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
6595 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6597 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6600 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6604 get_syscall_by_number (iter, &s);
6607 printf_filtered (" '%s' [%d]", s.name, s.number);
6609 printf_filtered (" %d", s.number);
6611 printf_filtered (")");
6614 printf_filtered (_("Catchpoint %d (any syscall)"),
6618 /* Implement the "print_recreate" breakpoint_ops method for syscall
6622 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6624 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6626 fprintf_unfiltered (fp, "catch syscall");
6628 if (c->syscalls_to_be_caught)
6633 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6638 get_syscall_by_number (iter, &s);
6640 fprintf_unfiltered (fp, " %s", s.name);
6642 fprintf_unfiltered (fp, " %d", s.number);
6645 print_recreate_thread (b, fp);
6648 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6650 static struct breakpoint_ops catch_syscall_breakpoint_ops;
6652 /* Returns non-zero if 'b' is a syscall catchpoint. */
6655 syscall_catchpoint_p (struct breakpoint *b)
6657 return (b->ops == &catch_syscall_breakpoint_ops);
6660 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6661 is non-zero, then make the breakpoint temporary. If COND_STRING is
6662 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6663 the breakpoint_ops structure associated to the catchpoint. */
6666 init_catchpoint (struct breakpoint *b,
6667 struct gdbarch *gdbarch, int tempflag,
6669 const struct breakpoint_ops *ops)
6671 struct symtab_and_line sal;
6674 sal.pspace = current_program_space;
6676 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
6678 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6679 b->disposition = tempflag ? disp_del : disp_donttouch;
6683 install_breakpoint (int internal, struct breakpoint *b)
6685 add_to_breakpoint_chain (b);
6686 set_breakpoint_number (internal, b);
6689 observer_notify_breakpoint_created (b);
6690 update_global_location_list (1);
6694 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6695 int tempflag, char *cond_string,
6696 const struct breakpoint_ops *ops)
6698 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
6700 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
6702 c->forked_inferior_pid = null_ptid;
6704 install_breakpoint (0, &c->base);
6707 /* Exec catchpoints. */
6709 /* An instance of this type is used to represent an exec catchpoint.
6710 It includes a "struct breakpoint" as a kind of base class; users
6711 downcast to "struct breakpoint *" when needed. A breakpoint is
6712 really of this type iff its ops pointer points to
6713 CATCH_EXEC_BREAKPOINT_OPS. */
6715 struct exec_catchpoint
6717 /* The base class. */
6718 struct breakpoint base;
6720 /* Filename of a program whose exec triggered this catchpoint.
6721 This field is only valid immediately after this catchpoint has
6723 char *exec_pathname;
6726 /* Implement the "dtor" breakpoint_ops method for exec
6730 dtor_catch_exec (struct breakpoint *b)
6732 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6734 xfree (c->exec_pathname);
6736 base_breakpoint_ops.dtor (b);
6740 insert_catch_exec (struct bp_location *bl)
6742 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6746 remove_catch_exec (struct bp_location *bl)
6748 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6752 breakpoint_hit_catch_exec (const struct bp_location *bl,
6753 struct address_space *aspace, CORE_ADDR bp_addr)
6755 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
6757 return inferior_has_execd (inferior_ptid, &c->exec_pathname);
6760 static enum print_stop_action
6761 print_it_catch_exec (bpstat bs)
6763 struct breakpoint *b = bs->breakpoint_at;
6764 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6766 annotate_catchpoint (b->number);
6767 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6769 return PRINT_SRC_AND_LOC;
6773 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6775 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6776 struct value_print_options opts;
6777 struct ui_out *uiout = current_uiout;
6779 get_user_print_options (&opts);
6781 /* Field 4, the address, is omitted (which makes the columns
6782 not line up too nicely with the headers, but the effect
6783 is relatively readable). */
6784 if (opts.addressprint)
6785 ui_out_field_skip (uiout, "addr");
6787 ui_out_text (uiout, "exec");
6788 if (c->exec_pathname != NULL)
6790 ui_out_text (uiout, ", program \"");
6791 ui_out_field_string (uiout, "what", c->exec_pathname);
6792 ui_out_text (uiout, "\" ");
6797 print_mention_catch_exec (struct breakpoint *b)
6799 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6802 /* Implement the "print_recreate" breakpoint_ops method for exec
6806 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6808 fprintf_unfiltered (fp, "catch exec");
6809 print_recreate_thread (b, fp);
6812 static struct breakpoint_ops catch_exec_breakpoint_ops;
6815 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6816 const struct breakpoint_ops *ops)
6818 struct syscall_catchpoint *c;
6819 struct gdbarch *gdbarch = get_current_arch ();
6821 c = XNEW (struct syscall_catchpoint);
6822 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
6823 c->syscalls_to_be_caught = filter;
6825 install_breakpoint (0, &c->base);
6829 hw_breakpoint_used_count (void)
6832 struct breakpoint *b;
6833 struct bp_location *bl;
6837 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6838 for (bl = b->loc; bl; bl = bl->next)
6840 /* Special types of hardware breakpoints may use more than
6842 i += b->ops->resources_needed (bl);
6849 /* Returns the resources B would use if it were a hardware
6853 hw_watchpoint_use_count (struct breakpoint *b)
6856 struct bp_location *bl;
6858 if (!breakpoint_enabled (b))
6861 for (bl = b->loc; bl; bl = bl->next)
6863 /* Special types of hardware watchpoints may use more than
6865 i += b->ops->resources_needed (bl);
6871 /* Returns the sum the used resources of all hardware watchpoints of
6872 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6873 the sum of the used resources of all hardware watchpoints of other
6874 types _not_ TYPE. */
6877 hw_watchpoint_used_count_others (struct breakpoint *except,
6878 enum bptype type, int *other_type_used)
6881 struct breakpoint *b;
6883 *other_type_used = 0;
6888 if (!breakpoint_enabled (b))
6891 if (b->type == type)
6892 i += hw_watchpoint_use_count (b);
6893 else if (is_hardware_watchpoint (b))
6894 *other_type_used = 1;
6901 disable_watchpoints_before_interactive_call_start (void)
6903 struct breakpoint *b;
6907 if (is_watchpoint (b) && breakpoint_enabled (b))
6909 b->enable_state = bp_call_disabled;
6910 update_global_location_list (0);
6916 enable_watchpoints_after_interactive_call_stop (void)
6918 struct breakpoint *b;
6922 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6924 b->enable_state = bp_enabled;
6925 update_global_location_list (1);
6931 disable_breakpoints_before_startup (void)
6933 struct breakpoint *b;
6938 if (b->pspace != current_program_space)
6941 if ((b->type == bp_breakpoint
6942 || b->type == bp_hardware_breakpoint)
6943 && breakpoint_enabled (b))
6945 b->enable_state = bp_startup_disabled;
6951 update_global_location_list (0);
6953 current_program_space->executing_startup = 1;
6957 enable_breakpoints_after_startup (void)
6959 struct breakpoint *b;
6962 current_program_space->executing_startup = 0;
6966 if (b->pspace != current_program_space)
6969 if ((b->type == bp_breakpoint
6970 || b->type == bp_hardware_breakpoint)
6971 && b->enable_state == bp_startup_disabled)
6973 b->enable_state = bp_enabled;
6979 breakpoint_re_set ();
6983 /* Set a breakpoint that will evaporate an end of command
6984 at address specified by SAL.
6985 Restrict it to frame FRAME if FRAME is nonzero. */
6988 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6989 struct frame_id frame_id, enum bptype type)
6991 struct breakpoint *b;
6993 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6995 gdb_assert (!frame_id_inlined_p (frame_id));
6997 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
6998 b->enable_state = bp_enabled;
6999 b->disposition = disp_donttouch;
7000 b->frame_id = frame_id;
7002 /* If we're debugging a multi-threaded program, then we want
7003 momentary breakpoints to be active in only a single thread of
7005 if (in_thread_list (inferior_ptid))
7006 b->thread = pid_to_thread_id (inferior_ptid);
7008 update_global_location_list_nothrow (1);
7013 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7014 The new breakpoint will have type TYPE, and use OPS as it
7017 static struct breakpoint *
7018 momentary_breakpoint_from_master (struct breakpoint *orig,
7020 const struct breakpoint_ops *ops)
7022 struct breakpoint *copy;
7024 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
7025 copy->loc = allocate_bp_location (copy);
7026 set_breakpoint_location_function (copy->loc, 1);
7028 copy->loc->gdbarch = orig->loc->gdbarch;
7029 copy->loc->requested_address = orig->loc->requested_address;
7030 copy->loc->address = orig->loc->address;
7031 copy->loc->section = orig->loc->section;
7032 copy->loc->pspace = orig->loc->pspace;
7034 if (orig->source_file == NULL)
7035 copy->source_file = NULL;
7037 copy->source_file = xstrdup (orig->source_file);
7039 copy->line_number = orig->line_number;
7040 copy->frame_id = orig->frame_id;
7041 copy->thread = orig->thread;
7042 copy->pspace = orig->pspace;
7044 copy->enable_state = bp_enabled;
7045 copy->disposition = disp_donttouch;
7046 copy->number = internal_breakpoint_number--;
7048 update_global_location_list_nothrow (0);
7052 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7056 clone_momentary_breakpoint (struct breakpoint *orig)
7058 /* If there's nothing to clone, then return nothing. */
7062 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
7066 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
7069 struct symtab_and_line sal;
7071 sal = find_pc_line (pc, 0);
7073 sal.section = find_pc_overlay (pc);
7074 sal.explicit_pc = 1;
7076 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
7080 /* Tell the user we have just set a breakpoint B. */
7083 mention (struct breakpoint *b)
7085 b->ops->print_mention (b);
7086 if (ui_out_is_mi_like_p (current_uiout))
7088 printf_filtered ("\n");
7092 static struct bp_location *
7093 add_location_to_breakpoint (struct breakpoint *b,
7094 const struct symtab_and_line *sal)
7096 struct bp_location *loc, **tmp;
7097 CORE_ADDR adjusted_address;
7098 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
7100 if (loc_gdbarch == NULL)
7101 loc_gdbarch = b->gdbarch;
7103 /* Adjust the breakpoint's address prior to allocating a location.
7104 Once we call allocate_bp_location(), that mostly uninitialized
7105 location will be placed on the location chain. Adjustment of the
7106 breakpoint may cause target_read_memory() to be called and we do
7107 not want its scan of the location chain to find a breakpoint and
7108 location that's only been partially initialized. */
7109 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
7112 loc = allocate_bp_location (b);
7113 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7117 loc->requested_address = sal->pc;
7118 loc->address = adjusted_address;
7119 loc->pspace = sal->pspace;
7120 gdb_assert (loc->pspace != NULL);
7121 loc->section = sal->section;
7122 loc->gdbarch = loc_gdbarch;
7123 set_breakpoint_location_function (loc,
7124 sal->explicit_pc || sal->explicit_line);
7129 /* Return 1 if LOC is pointing to a permanent breakpoint,
7130 return 0 otherwise. */
7133 bp_loc_is_permanent (struct bp_location *loc)
7137 const gdb_byte *brk;
7138 gdb_byte *target_mem;
7139 struct cleanup *cleanup;
7142 gdb_assert (loc != NULL);
7144 addr = loc->address;
7145 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7147 /* Software breakpoints unsupported? */
7151 target_mem = alloca (len);
7153 /* Enable the automatic memory restoration from breakpoints while
7154 we read the memory. Otherwise we could say about our temporary
7155 breakpoints they are permanent. */
7156 cleanup = save_current_space_and_thread ();
7158 switch_to_program_space_and_thread (loc->pspace);
7159 make_show_memory_breakpoints_cleanup (0);
7161 if (target_read_memory (loc->address, target_mem, len) == 0
7162 && memcmp (target_mem, brk, len) == 0)
7165 do_cleanups (cleanup);
7172 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7173 as textual description of the location, and COND_STRING
7174 as condition expression. */
7177 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
7178 struct symtabs_and_lines sals, char *addr_string,
7180 enum bptype type, enum bpdisp disposition,
7181 int thread, int task, int ignore_count,
7182 const struct breakpoint_ops *ops, int from_tty,
7183 int enabled, int internal, int display_canonical)
7187 if (type == bp_hardware_breakpoint)
7189 int i = hw_breakpoint_used_count ();
7190 int target_resources_ok =
7191 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7193 if (target_resources_ok == 0)
7194 error (_("No hardware breakpoint support in the target."));
7195 else if (target_resources_ok < 0)
7196 error (_("Hardware breakpoints used exceeds limit."));
7199 gdb_assert (sals.nelts > 0);
7201 for (i = 0; i < sals.nelts; ++i)
7203 struct symtab_and_line sal = sals.sals[i];
7204 struct bp_location *loc;
7208 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7210 loc_gdbarch = gdbarch;
7212 describe_other_breakpoints (loc_gdbarch,
7213 sal.pspace, sal.pc, sal.section, thread);
7218 init_raw_breakpoint (b, gdbarch, sal, type, ops);
7222 b->cond_string = cond_string;
7223 b->ignore_count = ignore_count;
7224 b->enable_state = enabled ? bp_enabled : bp_disabled;
7225 b->disposition = disposition;
7226 b->pspace = sals.sals[0].pspace;
7228 if (type == bp_static_tracepoint)
7230 struct tracepoint *t = (struct tracepoint *) b;
7231 struct static_tracepoint_marker marker;
7233 if (is_marker_spec (addr_string))
7235 /* We already know the marker exists, otherwise, we
7236 wouldn't see a sal for it. */
7237 char *p = &addr_string[3];
7242 p = skip_spaces (p);
7244 endp = skip_to_space (p);
7246 marker_str = savestring (p, endp - p);
7247 t->static_trace_marker_id = marker_str;
7249 printf_filtered (_("Probed static tracepoint "
7251 t->static_trace_marker_id);
7253 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7255 t->static_trace_marker_id = xstrdup (marker.str_id);
7256 release_static_tracepoint_marker (&marker);
7258 printf_filtered (_("Probed static tracepoint "
7260 t->static_trace_marker_id);
7263 warning (_("Couldn't determine the static "
7264 "tracepoint marker to probe"));
7267 if (enabled && b->pspace->executing_startup
7268 && (b->type == bp_breakpoint
7269 || b->type == bp_hardware_breakpoint))
7270 b->enable_state = bp_startup_disabled;
7276 loc = add_location_to_breakpoint (b, &sal);
7279 if (bp_loc_is_permanent (loc))
7280 make_breakpoint_permanent (b);
7284 char *arg = b->cond_string;
7285 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7287 error (_("Garbage %s follows condition"), arg);
7291 b->display_canonical = display_canonical;
7293 b->addr_string = addr_string;
7295 /* addr_string has to be used or breakpoint_re_set will delete
7298 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7302 create_breakpoint_sal (struct gdbarch *gdbarch,
7303 struct symtabs_and_lines sals, char *addr_string,
7305 enum bptype type, enum bpdisp disposition,
7306 int thread, int task, int ignore_count,
7307 const struct breakpoint_ops *ops, int from_tty,
7308 int enabled, int internal, int display_canonical)
7310 struct breakpoint *b;
7311 struct cleanup *old_chain;
7313 if (is_tracepoint_type (type))
7315 struct tracepoint *t;
7317 t = XCNEW (struct tracepoint);
7321 b = XNEW (struct breakpoint);
7323 old_chain = make_cleanup (xfree, b);
7325 init_breakpoint_sal (b, gdbarch,
7329 thread, task, ignore_count,
7331 enabled, internal, display_canonical);
7332 discard_cleanups (old_chain);
7334 install_breakpoint (internal, b);
7337 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7338 elements to fill the void space. */
7340 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7342 int i = index_to_remove+1;
7343 int last_index = sal->nelts-1;
7345 for (;i <= last_index; ++i)
7346 sal->sals[i-1] = sal->sals[i];
7351 /* If appropriate, obtains all sals that correspond to the same file
7352 and line as SAL, in all program spaces. Users debugging with IDEs,
7353 will want to set a breakpoint at foo.c:line, and not really care
7354 about program spaces. This is done only if SAL does not have
7355 explicit PC and has line and file information. If we got just a
7356 single expanded sal, return the original.
7358 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7359 which the name of enclosing function is different from SAL. This
7360 makes sure that if we have breakpoint originally set in template
7361 instantiation, say foo<int>(), we won't expand SAL to locations at
7362 the same line in all existing instantiations of 'foo'. */
7364 static struct symtabs_and_lines
7365 expand_line_sal_maybe (struct symtab_and_line sal)
7367 struct symtabs_and_lines expanded;
7368 CORE_ADDR original_pc = sal.pc;
7369 char *original_function = NULL;
7372 struct cleanup *old_chain;
7374 /* If we have explicit pc, don't expand.
7375 If we have no line number, we can't expand. */
7376 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7379 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7380 expanded.sals[0] = sal;
7386 old_chain = save_current_space_and_thread ();
7388 switch_to_program_space_and_thread (sal.pspace);
7390 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7392 /* Note that expand_line_sal visits *all* program spaces. */
7393 expanded = expand_line_sal (sal);
7395 if (expanded.nelts == 1)
7397 /* We had one sal, we got one sal. Return that sal, adjusting it
7398 past the function prologue if necessary. */
7399 xfree (expanded.sals);
7401 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7402 sal.pc = original_pc;
7403 expanded.sals[0] = sal;
7404 skip_prologue_sal (&expanded.sals[0]);
7405 do_cleanups (old_chain);
7409 if (!sal.explicit_line)
7411 CORE_ADDR func_addr, func_end;
7412 for (i = 0; i < expanded.nelts; ++i)
7414 CORE_ADDR pc = expanded.sals[i].pc;
7415 char *this_function;
7417 /* We need to switch threads as well since we're about to
7419 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7421 if (find_pc_partial_function (pc, &this_function,
7422 &func_addr, &func_end))
7425 && strcmp (this_function, original_function) != 0)
7427 remove_sal (&expanded, i);
7434 /* Skip the function prologue if necessary. */
7435 for (i = 0; i < expanded.nelts; ++i)
7436 skip_prologue_sal (&expanded.sals[i]);
7438 do_cleanups (old_chain);
7440 if (expanded.nelts <= 1)
7442 /* This is an ugly workaround. If we get zero expanded sals
7443 then something is really wrong. Fix that by returning the
7446 xfree (expanded.sals);
7448 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7449 sal.pc = original_pc;
7450 expanded.sals[0] = sal;
7457 for (i = 0; i < expanded.nelts; ++i)
7458 if (expanded.sals[i].pc == original_pc)
7469 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7470 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7471 value. COND_STRING, if not NULL, specified the condition to be
7472 used for all breakpoints. Essentially the only case where
7473 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7474 function. In that case, it's still not possible to specify
7475 separate conditions for different overloaded functions, so
7476 we take just a single condition string.
7478 NOTE: If the function succeeds, the caller is expected to cleanup
7479 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7480 array contents). If the function fails (error() is called), the
7481 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7482 COND and SALS arrays and each of those arrays contents. */
7485 create_breakpoints_sal (struct gdbarch *gdbarch,
7486 struct symtabs_and_lines sals,
7487 struct linespec_result *canonical,
7489 enum bptype type, enum bpdisp disposition,
7490 int thread, int task, int ignore_count,
7491 const struct breakpoint_ops *ops, int from_tty,
7492 int enabled, int internal)
7496 for (i = 0; i < sals.nelts; ++i)
7498 struct symtabs_and_lines expanded =
7499 expand_line_sal_maybe (sals.sals[i]);
7501 create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i],
7502 cond_string, type, disposition,
7503 thread, task, ignore_count, ops,
7504 from_tty, enabled, internal,
7505 canonical->special_display);
7509 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7510 followed by conditionals. On return, SALS contains an array of SAL
7511 addresses found. ADDR_STRING contains a vector of (canonical)
7512 address strings. ADDRESS points to the end of the SAL.
7514 The array and the line spec strings are allocated on the heap, it is
7515 the caller's responsibility to free them. */
7518 parse_breakpoint_sals (char **address,
7519 struct symtabs_and_lines *sals,
7520 struct linespec_result *canonical)
7522 char *addr_start = *address;
7524 /* If no arg given, or if first arg is 'if ', use the default
7526 if ((*address) == NULL
7527 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7529 /* The last displayed codepoint, if it's valid, is our default breakpoint
7531 if (last_displayed_sal_is_valid ())
7533 struct symtab_and_line sal;
7535 init_sal (&sal); /* Initialize to zeroes. */
7536 sals->sals = (struct symtab_and_line *)
7537 xmalloc (sizeof (struct symtab_and_line));
7539 /* Set sal's pspace, pc, symtab, and line to the values
7540 corresponding to the last call to print_frame_info. */
7541 get_last_displayed_sal (&sal);
7542 sal.section = find_pc_overlay (sal.pc);
7544 /* "break" without arguments is equivalent to "break *PC"
7545 where PC is the last displayed codepoint's address. So
7546 make sure to set sal.explicit_pc to prevent GDB from
7547 trying to expand the list of sals to include all other
7548 instances with the same symtab and line. */
7549 sal.explicit_pc = 1;
7551 sals->sals[0] = sal;
7555 error (_("No default breakpoint address now."));
7559 /* Force almost all breakpoints to be in terms of the
7560 current_source_symtab (which is decode_line_1's default).
7561 This should produce the results we want almost all of the
7562 time while leaving the last displayed codepoint pointers
7565 ObjC: However, don't match an Objective-C method name which
7566 may have a '+' or '-' succeeded by a '[' */
7568 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7570 if (last_displayed_sal_is_valid ()
7572 || ((strchr ("+-", (*address)[0]) != NULL)
7573 && ((*address)[1] != '['))))
7574 *sals = decode_line_1 (address, 1,
7575 get_last_displayed_symtab (),
7576 get_last_displayed_line (),
7579 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7582 /* For any SAL that didn't have a canonical string, fill one in. */
7583 if (sals->nelts > 0 && canonical->canonical == NULL)
7584 canonical->canonical = xcalloc (sals->nelts, sizeof (char *));
7585 if (addr_start != (*address))
7589 for (i = 0; i < sals->nelts; i++)
7591 /* Add the string if not present. */
7592 if (canonical->canonical[i] == NULL)
7593 canonical->canonical[i] = savestring (addr_start,
7594 (*address) - addr_start);
7600 /* Convert each SAL into a real PC. Verify that the PC can be
7601 inserted as a breakpoint. If it can't throw an error. */
7604 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7608 for (i = 0; i < sals->nelts; i++)
7609 resolve_sal_pc (&sals->sals[i]);
7612 /* Fast tracepoints may have restrictions on valid locations. For
7613 instance, a fast tracepoint using a jump instead of a trap will
7614 likely have to overwrite more bytes than a trap would, and so can
7615 only be placed where the instruction is longer than the jump, or a
7616 multi-instruction sequence does not have a jump into the middle of
7620 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7621 struct symtabs_and_lines *sals)
7624 struct symtab_and_line *sal;
7626 struct cleanup *old_chain;
7628 for (i = 0; i < sals->nelts; i++)
7630 sal = &sals->sals[i];
7632 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7634 old_chain = make_cleanup (xfree, msg);
7637 error (_("May not have a fast tracepoint at 0x%s%s"),
7638 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7640 do_cleanups (old_chain);
7644 /* Given TOK, a string specification of condition and thread, as
7645 accepted by the 'break' command, extract the condition
7646 string and thread number and set *COND_STRING and *THREAD.
7647 PC identifies the context at which the condition should be parsed.
7648 If no condition is found, *COND_STRING is set to NULL.
7649 If no thread is found, *THREAD is set to -1. */
7651 find_condition_and_thread (char *tok, CORE_ADDR pc,
7652 char **cond_string, int *thread, int *task)
7654 *cond_string = NULL;
7660 char *cond_start = NULL;
7661 char *cond_end = NULL;
7663 tok = skip_spaces (tok);
7665 end_tok = skip_to_space (tok);
7667 toklen = end_tok - tok;
7669 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7671 struct expression *expr;
7673 tok = cond_start = end_tok + 1;
7674 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7677 *cond_string = savestring (cond_start,
7678 cond_end - cond_start);
7680 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7686 *thread = strtol (tok, &tok, 0);
7688 error (_("Junk after thread keyword."));
7689 if (!valid_thread_id (*thread))
7690 error (_("Unknown thread %d."), *thread);
7692 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7698 *task = strtol (tok, &tok, 0);
7700 error (_("Junk after task keyword."));
7701 if (!valid_task_id (*task))
7702 error (_("Unknown task %d."), *task);
7705 error (_("Junk at end of arguments."));
7709 /* Decode a static tracepoint marker spec. */
7711 static struct symtabs_and_lines
7712 decode_static_tracepoint_spec (char **arg_p)
7714 VEC(static_tracepoint_marker_p) *markers = NULL;
7715 struct symtabs_and_lines sals;
7716 struct symtab_and_line sal;
7718 struct cleanup *old_chain;
7719 char *p = &(*arg_p)[3];
7724 p = skip_spaces (p);
7726 endp = skip_to_space (p);
7728 marker_str = savestring (p, endp - p);
7729 old_chain = make_cleanup (xfree, marker_str);
7731 markers = target_static_tracepoint_markers_by_strid (marker_str);
7732 if (VEC_empty(static_tracepoint_marker_p, markers))
7733 error (_("No known static tracepoint marker named %s"), marker_str);
7735 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7736 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7738 for (i = 0; i < sals.nelts; i++)
7740 struct static_tracepoint_marker *marker;
7742 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7744 init_sal (&sals.sals[i]);
7746 sals.sals[i] = find_pc_line (marker->address, 0);
7747 sals.sals[i].pc = marker->address;
7749 release_static_tracepoint_marker (marker);
7752 do_cleanups (old_chain);
7758 /* Set a breakpoint. This function is shared between CLI and MI
7759 functions for setting a breakpoint. This function has two major
7760 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7761 parameter. If non-zero, the function will parse arg, extracting
7762 breakpoint location, address and thread. Otherwise, ARG is just
7763 the location of breakpoint, with condition and thread specified by
7764 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7765 the breakpoint number will be allocated from the internal
7766 breakpoint count. Returns true if any breakpoint was created;
7770 create_breakpoint (struct gdbarch *gdbarch,
7771 char *arg, char *cond_string, int thread,
7772 int parse_condition_and_thread,
7773 int tempflag, enum bptype type_wanted,
7775 enum auto_boolean pending_break_support,
7776 const struct breakpoint_ops *ops,
7777 int from_tty, int enabled, int internal)
7779 volatile struct gdb_exception e;
7780 struct symtabs_and_lines sals;
7781 struct symtab_and_line pending_sal;
7783 char *addr_start = arg;
7784 struct linespec_result canonical;
7785 struct cleanup *old_chain;
7786 struct cleanup *bkpt_chain = NULL;
7790 int prev_bkpt_count = breakpoint_count;
7792 gdb_assert (ops != NULL);
7796 init_linespec_result (&canonical);
7798 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7802 sals = decode_static_tracepoint_spec (&arg);
7804 copy_arg = savestring (addr_start, arg - addr_start);
7805 canonical.canonical = xcalloc (sals.nelts, sizeof (char *));
7806 for (i = 0; i < sals.nelts; i++)
7807 canonical.canonical[i] = xstrdup (copy_arg);
7811 TRY_CATCH (e, RETURN_MASK_ALL)
7813 parse_breakpoint_sals (&arg, &sals, &canonical);
7816 /* If caller is interested in rc value from parse, set value. */
7820 throw_exception (e);
7824 case NOT_FOUND_ERROR:
7826 /* If pending breakpoint support is turned off, throw
7829 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7830 throw_exception (e);
7832 exception_print (gdb_stderr, e);
7834 /* If pending breakpoint support is auto query and the user
7835 selects no, then simply return the error code. */
7836 if (pending_break_support == AUTO_BOOLEAN_AUTO
7837 && !nquery (_("Make breakpoint pending on "
7838 "future shared library load? ")))
7841 /* At this point, either the user was queried about setting
7842 a pending breakpoint and selected yes, or pending
7843 breakpoint behavior is on and thus a pending breakpoint
7844 is defaulted on behalf of the user. */
7845 copy_arg = xstrdup (addr_start);
7846 canonical.canonical = ©_arg;
7848 sals.sals = &pending_sal;
7853 throw_exception (e);
7863 /* Create a chain of things that always need to be cleaned up. */
7864 old_chain = make_cleanup (null_cleanup, 0);
7868 /* Make sure that all storage allocated to SALS gets freed. */
7869 make_cleanup (xfree, sals.sals);
7871 /* Cleanup the canonical array but not its contents. */
7872 make_cleanup (xfree, canonical.canonical);
7875 /* ----------------------------- SNIP -----------------------------
7876 Anything added to the cleanup chain beyond this point is assumed
7877 to be part of a breakpoint. If the breakpoint create succeeds
7878 then the memory is not reclaimed. */
7879 bkpt_chain = make_cleanup (null_cleanup, 0);
7881 /* Mark the contents of the canonical for cleanup. These go on
7882 the bkpt_chain and only occur if the breakpoint create fails. */
7883 for (i = 0; i < sals.nelts; i++)
7885 if (canonical.canonical[i] != NULL)
7886 make_cleanup (xfree, canonical.canonical[i]);
7889 /* Resolve all line numbers to PC's and verify that the addresses
7890 are ok for the target. */
7892 breakpoint_sals_to_pc (&sals);
7894 /* Fast tracepoints may have additional restrictions on location. */
7895 if (type_wanted == bp_fast_tracepoint)
7896 check_fast_tracepoint_sals (gdbarch, &sals);
7898 /* Verify that condition can be parsed, before setting any
7899 breakpoints. Allocate a separate condition expression for each
7903 if (parse_condition_and_thread)
7905 /* Here we only parse 'arg' to separate condition
7906 from thread number, so parsing in context of first
7907 sal is OK. When setting the breakpoint we'll
7908 re-parse it in context of each sal. */
7911 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7914 make_cleanup (xfree, cond_string);
7918 /* Create a private copy of condition string. */
7921 cond_string = xstrdup (cond_string);
7922 make_cleanup (xfree, cond_string);
7926 /* If the user is creating a static tracepoint by marker id
7927 (strace -m MARKER_ID), then store the sals index, so that
7928 breakpoint_re_set can try to match up which of the newly
7929 found markers corresponds to this one, and, don't try to
7930 expand multiple locations for each sal, given than SALS
7931 already should contain all sals for MARKER_ID. */
7932 if (type_wanted == bp_static_tracepoint
7933 && is_marker_spec (canonical.canonical[0]))
7937 for (i = 0; i < sals.nelts; ++i)
7939 struct symtabs_and_lines expanded;
7940 struct tracepoint *tp;
7941 struct cleanup *old_chain;
7944 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7945 expanded.sals[0] = sals.sals[i];
7946 old_chain = make_cleanup (xfree, expanded.sals);
7948 tp = XCNEW (struct tracepoint);
7949 init_breakpoint_sal (&tp->base, gdbarch, expanded,
7950 canonical.canonical[i],
7951 cond_string, type_wanted,
7952 tempflag ? disp_del : disp_donttouch,
7953 thread, task, ignore_count, ops,
7954 from_tty, enabled, internal,
7955 canonical.special_display);
7956 /* Given that its possible to have multiple markers with
7957 the same string id, if the user is creating a static
7958 tracepoint by marker id ("strace -m MARKER_ID"), then
7959 store the sals index, so that breakpoint_re_set can
7960 try to match up which of the newly found markers
7961 corresponds to this one */
7962 tp->static_trace_marker_id_idx = i;
7964 install_breakpoint (internal, &tp->base);
7966 do_cleanups (old_chain);
7970 create_breakpoints_sal (gdbarch, sals, &canonical, cond_string,
7972 tempflag ? disp_del : disp_donttouch,
7973 thread, task, ignore_count, ops, from_tty,
7978 struct breakpoint *b;
7980 make_cleanup (xfree, copy_arg);
7982 b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops);
7983 set_breakpoint_number (internal, b);
7985 b->addr_string = canonical.canonical[0];
7986 b->cond_string = NULL;
7987 b->ignore_count = ignore_count;
7988 b->disposition = tempflag ? disp_del : disp_donttouch;
7989 b->condition_not_parsed = 1;
7990 b->enable_state = enabled ? bp_enabled : bp_disabled;
7991 b->pspace = current_program_space;
7992 b->py_bp_object = NULL;
7994 if (enabled && b->pspace->executing_startup
7995 && (b->type == bp_breakpoint
7996 || b->type == bp_hardware_breakpoint))
7997 b->enable_state = bp_startup_disabled;
8000 /* Do not mention breakpoints with a negative number,
8001 but do notify observers. */
8003 observer_notify_breakpoint_created (b);
8008 warning (_("Multiple breakpoints were set.\nUse the "
8009 "\"delete\" command to delete unwanted breakpoints."));
8010 prev_breakpoint_count = prev_bkpt_count;
8013 /* That's it. Discard the cleanups for data inserted into the
8015 discard_cleanups (bkpt_chain);
8016 /* But cleanup everything else. */
8017 do_cleanups (old_chain);
8019 /* error call may happen here - have BKPT_CHAIN already discarded. */
8020 update_global_location_list (1);
8025 /* Set a breakpoint.
8026 ARG is a string describing breakpoint address,
8027 condition, and thread.
8028 FLAG specifies if a breakpoint is hardware on,
8029 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8033 break_command_1 (char *arg, int flag, int from_tty)
8035 int tempflag = flag & BP_TEMPFLAG;
8036 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
8037 ? bp_hardware_breakpoint
8040 create_breakpoint (get_current_arch (),
8042 NULL, 0, 1 /* parse arg */,
8043 tempflag, type_wanted,
8044 0 /* Ignore count */,
8045 pending_break_support,
8046 &bkpt_breakpoint_ops,
8052 /* Helper function for break_command_1 and disassemble_command. */
8055 resolve_sal_pc (struct symtab_and_line *sal)
8059 if (sal->pc == 0 && sal->symtab != NULL)
8061 if (!find_line_pc (sal->symtab, sal->line, &pc))
8062 error (_("No line %d in file \"%s\"."),
8063 sal->line, sal->symtab->filename);
8066 /* If this SAL corresponds to a breakpoint inserted using a line
8067 number, then skip the function prologue if necessary. */
8068 if (sal->explicit_line)
8069 skip_prologue_sal (sal);
8072 if (sal->section == 0 && sal->symtab != NULL)
8074 struct blockvector *bv;
8078 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8081 sym = block_linkage_function (b);
8084 fixup_symbol_section (sym, sal->symtab->objfile);
8085 sal->section = SYMBOL_OBJ_SECTION (sym);
8089 /* It really is worthwhile to have the section, so we'll
8090 just have to look harder. This case can be executed
8091 if we have line numbers but no functions (as can
8092 happen in assembly source). */
8094 struct minimal_symbol *msym;
8095 struct cleanup *old_chain = save_current_space_and_thread ();
8097 switch_to_program_space_and_thread (sal->pspace);
8099 msym = lookup_minimal_symbol_by_pc (sal->pc);
8101 sal->section = SYMBOL_OBJ_SECTION (msym);
8103 do_cleanups (old_chain);
8110 break_command (char *arg, int from_tty)
8112 break_command_1 (arg, 0, from_tty);
8116 tbreak_command (char *arg, int from_tty)
8118 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8122 hbreak_command (char *arg, int from_tty)
8124 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8128 thbreak_command (char *arg, int from_tty)
8130 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8134 stop_command (char *arg, int from_tty)
8136 printf_filtered (_("Specify the type of breakpoint to set.\n\
8137 Usage: stop in <function | address>\n\
8138 stop at <line>\n"));
8142 stopin_command (char *arg, int from_tty)
8146 if (arg == (char *) NULL)
8148 else if (*arg != '*')
8153 /* Look for a ':'. If this is a line number specification, then
8154 say it is bad, otherwise, it should be an address or
8155 function/method name. */
8156 while (*argptr && !hasColon)
8158 hasColon = (*argptr == ':');
8163 badInput = (*argptr != ':'); /* Not a class::method */
8165 badInput = isdigit (*arg); /* a simple line number */
8169 printf_filtered (_("Usage: stop in <function | address>\n"));
8171 break_command_1 (arg, 0, from_tty);
8175 stopat_command (char *arg, int from_tty)
8179 if (arg == (char *) NULL || *arg == '*') /* no line number */
8186 /* Look for a ':'. If there is a '::' then get out, otherwise
8187 it is probably a line number. */
8188 while (*argptr && !hasColon)
8190 hasColon = (*argptr == ':');
8195 badInput = (*argptr == ':'); /* we have class::method */
8197 badInput = !isdigit (*arg); /* not a line number */
8201 printf_filtered (_("Usage: stop at <line>\n"));
8203 break_command_1 (arg, 0, from_tty);
8206 /* Implement the "breakpoint_hit" breakpoint_ops method for
8207 ranged breakpoints. */
8210 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
8211 struct address_space *aspace,
8214 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
8215 bl->length, aspace, bp_addr);
8218 /* Implement the "resources_needed" breakpoint_ops method for
8219 ranged breakpoints. */
8222 resources_needed_ranged_breakpoint (const struct bp_location *bl)
8224 return target_ranged_break_num_registers ();
8227 /* Implement the "print_it" breakpoint_ops method for
8228 ranged breakpoints. */
8230 static enum print_stop_action
8231 print_it_ranged_breakpoint (bpstat bs)
8233 struct breakpoint *b = bs->breakpoint_at;
8234 struct bp_location *bl = b->loc;
8235 struct ui_out *uiout = current_uiout;
8237 gdb_assert (b->type == bp_hardware_breakpoint);
8239 /* Ranged breakpoints have only one location. */
8240 gdb_assert (bl && bl->next == NULL);
8242 annotate_breakpoint (b->number);
8243 if (b->disposition == disp_del)
8244 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
8246 ui_out_text (uiout, "\nRanged breakpoint ");
8247 if (ui_out_is_mi_like_p (uiout))
8249 ui_out_field_string (uiout, "reason",
8250 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8251 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8253 ui_out_field_int (uiout, "bkptno", b->number);
8254 ui_out_text (uiout, ", ");
8256 return PRINT_SRC_AND_LOC;
8259 /* Implement the "print_one" breakpoint_ops method for
8260 ranged breakpoints. */
8263 print_one_ranged_breakpoint (struct breakpoint *b,
8264 struct bp_location **last_loc)
8266 struct bp_location *bl = b->loc;
8267 struct value_print_options opts;
8268 struct ui_out *uiout = current_uiout;
8270 /* Ranged breakpoints have only one location. */
8271 gdb_assert (bl && bl->next == NULL);
8273 get_user_print_options (&opts);
8275 if (opts.addressprint)
8276 /* We don't print the address range here, it will be printed later
8277 by print_one_detail_ranged_breakpoint. */
8278 ui_out_field_skip (uiout, "addr");
8280 print_breakpoint_location (b, bl);
8284 /* Implement the "print_one_detail" breakpoint_ops method for
8285 ranged breakpoints. */
8288 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
8289 struct ui_out *uiout)
8291 CORE_ADDR address_start, address_end;
8292 struct bp_location *bl = b->loc;
8293 struct ui_stream *stb = ui_out_stream_new (uiout);
8294 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
8298 address_start = bl->address;
8299 address_end = address_start + bl->length - 1;
8301 ui_out_text (uiout, "\taddress range: ");
8302 fprintf_unfiltered (stb->stream, "[%s, %s]",
8303 print_core_address (bl->gdbarch, address_start),
8304 print_core_address (bl->gdbarch, address_end));
8305 ui_out_field_stream (uiout, "addr", stb);
8306 ui_out_text (uiout, "\n");
8308 do_cleanups (cleanup);
8311 /* Implement the "print_mention" breakpoint_ops method for
8312 ranged breakpoints. */
8315 print_mention_ranged_breakpoint (struct breakpoint *b)
8317 struct bp_location *bl = b->loc;
8318 struct ui_out *uiout = current_uiout;
8321 gdb_assert (b->type == bp_hardware_breakpoint);
8323 if (ui_out_is_mi_like_p (uiout))
8326 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8327 b->number, paddress (bl->gdbarch, bl->address),
8328 paddress (bl->gdbarch, bl->address + bl->length - 1));
8331 /* Implement the "print_recreate" breakpoint_ops method for
8332 ranged breakpoints. */
8335 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
8337 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
8338 b->addr_string_range_end);
8339 print_recreate_thread (b, fp);
8342 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8344 static struct breakpoint_ops ranged_breakpoint_ops;
8346 /* Find the address where the end of the breakpoint range should be
8347 placed, given the SAL of the end of the range. This is so that if
8348 the user provides a line number, the end of the range is set to the
8349 last instruction of the given line. */
8352 find_breakpoint_range_end (struct symtab_and_line sal)
8356 /* If the user provided a PC value, use it. Otherwise,
8357 find the address of the end of the given location. */
8358 if (sal.explicit_pc)
8365 ret = find_line_pc_range (sal, &start, &end);
8367 error (_("Could not find location of the end of the range."));
8369 /* find_line_pc_range returns the start of the next line. */
8376 /* Implement the "break-range" CLI command. */
8379 break_range_command (char *arg, int from_tty)
8381 char *arg_start, *addr_string_start, *addr_string_end;
8382 struct linespec_result canonical_start, canonical_end;
8383 int bp_count, can_use_bp, length;
8385 struct breakpoint *b;
8386 struct symtab_and_line sal_start, sal_end;
8387 struct symtabs_and_lines sals_start, sals_end;
8388 struct cleanup *cleanup_bkpt;
8390 /* We don't support software ranged breakpoints. */
8391 if (target_ranged_break_num_registers () < 0)
8392 error (_("This target does not support hardware ranged breakpoints."));
8394 bp_count = hw_breakpoint_used_count ();
8395 bp_count += target_ranged_break_num_registers ();
8396 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8399 error (_("Hardware breakpoints used exceeds limit."));
8401 if (arg == NULL || arg[0] == '\0')
8402 error(_("No address range specified."));
8404 sals_start.sals = NULL;
8405 sals_start.nelts = 0;
8406 init_linespec_result (&canonical_start);
8408 while (*arg == ' ' || *arg == '\t')
8411 parse_breakpoint_sals (&arg, &sals_start, &canonical_start);
8413 sal_start = sals_start.sals[0];
8414 addr_string_start = canonical_start.canonical[0];
8415 cleanup_bkpt = make_cleanup (xfree, addr_string_start);
8416 xfree (sals_start.sals);
8417 xfree (canonical_start.canonical);
8420 error (_("Too few arguments."));
8421 else if (sals_start.nelts == 0)
8422 error (_("Could not find location of the beginning of the range."));
8423 else if (sals_start.nelts != 1)
8424 error (_("Cannot create a ranged breakpoint with multiple locations."));
8426 resolve_sal_pc (&sal_start);
8428 arg++; /* Skip the comma. */
8429 while (*arg == ' ' || *arg == '\t')
8432 /* Parse the end location. */
8434 sals_end.sals = NULL;
8436 init_linespec_result (&canonical_end);
8439 /* We call decode_line_1 directly here instead of using
8440 parse_breakpoint_sals because we need to specify the start location's
8441 symtab and line as the default symtab and line for the end of the
8442 range. This makes it possible to have ranges like "foo.c:27, +14",
8443 where +14 means 14 lines from the start location. */
8444 sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line,
8447 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8448 if (canonical_end.canonical == NULL)
8449 canonical_end.canonical = xcalloc (1, sizeof (char *));
8450 /* Add the string if not present. */
8451 if (arg_start != arg && canonical_end.canonical[0] == NULL)
8452 canonical_end.canonical[0] = savestring (arg_start, arg - arg_start);
8454 sal_end = sals_end.sals[0];
8455 addr_string_end = canonical_end.canonical[0];
8456 make_cleanup (xfree, addr_string_end);
8457 xfree (sals_end.sals);
8458 xfree (canonical_end.canonical);
8460 if (sals_end.nelts == 0)
8461 error (_("Could not find location of the end of the range."));
8462 else if (sals_end.nelts != 1)
8463 error (_("Cannot create a ranged breakpoint with multiple locations."));
8465 resolve_sal_pc (&sal_end);
8467 end = find_breakpoint_range_end (sal_end);
8468 if (sal_start.pc > end)
8469 error (_("Invalid address range, end precedes start."));
8471 length = end - sal_start.pc + 1;
8473 /* Length overflowed. */
8474 error (_("Address range too large."));
8475 else if (length == 1)
8477 /* This range is simple enough to be handled by
8478 the `hbreak' command. */
8479 hbreak_command (addr_string_start, 1);
8481 do_cleanups (cleanup_bkpt);
8486 /* Now set up the breakpoint. */
8487 b = set_raw_breakpoint (get_current_arch (), sal_start,
8488 bp_hardware_breakpoint, &ranged_breakpoint_ops);
8489 set_breakpoint_count (breakpoint_count + 1);
8490 b->number = breakpoint_count;
8491 b->disposition = disp_donttouch;
8492 b->addr_string = addr_string_start;
8493 b->addr_string_range_end = addr_string_end;
8494 b->loc->length = length;
8496 discard_cleanups (cleanup_bkpt);
8499 observer_notify_breakpoint_created (b);
8500 update_global_location_list (1);
8503 /* Return non-zero if EXP is verified as constant. Returned zero
8504 means EXP is variable. Also the constant detection may fail for
8505 some constant expressions and in such case still falsely return
8508 watchpoint_exp_is_const (const struct expression *exp)
8516 /* We are only interested in the descriptor of each element. */
8517 operator_length (exp, i, &oplenp, &argsp);
8520 switch (exp->elts[i].opcode)
8530 case BINOP_LOGICAL_AND:
8531 case BINOP_LOGICAL_OR:
8532 case BINOP_BITWISE_AND:
8533 case BINOP_BITWISE_IOR:
8534 case BINOP_BITWISE_XOR:
8536 case BINOP_NOTEQUAL:
8552 case TERNOP_SLICE_COUNT:
8564 case OP_OBJC_NSSTRING:
8567 case UNOP_LOGICAL_NOT:
8568 case UNOP_COMPLEMENT:
8571 /* Unary, binary and ternary operators: We have to check
8572 their operands. If they are constant, then so is the
8573 result of that operation. For instance, if A and B are
8574 determined to be constants, then so is "A + B".
8576 UNOP_IND is one exception to the rule above, because the
8577 value of *ADDR is not necessarily a constant, even when
8582 /* Check whether the associated symbol is a constant.
8584 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8585 possible that a buggy compiler could mark a variable as
8586 constant even when it is not, and TYPE_CONST would return
8587 true in this case, while SYMBOL_CLASS wouldn't.
8589 We also have to check for function symbols because they
8590 are always constant. */
8592 struct symbol *s = exp->elts[i + 2].symbol;
8594 if (SYMBOL_CLASS (s) != LOC_BLOCK
8595 && SYMBOL_CLASS (s) != LOC_CONST
8596 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8601 /* The default action is to return 0 because we are using
8602 the optimistic approach here: If we don't know something,
8603 then it is not a constant. */
8612 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8615 dtor_watchpoint (struct breakpoint *self)
8617 struct watchpoint *w = (struct watchpoint *) self;
8619 xfree (w->cond_exp);
8621 xfree (w->exp_string);
8622 xfree (w->exp_string_reparse);
8623 value_free (w->val);
8625 base_breakpoint_ops.dtor (self);
8628 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8631 re_set_watchpoint (struct breakpoint *b)
8633 struct watchpoint *w = (struct watchpoint *) b;
8635 /* Watchpoint can be either on expression using entirely global
8636 variables, or it can be on local variables.
8638 Watchpoints of the first kind are never auto-deleted, and even
8639 persist across program restarts. Since they can use variables
8640 from shared libraries, we need to reparse expression as libraries
8641 are loaded and unloaded.
8643 Watchpoints on local variables can also change meaning as result
8644 of solib event. For example, if a watchpoint uses both a local
8645 and a global variables in expression, it's a local watchpoint,
8646 but unloading of a shared library will make the expression
8647 invalid. This is not a very common use case, but we still
8648 re-evaluate expression, to avoid surprises to the user.
8650 Note that for local watchpoints, we re-evaluate it only if
8651 watchpoints frame id is still valid. If it's not, it means the
8652 watchpoint is out of scope and will be deleted soon. In fact,
8653 I'm not sure we'll ever be called in this case.
8655 If a local watchpoint's frame id is still valid, then
8656 w->exp_valid_block is likewise valid, and we can safely use it.
8658 Don't do anything about disabled watchpoints, since they will be
8659 reevaluated again when enabled. */
8660 update_watchpoint (w, 1 /* reparse */);
8663 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8666 insert_watchpoint (struct bp_location *bl)
8668 struct watchpoint *w = (struct watchpoint *) bl->owner;
8669 int length = w->exact ? 1 : bl->length;
8671 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8675 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8678 remove_watchpoint (struct bp_location *bl)
8680 struct watchpoint *w = (struct watchpoint *) bl->owner;
8681 int length = w->exact ? 1 : bl->length;
8683 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8688 breakpoint_hit_watchpoint (const struct bp_location *bl,
8689 struct address_space *aspace, CORE_ADDR bp_addr)
8691 struct breakpoint *b = bl->owner;
8692 struct watchpoint *w = (struct watchpoint *) b;
8694 /* Continuable hardware watchpoints are treated as non-existent if the
8695 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8696 some data address). Otherwise gdb won't stop on a break instruction
8697 in the code (not from a breakpoint) when a hardware watchpoint has
8698 been defined. Also skip watchpoints which we know did not trigger
8699 (did not match the data address). */
8700 if (is_hardware_watchpoint (b)
8701 && w->watchpoint_triggered == watch_triggered_no)
8708 check_status_watchpoint (bpstat bs)
8710 gdb_assert (is_watchpoint (bs->breakpoint_at));
8712 bpstat_check_watchpoint (bs);
8715 /* Implement the "resources_needed" breakpoint_ops method for
8716 hardware watchpoints. */
8719 resources_needed_watchpoint (const struct bp_location *bl)
8721 struct watchpoint *w = (struct watchpoint *) bl->owner;
8722 int length = w->exact? 1 : bl->length;
8724 return target_region_ok_for_hw_watchpoint (bl->address, length);
8727 /* Implement the "works_in_software_mode" breakpoint_ops method for
8728 hardware watchpoints. */
8731 works_in_software_mode_watchpoint (const struct breakpoint *b)
8733 /* Read and access watchpoints only work with hardware support. */
8734 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
8737 static enum print_stop_action
8738 print_it_watchpoint (bpstat bs)
8740 struct cleanup *old_chain;
8741 struct breakpoint *b;
8742 const struct bp_location *bl;
8743 struct ui_stream *stb;
8744 enum print_stop_action result;
8745 struct watchpoint *w;
8746 struct ui_out *uiout = current_uiout;
8748 gdb_assert (bs->bp_location_at != NULL);
8750 bl = bs->bp_location_at;
8751 b = bs->breakpoint_at;
8752 w = (struct watchpoint *) b;
8754 stb = ui_out_stream_new (uiout);
8755 old_chain = make_cleanup_ui_out_stream_delete (stb);
8760 case bp_hardware_watchpoint:
8761 annotate_watchpoint (b->number);
8762 if (ui_out_is_mi_like_p (uiout))
8765 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8767 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8768 ui_out_text (uiout, "\nOld value = ");
8769 watchpoint_value_print (bs->old_val, stb->stream);
8770 ui_out_field_stream (uiout, "old", stb);
8771 ui_out_text (uiout, "\nNew value = ");
8772 watchpoint_value_print (w->val, stb->stream);
8773 ui_out_field_stream (uiout, "new", stb);
8774 ui_out_text (uiout, "\n");
8775 /* More than one watchpoint may have been triggered. */
8776 result = PRINT_UNKNOWN;
8779 case bp_read_watchpoint:
8780 if (ui_out_is_mi_like_p (uiout))
8783 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8785 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8786 ui_out_text (uiout, "\nValue = ");
8787 watchpoint_value_print (w->val, stb->stream);
8788 ui_out_field_stream (uiout, "value", stb);
8789 ui_out_text (uiout, "\n");
8790 result = PRINT_UNKNOWN;
8793 case bp_access_watchpoint:
8794 if (bs->old_val != NULL)
8796 annotate_watchpoint (b->number);
8797 if (ui_out_is_mi_like_p (uiout))
8800 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8802 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8803 ui_out_text (uiout, "\nOld value = ");
8804 watchpoint_value_print (bs->old_val, stb->stream);
8805 ui_out_field_stream (uiout, "old", stb);
8806 ui_out_text (uiout, "\nNew value = ");
8811 if (ui_out_is_mi_like_p (uiout))
8814 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8815 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8816 ui_out_text (uiout, "\nValue = ");
8818 watchpoint_value_print (w->val, stb->stream);
8819 ui_out_field_stream (uiout, "new", stb);
8820 ui_out_text (uiout, "\n");
8821 result = PRINT_UNKNOWN;
8824 result = PRINT_UNKNOWN;
8827 do_cleanups (old_chain);
8831 /* Implement the "print_mention" breakpoint_ops method for hardware
8835 print_mention_watchpoint (struct breakpoint *b)
8837 struct cleanup *ui_out_chain;
8838 struct watchpoint *w = (struct watchpoint *) b;
8839 struct ui_out *uiout = current_uiout;
8844 ui_out_text (uiout, "Watchpoint ");
8845 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8847 case bp_hardware_watchpoint:
8848 ui_out_text (uiout, "Hardware watchpoint ");
8849 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8851 case bp_read_watchpoint:
8852 ui_out_text (uiout, "Hardware read watchpoint ");
8853 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
8855 case bp_access_watchpoint:
8856 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
8857 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
8860 internal_error (__FILE__, __LINE__,
8861 _("Invalid hardware watchpoint type."));
8864 ui_out_field_int (uiout, "number", b->number);
8865 ui_out_text (uiout, ": ");
8866 ui_out_field_string (uiout, "exp", w->exp_string);
8867 do_cleanups (ui_out_chain);
8870 /* Implement the "print_recreate" breakpoint_ops method for
8874 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
8876 struct watchpoint *w = (struct watchpoint *) b;
8881 case bp_hardware_watchpoint:
8882 fprintf_unfiltered (fp, "watch");
8884 case bp_read_watchpoint:
8885 fprintf_unfiltered (fp, "rwatch");
8887 case bp_access_watchpoint:
8888 fprintf_unfiltered (fp, "awatch");
8891 internal_error (__FILE__, __LINE__,
8892 _("Invalid watchpoint type."));
8895 fprintf_unfiltered (fp, " %s", w->exp_string);
8896 print_recreate_thread (b, fp);
8899 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8901 static struct breakpoint_ops watchpoint_breakpoint_ops;
8903 /* Implement the "insert" breakpoint_ops method for
8904 masked hardware watchpoints. */
8907 insert_masked_watchpoint (struct bp_location *bl)
8909 struct watchpoint *w = (struct watchpoint *) bl->owner;
8911 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
8912 bl->watchpoint_type);
8915 /* Implement the "remove" breakpoint_ops method for
8916 masked hardware watchpoints. */
8919 remove_masked_watchpoint (struct bp_location *bl)
8921 struct watchpoint *w = (struct watchpoint *) bl->owner;
8923 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
8924 bl->watchpoint_type);
8927 /* Implement the "resources_needed" breakpoint_ops method for
8928 masked hardware watchpoints. */
8931 resources_needed_masked_watchpoint (const struct bp_location *bl)
8933 struct watchpoint *w = (struct watchpoint *) bl->owner;
8935 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
8938 /* Implement the "works_in_software_mode" breakpoint_ops method for
8939 masked hardware watchpoints. */
8942 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
8947 /* Implement the "print_it" breakpoint_ops method for
8948 masked hardware watchpoints. */
8950 static enum print_stop_action
8951 print_it_masked_watchpoint (bpstat bs)
8953 struct breakpoint *b = bs->breakpoint_at;
8954 struct ui_out *uiout = current_uiout;
8956 /* Masked watchpoints have only one location. */
8957 gdb_assert (b->loc && b->loc->next == NULL);
8961 case bp_hardware_watchpoint:
8962 annotate_watchpoint (b->number);
8963 if (ui_out_is_mi_like_p (uiout))
8966 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8969 case bp_read_watchpoint:
8970 if (ui_out_is_mi_like_p (uiout))
8973 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8976 case bp_access_watchpoint:
8977 if (ui_out_is_mi_like_p (uiout))
8980 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8983 internal_error (__FILE__, __LINE__,
8984 _("Invalid hardware watchpoint type."));
8988 ui_out_text (uiout, _("\n\
8989 Check the underlying instruction at PC for the memory\n\
8990 address and value which triggered this watchpoint.\n"));
8991 ui_out_text (uiout, "\n");
8993 /* More than one watchpoint may have been triggered. */
8994 return PRINT_UNKNOWN;
8997 /* Implement the "print_one_detail" breakpoint_ops method for
8998 masked hardware watchpoints. */
9001 print_one_detail_masked_watchpoint (const struct breakpoint *b,
9002 struct ui_out *uiout)
9004 struct watchpoint *w = (struct watchpoint *) b;
9006 /* Masked watchpoints have only one location. */
9007 gdb_assert (b->loc && b->loc->next == NULL);
9009 ui_out_text (uiout, "\tmask ");
9010 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
9011 ui_out_text (uiout, "\n");
9014 /* Implement the "print_mention" breakpoint_ops method for
9015 masked hardware watchpoints. */
9018 print_mention_masked_watchpoint (struct breakpoint *b)
9020 struct watchpoint *w = (struct watchpoint *) b;
9021 struct ui_out *uiout = current_uiout;
9022 struct cleanup *ui_out_chain;
9026 case bp_hardware_watchpoint:
9027 ui_out_text (uiout, "Masked hardware watchpoint ");
9028 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
9030 case bp_read_watchpoint:
9031 ui_out_text (uiout, "Masked hardware read watchpoint ");
9032 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
9034 case bp_access_watchpoint:
9035 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
9036 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
9039 internal_error (__FILE__, __LINE__,
9040 _("Invalid hardware watchpoint type."));
9043 ui_out_field_int (uiout, "number", b->number);
9044 ui_out_text (uiout, ": ");
9045 ui_out_field_string (uiout, "exp", w->exp_string);
9046 do_cleanups (ui_out_chain);
9049 /* Implement the "print_recreate" breakpoint_ops method for
9050 masked hardware watchpoints. */
9053 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
9055 struct watchpoint *w = (struct watchpoint *) b;
9060 case bp_hardware_watchpoint:
9061 fprintf_unfiltered (fp, "watch");
9063 case bp_read_watchpoint:
9064 fprintf_unfiltered (fp, "rwatch");
9066 case bp_access_watchpoint:
9067 fprintf_unfiltered (fp, "awatch");
9070 internal_error (__FILE__, __LINE__,
9071 _("Invalid hardware watchpoint type."));
9074 sprintf_vma (tmp, w->hw_wp_mask);
9075 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
9076 print_recreate_thread (b, fp);
9079 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9081 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9083 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9086 is_masked_watchpoint (const struct breakpoint *b)
9088 return b->ops == &masked_watchpoint_breakpoint_ops;
9091 /* accessflag: hw_write: watch write,
9092 hw_read: watch read,
9093 hw_access: watch access (read or write) */
9095 watch_command_1 (char *arg, int accessflag, int from_tty,
9096 int just_location, int internal)
9098 volatile struct gdb_exception e;
9099 struct breakpoint *b, *scope_breakpoint = NULL;
9100 struct expression *exp;
9101 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9102 struct value *val, *mark, *result;
9103 struct frame_info *frame;
9104 char *exp_start = NULL;
9105 char *exp_end = NULL;
9106 char *tok, *end_tok;
9108 char *cond_start = NULL;
9109 char *cond_end = NULL;
9110 enum bptype bp_type;
9113 /* Flag to indicate whether we are going to use masks for
9114 the hardware watchpoint. */
9117 struct watchpoint *w;
9119 /* Make sure that we actually have parameters to parse. */
9120 if (arg != NULL && arg[0] != '\0')
9124 /* Look for "parameter value" pairs at the end
9125 of the arguments string. */
9126 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9128 /* Skip whitespace at the end of the argument list. */
9129 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9132 /* Find the beginning of the last token.
9133 This is the value of the parameter. */
9134 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9136 value_start = tok + 1;
9138 /* Skip whitespace. */
9139 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9144 /* Find the beginning of the second to last token.
9145 This is the parameter itself. */
9146 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9149 toklen = end_tok - tok + 1;
9151 if (toklen == 6 && !strncmp (tok, "thread", 6))
9153 /* At this point we've found a "thread" token, which means
9154 the user is trying to set a watchpoint that triggers
9155 only in a specific thread. */
9159 error(_("You can specify only one thread."));
9161 /* Extract the thread ID from the next token. */
9162 thread = strtol (value_start, &endp, 0);
9164 /* Check if the user provided a valid numeric value for the
9166 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9167 error (_("Invalid thread ID specification %s."), value_start);
9169 /* Check if the thread actually exists. */
9170 if (!valid_thread_id (thread))
9171 error (_("Unknown thread %d."), thread);
9173 else if (toklen == 4 && !strncmp (tok, "mask", 4))
9175 /* We've found a "mask" token, which means the user wants to
9176 create a hardware watchpoint that is going to have the mask
9178 struct value *mask_value, *mark;
9181 error(_("You can specify only one mask."));
9183 use_mask = just_location = 1;
9185 mark = value_mark ();
9186 mask_value = parse_to_comma_and_eval (&value_start);
9187 mask = value_as_address (mask_value);
9188 value_free_to_mark (mark);
9191 /* We didn't recognize what we found. We should stop here. */
9194 /* Truncate the string and get rid of the "parameter value" pair before
9195 the arguments string is parsed by the parse_exp_1 function. */
9200 /* Parse the rest of the arguments. */
9201 innermost_block = NULL;
9203 exp = parse_exp_1 (&arg, 0, 0);
9205 /* Remove trailing whitespace from the expression before saving it.
9206 This makes the eventual display of the expression string a bit
9208 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
9211 /* Checking if the expression is not constant. */
9212 if (watchpoint_exp_is_const (exp))
9216 len = exp_end - exp_start;
9217 while (len > 0 && isspace (exp_start[len - 1]))
9219 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
9222 exp_valid_block = innermost_block;
9223 mark = value_mark ();
9224 fetch_subexp_value (exp, &pc, &val, &result, NULL);
9230 exp_valid_block = NULL;
9231 val = value_addr (result);
9232 release_value (val);
9233 value_free_to_mark (mark);
9237 ret = target_masked_watch_num_registers (value_as_address (val),
9240 error (_("This target does not support masked watchpoints."));
9242 error (_("Invalid mask or memory region."));
9245 else if (val != NULL)
9246 release_value (val);
9248 tok = skip_spaces (arg);
9249 end_tok = skip_to_space (tok);
9251 toklen = end_tok - tok;
9252 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9254 struct expression *cond;
9256 innermost_block = NULL;
9257 tok = cond_start = end_tok + 1;
9258 cond = parse_exp_1 (&tok, 0, 0);
9260 /* The watchpoint expression may not be local, but the condition
9261 may still be. E.g.: `watch global if local > 0'. */
9262 cond_exp_valid_block = innermost_block;
9268 error (_("Junk at end of command."));
9270 if (accessflag == hw_read)
9271 bp_type = bp_read_watchpoint;
9272 else if (accessflag == hw_access)
9273 bp_type = bp_access_watchpoint;
9275 bp_type = bp_hardware_watchpoint;
9277 frame = block_innermost_frame (exp_valid_block);
9279 /* If the expression is "local", then set up a "watchpoint scope"
9280 breakpoint at the point where we've left the scope of the watchpoint
9281 expression. Create the scope breakpoint before the watchpoint, so
9282 that we will encounter it first in bpstat_stop_status. */
9283 if (exp_valid_block && frame)
9285 if (frame_id_p (frame_unwind_caller_id (frame)))
9288 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
9289 frame_unwind_caller_pc (frame),
9290 bp_watchpoint_scope,
9291 &momentary_breakpoint_ops);
9293 scope_breakpoint->enable_state = bp_enabled;
9295 /* Automatically delete the breakpoint when it hits. */
9296 scope_breakpoint->disposition = disp_del;
9298 /* Only break in the proper frame (help with recursion). */
9299 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
9301 /* Set the address at which we will stop. */
9302 scope_breakpoint->loc->gdbarch
9303 = frame_unwind_caller_arch (frame);
9304 scope_breakpoint->loc->requested_address
9305 = frame_unwind_caller_pc (frame);
9306 scope_breakpoint->loc->address
9307 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
9308 scope_breakpoint->loc->requested_address,
9309 scope_breakpoint->type);
9313 /* Now set up the breakpoint. */
9315 w = XCNEW (struct watchpoint);
9318 init_raw_breakpoint_without_location (b, NULL, bp_type,
9319 &masked_watchpoint_breakpoint_ops);
9321 init_raw_breakpoint_without_location (b, NULL, bp_type,
9322 &watchpoint_breakpoint_ops);
9324 b->disposition = disp_donttouch;
9325 b->pspace = current_program_space;
9327 w->exp_valid_block = exp_valid_block;
9328 w->cond_exp_valid_block = cond_exp_valid_block;
9331 struct type *t = value_type (val);
9332 CORE_ADDR addr = value_as_address (val);
9335 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
9336 name = type_to_string (t);
9338 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
9339 core_addr_to_string (addr));
9342 w->exp_string = xstrprintf ("-location %.*s",
9343 (int) (exp_end - exp_start), exp_start);
9345 /* The above expression is in C. */
9346 b->language = language_c;
9349 w->exp_string = savestring (exp_start, exp_end - exp_start);
9353 w->hw_wp_mask = mask;
9362 b->cond_string = savestring (cond_start, cond_end - cond_start);
9368 w->watchpoint_frame = get_frame_id (frame);
9369 w->watchpoint_thread = inferior_ptid;
9373 w->watchpoint_frame = null_frame_id;
9374 w->watchpoint_thread = null_ptid;
9377 if (scope_breakpoint != NULL)
9379 /* The scope breakpoint is related to the watchpoint. We will
9380 need to act on them together. */
9381 b->related_breakpoint = scope_breakpoint;
9382 scope_breakpoint->related_breakpoint = b;
9386 value_free_to_mark (mark);
9388 TRY_CATCH (e, RETURN_MASK_ALL)
9390 /* Finally update the new watchpoint. This creates the locations
9391 that should be inserted. */
9392 update_watchpoint (w, 1);
9396 delete_breakpoint (b);
9397 throw_exception (e);
9400 install_breakpoint (internal, b);
9403 /* Return count of debug registers needed to watch the given expression.
9404 If the watchpoint cannot be handled in hardware return zero. */
9407 can_use_hardware_watchpoint (struct value *v)
9409 int found_memory_cnt = 0;
9410 struct value *head = v;
9412 /* Did the user specifically forbid us to use hardware watchpoints? */
9413 if (!can_use_hw_watchpoints)
9416 /* Make sure that the value of the expression depends only upon
9417 memory contents, and values computed from them within GDB. If we
9418 find any register references or function calls, we can't use a
9419 hardware watchpoint.
9421 The idea here is that evaluating an expression generates a series
9422 of values, one holding the value of every subexpression. (The
9423 expression a*b+c has five subexpressions: a, b, a*b, c, and
9424 a*b+c.) GDB's values hold almost enough information to establish
9425 the criteria given above --- they identify memory lvalues,
9426 register lvalues, computed values, etcetera. So we can evaluate
9427 the expression, and then scan the chain of values that leaves
9428 behind to decide whether we can detect any possible change to the
9429 expression's final value using only hardware watchpoints.
9431 However, I don't think that the values returned by inferior
9432 function calls are special in any way. So this function may not
9433 notice that an expression involving an inferior function call
9434 can't be watched with hardware watchpoints. FIXME. */
9435 for (; v; v = value_next (v))
9437 if (VALUE_LVAL (v) == lval_memory)
9439 if (v != head && value_lazy (v))
9440 /* A lazy memory lvalue in the chain is one that GDB never
9441 needed to fetch; we either just used its address (e.g.,
9442 `a' in `a.b') or we never needed it at all (e.g., `a'
9443 in `a,b'). This doesn't apply to HEAD; if that is
9444 lazy then it was not readable, but watch it anyway. */
9448 /* Ahh, memory we actually used! Check if we can cover
9449 it with hardware watchpoints. */
9450 struct type *vtype = check_typedef (value_type (v));
9452 /* We only watch structs and arrays if user asked for it
9453 explicitly, never if they just happen to appear in a
9454 middle of some value chain. */
9456 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9457 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
9459 CORE_ADDR vaddr = value_address (v);
9463 len = (target_exact_watchpoints
9464 && is_scalar_type_recursive (vtype))?
9465 1 : TYPE_LENGTH (value_type (v));
9467 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
9471 found_memory_cnt += num_regs;
9475 else if (VALUE_LVAL (v) != not_lval
9476 && deprecated_value_modifiable (v) == 0)
9477 return 0; /* These are values from the history (e.g., $1). */
9478 else if (VALUE_LVAL (v) == lval_register)
9479 return 0; /* Cannot watch a register with a HW watchpoint. */
9482 /* The expression itself looks suitable for using a hardware
9483 watchpoint, but give the target machine a chance to reject it. */
9484 return found_memory_cnt;
9488 watch_command_wrapper (char *arg, int from_tty, int internal)
9490 watch_command_1 (arg, hw_write, from_tty, 0, internal);
9493 /* A helper function that looks for an argument at the start of a
9494 string. The argument must also either be at the end of the string,
9495 or be followed by whitespace. Returns 1 if it finds the argument,
9496 0 otherwise. If the argument is found, it updates *STR. */
9499 check_for_argument (char **str, char *arg, int arg_len)
9501 if (strncmp (*str, arg, arg_len) == 0
9502 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
9510 /* A helper function that looks for the "-location" argument and then
9511 calls watch_command_1. */
9514 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
9516 int just_location = 0;
9519 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
9520 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
9522 arg = skip_spaces (arg);
9526 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
9530 watch_command (char *arg, int from_tty)
9532 watch_maybe_just_location (arg, hw_write, from_tty);
9536 rwatch_command_wrapper (char *arg, int from_tty, int internal)
9538 watch_command_1 (arg, hw_read, from_tty, 0, internal);
9542 rwatch_command (char *arg, int from_tty)
9544 watch_maybe_just_location (arg, hw_read, from_tty);
9548 awatch_command_wrapper (char *arg, int from_tty, int internal)
9550 watch_command_1 (arg, hw_access, from_tty, 0, internal);
9554 awatch_command (char *arg, int from_tty)
9556 watch_maybe_just_location (arg, hw_access, from_tty);
9560 /* Helper routines for the until_command routine in infcmd.c. Here
9561 because it uses the mechanisms of breakpoints. */
9563 struct until_break_command_continuation_args
9565 struct breakpoint *breakpoint;
9566 struct breakpoint *breakpoint2;
9570 /* This function is called by fetch_inferior_event via the
9571 cmd_continuation pointer, to complete the until command. It takes
9572 care of cleaning up the temporary breakpoints set up by the until
9575 until_break_command_continuation (void *arg, int err)
9577 struct until_break_command_continuation_args *a = arg;
9579 delete_breakpoint (a->breakpoint);
9581 delete_breakpoint (a->breakpoint2);
9582 delete_longjmp_breakpoint (a->thread_num);
9586 until_break_command (char *arg, int from_tty, int anywhere)
9588 struct symtabs_and_lines sals;
9589 struct symtab_and_line sal;
9590 struct frame_info *frame = get_selected_frame (NULL);
9591 struct breakpoint *breakpoint;
9592 struct breakpoint *breakpoint2 = NULL;
9593 struct cleanup *old_chain;
9595 struct thread_info *tp;
9597 clear_proceed_status ();
9599 /* Set a breakpoint where the user wants it and at return from
9602 if (last_displayed_sal_is_valid ())
9603 sals = decode_line_1 (&arg, 1,
9604 get_last_displayed_symtab (),
9605 get_last_displayed_line (),
9608 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL);
9610 if (sals.nelts != 1)
9611 error (_("Couldn't get information on specified line."));
9614 xfree (sals.sals); /* malloc'd, so freed. */
9617 error (_("Junk at end of arguments."));
9619 resolve_sal_pc (&sal);
9622 /* If the user told us to continue until a specified location,
9623 we don't specify a frame at which we need to stop. */
9624 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9625 null_frame_id, bp_until);
9627 /* Otherwise, specify the selected frame, because we want to stop
9628 only at the very same frame. */
9629 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9630 get_stack_frame_id (frame),
9633 old_chain = make_cleanup_delete_breakpoint (breakpoint);
9635 tp = inferior_thread ();
9638 /* Keep within the current frame, or in frames called by the current
9641 if (frame_id_p (frame_unwind_caller_id (frame)))
9643 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
9644 sal.pc = frame_unwind_caller_pc (frame);
9645 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
9647 frame_unwind_caller_id (frame),
9649 make_cleanup_delete_breakpoint (breakpoint2);
9651 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
9652 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
9655 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
9657 /* If we are running asynchronously, and proceed call above has
9658 actually managed to start the target, arrange for breakpoints to
9659 be deleted when the target stops. Otherwise, we're already
9660 stopped and delete breakpoints via cleanup chain. */
9662 if (target_can_async_p () && is_running (inferior_ptid))
9664 struct until_break_command_continuation_args *args;
9665 args = xmalloc (sizeof (*args));
9667 args->breakpoint = breakpoint;
9668 args->breakpoint2 = breakpoint2;
9669 args->thread_num = thread;
9671 discard_cleanups (old_chain);
9672 add_continuation (inferior_thread (),
9673 until_break_command_continuation, args,
9677 do_cleanups (old_chain);
9680 /* This function attempts to parse an optional "if <cond>" clause
9681 from the arg string. If one is not found, it returns NULL.
9683 Else, it returns a pointer to the condition string. (It does not
9684 attempt to evaluate the string against a particular block.) And,
9685 it updates arg to point to the first character following the parsed
9686 if clause in the arg string. */
9689 ep_parse_optional_if_clause (char **arg)
9693 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
9696 /* Skip the "if" keyword. */
9699 /* Skip any extra leading whitespace, and record the start of the
9700 condition string. */
9701 *arg = skip_spaces (*arg);
9704 /* Assume that the condition occupies the remainder of the arg
9706 (*arg) += strlen (cond_string);
9711 /* Commands to deal with catching events, such as signals, exceptions,
9712 process start/exit, etc. */
9716 catch_fork_temporary, catch_vfork_temporary,
9717 catch_fork_permanent, catch_vfork_permanent
9722 catch_fork_command_1 (char *arg, int from_tty,
9723 struct cmd_list_element *command)
9725 struct gdbarch *gdbarch = get_current_arch ();
9726 char *cond_string = NULL;
9727 catch_fork_kind fork_kind;
9730 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
9731 tempflag = (fork_kind == catch_fork_temporary
9732 || fork_kind == catch_vfork_temporary);
9736 arg = skip_spaces (arg);
9738 /* The allowed syntax is:
9740 catch [v]fork if <cond>
9742 First, check if there's an if clause. */
9743 cond_string = ep_parse_optional_if_clause (&arg);
9745 if ((*arg != '\0') && !isspace (*arg))
9746 error (_("Junk at end of arguments."));
9748 /* If this target supports it, create a fork or vfork catchpoint
9749 and enable reporting of such events. */
9752 case catch_fork_temporary:
9753 case catch_fork_permanent:
9754 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9755 &catch_fork_breakpoint_ops);
9757 case catch_vfork_temporary:
9758 case catch_vfork_permanent:
9759 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9760 &catch_vfork_breakpoint_ops);
9763 error (_("unsupported or unknown fork kind; cannot catch it"));
9769 catch_exec_command_1 (char *arg, int from_tty,
9770 struct cmd_list_element *command)
9772 struct exec_catchpoint *c;
9773 struct gdbarch *gdbarch = get_current_arch ();
9775 char *cond_string = NULL;
9777 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9781 arg = skip_spaces (arg);
9783 /* The allowed syntax is:
9785 catch exec if <cond>
9787 First, check if there's an if clause. */
9788 cond_string = ep_parse_optional_if_clause (&arg);
9790 if ((*arg != '\0') && !isspace (*arg))
9791 error (_("Junk at end of arguments."));
9793 c = XNEW (struct exec_catchpoint);
9794 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
9795 &catch_exec_breakpoint_ops);
9796 c->exec_pathname = NULL;
9798 install_breakpoint (0, &c->base);
9801 static enum print_stop_action
9802 print_it_exception_catchpoint (bpstat bs)
9804 struct ui_out *uiout = current_uiout;
9805 struct breakpoint *b = bs->breakpoint_at;
9806 int bp_temp, bp_throw;
9808 annotate_catchpoint (b->number);
9810 bp_throw = strstr (b->addr_string, "throw") != NULL;
9811 if (b->loc->address != b->loc->requested_address)
9812 breakpoint_adjustment_warning (b->loc->requested_address,
9815 bp_temp = b->disposition == disp_del;
9817 bp_temp ? "Temporary catchpoint "
9819 if (!ui_out_is_mi_like_p (uiout))
9820 ui_out_field_int (uiout, "bkptno", b->number);
9822 bp_throw ? " (exception thrown), "
9823 : " (exception caught), ");
9824 if (ui_out_is_mi_like_p (uiout))
9826 ui_out_field_string (uiout, "reason",
9827 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9828 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9829 ui_out_field_int (uiout, "bkptno", b->number);
9831 return PRINT_SRC_AND_LOC;
9835 print_one_exception_catchpoint (struct breakpoint *b,
9836 struct bp_location **last_loc)
9838 struct value_print_options opts;
9839 struct ui_out *uiout = current_uiout;
9841 get_user_print_options (&opts);
9842 if (opts.addressprint)
9845 if (b->loc == NULL || b->loc->shlib_disabled)
9846 ui_out_field_string (uiout, "addr", "<PENDING>");
9848 ui_out_field_core_addr (uiout, "addr",
9849 b->loc->gdbarch, b->loc->address);
9854 if (strstr (b->addr_string, "throw") != NULL)
9855 ui_out_field_string (uiout, "what", "exception throw");
9857 ui_out_field_string (uiout, "what", "exception catch");
9861 print_mention_exception_catchpoint (struct breakpoint *b)
9863 struct ui_out *uiout = current_uiout;
9867 bp_temp = b->disposition == disp_del;
9868 bp_throw = strstr (b->addr_string, "throw") != NULL;
9869 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
9870 : _("Catchpoint "));
9871 ui_out_field_int (uiout, "bkptno", b->number);
9872 ui_out_text (uiout, bp_throw ? _(" (throw)")
9876 /* Implement the "print_recreate" breakpoint_ops method for throw and
9877 catch catchpoints. */
9880 print_recreate_exception_catchpoint (struct breakpoint *b,
9886 bp_temp = b->disposition == disp_del;
9887 bp_throw = strstr (b->addr_string, "throw") != NULL;
9888 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
9889 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
9890 print_recreate_thread (b, fp);
9893 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
9896 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
9897 enum exception_event_kind ex_event, int from_tty)
9899 char *trigger_func_name;
9901 if (ex_event == EX_EVENT_CATCH)
9902 trigger_func_name = "__cxa_begin_catch";
9904 trigger_func_name = "__cxa_throw";
9906 create_breakpoint (get_current_arch (),
9907 trigger_func_name, cond_string, -1,
9908 0 /* condition and thread are valid. */,
9909 tempflag, bp_breakpoint,
9911 AUTO_BOOLEAN_TRUE /* pending */,
9912 &gnu_v3_exception_catchpoint_ops, from_tty,
9919 /* Deal with "catch catch" and "catch throw" commands. */
9922 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
9923 int tempflag, int from_tty)
9925 char *cond_string = NULL;
9929 arg = skip_spaces (arg);
9931 cond_string = ep_parse_optional_if_clause (&arg);
9933 if ((*arg != '\0') && !isspace (*arg))
9934 error (_("Junk at end of arguments."));
9936 if (ex_event != EX_EVENT_THROW
9937 && ex_event != EX_EVENT_CATCH)
9938 error (_("Unsupported or unknown exception event; cannot catch it"));
9940 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
9943 warning (_("Unsupported with this platform/compiler combination."));
9946 /* Implementation of "catch catch" command. */
9949 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
9951 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9953 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
9956 /* Implementation of "catch throw" command. */
9959 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
9961 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9963 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
9967 init_ada_exception_breakpoint (struct breakpoint *b,
9968 struct gdbarch *gdbarch,
9969 struct symtab_and_line sal,
9971 const struct breakpoint_ops *ops,
9977 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9979 loc_gdbarch = gdbarch;
9981 describe_other_breakpoints (loc_gdbarch,
9982 sal.pspace, sal.pc, sal.section, -1);
9983 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9984 version for exception catchpoints, because two catchpoints
9985 used for different exception names will use the same address.
9986 In this case, a "breakpoint ... also set at..." warning is
9987 unproductive. Besides, the warning phrasing is also a bit
9988 inappropriate, we should use the word catchpoint, and tell
9989 the user what type of catchpoint it is. The above is good
9990 enough for now, though. */
9993 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
9995 b->enable_state = bp_enabled;
9996 b->disposition = tempflag ? disp_del : disp_donttouch;
9997 b->addr_string = addr_string;
9998 b->language = language_ada;
10001 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10002 filter list, or NULL if no filtering is required. */
10004 catch_syscall_split_args (char *arg)
10006 VEC(int) *result = NULL;
10007 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
10009 while (*arg != '\0')
10011 int i, syscall_number;
10013 char cur_name[128];
10016 /* Skip whitespace. */
10017 while (isspace (*arg))
10020 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
10021 cur_name[i] = arg[i];
10022 cur_name[i] = '\0';
10025 /* Check if the user provided a syscall name or a number. */
10026 syscall_number = (int) strtol (cur_name, &endptr, 0);
10027 if (*endptr == '\0')
10028 get_syscall_by_number (syscall_number, &s);
10031 /* We have a name. Let's check if it's valid and convert it
10033 get_syscall_by_name (cur_name, &s);
10035 if (s.number == UNKNOWN_SYSCALL)
10036 /* Here we have to issue an error instead of a warning,
10037 because GDB cannot do anything useful if there's no
10038 syscall number to be caught. */
10039 error (_("Unknown syscall name '%s'."), cur_name);
10042 /* Ok, it's valid. */
10043 VEC_safe_push (int, result, s.number);
10046 discard_cleanups (cleanup);
10050 /* Implement the "catch syscall" command. */
10053 catch_syscall_command_1 (char *arg, int from_tty,
10054 struct cmd_list_element *command)
10059 struct gdbarch *gdbarch = get_current_arch ();
10061 /* Checking if the feature if supported. */
10062 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
10063 error (_("The feature 'catch syscall' is not supported on \
10064 this architecture yet."));
10066 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
10068 arg = skip_spaces (arg);
10070 /* We need to do this first "dummy" translation in order
10071 to get the syscall XML file loaded or, most important,
10072 to display a warning to the user if there's no XML file
10073 for his/her architecture. */
10074 get_syscall_by_number (0, &s);
10076 /* The allowed syntax is:
10078 catch syscall <name | number> [<name | number> ... <name | number>]
10080 Let's check if there's a syscall name. */
10083 filter = catch_syscall_split_args (arg);
10087 create_syscall_event_catchpoint (tempflag, filter,
10088 &catch_syscall_breakpoint_ops);
10092 catch_command (char *arg, int from_tty)
10094 error (_("Catch requires an event name."));
10099 tcatch_command (char *arg, int from_tty)
10101 error (_("Catch requires an event name."));
10104 /* Delete breakpoints by address or line. */
10107 clear_command (char *arg, int from_tty)
10109 struct breakpoint *b;
10110 VEC(breakpoint_p) *found = 0;
10113 struct symtabs_and_lines sals;
10114 struct symtab_and_line sal;
10119 sals = decode_line_spec (arg, 1);
10124 sals.sals = (struct symtab_and_line *)
10125 xmalloc (sizeof (struct symtab_and_line));
10126 make_cleanup (xfree, sals.sals);
10127 init_sal (&sal); /* Initialize to zeroes. */
10129 /* Set sal's line, symtab, pc, and pspace to the values
10130 corresponding to the last call to print_frame_info. If the
10131 codepoint is not valid, this will set all the fields to 0. */
10132 get_last_displayed_sal (&sal);
10133 if (sal.symtab == 0)
10134 error (_("No source file specified."));
10136 sals.sals[0] = sal;
10142 /* We don't call resolve_sal_pc here. That's not as bad as it
10143 seems, because all existing breakpoints typically have both
10144 file/line and pc set. So, if clear is given file/line, we can
10145 match this to existing breakpoint without obtaining pc at all.
10147 We only support clearing given the address explicitly
10148 present in breakpoint table. Say, we've set breakpoint
10149 at file:line. There were several PC values for that file:line,
10150 due to optimization, all in one block.
10152 We've picked one PC value. If "clear" is issued with another
10153 PC corresponding to the same file:line, the breakpoint won't
10154 be cleared. We probably can still clear the breakpoint, but
10155 since the other PC value is never presented to user, user
10156 can only find it by guessing, and it does not seem important
10157 to support that. */
10159 /* For each line spec given, delete bps which correspond to it. Do
10160 it in two passes, solely to preserve the current behavior that
10161 from_tty is forced true if we delete more than one
10165 for (i = 0; i < sals.nelts; i++)
10167 /* If exact pc given, clear bpts at that pc.
10168 If line given (pc == 0), clear all bpts on specified line.
10169 If defaulting, clear all bpts on default line
10172 defaulting sal.pc != 0 tests to do
10177 1 0 <can't happen> */
10179 sal = sals.sals[i];
10181 /* Find all matching breakpoints and add them to 'found'. */
10182 ALL_BREAKPOINTS (b)
10185 /* Are we going to delete b? */
10186 if (b->type != bp_none && !is_watchpoint (b))
10188 struct bp_location *loc = b->loc;
10189 for (; loc; loc = loc->next)
10191 int pc_match = sal.pc
10192 && (loc->pspace == sal.pspace)
10193 && (loc->address == sal.pc)
10194 && (!section_is_overlay (loc->section)
10195 || loc->section == sal.section);
10196 int line_match = ((default_match || (0 == sal.pc))
10197 && b->source_file != NULL
10198 && sal.symtab != NULL
10199 && sal.pspace == loc->pspace
10200 && filename_cmp (b->source_file,
10201 sal.symtab->filename) == 0
10202 && b->line_number == sal.line);
10203 if (pc_match || line_match)
10212 VEC_safe_push(breakpoint_p, found, b);
10215 /* Now go thru the 'found' chain and delete them. */
10216 if (VEC_empty(breakpoint_p, found))
10219 error (_("No breakpoint at %s."), arg);
10221 error (_("No breakpoint at this line."));
10224 if (VEC_length(breakpoint_p, found) > 1)
10225 from_tty = 1; /* Always report if deleted more than one. */
10228 if (VEC_length(breakpoint_p, found) == 1)
10229 printf_unfiltered (_("Deleted breakpoint "));
10231 printf_unfiltered (_("Deleted breakpoints "));
10233 breakpoints_changed ();
10235 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
10238 printf_unfiltered ("%d ", b->number);
10239 delete_breakpoint (b);
10242 putchar_unfiltered ('\n');
10245 /* Delete breakpoint in BS if they are `delete' breakpoints and
10246 all breakpoints that are marked for deletion, whether hit or not.
10247 This is called after any breakpoint is hit, or after errors. */
10250 breakpoint_auto_delete (bpstat bs)
10252 struct breakpoint *b, *b_tmp;
10254 for (; bs; bs = bs->next)
10255 if (bs->breakpoint_at
10256 && bs->breakpoint_at->disposition == disp_del
10258 delete_breakpoint (bs->breakpoint_at);
10260 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10262 if (b->disposition == disp_del_at_next_stop)
10263 delete_breakpoint (b);
10267 /* A comparison function for bp_location AP and BP being interfaced to
10268 qsort. Sort elements primarily by their ADDRESS (no matter what
10269 does breakpoint_address_is_meaningful say for its OWNER),
10270 secondarily by ordering first bp_permanent OWNERed elements and
10271 terciarily just ensuring the array is sorted stable way despite
10272 qsort being an unstable algorithm. */
10275 bp_location_compare (const void *ap, const void *bp)
10277 struct bp_location *a = *(void **) ap;
10278 struct bp_location *b = *(void **) bp;
10279 /* A and B come from existing breakpoints having non-NULL OWNER. */
10280 int a_perm = a->owner->enable_state == bp_permanent;
10281 int b_perm = b->owner->enable_state == bp_permanent;
10283 if (a->address != b->address)
10284 return (a->address > b->address) - (a->address < b->address);
10286 /* Sort permanent breakpoints first. */
10287 if (a_perm != b_perm)
10288 return (a_perm < b_perm) - (a_perm > b_perm);
10290 /* Make the user-visible order stable across GDB runs. Locations of
10291 the same breakpoint can be sorted in arbitrary order. */
10293 if (a->owner->number != b->owner->number)
10294 return (a->owner->number > b->owner->number)
10295 - (a->owner->number < b->owner->number);
10297 return (a > b) - (a < b);
10300 /* Set bp_location_placed_address_before_address_max and
10301 bp_location_shadow_len_after_address_max according to the current
10302 content of the bp_location array. */
10305 bp_location_target_extensions_update (void)
10307 struct bp_location *bl, **blp_tmp;
10309 bp_location_placed_address_before_address_max = 0;
10310 bp_location_shadow_len_after_address_max = 0;
10312 ALL_BP_LOCATIONS (bl, blp_tmp)
10314 CORE_ADDR start, end, addr;
10316 if (!bp_location_has_shadow (bl))
10319 start = bl->target_info.placed_address;
10320 end = start + bl->target_info.shadow_len;
10322 gdb_assert (bl->address >= start);
10323 addr = bl->address - start;
10324 if (addr > bp_location_placed_address_before_address_max)
10325 bp_location_placed_address_before_address_max = addr;
10327 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10329 gdb_assert (bl->address < end);
10330 addr = end - bl->address;
10331 if (addr > bp_location_shadow_len_after_address_max)
10332 bp_location_shadow_len_after_address_max = addr;
10336 /* Download tracepoint locations if they haven't been. */
10339 download_tracepoint_locations (void)
10341 struct bp_location *bl, **blp_tmp;
10342 struct cleanup *old_chain;
10344 if (!target_can_download_tracepoint ())
10347 old_chain = save_current_space_and_thread ();
10349 ALL_BP_LOCATIONS (bl, blp_tmp)
10351 struct tracepoint *t;
10353 if (!is_tracepoint (bl->owner))
10356 if ((bl->owner->type == bp_fast_tracepoint
10357 ? !may_insert_fast_tracepoints
10358 : !may_insert_tracepoints))
10361 /* In tracepoint, locations are _never_ duplicated, so
10362 should_be_inserted is equivalent to
10363 unduplicated_should_be_inserted. */
10364 if (!should_be_inserted (bl) || bl->inserted)
10367 switch_to_program_space_and_thread (bl->pspace);
10369 target_download_tracepoint (bl);
10372 t = (struct tracepoint *) bl->owner;
10373 t->number_on_target = bl->owner->number;
10376 do_cleanups (old_chain);
10379 /* Swap the insertion/duplication state between two locations. */
10382 swap_insertion (struct bp_location *left, struct bp_location *right)
10384 const int left_inserted = left->inserted;
10385 const int left_duplicate = left->duplicate;
10386 const struct bp_target_info left_target_info = left->target_info;
10388 /* Locations of tracepoints can never be duplicated. */
10389 if (is_tracepoint (left->owner))
10390 gdb_assert (!left->duplicate);
10391 if (is_tracepoint (right->owner))
10392 gdb_assert (!right->duplicate);
10394 left->inserted = right->inserted;
10395 left->duplicate = right->duplicate;
10396 left->target_info = right->target_info;
10397 right->inserted = left_inserted;
10398 right->duplicate = left_duplicate;
10399 right->target_info = left_target_info;
10402 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10403 into the inferior, only remove already-inserted locations that no
10404 longer should be inserted. Functions that delete a breakpoint or
10405 breakpoints should pass false, so that deleting a breakpoint
10406 doesn't have the side effect of inserting the locations of other
10407 breakpoints that are marked not-inserted, but should_be_inserted
10408 returns true on them.
10410 This behaviour is useful is situations close to tear-down -- e.g.,
10411 after an exec, while the target still has execution, but breakpoint
10412 shadows of the previous executable image should *NOT* be restored
10413 to the new image; or before detaching, where the target still has
10414 execution and wants to delete breakpoints from GDB's lists, and all
10415 breakpoints had already been removed from the inferior. */
10418 update_global_location_list (int should_insert)
10420 struct breakpoint *b;
10421 struct bp_location **locp, *loc;
10422 struct cleanup *cleanups;
10424 /* Used in the duplicates detection below. When iterating over all
10425 bp_locations, points to the first bp_location of a given address.
10426 Breakpoints and watchpoints of different types are never
10427 duplicates of each other. Keep one pointer for each type of
10428 breakpoint/watchpoint, so we only need to loop over all locations
10430 struct bp_location *bp_loc_first; /* breakpoint */
10431 struct bp_location *wp_loc_first; /* hardware watchpoint */
10432 struct bp_location *awp_loc_first; /* access watchpoint */
10433 struct bp_location *rwp_loc_first; /* read watchpoint */
10435 /* Saved former bp_location array which we compare against the newly
10436 built bp_location from the current state of ALL_BREAKPOINTS. */
10437 struct bp_location **old_location, **old_locp;
10438 unsigned old_location_count;
10440 old_location = bp_location;
10441 old_location_count = bp_location_count;
10442 bp_location = NULL;
10443 bp_location_count = 0;
10444 cleanups = make_cleanup (xfree, old_location);
10446 ALL_BREAKPOINTS (b)
10447 for (loc = b->loc; loc; loc = loc->next)
10448 bp_location_count++;
10450 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
10451 locp = bp_location;
10452 ALL_BREAKPOINTS (b)
10453 for (loc = b->loc; loc; loc = loc->next)
10455 qsort (bp_location, bp_location_count, sizeof (*bp_location),
10456 bp_location_compare);
10458 bp_location_target_extensions_update ();
10460 /* Identify bp_location instances that are no longer present in the
10461 new list, and therefore should be freed. Note that it's not
10462 necessary that those locations should be removed from inferior --
10463 if there's another location at the same address (previously
10464 marked as duplicate), we don't need to remove/insert the
10467 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10468 and former bp_location array state respectively. */
10470 locp = bp_location;
10471 for (old_locp = old_location; old_locp < old_location + old_location_count;
10474 struct bp_location *old_loc = *old_locp;
10475 struct bp_location **loc2p;
10477 /* Tells if 'old_loc' is found among the new locations. If
10478 not, we have to free it. */
10479 int found_object = 0;
10480 /* Tells if the location should remain inserted in the target. */
10481 int keep_in_target = 0;
10484 /* Skip LOCP entries which will definitely never be needed.
10485 Stop either at or being the one matching OLD_LOC. */
10486 while (locp < bp_location + bp_location_count
10487 && (*locp)->address < old_loc->address)
10491 (loc2p < bp_location + bp_location_count
10492 && (*loc2p)->address == old_loc->address);
10495 if (*loc2p == old_loc)
10502 /* If this location is no longer present, and inserted, look if
10503 there's maybe a new location at the same address. If so,
10504 mark that one inserted, and don't remove this one. This is
10505 needed so that we don't have a time window where a breakpoint
10506 at certain location is not inserted. */
10508 if (old_loc->inserted)
10510 /* If the location is inserted now, we might have to remove
10513 if (found_object && should_be_inserted (old_loc))
10515 /* The location is still present in the location list,
10516 and still should be inserted. Don't do anything. */
10517 keep_in_target = 1;
10521 /* The location is either no longer present, or got
10522 disabled. See if there's another location at the
10523 same address, in which case we don't need to remove
10524 this one from the target. */
10526 /* OLD_LOC comes from existing struct breakpoint. */
10527 if (breakpoint_address_is_meaningful (old_loc->owner))
10530 (loc2p < bp_location + bp_location_count
10531 && (*loc2p)->address == old_loc->address);
10534 struct bp_location *loc2 = *loc2p;
10536 if (breakpoint_locations_match (loc2, old_loc))
10538 /* Read watchpoint locations are switched to
10539 access watchpoints, if the former are not
10540 supported, but the latter are. */
10541 if (is_hardware_watchpoint (old_loc->owner))
10543 gdb_assert (is_hardware_watchpoint (loc2->owner));
10544 loc2->watchpoint_type = old_loc->watchpoint_type;
10547 /* loc2 is a duplicated location. We need to check
10548 if it should be inserted in case it will be
10550 if (loc2 != old_loc
10551 && unduplicated_should_be_inserted (loc2))
10553 swap_insertion (old_loc, loc2);
10554 keep_in_target = 1;
10562 if (!keep_in_target)
10564 if (remove_breakpoint (old_loc, mark_uninserted))
10566 /* This is just about all we can do. We could keep
10567 this location on the global list, and try to
10568 remove it next time, but there's no particular
10569 reason why we will succeed next time.
10571 Note that at this point, old_loc->owner is still
10572 valid, as delete_breakpoint frees the breakpoint
10573 only after calling us. */
10574 printf_filtered (_("warning: Error removing "
10575 "breakpoint %d\n"),
10576 old_loc->owner->number);
10584 if (removed && non_stop
10585 && breakpoint_address_is_meaningful (old_loc->owner)
10586 && !is_hardware_watchpoint (old_loc->owner))
10588 /* This location was removed from the target. In
10589 non-stop mode, a race condition is possible where
10590 we've removed a breakpoint, but stop events for that
10591 breakpoint are already queued and will arrive later.
10592 We apply an heuristic to be able to distinguish such
10593 SIGTRAPs from other random SIGTRAPs: we keep this
10594 breakpoint location for a bit, and will retire it
10595 after we see some number of events. The theory here
10596 is that reporting of events should, "on the average",
10597 be fair, so after a while we'll see events from all
10598 threads that have anything of interest, and no longer
10599 need to keep this breakpoint location around. We
10600 don't hold locations forever so to reduce chances of
10601 mistaking a non-breakpoint SIGTRAP for a breakpoint
10604 The heuristic failing can be disastrous on
10605 decr_pc_after_break targets.
10607 On decr_pc_after_break targets, like e.g., x86-linux,
10608 if we fail to recognize a late breakpoint SIGTRAP,
10609 because events_till_retirement has reached 0 too
10610 soon, we'll fail to do the PC adjustment, and report
10611 a random SIGTRAP to the user. When the user resumes
10612 the inferior, it will most likely immediately crash
10613 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10614 corrupted, because of being resumed e.g., in the
10615 middle of a multi-byte instruction, or skipped a
10616 one-byte instruction. This was actually seen happen
10617 on native x86-linux, and should be less rare on
10618 targets that do not support new thread events, like
10619 remote, due to the heuristic depending on
10622 Mistaking a random SIGTRAP for a breakpoint trap
10623 causes similar symptoms (PC adjustment applied when
10624 it shouldn't), but then again, playing with SIGTRAPs
10625 behind the debugger's back is asking for trouble.
10627 Since hardware watchpoint traps are always
10628 distinguishable from other traps, so we don't need to
10629 apply keep hardware watchpoint moribund locations
10630 around. We simply always ignore hardware watchpoint
10631 traps we can no longer explain. */
10633 old_loc->events_till_retirement = 3 * (thread_count () + 1);
10634 old_loc->owner = NULL;
10636 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
10640 old_loc->owner = NULL;
10641 decref_bp_location (&old_loc);
10646 /* Rescan breakpoints at the same address and section, marking the
10647 first one as "first" and any others as "duplicates". This is so
10648 that the bpt instruction is only inserted once. If we have a
10649 permanent breakpoint at the same place as BPT, make that one the
10650 official one, and the rest as duplicates. Permanent breakpoints
10651 are sorted first for the same address.
10653 Do the same for hardware watchpoints, but also considering the
10654 watchpoint's type (regular/access/read) and length. */
10656 bp_loc_first = NULL;
10657 wp_loc_first = NULL;
10658 awp_loc_first = NULL;
10659 rwp_loc_first = NULL;
10660 ALL_BP_LOCATIONS (loc, locp)
10662 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10664 struct breakpoint *b = loc->owner;
10665 struct bp_location **loc_first_p;
10667 if (b->enable_state == bp_disabled
10668 || b->enable_state == bp_call_disabled
10669 || b->enable_state == bp_startup_disabled
10671 || loc->shlib_disabled
10672 || !breakpoint_address_is_meaningful (b)
10673 /* Don't detect duplicate for tracepoint locations because they are
10674 never duplicated. See the comments in field `duplicate' of
10675 `struct bp_location'. */
10676 || is_tracepoint (b))
10679 /* Permanent breakpoint should always be inserted. */
10680 if (b->enable_state == bp_permanent && ! loc->inserted)
10681 internal_error (__FILE__, __LINE__,
10682 _("allegedly permanent breakpoint is not "
10683 "actually inserted"));
10685 if (b->type == bp_hardware_watchpoint)
10686 loc_first_p = &wp_loc_first;
10687 else if (b->type == bp_read_watchpoint)
10688 loc_first_p = &rwp_loc_first;
10689 else if (b->type == bp_access_watchpoint)
10690 loc_first_p = &awp_loc_first;
10692 loc_first_p = &bp_loc_first;
10694 if (*loc_first_p == NULL
10695 || (overlay_debugging && loc->section != (*loc_first_p)->section)
10696 || !breakpoint_locations_match (loc, *loc_first_p))
10698 *loc_first_p = loc;
10699 loc->duplicate = 0;
10704 /* This and the above ensure the invariant that the first location
10705 is not duplicated, and is the inserted one.
10706 All following are marked as duplicated, and are not inserted. */
10708 swap_insertion (loc, *loc_first_p);
10709 loc->duplicate = 1;
10711 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
10712 && b->enable_state != bp_permanent)
10713 internal_error (__FILE__, __LINE__,
10714 _("another breakpoint was inserted on top of "
10715 "a permanent breakpoint"));
10718 if (breakpoints_always_inserted_mode () && should_insert
10719 && (have_live_inferiors ()
10720 || (gdbarch_has_global_breakpoints (target_gdbarch))))
10721 insert_breakpoint_locations ();
10724 download_tracepoint_locations ();
10726 do_cleanups (cleanups);
10730 breakpoint_retire_moribund (void)
10732 struct bp_location *loc;
10735 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
10736 if (--(loc->events_till_retirement) == 0)
10738 decref_bp_location (&loc);
10739 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
10745 update_global_location_list_nothrow (int inserting)
10747 struct gdb_exception e;
10749 TRY_CATCH (e, RETURN_MASK_ERROR)
10750 update_global_location_list (inserting);
10753 /* Clear BKP from a BPS. */
10756 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
10760 for (bs = bps; bs; bs = bs->next)
10761 if (bs->breakpoint_at == bpt)
10763 bs->breakpoint_at = NULL;
10764 bs->old_val = NULL;
10765 /* bs->commands will be freed later. */
10769 /* Callback for iterate_over_threads. */
10771 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
10773 struct breakpoint *bpt = data;
10775 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
10779 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10783 say_where (struct breakpoint *b)
10785 struct ui_out *uiout = current_uiout;
10786 struct value_print_options opts;
10788 get_user_print_options (&opts);
10790 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10792 if (b->loc == NULL)
10794 printf_filtered (_(" (%s) pending."), b->addr_string);
10798 if (opts.addressprint || b->source_file == NULL)
10800 printf_filtered (" at ");
10801 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
10804 if (b->source_file)
10805 printf_filtered (": file %s, line %d.",
10806 b->source_file, b->line_number);
10810 struct bp_location *loc = b->loc;
10812 for (; loc; loc = loc->next)
10814 printf_filtered (" (%d locations)", n);
10819 /* Default bp_location_ops methods. */
10822 bp_location_dtor (struct bp_location *self)
10824 xfree (self->cond);
10825 xfree (self->function_name);
10828 static const struct bp_location_ops bp_location_ops =
10833 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10837 base_breakpoint_dtor (struct breakpoint *self)
10839 decref_counted_command_line (&self->commands);
10840 xfree (self->cond_string);
10841 xfree (self->addr_string);
10842 xfree (self->addr_string_range_end);
10843 xfree (self->source_file);
10846 static struct bp_location *
10847 base_breakpoint_allocate_location (struct breakpoint *self)
10849 struct bp_location *loc;
10851 loc = XNEW (struct bp_location);
10852 init_bp_location (loc, &bp_location_ops, self);
10857 base_breakpoint_re_set (struct breakpoint *b)
10859 /* Nothing to re-set. */
10862 #define internal_error_pure_virtual_called() \
10863 gdb_assert_not_reached ("pure virtual function called")
10866 base_breakpoint_insert_location (struct bp_location *bl)
10868 internal_error_pure_virtual_called ();
10872 base_breakpoint_remove_location (struct bp_location *bl)
10874 internal_error_pure_virtual_called ();
10878 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
10879 struct address_space *aspace,
10882 internal_error_pure_virtual_called ();
10886 base_breakpoint_check_status (bpstat bs)
10891 /* A "works_in_software_mode" breakpoint_ops method that just internal
10895 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
10897 internal_error_pure_virtual_called ();
10900 /* A "resources_needed" breakpoint_ops method that just internal
10904 base_breakpoint_resources_needed (const struct bp_location *bl)
10906 internal_error_pure_virtual_called ();
10909 static enum print_stop_action
10910 base_breakpoint_print_it (bpstat bs)
10912 internal_error_pure_virtual_called ();
10916 base_breakpoint_print_one_detail (const struct breakpoint *self,
10917 struct ui_out *uiout)
10923 base_breakpoint_print_mention (struct breakpoint *b)
10925 internal_error_pure_virtual_called ();
10929 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
10931 internal_error_pure_virtual_called ();
10934 static struct breakpoint_ops base_breakpoint_ops =
10936 base_breakpoint_dtor,
10937 base_breakpoint_allocate_location,
10938 base_breakpoint_re_set,
10939 base_breakpoint_insert_location,
10940 base_breakpoint_remove_location,
10941 base_breakpoint_breakpoint_hit,
10942 base_breakpoint_check_status,
10943 base_breakpoint_resources_needed,
10944 base_breakpoint_works_in_software_mode,
10945 base_breakpoint_print_it,
10947 base_breakpoint_print_one_detail,
10948 base_breakpoint_print_mention,
10949 base_breakpoint_print_recreate
10952 /* Default breakpoint_ops methods. */
10955 bkpt_re_set (struct breakpoint *b)
10957 /* Do not attempt to re-set breakpoints disabled during startup. */
10958 if (b->enable_state == bp_startup_disabled)
10961 /* FIXME: is this still reachable? */
10962 if (b->addr_string == NULL)
10964 /* Anything without a string can't be re-set. */
10965 delete_breakpoint (b);
10969 breakpoint_re_set_default (b);
10973 bkpt_insert_location (struct bp_location *bl)
10975 if (bl->loc_type == bp_loc_hardware_breakpoint)
10976 return target_insert_hw_breakpoint (bl->gdbarch,
10979 return target_insert_breakpoint (bl->gdbarch,
10984 bkpt_remove_location (struct bp_location *bl)
10986 if (bl->loc_type == bp_loc_hardware_breakpoint)
10987 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
10989 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
10993 bkpt_breakpoint_hit (const struct bp_location *bl,
10994 struct address_space *aspace, CORE_ADDR bp_addr)
10996 struct breakpoint *b = bl->owner;
10998 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
11002 if (overlay_debugging /* unmapped overlay section */
11003 && section_is_overlay (bl->section)
11004 && !section_is_mapped (bl->section))
11011 bkpt_resources_needed (const struct bp_location *bl)
11013 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
11018 static enum print_stop_action
11019 bkpt_print_it (bpstat bs)
11021 struct breakpoint *b;
11022 const struct bp_location *bl;
11024 struct ui_out *uiout = current_uiout;
11026 gdb_assert (bs->bp_location_at != NULL);
11028 bl = bs->bp_location_at;
11029 b = bs->breakpoint_at;
11031 bp_temp = b->disposition == disp_del;
11032 if (bl->address != bl->requested_address)
11033 breakpoint_adjustment_warning (bl->requested_address,
11036 annotate_breakpoint (b->number);
11038 ui_out_text (uiout, "\nTemporary breakpoint ");
11040 ui_out_text (uiout, "\nBreakpoint ");
11041 if (ui_out_is_mi_like_p (uiout))
11043 ui_out_field_string (uiout, "reason",
11044 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11045 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11047 ui_out_field_int (uiout, "bkptno", b->number);
11048 ui_out_text (uiout, ", ");
11050 return PRINT_SRC_AND_LOC;
11054 bkpt_print_mention (struct breakpoint *b)
11056 if (ui_out_is_mi_like_p (current_uiout))
11061 case bp_breakpoint:
11062 case bp_gnu_ifunc_resolver:
11063 if (b->disposition == disp_del)
11064 printf_filtered (_("Temporary breakpoint"));
11066 printf_filtered (_("Breakpoint"));
11067 printf_filtered (_(" %d"), b->number);
11068 if (b->type == bp_gnu_ifunc_resolver)
11069 printf_filtered (_(" at gnu-indirect-function resolver"));
11071 case bp_hardware_breakpoint:
11072 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
11080 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
11082 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11083 fprintf_unfiltered (fp, "tbreak");
11084 else if (tp->type == bp_breakpoint)
11085 fprintf_unfiltered (fp, "break");
11086 else if (tp->type == bp_hardware_breakpoint
11087 && tp->disposition == disp_del)
11088 fprintf_unfiltered (fp, "thbreak");
11089 else if (tp->type == bp_hardware_breakpoint)
11090 fprintf_unfiltered (fp, "hbreak");
11092 internal_error (__FILE__, __LINE__,
11093 _("unhandled breakpoint type %d"), (int) tp->type);
11095 fprintf_unfiltered (fp, " %s", tp->addr_string);
11096 print_recreate_thread (tp, fp);
11099 /* Virtual table for internal breakpoints. */
11102 internal_bkpt_re_set (struct breakpoint *b)
11106 /* Delete overlay event and longjmp master breakpoints; they
11107 will be reset later by breakpoint_re_set. */
11108 case bp_overlay_event:
11109 case bp_longjmp_master:
11110 case bp_std_terminate_master:
11111 case bp_exception_master:
11112 delete_breakpoint (b);
11115 /* This breakpoint is special, it's set up when the inferior
11116 starts and we really don't want to touch it. */
11117 case bp_shlib_event:
11119 /* Like bp_shlib_event, this breakpoint type is special. Once
11120 it is set up, we do not want to touch it. */
11121 case bp_thread_event:
11127 internal_bkpt_check_status (bpstat bs)
11129 /* We do not stop for these. */
11133 static enum print_stop_action
11134 internal_bkpt_print_it (bpstat bs)
11136 struct breakpoint *b;
11138 b = bs->breakpoint_at;
11142 case bp_shlib_event:
11143 /* Did we stop because the user set the stop_on_solib_events
11144 variable? (If so, we report this as a generic, "Stopped due
11145 to shlib event" message.) */
11146 printf_filtered (_("Stopped due to shared library event\n"));
11149 case bp_thread_event:
11150 /* Not sure how we will get here.
11151 GDB should not stop for these breakpoints. */
11152 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11155 case bp_overlay_event:
11156 /* By analogy with the thread event, GDB should not stop for these. */
11157 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11160 case bp_longjmp_master:
11161 /* These should never be enabled. */
11162 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11165 case bp_std_terminate_master:
11166 /* These should never be enabled. */
11167 printf_filtered (_("std::terminate Master Breakpoint: "
11168 "gdb should not stop!\n"));
11171 case bp_exception_master:
11172 /* These should never be enabled. */
11173 printf_filtered (_("Exception Master Breakpoint: "
11174 "gdb should not stop!\n"));
11178 return PRINT_NOTHING;
11182 internal_bkpt_print_mention (struct breakpoint *b)
11184 /* Nothing to mention. These breakpoints are internal. */
11187 /* Virtual table for momentary breakpoints */
11190 momentary_bkpt_re_set (struct breakpoint *b)
11192 /* Keep temporary breakpoints, which can be encountered when we step
11193 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11194 Otherwise these should have been blown away via the cleanup chain
11195 or by breakpoint_init_inferior when we rerun the executable. */
11199 momentary_bkpt_check_status (bpstat bs)
11201 /* Nothing. The point of these breakpoints is causing a stop. */
11204 static enum print_stop_action
11205 momentary_bkpt_print_it (bpstat bs)
11207 struct ui_out *uiout = current_uiout;
11209 if (ui_out_is_mi_like_p (uiout))
11211 struct breakpoint *b = bs->breakpoint_at;
11216 ui_out_field_string
11218 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
11222 ui_out_field_string
11224 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
11229 return PRINT_UNKNOWN;
11233 momentary_bkpt_print_mention (struct breakpoint *b)
11235 /* Nothing to mention. These breakpoints are internal. */
11238 /* The breakpoint_ops structure to be used in tracepoints. */
11241 tracepoint_re_set (struct breakpoint *b)
11243 breakpoint_re_set_default (b);
11247 tracepoint_breakpoint_hit (const struct bp_location *bl,
11248 struct address_space *aspace, CORE_ADDR bp_addr)
11250 /* By definition, the inferior does not report stops at
11256 tracepoint_print_one_detail (const struct breakpoint *self,
11257 struct ui_out *uiout)
11259 struct tracepoint *tp = (struct tracepoint *) self;
11260 if (tp->static_trace_marker_id)
11262 gdb_assert (self->type == bp_static_tracepoint);
11264 ui_out_text (uiout, "\tmarker id is ");
11265 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
11266 tp->static_trace_marker_id);
11267 ui_out_text (uiout, "\n");
11272 tracepoint_print_mention (struct breakpoint *b)
11274 if (ui_out_is_mi_like_p (current_uiout))
11279 case bp_tracepoint:
11280 printf_filtered (_("Tracepoint"));
11281 printf_filtered (_(" %d"), b->number);
11283 case bp_fast_tracepoint:
11284 printf_filtered (_("Fast tracepoint"));
11285 printf_filtered (_(" %d"), b->number);
11287 case bp_static_tracepoint:
11288 printf_filtered (_("Static tracepoint"));
11289 printf_filtered (_(" %d"), b->number);
11292 internal_error (__FILE__, __LINE__,
11293 _("unhandled tracepoint type %d"), (int) b->type);
11300 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
11302 struct tracepoint *tp = (struct tracepoint *) self;
11304 if (self->type == bp_fast_tracepoint)
11305 fprintf_unfiltered (fp, "ftrace");
11306 if (self->type == bp_static_tracepoint)
11307 fprintf_unfiltered (fp, "strace");
11308 else if (self->type == bp_tracepoint)
11309 fprintf_unfiltered (fp, "trace");
11311 internal_error (__FILE__, __LINE__,
11312 _("unhandled tracepoint type %d"), (int) self->type);
11314 fprintf_unfiltered (fp, " %s", self->addr_string);
11315 print_recreate_thread (self, fp);
11317 if (tp->pass_count)
11318 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11321 struct breakpoint_ops tracepoint_breakpoint_ops;
11323 /* Delete a breakpoint and clean up all traces of it in the data
11327 delete_breakpoint (struct breakpoint *bpt)
11329 struct breakpoint *b;
11331 gdb_assert (bpt != NULL);
11333 /* Has this bp already been deleted? This can happen because
11334 multiple lists can hold pointers to bp's. bpstat lists are
11337 One example of this happening is a watchpoint's scope bp. When
11338 the scope bp triggers, we notice that the watchpoint is out of
11339 scope, and delete it. We also delete its scope bp. But the
11340 scope bp is marked "auto-deleting", and is already on a bpstat.
11341 That bpstat is then checked for auto-deleting bp's, which are
11344 A real solution to this problem might involve reference counts in
11345 bp's, and/or giving them pointers back to their referencing
11346 bpstat's, and teaching delete_breakpoint to only free a bp's
11347 storage when no more references were extent. A cheaper bandaid
11349 if (bpt->type == bp_none)
11352 /* At least avoid this stale reference until the reference counting
11353 of breakpoints gets resolved. */
11354 if (bpt->related_breakpoint != bpt)
11356 struct breakpoint *related;
11357 struct watchpoint *w;
11359 if (bpt->type == bp_watchpoint_scope)
11360 w = (struct watchpoint *) bpt->related_breakpoint;
11361 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
11362 w = (struct watchpoint *) bpt;
11366 watchpoint_del_at_next_stop (w);
11368 /* Unlink bpt from the bpt->related_breakpoint ring. */
11369 for (related = bpt; related->related_breakpoint != bpt;
11370 related = related->related_breakpoint);
11371 related->related_breakpoint = bpt->related_breakpoint;
11372 bpt->related_breakpoint = bpt;
11375 /* watch_command_1 creates a watchpoint but only sets its number if
11376 update_watchpoint succeeds in creating its bp_locations. If there's
11377 a problem in that process, we'll be asked to delete the half-created
11378 watchpoint. In that case, don't announce the deletion. */
11380 observer_notify_breakpoint_deleted (bpt);
11382 if (breakpoint_chain == bpt)
11383 breakpoint_chain = bpt->next;
11385 ALL_BREAKPOINTS (b)
11386 if (b->next == bpt)
11388 b->next = bpt->next;
11392 /* Be sure no bpstat's are pointing at the breakpoint after it's
11394 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11395 in all threads for now. Note that we cannot just remove bpstats
11396 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11397 commands are associated with the bpstat; if we remove it here,
11398 then the later call to bpstat_do_actions (&stop_bpstat); in
11399 event-top.c won't do anything, and temporary breakpoints with
11400 commands won't work. */
11402 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
11404 /* Now that breakpoint is removed from breakpoint list, update the
11405 global location list. This will remove locations that used to
11406 belong to this breakpoint. Do this before freeing the breakpoint
11407 itself, since remove_breakpoint looks at location's owner. It
11408 might be better design to have location completely
11409 self-contained, but it's not the case now. */
11410 update_global_location_list (0);
11412 bpt->ops->dtor (bpt);
11413 /* On the chance that someone will soon try again to delete this
11414 same bp, we mark it as deleted before freeing its storage. */
11415 bpt->type = bp_none;
11420 do_delete_breakpoint_cleanup (void *b)
11422 delete_breakpoint (b);
11426 make_cleanup_delete_breakpoint (struct breakpoint *b)
11428 return make_cleanup (do_delete_breakpoint_cleanup, b);
11431 /* Iterator function to call a user-provided callback function once
11432 for each of B and its related breakpoints. */
11435 iterate_over_related_breakpoints (struct breakpoint *b,
11436 void (*function) (struct breakpoint *,
11440 struct breakpoint *related;
11445 struct breakpoint *next;
11447 /* FUNCTION may delete RELATED. */
11448 next = related->related_breakpoint;
11450 if (next == related)
11452 /* RELATED is the last ring entry. */
11453 function (related, data);
11455 /* FUNCTION may have deleted it, so we'd never reach back to
11456 B. There's nothing left to do anyway, so just break
11461 function (related, data);
11465 while (related != b);
11469 do_delete_breakpoint (struct breakpoint *b, void *ignore)
11471 delete_breakpoint (b);
11474 /* A callback for map_breakpoint_numbers that calls
11475 delete_breakpoint. */
11478 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
11480 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
11484 delete_command (char *arg, int from_tty)
11486 struct breakpoint *b, *b_tmp;
11492 int breaks_to_delete = 0;
11494 /* Delete all breakpoints if no argument. Do not delete
11495 internal breakpoints, these have to be deleted with an
11496 explicit breakpoint number argument. */
11497 ALL_BREAKPOINTS (b)
11498 if (user_breakpoint_p (b))
11500 breaks_to_delete = 1;
11504 /* Ask user only if there are some breakpoints to delete. */
11506 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
11508 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11509 if (user_breakpoint_p (b))
11510 delete_breakpoint (b);
11514 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
11518 all_locations_are_pending (struct bp_location *loc)
11520 for (; loc; loc = loc->next)
11521 if (!loc->shlib_disabled)
11526 /* Subroutine of update_breakpoint_locations to simplify it.
11527 Return non-zero if multiple fns in list LOC have the same name.
11528 Null names are ignored. */
11531 ambiguous_names_p (struct bp_location *loc)
11533 struct bp_location *l;
11534 htab_t htab = htab_create_alloc (13, htab_hash_string,
11535 (int (*) (const void *,
11536 const void *)) streq,
11537 NULL, xcalloc, xfree);
11539 for (l = loc; l != NULL; l = l->next)
11542 const char *name = l->function_name;
11544 /* Allow for some names to be NULL, ignore them. */
11548 slot = (const char **) htab_find_slot (htab, (const void *) name,
11550 /* NOTE: We can assume slot != NULL here because xcalloc never
11554 htab_delete (htab);
11560 htab_delete (htab);
11564 /* When symbols change, it probably means the sources changed as well,
11565 and it might mean the static tracepoint markers are no longer at
11566 the same address or line numbers they used to be at last we
11567 checked. Losing your static tracepoints whenever you rebuild is
11568 undesirable. This function tries to resync/rematch gdb static
11569 tracepoints with the markers on the target, for static tracepoints
11570 that have not been set by marker id. Static tracepoint that have
11571 been set by marker id are reset by marker id in breakpoint_re_set.
11574 1) For a tracepoint set at a specific address, look for a marker at
11575 the old PC. If one is found there, assume to be the same marker.
11576 If the name / string id of the marker found is different from the
11577 previous known name, assume that means the user renamed the marker
11578 in the sources, and output a warning.
11580 2) For a tracepoint set at a given line number, look for a marker
11581 at the new address of the old line number. If one is found there,
11582 assume to be the same marker. If the name / string id of the
11583 marker found is different from the previous known name, assume that
11584 means the user renamed the marker in the sources, and output a
11587 3) If a marker is no longer found at the same address or line, it
11588 may mean the marker no longer exists. But it may also just mean
11589 the code changed a bit. Maybe the user added a few lines of code
11590 that made the marker move up or down (in line number terms). Ask
11591 the target for info about the marker with the string id as we knew
11592 it. If found, update line number and address in the matching
11593 static tracepoint. This will get confused if there's more than one
11594 marker with the same ID (possible in UST, although unadvised
11595 precisely because it confuses tools). */
11597 static struct symtab_and_line
11598 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
11600 struct tracepoint *tp = (struct tracepoint *) b;
11601 struct static_tracepoint_marker marker;
11607 find_line_pc (sal.symtab, sal.line, &pc);
11609 if (target_static_tracepoint_marker_at (pc, &marker))
11611 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
11612 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11614 tp->static_trace_marker_id, marker.str_id);
11616 xfree (tp->static_trace_marker_id);
11617 tp->static_trace_marker_id = xstrdup (marker.str_id);
11618 release_static_tracepoint_marker (&marker);
11623 /* Old marker wasn't found on target at lineno. Try looking it up
11625 if (!sal.explicit_pc
11627 && sal.symtab != NULL
11628 && tp->static_trace_marker_id != NULL)
11630 VEC(static_tracepoint_marker_p) *markers;
11633 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
11635 if (!VEC_empty(static_tracepoint_marker_p, markers))
11637 struct symtab_and_line sal;
11638 struct symbol *sym;
11639 struct static_tracepoint_marker *marker;
11640 struct ui_out *uiout = current_uiout;
11642 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
11644 xfree (tp->static_trace_marker_id);
11645 tp->static_trace_marker_id = xstrdup (marker->str_id);
11647 warning (_("marker for static tracepoint %d (%s) not "
11648 "found at previous line number"),
11649 b->number, tp->static_trace_marker_id);
11653 sal.pc = marker->address;
11655 sal = find_pc_line (marker->address, 0);
11656 sym = find_pc_sect_function (marker->address, NULL);
11657 ui_out_text (uiout, "Now in ");
11660 ui_out_field_string (uiout, "func",
11661 SYMBOL_PRINT_NAME (sym));
11662 ui_out_text (uiout, " at ");
11664 ui_out_field_string (uiout, "file", sal.symtab->filename);
11665 ui_out_text (uiout, ":");
11667 if (ui_out_is_mi_like_p (uiout))
11669 char *fullname = symtab_to_fullname (sal.symtab);
11672 ui_out_field_string (uiout, "fullname", fullname);
11675 ui_out_field_int (uiout, "line", sal.line);
11676 ui_out_text (uiout, "\n");
11678 b->line_number = sal.line;
11680 xfree (b->source_file);
11682 b->source_file = xstrdup (sal.symtab->filename);
11684 b->source_file = NULL;
11686 xfree (b->addr_string);
11687 b->addr_string = xstrprintf ("%s:%d",
11688 sal.symtab->filename, b->line_number);
11690 /* Might be nice to check if function changed, and warn if
11693 release_static_tracepoint_marker (marker);
11699 /* Returns 1 iff locations A and B are sufficiently same that
11700 we don't need to report breakpoint as changed. */
11703 locations_are_equal (struct bp_location *a, struct bp_location *b)
11707 if (a->address != b->address)
11710 if (a->shlib_disabled != b->shlib_disabled)
11713 if (a->enabled != b->enabled)
11720 if ((a == NULL) != (b == NULL))
11726 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11727 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11728 a ranged breakpoint. */
11731 update_breakpoint_locations (struct breakpoint *b,
11732 struct symtabs_and_lines sals,
11733 struct symtabs_and_lines sals_end)
11736 struct bp_location *existing_locations = b->loc;
11738 /* Ranged breakpoints have only one start location and one end location. */
11739 gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1));
11741 /* If there's no new locations, and all existing locations are
11742 pending, don't do anything. This optimizes the common case where
11743 all locations are in the same shared library, that was unloaded.
11744 We'd like to retain the location, so that when the library is
11745 loaded again, we don't loose the enabled/disabled status of the
11746 individual locations. */
11747 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
11752 for (i = 0; i < sals.nelts; ++i)
11754 struct bp_location *new_loc =
11755 add_location_to_breakpoint (b, &(sals.sals[i]));
11757 /* Reparse conditions, they might contain references to the
11759 if (b->cond_string != NULL)
11762 struct gdb_exception e;
11764 s = b->cond_string;
11765 TRY_CATCH (e, RETURN_MASK_ERROR)
11767 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
11772 warning (_("failed to reevaluate condition "
11773 "for breakpoint %d: %s"),
11774 b->number, e.message);
11775 new_loc->enabled = 0;
11779 if (b->source_file != NULL)
11780 xfree (b->source_file);
11781 if (sals.sals[i].symtab == NULL)
11782 b->source_file = NULL;
11784 b->source_file = xstrdup (sals.sals[i].symtab->filename);
11786 if (b->line_number == 0)
11787 b->line_number = sals.sals[i].line;
11789 if (sals_end.nelts)
11791 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
11793 new_loc->length = end - sals.sals[0].pc + 1;
11797 /* Update locations of permanent breakpoints. */
11798 if (b->enable_state == bp_permanent)
11799 make_breakpoint_permanent (b);
11801 /* If possible, carry over 'disable' status from existing
11804 struct bp_location *e = existing_locations;
11805 /* If there are multiple breakpoints with the same function name,
11806 e.g. for inline functions, comparing function names won't work.
11807 Instead compare pc addresses; this is just a heuristic as things
11808 may have moved, but in practice it gives the correct answer
11809 often enough until a better solution is found. */
11810 int have_ambiguous_names = ambiguous_names_p (b->loc);
11812 for (; e; e = e->next)
11814 if (!e->enabled && e->function_name)
11816 struct bp_location *l = b->loc;
11817 if (have_ambiguous_names)
11819 for (; l; l = l->next)
11820 if (breakpoint_locations_match (e, l))
11828 for (; l; l = l->next)
11829 if (l->function_name
11830 && strcmp (e->function_name, l->function_name) == 0)
11840 if (!locations_are_equal (existing_locations, b->loc))
11841 observer_notify_breakpoint_modified (b);
11843 update_global_location_list (1);
11846 /* Find the SaL locations corresponding to the given ADDR_STRING.
11847 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11849 static struct symtabs_and_lines
11850 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
11854 struct symtabs_and_lines sals = {0};
11855 struct gdb_exception e;
11858 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
11860 TRY_CATCH (e, RETURN_MASK_ERROR)
11864 struct tracepoint *tp = (struct tracepoint *) b;
11866 sals = decode_static_tracepoint_spec (&s);
11867 if (sals.nelts > tp->static_trace_marker_id_idx)
11869 sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx];
11873 error (_("marker %s not found"), tp->static_trace_marker_id);
11876 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL);
11880 int not_found_and_ok = 0;
11881 /* For pending breakpoints, it's expected that parsing will
11882 fail until the right shared library is loaded. User has
11883 already told to create pending breakpoints and don't need
11884 extra messages. If breakpoint is in bp_shlib_disabled
11885 state, then user already saw the message about that
11886 breakpoint being disabled, and don't want to see more
11888 if (e.error == NOT_FOUND_ERROR
11889 && (b->condition_not_parsed
11890 || (b->loc && b->loc->shlib_disabled)
11891 || b->enable_state == bp_disabled))
11892 not_found_and_ok = 1;
11894 if (!not_found_and_ok)
11896 /* We surely don't want to warn about the same breakpoint
11897 10 times. One solution, implemented here, is disable
11898 the breakpoint on error. Another solution would be to
11899 have separate 'warning emitted' flag. Since this
11900 happens only when a binary has changed, I don't know
11901 which approach is better. */
11902 b->enable_state = bp_disabled;
11903 throw_exception (e);
11907 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
11909 gdb_assert (sals.nelts == 1);
11911 resolve_sal_pc (&sals.sals[0]);
11912 if (b->condition_not_parsed && s && s[0])
11914 char *cond_string = 0;
11918 find_condition_and_thread (s, sals.sals[0].pc,
11919 &cond_string, &thread, &task);
11921 b->cond_string = cond_string;
11922 b->thread = thread;
11924 b->condition_not_parsed = 0;
11927 if (b->type == bp_static_tracepoint && !marker_spec)
11928 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
11938 /* The default re_set method, for typical hardware or software
11939 breakpoints. Reevaluate the breakpoint and recreate its
11943 breakpoint_re_set_default (struct breakpoint *b)
11946 struct symtabs_and_lines sals, sals_end;
11947 struct symtabs_and_lines expanded = {0};
11948 struct symtabs_and_lines expanded_end = {0};
11950 sals = addr_string_to_sals (b, b->addr_string, &found);
11953 make_cleanup (xfree, sals.sals);
11954 expanded = expand_line_sal_maybe (sals.sals[0]);
11957 if (b->addr_string_range_end)
11959 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
11962 make_cleanup (xfree, sals_end.sals);
11963 expanded_end = expand_line_sal_maybe (sals_end.sals[0]);
11967 update_breakpoint_locations (b, expanded, expanded_end);
11970 /* Prepare the global context for a re-set of breakpoint B. */
11972 static struct cleanup *
11973 prepare_re_set_context (struct breakpoint *b)
11975 struct cleanup *cleanups;
11977 input_radix = b->input_radix;
11978 cleanups = save_current_space_and_thread ();
11979 switch_to_program_space_and_thread (b->pspace);
11980 set_language (b->language);
11985 /* Reset a breakpoint given it's struct breakpoint * BINT.
11986 The value we return ends up being the return value from catch_errors.
11987 Unused in this case. */
11990 breakpoint_re_set_one (void *bint)
11992 /* Get past catch_errs. */
11993 struct breakpoint *b = (struct breakpoint *) bint;
11994 struct cleanup *cleanups;
11996 cleanups = prepare_re_set_context (b);
11997 b->ops->re_set (b);
11998 do_cleanups (cleanups);
12002 /* Re-set all breakpoints after symbols have been re-loaded. */
12004 breakpoint_re_set (void)
12006 struct breakpoint *b, *b_tmp;
12007 enum language save_language;
12008 int save_input_radix;
12009 struct cleanup *old_chain;
12011 save_language = current_language->la_language;
12012 save_input_radix = input_radix;
12013 old_chain = save_current_program_space ();
12015 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12017 /* Format possible error msg. */
12018 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
12020 struct cleanup *cleanups = make_cleanup (xfree, message);
12021 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
12022 do_cleanups (cleanups);
12024 set_language (save_language);
12025 input_radix = save_input_radix;
12027 jit_breakpoint_re_set ();
12029 do_cleanups (old_chain);
12031 create_overlay_event_breakpoint ();
12032 create_longjmp_master_breakpoint ();
12033 create_std_terminate_master_breakpoint ();
12034 create_exception_master_breakpoint ();
12036 /* While we're at it, reset the skip list too. */
12040 /* Reset the thread number of this breakpoint:
12042 - If the breakpoint is for all threads, leave it as-is.
12043 - Else, reset it to the current thread for inferior_ptid. */
12045 breakpoint_re_set_thread (struct breakpoint *b)
12047 if (b->thread != -1)
12049 if (in_thread_list (inferior_ptid))
12050 b->thread = pid_to_thread_id (inferior_ptid);
12052 /* We're being called after following a fork. The new fork is
12053 selected as current, and unless this was a vfork will have a
12054 different program space from the original thread. Reset that
12056 b->loc->pspace = current_program_space;
12060 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12061 If from_tty is nonzero, it prints a message to that effect,
12062 which ends with a period (no newline). */
12065 set_ignore_count (int bptnum, int count, int from_tty)
12067 struct breakpoint *b;
12072 ALL_BREAKPOINTS (b)
12073 if (b->number == bptnum)
12075 if (is_tracepoint (b))
12077 if (from_tty && count != 0)
12078 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12083 b->ignore_count = count;
12087 printf_filtered (_("Will stop next time "
12088 "breakpoint %d is reached."),
12090 else if (count == 1)
12091 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12094 printf_filtered (_("Will ignore next %d "
12095 "crossings of breakpoint %d."),
12098 breakpoints_changed ();
12099 observer_notify_breakpoint_modified (b);
12103 error (_("No breakpoint number %d."), bptnum);
12106 /* Command to set ignore-count of breakpoint N to COUNT. */
12109 ignore_command (char *args, int from_tty)
12115 error_no_arg (_("a breakpoint number"));
12117 num = get_number (&p);
12119 error (_("bad breakpoint number: '%s'"), args);
12121 error (_("Second argument (specified ignore-count) is missing."));
12123 set_ignore_count (num,
12124 longest_to_int (value_as_long (parse_and_eval (p))),
12127 printf_filtered ("\n");
12130 /* Call FUNCTION on each of the breakpoints
12131 whose numbers are given in ARGS. */
12134 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
12139 struct breakpoint *b, *tmp;
12141 struct get_number_or_range_state state;
12144 error_no_arg (_("one or more breakpoint numbers"));
12146 init_number_or_range (&state, args);
12148 while (!state.finished)
12150 char *p = state.string;
12154 num = get_number_or_range (&state);
12157 warning (_("bad breakpoint number at or near '%s'"), p);
12161 ALL_BREAKPOINTS_SAFE (b, tmp)
12162 if (b->number == num)
12165 function (b, data);
12169 printf_unfiltered (_("No breakpoint number %d.\n"), num);
12174 static struct bp_location *
12175 find_location_by_number (char *number)
12177 char *dot = strchr (number, '.');
12181 struct breakpoint *b;
12182 struct bp_location *loc;
12187 bp_num = get_number (&p1);
12189 error (_("Bad breakpoint number '%s'"), number);
12191 ALL_BREAKPOINTS (b)
12192 if (b->number == bp_num)
12197 if (!b || b->number != bp_num)
12198 error (_("Bad breakpoint number '%s'"), number);
12201 loc_num = get_number (&p1);
12203 error (_("Bad breakpoint location number '%s'"), number);
12207 for (;loc_num && loc; --loc_num, loc = loc->next)
12210 error (_("Bad breakpoint location number '%s'"), dot+1);
12216 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12217 If from_tty is nonzero, it prints a message to that effect,
12218 which ends with a period (no newline). */
12221 disable_breakpoint (struct breakpoint *bpt)
12223 /* Never disable a watchpoint scope breakpoint; we want to
12224 hit them when we leave scope so we can delete both the
12225 watchpoint and its scope breakpoint at that time. */
12226 if (bpt->type == bp_watchpoint_scope)
12229 /* You can't disable permanent breakpoints. */
12230 if (bpt->enable_state == bp_permanent)
12233 bpt->enable_state = bp_disabled;
12235 if (target_supports_enable_disable_tracepoint ()
12236 && current_trace_status ()->running && is_tracepoint (bpt))
12238 struct bp_location *location;
12240 for (location = bpt->loc; location; location = location->next)
12241 target_disable_tracepoint (location);
12244 update_global_location_list (0);
12246 observer_notify_breakpoint_modified (bpt);
12249 /* A callback for iterate_over_related_breakpoints. */
12252 do_disable_breakpoint (struct breakpoint *b, void *ignore)
12254 disable_breakpoint (b);
12257 /* A callback for map_breakpoint_numbers that calls
12258 disable_breakpoint. */
12261 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
12263 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
12267 disable_command (char *args, int from_tty)
12271 struct breakpoint *bpt;
12273 ALL_BREAKPOINTS (bpt)
12274 if (user_breakpoint_p (bpt))
12275 disable_breakpoint (bpt);
12277 else if (strchr (args, '.'))
12279 struct bp_location *loc = find_location_by_number (args);
12283 if (target_supports_enable_disable_tracepoint ()
12284 && current_trace_status ()->running && loc->owner
12285 && is_tracepoint (loc->owner))
12286 target_disable_tracepoint (loc);
12288 update_global_location_list (0);
12291 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
12295 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition)
12297 int target_resources_ok;
12299 if (bpt->type == bp_hardware_breakpoint)
12302 i = hw_breakpoint_used_count ();
12303 target_resources_ok =
12304 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
12306 if (target_resources_ok == 0)
12307 error (_("No hardware breakpoint support in the target."));
12308 else if (target_resources_ok < 0)
12309 error (_("Hardware breakpoints used exceeds limit."));
12312 if (is_watchpoint (bpt))
12314 /* Initialize it just to avoid a GCC false warning. */
12315 enum enable_state orig_enable_state = 0;
12316 struct gdb_exception e;
12318 TRY_CATCH (e, RETURN_MASK_ALL)
12320 struct watchpoint *w = (struct watchpoint *) bpt;
12322 orig_enable_state = bpt->enable_state;
12323 bpt->enable_state = bp_enabled;
12324 update_watchpoint (w, 1 /* reparse */);
12328 bpt->enable_state = orig_enable_state;
12329 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
12335 if (bpt->enable_state != bp_permanent)
12336 bpt->enable_state = bp_enabled;
12338 if (target_supports_enable_disable_tracepoint ()
12339 && current_trace_status ()->running && is_tracepoint (bpt))
12341 struct bp_location *location;
12343 for (location = bpt->loc; location; location = location->next)
12344 target_enable_tracepoint (location);
12347 bpt->disposition = disposition;
12348 update_global_location_list (1);
12349 breakpoints_changed ();
12351 observer_notify_breakpoint_modified (bpt);
12356 enable_breakpoint (struct breakpoint *bpt)
12358 enable_breakpoint_disp (bpt, bpt->disposition);
12362 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
12364 enable_breakpoint (bpt);
12367 /* A callback for map_breakpoint_numbers that calls
12368 enable_breakpoint. */
12371 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
12373 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
12376 /* The enable command enables the specified breakpoints (or all defined
12377 breakpoints) so they once again become (or continue to be) effective
12378 in stopping the inferior. */
12381 enable_command (char *args, int from_tty)
12385 struct breakpoint *bpt;
12387 ALL_BREAKPOINTS (bpt)
12388 if (user_breakpoint_p (bpt))
12389 enable_breakpoint (bpt);
12391 else if (strchr (args, '.'))
12393 struct bp_location *loc = find_location_by_number (args);
12397 if (target_supports_enable_disable_tracepoint ()
12398 && current_trace_status ()->running && loc->owner
12399 && is_tracepoint (loc->owner))
12400 target_enable_tracepoint (loc);
12402 update_global_location_list (1);
12405 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
12409 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
12411 enum bpdisp disp = *(enum bpdisp *) arg;
12413 enable_breakpoint_disp (bpt, disp);
12417 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
12419 enum bpdisp disp = disp_disable;
12421 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12425 enable_once_command (char *args, int from_tty)
12427 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
12431 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
12433 enum bpdisp disp = disp_del;
12435 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12439 enable_delete_command (char *args, int from_tty)
12441 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
12445 set_breakpoint_cmd (char *args, int from_tty)
12450 show_breakpoint_cmd (char *args, int from_tty)
12454 /* Invalidate last known value of any hardware watchpoint if
12455 the memory which that value represents has been written to by
12459 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
12460 const bfd_byte *data)
12462 struct breakpoint *bp;
12464 ALL_BREAKPOINTS (bp)
12465 if (bp->enable_state == bp_enabled
12466 && bp->type == bp_hardware_watchpoint)
12468 struct watchpoint *wp = (struct watchpoint *) bp;
12470 if (wp->val_valid && wp->val)
12472 struct bp_location *loc;
12474 for (loc = bp->loc; loc != NULL; loc = loc->next)
12475 if (loc->loc_type == bp_loc_hardware_watchpoint
12476 && loc->address + loc->length > addr
12477 && addr + len > loc->address)
12479 value_free (wp->val);
12487 /* Use the last displayed codepoint's values, or nothing
12488 if they aren't valid. */
12490 struct symtabs_and_lines
12491 decode_line_spec_1 (char *string, int funfirstline)
12493 struct symtabs_and_lines sals;
12496 error (_("Empty line specification."));
12497 if (last_displayed_sal_is_valid ())
12498 sals = decode_line_1 (&string, funfirstline,
12499 get_last_displayed_symtab (),
12500 get_last_displayed_line (),
12503 sals = decode_line_1 (&string, funfirstline,
12504 (struct symtab *) NULL, 0, NULL);
12506 error (_("Junk at end of line specification: %s"), string);
12510 /* Create and insert a raw software breakpoint at PC. Return an
12511 identifier, which should be used to remove the breakpoint later.
12512 In general, places which call this should be using something on the
12513 breakpoint chain instead; this function should be eliminated
12517 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
12518 struct address_space *aspace, CORE_ADDR pc)
12520 struct bp_target_info *bp_tgt;
12522 bp_tgt = XZALLOC (struct bp_target_info);
12524 bp_tgt->placed_address_space = aspace;
12525 bp_tgt->placed_address = pc;
12527 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
12529 /* Could not insert the breakpoint. */
12537 /* Remove a breakpoint BP inserted by
12538 deprecated_insert_raw_breakpoint. */
12541 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
12543 struct bp_target_info *bp_tgt = bp;
12546 ret = target_remove_breakpoint (gdbarch, bp_tgt);
12552 /* One (or perhaps two) breakpoints used for software single
12555 static void *single_step_breakpoints[2];
12556 static struct gdbarch *single_step_gdbarch[2];
12558 /* Create and insert a breakpoint for software single step. */
12561 insert_single_step_breakpoint (struct gdbarch *gdbarch,
12562 struct address_space *aspace,
12567 if (single_step_breakpoints[0] == NULL)
12569 bpt_p = &single_step_breakpoints[0];
12570 single_step_gdbarch[0] = gdbarch;
12574 gdb_assert (single_step_breakpoints[1] == NULL);
12575 bpt_p = &single_step_breakpoints[1];
12576 single_step_gdbarch[1] = gdbarch;
12579 /* NOTE drow/2006-04-11: A future improvement to this function would
12580 be to only create the breakpoints once, and actually put them on
12581 the breakpoint chain. That would let us use set_raw_breakpoint.
12582 We could adjust the addresses each time they were needed. Doing
12583 this requires corresponding changes elsewhere where single step
12584 breakpoints are handled, however. So, for now, we use this. */
12586 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
12587 if (*bpt_p == NULL)
12588 error (_("Could not insert single-step breakpoint at %s"),
12589 paddress (gdbarch, next_pc));
12592 /* Check if the breakpoints used for software single stepping
12593 were inserted or not. */
12596 single_step_breakpoints_inserted (void)
12598 return (single_step_breakpoints[0] != NULL
12599 || single_step_breakpoints[1] != NULL);
12602 /* Remove and delete any breakpoints used for software single step. */
12605 remove_single_step_breakpoints (void)
12607 gdb_assert (single_step_breakpoints[0] != NULL);
12609 /* See insert_single_step_breakpoint for more about this deprecated
12611 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
12612 single_step_breakpoints[0]);
12613 single_step_gdbarch[0] = NULL;
12614 single_step_breakpoints[0] = NULL;
12616 if (single_step_breakpoints[1] != NULL)
12618 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
12619 single_step_breakpoints[1]);
12620 single_step_gdbarch[1] = NULL;
12621 single_step_breakpoints[1] = NULL;
12625 /* Delete software single step breakpoints without removing them from
12626 the inferior. This is intended to be used if the inferior's address
12627 space where they were inserted is already gone, e.g. after exit or
12631 cancel_single_step_breakpoints (void)
12635 for (i = 0; i < 2; i++)
12636 if (single_step_breakpoints[i])
12638 xfree (single_step_breakpoints[i]);
12639 single_step_breakpoints[i] = NULL;
12640 single_step_gdbarch[i] = NULL;
12644 /* Detach software single-step breakpoints from INFERIOR_PTID without
12648 detach_single_step_breakpoints (void)
12652 for (i = 0; i < 2; i++)
12653 if (single_step_breakpoints[i])
12654 target_remove_breakpoint (single_step_gdbarch[i],
12655 single_step_breakpoints[i]);
12658 /* Check whether a software single-step breakpoint is inserted at
12662 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
12667 for (i = 0; i < 2; i++)
12669 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
12671 && breakpoint_address_match (bp_tgt->placed_address_space,
12672 bp_tgt->placed_address,
12680 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12681 non-zero otherwise. */
12683 is_syscall_catchpoint_enabled (struct breakpoint *bp)
12685 if (syscall_catchpoint_p (bp)
12686 && bp->enable_state != bp_disabled
12687 && bp->enable_state != bp_call_disabled)
12694 catch_syscall_enabled (void)
12696 struct inferior *inf = current_inferior ();
12698 return inf->total_syscalls_count != 0;
12702 catching_syscall_number (int syscall_number)
12704 struct breakpoint *bp;
12706 ALL_BREAKPOINTS (bp)
12707 if (is_syscall_catchpoint_enabled (bp))
12709 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
12711 if (c->syscalls_to_be_caught)
12715 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
12717 if (syscall_number == iter)
12727 /* Complete syscall names. Used by "catch syscall". */
12729 catch_syscall_completer (struct cmd_list_element *cmd,
12730 char *text, char *word)
12732 const char **list = get_syscall_names ();
12734 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
12740 /* Tracepoint-specific operations. */
12742 /* Set tracepoint count to NUM. */
12744 set_tracepoint_count (int num)
12746 tracepoint_count = num;
12747 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
12751 trace_command (char *arg, int from_tty)
12753 if (create_breakpoint (get_current_arch (),
12755 NULL, 0, 1 /* parse arg */,
12757 bp_tracepoint /* type_wanted */,
12758 0 /* Ignore count */,
12759 pending_break_support,
12760 &tracepoint_breakpoint_ops,
12764 set_tracepoint_count (breakpoint_count);
12768 ftrace_command (char *arg, int from_tty)
12770 if (create_breakpoint (get_current_arch (),
12772 NULL, 0, 1 /* parse arg */,
12774 bp_fast_tracepoint /* type_wanted */,
12775 0 /* Ignore count */,
12776 pending_break_support,
12777 &tracepoint_breakpoint_ops,
12781 set_tracepoint_count (breakpoint_count);
12784 /* strace command implementation. Creates a static tracepoint. */
12787 strace_command (char *arg, int from_tty)
12789 if (create_breakpoint (get_current_arch (),
12791 NULL, 0, 1 /* parse arg */,
12793 bp_static_tracepoint /* type_wanted */,
12794 0 /* Ignore count */,
12795 pending_break_support,
12796 &tracepoint_breakpoint_ops,
12800 set_tracepoint_count (breakpoint_count);
12803 /* Set up a fake reader function that gets command lines from a linked
12804 list that was acquired during tracepoint uploading. */
12806 static struct uploaded_tp *this_utp;
12807 static int next_cmd;
12810 read_uploaded_action (void)
12814 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
12821 /* Given information about a tracepoint as recorded on a target (which
12822 can be either a live system or a trace file), attempt to create an
12823 equivalent GDB tracepoint. This is not a reliable process, since
12824 the target does not necessarily have all the information used when
12825 the tracepoint was originally defined. */
12827 struct tracepoint *
12828 create_tracepoint_from_upload (struct uploaded_tp *utp)
12830 char *addr_str, small_buf[100];
12831 struct tracepoint *tp;
12833 if (utp->at_string)
12834 addr_str = utp->at_string;
12837 /* In the absence of a source location, fall back to raw
12838 address. Since there is no way to confirm that the address
12839 means the same thing as when the trace was started, warn the
12841 warning (_("Uploaded tracepoint %d has no "
12842 "source location, using raw address"),
12844 sprintf (small_buf, "*%s", hex_string (utp->addr));
12845 addr_str = small_buf;
12848 /* There's not much we can do with a sequence of bytecodes. */
12849 if (utp->cond && !utp->cond_string)
12850 warning (_("Uploaded tracepoint %d condition "
12851 "has no source form, ignoring it"),
12854 if (!create_breakpoint (get_current_arch (),
12856 utp->cond_string, -1, 0 /* parse cond/thread */,
12858 utp->type /* type_wanted */,
12859 0 /* Ignore count */,
12860 pending_break_support,
12861 &tracepoint_breakpoint_ops,
12863 utp->enabled /* enabled */,
12867 set_tracepoint_count (breakpoint_count);
12869 /* Get the tracepoint we just created. */
12870 tp = get_tracepoint (tracepoint_count);
12871 gdb_assert (tp != NULL);
12875 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
12877 trace_pass_command (small_buf, 0);
12880 /* If we have uploaded versions of the original commands, set up a
12881 special-purpose "reader" function and call the usual command line
12882 reader, then pass the result to the breakpoint command-setting
12884 if (!VEC_empty (char_ptr, utp->cmd_strings))
12886 struct command_line *cmd_list;
12891 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
12893 breakpoint_set_commands (&tp->base, cmd_list);
12895 else if (!VEC_empty (char_ptr, utp->actions)
12896 || !VEC_empty (char_ptr, utp->step_actions))
12897 warning (_("Uploaded tracepoint %d actions "
12898 "have no source form, ignoring them"),
12904 /* Print information on tracepoint number TPNUM_EXP, or all if
12908 tracepoints_info (char *args, int from_tty)
12910 struct ui_out *uiout = current_uiout;
12913 num_printed = breakpoint_1 (args, 0, is_tracepoint);
12915 if (num_printed == 0)
12917 if (args == NULL || *args == '\0')
12918 ui_out_message (uiout, 0, "No tracepoints.\n");
12920 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
12923 default_collect_info ();
12926 /* The 'enable trace' command enables tracepoints.
12927 Not supported by all targets. */
12929 enable_trace_command (char *args, int from_tty)
12931 enable_command (args, from_tty);
12934 /* The 'disable trace' command disables tracepoints.
12935 Not supported by all targets. */
12937 disable_trace_command (char *args, int from_tty)
12939 disable_command (args, from_tty);
12942 /* Remove a tracepoint (or all if no argument). */
12944 delete_trace_command (char *arg, int from_tty)
12946 struct breakpoint *b, *b_tmp;
12952 int breaks_to_delete = 0;
12954 /* Delete all breakpoints if no argument.
12955 Do not delete internal or call-dummy breakpoints, these
12956 have to be deleted with an explicit breakpoint number
12958 ALL_TRACEPOINTS (b)
12959 if (is_tracepoint (b) && user_breakpoint_p (b))
12961 breaks_to_delete = 1;
12965 /* Ask user only if there are some breakpoints to delete. */
12967 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
12969 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12970 if (is_tracepoint (b) && user_breakpoint_p (b))
12971 delete_breakpoint (b);
12975 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12978 /* Helper function for trace_pass_command. */
12981 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
12983 tp->pass_count = count;
12984 observer_notify_tracepoint_modified (tp->base.number);
12986 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12987 tp->base.number, count);
12990 /* Set passcount for tracepoint.
12992 First command argument is passcount, second is tracepoint number.
12993 If tracepoint number omitted, apply to most recently defined.
12994 Also accepts special argument "all". */
12997 trace_pass_command (char *args, int from_tty)
12999 struct tracepoint *t1;
13000 unsigned int count;
13002 if (args == 0 || *args == 0)
13003 error (_("passcount command requires an "
13004 "argument (count + optional TP num)"));
13006 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
13008 while (*args && isspace ((int) *args))
13011 if (*args && strncasecmp (args, "all", 3) == 0)
13013 struct breakpoint *b;
13015 args += 3; /* Skip special argument "all". */
13017 error (_("Junk at end of arguments."));
13019 ALL_TRACEPOINTS (b)
13021 t1 = (struct tracepoint *) b;
13022 trace_pass_set_count (t1, count, from_tty);
13025 else if (*args == '\0')
13027 t1 = get_tracepoint_by_number (&args, NULL, 1);
13029 trace_pass_set_count (t1, count, from_tty);
13033 struct get_number_or_range_state state;
13035 init_number_or_range (&state, args);
13036 while (!state.finished)
13038 t1 = get_tracepoint_by_number (&args, &state, 1);
13040 trace_pass_set_count (t1, count, from_tty);
13045 struct tracepoint *
13046 get_tracepoint (int num)
13048 struct breakpoint *t;
13050 ALL_TRACEPOINTS (t)
13051 if (t->number == num)
13052 return (struct tracepoint *) t;
13057 /* Find the tracepoint with the given target-side number (which may be
13058 different from the tracepoint number after disconnecting and
13061 struct tracepoint *
13062 get_tracepoint_by_number_on_target (int num)
13064 struct breakpoint *b;
13066 ALL_TRACEPOINTS (b)
13068 struct tracepoint *t = (struct tracepoint *) b;
13070 if (t->number_on_target == num)
13077 /* Utility: parse a tracepoint number and look it up in the list.
13078 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13079 If OPTIONAL_P is true, then if the argument is missing, the most
13080 recent tracepoint (tracepoint_count) is returned. */
13081 struct tracepoint *
13082 get_tracepoint_by_number (char **arg,
13083 struct get_number_or_range_state *state,
13086 extern int tracepoint_count;
13087 struct breakpoint *t;
13089 char *instring = arg == NULL ? NULL : *arg;
13093 gdb_assert (!state->finished);
13094 tpnum = get_number_or_range (state);
13096 else if (arg == NULL || *arg == NULL || ! **arg)
13099 tpnum = tracepoint_count;
13101 error_no_arg (_("tracepoint number"));
13104 tpnum = get_number (arg);
13108 if (instring && *instring)
13109 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13112 printf_filtered (_("Tracepoint argument missing "
13113 "and no previous tracepoint\n"));
13117 ALL_TRACEPOINTS (t)
13118 if (t->number == tpnum)
13120 return (struct tracepoint *) t;
13123 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
13128 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
13130 if (b->thread != -1)
13131 fprintf_unfiltered (fp, " thread %d", b->thread);
13134 fprintf_unfiltered (fp, " task %d", b->task);
13136 fprintf_unfiltered (fp, "\n");
13139 /* Save information on user settable breakpoints (watchpoints, etc) to
13140 a new script file named FILENAME. If FILTER is non-NULL, call it
13141 on each breakpoint and only include the ones for which it returns
13145 save_breakpoints (char *filename, int from_tty,
13146 int (*filter) (const struct breakpoint *))
13148 struct breakpoint *tp;
13151 struct cleanup *cleanup;
13152 struct ui_file *fp;
13153 int extra_trace_bits = 0;
13155 if (filename == 0 || *filename == 0)
13156 error (_("Argument required (file name in which to save)"));
13158 /* See if we have anything to save. */
13159 ALL_BREAKPOINTS (tp)
13161 /* Skip internal and momentary breakpoints. */
13162 if (!user_breakpoint_p (tp))
13165 /* If we have a filter, only save the breakpoints it accepts. */
13166 if (filter && !filter (tp))
13171 if (is_tracepoint (tp))
13173 extra_trace_bits = 1;
13175 /* We can stop searching. */
13182 warning (_("Nothing to save."));
13186 pathname = tilde_expand (filename);
13187 cleanup = make_cleanup (xfree, pathname);
13188 fp = gdb_fopen (pathname, "w");
13190 error (_("Unable to open file '%s' for saving (%s)"),
13191 filename, safe_strerror (errno));
13192 make_cleanup_ui_file_delete (fp);
13194 if (extra_trace_bits)
13195 save_trace_state_variables (fp);
13197 ALL_BREAKPOINTS (tp)
13199 /* Skip internal and momentary breakpoints. */
13200 if (!user_breakpoint_p (tp))
13203 /* If we have a filter, only save the breakpoints it accepts. */
13204 if (filter && !filter (tp))
13207 tp->ops->print_recreate (tp, fp);
13209 /* Note, we can't rely on tp->number for anything, as we can't
13210 assume the recreated breakpoint numbers will match. Use $bpnum
13213 if (tp->cond_string)
13214 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
13216 if (tp->ignore_count)
13217 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
13221 volatile struct gdb_exception ex;
13223 fprintf_unfiltered (fp, " commands\n");
13225 ui_out_redirect (current_uiout, fp);
13226 TRY_CATCH (ex, RETURN_MASK_ALL)
13228 print_command_lines (current_uiout, tp->commands->commands, 2);
13230 ui_out_redirect (current_uiout, NULL);
13233 throw_exception (ex);
13235 fprintf_unfiltered (fp, " end\n");
13238 if (tp->enable_state == bp_disabled)
13239 fprintf_unfiltered (fp, "disable\n");
13241 /* If this is a multi-location breakpoint, check if the locations
13242 should be individually disabled. Watchpoint locations are
13243 special, and not user visible. */
13244 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
13246 struct bp_location *loc;
13249 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
13251 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
13255 if (extra_trace_bits && *default_collect)
13256 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
13258 do_cleanups (cleanup);
13260 printf_filtered (_("Saved to file '%s'.\n"), filename);
13263 /* The `save breakpoints' command. */
13266 save_breakpoints_command (char *args, int from_tty)
13268 save_breakpoints (args, from_tty, NULL);
13271 /* The `save tracepoints' command. */
13274 save_tracepoints_command (char *args, int from_tty)
13276 save_breakpoints (args, from_tty, is_tracepoint);
13279 /* Create a vector of all tracepoints. */
13281 VEC(breakpoint_p) *
13282 all_tracepoints (void)
13284 VEC(breakpoint_p) *tp_vec = 0;
13285 struct breakpoint *tp;
13287 ALL_TRACEPOINTS (tp)
13289 VEC_safe_push (breakpoint_p, tp_vec, tp);
13296 /* This help string is used for the break, hbreak, tbreak and thbreak
13297 commands. It is defined as a macro to prevent duplication.
13298 COMMAND should be a string constant containing the name of the
13300 #define BREAK_ARGS_HELP(command) \
13301 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13302 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13303 If a line number is specified, break at start of code for that line.\n\
13304 If a function is specified, break at start of code for that function.\n\
13305 If an address is specified, break at that exact address.\n\
13306 With no LOCATION, uses current execution address of the selected\n\
13307 stack frame. This is useful for breaking on return to a stack frame.\n\
13309 THREADNUM is the number from \"info threads\".\n\
13310 CONDITION is a boolean expression.\n\
13312 Multiple breakpoints at one place are permitted, and useful if their\n\
13313 conditions are different.\n\
13315 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13317 /* List of subcommands for "catch". */
13318 static struct cmd_list_element *catch_cmdlist;
13320 /* List of subcommands for "tcatch". */
13321 static struct cmd_list_element *tcatch_cmdlist;
13324 add_catch_command (char *name, char *docstring,
13325 void (*sfunc) (char *args, int from_tty,
13326 struct cmd_list_element *command),
13327 char **(*completer) (struct cmd_list_element *cmd,
13328 char *text, char *word),
13329 void *user_data_catch,
13330 void *user_data_tcatch)
13332 struct cmd_list_element *command;
13334 command = add_cmd (name, class_breakpoint, NULL, docstring,
13336 set_cmd_sfunc (command, sfunc);
13337 set_cmd_context (command, user_data_catch);
13338 set_cmd_completer (command, completer);
13340 command = add_cmd (name, class_breakpoint, NULL, docstring,
13342 set_cmd_sfunc (command, sfunc);
13343 set_cmd_context (command, user_data_tcatch);
13344 set_cmd_completer (command, completer);
13348 clear_syscall_counts (struct inferior *inf)
13350 inf->total_syscalls_count = 0;
13351 inf->any_syscall_count = 0;
13352 VEC_free (int, inf->syscalls_counts);
13356 save_command (char *arg, int from_tty)
13358 printf_unfiltered (_("\"save\" must be followed by "
13359 "the name of a save subcommand.\n"));
13360 help_list (save_cmdlist, "save ", -1, gdb_stdout);
13363 struct breakpoint *
13364 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
13367 struct breakpoint *b, *b_tmp;
13369 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13371 if ((*callback) (b, data))
13378 /* Zero if any of the breakpoint's locations could be a location where
13379 functions have been inlined, nonzero otherwise. */
13382 is_non_inline_function (struct breakpoint *b)
13384 /* The shared library event breakpoint is set on the address of a
13385 non-inline function. */
13386 if (b->type == bp_shlib_event)
13392 /* Nonzero if the specified PC cannot be a location where functions
13393 have been inlined. */
13396 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc)
13398 struct breakpoint *b;
13399 struct bp_location *bl;
13401 ALL_BREAKPOINTS (b)
13403 if (!is_non_inline_function (b))
13406 for (bl = b->loc; bl != NULL; bl = bl->next)
13408 if (!bl->shlib_disabled
13409 && bpstat_check_location (bl, aspace, pc))
13418 initialize_breakpoint_ops (void)
13420 static int initialized = 0;
13422 struct breakpoint_ops *ops;
13428 /* The breakpoint_ops structure to be inherit by all kinds of
13429 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13430 internal and momentary breakpoints, etc.). */
13431 ops = &bkpt_base_breakpoint_ops;
13432 *ops = base_breakpoint_ops;
13433 ops->re_set = bkpt_re_set;
13434 ops->insert_location = bkpt_insert_location;
13435 ops->remove_location = bkpt_remove_location;
13436 ops->breakpoint_hit = bkpt_breakpoint_hit;
13438 /* The breakpoint_ops structure to be used in regular breakpoints. */
13439 ops = &bkpt_breakpoint_ops;
13440 *ops = bkpt_base_breakpoint_ops;
13441 ops->re_set = bkpt_re_set;
13442 ops->resources_needed = bkpt_resources_needed;
13443 ops->print_it = bkpt_print_it;
13444 ops->print_mention = bkpt_print_mention;
13445 ops->print_recreate = bkpt_print_recreate;
13447 /* Ranged breakpoints. */
13448 ops = &ranged_breakpoint_ops;
13449 *ops = bkpt_breakpoint_ops;
13450 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
13451 ops->resources_needed = resources_needed_ranged_breakpoint;
13452 ops->print_it = print_it_ranged_breakpoint;
13453 ops->print_one = print_one_ranged_breakpoint;
13454 ops->print_one_detail = print_one_detail_ranged_breakpoint;
13455 ops->print_mention = print_mention_ranged_breakpoint;
13456 ops->print_recreate = print_recreate_ranged_breakpoint;
13458 /* Internal breakpoints. */
13459 ops = &internal_breakpoint_ops;
13460 *ops = bkpt_base_breakpoint_ops;
13461 ops->re_set = internal_bkpt_re_set;
13462 ops->check_status = internal_bkpt_check_status;
13463 ops->print_it = internal_bkpt_print_it;
13464 ops->print_mention = internal_bkpt_print_mention;
13466 /* Momentary breakpoints. */
13467 ops = &momentary_breakpoint_ops;
13468 *ops = bkpt_base_breakpoint_ops;
13469 ops->re_set = momentary_bkpt_re_set;
13470 ops->check_status = momentary_bkpt_check_status;
13471 ops->print_it = momentary_bkpt_print_it;
13472 ops->print_mention = momentary_bkpt_print_mention;
13474 /* GNU v3 exception catchpoints. */
13475 ops = &gnu_v3_exception_catchpoint_ops;
13476 *ops = bkpt_breakpoint_ops;
13477 ops->print_it = print_it_exception_catchpoint;
13478 ops->print_one = print_one_exception_catchpoint;
13479 ops->print_mention = print_mention_exception_catchpoint;
13480 ops->print_recreate = print_recreate_exception_catchpoint;
13483 ops = &watchpoint_breakpoint_ops;
13484 *ops = base_breakpoint_ops;
13485 ops->dtor = dtor_watchpoint;
13486 ops->re_set = re_set_watchpoint;
13487 ops->insert_location = insert_watchpoint;
13488 ops->remove_location = remove_watchpoint;
13489 ops->breakpoint_hit = breakpoint_hit_watchpoint;
13490 ops->check_status = check_status_watchpoint;
13491 ops->resources_needed = resources_needed_watchpoint;
13492 ops->works_in_software_mode = works_in_software_mode_watchpoint;
13493 ops->print_it = print_it_watchpoint;
13494 ops->print_mention = print_mention_watchpoint;
13495 ops->print_recreate = print_recreate_watchpoint;
13497 /* Masked watchpoints. */
13498 ops = &masked_watchpoint_breakpoint_ops;
13499 *ops = watchpoint_breakpoint_ops;
13500 ops->insert_location = insert_masked_watchpoint;
13501 ops->remove_location = remove_masked_watchpoint;
13502 ops->resources_needed = resources_needed_masked_watchpoint;
13503 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
13504 ops->print_it = print_it_masked_watchpoint;
13505 ops->print_one_detail = print_one_detail_masked_watchpoint;
13506 ops->print_mention = print_mention_masked_watchpoint;
13507 ops->print_recreate = print_recreate_masked_watchpoint;
13510 ops = &tracepoint_breakpoint_ops;
13511 *ops = base_breakpoint_ops;
13512 ops->re_set = tracepoint_re_set;
13513 ops->breakpoint_hit = tracepoint_breakpoint_hit;
13514 ops->print_one_detail = tracepoint_print_one_detail;
13515 ops->print_mention = tracepoint_print_mention;
13516 ops->print_recreate = tracepoint_print_recreate;
13518 /* Fork catchpoints. */
13519 ops = &catch_fork_breakpoint_ops;
13520 *ops = base_breakpoint_ops;
13521 ops->insert_location = insert_catch_fork;
13522 ops->remove_location = remove_catch_fork;
13523 ops->breakpoint_hit = breakpoint_hit_catch_fork;
13524 ops->print_it = print_it_catch_fork;
13525 ops->print_one = print_one_catch_fork;
13526 ops->print_mention = print_mention_catch_fork;
13527 ops->print_recreate = print_recreate_catch_fork;
13529 /* Vfork catchpoints. */
13530 ops = &catch_vfork_breakpoint_ops;
13531 *ops = base_breakpoint_ops;
13532 ops->insert_location = insert_catch_vfork;
13533 ops->remove_location = remove_catch_vfork;
13534 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
13535 ops->print_it = print_it_catch_vfork;
13536 ops->print_one = print_one_catch_vfork;
13537 ops->print_mention = print_mention_catch_vfork;
13538 ops->print_recreate = print_recreate_catch_vfork;
13540 /* Exec catchpoints. */
13541 ops = &catch_exec_breakpoint_ops;
13542 *ops = base_breakpoint_ops;
13543 ops->dtor = dtor_catch_exec;
13544 ops->insert_location = insert_catch_exec;
13545 ops->remove_location = remove_catch_exec;
13546 ops->breakpoint_hit = breakpoint_hit_catch_exec;
13547 ops->print_it = print_it_catch_exec;
13548 ops->print_one = print_one_catch_exec;
13549 ops->print_mention = print_mention_catch_exec;
13550 ops->print_recreate = print_recreate_catch_exec;
13552 /* Syscall catchpoints. */
13553 ops = &catch_syscall_breakpoint_ops;
13554 *ops = base_breakpoint_ops;
13555 ops->dtor = dtor_catch_syscall;
13556 ops->insert_location = insert_catch_syscall;
13557 ops->remove_location = remove_catch_syscall;
13558 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
13559 ops->print_it = print_it_catch_syscall;
13560 ops->print_one = print_one_catch_syscall;
13561 ops->print_mention = print_mention_catch_syscall;
13562 ops->print_recreate = print_recreate_catch_syscall;
13566 _initialize_breakpoint (void)
13568 struct cmd_list_element *c;
13570 initialize_breakpoint_ops ();
13572 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
13573 observer_attach_inferior_exit (clear_syscall_counts);
13574 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
13576 breakpoint_objfile_key = register_objfile_data ();
13578 breakpoint_chain = 0;
13579 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13580 before a breakpoint is set. */
13581 breakpoint_count = 0;
13583 tracepoint_count = 0;
13585 add_com ("ignore", class_breakpoint, ignore_command, _("\
13586 Set ignore-count of breakpoint number N to COUNT.\n\
13587 Usage is `ignore N COUNT'."));
13589 add_com_alias ("bc", "ignore", class_breakpoint, 1);
13591 add_com ("commands", class_breakpoint, commands_command, _("\
13592 Set commands to be executed when a breakpoint is hit.\n\
13593 Give breakpoint number as argument after \"commands\".\n\
13594 With no argument, the targeted breakpoint is the last one set.\n\
13595 The commands themselves follow starting on the next line.\n\
13596 Type a line containing \"end\" to indicate the end of them.\n\
13597 Give \"silent\" as the first line to make the breakpoint silent;\n\
13598 then no output is printed when it is hit, except what the commands print."));
13600 add_com ("condition", class_breakpoint, condition_command, _("\
13601 Specify breakpoint number N to break only if COND is true.\n\
13602 Usage is `condition N COND', where N is an integer and COND is an\n\
13603 expression to be evaluated whenever breakpoint N is reached."));
13605 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
13606 Set a temporary breakpoint.\n\
13607 Like \"break\" except the breakpoint is only temporary,\n\
13608 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13609 by using \"enable delete\" on the breakpoint number.\n\
13611 BREAK_ARGS_HELP ("tbreak")));
13612 set_cmd_completer (c, location_completer);
13614 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
13615 Set a hardware assisted breakpoint.\n\
13616 Like \"break\" except the breakpoint requires hardware support,\n\
13617 some target hardware may not have this support.\n\
13619 BREAK_ARGS_HELP ("hbreak")));
13620 set_cmd_completer (c, location_completer);
13622 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
13623 Set a temporary hardware assisted breakpoint.\n\
13624 Like \"hbreak\" except the breakpoint is only temporary,\n\
13625 so it will be deleted when hit.\n\
13627 BREAK_ARGS_HELP ("thbreak")));
13628 set_cmd_completer (c, location_completer);
13630 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
13631 Enable some breakpoints.\n\
13632 Give breakpoint numbers (separated by spaces) as arguments.\n\
13633 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13634 This is used to cancel the effect of the \"disable\" command.\n\
13635 With a subcommand you can enable temporarily."),
13636 &enablelist, "enable ", 1, &cmdlist);
13638 add_com ("ab", class_breakpoint, enable_command, _("\
13639 Enable some breakpoints.\n\
13640 Give breakpoint numbers (separated by spaces) as arguments.\n\
13641 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13642 This is used to cancel the effect of the \"disable\" command.\n\
13643 With a subcommand you can enable temporarily."));
13645 add_com_alias ("en", "enable", class_breakpoint, 1);
13647 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
13648 Enable some breakpoints.\n\
13649 Give breakpoint numbers (separated by spaces) as arguments.\n\
13650 This is used to cancel the effect of the \"disable\" command.\n\
13651 May be abbreviated to simply \"enable\".\n"),
13652 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
13654 add_cmd ("once", no_class, enable_once_command, _("\
13655 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13656 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13659 add_cmd ("delete", no_class, enable_delete_command, _("\
13660 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13661 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13664 add_cmd ("delete", no_class, enable_delete_command, _("\
13665 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13666 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13669 add_cmd ("once", no_class, enable_once_command, _("\
13670 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13671 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13674 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
13675 Disable some breakpoints.\n\
13676 Arguments are breakpoint numbers with spaces in between.\n\
13677 To disable all breakpoints, give no argument.\n\
13678 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13679 &disablelist, "disable ", 1, &cmdlist);
13680 add_com_alias ("dis", "disable", class_breakpoint, 1);
13681 add_com_alias ("disa", "disable", class_breakpoint, 1);
13683 add_com ("sb", class_breakpoint, disable_command, _("\
13684 Disable some breakpoints.\n\
13685 Arguments are breakpoint numbers with spaces in between.\n\
13686 To disable all breakpoints, give no argument.\n\
13687 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13689 add_cmd ("breakpoints", class_alias, disable_command, _("\
13690 Disable some breakpoints.\n\
13691 Arguments are breakpoint numbers with spaces in between.\n\
13692 To disable all breakpoints, give no argument.\n\
13693 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13694 This command may be abbreviated \"disable\"."),
13697 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
13698 Delete some breakpoints or auto-display expressions.\n\
13699 Arguments are breakpoint numbers with spaces in between.\n\
13700 To delete all breakpoints, give no argument.\n\
13702 Also a prefix command for deletion of other GDB objects.\n\
13703 The \"unset\" command is also an alias for \"delete\"."),
13704 &deletelist, "delete ", 1, &cmdlist);
13705 add_com_alias ("d", "delete", class_breakpoint, 1);
13706 add_com_alias ("del", "delete", class_breakpoint, 1);
13708 add_com ("db", class_breakpoint, delete_command, _("\
13709 Delete some breakpoints.\n\
13710 Arguments are breakpoint numbers with spaces in between.\n\
13711 To delete all breakpoints, give no argument.\n"));
13713 add_cmd ("breakpoints", class_alias, delete_command, _("\
13714 Delete some breakpoints or auto-display expressions.\n\
13715 Arguments are breakpoint numbers with spaces in between.\n\
13716 To delete all breakpoints, give no argument.\n\
13717 This command may be abbreviated \"delete\"."),
13720 add_com ("clear", class_breakpoint, clear_command, _("\
13721 Clear breakpoint at specified line or function.\n\
13722 Argument may be line number, function name, or \"*\" and an address.\n\
13723 If line number is specified, all breakpoints in that line are cleared.\n\
13724 If function is specified, breakpoints at beginning of function are cleared.\n\
13725 If an address is specified, breakpoints at that address are cleared.\n\
13727 With no argument, clears all breakpoints in the line that the selected frame\n\
13728 is executing in.\n\
13730 See also the \"delete\" command which clears breakpoints by number."));
13731 add_com_alias ("cl", "clear", class_breakpoint, 1);
13733 c = add_com ("break", class_breakpoint, break_command, _("\
13734 Set breakpoint at specified line or function.\n"
13735 BREAK_ARGS_HELP ("break")));
13736 set_cmd_completer (c, location_completer);
13738 add_com_alias ("b", "break", class_run, 1);
13739 add_com_alias ("br", "break", class_run, 1);
13740 add_com_alias ("bre", "break", class_run, 1);
13741 add_com_alias ("brea", "break", class_run, 1);
13744 add_com_alias ("ba", "break", class_breakpoint, 1);
13748 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
13749 Break in function/address or break at a line in the current file."),
13750 &stoplist, "stop ", 1, &cmdlist);
13751 add_cmd ("in", class_breakpoint, stopin_command,
13752 _("Break in function or address."), &stoplist);
13753 add_cmd ("at", class_breakpoint, stopat_command,
13754 _("Break at a line in the current file."), &stoplist);
13755 add_com ("status", class_info, breakpoints_info, _("\
13756 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13757 The \"Type\" column indicates one of:\n\
13758 \tbreakpoint - normal breakpoint\n\
13759 \twatchpoint - watchpoint\n\
13760 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13761 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13762 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13763 address and file/line number respectively.\n\
13765 Convenience variable \"$_\" and default examine address for \"x\"\n\
13766 are set to the address of the last breakpoint listed unless the command\n\
13767 is prefixed with \"server \".\n\n\
13768 Convenience variable \"$bpnum\" contains the number of the last\n\
13769 breakpoint set."));
13772 add_info ("breakpoints", breakpoints_info, _("\
13773 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13774 The \"Type\" column indicates one of:\n\
13775 \tbreakpoint - normal breakpoint\n\
13776 \twatchpoint - watchpoint\n\
13777 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13778 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13779 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13780 address and file/line number respectively.\n\
13782 Convenience variable \"$_\" and default examine address for \"x\"\n\
13783 are set to the address of the last breakpoint listed unless the command\n\
13784 is prefixed with \"server \".\n\n\
13785 Convenience variable \"$bpnum\" contains the number of the last\n\
13786 breakpoint set."));
13788 add_info_alias ("b", "breakpoints", 1);
13791 add_com ("lb", class_breakpoint, breakpoints_info, _("\
13792 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13793 The \"Type\" column indicates one of:\n\
13794 \tbreakpoint - normal breakpoint\n\
13795 \twatchpoint - watchpoint\n\
13796 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13797 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13798 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13799 address and file/line number respectively.\n\
13801 Convenience variable \"$_\" and default examine address for \"x\"\n\
13802 are set to the address of the last breakpoint listed unless the command\n\
13803 is prefixed with \"server \".\n\n\
13804 Convenience variable \"$bpnum\" contains the number of the last\n\
13805 breakpoint set."));
13807 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
13808 Status of all breakpoints, or breakpoint number NUMBER.\n\
13809 The \"Type\" column indicates one of:\n\
13810 \tbreakpoint - normal breakpoint\n\
13811 \twatchpoint - watchpoint\n\
13812 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13813 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13814 \tuntil - internal breakpoint used by the \"until\" command\n\
13815 \tfinish - internal breakpoint used by the \"finish\" command\n\
13816 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13817 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13818 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13819 address and file/line number respectively.\n\
13821 Convenience variable \"$_\" and default examine address for \"x\"\n\
13822 are set to the address of the last breakpoint listed unless the command\n\
13823 is prefixed with \"server \".\n\n\
13824 Convenience variable \"$bpnum\" contains the number of the last\n\
13826 &maintenanceinfolist);
13828 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
13829 Set catchpoints to catch events."),
13830 &catch_cmdlist, "catch ",
13831 0/*allow-unknown*/, &cmdlist);
13833 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
13834 Set temporary catchpoints to catch events."),
13835 &tcatch_cmdlist, "tcatch ",
13836 0/*allow-unknown*/, &cmdlist);
13838 /* Add catch and tcatch sub-commands. */
13839 add_catch_command ("catch", _("\
13840 Catch an exception, when caught.\n\
13841 With an argument, catch only exceptions with the given name."),
13842 catch_catch_command,
13846 add_catch_command ("throw", _("\
13847 Catch an exception, when thrown.\n\
13848 With an argument, catch only exceptions with the given name."),
13849 catch_throw_command,
13853 add_catch_command ("fork", _("Catch calls to fork."),
13854 catch_fork_command_1,
13856 (void *) (uintptr_t) catch_fork_permanent,
13857 (void *) (uintptr_t) catch_fork_temporary);
13858 add_catch_command ("vfork", _("Catch calls to vfork."),
13859 catch_fork_command_1,
13861 (void *) (uintptr_t) catch_vfork_permanent,
13862 (void *) (uintptr_t) catch_vfork_temporary);
13863 add_catch_command ("exec", _("Catch calls to exec."),
13864 catch_exec_command_1,
13868 add_catch_command ("syscall", _("\
13869 Catch system calls by their names and/or numbers.\n\
13870 Arguments say which system calls to catch. If no arguments\n\
13871 are given, every system call will be caught.\n\
13872 Arguments, if given, should be one or more system call names\n\
13873 (if your system supports that), or system call numbers."),
13874 catch_syscall_command_1,
13875 catch_syscall_completer,
13879 c = add_com ("watch", class_breakpoint, watch_command, _("\
13880 Set a watchpoint for an expression.\n\
13881 Usage: watch [-l|-location] EXPRESSION\n\
13882 A watchpoint stops execution of your program whenever the value of\n\
13883 an expression changes.\n\
13884 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13885 the memory to which it refers."));
13886 set_cmd_completer (c, expression_completer);
13888 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
13889 Set a read watchpoint for an expression.\n\
13890 Usage: rwatch [-l|-location] EXPRESSION\n\
13891 A watchpoint stops execution of your program whenever the value of\n\
13892 an expression is read.\n\
13893 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13894 the memory to which it refers."));
13895 set_cmd_completer (c, expression_completer);
13897 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
13898 Set a watchpoint for an expression.\n\
13899 Usage: awatch [-l|-location] EXPRESSION\n\
13900 A watchpoint stops execution of your program whenever the value of\n\
13901 an expression is either read or written.\n\
13902 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13903 the memory to which it refers."));
13904 set_cmd_completer (c, expression_completer);
13906 add_info ("watchpoints", watchpoints_info, _("\
13907 Status of specified watchpoints (all watchpoints if no argument)."));
13909 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13910 respond to changes - contrary to the description. */
13911 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
13912 &can_use_hw_watchpoints, _("\
13913 Set debugger's willingness to use watchpoint hardware."), _("\
13914 Show debugger's willingness to use watchpoint hardware."), _("\
13915 If zero, gdb will not use hardware for new watchpoints, even if\n\
13916 such is available. (However, any hardware watchpoints that were\n\
13917 created before setting this to nonzero, will continue to use watchpoint\n\
13920 show_can_use_hw_watchpoints,
13921 &setlist, &showlist);
13923 can_use_hw_watchpoints = 1;
13925 /* Tracepoint manipulation commands. */
13927 c = add_com ("trace", class_breakpoint, trace_command, _("\
13928 Set a tracepoint at specified line or function.\n\
13930 BREAK_ARGS_HELP ("trace") "\n\
13931 Do \"help tracepoints\" for info on other tracepoint commands."));
13932 set_cmd_completer (c, location_completer);
13934 add_com_alias ("tp", "trace", class_alias, 0);
13935 add_com_alias ("tr", "trace", class_alias, 1);
13936 add_com_alias ("tra", "trace", class_alias, 1);
13937 add_com_alias ("trac", "trace", class_alias, 1);
13939 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
13940 Set a fast tracepoint at specified line or function.\n\
13942 BREAK_ARGS_HELP ("ftrace") "\n\
13943 Do \"help tracepoints\" for info on other tracepoint commands."));
13944 set_cmd_completer (c, location_completer);
13946 c = add_com ("strace", class_breakpoint, strace_command, _("\
13947 Set a static tracepoint at specified line, function or marker.\n\
13949 strace [LOCATION] [if CONDITION]\n\
13950 LOCATION may be a line number, function name, \"*\" and an address,\n\
13951 or -m MARKER_ID.\n\
13952 If a line number is specified, probe the marker at start of code\n\
13953 for that line. If a function is specified, probe the marker at start\n\
13954 of code for that function. If an address is specified, probe the marker\n\
13955 at that exact address. If a marker id is specified, probe the marker\n\
13956 with that name. With no LOCATION, uses current execution address of\n\
13957 the selected stack frame.\n\
13958 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13959 This collects arbitrary user data passed in the probe point call to the\n\
13960 tracing library. You can inspect it when analyzing the trace buffer,\n\
13961 by printing the $_sdata variable like any other convenience variable.\n\
13963 CONDITION is a boolean expression.\n\
13965 Multiple tracepoints at one place are permitted, and useful if their\n\
13966 conditions are different.\n\
13968 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13969 Do \"help tracepoints\" for info on other tracepoint commands."));
13970 set_cmd_completer (c, location_completer);
13972 add_info ("tracepoints", tracepoints_info, _("\
13973 Status of specified tracepoints (all tracepoints if no argument).\n\
13974 Convenience variable \"$tpnum\" contains the number of the\n\
13975 last tracepoint set."));
13977 add_info_alias ("tp", "tracepoints", 1);
13979 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
13980 Delete specified tracepoints.\n\
13981 Arguments are tracepoint numbers, separated by spaces.\n\
13982 No argument means delete all tracepoints."),
13985 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
13986 Disable specified tracepoints.\n\
13987 Arguments are tracepoint numbers, separated by spaces.\n\
13988 No argument means disable all tracepoints."),
13990 deprecate_cmd (c, "disable");
13992 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
13993 Enable specified tracepoints.\n\
13994 Arguments are tracepoint numbers, separated by spaces.\n\
13995 No argument means enable all tracepoints."),
13997 deprecate_cmd (c, "enable");
13999 add_com ("passcount", class_trace, trace_pass_command, _("\
14000 Set the passcount for a tracepoint.\n\
14001 The trace will end when the tracepoint has been passed 'count' times.\n\
14002 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14003 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14005 add_prefix_cmd ("save", class_breakpoint, save_command,
14006 _("Save breakpoint definitions as a script."),
14007 &save_cmdlist, "save ",
14008 0/*allow-unknown*/, &cmdlist);
14010 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
14011 Save current breakpoint definitions as a script.\n\
14012 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14013 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14014 session to restore them."),
14016 set_cmd_completer (c, filename_completer);
14018 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
14019 Save current tracepoint definitions as a script.\n\
14020 Use the 'source' command in another debug session to restore them."),
14022 set_cmd_completer (c, filename_completer);
14024 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
14025 deprecate_cmd (c, "save tracepoints");
14027 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
14028 Breakpoint specific settings\n\
14029 Configure various breakpoint-specific variables such as\n\
14030 pending breakpoint behavior"),
14031 &breakpoint_set_cmdlist, "set breakpoint ",
14032 0/*allow-unknown*/, &setlist);
14033 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
14034 Breakpoint specific settings\n\
14035 Configure various breakpoint-specific variables such as\n\
14036 pending breakpoint behavior"),
14037 &breakpoint_show_cmdlist, "show breakpoint ",
14038 0/*allow-unknown*/, &showlist);
14040 add_setshow_auto_boolean_cmd ("pending", no_class,
14041 &pending_break_support, _("\
14042 Set debugger's behavior regarding pending breakpoints."), _("\
14043 Show debugger's behavior regarding pending breakpoints."), _("\
14044 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14045 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14046 an error. If auto, an unrecognized breakpoint location results in a\n\
14047 user-query to see if a pending breakpoint should be created."),
14049 show_pending_break_support,
14050 &breakpoint_set_cmdlist,
14051 &breakpoint_show_cmdlist);
14053 pending_break_support = AUTO_BOOLEAN_AUTO;
14055 add_setshow_boolean_cmd ("auto-hw", no_class,
14056 &automatic_hardware_breakpoints, _("\
14057 Set automatic usage of hardware breakpoints."), _("\
14058 Show automatic usage of hardware breakpoints."), _("\
14059 If set, the debugger will automatically use hardware breakpoints for\n\
14060 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14061 a warning will be emitted for such breakpoints."),
14063 show_automatic_hardware_breakpoints,
14064 &breakpoint_set_cmdlist,
14065 &breakpoint_show_cmdlist);
14067 add_setshow_enum_cmd ("always-inserted", class_support,
14068 always_inserted_enums, &always_inserted_mode, _("\
14069 Set mode for inserting breakpoints."), _("\
14070 Show mode for inserting breakpoints."), _("\
14071 When this mode is off, breakpoints are inserted in inferior when it is\n\
14072 resumed, and removed when execution stops. When this mode is on,\n\
14073 breakpoints are inserted immediately and removed only when the user\n\
14074 deletes the breakpoint. When this mode is auto (which is the default),\n\
14075 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14076 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14077 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14078 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14080 &show_always_inserted_mode,
14081 &breakpoint_set_cmdlist,
14082 &breakpoint_show_cmdlist);
14084 add_com ("break-range", class_breakpoint, break_range_command, _("\
14085 Set a breakpoint for an address range.\n\
14086 break-range START-LOCATION, END-LOCATION\n\
14087 where START-LOCATION and END-LOCATION can be one of the following:\n\
14088 LINENUM, for that line in the current file,\n\
14089 FILE:LINENUM, for that line in that file,\n\
14090 +OFFSET, for that number of lines after the current line\n\
14091 or the start of the range\n\
14092 FUNCTION, for the first line in that function,\n\
14093 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14094 *ADDRESS, for the instruction at that address.\n\
14096 The breakpoint will stop execution of the inferior whenever it executes\n\
14097 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14098 range (including START-LOCATION and END-LOCATION)."));
14100 automatic_hardware_breakpoints = 1;
14102 observer_attach_about_to_proceed (breakpoint_about_to_proceed);